public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Marek Mietus <mmietus97@yahoo.com>
To: netdev@vger.kernel.org, sd@queasysnail.net, kuba@kernel.org,
	pabeni@redhat.com
Cc: Jason@zx2c4.com, Marek Mietus <mmietus97@yahoo.com>
Subject: [PATCH net-next v8 10/11] net: sit: convert ipip6_tunnel_xmit to use a noref dst
Date: Thu, 12 Mar 2026 16:56:56 +0100	[thread overview]
Message-ID: <20260312155657.25676-11-mmietus97@yahoo.com> (raw)
In-Reply-To: <20260312155657.25676-1-mmietus97@yahoo.com>

ipip6_tunnel_xmit unnecessarily references the dst_entry from the
dst_cache when interacting with the cache.

Reduce this overhead by avoiding the redundant refcount increments.

This change is safe since ipv4 supports noref xmit under RCU which is
already the case for ipip6_tunnel_xmit.

Signed-off-by: Marek Mietus <mmietus97@yahoo.com>
---
 net/ipv6/sit.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 34d4d72dc58a..2dd43d472e5d 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -934,31 +934,28 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
 			   IPPROTO_IPV6, 0, dst, tiph->saddr, 0, 0,
 			   sock_net_uid(tunnel->net, NULL));
 
-	rt = dst_cache_get_ip4(&tunnel->dst_cache, &fl4.saddr);
+	rt = dst_cache_get_ip4_rcu(&tunnel->dst_cache, &fl4.saddr);
 	if (!rt) {
 		rt = ip_route_output_flow(tunnel->net, &fl4, NULL);
 		if (IS_ERR(rt)) {
 			DEV_STATS_INC(dev, tx_carrier_errors);
 			goto tx_error_icmp;
 		}
-		dst_cache_set_ip4(&tunnel->dst_cache, &rt->dst, fl4.saddr);
+		dst_cache_steal_ip4(&tunnel->dst_cache, &rt->dst, fl4.saddr);
 	}
 
 	if (rt->rt_type != RTN_UNICAST && rt->rt_type != RTN_LOCAL) {
-		ip_rt_put(rt);
 		DEV_STATS_INC(dev, tx_carrier_errors);
 		goto tx_error_icmp;
 	}
 	tdev = rt->dst.dev;
 
 	if (tdev == dev) {
-		ip_rt_put(rt);
 		DEV_STATS_INC(dev, collisions);
 		goto tx_error;
 	}
 
 	if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP4)) {
-		ip_rt_put(rt);
 		goto tx_error;
 	}
 
@@ -967,7 +964,6 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
 
 		if (mtu < IPV4_MIN_MTU) {
 			DEV_STATS_INC(dev, collisions);
-			ip_rt_put(rt);
 			goto tx_error;
 		}
 
@@ -981,7 +977,6 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
 
 		if (skb->len > mtu && !skb_is_gso(skb)) {
 			icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
-			ip_rt_put(rt);
 			goto tx_error;
 		}
 	}
@@ -1004,7 +999,6 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
 	    (skb_cloned(skb) && !skb_clone_writable(skb, 0))) {
 		struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
 		if (!new_skb) {
-			ip_rt_put(rt);
 			DEV_STATS_INC(dev, tx_dropped);
 			kfree_skb(skb);
 			return NETDEV_TX_OK;
@@ -1020,16 +1014,13 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
 		ttl = iph6->hop_limit;
 	tos = INET_ECN_encapsulate(tos, ipv6_get_dsfield(iph6));
 
-	if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4) < 0) {
-		ip_rt_put(rt);
+	if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4) < 0)
 		goto tx_error;
-	}
 
 	skb_set_inner_ipproto(skb, IPPROTO_IPV6);
 
 	iptunnel_xmit(NULL, rt, skb, fl4.saddr, fl4.daddr, protocol, tos, ttl,
 		      df, !net_eq(tunnel->net, dev_net(dev)), 0);
-	ip_rt_put(rt);
 	return NETDEV_TX_OK;
 
 tx_error_icmp:
-- 
2.51.0


  parent reply	other threads:[~2026-03-12 16:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260312155657.25676-1-mmietus97.ref@yahoo.com>
2026-03-12 15:56 ` [PATCH net-next v8 00/11] net: tunnel: introduce noref xmit flows for tunnels Marek Mietus
2026-03-12 15:56   ` [PATCH net-next v8 01/11] net: dst_cache: add noref versions for dst_cache Marek Mietus
2026-03-12 15:56   ` [PATCH net-next v8 02/11] net: tunnel: convert iptunnel_xmit to noref Marek Mietus
2026-03-12 15:56   ` [PATCH net-next v8 03/11] net: tunnel: convert udp_tunnel{6,}_xmit_skb " Marek Mietus
2026-03-12 15:56   ` [PATCH net-next v8 04/11] net: tunnel: return noref dsts in udp_tunnel{,6}_dst_lookup Marek Mietus
2026-03-12 15:56   ` [PATCH net-next v8 05/11] net: ovpn: convert ovpn_udp{4,6}_output to use a noref dst Marek Mietus
2026-03-12 15:56   ` [PATCH net-next v8 06/11] wireguard: socket: convert send{4,6} to use a noref dst when possible Marek Mietus
2026-03-12 15:56   ` [PATCH net-next v8 07/11] net: tunnel: convert ip_md_tunnel_xmit to use noref dsts Marek Mietus
2026-03-12 15:56   ` [PATCH net-next v8 08/11] net: tunnel: convert ip_tunnel_xmit to use a noref dst when possible Marek Mietus
2026-03-12 15:56   ` [PATCH net-next v8 09/11] net: sctp: convert sctp_v{4,6}_xmit " Marek Mietus
2026-03-12 15:56   ` Marek Mietus [this message]
2026-03-12 15:56   ` [PATCH net-next v8 11/11] net: tipc: convert tipc_udp_xmit to use a noref dst Marek Mietus
2026-03-17 11:37   ` [PATCH net-next v8 00/11] net: tunnel: introduce noref xmit flows for tunnels Paolo Abeni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260312155657.25676-11-mmietus97@yahoo.com \
    --to=mmietus97@yahoo.com \
    --cc=Jason@zx2c4.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox