netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 net-next 00/11] ipv4: Convert RTM_{NEW,DEL}ADDR and more to per-netns RTNL.
@ 2024-10-18  1:22 Kuniyuki Iwashima
  2024-10-18  1:22 ` [PATCH v1 net-next 01/11] rtnetlink: Define RTNL_FLAG_DOIT_PERNET for per-netns RTNL doit() Kuniyuki Iwashima
                   ` (10 more replies)
  0 siblings, 11 replies; 27+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-18  1:22 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

The IPv4 address hash table and GC are already namespacified.

This series converts RTM_NEWADDR/RTM_DELADDR and some more
RTNL users to per-netns RTNL.


Kuniyuki Iwashima (11):
  rtnetlink: Define RTNL_FLAG_DOIT_PERNET for per-netns RTNL doit().
  ipv4: Factorise RTM_NEWADDR validation to inet_validate_rtm().
  ipv4: Don't allocate ifa for 0.0.0.0 in inet_rtm_newaddr().
  ipv4: Convert RTM_NEWADDR to per-netns RTNL.
  ipv4: Use per-netns RTNL helpers in inet_rtm_newaddr().
  ipv4: Convert RTM_DELADDR to per-netns RTNL.
  ipv4: Convert check_lifetime() to per-netns RTNL.
  rtnetlink: Define rtnl_net_lock().
  ipv4: Convert devinet_sysctl_forward() to per-netns RTNL.
  ipv4: Convert devinet_ioctl() to per-netns RTNL except for
    SIOCSIFFLAGS.
  ipv4: Convert devinet_ioctl to per-netns RTNL.

 include/linux/inetdevice.h |   9 ++
 include/linux/rtnetlink.h  |   6 ++
 include/net/rtnetlink.h    |   1 +
 net/core/dev_ioctl.c       |   6 +-
 net/core/rtnetlink.c       |  11 +++
 net/ipv4/devinet.c         | 190 +++++++++++++++++++++----------------
 6 files changed, 138 insertions(+), 85 deletions(-)

-- 
2.39.5 (Apple Git-154)


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH v1 net-next 01/11] rtnetlink: Define RTNL_FLAG_DOIT_PERNET for per-netns RTNL doit().
  2024-10-18  1:22 [PATCH v1 net-next 00/11] ipv4: Convert RTM_{NEW,DEL}ADDR and more to per-netns RTNL Kuniyuki Iwashima
@ 2024-10-18  1:22 ` Kuniyuki Iwashima
  2024-10-18 13:48   ` Eric Dumazet
  2024-10-18  1:22 ` [PATCH v1 net-next 02/11] ipv4: Factorise RTM_NEWADDR validation to inet_validate_rtm() Kuniyuki Iwashima
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 27+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-18  1:22 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

We will push RTNL down to each doit() as rtnl_net_lock().

We can use RTNL_FLAG_DOIT_UNLOCKED to call doit() without RTNL, but doit()
will still hold RTNL.

Let's define RTNL_FLAG_DOIT_PERNET as an alias of RTNL_FLAG_DOIT_UNLOCKED.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 include/net/rtnetlink.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
index bb49c5708ce7..3fa9da93364b 100644
--- a/include/net/rtnetlink.h
+++ b/include/net/rtnetlink.h
@@ -11,6 +11,7 @@ typedef int (*rtnl_dumpit_func)(struct sk_buff *, struct netlink_callback *);
 
 enum rtnl_link_flags {
 	RTNL_FLAG_DOIT_UNLOCKED		= BIT(0),
+#define RTNL_FLAG_DOIT_PERNET		RTNL_FLAG_DOIT_UNLOCKED
 	RTNL_FLAG_BULK_DEL_SUPPORTED	= BIT(1),
 	RTNL_FLAG_DUMP_UNLOCKED		= BIT(2),
 	RTNL_FLAG_DUMP_SPLIT_NLM_DONE	= BIT(3),	/* legacy behavior */
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v1 net-next 02/11] ipv4: Factorise RTM_NEWADDR validation to inet_validate_rtm().
  2024-10-18  1:22 [PATCH v1 net-next 00/11] ipv4: Convert RTM_{NEW,DEL}ADDR and more to per-netns RTNL Kuniyuki Iwashima
  2024-10-18  1:22 ` [PATCH v1 net-next 01/11] rtnetlink: Define RTNL_FLAG_DOIT_PERNET for per-netns RTNL doit() Kuniyuki Iwashima
@ 2024-10-18  1:22 ` Kuniyuki Iwashima
  2024-10-18 13:50   ` Eric Dumazet
  2024-10-18  1:22 ` [PATCH v1 net-next 03/11] ipv4: Don't allocate ifa for 0.0.0.0 in inet_rtm_newaddr() Kuniyuki Iwashima
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 27+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-18  1:22 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

rtm_to_ifaddr() validates some attributes, looks up a netdev,
allocates struct in_ifaddr, and validates IFA_CACHEINFO.

There is no reason to delay IFA_CACHEINFO validation.

We will push RTNL down to inet_rtm_newaddr(), and then we want
to complete rtnetlink validation before rtnl_net_lock().

Let's factorise the validation parts.

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

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 89b892eaeb95..64994ece27c0 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -831,35 +831,54 @@ static void set_ifa_lifetime(struct in_ifaddr *ifa, __u32 valid_lft,
 		WRITE_ONCE(ifa->ifa_cstamp, ifa->ifa_tstamp);
 }
 
-static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
-				       __u32 *pvalid_lft, __u32 *pprefered_lft,
-				       struct netlink_ext_ack *extack)
+static int inet_validate_rtm(struct nlmsghdr *nlh, struct nlattr **tb,
+			     struct netlink_ext_ack *extack,
+			     __u32 *valid_lft, __u32 *prefered_lft)
 {
-	struct nlattr *tb[IFA_MAX+1];
-	struct in_ifaddr *ifa;
-	struct ifaddrmsg *ifm;
-	struct net_device *dev;
-	struct in_device *in_dev;
+	struct ifaddrmsg *ifm = nlmsg_data(nlh);
 	int err;
 
 	err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
 				     ifa_ipv4_policy, extack);
 	if (err < 0)
-		goto errout;
-
-	ifm = nlmsg_data(nlh);
-	err = -EINVAL;
+		return err;
 
 	if (ifm->ifa_prefixlen > 32) {
 		NL_SET_ERR_MSG(extack, "ipv4: Invalid prefix length");
-		goto errout;
+		return -EINVAL;
 	}
 
 	if (!tb[IFA_LOCAL]) {
 		NL_SET_ERR_MSG(extack, "ipv4: Local address is not supplied");
-		goto errout;
+		return -EINVAL;
 	}
 
+	if (tb[IFA_CACHEINFO]) {
+		struct ifa_cacheinfo *ci;
+
+		ci = nla_data(tb[IFA_CACHEINFO]);
+		if (!ci->ifa_valid || ci->ifa_prefered > ci->ifa_valid) {
+			NL_SET_ERR_MSG(extack, "ipv4: address lifetime invalid");
+			return -EINVAL;
+		}
+
+		*valid_lft = ci->ifa_valid;
+		*prefered_lft = ci->ifa_prefered;
+	}
+
+	return 0;
+}
+
+static struct in_ifaddr *inet_rtm_to_ifa(struct net *net, struct nlmsghdr *nlh,
+					 struct nlattr **tb,
+					 struct netlink_ext_ack *extack)
+{
+	struct ifaddrmsg *ifm = nlmsg_data(nlh);
+	struct in_device *in_dev;
+	struct net_device *dev;
+	struct in_ifaddr *ifa;
+	int err;
+
 	dev = __dev_get_by_index(net, ifm->ifa_index);
 	err = -ENODEV;
 	if (!dev) {
@@ -908,23 +927,8 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
 	if (tb[IFA_PROTO])
 		ifa->ifa_proto = nla_get_u8(tb[IFA_PROTO]);
 
-	if (tb[IFA_CACHEINFO]) {
-		struct ifa_cacheinfo *ci;
-
-		ci = nla_data(tb[IFA_CACHEINFO]);
-		if (!ci->ifa_valid || ci->ifa_prefered > ci->ifa_valid) {
-			NL_SET_ERR_MSG(extack, "ipv4: address lifetime invalid");
-			err = -EINVAL;
-			goto errout_free;
-		}
-		*pvalid_lft = ci->ifa_valid;
-		*pprefered_lft = ci->ifa_prefered;
-	}
-
 	return ifa;
 
-errout_free:
-	inet_free_ifa(ifa);
 errout:
 	return ERR_PTR(err);
 }
@@ -949,15 +953,21 @@ static struct in_ifaddr *find_matching_ifa(struct in_ifaddr *ifa)
 static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh,
 			    struct netlink_ext_ack *extack)
 {
+	__u32 prefered_lft = INFINITY_LIFE_TIME;
+	__u32 valid_lft = INFINITY_LIFE_TIME;
 	struct net *net = sock_net(skb->sk);
-	struct in_ifaddr *ifa;
 	struct in_ifaddr *ifa_existing;
-	__u32 valid_lft = INFINITY_LIFE_TIME;
-	__u32 prefered_lft = INFINITY_LIFE_TIME;
+	struct nlattr *tb[IFA_MAX + 1];
+	struct in_ifaddr *ifa;
+	int ret;
 
 	ASSERT_RTNL();
 
-	ifa = rtm_to_ifaddr(net, nlh, &valid_lft, &prefered_lft, extack);
+	ret = inet_validate_rtm(nlh, tb, extack, &valid_lft, &prefered_lft);
+	if (ret < 0)
+		return ret;
+
+	ifa = inet_rtm_to_ifa(net, nlh, tb, extack);
 	if (IS_ERR(ifa))
 		return PTR_ERR(ifa);
 
@@ -968,8 +978,7 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh,
 		 */
 		set_ifa_lifetime(ifa, valid_lft, prefered_lft);
 		if (ifa->ifa_flags & IFA_F_MCAUTOJOIN) {
-			int ret = ip_mc_autojoin_config(net, true, ifa);
-
+			ret = ip_mc_autojoin_config(net, true, ifa);
 			if (ret < 0) {
 				NL_SET_ERR_MSG(extack, "ipv4: Multicast auto join failed");
 				inet_free_ifa(ifa);
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v1 net-next 03/11] ipv4: Don't allocate ifa for 0.0.0.0 in inet_rtm_newaddr().
  2024-10-18  1:22 [PATCH v1 net-next 00/11] ipv4: Convert RTM_{NEW,DEL}ADDR and more to per-netns RTNL Kuniyuki Iwashima
  2024-10-18  1:22 ` [PATCH v1 net-next 01/11] rtnetlink: Define RTNL_FLAG_DOIT_PERNET for per-netns RTNL doit() Kuniyuki Iwashima
  2024-10-18  1:22 ` [PATCH v1 net-next 02/11] ipv4: Factorise RTM_NEWADDR validation to inet_validate_rtm() Kuniyuki Iwashima
@ 2024-10-18  1:22 ` Kuniyuki Iwashima
  2024-10-18 13:51   ` Eric Dumazet
  2024-10-18  1:22 ` [PATCH v1 net-next 04/11] ipv4: Convert RTM_NEWADDR to per-netns RTNL Kuniyuki Iwashima
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 27+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-18  1:22 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

When we pass 0.0.0.0 to __inet_insert_ifa(), it frees ifa and returns 0.

We can do this check much earlier for RTM_NEWADDR even before allocating
struct in_ifaddr.

Let's move the validation to

  1. inet_insert_ifa() for ioctl()
  2. inet_rtm_newaddr() for RTM_NEWADDR

Now, we can remove the same check in find_matching_ifa().

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

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 64994ece27c0..636df3661963 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -493,11 +493,6 @@ static int __inet_insert_ifa(struct in_ifaddr *ifa, struct nlmsghdr *nlh,
 
 	ASSERT_RTNL();
 
-	if (!ifa->ifa_local) {
-		inet_free_ifa(ifa);
-		return 0;
-	}
-
 	ifa->ifa_flags &= ~IFA_F_SECONDARY;
 	last_primary = &in_dev->ifa_list;
 
@@ -569,6 +564,11 @@ static int __inet_insert_ifa(struct in_ifaddr *ifa, struct nlmsghdr *nlh,
 
 static int inet_insert_ifa(struct in_ifaddr *ifa)
 {
+	if (!ifa->ifa_local) {
+		inet_free_ifa(ifa);
+		return 0;
+	}
+
 	return __inet_insert_ifa(ifa, NULL, 0, NULL);
 }
 
@@ -938,15 +938,13 @@ static struct in_ifaddr *find_matching_ifa(struct in_ifaddr *ifa)
 	struct in_device *in_dev = ifa->ifa_dev;
 	struct in_ifaddr *ifa1;
 
-	if (!ifa->ifa_local)
-		return NULL;
-
 	in_dev_for_each_ifa_rtnl(ifa1, in_dev) {
 		if (ifa1->ifa_mask == ifa->ifa_mask &&
 		    inet_ifa_match(ifa1->ifa_address, ifa) &&
 		    ifa1->ifa_local == ifa->ifa_local)
 			return ifa1;
 	}
+
 	return NULL;
 }
 
@@ -967,6 +965,9 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh,
 	if (ret < 0)
 		return ret;
 
+	if (!nla_get_in_addr(tb[IFA_LOCAL]))
+		return 0;
+
 	ifa = inet_rtm_to_ifa(net, nlh, tb, extack);
 	if (IS_ERR(ifa))
 		return PTR_ERR(ifa);
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v1 net-next 04/11] ipv4: Convert RTM_NEWADDR to per-netns RTNL.
  2024-10-18  1:22 [PATCH v1 net-next 00/11] ipv4: Convert RTM_{NEW,DEL}ADDR and more to per-netns RTNL Kuniyuki Iwashima
                   ` (2 preceding siblings ...)
  2024-10-18  1:22 ` [PATCH v1 net-next 03/11] ipv4: Don't allocate ifa for 0.0.0.0 in inet_rtm_newaddr() Kuniyuki Iwashima
@ 2024-10-18  1:22 ` Kuniyuki Iwashima
  2024-10-18 13:51   ` Eric Dumazet
  2024-10-18  1:22 ` [PATCH v1 net-next 05/11] ipv4: Use per-netns RTNL helpers in inet_rtm_newaddr() Kuniyuki Iwashima
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 27+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-18  1:22 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

The address hash table and GC are already namespacified.

Let's push down RTNL into inet_rtm_newaddr() as rtnl_net_lock().

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

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 636df3661963..6abafdd20b3c 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -959,8 +959,6 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh,
 	struct in_ifaddr *ifa;
 	int ret;
 
-	ASSERT_RTNL();
-
 	ret = inet_validate_rtm(nlh, tb, extack, &valid_lft, &prefered_lft);
 	if (ret < 0)
 		return ret;
@@ -968,9 +966,13 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh,
 	if (!nla_get_in_addr(tb[IFA_LOCAL]))
 		return 0;
 
+	rtnl_net_lock(net);
+
 	ifa = inet_rtm_to_ifa(net, nlh, tb, extack);
-	if (IS_ERR(ifa))
-		return PTR_ERR(ifa);
+	if (IS_ERR(ifa)) {
+		ret = PTR_ERR(ifa);
+		goto unlock;
+	}
 
 	ifa_existing = find_matching_ifa(ifa);
 	if (!ifa_existing) {
@@ -983,11 +985,11 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh,
 			if (ret < 0) {
 				NL_SET_ERR_MSG(extack, "ipv4: Multicast auto join failed");
 				inet_free_ifa(ifa);
-				return ret;
+				goto unlock;
 			}
 		}
-		return __inet_insert_ifa(ifa, nlh, NETLINK_CB(skb).portid,
-					 extack);
+
+		ret = __inet_insert_ifa(ifa, nlh, NETLINK_CB(skb).portid, extack);
 	} else {
 		u32 new_metric = ifa->ifa_rt_priority;
 		u8 new_proto = ifa->ifa_proto;
@@ -997,7 +999,8 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh,
 		if (nlh->nlmsg_flags & NLM_F_EXCL ||
 		    !(nlh->nlmsg_flags & NLM_F_REPLACE)) {
 			NL_SET_ERR_MSG(extack, "ipv4: Address already assigned");
-			return -EEXIST;
+			ret = -EEXIST;
+			goto unlock;
 		}
 		ifa = ifa_existing;
 
@@ -1014,7 +1017,11 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh,
 				   &net->ipv4.addr_chk_work, 0);
 		rtmsg_ifa(RTM_NEWADDR, ifa, nlh, NETLINK_CB(skb).portid);
 	}
-	return 0;
+
+unlock:
+	rtnl_net_unlock(net);
+
+	return ret;
 }
 
 /*
@@ -2808,7 +2815,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},
+	{.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_GETADDR, .dumpit = inet_dump_ifaddr,
 	 .flags = RTNL_FLAG_DUMP_UNLOCKED | RTNL_FLAG_DUMP_SPLIT_NLM_DONE},
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v1 net-next 05/11] ipv4: Use per-netns RTNL helpers in inet_rtm_newaddr().
  2024-10-18  1:22 [PATCH v1 net-next 00/11] ipv4: Convert RTM_{NEW,DEL}ADDR and more to per-netns RTNL Kuniyuki Iwashima
                   ` (3 preceding siblings ...)
  2024-10-18  1:22 ` [PATCH v1 net-next 04/11] ipv4: Convert RTM_NEWADDR to per-netns RTNL Kuniyuki Iwashima
@ 2024-10-18  1:22 ` Kuniyuki Iwashima
  2024-10-18 13:52   ` Eric Dumazet
  2024-10-19 20:03   ` kernel test robot
  2024-10-18  1:22 ` [PATCH v1 net-next 06/11] ipv4: Convert RTM_DELADDR to per-netns RTNL Kuniyuki Iwashima
                   ` (5 subsequent siblings)
  10 siblings, 2 replies; 27+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-18  1:22 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

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(-)

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.
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v1 net-next 06/11] ipv4: Convert RTM_DELADDR to per-netns RTNL.
  2024-10-18  1:22 [PATCH v1 net-next 00/11] ipv4: Convert RTM_{NEW,DEL}ADDR and more to per-netns RTNL Kuniyuki Iwashima
                   ` (4 preceding siblings ...)
  2024-10-18  1:22 ` [PATCH v1 net-next 05/11] ipv4: Use per-netns RTNL helpers in inet_rtm_newaddr() Kuniyuki Iwashima
@ 2024-10-18  1:22 ` Kuniyuki Iwashima
  2024-10-18 13:53   ` Eric Dumazet
  2024-10-19 22:59   ` kernel test robot
  2024-10-18  1:22 ` [PATCH v1 net-next 07/11] ipv4: Convert check_lifetime() " Kuniyuki Iwashima
                   ` (4 subsequent siblings)
  10 siblings, 2 replies; 27+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-18  1:22 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

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(-)

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,
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v1 net-next 07/11] ipv4: Convert check_lifetime() to per-netns RTNL.
  2024-10-18  1:22 [PATCH v1 net-next 00/11] ipv4: Convert RTM_{NEW,DEL}ADDR and more to per-netns RTNL Kuniyuki Iwashima
                   ` (5 preceding siblings ...)
  2024-10-18  1:22 ` [PATCH v1 net-next 06/11] ipv4: Convert RTM_DELADDR to per-netns RTNL Kuniyuki Iwashima
@ 2024-10-18  1:22 ` Kuniyuki Iwashima
  2024-10-18 13:54   ` Eric Dumazet
  2024-10-18  1:22 ` [PATCH v1 net-next 08/11] rtnetlink: Define rtnl_net_lock() Kuniyuki Iwashima
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 27+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-18  1:22 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

Since commit 1675f385213e ("ipv4: Namespacify IPv4 address GC."),
check_lifetime() works on a per-netns basis.

Let's use rtnl_net_lock() and rtnl_net_dereference().

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

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index cbda22eb8d06..f8e232dbb96a 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -756,7 +756,8 @@ static void check_lifetime(struct work_struct *work)
 		rcu_read_unlock();
 		if (!change_needed)
 			continue;
-		rtnl_lock();
+
+		rtnl_net_lock(net);
 		hlist_for_each_entry_safe(ifa, n, head, addr_lst) {
 			unsigned long age;
 
@@ -773,7 +774,7 @@ static void check_lifetime(struct work_struct *work)
 				struct in_ifaddr *tmp;
 
 				ifap = &ifa->ifa_dev->ifa_list;
-				tmp = rtnl_dereference(*ifap);
+				tmp = rtnl_net_dereference(net, *ifap);
 				while (tmp) {
 					if (tmp == ifa) {
 						inet_del_ifa(ifa->ifa_dev,
@@ -781,7 +782,7 @@ static void check_lifetime(struct work_struct *work)
 						break;
 					}
 					ifap = &tmp->ifa_next;
-					tmp = rtnl_dereference(*ifap);
+					tmp = rtnl_net_dereference(net, *ifap);
 				}
 			} else if (ifa->ifa_preferred_lft !=
 				   INFINITY_LIFE_TIME &&
@@ -791,7 +792,7 @@ static void check_lifetime(struct work_struct *work)
 				rtmsg_ifa(RTM_NEWADDR, ifa, NULL, 0);
 			}
 		}
-		rtnl_unlock();
+		rtnl_net_unlock(net);
 	}
 
 	next_sec = round_jiffies_up(next);
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v1 net-next 08/11] rtnetlink: Define rtnl_net_lock().
  2024-10-18  1:22 [PATCH v1 net-next 00/11] ipv4: Convert RTM_{NEW,DEL}ADDR and more to per-netns RTNL Kuniyuki Iwashima
                   ` (6 preceding siblings ...)
  2024-10-18  1:22 ` [PATCH v1 net-next 07/11] ipv4: Convert check_lifetime() " Kuniyuki Iwashima
@ 2024-10-18  1:22 ` Kuniyuki Iwashima
  2024-10-18 13:55   ` Eric Dumazet
  2024-10-18  1:22 ` [PATCH v1 net-next 09/11] ipv4: Convert devinet_sysctl_forward() to per-netns RTNL Kuniyuki Iwashima
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 27+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-18  1:22 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

We will need the per-netns version of rtnl_trylock().

rtnl_net_trylock() calls __rtnl_net_lock() only when rtnl_trylock()
successfully holds RTNL.

When RTNL is removed, we will use mutex_trylock() for per-netns RTNL.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 include/linux/rtnetlink.h |  6 ++++++
 net/core/rtnetlink.c      | 11 +++++++++++
 2 files changed, 17 insertions(+)

diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index 8468a4ce8510..b34d610b1249 100644
--- a/include/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -101,6 +101,7 @@ void __rtnl_net_lock(struct net *net);
 void __rtnl_net_unlock(struct net *net);
 void rtnl_net_lock(struct net *net);
 void rtnl_net_unlock(struct net *net);
+int rtnl_net_trylock(struct net *net);
 int rtnl_net_lock_cmp_fn(const struct lockdep_map *a, const struct lockdep_map *b);
 
 bool rtnl_net_is_locked(struct net *net);
@@ -132,6 +133,11 @@ static inline void rtnl_net_unlock(struct net *net)
 	rtnl_unlock();
 }
 
+static inline int rtnl_net_trylock(struct net *net)
+{
+	return rtnl_trylock();
+}
+
 static inline void ASSERT_RTNL_NET(struct net *net)
 {
 	ASSERT_RTNL();
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index a9c92392fb1d..bb4927da0275 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -210,6 +210,17 @@ void rtnl_net_unlock(struct net *net)
 }
 EXPORT_SYMBOL(rtnl_net_unlock);
 
+int rtnl_net_trylock(struct net *net)
+{
+	int ret = rtnl_trylock();
+
+	if (ret)
+		__rtnl_net_lock(net);
+
+	return ret;
+}
+EXPORT_SYMBOL(rtnl_net_trylock);
+
 static int rtnl_net_cmp_locks(const struct net *net_a, const struct net *net_b)
 {
 	if (net_eq(net_a, net_b))
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v1 net-next 09/11] ipv4: Convert devinet_sysctl_forward() to per-netns RTNL.
  2024-10-18  1:22 [PATCH v1 net-next 00/11] ipv4: Convert RTM_{NEW,DEL}ADDR and more to per-netns RTNL Kuniyuki Iwashima
                   ` (7 preceding siblings ...)
  2024-10-18  1:22 ` [PATCH v1 net-next 08/11] rtnetlink: Define rtnl_net_lock() Kuniyuki Iwashima
@ 2024-10-18  1:22 ` Kuniyuki Iwashima
  2024-10-18 13:56   ` Eric Dumazet
  2024-10-18  1:22 ` [PATCH v1 net-next 10/11] ipv4: Convert devinet_ioctl() to per-netns RTNL except for SIOCSIFFLAGS Kuniyuki Iwashima
  2024-10-18  1:22 ` [PATCH v1 net-next 11/11] ipv4: Convert devinet_ioctl to per-netns RTNL Kuniyuki Iwashima
  10 siblings, 1 reply; 27+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-18  1:22 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

devinet_sysctl_forward() touches only a single netns.

Let's use rtnl_trylock() and __in_dev_get_rtnl_net().

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

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index f8e232dbb96a..1cc2c2b4a10a 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -2380,7 +2380,7 @@ static void inet_forward_change(struct net *net)
 		if (on)
 			dev_disable_lro(dev);
 
-		in_dev = __in_dev_get_rtnl(dev);
+		in_dev = __in_dev_get_rtnl_net(dev);
 		if (in_dev) {
 			IN_DEV_CONF_SET(in_dev, FORWARDING, on);
 			inet_netconf_notify_devconf(net, RTM_NEWNETCONF,
@@ -2471,7 +2471,7 @@ static int devinet_sysctl_forward(const struct ctl_table *ctl, int write,
 
 	if (write && *valp != val) {
 		if (valp != &IPV4_DEVCONF_DFLT(net, FORWARDING)) {
-			if (!rtnl_trylock()) {
+			if (!rtnl_net_trylock(net)) {
 				/* Restore the original values before restarting */
 				*valp = val;
 				*ppos = pos;
@@ -2490,7 +2490,7 @@ static int devinet_sysctl_forward(const struct ctl_table *ctl, int write,
 							    idev->dev->ifindex,
 							    cnf);
 			}
-			rtnl_unlock();
+			rtnl_net_unlock(net);
 			rt_cache_flush(net);
 		} else
 			inet_netconf_notify_devconf(net, RTM_NEWNETCONF,
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v1 net-next 10/11] ipv4: Convert devinet_ioctl() to per-netns RTNL except for SIOCSIFFLAGS.
  2024-10-18  1:22 [PATCH v1 net-next 00/11] ipv4: Convert RTM_{NEW,DEL}ADDR and more to per-netns RTNL Kuniyuki Iwashima
                   ` (8 preceding siblings ...)
  2024-10-18  1:22 ` [PATCH v1 net-next 09/11] ipv4: Convert devinet_sysctl_forward() to per-netns RTNL Kuniyuki Iwashima
@ 2024-10-18  1:22 ` Kuniyuki Iwashima
  2024-10-18 13:56   ` Eric Dumazet
  2024-10-18  1:22 ` [PATCH v1 net-next 11/11] ipv4: Convert devinet_ioctl to per-netns RTNL Kuniyuki Iwashima
  10 siblings, 1 reply; 27+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-18  1:22 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

Basically, devinet_ioctl() operates on a single netns.

However, ioctl(SIOCSIFFLAGS) will trigger the netdev notifier
that could touch another netdev in different netns.

Let's use per-netns RTNL helper in devinet_ioctl() and place
ASSERT_RTNL() for SIOCSIFFLAGS.

We will remove ASSERT_RTNL() once RTM_SETLINK and RTM_DELLINK
are converted.

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

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 1cc2c2b4a10a..f4790859ea69 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -574,9 +574,7 @@ static int inet_insert_ifa(struct in_ifaddr *ifa)
 
 static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa)
 {
-	struct in_device *in_dev = __in_dev_get_rtnl(dev);
-
-	ASSERT_RTNL();
+	struct in_device *in_dev = __in_dev_get_rtnl_net(dev);
 
 	ipv4_devconf_setall(in_dev);
 	neigh_parms_data_state_setall(in_dev->arp_parms);
@@ -1114,7 +1112,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr)
 		goto out;
 	}
 
-	rtnl_lock();
+	rtnl_net_lock(net);
 
 	ret = -ENODEV;
 	dev = __dev_get_by_name(net, ifr->ifr_name);
@@ -1124,7 +1122,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr)
 	if (colon)
 		*colon = ':';
 
-	in_dev = __in_dev_get_rtnl(dev);
+	in_dev = __in_dev_get_rtnl_net(dev);
 	if (in_dev) {
 		if (tryaddrmatch) {
 			/* Matthias Andree */
@@ -1134,7 +1132,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr)
 			   This is checked above. */
 
 			for (ifap = &in_dev->ifa_list;
-			     (ifa = rtnl_dereference(*ifap)) != NULL;
+			     (ifa = rtnl_net_dereference(net, *ifap)) != NULL;
 			     ifap = &ifa->ifa_next) {
 				if (!strcmp(ifr->ifr_name, ifa->ifa_label) &&
 				    sin_orig.sin_addr.s_addr ==
@@ -1148,7 +1146,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr)
 		   comparing just the label */
 		if (!ifa) {
 			for (ifap = &in_dev->ifa_list;
-			     (ifa = rtnl_dereference(*ifap)) != NULL;
+			     (ifa = rtnl_net_dereference(net, *ifap)) != NULL;
 			     ifap = &ifa->ifa_next)
 				if (!strcmp(ifr->ifr_name, ifa->ifa_label))
 					break;
@@ -1190,6 +1188,9 @@ int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr)
 				inet_del_ifa(in_dev, ifap, 1);
 			break;
 		}
+
+		/* NETDEV_UP/DOWN/CHANGE could touch a peer dev */
+		ASSERT_RTNL();
 		ret = dev_change_flags(dev, ifr->ifr_flags, NULL);
 		break;
 
@@ -1291,7 +1292,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr)
 		break;
 	}
 done:
-	rtnl_unlock();
+	rtnl_net_unlock(net);
 out:
 	return ret;
 }
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v1 net-next 11/11] ipv4: Convert devinet_ioctl to per-netns RTNL.
  2024-10-18  1:22 [PATCH v1 net-next 00/11] ipv4: Convert RTM_{NEW,DEL}ADDR and more to per-netns RTNL Kuniyuki Iwashima
                   ` (9 preceding siblings ...)
  2024-10-18  1:22 ` [PATCH v1 net-next 10/11] ipv4: Convert devinet_ioctl() to per-netns RTNL except for SIOCSIFFLAGS Kuniyuki Iwashima
@ 2024-10-18  1:22 ` Kuniyuki Iwashima
  2024-10-18 13:57   ` Eric Dumazet
  2024-10-20  3:07   ` kernel test robot
  10 siblings, 2 replies; 27+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-18  1:22 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

ioctl(SIOCGIFCONF) calls dev_ifconf() that operates on the current netns.

Let's use per-netns RTNL helpers in dev_ifconf() and inet_gifconf().

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 net/core/dev_ioctl.c | 6 +++---
 net/ipv4/devinet.c   | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index 473c437b6b53..46d43b950471 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -64,7 +64,7 @@ int dev_ifconf(struct net *net, struct ifconf __user *uifc)
 	}
 
 	/* Loop over the interfaces, and write an info block for each. */
-	rtnl_lock();
+	rtnl_net_lock(net);
 	for_each_netdev(net, dev) {
 		if (!pos)
 			done = inet_gifconf(dev, NULL, 0, size);
@@ -72,12 +72,12 @@ int dev_ifconf(struct net *net, struct ifconf __user *uifc)
 			done = inet_gifconf(dev, pos + total,
 					    len - total, size);
 		if (done < 0) {
-			rtnl_unlock();
+			rtnl_net_unlock(net);
 			return -EFAULT;
 		}
 		total += done;
 	}
-	rtnl_unlock();
+	rtnl_net_unlock(net);
 
 	return put_user(total, &uifc->ifc_len);
 }
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index f4790859ea69..6089d9255d31 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1299,7 +1299,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr)
 
 int inet_gifconf(struct net_device *dev, char __user *buf, int len, int size)
 {
-	struct in_device *in_dev = __in_dev_get_rtnl(dev);
+	struct in_device *in_dev = __in_dev_get_rtnl_net(dev);
 	const struct in_ifaddr *ifa;
 	struct ifreq ifr;
 	int done = 0;
@@ -1310,7 +1310,7 @@ int inet_gifconf(struct net_device *dev, char __user *buf, int len, int size)
 	if (!in_dev)
 		goto out;
 
-	in_dev_for_each_ifa_rtnl(ifa, in_dev) {
+	in_dev_for_each_ifa_rtnl_net(dev_net(dev), ifa, in_dev) {
 		if (!buf) {
 			done += size;
 			continue;
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH v1 net-next 01/11] rtnetlink: Define RTNL_FLAG_DOIT_PERNET for per-netns RTNL doit().
  2024-10-18  1:22 ` [PATCH v1 net-next 01/11] rtnetlink: Define RTNL_FLAG_DOIT_PERNET for per-netns RTNL doit() Kuniyuki Iwashima
@ 2024-10-18 13:48   ` Eric Dumazet
  0 siblings, 0 replies; 27+ messages in thread
From: Eric Dumazet @ 2024-10-18 13:48 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Kuniyuki Iwashima, netdev

On Fri, Oct 18, 2024 at 3:23 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote:
>
> We will push RTNL down to each doit() as rtnl_net_lock().
>
> We can use RTNL_FLAG_DOIT_UNLOCKED to call doit() without RTNL, but doit()
> will still hold RTNL.
>
> Let's define RTNL_FLAG_DOIT_PERNET as an alias of RTNL_FLAG_DOIT_UNLOCKED.
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>

Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v1 net-next 02/11] ipv4: Factorise RTM_NEWADDR validation to inet_validate_rtm().
  2024-10-18  1:22 ` [PATCH v1 net-next 02/11] ipv4: Factorise RTM_NEWADDR validation to inet_validate_rtm() Kuniyuki Iwashima
@ 2024-10-18 13:50   ` Eric Dumazet
  0 siblings, 0 replies; 27+ messages in thread
From: Eric Dumazet @ 2024-10-18 13:50 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Kuniyuki Iwashima, netdev

On Fri, Oct 18, 2024 at 3:23 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote:
>
> rtm_to_ifaddr() validates some attributes, looks up a netdev,
> allocates struct in_ifaddr, and validates IFA_CACHEINFO.
>
> There is no reason to delay IFA_CACHEINFO validation.
>
> We will push RTNL down to inet_rtm_newaddr(), and then we want
> to complete rtnetlink validation before rtnl_net_lock().
>
> Let's factorise the validation parts.
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>

Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v1 net-next 03/11] ipv4: Don't allocate ifa for 0.0.0.0 in inet_rtm_newaddr().
  2024-10-18  1:22 ` [PATCH v1 net-next 03/11] ipv4: Don't allocate ifa for 0.0.0.0 in inet_rtm_newaddr() Kuniyuki Iwashima
@ 2024-10-18 13:51   ` Eric Dumazet
  0 siblings, 0 replies; 27+ messages in thread
From: Eric Dumazet @ 2024-10-18 13:51 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Kuniyuki Iwashima, netdev

On Fri, Oct 18, 2024 at 3:23 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote:
>
> When we pass 0.0.0.0 to __inet_insert_ifa(), it frees ifa and returns 0.
>
> We can do this check much earlier for RTM_NEWADDR even before allocating
> struct in_ifaddr.
>
> Let's move the validation to
>
>   1. inet_insert_ifa() for ioctl()
>   2. inet_rtm_newaddr() for RTM_NEWADDR
>
> Now, we can remove the same check in find_matching_ifa().
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>

Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v1 net-next 04/11] ipv4: Convert RTM_NEWADDR to per-netns RTNL.
  2024-10-18  1:22 ` [PATCH v1 net-next 04/11] ipv4: Convert RTM_NEWADDR to per-netns RTNL Kuniyuki Iwashima
@ 2024-10-18 13:51   ` Eric Dumazet
  0 siblings, 0 replies; 27+ messages in thread
From: Eric Dumazet @ 2024-10-18 13:51 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Kuniyuki Iwashima, netdev

On Fri, Oct 18, 2024 at 3:24 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote:
>
> The address hash table and GC are already namespacified.
>
> Let's push down RTNL into inet_rtm_newaddr() as rtnl_net_lock().
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>

Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v1 net-next 05/11] ipv4: Use per-netns RTNL helpers in inet_rtm_newaddr().
  2024-10-18  1:22 ` [PATCH v1 net-next 05/11] ipv4: Use per-netns RTNL helpers in inet_rtm_newaddr() Kuniyuki Iwashima
@ 2024-10-18 13:52   ` Eric Dumazet
  2024-10-19 20:03   ` kernel test robot
  1 sibling, 0 replies; 27+ messages in thread
From: Eric Dumazet @ 2024-10-18 13:52 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Kuniyuki Iwashima, netdev

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>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v1 net-next 06/11] ipv4: Convert RTM_DELADDR to per-netns RTNL.
  2024-10-18  1:22 ` [PATCH v1 net-next 06/11] ipv4: Convert RTM_DELADDR to per-netns RTNL Kuniyuki Iwashima
@ 2024-10-18 13:53   ` Eric Dumazet
  2024-10-19 22:59   ` kernel test robot
  1 sibling, 0 replies; 27+ messages in thread
From: Eric Dumazet @ 2024-10-18 13:53 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Kuniyuki Iwashima, netdev

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>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v1 net-next 07/11] ipv4: Convert check_lifetime() to per-netns RTNL.
  2024-10-18  1:22 ` [PATCH v1 net-next 07/11] ipv4: Convert check_lifetime() " Kuniyuki Iwashima
@ 2024-10-18 13:54   ` Eric Dumazet
  0 siblings, 0 replies; 27+ messages in thread
From: Eric Dumazet @ 2024-10-18 13:54 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Kuniyuki Iwashima, netdev

On Fri, Oct 18, 2024 at 3:24 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote:
>
> Since commit 1675f385213e ("ipv4: Namespacify IPv4 address GC."),
> check_lifetime() works on a per-netns basis.
>
> Let's use rtnl_net_lock() and rtnl_net_dereference().
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>

Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v1 net-next 08/11] rtnetlink: Define rtnl_net_lock().
  2024-10-18  1:22 ` [PATCH v1 net-next 08/11] rtnetlink: Define rtnl_net_lock() Kuniyuki Iwashima
@ 2024-10-18 13:55   ` Eric Dumazet
  0 siblings, 0 replies; 27+ messages in thread
From: Eric Dumazet @ 2024-10-18 13:55 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Kuniyuki Iwashima, netdev

On Fri, Oct 18, 2024 at 3:25 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote:
>
> We will need the per-netns version of rtnl_trylock().
>
> rtnl_net_trylock() calls __rtnl_net_lock() only when rtnl_trylock()
> successfully holds RTNL.
>
> When RTNL is removed, we will use mutex_trylock() for per-netns RTNL.
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> ---

Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v1 net-next 09/11] ipv4: Convert devinet_sysctl_forward() to per-netns RTNL.
  2024-10-18  1:22 ` [PATCH v1 net-next 09/11] ipv4: Convert devinet_sysctl_forward() to per-netns RTNL Kuniyuki Iwashima
@ 2024-10-18 13:56   ` Eric Dumazet
  0 siblings, 0 replies; 27+ messages in thread
From: Eric Dumazet @ 2024-10-18 13:56 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Kuniyuki Iwashima, netdev

On Fri, Oct 18, 2024 at 3:25 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote:
>
> devinet_sysctl_forward() touches only a single netns.
>
> Let's use rtnl_trylock() and __in_dev_get_rtnl_net().
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>

Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v1 net-next 10/11] ipv4: Convert devinet_ioctl() to per-netns RTNL except for SIOCSIFFLAGS.
  2024-10-18  1:22 ` [PATCH v1 net-next 10/11] ipv4: Convert devinet_ioctl() to per-netns RTNL except for SIOCSIFFLAGS Kuniyuki Iwashima
@ 2024-10-18 13:56   ` Eric Dumazet
  0 siblings, 0 replies; 27+ messages in thread
From: Eric Dumazet @ 2024-10-18 13:56 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Kuniyuki Iwashima, netdev

On Fri, Oct 18, 2024 at 3:25 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote:
>
> Basically, devinet_ioctl() operates on a single netns.
>
> However, ioctl(SIOCSIFFLAGS) will trigger the netdev notifier
> that could touch another netdev in different netns.
>
> Let's use per-netns RTNL helper in devinet_ioctl() and place
> ASSERT_RTNL() for SIOCSIFFLAGS.
>
> We will remove ASSERT_RTNL() once RTM_SETLINK and RTM_DELLINK
> are converted.
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>

Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v1 net-next 11/11] ipv4: Convert devinet_ioctl to per-netns RTNL.
  2024-10-18  1:22 ` [PATCH v1 net-next 11/11] ipv4: Convert devinet_ioctl to per-netns RTNL Kuniyuki Iwashima
@ 2024-10-18 13:57   ` Eric Dumazet
  2024-10-20  3:07   ` kernel test robot
  1 sibling, 0 replies; 27+ messages in thread
From: Eric Dumazet @ 2024-10-18 13:57 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Kuniyuki Iwashima, netdev

On Fri, Oct 18, 2024 at 3:26 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote:
>
> ioctl(SIOCGIFCONF) calls dev_ifconf() that operates on the current netns.
>
> Let's use per-netns RTNL helpers in dev_ifconf() and inet_gifconf().
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>

Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v1 net-next 05/11] ipv4: Use per-netns RTNL helpers in inet_rtm_newaddr().
  2024-10-18  1:22 ` [PATCH v1 net-next 05/11] ipv4: Use per-netns RTNL helpers in inet_rtm_newaddr() Kuniyuki Iwashima
  2024-10-18 13:52   ` Eric Dumazet
@ 2024-10-19 20:03   ` kernel test robot
  2024-10-19 20:59     ` Kuniyuki Iwashima
  1 sibling, 1 reply; 27+ messages in thread
From: kernel test robot @ 2024-10-19 20:03 UTC (permalink / raw)
  To: Kuniyuki Iwashima, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, David Ahern
  Cc: oe-kbuild-all, netdev, Kuniyuki Iwashima

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	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v1 net-next 05/11] ipv4: Use per-netns RTNL helpers in inet_rtm_newaddr().
  2024-10-19 20:03   ` kernel test robot
@ 2024-10-19 20:59     ` Kuniyuki Iwashima
  0 siblings, 0 replies; 27+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-19 20:59 UTC (permalink / raw)
  To: lkp; +Cc: davem, dsahern, edumazet, kuba, kuniyu, netdev, oe-kbuild-all,
	pabeni

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	

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v1 net-next 06/11] ipv4: Convert RTM_DELADDR to per-netns RTNL.
  2024-10-18  1:22 ` [PATCH v1 net-next 06/11] ipv4: Convert RTM_DELADDR to per-netns RTNL Kuniyuki Iwashima
  2024-10-18 13:53   ` Eric Dumazet
@ 2024-10-19 22:59   ` kernel test robot
  1 sibling, 0 replies; 27+ messages in thread
From: kernel test robot @ 2024-10-19 22:59 UTC (permalink / raw)
  To: Kuniyuki Iwashima, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, David Ahern
  Cc: oe-kbuild-all, netdev, Kuniyuki Iwashima

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	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v1 net-next 11/11] ipv4: Convert devinet_ioctl to per-netns RTNL.
  2024-10-18  1:22 ` [PATCH v1 net-next 11/11] ipv4: Convert devinet_ioctl to per-netns RTNL Kuniyuki Iwashima
  2024-10-18 13:57   ` Eric Dumazet
@ 2024-10-20  3:07   ` kernel test robot
  1 sibling, 0 replies; 27+ messages in thread
From: kernel test robot @ 2024-10-20  3:07 UTC (permalink / raw)
  To: Kuniyuki Iwashima, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, David Ahern
  Cc: oe-kbuild-all, netdev, Kuniyuki Iwashima

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-12-kuniyu%40amazon.com
patch subject: [PATCH v1 net-next 11/11] ipv4: Convert devinet_ioctl to per-netns RTNL.
config: x86_64-randconfig-122-20241019 (https://download.01.org/0day-ci/archive/20241020/202410201022.bZkEgzK5-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/202410201022.bZkEgzK5-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/202410201022.bZkEgzK5-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
   net/ipv4/devinet.c:674:47: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu * @@
   net/ipv4/devinet.c:674:47: sparse:     expected void *p
   net/ipv4/devinet.c:674:47: sparse:     got struct in_ifaddr [noderef] __rcu *
   net/ipv4/devinet.c:775:65: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu * @@
   net/ipv4/devinet.c:775:65: sparse:     expected void *p
   net/ipv4/devinet.c:775:65: sparse:     got struct in_ifaddr [noderef] __rcu *
   net/ipv4/devinet.c:783:73: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu * @@
   net/ipv4/devinet.c:783:73: sparse:     expected void *p
   net/ipv4/devinet.c:783:73: sparse:     got struct in_ifaddr [noderef] __rcu *
   net/ipv4/devinet.c:945: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:945:9: sparse:     expected void *p
   net/ipv4/devinet.c:945:9: sparse:     got struct in_ifaddr [noderef] __rcu *ifa_list
   net/ipv4/devinet.c:945: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:945:9: sparse:     expected void *p
   net/ipv4/devinet.c:945:9: sparse:     got struct in_ifaddr [noderef] __rcu *ifa_next
   net/ipv4/devinet.c:1135:63: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu * @@
   net/ipv4/devinet.c:1135:63: sparse:     expected void *p
   net/ipv4/devinet.c:1135:63: sparse:     got struct in_ifaddr [noderef] __rcu *
   net/ipv4/devinet.c:1149:63: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu * @@
   net/ipv4/devinet.c:1149:63: sparse:     expected void *p
   net/ipv4/devinet.c:1149:63: sparse:     got struct in_ifaddr [noderef] __rcu *
   net/ipv4/devinet.c:1313: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:1313:9: sparse:     expected void *p
   net/ipv4/devinet.c:1313:9: sparse:     got struct in_ifaddr [noderef] __rcu *ifa_list
>> net/ipv4/devinet.c:1313:9: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu *const ifa_next @@
   net/ipv4/devinet.c:1313:9: sparse:     expected void *p
   net/ipv4/devinet.c:1313:9: sparse:     got struct in_ifaddr [noderef] __rcu *const 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:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *

vim +1313 net/ipv4/devinet.c

  1299	
  1300	int inet_gifconf(struct net_device *dev, char __user *buf, int len, int size)
  1301	{
  1302		struct in_device *in_dev = __in_dev_get_rtnl_net(dev);
  1303		const struct in_ifaddr *ifa;
  1304		struct ifreq ifr;
  1305		int done = 0;
  1306	
  1307		if (WARN_ON(size > sizeof(struct ifreq)))
  1308			goto out;
  1309	
  1310		if (!in_dev)
  1311			goto out;
  1312	
> 1313		in_dev_for_each_ifa_rtnl_net(dev_net(dev), ifa, in_dev) {
  1314			if (!buf) {
  1315				done += size;
  1316				continue;
  1317			}
  1318			if (len < size)
  1319				break;
  1320			memset(&ifr, 0, sizeof(struct ifreq));
  1321			strcpy(ifr.ifr_name, ifa->ifa_label);
  1322	
  1323			(*(struct sockaddr_in *)&ifr.ifr_addr).sin_family = AF_INET;
  1324			(*(struct sockaddr_in *)&ifr.ifr_addr).sin_addr.s_addr =
  1325									ifa->ifa_local;
  1326	
  1327			if (copy_to_user(buf + done, &ifr, size)) {
  1328				done = -EFAULT;
  1329				break;
  1330			}
  1331			len  -= size;
  1332			done += size;
  1333		}
  1334	out:
  1335		return done;
  1336	}
  1337	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2024-10-20  3:08 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-18  1:22 [PATCH v1 net-next 00/11] ipv4: Convert RTM_{NEW,DEL}ADDR and more to per-netns RTNL Kuniyuki Iwashima
2024-10-18  1:22 ` [PATCH v1 net-next 01/11] rtnetlink: Define RTNL_FLAG_DOIT_PERNET for per-netns RTNL doit() Kuniyuki Iwashima
2024-10-18 13:48   ` Eric Dumazet
2024-10-18  1:22 ` [PATCH v1 net-next 02/11] ipv4: Factorise RTM_NEWADDR validation to inet_validate_rtm() Kuniyuki Iwashima
2024-10-18 13:50   ` Eric Dumazet
2024-10-18  1:22 ` [PATCH v1 net-next 03/11] ipv4: Don't allocate ifa for 0.0.0.0 in inet_rtm_newaddr() Kuniyuki Iwashima
2024-10-18 13:51   ` Eric Dumazet
2024-10-18  1:22 ` [PATCH v1 net-next 04/11] ipv4: Convert RTM_NEWADDR to per-netns RTNL Kuniyuki Iwashima
2024-10-18 13:51   ` Eric Dumazet
2024-10-18  1:22 ` [PATCH v1 net-next 05/11] ipv4: Use per-netns RTNL helpers in inet_rtm_newaddr() Kuniyuki Iwashima
2024-10-18 13:52   ` Eric Dumazet
2024-10-19 20:03   ` kernel test robot
2024-10-19 20:59     ` Kuniyuki Iwashima
2024-10-18  1:22 ` [PATCH v1 net-next 06/11] ipv4: Convert RTM_DELADDR to per-netns RTNL Kuniyuki Iwashima
2024-10-18 13:53   ` Eric Dumazet
2024-10-19 22:59   ` kernel test robot
2024-10-18  1:22 ` [PATCH v1 net-next 07/11] ipv4: Convert check_lifetime() " Kuniyuki Iwashima
2024-10-18 13:54   ` Eric Dumazet
2024-10-18  1:22 ` [PATCH v1 net-next 08/11] rtnetlink: Define rtnl_net_lock() Kuniyuki Iwashima
2024-10-18 13:55   ` Eric Dumazet
2024-10-18  1:22 ` [PATCH v1 net-next 09/11] ipv4: Convert devinet_sysctl_forward() to per-netns RTNL Kuniyuki Iwashima
2024-10-18 13:56   ` Eric Dumazet
2024-10-18  1:22 ` [PATCH v1 net-next 10/11] ipv4: Convert devinet_ioctl() to per-netns RTNL except for SIOCSIFFLAGS Kuniyuki Iwashima
2024-10-18 13:56   ` Eric Dumazet
2024-10-18  1:22 ` [PATCH v1 net-next 11/11] ipv4: Convert devinet_ioctl to per-netns RTNL Kuniyuki Iwashima
2024-10-18 13:57   ` Eric Dumazet
2024-10-20  3:07   ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).