All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: isaku.yamahata@intel.com
Cc: kvm@vger.kernel.org, isaku.yamahata@gmail.com,
	 Paolo Bonzini <pbonzini@redhat.com>,
	kernel test robot <lkp@intel.com>
Subject: Re: [PATCH] KVM: VMX: Eliminate warnings by sparse in vmcs12.c and hyperv_evmcs.c
Date: Thu, 12 Mar 2026 10:49:16 -0700	[thread overview]
Message-ID: <abL8nHNYkUCcS73O@google.com> (raw)
In-Reply-To: <47e4570a1db6f68eacdde989c6cf4f53175cea75.1773193126.git.isaku.yamahata@intel.com>

On Tue, Mar 10, 2026, isaku.yamahata@intel.com wrote:
> From: Isaku Yamahata <isaku.yamahata@intel.com>
> 
> Make ROL16() explicitly mask instead of the truncation by u16 cast.
> Sparse complains as follows for vmcs12.c and hyperv_evmcs.c.
>   > vmcs12.c:17:9: warning: cast truncates bits from constant value
>   > (20002 becomes 2)
> 
> It is because ROL16(val, n) includes "(u16)(val) << (n)" whose type is int,
> not u16, due to integer promotion even with a u16 cast.  The outermost u16
> cast in ROL16() may truncate it.  Explicitly mask it to avoid truncation by
> the u16 cast.

Honestly, I'm inclined to ignore sparse.  The code is correct as-is, and adding
the GENMASK just makes it less readable IMO.

> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202603061942.wdSsERnL-lkp@intel.com/
> Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
> ---
>  arch/x86/kvm/vmx/vmcs.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/vmx/vmcs.h b/arch/x86/kvm/vmx/vmcs.h
> index 1f16ddeae9cb..b5b5f4870655 100644
> --- a/arch/x86/kvm/vmx/vmcs.h
> +++ b/arch/x86/kvm/vmx/vmcs.h
> @@ -18,7 +18,8 @@
>   * wasting too much memory, while the "algorithm" is fast enough to be used to
>   * lookup vmcs12 fields on-demand, e.g. for emulation.
>   */
> -#define ROL16(val, n) ((u16)(((u16)(val) << (n)) | ((u16)(val) >> (16 - (n)))))
> +#define ROL16(val, n) ((u16)((((u16)(val) << (n)) & GENMASK_U16(15, 0)) | \
> +			     ((u16)(val) >> (16 - (n)))))
>  #define VMCS12_IDX_TO_ENC(idx) ROL16(idx, 10)
>  #define ENC_TO_VMCS12_IDX(enc) ROL16(enc, 6)
>  
> 
> base-commit: 5128b972fb2801ad9aca54d990a75611ab5283a9
> -- 
> 2.45.2
> 

  reply	other threads:[~2026-03-12 17:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11  1:59 [PATCH] KVM: VMX: Eliminate warnings by sparse in vmcs12.c and hyperv_evmcs.c isaku.yamahata
2026-03-12 17:49 ` Sean Christopherson [this message]
2026-03-12 19:09   ` Isaku Yamahata

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=abL8nHNYkUCcS73O@google.com \
    --to=seanjc@google.com \
    --cc=isaku.yamahata@gmail.com \
    --cc=isaku.yamahata@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=pbonzini@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.