Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb usbnet: Enter uno_init with the core lock held.



details:   https://anonhg.NetBSD.org/src/rev/37fa1e67e0a9
branches:  trunk
changeset: 362511:37fa1e67e0a9
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Mar 03 05:50:22 2022 +0000

description:
usbnet: Enter uno_init with the core lock held.

This reduces code in all drivers except urndis(4) and aue(4).

However, it's still safe for urndis to drop the core lock because the
ifnet is locked, and the ifnet lock covers the DOWN->UP (uno_init)
and UP->DOWN (uno_stop) transitions.

diffstat:

 sys/dev/usb/if_aue.c    |   9 +++++----
 sys/dev/usb/if_axe.c    |   6 ++----
 sys/dev/usb/if_axen.c   |   6 ++----
 sys/dev/usb/if_cdce.c   |   6 ++----
 sys/dev/usb/if_cue.c    |   6 ++----
 sys/dev/usb/if_kue.c    |   6 ++----
 sys/dev/usb/if_mos.c    |   6 ++----
 sys/dev/usb/if_mue.c    |   6 ++----
 sys/dev/usb/if_smsc.c   |   6 ++----
 sys/dev/usb/if_udav.c   |   9 ++-------
 sys/dev/usb/if_upl.c    |   6 ++----
 sys/dev/usb/if_ure.c    |   6 ++----
 sys/dev/usb/if_url.c    |   6 ++----
 sys/dev/usb/if_urndis.c |  13 ++++++++++---
 sys/dev/usb/usbnet.c    |  11 ++++++++---
 15 files changed, 47 insertions(+), 61 deletions(-)

diffs (truncated from 502 to 300 lines):

diff -r 66d4a25b09e8 -r 37fa1e67e0a9 sys/dev/usb/if_aue.c
--- a/sys/dev/usb/if_aue.c      Thu Mar 03 05:50:12 2022 +0000
+++ b/sys/dev/usb/if_aue.c      Thu Mar 03 05:50:22 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_aue.c,v 1.171 2020/03/18 11:33:32 kre Exp $ */
+/*     $NetBSD: if_aue.c,v 1.172 2022/03/03 05:50:22 riastradh Exp $   */
 
 /*
  * Copyright (c) 1997, 1998, 1999, 2000
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.171 2020/03/18 11:33:32 kre Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.172 2022/03/03 05:50:22 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1000,11 +1000,9 @@
        struct usbnet * const   un = ifp->if_softc;
        int rv;
 
-       usbnet_lock_core(un);
        usbnet_busy(un);
        rv = aue_init_locked(ifp);
        usbnet_unbusy(un);
-       usbnet_unlock_core(un);
 
        return rv;
 }
@@ -1012,6 +1010,7 @@
 static int
 aue_uno_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
+       struct usbnet * const un = ifp->if_softc;
 
        AUEHIST_FUNC();
        AUEHIST_CALLARGSN(5, "aue%jd: enter cmd %#jx data %#jx",
@@ -1021,7 +1020,9 @@
        switch (cmd) {
        case SIOCADDMULTI:
        case SIOCDELMULTI:
+               usbnet_lock_core(un);
                aue_uno_init(ifp);
+               usbnet_unlock_core(un);
                break;
        default:
                break;
diff -r 66d4a25b09e8 -r 37fa1e67e0a9 sys/dev/usb/if_axe.c
--- a/sys/dev/usb/if_axe.c      Thu Mar 03 05:50:12 2022 +0000
+++ b/sys/dev/usb/if_axe.c      Thu Mar 03 05:50:22 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_axe.c,v 1.132 2021/03/01 17:41:00 jakllsch Exp $    */
+/*     $NetBSD: if_axe.c,v 1.133 2022/03/03 05:50:22 riastradh Exp $   */
 /*     $OpenBSD: if_axe.c,v 1.137 2016/04/13 11:03:37 mpi Exp $ */
 
 /*
@@ -87,7 +87,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.132 2021/03/01 17:41:00 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.133 2022/03/03 05:50:22 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1317,11 +1317,9 @@
 {
        struct usbnet * const un = ifp->if_softc;
 
-       usbnet_lock_core(un);
        usbnet_busy(un);
        int ret = axe_init_locked(ifp);
        usbnet_unbusy(un);
-       usbnet_unlock_core(un);
 
        return ret;
 }
diff -r 66d4a25b09e8 -r 37fa1e67e0a9 sys/dev/usb/if_axen.c
--- a/sys/dev/usb/if_axen.c     Thu Mar 03 05:50:12 2022 +0000
+++ b/sys/dev/usb/if_axen.c     Thu Mar 03 05:50:22 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_axen.c,v 1.74 2022/03/03 05:48:06 riastradh Exp $   */
+/*     $NetBSD: if_axen.c,v 1.75 2022/03/03 05:50:22 riastradh Exp $   */
 /*     $OpenBSD: if_axen.c,v 1.3 2013/10/21 10:10:22 yuo Exp $ */
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.74 2022/03/03 05:48:06 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.75 2022/03/03 05:50:22 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -935,11 +935,9 @@
 {
        struct usbnet * const un = ifp->if_softc;
 
-       usbnet_lock_core(un);
        usbnet_busy(un);
        int ret = axen_init_locked(ifp);
        usbnet_unbusy(un);
-       usbnet_unlock_core(un);
 
        return ret;
 }
diff -r 66d4a25b09e8 -r 37fa1e67e0a9 sys/dev/usb/if_cdce.c
--- a/sys/dev/usb/if_cdce.c     Thu Mar 03 05:50:12 2022 +0000
+++ b/sys/dev/usb/if_cdce.c     Thu Mar 03 05:50:22 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_cdce.c,v 1.72 2020/05/15 19:28:10 maxv Exp $ */
+/*     $NetBSD: if_cdce.c,v 1.73 2022/03/03 05:50:22 riastradh Exp $ */
 
 /*
  * Copyright (c) 1997, 1998, 1999, 2000-2003 Bill Paul <wpaul%windriver.com@localhost>
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.72 2020/05/15 19:28:10 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.73 2022/03/03 05:50:22 riastradh Exp $");
 
 #include <sys/param.h>
 
@@ -261,7 +261,6 @@
        struct usbnet           *un = ifp->if_softc;
        int rv;
 
-       usbnet_lock_core(un);
        if (usbnet_isdying(un))
                rv = EIO;
        else {
@@ -269,7 +268,6 @@
                rv = usbnet_init_rx_tx(un);
                usbnet_set_link(un, rv == 0);
        }
-       usbnet_unlock_core(un);
 
        return rv;
 }
diff -r 66d4a25b09e8 -r 37fa1e67e0a9 sys/dev/usb/if_cue.c
--- a/sys/dev/usb/if_cue.c      Thu Mar 03 05:50:12 2022 +0000
+++ b/sys/dev/usb/if_cue.c      Thu Mar 03 05:50:22 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_cue.c,v 1.92 2022/03/03 05:49:51 riastradh Exp $    */
+/*     $NetBSD: if_cue.c,v 1.93 2022/03/03 05:50:22 riastradh Exp $    */
 
 /*
  * Copyright (c) 1997, 1998, 1999, 2000
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_cue.c,v 1.92 2022/03/03 05:49:51 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_cue.c,v 1.93 2022/03/03 05:50:22 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -673,11 +673,9 @@
        struct usbnet * const   un = ifp->if_softc;
        int rv;
 
-       usbnet_lock_core(un);
        usbnet_busy(un);
        rv = cue_init_locked(ifp);
        usbnet_unbusy(un);
-       usbnet_unlock_core(un);
 
        return rv;
 }
diff -r 66d4a25b09e8 -r 37fa1e67e0a9 sys/dev/usb/if_kue.c
--- a/sys/dev/usb/if_kue.c      Thu Mar 03 05:50:12 2022 +0000
+++ b/sys/dev/usb/if_kue.c      Thu Mar 03 05:50:22 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_kue.c,v 1.105 2021/06/13 09:26:24 mlelstv Exp $     */
+/*     $NetBSD: if_kue.c,v 1.106 2022/03/03 05:50:22 riastradh Exp $   */
 
 /*
  * Copyright (c) 1997, 1998, 1999, 2000
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_kue.c,v 1.105 2021/06/13 09:26:24 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_kue.c,v 1.106 2022/03/03 05:50:22 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -633,11 +633,9 @@
        struct usbnet * const   un = ifp->if_softc;
        int rv;
 
-       usbnet_lock_core(un);
        usbnet_busy(un);
        rv = kue_init_locked(ifp);
        usbnet_unbusy(un);
-       usbnet_unlock_core(un);
 
        return rv;
 }
diff -r 66d4a25b09e8 -r 37fa1e67e0a9 sys/dev/usb/if_mos.c
--- a/sys/dev/usb/if_mos.c      Thu Mar 03 05:50:12 2022 +0000
+++ b/sys/dev/usb/if_mos.c      Thu Mar 03 05:50:22 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_mos.c,v 1.7 2020/04/02 04:09:36 nisimura Exp $      */
+/*     $NetBSD: if_mos.c,v 1.8 2022/03/03 05:50:22 riastradh Exp $     */
 /*     $OpenBSD: if_mos.c,v 1.40 2019/07/07 06:40:10 kevlo Exp $       */
 
 /*
@@ -72,7 +72,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_mos.c,v 1.7 2020/04/02 04:09:36 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mos.c,v 1.8 2022/03/03 05:50:22 riastradh Exp $");
 
 #include <sys/param.h>
 
@@ -760,11 +760,9 @@
 {
        struct usbnet * const un = ifp->if_softc;
 
-       usbnet_lock_core(un);
        usbnet_busy(un);
        int ret = mos_init_locked(ifp);
        usbnet_unbusy(un);
-       usbnet_unlock_core(un);
 
        return ret;
 }
diff -r 66d4a25b09e8 -r 37fa1e67e0a9 sys/dev/usb/if_mue.c
--- a/sys/dev/usb/if_mue.c      Thu Mar 03 05:50:12 2022 +0000
+++ b/sys/dev/usb/if_mue.c      Thu Mar 03 05:50:22 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_mue.c,v 1.63 2022/03/03 05:48:06 riastradh Exp $    */
+/*     $NetBSD: if_mue.c,v 1.64 2022/03/03 05:50:22 riastradh Exp $    */
 /*     $OpenBSD: if_mue.c,v 1.3 2018/08/04 16:42:46 jsg Exp $  */
 
 /*
@@ -20,7 +20,7 @@
 /* Driver for Microchip LAN7500/LAN7800 chipsets. */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.63 2022/03/03 05:48:06 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.64 2022/03/03 05:50:22 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1255,11 +1255,9 @@
        struct usbnet * const   un = ifp->if_softc;
        int rv;
 
-       usbnet_lock_core(un);
        usbnet_busy(un);
        rv = mue_init_locked(ifp);
        usbnet_unbusy(un);
-       usbnet_unlock_core(un);
 
        return rv;
 }
diff -r 66d4a25b09e8 -r 37fa1e67e0a9 sys/dev/usb/if_smsc.c
--- a/sys/dev/usb/if_smsc.c     Thu Mar 03 05:50:12 2022 +0000
+++ b/sys/dev/usb/if_smsc.c     Thu Mar 03 05:50:22 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_smsc.c,v 1.71 2022/03/03 05:48:06 riastradh Exp $   */
+/*     $NetBSD: if_smsc.c,v 1.72 2022/03/03 05:50:22 riastradh Exp $   */
 
 /*     $OpenBSD: if_smsc.c,v 1.4 2012/09/27 12:38:11 jsg Exp $ */
 /*     $FreeBSD: src/sys/dev/usb/net/if_smsc.c,v 1.1 2012/08/15 04:03:55 gonzo Exp $ */
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.71 2022/03/03 05:48:06 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.72 2022/03/03 05:50:22 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -552,11 +552,9 @@
 {
        struct usbnet * const un = ifp->if_softc;
 
-       usbnet_lock_core(un);
        usbnet_busy(un);
        int ret = smsc_init_locked(ifp);
        usbnet_unbusy(un);
-       usbnet_unlock_core(un);
 
        return ret;
 }
diff -r 66d4a25b09e8 -r 37fa1e67e0a9 sys/dev/usb/if_udav.c
--- a/sys/dev/usb/if_udav.c     Thu Mar 03 05:50:12 2022 +0000
+++ b/sys/dev/usb/if_udav.c     Thu Mar 03 05:50:22 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_udav.c,v 1.78 2021/04/02 09:27:44 skrll Exp $       */
+/*     $NetBSD: if_udav.c,v 1.79 2022/03/03 05:50:22 riastradh Exp $   */
 /*     $nabe: if_udav.c,v 1.3 2003/08/21 16:57:19 nabe Exp $   */
 



Home | Main Index | Thread Index | Old Index