KVM: arm64: Calculate cptr_el2 traps on activating traps
[ Upstream commit 2fd5b4b0e7b440602455b79977bfa64dea101e6c ]
Similar to VHE, calculate the value of cptr_el2 from scratch on
activate traps. This removes the need to store cptr_el2 in every
vcpu structure. Moreover, some traps, such as whether the guest
owns the fp registers, need to be set on every vcpu run.
Reported-by: James Clark <james.clark@linaro.org>
Fixes: 5294afdbf4 ("KVM: arm64: Exclude FP ownership from kvm_vcpu_arch")
Signed-off-by: Fuad Tabba <tabba@google.com>
Link: https://lore.kernel.org/r/20241216105057.579031-13-tabba@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
73ef4f6e37
commit
e6cd28bbbf
@@ -697,7 +697,6 @@ struct kvm_vcpu_arch {
|
|||||||
u64 hcr_el2;
|
u64 hcr_el2;
|
||||||
u64 hcrx_el2;
|
u64 hcrx_el2;
|
||||||
u64 mdcr_el2;
|
u64 mdcr_el2;
|
||||||
u64 cptr_el2;
|
|
||||||
|
|
||||||
/* Exception Information */
|
/* Exception Information */
|
||||||
struct kvm_vcpu_fault_info fault;
|
struct kvm_vcpu_fault_info fault;
|
||||||
|
|||||||
@@ -1577,7 +1577,6 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,
|
|||||||
}
|
}
|
||||||
|
|
||||||
vcpu_reset_hcr(vcpu);
|
vcpu_reset_hcr(vcpu);
|
||||||
vcpu->arch.cptr_el2 = kvm_get_reset_cptr_el2(vcpu);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle the "start in power-off" case.
|
* Handle the "start in power-off" case.
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ static void pvm_init_traps_aa64pfr0(struct kvm_vcpu *vcpu)
|
|||||||
const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64PFR0_EL1);
|
const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64PFR0_EL1);
|
||||||
u64 hcr_set = HCR_RW;
|
u64 hcr_set = HCR_RW;
|
||||||
u64 hcr_clear = 0;
|
u64 hcr_clear = 0;
|
||||||
u64 cptr_set = 0;
|
|
||||||
u64 cptr_clear = 0;
|
|
||||||
|
|
||||||
/* Protected KVM does not support AArch32 guests. */
|
/* Protected KVM does not support AArch32 guests. */
|
||||||
BUILD_BUG_ON(FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_EL0),
|
BUILD_BUG_ON(FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_EL0),
|
||||||
@@ -59,21 +57,10 @@ static void pvm_init_traps_aa64pfr0(struct kvm_vcpu *vcpu)
|
|||||||
/* Trap AMU */
|
/* Trap AMU */
|
||||||
if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_AMU), feature_ids)) {
|
if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_AMU), feature_ids)) {
|
||||||
hcr_clear |= HCR_AMVOFFEN;
|
hcr_clear |= HCR_AMVOFFEN;
|
||||||
cptr_set |= CPTR_EL2_TAM;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Trap SVE */
|
|
||||||
if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_SVE), feature_ids)) {
|
|
||||||
if (has_hvhe())
|
|
||||||
cptr_clear |= CPACR_ELx_ZEN;
|
|
||||||
else
|
|
||||||
cptr_set |= CPTR_EL2_TZ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vcpu->arch.hcr_el2 |= hcr_set;
|
vcpu->arch.hcr_el2 |= hcr_set;
|
||||||
vcpu->arch.hcr_el2 &= ~hcr_clear;
|
vcpu->arch.hcr_el2 &= ~hcr_clear;
|
||||||
vcpu->arch.cptr_el2 |= cptr_set;
|
|
||||||
vcpu->arch.cptr_el2 &= ~cptr_clear;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -103,7 +90,6 @@ static void pvm_init_traps_aa64dfr0(struct kvm_vcpu *vcpu)
|
|||||||
const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64DFR0_EL1);
|
const u64 feature_ids = pvm_read_id_reg(vcpu, SYS_ID_AA64DFR0_EL1);
|
||||||
u64 mdcr_set = 0;
|
u64 mdcr_set = 0;
|
||||||
u64 mdcr_clear = 0;
|
u64 mdcr_clear = 0;
|
||||||
u64 cptr_set = 0;
|
|
||||||
|
|
||||||
/* Trap/constrain PMU */
|
/* Trap/constrain PMU */
|
||||||
if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_PMUVer), feature_ids)) {
|
if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_PMUVer), feature_ids)) {
|
||||||
@@ -130,21 +116,12 @@ static void pvm_init_traps_aa64dfr0(struct kvm_vcpu *vcpu)
|
|||||||
if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_TraceFilt), feature_ids))
|
if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_TraceFilt), feature_ids))
|
||||||
mdcr_set |= MDCR_EL2_TTRF;
|
mdcr_set |= MDCR_EL2_TTRF;
|
||||||
|
|
||||||
/* Trap Trace */
|
|
||||||
if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_TraceVer), feature_ids)) {
|
|
||||||
if (has_hvhe())
|
|
||||||
cptr_set |= CPACR_EL1_TTA;
|
|
||||||
else
|
|
||||||
cptr_set |= CPTR_EL2_TTA;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Trap External Trace */
|
/* Trap External Trace */
|
||||||
if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_ExtTrcBuff), feature_ids))
|
if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_ExtTrcBuff), feature_ids))
|
||||||
mdcr_clear |= MDCR_EL2_E2TB_MASK << MDCR_EL2_E2TB_SHIFT;
|
mdcr_clear |= MDCR_EL2_E2TB_MASK << MDCR_EL2_E2TB_SHIFT;
|
||||||
|
|
||||||
vcpu->arch.mdcr_el2 |= mdcr_set;
|
vcpu->arch.mdcr_el2 |= mdcr_set;
|
||||||
vcpu->arch.mdcr_el2 &= ~mdcr_clear;
|
vcpu->arch.mdcr_el2 &= ~mdcr_clear;
|
||||||
vcpu->arch.cptr_el2 |= cptr_set;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -195,10 +172,6 @@ static void pvm_init_trap_regs(struct kvm_vcpu *vcpu)
|
|||||||
/* Clear res0 and set res1 bits to trap potential new features. */
|
/* Clear res0 and set res1 bits to trap potential new features. */
|
||||||
vcpu->arch.hcr_el2 &= ~(HCR_RES0);
|
vcpu->arch.hcr_el2 &= ~(HCR_RES0);
|
||||||
vcpu->arch.mdcr_el2 &= ~(MDCR_EL2_RES0);
|
vcpu->arch.mdcr_el2 &= ~(MDCR_EL2_RES0);
|
||||||
if (!has_hvhe()) {
|
|
||||||
vcpu->arch.cptr_el2 |= CPTR_NVHE_EL2_RES1;
|
|
||||||
vcpu->arch.cptr_el2 &= ~(CPTR_NVHE_EL2_RES0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -579,8 +552,6 @@ unlock:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
hyp_vcpu->vcpu.arch.cptr_el2 = kvm_get_reset_cptr_el2(&hyp_vcpu->vcpu);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,33 +36,46 @@ DEFINE_PER_CPU(unsigned long, kvm_hyp_vector);
|
|||||||
|
|
||||||
extern void kvm_nvhe_prepare_backtrace(unsigned long fp, unsigned long pc);
|
extern void kvm_nvhe_prepare_backtrace(unsigned long fp, unsigned long pc);
|
||||||
|
|
||||||
static void __activate_traps(struct kvm_vcpu *vcpu)
|
static void __activate_cptr_traps(struct kvm_vcpu *vcpu)
|
||||||
{
|
{
|
||||||
u64 val;
|
u64 val = CPTR_EL2_TAM; /* Same bit irrespective of E2H */
|
||||||
|
|
||||||
___activate_traps(vcpu, vcpu->arch.hcr_el2);
|
if (has_hvhe()) {
|
||||||
__activate_traps_common(vcpu);
|
val |= CPACR_ELx_TTA;
|
||||||
|
|
||||||
val = vcpu->arch.cptr_el2;
|
if (guest_owns_fp_regs()) {
|
||||||
val |= CPTR_EL2_TAM; /* Same bit irrespective of E2H */
|
val |= CPACR_ELx_FPEN;
|
||||||
val |= has_hvhe() ? CPACR_EL1_TTA : CPTR_EL2_TTA;
|
if (vcpu_has_sve(vcpu))
|
||||||
if (cpus_have_final_cap(ARM64_SME)) {
|
val |= CPACR_ELx_ZEN;
|
||||||
if (has_hvhe())
|
}
|
||||||
val &= ~CPACR_ELx_SMEN;
|
} else {
|
||||||
else
|
val |= CPTR_EL2_TTA | CPTR_NVHE_EL2_RES1;
|
||||||
val |= CPTR_EL2_TSM;
|
|
||||||
|
/*
|
||||||
|
* Always trap SME since it's not supported in KVM.
|
||||||
|
* TSM is RES1 if SME isn't implemented.
|
||||||
|
*/
|
||||||
|
val |= CPTR_EL2_TSM;
|
||||||
|
|
||||||
|
if (!vcpu_has_sve(vcpu) || !guest_owns_fp_regs())
|
||||||
|
val |= CPTR_EL2_TZ;
|
||||||
|
|
||||||
|
if (!guest_owns_fp_regs())
|
||||||
|
val |= CPTR_EL2_TFP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!guest_owns_fp_regs()) {
|
if (!guest_owns_fp_regs())
|
||||||
if (has_hvhe())
|
|
||||||
val &= ~(CPACR_ELx_FPEN | CPACR_ELx_ZEN);
|
|
||||||
else
|
|
||||||
val |= CPTR_EL2_TFP | CPTR_EL2_TZ;
|
|
||||||
|
|
||||||
__activate_traps_fpsimd32(vcpu);
|
__activate_traps_fpsimd32(vcpu);
|
||||||
}
|
|
||||||
|
|
||||||
kvm_write_cptr_el2(val);
|
kvm_write_cptr_el2(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __activate_traps(struct kvm_vcpu *vcpu)
|
||||||
|
{
|
||||||
|
___activate_traps(vcpu, vcpu->arch.hcr_el2);
|
||||||
|
__activate_traps_common(vcpu);
|
||||||
|
__activate_cptr_traps(vcpu);
|
||||||
|
|
||||||
write_sysreg(__this_cpu_read(kvm_hyp_vector), vbar_el2);
|
write_sysreg(__this_cpu_read(kvm_hyp_vector), vbar_el2);
|
||||||
|
|
||||||
if (cpus_have_final_cap(ARM64_WORKAROUND_SPECULATIVE_AT)) {
|
if (cpus_have_final_cap(ARM64_WORKAROUND_SPECULATIVE_AT)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user