* [PATCH net-next] phonet: no longer hold RTNL in route_dumpit()
@ 2024-05-06 12:11 Eric Dumazet
2024-05-06 17:23 ` Rémi Denis-Courmont
2024-05-06 18:26 ` Jakub Kicinski
0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2024-05-06 12:11 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, eric.dumazet, Eric Dumazet, Remi Denis-Courmont
route_dumpit() already relies on RCU, RTNL is not needed.
Also change return value at the end of a dump.
This allows NLMSG_DONE to be appended to the current
skb at the end of a dump, saving a couple of recvmsg()
system calls.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Remi Denis-Courmont <courmisch@gmail.com>
---
net/phonet/pn_netlink.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c
index 59aebe29689077bfa77d37516aea4617fe3b8a50..c11764ff72d6ac86e643123e2c49de6f0758bf97 100644
--- a/net/phonet/pn_netlink.c
+++ b/net/phonet/pn_netlink.c
@@ -178,7 +178,7 @@ static int fill_route(struct sk_buff *skb, struct net_device *dev, u8 dst,
rtm->rtm_type = RTN_UNICAST;
rtm->rtm_flags = 0;
if (nla_put_u8(skb, RTA_DST, dst) ||
- nla_put_u32(skb, RTA_OIF, dev->ifindex))
+ nla_put_u32(skb, RTA_OIF, READ_ONCE(dev->ifindex)))
goto nla_put_failure;
nlmsg_end(skb, nlh);
return 0;
@@ -263,6 +263,7 @@ static int route_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
static int route_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
{
struct net *net = sock_net(skb->sk);
+ int err = 0;
u8 addr;
rcu_read_lock();
@@ -272,16 +273,16 @@ static int route_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
if (!dev)
continue;
- if (fill_route(skb, dev, addr << 2, NETLINK_CB(cb->skb).portid,
- cb->nlh->nlmsg_seq, RTM_NEWROUTE) < 0)
- goto out;
+ err = fill_route(skb, dev, addr << 2,
+ NETLINK_CB(cb->skb).portid,
+ cb->nlh->nlmsg_seq, RTM_NEWROUTE);
+ if (err < 0)
+ break;;
}
-
-out:
rcu_read_unlock();
cb->args[0] = addr;
- return skb->len;
+ return err;
}
int __init phonet_netlink_register(void)
@@ -301,6 +302,6 @@ int __init phonet_netlink_register(void)
rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_DELROUTE,
route_doit, NULL, 0);
rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_GETROUTE,
- NULL, route_dumpit, 0);
+ NULL, route_dumpit, RTNL_FLAG_DUMP_UNLOCKED);
return 0;
}
--
2.45.0.rc1.225.g2a3ae87e7f-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] phonet: no longer hold RTNL in route_dumpit()
2024-05-06 12:11 [PATCH net-next] phonet: no longer hold RTNL in route_dumpit() Eric Dumazet
@ 2024-05-06 17:23 ` Rémi Denis-Courmont
2024-05-06 18:26 ` Jakub Kicinski
1 sibling, 0 replies; 4+ messages in thread
From: Rémi Denis-Courmont @ 2024-05-06 17:23 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni, Eric Dumazet
Cc: netdev, eric.dumazet, Eric Dumazet
Le maanantaina 6. toukokuuta 2024, 15.11.56 EEST Eric Dumazet a écrit :
> route_dumpit() already relies on RCU, RTNL is not needed.
>
> Also change return value at the end of a dump.
> This allows NLMSG_DONE to be appended to the current
> skb at the end of a dump, saving a couple of recvmsg()
> system calls.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Remi Denis-Courmont <courmisch@gmail.com>
No objections from me, but TBH I am not familiar with the underlying RTNL
locking so my ack wouldn't be worth anything.
> ---
> net/phonet/pn_netlink.c | 17 +++++++++--------
> 1 file changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c
> index
> 59aebe29689077bfa77d37516aea4617fe3b8a50..c11764ff72d6ac86e643123e2c49de6f0
> 758bf97 100644 --- a/net/phonet/pn_netlink.c
> +++ b/net/phonet/pn_netlink.c
> @@ -178,7 +178,7 @@ static int fill_route(struct sk_buff *skb, struct
> net_device *dev, u8 dst, rtm->rtm_type = RTN_UNICAST;
> rtm->rtm_flags = 0;
> if (nla_put_u8(skb, RTA_DST, dst) ||
> - nla_put_u32(skb, RTA_OIF, dev->ifindex))
> + nla_put_u32(skb, RTA_OIF, READ_ONCE(dev->ifindex)))
> goto nla_put_failure;
> nlmsg_end(skb, nlh);
> return 0;
> @@ -263,6 +263,7 @@ static int route_doit(struct sk_buff *skb, struct
> nlmsghdr *nlh, static int route_dumpit(struct sk_buff *skb, struct
> netlink_callback *cb) {
> struct net *net = sock_net(skb->sk);
> + int err = 0;
> u8 addr;
>
> rcu_read_lock();
> @@ -272,16 +273,16 @@ static int route_dumpit(struct sk_buff *skb, struct
> netlink_callback *cb) if (!dev)
> continue;
>
> - if (fill_route(skb, dev, addr << 2, NETLINK_CB(cb-
>skb).portid,
> - cb->nlh->nlmsg_seq, RTM_NEWROUTE) <
0)
> - goto out;
> + err = fill_route(skb, dev, addr << 2,
> + NETLINK_CB(cb->skb).portid,
> + cb->nlh->nlmsg_seq,
RTM_NEWROUTE);
> + if (err < 0)
> + break;;
> }
> -
> -out:
> rcu_read_unlock();
> cb->args[0] = addr;
>
> - return skb->len;
> + return err;
> }
>
> int __init phonet_netlink_register(void)
> @@ -301,6 +302,6 @@ int __init phonet_netlink_register(void)
> rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_DELROUTE,
> route_doit, NULL, 0);
> rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_GETROUTE,
> - NULL, route_dumpit, 0);
> + NULL, route_dumpit,
RTNL_FLAG_DUMP_UNLOCKED);
> return 0;
> }
--
Rémi Denis-Courmont
http://www.remlab.net/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] phonet: no longer hold RTNL in route_dumpit()
2024-05-06 12:11 [PATCH net-next] phonet: no longer hold RTNL in route_dumpit() Eric Dumazet
2024-05-06 17:23 ` Rémi Denis-Courmont
@ 2024-05-06 18:26 ` Jakub Kicinski
2024-05-06 18:45 ` Eric Dumazet
1 sibling, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2024-05-06 18:26 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Paolo Abeni, netdev, eric.dumazet,
Remi Denis-Courmont
On Mon, 6 May 2024 12:11:56 +0000 Eric Dumazet wrote:
> + if (err < 0)
> + break;;
coccicheck says:
net/phonet/pn_netlink.c:280:9-10: Unneeded semicolon
--
pw-bot: cr
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] phonet: no longer hold RTNL in route_dumpit()
2024-05-06 18:26 ` Jakub Kicinski
@ 2024-05-06 18:45 ` Eric Dumazet
0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2024-05-06 18:45 UTC (permalink / raw)
To: Jakub Kicinski
Cc: David S . Miller, Paolo Abeni, netdev, eric.dumazet,
Remi Denis-Courmont
On Mon, May 6, 2024 at 8:26 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Mon, 6 May 2024 12:11:56 +0000 Eric Dumazet wrote:
> > + if (err < 0)
> > + break;;
>
> coccicheck says:
>
> net/phonet/pn_netlink.c:280:9-10: Unneeded semicolon
Nice, thanks ! I will send a V2.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-06 18:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-06 12:11 [PATCH net-next] phonet: no longer hold RTNL in route_dumpit() Eric Dumazet
2024-05-06 17:23 ` Rémi Denis-Courmont
2024-05-06 18:26 ` Jakub Kicinski
2024-05-06 18:45 ` Eric Dumazet
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).