mbox series

[net,00/16] net: first round to use dev_net_rcu()

Message ID 20250131171334.1172661-1-edumazet@google.com (mailing list archive)
Headers show
Series net: first round to use dev_net_rcu() | expand

Message

Eric Dumazet Jan. 31, 2025, 5:13 p.m. UTC
dev_net(dev) should either be protected by RTNL or RCU.

There is no LOCKDEP support yet for this helper.

Adding it would trigger too many splats.

Instead, add dev_net_rcu() and start to use it
to either fix bugs or document points that were safely
using dev_net().

Eric Dumazet (16):
  net: add dev_net_rcu() helper
  ipv4: add RCU protection to ip4_dst_hoplimit()
  ipv4: use RCU protection in ip_dst_mtu_maybe_forward()
  ipv4: use RCU protection in ipv4_default_advmss()
  ipv4: use RCU protection in rt_is_expired()
  tcp: convert to dev_net_rcu()
  net: gro: convert four dev_net() calls
  udp: convert to dev_net_rcu()
  ipv4: icmp: convert to dev_net_rcu()
  ipv6: icmp: convert to dev_net_rcu()
  ipv6: input: convert to dev_net_rcu()
  ipv6: output: convert to dev_net_rcu()
  ipv6: use RCU protection in ip6_default_advmss()
  net: filter: convert to dev_net_rcu()
  flow_dissector: use rcu protection to fetch dev_net()
  ipv4: use RCU protection in inet_select_addr()

 include/linux/netdevice.h      |  6 +++++
 include/net/inet6_hashtables.h |  2 +-
 include/net/inet_hashtables.h  |  2 +-
 include/net/ip.h               | 13 ++++++++---
 include/net/net_namespace.h    |  2 +-
 include/net/route.h            |  9 ++++++--
 net/core/filter.c              | 40 +++++++++++++++++-----------------
 net/core/flow_dissector.c      | 21 +++++++++---------
 net/ipv4/devinet.c             |  3 ++-
 net/ipv4/icmp.c                | 22 +++++++++----------
 net/ipv4/route.c               | 19 ++++++++++++----
 net/ipv4/tcp_ipv4.c            |  8 +++----
 net/ipv4/tcp_metrics.c         |  6 ++---
 net/ipv4/tcp_offload.c         |  2 +-
 net/ipv4/udp.c                 | 19 ++++++++--------
 net/ipv4/udp_offload.c         |  2 +-
 net/ipv6/icmp.c                | 22 +++++++++----------
 net/ipv6/ip6_input.c           | 12 +++++-----
 net/ipv6/ip6_output.c          |  4 ++--
 net/ipv6/output_core.c         |  2 +-
 net/ipv6/route.c               |  7 +++++-
 net/ipv6/tcp_ipv6.c            | 10 ++++-----
 net/ipv6/tcpv6_offload.c       |  2 +-
 net/ipv6/udp.c                 | 18 +++++++--------
 net/ipv6/udp_offload.c         |  2 +-
 25 files changed, 146 insertions(+), 109 deletions(-)

Comments

Jakub Kicinski Feb. 2, 2025, 2:18 a.m. UTC | #1
On Fri, 31 Jan 2025 17:13:18 +0000 Eric Dumazet wrote:
>   ipv4: use RCU protection in inet_select_addr()

patchwork thinks it's an incomplete series due to lack of this patch 
on the list. I'm afraid a repost will be needed :(
Eric Dumazet Feb. 3, 2025, 10:12 a.m. UTC | #2
On Sun, Feb 2, 2025 at 3:18 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Fri, 31 Jan 2025 17:13:18 +0000 Eric Dumazet wrote:
> >   ipv4: use RCU protection in inet_select_addr()
>
> patchwork thinks it's an incomplete series due to lack of this patch
> on the list. I'm afraid a repost will be needed :(

Interesting, I wonder what happened...

I will send a v2, here what it looks like:

commit 52a1dc65d01230876fbacc7f8fe63ee7a758603f (HEAD)
Author: Eric Dumazet <edumazet@google.com>
Date:   Fri Jan 31 16:47:50 2025 +0000

    ipv4: use RCU protection in inet_select_addr()

    inet_select_addr() must use RCU protection to make
    sure the net structure it reads does not disappear.

    Fixes: c4544c724322 ("[NETNS]: Process inet_select_addr inside a
namespace.")
    Signed-off-by: Eric Dumazet <edumazet@google.com>

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index c8b3cf5fba4c02941b919687a6a657cf68f5f99a..55b8151759bc9f76ebdbfae27544d6ee666a4809
100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1371,10 +1371,11 @@ __be32 inet_select_addr(const struct
net_device *dev, __be32 dst, int scope)
        __be32 addr = 0;
        unsigned char localnet_scope = RT_SCOPE_HOST;
        struct in_device *in_dev;
-       struct net *net = dev_net(dev);
+       struct net *net;
        int master_idx;

        rcu_read_lock();
+       net = dev_net_rcu(dev);
        in_dev = __in_dev_get_rcu(dev);
        if (!in_dev)
                goto no_in_dev;