Message ID | 20250109223836.419240-1-robh@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | KVM: arm64: Explicitly handle BRBE traps as UNDEFINED | expand |
On Thu, 09 Jan 2025 16:38:36 -0600, Rob Herring (Arm) wrote: > The Branch Record Buffer Extension (BRBE) adds a number of system > registers and instructions which we don't currently intend to expose to > guests. Our existing logic handles this safely, but this could be > improved with some explicit handling of BRBE. > > KVM currently hides BRBE from guests: the cpufeature code's > ftr_id_aa64dfr0[] table doesn't have an entry for the BRBE field, and so > this will be zero in the sanitised value of ID_AA64DFR0 exposed to > guests via read_sanitised_id_aa64dfr0_el1(). > > [...] Applied to next, thanks! [1/1] KVM: arm64: Explicitly handle BRBE traps as UNDEFINED commit: a7f1fa5564be565bd4bc18875bb46ffd0c01d292 Cheers, M.
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 83c6b4a07ef5..bc91ddc75487 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1806,6 +1806,9 @@ static u64 sanitise_id_aa64dfr0_el1(const struct kvm_vcpu *vcpu, u64 val) /* Hide SPE from guests */ val &= ~ID_AA64DFR0_EL1_PMSVer_MASK; + /* Hide BRBE from guests */ + val &= ~ID_AA64DFR0_EL1_BRBE_MASK; + return val; } @@ -4972,6 +4975,14 @@ void kvm_calculate_traps(struct kvm_vcpu *vcpu) kvm->arch.fgu[HAFGRTR_GROUP] |= ~(HAFGRTR_EL2_RES0 | HAFGRTR_EL2_RES1); + if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, BRBE, IMP)) { + kvm->arch.fgu[HDFGRTR_GROUP] |= (HDFGRTR_EL2_nBRBDATA | + HDFGRTR_EL2_nBRBCTL | + HDFGRTR_EL2_nBRBIDR); + kvm->arch.fgu[HFGITR_GROUP] |= (HFGITR_EL2_nBRBINJ | + HFGITR_EL2_nBRBIALL); + } + set_bit(KVM_ARCH_FLAG_FGU_INITIALIZED, &kvm->arch.flags); out: mutex_unlock(&kvm->arch.config_lock);