From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, netdev@vger.kernel.org
Subject: [PATCH io_uring 13/16] io_uring/zcrx: move freelist lock to struct zcrx
Date: Fri, 7 Aug 2026 14:19:31 +0100 [thread overview]
Message-ID: <be7feadff1e210861433f99fe44170aa27ec5b33.1786108672.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1786108672.git.asml.silence@gmail.com>
freelist_lock, which protects slow path allocations, is currently stored
in struct io_zcrx_area. Once we add support for multiple queues, we'll
need a lock in the zcrx ctx, move it there.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
io_uring/zcrx.c | 14 +++++++-------
io_uring/zcrx.h | 2 +-
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index be3560739bbc..3cf5e456990a 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -542,7 +542,6 @@ static int __zcrx_create_area(struct io_zcrx_ifq *ifq,
/* we're only supporting one area per ifq for now */
area->area_id = 0;
area_reg->rq_area_token = zcrx_area_id_to_token(area->area_id);
- spin_lock_init(&area->freelist_lock);
ret = io_zcrx_append_area(ifq, area);
if (!ret)
@@ -573,6 +572,7 @@ static struct io_zcrx_ifq *io_zcrx_ifq_alloc(struct io_ring_ctx *ctx)
ifq->if_rxq = -1;
spin_lock_init(&ifq->ctx_lock);
spin_lock_init(&ifq->rq.lock);
+ spin_lock_init(&ifq->alloc_lock);
mutex_init(&ifq->pp_lock);
refcount_set(&ifq->refs, 1);
refcount_set(&ifq->user_refs, 1);
@@ -647,8 +647,9 @@ static void io_put_zcrx_ifq(struct io_zcrx_ifq *ifq)
static void io_zcrx_return_niov_freelist(struct net_iov *niov)
{
struct io_zcrx_area *area = io_zcrx_iov_to_area(niov);
+ struct io_zcrx_ifq *ifq = area->ifq;
- guard(spinlock_bh)(&area->freelist_lock);
+ guard(spinlock_bh)(&ifq->alloc_lock);
if (WARN_ON_ONCE(area->free_count >= area->nia.num_niovs))
return;
area->freelist[area->free_count++] = net_iov_idx(niov);
@@ -658,7 +659,7 @@ static struct net_iov *zcrx_get_free_niov(struct io_zcrx_area *area)
{
unsigned niov_idx;
- lockdep_assert_held(&area->freelist_lock);
+ lockdep_assert_held(&area->ifq->alloc_lock);
if (unlikely(!area->free_count))
return NULL;
@@ -1251,7 +1252,7 @@ static unsigned io_zcrx_refill_slow(struct page_pool *pp, struct io_zcrx_ifq *if
struct io_zcrx_area *area = ifq->area;
unsigned allocated = 0;
- guard(spinlock_bh)(&area->freelist_lock);
+ guard(spinlock_bh)(&ifq->alloc_lock);
for (allocated = 0; allocated < to_alloc; allocated++) {
struct net_iov *niov = zcrx_get_free_niov(area);
@@ -1564,14 +1565,13 @@ static bool io_zcrx_queue_cqe(struct io_kiocb *req, struct net_iov *niov,
static struct net_iov *io_alloc_fallback_niov(struct io_zcrx_ifq *ifq)
{
- struct io_zcrx_area *area = ifq->area;
struct net_iov *niov = NULL;
if (!ifq->kern_readable)
return NULL;
- scoped_guard(spinlock_bh, &area->freelist_lock)
- niov = zcrx_get_free_niov(area);
+ scoped_guard(spinlock_bh, &ifq->alloc_lock)
+ niov = zcrx_get_free_niov(ifq->area);
if (niov)
page_pool_fragment_netmem(net_iov_to_netmem(niov), 1);
diff --git a/io_uring/zcrx.h b/io_uring/zcrx.h
index 4f8428db4aa4..18de02716453 100644
--- a/io_uring/zcrx.h
+++ b/io_uring/zcrx.h
@@ -37,7 +37,6 @@ struct io_zcrx_area {
u16 area_id;
/* freelist */
- spinlock_t freelist_lock ____cacheline_aligned_in_smp;
u32 free_count;
u32 *freelist;
@@ -66,6 +65,7 @@ struct io_zcrx_ifq {
bool kern_readable;
struct zcrx_rq rq ____cacheline_aligned_in_smp;
+ spinlock_t alloc_lock ____cacheline_aligned_in_smp;
u32 if_rxq;
struct device *dev;
--
2.54.0
next prev parent reply other threads:[~2026-08-07 13:20 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 13:19 [PATCH io_uring 00/16] zcrx update for-7.3 Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 01/16] io_uring/zcrx: scale refilling with large pages Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 02/16] io_uring/zcrx: move RQ head/tail to separate cache lines Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 03/16] io_uring/zcrx: add RQ iterator Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 04/16] io_uring/zcrx: cache RQ tail Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 05/16] io_uring/zcrx: coalesce same-niov RQEs on refill Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 06/16] io_uring/zcrx: constify area_reg on import Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 07/16] io_urint/zcrx: narrow var scope in io_zcrx_recv_skb() Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 08/16] io_uring/zcrx: don't reload skb_shinfo Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 09/16] io_uring/zcrx: add helper for deriving area token Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 10/16] io_uring/zcrx: don't pass ifq_reg to area creation Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 11/16] io_uring/zcrx: split dmabuf unmap and release Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 12/16] io_uring/zcrx: unmap under netdev lock Pavel Begunkov
2026-08-07 13:19 ` Pavel Begunkov [this message]
2026-08-07 13:19 ` [PATCH io_uring 14/16] io_uring/zcrx: keep array of areas Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 15/16] io_uring/zcrx: lock area creation with pp_lock Pavel Begunkov
2026-08-07 13:19 ` [PATCH io_uring 16/16] io_uring/zcrx: add dynamic area provisioning Pavel Begunkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=be7feadff1e210861433f99fe44170aa27ec5b33.1786108672.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=io-uring@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox