Source-Changes-HG archive

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

[src/netbsd-8]: src/sys/net Pull up following revision(s) (requested by ozaki...



details:   https://anonhg.NetBSD.org/src/rev/36730bba82e4
branches:  netbsd-8
changeset: 434997:36730bba82e4
user:      martin <martin%NetBSD.org@localhost>
date:      Tue May 15 13:48:37 2018 +0000

description:
Pull up following revision(s) (requested by ozaki-r in ticket #826):

        sys/net/if_bridge.c: revision 1.155
        sys/net/if.c: revision 1.421
        sys/net/bpf.c: revision 1.224
        sys/net/if.c: revision 1.422
        sys/net/if.c: revision 1.423

Use if_is_mpsafe (NFC)

Protect packet input routines with KERNEL_LOCK and splsoftnet
if_input, i.e, ether_input and friends, now runs in softint without any
protections.  It's ok for ether_input itself because it's already MP-safe,
however, subsequent routines called from it such as carp_input and agr_input
aren't safe because they're not MP-safe.  Protect if_input with KERNEL_LOCK.
if_input can be called from a normal LWP context.  In that case we need to
prevent interrupts (softint) from running by splsoftnet to protect
non-MP-safe
codes (e.g., carp_input and agr_input).

Pointed out by mlelstv@

Protect if_deferred_start_softint with KERNEL_LOCK if the interface isn't
MP-safe

diffstat:

 sys/net/bpf.c       |  12 ++++++++----
 sys/net/if.c        |  19 +++++++++++--------
 sys/net/if_bridge.c |  10 ++++------
 3 files changed, 23 insertions(+), 18 deletions(-)

diffs (128 lines):

diff -r 80d733304d3f -r 36730bba82e4 sys/net/bpf.c
--- a/sys/net/bpf.c     Tue May 15 13:42:49 2018 +0000
+++ b/sys/net/bpf.c     Tue May 15 13:48:37 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bpf.c,v 1.216.6.5 2018/02/05 14:18:00 martin Exp $     */
+/*     $NetBSD: bpf.c,v 1.216.6.6 2018/05/15 13:48:37 martin Exp $     */
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216.6.5 2018/02/05 14:18:00 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216.6.6 2018/05/15 13:48:37 martin Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_bpf.h"
@@ -836,9 +836,13 @@
        error = if_output_lock(ifp, ifp, m, (struct sockaddr *) &dst, NULL);
 
        if (mc != NULL) {
-               if (error == 0)
+               if (error == 0) {
+                       int s = splsoftnet();
+                       KERNEL_LOCK_UNLESS_IFP_MPSAFE(ifp);
                        ifp->_if_input(ifp, mc);
-               else
+                       KERNEL_UNLOCK_UNLESS_IFP_MPSAFE(ifp);
+                       splx(s);
+               } else
                        m_freem(mc);
        }
        /*
diff -r 80d733304d3f -r 36730bba82e4 sys/net/if.c
--- a/sys/net/if.c      Tue May 15 13:42:49 2018 +0000
+++ b/sys/net/if.c      Tue May 15 13:48:37 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.394.2.9 2018/02/28 18:54:43 martin Exp $      */
+/*     $NetBSD: if.c,v 1.394.2.10 2018/05/15 13:48:37 martin 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.394.2.9 2018/02/28 18:54:43 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.10 2018/05/15 13:48:37 martin Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -716,8 +716,7 @@
 
        if (if_is_link_state_changeable(ifp)) {
                u_int flags = SOFTINT_NET;
-               flags |= ISSET(ifp->if_extflags, IFEF_MPSAFE) ?
-                   SOFTINT_MPSAFE : 0;
+               flags |= if_is_mpsafe(ifp) ? SOFTINT_MPSAFE : 0;
                ifp->if_link_si = softint_establish(flags,
                    if_link_state_change_si, ifp);
                if (ifp->if_link_si == NULL) {
@@ -834,11 +833,13 @@
 if_percpuq_create(struct ifnet *ifp)
 {
        struct if_percpuq *ipq;
+       u_int flags = SOFTINT_NET;
+
+       flags |= if_is_mpsafe(ifp) ? SOFTINT_MPSAFE : 0;
 
        ipq = kmem_zalloc(sizeof(*ipq), KM_SLEEP);
        ipq->ipq_ifp = ifp;
-       ipq->ipq_si = softint_establish(SOFTINT_NET|SOFTINT_MPSAFE,
-           if_percpuq_softint, ipq);
+       ipq->ipq_si = softint_establish(flags, if_percpuq_softint, ipq);
        ipq->ipq_ifqs = percpu_alloc(sizeof(struct ifqueue));
        percpu_foreach(ipq->ipq_ifqs, &if_percpuq_init_ifq, NULL);
 
@@ -1066,11 +1067,13 @@
 if_deferred_start_init(struct ifnet *ifp, void (*func)(struct ifnet *))
 {
        struct if_deferred_start *ids;
+       u_int flags = SOFTINT_NET;
+
+       flags |= if_is_mpsafe(ifp) ? SOFTINT_MPSAFE : 0;
 
        ids = kmem_zalloc(sizeof(*ids), KM_SLEEP);
        ids->ids_ifp = ifp;
-       ids->ids_si = softint_establish(SOFTINT_NET|SOFTINT_MPSAFE,
-           if_deferred_start_softint, ids);
+       ids->ids_si = softint_establish(flags, if_deferred_start_softint, ids);
        if (func != NULL)
                ids->ids_if_start = func;
        else
diff -r 80d733304d3f -r 36730bba82e4 sys/net/if_bridge.c
--- a/sys/net/if_bridge.c       Tue May 15 13:42:49 2018 +0000
+++ b/sys/net/if_bridge.c       Tue May 15 13:48:37 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_bridge.c,v 1.134.6.9 2018/04/18 14:11:42 martin Exp $       */
+/*     $NetBSD: if_bridge.c,v 1.134.6.10 2018/05/15 13:48:37 martin Exp $      */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.134.6.9 2018/04/18 14:11:42 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.134.6.10 2018/05/15 13:48:37 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_bridge_ipf.h"
@@ -1575,13 +1575,11 @@
                                m_set_rcvif(mc, dst_if);
                                mc->m_flags &= ~M_PROMISC;
 
-#ifndef NET_MPSAFE
                                s = splsoftnet();
-#endif
+                               KERNEL_LOCK_UNLESS_IFP_MPSAFE(dst_if);
                                ether_input(dst_if, mc);
-#ifndef NET_MPSAFE
+                               KERNEL_UNLOCK_UNLESS_IFP_MPSAFE(dst_if);
                                splx(s);
-#endif
                        }
 
 next:



Home | Main Index | Thread Index | Old Index