Thu Mar 3 05:50:22 2022 UTC ()
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.
(riastradh)
diff -r1.171 -r1.172 src/sys/dev/usb/if_aue.c
diff -r1.132 -r1.133 src/sys/dev/usb/if_axe.c
diff -r1.74 -r1.75 src/sys/dev/usb/if_axen.c
diff -r1.72 -r1.73 src/sys/dev/usb/if_cdce.c
diff -r1.92 -r1.93 src/sys/dev/usb/if_cue.c
diff -r1.105 -r1.106 src/sys/dev/usb/if_kue.c
diff -r1.7 -r1.8 src/sys/dev/usb/if_mos.c
diff -r1.63 -r1.64 src/sys/dev/usb/if_mue.c
diff -r1.71 -r1.72 src/sys/dev/usb/if_smsc.c
diff -r1.71 -r1.72 src/sys/dev/usb/if_upl.c
diff -r1.78 -r1.79 src/sys/dev/usb/if_udav.c
diff -r1.78 -r1.79 src/sys/dev/usb/if_url.c
diff -r1.40 -r1.41 src/sys/dev/usb/if_ure.c
diff -r1.39 -r1.40 src/sys/dev/usb/if_urndis.c
diff -r1.70 -r1.71 src/sys/dev/usb/usbnet.c
--- src/sys/dev/usb/if_aue.c 2020/03/18 11:33:32 1.171
+++ src/sys/dev/usb/if_aue.c 2022/03/03 05:50:22 1.172
@@ -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;
--- src/sys/dev/usb/if_axe.c 2021/03/01 17:41:00 1.132
+++ src/sys/dev/usb/if_axe.c 2022/03/03 05:50:22 1.133
@@ -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;
}
--- src/sys/dev/usb/if_axen.c 2022/03/03 05:48:06 1.74
+++ src/sys/dev/usb/if_axen.c 2022/03/03 05:50:22 1.75
@@ -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;
}
--- src/sys/dev/usb/if_cdce.c 2020/05/15 19:28:10 1.72
+++ src/sys/dev/usb/if_cdce.c 2022/03/03 05:50:22 1.73
@@ -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>
@@ -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;
}
--- src/sys/dev/usb/if_cue.c 2022/03/03 05:49:51 1.92
+++ src/sys/dev/usb/if_cue.c 2022/03/03 05:50:22 1.93
@@ -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;
}
--- src/sys/dev/usb/if_kue.c 2021/06/13 09:26:24 1.105
+++ src/sys/dev/usb/if_kue.c 2022/03/03 05:50:22 1.106
@@ -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;
}
--- src/sys/dev/usb/if_mos.c 2020/04/02 04:09:36 1.7
+++ src/sys/dev/usb/if_mos.c 2022/03/03 05:50:22 1.8
@@ -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;
}
--- src/sys/dev/usb/if_mue.c 2022/03/03 05:48:06 1.63
+++ src/sys/dev/usb/if_mue.c 2022/03/03 05:50:22 1.64
@@ -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;
}
--- src/sys/dev/usb/if_smsc.c 2022/03/03 05:48:06 1.71
+++ src/sys/dev/usb/if_smsc.c 2022/03/03 05:50:22 1.72
@@ -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;
}
--- src/sys/dev/usb/if_upl.c 2020/03/15 23:04:51 1.71
+++ src/sys/dev/usb/if_upl.c 2022/03/03 05:50:22 1.72
@@ -1,4 +1,4 @@
-/* $NetBSD: if_upl.c,v 1.71 2020/03/15 23:04:51 thorpej Exp $ */
+/* $NetBSD: if_upl.c,v 1.72 2022/03/03 05:50:22 riastradh Exp $ */
/*
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_upl.c,v 1.71 2020/03/15 23:04:51 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_upl.c,v 1.72 2022/03/03 05:50:22 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -257,12 +257,10 @@
struct usbnet * const un = ifp->if_softc;
int rv;
- usbnet_lock_core(un);
if (usbnet_isdying(un))
rv = EIO;
else
rv = usbnet_init_rx_tx(un);
- usbnet_unlock_core(un);
return rv;
}
--- src/sys/dev/usb/if_udav.c 2021/04/02 09:27:44 1.78
+++ src/sys/dev/usb/if_udav.c 2022/03/03 05:50:22 1.79
@@ -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 $ */
/*
@@ -45,7 +45,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_udav.c,v 1.78 2021/04/02 09:27:44 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_udav.c,v 1.79 2022/03/03 05:50:22 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -478,10 +478,7 @@
DPRINTF(("%s: %s: enter\n", device_xname(un->un_dev), __func__));
- usbnet_lock_core(un);
-
if (usbnet_isdying(un)) {
- usbnet_unlock_core(un);
return EIO;
}
@@ -522,7 +519,6 @@
if (rc != 0) {
usbnet_unbusy(un);
- usbnet_unlock_core(un);
return rc;
}
@@ -532,7 +528,6 @@
rc = usbnet_init_rx_tx(un);
usbnet_unbusy(un);
- usbnet_unlock_core(un);
return rc;
}
--- src/sys/dev/usb/if_url.c 2022/03/03 05:48:14 1.78
+++ src/sys/dev/usb/if_url.c 2022/03/03 05:50:22 1.79
@@ -1,4 +1,4 @@
-/* $NetBSD: if_url.c,v 1.78 2022/03/03 05:48:14 riastradh Exp $ */
+/* $NetBSD: if_url.c,v 1.79 2022/03/03 05:50:22 riastradh Exp $ */
/*
* Copyright (c) 2001, 2002
@@ -44,7 +44,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_url.c,v 1.78 2022/03/03 05:48:14 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_url.c,v 1.79 2022/03/03 05:50:22 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -408,11 +408,9 @@
{
struct usbnet * const un = ifp->if_softc;
- usbnet_lock_core(un);
usbnet_busy(un);
int ret = url_init_locked(ifp);
usbnet_unbusy(un);
- usbnet_unlock_core(un);
return ret;
}
--- src/sys/dev/usb/if_ure.c 2020/03/27 18:04:45 1.40
+++ src/sys/dev/usb/if_ure.c 2022/03/03 05:50:22 1.41
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ure.c,v 1.40 2020/03/27 18:04:45 nisimura Exp $ */
+/* $NetBSD: if_ure.c,v 1.41 2022/03/03 05:50:22 riastradh Exp $ */
/* $OpenBSD: if_ure.c,v 1.10 2018/11/02 21:32:30 jcs Exp $ */
/*-
@@ -30,7 +30,7 @@
/* RealTek RTL8152/RTL8153 10/100/Gigabit USB Ethernet device */
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ure.c,v 1.40 2020/03/27 18:04:45 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ure.c,v 1.41 2022/03/03 05:50:22 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -456,11 +456,9 @@
{
struct usbnet * const un = ifp->if_softc;
- usbnet_lock_core(un);
usbnet_busy(un);
int ret = ure_init_locked(ifp);
usbnet_unbusy(un);
- usbnet_unlock_core(un);
return ret;
}
--- src/sys/dev/usb/if_urndis.c 2020/03/15 23:04:51 1.39
+++ src/sys/dev/usb/if_urndis.c 2022/03/03 05:50:22 1.40
@@ -1,4 +1,4 @@
-/* $NetBSD: if_urndis.c,v 1.39 2020/03/15 23:04:51 thorpej Exp $ */
+/* $NetBSD: if_urndis.c,v 1.40 2022/03/03 05:50:22 riastradh Exp $ */
/* $OpenBSD: if_urndis.c,v 1.31 2011/07/03 15:47:17 matthew Exp $ */
/*
@@ -21,7 +21,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_urndis.c,v 1.39 2020/03/15 23:04:51 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urndis.c,v 1.40 2022/03/03 05:50:22 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -883,8 +883,15 @@
urndis_uno_init(struct ifnet *ifp)
{
struct usbnet *un = ifp->if_softc;
+ int error;
- return urndis_init_un(ifp, un);
+ KASSERT(IFNET_LOCKED(ifp));
+
+ usbnet_unlock_core(un);
+ error = urndis_init_un(ifp, un);
+ usbnet_lock_core(un);
+
+ return error;
}
static int
--- src/sys/dev/usb/usbnet.c 2022/03/03 05:50:12 1.70
+++ src/sys/dev/usb/usbnet.c 2022/03/03 05:50:22 1.71
@@ -1,4 +1,4 @@
-/* $NetBSD: usbnet.c,v 1.70 2022/03/03 05:50:12 riastradh Exp $ */
+/* $NetBSD: usbnet.c,v 1.71 2022/03/03 05:50:22 riastradh Exp $ */
/*
* Copyright (c) 2019 Matthew R. Green
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.70 2022/03/03 05:50:12 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.71 2022/03/03 05:50:22 riastradh Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -1291,6 +1291,7 @@
USBNETHIST_FUNC(); USBNETHIST_CALLED();
struct usbnet * const un = ifp->if_softc;
bool dying;
+ int error;
KASSERTMSG(IFNET_LOCKED(ifp), "%s", ifp->if_xname);
@@ -1304,7 +1305,11 @@
if (dying)
return EIO;
- return uno_init(un, ifp);
+ mutex_enter(&un->un_pri->unp_core_lock);
+ error = uno_init(un, ifp);
+ mutex_exit(&un->un_pri->unp_core_lock);
+
+ return error;
}