From 208894259f593416d91546c9c8f8325614aefef1 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 23 Nov 2026 17:46:23 -0700 Subject: [PATCH 1/2] iommu/apple-dart: hold a sleep lease with a semaphore, not a mutex v27_lifecycle is taken by apple_dart_v27_claim() and stays held for as long as the sleep lease lasts. The claim runs in the suspend's async work and the lease is finished by the resume, from another task. A mutex has to be released by the task that took it. With lock checking on, the first T6050 deep sleep reports both ends: BUG: workqueue leaked atomic, lock or RCU: kworker/u73:1[211] locks held by kworker/u73:1/211: #0: (&dart->v27_lifecycle), at: apple_dart_v27_claim+0xf4/0xb80 WARNING: bad unlock balance detected! mutex_unlock apple_dart_v27_finish dcp_v27_late_disarm and lockdep turns itself off for the rest of the boot. A lock that changes hands is a semaphore. Make it one; no change to who waits for what. Signed-off-by: Jens Axboe --- drivers/iommu/apple-dart-v27-late.inc | 8 ++++---- drivers/iommu/apple-dart.c | 21 ++++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/apple-dart-v27-late.inc b/drivers/iommu/apple-dart-v27-late.inc index 74e663b1e406..965eaf0f17ed 100644 --- a/drivers/iommu/apple-dart-v27-late.inc +++ b/drivers/iommu/apple-dart-v27-late.inc @@ -137,12 +137,12 @@ int apple_dart_v27_claim(struct device *dev, struct device *owner, return -EBUSY; } if (dev->driver != &apple_dart_driver.driver || !(d = dev_get_drvdata(dev)) || - !d->v27_provider || !mutex_trylock(&d->v27_lifecycle)) { + !d->v27_provider || down_trylock(&d->v27_lifecycle)) { device_unlock(dev); return -ENODEV; } if (!try_module_get(THIS_MODULE)) { - mutex_unlock(&d->v27_lifecycle); + up(&d->v27_lifecycle); device_unlock(dev); return -ENODEV; } @@ -340,7 +340,7 @@ free: unlock: module_put(THIS_MODULE); put_device(dev); - mutex_unlock(&d->v27_lifecycle); + up(&d->v27_lifecycle); return ret; } EXPORT_SYMBOL_GPL(apple_dart_v27_claim); @@ -459,7 +459,7 @@ int apple_dart_v27_finish(struct apple_dart_v27_lease *l, bool stopped) WRITE_ONCE(d->m5_sleep_owner, NULL); WRITE_ONCE(d->v27_restoring, false); pm_runtime_put_noidle(d->dev); - mutex_unlock(&d->v27_lifecycle); + up(&d->v27_lifecycle); module_put(l->module); put_device(provider); kfree(l); diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index bf7a4fc0807f..5301e8ecb192 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -385,7 +386,11 @@ struct apple_dart { u32 m5_disp_streams; /* the display pipe's streams before its domain went off */ bool m5_released, m5_changed, m5_display, m5_failed; /* Optional cached evidence; never a sleep-ownership grant. */ - struct mutex v27_lifecycle; + /* + * Held for as long as a sleep lease lasts: taken by the suspend that claims the lease and + * released by the resume that finishes it, in another task. So a semaphore, not a mutex. + */ + struct semaphore v27_lifecycle; struct list_head v27_clients; atomic_t v27_ops; bool v27_provider, v27_lost, v27_noirq_skip, v27_restoring; @@ -5795,7 +5800,7 @@ static int apple_dart_probe(struct platform_device *pdev) } } spin_lock_init(&dart->lock); - mutex_init(&dart->v27_lifecycle); + sema_init(&dart->v27_lifecycle, 1); INIT_LIST_HEAD(&dart->v27_clients); atomic_set(&dart->v27_ops, 0); dart->v27_provider = res && apple_dart_v27_provider(dev, res->start); @@ -6535,10 +6540,12 @@ int apple_dart_restore_tunnel_state(struct device *dev) } EXPORT_SYMBOL_GPL(apple_dart_restore_tunnel_state); +DEFINE_GUARD(apple_dart_v27_lifecycle, struct semaphore *, down(_T), up(_T)) + static void apple_dart_remove(struct platform_device *pdev) { struct apple_dart *dart = platform_get_drvdata(pdev); - guard(mutex)(&dart->v27_lifecycle); + guard(apple_dart_v27_lifecycle)(&dart->v27_lifecycle); if (dart->cold_ane) { dev_warn(&pdev->dev, "cold ANE DART retained until reset\n"); @@ -6593,11 +6600,11 @@ static void apple_dart_shutdown(struct platform_device *pdev) struct apple_dart *dart = platform_get_drvdata(pdev); /* - * A sleep lease that lost its retained state keeps this mutex for good, so that nothing + * A sleep lease that lost its retained state keeps this semaphore for good, so that nothing * reuses the DART before the platform reset. The reset is what follows here: waiting for - * the mutex would hang the shutdown. + * it would hang the shutdown. */ - if (!mutex_trylock(&dart->v27_lifecycle)) { + if (down_trylock(&dart->v27_lifecycle)) { dev_info(&pdev->dev, "shutdown: left as its sleep lease pinned it\n"); return; } @@ -6609,7 +6616,7 @@ static void apple_dart_shutdown(struct platform_device *pdev) */ if (apple_dart_has_borrowed(dart)) apple_dart_fail_borrowed(dart, "shutdown"); - mutex_unlock(&dart->v27_lifecycle); + up(&dart->v27_lifecycle); } static const struct apple_dart_hw apple_dart_hw_t8103 = { From 7d64087e37aa9f17d7e2c1504ff6efb8a6300f28 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 23 Nov 2026 17:46:24 -0700 Subject: [PATCH 2/2] soc: apple: sleep: keep RCU watching while the T6050 entry prepares On a SoC with early_context the whole entry runs as cpu_suspend()'s finisher. cpu_suspend() calls the finisher after ct_cpuidle_enter(), with RCU not watching, which fits a finisher that only powers the core down. This one first checks the RTC alarm over SPMI under the controller's lock, stops the coprocessors, looks at work items and logs. With lock checking on, the first T6050 deep sleep reports each of them: RCU not watching for tracepoint WARNING: include/trace/events/lock.h:47 at lock_acquire _mutex_trylock_nest_lock apple_spmi_fifo_trylock t6050_sleep_pmu_xfer t6050_sleep_check_alarm apple_sleep_enter_saved cpu_suspend WARNING: suspicious RCU usage work_busy apple_nvme_m5_last_check apple_sleep_enter_saved Leave the idle state for the preparation and enter it again before the commit, which is the part that never returns. Signed-off-by: Jens Axboe --- drivers/soc/apple/sleep.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index 9cee856626f9..375988d9697d 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -6027,14 +6028,21 @@ static int apple_sleep_enter_prepare(struct apple_sleep *s) static int apple_sleep_enter_saved(unsigned long unused) { struct apple_sleep *s = apple_sleep; - int ret = s->soc->ops->cpu_prepare(s->mbox->boot_mpidr); + int ret; + /* + * cpu_suspend() calls its finisher with RCU not watching. Up to the commit this one + * takes locks, logs and looks at work items: RCU watches until then. + */ + ct_cpuidle_exit(); + ret = s->soc->ops->cpu_prepare(s->mbox->boot_mpidr); + if (!ret) + ret = apple_sleep_enter_prepare(s); + if (!ret) + pm_set_resume_via_firmware(); + ct_cpuidle_enter(); if (ret) return ret; - ret = apple_sleep_enter_prepare(s); - if (ret) - return ret; - pm_set_resume_via_firmware(); /* cpu_suspend has already saved boot context. Commit never returns. */ return apple_sleep_commit(0); }