Skip to contentSkip to conversation

tcp: drop dst in tcp_add_backlog()

PATCH In review Eric Dumazet 2 participants 6 messages Nov 20, 2018 – Nov 21, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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
index 0952d4b772e7aa3cfb936596aa586dbd2dd6efde..795605a2327504b8a025405826e7e0ca8dc8501d 100644
@@ -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
maintainer
#1 lore raw

From: 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() calling skb_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.

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)

#2 lore raw
Quoted 17 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Mon, 19 Nov 2018 17:45:55 -0800

Quoted 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() 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.

Quoted 6 lines
Quoted 1 line

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

maintainer
#3 lore raw

From: 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 -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() calling skb_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.

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->dst being NULL there I believe.

For reference look at

commit 5037e9ef9454917b047f9f3a19b4dd179fbf7cd4 net: 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.

#4 lore raw
Quoted 31 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Tue, 20 Nov 2018 10:08:12 -0800

Quoted 27 lines · David Miller
Quoted 17 lines

From: Eric Dumazet <[email protected]>
Date: Mon, 19 Nov 2018 17:45:55 -0800

Quoted 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() 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.

Quoted 6 lines
Quoted 1 line

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.

Quoted 7 lines
Quoted 3 lines

For reference look at

commit 5037e9ef9454917b047f9f3a19b4dd179fbf7cd4 net: 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.

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()

maintainer
#5 lore raw

From: 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.