Skip to content

Commit 8b69055

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm fixes from Paolo Bonzini: "Arm: - Only adjust the ID registers when no irqchip has been created once per VM run, instead of doing it once per vcpu, as this otherwise triggers a pretty bad conbsistency check failure in the sysreg code - Make sure the per-vcpu Fine Grain Traps are computed before we load the system registers on the HW, as we otherwise start running without anything set until the first preemption of the vcpu x86: - Fix selftests failure on AMD, checking for an optimization that was not happening anymore" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: SVM: Fix redundant updates of LBR MSR intercepts KVM: arm64: VHE: Compute fgt traps before activating them KVM: arm64: Finalize ID registers only once per VM
2 parents 5bebe8d + 3fa05f9 commit 8b69055

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

arch/arm64/kvm/arm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
624624
kvm_timer_vcpu_load(vcpu);
625625
kvm_vgic_load(vcpu);
626626
kvm_vcpu_load_debug(vcpu);
627+
kvm_vcpu_load_fgt(vcpu);
627628
if (has_vhe())
628629
kvm_vcpu_load_vhe(vcpu);
629630
kvm_arch_vcpu_load_fp(vcpu);
@@ -642,7 +643,6 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
642643
vcpu->arch.hcr_el2 |= HCR_TWI;
643644

644645
vcpu_set_pauth_traps(vcpu);
645-
kvm_vcpu_load_fgt(vcpu);
646646

647647
if (is_protected_kvm_enabled()) {
648648
kvm_call_hyp_nvhe(__pkvm_vcpu_load,

arch/arm64/kvm/sys_regs.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5609,7 +5609,11 @@ int kvm_finalize_sys_regs(struct kvm_vcpu *vcpu)
56095609

56105610
guard(mutex)(&kvm->arch.config_lock);
56115611

5612-
if (!irqchip_in_kernel(kvm)) {
5612+
/*
5613+
* This hacks into the ID registers, so only perform it when the
5614+
* first vcpu runs, or the kvm_set_vm_id_reg() helper will scream.
5615+
*/
5616+
if (!irqchip_in_kernel(kvm) && !kvm_vm_has_ran_once(kvm)) {
56135617
u64 val;
56145618

56155619
val = kvm_read_vm_id_reg(kvm, SYS_ID_AA64PFR0_EL1) & ~ID_AA64PFR0_EL1_GIC;

arch/x86/kvm/svm/svm.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,11 @@ void *svm_alloc_permissions_map(unsigned long size, gfp_t gfp_mask)
705705

706706
static void svm_recalc_lbr_msr_intercepts(struct kvm_vcpu *vcpu)
707707
{
708-
bool intercept = !(to_svm(vcpu)->vmcb->control.virt_ext & LBR_CTL_ENABLE_MASK);
708+
struct vcpu_svm *svm = to_svm(vcpu);
709+
bool intercept = !(svm->vmcb->control.virt_ext & LBR_CTL_ENABLE_MASK);
710+
711+
if (intercept == svm->lbr_msrs_intercepted)
712+
return;
709713

710714
svm_set_intercept_for_msr(vcpu, MSR_IA32_LASTBRANCHFROMIP, MSR_TYPE_RW, intercept);
711715
svm_set_intercept_for_msr(vcpu, MSR_IA32_LASTBRANCHTOIP, MSR_TYPE_RW, intercept);
@@ -714,6 +718,8 @@ static void svm_recalc_lbr_msr_intercepts(struct kvm_vcpu *vcpu)
714718

715719
if (sev_es_guest(vcpu->kvm))
716720
svm_set_intercept_for_msr(vcpu, MSR_IA32_DEBUGCTLMSR, MSR_TYPE_RW, intercept);
721+
722+
svm->lbr_msrs_intercepted = intercept;
717723
}
718724

719725
void svm_vcpu_free_msrpm(void *msrpm)
@@ -1221,6 +1227,7 @@ static int svm_vcpu_create(struct kvm_vcpu *vcpu)
12211227
}
12221228

12231229
svm->x2avic_msrs_intercepted = true;
1230+
svm->lbr_msrs_intercepted = true;
12241231

12251232
svm->vmcb01.ptr = page_address(vmcb01_page);
12261233
svm->vmcb01.pa = __sme_set(page_to_pfn(vmcb01_page) << PAGE_SHIFT);

arch/x86/kvm/svm/svm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ struct vcpu_svm {
336336
bool guest_state_loaded;
337337

338338
bool x2avic_msrs_intercepted;
339+
bool lbr_msrs_intercepted;
339340

340341
/* Guest GIF value, used when vGIF is not enabled */
341342
bool guest_gif;

0 commit comments

Comments
 (0)