From: Jim MacArthur <jim.macarthur@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Peter Xu <peterx@redhat.com>
Subject: Re: [PATCH for-11.2] target/arm: Handle "PMU disabled" in migration validate functions
Date: Mon, 23 Nov 2026 13:25:18 +0000 [thread overview]
Message-ID: <awQ-vnYjY8BEAdFi@linaro.org> (raw)
In-Reply-To: <20261119165546.3050013-1-peter.maydell@linaro.org>
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
next prev parent reply other threads:[~2026-11-23 13:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-11-23 13:37 ` Peter Maydell
2026-11-24 6:21 ` Karl Mehltretter
2026-11-24 9:00 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awQ-vnYjY8BEAdFi@linaro.org \
--to=jim.macarthur@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.