Skip to contentSkip to conversation

linux-user: elf: ELF_HWCAP for s390x

PATCH In review David Hildenbrand 3 participants 5 messages Jun 4, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: elf: ELF_HWCAP for s390x

Let's add all HWCAPs that we can support under TCG right now, when the respective CPU facilities are enabled.

Cc Riku Voipio <[email protected]>
Cc Laurent Vivier <[email protected]>
Cc Cornelia Huck <[email protected]>
Cc Laurent Vivier <[email protected]>
Cc Richard Henderson <[email protected]>

---

This patch is based on "[PATCH v2 00/22] s390x/tcg: Vector Instruction Support Part 4". I guess it is best if I just include it in my next pull request.

---
 include/elf.h        |  1 +
 linux-user/elfload.c | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
include/elf.h +1 -0
index ea7708a4ea..3501e0c8d0 100644
@@ -598,6 +598,7 @@ typedef struct {
 #define HWCAP_S390_ETF3EH       256
 #define HWCAP_S390_HIGH_GPRS    512
 #define HWCAP_S390_TE           1024
+#define HWCAP_S390_VXRS         2048
 
 /* M68K specific definitions. */
 /* We use the top 24 bits to encode information about the
linux-user/elfload.c +39 -0
index a57b7049dd..59b813066c 100644
@@ -1308,6 +1308,45 @@ static inline void init_thread(struct target_pt_regs *regs,
 #define ELF_DATA	ELFDATA2MSB
 #define ELF_ARCH	EM_S390
 
+#include "elf.h"
+
+#define ELF_HWCAP get_elf_hwcap()
+
+static uint32_t get_elf_hwcap(void)
+{
+    uint32_t hwcap = 0;
+
+    if (s390_has_feat(S390_FEAT_ESAN3)) {
+        hwcap |= HWCAP_S390_ESAN3;
+    }
+    if (s390_has_feat(S390_FEAT_ZARCH)) {
+        hwcap |= HWCAP_S390_ZARCH;
+    }
+    if (s390_has_feat(S390_FEAT_STFLE)) {
+        hwcap |= HWCAP_S390_STFLE;
+    }
+    if (s390_has_feat(S390_FEAT_MSA)) {
+        hwcap |= HWCAP_S390_MSA;
+    }
+    if (s390_has_feat(S390_FEAT_LONG_DISPLACEMENT)) {
+        hwcap |= HWCAP_S390_LDISP;
+    }
+    if (s390_has_feat(S390_FEAT_EXTENDED_IMMEDIATE)) {
+        hwcap |= HWCAP_S390_EIMM;
+    }
+    if (s390_has_feat(S390_FEAT_EXTENDED_TRANSLATION_3) &&
+        s390_has_feat(S390_FEAT_ETF3_ENH)) {
+        hwcap |= HWCAP_S390_ETF3EH;
+    }
+    /* 31-bit processes can use 64-bit registers */
+    hwcap |= HWCAP_S390_HIGH_GPRS;
+    if (s390_has_feat(S390_FEAT_VECTOR)) {
+        hwcap |= HWCAP_S390_VXRS;
+    }
+
+    return hwcap;
+}
+
 static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
 {
     regs->psw.addr = infop->entry;
Signature · 1 line
2.21.0
Acked-by on v1 1/1
#1 lore raw

Le 04/06/2019 à 11:36, David Hildenbrand a écrit :

Quoted 9 lines

Let's add all HWCAPs that we can support under TCG right now, when the respective CPU facilities are enabled.

Cc Riku Voipio <[email protected]>
Cc Laurent Vivier <[email protected]>
Cc Cornelia Huck <[email protected]>
Cc Laurent Vivier <[email protected]>
Cc Richard Henderson <[email protected]>
Quoted 5 lines

---

This patch is based on "[PATCH v2 00/22] s390x/tcg: Vector Instruction Support Part 4". I guess it is best if I just include it in my next pull request.

Based-on: <[email protected]>

          [PATCH v2 00/22] s390x/tcg: Vector Instruction Support Part 4
Quoted 59 lines
---
 include/elf.h        |  1 +
 linux-user/elfload.c | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
include/elf.h +1 -0
index ea7708a4ea..3501e0c8d0 100644
@@ -598,6 +598,7 @@ typedef struct {
 #define HWCAP_S390_ETF3EH       256
 #define HWCAP_S390_HIGH_GPRS    512
 #define HWCAP_S390_TE           1024
+#define HWCAP_S390_VXRS         2048
 
 /* M68K specific definitions. */
 /* We use the top 24 bits to encode information about the
linux-user/elfload.c +32 -0
index a57b7049dd..59b813066c 100644
@@ -1308,6 +1308,45 @@ static inline void init_thread(struct target_pt_regs *regs,
 #define ELF_DATA	ELFDATA2MSB
 #define ELF_ARCH	EM_S390
 
+#include "elf.h"
+
+#define ELF_HWCAP get_elf_hwcap()
+
+static uint32_t get_elf_hwcap(void)
+{
+    uint32_t hwcap = 0;
+
+    if (s390_has_feat(S390_FEAT_ESAN3)) {
+        hwcap |= HWCAP_S390_ESAN3;
+    }
+    if (s390_has_feat(S390_FEAT_ZARCH)) {
+        hwcap |= HWCAP_S390_ZARCH;
+    }
+    if (s390_has_feat(S390_FEAT_STFLE)) {
+        hwcap |= HWCAP_S390_STFLE;
+    }
+    if (s390_has_feat(S390_FEAT_MSA)) {
+        hwcap |= HWCAP_S390_MSA;
+    }
+    if (s390_has_feat(S390_FEAT_LONG_DISPLACEMENT)) {
+        hwcap |= HWCAP_S390_LDISP;
+    }
+    if (s390_has_feat(S390_FEAT_EXTENDED_IMMEDIATE)) {
+        hwcap |= HWCAP_S390_EIMM;
+    }
+    if (s390_has_feat(S390_FEAT_EXTENDED_TRANSLATION_3) &&
+        s390_has_feat(S390_FEAT_ETF3_ENH)) {
+        hwcap |= HWCAP_S390_ETF3EH;
+    }
+    /* 31-bit processes can use 64-bit registers */
+    hwcap |= HWCAP_S390_HIGH_GPRS;

linux-user/elfload.c static inline void init_thread(struct target_pt_regs *regs, · line 1352

Quoted 10 lines
linux-user/elfload.c +7 -0
+    if (s390_has_feat(S390_FEAT_VECTOR)) {
+        hwcap |= HWCAP_S390_VXRS;
+    }
+
+    return hwcap;
+}
+
 static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
 {
     regs->psw.addr = infop->entry;

You can also do like the other architectures that use shortcuts like this:

#define GET_FEATURE(feat, hwcap) \
    do { if (s390_has_feat(feat)) { hwcaps |= hwcap; } } while (0)

...
GET_FEATURE(S390_FEAT_VECTOR, HWCAP_S390_VXRS);
...

Thanks,
Laurent

Reviewed-by on v1 1/1
#3 lore raw
In reply to David Hildenbrand

linux-user/elfload.c static inline void init_thread(struct target_pt_regs *regs, · line 1324

Quoted 6 lines · David Hildenbrand
linux-user/elfload.c +6 -0
+    if (s390_has_feat(S390_FEAT_ESAN3)) {
+        hwcap |= HWCAP_S390_ESAN3;
+    }
+    if (s390_has_feat(S390_FEAT_ZARCH)) {
+        hwcap |= HWCAP_S390_ZARCH;
+    }

While it's nice and symetrical testing these two features, I don't think they can ever be false.

Quoted 8 lines
linux-user/elfload.c +8 -0
+    if (s390_has_feat(S390_FEAT_STFLE)) {
+        hwcap |= HWCAP_S390_STFLE;
+    }
+    if (s390_has_feat(S390_FEAT_MSA)) {
+        hwcap |= HWCAP_S390_MSA;
+    }
+    if (s390_has_feat(S390_FEAT_LONG_DISPLACEMENT)) {
+        hwcap |= HWCAP_S390_LDISP;

linux-user/elfload.c static inline void init_thread(struct target_pt_regs *regs, · line 1342

Quoted 10 lines
linux-user/elfload.c +10 -0
+    }
+    if (s390_has_feat(S390_FEAT_EXTENDED_IMMEDIATE)) {
+        hwcap |= HWCAP_S390_EIMM;
+    }
+    if (s390_has_feat(S390_FEAT_EXTENDED_TRANSLATION_3) &&
+        s390_has_feat(S390_FEAT_ETF3_ENH)) {
+        hwcap |= HWCAP_S390_ETF3EH;
+    }
+    /* 31-bit processes can use 64-bit registers */
+    hwcap |= HWCAP_S390_HIGH_GPRS;

And certainly this could never be set unless ZARCH, otherwise you have no 64-bit registers. ;-)

So maybe clearer to just start with

  hwcap = HWCAP_S390_ESAN3 | HWCAP_S390_ZARCH | HWCAP_S390_HIGH_GPRS;

and continue from there.

Otherwise,

r~

#2 lore raw
In reply to Laurent Vivier
Quoted 90 lines · Laurent Vivier

Le 04/06/2019 à 11:36, David Hildenbrand a écrit :

Quoted 9 lines

Let's add all HWCAPs that we can support under TCG right now, when the respective CPU facilities are enabled.

Cc Riku Voipio <[email protected]>
Cc Laurent Vivier <[email protected]>
Cc Cornelia Huck <[email protected]>
Cc Laurent Vivier <[email protected]>
Cc Richard Henderson <[email protected]>
Quoted 5 lines

---

This patch is based on "[PATCH v2 00/22] s390x/tcg: Vector Instruction Support Part 4". I guess it is best if I just include it in my next pull request.

Based-on: <[email protected]>

          [PATCH v2 00/22] s390x/tcg: Vector Instruction Support Part 4
Quoted 59 lines
---
 include/elf.h        |  1 +
 linux-user/elfload.c | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
include/elf.h +1 -0
index ea7708a4ea..3501e0c8d0 100644
@@ -598,6 +598,7 @@ typedef struct {
 #define HWCAP_S390_ETF3EH       256
 #define HWCAP_S390_HIGH_GPRS    512
 #define HWCAP_S390_TE           1024
+#define HWCAP_S390_VXRS         2048
 
 /* M68K specific definitions. */
 /* We use the top 24 bits to encode information about the
linux-user/elfload.c +32 -0
index a57b7049dd..59b813066c 100644
@@ -1308,6 +1308,45 @@ static inline void init_thread(struct target_pt_regs *regs,
 #define ELF_DATA	ELFDATA2MSB
 #define ELF_ARCH	EM_S390
 
+#include "elf.h"
+
+#define ELF_HWCAP get_elf_hwcap()
+
+static uint32_t get_elf_hwcap(void)
+{
+    uint32_t hwcap = 0;
+
+    if (s390_has_feat(S390_FEAT_ESAN3)) {
+        hwcap |= HWCAP_S390_ESAN3;
+    }
+    if (s390_has_feat(S390_FEAT_ZARCH)) {
+        hwcap |= HWCAP_S390_ZARCH;
+    }
+    if (s390_has_feat(S390_FEAT_STFLE)) {
+        hwcap |= HWCAP_S390_STFLE;
+    }
+    if (s390_has_feat(S390_FEAT_MSA)) {
+        hwcap |= HWCAP_S390_MSA;
+    }
+    if (s390_has_feat(S390_FEAT_LONG_DISPLACEMENT)) {
+        hwcap |= HWCAP_S390_LDISP;
+    }
+    if (s390_has_feat(S390_FEAT_EXTENDED_IMMEDIATE)) {
+        hwcap |= HWCAP_S390_EIMM;
+    }
+    if (s390_has_feat(S390_FEAT_EXTENDED_TRANSLATION_3) &&
+        s390_has_feat(S390_FEAT_ETF3_ENH)) {
+        hwcap |= HWCAP_S390_ETF3EH;
+    }
+    /* 31-bit processes can use 64-bit registers */
+    hwcap |= HWCAP_S390_HIGH_GPRS;

linux-user/elfload.c static inline void init_thread(struct target_pt_regs *regs, · line 1352

Quoted 10 lines
linux-user/elfload.c +7 -0
+    if (s390_has_feat(S390_FEAT_VECTOR)) {
+        hwcap |= HWCAP_S390_VXRS;
+    }
+
+    return hwcap;
+}
+
 static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
 {
     regs->psw.addr = infop->entry;
Quoted 7 lines

You can also do like the other architectures that use shortcuts like this:

#define GET_FEATURE(feat, hwcap) \
    do { if (s390_has_feat(feat)) { hwcaps |= hwcap; } } while (0)

...
GET_FEATURE(S390_FEAT_VECTOR, HWCAP_S390_VXRS);
...

Thanks, I'll use this.

Cheers!

Signature · 3 lines
Thanks,

David / dhildenb
#4 lore raw
In reply to Richard Henderson
Quoted 30 lines · Richard Henderson

linux-user/elfload.c static inline void init_thread(struct target_pt_regs *regs, · line 1324

Quoted 6 lines · David Hildenbrand
linux-user/elfload.c +6 -0
+    if (s390_has_feat(S390_FEAT_ESAN3)) {
+        hwcap |= HWCAP_S390_ESAN3;
+    }
+    if (s390_has_feat(S390_FEAT_ZARCH)) {
+        hwcap |= HWCAP_S390_ZARCH;
+    }

While it's nice and symetrical testing these two features, I don't think they can ever be false.

Quoted 8 lines
linux-user/elfload.c +8 -0
+    if (s390_has_feat(S390_FEAT_STFLE)) {
+        hwcap |= HWCAP_S390_STFLE;
+    }
+    if (s390_has_feat(S390_FEAT_MSA)) {
+        hwcap |= HWCAP_S390_MSA;
+    }
+    if (s390_has_feat(S390_FEAT_LONG_DISPLACEMENT)) {
+        hwcap |= HWCAP_S390_LDISP;

linux-user/elfload.c static inline void init_thread(struct target_pt_regs *regs, · line 1342

Quoted 10 lines
linux-user/elfload.c +10 -0
+    }
+    if (s390_has_feat(S390_FEAT_EXTENDED_IMMEDIATE)) {
+        hwcap |= HWCAP_S390_EIMM;
+    }
+    if (s390_has_feat(S390_FEAT_EXTENDED_TRANSLATION_3) &&
+        s390_has_feat(S390_FEAT_ETF3_ENH)) {
+        hwcap |= HWCAP_S390_ETF3EH;
+    }
+    /* 31-bit processes can use 64-bit registers */
+    hwcap |= HWCAP_S390_HIGH_GPRS;
Quoted 6 lines

And certainly this could never be set unless ZARCH, otherwise you have no 64-bit registers. ;-)

So maybe clearer to just start with

  hwcap = HWCAP_S390_ESAN3 | HWCAP_S390_ZARCH | HWCAP_S390_HIGH_GPRS;

Makes sense, and fits into a single line ;)

Thanks!

Quoted 9 lines

and continue from there.

Otherwise,

r~

Signature · 3 lines
Thanks,

David / dhildenb