Merge branch kvm-arm64/misc-5.20 into kvmarm-master/next
[sfrench/cifs-2.6.git] / arch / arm64 / kvm / hyp / vhe / switch.c
index 262dfe03134daba2f7c9669b115ae792cd5b15e1..7acb87eaa0925a75e6f1843fd80b925bad0d3c85 100644 (file)
@@ -41,7 +41,8 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
 
        val = read_sysreg(cpacr_el1);
        val |= CPACR_EL1_TTA;
-       val &= ~(CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN);
+       val &= ~(CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN |
+                CPACR_EL1_SMEN_EL0EN | CPACR_EL1_SMEN_EL1EN);
 
        /*
         * With VHE (HCR.E2H == 1), accesses to CPACR_EL1 are routed to
@@ -54,7 +55,7 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
 
        val |= CPTR_EL2_TAM;
 
-       if (update_fp_enabled(vcpu)) {
+       if (guest_owns_fp_regs(vcpu)) {
                if (vcpu_has_sve(vcpu))
                        val |= CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN;
        } else {
@@ -62,6 +63,10 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
                __activate_traps_fpsimd32(vcpu);
        }
 
+       if (cpus_have_final_cap(ARM64_SME))
+               write_sysreg(read_sysreg(sctlr_el2) & ~SCTLR_ELx_ENTP2,
+                            sctlr_el2);
+
        write_sysreg(val, cpacr_el1);
 
        write_sysreg(__this_cpu_read(kvm_hyp_vector), vbar_el1);
@@ -83,6 +88,10 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu)
         */
        asm(ALTERNATIVE("nop", "isb", ARM64_WORKAROUND_SPECULATIVE_AT));
 
+       if (cpus_have_final_cap(ARM64_SME))
+               write_sysreg(read_sysreg(sctlr_el2) | SCTLR_ELx_ENTP2,
+                            sctlr_el2);
+
        write_sysreg(CPACR_EL1_DEFAULT, cpacr_el1);
 
        if (!arm64_kernel_unmapped_at_el0())
@@ -166,7 +175,7 @@ static int __kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu)
 
        sysreg_restore_host_state_vhe(host_ctxt);
 
-       if (vcpu->arch.flags & KVM_ARM64_FP_ENABLED)
+       if (vcpu->arch.fp_state == FP_STATE_GUEST_OWNED)
                __fpsimd_save_fpexc32(vcpu);
 
        __debug_switch_to_host(vcpu);
@@ -240,5 +249,5 @@ void __noreturn hyp_panic(void)
 
 asmlinkage void kvm_unexpected_el2_exception(void)
 {
-       return __kvm_unexpected_el2_exception();
+       __kvm_unexpected_el2_exception();
 }