mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xiaoyao Li <xiaoyao.li@intel.com>
To: Hao Xiang <hao.xiang@linux.alibaba.com>, kvm@vger.kernel.org
Cc: shannon.zhao@linux.alibaba.com, pbonzini@redhat.com,
	seanjc@google.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kvm: x86: emulate MSR_PLATFORM_INFO msr bits
Date: Wed, 23 Aug 2023 11:41:46 +0800	[thread overview]
Message-ID: <cf7c7ab6-0907-2eea-bf9c-0811f8ec6c59@intel.com> (raw)
In-Reply-To: <1692588151-33716-1-git-send-email-hao.xiang@linux.alibaba.com>

On 8/21/2023 11:22 AM, Hao Xiang wrote:
> For intel platform, The BzyMhz field of Turbostat shows zero
> due to the missing of part msr bits of MSR_PLATFORM_INFO.
> 
> Acquire necessary msr bits, and expose following msr info to guest,
> to make sure guest can get correct turbo frequency info.
>
> MSR_PLATFORM_INFO bits
> bit 15:8, Maximum Non-Turbo Ratio (MAX_NON_TURBO_LIM_RATIO)
> bit 47:40, Maximum Efficiency Ratio (MAX_EFFICIENCY_RATIO)

I'm curious. How are they related to turbo frequency info?

bits 15:8, tell the Non-turbo frequency and bits 47:40 tells the min 
frequency.

> Signed-off-by: Hao Xiang <hao.xiang@linux.alibaba.com>
> ---
>   arch/x86/include/asm/msr-index.h |  4 ++++
>   arch/x86/kvm/x86.c               | 25 ++++++++++++++++++++++++-
>   2 files changed, 28 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
> index 1d11135..1c8a276 100644
> --- a/arch/x86/include/asm/msr-index.h
> +++ b/arch/x86/include/asm/msr-index.h
> @@ -68,6 +68,10 @@
>   #define MSR_PLATFORM_INFO		0x000000ce
>   #define MSR_PLATFORM_INFO_CPUID_FAULT_BIT	31
>   #define MSR_PLATFORM_INFO_CPUID_FAULT		BIT_ULL(MSR_PLATFORM_INFO_CPUID_FAULT_BIT)
> +/* MSR_PLATFORM_INFO bit 15:8, Maximum Non-Turbo Ratio (MAX_NON_TURBO_LIM_RATIO) */
> +#define MSR_PLATFORM_INFO_MAX_NON_TURBO_LIM_RATIO	0x00000000ff00
> +/* MSR_PLATFORM_INFO bit 47:40, Maximum Efficiency Ratio (MAX_EFFICIENCY_RATIO) */
> +#define MSR_PLATFORM_INFO_MAX_EFFICIENCY_RATIO		0xff0000000000

They are mask not the value, please name them with _MASK suffix.

>   
>   #define MSR_IA32_UMWAIT_CONTROL			0xe1
>   #define MSR_IA32_UMWAIT_CONTROL_C02_DISABLE	BIT(0)
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index c381770..621c3e1 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -1679,6 +1679,29 @@ static u64 kvm_get_arch_capabilities(void)
>   	return data;
>   }
>   
> +
> +static u64 kvm_get_msr_platform_info(void)
> +{
> +	u64 msr_platform_info = 0;
> +
> +	rdmsrl_safe(MSR_PLATFORM_INFO, &msr_platform_info);
> +	/*
> +	 * MSR_PLATFORM_INFO bits:
> +	 * bit 15:8, Maximum Non-Turbo Ratio (MAX_NON_TURBO_LIM_RATIO)
> +	 * bit 31, CPUID Faulting Enabled (CPUID_FAULTING_EN)
> +	 * bit 47:40, Maximum Efficiency Ratio (MAX_EFFICIENCY_RATIO)
> +	 *
> +	 * Emulate part msr bits, expose above msr info to guest,
> +	 * to make sure guest can get correct turbo frequency info.
> +	 */
> +
> +	msr_platform_info &= (MSR_PLATFORM_INFO_MAX_NON_TURBO_RATIO |
> +			MSR_PLATFORM_INFO_MAX_EFFICIENCY_RATIO);
> +	msr_platform_info |= MSR_PLATFORM_INFO_CPUID_FAULT;
> +
> +	return msr_platform_info;
> +}
> +
>   static int kvm_get_msr_feature(struct kvm_msr_entry *msr)
>   {
>   	switch (msr->index) {
> @@ -11919,7 +11942,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
>   		goto free_guest_fpu;
>   
>   	vcpu->arch.arch_capabilities = kvm_get_arch_capabilities();
> -	vcpu->arch.msr_platform_info = MSR_PLATFORM_INFO_CPUID_FAULT;
> +	vcpu->arch.msr_platform_info = kvm_get_msr_platform_info();
>   	kvm_xen_init_vcpu(vcpu);
>   	kvm_vcpu_mtrr_init(vcpu);
>   	vcpu_load(vcpu);


  parent reply	other threads:[~2023-08-23  3:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-21  3:22 Hao Xiang
2023-08-22 16:50 ` kernel test robot
2023-08-23  0:26 ` kernel test robot
2023-08-23  3:41 ` Xiaoyao Li [this message]
2023-08-21  3:26 Hao Xiang
2023-08-21  7:52 ` Chao Gao
2023-08-21  9:11   ` Hao Xiang
2023-08-21 10:44     ` Chao Gao
2023-08-21 11:44       ` Hao Xiang
2023-08-21 16:11         ` Sean Christopherson
2023-08-23  6:24           ` Xiaoyao Li
2023-08-23 14:31             ` Sean Christopherson
2023-08-25  3:27               ` Xiaoyao Li

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=cf7c7ab6-0907-2eea-bf9c-0811f8ec6c59@intel.com \
    --to=xiaoyao.li@intel.com \
    --cc=hao.xiang@linux.alibaba.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=shannon.zhao@linux.alibaba.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®