From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57352) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkAog-0004KC-Ak for qemu-devel@nongnu.org; Wed, 14 Sep 2016 10:05:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkAoZ-0004z8-3Q for qemu-devel@nongnu.org; Wed, 14 Sep 2016 10:05:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53472) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkAoY-0004yy-S2 for qemu-devel@nongnu.org; Wed, 14 Sep 2016 10:05:27 -0400 Date: Wed, 14 Sep 2016 16:05:21 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= Message-ID: <20160914140520.GC17296@potion> References: <1473832464-3478-1-git-send-email-wanpeng.li@hotmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1473832464-3478-1-git-send-email-wanpeng.li@hotmail.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2] pc: apic: fix touch LAPIC when irqchip is split List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wanpeng Li Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org, Wanpeng Li , Paolo Bonzini , "Michael S. Tsirkin" , Eduardo Habkost 2016-09-14 13:54+0800, Wanpeng Li: > From: Wanpeng Li >=20 > Add -kernel_irqchip=3Dsplit > ./x86-run x86/eventinj.flat >=20 > qemu-system-x86_64 -enable-kvm -machine kernel_irqchip=3Dsplit -cpu hos= t > -device pc-testdev -device isa-debug-exit,iobase=3D0xf4,iosize=3D0x4 -v= nc > none -serial stdio -device pci-testdev -kernel x86/eventinj.flat > enabling apic > paging enabled > cr0 =3D 80010011 > cr3 =3D 7fff000 > cr4 =3D 20 > Sending vec 33 and 62 and mask one with TPR > irq1 running > irq1 running > After 33/62 TPR test > FAIL: TPR > irq0 running > irq0 running >=20 > Both irq1 and irq0 are executing twice. >=20 > kvm_entry: vcpu 0 > kvm_exit: reason MSR_WRITE rip 0x401f33 info 0 0 > kvm_apic: apic_write APIC_EOI =3D 0x0 > kvm_eoi: apicid 0 vector 62 > kvm_msr: msr_write 80b =3D 0x0 > kvm_entry: vcpu 0 > kvm_exit: reason PENDING_INTERRUPT rip 0x401f35 info 0 0 > kvm_userspace_exit: reason KVM_EXIT_IRQ_WINDOW_OPEN (7) > kvm_inj_virq: irq 62 > kvm_entry: vcpu 0 > kvm_exit: reason IO_INSTRUCTION rip 0x4016ec info 3fd0008 0 >=20 > From the trace we can see there is an interrupt window exit=20 > after the first interrupt EOI(irq 62), and the same irq(62)=20 > is injected duplicately after the interrupt window. >=20 > QEMU does KVM_INTERRUPT(62) ioctl after KVM exits with=20 > KVM_EXIT_IRQ_WINDOW_OPEN, which QEMU requested while the > guest was printing. The printing calls >=20 > serial_update_irq() -> qemu_irq_lower() -> qemu_set_irq() -> > gsi_handler() -> qemu_set_irq() -> pic_irq_request() -> > apic_deliver_pic_intr() -> kvm_handle_interrupt() >=20 > kvm_handle_interrupt() does >=20 > interrupt_request |=3D CPU_INTERRUPT_HARD >=20 > which later calls cpu_get_pic_interrupt() in kvm_arch_pre_run(),=20 > but that function uses stale information from APIC and injects=20 > 62 again. If we synchronized the APIC, then the test would #GP,=20 > because there would be no injectable interrupt in LAPIC or PIC,=20 > so pic_read_irq() would return 15, thinking it was spurious. >=20 > This patch fix it by don't touch LAPIC if LAPIC is in kernel. >=20 > Suggested-by: Paolo Bonzini > Suggested-by: Radim Kr=C4=8Dm=C3=A1=C5=99 > Cc: Paolo Bonzini > Cc: Radim Kr=C4=8Dm=C3=A1=C5=99 > Cc: Michael S. Tsirkin > Cc: Eduardo Habkost > Signed-off-by: Wanpeng Li > --- Reviewed-by: Radim Kr=C4=8Dm=C3=A1=C5=99