From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796568301; b=ZORdGot5f7A85t19G8gOROtpitxZ6JZirXQ4nkYABom8ZPFLkUrjMFuI9d+gJ0NoUwwX k8XsxUc670GKcfT0LDzkqWS04dAUfrPLHa4O/+NGoUK013sZaAdJly2r2BNrcPwmV67bz dKnYv0EV20bIf8xj9dBOQJj2fZN0SkhKjlA07VI00hJY8ZyDBv+Gi/jTK/UGMlfC94qy9 BbTlwsYDd85FKAG+89DvpIwOQZq11WbfZpwG7Ee2xWT+lqooMpHsSj2XHYH7tY4nfe3Y+ hLc5I4CNDMbN+oSuZwXdZQKXCOEmYe1RekoYjovOkDBN7Cblax3CrBwI3vZJX6JkSkA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796568301; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=AYYSxorAektyKWYnjK/CYtXJkQhD7FFaVVDpgohbJuk=; b=Je37OyY6x1S/FoBr7vgWfhth9fZrBYE3+9S6w4uadUeXLu8+FAGg/pzPZpP6pCNxXXzA aBsu+0SgihQSLPPq76Z79KsQ8b15ySc8IVImIOh2FdPIU78/iLBHu7Mv0G7DAw+0mxJTM weNoRyhlYY8+r+X/vvlo0ZNNYoAAodwPkt21wVRh+PR15MLIZPDuTKjZxrtxlLMsu/iXc c+i+beqWggbrOfiB8XvlGpSI5Xkcp1sPSfpFCR7oyAW/CqDkkAsvO7pxhS5ykUtJuZm+5 nnjntwJuHCJlW6o8o8c/N1uzVYSWVkDEJIV9uTqHTwRrL7eVV9KkXaT7UvkBngw6V3g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=d+LR9Yi0; arc=none smtp.remote-ip=74.125.82.180 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16970606A322 for ; Sun, 6 Dec 2026 14:45:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 16970606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=d+LR9Yi0 Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-38699cf08dfso3703238eec.1 for ; Sun, 06 Dec 2026 06:45:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796568300; x=1797173100; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=AYYSxorAektyKWYnjK/CYtXJkQhD7FFaVVDpgohbJuk=; b=d+LR9Yi0ZyxSCx7zzDNcRimKwbq5a248QBm3k2sy9Ps11LhhyJ29DyVUr8P/djbK+y le0mvRmz87trNqEdRQkYiZc5lQgILIkMmeiarAYAu+ZJm4L0PnFqrPmW1RZvW6JclcYk IlC9IaJz6wGaKphCAepKO/31fQoIoejX0QSXHJac3YMaghOaChDX7UEOPLknlKRMzVZL QbwMlXNHv6AxorcmZtlV4H6eHhxhE7g2zjk6jZ4iHsi6Sj9ISFWoBHzkHSbs+jc/2zgE uy9WuVs7tlbFIJG0ZOQwEejTpLRYWUSIVVjLQvUh4hGvqL0ylgc9ueWYsXXWwWfgFacb 7B+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796568300; x=1797173100; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=AYYSxorAektyKWYnjK/CYtXJkQhD7FFaVVDpgohbJuk=; b=ROU0lI5QX5xfCKmSgdHoM/GXZ1YrS4iLoRfm364lbQy3h1Rr3DXoXMH+0I9gw2VE4j sdFLuMSyLsHEtRU3HVijxPcUBpePlbzgAIYXDoHfIkwjbQWgU3tOET80wr6K76S0gpvj H29BByCOsAHSFhK5xW4BgJYxogGCNSs94ipry6yXMh0p2Vck5Ki32YNyMguDplNgNgj6 bsZ/f1LxeOXGpO9W5GzvHVV17LNo38KzVlELkfVXApWXqwMuSv7tLir/eT5KussedJzI +JI6eh1Q3SATscc8NQHG/aHCT8N6g5VPEMWxLbeh4ye2w4Hu4KUvoTw18u9cKL83Lmgm eOdw== X-Forwarded-Encrypted: i=1; AL+hErGTdRP+o3+BfUlAZI4iZCchl1RaT8I4GezQj9vH3EJDq66RHUQWUtQyhZMaGXYwGUQEDZHxSJw=@vger.kernel.org X-Gm-Message-State: AB4q+uFJGGe09SqOoLmoOS+OzEIhHSWGASGA/SpjLkGG8DjLXdxgBI1d Vg/hgzNajMCLuhQE9RkFaihMRZX9wYbrz+axpwnP7aHgp2LogqEVRgLGOxPYkQ== X-Gm-Gg: AZFdTZdLdrzNpOqhAR8ZBBOp82JVQSCZTPy4/mwpTrfDZ4Bpq6oYQcenwD9QD4yamMH of4B4irrEkD+Biux8WqYcgMDzGzX/OVWW7tKRnn90R68flfuLEB8k9JarYdcbD/+yfjLR4mF44z LImg0wxpX2rjlBfw7FylvHeftk+HuFAZTnHZxfK1IE7Caf0LuBdzNnOsC51yPhKn4+GlPGcmFAu CRgvc30SJuSqxMKHk0ocT5wX65I5Lbh6k7SzsSJcoXmAWXvUDhwpwcdW0fuuYNjGj+Dgqm+qm57 +8iUMXN6ptSDcRwEEE/0IBi3G0uIRKk6VS6iv5okXPfwR8VCp+89shkx2T/OhA28NAwRx8XV8VL pit8yJiM4Oh9DvwmGOoPYGbZxKiHvgVPs+7Lu8pNC9CWBWzdrK5XjWIys2P385Bqe+JcplFa6j/ SRFu8Y8xr/eZWCSCdR8H/CHxPLp190gD3fYTkrifBRMK+CHJXt/n95VygM+AR/okAYwWBkky4UF 9GOZiCMecU1zTT15MeOgP9WMUy1lHbaPsTsO+9BONzRVm8/0DbGJPwdieKzD9V/ePjdj1mKuI7Y is1QY9AcsxgZVmBN0gJ6Iwt+y0JbBDuQceNPiUlqTFeuUmhqCIe6ZI1WQ6tKKdKt1EyV67LjfrJ ZrOi21OC8SlWN++OP/MXLHdvuQqCBY3wecRJsuM/ODvKKnBFTvK8hdO4hznjWtOn+IiqDdWexlF nfkYcGka8Z3cc= X-Received: by 2002:a05:7300:c8c8:b0:386:ea31:7123 with SMTP id 5a478bee46e88-38752153975mr7374721eec.25.1796568300157; Sun, 06 Dec 2026 06:45:00 -0800 (PST) Received: from SeungJong-Mac-mini.local ([210.117.237.143]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521e1c55sm28623252eec.16.2026.12.06.06.44.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 06:44:59 -0800 (PST) From: SeungJong Ha Date: Sun, 06 Dec 2026 23:44:43 +0900 Subject: [PATCH RFC net-next 2/5] ptr_ring: split ptr_ring_resize_multiple_bh() into alloc and swap X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261206-tc1-txqlen-commit-v1-2-ec9f34dce973@gmail.com> References: <20261206-tc1-txqlen-commit-v1-0-ec9f34dce973@gmail.com> In-Reply-To: <20261206-tc1-txqlen-commit-v1-0-ec9f34dce973@gmail.com> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Jamal Hadi Salim , Jiri Pirko , Andrew Lunn , Willem de Bruijn , Jason Wang Cc: "Michael S. Tsirkin" , John Fastabend , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, SeungJong Ha X-Mailer: b4 0.15.2 ptr_ring_resize_multiple_bh() allocates all the new queues before it swaps any of them in, so it either resizes every ring or none. A caller that has to do other work that can fail between allocating and swapping cannot use it. pfifo_fast needs this to change the rings of all tx queues of a device together. Split it into ptr_ring_alloc_queues(), which can fail, and ptr_ring_swap_queues_bh(), which cannot. ptr_ring_free_queues() frees an allocation that is not swapped in. ptr_ring_resize_multiple_bh() now calls the first two in turn; no functional change. The patch was written with Claude Code (Claude Opus 5.5). Signed-off-by: SeungJong Ha --- include/linux/ptr_ring.h | 79 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 20 deletions(-) diff --git a/include/linux/ptr_ring.h b/include/linux/ptr_ring.h index 4e710397903b..539063e29a55 100644 --- a/include/linux/ptr_ring.h +++ b/include/linux/ptr_ring.h @@ -645,22 +645,18 @@ static inline int ptr_ring_resize_noprof(struct ptr_ring *r, int size, gfp_t gfp #define ptr_ring_resize(...) alloc_hooks(ptr_ring_resize_noprof(__VA_ARGS__)) /* - * Note: producer lock is nested within consumer lock, so if you - * resize you must make sure all uses nest correctly. - * In particular if you consume ring in BH context, you must - * disable BH when doing so. + * Allocate @nrings queues of @size entries for ptr_ring_swap_queues_bh(). + * On failure, return NULL with nothing allocated. */ -static inline int ptr_ring_resize_multiple_bh_noprof(struct ptr_ring **rings, - unsigned int nrings, - int size, gfp_t gfp, - void (*destroy)(void *)) +static inline void ***ptr_ring_alloc_queues_noprof(unsigned int nrings, + int size, gfp_t gfp) { void ***queues; int i; queues = kmalloc_array_noprof(nrings, sizeof(*queues), gfp); if (!queues) - goto noqueues; + return NULL; for (i = 0; i < nrings; ++i) { queues[i] = __ptr_ring_init_queue_alloc_noprof(size, gfp); @@ -668,6 +664,41 @@ static inline int ptr_ring_resize_multiple_bh_noprof(struct ptr_ring **rings, goto nomem; } + return queues; + +nomem: + while (--i >= 0) + kvfree(queues[i]); + + kfree(queues); + + return NULL; +} +#define ptr_ring_alloc_queues(...) \ + alloc_hooks(ptr_ring_alloc_queues_noprof(__VA_ARGS__)) + +/* Free @queues from ptr_ring_alloc_queues() without swapping them in. */ +static inline void ptr_ring_free_queues(void ***queues, unsigned int nrings) +{ + int i; + + for (i = 0; i < nrings; ++i) + kvfree(queues[i]); + + kfree(queues); +} + +/* + * Swap in @queues from ptr_ring_alloc_queues() with the same @nrings and + * @size, then free the old queues and @queues. Locking is as for + * ptr_ring_resize_multiple_bh(). + */ +static inline void ptr_ring_swap_queues_bh(struct ptr_ring **rings, + void ***queues, unsigned int nrings, + int size, void (*destroy)(void *)) +{ + int i; + for (i = 0; i < nrings; ++i) { spin_lock_bh(&(rings[i])->consumer_lock); spin_lock(&(rings[i])->producer_lock); @@ -677,21 +708,29 @@ static inline int ptr_ring_resize_multiple_bh_noprof(struct ptr_ring **rings, spin_unlock_bh(&(rings[i])->consumer_lock); } - for (i = 0; i < nrings; ++i) - kvfree(queues[i]); - - kfree(queues); + ptr_ring_free_queues(queues, nrings); +} - return 0; +/* + * Note: producer lock is nested within consumer lock, so if you + * resize you must make sure all uses nest correctly. + * In particular if you consume ring in BH context, you must + * disable BH when doing so. + */ +static inline int ptr_ring_resize_multiple_bh_noprof(struct ptr_ring **rings, + unsigned int nrings, + int size, gfp_t gfp, + void (*destroy)(void *)) +{ + void ***queues; -nomem: - while (--i >= 0) - kvfree(queues[i]); + queues = ptr_ring_alloc_queues_noprof(nrings, size, gfp); + if (!queues) + return -ENOMEM; - kfree(queues); + ptr_ring_swap_queues_bh(rings, queues, nrings, size, destroy); -noqueues: - return -ENOMEM; + return 0; } #define ptr_ring_resize_multiple_bh(...) \ alloc_hooks(ptr_ring_resize_multiple_bh_noprof(__VA_ARGS__)) -- 2.54.0