public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Su Hui <suhui@nfschina.com>, Andrew Morton <akpm@linux-foundation.org>
Cc: binbin.wu@linux.intel.com, pbonzini@redhat.com,
	 linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	 kvm@vger.kernel.org
Subject: Re: [PATCH] include/linux/log2.h: mark is_power_of_2() with __always_inline
Date: Mon, 24 Feb 2025 07:57:45 -0800	[thread overview]
Message-ID: <Z7yW-aNXV1sK6eQN@google.com> (raw)
In-Reply-To: <20250221071624.1356899-1-suhui@nfschina.com>

+Andrew

On Fri, Feb 21, 2025, Su Hui wrote:
> When build kernel with randconfig, there is an error:
> 
> In function ‘kvm_is_cr4_bit_set’,inlined from
> ‘kvm_update_cpuid_runtime’ at arch/x86/kvm/cpuid.c:310:9:
> 
> include/linux/compiler_types.h:542:38: error: call to
> ‘__compiletime_assert_380’ declared with attribute error:
> BUILD_BUG_ON failed: !is_power_of_2(cr4_bit).

Andrew, do you want to grab this?  Looks like you've taken the last few changes
to log2.h, and KVM isn't the only subsystem that expects is_power_of_2() to yield
a compile-time constant; taking this through the KVM tree feels wrong.

  arch/x86/kvm/kvm_cache_regs.h:	BUILD_BUG_ON(!is_power_of_2(cr0_bit));
  arch/x86/kvm/kvm_cache_regs.h:	BUILD_BUG_ON(!is_power_of_2(cr4_bit));
  arch/x86/kvm/x86.c:	BUILD_BUG_ON(!is_power_of_2(ASYNC_PF_PER_VCPU));
  drivers/net/ipa/gsi.c:	BUILD_BUG_ON(!is_power_of_2(GSI_RING_ELEMENT_SIZE));
  drivers/vfio/pci/virtio/legacy_io.c:	BUILD_BUG_ON(!is_power_of_2(virtvdev->bar0_virtual_buf_size));
  kernel/kcov.c:		BUILD_BUG_ON(!is_power_of_2(KCOV_WORDS_PER_CMP));
  mm/sparse.c:	BUILD_BUG_ON(!is_power_of_2(sizeof(struct mem_section)));
  mm/swap_cgroup.c:	BUILD_BUG_ON(!is_power_of_2(ID_PER_SC));

> '!is_power_of_2(X86_CR4_OSXSAVE)' is False, but gcc treats is_power_of_2()
> as non-inline function and a compilation error happens. Fix this by marking
> is_power_of_2() with __always_inline.
> 
> Signed-off-by: Su Hui <suhui@nfschina.com>
> ---
>  include/linux/log2.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/log2.h b/include/linux/log2.h
> index 9f30d087a128..1366cb688a6d 100644
> --- a/include/linux/log2.h
> +++ b/include/linux/log2.h
> @@ -41,7 +41,7 @@ int __ilog2_u64(u64 n)
>   * *not* considered a power of two.
>   * Return: true if @n is a power of 2, otherwise false.
>   */
> -static inline __attribute__((const))
> +static __always_inline __attribute__((const))
>  bool is_power_of_2(unsigned long n)
>  {
>  	return (n != 0 && ((n & (n - 1)) == 0));
> -- 
> 2.30.2
> 

      reply	other threads:[~2025-02-24 15:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-21  7:16 [PATCH] include/linux/log2.h: mark is_power_of_2() with __always_inline Su Hui
2025-02-24 15:57 ` Sean Christopherson [this message]

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=Z7yW-aNXV1sK6eQN@google.com \
    --to=seanjc@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=binbin.wu@linux.intel.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=suhui@nfschina.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