mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xiaolei Wang <wangxiaolei01@kaihong.com>
To: linusw@kernel.org, florian.fainelli@broadcom.com,
	bcm-kernel-feedback-list@broadcom.com, daniel@dragonzap.com,
	wangxiaolei01@kaihong.com, iivanov@suse.de,
	andrea.porta@suse.com, phil@raspberrypi.com
Cc: linux-gpio@vger.kernel.org, linux-rpi-kernel@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 1/2] pinctrl: rp1: use raw spinlock for gpio regmap
Date: Thu, 26 Nov 2026 03:54:19 +0000	[thread overview]
Message-ID: <20261126035420.1836760-2-wangxiaolei01@kaihong.com> (raw)
In-Reply-To: <20261126035420.1836760-1-wangxiaolei01@kaihong.com>

The rp1 gpio irq_chip callbacks run in atomic context: irq_set_type()
is called with the irq descriptor's raw spinlock held, and the driver
itself also disables preemption/interrupts while accessing the GPIO
registers.  On PREEMPT_RT, however, the gpio regmap is created with the
default spinlock_t, which becomes a sleepable rt_spin_lock.  Writing a
register field from that atomic context therefore attempts to sleep and
triggers a "sleeping function called from invalid context" BUG.

This is reachable from ordinary userspace: requesting a GPIO line with
an edge trigger through the GPIO cdev ioctl ends up in irq_set_type(),
so any application using edge-detected GPIO lines hits it on an RT
kernel.

  Call trace:
   __might_resched
   rt_spin_lock
   regmap_lock_spinlock
   regmap_field_update_bits_base
   rp1_gpio_irq_set_type
   __irq_set_trigger
   __setup_irq
   request_threaded_irq
   edge_detector_setup
   linereq_create
   gpio_ioctl

Make the gpio regmap use a raw spinlock so its lock matches the atomic
contexts the registers are accessed from.

Fixes: 4732f079cd19f ("pinctrl: rp1: Implement RaspberryPi RP1 gpio support")
Cc: stable@vger.kernel.org
Signed-off-by: Xiaolei Wang <wangxiaolei01@kaihong.com>
---
 drivers/pinctrl/pinctrl-rp1.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pinctrl/pinctrl-rp1.c b/drivers/pinctrl/pinctrl-rp1.c
index dd0e85c2ca33..99566a25ecb4 100644
--- a/drivers/pinctrl/pinctrl-rp1.c
+++ b/drivers/pinctrl/pinctrl-rp1.c
@@ -1693,6 +1693,7 @@ static const struct regmap_config rp1_pinctrl_gpio_regmap_cfg = {
 	.rd_table = &rp1_gpio_reg_table,
 	.name = "rp1-gpio",
 	.max_register = 0xb11c,
+	.use_raw_spinlock = true,
 };
 
 static const struct regmap_config rp1_pinctrl_rio_regmap_cfg = {
-- 
2.34.1


  reply	other threads:[~2026-11-26  3:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  3:54 [PATCH 0/2] pinctrl: rp1: fix RT sleep and clean up map freeing Xiaolei Wang
2026-11-26  3:54 ` Xiaolei Wang [this message]
2026-11-26  3:54 ` [PATCH 2/2] pinctrl: rp1: use pinctrl_utils_free_map() for map cleanup Xiaolei Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126035420.1836760-2-wangxiaolei01@kaihong.com \
    --to=wangxiaolei01@kaihong.com \
    --cc=andrea.porta@suse.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=daniel@dragonzap.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=iivanov@suse.de \
    --cc=linusw@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=phil@raspberrypi.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®