Module Name:    src
Committed By:   ozaki-r
Date:           Mon Sep 25 01:57:54 UTC 2017

Modified Files:
        src/sys/net: raw_usrreq.c rtsock.c

Log Message:
Use a dedicated mutex for rt_rawcb instead of softnet_lock if NET_MPSAFE


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/net/raw_usrreq.c
cvs rdiff -u -r1.228 -r1.229 src/sys/net/rtsock.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/raw_usrreq.c
diff -u src/sys/net/raw_usrreq.c:1.57 src/sys/net/raw_usrreq.c:1.58
--- src/sys/net/raw_usrreq.c:1.57	Mon Sep 25 01:56:22 2017
+++ src/sys/net/raw_usrreq.c	Mon Sep 25 01:57:54 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: raw_usrreq.c,v 1.57 2017/09/25 01:56:22 ozaki-r Exp $	*/
+/*	$NetBSD: raw_usrreq.c,v 1.58 2017/09/25 01:57:54 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: raw_usrreq.c,v 1.57 2017/09/25 01:56:22 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_usrreq.c,v 1.58 2017/09/25 01:57:54 ozaki-r Exp $");
 
 #include <sys/param.h>
 #include <sys/mbuf.h>
@@ -75,8 +75,6 @@ raw_input(struct mbuf *m0, ...)
 	struct sockaddr *src, *dst;
 	struct rawcbhead *rawcbhead;
 
-	KASSERT(mutex_owned(softnet_lock));
-
 	va_start(ap, m0);
 	proto = va_arg(ap, struct sockproto *);
 	src = va_arg(ap, struct sockaddr *);

Index: src/sys/net/rtsock.c
diff -u src/sys/net/rtsock.c:1.228 src/sys/net/rtsock.c:1.229
--- src/sys/net/rtsock.c:1.228	Mon Sep 25 01:56:22 2017
+++ src/sys/net/rtsock.c	Mon Sep 25 01:57:54 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtsock.c,v 1.228 2017/09/25 01:56:22 ozaki-r Exp $	*/
+/*	$NetBSD: rtsock.c,v 1.229 2017/09/25 01:57:54 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.228 2017/09/25 01:56:22 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.229 2017/09/25 01:57:54 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -184,6 +184,11 @@ struct routecb {
 };
 #define sotoroutecb(so)	((struct routecb *)(so)->so_pcb)
 
+static struct rawcbhead rt_rawcb;
+#ifdef NET_MPSAFE
+static kmutex_t *rt_so_mtx;
+#endif
+
 static void
 rt_adjustcount(int af, int cnt)
 {
@@ -260,6 +265,14 @@ COMPATNAME(route_attach)(struct socket *
 	so->so_pcb = rp;
 
 	s = splsoftnet();
+
+#ifdef NET_MPSAFE
+	KASSERT(so->so_lock == NULL);
+	mutex_obj_hold(rt_so_mtx);
+	so->so_lock = rt_so_mtx;
+	solock(so);
+#endif
+
 	if ((error = raw_attach(so, proto, &rt_rawcb)) == 0) {
 		rt_adjustcount(rp->rcb_proto.sp_protocol, 1);
 		rp->rcb_laddr = &COMPATNAME(route_info).ri_src;
@@ -2025,8 +2038,10 @@ COMPATNAME(route_intr)(void *cookie)
 	struct route_info * const ri = &COMPATNAME(route_info);
 	struct mbuf *m;
 
+#ifndef NET_MPSAFE
 	mutex_enter(softnet_lock);
 	KERNEL_LOCK(1, NULL);
+#endif
 	for (;;) {
 		IFQ_LOCK(&ri->ri_intrq);
 		IF_DEQUEUE(&ri->ri_intrq, m);
@@ -2034,10 +2049,18 @@ COMPATNAME(route_intr)(void *cookie)
 		if (m == NULL)
 			break;
 		proto.sp_protocol = M_GETCTX(m, uintptr_t);
+#ifdef NET_MPSAFE
+		mutex_enter(rt_so_mtx);
+#endif
 		raw_input(m, &proto, &ri->ri_src, &ri->ri_dst, &rt_rawcb);
+#ifdef NET_MPSAFE
+		mutex_exit(rt_so_mtx);
+#endif
 	}
+#ifndef NET_MPSAFE
 	KERNEL_UNLOCK_ONE(NULL);
 	mutex_exit(softnet_lock);
+#endif
 }
 
 /*
@@ -2075,6 +2098,9 @@ COMPATNAME(route_init)(void)
 #ifndef COMPAT_RTSOCK
 	rt_init();
 #endif
+#ifdef NET_MPSAFE
+	rt_so_mtx = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
+#endif
 
 	sysctl_net_route_setup(NULL);
 	ri->ri_intrq.ifq_maxlen = ri->ri_maxqlen;

Reply via email to