public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Like Xu <like.xu@linux.intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org, Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Joerg Roedel <joro@8bytes.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM/x86: pmu: Fix #GP condition check for RDPMC emulation
Date: Wed, 8 Jul 2020 08:18:25 -0700	[thread overview]
Message-ID: <20200708151824.GA22737@linux.intel.com> (raw)
In-Reply-To: <20200708074409.39028-1-like.xu@linux.intel.com>

On Wed, Jul 08, 2020 at 03:44:09PM +0800, Like Xu wrote:
> in guest protected mode, if the current privilege level
> is not 0 and the pce flag in the cr4 register is cleared,
> we will inject a #gp for rdpmc usage.

Wrapping at ~58 characters is a bit aggressive.  checkpatch enforces 75
chars, something near that would be prefereable.

> Signed-off-by: Like Xu <like.xu@linux.intel.com>
> ---
>  arch/x86/kvm/pmu.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index b86346903f2e..d080d475c808 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -372,6 +372,11 @@ int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned idx, u64 *data)
>  	if (!pmc)
>  		return 1;
>  
> +	if ((kvm_x86_ops.get_cpl(vcpu) != 0) &&
> +	    !(kvm_read_cr4(vcpu) & X86_CR4_PCE) &&
> +	    (kvm_read_cr4(vcpu) & X86_CR0_PE))

This reads CR4 but checks CR0.PE.

And maybe put the X86_CR4_PCE check first so that it's the focus of the
statement?

> +		return 1;
> +
>  	*data = pmc_read_counter(pmc) & mask;
>  	return 0;
>  }
> -- 
> 2.21.3
> 

  reply	other threads:[~2020-07-08 15:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-08  7:44 [PATCH] KVM/x86: pmu: Fix #GP condition check for RDPMC emulation Like Xu
2020-07-08 15:18 ` Sean Christopherson [this message]
2020-07-08 15:31   ` Paolo Bonzini
2020-07-08 15:45     ` Sean Christopherson
2020-07-08 15:54       ` 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=20200708151824.GA22737@linux.intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=like.xu@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox