Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Unify IFEF_*_MPSAFE into IFEF_MPSAFE



details:   https://anonhg.NetBSD.org/src/rev/67a69f18e9dd
branches:  trunk
changeset: 827880:67a69f18e9dd
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Thu Nov 16 03:07:17 2017 +0000

description:
Unify IFEF_*_MPSAFE into IFEF_MPSAFE

There are already two flags for if_output and if_start, however, it seems such
MPSAFE flags are eventually needed for all if_XXX operations. Having discrete
flags for each operation is wasteful of if_extflags bits. So let's unify
the flags into one: IFEF_MPSAFE.

Fortunately IFEF_*_MPSAFE flags have never been included in any releases, so
we can change them without breaking backward compatibility of the releases
(though the kernel version of -current should be bumped).

Note that if an interface have both MP-safe and non-MP-safe operations at a
time, we have to set the IFEF_MPSAFE flag and let callees of non-MP-safe
opeartions take the kernel lock.

Proposed on tech-kern@ and tech-net@

diffstat:

 sys/arch/arm/sunxi/sunxi_emac.c |   6 +++---
 sys/dev/ic/dwc_gmac.c           |   8 ++++----
 sys/dev/pci/if_wm.c             |  10 +++++-----
 sys/dev/pci/ixgbe/ixgbe.c       |   4 ++--
 sys/dev/pci/ixgbe/ixv.c         |   4 ++--
 sys/net/if.h                    |  28 +++++++++++++---------------
 sys/net/if_bridge.c             |   8 ++++----
 sys/net/if_ethersubr.c          |  12 ++----------
 sys/net/if_gif.c                |   6 +++---
 sys/net/if_l2tp.c               |   7 +++----
 sys/net/if_loop.c               |   6 +++---
 sys/net/if_pppoe.c              |   6 +++---
 sys/net/if_vlan.c               |   6 +++---
 sys/netcan/if_canloop.c         |   6 +++---
 sys/netinet/ip_carp.c           |   5 ++---
 15 files changed, 55 insertions(+), 67 deletions(-)

diffs (truncated from 474 to 300 lines):

diff -r fb09ce9bb34e -r 67a69f18e9dd sys/arch/arm/sunxi/sunxi_emac.c
--- a/sys/arch/arm/sunxi/sunxi_emac.c   Thu Nov 16 01:24:42 2017 +0000
+++ b/sys/arch/arm/sunxi/sunxi_emac.c   Thu Nov 16 03:07:17 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_emac.c,v 1.8 2017/10/01 15:05:09 jmcneill Exp $ */
+/* $NetBSD: sunxi_emac.c,v 1.9 2017/11/16 03:07:17 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 2016-2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -33,7 +33,7 @@
 #include "opt_net_mpsafe.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.8 2017/10/01 15:05:09 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.9 2017/11/16 03:07:17 ozaki-r Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -1381,7 +1381,7 @@
        snprintf(ifp->if_xname, IFNAMSIZ, EMAC_IFNAME, device_unit(self));
        ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
 #ifdef EMAC_MPSAFE
-       ifp->if_extflags = IFEF_START_MPSAFE;
+       ifp->if_extflags = IFEF_MPSAFE;
 #endif
        ifp->if_start = sunxi_emac_start;
        ifp->if_ioctl = sunxi_emac_ioctl;
diff -r fb09ce9bb34e -r 67a69f18e9dd sys/dev/ic/dwc_gmac.c
--- a/sys/dev/ic/dwc_gmac.c     Thu Nov 16 01:24:42 2017 +0000
+++ b/sys/dev/ic/dwc_gmac.c     Thu Nov 16 03:07:17 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc_gmac.c,v 1.42 2017/10/23 15:08:05 jakllsch Exp $ */
+/* $NetBSD: dwc_gmac.c,v 1.43 2017/11/16 03:07:17 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.42 2017/10/23 15:08:05 jakllsch Exp $");
+__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.43 2017/11/16 03:07:17 ozaki-r Exp $");
 
 /* #define     DWC_GMAC_DEBUG  1 */
 
@@ -223,7 +223,7 @@
        ifp->if_softc = sc;
        strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ);
        ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
-       ifp->if_extflags = IFEF_START_MPSAFE;
+       ifp->if_extflags = IFEF_MPSAFE;
        ifp->if_ioctl = dwc_gmac_ioctl;
        ifp->if_start = dwc_gmac_start;
        ifp->if_init = dwc_gmac_init;
@@ -836,7 +836,7 @@
 dwc_gmac_start(struct ifnet *ifp)
 {
        struct dwc_gmac_softc *sc = ifp->if_softc;
-       KASSERT(ifp->if_extflags & IFEF_START_MPSAFE);
+       KASSERT(if_is_mpsafe(ifp));
 
        mutex_enter(sc->sc_lock);
        if (!sc->sc_stopping) {
diff -r fb09ce9bb34e -r 67a69f18e9dd sys/dev/pci/if_wm.c
--- a/sys/dev/pci/if_wm.c       Thu Nov 16 01:24:42 2017 +0000
+++ b/sys/dev/pci/if_wm.c       Thu Nov 16 03:07:17 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_wm.c,v 1.542 2017/10/23 23:29:38 knakahara Exp $    */
+/*     $NetBSD: if_wm.c,v 1.543 2017/11/16 03:07:18 ozaki-r Exp $      */
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.542 2017/10/23 23:29:38 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.543 2017/11/16 03:07:18 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -2630,7 +2630,7 @@
        ifp->if_softc = sc;
        ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
 #ifdef WM_MPSAFE
-       ifp->if_extflags = IFEF_START_MPSAFE;
+       ifp->if_extflags = IFEF_MPSAFE;
 #endif
        ifp->if_ioctl = wm_ioctl;
        if ((sc->sc_flags & WM_F_NEWQUEUE) != 0) {
@@ -6990,7 +6990,7 @@
        struct wm_txqueue *txq = &sc->sc_queue[0].wmq_txq;
 
 #ifdef WM_MPSAFE
-       KASSERT(ifp->if_extflags & IFEF_START_MPSAFE);
+       KASSERT(if_is_mpsafe(ifp));
 #endif
        /*
         * ifp->if_obytes and ifp->if_omcasts are added in if_transmit()@if.c.
@@ -7583,7 +7583,7 @@
        struct wm_txqueue *txq = &sc->sc_queue[0].wmq_txq;
 
 #ifdef WM_MPSAFE
-       KASSERT(ifp->if_extflags & IFEF_START_MPSAFE);
+       KASSERT(if_is_mpsafe(ifp));
 #endif
        /*
         * ifp->if_obytes and ifp->if_omcasts are added in if_transmit()@if.c.
diff -r fb09ce9bb34e -r 67a69f18e9dd sys/dev/pci/ixgbe/ixgbe.c
--- a/sys/dev/pci/ixgbe/ixgbe.c Thu Nov 16 01:24:42 2017 +0000
+++ b/sys/dev/pci/ixgbe/ixgbe.c Thu Nov 16 03:07:17 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.111 2017/11/12 05:11:36 msaitoh Exp $ */
+/* $NetBSD: ixgbe.c,v 1.112 2017/11/16 03:07:18 ozaki-r Exp $ */
 
 /******************************************************************************
 
@@ -1214,7 +1214,7 @@
        ifp->if_softc = adapter;
        ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
 #ifdef IXGBE_MPSAFE
-       ifp->if_extflags = IFEF_START_MPSAFE;
+       ifp->if_extflags = IFEF_MPSAFE;
 #endif
        ifp->if_ioctl = ixgbe_ioctl;
 #if __FreeBSD_version >= 1100045
diff -r fb09ce9bb34e -r 67a69f18e9dd sys/dev/pci/ixgbe/ixv.c
--- a/sys/dev/pci/ixgbe/ixv.c   Thu Nov 16 01:24:42 2017 +0000
+++ b/sys/dev/pci/ixgbe/ixv.c   Thu Nov 16 03:07:17 2017 +0000
@@ -1,4 +1,4 @@
-/*$NetBSD: ixv.c,v 1.73 2017/10/23 09:31:18 msaitoh Exp $*/
+/*$NetBSD: ixv.c,v 1.74 2017/11/16 03:07:18 ozaki-r Exp $*/
 
 /******************************************************************************
 
@@ -1391,7 +1391,7 @@
        ifp->if_softc = adapter;
        ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
 #ifdef IXGBE_MPSAFE
-       ifp->if_extflags = IFEF_START_MPSAFE;
+       ifp->if_extflags = IFEF_MPSAFE;
 #endif
        ifp->if_ioctl = ixv_ioctl;
        if (adapter->feat_en & IXGBE_FEATURE_LEGACY_TX) {
diff -r fb09ce9bb34e -r 67a69f18e9dd sys/net/if.h
--- a/sys/net/if.h      Thu Nov 16 01:24:42 2017 +0000
+++ b/sys/net/if.h      Thu Nov 16 03:07:17 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.h,v 1.241 2017/10/23 09:21:20 msaitoh Exp $ */
+/*     $NetBSD: if.h,v 1.242 2017/11/16 03:07:18 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -387,16 +387,21 @@
 #define        IFF_LINK2       0x4000          /* per link layer defined bit */
 #define        IFF_MULTICAST   0x8000          /* supports multicast */
 
-#define        IFEF_OUTPUT_MPSAFE              __BIT(0)        /* if_output() can run parallel */
-#define        IFEF_START_MPSAFE               __BIT(1)        /* if_start() can run parallel */
-#define        IFEF_NO_LINK_STATE_CHANGE       __BIT(2)        /* doesn't use link state interrupts */
+#define        IFEF_MPSAFE                     __BIT(0)        /* handlers can run in parallel (see below) */
+#define        IFEF_NO_LINK_STATE_CHANGE       __BIT(1)        /* doesn't use link state interrupts */
+
+/*
+ * if_XXX() handlers that IFEF_MPSAFE suppresses KERNEL_LOCK:
+ *   - if_start
+ *   - if_output
+ */
 
 #ifdef _KERNEL
 static inline bool
-if_output_is_mpsafe(struct ifnet *ifp)
+if_is_mpsafe(struct ifnet *ifp)
 {
 
-       return ((ifp->if_extflags & IFEF_OUTPUT_MPSAFE) != 0);
+       return ((ifp->if_extflags & IFEF_MPSAFE) != 0);
 }
 
 static inline int
@@ -404,7 +409,7 @@
     const struct sockaddr *dst, const struct rtentry *rt)
 {
 
-       if (if_output_is_mpsafe(cifp)) {
+       if (if_is_mpsafe(cifp)) {
                return (*cifp->if_output)(ifp, m, dst, rt);
        } else {
                int ret;
@@ -416,18 +421,11 @@
        }
 }
 
-static inline bool
-if_start_is_mpsafe(struct ifnet *ifp)
-{
-
-       return ((ifp->if_extflags & IFEF_START_MPSAFE) != 0);
-}
-
 static inline void
 if_start_lock(struct ifnet *ifp)
 {
 
-       if (if_start_is_mpsafe(ifp)) {
+       if (if_is_mpsafe(ifp)) {
                (*ifp->if_start)(ifp);
        } else {
                KERNEL_LOCK(1, NULL);
diff -r fb09ce9bb34e -r 67a69f18e9dd sys/net/if_bridge.c
--- a/sys/net/if_bridge.c       Thu Nov 16 01:24:42 2017 +0000
+++ b/sys/net/if_bridge.c       Thu Nov 16 03:07:17 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_bridge.c,v 1.139 2017/11/15 06:17:40 ozaki-r Exp $  */
+/*     $NetBSD: if_bridge.c,v 1.140 2017/11/16 03:07:18 ozaki-r Exp $  */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.139 2017/11/15 06:17:40 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.140 2017/11/16 03:07:18 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_bridge_ipf.h"
@@ -424,7 +424,7 @@
 
        if_initname(ifp, ifc->ifc_name, unit);
        ifp->if_softc = sc;
-       ifp->if_extflags = IFEF_OUTPUT_MPSAFE;
+       ifp->if_extflags = IFEF_MPSAFE;
        ifp->if_mtu = ETHERMTU;
        ifp->if_ioctl = bridge_ioctl;
        ifp->if_output = bridge_output;
@@ -1440,7 +1440,7 @@
        /*
         * bridge_output() is called from ether_output(), furthermore
         * ifp argument doesn't point to bridge(4). So, don't assert
-        * IFEF_OUTPUT_MPSAFE here.
+        * IFEF_MPSAFE here.
         */
 
        if (m->m_len < ETHER_HDR_LEN) {
diff -r fb09ce9bb34e -r 67a69f18e9dd sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c    Thu Nov 16 01:24:42 2017 +0000
+++ b/sys/net/if_ethersubr.c    Thu Nov 16 03:07:17 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ethersubr.c,v 1.245 2017/10/26 09:41:15 msaitoh Exp $       */
+/*     $NetBSD: if_ethersubr.c,v 1.246 2017/11/16 03:07:18 ozaki-r Exp $       */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.245 2017/10/26 09:41:15 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.246 2017/11/16 03:07:18 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -204,13 +204,6 @@
        struct at_ifaddr *aa;
 #endif /* NETATALK */
 
-       /*
-        * some paths such as carp_output() call ethr_output() with "ifp"
-        * argument as other than ether ifnet.
-        */
-       KASSERT(ifp->if_output != ether_output
-           || ifp->if_extflags & IFEF_OUTPUT_MPSAFE);
-
 #ifdef MBUFTRACE
        m_claimm(m, ifp->if_mowner);
 #endif
@@ -951,7 +944,6 @@
 {
        struct ethercom *ec = (struct ethercom *)ifp;
 
-       ifp->if_extflags |= IFEF_OUTPUT_MPSAFE;
        ifp->if_type = IFT_ETHER;
        ifp->if_hdrlen = ETHER_HDR_LEN;
        ifp->if_dlt = DLT_EN10MB;
diff -r fb09ce9bb34e -r 67a69f18e9dd sys/net/if_gif.c
--- a/sys/net/if_gif.c  Thu Nov 16 01:24:42 2017 +0000
+++ b/sys/net/if_gif.c  Thu Nov 16 03:07:17 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_gif.c,v 1.131 2017/10/23 09:31:18 msaitoh Exp $     */
+/*     $NetBSD: if_gif.c,v 1.132 2017/11/16 03:07:18 ozaki-r Exp $     */
 /*     $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $    */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.131 2017/10/23 09:31:18 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.132 2017/11/16 03:07:18 ozaki-r Exp $");



Home | Main Index | Thread Index | Old Index