Article View: linux.kernel.netdev
Article #26541Re: [PATCH net v4] wireguard: drain per-peer queues with sentinels
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 18:02
Date: Thu, 03 Dec 2026 18:02
176 lines
15000 bytes
15000 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] Bulk peer removal now takes about twice as many RCU grace
periods, and under RTNL they are expedited.
- [Low] The commit has no Fixes: tag, but it fixes a long-standing bug.
- [Low] Two comments in peer_remove_after_dead() do not match the code.
--
wireguard: drain per-peer queues with sentinels
The device-wide flush_workqueue() calls in peer_remove_after_dead() are
replaced with on-stack sentinels. The sentinels are enqueued on the peer's
TX and RX prev_queues, and the remover waits for completions that fire when
the serial consumers reach them. State publication and consumer scheduling
in wg_queue_enqueue_per_peer_tx()/rx() are wrapped in RCU read-side
sections. A synchronize_net() follows the completions, and only the peer's
own transmit_handshake_work is flushed.
> diff --git a/drivers/net/wireguard/peer.c b/drivers/net/wireguard/peer.c
> index 1cb502a932e07..0aa17fa0a0829 100644
> --- a/drivers/net/wireguard/peer.c
> +++ b/drivers/net/wireguard/peer.c
[ ... ]
> @@ -105,28 +109,32 @@ static void peer_remove_after_dead(struct wg_peer *peer)
> */
> wg_timers_stop(peer);
>
> - /* The transition between packet encryption/decryption queues isn't
> - * guarded by is_dead, but each reference's life is strictly bounded by
> - * two generations: once for parallel crypto and once for serial
> - * ingestion, so we can simply flush twice, and be sure that we no
> - * longer have references inside these queues.
> + /* While is_dead guards against new TX/RX, there may be existing items
> + * in encryption/decryption queues. To address that, queue a sentinel
> + * on those queues and wait for completion for both tx/rx queues.
> + */
> + wg_prev_queue_enqueue_sentinel(&peer->tx_queue, &tx, &tx_done);
> + wg_prev_queue_enqueue_sentinel(&peer->rx_queue, &rx, &rx_done);
> + queue_work_on(wg_cpumask_choose_online(&peer->serial_work_cpu, peer->internal_id),
> + peer->device->packet_crypt_wq, &peer->transmit_packet_work);
> + napi_schedule(&peer->napi);
> + wait_for_completion(&tx_done);
> + wait_for_completion(&rx_done);
[Severity: Low]
This isn't a bug, but should this patch carry a Fixes: tag?
The old code ran flush_workqueue(peer->device->packet_crypt_wq) twice and
flush_workqueue(peer->device->handshake_send_wq) while holding RTNL and
device_update_lock. The path is wg_set_device() with
WGDEVICE_F_REPLACE_PEERS -> wg_peer_remove_all() ->
peer_remove_after_dead().
packet_crypt_wq hosts the device-wide crypto workers, which loop for as
long as the shared ring has packets:
drivers/net/wireguard/send.c:wg_packet_encrypt_worker() {
...
while ((first = ptr_ring_consume_bh(&queue->ring)) != NULL) {
...
}
The loop only calls cond_resched(). If other peers keep wg->encrypt_queue
or wg->decrypt_queue non-empty, a worker that is already running never
returns. flush_workqueue() has to wait for it, so RTNL can stay held for an
unbounded time.
Those flushes come from the original driver commit, so the tag would be:
Fixes: e7096c131e51 ("net: WireGuard secure network tunnel")
The commit message does mention the RTNL delay. Could it also say that the
stall can be unbounded?
> +
> + /* Handle edge cases where a consumer can finish a packet before crypto
> + * helper schedules the consumer again. Use RCU sync to ensure that all
> + * notification helpers finish. Expedite the grace period under RTNL.
> */
> + synchronize_net();
[Severity: Medium]
Does this double the number of grace periods taken during bulk peer
removal?
netif_napi_del(), called a few lines below, already does one grace period
per peer:
include/linux/netdevice.h:netif_napi_del() {
__netif_napi_del(napi);
synchronize_net();
}
wg_peer_remove_all() then calls peer_remove_after_dead() once per peer, one
after another:
drivers/net/wireguard/peer.c:wg_peer_remove_all() {
...
synchronize_net();
list_for_each_entry_safe(peer, temp, &dead_peers, peer_list)
peer_remove_after_dead(peer);
}
On the wg_set_device() WGDEVICE_F_REPLACE_PEERS path RTNL is held, so
synchronize_net() becomes synchronize_rcu_expedited(). Each peer now costs
two expedited grace periods, each with IPIs to all CPUs, plus the sentinel
round trip. Before this patch it cost one.
A device can have up to MAX_PEERS_PER_DEVICE peers, for example after a
wg setconf on a server. Could this roughly double the RTNL hold time on the
replace path? Device teardown through wg_destruct() -> wg_peer_remove_all()
would also pay the extra grace periods.
Since the goal is shorter RTNL hold times, would it be possible to batch
the bulk path? It could enqueue sentinels for every dead peer, wait for all
the completions, and then call synchronize_net() once. The commit message
also doesn't mention this trade-off.
>
> - /* a) For encrypt/decrypt. */
> - flush_workqueue(peer->device->packet_crypt_wq);
> - /* b.1) For send (but not receive, since that's napi). */
> - flush_workqueue(peer->device->packet_crypt_wq);
> - /* b.2.1) For receive (but not send, since that's wq). */
> + /* Keep the sentinels alive until both consumers have finished. */
> + flush_work(&peer->transmit_packet_work);
> napi_disable(&peer->napi);
[Severity: Low]
This isn't a bug, but does this comment describe what flush_work() and
napi_disable() are doing here?
The tx and rx sentinels are on the stack, so they live until
peer_remove_after_dead() returns, whatever these calls do. Both consumers
stop touching the sentinel right after complete():
drivers/net/wireguard/send.c:wg_packet_tx_worker() {
...
if (unlikely(state == PACKET_STATE_DRAIN)) {
complete(PACKET_CB(first)->completion);
break;
}
...
}
wg_packet_rx_poll() follows the same pattern.
These calls seem to quiesce TX work and NAPI polls that the remover or
wg_queue_enqueue_per_peer_tx()/rx() may have rescheduled. That has to
happen before netif_napi_del() and the final wg_peer_put(). Could the
comment say that? Otherwise a later change might drop or reorder the
flush_work()/napi_disable() pair as if it only concerned sentinel lifetime.
The comment above the wg_prev_queue_enqueue_sentinel() calls says the
sentinels go on the "encryption/decryption queues". In this driver that
usually means the device-wide wg->encrypt_queue and wg->decrypt_queue
ptr_rings. The sentinels actually go on the per-peer peer->tx_queue and
peer->rx_queue. Could that comment name the per-peer serial queues instead?
[ ... ]
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-fix-wg-peer-removal-v4-1-55e7d45fd250%40cloudflare.com
Technical Details
Message-ID:
<179632093175.3146.17526868242498836785@kernel.org>Path:
mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376807-linux-kernel-netdev=dewy.ruReferences:
<20261202-fix-wg-peer-removal-v4-1-55e7d45fd250@cloudflare.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376807-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v4] wireguard: drain per-peer queues with sentinels Date: Thu, 03 Dec 2026 18:02:11 +0000 Organization: Usenet Network Message-ID: <179632093175.3146.17526868242498836785@kernel.org> References: <20261202-fix-wg-peer-removal-v4-1-55e7d45fd250@cloudflare.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2560942"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:AA66Ionwxf2HbVcOZE57MO+Wwog= sha256:+TX22t3MwRMJ9WhMEetbrbZ+zvIuViuLBCTIC5mZBVg= sha1:W/Nv6hhzOVFWmMTkVZgJi65yOnI= sha256:QIYmBChp+MmGw1421/AnUbxLSXLiDIP7ticqVnSXPN4= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 142651179FF; Thu, 3 Dec 2026 21:02:32 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.74 X-Spam-Status: No, score=-3.74 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QGpjadPKlnaN; Thu, 3 Dec 2026 21:02:28 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376807-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 73ED11179B9; Thu, 3 Dec 2026 21:02:19 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 5D3A925100; Thu, 3 Dec 2026 18:02:16 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796320934; b=HJuGb3JvWuJtYvnIvh2i2riFwvxTSE+BRcvqcazkF/CMUQJ6zjfNASNThmWoSXe4Baau gmCB/5F3KcXFSv7GiuG7Fr3KF+tIQW+nzqu1wtxUd+7T3xIKGYbwwO+Lne4LiM1plq2Bg AJXhsr9G7aoUMJo8CNyP0+wBEkgnskFYE1czcfy6zcS0ICjOOlAd+MnxlXTZSnPz25UzR UNLbZUy2fUCmF7yTaCJSHPLytnVuQsvxqNPFwA93Fk7G0rtjLjJuVIKJtAdhFcyqbm9Wg Qo/NVZiuaaRU7FVTfp7p7VQ9VEGqma4Dui9ZaJOoQA/+zgasQ4NOX2kN8GqM8oyWQmg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796320934; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=B3NfUtPUUADbr5jKwGpHnOD6bl/nIh/vNqK7U3fIGUI=; b=ldllL5h55p3bLGM20cXsJIJzJddZgeH5wN/IAEj2rLrZFgtjc4NSILGExmsZMgUGtHAJ 1jTMYeZp29lELEF5hiPSFfpVzfBI8Uk7nVFUr/2kaPizMjJNURVKJtxja78FZlpGoA0Gs 1dYgr35fn416Y1KBIbSSh6Eg6XAK93gukC4M16EHFSnkGjrd6Xzeq2+6+oKbeIBBSse2p e/0RzaoJlAWbogzaJUDkmb51EgaAv9U695xq216RRbFM4Jc98G2MVkOBbe7QGuw/f+p3x rADwAyy+WQRSNgMWSzGDjo1/tIN6yI/xNhZ7Pcz0C5l+tvP3IRO8ZH41IrrAViZgQtQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NAT517NE; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DCC00606A333; Thu, 3 Dec 2026 18:02:13 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NAT517NE X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796320933; b=1cRlVbkjOst7S7xfsAo16G2Yntg8LCJ5gluYtlTtXn3ZnnU76JL5OkVXN0XMIlxQjjbD H+iABSHZ+yYT5ovyNJ/exNcCPrbfNnnK6KteRgKYwu7QyZ/jDQVxdEoZWnLVTDLa2ARKb l1hprK2VW9+RZZyp2zb9KsHLf4+Da9qQUFGonp4UCKCBazlJQS7fd5YcCQ7N7SY8rPnnx HqQpEBFsqGUf45C7Z3Y70ufdl0Cu7MPO+jL5Nu7auy8LyUcd44XlSYyjT274HW+nQ2BMb 0XlxhJZgWtBHpEXOyIU1Mxu3xgM3IrjrZwdPkbDfjXOsYi0MnAQQDZyqacv/AL1kBqA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796320933; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=B3NfUtPUUADbr5jKwGpHnOD6bl/nIh/vNqK7U3fIGUI=; b=3Eqhuleh7oGqfVAALFfVTokbps0xRKi0KLw1Q5NfBLjZKrdMyaHrHg1Gbza13YTa0XGY QBPAFBVKChX4v98ZlmUzgMZbi2VgTcjOLzOG5eUqFQdfXi90vUlprEvkt1619vBtdacfi /u5C6/tG+fasXSnaAmcblt7LfwrbkdXxrgjLcWJgVBqXi+hYmPI/DkbDExij6S07lmdxb bWOlNs4VzXw0SrZac9EQ/+p9aEiHk9OgAEFPoZtIXXn+Th9xCcIhKWycY4FgTz1nj4CoQ Ubx0vZ6Eokd0h695DooC8rtIq6PbFyK6/I8wUlVUc3lllPlKE+yt18Ss0SMUTvMrhdg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NAT517NE; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03B90606A322 for <netdev@vger.kernel.org>; Thu, 3 Dec 2026 18:02:13 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42D7D1F000C1; Thu, 3 Dec 2026 18:02:12 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796320932; bh=B3NfUtPUUADbr5jKwGpHnOD6bl/nIh/vNqK7U3fIGUI=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=NAT517NEtaR+1LhhIhwCqgnXSxpFkPRGjklThgbqSIGOrFhsdFFnAMas1bxmhS3RJ +P5/wL9oTj7y8J0B6sJ9k9F8Zga2YDURRGhkOtzjH4KaWfo4VA/0egsuXBR2Z6rDpT rhXirecUpbJK5oWDNGa80zQVdQm3X9KDaXmII6dmm3WiISZi/gMmG8lM5cutCRIktn 0X5jIQZqQ6wCFOs91GS2y/V+p4Z/MecgvoCeWaKADjP1ulziphZWLBXB2RDsy9nrm3 7zs8RJNwakVFoXbQ8TfFRl+gk0hQ0DTVTrx3OxRjIsylJOPhx+nQL9DJjnSYJ6fSNT V84504dlzcgeg== X-Cc: Jason@zx2c4.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, wireguard@lists.zx2c4.com, netdev@vger.kernel.org, kernel-team@cloudflare.com X-In-Reply-To: <20261202-fix-wg-peer-removal-v4-1-55e7d45fd250@cloudflare.com> X-sashiko-severity: Medium X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list