Allow the RAS feature bit in ID_AA64PFR0_EL1 writable from userspace
cover Allow the RAS feature bit in ID_AA64PFR0_EL1 writable from userspace
Currently the RAS feature bit is not writable in ID_AA64PFR0EL1, this makes migration fail when migration from the machine which RAS is 1 to another machine which RAS is 2.
Allow RAS writable from userspace would make the migration possible between two machines which RAS is different.
Shaoqin Huang (2):
KVM: arm64: Use kvm_has_feat() to check if FEAT_RAS is advertised to
the guest
KVM: arm64: Allow the RAS feature bit in ID_AA64PFR0_EL1 writable from
userspace
arch/arm64/kvm/guest.c | 4 ++-- arch/arm64/kvm/handle_exit.c | 2 +- arch/arm64/kvm/hyp/include/hyp/switch.h | 2 +- arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 7 +++++-- arch/arm64/kvm/sys_regs.c | 3 +-- tools/testing/selftests/kvm/aarch64/set_id_regs.c | 1 + 6 files changed, 11 insertions(+), 8 deletions(-)
Signature · 1 line
2.40.1
RFC PATCH 1/2 KVM: arm64: Use kvm_has_feat() to check if FEAT_RAS is advertised to the guest
Use kvm_has_feat() to check if FEAT_RAS is advertised to the guest, this is useful when FEAT_RAS is writable.
--- arch/arm64/kvm/guest.c | 4 ++-- arch/arm64/kvm/handle_exit.c | 2 +- arch/arm64/kvm/hyp/include/hyp/switch.h | 2 +- arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 7 +++++-- arch/arm64/kvm/sys_regs.c | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-)
arch/arm64/kvm/guest.c +2 -2
@@ -819,7 +819,7 @@ int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu, struct kvm_vcpu_events *events) { events->exception.serror_pending = !!(vcpu->arch.hcr_el2 &HCR_VSE ); - events->exception.serror_has_esr =cpus_have_final_cap (ARM64_HAS_RAS_EXTN ); + events->exception.serror_has_esr =kvm_has_feat (vcpu->kvm,ID_AA64PFR0_EL1 ,RAS ,IMP );if (events->exception.serror_pending && events->exception.serror_has_esr) events->exception.serror_esr =vcpu_get_vsesr (vcpu);
@@ -841,7 +841,7 @@ int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,bool ext_dabt_pending = events->exception.ext_dabt_pending;if (serror_pending && has_esr) { -if (!cpus_have_final_cap (ARM64_HAS_RAS_EXTN )) +if (!kvm_has_feat (vcpu->kvm,ID_AA64PFR0_EL1 ,RAS ,IMP ))return -EINVAL ;if (!((events->exception.serror_esr) & ~ESR_ELx_ISS_MASK))
arch/arm64/kvm/handle_exit.c +1 -1
@@ -405,7 +405,7 @@ int handle_exit(struct kvm_vcpu *vcpu, int exception_index)void handle_exit_early (struct kvm_vcpu *vcpu,int exception_index) {if (ARM_SERROR_PENDING (exception_index)) { -if (this_cpu_has_cap (ARM64_HAS_RAS_EXTN )) { +if (kvm_has_feat (vcpu->kvm,ID_AA64PFR0_EL1 ,RAS ,IMP )) {u64 disr =kvm_vcpu_get_disr (vcpu);kvm_handle_guest_serror (vcpu,disr_to_esr (disr));
arch/arm64/kvm/hyp/include/hyp/switch.h +1 -1
@@ -272,7 +272,7 @@ static inline void ___activate_traps(struct kvm_vcpu *vcpu, u64 hcr)write_sysreg (hcr, hcr_el2); -if (cpus_have_final_cap (ARM64_HAS_RAS_EXTN ) && (hcr &HCR_VSE )) +if (kvm_has_feat (vcpu->kvm,ID_AA64PFR0_EL1 ,RAS ,IMP ) && (hcr &HCR_VSE ))write_sysreg_s (vcpu->arch.vsesr_el2,SYS_VSESR_EL2 ); }
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +5 -2
@@ -105,6 +105,8 @@ static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt)static inline void __sysreg_save_el2_return_state (struct kvm_cpu_context *ctxt) { +struct kvm_vcpu *vcpu =ctxt_to_vcpu (ctxt); + ctxt->regs.pc =read_sysreg_el2 (SYS_ELR );/* * Guest PSTATE gets saved at guest fixup time in all
@@ -113,7 +115,7 @@ static inline void __sysreg_save_el2_return_state(struct kvm_cpu_context *ctxt)if (!has_vhe () && ctxt->__hyp_running_vcpu) ctxt->regs.pstate =read_sysreg_el2 (SYS_SPSR ); -if (cpus_have_final_cap (ARM64_HAS_RAS_EXTN )) +if (kvm_has_feat (vcpu->kvm,ID_AA64PFR0_EL1 ,RAS ,IMP ))ctxt_sys_reg (ctxt,DISR_EL1 ) =read_sysreg_s (SYS_VDISR_EL2 ); }
@@ -220,6 +222,7 @@ static inline void __sysreg_restore_el2_return_state(struct kvm_cpu_context *ctx {u64 pstate =to_hw_pstate (ctxt);u64 mode = pstate &PSR_AA32_MODE_MASK ; +struct kvm_vcpu *vcpu =ctxt_to_vcpu (ctxt);/* * Safety check to ensure we're setting the CPU up to enter the guest
@@ -238,7 +241,7 @@ static inline void __sysreg_restore_el2_return_state(struct kvm_cpu_context *ctxwrite_sysreg_el2 (ctxt->regs.pc,SYS_ELR );write_sysreg_el2 (pstate,SYS_SPSR ); -if (cpus_have_final_cap (ARM64_HAS_RAS_EXTN )) +if (kvm_has_feat (vcpu->kvm,ID_AA64PFR0_EL1 ,RAS ,IMP ))write_sysreg_s (ctxt_sys_reg (ctxt,DISR_EL1 ),SYS_VDISR_EL2 ); }
arch/arm64/kvm/sys_regs.c +1 -1
@@ -4513,7 +4513,7 @@ static void vcpu_set_hcr(struct kvm_vcpu *vcpu)if (has_vhe () ||has_hvhe ()) vcpu->arch.hcr_el2 |=HCR_E2H ; -if (cpus_have_final_cap (ARM64_HAS_RAS_EXTN )) { +if (kvm_has_feat (kvm,ID_AA64PFR0_EL1 ,RAS ,IMP )) {/* route synchronous external abort exceptions to EL2 */ vcpu->arch.hcr_el2 |=HCR_TEA ;/* trap error record accesses */
Signature · 1 line
2.40.1
Re: [RFC PATCH v1 1/2] KVM: arm64: Use kvm_has_feat() to check if FEAT_RAS is advertised to the guest
arch/arm64/kvm/handle_exit.c int handle_exit(struct kvm_vcpu *vcpu, int exception_index) · line 411
Quoted 13 lines · Shaoqin Huang
arch/arm64/kvm/handle_exit.c +1
-1@@ -405,7 +405,7 @@ int handle_exit(struct kvm_vcpu *vcpu, int exception_index)void handle_exit_early (struct kvm_vcpu *vcpu,int exception_index) {if (ARM_SERROR_PENDING (exception_index)) { -if (this_cpu_has_cap (ARM64_HAS_RAS_EXTN )) { +if (kvm_has_feat (vcpu->kvm,ID_AA64PFR0_EL1 ,RAS ,IMP )) {u64 disr =kvm_vcpu_get_disr (vcpu);kvm_handle_guest_serror (vcpu,disr_to_esr (disr));
This is wrong; this is about handling *physical* SErrors, not virtual ones.
So it really ought to be keyed off of the host cpucap.
arch/arm64/kvm/hyp/include/hyp/switch.h static inline void ___activate_traps(struct kvm_vcpu *vcpu, u64 hcr) · line 277
Quoted 12 lines
arch/arm64/kvm/hyp/include/hyp/switch.h +1
-1@@ -272,7 +272,7 @@ static inline void ___activate_traps(struct kvm_vcpu *vcpu, u64 hcr)write_sysreg (hcr, hcr_el2); -if (cpus_have_final_cap (ARM64_HAS_RAS_EXTN ) && (hcr &HCR_VSE )) +if (kvm_has_feat (vcpu->kvm,ID_AA64PFR0_EL1 ,RAS ,IMP ) && (hcr &HCR_VSE ))write_sysreg_s (vcpu->arch.vsesr_el2,SYS_VSESR_EL2 ); }
I don't think this should be conditioned on guest visibility either. If FEAT_RAS is implemented in hardware, ESR_EL1 is set to the value of VSESR_EL2 when the vSError is taken, no matter what.
Quoted 31 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +4
-1@@ -105,6 +105,8 @@ static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt)static inline void __sysreg_save_el2_return_state (struct kvm_cpu_context *ctxt) { +struct kvm_vcpu *vcpu =ctxt_to_vcpu (ctxt); + ctxt->regs.pc =read_sysreg_el2 (SYS_ELR );/* * Guest PSTATE gets saved at guest fixup time in all @@ -113,7 +115,7 @@ static inline void __sysreg_save_el2_return_state(struct kvm_cpu_context *ctxt)if (!has_vhe () && ctxt->__hyp_running_vcpu) ctxt->regs.pstate =read_sysreg_el2 (SYS_SPSR ); -if (cpus_have_final_cap (ARM64_HAS_RAS_EXTN )) +if (kvm_has_feat (vcpu->kvm,ID_AA64PFR0_EL1 ,RAS ,IMP ))ctxt_sys_reg (ctxt,DISR_EL1 ) =read_sysreg_s (SYS_VDISR_EL2 ); }@@ -220,6 +222,7 @@ static inline void __sysreg_restore_el2_return_state(struct kvm_cpu_context *ctx {u64 pstate =to_hw_pstate (ctxt);u64 mode = pstate &PSR_AA32_MODE_MASK ; +struct kvm_vcpu *vcpu =ctxt_to_vcpu (ctxt);/* * Safety check to ensure we're setting the CPU up to enter the guest
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h static inline void __sysreg_restore_el2_return_state(struct kvm_cpu_context *ctx · line 246
Quoted 7 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +1
-1@@ -238,7 +241,7 @@ static inline void __sysreg_restore_el2_return_state(struct kvm_cpu_context *ctxwrite_sysreg_el2 (ctxt->regs.pc,SYS_ELR );write_sysreg_el2 (pstate,SYS_SPSR ); -if (cpus_have_final_cap (ARM64_HAS_RAS_EXTN )) +if (kvm_has_feat (vcpu->kvm,ID_AA64PFR0_EL1 ,RAS ,IMP ))write_sysreg_s (ctxt_sys_reg (ctxt,DISR_EL1 ),SYS_VDISR_EL2 ); }
These registers are still stateful no matter what, we cannot prevent an ESB instruction inside the VM from consuming a pending vSError.
Keep in mind the ESB instruction is a NOP without FEAT_RAS, so it is still a legal instruction for a VM w/o FEAT_RAS.
arch/arm64/kvm/sys_regs.c static void vcpu_set_hcr(struct kvm_vcpu *vcpu) · line 4519
Quoted 13 lines
arch/arm64/kvm/sys_regs.c +1
-1@@ -4513,7 +4513,7 @@ static void vcpu_set_hcr(struct kvm_vcpu *vcpu)if (has_vhe () ||has_hvhe ()) vcpu->arch.hcr_el2 |=HCR_E2H ; -if (cpus_have_final_cap (ARM64_HAS_RAS_EXTN )) { +if (kvm_has_feat (kvm,ID_AA64PFR0_EL1 ,RAS ,IMP )) {/* route synchronous external abort exceptions to EL2 */ vcpu->arch.hcr_el2 |=HCR_TEA ;/* trap error record accesses */
No, we want external aborts to be taken to EL2. Wouldn't this also have the interesting property of allowing a VM w/o FEAT_RAS to access the error record registers?
Signature · 2 lines
Thanks, Oliver
RFC PATCH 2/2 KVM: arm64: Allow the RAS feature bit in ID_AA64PFR0_EL1 writable from userspace
In reply to Shaoqin HuangCurrently FEAT_RAS is not writable, this makes migration fail between systems where this feature differ. Allow the FEAT_RAS writable in ID_AA64PFR0_EL1 to let the migration possible when the RAS is differ between two machines.
Also update the kselftest to test the RAS field.
--- arch/arm64/kvm/sys_regs.c | 1 - tools/testing/selftests/kvm/aarch64/set_id_regs.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/sys_regs.c +0 -1
@@ -2364,7 +2364,6 @@ static const struct sys_reg_desc sys_reg_descs[] = { .val = ~(ID_AA64PFR0_EL1_AMU |ID_AA64PFR0_EL1_MPAM |ID_AA64PFR0_EL1_SVE | -ID_AA64PFR0_EL1_RAS |ID_AA64PFR0_EL1_GIC | ID_AA64PFR0_EL1_AdvSIMD | ID_AA64PFR0_EL1_FP), },
tools/testing/selftests/kvm/aarch64/set_id_regs.c +1 -0
@@ -126,6 +126,7 @@ static const struct reg_ftr_bits ftr_id_aa64pfr0_el1[] = {REG_FTR_BITS (FTR_LOWER_SAFE ,ID_AA64PFR0_EL1 ,CSV2 ,0 ),REG_FTR_BITS (FTR_LOWER_SAFE ,ID_AA64PFR0_EL1 ,DIT ,0 ),REG_FTR_BITS (FTR_LOWER_SAFE ,ID_AA64PFR0_EL1 ,SEL2 ,0 ), +REG_FTR_BITS (FTR_LOWER_SAFE ,ID_AA64PFR0_EL1 ,RAS ,0 ),REG_FTR_BITS (FTR_LOWER_SAFE ,ID_AA64PFR0_EL1 ,EL3 ,0 ),REG_FTR_BITS (FTR_LOWER_SAFE ,ID_AA64PFR0_EL1 ,EL2 ,0 ), REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64PFR0_EL1, EL1, 0),
Signature · 1 line
2.40.1
Re: [RFC PATCH v1 2/2] KVM: arm64: Allow the RAS feature bit in ID_AA64PFR0_EL1 writable from userspace
Quoted 6 lines · Shaoqin Huang
Currently
FEAT_RASis not writable, this makes migration fail between systems where this feature differ. Allow theFEAT_RASwritable inID_AA64PFR0_EL1to let the migration possible when the RAS is differ between two machines.Also update the kselftest to test the RAS field.
Please do kernel + selftests changes in separate patches.
Signature · 2 lines
Thanks, Oliver