mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Vitaly Kuznetsov <vkuznets@redhat.com>, kvm@vger.kernel.org
Cc: Sean Christopherson <seanjc@google.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Wei Huang <wei.huang2@amd.com>,
	Joerg Roedel <joro@8bytes.org>,
	Haiwei Li <lihaiwei.kernel@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: x86/vPMU: Forbid reading from MSR_F15H_PERF MSRs when guest doesn't have X86_FEATURE_PERFCTR_CORE
Date: Tue, 30 Mar 2021 19:10:30 +0200	[thread overview]
Message-ID: <3a741047-48a7-ee72-27ec-f83b0b7669f6@redhat.com> (raw)
In-Reply-To: <20210329124804.170173-1-vkuznets@redhat.com>

On 29/03/21 14:48, Vitaly Kuznetsov wrote:
> MSR_F15H_PERF_CTL0-5, MSR_F15H_PERF_CTR0-5 MSRs have a CPUID bit assigned
> to them (X86_FEATURE_PERFCTR_CORE) and when it wasn't exposed to the guest
> the correct behavior is to inject #GP an not just return zero.
> 
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>   arch/x86/kvm/x86.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index fe806e894212..125453155ede 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -3381,6 +3381,12 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
>   		msr_info->data = 0;
>   		break;
>   	case MSR_F15H_PERF_CTL0 ... MSR_F15H_PERF_CTR5:
> +		if (kvm_pmu_is_valid_msr(vcpu, msr_info->index))
> +			return kvm_pmu_get_msr(vcpu, msr_info);
> +		if (!msr_info->host_initiated)
> +			return 1;
> +		msr_info->data = 0;
> +		break;
>   	case MSR_K7_EVNTSEL0 ... MSR_K7_EVNTSEL3:
>   	case MSR_K7_PERFCTR0 ... MSR_K7_PERFCTR3:
>   	case MSR_P6_PERFCTR0 ... MSR_P6_PERFCTR1:
> 

Queued to kvm/next, thanks (the write side goes to kvm/master instead).

Paolo


      reply	other threads:[~2021-03-30 17:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-29 12:48 Vitaly Kuznetsov
2021-03-30 17:10 ` Paolo Bonzini [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=3a741047-48a7-ee72-27ec-f83b0b7669f6@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=lihaiwei.kernel@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®