Commit 9b73896a authored by Tom Herbert's avatar Tom Herbert Committed by David S. Miller

kcm: Use stream parser

Adapt KCM to use the stream parser. This mostly involves removing
the RX handling and setting up the strparser using the interface.
Signed-off-by: default avatarTom Herbert <tom@herbertland.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 43a0c675
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <net/sock.h> #include <net/sock.h>
#include <net/strparser.h>
#include <uapi/linux/kcm.h> #include <uapi/linux/kcm.h>
extern unsigned int kcm_net_id; extern unsigned int kcm_net_id;
...@@ -21,16 +22,8 @@ extern unsigned int kcm_net_id; ...@@ -21,16 +22,8 @@ extern unsigned int kcm_net_id;
#define KCM_STATS_INCR(stat) ((stat)++) #define KCM_STATS_INCR(stat) ((stat)++)
struct kcm_psock_stats { struct kcm_psock_stats {
unsigned long long rx_msgs;
unsigned long long rx_bytes;
unsigned long long tx_msgs; unsigned long long tx_msgs;
unsigned long long tx_bytes; unsigned long long tx_bytes;
unsigned int rx_aborts;
unsigned int rx_mem_fail;
unsigned int rx_need_more_hdr;
unsigned int rx_msg_too_big;
unsigned int rx_msg_timeouts;
unsigned int rx_bad_hdr_len;
unsigned long long reserved; unsigned long long reserved;
unsigned long long unreserved; unsigned long long unreserved;
unsigned int tx_aborts; unsigned int tx_aborts;
...@@ -64,13 +57,6 @@ struct kcm_tx_msg { ...@@ -64,13 +57,6 @@ struct kcm_tx_msg {
struct sk_buff *last_skb; struct sk_buff *last_skb;
}; };
struct kcm_rx_msg {
int full_len;
int accum_len;
int offset;
int early_eaten;
};
/* Socket structure for KCM client sockets */ /* Socket structure for KCM client sockets */
struct kcm_sock { struct kcm_sock {
struct sock sk; struct sock sk;
...@@ -87,6 +73,7 @@ struct kcm_sock { ...@@ -87,6 +73,7 @@ struct kcm_sock {
struct work_struct tx_work; struct work_struct tx_work;
struct list_head wait_psock_list; struct list_head wait_psock_list;
struct sk_buff *seq_skb; struct sk_buff *seq_skb;
u32 tx_stopped : 1;
/* Don't use bit fields here, these are set under different locks */ /* Don't use bit fields here, these are set under different locks */
bool tx_wait; bool tx_wait;
...@@ -104,11 +91,11 @@ struct bpf_prog; ...@@ -104,11 +91,11 @@ struct bpf_prog;
/* Structure for an attached lower socket */ /* Structure for an attached lower socket */
struct kcm_psock { struct kcm_psock {
struct sock *sk; struct sock *sk;
struct strparser strp;
struct kcm_mux *mux; struct kcm_mux *mux;
int index; int index;
u32 tx_stopped : 1; u32 tx_stopped : 1;
u32 rx_stopped : 1;
u32 done : 1; u32 done : 1;
u32 unattaching : 1; u32 unattaching : 1;
...@@ -121,18 +108,12 @@ struct kcm_psock { ...@@ -121,18 +108,12 @@ struct kcm_psock {
struct kcm_psock_stats stats; struct kcm_psock_stats stats;
/* Receive */ /* Receive */
struct sk_buff *rx_skb_head;
struct sk_buff **rx_skb_nextp;
struct sk_buff *ready_rx_msg;
struct list_head psock_ready_list; struct list_head psock_ready_list;
struct work_struct rx_work;
struct delayed_work rx_delayed_work;
struct bpf_prog *bpf_prog; struct bpf_prog *bpf_prog;
struct kcm_sock *rx_kcm; struct kcm_sock *rx_kcm;
unsigned long long saved_rx_bytes; unsigned long long saved_rx_bytes;
unsigned long long saved_rx_msgs; unsigned long long saved_rx_msgs;
struct timer_list rx_msg_timer; struct sk_buff *ready_rx_msg;
unsigned int rx_need_bytes;
/* Transmit */ /* Transmit */
struct kcm_sock *tx_kcm; struct kcm_sock *tx_kcm;
...@@ -146,6 +127,7 @@ struct kcm_net { ...@@ -146,6 +127,7 @@ struct kcm_net {
struct mutex mutex; struct mutex mutex;
struct kcm_psock_stats aggregate_psock_stats; struct kcm_psock_stats aggregate_psock_stats;
struct kcm_mux_stats aggregate_mux_stats; struct kcm_mux_stats aggregate_mux_stats;
struct strp_aggr_stats aggregate_strp_stats;
struct list_head mux_list; struct list_head mux_list;
int count; int count;
}; };
...@@ -163,6 +145,7 @@ struct kcm_mux { ...@@ -163,6 +145,7 @@ struct kcm_mux {
struct kcm_mux_stats stats; struct kcm_mux_stats stats;
struct kcm_psock_stats aggregate_psock_stats; struct kcm_psock_stats aggregate_psock_stats;
struct strp_aggr_stats aggregate_strp_stats;
/* Receive */ /* Receive */
spinlock_t rx_lock ____cacheline_aligned_in_smp; spinlock_t rx_lock ____cacheline_aligned_in_smp;
...@@ -190,14 +173,6 @@ static inline void aggregate_psock_stats(struct kcm_psock_stats *stats, ...@@ -190,14 +173,6 @@ static inline void aggregate_psock_stats(struct kcm_psock_stats *stats,
/* Save psock statistics in the mux when psock is being unattached. */ /* Save psock statistics in the mux when psock is being unattached. */
#define SAVE_PSOCK_STATS(_stat) (agg_stats->_stat += stats->_stat) #define SAVE_PSOCK_STATS(_stat) (agg_stats->_stat += stats->_stat)
SAVE_PSOCK_STATS(rx_msgs);
SAVE_PSOCK_STATS(rx_bytes);
SAVE_PSOCK_STATS(rx_aborts);
SAVE_PSOCK_STATS(rx_mem_fail);
SAVE_PSOCK_STATS(rx_need_more_hdr);
SAVE_PSOCK_STATS(rx_msg_too_big);
SAVE_PSOCK_STATS(rx_msg_timeouts);
SAVE_PSOCK_STATS(rx_bad_hdr_len);
SAVE_PSOCK_STATS(tx_msgs); SAVE_PSOCK_STATS(tx_msgs);
SAVE_PSOCK_STATS(tx_bytes); SAVE_PSOCK_STATS(tx_bytes);
SAVE_PSOCK_STATS(reserved); SAVE_PSOCK_STATS(reserved);
......
...@@ -172,6 +172,5 @@ static void __exit ila_fini(void) ...@@ -172,6 +172,5 @@ static void __exit ila_fini(void)
module_init(ila_init); module_init(ila_init);
module_exit(ila_fini); module_exit(ila_fini);
MODULE_ALIAS_RTNL_LWT(ILA);
MODULE_AUTHOR("Tom Herbert <tom@herbertland.com>"); MODULE_AUTHOR("Tom Herbert <tom@herbertland.com>");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
...@@ -3,6 +3,7 @@ config AF_KCM ...@@ -3,6 +3,7 @@ config AF_KCM
tristate "KCM sockets" tristate "KCM sockets"
depends on INET depends on INET
select BPF_SYSCALL select BPF_SYSCALL
select STREAM_PARSER
---help--- ---help---
KCM (Kernel Connection Multiplexor) sockets provide a method KCM (Kernel Connection Multiplexor) sockets provide a method
for multiplexing messages of a message based application for multiplexing messages of a message based application
......
...@@ -155,8 +155,8 @@ static void kcm_format_psock(struct kcm_psock *psock, struct seq_file *seq, ...@@ -155,8 +155,8 @@ static void kcm_format_psock(struct kcm_psock *psock, struct seq_file *seq,
seq_printf(seq, seq_printf(seq,
" psock-%-5u %-10llu %-16llu %-10llu %-16llu %-8d %-8d %-8d %-8d ", " psock-%-5u %-10llu %-16llu %-10llu %-16llu %-8d %-8d %-8d %-8d ",
psock->index, psock->index,
psock->stats.rx_msgs, psock->strp.stats.rx_msgs,
psock->stats.rx_bytes, psock->strp.stats.rx_bytes,
psock->stats.tx_msgs, psock->stats.tx_msgs,
psock->stats.tx_bytes, psock->stats.tx_bytes,
psock->sk->sk_receive_queue.qlen, psock->sk->sk_receive_queue.qlen,
...@@ -170,9 +170,12 @@ static void kcm_format_psock(struct kcm_psock *psock, struct seq_file *seq, ...@@ -170,9 +170,12 @@ static void kcm_format_psock(struct kcm_psock *psock, struct seq_file *seq,
if (psock->tx_stopped) if (psock->tx_stopped)
seq_puts(seq, "TxStop "); seq_puts(seq, "TxStop ");
if (psock->rx_stopped) if (psock->strp.rx_stopped)
seq_puts(seq, "RxStop "); seq_puts(seq, "RxStop ");
if (psock->strp.rx_paused)
seq_puts(seq, "RxPause ");
if (psock->tx_kcm) if (psock->tx_kcm)
seq_printf(seq, "Rsvd-%d ", psock->tx_kcm->index); seq_printf(seq, "Rsvd-%d ", psock->tx_kcm->index);
...@@ -275,6 +278,7 @@ static int kcm_stats_seq_show(struct seq_file *seq, void *v) ...@@ -275,6 +278,7 @@ static int kcm_stats_seq_show(struct seq_file *seq, void *v)
{ {
struct kcm_psock_stats psock_stats; struct kcm_psock_stats psock_stats;
struct kcm_mux_stats mux_stats; struct kcm_mux_stats mux_stats;
struct strp_aggr_stats strp_stats;
struct kcm_mux *mux; struct kcm_mux *mux;
struct kcm_psock *psock; struct kcm_psock *psock;
struct net *net = seq->private; struct net *net = seq->private;
...@@ -282,20 +286,28 @@ static int kcm_stats_seq_show(struct seq_file *seq, void *v) ...@@ -282,20 +286,28 @@ static int kcm_stats_seq_show(struct seq_file *seq, void *v)
memset(&mux_stats, 0, sizeof(mux_stats)); memset(&mux_stats, 0, sizeof(mux_stats));
memset(&psock_stats, 0, sizeof(psock_stats)); memset(&psock_stats, 0, sizeof(psock_stats));
memset(&strp_stats, 0, sizeof(strp_stats));
mutex_lock(&knet->mutex); mutex_lock(&knet->mutex);
aggregate_mux_stats(&knet->aggregate_mux_stats, &mux_stats); aggregate_mux_stats(&knet->aggregate_mux_stats, &mux_stats);
aggregate_psock_stats(&knet->aggregate_psock_stats, aggregate_psock_stats(&knet->aggregate_psock_stats,
&psock_stats); &psock_stats);
aggregate_strp_stats(&knet->aggregate_strp_stats,
&strp_stats);
list_for_each_entry_rcu(mux, &knet->mux_list, kcm_mux_list) { list_for_each_entry_rcu(mux, &knet->mux_list, kcm_mux_list) {
spin_lock_bh(&mux->lock); spin_lock_bh(&mux->lock);
aggregate_mux_stats(&mux->stats, &mux_stats); aggregate_mux_stats(&mux->stats, &mux_stats);
aggregate_psock_stats(&mux->aggregate_psock_stats, aggregate_psock_stats(&mux->aggregate_psock_stats,
&psock_stats); &psock_stats);
list_for_each_entry(psock, &mux->psocks, psock_list) aggregate_strp_stats(&mux->aggregate_strp_stats,
&strp_stats);
list_for_each_entry(psock, &mux->psocks, psock_list) {
aggregate_psock_stats(&psock->stats, &psock_stats); aggregate_psock_stats(&psock->stats, &psock_stats);
save_strp_stats(&psock->strp, &strp_stats);
}
spin_unlock_bh(&mux->lock); spin_unlock_bh(&mux->lock);
} }
...@@ -328,7 +340,7 @@ static int kcm_stats_seq_show(struct seq_file *seq, void *v) ...@@ -328,7 +340,7 @@ static int kcm_stats_seq_show(struct seq_file *seq, void *v)
mux_stats.rx_ready_drops); mux_stats.rx_ready_drops);
seq_printf(seq, seq_printf(seq,
"%-8s %-10s %-16s %-10s %-16s %-10s %-10s %-10s %-10s %-10s %-10s %-10s %-10s %-10s\n", "%-8s %-10s %-16s %-10s %-16s %-10s %-10s %-10s %-10s %-10s %-10s %-10s %-10s %-10s %-10s %-10s\n",
"Psock", "Psock",
"RX-Msgs", "RX-Msgs",
"RX-Bytes", "RX-Bytes",
...@@ -337,6 +349,8 @@ static int kcm_stats_seq_show(struct seq_file *seq, void *v) ...@@ -337,6 +349,8 @@ static int kcm_stats_seq_show(struct seq_file *seq, void *v)
"Reserved", "Reserved",
"Unreserved", "Unreserved",
"RX-Aborts", "RX-Aborts",
"RX-Intr",
"RX-Unrecov",
"RX-MemFail", "RX-MemFail",
"RX-NeedMor", "RX-NeedMor",
"RX-BadLen", "RX-BadLen",
...@@ -345,20 +359,22 @@ static int kcm_stats_seq_show(struct seq_file *seq, void *v) ...@@ -345,20 +359,22 @@ static int kcm_stats_seq_show(struct seq_file *seq, void *v)
"TX-Aborts"); "TX-Aborts");
seq_printf(seq, seq_printf(seq,
"%-8s %-10llu %-16llu %-10llu %-16llu %-10llu %-10llu %-10u %-10u %-10u %-10u %-10u %-10u %-10u\n", "%-8s %-10llu %-16llu %-10llu %-16llu %-10llu %-10llu %-10u %-10u %-10u %-10u %-10u %-10u %-10u %-10u %-10u\n",
"", "",
psock_stats.rx_msgs, strp_stats.rx_msgs,
psock_stats.rx_bytes, strp_stats.rx_bytes,
psock_stats.tx_msgs, psock_stats.tx_msgs,
psock_stats.tx_bytes, psock_stats.tx_bytes,
psock_stats.reserved, psock_stats.reserved,
psock_stats.unreserved, psock_stats.unreserved,
psock_stats.rx_aborts, strp_stats.rx_aborts,
psock_stats.rx_mem_fail, strp_stats.rx_interrupted,
psock_stats.rx_need_more_hdr, strp_stats.rx_unrecov_intr,
psock_stats.rx_bad_hdr_len, strp_stats.rx_mem_fail,
psock_stats.rx_msg_too_big, strp_stats.rx_need_more_hdr,
psock_stats.rx_msg_timeouts, strp_stats.rx_bad_hdr_len,
strp_stats.rx_msg_too_big,
strp_stats.rx_msg_timeouts,
psock_stats.tx_aborts); psock_stats.tx_aborts);
return 0; return 0;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment