Module Name: src Committed By: riastradh Date: Mon Jul 29 16:01:13 UTC 2024
Modified Files: src/sys/net: if_wg.c Log Message: wg(4): Omit needless atomic_load. wgs_local_index is only ever written to while only one thread has access to it and it is not in the thmap -- before it is published in wg_get_session_index, and after it is unpublished in wg_destroy_session. So no need for atomic_load -- it is stable if we observe it in thmap_get result. (Of course this is only for an assertion, which if tripped obviously indicates a violation of our assumptions. But if that happens, well, in the worst case we'll see a weird assertion message claiming that the index is not equal to itself, which from which we can conclude there must have been a concurrent update, which is good enough to help diagnose that problem without any atomic_load.) Tidying some of the changes for: PR kern/55729: net/if_wg/t_misc:wg_rekey test case fails PR kern/56252: wg(4) state machine has race conditions PR kern/58463: if_wg does not work when idle. To generate a diff of this commit: cvs rdiff -u -r1.119 -r1.120 src/sys/net/if_wg.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/if_wg.c diff -u src/sys/net/if_wg.c:1.119 src/sys/net/if_wg.c:1.120 --- src/sys/net/if_wg.c:1.119 Mon Jul 29 16:00:41 2024 +++ src/sys/net/if_wg.c Mon Jul 29 16:01:13 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: if_wg.c,v 1.119 2024/07/29 16:00:41 riastradh Exp $ */ +/* $NetBSD: if_wg.c,v 1.120 2024/07/29 16:01:13 riastradh Exp $ */ /* * Copyright (C) Ryota Ozaki <ozaki.ry...@gmail.com> @@ -41,7 +41,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.119 2024/07/29 16:00:41 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.120 2024/07/29 16:01:13 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_altq_enabled.h" @@ -2490,11 +2490,9 @@ wg_lookup_session_by_index(struct wg_sof int s = pserialize_read_enter(); wgs = thmap_get(wg->wg_sessions_byindex, &index, sizeof index); if (wgs != NULL) { - uint32_t oindex __diagused = - atomic_load_relaxed(&wgs->wgs_local_index); - KASSERTMSG(index == oindex, + KASSERTMSG(index == wgs->wgs_local_index, "index=%"PRIx32" wgs->wgs_local_index=%"PRIx32, - index, oindex); + index, wgs->wgs_local_index); psref_acquire(psref, &wgs->wgs_psref, wg_psref_class); } pserialize_read_exit(s);