Module Name: src Committed By: riastradh Date: Tue Sep 8 16:39:58 UTC 2020
Modified Files: src/sys/net: if_wg.c Log Message: wg: Drop wgp_lock while waiting for endpoint psref to drain. - This is safe because wgp_endpoint_changing locks out any attempts to change the endpoint until the draining is complete. - This is necessary to avoid a deadlock where the handshake thread holds a psref and awaits mutex_enter(wgp->wgp_lock). XXX The same deadlock may occur in wg_destroy_session. Not clear that it's safe to just release wgp_lock there; may need to create a new session state, say WGS_STATE_DRAINING, while we wait for psref_target_destroy. But this needs a little more thought; a new state may not be necessary, and would be nice to avoid if not necessary. To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 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.55 src/sys/net/if_wg.c:1.56 --- src/sys/net/if_wg.c:1.55 Mon Sep 7 01:15:25 2020 +++ src/sys/net/if_wg.c Tue Sep 8 16:39:57 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: if_wg.c,v 1.55 2020/09/07 01:15:25 riastradh Exp $ */ +/* $NetBSD: if_wg.c,v 1.56 2020/09/08 16:39:57 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.55 2020/09/07 01:15:25 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.56 2020/09/08 16:39:57 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -2965,10 +2965,12 @@ wg_task_endpoint_changed(struct wg_softc if (atomic_load_relaxed(&wgp->wgp_endpoint_changing)) { pserialize_perform(wgp->wgp_psz); + mutex_exit(wgp->wgp_lock); psref_target_destroy(&wgp->wgp_endpoint0->wgsa_psref, wg_psref_class); psref_target_init(&wgp->wgp_endpoint0->wgsa_psref, wg_psref_class); + mutex_enter(wgp->wgp_lock); atomic_store_release(&wgp->wgp_endpoint_changing, 0); } }