From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joerg Roedel Subject: Re: [PATCH 09/10] KVM: SVM: Make lazy FPU switching work with nested svm Date: Thu, 18 Feb 2010 17:29:35 +0100 Message-ID: <20100218162935.GR22141@amd.com> References: <1266493115-28386-1-git-send-email-joerg.roedel@amd.com> <1266493115-28386-10-git-send-email-joerg.roedel@amd.com> <4B7D4F62.3010903@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Cc: Marcelo Tosatti , kvm@vger.kernel.org, linux-kernel@vger.kernel.org To: Avi Kivity Return-path: Received: from tx2ehsobe002.messaging.microsoft.com ([65.55.88.12]:27238 "EHLO TX2EHSOBE004.bigfish.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757631Ab0BRQ3t (ORCPT ); Thu, 18 Feb 2010 11:29:49 -0500 Content-Disposition: inline In-Reply-To: <4B7D4F62.3010903@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Thu, Feb 18, 2010 at 04:32:02PM +0200, Avi Kivity wrote: > On 02/18/2010 01:38 PM, Joerg Roedel wrote: > >TDB. > > > > ... > > >@@ -973,6 +973,7 @@ static void svm_decache_cr4_guest_bits(struct kvm_vcpu *vcpu) > > > > static void update_cr0_intercept(struct vcpu_svm *svm) > > { > >+ struct vmcb *vmcb = svm->vmcb; > > ulong gcr0 = svm->vcpu.arch.cr0; > > u64 *hcr0 =&svm->vmcb->save.cr0; > > > >@@ -984,11 +985,25 @@ static void update_cr0_intercept(struct vcpu_svm *svm) > > > > > > if (gcr0 == *hcr0&& svm->vcpu.fpu_active) { > >- svm->vmcb->control.intercept_cr_read&= ~INTERCEPT_CR0_MASK; > >- svm->vmcb->control.intercept_cr_write&= ~INTERCEPT_CR0_MASK; > >+ vmcb->control.intercept_cr_read&= ~INTERCEPT_CR0_MASK; > >+ vmcb->control.intercept_cr_write&= ~INTERCEPT_CR0_MASK; > >+ if (is_nested(svm)) { > >+ struct vmcb *hsave = svm->nested.hsave; > >+ > >+ hsave->control.intercept_cr_read&= ~INTERCEPT_CR0_MASK; > >+ hsave->control.intercept_cr_write&= ~INTERCEPT_CR0_MASK; > >+ vmcb->control.intercept_cr_read |= svm->nested.intercept_cr_read; > >+ vmcb->control.intercept_cr_write |= svm->nested.intercept_cr_write; > > Why are the last two lines needed? Because we don't know if the l1 hypervisor wants to intercept cr0. In this case we need this intercept to stay enabled. > >+ } > > } else { > > svm->vmcb->control.intercept_cr_read |= INTERCEPT_CR0_MASK; > > svm->vmcb->control.intercept_cr_write |= INTERCEPT_CR0_MASK; > >+ if (is_nested(svm)) { > >+ struct vmcb *hsave = svm->nested.hsave; > >+ > >+ hsave->control.intercept_cr_read |= INTERCEPT_CR0_MASK; > >+ hsave->control.intercept_cr_write |= INTERCEPT_CR0_MASK; > >+ } > > } > > } > > Maybe it's better to call update_cr0_intercept() after a vmexit > instead, to avoid this repetition, and since the if () may take a > different branch for the nested guest and guest cr0. Thinking again about it I am not sure if this is needed at all. At vmexit emulation we call svm_set_cr0 which itself calls update_cr0_intercept. I'll try this. Joerg