From mboxrd@z Thu Jan 1 00:00:00 1970 From: Radim =?utf-8?B?S3LEjW3DocWZ?= Subject: [PATCH] KVM: SVM: fix interrupt injection (apic->isr_count always 0) Date: Wed, 25 Feb 2015 20:41:41 +0100 Message-ID: <20150225194140.GA9777@potion.brq.redhat.com> References: <20150225160056.GF3226@pd.tnic> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Tiejun Chen , Paolo Bonzini , kvm ML , lkml To: Borislav Petkov Return-path: Content-Disposition: inline In-Reply-To: <20150225160056.GF3226@pd.tnic> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org 2015-02-25 17:00+0100, Borislav Petkov: > Hi, >=20 > commit in $Subject breaks my kvm guest on AMD host, causing it to do = the > following below. Mouse doesn't work anymore in the guest, network is > gone too. >=20 > Reverting it fixes the issue. Thanks, this patch should fix it. ---8<--- In commit b4eef9b36db4, we started to use hwapic_isr_update() !=3D NULL instead of kvm_apic_vid_enabled(vcpu->kvm). This didn't work because SVM had it defined and "apicv" path in apic_{set,clear}_isr() does not change apic->isr_count, because it should always be 1. The initial value of apic->isr_count was based on kvm_apic_vid_enabled(vcpu->kvm), which is always 0 for SVM, so KVM could have injected interrupts when i= t shouldn't. =46ix it by setting SVM's hwapic_isr_update to NULL and make the initia= l isr_count depend on hwapic_isr_update() for good measure. =46ixes: b4eef9b36db4 ("kvm: x86: vmx: NULL out hwapic_isr_update() in = case of !enable_apicv") Reported-by: Borislav Petkov Signed-off-by: Radim Kr=C4=8Dm=C3=A1=C5=99 --- arch/x86/kvm/lapic.c | 4 ++-- arch/x86/kvm/svm.c | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index e55b5fc344eb..bd4e34de24c7 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1572,7 +1572,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu) apic_set_reg(apic, APIC_TMR + 0x10 * i, 0); } apic->irr_pending =3D kvm_apic_vid_enabled(vcpu->kvm); - apic->isr_count =3D kvm_apic_vid_enabled(vcpu->kvm); + apic->isr_count =3D kvm_x86_ops->hwapic_isr_update ? 1 : 0; apic->highest_isr_cache =3D -1; update_divide_count(apic); atomic_set(&apic->lapic_timer.pending, 0); @@ -1782,7 +1782,7 @@ void kvm_apic_post_state_restore(struct kvm_vcpu = *vcpu, update_divide_count(apic); start_apic_timer(apic); apic->irr_pending =3D true; - apic->isr_count =3D kvm_apic_vid_enabled(vcpu->kvm) ? + apic->isr_count =3D kvm_x86_ops->hwapic_isr_update ? 1 : count_vectors(apic->regs + APIC_ISR); apic->highest_isr_cache =3D -1; if (kvm_x86_ops->hwapic_irr_update) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index d319e0c24758..54c7b36ad12d 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -3649,11 +3649,6 @@ static void svm_load_eoi_exitmap(struct kvm_vcpu= *vcpu, u64 *eoi_exit_bitmap) return; } =20 -static void svm_hwapic_isr_update(struct kvm *kvm, int isr) -{ - return; -} - static void svm_sync_pir_to_irr(struct kvm_vcpu *vcpu) { return; @@ -4403,7 +4398,7 @@ static struct kvm_x86_ops svm_x86_ops =3D { .set_virtual_x2apic_mode =3D svm_set_virtual_x2apic_mode, .vm_has_apicv =3D svm_vm_has_apicv, .load_eoi_exitmap =3D svm_load_eoi_exitmap, - .hwapic_isr_update =3D svm_hwapic_isr_update, + .hwapic_isr_update =3D NULL, .sync_pir_to_irr =3D svm_sync_pir_to_irr, =20 .set_tss_addr =3D svm_set_tss_addr,