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 = { 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); }