netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Remi Denis-Courmont <courmisch@gmail.com>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>,
	Kuniyuki Iwashima <kuni1840@gmail.com>, <netdev@vger.kernel.org>
Subject: [PATCH v1 net-next 2/9] phonet: Pass net and ifindex to phonet_address_notify().
Date: Thu, 17 Oct 2024 11:31:33 -0700	[thread overview]
Message-ID: <20241017183140.43028-3-kuniyu@amazon.com> (raw)
In-Reply-To: <20241017183140.43028-1-kuniyu@amazon.com>

Currently, phonet_address_notify() fetches netns and ifindex from dev.

Once addr_doit() is converted to RCU, phonet_address_notify() will be
called outside of RCU due to GFP_KERNEL, and dev will be unavailable
there.

Let's pass net and ifindex to phonet_address_notify().

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 include/net/phonet/pn_dev.h |  2 +-
 net/phonet/pn_dev.c         | 10 +++++++---
 net/phonet/pn_netlink.c     | 12 ++++++------
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/include/net/phonet/pn_dev.h b/include/net/phonet/pn_dev.h
index e9dc8dca5817..6b2102b4ece3 100644
--- a/include/net/phonet/pn_dev.h
+++ b/include/net/phonet/pn_dev.h
@@ -38,7 +38,7 @@ int phonet_address_add(struct net_device *dev, u8 addr);
 int phonet_address_del(struct net_device *dev, u8 addr);
 u8 phonet_address_get(struct net_device *dev, u8 addr);
 int phonet_address_lookup(struct net *net, u8 addr);
-void phonet_address_notify(int event, struct net_device *dev, u8 addr);
+void phonet_address_notify(struct net *net, int event, u32 ifindex, u8 addr);
 
 int phonet_route_add(struct net_device *dev, u8 daddr);
 int phonet_route_del(struct net_device *dev, u8 daddr);
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index cde671d29d5d..2e7d850dc726 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -98,10 +98,13 @@ static void phonet_device_destroy(struct net_device *dev)
 	mutex_unlock(&pndevs->lock);
 
 	if (pnd) {
+		struct net *net = dev_net(dev);
+		u32 ifindex = dev->ifindex;
 		u8 addr;
 
 		for_each_set_bit(addr, pnd->addrs, 64)
-			phonet_address_notify(RTM_DELADDR, dev, addr);
+			phonet_address_notify(net, RTM_DELADDR, ifindex, addr);
+
 		kfree(pnd);
 	}
 }
@@ -244,8 +247,9 @@ static int phonet_device_autoconf(struct net_device *dev)
 	ret = phonet_address_add(dev, req.ifr_phonet_autoconf.device);
 	if (ret)
 		return ret;
-	phonet_address_notify(RTM_NEWADDR, dev,
-				req.ifr_phonet_autoconf.device);
+
+	phonet_address_notify(dev_net(dev), RTM_NEWADDR, dev->ifindex,
+			      req.ifr_phonet_autoconf.device);
 	return 0;
 }
 
diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c
index 3205d2457477..23097085ad38 100644
--- a/net/phonet/pn_netlink.c
+++ b/net/phonet/pn_netlink.c
@@ -22,7 +22,7 @@
 static int fill_addr(struct sk_buff *skb, u32 ifindex, u8 addr,
 		     u32 portid, u32 seq, int event);
 
-void phonet_address_notify(int event, struct net_device *dev, u8 addr)
+void phonet_address_notify(struct net *net, int event, u32 ifindex, u8 addr)
 {
 	struct sk_buff *skb;
 	int err = -ENOBUFS;
@@ -32,17 +32,17 @@ void phonet_address_notify(int event, struct net_device *dev, u8 addr)
 	if (skb == NULL)
 		goto errout;
 
-	err = fill_addr(skb, dev->ifindex, addr, 0, 0, event);
+	err = fill_addr(skb, ifindex, addr, 0, 0, event);
 	if (err < 0) {
 		WARN_ON(err == -EMSGSIZE);
 		kfree_skb(skb);
 		goto errout;
 	}
-	rtnl_notify(skb, dev_net(dev), 0,
-		    RTNLGRP_PHONET_IFADDR, NULL, GFP_KERNEL);
+
+	rtnl_notify(skb, net, 0, RTNLGRP_PHONET_IFADDR, NULL, GFP_KERNEL);
 	return;
 errout:
-	rtnl_set_sk_err(dev_net(dev), RTNLGRP_PHONET_IFADDR, err);
+	rtnl_set_sk_err(net, RTNLGRP_PHONET_IFADDR, err);
 }
 
 static const struct nla_policy ifa_phonet_policy[IFA_MAX+1] = {
@@ -89,7 +89,7 @@ static int addr_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
 	else
 		err = phonet_address_del(dev, pnaddr);
 	if (!err)
-		phonet_address_notify(nlh->nlmsg_type, dev, pnaddr);
+		phonet_address_notify(net, nlh->nlmsg_type, ifm->ifa_index, pnaddr);
 	return err;
 }
 
-- 
2.39.5 (Apple Git-154)


  parent reply	other threads:[~2024-10-17 18:32 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-17 18:31 [PATCH v1 net-next 0/9] phonet: Convert all doit() and dumpit() to RCU Kuniyuki Iwashima
2024-10-17 18:31 ` [PATCH v1 net-next 1/9] phonet: Pass ifindex to fill_addr() Kuniyuki Iwashima
2024-10-23 15:24   ` Eric Dumazet
2024-10-17 18:31 ` Kuniyuki Iwashima [this message]
2024-10-23 15:25   ` [PATCH v1 net-next 2/9] phonet: Pass net and ifindex to phonet_address_notify() Eric Dumazet
2024-10-17 18:31 ` [PATCH v1 net-next 3/9] phonet: Convert phonet_device_list.lock to spinlock_t Kuniyuki Iwashima
2024-10-23 15:26   ` Eric Dumazet
2024-10-17 18:31 ` [PATCH v1 net-next 4/9] phonet: Don't hold RTNL for addr_doit() Kuniyuki Iwashima
2024-10-23 15:27   ` Eric Dumazet
2024-10-17 18:31 ` [PATCH v1 net-next 5/9] phonet: Don't hold RTNL for getaddr_dumpit() Kuniyuki Iwashima
2024-10-17 18:49   ` Rémi Denis-Courmont
2024-10-18 17:16     ` Kuniyuki Iwashima
2024-10-19  7:48       ` Rémi Denis-Courmont
2024-10-20  1:30         ` Kuniyuki Iwashima
2024-10-23 11:04         ` Paolo Abeni
2024-10-23 11:16           ` Paolo Abeni
2024-10-23 15:30   ` Eric Dumazet
2024-10-17 18:31 ` [PATCH v1 net-next 6/9] phonet: Pass ifindex to fill_route() Kuniyuki Iwashima
2024-10-23 15:30   ` Eric Dumazet
2024-10-17 18:31 ` [PATCH v1 net-next 7/9] phonet: Pass net and ifindex to rtm_phonet_notify() Kuniyuki Iwashima
2024-10-23 15:32   ` Eric Dumazet
2024-10-17 18:31 ` [PATCH v1 net-next 8/9] phonet: Convert phonet_routes.lock to spinlock_t Kuniyuki Iwashima
2024-10-23 15:33   ` Eric Dumazet
2024-10-17 18:31 ` [PATCH v1 net-next 9/9] phonet: Don't hold RTNL for route_doit() Kuniyuki Iwashima
2024-10-23 15:34   ` Eric Dumazet
2024-10-24 14:10 ` [PATCH v1 net-next 0/9] phonet: Convert all doit() and dumpit() to RCU patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241017183140.43028-3-kuniyu@amazon.com \
    --to=kuniyu@amazon.com \
    --cc=courmisch@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).