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 9/9] phonet: Don't hold RTNL for route_doit().
Date: Thu, 17 Oct 2024 11:31:40 -0700	[thread overview]
Message-ID: <20241017183140.43028-10-kuniyu@amazon.com> (raw)
In-Reply-To: <20241017183140.43028-1-kuniyu@amazon.com>

Now only __dev_get_by_index() depends on RTNL in route_doit().

Let's use dev_get_by_index_rcu() and register route_doit() with
RTNL_FLAG_DOIT_UNLOCKED.

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

diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c
index bfec5bd639b6..ca1f04e4a2d9 100644
--- a/net/phonet/pn_netlink.c
+++ b/net/phonet/pn_netlink.c
@@ -245,8 +245,6 @@ static int route_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
 	if (!netlink_capable(skb, CAP_SYS_ADMIN))
 		return -EPERM;
 
-	ASSERT_RTNL();
-
 	err = nlmsg_parse_deprecated(nlh, sizeof(*rtm), tb, RTA_MAX,
 				     rtm_phonet_policy, extack);
 	if (err < 0)
@@ -262,16 +260,25 @@ static int route_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
 		return -EINVAL;
 
 	ifindex = nla_get_u32(tb[RTA_OIF]);
-	dev = __dev_get_by_index(net, ifindex);
-	if (dev == NULL)
+
+	rcu_read_lock();
+
+	dev = dev_get_by_index_rcu(net, ifindex);
+	if (!dev) {
+		rcu_read_unlock();
 		return -ENODEV;
+	}
 
 	if (nlh->nlmsg_type == RTM_NEWROUTE)
 		err = phonet_route_add(dev, dst);
 	else
 		err = phonet_route_del(dev, dst);
+
+	rcu_read_unlock();
+
 	if (!err)
 		rtm_phonet_notify(net, nlh->nlmsg_type, ifindex, dst);
+
 	return err;
 }
 
@@ -308,9 +315,9 @@ static const struct rtnl_msg_handler phonet_rtnl_msg_handlers[] __initdata_or_mo
 	{.owner = THIS_MODULE, .protocol = PF_PHONET, .msgtype = RTM_GETADDR,
 	 .dumpit = getaddr_dumpit, .flags = RTNL_FLAG_DUMP_UNLOCKED},
 	{.owner = THIS_MODULE, .protocol = PF_PHONET, .msgtype = RTM_NEWROUTE,
-	 .doit = route_doit},
+	 .doit = route_doit, .flags = RTNL_FLAG_DOIT_UNLOCKED},
 	{.owner = THIS_MODULE, .protocol = PF_PHONET, .msgtype = RTM_DELROUTE,
-	 .doit = route_doit},
+	 .doit = route_doit, .flags = RTNL_FLAG_DOIT_UNLOCKED},
 	{.owner = THIS_MODULE, .protocol = PF_PHONET, .msgtype = RTM_GETROUTE,
 	 .dumpit = route_dumpit, .flags = RTNL_FLAG_DUMP_UNLOCKED},
 };
-- 
2.39.5 (Apple Git-154)


  parent reply	other threads:[~2024-10-17 18:34 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 ` [PATCH v1 net-next 2/9] phonet: Pass net and ifindex to phonet_address_notify() Kuniyuki Iwashima
2024-10-23 15:25   ` 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 ` Kuniyuki Iwashima [this message]
2024-10-23 15:34   ` [PATCH v1 net-next 9/9] phonet: Don't hold RTNL for route_doit() 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-10-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).