Mark Wielaard 216add
commit 6bb6c8a65a341a67bd059ec6e1c805813eb17264
Mark Wielaard 216add
Author: Mark Wielaard <mark@klomp.org>
Mark Wielaard 216add
Date:   Tue Jun 19 18:00:45 2018 +0200
Mark Wielaard 216add
Mark Wielaard 216add
    Mask AT_HWCAPS on arm64 to those instructions VEX implements.
Mark Wielaard 216add
    
Mark Wielaard 216add
    This patch makes sure that the process running under valgrind only sees
Mark Wielaard 216add
    the AES, PMULL, SHA1, SHA2, CRC32, FP, and ASIMD features in auxv AT_HWCAPS.
Mark Wielaard 216add
    
Mark Wielaard 216add
    https://bugs.kde.org/show_bug.cgi?id=381556
Mark Wielaard 216add
Mark Wielaard 39ca09
diff --git a/coregrind/m_initimg/initimg-linux.c b/coregrind/m_initimg/initimg-linux.c
Mark Wielaard 216add
index 30e1f85..61cc458 100644
Mark Wielaard 39ca09
--- a/coregrind/m_initimg/initimg-linux.c
Mark Wielaard 39ca09
+++ b/coregrind/m_initimg/initimg-linux.c
Mark Wielaard 216add
@@ -703,6 +703,19 @@ Addr setup_client_stack( void*  init_sp,
Mark Wielaard 39ca09
                   (and anything above) are not supported by Valgrind. */
Mark Wielaard 39ca09
                auxv->u.a_val &= VKI_HWCAP_S390_TE - 1;
Mark Wielaard 39ca09
             }
Mark Wielaard 39ca09
+#           elif defined(VGP_arm64_linux)
Mark Wielaard 39ca09
+            {
Mark Wielaard 216add
+               /* Limit the AT_HWCAP to just those features we explicitly
Mark Wielaard 216add
+		  support in VEX.  */
Mark Wielaard 216add
+#define ARM64_SUPPORTED_HWCAP (VKI_HWCAP_AES	        \
Mark Wielaard 216add
+                               | VKI_HWCAP_PMULL        \
Mark Wielaard 216add
+                               | VKI_HWCAP_SHA1         \
Mark Wielaard 216add
+                               | VKI_HWCAP_SHA2         \
Mark Wielaard 216add
+                               | VKI_HWCAP_CRC32        \
Mark Wielaard 216add
+                               | VKI_HWCAP_FP           \
Mark Wielaard 216add
+                               | VKI_HWCAP_ASIMD)
Mark Wielaard 216add
+               auxv->u.a_val &= ARM64_SUPPORTED_HWCAP;
Mark Wielaard 39ca09
+            }
Mark Wielaard 39ca09
 #           endif
Mark Wielaard 39ca09
             break;
Mark Wielaard 39ca09
 #        if defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
Mark Wielaard 216add
diff --git a/include/vki/vki-arm64-linux.h b/include/vki/vki-arm64-linux.h
Mark Wielaard 216add
index af6b435..54b0428 100644
Mark Wielaard 216add
--- a/include/vki/vki-arm64-linux.h
Mark Wielaard 216add
+++ b/include/vki/vki-arm64-linux.h
Mark Wielaard 216add
@@ -692,6 +692,39 @@ struct vki_shminfo64 {
Mark Wielaard 216add
 #define VKI_TIOCSSERIAL     0x541F
Mark Wielaard 216add
 
Mark Wielaard 216add
 //----------------------------------------------------------------------
Mark Wielaard 216add
+// From linux-4.17/include/uapi/asm-generic/ioctls.h
Mark Wielaard 216add
+//----------------------------------------------------------------------
Mark Wielaard 216add
+
Mark Wielaard 216add
+#define VKI_HWCAP_FP                (1 << 0)
Mark Wielaard 216add
+#define VKI_HWCAP_ASIMD             (1 << 1)
Mark Wielaard 216add
+#define VKI_HWCAP_EVTSTRM           (1 << 2)
Mark Wielaard 216add
+#define VKI_HWCAP_AES               (1 << 3)
Mark Wielaard 216add
+#define VKI_HWCAP_PMULL             (1 << 4)
Mark Wielaard 216add
+#define VKI_HWCAP_SHA1              (1 << 5)
Mark Wielaard 216add
+#define VKI_HWCAP_SHA2              (1 << 6)
Mark Wielaard 216add
+#define VKI_HWCAP_CRC32             (1 << 7)
Mark Wielaard 216add
+#define VKI_HWCAP_ATOMICS           (1 << 8)
Mark Wielaard 216add
+#define VKI_HWCAP_FPHP              (1 << 9)
Mark Wielaard 216add
+#define VKI_HWCAP_ASIMDHP           (1 << 10)
Mark Wielaard 216add
+#define VKI_HWCAP_CPUID             (1 << 11)
Mark Wielaard 216add
+#define VKI_HWCAP_ASIMDRDM          (1 << 12)
Mark Wielaard 216add
+#define VKI_HWCAP_JSCVT             (1 << 13)
Mark Wielaard 216add
+#define VKI_HWCAP_FCMA              (1 << 14)
Mark Wielaard 216add
+#define VKI_HWCAP_LRCPC             (1 << 15)
Mark Wielaard 216add
+#define VKI_HWCAP_DCPOP             (1 << 16)
Mark Wielaard 216add
+#define VKI_HWCAP_SHA3              (1 << 17)
Mark Wielaard 216add
+#define VKI_HWCAP_SM3               (1 << 18)
Mark Wielaard 216add
+#define VKI_HWCAP_SM4               (1 << 19)
Mark Wielaard 216add
+#define VKI_HWCAP_ASIMDDP           (1 << 20)
Mark Wielaard 216add
+#define VKI_HWCAP_SHA512            (1 << 21)
Mark Wielaard 216add
+#define VKI_HWCAP_SVE               (1 << 22)
Mark Wielaard 216add
+#define VKI_HWCAP_ASIMDFHM          (1 << 23)
Mark Wielaard 216add
+#define VKI_HWCAP_DIT               (1 << 24)
Mark Wielaard 216add
+#define VKI_HWCAP_USCAT             (1 << 25)
Mark Wielaard 216add
+#define VKI_HWCAP_ILRCPC            (1 << 26)
Mark Wielaard 216add
+#define VKI_HWCAP_FLAGM             (1 << 27)
Mark Wielaard 216add
+
Mark Wielaard 216add
+//----------------------------------------------------------------------
Mark Wielaard 216add
 // And that's it!
Mark Wielaard 216add
 //----------------------------------------------------------------------
Mark Wielaard 216add