From: Marc Zyngier <maz@kernel.org>
To: Marek Vasut <marex@denx.de>
Cc: linux-gpio@vger.kernel.org,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
Linus Walleij <linus.walleij@linaro.org>,
Loic Poulain <loic.poulain@linaro.org>,
NXP Linux Team <linux-imx@nxp.com>, Peng Fan <peng.fan@nxp.com>,
Shawn Guo <shawnguo@kernel.org>
Subject: Re: [PATCH v3 1/2] gpio: mxc: Protect GPIO irqchip RMW with bgpio spinlock
Date: Sun, 24 Jul 2022 18:50:46 +0100 [thread overview]
Message-ID: <87fsiqxuvd.wl-maz@kernel.org> (raw)
In-Reply-To: <20220724171057.18549-1-marex@denx.de>
Where is the cover letter? If sending more than a single patch, please
include one.
On Sun, 24 Jul 2022 18:10:56 +0100,
Marek Vasut <marex@denx.de> wrote:
>
> The driver currently performs register read-modify-write without locking
> in its irqchip part, this could lead to a race condition when configuring
> interrupt mode setting. Add the missing bgpio spinlock lock/unlock around
> the register read-modify-write.
>
> Fixes: 07bd1a6cc7cbb ("MXC arch: Add gpio support for the whole platform")
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Loic Poulain <loic.poulain@linaro.org>
> Cc: Marc Zyngier <maz@kernel.org>
> Cc: NXP Linux Team <linux-imx@nxp.com>
> Cc: Peng Fan <peng.fan@nxp.com>
> Cc: Shawn Guo <shawnguo@kernel.org>
> ---
> V3: New patch
> ---
> drivers/gpio/gpio-mxc.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
> index c871602fc5ba9..74a50139c9202 100644
> --- a/drivers/gpio/gpio-mxc.c
> +++ b/drivers/gpio/gpio-mxc.c
> @@ -147,6 +147,7 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type)
> {
> struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
> struct mxc_gpio_port *port = gc->private;
> + unsigned long flags;
> u32 bit, val;
> u32 gpio_idx = d->hwirq;
> int edge;
> @@ -185,6 +186,8 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type)
> return -EINVAL;
> }
>
> + spin_lock_irqsave(&port->gc.bgpio_lock, flags);
In my tree, bgpio is a raw spinlock, and has been since 3c938cc5cebcb.
Now, looking a bit closer at this code, I have to withdraw my earlier
comment about the lack of mutual exclusion in the existing code. All
writes are of the form:
writel(single_bit_mask, some_addr + MXS_{SET,CLR});
which indicates that the write side can be accessed with a hot-bit
pattern, avoiding a RWM pattern and thus the need for a lock.
Your second patch, however requires the lock. I'm not sure it is safe
to do after the interrupt type has been configured though. You may
want to refer to the TRM for this.
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2022-07-24 17:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-24 17:10 [PATCH v3 1/2] gpio: mxc: Protect GPIO irqchip RMW with bgpio spinlock Marek Vasut
2022-07-24 17:10 ` [PATCH v3 2/2] gpio: mxc: Always set GPIOs used as interrupt source to INPUT mode Marek Vasut
2022-07-25 20:36 ` Andy Shevchenko
2022-07-25 21:26 ` Marek Vasut
2022-07-26 8:22 ` Linus Walleij
2022-07-24 17:50 ` Marc Zyngier [this message]
2022-07-24 18:15 ` [PATCH v3 1/2] gpio: mxc: Protect GPIO irqchip RMW with bgpio spinlock Marek Vasut
2022-07-25 6:53 ` Marc Zyngier
2022-07-25 9:57 ` Marek Vasut
2022-07-25 10:06 ` Marc Zyngier
2022-07-24 18:32 ` kernel test robot
2022-07-24 18:42 ` kernel test robot
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=87fsiqxuvd.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=bgolaszewski@baylibre.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-imx@nxp.com \
--cc=loic.poulain@linaro.org \
--cc=marex@denx.de \
--cc=peng.fan@nxp.com \
--cc=shawnguo@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;
as well as URLs for NNTP newsgroup(s).