Skip to contentSkip to conversation

tcg patch queue

GIT PULL Applied Richard Henderson 1 participant 9 messages Jul 3, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

The following changes since commit 6746482d12da3b6e4d3cdf06481a0027a797f719:

Merge tag 'sdmmc-20240702' of https://github.com/philmd/qemu into staging (2024-07-02 09:52:10 -0700)

are available in the Git repository at:

https://gitlab.com/rth7680/qemu tags/pull-tcg-20240703

for you to fetch changes up to a71d9dfbf63db42d6e6ae87fc112d1f5502183bd:

tcg/optimize: Fix TCG_COND_TST* simplification of setcond2 (2024-07-03 10:24:12 -0700)

----------------------------------------------------------------
util: cpuinfo portability fixes for FreeBSD and OpenBSD
util: cpuinfo for riscv host
tcg/optimize: Fix TCG_COND_TST* simplification of setcond2

----------------------------------------------------------------
Brad Smith (3):
util/cpuinfo-ppc: Fix building on OpenBSD
util/cpuinfo-ppc: Add FreeBSD support
util/cpuinfo-aarch64: Add OpenBSD support

Richard Henderson (4):
util/cpuinfo-riscv: Support host/cpuinfo.h for riscv util/cpuinfo-riscv: Support OpenBSD signal frame util/cpuinfo-riscv: Use linux __riscv_hwprobe syscall tcg/optimize: Fix TCG_COND_TST* simplification of setcond2

 meson.build                       |   6 ++
 host/include/riscv/host/cpuinfo.h |  23 ++++++++
 tcg/riscv/tcg-target.h            |  46 +++++++--------
 tcg/optimize.c                    |   2 +-
 tests/tcg/x86_64/test-2413.c      |  30 ++++++++++
 util/cpuinfo-aarch64.c            |  36 ++++++++++++
 util/cpuinfo-ppc.c                |  27 ++++++---
 util/cpuinfo-riscv.c              | 118 ++++++++++++++++++++++++++++++++++++++
 tcg/riscv/tcg-target.c.inc        |  84 +++------------------------
 tests/tcg/x86_64/Makefile.target  |   2 +
 util/meson.build                  |   2 +
 11 files changed, 266 insertions(+), 110 deletions(-)
 create mode 100644 host/include/riscv/host/cpuinfo.h
 create mode 100644 tests/tcg/x86_64/test-2413.c
 create mode 100644 util/cpuinfo-riscv.c
#1 lore raw

[PULL 2/7] util/cpuinfo-ppc: Add FreeBSD support

From: Brad Smith <[email protected]>

Message-Id: <[email protected]>

---
 util/cpuinfo-ppc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
util/cpuinfo-ppc.c +8 -1
index 47af55aa0c..1304f9aa80 100644
@@ -14,6 +14,13 @@
 #  include "elf.h"
 # endif
 #endif
+#ifdef __FreeBSD__
+# include <machine/cpu.h>
+# ifndef PPC_FEATURE2_ARCH_3_1
+#  define PPC_FEATURE2_ARCH_3_1   0
+# endif
+# define PPC_FEATURE2_VEC_CRYPTO  PPC_FEATURE2_HAS_VEC_CRYPTO
+#endif
 
 unsigned cpuinfo;
 
@@ -28,7 +35,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
 
     info = CPUINFO_ALWAYS;
 
-#ifdef CONFIG_LINUX
+#if defined(CONFIG_LINUX) || defined(__FreeBSD__)
     unsigned long hwcap = qemu_getauxval(AT_HWCAP);
     unsigned long hwcap2 = qemu_getauxval(AT_HWCAP2);
 
Signature · 1 line
2.34.1
#2 lore raw

[PULL 1/7] util/cpuinfo-ppc: Fix building on OpenBSD

In reply to Richard Henderson

From: Brad Smith <[email protected]>

OpenBSD does not support AT_HWCAP.

Message-Id: <[email protected]>

---
 util/cpuinfo-ppc.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
util/cpuinfo-ppc.c +12 -8
index b2d8893a06..47af55aa0c 100644
@@ -6,11 +6,13 @@
 #include "qemu/osdep.h"
 #include "host/cpuinfo.h"
 
-#include <asm/cputable.h>
-#ifdef CONFIG_GETAUXVAL
-# include <sys/auxv.h>
-#else
-# include "elf.h"
+#ifdef CONFIG_LINUX
+# include <asm/cputable.h>
+# ifdef CONFIG_GETAUXVAL
+#  include <sys/auxv.h>
+# else
+#  include "elf.h"
+# endif
 #endif
 
 unsigned cpuinfo;
@@ -19,16 +21,17 @@ unsigned cpuinfo;
 unsigned __attribute__((constructor)) cpuinfo_init(void)
 {
     unsigned info = cpuinfo;
-    unsigned long hwcap, hwcap2;
 
     if (info) {
         return info;
     }
 
-    hwcap = qemu_getauxval(AT_HWCAP);
-    hwcap2 = qemu_getauxval(AT_HWCAP2);
     info = CPUINFO_ALWAYS;
 
+#ifdef CONFIG_LINUX
+    unsigned long hwcap = qemu_getauxval(AT_HWCAP);
+    unsigned long hwcap2 = qemu_getauxval(AT_HWCAP2);
+
     /* Version numbers are monotonic, and so imply all lower versions. */
     if (hwcap2 & PPC_FEATURE2_ARCH_3_1) {
         info |= CPUINFO_V3_1 | CPUINFO_V3_0 | CPUINFO_V2_07 | CPUINFO_V2_06;
@@ -58,6 +61,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
             }
         }
     }
+#endif
 
     cpuinfo = info;
     return info;
Signature · 1 line
2.34.1
#3 lore raw

[PULL 6/7] util/cpuinfo-riscv: Use linux __riscv_hwprobe syscall

In reply to Richard Henderson

With recent linux kernels, there is a syscall to probe for various ISA extensions. These bits were phased in over several kernel releases, so we still require checks for symbol availability.

---
 meson.build          |  6 ++++++
 util/cpuinfo-riscv.c | 26 ++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
meson.build +6 -0
index 54e6b09f4f..2f981f936e 100644
@@ -2862,6 +2862,12 @@ have_cpuid_h = cc.links('''
   }''')
 config_host_data.set('CONFIG_CPUID_H', have_cpuid_h)
 
+# Don't bother to advertise asm/hwprobe.h for old versions that do
+# not contain RISCV_HWPROBE_EXT_ZBA.
+config_host_data.set('CONFIG_ASM_HWPROBE_H',
+                     cc.has_header_symbol('asm/hwprobe.h',
+                                          'RISCV_HWPROBE_EXT_ZBA'))
+
 config_host_data.set('CONFIG_AVX2_OPT', get_option('avx2') \
   .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot enable AVX2') \
   .require(cc.links('''
util/cpuinfo-riscv.c +26 -0
index 7dcfbee2ab..497ce12680 100644
@@ -6,6 +6,11 @@
 #include "qemu/osdep.h"
 #include "host/cpuinfo.h"
 
+#ifdef CONFIG_ASM_HWPROBE_H
+#include <asm/hwprobe.h>
+#include <sys/syscall.h>
+#endif
+
 unsigned cpuinfo;
 static volatile sig_atomic_t got_sigill;
 
@@ -47,6 +52,27 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
 #endif
     left &= ~info;
 
+#ifdef CONFIG_ASM_HWPROBE_H
+    if (left) {
+        /*
+         * TODO: glibc 2.40 will introduce <sys/hwprobe.h>, which
+         * provides __riscv_hwprobe and __riscv_hwprobe_one,
+         * which is a slightly cleaner interface.
+         */
+        struct riscv_hwprobe pair = { .key = RISCV_HWPROBE_KEY_IMA_EXT_0 };
+        if (syscall(__NR_riscv_hwprobe, &pair, 1, 0, NULL, 0) == 0
+            && pair.key >= 0) {
+            info |= pair.value & RISCV_HWPROBE_EXT_ZBA ? CPUINFO_ZBA : 0;
+            info |= pair.value & RISCV_HWPROBE_EXT_ZBB ? CPUINFO_ZBB : 0;
+            left &= ~(CPUINFO_ZBA | CPUINFO_ZBB);
+#ifdef RISCV_HWPROBE_EXT_ZICOND
+            info |= pair.value & RISCV_HWPROBE_EXT_ZICOND ? CPUINFO_ZICOND : 0;
+            left &= ~CPUINFO_ZICOND;
+#endif
+        }
+    }
+#endif /* CONFIG_ASM_HWPROBE_H */
+
     if (left) {
         struct sigaction sa_old, sa_new;
 
Signature · 1 line
2.34.1
#4 lore raw

[PULL 3/7] util/cpuinfo-aarch64: Add OpenBSD support

In reply to Richard Henderson

From: Brad Smith <[email protected]>

Message-Id: <[email protected]>

---
 util/cpuinfo-aarch64.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
util/cpuinfo-aarch64.c +36 -0
index 4c8a005715..8ca775a14b 100644
@@ -20,6 +20,12 @@
 #ifdef CONFIG_DARWIN
 # include <sys/sysctl.h>
 #endif
+#ifdef __OpenBSD__
+# include <machine/armreg.h>
+# include <machine/cpu.h>
+# include <sys/types.h>
+# include <sys/sysctl.h>
+#endif
 
 unsigned cpuinfo;
 
@@ -72,6 +78,36 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
     info |= sysctl_for_bool("hw.optional.arm.FEAT_PMULL") * CPUINFO_PMULL;
     info |= sysctl_for_bool("hw.optional.arm.FEAT_BTI") * CPUINFO_BTI;
 #endif
+#ifdef __OpenBSD__
+    int mib[2];
+    uint64_t isar0;
+    uint64_t pfr1;
+    size_t len;
+
+    mib[0] = CTL_MACHDEP;
+    mib[1] = CPU_ID_AA64ISAR0;
+    len = sizeof(isar0);
+    if (sysctl(mib, 2, &isar0, &len, NULL, 0) != -1) {
+        if (ID_AA64ISAR0_ATOMIC(isar0) >= ID_AA64ISAR0_ATOMIC_IMPL) {
+            info |= CPUINFO_LSE;
+        }
+        if (ID_AA64ISAR0_AES(isar0) >= ID_AA64ISAR0_AES_BASE) {
+            info |= CPUINFO_AES;
+        }
+        if (ID_AA64ISAR0_AES(isar0) >= ID_AA64ISAR0_AES_PMULL) {
+            info |= CPUINFO_PMULL;
+        }
+    }
+
+    mib[0] = CTL_MACHDEP;
+    mib[1] = CPU_ID_AA64PFR1;
+    len = sizeof(pfr1);
+    if (sysctl(mib, 2, &pfr1, &len, NULL, 0) != -1) {
+        if (ID_AA64PFR1_BT(pfr1) >= ID_AA64PFR1_BT_IMPL) {
+            info |= CPUINFO_BTI;
+        }
+    }
+#endif
 
     cpuinfo = info;
     return info;
Signature · 1 line
2.34.1
#5 lore raw

[PULL 5/7] util/cpuinfo-riscv: Support OpenBSD signal frame

In reply to Richard Henderson
---
 util/cpuinfo-riscv.c | 7 +++++++
 1 file changed, 7 insertions(+)
util/cpuinfo-riscv.c +7 -0
index 1236ee5fa4..7dcfbee2ab 100644
@@ -13,7 +13,14 @@ static void sigill_handler(int signo, siginfo_t *si, void *data)
 {
     /* Skip the faulty instruction */
     ucontext_t *uc = (ucontext_t *)data;
+
+#ifdef __linux__
     uc->uc_mcontext.__gregs[REG_PC] += 4;
+#elif defined(__OpenBSD__)
+    uc->sc_sepc += 4;
+#else
+# error Unsupported OS
+#endif
 
     got_sigill = 1;
 }
Signature · 1 line
2.34.1
#6 lore raw

[PULL 4/7] util/cpuinfo-riscv: Support host/cpuinfo.h for riscv

In reply to Richard Henderson

Move detection code out of tcg, similar to other hosts.

---
 host/include/riscv/host/cpuinfo.h | 23 +++++++++
 tcg/riscv/tcg-target.h            | 46 ++++++++---------
 util/cpuinfo-riscv.c              | 85 +++++++++++++++++++++++++++++++
 tcg/riscv/tcg-target.c.inc        | 84 +++---------------------------
 util/meson.build                  |  2 +
 5 files changed, 139 insertions(+), 101 deletions(-)
 create mode 100644 host/include/riscv/host/cpuinfo.h
 create mode 100644 util/cpuinfo-riscv.c
host/include/riscv/host/cpuinfo.h new file +23 -0
new file mode 100644
index 0000000000..2b00660e36
@@ -0,0 +1,23 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * Host specific cpu identification for RISC-V.
+ */
+
+#ifndef HOST_CPUINFO_H
+#define HOST_CPUINFO_H
+
+#define CPUINFO_ALWAYS          (1u << 0)  /* so cpuinfo is nonzero */
+#define CPUINFO_ZBA             (1u << 1)
+#define CPUINFO_ZBB             (1u << 2)
+#define CPUINFO_ZICOND          (1u << 3)
+
+/* Initialized with a constructor. */
+extern unsigned cpuinfo;
+
+/*
+ * We cannot rely on constructor ordering, so other constructors must
+ * use the function interface rather than the variable above.
+ */
+unsigned cpuinfo_init(void);
+
+#endif /* HOST_CPUINFO_H */
tcg/riscv/tcg-target.h +21 -25

87 lines not on this page · raw message

util/cpuinfo-riscv.c new file +85 -0

85 lines not on this page · raw message

tcg/riscv/tcg-target.c.inc +8 -76

146 lines not on this page · raw message

util/meson.build +2 -0
index 72b505df11..5d8bef9891 100644
@@ -127,4 +127,6 @@ elif cpu == 'loongarch64'
   util_ss.add(files('cpuinfo-loongarch.c'))
 elif cpu in ['ppc', 'ppc64']
   util_ss.add(files('cpuinfo-ppc.c'))
+elif cpu in ['riscv32', 'riscv64']
+  util_ss.add(files('cpuinfo-riscv.c'))
 endif
Signature · 1 line
2.34.1
#7 lore raw

[PULL 7/7] tcg/optimize: Fix TCG_COND_TST* simplification of setcond2

In reply to Richard Henderson

Argument ordering for setcond2 is:

output, a_low, a_high, b_low, b_high, cond

The test is supposed to be against b_low, not a_high.

Fixes ceb9ee06b71 ("tcg/optimize: Handle TCG_COND_TST{EQ,NE}")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2413

Message-Id: <[email protected]>

---
 tcg/optimize.c                   |  2 +-
 tests/tcg/x86_64/test-2413.c     | 30 ++++++++++++++++++++++++++++++
 tests/tcg/x86_64/Makefile.target |  2 ++
 3 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/x86_64/test-2413.c
tcg/optimize.c +1 -1
index 8886f7037a..ba16ec27e2 100644
@@ -2384,7 +2384,7 @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op)
 
     case TCG_COND_TSTEQ:
     case TCG_COND_TSTNE:
-        if (arg_is_const_val(op->args[2], 0)) {
+        if (arg_is_const_val(op->args[3], 0)) {
             goto do_setcond_high;
         }
         if (arg_is_const_val(op->args[4], 0)) {
tests/tcg/x86_64/test-2413.c new file +30 -0
new file mode 100644
index 0000000000..456e5332fc
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright 2024 Linaro, Ltd. */
+/* See https://gitlab.com/qemu-project/qemu/-/issues/2413 */
+
+#include <assert.h>
+
+void test(unsigned long *a, unsigned long *d, unsigned long c)
+{
+    asm("xorl %%eax, %%eax\n\t"
+        "xorl %%edx, %%edx\n\t"
+        "testb $0x20, %%cl\n\t"
+        "sete %%al\n\t"
+        "setne %%dl\n\t"
+        "shll %%cl, %%eax\n\t"
+        "shll %%cl, %%edx\n\t"
+        : "=a"(*a), "=d"(*d)
+        : "c"(c));
+}
+
+int main(void)
+{
+    unsigned long a, c, d;
+
+    for (c = 0; c < 64; c++) {
+        test(&a, &d, c);
+        assert(a == (c & 0x20 ? 0 : 1u << (c & 0x1f)));
+        assert(d == (c & 0x20 ? 1u << (c & 0x1f) : 0));
+    }
+    return 0;
+}
tests/tcg/x86_64/Makefile.target +2 -0
index 5fedf22117..eda9bd7396 100644
@@ -8,6 +8,8 @@
 
 include $(SRC_PATH)/tests/tcg/i386/Makefile.target
 
+X86_64_TESTS += test-2413
+
 ifeq ($(filter %-linux-user, $(TARGET)),$(TARGET))
 X86_64_TESTS += vsyscall
 X86_64_TESTS += noexec
Signature · 1 line
2.34.1
author Applied
#8 lore raw
In reply to Richard Henderson
Quoted 8 lines · Richard Henderson

The following changes since commit 6746482d12da3b6e4d3cdf06481a0027a797f719:

   Merge tag 'sdmmc-20240702' ofhttps://github.com/philmd/qemu  into staging (2024-07-02 09:52:10 -0700)

are available in the Git repository at:

   https://gitlab.com/rth7680/qemu  tags/pull-tcg-20240703
Quoted 8 lines

for you to fetch changes up to a71d9dfbf63db42d6e6ae87fc112d1f5502183bd:

   tcg/optimize: Fix TCG_COND_TST* simplification of setcond2 (2024-07-03 10:24:12 -0700)

----------------------------------------------------------------
util: cpuinfo portability fixes for FreeBSD and OpenBSD
util: cpuinfo for riscv host
tcg/optimize: Fix TCG_COND_TST* simplification of setcond2

Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/9.1 as appropriate.

r~