public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH kvmtool] remove wordsize.h inclusion (for musl compatibility)
@ 2024-08-01 11:10 Andre Przywara
  2024-08-02  9:55 ` Alexandru Elisei
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andre Przywara @ 2024-08-01 11:10 UTC (permalink / raw)
  To: Will Deacon, Julien Thierry; +Cc: kvm, Alexandru Elisei, J . Neuschäfer

The wordsize.h header file and the __WORDSIZE definition do not seem
to be universal, the musl libc for instance has the definition in a
different header file. This breaks compilation of kvmtool against musl.

The two leading underscores suggest a compiler-internal symbol anyway, so
let's just remove that particular macro usage entirely, and replace it
with the number we really want: the size of a "long" type.

Reported-by: J. Neuschäfer <j.neuschaefer@gmx.net>
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
Hi,

can someone test this on a proper/pure musl installation? I tested this
with Ubuntu's musl-gcc wrapper, but this didn't show the problem before,
so I guess there are subtle differences.

Cheers,
Andre

 include/linux/bitops.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index ae33922f5..ee8fd5609 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -1,15 +1,13 @@
 #ifndef _KVM_LINUX_BITOPS_H_
 #define _KVM_LINUX_BITOPS_H_
 
-#include <bits/wordsize.h>
-
 #include <linux/kernel.h>
 #include <linux/compiler.h>
 #include <asm/hweight.h>
 
-#define BITS_PER_LONG __WORDSIZE
 #define BITS_PER_BYTE           8
-#define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
+#define BITS_PER_LONG           (BITS_PER_BYTE * sizeof(long))
+#define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_LONG)
 
 #define BIT_WORD(nr)		((nr) / BITS_PER_LONG)
 
-- 
2.25.1


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

* Re: [PATCH kvmtool] remove wordsize.h inclusion (for musl compatibility)
  2024-08-01 11:10 [PATCH kvmtool] remove wordsize.h inclusion (for musl compatibility) Andre Przywara
@ 2024-08-02  9:55 ` Alexandru Elisei
  2024-08-04 23:15 ` J. Neuschäfer
  2024-08-05 13:43 ` Will Deacon
  2 siblings, 0 replies; 4+ messages in thread
From: Alexandru Elisei @ 2024-08-02  9:55 UTC (permalink / raw)
  To: Andre Przywara; +Cc: Will Deacon, Julien Thierry, kvm, J . Neuschäfer

Hi Andre,

On Thu, Aug 01, 2024 at 12:10:54PM +0100, Andre Przywara wrote:
> The wordsize.h header file and the __WORDSIZE definition do not seem
> to be universal, the musl libc for instance has the definition in a
> different header file. This breaks compilation of kvmtool against musl.
> 
> The two leading underscores suggest a compiler-internal symbol anyway, so
> let's just remove that particular macro usage entirely, and replace it
> with the number we really want: the size of a "long" type.
> 
> Reported-by: J. Neuschäfer <j.neuschaefer@gmx.net>
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
> Hi,
> 
> can someone test this on a proper/pure musl installation? I tested this
> with Ubuntu's musl-gcc wrapper, but this didn't show the problem before,
> so I guess there are subtle differences.
> 
> Cheers,
> Andre
> 
>  include/linux/bitops.h | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/include/linux/bitops.h b/include/linux/bitops.h
> index ae33922f5..ee8fd5609 100644
> --- a/include/linux/bitops.h
> +++ b/include/linux/bitops.h
> @@ -1,15 +1,13 @@
>  #ifndef _KVM_LINUX_BITOPS_H_
>  #define _KVM_LINUX_BITOPS_H_
>  
> -#include <bits/wordsize.h>
> -
>  #include <linux/kernel.h>
>  #include <linux/compiler.h>
>  #include <asm/hweight.h>
>  
> -#define BITS_PER_LONG __WORDSIZE
>  #define BITS_PER_BYTE           8
> -#define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
> +#define BITS_PER_LONG           (BITS_PER_BYTE * sizeof(long))
> +#define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_LONG)

This makes perfect sense to me. I would just like to point out that the code
already used this definition for the number of bits in a long, in the
BITS_TO_LONGS() macro, where it used BITS_PER_BYTE * sizeof(long) instead of
BITS_PER_LONG.

Also tested this by cross-compiling for arm and arm64 on an x86 host, and
compiling natively for arm64.

Reviewed-by: Alexandru Elisei <alexandru.elisei@arm.com>

Thanks,
Alex

>  
>  #define BIT_WORD(nr)		((nr) / BITS_PER_LONG)
>  
> -- 
> 2.25.1
> 

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

* Re: [PATCH kvmtool] remove wordsize.h inclusion (for musl compatibility)
  2024-08-01 11:10 [PATCH kvmtool] remove wordsize.h inclusion (for musl compatibility) Andre Przywara
  2024-08-02  9:55 ` Alexandru Elisei
@ 2024-08-04 23:15 ` J. Neuschäfer
  2024-08-05 13:43 ` Will Deacon
  2 siblings, 0 replies; 4+ messages in thread
From: J. Neuschäfer @ 2024-08-04 23:15 UTC (permalink / raw)
  To: Andre Przywara
  Cc: Will Deacon, Julien Thierry, kvm, Alexandru Elisei,
	J . Neuschäfer

On Thu, Aug 01, 2024 at 12:10:54PM +0100, Andre Przywara wrote:
> The wordsize.h header file and the __WORDSIZE definition do not seem
> to be universal, the musl libc for instance has the definition in a
> different header file. This breaks compilation of kvmtool against musl.
>
> The two leading underscores suggest a compiler-internal symbol anyway, so
> let's just remove that particular macro usage entirely, and replace it
> with the number we really want: the size of a "long" type.
>
> Reported-by: J. Neuschäfer <j.neuschaefer@gmx.net>
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
> Hi,
>
> can someone test this on a proper/pure musl installation? I tested this
> with Ubuntu's musl-gcc wrapper, but this didn't show the problem before,
> so I guess there are subtle differences.

Compile-tested successfully on Alpine Linux 3.21 (gcc 13.2.1, musl 1.2.5).

Thanks a lot!
-- jn

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

* Re: [PATCH kvmtool] remove wordsize.h inclusion (for musl compatibility)
  2024-08-01 11:10 [PATCH kvmtool] remove wordsize.h inclusion (for musl compatibility) Andre Przywara
  2024-08-02  9:55 ` Alexandru Elisei
  2024-08-04 23:15 ` J. Neuschäfer
@ 2024-08-05 13:43 ` Will Deacon
  2 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2024-08-05 13:43 UTC (permalink / raw)
  To: Julien Thierry, Andre Przywara
  Cc: catalin.marinas, kernel-team, Will Deacon, kvm, Alexandru Elisei,
	J . Neuschäfer

On Thu, 01 Aug 2024 12:10:54 +0100, Andre Przywara wrote:
> The wordsize.h header file and the __WORDSIZE definition do not seem
> to be universal, the musl libc for instance has the definition in a
> different header file. This breaks compilation of kvmtool against musl.
> 
> The two leading underscores suggest a compiler-internal symbol anyway, so
> let's just remove that particular macro usage entirely, and replace it
> with the number we really want: the size of a "long" type.
> 
> [...]

Applied to kvmtool (master), thanks!

[1/1] remove wordsize.h inclusion (for musl compatibility)
      https://git.kernel.org/will/kvmtool/c/0592f8f829c8

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

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

end of thread, other threads:[~2024-08-05 13:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-01 11:10 [PATCH kvmtool] remove wordsize.h inclusion (for musl compatibility) Andre Przywara
2024-08-02  9:55 ` Alexandru Elisei
2024-08-04 23:15 ` J. Neuschäfer
2024-08-05 13:43 ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox