All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for-11.2] target/arm: Handle "PMU disabled" in migration validate functions
@ 2026-11-19 16:55 Peter Maydell
  2026-11-19 21:12 ` Peter Xu
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Peter Maydell @ 2026-11-19 16:55 UTC (permalink / raw)
  To: qemu-arm, qemu-devel; +Cc: Peter Xu

In various test functions for VMSTATE_VALIDATE() fields, we check
whether the migrated region number register is within bounds (i.e.
less than the total number of configured regions).  These tests fail
spuriously if there are zero configured regions, because then "x <
cpu->pmsav7_dregion" is always false.

When we allowed v6M CPUs to have PMSAv7 in commit 157f6c69edd06, this
exposed a bug, because we now have a CPU which has PMSAv7 according
to the pmsav7_needed() function but which is configured with 0 PMSA
regions: the Cortex-M0.

We could fix this by having pmsav7_needed() return false if there
are 0 regions; however, the cpu/m-security vmstate struct does
migration of the secure equivalents of these fields, and we also do
a VMSTATE_VALIDATE that checks against the number of MPU regions
there. Making those fields be migrated only if there is more than
one region would be awkward (we'd need to pull them out into their
own vmstate struct), and it's unnecessary -- migrating something
that's all zeroes and not used isn't a problem.

So instead we relax the checks to handle the "no configured regions"
case, insisting then that the rnr field in the CPU state (which
should never be used) is zero.

Similarly, we adjust the check in sau_rnr_vmstate_validate against
sau_sregion; this one is currently theoretical as all our CPUs which
implement the Security Extension have at least one SAU region, but
architecturally it is permitted to implemnt no SAU regions.

Fixes: 157f6c69edd06 ("target/arm: extend PMSAv7 support to v6-M CPUs")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/arm/machine.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/target/arm/machine.c b/target/arm/machine.c
index c3aef3f3301..d624425c0dd 100644
--- a/target/arm/machine.c
+++ b/target/arm/machine.c
@@ -593,7 +593,8 @@ static bool pmsav7_rgnr_vmstate_validate(void *opaque, int version_id)
 {
     ARMCPU *cpu = opaque;
 
-    return cpu->env.pmsav7.rnr[M_REG_NS] < cpu->pmsav7_dregion;
+    return cpu->env.pmsav7.rnr[M_REG_NS] < cpu->pmsav7_dregion ||
+        (cpu->pmsav7_dregion == 0 && cpu->env.pmsav7.rnr[M_REG_NS] == 0);
 }
 
 static const VMStateDescription vmstate_pmsav7 = {
@@ -693,14 +694,16 @@ static bool s_rnr_vmstate_validate(void *opaque, int version_id)
 {
     ARMCPU *cpu = opaque;
 
-    return cpu->env.pmsav7.rnr[M_REG_S] < cpu->pmsav7_dregion;
+    return cpu->env.pmsav7.rnr[M_REG_S] < cpu->pmsav7_dregion ||
+        (cpu->pmsav7_dregion == 0 && cpu->env.pmsav7.rnr[M_REG_NS] == 0);
 }
 
 static bool sau_rnr_vmstate_validate(void *opaque, int version_id)
 {
     ARMCPU *cpu = opaque;
 
-    return cpu->env.sau.rnr < cpu->sau_sregion;
+    return cpu->env.sau.rnr < cpu->sau_sregion ||
+        (cpu->sau_sregion == 0 && cpu->env.sau.rnr == 0);
 }
 
 static bool m_security_needed(void *opaque)
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-24  9:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 16:55 [PATCH for-11.2] target/arm: Handle "PMU disabled" in migration validate functions Peter Maydell
2026-11-19 21:12 ` Peter Xu
2026-11-23 12:57 ` Peter Maydell
2026-11-23 13:15   ` Peter Maydell
2026-11-23 13:25 ` Jim MacArthur
2026-11-23 13:37   ` Peter Maydell
2026-11-24  6:21 ` Karl Mehltretter
2026-11-24  9:00   ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.