Source-Changes-HG archive

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

[src/trunk]: src/sys/net In ifmedia_ioctl(), go to splnet() before acquiring ...



details:   https://anonhg.NetBSD.org/src/rev/402ba82d42c4
branches:  trunk
changeset: 1006599:402ba82d42c4
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Jan 20 19:35:39 2020 +0000

description:
In ifmedia_ioctl(), go to splnet() before acquiring the KERNEL_LOCK.
For non-NET_MPSAFE, this is benign, because we can nest raising to
splnet().  For the NET_MPSAFE, it means that drivers don't need to
raise to splnet() just in order to call ifmedia_ioctl().

diffstat:

 sys/net/if_media.c |  17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diffs (42 lines):

diff -r 2cc053962e03 -r 402ba82d42c4 sys/net/if_media.c
--- a/sys/net/if_media.c        Mon Jan 20 18:48:15 2020 +0000
+++ b/sys/net/if_media.c        Mon Jan 20 19:35:39 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_media.c,v 1.48 2019/10/01 17:45:25 chs Exp $        */
+/*     $NetBSD: if_media.c,v 1.49 2020/01/20 19:35:39 thorpej Exp $    */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.48 2019/10/01 17:45:25 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.49 2020/01/20 19:35:39 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -362,12 +362,21 @@
        int e;
 
        /*
-        * If if_is_mpsafe(ifp), KERNEL_LOCK isn't held here,
-        * but ifmedia_ioctl_locked isn't MP-safe yet, so we must hold the lock.
+        * If if_is_mpsafe(ifp), KERNEL_LOCK isn't held here and
+        * ipl will not have been raised (well, maybe it has, but
+        * it doesn't matter), but ifmedia_ioctl_locked isn't MP-safe
+        * yet, so we go to splnet and grab the KERNEL_LOCK.
+        *
+        * In the non-mpsafe case, the interface's ioctl routine
+        * will already be running at splnet() and so raising it
+        * again is redundant, but also harmless.
         */
+       int s = splnet();
        KERNEL_LOCK_IF_IFP_MPSAFE(ifp);
        e = ifmedia_ioctl_locked(ifp, ifr, ifm, cmd);
        KERNEL_UNLOCK_IF_IFP_MPSAFE(ifp);
+       splx(s);
+
        return e;
 }
 



Home | Main Index | Thread Index | Old Index