Module Name: src
Committed By: riastradh
Date: Thu Mar 3 05:47:36 UTC 2022
Modified Files:
src/sys/dev/usb: usbnet.c
Log Message:
usbnet: Assert IFNET_LOCKED in usbnet_init_rx_tx, usbnet_stop.
Exception: urndis(4) abuses this API to start this logic before the
ifp is actually initialized. So for the sake of urndis(4), until
sense can be beaten into it, allow the !unp_ifp_attached case to run
without IFNET_LOCK.
To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/dev/usb/usbnet.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/usb/usbnet.c
diff -u src/sys/dev/usb/usbnet.c:1.50 src/sys/dev/usb/usbnet.c:1.51
--- src/sys/dev/usb/usbnet.c:1.50 Thu Mar 3 05:47:28 2022
+++ src/sys/dev/usb/usbnet.c Thu Mar 3 05:47:36 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: usbnet.c,v 1.50 2022/03/03 05:47:28 riastradh Exp $ */
+/* $NetBSD: usbnet.c,v 1.51 2022/03/03 05:47:36 riastradh Exp $ */
/*
* Copyright (c) 2019 Matthew R. Green
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.50 2022/03/03 05:47:28 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.51 2022/03/03 05:47:36 riastradh Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -151,6 +151,8 @@ fail:
static void
uno_stop(struct usbnet *un, struct ifnet *ifp, int disable)
{
+ KASSERTMSG(!un->un_pri->unp_ifp_attached || IFNET_LOCKED(ifp),
+ "%s", ifp->if_xname);
usbnet_isowned_core(un);
if (un->un_ops->uno_stop)
(*un->un_ops->uno_stop)(ifp, disable);
@@ -820,6 +822,9 @@ usbnet_init_rx_tx(struct usbnet * const
usbd_status err;
int error = 0;
+ KASSERTMSG(!unp->unp_ifp_attached || IFNET_LOCKED(ifp),
+ "%s", ifp->if_xname);
+
usbnet_isowned_core(un);
if (unp->unp_dying) {
@@ -1117,6 +1122,8 @@ usbnet_stop(struct usbnet *un, struct if
USBNETHIST_FUNC(); USBNETHIST_CALLED();
+ KASSERTMSG(!unp->unp_ifp_attached || IFNET_LOCKED(ifp),
+ "%s", ifp->if_xname);
usbnet_isowned_core(un);
usbnet_busy(un);
@@ -1147,13 +1154,9 @@ usbnet_stop(struct usbnet *un, struct if
/* Close pipes. */
usbnet_ep_close_pipes(un);
- /*
- * XXXSMP Would like to
- * KASSERT(IFNET_LOCKED(ifp))
- * here but the locking order is:
- * ifnet -> core_lock -> rxlock -> txlock
- * and core_lock is already held.
- */
+ /* Everything is quesced now. */
+ KASSERTMSG(!unp->unp_ifp_attached || IFNET_LOCKED(ifp),
+ "%s", ifp->if_xname);
ifp->if_flags &= ~IFF_RUNNING;
usbnet_unbusy(un);