On Tue, Nov 25 2025, Eric Auger <[email protected]> wrote:

> Newer kernels may revoke exposure of KVM regs to userspace. This can
> happen when one notices that some registers were unconditionnally
> exposed whether they shall be conditionnally exposed for example.
>
> An example of such situation is: TCR2_EL1, PIRE0_EL1,  PIR_EL1.
> Associated kernel commits were:
> 0fcb4eea5345  KVM: arm64: Hide TCR2_EL1 from userspace when disabled for 
> guests
> a68cddbe47ef  KVM: arm64: Hide S1PIE registers from userspace when disabled 
> for guests
>
> Those commits were actual fixes but the cons is that is breaks forward
> migration on some HW. Indeed when migrating from an old kernel that
> does not feature those commits to a more recent one, destination
> qemu detects there are more KVM regs in the input migration stream than
> exposed by the destination host and the migration fails with:
> "failed to load cpu:cpreg_vmstate_array_len"
>
> This patchs adds the capability to define an array of register indexes
> that may exist in the migration incoming stream but may be not
> exposed by KVM on the destination.
>
> We provision for extra space in cpreg_vmstate_* arrays during the preload
> phase to allow the state to be saved without overflow, in case the
> registers only are in the inbound data.
>
> On postload we make sure to ignore them when analyzing potential
> mismatch between registers. The actual cpreg array is never altered
> meaning those registers are never accessed nor saved.
>
> The array will be populated with a dedicated array property.
>
> Signed-off-by: Eric Auger <[email protected]>
>
> ---
>
> v2 -> v3:
> - add a missing_as_expected trace point
>
> v1 -> v2:
> - get rid of the enforced/fake terminology
> - remove the useless array of fake regs. Only the number of missing
>   regs is needed
>
> RFC -> v1:
> - improve comment in target/arm/cpu.h (Connie)
> ---
>  target/arm/cpu.h        | 22 ++++++++++++++++++++++
>  target/arm/machine.c    | 30 +++++++++++++++++++++---------
>  target/arm/trace-events |  1 +
>  3 files changed, 44 insertions(+), 9 deletions(-)

Reviewed-by: Cornelia Huck <[email protected]>


Reply via email to