Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Provide macros for softnet_lock and KERNEL_LOCK hiding N...
details: https://anonhg.NetBSD.org/src/rev/a26635b14dc5
branches: trunk
changeset: 357594:a26635b14dc5
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Fri Nov 17 07:37:12 2017 +0000
description:
Provide macros for softnet_lock and KERNEL_LOCK hiding NET_MPSAFE switch
It reduces C&P codes such as "#ifndef NET_MPSAFE KERNEL_LOCK(1, NULL); ..."
scattered all over the source code and makes it easy to identify remaining
KERNEL_LOCK and/or softnet_lock that are held even if NET_MPSAFE.
No functional change
diffstat:
sys/net/bpf.c | 28 ++++++++--------------------
sys/net/if.c | 14 ++++----------
sys/net/if.h | 42 +++++++++++++++++++++++++++++++++++++++++-
sys/net/if_loop.c | 12 ++++--------
sys/net/if_pppoe.c | 13 +++++--------
sys/net/npf/npf_os.c | 24 ++++++------------------
sys/net/rtsock.c | 14 ++++----------
sys/netinet/if_arp.c | 25 ++++++-------------------
sys/netinet/igmp.c | 12 ++++--------
sys/netinet/in.c | 12 ++++--------
sys/netinet/ip_flow.c | 42 ++++++++++--------------------------------
sys/netinet/ip_input.c | 22 ++++++----------------
sys/netinet/ip_output.c | 12 ++++--------
sys/netinet6/frag6.c | 24 ++++++------------------
sys/netinet6/in6.c | 20 ++++++--------------
sys/netinet6/ip6_flow.c | 42 ++++++++++--------------------------------
sys/netinet6/ip6_input.c | 12 ++++--------
sys/netinet6/mld6.c | 16 ++++------------
sys/netinet6/nd6.c | 34 ++++++++--------------------------
sys/netinet6/nd6_nbr.c | 14 ++++----------
sys/netipsec/ipsec_output.c | 12 ++++--------
21 files changed, 152 insertions(+), 294 deletions(-)
diffs (truncated from 1163 to 300 lines):
diff -r e29dc73034ed -r a26635b14dc5 sys/net/bpf.c
--- a/sys/net/bpf.c Fri Nov 17 07:16:06 2017 +0000
+++ b/sys/net/bpf.c Fri Nov 17 07:37:12 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bpf.c,v 1.218 2017/10/25 08:12:40 maya Exp $ */
+/* $NetBSD: bpf.c,v 1.219 2017/11/17 07:37:12 ozaki-r Exp $ */
/*
* Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.218 2017/10/25 08:12:40 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.219 2017/11/17 07:37:12 ozaki-r Exp $");
#if defined(_KERNEL_OPT)
#include "opt_bpf.h"
@@ -484,13 +484,9 @@
* the interface was configured down, so only panic
* if we don't get an unexpected error.
*/
-#ifndef NET_MPSAFE
- KERNEL_LOCK(1, NULL);
-#endif
+ KERNEL_LOCK_UNLESS_NET_MPSAFE();
error = ifpromisc(bp->bif_ifp, 0);
-#ifndef NET_MPSAFE
- KERNEL_UNLOCK_ONE(NULL);
-#endif
+ KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
#ifdef DIAGNOSTIC
if (error)
printf("%s: ifpromisc failed: %d", __func__, error);
@@ -1022,13 +1018,9 @@
break;
}
if (d->bd_promisc == 0) {
-#ifndef NET_MPSAFE
- KERNEL_LOCK(1, NULL);
-#endif
+ KERNEL_LOCK_UNLESS_NET_MPSAFE();
error = ifpromisc(d->bd_bif->bif_ifp, 1);
-#ifndef NET_MPSAFE
- KERNEL_UNLOCK_ONE(NULL);
-#endif
+ KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
if (error == 0)
d->bd_promisc = 1;
}
@@ -2249,13 +2241,9 @@
bpf_attachd(d, bp);
reset_d(d);
if (opromisc) {
-#ifndef NET_MPSAFE
- KERNEL_LOCK(1, NULL);
-#endif
+ KERNEL_LOCK_UNLESS_NET_MPSAFE();
error = ifpromisc(bp->bif_ifp, 1);
-#ifndef NET_MPSAFE
- KERNEL_UNLOCK_ONE(NULL);
-#endif
+ KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
if (error)
printf("%s: bpf_setdlt: ifpromisc failed (%d)\n",
bp->bif_ifp->if_xname, error);
diff -r e29dc73034ed -r a26635b14dc5 sys/net/if.c
--- a/sys/net/if.c Fri Nov 17 07:16:06 2017 +0000
+++ b/sys/net/if.c Fri Nov 17 07:37:12 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if.c,v 1.396 2017/10/23 09:21:20 msaitoh Exp $ */
+/* $NetBSD: if.c,v 1.397 2017/11/17 07:37:12 ozaki-r Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.396 2017/10/23 09:21:20 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.397 2017/11/17 07:37:12 ozaki-r Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
@@ -2331,10 +2331,7 @@
int s;
uint8_t state;
-#ifndef NET_MPSAFE
- mutex_enter(softnet_lock);
- KERNEL_LOCK(1, NULL);
-#endif
+ SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
s = splnet();
/* Pop a link state change from the queue and process it. */
@@ -2346,10 +2343,7 @@
softint_schedule(ifp->if_link_si);
splx(s);
-#ifndef NET_MPSAFE
- KERNEL_UNLOCK_ONE(NULL);
- mutex_exit(softnet_lock);
-#endif
+ SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
}
/*
diff -r e29dc73034ed -r a26635b14dc5 sys/net/if.h
--- a/sys/net/if.h Fri Nov 17 07:16:06 2017 +0000
+++ b/sys/net/if.h Fri Nov 17 07:37:12 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if.h,v 1.242 2017/11/16 03:07:18 ozaki-r Exp $ */
+/* $NetBSD: if.h,v 1.243 2017/11/17 07:37:12 ozaki-r Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -440,6 +440,46 @@
return ((ifp->if_extflags & IFEF_NO_LINK_STATE_CHANGE) == 0);
}
+
+#ifdef _KERNEL_OPT
+#include "opt_net_mpsafe.h"
+#endif
+
+/* XXX explore a better place to define */
+#ifdef NET_MPSAFE
+
+#define KERNEL_LOCK_UNLESS_NET_MPSAFE() do { } while (0)
+#define KERNEL_UNLOCK_UNLESS_NET_MPSAFE() do { } while (0)
+
+#define SOFTNET_LOCK_UNLESS_NET_MPSAFE() do { } while (0)
+#define SOFTNET_UNLOCK_UNLESS_NET_MPSAFE() do { } while (0)
+
+#else /* NET_MPSAFE */
+
+#define KERNEL_LOCK_UNLESS_NET_MPSAFE() \
+ do { KERNEL_LOCK(1, NULL); } while (0)
+#define KERNEL_UNLOCK_UNLESS_NET_MPSAFE() \
+ do { KERNEL_UNLOCK_ONE(NULL); } while (0)
+
+#define SOFTNET_LOCK_UNLESS_NET_MPSAFE() \
+ do { mutex_enter(softnet_lock); } while (0)
+#define SOFTNET_UNLOCK_UNLESS_NET_MPSAFE() \
+ do { mutex_exit(softnet_lock); } while (0)
+
+#endif /* NET_MPSAFE */
+
+#define SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE() \
+ do { \
+ SOFTNET_LOCK_UNLESS_NET_MPSAFE(); \
+ KERNEL_LOCK_UNLESS_NET_MPSAFE(); \
+ } while (0)
+
+#define SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE() \
+ do { \
+ KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); \
+ SOFTNET_UNLOCK_UNLESS_NET_MPSAFE(); \
+ } while (0)
+
#endif /* _KERNEL */
#define IFFBITS \
diff -r e29dc73034ed -r a26635b14dc5 sys/net/if_loop.c
--- a/sys/net/if_loop.c Fri Nov 17 07:16:06 2017 +0000
+++ b/sys/net/if_loop.c Fri Nov 17 07:37:12 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_loop.c,v 1.98 2017/11/16 03:07:18 ozaki-r Exp $ */
+/* $NetBSD: if_loop.c,v 1.99 2017/11/17 07:37:12 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.98 2017/11/16 03:07:18 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.99 2017/11/17 07:37:12 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -247,9 +247,7 @@
MCLAIM(m, ifp->if_mowner);
-#ifndef NET_MPSAFE
- KERNEL_LOCK(1, NULL);
-#endif
+ KERNEL_LOCK_UNLESS_NET_MPSAFE();
if ((m->m_flags & M_PKTHDR) == 0)
panic("looutput: no header mbuf");
@@ -375,9 +373,7 @@
schednetisr(isr);
splx(s);
out:
-#ifndef NET_MPSAFE
- KERNEL_UNLOCK_ONE(NULL);
-#endif
+ KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
return error;
}
diff -r e29dc73034ed -r a26635b14dc5 sys/net/if_pppoe.c
--- a/sys/net/if_pppoe.c Fri Nov 17 07:16:06 2017 +0000
+++ b/sys/net/if_pppoe.c Fri Nov 17 07:37:12 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.131 2017/11/16 03:07:18 ozaki-r Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.132 2017/11/17 07:37:12 ozaki-r Exp $ */
/*-
* Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.131 2017/11/16 03:07:18 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.132 2017/11/17 07:37:12 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "pppoe.h"
@@ -477,9 +477,7 @@
struct mbuf *m;
int disc_done, data_done;
-#ifndef PPPOE_MPSAFE
- mutex_enter(softnet_lock);
-#endif
+ SOFTNET_LOCK_UNLESS_NET_MPSAFE();
do {
disc_done = 0;
@@ -502,9 +500,8 @@
pppoe_data_input(m);
}
} while (disc_done || data_done);
-#ifndef PPPOE_MPSAFE
- mutex_exit(softnet_lock);
-#endif
+
+ SOFTNET_UNLOCK_UNLESS_NET_MPSAFE();
}
/* analyze and handle a single received packet while not in session state */
diff -r e29dc73034ed -r a26635b14dc5 sys/net/npf/npf_os.c
--- a/sys/net/npf/npf_os.c Fri Nov 17 07:16:06 2017 +0000
+++ b/sys/net/npf/npf_os.c Fri Nov 17 07:37:12 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: npf_os.c,v 1.7 2017/07/20 23:37:56 pgoyette Exp $ */
+/* $NetBSD: npf_os.c,v 1.8 2017/11/17 07:37:12 ozaki-r Exp $ */
/*-
* Copyright (c) 2009-2016 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
#ifdef _KERNEL
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.7 2017/07/20 23:37:56 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.8 2017/11/17 07:37:12 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "pf.h"
@@ -397,10 +397,7 @@
npf_t *npf = npf_getkernctx();
int error = 0;
-#ifndef NET_MPSAFE
- mutex_enter(softnet_lock);
- KERNEL_LOCK(1, NULL);
-#endif
+ SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
/* Init: interface re-config and attach/detach hook. */
if (!npf_ph_if) {
@@ -455,10 +452,7 @@
npf_ifaddr_syncall(npf);
pfil_registered = true;
out:
-#ifndef NET_MPSAFE
- KERNEL_UNLOCK_ONE(NULL);
- mutex_exit(softnet_lock);
-#endif
+ SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
return error;
}
@@ -471,10 +465,7 @@
{
npf_t *npf = npf_getkernctx();
-#ifndef NET_MPSAFE
- mutex_enter(softnet_lock);
- KERNEL_LOCK(1, NULL);
-#endif
+ SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
if (fini && npf_ph_if) {
(void)pfil_remove_ihook(npf_ifhook, NULL,
@@ -492,10 +483,7 @@
Home |
Main Index |
Thread Index |
Old Index