From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: NMI Injection to Guest Date: Mon, 27 Jul 2009 08:19:02 +0300 Message-ID: <20090727051902.GB20501@redhat.com> References: <6d8082040907251346h79430f03nb31e762da29c665d@mail.gmail.com> <20090726054705.GI7928@redhat.com> <6d8082040907261225u6c5a7012jc9c3492e29e7feb1@mail.gmail.com> <4cb7f2290907261241h34fb0937ia5244b3c1cc58a47@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Jiaqing Du , kvm@vger.kernel.org To: Nipun sehrawat Return-path: Received: from mx2.redhat.com ([66.187.237.31]:35051 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751284AbZG0FTF convert rfc822-to-8bit (ORCPT ); Mon, 27 Jul 2009 01:19:05 -0400 Content-Disposition: inline In-Reply-To: <4cb7f2290907261241h34fb0937ia5244b3c1cc58a47@mail.gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, Jul 27, 2009 at 01:11:46AM +0530, Nipun sehrawat wrote: > Hi all, >=20 > What about using vmx_inject_nmi(vcpu) to inject the NMIs into the > guest, when we are sure about the vcpu on which the NMI is to be > injected. >=20 The only save place to call it is were it is called now. If you want vmx_inject_nmi(vcpu) to be called set vcpu->arch.nmi_pending to 1. > Nipun >=20 > On Mon, Jul 27, 2009 at 12:55 AM, Jiaqing Du wrot= e: > > > > Hi Gleb, > > > > Thanks for your reply. > > > > 2009/7/26 Gleb Natapov : > > > On Sat, Jul 25, 2009 at 10:46:39PM +0200, Jiaqing Du wrote: > > >> Hi list, > > >> > > >> I'm trying to extend OProfile to support guest profiling. One st= ep of > > >> my work is to push an NMI to the guest(s) when a performance cou= nter > > >> overflows. Please correct me if the following is not correct: > > >> > > >> counter overflow --> NMI to host --> VM exit --> "int $2" to han= dle > > >> NMI on host --> ... =9A --> VM entry --> NMI to guest > > >> > > > Correct except the last step (--> NMI to guest). Host nmi is not > > > propagated to guests. > > > > Yes. I need to add some code to propagate host NMI to guests. > > > > > >> On the path between VM-exit and VM-entry, I want to push an NMI = to the > > >> guest. I tried to put the following code on the path, but never > > >> succeeded. Various wired things happened, such as KVM hangs, gue= st > > >> kernel oops, and host hangs. I tried both code with Linux 2.6.30= and > > >> version 88. > > >> > > >> if (vmx_nmi_allowed()) =9A{ vmx_inject_nmi(); } > > >> > > >> Any suggestions? Where is the right place to push an NMI and wha= t are > > >> the necessary checks? > > > Call kvm_inject_nmi(vcpu). And don't forget to vcpu_load(vcpu) be= fore > > > doing it. See kvm_vcpu_ioctl_nmi(). > > > > Based on the code with Linux 2.6.30, what kvm_inject_nmi(vcpu) does= is > > just set vcpu->arch.nmi_pending to 1. kvm_vcpu_ioctl_nmi() puts > > vcpu_load() before the setting and vcpu_put() after it. > > > > I need to push host NMI to guests between a VM-exit and a VM-entry > > after that. The VM-exit is due to an NMI caused by performance coun= ter > > overflow. The following code with vcpu_enter_guest(), which is > > surrounded by a vcpu_load() and vcpu_put(), checks this > > vcpu->arch.nmi_pending and other related flags to decide whether an > > NMI should be pushed to guests. > > > > =9A =9A =9A =9Aif (vcpu->arch.exception.pending) > > =9A =9A =9A =9A =9A =9A =9A =9A__queue_exception(vcpu); > > =9A =9A =9A =9Aelse if (irqchip_in_kernel(vcpu->kvm)) > > =9A =9A =9A =9A =9A =9A =9A =9Akvm_x86_ops->inject_pending_irq(vcpu= ); > > =9A =9A =9A =9Aelse > > =9A =9A =9A =9A =9A =9A =9A =9Akvm_x86_ops->inject_pending_vectors(= vcpu, kvm_run); > > > > What I did is given below: > > > > 3097 static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_= run *kvm_run) > > 3098 { > > =9A =9A =9A =9A =9A =9A =9A ... ... > > > > 3156 =9A =9A =9A =9A if (kvm_vm_exit_on_cnt_overflow) { > > 3157 =9A =9A =9A =9A =9A =9A =9A =9A vcpu->arch.nmi_pending =3D 1; > > 3158 =9A =9A =9A =9A } > > 3159 > > 3160 =9A =9A =9A =9A if (vcpu->arch.exception.pending) > > 3161 =9A =9A =9A =9A =9A =9A =9A =9A __queue_exception(vcpu); > > 3162 =9A =9A =9A =9A else if (irqchip_in_kernel(vcpu->kvm)) > > 3163 =9A =9A =9A =9A =9A =9A =9A =9A kvm_x86_ops->inject_pending_ir= q(vcpu); > > 3164 =9A =9A =9A =9A else > > 3165 =9A =9A =9A =9A =9A =9A =9A =9A kvm_x86_ops->inject_pending_ve= ctors(vcpu, kvm_run); > > > > =9A =9A =9A =9A =9A =9A =9A... .... > > 3236 } > > > > In vcpu_enter_guest(), before this part of code is reached, > > vcpu->arch.nmi_pending is set to 1 if the VM-exit is due to > > performance counter overflow. Still, no NMIs are seen by the guests= =2E I > > also tried to put this "vcpu->arch.nmi_pending =3D 1;" somewhere el= se on > > the path between a VM-exit and VM-entry, it does not seem to work > > neither. Only vmx_inject_nmi() manages to push NMIs to guests, but > > without right sanity checks, it causes various wired host and guest > > behaviors. > > > > To inject NMIs on the path between a VM-exit and VM-entry, what's t= o try next? > > > > > > > > -- > > > =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9AGleb. > > > > > > > Thanks, > > Jiaqing > > -- > > To unsubscribe from this list: send the line "unsubscribe kvm" in > > the body of a message to majordomo@vger.kernel.org > > More majordomo info at =9Ahttp://vger.kernel.org/majordomo-info.htm= l -- Gleb.