All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Cathy Avery <cavery@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	pbonzini@redhat.com, vkuznets@redhat.com, wei.huang2@amd.com
Subject: Re: [PATCH] KVM: nSVM: Additions to optimizing L12 to L2 vmcb.save copies
Date: Tue, 23 Mar 2021 16:08:47 +0000	[thread overview]
Message-ID: <YFoSj9xmCzHe0/X7@google.com> (raw)
In-Reply-To: <20210317162930.28135-1-cavery@redhat.com>

On Wed, Mar 17, 2021, Cathy Avery wrote:
> Extend using the vmcb12 control clean field to determine which
> vmcb12.save registers were marked dirty in order to minimize
> register copies by including the CR bit.
> 
> This patch also fixes the init of last_vmcb12_gpa by using an invalid
> physical address instead of 0.
> 
> Tested:
> kvm-unit-tests
> kvm selftests
> Fedora L1 L2
> 
> Signed-off-by: Cathy Avery <cavery@redhat.com>
> ---
>  arch/x86/kvm/svm/nested.c | 9 ++++++---
>  arch/x86/kvm/svm/svm.c    | 2 +-
>  2 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> index 8523f60adb92..6f9a40e002bc 100644
> --- a/arch/x86/kvm/svm/nested.c
> +++ b/arch/x86/kvm/svm/nested.c
> @@ -449,9 +449,12 @@ static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *vmcb12
>  	}
>  
>  	kvm_set_rflags(&svm->vcpu, vmcb12->save.rflags | X86_EFLAGS_FIXED);
> -	svm_set_efer(&svm->vcpu, vmcb12->save.efer);
> -	svm_set_cr0(&svm->vcpu, vmcb12->save.cr0);
> -	svm_set_cr4(&svm->vcpu, vmcb12->save.cr4);
> +
> +	if (unlikely(new_vmcb12 || vmcb_is_dirty(vmcb12, VMCB_CR))) {
> +		svm_set_efer(&svm->vcpu, vmcb12->save.efer);
> +		svm_set_cr0(&svm->vcpu, vmcb12->save.cr0);
> +		svm_set_cr4(&svm->vcpu, vmcb12->save.cr4);

This doesn't seem correct.  Regardless of when vmcb12 was last touched, KVM
still needs to set L2's state in vcpu->arch and set the correct MMU context.

> +	}
>  
>  	svm->vcpu.arch.cr2 = vmcb12->save.cr2;
>  
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 271196400495..41f5cd1009ca 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -1234,7 +1234,7 @@ static void init_vmcb(struct kvm_vcpu *vcpu)
>  	svm->asid = 0;
>  
>  	svm->nested.vmcb12_gpa = 0;
> -	svm->nested.last_vmcb12_gpa = 0;
> +	svm->nested.last_vmcb12_gpa = -1;

INVALID_PAGE would be even better.

>  	vcpu->arch.hflags = 0;
>  
>  	if (!kvm_pause_in_guest(vcpu->kvm)) {
> -- 
> 2.26.2
> 

      reply	other threads:[~2021-03-23 16:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17 16:29 [PATCH] KVM: nSVM: Additions to optimizing L12 to L2 vmcb.save copies Cathy Avery
2021-03-23 16:08 ` Sean Christopherson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YFoSj9xmCzHe0/X7@google.com \
    --to=seanjc@google.com \
    --cc=cavery@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=vkuznets@redhat.com \
    --cc=wei.huang2@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.