public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v1] net: io_uring/zcrx: call netdev_queue_get_dma_dev() under instance lock
@ 2025-10-28 21:26 David Wei
  2025-10-28 22:38 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: David Wei @ 2025-10-28 21:26 UTC (permalink / raw)
  To: io-uring, netdev
  Cc: Jens Axboe, Pavel Begunkov, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman

netdev ops must be called under instance lock or rtnl_lock, but
io_register_zcrx_ifq() isn't doing this for netdev_queue_get_dma_dev().

Fix this by taking the instance lock.

Opted to do this by hand instead of netdev_get_by_index_lock(), which is
an older helper that doesn't take netdev tracker.

Signed-off-by: David Wei <dw@davidwei.uk>
---
 io_uring/zcrx.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index a816f5902091..55010c0aa7b9 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -606,11 +606,13 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
 		goto err;
 	}
 
+	netdev_lock(ifq->netdev);
 	ifq->dev = netdev_queue_get_dma_dev(ifq->netdev, reg.if_rxq);
 	if (!ifq->dev) {
 		ret = -EOPNOTSUPP;
-		goto err;
+		goto netdev_unlock;
 	}
+	netdev_unlock(ifq->netdev);
 	get_device(ifq->dev);
 
 	ret = io_zcrx_create_area(ifq, &area);
@@ -640,6 +642,8 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
 		goto err;
 	}
 	return 0;
+netdev_unlock:
+	netdev_unlock(ifq->netdev);
 err:
 	scoped_guard(mutex, &ctx->mmap_lock)
 		xa_erase(&ctx->zcrx_ctxs, id);
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net v1] net: io_uring/zcrx: call netdev_queue_get_dma_dev() under instance lock
  2025-10-28 21:26 [PATCH net v1] net: io_uring/zcrx: call netdev_queue_get_dma_dev() under instance lock David Wei
@ 2025-10-28 22:38 ` Jakub Kicinski
  2025-10-28 22:44   ` David Wei
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2025-10-28 22:38 UTC (permalink / raw)
  To: David Wei
  Cc: io-uring, netdev, Jens Axboe, Pavel Begunkov, David S. Miller,
	Eric Dumazet, Paolo Abeni, Simon Horman

On Tue, 28 Oct 2025 14:26:39 -0700 David Wei wrote:
> netdev ops must be called under instance lock or rtnl_lock, but
> io_register_zcrx_ifq() isn't doing this for netdev_queue_get_dma_dev().
> 
> Fix this by taking the instance lock.
> 
> Opted to do this by hand instead of netdev_get_by_index_lock(), which is
> an older helper that doesn't take netdev tracker.

Fixes tag missing.

netdev_get_by_index_lock() + netdev_hold() would be a better choice indeed.
Just a reference doesn't hold off device shutdown.

Is there a chance to reorder the io_zcrx_create_area() call, keep
holding the lock and call __net_mp_open_rxq() ?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net v1] net: io_uring/zcrx: call netdev_queue_get_dma_dev() under instance lock
  2025-10-28 22:38 ` Jakub Kicinski
@ 2025-10-28 22:44   ` David Wei
  0 siblings, 0 replies; 3+ messages in thread
From: David Wei @ 2025-10-28 22:44 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: io-uring, netdev, Jens Axboe, Pavel Begunkov, David S. Miller,
	Eric Dumazet, Paolo Abeni, Simon Horman

On 2025-10-28 15:38, Jakub Kicinski wrote:
> On Tue, 28 Oct 2025 14:26:39 -0700 David Wei wrote:
>> netdev ops must be called under instance lock or rtnl_lock, but
>> io_register_zcrx_ifq() isn't doing this for netdev_queue_get_dma_dev().
>>
>> Fix this by taking the instance lock.
>>
>> Opted to do this by hand instead of netdev_get_by_index_lock(), which is
>> an older helper that doesn't take netdev tracker.
> 
> Fixes tag missing.

Sorry, will add, keep forgetting this...

> 
> netdev_get_by_index_lock() + netdev_hold() would be a better choice indeed.
> Just a reference doesn't hold off device shutdown.

Got it, I'll switch to this.

> 
> Is there a chance to reorder the io_zcrx_create_area() call, keep
> holding the lock and call __net_mp_open_rxq() ?

Yeah, I also thought about it, wasn't sure if it was appropriate to
extend the critical section. I'll do this in v2.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-28 22:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-28 21:26 [PATCH net v1] net: io_uring/zcrx: call netdev_queue_get_dma_dev() under instance lock David Wei
2025-10-28 22:38 ` Jakub Kicinski
2025-10-28 22:44   ` David Wei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox