Skip to content

Commit 6fbc0e6

Browse files
committed
global: use synchronize_net rather than synchronize_rcu
Many of the synchronization points are sometimes called under the rtnl lock, which means we should use synchronize_net rather than synchronize_rcu. Under the hood, this expands to using the expedited flavor of function in the event that rtnl is held, in order to not stall other concurrent changes. This fixes some very, very long delays when removing multiple peers at once, which would cause some operations to take several minutes. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent 405caf0 commit 6fbc0e6

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/peer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static void peer_make_dead(struct wg_peer *peer)
8888
/* Mark as dead, so that we don't allow jumping contexts after. */
8989
WRITE_ONCE(peer->is_dead, true);
9090

91-
/* The caller must now synchronize_rcu() for this to take effect. */
91+
/* The caller must now synchronize_net() for this to take effect. */
9292
}
9393

9494
static void peer_remove_after_dead(struct wg_peer *peer)
@@ -160,7 +160,7 @@ void wg_peer_remove(struct wg_peer *peer)
160160
lockdep_assert_held(&peer->device->device_update_lock);
161161

162162
peer_make_dead(peer);
163-
synchronize_rcu();
163+
synchronize_net();
164164
peer_remove_after_dead(peer);
165165
}
166166

@@ -178,7 +178,7 @@ void wg_peer_remove_all(struct wg_device *wg)
178178
peer_make_dead(peer);
179179
list_add_tail(&peer->peer_list, &dead_peers);
180180
}
181-
synchronize_rcu();
181+
synchronize_net();
182182
list_for_each_entry_safe(peer, temp, &dead_peers, peer_list)
183183
peer_remove_after_dead(peer);
184184
}

src/socket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ void wg_socket_reinit(struct wg_device *wg, struct sock *new4,
430430
if (new4)
431431
wg->incoming_port = ntohs(inet_sk(new4)->inet_sport);
432432
mutex_unlock(&wg->socket_update_lock);
433-
synchronize_rcu();
433+
synchronize_net();
434434
sock_free(old4);
435435
sock_free(old6);
436436
}

0 commit comments

Comments
 (0)