From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796336484; b=Xu9Oq6N+N4JEkuG+FijB603AcBH9qu0AIjLj38e33xwqrd7Y5H4LLoNdumRotC+wxRGg pxNcwykowAQGQHfMWscRqtRajk36xz86cskdUnKj6135qy02G/tmL3jSqEkO9GcvfIKOp yGNKuVjghf59gt/nLYAfYJmUwETY5SQheyIY89329HivL9YmJKMhJ1Q749ulybWPnu1fu OoPjeDUkg80bMmowLAt/AHT7cdDhiRqTzip87vGbDmgdyoaV3xvIam6grCZBGRvJHsI4n YLzNCf3CV6BoGUdZJiAht8epsmH1G6XN/FjtM7IDomw0SvP4Q9Q5aZAw9MOK8qSH+8g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796336484; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=0PkiHHC2nMipRnXawCs3U2ZmoLjdvYt4nDPR9qGvLSE=; b=Md8J/2X5+Z0C0WFfoz9hL31ONpi/cTQBZmvH0r+NuLYURPEl69vTc+XDzfsYhU6ek/3Z op62rgMp2v4UoZx3hnmwuDq5PER0FK6tSwQ/kgbnRcjp2KiRlVwKoiDp/eHNfuqDiHtD9 Uj47gBw5hhHKnkNUeml4KKCvyHWMqL0rBMoQ1Kj5vi79kI/UbNBPhpuUQD9w5DUChcOAm Wme+45T9xQhlUouWKoPUis1/pDqrytPv5mkUKoFVYDySLtZ+exdbgs+zgaukk1omPHmsg JmLbUazWr1Myf3hzaatQ/otMxmACNBcI8T7NIsFE0clSAZqt0y1cOMbyScCQ8uP9gbA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RZLrmb99; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1D81606A322 for ; Thu, 3 Dec 2026 22:21:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RZLrmb99 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D07901F000C2; Thu, 3 Dec 2026 22:21:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796336484; bh=0PkiHHC2nMipRnXawCs3U2ZmoLjdvYt4nDPR9qGvLSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RZLrmb997BoZMzBDvA1noY+ZZWDgvfFZy5uB+JefLPG0hLol9RUTgU8ysfn1TUFCT Fhz8P2cx6OwxB/OI6YwBJzl8wwQv+J0KdEie82xAk68jEqOI+BRnPWwt4JZZzvtkDz liYQDdU5QrljYNzf1TDvk7X1969YFazzZgG1YuuWQmJnimZ2c7y1emOMTyeGbPNYhD GnwcUg6rvv4HfdKQ65v7BYkw8aOS478mlaZC5NpFhMDNWkw5tyuQqqPLYE6W4PFczm 9Bn8/i8eU7QyimeZ3mi7+Zb3tvoRxjWSVL0DGjkVZk2ZILCYhKtvrKojU/KYFdZDwW 991IwUhdEysNA== From: Sasha Levin To: stable@vger.kernel.org Cc: David Thompson , Bartosz Golaszewski , Sasha Levin Subject: [PATCH 6.6.y] gpio: mlxbf2: Disable interrupts around the chip lock in direction ops Date: Thu, 3 Dec 2026 17:21:22 -0500 Message-ID: <20261203222047.823986-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120225-spending-hexagram-1489@gregkh> References: <2026120225-spending-hexagram-1489@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: David Thompson [ Upstream commit f95bdff1d53471159e3c7112c5de4f6240772521 ] mlxbf2_gpio_lock_acquire() takes the generic GPIO chip lock with gpio_generic_chip_lock(), a plain raw_spin_lock() that leaves interrupts enabled. The same lock is also taken with the irqsave variant by the IRQ callbacks (irq_set_type, irq_enable, irq_disable), which run with the IRQ descriptor lock held. This creates a possible deadlock that lockdep reports as an IRQ lock inversion: CPU0 CPU1 ---- ---- lock(&chip->lock) lock(irq_desc->lock) lock(&chip->lock) lock(irq_desc->lock) If a GPIO interrupt arrives on CPU0 while it holds the chip lock during a direction change, the interrupt handler spins on the descriptor lock that CPU1 holds, while CPU1 spins on the chip lock held by CPU0. This was seen during probe of pwr-mlxbf. acpi_dev_gpio_irq_get() sets the pin to input through mlxbf2_gpio_direction_input(), and then irq_set_irq_type() runs with the descriptor lock held. Use the irqsave variant for the chip lock in mlxbf2_gpio_lock_acquire() and its release counterpart, and pass the saved flags from mlxbf2_gpio_direction_input() and mlxbf2_gpio_direction_output(). This matches the IRQ callbacks, so interrupts stay disabled for the whole ModeX update. Fixes: 2b725265cb08 ("gpio: mlxbf2: Introduce IRQ support") Cc: stable@vger.kernel.org Signed-off-by: David Thompson Link: https://patch.msgid.link/20261113184444.3431-1-davthompson@nvidia.com Signed-off-by: Bartosz Golaszewski [ sashal: Adapted the chip lock calls from gpio_generic_chip_lock*() helpers on gs->chip to raw_spin_lock_irqsave()/raw_spin_unlock_irqrestore() on gs->gc.bgpio_lock. ] Signed-off-by: Sasha Levin --- drivers/gpio/gpio-mlxbf2.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/gpio/gpio-mlxbf2.c b/drivers/gpio/gpio-mlxbf2.c index c03945af8538e..7c7678296767b 100644 --- a/drivers/gpio/gpio-mlxbf2.c +++ b/drivers/gpio/gpio-mlxbf2.c @@ -127,12 +127,20 @@ static int mlxbf2_gpio_get_lock_res(struct platform_device *pdev) * Acquire the YU arm_gpio_lock to be able to change the direction * mode. If the lock_active bit is already set, return an error. */ -static int mlxbf2_gpio_lock_acquire(struct mlxbf2_gpio_context *gs) +static int mlxbf2_gpio_lock_acquire(struct mlxbf2_gpio_context *gs, + unsigned long *flags) { u32 arm_gpio_lock_val; mutex_lock(yu_arm_gpio_lock_param.lock); - raw_spin_lock(&gs->gc.bgpio_lock); + /* + * Disable interrupts before taking the chip lock. The GPIO irq + * callbacks take this lock while holding the irq descriptor lock, + * and the irq handler takes the descriptor lock in hardirq context. + * A plain spin_lock() here lets lockdep report an inversion, and + * can deadlock if a GPIO interrupt arrives on this CPU. + */ + raw_spin_lock_irqsave(&gs->gc.bgpio_lock, *flags); arm_gpio_lock_val = readl(yu_arm_gpio_lock_param.io); @@ -140,7 +148,7 @@ static int mlxbf2_gpio_lock_acquire(struct mlxbf2_gpio_context *gs) * When lock active bit[31] is set, ModeX is write enabled */ if (YU_LOCK_ACTIVE_BIT(arm_gpio_lock_val)) { - raw_spin_unlock(&gs->gc.bgpio_lock); + raw_spin_unlock_irqrestore(&gs->gc.bgpio_lock, *flags); mutex_unlock(yu_arm_gpio_lock_param.lock); return -EINVAL; } @@ -153,12 +161,13 @@ static int mlxbf2_gpio_lock_acquire(struct mlxbf2_gpio_context *gs) /* * Release the YU arm_gpio_lock after changing the direction mode. */ -static void mlxbf2_gpio_lock_release(struct mlxbf2_gpio_context *gs) +static void mlxbf2_gpio_lock_release(struct mlxbf2_gpio_context *gs, + unsigned long flags) __releases(&gs->gc.bgpio_lock) __releases(yu_arm_gpio_lock_param.lock) { writel(YU_ARM_GPIO_LOCK_RELEASE, yu_arm_gpio_lock_param.io); - raw_spin_unlock(&gs->gc.bgpio_lock); + raw_spin_unlock_irqrestore(&gs->gc.bgpio_lock, flags); mutex_unlock(yu_arm_gpio_lock_param.lock); } @@ -184,20 +193,21 @@ static int mlxbf2_gpio_direction_input(struct gpio_chip *chip, unsigned int offset) { struct mlxbf2_gpio_context *gs = gpiochip_get_data(chip); + unsigned long flags; int ret; /* * Although the arm_gpio_lock was set in the probe function, check again * if it is still enabled to be able to write to the ModeX registers. */ - ret = mlxbf2_gpio_lock_acquire(gs); + ret = mlxbf2_gpio_lock_acquire(gs, &flags); if (ret < 0) return ret; writel(BIT(offset), gs->gpio_io + YU_GPIO_MODE0_CLEAR); writel(BIT(offset), gs->gpio_io + YU_GPIO_MODE1_CLEAR); - mlxbf2_gpio_lock_release(gs); + mlxbf2_gpio_lock_release(gs, flags); return ret; } @@ -211,6 +221,7 @@ static int mlxbf2_gpio_direction_output(struct gpio_chip *chip, int value) { struct mlxbf2_gpio_context *gs = gpiochip_get_data(chip); + unsigned long flags; int ret = 0; /* @@ -218,14 +229,14 @@ static int mlxbf2_gpio_direction_output(struct gpio_chip *chip, * check again it is still enabled to be able to write to the * ModeX registers. */ - ret = mlxbf2_gpio_lock_acquire(gs); + ret = mlxbf2_gpio_lock_acquire(gs, &flags); if (ret < 0) return ret; writel(BIT(offset), gs->gpio_io + YU_GPIO_MODE1_CLEAR); writel(BIT(offset), gs->gpio_io + YU_GPIO_MODE0_SET); - mlxbf2_gpio_lock_release(gs); + mlxbf2_gpio_lock_release(gs, flags); return ret; } -- 2.53.0