tcp: drop dst in tcp_add_backlog()
Subsystems (3)
PATCH 1/1 tcp: drop dst in tcp_add_backlog()
Under stress, softirq rx handler often hits a socket owned by the user, and has to queue the packet into socket backlog.
When this happens, skb dst refcount is taken before we escape rcu protected region. This is done from __sk_add_backlog() calling skb_dst_force().
Consumer will have to perform the opposite costly operation.
AFAIK nothing in tcp stack requests the dst after skb was stored in the backlog. If this was the case, we would have had failures already since skb_dst_force() can end up clearing skb dst anyway.
--- net/ipv4/tcp_ipv4.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv4/tcp_ipv4.c +2 -0
@@ -1634,6 +1634,8 @@ bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb)*/ skb_condense (skb); +skb_dst_drop (skb); +if (unlikely (sk_add_backlog (sk, skb, limit))) {bh_unlock_sock (sk);__NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPBACKLOGDROP );
Signature · 1 line
2.19.1.1215.g8438c0b245-goog
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Mon, 19 Nov 2018 17:45:55 -0800
Quoted 7 lines
Under stress, softirq rx handler often hits a socket owned by the user, and has to queue the packet into socket backlog.
When this happens, skb dst refcount is taken before we escape rcu protected region. This is done from
__sk_add_backlog()callingskb_dst_force().
Quoted 7 lines
Consumer will have to perform the opposite costly operation.
AFAIK nothing in tcp stack requests the dst after skb was stored in the backlog. If this was the case, we would have had failures already since
skb_dst_force()can end up clearing skb dst anyway.Signed-off-by Eric Dumazet <[email protected]>
Hmmm, it seems to be used by connection completion code to setup the socket cached rx dst, right?
For example tcp_finish_connect() --> icsk->icsk_af_ops->sk_rx_dst_set(sk, skb)
Quoted 17 lines · David Miller
From: Eric Dumazet <[email protected]>
Date: Mon, 19 Nov 2018 17:45:55 -0800Quoted 13 lines
Under stress, softirq rx handler often hits a socket owned by the user, and has to queue the packet into socket backlog.
When this happens, skb dst refcount is taken before we escape rcu protected region. This is done from
__sk_add_backlog()callingskb_dst_force().Consumer will have to perform the opposite costly operation.
AFAIK nothing in tcp stack requests the dst after skb was stored in the backlog. If this was the case, we would have had failures already since
skb_dst_force()can end up clearing skb dst anyway.
Quoted 6 lines
Quoted 1 line
Signed-off-by Eric Dumazet <[email protected]>Hmmm, it seems to be used by connection completion code to setup the socket cached rx dst, right?
For example
tcp_finish_connect()-->icsk->icsk_af_ops->sk_rx_dst_set(sk, skb)
We already cope with skb->dst being NULL there I believe.
For reference look at
commit 5037e9ef9454917b047f9f3a19b4dd179fbf7cd4 net: fix IP early demux races
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Tue, 20 Nov 2018 10:08:12 -0800
Quoted 23 lines · David Miller
Quoted 22 lines
From: Eric Dumazet <[email protected]>
Date: Mon, 19 Nov 2018 17:45:55 -0800Quoted 7 lines
Under stress, softirq rx handler often hits a socket owned by the user, and has to queue the packet into socket backlog.
When this happens, skb dst refcount is taken before we escape rcu protected region. This is done from
__sk_add_backlog()callingskb_dst_force().Quoted 7 lines
Consumer will have to perform the opposite costly operation.
AFAIK nothing in tcp stack requests the dst after skb was stored in the backlog. If this was the case, we would have had failures already since
skb_dst_force()can end up clearing skb dst anyway.Signed-off-by Eric Dumazet <[email protected]>Hmmm, it seems to be used by connection completion code to setup the socket cached rx dst, right?
Quoted 7 lines
Quoted 1 line
For example
tcp_finish_connect()-->icsk->icsk_af_ops->sk_rx_dst_set(sk, skb)We already cope with
skb->dstbeing NULL there I believe.For reference look at
commit
5037e9ef9454917b047f9f3a19b4dd179fbf7cd4net: fix IP early demux races
Well, I'm sure we "handle" it. But I was more asking about the performance tradeoff, which probably is on the side of your change but I wanted to just be sure.
Quoted 31 lines · David Miller
From: Eric Dumazet <[email protected]>
Date: Tue, 20 Nov 2018 10:08:12 -0800Quoted 27 lines · David Miller
Quoted 17 lines
From: Eric Dumazet <[email protected]>
Date: Mon, 19 Nov 2018 17:45:55 -0800Quoted 13 lines
Under stress, softirq rx handler often hits a socket owned by the user, and has to queue the packet into socket backlog.
When this happens, skb dst refcount is taken before we escape rcu protected region. This is done from
__sk_add_backlog()callingskb_dst_force().Consumer will have to perform the opposite costly operation.
AFAIK nothing in tcp stack requests the dst after skb was stored in the backlog. If this was the case, we would have had failures already since
skb_dst_force()can end up clearing skb dst anyway.Quoted 6 lines
Quoted 1 line
Signed-off-by Eric Dumazet <[email protected]>Hmmm, it seems to be used by connection completion code to setup the socket cached rx dst, right?
For example
tcp_finish_connect()-->icsk->icsk_af_ops->sk_rx_dst_set(sk, skb)We already cope with
skb->dstbeing NULL there I believe.
Quoted 7 lines
Quoted 3 lines
For reference look at
commit
5037e9ef9454917b047f9f3a19b4dd179fbf7cd4net: fix IP early demux racesWell, I'm sure we "handle" it. But I was more asking about the performance tradeoff, which probably is on the side of your change but I wanted to just be sure.
Ah sorry for misunderstanding.
Yes, that should be fine, backlog is not generally used at the beginning of a flow.
I am working on adding coalescing support to tcp_add_backlog() to balance time spent in softirq and time spent from process context, hoping to reduce probability of having user threads trapped for a while in __release_sock()
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Tue, 20 Nov 2018 10:21:22 -0800
Quoted 6 lines · David Miller
Quoted 4 lines
Well, I'm sure we "handle" it. But I was more asking about the performance tradeoff, which probably is on the side of your change but I wanted to just be sure.
Quoted 7 lines
Ah sorry for misunderstanding.
Yes, that should be fine, backlog is not generally used at the beginning of a flow.I am working on adding coalescing support to
tcp_add_backlog()to balance time spent in softirq and time spent from process context, hoping to reduce probability of having user threads trapped for a while in__release_sock()
Ok, meanwhile I applied the patch under discussion.
Thanks.