From patchwork Fri May 28 07:47:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 53868 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CD4D3B6EFF for ; Fri, 28 May 2010 17:48:18 +1000 (EST) Received: from localhost ([127.0.0.1]:42790 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OHuIi-0006Og-54 for incoming@patchwork.ozlabs.org; Fri, 28 May 2010 03:48:16 -0400 Received: from [140.186.70.92] (port=50338 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OHuI0-0006LA-PE for qemu-devel@nongnu.org; Fri, 28 May 2010 03:47:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OHuHz-0007Fr-Jh for qemu-devel@nongnu.org; Fri, 28 May 2010 03:47:32 -0400 Received: from fmmailgate03.web.de ([217.72.192.234]:49823) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OHuHz-0007Fg-4n for qemu-devel@nongnu.org; Fri, 28 May 2010 03:47:31 -0400 Received: from smtp01.web.de ( [172.20.0.243]) by fmmailgate03.web.de (Postfix) with ESMTP id 920DC15302AB4; Fri, 28 May 2010 09:47:29 +0200 (CEST) Received: from [88.65.252.165] (helo=[192.168.1.10]) by smtp01.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #4) id 1OHuHx-0007vv-00; Fri, 28 May 2010 09:47:29 +0200 Message-ID: <4BFF750D.70309@web.de> Date: Fri, 28 May 2010 09:47:25 +0200 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: "Roedel, Joerg" References: <4BFE8F13.2000009@cs.vu.nl> <4BFEBF9E.90600@web.de> <4BFECCC3.2000806@cs.vu.nl> <4BFEF010.50300@web.de> <20100528073346.GC3266@amd.com> In-Reply-To: <20100528073346.GC3266@amd.com> X-Enigmail-Version: 0.95.7 X-Sender: jan.kiszka@web.de X-Provags-ID: V01U2FsdGVkX19rcRdANML1L5m1n3cFbu0Yg/8FXZ6pjlXSwh0j 1ctWn1geI1vwwJjEGAFotjgiQSEimh/DSDhfrB/uJ+WeA5b/HE O/Rk14xFg= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Cc: Gleb Natapov , "qemu-devel@nongnu.org" , Erik van der Kouwe Subject: [Qemu-devel] Re: SVM emulation: EVENTINJ marked valid when a pagefault happens while issuing a software interrupt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Roedel, Joerg wrote: > On Thu, May 27, 2010 at 06:20:00PM -0400, Jan Kiszka wrote: >> Erik van der Kouwe wrote: >>> Problem is: I'm compiling in Linux and testing in MINIX. Testing on the >>> real hardware would require a reboot everytime. Moreover, it might screw >>> up my system if I make bad mistakes (the MINIX filesystem is easily >>> corrupted). >> Use Linux+KVM as host OS, it can also run VMMs as guests (aka nested >> SVM). And you could even debug those guests just like when you would run >> QEMU in emulation mode. In contrast to SVM emulation, nesting is fairly >> stable AFAIK. And it is faster. > > At least it is more stable than any other nested-svm implementation I > know of ;-) > There are issues with kvmclock when you run kvm-on-kvm and you should > not expect windows-based hypervisors to run without problems. Beside > that, for running kvm-on-kvm and xen-on-kvm it is indeed fairly > stable :-) > >>> Linux source tree (2.6.31-ubuntu), arch/x86/kvm/svm.c, end of function >>> nested_svm_vmrun. Here event_inj and event_inj_err are copied from a >>> different VMCB, effectively clearing the value set by the CPU. Maybe >>> this isn't were I should have been looking though? > > The interesting part is in nested_svm_vmexit. There you have this piece > of code: > > /* > * If we emulate a VMRUN/#VMEXIT in the same host #vmexit cycle we have > * to make sure that we do not lose injected events. So check event_inj > * here and copy it to exit_int_info if it is valid. > * Exit_int_info and event_inj can't be both valid because the case > * below only happens on a VMRUN instruction intercept which has > * no valid exit_int_info set. > */ > if (vmcb->control.event_inj & SVM_EVTINJ_VALID) { > struct vmcb_control_area *nc = &nested_vmcb->control; > > nc->exit_int_info = vmcb->control.event_inj; > nc->exit_int_info_err = vmcb->control.event_inj_err; > } > > and a few lines later: > > nested_vmcb->control.event_inj = 0; > nested_vmcb->control.event_inj_err = 0; > > ... which takes care of this situation. The vmcb.eventinf field is _defined_ to > be zero on a #vmexit. (Hmm, must have missed that line in the spec.) In that case something like should resolve the QEMU issue, right? Jan diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c index dcbdfe7..caabdb4 100644 --- a/target-i386/op_helper.c +++ b/target-i386/op_helper.c @@ -1263,13 +1263,6 @@ void do_interrupt(int intno, int is_int, int error_code, #endif do_interrupt_real(intno, is_int, error_code, next_eip); } - -#if !defined(CONFIG_USER_ONLY) - if (env->hflags & HF_SVMI_MASK) { - uint32_t event_inj = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj)); - stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj), event_inj & ~SVM_EVTINJ_VALID); - } -#endif } /* This should come from sysemu.h - if we could include it here... */ @@ -5388,6 +5381,7 @@ void helper_vmexit(uint32_t exit_code, uint64_t exit_info_1) ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj))); stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_int_info_err), ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj_err))); + stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj), 0); env->hflags2 &= ~HF2_GIF_MASK; /* FIXME: Resets the current ASID register to zero (host ASID). */