Skip to contentSkip to conversation

ARM: stm32: Fix secure_waitbits() mask check

PATCH In review Marek Vasut 2 participants 4 messages Jul 8, 2024 – Sep 25, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: stm32: Fix secure_waitbits() mask check

Do not apply bitwise AND to register value and expected value, only apply bitwise AND to register value and mask, and only then compare the result with expected value that the function polls for.

Fixes b49105320a5b ("stm32mp: psci: Implement PSCI system suspend and DRAM SSR")

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 arch/arm/mach-stm32mp/stm32mp1/psci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm/mach-stm32mp/stm32mp1/psci.c +1 -2
index e99103910d9..ffdafea464d 100644
@@ -393,8 +393,7 @@ static int __secure secure_waitbits(u32 reg, u32 mask, u32 val)
 	asm volatile("mrrc p15, 0, %Q0, %R0, c14" : "=r" (start));
 	for (;;) {
 		tmp = readl(reg);
-		tmp &= mask;
-		if ((tmp & val) == val)
+		if ((tmp & mask) == val)
 			return 0;
 		asm volatile("mrrc p15, 0, %Q0, %R0, c14" : "=r" (end));
 		if ((end - start) > delay)
Signature · 1 line
2.43.0
#1 lore raw
Quoted 21 lines · Marek Vasut

Do not apply bitwise AND to register value and expected value, only apply bitwise AND to register value and mask, and only then compare the result with expected value that the function polls for.

Fixes b49105320a5b ("stm32mp: psci: Implement PSCI system suspend and DRAM SSR")

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
  arch/arm/mach-stm32mp/stm32mp1/psci.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm/mach-stm32mp/stm32mp1/psci.c +0 -0
index e99103910d9..ffdafea464d 100644

arch/arm/mach-stm32mp/stm32mp1/psci.c static int __secure secure_waitbits(u32 reg, u32 mask, u32 val) · line 399

Quoted 9 lines
arch/arm/mach-stm32mp/stm32mp1/psci.c +1 -2
@@ -393,8 +393,7 @@ static int __secure secure_waitbits(u32 reg, u32 mask, u32 val)
  	asm volatile("mrrc p15, 0, %Q0, %R0, c14" : "=r" (start));
  	for (;;) {
  		tmp = readl(reg);
-		tmp &= mask;
-		if ((tmp & val) == val)
+		if ((tmp & mask) == val)
  			return 0;
  		asm volatile("mrrc p15, 0, %Q0, %R0, c14" : "=r" (end));
  		if ((end - start) > delay)

I hope this bugfix will make it into 2024.10 , can you prepare a bugfix PR for 2024.10 ?

Reviewed-by on v1 1/1
#2 lore raw
In reply to Marek Vasut

Hi Marek,

Quoted 21 lines · Marek Vasut

Do not apply bitwise AND to register value and expected value, only apply bitwise AND to register value and mask, and only then compare the result with expected value that the function polls for.

Fixes b49105320a5b ("stm32mp: psci: Implement PSCI system suspend and DRAM SSR")

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
  arch/arm/mach-stm32mp/stm32mp1/psci.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm/mach-stm32mp/stm32mp1/psci.c +0 -0
index e99103910d9..ffdafea464d 100644

arch/arm/mach-stm32mp/stm32mp1/psci.c static int __secure secure_waitbits(u32 reg, u32 mask, u32 val) · line 399

Quoted 9 lines
arch/arm/mach-stm32mp/stm32mp1/psci.c +1 -2
@@ -393,8 +393,7 @@ static int __secure secure_waitbits(u32 reg, u32 mask, u32 val)
  	asm volatile("mrrc p15, 0, %Q0, %R0, c14" : "=r" (start));
  	for (;;) {
  		tmp = readl(reg);
-		tmp &= mask;
-		if ((tmp & val) == val)
+		if ((tmp & mask) == val)
  			return 0;
  		asm volatile("mrrc p15, 0, %Q0, %R0, c14" : "=r" (end));
  		if ((end - start) > delay)

Thanks
Patrick

#3 lore raw
Quoted 39 lines · Patrick DELAUNAY

Hi Marek,

Quoted 30 lines · Marek Vasut

Do not apply bitwise AND to register value and expected value, only apply bitwise AND to register value and mask, and only then compare the result with expected value that the function polls for.

Fixes b49105320a5b ("stm32mp: psci: Implement PSCI system suspend and DRAM SSR")

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
  arch/arm/mach-stm32mp/stm32mp1/psci.c | 3 +--

  1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm/mach-stm32mp/stm32mp1/psci.c +1 -2
index e99103910d9..ffdafea464d 100644
@@ -393,8 +393,7 @@ static int __secure secure_waitbits(u32 reg, u32 
 mask, u32 val)
       asm volatile("mrrc p15, 0, %Q0, %R0, c14" : "=r" (start));
       for (;;) {
           tmp = readl(reg);
-        tmp &= mask;
-        if ((tmp & val) == val)
+        if ((tmp & mask) == val)
               return 0;
           asm volatile("mrrc p15, 0, %Q0, %R0, c14" : "=r" (end));
Quoted 1 line

          if ((end - start) > delay)

Quoted 3 lines

Thanks
Patrick

Applied to u-boot-stm/master, thanks!

Regards
Patrick