Re: [Bug report] __arch_hweight32/64 x86

From: Dave Hansen
Date: Mon Jun 26 2023 - 18:41:34 EST


On 6/26/23 14:42, Sebastian Sumpf wrote:
>
>>> Therefore, these registers will not be restored
>>> upon function return by the compiler. This leads to varying
>>> exceptions/bad behavior caused by the thus corrupted registers later
>>> on.
>>
>> How do I reproduce what you're observing so that I can take a look?
>
> This is hard to tell, I would disable the " X86_FEATURE_POPCNT" feature
> and use the ' CONFIG_ARCH_HAS_FAST_MULTIPLIER' option in order to use
> the multiplier implementation in '__sw_hweight64' in 'lib/hweight.c' At
> least that is what triggered it here.

Looks like you'd also have to be using UML:

$ grep hweight lib/Makefile
obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
$ grep -r GENERIC_HWEIGHT arch/x86
arch/x86/um/Kconfig:config GENERIC_HWEIGHT

I'm not even sure that UML needs GENERIC_HWEIGHT. From a quick glance,
it looks like x86 used to use GENERIC_HWEIGHT, but got arch-specific
versions later. UML just never moved over to the arch-specific versions.

I _think_ the attached patch might just fix the problems with the C
version and bring the x86/UML implementation back in line with the rest
of x86.

Thoughts?diff --git a/arch/x86/um/Kconfig b/arch/x86/um/Kconfig
index 186f13268401..76d507860be4 100644
--- a/arch/x86/um/Kconfig
+++ b/arch/x86/um/Kconfig
@@ -44,6 +44,3 @@ config ARCH_HAS_SC_SIGNALS

config ARCH_REUSE_HOST_VSYSCALL_AREA
def_bool !64BIT
-
-config GENERIC_HWEIGHT
- def_bool y