ipv6: tcp: no longer rebuild fl6 at each transmit
Subsystems (3)
cover ipv6: tcp: no longer rebuild fl6 at each transmit
TCP v6 spends a good amount of time rebuilding a fresh fl6 at each transmit in inet6_csk_xmit()/inet6_csk_route_socket().
TCP v4 caches the information in inet->cork.fl.u.ip4 instead.
This series changes TCP v6 to behave the same, saving cpu cycles and reducing cache line misses and stack use.
Eric Dumazet (7):
ipv6: add daddr/final storage in struct ipv6_pinfo
ipv6: use np->final in inet6_sk_rebuild_header()
ipv6: use inet->cork.fl.u.ip6 and np->final in
ip6_datagram_dst_update()
ipv6: inet6_csk_xmit() and inet6_csk_update_pmtu() use
inet->cork.fl.u.ip6
tcp: populate inet->cork.fl.u.ip6 in tcp_v6_connect()
tcp: populate inet->cork.fl.u.ip6 in tcp_v6_syn_recv_sock()
tcp: inet6_csk_xmit() optimization
include/linux/ipv6.h | 4 ++ include/net/inet6_connection_sock.h | 4 +- net/ipv6/af_inet6.c | 4 +- net/ipv6/datagram.c | 21 +++++----- net/ipv6/inet6_connection_sock.c | 57 +++++++++++++------------ net/ipv6/tcp_ipv6.c | 64 ++++++++++++++--------------- 6 files changed, 82 insertions(+), 72 deletions(-)
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
PATCH 1/7 ipv6: add daddr/final storage in struct ipv6_pinfo
After commit b409a7f7176b ("ipv6: colocate inet6_cork in inet_cork_full") we have room in ipv6_pinfo to hold daddr/final in case they need to be populated in fl6_update_dst() calls.
This will allow stack canary removal in IPv6 tx fast paths.
--- include/linux/ipv6.h | 4 ++++ 1 file changed, 4 insertions(+)
include/linux/ipv6.h +4 -0
@@ -209,6 +209,10 @@ struct ipv6_fl_socklist;struct ipv6_pinfo {/* Used in tx path (inet6_csk_route_socket(), ip6_xmit()) */ struct in6_addr saddr; +union { +struct in6_addr daddr; +struct in6_addr final; + };__be32 flow_label;u32 dst_cookie;struct ipv6_txoptions __rcu *opt;
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
Re: [PATCH net-next 1/7] ipv6: add daddr/final storage in struct ipv6_pinfo
Quoted 8 lines · Eric Dumazet
After commit
b409a7f7176b("ipv6: colocateinet6_corkininet_cork_full") we have room inipv6_pinfoto hold daddr/final in case they need to be populated infl6_update_dst()calls.This will allow stack canary removal in IPv6 tx fast paths.
Signed-off-by Eric Dumazet <[email protected]>
PATCH 2/7 ipv6: use np->final in inet6_sk_rebuild_header()
In reply to Eric DumazetInstead of using an automatic variable, use np->final to get rid of the stack canary in inet6_sk_rebuild_header().
--- net/ipv6/af_inet6.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv6/af_inet6.c +2 -2
@@ -825,7 +825,7 @@ int inet6_sk_rebuild_header(struct sock *sk) {struct ipv6_pinfo *np =inet6_sk (sk);struct inet_sock *inet =inet_sk (sk); -struct in6_addr *final_p, final; +struct in6_addr *final_p;struct dst_entry *dst;struct flowi6 *fl6;
@@ -847,7 +847,7 @@ int inet6_sk_rebuild_header(struct sock *sk)security_sk_classify_flow (sk,flowi6_to_flowi_common (fl6));rcu_read_lock (); - final_p =fl6_update_dst (fl6,rcu_dereference (np->opt), &final); + final_p =fl6_update_dst (fl6,rcu_dereference (np->opt), &np->final);rcu_read_unlock (); dst =ip6_dst_lookup_flow (sock_net (sk), sk, fl6, final_p);
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
Re: [PATCH net-next 2/7] ipv6: use np->final in inet6_sk_rebuild_header()
Quoted 5 lines · Eric Dumazet
Instead of using an automatic variable, use
np->finalto get rid of the stack canary ininet6_sk_rebuild_header().Signed-off-by Eric Dumazet <[email protected]>
PATCH 3/7 ipv6: use inet->cork.fl.u.ip6 and np->final in ip6_datagram_dst_update()
In reply to Eric DumazetGet rid of @fl6 and &final variables in ip6_datagram_dst_update().
Use instead inet->cork.fl.u.ip6 and np->final so that a stack canary is no longer needed.
--- net/ipv6/datagram.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
net/ipv6/datagram.c +11 -10
@@ -72,12 +72,12 @@ static void ip6_datagram_flow_key_init(struct flowi6 *fl6,int ip6_datagram_dst_update (struct sock *sk,bool fix_sk_saddr) {struct ip6_flowlabel *flowlabel =NULL ; -struct in6_addr *final_p, final; -struct ipv6_txoptions *opt; -struct dst_entry *dst;struct inet_sock *inet =inet_sk (sk);struct ipv6_pinfo *np =inet6_sk (sk); -struct flowi6 fl6; +struct ipv6_txoptions *opt; +struct in6_addr *final_p; +struct dst_entry *dst; +struct flowi6 *fl6;int err =0 ; if (inet6_test_bit(SNDFLOW, sk) &&
@@ -86,14 +86,15 @@ int ip6_datagram_dst_update(struct sock *sk, bool fix_sk_saddr)if (IS_ERR (flowlabel))return -EINVAL ; } -ip6_datagram_flow_key_init (&fl6, sk); + fl6 = &inet_sk (sk)->cork.fl.u.ip6; +ip6_datagram_flow_key_init (fl6, sk);rcu_read_lock (); opt = flowlabel ? flowlabel->opt :rcu_dereference (np->opt); - final_p =fl6_update_dst (&fl6, opt, &final); + final_p =fl6_update_dst (fl6, opt, &np->final);rcu_read_unlock (); - dst =ip6_dst_lookup_flow (sock_net (sk), sk, &fl6, final_p); + dst =ip6_dst_lookup_flow (sock_net (sk), sk, fl6, final_p);if (IS_ERR (dst)) { err =PTR_ERR (dst); goto out;
@@ -101,17 +102,17 @@ int ip6_datagram_dst_update(struct sock *sk, bool fix_sk_saddr)if (fix_sk_saddr) {if (ipv6_addr_any (&np->saddr)) - np->saddr = fl6.saddr; + np->saddr = fl6->saddr;if (ipv6_addr_any (&sk->sk_v6_rcv_saddr)) { - sk->sk_v6_rcv_saddr = fl6.saddr; + sk->sk_v6_rcv_saddr = fl6->saddr; inet->inet_rcv_saddr =LOOPBACK4_IPV6 ;if (sk->sk_prot->rehash) sk->sk_prot->rehash (sk); } } -ip6_sk_dst_store_flow (sk, dst, &fl6); +ip6_sk_dst_store_flow (sk, dst, fl6); out:fl6_sock_release (flowlabel);
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
Re: [PATCH net-next 3/7] ipv6: use inet->cork.fl.u.ip6 and np->final in ip6_datagram_dst_update()
Quoted 7 lines · Eric Dumazet
Get rid of @fl6 and &final variables in
ip6_datagram_dst_update().Use instead
inet->cork.fl.u.ip6andnp->finalso that a stack canary is no longer needed.Signed-off-by Eric Dumazet <[email protected]>
PATCH 4/7 ipv6: inet6_csk_xmit() and inet6_csk_update_pmtu() use inet->cork.fl.u.ip6
In reply to Eric DumazetConvert inet6_csk_route_socket() to use np->final instead of an automatic variable to get rid of a stack canary.
Convert inet6_csk_xmit() and inet6_csk_update_pmtu() to use inet->cork.fl.u.ip6 instead of @fl6 automatic variable.
--- net/ipv6/inet6_connection_sock.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
net/ipv6/inet6_connection_sock.c +11 -9
@@ -60,7 +60,7 @@ static struct dst_entry *inet6_csk_route_socket(struct sock *sk, {struct inet_sock *inet =inet_sk (sk);struct ipv6_pinfo *np =inet6_sk (sk); -struct in6_addr *final_p, final; +struct in6_addr *final_p;struct dst_entry *dst;memset (fl6,0 ,sizeof (*fl6));
@@ -77,7 +77,7 @@ static struct dst_entry *inet6_csk_route_socket(struct sock *sk,security_sk_classify_flow (sk,flowi6_to_flowi_common (fl6));rcu_read_lock (); - final_p =fl6_update_dst (fl6,rcu_dereference (np->opt), &final); + final_p =fl6_update_dst (fl6,rcu_dereference (np->opt), &np->final);rcu_read_unlock (); dst =__sk_dst_check (sk, np->dst_cookie);
@@ -92,12 +92,12 @@ static struct dst_entry *inet6_csk_route_socket(struct sock *sk,int inet6_csk_xmit (struct sock *sk,struct sk_buff *skb,struct flowi *fl_unused) { +struct flowi6 *fl6 = &inet_sk (sk)->cork.fl.u.ip6;struct ipv6_pinfo *np =inet6_sk (sk); -struct flowi6 fl6;struct dst_entry *dst;int res; - dst =inet6_csk_route_socket (sk, &fl6); + dst =inet6_csk_route_socket (sk, fl6);if (IS_ERR (dst)) {WRITE_ONCE (sk->sk_err_soft, -PTR_ERR (dst)); sk->sk_route_caps =0 ;
@@ -109,9 +109,9 @@ int inet6_csk_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl_unusedskb_dst_set_noref (skb, dst);/* Restore final destination back after routing done */ - fl6.daddr = sk->sk_v6_daddr; + fl6->daddr = sk->sk_v6_daddr; - res =ip6_xmit (sk, skb, &fl6, sk->sk_mark,rcu_dereference (np->opt), + res =ip6_xmit (sk, skb, fl6, sk->sk_mark,rcu_dereference (np->opt), np->tclass,READ_ONCE (sk->sk_priority));rcu_read_unlock ();return res;
@@ -120,13 +120,15 @@ EXPORT_SYMBOL_GPL(inet6_csk_xmit);struct dst_entry *inet6_csk_update_pmtu (struct sock *sk,u32 mtu) { -struct flowi6 fl6; -struct dst_entry *dst =inet6_csk_route_socket (sk, &fl6); +struct flowi6 *fl6 = &inet_sk (sk)->cork.fl.u.ip6; +struct dst_entry *dst; + + dst =inet6_csk_route_socket (sk, fl6);if (IS_ERR (dst))return NULL ; dst->ops->update_pmtu (dst, sk,NULL , mtu, true); - dst =inet6_csk_route_socket (sk, &fl6); + dst =inet6_csk_route_socket (sk, fl6);return IS_ERR (dst) ?NULL : dst; }
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
Re: [PATCH net-next 4/7] ipv6: inet6_csk_xmit() and inet6_csk_update_pmtu() use inet->cork.fl.u.ip6
Quoted 8 lines · Eric Dumazet
Convert
inet6_csk_route_socket()to usenp->finalinstead of an automatic variable to get rid of a stack canary.Convert
inet6_csk_xmit()andinet6_csk_update_pmtu()to useinet->cork.fl.u.ip6instead of @fl6 automatic variable.Signed-off-by Eric Dumazet <[email protected]>
PATCH 5/7 tcp: populate inet->cork.fl.u.ip6 in tcp_v6_connect()
In reply to Eric DumazetInstead of using private @fl6 and @final variables use respectively inet->cork.fl.u.ip6 and np->final.
As explained in commit 85d05e281712 ("ipv6: change inet6_sk_rebuild_header() to use inet->cork.fl.u.ip6"):
TCP v6 spends a good amount of time rebuilding a fresh fl6 at each transmit in inet6_csk_xmit()/inet6_csk_route_socket().
TCP v4 caches the information in inet->cork.fl.u.ip4 instead.
After this patch, active TCP ipv6 flows have correctly initialized inet->cork.fl.u.ip6 structure.
--- net/ipv6/tcp_ipv6.c | 47 +++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 23 deletions(-)
net/ipv6/tcp_ipv6.c +24 -23
@@ -138,15 +138,15 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr, {struct sockaddr_in6 *usin = (struct sockaddr_in6 *) uaddr;struct inet_connection_sock *icsk =inet_csk (sk); -struct in6_addr *saddr =NULL , *final_p, final;struct inet_timewait_death_row *tcp_death_row;struct ipv6_pinfo *np =tcp_inet6_sk (sk); +struct in6_addr *saddr =NULL , *final_p;struct inet_sock *inet =inet_sk (sk);struct tcp_sock *tp =tcp_sk (sk);struct net *net =sock_net (sk);struct ipv6_txoptions *opt;struct dst_entry *dst; -struct flowi6 fl6; +struct flowi6 *fl6;int addr_type;int err;
@@ -156,14 +156,15 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr,if (usin->sin6_family !=AF_INET6 )return -EAFNOSUPPORT ; -memset (&fl6,0 ,sizeof (fl6)); + fl6 = &inet_sk (sk)->cork.fl.u.ip6; +memset (fl6,0 ,sizeof (*fl6));if (inet6_test_bit (SNDFLOW , sk)) { - fl6.flowlabel = usin->sin6_flowinfo&IPV6_FLOWINFO_MASK ; -IP6_ECN_flow_init (fl6.flowlabel); -if (fl6.flowlabel&IPV6_FLOWLABEL_MASK ) { + fl6->flowlabel = usin->sin6_flowinfo &IPV6_FLOWINFO_MASK ; +IP6_ECN_flow_init (fl6->flowlabel); +if (fl6->flowlabel &IPV6_FLOWLABEL_MASK ) {struct ip6_flowlabel *flowlabel; - flowlabel =fl6_sock_lookup (sk, fl6.flowlabel); + flowlabel =fl6_sock_lookup (sk, fl6->flowlabel);if (IS_ERR (flowlabel))return -EINVAL ;fl6_sock_release (flowlabel);
@@ -212,7 +213,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr, } sk->sk_v6_daddr = usin->sin6_addr; - np->flow_label = fl6.flowlabel; + np->flow_label = fl6->flowlabel;/* * TCP over IPv4
@@ -260,24 +261,24 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr,if (!ipv6_addr_any (&sk->sk_v6_rcv_saddr)) saddr = &sk->sk_v6_rcv_saddr; - fl6.flowi6_proto =IPPROTO_TCP ; - fl6.daddr = sk->sk_v6_daddr; - fl6.saddr = saddr ? *saddr : np->saddr; - fl6.flowlabel =ip6_make_flowinfo (np->tclass, np->flow_label); - fl6.flowi6_oif = sk->sk_bound_dev_if; - fl6.flowi6_mark = sk->sk_mark; - fl6.fl6_dport = usin->sin6_port; - fl6.fl6_sport = inet->inet_sport; -if (IS_ENABLED (CONFIG_IP_ROUTE_MULTIPATH ) && !fl6.fl6_sport) - fl6.flowi6_flags =FLOWI_FLAG_ANY_SPORT ; - fl6.flowi6_uid =sk_uid (sk); + fl6->flowi6_proto =IPPROTO_TCP ; + fl6->daddr = sk->sk_v6_daddr; + fl6->saddr = saddr ? *saddr : np->saddr; + fl6->flowlabel =ip6_make_flowinfo (np->tclass, np->flow_label); + fl6->flowi6_oif = sk->sk_bound_dev_if; + fl6->flowi6_mark = sk->sk_mark; + fl6->fl6_dport = usin->sin6_port; + fl6->fl6_sport = inet->inet_sport; +if (IS_ENABLED (CONFIG_IP_ROUTE_MULTIPATH ) && !fl6->fl6_sport) + fl6->flowi6_flags =FLOWI_FLAG_ANY_SPORT ; + fl6->flowi6_uid =sk_uid (sk); opt =rcu_dereference_protected (np->opt,lockdep_sock_is_held (sk)); - final_p =fl6_update_dst (&fl6, opt, &final); + final_p =fl6_update_dst (fl6, opt, &np->final); -security_sk_classify_flow (sk,flowi6_to_flowi_common (&fl6)); +security_sk_classify_flow (sk,flowi6_to_flowi_common (fl6)); - dst =ip6_dst_lookup_flow (net, sk, &fl6, final_p); + dst =ip6_dst_lookup_flow (net, sk, fl6, final_p);if (IS_ERR (dst)) { err =PTR_ERR (dst); goto failure;
@@ -287,7 +288,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr, tcp_death_row = &sock_net (sk)->ipv4.tcp_death_row;if (!saddr) { - saddr = &fl6.saddr; + saddr = &fl6->saddr; err =inet_bhash2_update_saddr (sk, saddr,AF_INET6 );if (err)
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
Re: [PATCH net-next 5/7] tcp: populate inet->cork.fl.u.ip6 in tcp_v6_connect()
Quoted 10 lines · Eric Dumazet
Instead of using private @fl6 and @final variables use respectively
inet->cork.fl.u.ip6andnp->final.As explained in commit
85d05e281712("ipv6: changeinet6_sk_rebuild_header()to useinet->cork.fl.u.ip6"):TCP v6 spends a good amount of time rebuilding a fresh fl6 at each transmit in inet6_csk_xmit()/inet6_csk_route_socket().
Quoted 6 lines
TCP v4 caches the information in
inet->cork.fl.u.ip4instead.After this patch, active TCP ipv6 flows have correctly initialized
inet->cork.fl.u.ip6structure.Signed-off-by Eric Dumazet <[email protected]>
PATCH 6/7 tcp: populate inet->cork.fl.u.ip6 in tcp_v6_syn_recv_sock()
In reply to Eric DumazetAs explained in commit 85d05e281712 ("ipv6: change inet6_sk_rebuild_header() to use inet->cork.fl.u.ip6"):
TCP v6 spends a good amount of time rebuilding a fresh fl6 at each transmit in inet6_csk_xmit()/inet6_csk_route_socket().
TCP v4 caches the information in inet->cork.fl.u.ip4 instead.
After this patch, passive TCP ipv6 flows have correctly initialized inet->cork.fl.u.ip6 structure.
--- include/net/inet6_connection_sock.h | 4 +++- net/ipv6/inet6_connection_sock.c | 11 ++++++----- net/ipv6/tcp_ipv6.c | 17 ++++++++--------- 3 files changed, 17 insertions(+), 15 deletions(-)
include/net/inet6_connection_sock.h +3 -1
@@ -18,7 +18,9 @@ struct sk_buff;struct sock ;struct sockaddr ; -struct dst_entry *inet6_csk_route_req (const struct sock *sk,struct flowi6 *fl6, +struct dst_entry *inet6_csk_route_req (const struct sock *sk, +struct dst_entry *dst, +struct flowi6 *fl6,const struct request_sock *req,u8 proto);int inet6_csk_xmit (struct sock *sk,struct sk_buff *skb,struct flowi *fl);
net/ipv6/inet6_connection_sock.c +6 -5
@@ -25,6 +25,7 @@#include <net/sock_reuseport.h> struct dst_entry *inet6_csk_route_req (const struct sock *sk, +struct dst_entry *dst,struct flowi6 *fl6,const struct request_sock *req,u8 proto)
@@ -32,7 +33,6 @@ struct dst_entry *inet6_csk_route_req(const struct sock *sk,const struct inet_request_sock *ireq =inet_rsk (req);const struct ipv6_pinfo *np =inet6_sk (sk);struct in6_addr *final_p, final; -struct dst_entry *dst;memset (fl6,0 ,sizeof (*fl6)); fl6->flowi6_proto = proto;
@@ -48,10 +48,11 @@ struct dst_entry *inet6_csk_route_req(const struct sock *sk, fl6->flowi6_uid =sk_uid (sk);security_req_classify_flow (req,flowi6_to_flowi_common (fl6)); - dst =ip6_dst_lookup_flow (sock_net (sk), sk, fl6, final_p); -if (IS_ERR (dst)) -return NULL ; - +if (!dst) { + dst =ip6_dst_lookup_flow (sock_net (sk), sk, fl6, final_p); +if (IS_ERR (dst)) +return NULL ; + }return dst; }
net/ipv6/tcp_ipv6.c +8 -9
@@ -539,7 +539,7 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,u8 tclass;/* First, grab a route. */ -if (!dst && (dst =inet6_csk_route_req (sk, fl6, req, +if (!dst && (dst =inet6_csk_route_req (sk,NULL , fl6, req,IPPROTO_TCP )) ==NULL ) goto done;
@@ -789,7 +789,7 @@ static struct dst_entry *tcp_v6_route_req(const struct sock *sk,if (security_inet_conn_request (sk, skb, req))return NULL ; -return inet6_csk_route_req (sk, &fl->u.ip6, req,IPPROTO_TCP ); +return inet6_csk_route_req (sk,NULL , &fl->u.ip6, req,IPPROTO_TCP ); }struct request_sock_ops tcp6_request_sock_ops__read_mostly = {
@@ -1318,12 +1318,12 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *struct request_sock *req_unhash, bool *own_req) { - struct inet_request_sock *ireq; -struct ipv6_pinfo *newnp; const struct ipv6_pinfo *np = tcp_inet6_sk(sk); +struct inet_request_sock *ireq;struct ipv6_txoptions *opt;struct inet_sock *newinet;bool found_dup_sk = false; +struct ipv6_pinfo *newnp;struct tcp_sock *newtp;struct sock *newsk;#ifdef CONFIG_TCP_MD5SIG
@@ -1392,11 +1392,9 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *if (sk_acceptq_is_full (sk)) goto exit_overflow; -if (!dst) { - dst =inet6_csk_route_req (sk, &fl6, req,IPPROTO_TCP ); -if (!dst) - goto exit; - } + dst =inet6_csk_route_req (sk, dst, &fl6, req,IPPROTO_TCP ); +if (!dst) + goto exit; newsk =tcp_create_openreq_child (sk, req, skb);if (!newsk)
@@ -1412,6 +1410,7 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *inet6_sk_rx_dst_set (newsk, skb); newinet =inet_sk (newsk); + newinet->cork.fl.u.ip6 = fl6; newinet->pinet6 =tcp_inet6_sk (newsk); newinet->ipv6_fl_list =NULL ; newinet->inet_opt =NULL ;
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
Re: [PATCH net-next 6/7] tcp: populate inet->cork.fl.u.ip6 in tcp_v6_syn_recv_sock()
Quoted 7 lines · Eric Dumazet
As explained in commit
85d05e281712("ipv6: changeinet6_sk_rebuild_header()to useinet->cork.fl.u.ip6"):TCP v6 spends a good amount of time rebuilding a fresh fl6 at each transmit in inet6_csk_xmit()/inet6_csk_route_socket().
Quoted 6 lines
TCP v4 caches the information in
inet->cork.fl.u.ip4instead.After this patch, passive TCP ipv6 flows have correctly initialized
inet->cork.fl.u.ip6structure.Signed-off-by Eric Dumazet <[email protected]>
PATCH 7/7 tcp: inet6_csk_xmit() optimization
In reply to Eric DumazetAfter prior patches, inet6_csk_xmit() can reuse inet->cork.fl.u.ip6 if __sk_dst_check() returns a valid dst.
Otherwise call inet6_csk_route_socket() to refresh inet->cork.fl.u.ip6 content and get a new dst.
--- net/ipv6/inet6_connection_sock.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
net/ipv6/inet6_connection_sock.c +15 -15
@@ -81,13 +81,11 @@ static struct dst_entry *inet6_csk_route_socket(struct sock *sk, final_p =fl6_update_dst (fl6,rcu_dereference (np->opt), &np->final);rcu_read_unlock (); - dst =__sk_dst_check (sk, np->dst_cookie); -if (!dst) { - dst =ip6_dst_lookup_flow (sock_net (sk), sk, fl6, final_p); + dst =ip6_dst_lookup_flow (sock_net (sk), sk, fl6, final_p); + +if (!IS_ERR (dst)) +ip6_dst_store (sk, dst, false, false); -if (!IS_ERR (dst)) -ip6_dst_store (sk, dst, false, false); - }return dst; }
@@ -98,20 +96,22 @@ int inet6_csk_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl_unusedstruct dst_entry *dst;int res; - dst =inet6_csk_route_socket (sk, fl6); -if (IS_ERR (dst)) { -WRITE_ONCE (sk->sk_err_soft, -PTR_ERR (dst)); - sk->sk_route_caps =0 ; -kfree_skb (skb); -return PTR_ERR (dst); + dst =__sk_dst_check (sk, np->dst_cookie); +if (unlikely (!dst)) { + dst =inet6_csk_route_socket (sk, fl6); +if (IS_ERR (dst)) { +WRITE_ONCE (sk->sk_err_soft, -PTR_ERR (dst)); + sk->sk_route_caps =0 ; +kfree_skb (skb); +return PTR_ERR (dst); + } +/* Restore final destination back after routing done */ + fl6->daddr = sk->sk_v6_daddr; }rcu_read_lock ();skb_dst_set_noref (skb, dst); -/* Restore final destination back after routing done */ - fl6->daddr = sk->sk_v6_daddr; - res =ip6_xmit (sk, skb, fl6, sk->sk_mark,rcu_dereference (np->opt), np->tclass,READ_ONCE (sk->sk_priority));rcu_read_unlock ();
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
Re: [PATCH net-next 7/7] tcp: inet6_csk_xmit() optimization
Quoted 8 lines · Eric Dumazet
After prior patches,
inet6_csk_xmit()can reuseinet->cork.fl.u.ip6if__sk_dst_check()returns a valid dst.Otherwise call
inet6_csk_route_socket()to refreshinet->cork.fl.u.ip6content and get a new dst.Signed-off-by Eric Dumazet <[email protected]>
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Fri, 6 Feb 2026 17:34:19 +0000 you wrote:
TCP v6 spends a good amount of time rebuilding a fresh fl6 at each transmit in inet6_csk_xmit()/inet6_csk_route_socket().
TCP v4 caches the information in
inet->cork.fl.u.ip4instead.This series changes TCP v6 to behave the same, saving cpu cycles and reducing cache line misses and stack use.
[...]
Here is the summary with links:
- [net-next,1/7] ipv6: add daddr/final storage in struct ipv6_pinfo
https://git.kernel.org/netdev/net-next/c/03ff0cb1a926 - [net-next,2/7] ipv6: use np->final in inet6_sk_rebuild_header() https://git.kernel.org/netdev/net-next/c/3d3f075e80f2 - [net-next,3/7] ipv6: use inet->cork.fl.u.ip6 and np->final in ip6_datagram_dst_update() https://git.kernel.org/netdev/net-next/c/4e6c91cf60f2 - [net-next,4/7] ipv6: inet6_csk_xmit() and inet6_csk_update_pmtu() use inet->cork.fl.u.ip6 https://git.kernel.org/netdev/net-next/c/969a20198bd6 - [net-next,5/7] tcp: populate inet->cork.fl.u.ip6 in tcp_v6_connect() https://git.kernel.org/netdev/net-next/c/19bdb267f733 - [net-next,6/7] tcp: populate inet->cork.fl.u.ip6 in tcp_v6_syn_recv_sock() https://git.kernel.org/netdev/net-next/c/a6eee39cc2b9 - [net-next,7/7] tcp: inet6_csk_xmit() optimization https://git.kernel.org/netdev/net-next/c/97d7ae6e14c8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html