All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] KVM: x86: allow KVM_REQ_GET_NESTED_STATE_PAGES outside guest mode for VMX
Date: Mon, 25 Jan 2021 11:16:46 -0800	[thread overview]
Message-ID: <YA8ZHrh9ca0lPJgk@google.com> (raw)
In-Reply-To: <20210125172044.1360661-1-pbonzini@redhat.com>

On Mon, Jan 25, 2021, Paolo Bonzini wrote:
> +static bool nested_get_vmcs12_pages(struct kvm_vcpu *vcpu)
> +{
> +	struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
> +	struct vcpu_vmx *vmx = to_vmx(vcpu);
> +	struct kvm_host_map *map;
> +	struct page *page;
> +	u64 hpa;
> +
> +	if (!nested_get_evmcs_page(vcpu))
> +		return false;
>  
>  	if (nested_cpu_has2(vmcs12, SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES)) {
>  		/*
> @@ -3224,6 +3233,17 @@ static bool nested_get_vmcs12_pages(struct kvm_vcpu *vcpu)
>  	return true;
>  }
>  
> +static bool vmx_get_nested_state_pages(struct kvm_vcpu *vcpu)
> +{
> +	if (!nested_get_evmcs_page(vcpu))
> +		return false;
> +
> +	if (is_guest_mode(vcpu) && !nested_get_vmcs12_pages(vcpu))
> +		return false;

nested_get_evmcs_page() will get called twice in the common case of
is_guest_mode() == true.  I can't tell if that will ever be fatal, but it's
definitely weird.  Maybe this?

	if (!is_guest_mode(vcpu))
		return nested_get_evmcs_page(vcpu);

	return nested_get_vmcs12_pages(vcpu);

> +
> +	return true;
> +}
> +
>  static int nested_vmx_write_pml_buffer(struct kvm_vcpu *vcpu, gpa_t gpa)
>  {
>  	struct vmcs12 *vmcs12;
> @@ -6602,7 +6622,7 @@ struct kvm_x86_nested_ops vmx_nested_ops = {
>  	.hv_timer_pending = nested_vmx_preemption_timer_pending,
>  	.get_state = vmx_get_nested_state,
>  	.set_state = vmx_set_nested_state,
> -	.get_nested_state_pages = nested_get_vmcs12_pages,
> +	.get_nested_state_pages = vmx_get_nested_state_pages,
>  	.write_log_dirty = nested_vmx_write_pml_buffer,
>  	.enable_evmcs = nested_enable_evmcs,
>  	.get_evmcs_version = nested_get_evmcs_version,
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 9a8969a6dd06..b910aa74ee05 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -8802,9 +8802,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
>  
>  	if (kvm_request_pending(vcpu)) {
>  		if (kvm_check_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu)) {
> -			if (WARN_ON_ONCE(!is_guest_mode(vcpu)))
> -				;
> -			else if (unlikely(!kvm_x86_ops.nested_ops->get_nested_state_pages(vcpu))) {
> +			if (unlikely(!kvm_x86_ops.nested_ops->get_nested_state_pages(vcpu))) {
>  				r = 0;
>  				goto out;
>  			}
> -- 
> 2.26.2
> 

  reply	other threads:[~2021-01-25 19:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-25 17:20 [PATCH] KVM: x86: allow KVM_REQ_GET_NESTED_STATE_PAGES outside guest mode for VMX Paolo Bonzini
2021-01-25 19:16 ` Sean Christopherson [this message]
2021-01-25 19:35   ` Paolo Bonzini
2021-01-25 19:53     ` Sean Christopherson
2021-01-25 21:59       ` Paolo Bonzini

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=YA8ZHrh9ca0lPJgk@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=stable@vger.kernel.org \
    /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.