Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/sdmmc sdhc: avoid taking adaptive mutex while holdin...



details:   https://anonhg.NetBSD.org/src/rev/08022b4106af
branches:  trunk
changeset: 359703:08022b4106af
user:      mrg <mrg%NetBSD.org@localhost>
date:      Mon Jan 17 20:10:37 2022 +0000

description:
sdhc: avoid taking adaptive mutex while holding spin mutex

the clock_bus pre- and post- callbacks used in sdhc_bus_clock_ddr()
are called with a spin mutex held, and the new sdhc@acpi ends up
calling into (sleeping) ACPI code, triggering lockdebug assertion.

introduce an adaptive mutex that is held around these callbacks,
and reduce the spin mutex held time in sdhc_bus_clock_ddr().

diffstat:

 sys/dev/sdmmc/sdhc.c |  22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diffs (85 lines):

diff -r a4141395652a -r 08022b4106af sys/dev/sdmmc/sdhc.c
--- a/sys/dev/sdmmc/sdhc.c      Mon Jan 17 20:01:43 2022 +0000
+++ b/sys/dev/sdmmc/sdhc.c      Mon Jan 17 20:10:37 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sdhc.c,v 1.113 2022/01/15 14:33:36 jmcneill Exp $      */
+/*     $NetBSD: sdhc.c,v 1.114 2022/01/17 20:10:37 mrg Exp $   */
 /*     $OpenBSD: sdhc.c,v 1.25 2009/01/13 19:44:20 grange Exp $        */
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.113 2022/01/15 14:33:36 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.114 2022/01/17 20:10:37 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -77,6 +77,7 @@
        uint16_t intr_status;           /* soft interrupt status */
        uint16_t intr_error_status;     /* soft error status */
        kmutex_t intr_lock;
+       kmutex_t bus_clock_lock;
        kcondvar_t intr_cv;
 
        callout_t tuning_timer;
@@ -296,6 +297,7 @@
        hp->dmat = sc->sc_dmat;
 
        mutex_init(&hp->intr_lock, MUTEX_DEFAULT, IPL_SDMMC);
+       mutex_init(&hp->bus_clock_lock, MUTEX_DEFAULT, IPL_NONE);
        cv_init(&hp->intr_cv, "sdhcintr");
        callout_init(&hp->tuning_timer, CALLOUT_MPSAFE);
        callout_setfunc(&hp->tuning_timer, sdhc_tuning_timer, hp);
@@ -650,6 +652,7 @@
 err:
        callout_destroy(&hp->tuning_timer);
        cv_destroy(&hp->intr_cv);
+       mutex_destroy(&hp->bus_clock_lock);
        mutex_destroy(&hp->intr_lock);
        free(hp, M_DEVBUF);
        sc->sc_host[--sc->sc_nhosts] = NULL;
@@ -1097,8 +1100,6 @@
        int error = 0;
        bool present __diagused;
 
-       mutex_enter(&hp->intr_lock);
-
 #ifdef DIAGNOSTIC
        present = ISSET(HREAD4(hp, SDHC_PRESENT_STATE), SDHC_CMD_INHIBIT_MASK);
 
@@ -1110,11 +1111,15 @@
 #endif
 
        if (hp->sc->sc_vendor_bus_clock) {
+               mutex_enter(&hp->bus_clock_lock);
                error = (*hp->sc->sc_vendor_bus_clock)(hp->sc, freq);
+               mutex_exit(&hp->bus_clock_lock);
                if (error != 0)
-                       goto out;
+                       return error;
        }
 
+       mutex_enter(&hp->intr_lock);
+
        /*
         * Stop SD clock before changing the frequency.
         */
@@ -1275,11 +1280,14 @@
                        HCLR1(hp, SDHC_HOST_CTL, SDHC_HIGH_SPEED);
        }
 
+       mutex_exit(&hp->intr_lock);
+
        if (hp->sc->sc_vendor_bus_clock_post) {
+               mutex_enter(&hp->bus_clock_lock);
                error = (*hp->sc->sc_vendor_bus_clock_post)(hp->sc, freq);
-               if (error != 0)
-                       goto out;
+               mutex_exit(&hp->bus_clock_lock);
        }
+       return error;
 
 out:
        mutex_exit(&hp->intr_lock);



Home | Main Index | Thread Index | Old Index