Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net Fix race in wg_worker kthread destruction.
details: https://anonhg.NetBSD.org/src/rev/9d159c305d1d
branches: trunk
changeset: 1013080:9d159c305d1d
user: riastradh <riastradh%NetBSD.org@localhost>
date: Thu Aug 20 21:34:13 2020 +0000
description:
Fix race in wg_worker kthread destruction.
Also allow the thread to migrate between CPUs -- just not while we're
in the middle of processing and holding onto things with psrefs.
diffstat:
sys/net/if_wg.c | 22 +++++++++++-----------
1 files changed, 11 insertions(+), 11 deletions(-)
diffs (60 lines):
diff -r 4aea1cc63d7f -r 9d159c305d1d sys/net/if_wg.c
--- a/sys/net/if_wg.c Thu Aug 20 21:34:03 2020 +0000
+++ b/sys/net/if_wg.c Thu Aug 20 21:34:13 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_wg.c,v 1.9 2020/08/20 21:34:03 riastradh Exp $ */
+/* $NetBSD: if_wg.c,v 1.10 2020/08/20 21:34:13 riastradh Exp $ */
/*
* Copyright (C) Ryota Ozaki <ozaki.ryota%gmail.com@localhost>
@@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.9 2020/08/20 21:34:03 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.10 2020/08/20 21:34:13 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -2736,32 +2736,32 @@
{
struct wg_softc *wg = arg;
struct wg_worker *wgw = wg->wg_worker;
- int bound = curlwp_bind();
+ bool todie = false;
KASSERT(wg != NULL);
KASSERT(wgw != NULL);
- while (!wgw->wgw_todie) {
+ while (!todie) {
int reasons;
+ int bound;
mutex_enter(&wgw->wgw_lock);
/* New tasks may come during task handling */
- if (wgw->wgw_wakeup_reasons == 0)
+ while ((reasons = wgw->wgw_wakeup_reasons) == 0 &&
+ !(todie = wgw->wgw_todie))
cv_wait(&wgw->wgw_cv, &wgw->wgw_lock);
- reasons = wgw->wgw_wakeup_reasons;
wgw->wgw_wakeup_reasons = 0;
mutex_exit(&wgw->wgw_lock);
+ bound = curlwp_bind();
if (ISSET(reasons, WG_WAKEUP_REASON_RECEIVE_PACKETS_IPV4))
wg_receive_packets(wg, AF_INET);
if (ISSET(reasons, WG_WAKEUP_REASON_RECEIVE_PACKETS_IPV6))
wg_receive_packets(wg, AF_INET6);
- if (!ISSET(reasons, WG_WAKEUP_REASON_PEER))
- continue;
-
- wg_process_peer_tasks(wg);
+ if (ISSET(reasons, WG_WAKEUP_REASON_PEER))
+ wg_process_peer_tasks(wg);
+ curlwp_bindx(bound);
}
- curlwp_bindx(bound);
kthread_exit(0);
}
Home |
Main Index |
Thread Index |
Old Index