diff mbox series

[v1,net-next,06/11] ipv4: Convert RTM_DELADDR to per-netns RTNL.

Message ID 20241018012225.90409-7-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

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 64 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 1 this patch: 1
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-10-19--00-00 (tests: 777)

Commit Message

Kuniyuki Iwashima Oct. 18, 2024, 1:22 a.m. UTC
Let's push down RTNL into inet_rtm_deladdr() as rtnl_net_lock().

Now, ip_mc_autojoin_config() is always called under per-netns RTNL,
so ASSERT_RTNL() can be replaced with ASSERT_RTNL_NET().

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 net/ipv4/devinet.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

Comments

Eric Dumazet Oct. 18, 2024, 1:53 p.m. UTC | #1
On Fri, Oct 18, 2024 at 3:24 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote:
>
> Let's push down RTNL into inet_rtm_deladdr() as rtnl_net_lock().
>
> Now, ip_mc_autojoin_config() is always called under per-netns RTNL,
> so ASSERT_RTNL() can be replaced with ASSERT_RTNL_NET().
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> ---

Reviewed-by: Eric Dumazet <edumazet@google.com>
kernel test robot Oct. 19, 2024, 10:59 p.m. UTC | #2
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-7-kuniyu%40amazon.com
patch subject: [PATCH v1 net-next 06/11] ipv4: Convert RTM_DELADDR to per-netns RTNL.
config: x86_64-randconfig-122-20241019 (https://download.01.org/0day-ci/archive/20241020/202410200600.GGC28WrU-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/202410200600.GGC28WrU-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/202410200600.GGC28WrU-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> net/ipv4/devinet.c:676:47: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu * @@
   net/ipv4/devinet.c:676:47: sparse:     expected void *p
   net/ipv4/devinet.c:676:47: sparse:     got struct in_ifaddr [noderef] __rcu *
   net/ipv4/devinet.c:946: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:946:9: sparse:     expected void *p
   net/ipv4/devinet.c:946:9: sparse:     got struct in_ifaddr [noderef] __rcu *ifa_list
   net/ipv4/devinet.c:946: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:946:9: sparse:     expected void *p
   net/ipv4/devinet.c:946:9: sparse:     got struct in_ifaddr [noderef] __rcu *ifa_next
   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 *
   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 +676 net/ipv4/devinet.c

   647	
   648	static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh,
   649				    struct netlink_ext_ack *extack)
   650	{
   651		struct net *net = sock_net(skb->sk);
   652		struct in_ifaddr __rcu **ifap;
   653		struct nlattr *tb[IFA_MAX+1];
   654		struct in_device *in_dev;
   655		struct ifaddrmsg *ifm;
   656		struct in_ifaddr *ifa;
   657		int err;
   658	
   659		err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
   660					     ifa_ipv4_policy, extack);
   661		if (err < 0)
   662			goto out;
   663	
   664		ifm = nlmsg_data(nlh);
   665	
   666		rtnl_net_lock(net);
   667	
   668		in_dev = inetdev_by_index(net, ifm->ifa_index);
   669		if (!in_dev) {
   670			NL_SET_ERR_MSG(extack, "ipv4: Device not found");
   671			err = -ENODEV;
   672			goto unlock;
   673		}
   674	
   675		for (ifap = &in_dev->ifa_list;
 > 676		     (ifa = rtnl_net_dereference(net, *ifap)) != NULL;
   677		     ifap = &ifa->ifa_next) {
   678			if (tb[IFA_LOCAL] &&
   679			    ifa->ifa_local != nla_get_in_addr(tb[IFA_LOCAL]))
   680				continue;
   681	
   682			if (tb[IFA_LABEL] && nla_strcmp(tb[IFA_LABEL], ifa->ifa_label))
   683				continue;
   684	
   685			if (tb[IFA_ADDRESS] &&
   686			    (ifm->ifa_prefixlen != ifa->ifa_prefixlen ||
   687			    !inet_ifa_match(nla_get_in_addr(tb[IFA_ADDRESS]), ifa)))
   688				continue;
   689	
   690			if (ipv4_is_multicast(ifa->ifa_address))
   691				ip_mc_autojoin_config(net, false, ifa);
   692	
   693			__inet_del_ifa(in_dev, ifap, 1, nlh, NETLINK_CB(skb).portid);
   694			goto unlock;
   695		}
   696	
   697		NL_SET_ERR_MSG(extack, "ipv4: Address not found");
   698		err = -EADDRNOTAVAIL;
   699	unlock:
   700		rtnl_net_unlock(net);
   701	out:
   702		return err;
   703	}
   704
diff mbox series

Patch

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 4f94fc8f552d..cbda22eb8d06 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -630,7 +630,7 @@  static int ip_mc_autojoin_config(struct net *net, bool join,
 	struct sock *sk = net->ipv4.mc_autojoin_sk;
 	int ret;
 
-	ASSERT_RTNL();
+	ASSERT_RTNL_NET(net);
 
 	lock_sock(sk);
 	if (join)
@@ -656,22 +656,24 @@  static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh,
 	struct in_ifaddr *ifa;
 	int err;
 
-	ASSERT_RTNL();
-
 	err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
 				     ifa_ipv4_policy, extack);
 	if (err < 0)
-		goto errout;
+		goto out;
 
 	ifm = nlmsg_data(nlh);
+
+	rtnl_net_lock(net);
+
 	in_dev = inetdev_by_index(net, ifm->ifa_index);
 	if (!in_dev) {
 		NL_SET_ERR_MSG(extack, "ipv4: Device not found");
 		err = -ENODEV;
-		goto errout;
+		goto unlock;
 	}
 
-	for (ifap = &in_dev->ifa_list; (ifa = rtnl_dereference(*ifap)) != NULL;
+	for (ifap = &in_dev->ifa_list;
+	     (ifa = rtnl_net_dereference(net, *ifap)) != NULL;
 	     ifap = &ifa->ifa_next) {
 		if (tb[IFA_LOCAL] &&
 		    ifa->ifa_local != nla_get_in_addr(tb[IFA_LOCAL]))
@@ -687,13 +689,16 @@  static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh,
 
 		if (ipv4_is_multicast(ifa->ifa_address))
 			ip_mc_autojoin_config(net, false, ifa);
+
 		__inet_del_ifa(in_dev, ifap, 1, nlh, NETLINK_CB(skb).portid);
-		return 0;
+		goto unlock;
 	}
 
 	NL_SET_ERR_MSG(extack, "ipv4: Address not found");
 	err = -EADDRNOTAVAIL;
-errout:
+unlock:
+	rtnl_net_unlock(net);
+out:
 	return err;
 }
 
@@ -2817,7 +2822,8 @@  static struct rtnl_af_ops inet_af_ops __read_mostly = {
 static const struct rtnl_msg_handler devinet_rtnl_msg_handlers[] __initconst = {
 	{.protocol = PF_INET, .msgtype = RTM_NEWADDR, .doit = inet_rtm_newaddr,
 	 .flags = RTNL_FLAG_DOIT_PERNET},
-	{.protocol = PF_INET, .msgtype = RTM_DELADDR, .doit = inet_rtm_deladdr},
+	{.protocol = PF_INET, .msgtype = RTM_DELADDR, .doit = inet_rtm_deladdr,
+	 .flags = RTNL_FLAG_DOIT_PERNET},
 	{.protocol = PF_INET, .msgtype = RTM_GETADDR, .dumpit = inet_dump_ifaddr,
 	 .flags = RTNL_FLAG_DUMP_UNLOCKED | RTNL_FLAG_DUMP_SPLIT_NLM_DONE},
 	{.protocol = PF_INET, .msgtype = RTM_GETNETCONF,