target/arm/machine.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
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
On Thu, Nov 19, 2026 at 04:55:46PM +0000, Peter Maydell wrote:
> 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>
Not that I know at all what is happening.. but just that I think we should
fix a source crash during migration before we stop asserting at all,
Acked-by: Peter Xu <peterx@redhat.com>
--
Peter Xu
© 2016 - 2026 Red Hat, Inc.