From: Alex Williamson Subject: vmx real mode emulated mmio? Date: Fri, 14 Dec 2012 16:42:36 -0700 Message-ID: <1355528556.3224.394.camel@bling.home> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: kvm To: Gleb Natapov , Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:12149 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756226Ab2LNXmh (ORCPT ); Fri, 14 Dec 2012 18:42:37 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBENgaoM015768 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 14 Dec 2012 18:42:36 -0500 Sender: kvm-owner@vger.kernel.org List-ID: I don't really know what I'm doing messing around with realmode exception handling, but are we missing something like this: --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -4332,7 +4332,8 @@ static int handle_exception(struct kvm_vcpu *vcpu) if (vcpu->arch.halt_request) { vcpu->arch.halt_request = 0; return kvm_emulate_halt(vcpu); - } + } else if (vcpu->mmio_needed) + return 0; return 1; } The background is that I was playing around with when the MMIO regions of PCI assigned devices get direct mapped through KVM and start using memory slots and I found that the boot ROM on an e1000e card that I often use for testing causes the VM to hang when not directly mapped through a memory slot. This happens with both pci-assign and vfio-pci. Debugging further, I see the kernel instruction emulator decodes this and sets all the necessary flags and fragments for userspace to complete the access, but since it happened in real mode, vcpu_enter_guest always returns 1 and therefore KVM_RUN never exits to userspace and KVM gets stuck in an infinite loop re-handling this instruction. The above is pretty trivial and allows the ROM to work again. Is it correct? What other exceptions are we missing here that should allow an exit? This particular access generated a GP_VECTOR exception if we want to key on that somewhere. Thanks, Alex