mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tools/include/linux/bitops.h: undef PAGE_SIZE after including limits.h
@ 2026-05-07 23:48 Hisam Mehboob
  2026-09-29 13:49 ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: Hisam Mehboob @ 2026-05-07 23:48 UTC (permalink / raw)
  To: acme
  Cc: shuah, seanjc, linux-kernel, linux-kselftest, Hisam Mehboob,
	Aqib Faruqui

musl libc defines PAGE_SIZE as a signed int in <limits.h>
under _GNU_SOURCE, conflicting with kernel headers that
require an unsigned 64-bit definition:

  include/x86/processor.h:372:9: warning: 'PAGE_SIZE' redefined
  /usr/include/x86_64-linux-musl/limits.h:97:9: note: this is the
  location of the previous definition

Undefine PAGE_SIZE immediately after the #include <limits.h> to
prevent musl's definition from leaking into kernel headers. This
is a no-op on glibc, which does not define PAGE_SIZE in <limits.h>.

Reported-by: Aqib Faruqui <aqibaf@amazon.com>
Link: https://lore.kernel.org/kvm/aL8e0MMa4U2-nstQ@google.com/
Signed-off-by: Hisam Mehboob <hisamshar@gmail.com>
---
 tools/include/linux/bitops.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h
index b4e4cd071f8c..62117a77ceb5 100644
--- a/tools/include/linux/bitops.h
+++ b/tools/include/linux/bitops.h
@@ -4,6 +4,7 @@
 
 #include <asm/types.h>
 #include <limits.h>
+#undef PAGE_SIZE
 #ifndef __WORDSIZE
 #define __WORDSIZE (__SIZEOF_LONG__ * 8)
 #endif
-- 
2.51.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] tools/include/linux/bitops.h: undef PAGE_SIZE after including limits.h
  2026-05-07 23:48 [PATCH] tools/include/linux/bitops.h: undef PAGE_SIZE after including limits.h Hisam Mehboob
@ 2026-09-29 13:49 ` Sean Christopherson
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2026-09-29 13:49 UTC (permalink / raw)
  To: Hisam Mehboob; +Cc: acme, shuah, linux-kernel, linux-kselftest, Aqib Faruqui

On Fri, May 08, 2026, Hisam Mehboob wrote:
> musl libc defines PAGE_SIZE as a signed int in <limits.h>
> under _GNU_SOURCE, conflicting with kernel headers that
> require an unsigned 64-bit definition:
> 
>   include/x86/processor.h:372:9: warning: 'PAGE_SIZE' redefined
>   /usr/include/x86_64-linux-musl/limits.h:97:9: note: this is the
>   location of the previous definition
> 
> Undefine PAGE_SIZE immediately after the #include <limits.h> to
> prevent musl's definition from leaking into kernel headers. This
> is a no-op on glibc, which does not define PAGE_SIZE in <limits.h>.

Sorry, but I don't like this option either, as it only works if whatever defines
PAGE_SIZE is included after <limits.h>, and obviously doesn't help if something
includes <limits.h> directly without including bitops.h.  Which might not happen
in the current code base, but given that building against musl is obviously not
very common, it's not hard to imagine such an issue "sneaking" in.

What if we explicity force an include+undef in the KVM selftests header that has
the requirement that PAGE_SIZE is a 64-bit unsigned value?  The downside is that
it would hide bugs if something other than musl pre-defines PAGE_SIZE, but that's
unlikely to be fatal, and I don't think would lead to a game of whack-a-mole.

diff --git a/tools/testing/selftests/kvm/include/x86/processor.h b/tools/testing/selftests/kvm/include/x86/processor.h
index 7579e692bc2b..ee8186e75552 100644
--- a/tools/testing/selftests/kvm/include/x86/processor.h
+++ b/tools/testing/selftests/kvm/include/x86/processor.h
@@ -6,6 +6,14 @@
 #ifndef SELFTEST_KVM_PROCESSOR_H
 #define SELFTEST_KVM_PROCESSOR_H
 
+/*
+ * Explicitly include the system's limit.h and undefine PAGE_SIZE to workaround
+ * an incompatibility where musl defines PAGE_SIZE as a signed integer, whereas
+ * KVM selftests expect it to be a 64-bit unsigned value.
+ */
+#include <limits.h>
+#undef PAGE_SIZE
+
 #include <assert.h>
 #include <stdint.h>
 #include <syscall.h>

> Reported-by: Aqib Faruqui <aqibaf@amazon.com>
> Link: https://lore.kernel.org/kvm/aL8e0MMa4U2-nstQ@google.com/
> Signed-off-by: Hisam Mehboob <hisamshar@gmail.com>
> ---
>  tools/include/linux/bitops.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h
> index b4e4cd071f8c..62117a77ceb5 100644
> --- a/tools/include/linux/bitops.h
> +++ b/tools/include/linux/bitops.h
> @@ -4,6 +4,7 @@
>  
>  #include <asm/types.h>
>  #include <limits.h>
> +#undef PAGE_SIZE
>  #ifndef __WORDSIZE
>  #define __WORDSIZE (__SIZEOF_LONG__ * 8)
>  #endif
> -- 
> 2.51.0
> 
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-29 13:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-07 23:48 [PATCH] tools/include/linux/bitops.h: undef PAGE_SIZE after including limits.h Hisam Mehboob
2026-09-29 13:49 ` Sean Christopherson

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®