net-tcp: TCP/IP stack bypass for loopback connections
Subsystems (5)
PATCH v3 1/1 net-tcp: TCP/IP stack bypass for loopback connections
From: "Bruce \"Brutus\" Curtis" <[email protected]>
TCP/IP loopback socket pair stack bypass, based on an idea by, and rough upstream patch from, David Miller <[email protected]> called "friends", the data structure modifcations and connection scheme are reused with extensive data-path changes.
A new sysctl, net.ipv4.tcp_friends, is added:
0: disable friends and use the stock data path.
1: enable friends and bypass the stack data path, the default.
Note, when friends is enabled any loopback interpose, e.g. tcpdump, will only see the TCP/IP packets during connection establishment and finish, all data bypasses the stack and instead is delivered to the destination socket directly.
Testing done on a 4 socket 2.2GHz "Quad-Core AMD Opteron(tm) Processor 8354 CPU" based system, netperf results for a single connection show increased TCP_STREAM throughput, increased TCP_RR and TCP_CRR transaction rate for most message sizes vs baseline and comparable to AF_UNIX.
Significant increase (up to 4.88x) in aggregate throughput for multiple netperf runs (STREAM 32KB I/O x N) is seen.
Some netperf results:
Default netperf: netperf
netperf -t STREAM_STREAM
netperf
Baseline AF_UNIX Friends
Mbits/S Mbits/S Mbits/S
9319 669 7% 11798 127% 1764%
Note, for the default netperf runs AF_UNIX (STREAM_STREAM) is at a big disadvantage as it's default socket buffer sizes and messages sizes (derived from the socket buffer sizes) are small compared with TCP, also for baseline TCP as no socket buffer sizes are set autosizing is used, in the above baseline results the final netperf send buffer size was 650k+ and the netserver recieve buffer was 2g+ while friends is fixed at 16384 and 87380.
A second set of runs done with the same fixed socket buffers and message sizes are done.
Orange-to-Orange netperf:
netperf -- -s 8192,43690 -S 8192,43690 -m 16384 -M 87380
netperf -t STREAM_STREAM -- -s 51882 -m 16384 -M 87380
netperf -- -s 8192,43690 -S 8192,43690 -m 16384 -M 87380
Baseline AF_UNIX Friends
Mbits/S Mbits/S Mbits/S
4014 7717 192% 11716 292% 152%All subsequent AF_UNIX (STREAM_STREAM, STREAM_RR) tests are done with "-s 51882" such that the same total effective socket buffering is used as for the TCP runs defaults (16384+87380/2).
STREAM 32KB I/O x N: netperf -l 100 -t TCP_STREAM -- -m 32K -M 32K
netperf -l 100 -t STREAM_STREAM -- -s 51882 -m 32K -M 32K
netperf -l 100 -t TCP_STREAM -- -m 32K -M 32K
Baseline AF_UNIX Friends
N COC Mbits/S Mbits/S Mbits/S
1 - 9510 7472 97% 11851 125% 159%
2 - 18037 19602 86% 22942 127% 117%
16 2 75132 324053 402% 351214 467% 108%
32 4 66346 282396 332% 303547 458% 107%
256 32 72427 81883 138% 294526 407% 360%
512 64 79874 85047 116% 295999 371% 348%
1600 200 110380 148549 223% 426542 386% 287%COC = Cpu Over Commit ratio (16 core platform)
STREAM: netperf -l 100 -t TCP_STREAM
netperf -l 100 -t STREAM_STREAM -- -s 51882 -m 16384 -M 87380 netperf -l 100 -t TCP_STREAM
netperf Baseline AF_UNIX Friends -m/-M N Mbits/S Mbits/S Mbits/S 64 930 415 45% 414 45% 100% 1K 5127 4362 85% 3235 63% 74% 8K 6302 7830 124% 9041 155% 124% 32K 8557 9284 108% 14469 169% 156% 64K 9411 9438 100% 15206 162% 161% 128K 10233 9560 93% 15495 151% 162% 256K 10690 9639 90% 15410 144% 160% 512K 10984 9465 86% 14045 128% 148% 1M 9384 9434 101% 12913 138% 137% 16M 7520 9195 122% 12233 163% 133%
RR: netperf -l 100 -t TCP_RR
netperf -l 100 -t STREAM_RR -- -s 51882
netperf -l 100 -t TCP_RR
netperf Baseline AF_UNIX Friends -r N,N Trans./S Trans./S Trans./S 64 49808 88076 177% 92371 185% 105% 1K 45111 81297 180% 84171 187% 104% 8K 27256 29888 110% 31861 117% 107% 32K 11138 11860 106% 12535 113% 106% 64K 7210 6307 87% 7682 107% 122% 128K 4399 3335 76% 3911 89% 117% 256K 2550 1856 73% 2342 92% 126% 512K 1030 1026 100% 1236 120% 120%
1M 424 501 118% 515 121% 103%
16M 27.1 33.5 124% 34.5 127% 103%
CRR: netperf -l 100 -t TCP_CRR
netperf -l 100 -t TCP_CRR
netperf Baseline AF_UNIX Friends -r N Trans./S Trans./S Trans./S 64 16848 - 19374 115% - 1K 15575 - 18938 122% - 8K 12581 - 14993 119% - 32K 7740 - 8451 109% - 64K 4484 - 6003 134% - 128K 2394 - 3387 141% - 256K 1341 - 2126 159% - 512K 651 - 1055 162% - 1M 375 - 475 127% - 16M 28.8 - 34.1 118% -
SPLICE 32KB I/O:
Where: "Z" source File /dev/zero, "-" source user memory
"N" sink File /dev/null, "-" sink user memory "S" Splice on, "-" Splice off
Source
Sink Baseline AF_UNIX Friends FSFS Mbits/S Mbits/S Mbits/S ---- 9147 - 12020 131% - Z--- 7731 - 11680 151% - --N- 9200 - 11728 127% - Z-N- 8877 - 11633 131% - -S-- 20894 - 21956 105% - ZS-- 8226 - 9218 112% - -SN- 18729 - 24025 128% - ZSN- 8023 - 9043 113% - ---S 8636 - 8255 96% - Z--S 8399 - 8417 100% - --NS 13698 - 10222 75% - Z-NS 11851 - 10237 86% - -S-S 14254 - 18314 128% - ZS-S 7788 - 8504 109% - -SNS 19005 - 20409 107% - ZSNS 13161 - 15079 115% -
--- Documentation/networking/ip-sysctl.txt | 8 + include/linux/skbuff.h | 2 + include/net/request_sock.h | 1 + include/net/sock.h | 32 ++- include/net/tcp.h | 13 +- net/core/skbuff.c | 1 + net/core/sock.c | 1 + net/core/stream.c | 36 ++ net/ipv4/inet_connection_sock.c | 20 + net/ipv4/sysctl_net_ipv4.c | 7 + net/ipv4/tcp.c | 603 +++++++++++++++++++++++++++----- net/ipv4/tcp_input.c | 22 +- net/ipv4/tcp_ipv4.c | 2 + net/ipv4/tcp_minisocks.c | 4 + net/ipv4/tcp_output.c | 16 +- net/ipv6/tcp_ipv6.c | 1 + 16 files changed, 679 insertions(+), 90 deletions(-)
Documentation/networking/ip-sysctl.txt +8 -0
@@ -214,6 +214,14 @@ tcp_fack - BOOLEAN Enable FACK congestion avoidance and fast retransmission. The value is not used, if tcp_sack is not enabled. +tcp_friends - BOOLEAN + If set, TCP loopback socket pair stack bypass is enabled such + that all data sent will be directly queued to the receiver's + socket for receive. Note, normal connection establishment and + finish is used to make friends so any loopback interpose, e.g. + tcpdump, will see these TCP segements but no data segments. + Default: 1 + tcp_fin_timeout - INTEGER Time to hold socket in state FIN-WAIT-2, if it was closed by our side. Peer can be broken and never close its side,
include/linux/skbuff.h +2 -0
@@ -332,6 +332,7 @@ typedef unsigned char *sk_buff_data_t;* @cb: Control buffer. Free for use by every layer. Put private vars here * @_skb_refdst: destination entry (with norefcount bit) * @sp: the security path, used for xfrm +* @friend: loopback friend socket * @len: Length of actual data * @data_len: Data length * @mac_len: Length of link layer header
@@ -407,6 +408,7 @@ struct sk_buff {#ifdef CONFIG_XFRM struct sec_path *sp;#endif +struct sock *friend;unsigned int len, data_len; __u16 mac_len,
include/net/request_sock.h +1 -0
@@ -63,6 +63,7 @@ struct request_sock {unsigned long expires;const struct request_sock_ops *rsk_ops;struct sock *sk; +struct sock *friend;u32 secid;u32 peer_secid; };
include/net/sock.h +29 -3
@@ -197,6 +197,7 @@ struct cg_proto;* @sk_userlocks: %SO_SNDBUF and %SO_RCVBUF settings * @sk_lock: synchronizer * @sk_rcvbuf: size of receive buffer in bytes +* @sk_friend: loopback friend socket * @sk_wq: sock wait queue and async head * @sk_rx_dst: receive input route used by early tcp demux * @sk_dst_cache: destination cache
@@ -287,6 +288,14 @@ struct sock {socket_lock_t sk_lock;struct sk_buff_head sk_receive_queue;/* +* If socket has a friend (sk_friend != NULL) then a send skb is +* enqueued directly to the friend's sk_receive_queue such that: +* +* sk_sndbuf -> sk_sndbuf + sk_friend->sk_rcvbuf +* sk_wmem_queued -> sk_friend->sk_rmem_alloc +*/ +struct sock *sk_friend; +/* * The backlog queue is special, it is always used with * the per-socket spinlock held and requires low latency * access. Therefore we special case it's implementation.
@@ -705,24 +714,40 @@ static inline bool sk_acceptq_is_full(const struct sock *sk)return sk->sk_ack_backlog > sk->sk_max_ack_backlog; } +static inline int sk_wmem_queued_get (const struct sock *sk) +{ +if (sk->sk_friend) +return atomic_read (&sk->sk_friend->sk_rmem_alloc); +else +return sk->sk_wmem_queued; +} + +static inline int sk_sndbuf_get (const struct sock *sk) +{ +if (sk->sk_friend) +return sk->sk_sndbuf + sk->sk_friend->sk_rcvbuf; +else +return sk->sk_sndbuf; +} +/* * Compute minimal free write space needed to queue new packets. */ static inline int sk_stream_min_wspace (const struct sock *sk) { -return sk->sk_wmem_queued >>1 ; +return sk_wmem_queued_get (sk) >>1 ; }static inline int sk_stream_wspace (const struct sock *sk) { -return sk->sk_sndbuf - sk->sk_wmem_queued; +return sk_sndbuf_get (sk) -sk_wmem_queued_get (sk); }extern void sk_stream_write_space (struct sock *sk);static inline bool sk_stream_memory_free (const struct sock *sk) { -return sk->sk_wmem_queued < sk->sk_sndbuf; +return sk_wmem_queued_get (sk) <sk_sndbuf_get (sk); }/* OOB backlog add */
@@ -831,6 +856,7 @@ static inline void sock_rps_reset_rxhash(struct sock *sk) })extern int sk_stream_wait_connect (struct sock *sk,long *timeo_p); +extern int sk_stream_wait_friend (struct sock *sk,long *timeo_p);extern int sk_stream_wait_memory (struct sock *sk,long *timeo_p);extern void sk_stream_wait_close (struct sock *sk,long timeo_p);extern int sk_stream_error (struct sock *sk,int flags,int err);
include/net/tcp.h +12 -1
@@ -292,6 +292,7 @@ extern int sysctl_tcp_thin_dupack;extern int sysctl_tcp_early_retrans;extern int sysctl_tcp_limit_output_bytes;extern int sysctl_tcp_challenge_ack_limit; +extern int sysctl_tcp_friends;extern atomic_long_t tcp_memory_allocated;extern struct percpu_counter tcp_sockets_allocated;
@@ -688,6 +689,15 @@ void tcp_send_window_probe(struct sock *sk);#define TCPHDR_ECE 0x40#define TCPHDR_CWR 0x80 +/* If skb->friend, TCP friends per packet state. +*/ +struct friend_skb_parm { +bool tail_inuse;/* In use by skb->friend send while */ +/* on sk_receive_queue for tail put */ +}; + +#define TCP_FRIEND_CB (tcb) (&(tcb)->header.hf) +/* This is what the send packet queuing engine uses to pass * TCP per-packet control information to the transmission code. * We also store the host-order sequence numbers in here too.
@@ -700,6 +710,7 @@ struct tcp_skb_cb {#if IS_ENABLED (CONFIG_IPV6 )struct inet6_skb_parm h6;#endif +struct friend_skb_parm hf; } header;/* For incoming frames */ __u32 seq;/* Starting sequence number */ __u32 end_seq;/* SEQ + FIN + SYN + datalen */
@@ -1042,7 +1053,7 @@ static inline bool tcp_prequeue(struct sock *sk, struct sk_buff *skb) {struct tcp_sock *tp =tcp_sk (sk); -if (sysctl_tcp_low_latency || !tp->ucopy.task) +if (sysctl_tcp_low_latency || !tp->ucopy.task || sk->sk_friend)return false;__skb_queue_tail (&tp->ucopy.prequeue, skb);
net/core/skbuff.c +1 -0
@@ -703,6 +703,7 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)#ifdef CONFIG_XFRM new->sp =secpath_get (old->sp);#endif + new->friend = old->friend;memcpy (new->cb, old->cb,sizeof (old->cb)); new->csum = old->csum; new->local_df = old->local_df;
net/core/sock.c +1 -0
@@ -2134,6 +2134,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)#ifdef CONFIG_NET_DMA skb_queue_head_init (&sk->sk_async_wait_queue);#endif + sk->sk_friend =NULL ; sk->sk_send_head =NULL ;
net/core/stream.c +36 -0
@@ -83,6 +83,42 @@ int sk_stream_wait_connect(struct sock *sk, long *timeo_p)EXPORT_SYMBOL (sk_stream_wait_connect);/** +* sk_stream_wait_friend - Wait for a socket to make friends +* @sk: sock to wait on +* @timeo_p: for how long to wait +* +* Must be called with the socket locked. +*/ +int sk_stream_wait_friend (struct sock *sk,long *timeo_p) +{ +struct task_struct *tsk = current; +DEFINE_WAIT (wait); +int done; + +do { +int err =sock_error (sk); +if (err) +return err; +if (!sk->sk_friend) +return -EBADFD ; +if (!*timeo_p) +return -EAGAIN ; +if (signal_pending (tsk)) +return sock_intr_errno (*timeo_p); + +prepare_to_wait (sk_sleep (sk), &wait,TASK_INTERRUPTIBLE ); + sk->sk_write_pending++; + done =sk_wait_event (sk, timeo_p, + !sk->sk_err && + sk->sk_friend->sk_friend); +finish_wait (sk_sleep (sk), &wait); + sk->sk_write_pending--; + }while (!done); +return 0 ; +} +EXPORT_SYMBOL (sk_stream_wait_friend); + +/** * sk_stream_closing - Return 1 if we still have things to send in our buffers. * @sk: socket to verify */
net/ipv4/inet_connection_sock.c +20 -0
@@ -648,6 +648,26 @@ struct sock *inet_csk_clone_lock(const struct sock *sk,if (newsk !=NULL ) {struct inet_connection_sock *newicsk =inet_csk (newsk); +if (req->friend) { +/* +* Make friends with the requestor but the ACK of +* the request is already in-flight so the race is +* on to make friends before the ACK is processed. +* If the requestor's sk_friend value is != NULL +* then the requestor has already processed the +* ACK so indicate state change to wake'm up. +*/ +struct sock *was; + +sock_hold (req->friend); + newsk->sk_friend = req->friend; +sock_hold (newsk); + was =xchg (&req->friend->sk_friend, newsk); +/* If requester already connect()ed, maybe sleeping */ +if (was && !sock_flag (req->friend,SOCK_DEAD )) + sk->sk_state_change (req->friend); + } + newsk->sk_state =TCP_SYN_RECV ; newicsk->icsk_bind_hash =NULL ;
net/ipv4/sysctl_net_ipv4.c +7 -0
@@ -794,6 +794,13 @@ static struct ctl_table ipv4_table[] = { .proc_handler = proc_dointvec_minmax, .extra1 = &zero }, + { + .procname = "tcp_friends", + .data = &sysctl_tcp_friends, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec + }, { } };
net/ipv4/tcp.c +523 -80
930 lines not on this page · raw message
net/ipv4/tcp_input.c +18 -4
@@ -530,6 +530,9 @@ void tcp_rcv_space_adjust(struct sock *sk)int time;int space; +if (sk->sk_friend) +return ; +if (tp->rcvq_space.time ==0 ) goto new_measure;
@@ -4326,8 +4329,9 @@ static int tcp_prune_queue(struct sock *sk);static int tcp_try_rmem_schedule (struct sock *sk,struct sk_buff *skb,unsigned int size) { -if (atomic_read (&sk->sk_rmem_alloc) > sk->sk_rcvbuf || - !sk_rmem_schedule (sk, skb, size)) { +if (!sk->sk_friend && + (atomic_read (&sk->sk_rmem_alloc) > sk->sk_rcvbuf || + !sk_rmem_schedule (sk, skb, size))) {if (tcp_prune_queue (sk) <0 )return -1 ;
@@ -5712,6 +5716,16 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,* state to ESTABLISHED..." */ +if (skb->friend) { +/* +* If friends haven't been made yet, our sk_friend +* still == NULL, then update with the ACK's friend +* value (the listen()er's sock addr) which is used +* as a place holder. +*/ +cmpxchg (&sk->sk_friend,NULL , skb->friend); + } +TCP_ECN_rcv_synack (tp, th);tcp_init_wl (tp,TCP_SKB_CB (skb)->seq);
@@ -5787,9 +5801,9 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, tcp_rcv_fastopen_synack(sk, skb, &foc))return -1 ; -if (sk->sk_write_pending || +if (!skb->friend && (sk->sk_write_pending || icsk->icsk_accept_queue.rskq_defer_accept || - icsk->icsk_ack.pingpong) { + icsk->icsk_ack.pingpong)) {/* Save one ACK. Data will be ready after * several ticks, if write_pending is set. *
net/ipv4/tcp_ipv4.c +2 -0
@@ -1512,6 +1512,8 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)tcp_rsk (req)->af_specific = &tcp_request_sock_ipv4_ops;#endif + req->friend = skb->friend; +tcp_clear_options (&tmp_opt); tmp_opt.mss_clamp =TCP_MSS_DEFAULT ; tmp_opt.user_mss = tp->rx_opt.user_mss;
net/ipv4/tcp_minisocks.c +4 -0
@@ -268,6 +268,9 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)const struct tcp_sock *tp =tcp_sk (sk);bool recycle_ok = false; +if (sk->sk_friend) + goto out; +if (tcp_death_row.sysctl_tw_recycle && tp->rx_opt.ts_recent_stamp) recycle_ok =tcp_remember_stamp (sk);
@@ -347,6 +350,7 @@ void tcp_time_wait(struct sock *sk, int state, int timeo) }tcp_update_metrics (sk); +out:tcp_done (sk); }
net/ipv4/tcp_output.c +14 -2
@@ -65,6 +65,9 @@ int sysctl_tcp_base_mss __read_mostly = TCP_BASE_MSS;/* By default, RFC2861 behavior. */ int sysctl_tcp_slow_start_after_idle__read_mostly =1 ; +/* By default, TCP loopback bypass */ +int sysctl_tcp_friends__read_mostly =1 ; +int sysctl_tcp_cookie_size__read_mostly =0 ;/* TCP_COOKIE_MAX */ EXPORT_SYMBOL_GPL (sysctl_tcp_cookie_size);
@@ -1025,9 +1028,13 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it, tcb =TCP_SKB_CB (skb);memset (&opts,0 ,sizeof (opts)); -if (unlikely (tcb->tcp_flags &TCPHDR_SYN )) +if (unlikely (tcb->tcp_flags &TCPHDR_SYN )) { +/* Only try to make friends if enabled */ +if (sysctl_tcp_friends) + skb->friend = sk; + tcp_options_size =tcp_syn_options (sk, skb, &opts, &md5); -else + }else tcp_options_size =tcp_established_options (sk, skb, &opts, &md5); tcp_header_size = tcp_options_size +sizeof (struct tcphdr );
@@ -2721,6 +2728,11 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst, }memset (&opts,0 ,sizeof (opts)); + +/* Only try to make friends if enabled */ +if (sysctl_tcp_friends) + skb->friend = sk; +#ifdef CONFIG_SYN_COOKIES if (unlikely (req->cookie_ts))TCP_SKB_CB (skb)->when =cookie_init_timestamp (req);
net/ipv6/tcp_ipv6.c +1 -0
@@ -1049,6 +1049,7 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)tcp_rsk (req)->af_specific = &tcp_request_sock_ipv6_ops;#endif + req->friend = skb->friend;tcp_clear_options (&tmp_opt); tmp_opt.mss_clamp =IPV6_MIN_MTU -sizeof (struct tcphdr ) -sizeof (struct ipv6hdr ); tmp_opt.user_mss = tp->rx_opt.user_mss;
Signature · 1 line
1.7.7.3
Quoted 6 lines · Bruce "Brutus" Curtis
From: "Bruce \"Brutus\" Curtis" <[email protected]>
TCP/IP loopback socket pair stack bypass, based on an idea by, and rough upstream patch from, David Miller <[email protected]> called "friends", the data structure modifcations and connection scheme are reused with extensive data-path changes.
...
net/ipv4/tcp_input.c static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, · line 5727
Quoted 10 lines
net/ipv4/tcp_input.c +9
-0+if (skb->friend) { +/* +* If friends haven't been made yet, our sk_friend +* still == NULL, then update with the ACK's friend +* value (the listen()er's sock addr) which is used +* as a place holder. +*/ +cmpxchg (&sk->sk_friend,NULL , skb->friend); + }
There is a fundamental issue with this patch
Setting skb->friend to a socket structure, without holding a reference on it is going to add subtle races and bugs.
In this code, we have no guarantee the socket pointed by skb->friend was eventually freed and/or reused.
But adding references might be overkill, as we need to unref them in some places, in hot path.
Quoted 25 lines · Eric Dumazet
Quoted 6 lines · Bruce "Brutus" Curtis
From: "Bruce \"Brutus\" Curtis" <[email protected]>
TCP/IP loopback socket pair stack bypass, based on an idea by, and rough upstream patch from, David Miller <[email protected]> called "friends", the data structure modifcations and connection scheme are reused with extensive data-path changes.
...
net/ipv4/tcp_input.c static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, · line 5727
Quoted 10 lines
net/ipv4/tcp_input.c +9
-0+if (skb->friend) { +/* +* If friends haven't been made yet, our sk_friend +* still == NULL, then update with the ACK's friend +* value (the listen()er's sock addr) which is used +* as a place holder. +*/ +cmpxchg (&sk->sk_friend,NULL , skb->friend); + }There is a fundamental issue with this patch
Quoted 8 lines
Setting
skb->friendto a socket structure, without holding a reference on it is going to add subtle races and bugs.In this code, we have no guarantee the socket pointed by
skb->friendwas eventually freed and/or reused.But adding references might be overkill, as we need to unref them in some places, in hot path.
Yes, this could be a problem, putting a hold on the sk would be overkill for the hot-path, working on it now, more soon.
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Mon, 17 Sep 2012 22:20:39 +0200
Quoted 24 lines · Bruce "Brutus" Curtis
Quoted 6 lines
From: "Bruce \"Brutus\" Curtis" <[email protected]>
TCP/IP loopback socket pair stack bypass, based on an idea by, and rough upstream patch from, David Miller <[email protected]> called "friends", the data structure modifcations and connection scheme are reused with extensive data-path changes.
...
net/ipv4/tcp_input.c static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, · line 5727
Quoted 10 lines
net/ipv4/tcp_input.c +9
-0+if (skb->friend) { +/* +* If friends haven't been made yet, our sk_friend +* still == NULL, then update with the ACK's friend +* value (the listen()er's sock addr) which is used +* as a place holder. +*/ +cmpxchg (&sk->sk_friend,NULL , skb->friend); + }There is a fundamental issue with this patch
Quoted 8 lines
Setting
skb->friendto a socket structure, without holding a reference on it is going to add subtle races and bugs.In this code, we have no guarantee the socket pointed by
skb->friendwas eventually freed and/or reused.But adding references might be overkill, as we need to unref them in some places, in hot path.
I have an idea on how to handle this.
In drivers/net/loopback.c:loopback_tx(), skip the SKB orphan operation if there is a friend socket at skb->friend.
When sending such friend SKBs out at connection startup, arrange it such that the skb->destructor will zap the skb->friend pointer to NULL.
Also, in skb_orphan*(), if necessary, set skb->friend to NULL.
skb->sk will hold a reference to the socket, and since skb->friend will be equal, this will make sure a pointer to an unreferenced socket does not escape.
Quoted 9 lines · David Miller
I have an idea on how to handle this.
In drivers/net/loopback.c:loopback_tx(), skip the SKB orphan operation if there is a friend socket at
skb->friend.When sending such friend SKBs out at connection startup, arrange it such that the
skb->destructorwill zap theskb->friendpointer to NULL.
Quoted 5 lines
Also, in skb_orphan*(), if necessary, set
skb->friendto NULL.
skb->skwill hold a reference to the socket, and sinceskb->friendwill be equal, this will make sure a pointer to an unreferenced socket does not escape.
I now am wondering if we still need skb->friend field.
If skb->sk is not zeroed by a premature skb_orphan(), then
skb->sk->sk_friend gives the friend ?
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Wed, 19 Sep 2012 23:03:54 +0200
Quoted 17 lines · David Miller
Quoted 10 lines
I have an idea on how to handle this.
In drivers/net/loopback.c:loopback_tx(), skip the SKB orphan operation if there is a friend socket at
skb->friend.When sending such friend SKBs out at connection startup, arrange it such that the
skb->destructorwill zap theskb->friendpointer to NULL.Quoted 5 lines
Also, in skb_orphan*(), if necessary, set
skb->friendto NULL.
skb->skwill hold a reference to the socket, and sinceskb->friendwill be equal, this will make sure a pointer to an unreferenced socket does not escape.
Quoted 5 lines
I now am wondering if we still need
skb->friendfield.If
skb->skis not zeroed by a prematureskb_orphan(), then
skb->sk->sk_friendgives the friend ?
Good point.
Quoted 18 lines · Eric Dumazet
Quoted 9 lines · David Miller
I have an idea on how to handle this.
In drivers/net/loopback.c:loopback_tx(), skip the SKB orphan operation if there is a friend socket at
skb->friend.When sending such friend SKBs out at connection startup, arrange it such that the
skb->destructorwill zap theskb->friendpointer to NULL.Quoted 5 lines
Also, in skb_orphan*(), if necessary, set
skb->friendto NULL.
skb->skwill hold a reference to the socket, and sinceskb->friendwill be equal, this will make sure a pointer to an unreferenced socket does not escape.
Quoted 7 lines
I now am wondering if we still need
skb->friendfield.If
skb->skis not zeroed by a prematureskb_orphan(), then
skb->sk->sk_friendgives the friend ?
Good question, in the friends data path it's only used to differentiate a friend directly Q'd skb so should work, I'll look into it.
Quoted 20 lines · Bruce Curtis
Quoted 18 lines · Eric Dumazet
Quoted 15 lines · David Miller
I have an idea on how to handle this.
In drivers/net/loopback.c:loopback_tx(), skip the SKB orphan operation if there is a friend socket at
skb->friend.When sending such friend SKBs out at connection startup, arrange it such that the
skb->destructorwill zap theskb->friendpointer to NULL.Also, in skb_orphan*(), if necessary, set
skb->friendto NULL.
skb->skwill hold a reference to the socket, and sinceskb->friendwill be equal, this will make sure a pointer to an unreferenced socket does not escape.
Quoted 8 lines
Quoted 8 lines
I now am wondering if we still need
skb->friendfield.If
skb->skis not zeroed by a prematureskb_orphan(), then
skb->sk->sk_friendgives the friend ?
Does this mean traffic on the loopback interface will not traverse netfilter?
Signature · 5 lines
"They that give up essential liberty to obtain temporary safety, deserve neither liberty nor safety." (Ben Franklin) "The course of history shows that as a government grows, liberty decreases." (Thomas Jefferson)
Quoted 4 lines · Stephen Clark
Does this mean traffic on the loopback interface will not traverse netfilter?
Yes this was already mentioned.
Only the SYN / SYNACK messages will
All data will bypass IP stack, qdisc (if any), loopback driver, and netfilter.
Quoted 6 lines · Eric Dumazet
Quoted 4 lines · Stephen Clark
Does this mean traffic on the loopback interface will not traverse netfilter?
Quoted 6 lines
Yes this was already mentioned.
Only the SYN / SYNACK messages will
All data will bypass IP stack, qdisc (if any), loopback driver, and netfilter.
Does that then lift the tent flap for TOE? As I recall, TOE's bypassing of all those things is one of the reasons used to reject TOE.
rick jones
David Miller
maintainerFrom: Rick Jones <[email protected]>
Date: Thu, 20 Sep 2012 10:24:36 -0700
Quoted 9 lines · Eric Dumazet
Quoted 8 lines · Stephen Clark
Quoted 4 lines
Does this mean traffic on the loopback interface will not traverse netfilter?
Yes this was already mentioned.
Quoted 8 lines
Quoted 4 lines
Only the SYN / SYNACK messages will
All data will bypass IP stack, qdisc (if any), loopback driver, and netfilter.
Does that then lift the tent flap for TOE? As I recall, TOE's bypassing of all those things is one of the reasons used to reject TOE.
Wrong. This bypassing is completely in software, and completely controlled by us.
Which is completely opposite to TOE.
Don't spread fud like this, even on a whim.
Quoted 6 lines · Eric Dumazet
Quoted 4 lines · Stephen Clark
Does this mean traffic on the loopback interface will not traverse netfilter?
Quoted 6 lines
Yes this was already mentioned.
Only the SYN / SYNACK messages will
All data will bypass IP stack, qdisc (if any), loopback driver, and netfilter.
These restrictions and any others should be documented in ip-sysctl.txt.
Quoted 1 line
From Eric's earlier e-mail:
-> no iptables,
no qdisc (by default there is no qdisc on lo),
no loopback stats (ifconfig lo).
some SNMP stats missing as well (netstat -s)
-Bill
David Miller
maintainerFrom: Stephen Clark <[email protected]>
Date: Thu, 20 Sep 2012 07:28:41 -0400
Quoted 2 lines
Does this mean traffic on the loopback interface will not traverse netfilter?
Please, we've had this discussion before, let's not have it again. Read the archives for the postings of the previous versions of this patch.