Re: [PATCH 06/12] pinctrl: imx: Serialise MMIO register updates with a spinlock
From: Lee Jones
Date: Wed Dec 02 2026 - 15:09:01 EST
> On Wed, Dec 02, 2026 at 09:30:00AM +0000, Lee Jones wrote:
> > The pinctrl core does not serialise .set_mux() and .pin_config_set()
> > callbacks against one another or against concurrent .set_mux() calls.
> > On i.MX platforms that share mux and configuration registers via
> > SHARE_MUX_CONF_REG or share general-purpose select-input registers,
> > concurrent read-modify-write sequences in imx_pmx_set_one_pin_mmio(),
> > imx_pinconf_set_mmio(), and the GPIO direction callbacks can race and
> > overwrite each other's updates.
> >
> > Add a raw_spinlock_t to struct imx_pinctrl and hold it across MMIO
>
> why choose raw_spinlock_t instead of spinlock_t?
Thanks for the interest and the question, Frank.
A regular 'spinlock_t' becomes a sleeping rt_mutex under PREEMPT_RT.
Whilst standard pinctrl state transitions like pinctrl_select_state()
occur in process context, the '.gpio_set_direction' callback is also
wired into the pinctrl ops and shares this lock.
Moreover, pinctrl state switches can be invoked from low-level PM and
idle paths where sleeping is not allowed and 'raw_spinlock_t' is the
standard choice across pinctrl drivers for short MMIO register
read-modify-write.
If someone can confirm that none of the i.MX call paths can ever be
reached from atomic or non-sleepable contexts (even under PREEMPT_RT),
we could downgrade this to 'spinlock_t', otherwise 'raw_spinlock_t' is
the safer option for a few-instruction MMIO critical section.
--
Lee Jones