mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xiaoyao Li <xiaoyao.li@intel.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Kai Huang <kai.huang@intel.com>, Shan Kang <shan.kang@intel.com>,
	Xin Li <xin3.li@intel.com>, Zhao Liu <zhao1.liu@intel.com>
Subject: Re: [PATCH v7 07/10] KVM: nVMX: Add a helper to encode VMCS info in MSR_IA32_VMX_BASIC
Date: Wed, 22 May 2024 14:54:33 +0800	[thread overview]
Message-ID: <783061e3-51ad-46f3-aca8-73cebf603e27@intel.com> (raw)
In-Reply-To: <20240520175925.1217334-8-seanjc@google.com>

On 5/21/2024 1:59 AM, Sean Christopherson wrote:
> Add a helper to encode the VMCS revision, size, and supported memory types
> in MSR_IA32_VMX_BASIC, i.e. when synthesizing KVM's supported BASIC MSR
> value, and delete the now unused VMCS size and memtype shift macros.
> 
> For a variety of reasons, KVM has shifted (pun intended) to using helpers
> to *get* information from the VMX MSRs, as opposed to defined MASK and
> SHIFT macros for direct use.  Provide a similar helper for the nested VMX
> code, which needs to *set* information, so that KVM isn't left with a mix
> of SHIFT macros and dedicated helpers.
> 
> Reported-by: Xiaoyao Li <xiaoyao.li@intel.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>

> ---
>   arch/x86/include/asm/vmx.h | 7 +++++--
>   arch/x86/kvm/vmx/nested.c  | 8 +++-----
>   2 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
> index 90963b14afaa..65aaf0577265 100644
> --- a/arch/x86/include/asm/vmx.h
> +++ b/arch/x86/include/asm/vmx.h
> @@ -135,10 +135,8 @@
>   #define VMX_VMFUNC_EPTP_SWITCHING               VMFUNC_CONTROL_BIT(EPTP_SWITCHING)
>   #define VMFUNC_EPTP_ENTRIES  512
>   
> -#define VMX_BASIC_VMCS_SIZE_SHIFT		32
>   #define VMX_BASIC_32BIT_PHYS_ADDR_ONLY		BIT_ULL(48)
>   #define VMX_BASIC_DUAL_MONITOR_TREATMENT	BIT_ULL(49)
> -#define VMX_BASIC_MEM_TYPE_SHIFT		50
>   #define VMX_BASIC_INOUT				BIT_ULL(54)
>   #define VMX_BASIC_TRUE_CTLS			BIT_ULL(55)
>   
> @@ -157,6 +155,11 @@ static inline u32 vmx_basic_vmcs_mem_type(u64 vmx_basic)
>   	return (vmx_basic & GENMASK_ULL(53, 50)) >> 50;
>   }
>   
> +static inline u64 vmx_basic_encode_vmcs_info(u32 revision, u16 size, u8 memtype)
> +{
> +	return revision | ((u64)size << 32) | ((u64)memtype << 50);
> +}
> +
>   static inline int vmx_misc_preemption_timer_rate(u64 vmx_misc)
>   {
>   	return vmx_misc & VMX_MISC_PREEMPTION_TIMER_RATE_MASK;
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index fbfd3c5cb541..d690fa720dcf 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -7035,12 +7035,10 @@ static void nested_vmx_setup_basic(struct nested_vmx_msrs *msrs)
>   	 * guest, and the VMCS structure we give it - not about the
>   	 * VMX support of the underlying hardware.
>   	 */
> -	msrs->basic =
> -		VMCS12_REVISION |
> -		VMX_BASIC_TRUE_CTLS |
> -		((u64)VMCS12_SIZE << VMX_BASIC_VMCS_SIZE_SHIFT) |
> -		(X86_MEMTYPE_WB << VMX_BASIC_MEM_TYPE_SHIFT);
> +	msrs->basic = vmx_basic_encode_vmcs_info(VMCS12_REVISION, VMCS12_SIZE,
> +						 X86_MEMTYPE_WB);
>   
> +	msrs->basic |= VMX_BASIC_TRUE_CTLS;
>   	if (cpu_has_vmx_basic_inout())
>   		msrs->basic |= VMX_BASIC_INOUT;
>   }


  parent reply	other threads:[~2024-05-22  6:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-20 17:59 [PATCH v7 00/10] x86/cpu: KVM: Clean up PAT and VMX macros Sean Christopherson
2024-05-20 17:59 ` [PATCH v7 01/10] x86/cpu: KVM: Add common defines for architectural memory types (PAT, MTRRs, etc.) Sean Christopherson
2024-05-20 17:59 ` [PATCH v7 02/10] x86/cpu: KVM: Move macro to encode PAT value to common header Sean Christopherson
2024-05-20 17:59 ` [PATCH v7 03/10] KVM: x86: Stuff vCPU's PAT with default value at RESET, not creation Sean Christopherson
2024-05-20 18:01   ` Jim Mattson
2024-05-20 17:59 ` [PATCH v7 04/10] KVM: VMX: Move MSR_IA32_VMX_BASIC bit defines to asm/vmx.h Sean Christopherson
2024-05-22  6:48   ` Xiaoyao Li
2024-05-22  7:07     ` Xiaoyao Li
2024-05-20 17:59 ` [PATCH v7 05/10] KVM: VMX: Track CPU's MSR_IA32_VMX_BASIC as a single 64-bit value Sean Christopherson
2024-05-20 17:59 ` [PATCH v7 06/10] KVM: nVMX: Use macros and #defines in vmx_restore_vmx_basic() Sean Christopherson
2024-05-20 17:59 ` [PATCH v7 07/10] KVM: nVMX: Add a helper to encode VMCS info in MSR_IA32_VMX_BASIC Sean Christopherson
2024-05-20 23:16   ` Huang, Kai
2024-05-22  6:54   ` Xiaoyao Li [this message]
2024-05-20 17:59 ` [PATCH v7 08/10] KVM VMX: Move MSR_IA32_VMX_MISC bit defines to asm/vmx.h Sean Christopherson
2024-05-22  7:09   ` Xiaoyao Li
2024-06-05 15:38     ` Sean Christopherson
2024-05-20 17:59 ` [PATCH v7 09/10] KVM: VMX: Open code VMX preemption timer rate mask in its accessor Sean Christopherson
2024-05-20 17:59 ` [PATCH v7 10/10] KVM: nVMX: Use macros and #defines in vmx_restore_vmx_misc() Sean Christopherson

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=783061e3-51ad-46f3-aca8-73cebf603e27@intel.com \
    --to=xiaoyao.li@intel.com \
    --cc=kai.huang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=shan.kang@intel.com \
    --cc=xin3.li@intel.com \
    --cc=zhao1.liu@intel.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®