Module Name:    src
Committed By:   riastradh
Date:           Sun Sep 13 17:18:13 UTC 2020

Modified Files:
        src/sys/net: if_wg.c

Log Message:
wg: Use RUN_ONCE to defer workqueue_create until after configure.

Should really fix workqueue(9) so workqueue_create can be done before
CPUs have been detected in configure, but this will serve as a stop-
gap measure.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 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.57 src/sys/net/if_wg.c:1.58
--- src/sys/net/if_wg.c:1.57	Sun Sep 13 17:17:31 2020
+++ src/sys/net/if_wg.c	Sun Sep 13 17:18:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wg.c,v 1.57 2020/09/13 17:17:31 riastradh Exp $	*/
+/*	$NetBSD: if_wg.c,v 1.58 2020/09/13 17:18: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.57 2020/09/13 17:17:31 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.58 2020/09/13 17:18:13 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -64,6 +64,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.
 #include <sys/mbuf.h>
 #include <sys/module.h>
 #include <sys/mutex.h>
+#include <sys/once.h>
 #include <sys/percpu.h>
 #include <sys/pserialize.h>
 #include <sys/psref.h>
@@ -807,13 +808,25 @@ wgattach(int count)
 static void
 wginit(void)
 {
-	int error __diagused;
 
 	wg_psref_class = psref_class_create("wg", IPL_SOFTNET);
 
 	mutex_init(&wg_softcs.lock, MUTEX_DEFAULT, IPL_NONE);
 	LIST_INIT(&wg_softcs.list);
 
+	if_clone_attach(&wg_cloner);
+}
+
+/*
+ * XXX Kludge: This should just happen in wginit, but workqueue_create
+ * cannot be run until after CPUs have been detected, and wginit runs
+ * before configure.
+ */
+static int
+wginitqueues(void)
+{
+	int error __diagused;
+
 	wg_pktq = pktq_create(IFQ_MAXLEN, wgintr, NULL);
 	KASSERT(wg_pktq != NULL);
 
@@ -821,7 +834,17 @@ wginit(void)
 	    PRI_NONE, IPL_SOFTNET, WQ_MPSAFE|WQ_PERCPU);
 	KASSERT(error == 0);
 
-	if_clone_attach(&wg_cloner);
+	return 0;
+}
+
+static void
+wg_guarantee_initialized(void)
+{
+	static ONCE_DECL(init);
+	int error __diagused;
+
+	error = RUN_ONCE(&init, wginitqueues);
+	KASSERT(error == 0);
 }
 
 static int
@@ -3530,6 +3553,8 @@ wg_clone_create(struct if_clone *ifc, in
 	struct wg_softc *wg;
 	int error;
 
+	wg_guarantee_initialized();
+
 	wg = kmem_zalloc(sizeof(*wg), KM_SLEEP);
 
 	if_initname(&wg->wg_if, ifc->ifc_name, unit);

Reply via email to