Skip to contentSkip to conversation

WireGuard fixes for 7.1-rc1

PATCH Applied Jason A. Donenfeld 2 participants 6 messages Apr 14

Subsystems (5)
lore
Share & tools
lore

Jason A. Donenfeld

author maintainer
#0 lore raw

cover WireGuard fixes for 7.1-rc1

Hi Jakub,

Please find 4 simple patches attached:

1) Asbjørn's YNL sample, finally merged. Sorry for the wait on this one.

2) A simplification to use kfree_rcu instead of call_rcu, since kfree_rcu now works with kmem caches.

3) A trivial formatting derp.

4) Fix for a deadlock by moving to using exit_rtnl instead of pre_exit.

Please apply these!

Thanks,
Jason

Asbjørn Sloth Tønnesen (1):
tools: ynl: add sample for wireguard

Fushuai Wang (1):
wireguard: allowedips: Use kfree_rcu() instead of call_rcu()

Jason A. Donenfeld (1):
wireguard: allowedips: remove redundant space in comment

Shardul Bankar (1):
wireguard: device: use exit_rtnl callback instead of manual rtnl_lock
in pre_exit

 drivers/net/wireguard/allowedips.c          |   9 +-
 drivers/net/wireguard/device.c              |   8 +-
 drivers/net/wireguard/selftest/allowedips.c |   2 +-
 tools/net/ynl/tests/.gitignore              |   1 +
 tools/net/ynl/tests/wireguard.c             | 106 ++++++++++++++++++++
 5 files changed, 113 insertions(+), 13 deletions(-)
 create mode 100644 tools/net/ynl/tests/wireguard.c
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH 1/4 wireguard: allowedips: Use kfree_rcu() instead of call_rcu()

From: Fushuai Wang <[email protected]>

Replace call_rcu() + kmem_cache_free() with kfree_rcu() to simplify the code and reduce function size.

---
 drivers/net/wireguard/allowedips.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/net/wireguard/allowedips.c +2 -7
index 09f7fcd7da78b..5ece9acad64d8 100644
@@ -48,11 +48,6 @@ static void push_rcu(struct allowedips_node **stack,
 	}
 }
 
-static void node_free_rcu(struct rcu_head *rcu)
-{
-	kmem_cache_free(node_cache, container_of(rcu, struct allowedips_node, rcu));
-}
-
 static void root_free_rcu(struct rcu_head *rcu)
 {
 	struct allowedips_node *node, *stack[MAX_ALLOWEDIPS_DEPTH] = {
@@ -271,13 +266,13 @@ static void remove_node(struct allowedips_node *node, struct mutex *lock)
 	if (free_parent)
 		child = rcu_dereference_protected(parent->bit[!(node->parent_bit_packed & 1)],
 						  lockdep_is_held(lock));
-	call_rcu(&node->rcu, node_free_rcu);
+	kfree_rcu(node, rcu);
 	if (!free_parent)
 		return;
 	if (child)
 		child->parent_bit_packed = parent->parent_bit_packed;
 	*(struct allowedips_node **)(parent->parent_bit_packed & ~3UL) = child;
-	call_rcu(&parent->rcu, node_free_rcu);
+	kfree_rcu(parent, rcu);
 }
 
 static int remove(struct allowedips_node __rcu **trie, u8 bits, const u8 *key,
Signature · 1 line
2.53.0
author maintainer
#2 lore raw

PATCH 2/4 tools: ynl: add sample for wireguard

In reply to Jason A. Donenfeld

From: Asbjørn Sloth Tønnesen <[email protected]>

Add a sample application for WireGuard, using the generated C library.

The main benefit of this is to exercise the generated library, which might be useful for future self-tests.

Example:

  $ make -C tools/net/ynl/lib
  $ make -C tools/net/ynl/generated
  $ make -C tools/net/ynl/tests wireguard
  $ ./tools/net/ynl/tests/wireguard
  usage: ./tools/net/ynl/tests/wireguard <ifindex|ifname>
  $ sudo ./tools/net/ynl/tests/wireguard wg-test
  Interface 3: wg-test
      Peer 6adfb183a4a2c94a2f92dab5ade762a4788[...]:
          Data: rx: 42 / tx: 42 bytes
          Allowed IPs:
              0.0.0.0/0
              ::/0
---
 tools/net/ynl/tests/.gitignore  |   1 +
 tools/net/ynl/tests/wireguard.c | 106 ++++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+)
 create mode 100644 tools/net/ynl/tests/wireguard.c
tools/net/ynl/tests/.gitignore +1 -0
index 045385df42a45..a7832ebfdbbc3 100644
@@ -7,3 +7,4 @@ rt-link
 rt-route
 tc
 tc-filter-add
+wireguard
tools/net/ynl/tests/wireguard.c new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
2.53.0
author maintainer
#3 lore raw

PATCH 3/4 wireguard: allowedips: remove redundant space

In reply to Jason A. Donenfeld

Not a contentful commit, but amusingly found when porting ba3d7b93 to Windows.

---
 drivers/net/wireguard/selftest/allowedips.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireguard/selftest/allowedips.c +1 -1
index 2da3008c3a014..3e857e6fb627b 100644
@@ -623,7 +623,7 @@ bool __init wg_allowedips_selftest(void)
 	test_boolean(!remove(6, b, 0x24446801, 0x40e40800, 0xdeaebeef, 0xdefbeef, 128));
 	test(6, a, 0x24446801, 0x40e40800, 0xdeaebeef, 0xdefbeef);
 	/* invalid CIDR should have no effect and return -EINVAL */
-	test_boolean(remove(6, a, 0x24446801, 0x40e40800, 0xdeaebeef, 0xdefbeef, 129)  == -EINVAL);
+	test_boolean(remove(6, a, 0x24446801, 0x40e40800, 0xdeaebeef, 0xdefbeef, 129) == -EINVAL);
 	test(6, a, 0x24446801, 0x40e40800, 0xdeaebeef, 0xdefbeef);
 	remove(6, a, 0x24446801, 0x40e40800, 0xdeaebeef, 0xdefbeef, 128);
 	test_negative(6, a, 0x24446801, 0x40e40800, 0xdeaebeef, 0xdefbeef);
Signature · 1 line
2.53.0
author maintainer
#4 lore raw

PATCH 4/4 wireguard: device: use exit_rtnl callback instead of manual rtnl_lock in pre_exit

In reply to Jason A. Donenfeld

From: Shardul Bankar <[email protected]>

wg_netns_pre_exit() manually acquires rtnl_lock() inside the pernet .pre_exit callback. This causes a hung task when another thread holds rtnl_mutex - the cleanup_net workqueue (or the setup_net failure rollback path) blocks indefinitely in wg_netns_pre_exit() waiting to acquire the lock.

Convert to .exit_rtnl, introduced in commit 7a60d91c690b ("net:
Add ->exit_rtnl() hook to struct pernet_operations."), where the framework already holds RTNL and batches all callbacks under a single rtnl_lock()/rtnl_unlock() pair, eliminating the contention window.

The rcu_assign_pointer(wg->creating_net, NULL) is safe to move from .pre_exit to .exit_rtnl (which runs after synchronize_rcu()) because all RCU readers of creating_net either use maybe_get_net()
- which returns NULL for a dying namespace with zero refcount - or access net->user_ns which remains valid throughout the entire ops_undo_list sequence.

Reported-by [email protected]
[ Jason: added __net_exit and __read_mostly annotations that were missing. ]
Fixes 900575aa33a3 ("wireguard: device: avoid circular netns references")
---
 drivers/net/wireguard/device.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/wireguard/device.c +3 -5
index 46a71ec36af87..67b07ee2d6600 100644
@@ -411,12 +411,11 @@ static struct rtnl_link_ops link_ops __read_mostly = {
 	.newlink		= wg_newlink,
 };
 
-static void wg_netns_pre_exit(struct net *net)
+static void __net_exit wg_netns_exit_rtnl(struct net *net, struct list_head *dev_kill_list)
 {
 	struct wg_device *wg;
 	struct wg_peer *peer;
 
-	rtnl_lock();
 	list_for_each_entry(wg, &device_list, device_list) {
 		if (rcu_access_pointer(wg->creating_net) == net) {
 			pr_debug("%s: Creating namespace exiting\n", wg->dev->name);
@@ -429,11 +428,10 @@ static void wg_netns_pre_exit(struct net *net)
 			mutex_unlock(&wg->device_update_lock);
 		}
 	}
-	rtnl_unlock();
 }
 
-static struct pernet_operations pernet_ops = {
-	.pre_exit = wg_netns_pre_exit
+static struct pernet_operations pernet_ops __read_mostly = {
+	.exit_rtnl = wg_netns_exit_rtnl
 };
 
 int __init wg_device_init(void)
Signature · 1 line
2.53.0
#5 lore raw
In reply to Jason A. Donenfeld
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Tue, 14 Apr 2026 17:39:40 +0200 you wrote:

Hi Jakub,

Please find 4 simple patches attached:

1) Asbjørn's YNL sample, finally merged. Sorry for the wait on this one.

2) A simplification to use kfree_rcu instead of call_rcu, since kfree_rcu now works with kmem caches.

[...]

Here is the summary with links:
- [net-next,1/4] wireguard: allowedips: Use kfree_rcu() instead of call_rcu()

    https://git.kernel.org/netdev/net-next/c/e5549aecdd24
  - [net-next,2/4] tools: ynl: add sample for wireguard
    https://git.kernel.org/netdev/net-next/c/121f416756d6
  - [net-next,3/4] wireguard: allowedips: remove redundant space
    https://git.kernel.org/netdev/net-next/c/f364db381c9d
  - [net-next,4/4] wireguard: device: use exit_rtnl callback instead of manual rtnl_lock in pre_exit
    https://git.kernel.org/netdev/net-next/c/60a25ef8dacb

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html