diff mbox series

[net-next,v2,07/11] net: protect rxq->mp_params with the instance lock

Message ID 20250324224537.248800-8-kuba@kernel.org (mailing list archive)
State Accepted
Commit b52458652eca5a551ddb55605201b136f091b04d
Delegated to: Netdev Maintainers
Headers show
Series net: skip taking rtnl_lock for queue GET | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 2 maintainers not CCed: hawk@kernel.org ilias.apalodimas@linaro.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5 this patch: 5
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 37 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 72 this patch: 72
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2025-03-25--15-00 (tests: 896)

Commit Message

Jakub Kicinski March 24, 2025, 10:45 p.m. UTC
Ensure that all accesses to mp_params are under the netdev
instance lock. The only change we need is to move
dev_memory_provider_uninstall() under the lock.

Appropriately swap the asserts.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 net/core/dev.c       | 4 ++--
 net/core/page_pool.c | 7 ++-----
 2 files changed, 4 insertions(+), 7 deletions(-)

Comments

Mina Almasry March 25, 2025, 5:34 a.m. UTC | #1
On Mon, Mar 24, 2025 at 3:47 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> Ensure that all accesses to mp_params are under the netdev
> instance lock. The only change we need is to move
> dev_memory_provider_uninstall() under the lock.
>
> Appropriately swap the asserts.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Mina Almasry <almasrymina@google.com>

> ---
>  net/core/dev.c       | 4 ++--
>  net/core/page_pool.c | 7 ++-----
>  2 files changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 690d46497b2f..652f2c6f5674 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -10353,7 +10353,7 @@ u32 dev_get_min_mp_channel_count(const struct net_device *dev)
>  {
>         int i;
>
> -       ASSERT_RTNL();
> +       netdev_ops_assert_locked(dev);
>
>         for (i = dev->real_num_rx_queues - 1; i >= 0; i--)
>                 if (dev->_rx[i].mp_params.mp_priv)
> @@ -11957,9 +11957,9 @@ void unregister_netdevice_many_notify(struct list_head *head,
>                 dev_tcx_uninstall(dev);
>                 netdev_lock_ops(dev);
>                 dev_xdp_uninstall(dev);
> +               dev_memory_provider_uninstall(dev);
>                 netdev_unlock_ops(dev);
>                 bpf_dev_bound_netdev_unregister(dev);
> -               dev_memory_provider_uninstall(dev);

So initially I thought this may be wrong because netdev_lock_ops()
only locks if there are queue_mgmt_ops, but access to mp_params should
be locked anyway. But I guess you're relying on the fact that if the
device doesn't support queue_mgmt_ops memory providers don't work
anyway.
Jakub Kicinski March 25, 2025, 9:50 a.m. UTC | #2
On Mon, 24 Mar 2025 22:34:43 -0700 Mina Almasry wrote:
> > @@ -11957,9 +11957,9 @@ void unregister_netdevice_many_notify(struct list_head *head,
> >                 dev_tcx_uninstall(dev);
> >                 netdev_lock_ops(dev);
> >                 dev_xdp_uninstall(dev);
> > +               dev_memory_provider_uninstall(dev);
> >                 netdev_unlock_ops(dev);
> >                 bpf_dev_bound_netdev_unregister(dev);
> > -               dev_memory_provider_uninstall(dev);  
> 
> So initially I thought this may be wrong because netdev_lock_ops()
> only locks if there are queue_mgmt_ops, but access to mp_params should
> be locked anyway. But I guess you're relying on the fact that if the
> device doesn't support queue_mgmt_ops memory providers don't work
> anyway.

Right, my expectation is that they must be NULL if device is not
ops-locked. Not sure if that's what textbooks would consider "correct"
but I think KCSAN will not complain :)
diff mbox series

Patch

diff --git a/net/core/dev.c b/net/core/dev.c
index 690d46497b2f..652f2c6f5674 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -10353,7 +10353,7 @@  u32 dev_get_min_mp_channel_count(const struct net_device *dev)
 {
 	int i;
 
-	ASSERT_RTNL();
+	netdev_ops_assert_locked(dev);
 
 	for (i = dev->real_num_rx_queues - 1; i >= 0; i--)
 		if (dev->_rx[i].mp_params.mp_priv)
@@ -11957,9 +11957,9 @@  void unregister_netdevice_many_notify(struct list_head *head,
 		dev_tcx_uninstall(dev);
 		netdev_lock_ops(dev);
 		dev_xdp_uninstall(dev);
+		dev_memory_provider_uninstall(dev);
 		netdev_unlock_ops(dev);
 		bpf_dev_bound_netdev_unregister(dev);
-		dev_memory_provider_uninstall(dev);
 
 		netdev_offload_xstats_disable_all(dev);
 
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index acef1fcd8ddc..7745ad924ae2 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -11,6 +11,7 @@ 
 #include <linux/slab.h>
 #include <linux/device.h>
 
+#include <net/netdev_lock.h>
 #include <net/netdev_rx_queue.h>
 #include <net/page_pool/helpers.h>
 #include <net/page_pool/memory_provider.h>
@@ -279,11 +280,7 @@  static int page_pool_init(struct page_pool *pool,
 		get_device(pool->p.dev);
 
 	if (pool->slow.flags & PP_FLAG_ALLOW_UNREADABLE_NETMEM) {
-		/* We rely on rtnl_lock()ing to make sure netdev_rx_queue
-		 * configuration doesn't change while we're initializing
-		 * the page_pool.
-		 */
-		ASSERT_RTNL();
+		netdev_assert_locked(pool->slow.netdev);
 		rxq = __netif_get_rx_queue(pool->slow.netdev,
 					   pool->slow.queue_idx);
 		pool->mp_priv = rxq->mp_params.mp_priv;