All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabiano Rosas <farosas@suse.de>
To: Peter Xu <peterx@redhat.com>, qemu-devel@nongnu.org
Cc: Juraj Marcin <jmarcin@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	peterx@redhat.com, Gavin Shan <gshan@redhat.com>,
	qemu-arm@nongnu.org
Subject: Re: [PATCH for-12.0 v2 8/9] arm/machine: Move all VMSTATE_VALIDATE() usages into post_load
Date: Fri, 27 Nov 2026 10:41:57 -0300	[thread overview]
Message-ID: <87pkvqqtlm.fsf@suse.de> (raw)
In-Reply-To: <20261126231631.3392756-9-peterx@redhat.com>

Peter Xu <peterx@redhat.com> writes:

> To pave way removing VMSTATE_VALIDATE(), move all four such uses into a
> post_load hook instead.
>
> Cc: Peter Maydell <peter.maydell@linaro.org>
> Cc: qemu-arm@nongnu.org
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  target/arm/machine.c | 90 ++++++++++++++++++--------------------------
>  1 file changed, 37 insertions(+), 53 deletions(-)
>
> diff --git a/target/arm/machine.c b/target/arm/machine.c
> index e86fa85a9b..b401593496 100644
> --- a/target/arm/machine.c
> +++ b/target/arm/machine.c
> @@ -407,14 +407,6 @@ static const VMStateDescription vmstate_m_faultmask_primask = {
>   * just non-secure, we transfer both banks here rather than putting
>   * the secure banked version in the m-security subsection.
>   */
> -static bool csselr_vmstate_validate(void *opaque, int version_id)
> -{
> -    ARMCPU *cpu = opaque;
> -
> -    return cpu->env.v7m.csselr[M_REG_NS] <= R_V7M_CSSELR_INDEX_MASK
> -        && cpu->env.v7m.csselr[M_REG_S] <= R_V7M_CSSELR_INDEX_MASK;
> -}
> -
>  static bool m_csselr_needed(void *opaque)
>  {
>      ARMCPU *cpu = opaque;
> @@ -429,7 +421,6 @@ static const VMStateDescription vmstate_m_csselr = {
>      .needed = m_csselr_needed,
>      .fields = (const VMStateField[]) {
>          VMSTATE_UINT32_ARRAY(env.v7m.csselr, ARMCPU, M_REG_NUM_BANKS),
> -        VMSTATE_VALIDATE("CSSELR is valid", csselr_vmstate_validate),
>          VMSTATE_END_OF_LIST()
>      }
>  };
> @@ -590,18 +581,6 @@ static bool pmsav7_needed(void *opaque)
>             !arm_feature(env, ARM_FEATURE_V8);
>  }
>  
> -static bool pmsav7_rgnr_vmstate_validate(void *opaque, int version_id)
> -{
> -    ARMCPU *cpu = opaque;
> -
> -    /*
> -     * Check MPU_RNR in-bounds. If no MPU, we still migrate this field
> -     * but number of regions == 0 and MPU_RNR is RAZ/WI so also 0
> -     */
> -    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 = {
>      .name = "cpu/pmsav7",
>      .version_id = 1,
> @@ -614,7 +593,6 @@ static const VMStateDescription vmstate_pmsav7 = {
>                                vmstate_info_uint32, uint32_t),
>          VMSTATE_VARRAY_UINT32(env.pmsav7.dracr, ARMCPU, pmsav7_dregion, 0,
>                                vmstate_info_uint32, uint32_t),
> -        VMSTATE_VALIDATE("rgnr is valid", pmsav7_rgnr_vmstate_validate),
>          VMSTATE_END_OF_LIST()
>      }
>  };
> @@ -695,31 +673,6 @@ static const VMStateDescription vmstate_pmsav8 = {
>      }
>  };
>  
> -static bool s_rnr_vmstate_validate(void *opaque, int version_id)
> -{
> -    ARMCPU *cpu = opaque;
> -
> -    /*
> -     * Check MPU_RNR in-bounds. If no MPU, we still migrate this field
> -     * but number of regions == 0 and MPU_RNR is RAZ/WI so also 0
> -     */
> -    return cpu->env.pmsav7.rnr[M_REG_S] < cpu->pmsav7_dregion ||
> -        (cpu->pmsav7_dregion == 0 && cpu->env.pmsav7.rnr[M_REG_S] == 0);
> -}
> -
> -static bool sau_rnr_vmstate_validate(void *opaque, int version_id)
> -{
> -    ARMCPU *cpu = opaque;
> -
> -    /*
> -     * Check SAU_RNR in-bounds. If no SAU regions are implemented,
> -     * we still migrate this field, but number of regions == 0 and
> -     * SAU_RNR is RAZ/WI so also 0
> -     */
> -    return cpu->env.sau.rnr < cpu->sau_sregion ||
> -        (cpu->sau_sregion == 0 && cpu->env.sau.rnr == 0);
> -}
> -
>  static bool m_security_needed(void *opaque)
>  {
>      ARMCPU *cpu = opaque;
> @@ -749,7 +702,6 @@ static const VMStateDescription vmstate_m_security = {
>          VMSTATE_VARRAY_UINT32(env.pmsav8.rlar[M_REG_S], ARMCPU, pmsav7_dregion,
>                                0, vmstate_info_uint32, uint32_t),
>          VMSTATE_UINT32(env.pmsav7.rnr[M_REG_S], ARMCPU),
> -        VMSTATE_VALIDATE("secure MPU_RNR is valid", s_rnr_vmstate_validate),
>          VMSTATE_UINT32(env.v7m.mpu_ctrl[M_REG_S], ARMCPU),
>          VMSTATE_UINT32(env.v7m.ccr[M_REG_S], ARMCPU),
>          VMSTATE_UINT32(env.v7m.mmfar[M_REG_S], ARMCPU),
> @@ -761,7 +713,6 @@ static const VMStateDescription vmstate_m_security = {
>          VMSTATE_VARRAY_UINT32(env.sau.rlar, ARMCPU, sau_sregion, 0,
>                                vmstate_info_uint32, uint32_t),
>          VMSTATE_UINT32(env.sau.rnr, ARMCPU),
> -        VMSTATE_VALIDATE("SAU_RNR is valid", sau_rnr_vmstate_validate),
>          VMSTATE_UINT32(env.sau.ctrl, ARMCPU),
>          VMSTATE_UINT32(env.v7m.scr[M_REG_S], ARMCPU),
>          /* AIRCR is not secure-only, but our implementation is R/O if the
> @@ -1177,11 +1128,48 @@ static bool cpu_post_load(void *opaque, int version_id, Error **errp)
>      ARMCPU *cpu = opaque;
>      CPUARMState *env = &cpu->env;
>      bool ignore_s_regs;
> +    bool valid;
>      int i, v;
>  
>      trace_cpu_post_load(cpu->cpreg_vmstate_array_len,
>                          cpu->cpreg_array_len);
>  
> +    if (env->v7m.csselr[M_REG_NS] > R_V7M_CSSELR_INDEX_MASK ||
> +        env->v7m.csselr[M_REG_S] > R_V7M_CSSELR_INDEX_MASK) {
> +        error_setg(errp, "CSSELR is invalid");
> +        return false;
> +    }
> +
> +    /*
> +     * Check MPU_RNR in-bounds. If no MPU, we still migrate these fields
> +     * but number of regions == 0 and MPU_RNR is RAZ/WI so also 0
> +     */
> +    valid = env->pmsav7.rnr[M_REG_NS] < cpu->pmsav7_dregion ||
> +        (cpu->pmsav7_dregion == 0 && env->pmsav7.rnr[M_REG_NS] == 0);
> +    if (!valid) {
> +        error_setg(errp, "rgnr is invalid");
> +        return false;
> +    }
> +
> +    valid = env->pmsav7.rnr[M_REG_S] < cpu->pmsav7_dregion ||
> +        (cpu->pmsav7_dregion == 0 && env->pmsav7.rnr[M_REG_S] == 0);
> +    if (!valid) {
> +        error_setg(errp, "secure MPU_RNR is invalid");
> +        return false;
> +    }
> +
> +    /*
> +     * Check SAU_RNR in-bounds. If no SAU regions are implemented,
> +     * we still migrate this field, but number of regions == 0 and
> +     * SAU_RNR is RAZ/WI so also 0
> +     */
> +    valid = env->sau.rnr < cpu->sau_sregion ||
> +        (cpu->sau_sregion == 0 && env->sau.rnr == 0);
> +    if (!valid) {
> +        error_setg(errp, "SAU_RNR is invalid");
> +        return false;
> +    }

Shouldn't you guard these blocks with the result of what .needed would
have returned on the source? Otherwise we may not migrate a value but
still try to validate it here? I haven't checked if the unmigrated field
may end up with a value that will cause these checks to pass.

> +
>      /*
>       * Handle migration compatibility from old QEMU which didn't
>       * send the irq-line-state subsection. A QEMU without it did not
> @@ -1426,10 +1414,6 @@ const VMStateDescription vmstate_arm_cpu = {
>          &vmstate_vfp,
>          &vmstate_m,
>          &vmstate_thumb2ee,
> -        /* pmsav7_rnr must come before pmsav7 so that we have the
> -         * region number before we test it in the VMSTATE_VALIDATE
> -         * in vmstate_pmsav7.
> -         */
>          &vmstate_pmsav7_rnr,
>          &vmstate_pmsav7,
>          &vmstate_pmsav8,


  reply	other threads:[~2026-11-27 13:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 23:16 [PATCH for-12.0 v2 0/9] migration: Remove VMSTATE_VALIDATE() and VMS_MUST_EXIST Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 1/9] rust/migration: Allow usize as the length of a varray Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 2/9] rust/hpet: Move vmstate_validate!() check into post_load Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 3/9] rust/migration: Remove vmstate_validate!() macro and test Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 4/9] pcie/aer: Remove the usage of VMSTATE_VALIDATE() Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 5/9] hw/gpio/zaurus: Move VMSTATE_VALIDATE() check into post_load_errp() Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 6/9] hpet: Move VMSTATE_VALIDATE() check into post_load Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 7/9] arm/machine: Convert cpu_post_load() to take Error** Peter Xu
2026-11-27 13:22   ` Fabiano Rosas
2026-11-27 14:23     ` Peter Xu
2026-11-27 14:44       ` Peter Maydell
2026-11-27 17:00         ` Eric Auger
2026-11-26 23:16 ` [PATCH for-12.0 v2 8/9] arm/machine: Move all VMSTATE_VALIDATE() usages into post_load Peter Xu
2026-11-27 13:41   ` Fabiano Rosas [this message]
2026-11-27 13:50     ` Peter Maydell
2026-11-27 14:29     ` Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 9/9] migration: Drop VMSTATE_VALIDATE() and VMS_MUST_EXIST Peter Xu
2026-11-27 14:16   ` Fabiano Rosas

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=87pkvqqtlm.fsf@suse.de \
    --to=farosas@suse.de \
    --cc=gshan@redhat.com \
    --cc=jmarcin@redhat.com \
    --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.