Message ID | 20241018012225.90409-6-kuniyu@amazon.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | ipv4: Convert RTM_{NEW,DEL}ADDR and more to per-netns RTNL. | expand |
On Fri, Oct 18, 2024 at 3:24 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote: > > inet_rtm_to_ifa() and find_matching_ifa() are called > under rtnl_net_lock(). > > __in_dev_get_rtnl() and in_dev_for_each_ifa_rtnl() there > can use per-netns RTNL helpers. > > Let's define and use __in_dev_get_rtnl_net() and > in_dev_for_each_ifa_rtnl_net(). > > Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Reviewed-by: Eric Dumazet <edumazet@google.com>
Hi Kuniyuki, kernel test robot noticed the following build warnings: [auto build test WARNING on net-next/main] url: https://github.com/intel-lab-lkp/linux/commits/Kuniyuki-Iwashima/rtnetlink-Define-RTNL_FLAG_DOIT_PERNET-for-per-netns-RTNL-doit/20241018-092802 base: net-next/main patch link: https://lore.kernel.org/r/20241018012225.90409-6-kuniyu%40amazon.com patch subject: [PATCH v1 net-next 05/11] ipv4: Use per-netns RTNL helpers in inet_rtm_newaddr(). config: x86_64-randconfig-122-20241019 (https://download.01.org/0day-ci/archive/20241020/202410200325.SaEJmyZS-lkp@intel.com/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241020/202410200325.SaEJmyZS-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202410200325.SaEJmyZS-lkp@intel.com/ sparse warnings: (new ones prefixed by >>) >> net/ipv4/devinet.c:941:9: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void *p @@ got struct in_ifaddr [noderef] __rcu *ifa_list @@ net/ipv4/devinet.c:941:9: sparse: expected void *p net/ipv4/devinet.c:941:9: sparse: got struct in_ifaddr [noderef] __rcu *ifa_list >> net/ipv4/devinet.c:941:9: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void *p @@ got struct in_ifaddr [noderef] __rcu *ifa_next @@ net/ipv4/devinet.c:941:9: sparse: expected void *p net/ipv4/devinet.c:941:9: sparse: got struct in_ifaddr [noderef] __rcu *ifa_next net/ipv4/devinet.c: note: in included file: >> include/linux/inetdevice.h:261:54: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void *p @@ got struct in_device [noderef] __rcu *const ip_ptr @@ include/linux/inetdevice.h:261:54: sparse: expected void *p include/linux/inetdevice.h:261:54: sparse: got struct in_device [noderef] __rcu *const ip_ptr net/ipv4/devinet.c: note: in included file (through include/linux/inetdevice.h): >> include/linux/rtnetlink.h:147:16: sparse: sparse: incompatible types in comparison expression (different address spaces): include/linux/rtnetlink.h:147:16: sparse: void [noderef] __rcu * include/linux/rtnetlink.h:147:16: sparse: void * >> include/linux/rtnetlink.h:147:16: sparse: sparse: incompatible types in comparison expression (different address spaces): include/linux/rtnetlink.h:147:16: sparse: void [noderef] __rcu * include/linux/rtnetlink.h:147:16: sparse: void * >> include/linux/rtnetlink.h:147:16: sparse: sparse: incompatible types in comparison expression (different address spaces): include/linux/rtnetlink.h:147:16: sparse: void [noderef] __rcu * include/linux/rtnetlink.h:147:16: sparse: void * vim +941 net/ipv4/devinet.c 935 936 static struct in_ifaddr *find_matching_ifa(struct net *net, struct in_ifaddr *ifa) 937 { 938 struct in_device *in_dev = ifa->ifa_dev; 939 struct in_ifaddr *ifa1; 940 > 941 in_dev_for_each_ifa_rtnl_net(net, ifa1, in_dev) { 942 if (ifa1->ifa_mask == ifa->ifa_mask && 943 inet_ifa_match(ifa1->ifa_address, ifa) && 944 ifa1->ifa_local == ifa->ifa_local) 945 return ifa1; 946 } 947 948 return NULL; 949 } 950
From: kernel test robot <lkp@intel.com> Date: Sun, 20 Oct 2024 04:03:55 +0800 > Hi Kuniyuki, > > kernel test robot noticed the following build warnings: > > [auto build test WARNING on net-next/main] > > url: https://github.com/intel-lab-lkp/linux/commits/Kuniyuki-Iwashima/rtnetlink-Define-RTNL_FLAG_DOIT_PERNET-for-per-netns-RTNL-doit/20241018-092802 > base: net-next/main > patch link: https://lore.kernel.org/r/20241018012225.90409-6-kuniyu%40amazon.com > patch subject: [PATCH v1 net-next 05/11] ipv4: Use per-netns RTNL helpers in inet_rtm_newaddr(). > config: x86_64-randconfig-122-20241019 (https://download.01.org/0day-ci/archive/20241020/202410200325.SaEJmyZS-lkp@intel.com/config) > compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241020/202410200325.SaEJmyZS-lkp@intel.com/reproduce) > > If you fix the issue in a separate patch/commit (i.e. not just a new version of > the same patch/commit), kindly add following tags > | Reported-by: kernel test robot <lkp@intel.com> > | Closes: https://lore.kernel.org/oe-kbuild-all/202410200325.SaEJmyZS-lkp@intel.com/ > > sparse warnings: (new ones prefixed by >>) > >> net/ipv4/devinet.c:941:9: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void *p @@ got struct in_ifaddr [noderef] __rcu *ifa_list @@ > net/ipv4/devinet.c:941:9: sparse: expected void *p > net/ipv4/devinet.c:941:9: sparse: got struct in_ifaddr [noderef] __rcu *ifa_list Hmm.. when DEBUG_NET_SMALL_RTNL is off, we use static inline helper returning (void *) to make sure net is always evaluated as requested in this thread. https://lore.kernel.org/netdev/20241004132145.7fd208e9@kernel.org/ But it seems we can't do that when the pointer has __rcu annotation. Also, this (void *)net evaluation in turn makes build fail due to -Werror=unused-value. #define rtnl_net_dereference(net, p) \ ({ \ (void *)net; \ rtnl_dereference(p); \ }) net/ipv4/devinet.c: In function ‘inet_rtm_deladdr’: ./include/linux/rtnetlink.h:154:17: error: statement with no effect [-Werror=unused-value] 154 | (void *)net; \ net/ipv4/devinet.c:674:21: note: in expansion of macro ‘rtnl_net_dereference’ 674 | (ifa = rtnl_net_dereference(net, *ifap)) != NULL; | ^~~~~~~~~~~~~~~~~~~~ So, we need to go back to the simplest macro. #define rtnl_net_dereference(net, p) \ rtnl_dereference(p); I'll include the fix in v2. > >> net/ipv4/devinet.c:941:9: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void *p @@ got struct in_ifaddr [noderef] __rcu *ifa_next @@ > net/ipv4/devinet.c:941:9: sparse: expected void *p > net/ipv4/devinet.c:941:9: sparse: got struct in_ifaddr [noderef] __rcu *ifa_next > net/ipv4/devinet.c: note: in included file: > >> include/linux/inetdevice.h:261:54: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void *p @@ got struct in_device [noderef] __rcu *const ip_ptr @@ > include/linux/inetdevice.h:261:54: sparse: expected void *p > include/linux/inetdevice.h:261:54: sparse: got struct in_device [noderef] __rcu *const ip_ptr > net/ipv4/devinet.c: note: in included file (through include/linux/inetdevice.h): > >> include/linux/rtnetlink.h:147:16: sparse: sparse: incompatible types in comparison expression (different address spaces): > include/linux/rtnetlink.h:147:16: sparse: void [noderef] __rcu * > include/linux/rtnetlink.h:147:16: sparse: void * > >> include/linux/rtnetlink.h:147:16: sparse: sparse: incompatible types in comparison expression (different address spaces): > include/linux/rtnetlink.h:147:16: sparse: void [noderef] __rcu * > include/linux/rtnetlink.h:147:16: sparse: void * > >> include/linux/rtnetlink.h:147:16: sparse: sparse: incompatible types in comparison expression (different address spaces): > include/linux/rtnetlink.h:147:16: sparse: void [noderef] __rcu * > include/linux/rtnetlink.h:147:16: sparse: void * > > vim +941 net/ipv4/devinet.c > > 935 > 936 static struct in_ifaddr *find_matching_ifa(struct net *net, struct in_ifaddr *ifa) > 937 { > 938 struct in_device *in_dev = ifa->ifa_dev; > 939 struct in_ifaddr *ifa1; > 940 > > 941 in_dev_for_each_ifa_rtnl_net(net, ifa1, in_dev) { > 942 if (ifa1->ifa_mask == ifa->ifa_mask && > 943 inet_ifa_match(ifa1->ifa_address, ifa) && > 944 ifa1->ifa_local == ifa->ifa_local) > 945 return ifa1; > 946 } > 947 > 948 return NULL; > 949 } > 950
diff --git a/include/linux/inetdevice.h b/include/linux/inetdevice.h index d9c690c8c80b..5730ba6b1cfa 100644 --- a/include/linux/inetdevice.h +++ b/include/linux/inetdevice.h @@ -226,6 +226,10 @@ static __inline__ bool bad_mask(__be32 mask, __be32 addr) for (ifa = rtnl_dereference((in_dev)->ifa_list); ifa; \ ifa = rtnl_dereference(ifa->ifa_next)) +#define in_dev_for_each_ifa_rtnl_net(net, ifa, in_dev) \ + for (ifa = rtnl_net_dereference(net, (in_dev)->ifa_list); ifa; \ + ifa = rtnl_net_dereference(net, ifa->ifa_next)) + #define in_dev_for_each_ifa_rcu(ifa, in_dev) \ for (ifa = rcu_dereference((in_dev)->ifa_list); ifa; \ ifa = rcu_dereference(ifa->ifa_next)) @@ -252,6 +256,11 @@ static inline struct in_device *__in_dev_get_rtnl(const struct net_device *dev) return rtnl_dereference(dev->ip_ptr); } +static inline struct in_device *__in_dev_get_rtnl_net(const struct net_device *dev) +{ + return rtnl_net_dereference(dev_net(dev), dev->ip_ptr); +} + /* called with rcu_read_lock or rtnl held */ static inline bool ip_ignore_linkdown(const struct net_device *dev) { diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 6abafdd20b3c..4f94fc8f552d 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -886,7 +886,7 @@ static struct in_ifaddr *inet_rtm_to_ifa(struct net *net, struct nlmsghdr *nlh, goto errout; } - in_dev = __in_dev_get_rtnl(dev); + in_dev = __in_dev_get_rtnl_net(dev); err = -ENOBUFS; if (!in_dev) goto errout; @@ -933,12 +933,12 @@ static struct in_ifaddr *inet_rtm_to_ifa(struct net *net, struct nlmsghdr *nlh, return ERR_PTR(err); } -static struct in_ifaddr *find_matching_ifa(struct in_ifaddr *ifa) +static struct in_ifaddr *find_matching_ifa(struct net *net, struct in_ifaddr *ifa) { struct in_device *in_dev = ifa->ifa_dev; struct in_ifaddr *ifa1; - in_dev_for_each_ifa_rtnl(ifa1, in_dev) { + in_dev_for_each_ifa_rtnl_net(net, ifa1, in_dev) { if (ifa1->ifa_mask == ifa->ifa_mask && inet_ifa_match(ifa1->ifa_address, ifa) && ifa1->ifa_local == ifa->ifa_local) @@ -974,7 +974,7 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, goto unlock; } - ifa_existing = find_matching_ifa(ifa); + ifa_existing = find_matching_ifa(net, ifa); if (!ifa_existing) { /* It would be best to check for !NLM_F_CREATE here but * userspace already relies on not having to provide this.
inet_rtm_to_ifa() and find_matching_ifa() are called under rtnl_net_lock(). __in_dev_get_rtnl() and in_dev_for_each_ifa_rtnl() there can use per-netns RTNL helpers. Let's define and use __in_dev_get_rtnl_net() and in_dev_for_each_ifa_rtnl_net(). Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> --- include/linux/inetdevice.h | 9 +++++++++ net/ipv4/devinet.c | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-)