From: Andreas Arnez Date: Tue, 6 Aug 2019 16:29:46 +0000 (+0200) Subject: s390x: Fix vector facility (vx) check in test suite X-Git-Tag: VALGRIND_3_16_0~247 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=161d22f0af2c8ee9817df4334572a1a298e1df8a;p=thirdparty%2Fvalgrind.git s390x: Fix vector facility (vx) check in test suite When checking the prereqisuites of running a vector test case, it is not sufficient to check for the appropriate CPU facility bit. It must also be verified that the kernel and hypervisor(s) have actually enabled the vector facility. There are various ways of checking this. E.g., we could try executing a vector instruction and handle any signals. Or we can check the HWCAP for the appropriate bit. This patch does the latter. --- diff --git a/tests/s390x_features.c b/tests/s390x_features.c index ce6c4ab263..16f9220f77 100644 --- a/tests/s390x_features.c +++ b/tests/s390x_features.c @@ -10,6 +10,7 @@ #include // open #include // lseek #include // S_IRUSR +#include // __GLIBC_PREREQ // This file determines s390x features a processor supports. // @@ -39,6 +40,17 @@ jmp_buf env; #if defined(VGA_s390x) +// Features that require kernel support should be checked against HWCAP instead +// of the CPU facility list. To read the HWCAP, use 'getauxval' if available -- +// which should be the case with glibc versions >= 2.16. A system with an older +// glibc is unlikely to support any of these features anyhow. +#if __GLIBC_PREREQ(2, 16) +#include +#define GET_HWCAP() getauxval(AT_HWCAP) +#else +#define GET_HWCAP() 0UL +#endif + /* Number of double words needed to store all facility bits. */ #define S390_NUM_FACILITY_DW 3 @@ -246,7 +258,8 @@ static int go(char *feature, char *cpu) } else if (strcmp(feature, "s390x-highw") == 0 ) { match = facilities[0] & FAC_BIT(45); } else if (strcmp(feature, "s390x-vx") == 0 ) { - match = facilities[2] & FAC_BIT(0); + /* VX needs kernel support; thus check the appropriate HWCAP bit. */ + match = GET_HWCAP() & 0x800; } else if (strcmp(feature, "s390x-msa5") == 0 ) { match = facilities[0] & FAC_BIT(57); /* message security assist 5 facility */ } else if (strcmp(feature, "s390x-mi2") == 0 ) {