[PATCH net v4 2/2] arp: switch to dev_getbyhwaddr() in arp_req_set_public()

Breno Leitao posted 2 patches 10 months, 1 week ago
There is a newer version of this series
[PATCH net v4 2/2] arp: switch to dev_getbyhwaddr() in arp_req_set_public()
Posted by Breno Leitao 10 months, 1 week ago
The arp_req_set_public() function is called with the rtnl lock held,
which provides enough synchronization protection. This makes the RCU
variant of dev_getbyhwaddr() unnecessary. Switch to using the simpler
dev_getbyhwaddr() function since we already have the required rtnl
locking.

This change helps maintain consistency in the networking code by using
the appropriate helper function for the existing locking context.

Fixes: 941666c2e3e0 ("net: RCU conversion of dev_getbyhwaddr() and arp_ioctl()")
Suggested-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Breno Leitao <leitao@debian.org>
---
 net/ipv4/arp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index f23a1ec6694cb2f1bd60f28faa357fcad83c165a..814300eee39de12b959caf225f65d9190594bba9 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -1077,7 +1077,7 @@ static int arp_req_set_public(struct net *net, struct arpreq *r,
 	__be32 mask = ((struct sockaddr_in *)&r->arp_netmask)->sin_addr.s_addr;
 
 	if (!dev && (r->arp_flags & ATF_COM)) {
-		dev = dev_getbyhwaddr_rcu(net, r->arp_ha.sa_family,
+		dev = dev_getbyhwaddr(net, r->arp_ha.sa_family,
 				      r->arp_ha.sa_data);
 		if (!dev)
 			return -ENODEV;

-- 
2.43.5
Re: [PATCH net v4 2/2] arp: switch to dev_getbyhwaddr() in arp_req_set_public()
Posted by Jakub Kicinski 10 months ago
On Thu, 13 Feb 2025 04:42:38 -0800 Breno Leitao wrote:
> The arp_req_set_public() function is called with the rtnl lock held,
> which provides enough synchronization protection. This makes the RCU
> variant of dev_getbyhwaddr() unnecessary. Switch to using the simpler
> dev_getbyhwaddr() function since we already have the required rtnl
> locking.
> 
> This change helps maintain consistency in the networking code by using
> the appropriate helper function for the existing locking context.

I think you should make it clearer whether this fixes a splat with
PROVE_RCU_LIST=y
Re: [PATCH net v4 2/2] arp: switch to dev_getbyhwaddr() in arp_req_set_public()
Posted by Breno Leitao 10 months ago
On Mon, Feb 17, 2025 at 04:33:44PM -0800, Jakub Kicinski wrote:
> On Thu, 13 Feb 2025 04:42:38 -0800 Breno Leitao wrote:
> > The arp_req_set_public() function is called with the rtnl lock held,
> > which provides enough synchronization protection. This makes the RCU
> > variant of dev_getbyhwaddr() unnecessary. Switch to using the simpler
> > dev_getbyhwaddr() function since we already have the required rtnl
> > locking.
> > 
> > This change helps maintain consistency in the networking code by using
> > the appropriate helper function for the existing locking context.
> 
> I think you should make it clearer whether this fixes a splat with
> PROVE_RCU_LIST=y

This one doesn't fix the splat in fact, since rtnl lock was held, and it
is moving from dev_getbyhwaddr_rcu() to dev_getbyhwaddr(), since rtnl
lock was held.
Re: [PATCH net v4 2/2] arp: switch to dev_getbyhwaddr() in arp_req_set_public()
Posted by Jakub Kicinski 10 months ago
On Tue, 18 Feb 2025 01:36:30 -0800 Breno Leitao wrote:
> On Mon, Feb 17, 2025 at 04:33:44PM -0800, Jakub Kicinski wrote:
> > On Thu, 13 Feb 2025 04:42:38 -0800 Breno Leitao wrote:  
> > > The arp_req_set_public() function is called with the rtnl lock held,
> > > which provides enough synchronization protection. This makes the RCU
> > > variant of dev_getbyhwaddr() unnecessary. Switch to using the simpler
> > > dev_getbyhwaddr() function since we already have the required rtnl
> > > locking.
> > > 
> > > This change helps maintain consistency in the networking code by using
> > > the appropriate helper function for the existing locking context.  
> > 
> > I think you should make it clearer whether this fixes a splat with
> > PROVE_RCU_LIST=y  
> 
> This one doesn't fix the splat in fact, since rtnl lock was held, and it
> is moving from dev_getbyhwaddr_rcu() to dev_getbyhwaddr(), since rtnl
> lock was held.

Are you sure? I don't see the RCU lock being taken on the path that
ends up here. arp_ioctl() -> arp_req_set() -> arp_req_set_public()
Re: [PATCH net v4 2/2] arp: switch to dev_getbyhwaddr() in arp_req_set_public()
Posted by Breno Leitao 10 months ago
Hello Jakub,

On Tue, Feb 18, 2025 at 06:29:20AM -0800, Jakub Kicinski wrote:
> On Tue, 18 Feb 2025 01:36:30 -0800 Breno Leitao wrote:
> > On Mon, Feb 17, 2025 at 04:33:44PM -0800, Jakub Kicinski wrote:
> > > On Thu, 13 Feb 2025 04:42:38 -0800 Breno Leitao wrote:  
> > > > The arp_req_set_public() function is called with the rtnl lock held,
> > > > which provides enough synchronization protection. This makes the RCU
> > > > variant of dev_getbyhwaddr() unnecessary. Switch to using the simpler
> > > > dev_getbyhwaddr() function since we already have the required rtnl
> > > > locking.
> > > > 
> > > > This change helps maintain consistency in the networking code by using
> > > > the appropriate helper function for the existing locking context.  
> > > 
> > > I think you should make it clearer whether this fixes a splat with
> > > PROVE_RCU_LIST=y  
> > 
> > This one doesn't fix the splat in fact, since rtnl lock was held, and it
> > is moving from dev_getbyhwaddr_rcu() to dev_getbyhwaddr(), since rtnl
> > lock was held.
> 
> Are you sure? I don't see the RCU lock being taken on the path that
> ends up here. arp_ioctl() -> arp_req_set() -> arp_req_set_public()

Ack, this will fix the PROVE_RCU_LIST issue.