https://bugs.kde.org/show_bug.cgi?id=444545

Christopher Wecht <cwe...@mailbox.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cwe...@mailbox.org

--- Comment #12 from Christopher Wecht <cwe...@mailbox.org> ---
I think, that I can clarify this issue a bit. From my understanding, this issue
is caused by a unfortunate combination of glibc and VirtualBox.

1. VirtualBox has the oddity of providing AVX2 instructions to its clients, but
not BMI instructions: https://www.virtualbox.org/ticket/15471
This fact makes VirtualBox a quite weird plattform: at least for Intel CPUs BMI
and AVX2 have both been introduced with Haswell. It is actually quite unusual,
that a CPU architecture supports AVX2 but _not_ BMI.

2. glibc uses a special implementations of memchr for different instruction
sets available. Which one is actually used is decided depending on the
available instruction sets:
https://github.com/bminor/glibc/blob/glibc-2.36/sysdeps/x86_64/multiarch/ifunc-impl-list.c#L60

3. The AVX2 implementation of memchr is enabled if AVX2 is available:
https://github.com/bminor/glibc/blob/glibc-2.36/sysdeps/x86_64/multiarch/ifunc-impl-list.c#L71

4. But it turns out, that the AVX2 implementation of memchr uses not only AVX2
instructions but also BMI instructions, namely TZCNTL:
https://github.com/bminor/glibc/blob/master/sysdeps/x86_64/multiarch/memchr-avx2.S#L101

5. My conclusion is now: VirtualBox communicates to its guests, that AVX2 is
available but not BMI. This results in glibc using the AVX2 implemntation
although it needs the BMI instructions, too. This is probably not an issue if
the VBox is executed on a x86 guest, because the needed instructions are
actually supported there and with modern CPU fetures for virtualization
(https://bugs.kde.org/show_bug.cgi?id=444545) the instructions are more or less
directly forwarded to the CPU anyways (AFAIK). It seems now, that massif is
confused by running a program which uses BMI instructions on a system which
allegidly doesn't support them.

I can backup this claim with the following observations:
  - The above provided test programm work with massif on ubuntu 20.04 and 20.04
but not with 21.10, 22.04 and 22.10. The breaking change must have been
introduced between 2.33 and 2.34. It turns out, that 2.34 is exactly the
version, in which the BMI instructions have been introduced in the "main path"
(see
https://github.com/bminor/glibc/blob/glibc-2.34/sysdeps/x86_64/multiarch/memchr-avx2.S
vs
https://github.com/bminor/glibc/blob/glibc-2.33/sysdeps/x86_64/multiarch/memchr-avx2.S).
 

Interestinly in the master branch, there is now a check for BMI2 in place
(https://github.com/bminor/glibc/blob/master/sysdeps/x86_64/multiarch/ifunc-impl-list.c#L76)
so supposedly, this issue should not occure with the most recent "nigtly"
version of glibc, if my reasoning is correct.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to