i2c: tegra: Do not mark ACPI devices as irq safe
authorBreno Leitao <leitao@debian.org>
Tue, 13 Aug 2024 16:12:53 +0000 (09:12 -0700)
committerAndi Shyti <andi.shyti@kernel.org>
Wed, 14 Aug 2024 22:22:28 +0000 (00:22 +0200)
On ACPI machines, the tegra i2c module encounters an issue due to a
mutex being called inside a spinlock. This leads to the following bug:

BUG: sleeping function called from invalid context at kernel/locking/mutex.c:585
...

Call trace:
__might_sleep
__mutex_lock_common
mutex_lock_nested
acpi_subsys_runtime_resume
rpm_resume
tegra_i2c_xfer

The problem arises because during __pm_runtime_resume(), the spinlock
&dev->power.lock is acquired before rpm_resume() is called. Later,
rpm_resume() invokes acpi_subsys_runtime_resume(), which relies on
mutexes, triggering the error.

To address this issue, devices on ACPI are now marked as not IRQ-safe,
considering the dependency of acpi_subsys_runtime_resume() on mutexes.

Fixes: bd2fdedbf2ba ("i2c: tegra: Add the ACPI support")
Cc: <stable@vger.kernel.org> # v5.17+
Co-developed-by: Michael van der Westhuizen <rmikey@meta.com>
Signed-off-by: Michael van der Westhuizen <rmikey@meta.com>
Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
drivers/i2c/busses/i2c-tegra.c

index 85b31edc558dff21a54120ea2f8b01e3dd8a3f00..1df5b42041427c87753cd10739805412890cf726 100644 (file)
@@ -1802,9 +1802,9 @@ static int tegra_i2c_probe(struct platform_device *pdev)
         * domain.
         *
         * VI I2C device shouldn't be marked as IRQ-safe because VI I2C won't
-        * be used for atomic transfers.
+        * be used for atomic transfers. ACPI device is not IRQ safe also.
         */
-       if (!IS_VI(i2c_dev))
+       if (!IS_VI(i2c_dev) && !has_acpi_companion(i2c_dev->dev))
                pm_runtime_irq_safe(i2c_dev->dev);
 
        pm_runtime_enable(i2c_dev->dev);