* [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
* Re: [PATCH for-11.2] target/arm: Handle "PMU disabled" in migration validate functions
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
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Peter Xu @ 2026-11-19 21:12 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-arm, qemu-devel
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH for-11.2] target/arm: Handle "PMU disabled" in migration validate functions
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-24 6:21 ` Karl Mehltretter
3 siblings, 1 reply; 8+ messages in thread
From: Peter Maydell @ 2026-11-23 12:57 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Peter Xu
On Thu, 19 Nov 2026 at 16:55, Peter Maydell <peter.maydell@linaro.org> 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
Just noticed that this should read "only if there is at least one
region".
> own vmstate struct), and it's unnecessary -- migrating something
> that's all zeroes and not used isn't a problem.
-- PMM
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH for-11.2] target/arm: Handle "PMU disabled" in migration validate functions
2026-11-23 12:57 ` Peter Maydell
@ 2026-11-23 13:15 ` Peter Maydell
0 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2026-11-23 13:15 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Peter Xu
On Mon, 23 Nov 2026 at 12:57, Peter Maydell <peter.maydell@linaro.org> wrote:
>
> On Thu, 19 Nov 2026 at 16:55, Peter Maydell <peter.maydell@linaro.org> 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
>
> Just noticed that this should read "only if there is at least one
> region".
Also this is
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4905
-- PMM
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH for-11.2] target/arm: Handle "PMU disabled" in migration validate functions
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:25 ` Jim MacArthur
2026-11-23 13:37 ` Peter Maydell
2026-11-24 6:21 ` Karl Mehltretter
3 siblings, 1 reply; 8+ messages in thread
From: Jim MacArthur @ 2026-11-23 13:25 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-arm, qemu-devel, Peter Xu
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>
> ---
> 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
>
>
The logic makes sense; it would be nice to have a comment in there explaining
that RNR==0 indicates an unused value rather than a genuine region numbered
0, but I'm OK with this being applied as is.
Reviewed-by: Jim MacArthur <jim.macarthur@linaro.org>
Jim
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH for-11.2] target/arm: Handle "PMU disabled" in migration validate functions
2026-11-23 13:25 ` Jim MacArthur
@ 2026-11-23 13:37 ` Peter Maydell
0 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2026-11-23 13:37 UTC (permalink / raw)
To: Jim MacArthur; +Cc: qemu-arm, qemu-devel, Peter Xu
On Mon, 23 Nov 2026 at 13:25, Jim MacArthur <jim.macarthur@linaro.org> wrote:
>
> 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>
> > ---
> > 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
> >
> >
>
> The logic makes sense; it would be nice to have a comment in there explaining
> that RNR==0 indicates an unused value rather than a genuine region numbered
> 0, but I'm OK with this being applied as is.
Yeah, that's reasonable. Something like:
/*
* field is migrated even when MPU not present: in that case number
* of regions is 0 and the field is RAZ/WI and also 0
*/
?
thanks
-- PMM
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH for-11.2] target/arm: Handle "PMU disabled" in migration validate functions
2026-11-19 16:55 [PATCH for-11.2] target/arm: Handle "PMU disabled" in migration validate functions Peter Maydell
` (2 preceding siblings ...)
2026-11-23 13:25 ` Jim MacArthur
@ 2026-11-24 6:21 ` Karl Mehltretter
2026-11-24 9:00 ` Peter Maydell
3 siblings, 1 reply; 8+ messages in thread
From: Karl Mehltretter @ 2026-11-24 6:21 UTC (permalink / raw)
To: Peter Maydell
Cc: Karl Mehltretter, qemu-arm, qemu-devel, Peter Xu, Jim MacArthur
On Thu, 19 Nov 2026 at 16:55, Peter Maydell <peter.maydell@linaro.org> wrote:
> @@ -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);
> }
the second clause checks rnr[M_REG_NS] == 0. Should this be M_REG_S too ?
Thanks,
Karl
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH for-11.2] target/arm: Handle "PMU disabled" in migration validate functions
2026-11-24 6:21 ` Karl Mehltretter
@ 2026-11-24 9:00 ` Peter Maydell
0 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2026-11-24 9:00 UTC (permalink / raw)
To: Karl Mehltretter; +Cc: qemu-arm, qemu-devel, Peter Xu, Jim MacArthur
On Tue, 24 Nov 2026 at 06:21, Karl Mehltretter <kmehltretter@gmail.com> wrote:
>
> On Thu, 19 Nov 2026 at 16:55, Peter Maydell <peter.maydell@linaro.org> wrote:
> > @@ -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);
> > }
>
> the second clause checks rnr[M_REG_NS] == 0. Should this be M_REG_S too ?
Yikes, thanks for catching that cut-and-paste error.
-- PMM
^ permalink raw reply [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.