Questions regarding manipulation of IFUNC selection and tunables like glibc.cpu.hwcap_mask

Stefan Liebler stli@linux.ibm.com
Thu Aug 25 09:54:53 GMT 2022


Hi,

on s390x, the IFUNC'ed functions or other hw-dependent code-paths are
usually selected by either the HWCAPs or the facility-list retrieved via
stfle-instruction.

Now we need a possibility to manipulate the IFUNC selection. As the
current IFUNC-resolvers always select the functions for the newest
features, we only need a possibility to disable features.

According to <glibc>/manual/tunables.texi:
@deftp Tunable glibc.cpu.hwcap_mask
This tunable supersedes the @env{LD_HWCAP_MASK} environment variable and is
identical in features.

The @code{AT_HWCAP} key in the Auxiliary Vector specifies instruction set
extensions available in the processor at runtime for some architectures.
 The
@code{glibc.cpu.hwcap_mask} tunable allows the user to mask out those
capabilities at runtime, thus disabling use of those extensions.
@end deftp

But a small testprogram (see attached tst-ifunc-manipulation.c) shows
that neither setting the environment variable
GLIBC_TUNABLES="glibc.cpu.hwcap_mask=0" nor LD_HWCAP_MASK="0x0
influences the HWCAPs.

On s390x, the IFUNC-resolvers get the HWCAPs as argument (the most other
architectures don't have this argument). Other code-paths can get the
HWCAPs via getauxval(AT_HWCAP). In both cases the HWCAPs are loaded from
"GLRO(dl_hwcap)". See:
-
https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/s390/dl-irel.h;h=20e4887467d80a1b3f95da00bb98386e3eadfe47;hb=HEAD#l33
-
https://sourceware.org/git/?p=glibc.git;a=blob;f=misc/getauxval.c;h=714ce5bd62ec33c38356b187e6ec067b72b77afb;hb=HEAD#l32


Is it a bug or the intention that the HWCAP values are not influenced by
glibc.cpu.hwcap_mask tunable?

If it is a bug, would it be possible to apply the mask after
__tunables_init() like this:
GLRO(dl_hwcap) &= GET_HWCAP_MASK();
This would affect the IFUNC-resolver, getauxval(AT_HWCAP) and more (e.g.
if lock-elision is available or not) on all architectures. This would
also change the behavior of programs/libraries using getauxval(AT_HWCAP).

As alternative, we could also introduce a new s390-specific tunable
like: glibc.cpu.s390.hwcap_mask which influences only the s390-IFUNCS /
s390-code-pathes within glibc. The behaviour of programs/libraries using
getauxval(AT_HWCAP) is not changed.

Independent of the HWCAPs, we need to introduce a new s390-specific
tunable like glibc.cpu.s390.stfle_mask in order to influence the
s390-IFUNCs within glibc which are dependent on the facility-list.

Are there other hints?

Thanks in advance,
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tst-ifunc-manipulation.c
Type: text/x-csrc
Size: 1177 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20220825/129cd830/attachment.bin>


More information about the Libc-alpha mailing list