From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, axboe@kernel.dk, netdev@vger.kernel.org
Subject: [PATCH io_uring-7.1 08/16] io_uring/zcrx: use guards for locking
Date: Mon, 23 Mar 2026 12:43:57 +0000 [thread overview]
Message-ID: <eb4667cfaf88c559700f6399da9e434889f5b04a.1774261953.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1774261953.git.asml.silence@gmail.com>
Convert last several places using manual locking to guards to simplify
the code.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
io_uring/zcrx.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index 0a5f8eab92c3..db723644ddcb 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -586,9 +586,8 @@ static void io_zcrx_return_niov_freelist(struct net_iov *niov)
{
struct io_zcrx_area *area = io_zcrx_iov_to_area(niov);
- spin_lock_bh(&area->freelist_lock);
+ guard(spinlock_bh)(&area->freelist_lock);
area->freelist[area->free_count++] = net_iov_idx(niov);
- spin_unlock_bh(&area->freelist_lock);
}
static void io_zcrx_return_niov(struct net_iov *niov)
@@ -1051,7 +1050,8 @@ static void io_zcrx_refill_slow(struct page_pool *pp, struct io_zcrx_ifq *ifq)
{
struct io_zcrx_area *area = ifq->area;
- spin_lock_bh(&area->freelist_lock);
+ guard(spinlock_bh)(&area->freelist_lock);
+
while (area->free_count && pp->alloc.count < PP_ALLOC_CACHE_REFILL) {
struct net_iov *niov = __io_zcrx_get_free_niov(area);
netmem_ref netmem = net_iov_to_netmem(niov);
@@ -1060,7 +1060,6 @@ static void io_zcrx_refill_slow(struct page_pool *pp, struct io_zcrx_ifq *ifq)
io_zcrx_sync_for_device(pp, niov);
net_mp_netmem_place_in_cache(pp, netmem);
}
- spin_unlock_bh(&area->freelist_lock);
}
static netmem_ref io_pp_zc_alloc_netmems(struct page_pool *pp, gfp_t gfp)
@@ -1283,10 +1282,10 @@ static struct net_iov *io_alloc_fallback_niov(struct io_zcrx_ifq *ifq)
if (area->mem.is_dmabuf)
return NULL;
- spin_lock_bh(&area->freelist_lock);
- if (area->free_count)
- niov = __io_zcrx_get_free_niov(area);
- spin_unlock_bh(&area->freelist_lock);
+ scoped_guard(spinlock_bh, &area->freelist_lock) {
+ if (area->free_count)
+ niov = __io_zcrx_get_free_niov(area);
+ }
if (niov)
page_pool_fragment_netmem(net_iov_to_netmem(niov), 1);
--
2.53.0
next prev parent reply other threads:[~2026-03-23 12:44 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 12:43 [PATCH io_uring-7.1 00/16] zcrx update for-7.1 Pavel Begunkov
2026-03-23 12:43 ` [PATCH io_uring-7.1 01/16] io_uring/zcrx: return back two step unregistration Pavel Begunkov
2026-03-23 15:01 ` Jens Axboe
2026-03-23 16:14 ` Pavel Begunkov
2026-03-23 16:44 ` Jens Axboe
2026-03-23 12:43 ` [PATCH io_uring-7.1 02/16] io_uring/zcrx: fully clean area on error in io_import_umem() Pavel Begunkov
2026-03-23 12:43 ` [PATCH io_uring-7.1 03/16] io_uring/zcrx: always dma map in advance Pavel Begunkov
2026-03-23 12:43 ` [PATCH io_uring-7.1 04/16] io_uring/zcrx: extract netdev+area init into a helper Pavel Begunkov
2026-03-23 12:43 ` [PATCH io_uring-7.1 05/16] io_uring/zcrx: implement device-less mode for zcrx Pavel Begunkov
2026-03-23 12:43 ` [PATCH io_uring-7.1 06/16] io_uring/zcrx: use better name for RQ region Pavel Begunkov
2026-03-23 12:43 ` [PATCH io_uring-7.1 07/16] io_uring/zcrx: add a struct for refill queue Pavel Begunkov
2026-03-23 12:43 ` Pavel Begunkov [this message]
2026-03-23 12:43 ` [PATCH io_uring-7.1 09/16] io_uring/zcrx: move count check into zcrx_get_free_niov Pavel Begunkov
2026-03-23 12:43 ` [PATCH io_uring-7.1 10/16] io_uring/zcrx: warn on alloc with non-empty pp cache Pavel Begunkov
2026-03-23 12:44 ` [PATCH io_uring-7.1 11/16] io_uring/zcrx: netmem array as refiling format Pavel Begunkov
2026-03-23 12:44 ` [PATCH io_uring-7.1 12/16] io_uring/zcrx: consolidate dma syncing Pavel Begunkov
2026-03-23 12:44 ` [PATCH io_uring-7.1 13/16] io_uring/zcrx: warn on a repeated area append Pavel Begunkov
2026-03-23 12:44 ` [PATCH io_uring-7.1 14/16] io_uring/zcrx: cache fallback availability in zcrx ctx Pavel Begunkov
2026-03-23 12:44 ` [PATCH io_uring-7.1 15/16] io_uring/zcrx: check ctrl op payload struct sizes Pavel Begunkov
2026-03-23 12:44 ` [PATCH io_uring-7.1 16/16] io_uring/zcrx: rename zcrx [un]register functions Pavel Begunkov
2026-03-23 22:32 ` [PATCH io_uring-7.1 00/16] zcrx update for-7.1 Jakub Kicinski
2026-03-23 22:34 ` Jens Axboe
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=eb4667cfaf88c559700f6399da9e434889f5b04a.1774261953.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--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