From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796568301; b=yNRWOvQo4mh27Qn1JNRYDGo63rZMJdlEftuipoWkd2G0EydvfBWa2zwmGCTMgbGvw8LF bATzjf0hRIAcvcOm5gkBvDooJ35AyII0DfFMQ0rvaYUV9sLsdb1MeH53hQZOjOderFMWL JRQKnUbJJS+HL/pudFLy1Ai47vIt1mbFh8igEc2RJysNvv/huuN21JF3HiEU2d8oSJQIw 1x6BgpiyPvPRFzhJvGUuqMV3rRbrcw7+rC7jRR2+JHcD/qDwKRdXjz8HB6rroV4LQSotB MR+Ajzf/3Ish70CWjxA+GuyaW2Lv3tu5wgJmvZXvQoPR1t66R9kAY2TdJzetwAci9xA== 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=NKdsvO+auJIux9upKGFyuLSDWzsUbkNALAXDIVmDsz9X0D/0udEVtg5YIoADJLTr8/Ai wZwsU4OSp3aLR3J6ik14mQDZmxIswTSSyN1Rgw3DEYPfWKuMCWVkLV4CkGQ5f7JK2ekCk iR55i9+WClQaRMV8Uvd42TVhpbPh0m4fYUEwAtasTJBHB7WjbAXtUOvYMJhjAayBoZBHU TTlWarZI4DnDIgKa0qIhIM9CytgnsXEGD//cfUrPyZAnyCU0WzgEkRoZvUPIjs0l2Tl8O 39HwtM5iVS+7mra7YOP8/JynaqNU5DZkkKS2KsnCeZtCqbyJx2OrozXZO0zErkoNRag== 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.181 Received: from mail-dy1-f181.google.com (mail-dy1-f181.google.com [74.125.82.181]) (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 DDCEA606A31F for ; Sun, 6 Dec 2026 14:45:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DDCEA606A31F 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-f181.google.com with SMTP id 5a478bee46e88-38699cf08dfso3703241eec.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=kGyl8SK6fAbIHLW+CmcATyajDmsRwah7i3FSWTtJZsgqwSKqHyO4zo0QY1O4+xBt4o A93k4R1KAO+qTWfVhEV1MEsHyJewZhNocNzchE7UD+72xWuSP4i7QsrVpPoz6HLjgK6c 4ktAXHhiwGPvmWQReo+H1YhNXHvDt8WY/S0vvGn80HzgTf6oEfE7gkVh7PJzUXRd29i/ AvfCy6Opaoj68nsAmTOCleb0KgeeBrdtPECZCTr1Hj+beSx+SQ7sMOkgjjD+u++hPgPz v8MPN1dpNhkMYlBDYD9ABg8OTLa8BjVBUidZu2r4amAMEzLk4cyD9YF7FVCrtFIZpMwM A+OQ== X-Forwarded-Encrypted: i=1; AL+hErFlpW7jJzhtX1chnQzSGwsvClh5vBQQRS2t23nMjxZCsQnluaUlWJR4XEGZBEHbjHxeXwypPfjDOuFiUHY=@vger.kernel.org X-Gm-Message-State: AB4q+uG8t9a04IE9Pcf1oOK0vVnK9cYgLL99rVCDr/cvgOTqLK1bbD2S hExd9IdftIWpqyKRtTCnOHthGYrHOhF814kD1c7CLhSy/GafenTsv4r6 X-Gm-Gg: AZFdTZeJTgOjBZAF+7W13dB+8m/s54nWvufL1Zihz81F4dhJjs8xHlLLFjKNJCLLQs7 lPffbCYfg4iBwQao0FY0XLU+dE9T/Xtqe4fsxdRMPGoU3H0FsKHDhrDzeEj1EwwCz8IjTTZ4fCW me4/rzmoPV5ZG5Buf/evXEEP225K66tR4j+uUCqe/cKlBkV2FmQSDhOpfk3qpi9svtYumIZC0Ti gxGIpEXFGWkPy/ZmY6lQG81MYJbV+lioH6qDO0wiUybJI4Ib9YxH0nXsk5/siqvqTW1KPlBtjJV t/+CD4OTiBWwxAJg+UovV95aZkCaPh57heaC0CD5HsgkY3h0s/lE24PfTpREuid8PtfAHhaB9ju AW82ZE7Rr65MAzP0tieRX0XbCSM4muxigSHsIrpbS4qtZEShFnddeq5BFXeqM4pMxRdPmFF5HIX THKF/9MraU4jNz/Eap/GxOR0NifOnINJJRAG0kKqWlnLwlAgLLm7cUe+da9NxmUaBqvoTbvZZ5S 162jWsrhZnBMSCfn0icG3RqYBwK769Y5aiUhtW+eGuTkwdrvFwGRJvsiDOzGB1pWL19+kU4P1XV d7A370ebzq3z8RV/VqxeJXPMqNHpFXpk52ug8ao+/1pM/IZMAAVNw/fV9Z2/kmUHMAdKY7oqD0I H41nAlyhvjxqMo5/K0yX9FwM8LFOj3a8EI9tUugXamGpYp+5zzNyJsTjESU2y5I7eYoIiYyF6Ox iMkVGwzPbkJl8= 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: linux-kernel@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