mbox series

[net,0/2] netpoll: Use RCU primitives for npinfo pointer access

Message ID 20241118-netpoll_rcu-v1-0-a1888dcb4a02@debian.org (mailing list archive)
Headers show
Series netpoll: Use RCU primitives for npinfo pointer access | expand

Message

Breno Leitao Nov. 18, 2024, 11:15 a.m. UTC
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.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
Breno Leitao (2):
      netpoll: Use rcu_access_pointer() in __netpoll_setup
      netpoll: Use rcu_access_pointer() in netpoll_poll_lock

 include/linux/netpoll.h | 2 +-
 net/core/netpoll.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
---
base-commit: 8ffade77b6337a8767fae9820d57d7a6413dd1a1
change-id: 20241115-netpoll_rcu-eb1296511b71

Best regards,

Comments

patchwork-bot+netdevbpf@kernel.org Nov. 19, 2024, 3:40 a.m. UTC | #1
Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 18 Nov 2024 03:15:16 -0800 you wrote:
> The net_device->npinfo pointer is marked with __rcu, indicating it requires
> proper RCU access primitives:
> 
>   struct net_device {
> 	...
> 	struct netpoll_info __rcu *npinfo;
> 	...
>   };
> 
> [...]

Here is the summary with links:
  - [net,1/2] netpoll: Use rcu_access_pointer() in __netpoll_setup
    https://git.kernel.org/netdev/net/c/c69c5e10adb9
  - [net,2/2] netpoll: Use rcu_access_pointer() in netpoll_poll_lock
    https://git.kernel.org/netdev/net/c/a57d5a72f8de

You are awesome, thank you!
Herbert Xu Nov. 19, 2024, 3:53 a.m. UTC | #2
On Tue, Nov 19, 2024 at 03:40:31AM +0000, patchwork-bot+netdevbpf@kernel.org wrote:
> Hello:
> 
> This series was applied to netdev/net.git (main)
> by Jakub Kicinski <kuba@kernel.org>:
> 
> On Mon, 18 Nov 2024 03:15:16 -0800 you wrote:
> > The net_device->npinfo pointer is marked with __rcu, indicating it requires
> > proper RCU access primitives:
> > 
> >   struct net_device {
> > 	...
> > 	struct netpoll_info __rcu *npinfo;
> > 	...
> >   };
> > 
> > [...]
> 
> Here is the summary with links:
>   - [net,1/2] netpoll: Use rcu_access_pointer() in __netpoll_setup
>     https://git.kernel.org/netdev/net/c/c69c5e10adb9
>   - [net,2/2] netpoll: Use rcu_access_pointer() in netpoll_poll_lock
>     https://git.kernel.org/netdev/net/c/a57d5a72f8de

These are not bug fixes.  They should not be going through during
a merge window, especially with such a short period of review.

Thanks,
Jakub Kicinski Nov. 19, 2024, 2:34 p.m. UTC | #3
On Tue, 19 Nov 2024 11:53:49 +0800 Herbert Xu wrote:
> > Here is the summary with links:
> >   - [net,1/2] netpoll: Use rcu_access_pointer() in __netpoll_setup
> >     https://git.kernel.org/netdev/net/c/c69c5e10adb9
> >   - [net,2/2] netpoll: Use rcu_access_pointer() in netpoll_poll_lock
> >     https://git.kernel.org/netdev/net/c/a57d5a72f8de  
> 
> These are not bug fixes.  They should not be going through during
> a merge window, especially with such a short period of review.

Sorry, I do agree with your assessment, especially on patch 1.
But it's good to silence the false positive, so I applied and
stripped the Fixes tag.