Module Name:    src
Committed By:   ozaki-r
Date:           Wed Jan 10 02:50:26 UTC 2018

Modified Files:
        src/sys/kern: uipc_domain.c
        src/sys/rump/librump/rumpnet: rump_net.c
        src/sys/sys: domain.h

Log Message:
Don't start callouts for domains before attaching domains on rump kernels

On rump kernels, the callouts for domains, pffasttimo and pfslowtimo, started
before domains were attached. Normally the callouts were dispatched after
domain attaches (initializations) finished, however, under load the callouts
could be executed prior to the attaches, resulting in that the callouts accessed
unallocated or uninitialized resources.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/kern/uipc_domain.c
cvs rdiff -u -r1.20 -r1.21 src/sys/rump/librump/rumpnet/rump_net.c
cvs rdiff -u -r1.33 -r1.34 src/sys/sys/domain.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/uipc_domain.c
diff -u src/sys/kern/uipc_domain.c:1.100 src/sys/kern/uipc_domain.c:1.101
--- src/sys/kern/uipc_domain.c:1.100	Sat Sep  9 14:41:19 2017
+++ src/sys/kern/uipc_domain.c	Wed Jan 10 02:50:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_domain.c,v 1.100 2017/09/09 14:41:19 joerg Exp $	*/
+/*	$NetBSD: uipc_domain.c,v 1.101 2018/01/10 02:50:26 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_domain.c,v 1.100 2017/09/09 14:41:19 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_domain.c,v 1.101 2018/01/10 02:50:26 ozaki-r Exp $");
 
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -84,6 +84,17 @@ static void sysctl_net_setup(void);
 static struct domain domain_dummy;
 __link_set_add_rodata(domains,domain_dummy);
 
+static void
+domain_init_timers(void)
+{
+
+	callout_init(&pffasttimo_ch, CALLOUT_MPSAFE);
+	callout_init(&pfslowtimo_ch, CALLOUT_MPSAFE);
+
+	callout_reset(&pffasttimo_ch, 1, pffasttimo, NULL);
+	callout_reset(&pfslowtimo_ch, 1, pfslowtimo, NULL);
+}
+
 void
 domaininit(bool attach)
 {
@@ -108,13 +119,20 @@ domaininit(bool attach)
 		}
 		if (rt_domain)
 			domain_attach(rt_domain);
+
+		domain_init_timers();
 	}
+}
 
-	callout_init(&pffasttimo_ch, CALLOUT_MPSAFE);
-	callout_init(&pfslowtimo_ch, CALLOUT_MPSAFE);
+/*
+ * Must be called only if domaininit has been called with false and
+ * after all domains have been attached.
+ */
+void
+domaininit_post(void)
+{
 
-	callout_reset(&pffasttimo_ch, 1, pffasttimo, NULL);
-	callout_reset(&pfslowtimo_ch, 1, pfslowtimo, NULL);
+	domain_init_timers();
 }
 
 void

Index: src/sys/rump/librump/rumpnet/rump_net.c
diff -u src/sys/rump/librump/rumpnet/rump_net.c:1.20 src/sys/rump/librump/rumpnet/rump_net.c:1.21
--- src/sys/rump/librump/rumpnet/rump_net.c:1.20	Tue Jan 17 02:03:09 2017
+++ src/sys/rump/librump/rumpnet/rump_net.c	Wed Jan 10 02:50:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: rump_net.c,v 1.20 2017/01/17 02:03:09 christos Exp $	*/
+/*	$NetBSD: rump_net.c,v 1.21 2018/01/10 02:50:26 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rump_net.c,v 1.20 2017/01/17 02:03:09 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump_net.c,v 1.21 2018/01/10 02:50:26 ozaki-r Exp $");
 
 #include <sys/param.h>
 
@@ -56,4 +56,6 @@ RUMP_COMPONENT(RUMP__FACTION_NET)
 	rump_component_init(RUMP_COMPONENT_NET_ROUTE);
 	rump_component_init(RUMP_COMPONENT_NET_IF);
 	rump_component_init(RUMP_COMPONENT_NET_IFCFG);
+
+	domaininit_post();
 }

Index: src/sys/sys/domain.h
diff -u src/sys/sys/domain.h:1.33 src/sys/sys/domain.h:1.34
--- src/sys/sys/domain.h:1.33	Thu Sep 21 07:15:35 2017
+++ src/sys/sys/domain.h	Wed Jan 10 02:50:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: domain.h,v 1.33 2017/09/21 07:15:35 ozaki-r Exp $	*/
+/*	$NetBSD: domain.h,v 1.34 2018/01/10 02:50:26 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -103,6 +103,7 @@ STAILQ_HEAD(domainhead,domain);
 extern struct domainhead domains;
 void domain_attach(struct domain *);
 void domaininit(bool);
+void domaininit_post(void);
 #endif
 
 #endif /* !_SYS_DOMAIN_H_ */

Reply via email to