Received: from out30-77.freemail.mail.aliyun.com (out30-77.freemail.mail.aliyun.com [115.124.30.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A4A830C618; Mon, 2 Mar 2026 07:37:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.77 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772437042; cv=none; b=oIyBJQaN23ERdvS5zGqT/7NP2taRoAIQ/2sxP2jLyeubQGc0YHtuZbnz2MGinjI5segb3PWFXRW/jI8VY4/NPXudCd4j2IZsL86AxEvF5kfda8Lq0bH1asv7l7gF1xRttuxz6u9AZMFcT/gaP2g88hJ3I9A8l50jmcxgECXvDVA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772437042; c=relaxed/simple; bh=Ff41Zes6jf50ZyzjrXCM9kt3tblMrdZ4M4R8vN5saZ8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eGT+/qjTO3DEMzBACOf+0rbuL0jzKX4TVbrOnx0Oxxx/wgH7lcoggm+GCiF6gT80AjvrZQOP46HL1f8UyThv7vYMKkyEQalfNu0Iq/rofDUtsc2qE9EvlLqFVOlHXfzNe5Nuq0j4MvKAXKndK8E9tyD0e9mE7OKWup57ruh0pFs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=aliyun.com; spf=pass smtp.mailfrom=aliyun.com; dkim=pass (1024-bit key) header.d=aliyun.com header.i=@aliyun.com header.b=S+lcLrGS; arc=none smtp.client-ip=115.124.30.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=aliyun.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aliyun.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=aliyun.com header.i=@aliyun.com header.b="S+lcLrGS" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=aliyun.com; s=s1024; t=1772437038; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=W5bB1/y6hbLBBi7VUi+Ckh0OiWFLTDJMfuSqAZO0h5w=; b=S+lcLrGSXwlr0mz/sMG0YgwiqKekUoMGzSYr2x95Y/NYRHWqHe7JJWXkApibLoyum4Hwm+LEEJ9+ekPGsQWxWuxqjyadsCU+Rgb3araHcBofDENlXhllIO1brPRKLY7TuU/jDXXZdTD2D2mZ/IXAcZ6FJN3Uur+hEQ5ZMj+kNLA= Received: from China-team(mailfrom:ruohanlan@aliyun.com fp:SMTPD_---0X-2840m_1772437036 cluster:ay36) by smtp.aliyun-inc.com; Mon, 02 Mar 2026 15:37:17 +0800 From: Ruohan Lan To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: edumazet@google.com, kuniyu@google.com, kuba@kernel.org, dsahern@kernel.org, netdev@vger.kernel.org, Ruohan Lan Subject: [PATCH 6.6.y 3/3] net: use dst_dev_rcu() in sk_setup_caps() Date: Mon, 2 Mar 2026 15:36:30 +0800 Message-Id: <20260302073630.988982-4-ruohanlan@aliyun.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260302073630.988982-1-ruohanlan@aliyun.com> References: <20260302073630.988982-1-ruohanlan@aliyun.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Eric Dumazet [ Upstream commit 99a2ace61b211b0be861b07fbaa062fca4b58879 ] Use RCU to protect accesses to dst->dev from sk_setup_caps() and sk_dst_gso_max_size(). Also use dst_dev_rcu() in ip6_dst_mtu_maybe_forward(), and ip_dst_mtu_maybe_forward(). ip4_dst_hoplimit() can use dst_dev_net_rcu(). Fixes: 4a6ce2b6f2ec ("net: introduce a new function dst_dev_put()") Signed-off-by: Eric Dumazet Reviewed-by: David Ahern Link: https://patch.msgid.link/20250828195823.3958522-6-edumazet@google.com Signed-off-by: Jakub Kicinski [ Adjust context ] Signed-off-by: Ruohan Lan --- include/net/ip.h | 7 +++++-- include/net/ip6_route.h | 2 +- include/net/route.h | 2 +- net/core/sock.c | 16 ++++++++++------ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index d8bf1f0a6919..ff63b1835be8 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -458,9 +458,12 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst, bool forwarding) { const struct rtable *rt = container_of(dst, struct rtable, dst); - struct net *net = dev_net(dst->dev); + struct net *net; + const struct net_device *dev; unsigned int mtu; + dev = dst_dev_rcu(dst); + net = dev_net_rcu(dev); if (READ_ONCE(net->ipv4.sysctl_ip_fwd_use_pmtu) || ip_mtu_locked(dst) || !forwarding) { @@ -474,7 +477,7 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst, if (mtu) goto out; - mtu = READ_ONCE(dst->dev->mtu); + mtu = READ_ONCE(dev->mtu); if (unlikely(ip_mtu_locked(dst))) { if (rt->rt_uses_gateway && mtu > 576) diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h index 392232fcd703..dca39485e672 100644 --- a/include/net/ip6_route.h +++ b/include/net/ip6_route.h @@ -333,7 +333,7 @@ static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dst mtu = IPV6_MIN_MTU; rcu_read_lock(); - idev = __in6_dev_get(dst->dev); + idev = __in6_dev_get(dst_dev_rcu(dst)); if (idev) mtu = idev->cnf.mtu6; rcu_read_unlock(); diff --git a/include/net/route.h b/include/net/route.h index 27c17aff0bbe..af1a9ec559b2 100644 --- a/include/net/route.h +++ b/include/net/route.h @@ -363,7 +363,7 @@ static inline int ip4_dst_hoplimit(const struct dst_entry *dst) const struct net *net; rcu_read_lock(); - net = dev_net_rcu(dst->dev); + net = dst_dev_net_rcu(dst); hoplimit = READ_ONCE(net->ipv4.sysctl_ip_default_ttl); rcu_read_unlock(); } diff --git a/net/core/sock.c b/net/core/sock.c index 0e52847c57f8..d9e6084b33e9 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2440,7 +2440,7 @@ void sk_free_unlock_clone(struct sock *sk) } EXPORT_SYMBOL_GPL(sk_free_unlock_clone); -static u32 sk_dst_gso_max_size(struct sock *sk, struct dst_entry *dst) +static u32 sk_dst_gso_max_size(struct sock *sk, const struct net_device *dev) { bool is_ipv6 = false; u32 max_size; @@ -2450,8 +2450,8 @@ static u32 sk_dst_gso_max_size(struct sock *sk, struct dst_entry *dst) !ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr)); #endif /* pairs with the WRITE_ONCE() in netif_set_gso(_ipv4)_max_size() */ - max_size = is_ipv6 ? READ_ONCE(dst_dev(dst)->gso_max_size) : - READ_ONCE(dst_dev(dst)->gso_ipv4_max_size); + max_size = is_ipv6 ? READ_ONCE(dev->gso_max_size) : + READ_ONCE(dev->gso_ipv4_max_size); if (max_size > GSO_LEGACY_MAX_SIZE && !sk_is_tcp(sk)) max_size = GSO_LEGACY_MAX_SIZE; @@ -2460,9 +2460,12 @@ static u32 sk_dst_gso_max_size(struct sock *sk, struct dst_entry *dst) void sk_setup_caps(struct sock *sk, struct dst_entry *dst) { + const struct net_device *dev; u32 max_segs = 1; - sk->sk_route_caps = dst_dev(dst)->features; + rcu_read_lock(); + dev = dst_dev_rcu(dst); + sk->sk_route_caps = dev->features; if (sk_is_tcp(sk)) sk->sk_route_caps |= NETIF_F_GSO; if (sk->sk_route_caps & NETIF_F_GSO) @@ -2474,13 +2477,14 @@ void sk_setup_caps(struct sock *sk, struct dst_entry *dst) sk->sk_route_caps &= ~NETIF_F_GSO_MASK; } else { sk->sk_route_caps |= NETIF_F_SG | NETIF_F_HW_CSUM; - sk->sk_gso_max_size = sk_dst_gso_max_size(sk, dst); + sk->sk_gso_max_size = sk_dst_gso_max_size(sk, dev); /* pairs with the WRITE_ONCE() in netif_set_gso_max_segs() */ - max_segs = max_t(u32, READ_ONCE(dst_dev(dst)->gso_max_segs), 1); + max_segs = max_t(u32, READ_ONCE(dev->gso_max_segs), 1); } } sk->sk_gso_max_segs = max_segs; sk_dst_set(sk, dst); + rcu_read_unlock(); } EXPORT_SYMBOL_GPL(sk_setup_caps); -- 2.43.0