[PATCH] pmdomain: renesas: rcar-sysc: publish the external request mask

Jaidev Shastri via B4 Relay posted 1 patch 2 days, 15 hours ago
drivers/pmdomain/renesas/rcar-sysc.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
[PATCH] pmdomain: renesas: rcar-sysc: publish the external request mask
Posted by Jaidev Shastri via B4 Relay 2 days, 15 hours ago
From: Jaidev Shastri <jaidevshastri@vt.edu>

rcar_sysc_pd_init() maps the SYSC registers and stores rcar_sysc_base,
rcar_sysc_extmask_offs and rcar_sysc_extmask_val with plain stores,
before it registers the power domains. rcar_sysc_power() tests
rcar_sysc_extmask_val and then writes through rcar_sysc_base at that
offset, from genpd on any CPU.

Publish the mask value last with smp_store_release() and read it once
with smp_load_acquire() in rcar_sysc_power().

Found with MBCheck, a static herd7-based memory consistency checker.

Signed-off-by: Jaidev Shastri <jaidevshastri@vt.edu>
---
 drivers/pmdomain/renesas/rcar-sysc.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/pmdomain/renesas/rcar-sysc.c b/drivers/pmdomain/renesas/rcar-sysc.c
index bd7bb9cbd..d0eaaeeb9 100644
--- a/drivers/pmdomain/renesas/rcar-sysc.c
+++ b/drivers/pmdomain/renesas/rcar-sysc.c
@@ -106,15 +106,19 @@ static int rcar_sysc_power(const struct rcar_sysc_pd *pd, bool on)
 	unsigned int chan_mask = BIT(pd->chan_bit);
 	unsigned int status, k;
 	unsigned long flags;
+	u32 extmask_val;
 	int ret;
 
 	spin_lock_irqsave(&rcar_sysc_lock, flags);
 
+	/* Pairs with the smp_store_release() in rcar_sysc_pd_init(). */
+	extmask_val = smp_load_acquire(&rcar_sysc_extmask_val);
+
 	/*
 	 * Mask external power requests for CPU or 3DG domains
 	 */
-	if (rcar_sysc_extmask_val) {
-		iowrite32(rcar_sysc_extmask_val,
+	if (extmask_val) {
+		iowrite32(extmask_val,
 			  rcar_sysc_base + rcar_sysc_extmask_offs);
 	}
 
@@ -157,7 +161,7 @@ static int rcar_sysc_power(const struct rcar_sysc_pd *pd, bool on)
 	iowrite32(isr_mask, rcar_sysc_base + SYSCISCR);
 
  out:
-	if (rcar_sysc_extmask_val)
+	if (extmask_val)
 		iowrite32(0, rcar_sysc_base + rcar_sysc_extmask_offs);
 
 	spin_unlock_irqrestore(&rcar_sysc_lock, flags);
@@ -381,7 +385,12 @@ static int __init rcar_sysc_pd_init(void)
 
 	/* Optional External Request Mask Register */
 	rcar_sysc_extmask_offs = info->extmask_offs;
-	rcar_sysc_extmask_val = info->extmask_val;
+	/*
+	 * rcar_sysc_power() tests rcar_sysc_extmask_val and then uses
+	 * rcar_sysc_base and the offset, so publish the value last, with
+	 * release semantics.
+	 */
+	smp_store_release(&rcar_sysc_extmask_val, info->extmask_val);
 
 	domains = kzalloc_obj(*domains);
 	if (!domains) {

---
base-commit: 93f51579e7df248780214094418f205253383cc5
change-id: 20260921-mb-rcar-sysc-6e76b8d94835

Best regards,
--  
Jaidev Shastri <jaidevshastri@vt.edu>
Re: [PATCH] pmdomain: renesas: rcar-sysc: publish the external request mask
Posted by Geert Uytterhoeven 2 days, 7 hours ago
Hi Jaidev,

On Tue, 22 Sept 2026 at 03:18, Jaidev Shastri via B4 Relay
<devnull+jaidevshastri.vt.edu@kernel.org> wrote:
> From: Jaidev Shastri <jaidevshastri@vt.edu>
>
> rcar_sysc_pd_init() maps the SYSC registers and stores rcar_sysc_base,
> rcar_sysc_extmask_offs and rcar_sysc_extmask_val with plain stores,
> before it registers the power domains. rcar_sysc_power() tests
> rcar_sysc_extmask_val and then writes through rcar_sysc_base at that
> offset, from genpd on any CPU.
>
> Publish the mask value last with smp_store_release() and read it once
> with smp_load_acquire() in rcar_sysc_power().
>
> Found with MBCheck, a static herd7-based memory consistency checker.
>
> Signed-off-by: Jaidev Shastri <jaidevshastri@vt.edu>

Thanks for your patch!

Have you tested it?

> --- a/drivers/pmdomain/renesas/rcar-sysc.c
> +++ b/drivers/pmdomain/renesas/rcar-sysc.c
> @@ -106,15 +106,19 @@ static int rcar_sysc_power(const struct rcar_sysc_pd *pd, bool on)
>         unsigned int chan_mask = BIT(pd->chan_bit);
>         unsigned int status, k;
>         unsigned long flags;
> +       u32 extmask_val;
>         int ret;
>
>         spin_lock_irqsave(&rcar_sysc_lock, flags);

Isn't the spin_lock acquisition a sufficient barrier?

>
> +       /* Pairs with the smp_store_release() in rcar_sysc_pd_init(). */
> +       extmask_val = smp_load_acquire(&rcar_sysc_extmask_val);
> +
>         /*
>          * Mask external power requests for CPU or 3DG domains
>          */
> -       if (rcar_sysc_extmask_val) {
> -               iowrite32(rcar_sysc_extmask_val,
> +       if (extmask_val) {
> +               iowrite32(extmask_val,
>                           rcar_sysc_base + rcar_sysc_extmask_offs);
>         }
>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds