Keep KVM kernel register-list migration policy with the other KVM cpreg helpers.
- Move kvm_arm_set_cpreg_mig_tolerances from cpu64.c to kvm.c - Declare it in kvm_arm.h - Add a kvm-stub.c assert stub Signed-off-by: Yonggang Luo <[email protected]> --- target/arm/cpu64.c | 38 -------------------------------------- target/arm/kvm-stub.c | 5 +++++ target/arm/kvm.c | 36 ++++++++++++++++++++++++++++++++++++ target/arm/kvm_arm.h | 9 +++++++++ 4 files changed, 50 insertions(+), 38 deletions(-) diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 4e8c4725308..1e64eb54cdc 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -754,44 +754,6 @@ static void aarch64_a53_initfn(Object *obj) define_cortex_a72_a57_a53_cp_reginfo(cpu); } -#if defined(CONFIG_KVM) -static void kvm_arm_set_cpreg_mig_tolerances(ARMCPU *cpu) -{ - /* - * Registers that may be in the incoming stream and not exposed - * on the destination - */ - - /* - * TCR_EL1 was erroneously unconditionnally exposed before linux v6.13. - * See commit 0fcb4eea5345 ("KVM: arm64: Hide TCR2_EL1 from userspace - * when disabled for guests") - */ - arm_register_cpreg_mig_tolerance(cpu, ARM64_SYS_REG(3, 0, 2, 0, 3), - 0, 0, ToleranceNotOnBothEnds); - /* - * PIRE0_EL1 and PIR_EL1 were erroneously unconditionnally exposed - * before linux v6.13. See commit a68cddbe47ef ("KVM: arm64: Hide - * S1PIE registers from userspace when disabled for guests") - */ - arm_register_cpreg_mig_tolerance(cpu, ARM64_SYS_REG(3, 0, 10, 2, 2), - 0, 0, ToleranceNotOnBothEnds); - arm_register_cpreg_mig_tolerance(cpu, ARM64_SYS_REG(3, 0, 10, 2, 3), - 0, 0, ToleranceNotOnBothEnds); - - /* - * KVM_REG_ARM_VENDOR_HYP_BMAP_2 pseudo FW register is exposed - * from v6.15 onwards. Backward migration from a >= v6.15 to an older - * kernel would fail without cpreg migration tolerance definition. - * If the register is present on source but not on destination, make - * sure it has its reset value, ie. 0, meaning no service is exposed - * to the guest. - */ - arm_register_cpreg_mig_tolerance(cpu, KVM_REG_ARM_FW_FEAT_BMAP_REG(3), - UINT64_MAX, 0, ToleranceOnlySrcTestValue); -} -#endif - void aarch64_host_initfn(Object *obj) { ARMCPU *cpu = ARM_CPU(obj); diff --git a/target/arm/kvm-stub.c b/target/arm/kvm-stub.c index 88cbe8d85c4..ecbd4f9aca1 100644 --- a/target/arm/kvm-stub.c +++ b/target/arm/kvm-stub.c @@ -50,6 +50,11 @@ void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu) g_assert_not_reached(); } +void kvm_arm_set_cpreg_mig_tolerances(ARMCPU *cpu) +{ + g_assert_not_reached(); +} + void kvm_arm_add_vcpu_properties(ARMCPU *cpu) { g_assert_not_reached(); diff --git a/target/arm/kvm.c b/target/arm/kvm.c index ed99be7fd80..2525b9d429c 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -505,6 +505,42 @@ void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu) env->features = arm_host_cpu_features.features; } +void kvm_arm_set_cpreg_mig_tolerances(ARMCPU *cpu) +{ + /* + * Registers that may be in the incoming stream and not exposed + * on the destination + */ + + /* + * TCR_EL1 was erroneously unconditionnally exposed before linux v6.13. + * See commit 0fcb4eea5345 ("KVM: arm64: Hide TCR2_EL1 from userspace + * when disabled for guests") + */ + arm_register_cpreg_mig_tolerance(cpu, ARM64_SYS_REG(3, 0, 2, 0, 3), + 0, 0, ToleranceNotOnBothEnds); + /* + * PIRE0_EL1 and PIR_EL1 were erroneously unconditionnally exposed + * before linux v6.13. See commit a68cddbe47ef ("KVM: arm64: Hide + * S1PIE registers from userspace when disabled for guests") + */ + arm_register_cpreg_mig_tolerance(cpu, ARM64_SYS_REG(3, 0, 10, 2, 2), + 0, 0, ToleranceNotOnBothEnds); + arm_register_cpreg_mig_tolerance(cpu, ARM64_SYS_REG(3, 0, 10, 2, 3), + 0, 0, ToleranceNotOnBothEnds); + + /* + * KVM_REG_ARM_VENDOR_HYP_BMAP_2 pseudo FW register is exposed + * from v6.15 onwards. Backward migration from a >= v6.15 to an older + * kernel would fail without cpreg migration tolerance definition. + * If the register is present on source but not on destination, make + * sure it has its reset value, ie. 0, meaning no service is exposed + * to the guest. + */ + arm_register_cpreg_mig_tolerance(cpu, KVM_REG_ARM_FW_FEAT_BMAP_REG(3), + UINT64_MAX, 0, ToleranceOnlySrcTestValue); +} + static bool kvm_no_adjvtime_get(Object *obj, Error **errp) { return !ARM_CPU(obj)->kvm_adjvtime; diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h index e7c40fb003e..014b7bad65b 100644 --- a/target/arm/kvm_arm.h +++ b/target/arm/kvm_arm.h @@ -133,6 +133,15 @@ void kvm_arm_destroy_scratch_host_vcpu(int *fdarray); */ void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu); +/** + * kvm_arm_set_cpreg_mig_tolerances: + * @cpu: ARMCPU to register the tolerances on + * + * Register KVM cpreg migration tolerances for kernel register-list + * differences (hidden sysregs and newer FW feature bitmaps). + */ +void kvm_arm_set_cpreg_mig_tolerances(ARMCPU *cpu); + /** * kvm_arm_add_vcpu_properties: * @cpu: The CPU object to add the properties to -- 2.52.0.windows.1
