Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/hyperv hvn(4): Prevent from occur panic when acquiri...



details:   https://anonhg.NetBSD.org/src/rev/f3af4ca9e3da
branches:  trunk
changeset: 972338:f3af4ca9e3da
user:      nonaka <nonaka%NetBSD.org@localhost>
date:      Sun May 24 10:31:59 2020 +0000

description:
hvn(4): Prevent from occur panic when acquiring the media status.

hvn(4) sleeps during hvn_media_status(), and thus requires an adaptive mutex
for the media lock.  Taken from recent iwm(4) change.

diffstat:

 sys/dev/hyperv/if_hvn.c |  16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diffs (58 lines):

diff -r 052faf8dcc55 -r f3af4ca9e3da sys/dev/hyperv/if_hvn.c
--- a/sys/dev/hyperv/if_hvn.c   Sun May 24 09:55:43 2020 +0000
+++ b/sys/dev/hyperv/if_hvn.c   Sun May 24 10:31:59 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_hvn.c,v 1.17 2020/02/04 05:25:38 thorpej Exp $      */
+/*     $NetBSD: if_hvn.c,v 1.18 2020/05/24 10:31:59 nonaka Exp $       */
 /*     $OpenBSD: if_hvn.c,v 1.39 2018/03/11 14:31:34 mikeb Exp $       */
 
 /*-
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_hvn.c,v 1.17 2020/02/04 05:25:38 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_hvn.c,v 1.18 2020/05/24 10:31:59 nonaka Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -133,6 +133,7 @@
 
        struct ethercom                 sc_ec;
        struct ifmedia                  sc_media;
+       kmutex_t                        sc_media_lock;  /* XXX */
        struct if_percpuq               *sc_ipq;
        int                             sc_link_state;
        int                             sc_promisc;
@@ -294,8 +295,10 @@
 
        /* Initialize ifmedia structures. */
        sc->sc_ec.ec_ifmedia = &sc->sc_media;
-       ifmedia_init(&sc->sc_media, IFM_IMASK, hvn_media_change,
-           hvn_media_status);
+       /* XXX media locking needs revisiting */
+       mutex_init(&sc->sc_media_lock, MUTEX_DEFAULT, IPL_SOFTNET);
+       ifmedia_init_with_lock(&sc->sc_media, IFM_IMASK,
+           hvn_media_change, hvn_media_status, &sc->sc_media_lock);
        ifmedia_add(&sc->sc_media, IFM_ETHER | IFM_MANUAL, 0, NULL);
        ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_MANUAL);
 
@@ -341,7 +344,9 @@
 
 fail4: hvn_rndis_detach(sc);
        if_percpuq_destroy(sc->sc_ipq);
-fail3: hvn_tx_ring_destroy(sc);
+fail3: ifmedia_fini(&sc->sc_media);
+       mutex_destroy(&sc->sc_media_lock);
+       hvn_tx_ring_destroy(sc);
 fail2: hvn_rx_ring_destroy(sc);
 fail1: hvn_nvs_detach(sc);
 }
@@ -363,6 +368,7 @@
        ether_ifdetach(ifp);
        if_detach(ifp);
        ifmedia_fini(&sc->sc_media);
+       mutex_destroy(&sc->sc_media_lock);
        if_percpuq_destroy(sc->sc_ipq);
 
        hvn_rndis_detach(sc);



Home | Main Index | Thread Index | Old Index