lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d3d22390-6557-45a1-9979-4b4580fd629c@intel.com>
Date: Fri, 9 Jan 2026 19:34:28 +0800
From: Xiaoyao Li <xiaoyao.li@...el.com>
To: Sean Christopherson <seanjc@...gle.com>,
 Paolo Bonzini <pbonzini@...hat.com>
Cc: kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
 Chao Gao <chao.gao@...el.com>, Xin Li <xin@...or.com>,
 Yosry Ahmed <yosry.ahmed@...ux.dev>
Subject: Re: [PATCH v3 2/4] KVM: VMX: Add a wrapper around ROL16() to get a
 vmcs12 from a field encoding

On 1/9/2026 12:15 PM, Sean Christopherson wrote:
> Add a wrapper macro, ENC_TO_VMCS12_IDX(), to get a vmcs12 index given a
> field encoding in anticipation of add a macro to get from a vmcs12 index
                                      ^
s/add/adding ?

> back to the field encoding.  And because open coding ROL16(n, 6) everywhere
> is gross.
> 
> No functional change intended.
> 
> Suggested-by: Xiaoyao Li <xiaoyao.li@...el.com>
> Signed-off-by: Sean Christopherson <seanjc@...gle.com>

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

> ---
>   arch/x86/kvm/vmx/hyperv_evmcs.c | 2 +-
>   arch/x86/kvm/vmx/hyperv_evmcs.h | 2 +-
>   arch/x86/kvm/vmx/vmcs.h         | 1 +
>   arch/x86/kvm/vmx/vmcs12.c       | 4 ++--
>   arch/x86/kvm/vmx/vmcs12.h       | 2 +-
>   5 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx/hyperv_evmcs.c b/arch/x86/kvm/vmx/hyperv_evmcs.c
> index 904bfcd1519b..cc728c9a3de5 100644
> --- a/arch/x86/kvm/vmx/hyperv_evmcs.c
> +++ b/arch/x86/kvm/vmx/hyperv_evmcs.c
> @@ -7,7 +7,7 @@
>   #include "hyperv_evmcs.h"
>   
>   #define EVMCS1_OFFSET(x) offsetof(struct hv_enlightened_vmcs, x)
> -#define EVMCS1_FIELD(number, name, clean_field)[ROL16(number, 6)] = \
> +#define EVMCS1_FIELD(number, name, clean_field)[ENC_TO_VMCS12_IDX(number)] = \
>   		{EVMCS1_OFFSET(name), clean_field}
>   
>   const struct evmcs_field vmcs_field_to_evmcs_1[] = {
> diff --git a/arch/x86/kvm/vmx/hyperv_evmcs.h b/arch/x86/kvm/vmx/hyperv_evmcs.h
> index 6536290f4274..fc7c4e7bd1bf 100644
> --- a/arch/x86/kvm/vmx/hyperv_evmcs.h
> +++ b/arch/x86/kvm/vmx/hyperv_evmcs.h
> @@ -130,7 +130,7 @@ static __always_inline int evmcs_field_offset(unsigned long field,
>   					      u16 *clean_field)
>   {
>   	const struct evmcs_field *evmcs_field;
> -	unsigned int index = ROL16(field, 6);
> +	unsigned int index = ENC_TO_VMCS12_IDX(field);
>   
>   	if (unlikely(index >= nr_evmcs_1_fields))
>   		return -ENOENT;
> diff --git a/arch/x86/kvm/vmx/vmcs.h b/arch/x86/kvm/vmx/vmcs.h
> index b25625314658..9aa204c87661 100644
> --- a/arch/x86/kvm/vmx/vmcs.h
> +++ b/arch/x86/kvm/vmx/vmcs.h
> @@ -12,6 +12,7 @@
>   #include "capabilities.h"
>   
>   #define ROL16(val, n) ((u16)(((u16)(val) << (n)) | ((u16)(val) >> (16 - (n)))))
> +#define ENC_TO_VMCS12_IDX(enc) ROL16(enc, 6)
>   
>   struct vmcs_hdr {
>   	u32 revision_id:31;
> diff --git a/arch/x86/kvm/vmx/vmcs12.c b/arch/x86/kvm/vmx/vmcs12.c
> index 4233b5ca9461..c2ac9e1a50b3 100644
> --- a/arch/x86/kvm/vmx/vmcs12.c
> +++ b/arch/x86/kvm/vmx/vmcs12.c
> @@ -4,10 +4,10 @@
>   #include "vmcs12.h"
>   
>   #define VMCS12_OFFSET(x) offsetof(struct vmcs12, x)
> -#define FIELD(number, name)	[ROL16(number, 6)] = VMCS12_OFFSET(name)
> +#define FIELD(number, name)	[ENC_TO_VMCS12_IDX(number)] = VMCS12_OFFSET(name)
>   #define FIELD64(number, name)						\
>   	FIELD(number, name),						\
> -	[ROL16(number##_HIGH, 6)] = VMCS12_OFFSET(name) + sizeof(u32)
> +	[ENC_TO_VMCS12_IDX(number##_HIGH)] = VMCS12_OFFSET(name) + sizeof(u32)
>   
>   const unsigned short vmcs12_field_offsets[] = {
>   	FIELD(VIRTUAL_PROCESSOR_ID, virtual_processor_id),
> diff --git a/arch/x86/kvm/vmx/vmcs12.h b/arch/x86/kvm/vmx/vmcs12.h
> index 4ad6b16525b9..7a5fdd9b27ba 100644
> --- a/arch/x86/kvm/vmx/vmcs12.h
> +++ b/arch/x86/kvm/vmx/vmcs12.h
> @@ -385,7 +385,7 @@ static inline short get_vmcs12_field_offset(unsigned long field)
>   	if (field >> 15)
>   		return -ENOENT;
>   
> -	index = ROL16(field, 6);
> +	index = ENC_TO_VMCS12_IDX(field);
>   	if (index >= nr_vmcs12_fields)
>   		return -ENOENT;
>   


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ