Re: [PATCH v6 5/9] KVM: VMX: Track CPU's MSR_IA32_VMX_BASIC as a single 64-bit value

From: Zhao Liu
Date: Fri Mar 15 2024 - 11:13:14 EST


Hi Sean,

On Fri, Mar 08, 2024 at 05:27:21PM -0800, Sean Christopherson wrote:
> Date: Fri, 8 Mar 2024 17:27:21 -0800
> From: Sean Christopherson <seanjc@xxxxxxxxxx>
> Subject: [PATCH v6 5/9] KVM: VMX: Track CPU's MSR_IA32_VMX_BASIC as a
> single 64-bit value
> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog
>
> Track the "basic" capabilities VMX MSR as a single u64 in vmcs_config
> instead of splitting it across three fields, that obviously don't combine
> into a single 64-bit value, so that KVM can use the macros that define MSR
> bits using their absolute position. Replace all open coded shifts and
> masks, many of which are relative to the "high" half, with the appropriate
> macro.
>
> Opportunistically use VMX_BASIC_32BIT_PHYS_ADDR_ONLY instead of an open
> coded equivalent, and clean up the related comment to not reference a
> specific SDM section (to the surprise of no one, the comment is stale).
>
> No functional change intended (though obviously the code generation will
> be quite different).
>
> Cc: Shan Kang <shan.kang@xxxxxxxxx>
> Cc: Kai Huang <kai.huang@xxxxxxxxx>
> Signed-off-by: Xin Li <xin3.li@xxxxxxxxx>
> [sean: split to separate patch, write changelog]
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> ---
> arch/x86/include/asm/vmx.h | 5 +++++
> arch/x86/kvm/vmx/capabilities.h | 6 ++----
> arch/x86/kvm/vmx/vmx.c | 28 ++++++++++++++--------------
> 3 files changed, 21 insertions(+), 18 deletions(-)
>
> diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
> index c3a97dca4a33..ce6d166fc3c5 100644
> --- a/arch/x86/include/asm/vmx.h
> +++ b/arch/x86/include/asm/vmx.h
> @@ -150,6 +150,11 @@ static inline u32 vmx_basic_vmcs_size(u64 vmx_basic)
> return (vmx_basic & GENMASK_ULL(44, 32)) >> 32;

Maybe we could use VMX_BASIC_VMCS_SIZE_SHIFT to replace "32"?

> }
>
> +static inline u32 vmx_basic_vmcs_mem_type(u64 vmx_basic)
> +{
> + return (vmx_basic & GENMASK_ULL(53, 50)) >> 50;
> +}
> +

Also here, we can use VMX_BASIC_MEM_TYPE_SHIFT to replace "50".

And what about defining VMX_BASIC_MEM_TYPE_MASK to replace
GENMASK_ULL(53, 50), and VMX_BASIC_VMCS_SIZE_MSAK to replace
GENMASK_ULL(44, 32) above?

Thanks,
Zhao