diff options
author | Jakub Kicinski <kuba@kernel.org> | 2024-11-18 18:59:34 -0800 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2024-11-18 19:01:47 -0800 |
commit | 21742be898fb6d99d4d85e293bd501b6870b503a (patch) | |
tree | 8689e499621e0d7e495ef6ee3edb36dba7de1726 | |
parent | 4262bacb748fdab129dfbe1e93af75119a9c2775 (diff) | |
parent | a57d5a72f8dec7db8a79d0016fb0a3bdecc82b56 (diff) |
Merge branch 'netpoll-use-rcu-primitives-for-npinfo-pointer-access'
Breno Leitao says:
====================
netpoll: Use RCU primitives for npinfo pointer access
The net_device->npinfo pointer is marked with __rcu, indicating it requires
proper RCU access primitives:
struct net_device {
...
struct netpoll_info __rcu *npinfo;
...
};
Direct access to this pointer can lead to issues such as:
- Compiler incorrectly caching/reusing stale pointer values
- Missing memory ordering guarantees
- Non-atomic pointer loads
Replace direct NULL checks of npinfo with rcu_access_pointer(),
which provides the necessary memory ordering guarantees without the
overhead of a full RCU dereference, since we only need to verify
if the pointer is NULL.
In both cases, the RCU read lock is not held when the function is being
called. I checked that by using lockdep_assert_in_rcu_read_lock(), and
seeing the warning on both cases.
====================
Link: https://patch.msgid.link/20241118-netpoll_rcu-v1-0-a1888dcb4a02@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
-rw-r--r-- | include/linux/netpoll.h | 2 | ||||
-rw-r--r-- | net/core/netpoll.c | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h index cd4e28db0cbd..959a4daacea1 100644 --- a/include/linux/netpoll.h +++ b/include/linux/netpoll.h @@ -72,7 +72,7 @@ static inline void *netpoll_poll_lock(struct napi_struct *napi) { struct net_device *dev = napi->dev; - if (dev && dev->npinfo) { + if (dev && rcu_access_pointer(dev->npinfo)) { int owner = smp_processor_id(); while (cmpxchg(&napi->poll_owner, -1, owner) != -1) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index aa49b92e9194..45fb60bc4803 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -626,7 +626,7 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev) goto out; } - if (!ndev->npinfo) { + if (!rcu_access_pointer(ndev->npinfo)) { npinfo = kmalloc(sizeof(*npinfo), GFP_KERNEL); if (!npinfo) { err = -ENOMEM; |