From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752452Ab0DWOTq (ORCPT ); Fri, 23 Apr 2010 10:19:46 -0400 Received: from cantor2.suse.de ([195.135.220.15]:43078 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751314Ab0DWOTp convert rfc822-to-8bit (ORCPT ); Fri, 23 Apr 2010 10:19:45 -0400 Subject: Re: [PATCH 1/8] KVM: SVM: Fix nested nmi handling Mime-Version: 1.0 (Apple Message framework v1078) Content-Type: text/plain; charset=us-ascii From: Alexander Graf In-Reply-To: <20100423141355.GD31537@amd.com> Date: Fri, 23 Apr 2010 16:19:40 +0200 Cc: Avi Kivity , Marcelo Tosatti , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8BIT Message-Id: <85D89C34-806C-4376-89BA-5BFD413F5396@suse.de> References: <1271932394-13968-1-git-send-email-joerg.roedel@amd.com> <1271932394-13968-2-git-send-email-joerg.roedel@amd.com> <622FCBB5-826D-4392-A521-7E395507398B@suse.de> <20100423141355.GD31537@amd.com> To: Joerg Roedel X-Mailer: Apple Mail (2.1078) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23.04.2010, at 16:13, Joerg Roedel wrote: > On Fri, Apr 23, 2010 at 03:46:07PM +0200, Alexander Graf wrote: >> >> On 22.04.2010, at 12:33, Joerg Roedel wrote: >> >>> The patch introducing nested nmi handling had a bug. The >>> check does not belong to enable_nmi_window but must be in >>> nmi_allowed. This patch fixes this. >>> >>> Signed-off-by: Joerg Roedel >>> --- >>> arch/x86/kvm/svm.c | 16 +++++++++------- >>> 1 files changed, 9 insertions(+), 7 deletions(-) >>> >>> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c >>> index ab78eb8..ec20584 100644 >>> --- a/arch/x86/kvm/svm.c >>> +++ b/arch/x86/kvm/svm.c >>> @@ -2771,8 +2771,12 @@ static int svm_nmi_allowed(struct kvm_vcpu *vcpu) >>> { >>> struct vcpu_svm *svm = to_svm(vcpu); >>> struct vmcb *vmcb = svm->vmcb; >>> - return !(vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) && >>> - !(svm->vcpu.arch.hflags & HF_NMI_MASK); >>> + int ret; >>> + ret = !(vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) && >>> + !(svm->vcpu.arch.hflags & HF_NMI_MASK); >>> + ret = ret && gif_set(svm) && nested_svm_nmi(svm); >>> + >>> + return ret; >>> } >>> >>> static bool svm_get_nmi_mask(struct kvm_vcpu *vcpu) >>> @@ -2841,11 +2845,9 @@ static void enable_nmi_window(struct kvm_vcpu *vcpu) >>> * Something prevents NMI from been injected. Single step over possible >>> * problem (IRET or exception injection or interrupt shadow) >>> */ >>> - if (gif_set(svm) && nested_svm_nmi(svm)) { >>> - svm->nmi_singlestep = true; >>> - svm->vmcb->save.rflags |= (X86_EFLAGS_TF | X86_EFLAGS_RF); >>> - update_db_intercept(vcpu); >>> - } >>> + svm->nmi_singlestep = true; >>> + svm->vmcb->save.rflags |= (X86_EFLAGS_TF | X86_EFLAGS_RF); >>> + update_db_intercept(vcpu); >> >> So we're always messing with the nested guest state when the host >> wants to inject an nmi into the l1 guest? Is that safe? > > Why not? We can't inject an NMI directly into L2 if the nested > hypervisor intercepts it. So where did the code go that does the #vmexit in case the nested hypervisor does intercept it? It used to be nested_svm_nmi(), right? Alex