Skip to contentSkip to conversation

Improve getauxval support

PATCH In review Richard Henderson 2 participants 12 messages Oct 17, 2013 – Nov 29, 2013

lore
Share & tools
lore
#0 lore raw

v3 cover Improve getauxval support

Changes from v2:
* Rebase for trivial conflicts
* Fix codingstyle errors
* Drop the static fallback code
* Use getauxval for AT_EXECFD

r~

Richard Henderson (6):
osdep: Create qemu_getauxval and qemu_init_auxval
tcg-ppc64: Use qemu_getauxval
tcg-arm: Use qemu_getauxval
tcg-s390: Use qemu_getauxval in query_facilities
util: Use qemu_getauxval in linux qemu_cache_utils_init
linux-user: Use qemu_getauxval for AT_EXECFD

 include/elf.h              | 73 +++++++++++++++++++++++++++++++++++
 include/qemu/cache-utils.h |  4 +-
 include/qemu/osdep.h       | 25 ++++++++++++
 linux-user/main.c          | 35 ++++-------------
 tcg/arm/tcg-target.c       | 14 +++----
 tcg/ppc64/tcg-target.c     | 11 +-----
 tcg/s390/tcg-target.c      | 95 ++++++----------------------------------------
 util/Makefile.objs         |  1 +
 util/cache-utils.c         | 51 ++++++++++---------------
 util/getauxval.c           | 74 ++++++++++++++++++++++++++++++++++++
 vl.c                       |  3 +-
 11 files changed, 224 insertions(+), 162 deletions(-)
 create mode 100644 util/getauxval.c
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v3 1/6 osdep: Create qemu_getauxval and qemu_init_auxval

Abstract away dependence on a system implementation of getauxval.

---
 include/qemu/osdep.h | 25 ++++++++++++++++++
 linux-user/main.c    |  1 +
 util/Makefile.objs   |  1 +
 util/getauxval.c     | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c                 |  1 +
 5 files changed, 102 insertions(+)
 create mode 100644 util/getauxval.c
include/qemu/osdep.h +25 -0
index 26136f1..b3e2b6d 100644
@@ -215,4 +215,29 @@ bool fips_get_state(void);
  */
 char *qemu_get_local_state_pathname(const char *relative_pathname);
 
+/**
+ * qemu_getauxval:
+ * @type: the auxiliary vector key to lookup
+ *
+ * Search the auxiliary vector for @type, returning the value
+ * or 0 if @type is not present.
+ */
+#if defined(CONFIG_GETAUXVAL) || defined(__linux__)
+unsigned long qemu_getauxval(unsigned long type);
+#else
+static inline unsigned long qemu_getauxval(unsigned long type) { return 0; }
+#endif
+
+/**
+ * qemu_init_auxval:
+ * @envp: the third argument to main
+ *
+ * If supported and required, locate the auxiliary vector at program startup.
+ */
+#if defined(CONFIG_GETAUXVAL) || !defined(__linux__)
+static inline void qemu_init_auxval(char **envp) { }
+#else
+void qemu_init_auxval(char **envp);
+#endif
+
 #endif
linux-user/main.c +1 -0
index 6b4ab09..0e45336 100644
@@ -3701,6 +3701,7 @@ int main(int argc, char **argv, char **envp)
 
     module_call_init(MODULE_INIT_QOM);
 
+    qemu_init_auxval(envp);
     qemu_cache_utils_init(envp);
 
     if ((envlist = envlist_create()) == NULL) {
util/Makefile.objs +1 -0
index 2bb13a2..af3e5cb 100644
@@ -12,3 +12,4 @@ util-obj-y += qemu-option.o qemu-progress.o
 util-obj-y += hexdump.o
 util-obj-y += crc32c.o
 util-obj-y += throttle.o
+util-obj-y += getauxval.o
util/getauxval.c new file +74 -0

74 lines not on this page · raw message

vl.c +1 -0
index 7e1f408..1b0b2d3 100644
@@ -2893,6 +2893,7 @@ int main(int argc, char **argv, char **envp)
     init_clocks();
     rtc_clock = QEMU_CLOCK_HOST;
 
+    qemu_init_auxval(envp);
     qemu_cache_utils_init(envp);
 
     QLIST_INIT (&vm_change_state_head);
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v3 2/6 tcg-ppc64: Use qemu_getauxval

In reply to Richard Henderson

Allow host detection on linux systems without glibc 2.16 or later.

---
 include/elf.h          | 34 ++++++++++++++++++++++++++++++++++
 tcg/ppc64/tcg-target.c | 11 ++---------
 2 files changed, 36 insertions(+), 9 deletions(-)
include/elf.h +34 -0
index 58bfbf8..7fdd3df 100644
@@ -411,6 +411,40 @@ typedef struct {
 #define R_SPARC_5		44
 #define R_SPARC_6		45
 
+/* Bits present in AT_HWCAP for PowerPC.  */
+
+#define PPC_FEATURE_32                  0x80000000
+#define PPC_FEATURE_64                  0x40000000
+#define PPC_FEATURE_601_INSTR           0x20000000
+#define PPC_FEATURE_HAS_ALTIVEC         0x10000000
+#define PPC_FEATURE_HAS_FPU             0x08000000
+#define PPC_FEATURE_HAS_MMU             0x04000000
+#define PPC_FEATURE_HAS_4xxMAC          0x02000000
+#define PPC_FEATURE_UNIFIED_CACHE       0x01000000
+#define PPC_FEATURE_HAS_SPE             0x00800000
+#define PPC_FEATURE_HAS_EFP_SINGLE      0x00400000
+#define PPC_FEATURE_HAS_EFP_DOUBLE      0x00200000
+#define PPC_FEATURE_NO_TB               0x00100000
+#define PPC_FEATURE_POWER4              0x00080000
+#define PPC_FEATURE_POWER5              0x00040000
+#define PPC_FEATURE_POWER5_PLUS         0x00020000
+#define PPC_FEATURE_CELL                0x00010000
+#define PPC_FEATURE_BOOKE               0x00008000
+#define PPC_FEATURE_SMT                 0x00004000
+#define PPC_FEATURE_ICACHE_SNOOP        0x00002000
+#define PPC_FEATURE_ARCH_2_05           0x00001000
+#define PPC_FEATURE_PA6T                0x00000800
+#define PPC_FEATURE_HAS_DFP             0x00000400
+#define PPC_FEATURE_POWER6_EXT          0x00000200
+#define PPC_FEATURE_ARCH_2_06           0x00000100
+#define PPC_FEATURE_HAS_VSX             0x00000080
+
+#define PPC_FEATURE_PSERIES_PERFMON_COMPAT \
+                                        0x00000040
+
+#define PPC_FEATURE_TRUE_LE             0x00000002
+#define PPC_FEATURE_PPC_LE              0x00000001
+
 /* Bits present in AT_HWCAP, primarily for Sparc32.  */
 
 #define HWCAP_SPARC_FLUSH       1    /* CPU supports flush instruction. */
tcg/ppc64/tcg-target.c +2 -9
index 6109d86..06e440f 100644
@@ -45,15 +45,10 @@ static uint8_t *tb_ret_addr;
 #define GUEST_BASE 0
 #endif
 
-#ifdef CONFIG_GETAUXVAL
-#include <sys/auxv.h>
+#include "elf.h"
 static bool have_isa_2_06;
 #define HAVE_ISA_2_06  have_isa_2_06
 #define HAVE_ISEL      have_isa_2_06
-#else
-#define HAVE_ISA_2_06  0
-#define HAVE_ISEL      0
-#endif
 
 #ifdef CONFIG_USE_GUEST_BASE
 #define TCG_GUEST_BASE_REG 30
@@ -2132,12 +2127,10 @@ static const TCGTargetOpDef ppc_op_defs[] = {
 
 static void tcg_target_init(TCGContext *s)
 {
-#ifdef CONFIG_GETAUXVAL
-    unsigned long hwcap = getauxval(AT_HWCAP);
+    unsigned long hwcap = qemu_getauxval(AT_HWCAP);
     if (hwcap & PPC_FEATURE_ARCH_2_06) {
         have_isa_2_06 = true;
     }
-#endif
 
     tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I32], 0, 0xffffffff);
     tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I64], 0, 0xffffffff);
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH v3 3/6 tcg-arm: Use qemu_getauxval

In reply to Richard Henderson

Allow host detection on linux systems without glibc 2.16 or later.

---
 include/elf.h        | 25 +++++++++++++++++++++++++
 tcg/arm/tcg-target.c | 14 +++++---------
 2 files changed, 30 insertions(+), 9 deletions(-)
include/elf.h +25 -0
index 7fdd3df..654e33b 100644
@@ -411,6 +411,31 @@ typedef struct {
 #define R_SPARC_5		44
 #define R_SPARC_6		45
 
+/* Bits present in AT_HWCAP for ARM.  */
+
+#define HWCAP_ARM_SWP           (1 << 0)
+#define HWCAP_ARM_HALF          (1 << 1)
+#define HWCAP_ARM_THUMB         (1 << 2)
+#define HWCAP_ARM_26BIT         (1 << 3)
+#define HWCAP_ARM_FAST_MULT     (1 << 4)
+#define HWCAP_ARM_FPA           (1 << 5)
+#define HWCAP_ARM_VFP           (1 << 6)
+#define HWCAP_ARM_EDSP          (1 << 7)
+#define HWCAP_ARM_JAVA          (1 << 8)
+#define HWCAP_ARM_IWMMXT        (1 << 9)
+#define HWCAP_ARM_CRUNCH        (1 << 10)
+#define HWCAP_ARM_THUMBEE       (1 << 11)
+#define HWCAP_ARM_NEON          (1 << 12)
+#define HWCAP_ARM_VFPv3         (1 << 13)
+#define HWCAP_ARM_VFPv3D16      (1 << 14)       /* also set for VFPv4-D16 */
+#define HWCAP_ARM_TLS           (1 << 15)
+#define HWCAP_ARM_VFPv4         (1 << 16)
+#define HWCAP_ARM_IDIVA         (1 << 17)
+#define HWCAP_ARM_IDIVT         (1 << 18)
+#define HWCAP_IDIV              (HWCAP_IDIVA | HWCAP_IDIVT)
+#define HWCAP_VFPD32            (1 << 19)       /* set if VFP has 32 regs */
+#define HWCAP_LPAE              (1 << 20)
+
 /* Bits present in AT_HWCAP for PowerPC.  */
 
 #define PPC_FEATURE_32                  0x80000000
tcg/arm/tcg-target.c +5 -9
index e93a4a2..82658a1 100644
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 
+#include "elf.h"
 #include "tcg-be-ldst.h"
 
 /* The __ARM_ARCH define is provided by gcc 4.8.  Construct it otherwise.  */
@@ -58,9 +59,6 @@ static int arm_arch = __ARM_ARCH;
 #ifndef use_idiv_instructions
 bool use_idiv_instructions;
 #endif
-#ifdef CONFIG_GETAUXVAL
-# include <sys/auxv.h>
-#endif
 
 #ifndef NDEBUG
 static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
@@ -2036,22 +2034,20 @@ static const TCGTargetOpDef arm_op_defs[] = {
 
 static void tcg_target_init(TCGContext *s)
 {
-#if defined(CONFIG_GETAUXVAL)
     /* Only probe for the platform and capabilities if we havn't already
        determined maximum values at compile time.  */
-# if !defined(use_idiv_instructions)
+#ifndef use_idiv_instructions
     {
-        unsigned long hwcap = getauxval(AT_HWCAP);
+        unsigned long hwcap = qemu_getauxval(AT_HWCAP);
         use_idiv_instructions = (hwcap & HWCAP_ARM_IDIVA) != 0;
     }
-# endif
+#endif
     if (__ARM_ARCH < 7) {
-        const char *pl = (const char *)getauxval(AT_PLATFORM);
+        const char *pl = (const char *)qemu_getauxval(AT_PLATFORM);
         if (pl != NULL && pl[0] == 'v' && pl[1] >= '4' && pl[1] <= '9') {
             arm_arch = pl[1] - '0';
         }
     }
-#endif /* GETAUXVAL */
 
     tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I32], 0, 0xffff);
     tcg_regset_set32(tcg_target_call_clobber_regs, 0,
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH v3 4/6 tcg-s390: Use qemu_getauxval in query_facilities

In reply to Richard Henderson

No need to set up a SIGILL signal handler for detection anymore.

Remove a ton of sanity checks that must be true, given that we're requiring a 64-bit build (the note about 31-bit KVM is satisfied by configuring with TCI).

---
 include/elf.h         | 14 ++++++++
 tcg/s390/tcg-target.c | 95 +++++++--------------------------------------------
 2 files changed, 26 insertions(+), 83 deletions(-)
include/elf.h +14 -0
index 654e33b..a6790c4 100644
@@ -479,6 +479,20 @@ typedef struct {
 #define HWCAP_SPARC_V9		16
 #define HWCAP_SPARC_ULTRA3	32
 
+/* Bits present in AT_HWCAP for s390.  */
+
+#define HWCAP_S390_ESAN3        1
+#define HWCAP_S390_ZARCH        2
+#define HWCAP_S390_STFLE        4
+#define HWCAP_S390_MSA          8
+#define HWCAP_S390_LDISP        16
+#define HWCAP_S390_EIMM         32
+#define HWCAP_S390_DFP          64
+#define HWCAP_S390_HPAGE        128
+#define HWCAP_S390_ETF3EH       256
+#define HWCAP_S390_HIGH_GPRS    512
+#define HWCAP_S390_TE           1024
+
 /*
  * 68k ELF relocation types
  */
tcg/s390/tcg-target.c +12 -83

109 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#7 lore raw

PATCH v3 5/6 util: Use qemu_getauxval in linux qemu_cache_utils_init

In reply to Richard Henderson

With this we no longer pass down envp, and thus all systems can have the same void prototype. So also eliminate a useless thunk.

---
 include/qemu/cache-utils.h |  4 ++--
 linux-user/main.c          |  2 +-
 util/cache-utils.c         | 51 ++++++++++++++++++----------------------------
 vl.c                       |  2 +-
 4 files changed, 24 insertions(+), 35 deletions(-)
include/qemu/cache-utils.h +2 -2
index 2c57f78..211245b 100644
@@ -12,7 +12,7 @@ struct qemu_cache_conf {
 
 extern struct qemu_cache_conf qemu_cache_conf;
 
-void qemu_cache_utils_init(char **envp);
+void qemu_cache_utils_init(void);
 
 /* mildly adjusted code from tcg-dyngen.c */
 static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
@@ -38,7 +38,7 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
 }
 
 #else
-#define qemu_cache_utils_init(envp) do { (void) (envp); } while (0)
+#define qemu_cache_utils_init() do { } while (0)
 #endif
 
 #endif /* QEMU_CACHE_UTILS_H */
linux-user/main.c +1 -1
index 0e45336..50db755 100644
@@ -3702,7 +3702,7 @@ int main(int argc, char **argv, char **envp)
     module_call_init(MODULE_INIT_QOM);
 
     qemu_init_auxval(envp);
-    qemu_cache_utils_init(envp);
+    qemu_cache_utils_init();
 
     if ((envlist = envlist_create()) == NULL) {
         (void) fprintf(stderr, "Unable to allocate envlist\n");
util/cache-utils.c +20 -31

94 lines not on this page · raw message

vl.c +1 -1
index 1b0b2d3..4b46c70 100644
@@ -2894,7 +2894,7 @@ int main(int argc, char **argv, char **envp)
     rtc_clock = QEMU_CLOCK_HOST;
 
     qemu_init_auxval(envp);
-    qemu_cache_utils_init(envp);
+    qemu_cache_utils_init();
 
     QLIST_INIT (&vm_change_state_head);
     os_setup_early_signal_handling();
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH v3 6/6 linux-user: Use qemu_getauxval for AT_EXECFD

In reply to Richard Henderson
---
 linux-user/main.c | 32 ++++++--------------------------
 1 file changed, 6 insertions(+), 26 deletions(-)
linux-user/main.c +6 -26
index 50db755..54f71fe 100644
@@ -3663,26 +3663,6 @@ static int parse_args(int argc, char **argv)
     return optind;
 }
 
-static int get_execfd(char **envp)
-{
-    typedef struct {
-        long a_type;
-        long a_val;
-    } auxv_t;
-    auxv_t *auxv;
-
-    while (*envp++ != NULL) {
-        ;
-    }
-
-    for (auxv = (auxv_t *)envp; auxv->a_type != AT_NULL; auxv++) {
-        if (auxv->a_type == AT_EXECFD) {
-            return auxv->a_val;
-        }
-    }
-    return -1;
-}
-
 int main(int argc, char **argv, char **envp)
 {
     struct target_pt_regs regs1, *regs = &regs1;
@@ -3876,13 +3856,13 @@ int main(int argc, char **argv, char **envp)
     env->opaque = ts;
     task_settid(ts);
 
-    execfd = get_execfd(envp);
-    if (execfd < 0) {
+    execfd = qemu_getauxval(AT_EXECFD);
+    if (execfd == 0) {
         execfd = open(filename, O_RDONLY);
-    }
-    if (execfd < 0) {
-        printf("Error while loading %s: %s\n", filename, strerror(-execfd));
-        _exit(1);
+        if (execfd < 0) {
+            printf("Error while loading %s: %s\n", filename, strerror(errno));
+            _exit(1);
+        }
     }
 
     ret = loader_exec(execfd, filename, target_argv, target_environ, regs,
Signature · 1 line
1.8.3.1
#10 lore raw
In reply to Richard Henderson

Ping.

r~

Quoted 32 lines · Richard Henderson

Changes from v2:
* Rebase for trivial conflicts
* Fix codingstyle errors
* Drop the static fallback code
* Use getauxval for AT_EXECFD

r~

Richard Henderson (6):
osdep: Create qemu_getauxval and qemu_init_auxval
tcg-ppc64: Use qemu_getauxval
tcg-arm: Use qemu_getauxval
tcg-s390: Use qemu_getauxval in query_facilities
util: Use qemu_getauxval in linux qemu_cache_utils_init
linux-user: Use qemu_getauxval for AT_EXECFD

 include/elf.h              | 73 +++++++++++++++++++++++++++++++++++
 include/qemu/cache-utils.h |  4 +-
 include/qemu/osdep.h       | 25 ++++++++++++
 linux-user/main.c          | 35 ++++-------------
 tcg/arm/tcg-target.c       | 14 +++----
 tcg/ppc64/tcg-target.c     | 11 +-----
 tcg/s390/tcg-target.c      | 95 ++++++----------------------------------------
 util/Makefile.objs         |  1 +
 util/cache-utils.c         | 51 ++++++++++---------------
 util/getauxval.c           | 74 ++++++++++++++++++++++++++++++++++++
 vl.c                       |  3 +-
 11 files changed, 224 insertions(+), 162 deletions(-)
 create mode 100644 util/getauxval.c
#11 lore raw

Ping.

r~

Quoted 38 lines · Richard Henderson

Ping.

r~

Quoted 32 lines · Richard Henderson

Changes from v2:
* Rebase for trivial conflicts
* Fix codingstyle errors
* Drop the static fallback code
* Use getauxval for AT_EXECFD

r~

Richard Henderson (6):
osdep: Create qemu_getauxval and qemu_init_auxval
tcg-ppc64: Use qemu_getauxval
tcg-arm: Use qemu_getauxval
tcg-s390: Use qemu_getauxval in query_facilities
util: Use qemu_getauxval in linux qemu_cache_utils_init
linux-user: Use qemu_getauxval for AT_EXECFD

 include/elf.h              | 73 +++++++++++++++++++++++++++++++++++
 include/qemu/cache-utils.h |  4 +-
 include/qemu/osdep.h       | 25 ++++++++++++
 linux-user/main.c          | 35 ++++-------------
 tcg/arm/tcg-target.c       | 14 +++----
 tcg/ppc64/tcg-target.c     | 11 +-----
 tcg/s390/tcg-target.c      | 95 ++++++----------------------------------------
 util/Makefile.objs         |  1 +
 util/cache-utils.c         | 51 ++++++++++---------------
 util/getauxval.c           | 74 ++++++++++++++++++++++++++++++++++++
 vl.c                       |  3 +-
 11 files changed, 224 insertions(+), 162 deletions(-)
 create mode 100644 util/getauxval.c