From nobody Tue Apr 29 18:30:38 2025 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Zn85C4FWcz5vN65; Tue, 29 Apr 2025 18:30:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Zn85B6tGPz4HMN; Tue, 29 Apr 2025 18:30:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745951439; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cQAMI4tF643SWcVMoz6jXPO+xKFxf0TInZV4NYzSVVo=; b=fzpOgVc3/sJS0kn3rX5URqra/cwaiWV72gLeLjhg3pu4CwYASv++f1Ceh797OkJaWp8Piq ljKH+M2ZqZAWV/pmgoRaRzuVTz6WrlymNXVor6lP2EdAShunPBQUvqwm6b94TIhnpdh/44 sbt+jZmi7s+Z3ScfT4YL+JCAoN+1lVyNOOWZ+z0Mr/9VxTPuIUu1YXrTqs7hQ1E2k4uoNB HAA482A75SeKEwqHAZKxCGhAJ4fHTBjVCF76f4yDzfc+k+nzs6c+Mz/t08J4FdT1P0eIyk ev6lnKKf9F5HBiIkJncJlBWJ6GMPGK4a/SE1zkC3W5oMnqsS9hFx2AaOb0fSiA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1745951439; a=rsa-sha256; cv=none; b=nJCV2spMjoOSJ3+J42L6S0jKr3okE7s52lqlbORFIvxnl/yRgrKERq6+AAuRplwlxTlo6s DGzsP5NkswNxcDD5fXtgKwfSA1smqQE6coTi87hYLWpCztraghBdeuF8/0mPPLWUv2cGF6 5fKgBhKmQj2oYExdQ1ci+tM05iejNAhl8ENopwsJibG4RJDwKrEhX6EJW2T69DXlJo739f wD2LVyTRak6z/Gtnx1k0Bl8+b+53sLiaDYXJmw1CeUTI0CJihHvWzGah1/2DrrZP0OEQwr /5FnaGzG/P/3FdyhoLaoPI8no3YGsiA3Zb0FsCieYdm9/wZYPK5IA9y/SIYxyw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745951439; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cQAMI4tF643SWcVMoz6jXPO+xKFxf0TInZV4NYzSVVo=; b=UnBIE8T3EHAqEgLFIZubsUw5WXGuxDt07uz4E1ahy2GK3zvTUhKBdg0YgGx7ue7viBMF/Y 2OEzYP3857w4U/k3rS/a4bGOUNlBrLT3hEYlMjgV+7m8RkAU6n8QJ258rph3Y3ZqlvQ/e7 K5SY3Y/6W/wZizGfHl627OlMivioRQHV4LDFj8QU62ZXjQ0kKjKcTWXUyr1pO7YzYD1Kia MkHBoQQZtgznEhkocbBZJ/ekZzvUPKN2RVSggYRM7SMdiWxBuDiEBGX1n58wKnvaPAa20U cgWnWv0bu6LQ+xTwT5NStObRIOP8uDojVQo70MnobkQWZbH/tO6c0iT8sFlzvA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Zn85B5wpTzXb4; Tue, 29 Apr 2025 18:30:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53TIUcSh022595; Tue, 29 Apr 2025 18:30:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53TIUcvB022592; Tue, 29 Apr 2025 18:30:38 GMT (envelope-from git) Date: Tue, 29 Apr 2025 18:30:38 GMT Message-Id: <202504291830.53TIUcvB022592@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: ee08e8455170 - stable/14 - mmc: Use bus_topo_lock and taskqueue_bus while adding/removing child devices List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: ee08e8455170b65b85e85aa44374494b95fc5f0c Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=ee08e8455170b65b85e85aa44374494b95fc5f0c commit ee08e8455170b65b85e85aa44374494b95fc5f0c Author: John Baldwin AuthorDate: 2025-03-10 17:32:53 +0000 Commit: John Baldwin CommitDate: 2025-04-29 14:40:47 +0000 mmc: Use bus_topo_lock and taskqueue_bus while adding/removing child devices Some drivers held regular mutexes across some new-bus calls; instead depend on bus_topo_lock to protect the relevant softc members. This also fixes the bus_topo_lock to be explicit in these drivers rather than relying on the implicit Giant from taskqueue_swi_giant. It avoids calling sleepable routines like device_probe_and_attach from an swi context. Differential Revision: https://reviews.freebsd.org/D49270 (cherry picked from commit c0bed9bd0bda2ca9239f5913cd2d5c1bd5d29bfa) --- sys/arm/allwinner/aw_mmc.c | 11 ++++------- sys/dev/mmc/host/dwmmc.c | 22 +++++++++------------- sys/dev/mmc/mmc_fdt_helpers.c | 10 +++++----- sys/dev/rtsx/rtsx.c | 18 +++++++++++------- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/sys/arm/allwinner/aw_mmc.c b/sys/arm/allwinner/aw_mmc.c index 8b0d825e4d4f..37dc95778105 100644 --- a/sys/arm/allwinner/aw_mmc.c +++ b/sys/arm/allwinner/aw_mmc.c @@ -323,32 +323,29 @@ aw_mmc_helper_cd_handler(device_t dev, bool present) #ifdef MMCCAM mmc_cam_sim_discover(&sc->mmc_sim); #else - AW_MMC_LOCK(sc); + bus_topo_lock(); if (present) { if (sc->child == NULL) { if (__predict_false(aw_mmc_debug & AW_MMC_DEBUG_CARD)) device_printf(sc->aw_dev, "Card inserted\n"); sc->child = device_add_child(sc->aw_dev, "mmc", -1); - AW_MMC_UNLOCK(sc); if (sc->child) { device_set_ivars(sc->child, sc); (void)device_probe_and_attach(sc->child); } - } else - AW_MMC_UNLOCK(sc); + } } else { /* Card isn't present, detach if necessary */ if (sc->child != NULL) { if (__predict_false(aw_mmc_debug & AW_MMC_DEBUG_CARD)) device_printf(sc->aw_dev, "Card removed\n"); - AW_MMC_UNLOCK(sc); device_delete_child(sc->aw_dev, sc->child); sc->child = NULL; - } else - AW_MMC_UNLOCK(sc); + } } + bus_topo_unlock(); #endif /* MMCCAM */ } diff --git a/sys/dev/mmc/host/dwmmc.c b/sys/dev/mmc/host/dwmmc.c index be6f5e9de2d1..965a40f45505 100644 --- a/sys/dev/mmc/host/dwmmc.c +++ b/sys/dev/mmc/host/dwmmc.c @@ -463,10 +463,10 @@ dwmmc_handle_card_present(struct dwmmc_softc *sc, bool is_present) was_present = sc->child != NULL; if (!was_present && is_present) { - taskqueue_enqueue_timeout(taskqueue_swi_giant, + taskqueue_enqueue_timeout(taskqueue_bus, &sc->card_delayed_task, -(hz / 2)); } else if (was_present && !is_present) { - taskqueue_enqueue(taskqueue_swi_giant, &sc->card_task); + taskqueue_enqueue(taskqueue_bus, &sc->card_task); } } @@ -478,8 +478,7 @@ dwmmc_card_task(void *arg, int pending __unused) #ifdef MMCCAM mmc_cam_sim_discover(&sc->mmc_sim); #else - DWMMC_LOCK(sc); - + bus_topo_lock(); if (READ4(sc, SDMMC_CDETECT) == 0 || (sc->mmc_helper.props & MMC_PROP_BROKEN_CD)) { if (sc->child == NULL) { @@ -487,25 +486,22 @@ dwmmc_card_task(void *arg, int pending __unused) device_printf(sc->dev, "Card inserted\n"); sc->child = device_add_child(sc->dev, "mmc", -1); - DWMMC_UNLOCK(sc); if (sc->child) { device_set_ivars(sc->child, sc); (void)device_probe_and_attach(sc->child); } - } else - DWMMC_UNLOCK(sc); + } } else { /* Card isn't present, detach if necessary */ if (sc->child != NULL) { if (bootverbose) device_printf(sc->dev, "Card removed\n"); - DWMMC_UNLOCK(sc); device_delete_child(sc->dev, sc->child); sc->child = NULL; - } else - DWMMC_UNLOCK(sc); + } } + bus_topo_unlock(); #endif /* MMCCAM */ } @@ -752,7 +748,7 @@ dwmmc_attach(device_t dev) WRITE4(sc, SDMMC_CTRL, SDMMC_CTRL_INT_ENABLE); TASK_INIT(&sc->card_task, 0, dwmmc_card_task, sc); - TIMEOUT_TASK_INIT(taskqueue_swi_giant, &sc->card_delayed_task, 0, + TIMEOUT_TASK_INIT(taskqueue_bus, &sc->card_delayed_task, 0, dwmmc_card_task, sc); #ifdef MMCCAM @@ -783,8 +779,8 @@ dwmmc_detach(device_t dev) if (ret != 0) return (ret); - taskqueue_drain(taskqueue_swi_giant, &sc->card_task); - taskqueue_drain_timeout(taskqueue_swi_giant, &sc->card_delayed_task); + taskqueue_drain(taskqueue_bus, &sc->card_task); + taskqueue_drain_timeout(taskqueue_bus, &sc->card_delayed_task); if (sc->intr_cookie != NULL) { ret = bus_teardown_intr(dev, sc->res[1], sc->intr_cookie); diff --git a/sys/dev/mmc/mmc_fdt_helpers.c b/sys/dev/mmc/mmc_fdt_helpers.c index 30538ea20ca3..47c8c6ce1c79 100644 --- a/sys/dev/mmc/mmc_fdt_helpers.c +++ b/sys/dev/mmc/mmc_fdt_helpers.c @@ -112,7 +112,7 @@ cd_intr(void *arg) { struct mmc_helper *helper = arg; - taskqueue_enqueue_timeout(taskqueue_swi_giant, + taskqueue_enqueue_timeout(taskqueue_bus, &helper->cd_delayed_task, -(hz / 2)); } @@ -130,7 +130,7 @@ cd_card_task(void *arg, int pending __unused) /* If we're polling re-schedule the task */ if (helper->cd_ihandler == NULL) - taskqueue_enqueue_timeout_sbt(taskqueue_swi_giant, + taskqueue_enqueue_timeout_sbt(taskqueue_bus, &helper->cd_delayed_task, mstosbt(500), 0, C_PREL(2)); } @@ -146,7 +146,7 @@ cd_setup(struct mmc_helper *helper, phandle_t node) dev = helper->dev; - TIMEOUT_TASK_INIT(taskqueue_swi_giant, &helper->cd_delayed_task, 0, + TIMEOUT_TASK_INIT(taskqueue_bus, &helper->cd_delayed_task, 0, cd_card_task, helper); /* @@ -281,7 +281,7 @@ mmc_fdt_gpio_setup(device_t dev, phandle_t node, struct mmc_helper *helper, /* * Schedule a card detection */ - taskqueue_enqueue_timeout_sbt(taskqueue_swi_giant, + taskqueue_enqueue_timeout_sbt(taskqueue_bus, &helper->cd_delayed_task, mstosbt(500), 0, C_PREL(2)); return (0); } @@ -302,7 +302,7 @@ mmc_fdt_gpio_teardown(struct mmc_helper *helper) if (helper->cd_ires != NULL) bus_release_resource(helper->dev, SYS_RES_IRQ, 0, helper->cd_ires); - taskqueue_drain_timeout(taskqueue_swi_giant, &helper->cd_delayed_task); + taskqueue_drain_timeout(taskqueue_bus, &helper->cd_delayed_task); } bool diff --git a/sys/dev/rtsx/rtsx.c b/sys/dev/rtsx/rtsx.c index b02e7fd2d24a..461f39e3d3c4 100644 --- a/sys/dev/rtsx/rtsx.c +++ b/sys/dev/rtsx/rtsx.c @@ -634,10 +634,10 @@ rtsx_handle_card_present(struct rtsx_softc *sc) * (sometimes the card detect pin stabilizes * before the other pins have made good contact). */ - taskqueue_enqueue_timeout(taskqueue_swi_giant, + taskqueue_enqueue_timeout(taskqueue_bus, &sc->rtsx_card_insert_task, -hz); } else if (was_present && !is_present) { - taskqueue_enqueue(taskqueue_swi_giant, &sc->rtsx_card_remove_task); + taskqueue_enqueue(taskqueue_bus, &sc->rtsx_card_remove_task); } } @@ -649,6 +649,9 @@ rtsx_card_task(void *arg, int pending __unused) { struct rtsx_softc *sc = arg; +#ifndef MMCCAM + bus_topo_lock(); +#endif if (rtsx_is_card_present(sc)) { sc->rtsx_flags |= RTSX_F_CARD_PRESENT; /* Card is present, attach if necessary. */ @@ -665,9 +668,7 @@ rtsx_card_task(void *arg, int pending __unused) sc->rtsx_cam_status = 1; mmc_cam_sim_discover(&sc->rtsx_mmc_sim); #else /* !MMCCAM */ - RTSX_LOCK(sc); sc->rtsx_mmc_dev = device_add_child(sc->rtsx_dev, "mmc", -1); - RTSX_UNLOCK(sc); if (sc->rtsx_mmc_dev == NULL) { device_printf(sc->rtsx_dev, "Adding MMC bus failed\n"); } else { @@ -700,6 +701,9 @@ rtsx_card_task(void *arg, int pending __unused) #endif /* MMCCAM */ } } +#ifndef MMCCAM + bus_topo_unlock(); +#endif } static bool @@ -3690,7 +3694,7 @@ rtsx_attach(device_t dev) sc->rtsx_mem_btag = rman_get_bustag(sc->rtsx_mem_res); sc->rtsx_mem_bhandle = rman_get_bushandle(sc->rtsx_mem_res); - TIMEOUT_TASK_INIT(taskqueue_swi_giant, &sc->rtsx_card_insert_task, 0, + TIMEOUT_TASK_INIT(taskqueue_bus, &sc->rtsx_card_insert_task, 0, rtsx_card_task, sc); TASK_INIT(&sc->rtsx_card_remove_task, 0, rtsx_card_task, sc); @@ -3789,8 +3793,8 @@ rtsx_detach(device_t dev) if (error) return (error); - taskqueue_drain_timeout(taskqueue_swi_giant, &sc->rtsx_card_insert_task); - taskqueue_drain(taskqueue_swi_giant, &sc->rtsx_card_remove_task); + taskqueue_drain_timeout(taskqueue_bus, &sc->rtsx_card_insert_task); + taskqueue_drain(taskqueue_bus, &sc->rtsx_card_remove_task); /* Teardown the state in our softc created in our attach routine. */ rtsx_dma_free(sc);