* [PATCH net v4 0/2] net: core: improvements to device lookup by hardware address.
@ 2025-02-13 12:42 Breno Leitao
2025-02-13 12:42 ` [PATCH net v4 1/2] net: Add non-RCU dev_getbyhwaddr() helper Breno Leitao
2025-02-13 12:42 ` [PATCH net v4 2/2] arp: switch to dev_getbyhwaddr() in arp_req_set_public() Breno Leitao
0 siblings, 2 replies; 9+ messages in thread
From: Breno Leitao @ 2025-02-13 12:42 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Andrew Lunn, David Ahern
Cc: linux-kernel, netdev, Eric Dumazet, Breno Leitao, kuniyu,
ushankar, kuniyu
The first patch adds a new dev_getbyhwaddr() helper function for
finding devices by hardware address when the rtnl lock is held. This
prevents PROVE_LOCKING warnings that occurred when rtnl lock was held
but the RCU read lock wasn't. The common address comparison logic is
extracted into dev_comp_addr() to avoid code duplication.
The second coverts arp_req_set_public() to the new helper.
Signed-off-by: Breno Leitao <leitao@debian.org>
---
Changes in v4:
- Split the patchset in two, and now targeting `net` instead of
`net-next` (Kuniyuki Iwashima)
- Identended the kernel-doc in the new way. The other functions will
come in a separate patchset. (Kuniyuki Iwashima)
- Link to v3: https://lore.kernel.org/r/20250212-arm_fix_selftest-v3-0-72596cb77e44@debian.org
Changes in v3:
- Fixed the cover letter (Kuniyuki Iwashima)
- Added a third patch converting arp_req_set_public() to the new helper
(Kuniyuki Iwashima)
- Link to v2:
https://lore.kernel.org/r/20250210-arm_fix_selftest-v2-0-ba84b5bc58c8@debian.org
Changes in v2:
- Fixed the documentation (Jakub)
- Renamed the function from dev_getbyhwaddr_rtnl() to dev_getbyhwaddr()
(Jakub)
- Exported the function in the header (Jakub)
- Link to v1: https://lore.kernel.org/r/20250207-arm_fix_selftest-v1-1-487518d2fd1c@debian.org
---
Breno Leitao (2):
net: Add non-RCU dev_getbyhwaddr() helper
arp: switch to dev_getbyhwaddr() in arp_req_set_public()
include/linux/netdevice.h | 2 ++
net/core/dev.c | 37 ++++++++++++++++++++++++++++++++++---
net/ipv4/arp.c | 2 +-
3 files changed, 37 insertions(+), 4 deletions(-)
---
base-commit: 0469b410c888414c3505d8d2b5814eb372404638
change-id: 20250207-arm_fix_selftest-ee29dbc33a06
Best regards,
--
Breno Leitao <leitao@debian.org>
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH net v4 1/2] net: Add non-RCU dev_getbyhwaddr() helper 2025-02-13 12:42 [PATCH net v4 0/2] net: core: improvements to device lookup by hardware address Breno Leitao @ 2025-02-13 12:42 ` Breno Leitao 2025-02-14 5:49 ` Kuniyuki Iwashima 2025-02-18 0:32 ` Jakub Kicinski 2025-02-13 12:42 ` [PATCH net v4 2/2] arp: switch to dev_getbyhwaddr() in arp_req_set_public() Breno Leitao 1 sibling, 2 replies; 9+ messages in thread From: Breno Leitao @ 2025-02-13 12:42 UTC (permalink / raw) To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, Andrew Lunn, David Ahern Cc: linux-kernel, netdev, Eric Dumazet, Breno Leitao, kuniyu, ushankar, kuniyu Add dedicated helper for finding devices by hardware address when holding rtnl_lock, similar to existing dev_getbyhwaddr_rcu(). This prevents PROVE_LOCKING warnings when rtnl_lock is held but RCU read lock is not. Extract common address comparison logic into dev_comp_addr(). The context about this change could be found in the following discussion: Link: https://lore.kernel.org/all/20250206-scarlet-ermine-of-improvement-1fcac5@leitao/ Cc: kuniyu@amazon.com Cc: ushankar@purestorage.com Suggested-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Breno Leitao <leitao@debian.org> --- include/linux/netdevice.h | 2 ++ net/core/dev.c | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 365f0e2098d13f40ce6d8865962678b052b39a16..ab550a89b9bfaa5682e65f1dcc7f5f99ce90eb94 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3275,6 +3275,8 @@ static inline struct net_device *first_net_device_rcu(struct net *net) } int netdev_boot_setup_check(struct net_device *dev); +struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type, + const char *hwaddr); struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type, const char *hwaddr); struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type); diff --git a/net/core/dev.c b/net/core/dev.c index 55e356a68db667982e7e62d09d07feecc14deebe..6d5bb4a5511dc6ad0cd2a0feddb9c1c689ed7ab8 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1121,6 +1121,12 @@ int netdev_get_name(struct net *net, char *name, int ifindex) return ret; } +static bool dev_comp_addr(struct net_device *dev, unsigned short type, + const char *ha) +{ + return dev->type == type && !memcmp(dev->dev_addr, ha, dev->addr_len); +} + /** * dev_getbyhwaddr_rcu - find a device by its hardware address * @net: the applicable net namespace @@ -1129,7 +1135,7 @@ int netdev_get_name(struct net *net, char *name, int ifindex) * * Search for an interface by MAC address. Returns NULL if the device * is not found or a pointer to the device. - * The caller must hold RCU or RTNL. + * The caller must hold RCU. * The returned device has not had its ref count increased * and the caller must therefore be careful about locking * @@ -1141,14 +1147,39 @@ struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type, struct net_device *dev; for_each_netdev_rcu(net, dev) - if (dev->type == type && - !memcmp(dev->dev_addr, ha, dev->addr_len)) + if (dev_comp_addr(dev, type, ha)) return dev; return NULL; } EXPORT_SYMBOL(dev_getbyhwaddr_rcu); +/** + * dev_getbyhwaddr - find a device by its hardware address + * @net: the applicable net namespace + * @type: media type of device + * @ha: hardware address + * + * Similar to dev_getbyhwaddr_rcu(), but the owner needs to hold + * rtnl_lock. + * + * Context: rtnl_lock() must be held. + * Return: pointer to the net_device, or NULL if not found + */ +struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type, + const char *ha) +{ + struct net_device *dev; + + ASSERT_RTNL(); + for_each_netdev(net, dev) + if (dev_comp_addr(dev, type, ha)) + return dev; + + return NULL; +} +EXPORT_SYMBOL(dev_getbyhwaddr); + struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type) { struct net_device *dev, *ret = NULL; -- 2.43.5 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH net v4 1/2] net: Add non-RCU dev_getbyhwaddr() helper 2025-02-13 12:42 ` [PATCH net v4 1/2] net: Add non-RCU dev_getbyhwaddr() helper Breno Leitao @ 2025-02-14 5:49 ` Kuniyuki Iwashima 2025-02-18 0:32 ` Jakub Kicinski 1 sibling, 0 replies; 9+ messages in thread From: Kuniyuki Iwashima @ 2025-02-14 5:49 UTC (permalink / raw) To: leitao Cc: andrew+netdev, davem, dsahern, edumazet, eric.dumazet, horms, kuba, kuniyu, kuniyu, linux-kernel, netdev, pabeni, ushankar From: Breno Leitao <leitao@debian.org> Date: Thu, 13 Feb 2025 04:42:37 -0800 > Add dedicated helper for finding devices by hardware address when > holding rtnl_lock, similar to existing dev_getbyhwaddr_rcu(). This prevents > PROVE_LOCKING warnings when rtnl_lock is held but RCU read lock is not. > > Extract common address comparison logic into dev_comp_addr(). > > The context about this change could be found in the following > discussion: > > Link: https://lore.kernel.org/all/20250206-scarlet-ermine-of-improvement-1fcac5@leitao/ > > Cc: kuniyu@amazon.com > Cc: ushankar@purestorage.com > Suggested-by: Eric Dumazet <edumazet@google.com> > Signed-off-by: Breno Leitao <leitao@debian.org> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Thanks! ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net v4 1/2] net: Add non-RCU dev_getbyhwaddr() helper 2025-02-13 12:42 ` [PATCH net v4 1/2] net: Add non-RCU dev_getbyhwaddr() helper Breno Leitao 2025-02-14 5:49 ` Kuniyuki Iwashima @ 2025-02-18 0:32 ` Jakub Kicinski 1 sibling, 0 replies; 9+ messages in thread From: Jakub Kicinski @ 2025-02-18 0:32 UTC (permalink / raw) To: Breno Leitao Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman, Andrew Lunn, David Ahern, linux-kernel, netdev, Eric Dumazet, kuniyu, ushankar, kuniyu On Thu, 13 Feb 2025 04:42:37 -0800 Breno Leitao wrote: > +static bool dev_comp_addr(struct net_device *dev, unsigned short type, sorry for the nit, but: dev_comp_addr() -> dev_addr_cmp() ? cmp is the typical abbreviation for compare in C > + * dev_getbyhwaddr - find a device by its hardware address another tiny nit here: I think ideally there should be a () after the function name -- pw-bot: cr ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net v4 2/2] arp: switch to dev_getbyhwaddr() in arp_req_set_public() 2025-02-13 12:42 [PATCH net v4 0/2] net: core: improvements to device lookup by hardware address Breno Leitao 2025-02-13 12:42 ` [PATCH net v4 1/2] net: Add non-RCU dev_getbyhwaddr() helper Breno Leitao @ 2025-02-13 12:42 ` Breno Leitao 2025-02-18 0:33 ` Jakub Kicinski 1 sibling, 1 reply; 9+ messages in thread From: Breno Leitao @ 2025-02-13 12:42 UTC (permalink / raw) To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, Andrew Lunn, David Ahern Cc: linux-kernel, netdev, Eric Dumazet, Breno Leitao, kuniyu, ushankar, Kuniyuki Iwashima 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 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH net v4 2/2] arp: switch to dev_getbyhwaddr() in arp_req_set_public() 2025-02-13 12:42 ` [PATCH net v4 2/2] arp: switch to dev_getbyhwaddr() in arp_req_set_public() Breno Leitao @ 2025-02-18 0:33 ` Jakub Kicinski 2025-02-18 9:36 ` Breno Leitao 0 siblings, 1 reply; 9+ messages in thread From: Jakub Kicinski @ 2025-02-18 0:33 UTC (permalink / raw) To: Breno Leitao Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman, Andrew Lunn, David Ahern, linux-kernel, netdev, Eric Dumazet, kuniyu, ushankar, Kuniyuki Iwashima 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net v4 2/2] arp: switch to dev_getbyhwaddr() in arp_req_set_public() 2025-02-18 0:33 ` Jakub Kicinski @ 2025-02-18 9:36 ` Breno Leitao 2025-02-18 14:29 ` Jakub Kicinski 0 siblings, 1 reply; 9+ messages in thread From: Breno Leitao @ 2025-02-18 9:36 UTC (permalink / raw) To: Jakub Kicinski Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman, Andrew Lunn, David Ahern, linux-kernel, netdev, Eric Dumazet, kuniyu, ushankar, Kuniyuki Iwashima 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. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net v4 2/2] arp: switch to dev_getbyhwaddr() in arp_req_set_public() 2025-02-18 9:36 ` Breno Leitao @ 2025-02-18 14:29 ` Jakub Kicinski 2025-02-18 16:27 ` Breno Leitao 0 siblings, 1 reply; 9+ messages in thread From: Jakub Kicinski @ 2025-02-18 14:29 UTC (permalink / raw) To: Breno Leitao Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman, Andrew Lunn, David Ahern, linux-kernel, netdev, Eric Dumazet, kuniyu, ushankar, Kuniyuki Iwashima 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() ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net v4 2/2] arp: switch to dev_getbyhwaddr() in arp_req_set_public() 2025-02-18 14:29 ` Jakub Kicinski @ 2025-02-18 16:27 ` Breno Leitao 0 siblings, 0 replies; 9+ messages in thread From: Breno Leitao @ 2025-02-18 16:27 UTC (permalink / raw) To: Jakub Kicinski Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman, Andrew Lunn, David Ahern, linux-kernel, netdev, Eric Dumazet, kuniyu, ushankar, Kuniyuki Iwashima 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. ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-02-18 16:27 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-02-13 12:42 [PATCH net v4 0/2] net: core: improvements to device lookup by hardware address Breno Leitao 2025-02-13 12:42 ` [PATCH net v4 1/2] net: Add non-RCU dev_getbyhwaddr() helper Breno Leitao 2025-02-14 5:49 ` Kuniyuki Iwashima 2025-02-18 0:32 ` Jakub Kicinski 2025-02-13 12:42 ` [PATCH net v4 2/2] arp: switch to dev_getbyhwaddr() in arp_req_set_public() Breno Leitao 2025-02-18 0:33 ` Jakub Kicinski 2025-02-18 9:36 ` Breno Leitao 2025-02-18 14:29 ` Jakub Kicinski 2025-02-18 16:27 ` Breno Leitao
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).