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=1796380927; b=s09FphOCuwPOo6CB8mwTATwNz1oA7pUslG2VWbMBWRaRgUeWMa+DicvDE1dbaCgYQpxi aFyjuDEOgJQ1f/0PtO+5TGjIGAwAo20zrC4EOEfRyA+ayc4b95H5kQkhvPA79fa0hT+Ay cTi3rk+jt3mP2RpztnloSjQ+KutBsr+Oc0BwAWBmdL2eWTQYev0rkJLqwiauvJqj2kP67 qy++FkCy9HmCbDyopE5BPcMSq/mGVbuRJ2s3rigD7oSEI4A3SC2zAVek/PJdf+jt/2fjc CjrPkvJNiG5KXSqgX0rf83ptOnJJo0lNVc2queRYkW9L+Ix3UBxB6d3H2LZ5wWMETxA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380927; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=b7S0pNyNE4mQDbHJOgznF1rWkWIAGi0kqcDSt2IlaRI=; b=PykNOog6XRbPJ1DYg58OScN+Bp8008SVhIfDjYzTbmzH5i1KshXXdcTmRCrVCsAAHhUS 4rvazFBT8zqlXxp/Icv+3XOgkZNSXptpylIycDr2EzVzWvWaRXDK486Uyjl5kGBHuSxW4 TiJgtgkn+dthBYXrd+Ji9mJRF30E5XgtPmvu93qVh/PZoOg44BW32ICv8FqH2Vysrgf0v 4FJ8OpOuPYfshaEY82RH9+QeBcWb8z+zDY1eI+IExNq9q8pLPhmZY90kwx3OYNOWBqBAf Yjf9XMFZtIxkjsNyq3kY/uGfYLtlRZshNi2XGEKtRtvJtgQUBJQZnj0kKNaHxb9N+ZA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=wjtzJTXW; 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 73A66606A322; Fri, 4 Dec 2026 10:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=wjtzJTXW Received: by smtp.kernel.org (Postfix) with ESMTPSA id D03631F000C2; Fri, 4 Dec 2026 10:42:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380927; bh=b7S0pNyNE4mQDbHJOgznF1rWkWIAGi0kqcDSt2IlaRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wjtzJTXWY+5tPn9euaeSltc2v6cTLT4TvxPg7pxbNkES8RGY/nsS6KwbnA0XMaJ5e hkyK0rFXERuninQO5Q7q9QPUfMvQMANGmSrXDJd+mZc+zCItSP0lDUCK0oSKtxcNtt f0YxRhqz6rRbXwxJdH75EyC81y4KausJ8UHuSS0o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, David Thompson , Bartosz Golaszewski Subject: [PATCH 7.3 482/742] gpio: mlxbf2: Disable interrupts around the chip lock in direction ops Date: Fri, 4 Dec 2026 19:05:46 +0900 Message-ID: <20261204100647.947720313@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Thompson commit f95bdff1d53471159e3c7112c5de4f6240772521 upstream. 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 Signed-off-by: Greg Kroah-Hartman --- drivers/gpio/gpio-mlxbf2.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) --- a/drivers/gpio/gpio-mlxbf2.c +++ b/drivers/gpio/gpio-mlxbf2.c @@ -128,12 +128,20 @@ exit: * 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); - gpio_generic_chip_lock(&gs->chip); + /* + * 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. + */ + gpio_generic_chip_lock_irqsave(&gs->chip, *flags); arm_gpio_lock_val = readl(yu_arm_gpio_lock_param.io); @@ -141,7 +149,7 @@ static int mlxbf2_gpio_lock_acquire(stru * When lock active bit[31] is set, ModeX is write enabled */ if (YU_LOCK_ACTIVE_BIT(arm_gpio_lock_val)) { - gpio_generic_chip_unlock(&gs->chip); + gpio_generic_chip_unlock_irqrestore(&gs->chip, *flags); mutex_unlock(yu_arm_gpio_lock_param.lock); return -EINVAL; } @@ -154,12 +162,13 @@ static int mlxbf2_gpio_lock_acquire(stru /* * 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->chip.lock) __releases(yu_arm_gpio_lock_param.lock) { writel(YU_ARM_GPIO_LOCK_RELEASE, yu_arm_gpio_lock_param.io); - gpio_generic_chip_unlock(&gs->chip); + gpio_generic_chip_unlock_irqrestore(&gs->chip, flags); mutex_unlock(yu_arm_gpio_lock_param.lock); } @@ -185,20 +194,21 @@ static int mlxbf2_gpio_direction_input(s 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; } @@ -212,6 +222,7 @@ static int mlxbf2_gpio_direction_output( int value) { struct mlxbf2_gpio_context *gs = gpiochip_get_data(chip); + unsigned long flags; int ret = 0; /* @@ -219,14 +230,14 @@ static int mlxbf2_gpio_direction_output( * 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; }