Skip to content

Commit 21742be

Browse files
committed
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>
2 parents 4262bac + a57d5a7 commit 21742be

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

include/linux/netpoll.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static inline void *netpoll_poll_lock(struct napi_struct *napi)
7272
{
7373
struct net_device *dev = napi->dev;
7474

75-
if (dev && dev->npinfo) {
75+
if (dev && rcu_access_pointer(dev->npinfo)) {
7676
int owner = smp_processor_id();
7777

7878
while (cmpxchg(&napi->poll_owner, -1, owner) != -1)

net/core/netpoll.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
626626
goto out;
627627
}
628628

629-
if (!ndev->npinfo) {
629+
if (!rcu_access_pointer(ndev->npinfo)) {
630630
npinfo = kmalloc(sizeof(*npinfo), GFP_KERNEL);
631631
if (!npinfo) {
632632
err = -ENOMEM;

0 commit comments

Comments
 (0)