Skip to contentSkip to conversation

linux-user: Emulate /proc/cpuinfo on s390x

PATCH Superseded Ilya Leoshkevich 2 participants 11 messages Jun 1, 2023 – Jun 2, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#3 lore raw

PATCH 2/4 linux-user/elfload: Expose get_elf_hwcap() on s390x

In reply to Ilya Leoshkevich

It is required for implementing /proc/cpuinfo emulation.

---
 linux-user/elfload.c | 2 +-
 linux-user/loader.h  | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)
linux-user/elfload.c +1 -1
index 418ad92598c..49ec9ccc944 100644
@@ -1583,7 +1583,7 @@ static inline void init_thread(struct target_pt_regs *regs,
 #define GET_FEATURE(_feat, _hwcap) \
     do { if (s390_has_feat(_feat)) { hwcap |= _hwcap; } } while (0)
 
-static uint32_t get_elf_hwcap(void)
+uint32_t get_elf_hwcap(void)
 {
     /*
      * Let's assume we always have esan3 and zarch.
linux-user/loader.h +4 -0
index f375ee0679b..ad6ca9dbe35 100644
@@ -56,4 +56,8 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src,
 
 extern unsigned long guest_stack_size;
 
+#ifdef TARGET_S390X
+uint32_t get_elf_hwcap(void);
+#endif
+
 #endif /* LINUX_USER_LOADER_H */
Signature · 1 line
2.40.1
#5 lore raw

PATCH 3/4 linux-user/elfload: Introduce elf_hwcap_str() on s390x

In reply to Ilya Leoshkevich

It is required for implementing /proc/cpuinfo emulation.

---
 linux-user/elfload.c | 27 +++++++++++++++++++++++++++
 linux-user/loader.h  |  1 +
 2 files changed, 28 insertions(+)
linux-user/elfload.c +27 -0
index 49ec9ccc944..d80d68484b6 100644
@@ -1605,6 +1605,33 @@ uint32_t get_elf_hwcap(void)
     return hwcap;
 }
 
+const char *elf_hwcap_str(uint32_t bit)
+{
+    static const char *hwcap_str[] = {
+        [HWCAP_S390_ESAN3]     = "esan3",
+        [HWCAP_S390_ZARCH]     = "zarch",
+        [HWCAP_S390_STFLE]     = "stfle",
+        [HWCAP_S390_MSA]       = "msa",
+        [HWCAP_S390_LDISP]     = "ldisp",
+        [HWCAP_S390_EIMM]      = "eimm",
+        [HWCAP_S390_DFP]       = "dfp",
+        [HWCAP_S390_HPAGE]     = "edat",
+        [HWCAP_S390_ETF3EH]    = "etf3eh",
+        [HWCAP_S390_HIGH_GPRS] = "highgprs",
+        [HWCAP_S390_TE]        = "te",
+        [HWCAP_S390_VXRS]      = "vx",
+        [HWCAP_S390_VXRS_BCD]  = "vxd",
+        [HWCAP_S390_VXRS_EXT]  = "vxe",
+        [HWCAP_S390_GS]        = "gs",
+        [HWCAP_S390_VXRS_EXT2] = "vxe2",
+        [HWCAP_S390_VXRS_PDE]  = "vxp",
+        [HWCAP_S390_SORT]      = "sort",
+        [HWCAP_S390_DFLT]      = "dflt",
+    };
+
+    return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
+}
+
 static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
 {
     regs->psw.addr = infop->entry;
linux-user/loader.h +1 -0
index ad6ca9dbe35..59cbeacf24f 100644
@@ -58,6 +58,7 @@ extern unsigned long guest_stack_size;
 
 #ifdef TARGET_S390X
 uint32_t get_elf_hwcap(void);
+const char *elf_hwcap_str(uint32_t bit);
 #endif
 
 #endif /* LINUX_USER_LOADER_H */
Signature · 1 line
2.40.1
#0 lore raw

cover linux-user: Emulate /proc/cpuinfo on s390x

Hi,

This series introduces /proc/cpuinfo linux-user emulation for s390x. /proc/cpuinfo emulation already exists for sparc, hppa and riscv; this series follows the pattern established for these platforms.

Patch 1 is a fix for an issue that I noticed while looking for ways to get to the "identification" field.

Patches 2 and 3 introduce the necessary helpers.

Patch 4 is the actual implementation.

The trigger for this work is a bug report filed by Tulio [1], which has to do with the llvm-project testcases failing under qemu-user.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=2211472

Best regards,
Ilya

Ilya Leoshkevich (4):
s390x/tcg: Fix CPU address returned by STIDP linux-user/elfload: Expose get_elf_hwcap() on s390x linux-user/elfload: Introduce elf_hwcap_str() on s390x
linux-user: Emulate /proc/cpuinfo on s390x

 linux-user/elfload.c      |  29 ++++++++++-
 linux-user/loader.h       |   5 ++
 linux-user/syscall.c      | 106 +++++++++++++++++++++++++++++++++++++-
 target/s390x/cpu_models.c |   4 +-
 target/s390x/cpu_models.h |  10 +++-
 5 files changed, 149 insertions(+), 5 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/4 s390x/tcg: Fix CPU address returned by STIDP

In qemu-user-s390x, /proc/cpuinfo contains:

cpu number : 0
identification : 000000

cpu number : 1
identification : 400000

The highest nibble is supposed to contain the CPU address, but it's off by 2 bits. Fix the shift value and provide a symbolic constant for it.

Fixes 076d4d39b65f ("s390x/cpumodel: wire up cpu type + id for TCG")
---
 target/s390x/cpu_models.c |  4 ++--
 target/s390x/cpu_models.h | 10 +++++++++-
 2 files changed, 11 insertions(+), 3 deletions(-)
target/s390x/cpu_models.c +2 -2
index 457b5cb10c4..ae8880e81dc 100644
@@ -607,8 +607,8 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp)
 #if !defined(CONFIG_USER_ONLY)
     cpu->env.cpuid = s390_cpuid_from_cpu_model(cpu->model);
     if (tcg_enabled()) {
-        /* basic mode, write the cpu address into the first 4 bit of the ID */
-        cpu->env.cpuid = deposit64(cpu->env.cpuid, 54, 4, cpu->env.core_id);
+        cpu->env.cpuid = deposit64(cpu->env.cpuid, CPU_PHYS_ADDR_SHIFT,
+                                   CPU_PHYS_ADDR_BITS, cpu->env.core_id);
     }
 #endif
 }
target/s390x/cpu_models.h +9 -1
index fb1adc8b210..cc7305ec213 100644
@@ -96,10 +96,18 @@ static inline bool s390_known_cpu_type(uint16_t type)
 {
     return s390_get_gen_for_cpu_type(type) != 0;
 }
+#define CPU_ID_SHIFT 32
+#define CPU_ID_BITS 24
+/*
+ * When cpu_id_format is 0 (basic mode), the leftmost 4 bits of cpu_id contain
+ * the rightmost 4 bits of the physical CPU address.
+ */
+#define CPU_PHYS_ADDR_BITS 4
+#define CPU_PHYS_ADDR_SHIFT (CPU_ID_SHIFT + CPU_ID_BITS - CPU_PHYS_ADDR_BITS)
 static inline uint64_t s390_cpuid_from_cpu_model(const S390CPUModel *model)
 {
     return ((uint64_t)model->cpu_ver << 56) |
-           ((uint64_t)model->cpu_id << 32) |
+           ((uint64_t)model->cpu_id << CPU_ID_SHIFT) |
            ((uint64_t)model->def->type << 16) |
            (model->def->gen == 7 ? 0 : (uint64_t)model->cpu_id_format << 15);
 }
Signature · 1 line
2.40.1
#7 lore raw

PATCH 4/4 linux-user: Emulate /proc/cpuinfo on s390x

In reply to Ilya Leoshkevich

Some s390x userspace programs are confused when seeing a foreign /proc/cpuinfo [1]. Add the emulation for s390x; follow the respective kernel code structure where possible.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=2211472

---
 linux-user/syscall.c | 106 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 105 insertions(+), 1 deletion(-)
linux-user/syscall.c +105 -1
index 3e6ed51ce62..d142e09dc70 100644
@@ -8339,6 +8339,109 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd)
 }
 #endif
 
+#if defined(TARGET_S390X)
+/*
+ * Emulate what a Linux kernel running in qemu-system-s390x -M accel=tcg would
+ * show in /proc/cpuinfo.
+ *
+ * Skip the following in order to match the missing support in op_ecag():
+ * - show_cacheinfo().
+ * - show_cpu_topology().
+ * - show_cpu_mhz().
+ *
+ * Use fixed values for certain fields:
+ * - bogomips per cpu - from a qemu-system-s390x run.
+ * - max thread id = 0, since SMT / SIGP_SET_MULTI_THREADING is not supported.
+ *
+ * Keep the code structure close to arch/s390/kernel/processor.c.
+ */
+
+static void show_facilities(int fd)
+{
+    size_t sizeof_stfl_bytes = 2048;
+    g_autofree uint8_t *stfl_bytes = g_new0(uint8_t, sizeof_stfl_bytes);
+    unsigned int bit;
+
+    dprintf(fd, "facilities      :");
+    s390_get_feat_block(S390_FEAT_TYPE_STFL, stfl_bytes);
+    for (bit = 0; bit < sizeof_stfl_bytes * 8; bit++) {
+        if (test_be_bit(bit, stfl_bytes)) {
+            dprintf(fd, " %d", bit);
+        }
+    }
+    dprintf(fd, "\n");
+}
+
+static int cpu_ident(unsigned long n)
+{
+    return deposit32(0, CPU_ID_BITS - CPU_PHYS_ADDR_BITS, CPU_PHYS_ADDR_BITS,
+                     n);
+}
+
+static void show_cpu_summary(CPUArchState *cpu_env, int fd)
+{
+    S390CPUModel *model = env_archcpu(cpu_env)->model;
+    int num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+    uint32_t elf_hwcap = get_elf_hwcap();
+    const char *hwcap_str;
+    int i;
+
+    dprintf(fd, "vendor_id       : IBM/S390\n"
+                "# processors    : %i\n"
+                "bogomips per cpu: 13370.00\n",
+            num_cpus);
+    dprintf(fd, "max thread id   : 0\n");
+    dprintf(fd, "features\t: ");
+    for (i = 0; i < sizeof(elf_hwcap) * 8; i++) {
+        if (!(elf_hwcap & (1 << i))) {
+            continue;
+        }
+        hwcap_str = elf_hwcap_str(i);
+        if (hwcap_str) {
+            dprintf(fd, "%s ", hwcap_str);
+        }
+    }
+    dprintf(fd, "\n");
+    show_facilities(fd);
+    for (i = 0; i < num_cpus; i++) {
+        dprintf(fd, "processor %d: "
+               "version = %02X,  "
+               "identification = %06X,  "
+               "machine = %04X\n",
+               i, model->cpu_ver, cpu_ident(i), model->def->type);
+    }
+}
+
+static void show_cpu_ids(CPUArchState *cpu_env, int fd, unsigned long n)
+{
+    S390CPUModel *model = env_archcpu(cpu_env)->model;
+
+    dprintf(fd, "version         : %02X\n", model->cpu_ver);
+    dprintf(fd, "identification  : %06X\n", cpu_ident(n));
+    dprintf(fd, "machine         : %04X\n", model->def->type);
+}
+
+static void show_cpuinfo(CPUArchState *cpu_env, int fd, unsigned long n)
+{
+    if (n == 0) {
+        show_cpu_summary(cpu_env, fd);
+    }
+    dprintf(fd, "\ncpu number      : %ld\n", n);
+    show_cpu_ids(cpu_env, fd, n);
+}
+
+static int open_cpuinfo(CPUArchState *cpu_env, int fd)
+{
+    int num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+    int i;
+
+    for (i = 0; i < num_cpus; i++) {
+        show_cpuinfo(cpu_env, fd, i);
+    }
+    return 0;
+}
+#endif
+
 #if defined(TARGET_M68K)
 static int open_hardware(CPUArchState *cpu_env, int fd)
 {
@@ -8364,7 +8467,8 @@ int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname,
 #if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN
         { "/proc/net/route", open_net_route, is_proc },
 #endif
-#if defined(TARGET_SPARC) || defined(TARGET_HPPA) || defined(TARGET_RISCV)
+#if defined(TARGET_SPARC) || defined(TARGET_HPPA) || \
+    defined(TARGET_RISCV) || defined(TARGET_S390X)
         { "/proc/cpuinfo", open_cpuinfo, is_proc },
 #endif
 #if defined(TARGET_M68K)
Signature · 1 line
2.40.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] s390x/tcg: Fix CPU address returned by STIDP

In reply to Ilya Leoshkevich
Quoted 11 lines · Ilya Leoshkevich

In qemu-user-s390x, /proc/cpuinfo contains:

cpu number : 0
identification : 000000

cpu number : 1
identification : 400000

The highest nibble is supposed to contain the CPU address, but it's off by 2 bits. Fix the shift value and provide a symbolic constant for it.

Would be helpful to show the output with this fix.

Quoted 36 lines
Fixes 076d4d39b65f ("s390x/cpumodel: wire up cpu type + id for TCG")
---
  target/s390x/cpu_models.c |  4 ++--
  target/s390x/cpu_models.h | 10 +++++++++-
  2 files changed, 11 insertions(+), 3 deletions(-)
target/s390x/cpu_models.c +2 -2
index 457b5cb10c4..ae8880e81dc 100644
@@ -607,8 +607,8 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp)
  #if !defined(CONFIG_USER_ONLY)
      cpu->env.cpuid = s390_cpuid_from_cpu_model(cpu->model);
      if (tcg_enabled()) {
-        /* basic mode, write the cpu address into the first 4 bit of the ID */
-        cpu->env.cpuid = deposit64(cpu->env.cpuid, 54, 4, cpu->env.core_id);
+        cpu->env.cpuid = deposit64(cpu->env.cpuid, CPU_PHYS_ADDR_SHIFT,
+                                   CPU_PHYS_ADDR_BITS, cpu->env.core_id);
      }
  #endif
  }
target/s390x/cpu_models.h +6 -0
index fb1adc8b210..cc7305ec213 100644
@@ -96,10 +96,18 @@ static inline bool s390_known_cpu_type(uint16_t type)
  {
      return s390_get_gen_for_cpu_type(type) != 0;
  }
+#define CPU_ID_SHIFT 32
+#define CPU_ID_BITS 24
+/*
+ * When cpu_id_format is 0 (basic mode), the leftmost 4 bits of cpu_id contain
+ * the rightmost 4 bits of the physical CPU address.
+ */

target/s390x/cpu_models.h static inline bool s390_known_cpu_type(uint16_t type) · line 113

Quoted 10 lines
target/s390x/cpu_models.h +3 -1
+#define CPU_PHYS_ADDR_BITS 4
+#define CPU_PHYS_ADDR_SHIFT (CPU_ID_SHIFT + CPU_ID_BITS - CPU_PHYS_ADDR_BITS)
  static inline uint64_t s390_cpuid_from_cpu_model(const S390CPUModel *model)
  {
      return ((uint64_t)model->cpu_ver << 56) |
-           ((uint64_t)model->cpu_id << 32) |
+           ((uint64_t)model->cpu_id << CPU_ID_SHIFT) |
             ((uint64_t)model->def->type << 16) |
             (model->def->gen == 7 ? 0 : (uint64_t)model->cpu_id_format << 15);
  }

Thanks!

Signature · 3 lines
Thanks,

David / dhildenb
#8 lore raw
In reply to Ilya Leoshkevich
Quoted 23 lines · Ilya Leoshkevich

Some s390x userspace programs are confused when seeing a foreign /proc/cpuinfo [1]. Add the emulation for s390x; follow the respective kernel code structure where possible.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=2211472

---
 linux-user/syscall.c | 106
++++++++++++++++++++++++++++++++++++++++++-

 1 file changed, 105 insertions(+), 1 deletion(-)
linux-user/syscall.c +2 -1
@@ -8364,7 +8467,8 @@ int do_guest_openat(CPUArchState *cpu_env, int
 dirfd, const char *pathname,
  #if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN
          { "/proc/net/route", open_net_route, is_proc },
  #endif
-#if defined(TARGET_SPARC) || defined(TARGET_HPPA) ||
 defined(TARGET_RISCV)
+#if defined(TARGET_SPARC) || defined(TARGET_HPPA) || \
+    defined(TARGET_RISCV) || defined(TARGET_S390X)
          { "/proc/cpuinfo", open_cpuinfo, is_proc },
Quoted 2 lines

 #endif
 #if defined(TARGET_M68K)

I'll need to add #if defined(TARGET_S390X) for is_proc, otherwise the build will fail on s390x hosts. I will include this in v2.

Reviewed-by on v1 3/4
#6 lore raw

Re: [PATCH 3/4] linux-user/elfload: Introduce elf_hwcap_str() on s390x

In reply to Ilya Leoshkevich
Quoted 51 lines · Ilya Leoshkevich

It is required for implementing /proc/cpuinfo emulation.

---
  linux-user/elfload.c | 27 +++++++++++++++++++++++++++
  linux-user/loader.h  |  1 +
  2 files changed, 28 insertions(+)
linux-user/elfload.c +27 -0
index 49ec9ccc944..d80d68484b6 100644
@@ -1605,6 +1605,33 @@ uint32_t get_elf_hwcap(void)
      return hwcap;
  }
 
+const char *elf_hwcap_str(uint32_t bit)
+{
+    static const char *hwcap_str[] = {
+        [HWCAP_S390_ESAN3]     = "esan3",
+        [HWCAP_S390_ZARCH]     = "zarch",
+        [HWCAP_S390_STFLE]     = "stfle",
+        [HWCAP_S390_MSA]       = "msa",
+        [HWCAP_S390_LDISP]     = "ldisp",
+        [HWCAP_S390_EIMM]      = "eimm",
+        [HWCAP_S390_DFP]       = "dfp",
+        [HWCAP_S390_HPAGE]     = "edat",
+        [HWCAP_S390_ETF3EH]    = "etf3eh",
+        [HWCAP_S390_HIGH_GPRS] = "highgprs",
+        [HWCAP_S390_TE]        = "te",
+        [HWCAP_S390_VXRS]      = "vx",
+        [HWCAP_S390_VXRS_BCD]  = "vxd",
+        [HWCAP_S390_VXRS_EXT]  = "vxe",
+        [HWCAP_S390_GS]        = "gs",
+        [HWCAP_S390_VXRS_EXT2] = "vxe2",
+        [HWCAP_S390_VXRS_PDE]  = "vxp",
+        [HWCAP_S390_SORT]      = "sort",
+        [HWCAP_S390_DFLT]      = "dflt",
+    };
+
+    return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
+}
+
  static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
  {
      regs->psw.addr = infop->entry;
linux-user/loader.h +0 -0
index ad6ca9dbe35..59cbeacf24f 100644

linux-user/loader.h extern unsigned long guest_stack_size; · line 64

Quoted 7 lines
linux-user/loader.h +1 -0
@@ -58,6 +58,7 @@ extern unsigned long guest_stack_size;
 
  #ifdef TARGET_S390X
  uint32_t get_elf_hwcap(void);
+const char *elf_hwcap_str(uint32_t bit);
  #endif
 
  #endif /* LINUX_USER_LOADER_H */
Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] linux-user/elfload: Expose get_elf_hwcap() on s390x

In reply to Ilya Leoshkevich
Quoted 26 lines · Ilya Leoshkevich

It is required for implementing /proc/cpuinfo emulation.

---
  linux-user/elfload.c | 2 +-
  linux-user/loader.h  | 4 ++++
  2 files changed, 5 insertions(+), 1 deletion(-)
linux-user/elfload.c +1 -1
index 418ad92598c..49ec9ccc944 100644
@@ -1583,7 +1583,7 @@ static inline void init_thread(struct target_pt_regs *regs,
  #define GET_FEATURE(_feat, _hwcap) \
      do { if (s390_has_feat(_feat)) { hwcap |= _hwcap; } } while (0)
 
-static uint32_t get_elf_hwcap(void)
+uint32_t get_elf_hwcap(void)
  {
      /*
       * Let's assume we always have esan3 and zarch.
linux-user/loader.h +0 -0
index f375ee0679b..ad6ca9dbe35 100644

linux-user/loader.h abi_long memcpy_to_target(abi_ulong dest, const void *src, · line 63

Quoted 8 lines
linux-user/loader.h +4 -0
@@ -56,4 +56,8 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src,
 
  extern unsigned long guest_stack_size;
 
+#ifdef TARGET_S390X
+uint32_t get_elf_hwcap(void);
+#endif
+
  #endif /* LINUX_USER_LOADER_H */
Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by on v1 4/4
#9 lore raw
In reply to Ilya Leoshkevich
Quoted 6 lines · Ilya Leoshkevich

Some s390x userspace programs are confused when seeing a foreign /proc/cpuinfo [1]. Add the emulation for s390x; follow the respective kernel code structure where possible.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=2211472

Would be nice to have an example output here.

Quoted 14 lines
---
  linux-user/syscall.c | 106 ++++++++++++++++++++++++++++++++++++++++++-
  1 file changed, 105 insertions(+), 1 deletion(-)
linux-user/syscall.c +0 -0
index 3e6ed51ce62..d142e09dc70 100644
@@ -8339,6 +8339,109 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd)
  }
  #endif
 

[...]

linux-user/syscall.c static int open_cpuinfo(CPUArchState *cpu_env, int fd) · line 8431

Quoted 9 lines
linux-user/syscall.c +9 -0
+
+static void show_cpuinfo(CPUArchState *cpu_env, int fd, unsigned long n)
+{
+    if (n == 0) {
+        show_cpu_summary(cpu_env, fd);
+    }
+    dprintf(fd, "\ncpu number      : %ld\n", n);
+    show_cpu_ids(cpu_env, fd, n);
+}

Considering the n==0 special case, it might be cleaner to just place that code directly into open_cpuinfo and get rid of show_cpuinfo().

Quoted 17 lines
linux-user/syscall.c +13 -0
+
+static int open_cpuinfo(CPUArchState *cpu_env, int fd)
+{
+    int num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+    int i;
+
+    for (i = 0; i < num_cpus; i++) {
+        show_cpuinfo(cpu_env, fd, i);
+    }
+    return 0;
+}
+#endif
+
  #if defined(TARGET_M68K)
  static int open_hardware(CPUArchState *cpu_env, int fd)
  {

linux-user/syscall.c int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, · line 8474

Quoted 9 lines
linux-user/syscall.c +2 -1
@@ -8364,7 +8467,8 @@ int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname,
  #if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN
          { "/proc/net/route", open_net_route, is_proc },
  #endif
-#if defined(TARGET_SPARC) || defined(TARGET_HPPA) || defined(TARGET_RISCV)
+#if defined(TARGET_SPARC) || defined(TARGET_HPPA) || \
+    defined(TARGET_RISCV) || defined(TARGET_S390X)
          { "/proc/cpuinfo", open_cpuinfo, is_proc },
  #endif
  #if defined(TARGET_M68K)

In general, looks very good to me, thanks! With the fixup:

Signature · 3 lines
Thanks,

David / dhildenb
#10 lore raw
Quoted 30 lines · David Hildenbrand
Quoted 7 lines · Ilya Leoshkevich

Some s390x userspace programs are confused when seeing a foreign /proc/cpuinfo [1]. Add the emulation for s390x; follow the respective
kernel code structure where possible.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=2211472

Would be nice to have an example output here.

Quoted 16 lines

---
  linux-user/syscall.c | 106
++++++++++++++++++++++++++++++++++++++++++-

  1 file changed, 105 insertions(+), 1 deletion(-)
linux-user/syscall.c +0 -0
index 3e6ed51ce62..d142e09dc70 100644
@@ -8339,6 +8339,109 @@ static int open_cpuinfo(CPUArchState
 *cpu_env, int fd)
   }
   #endif

[...]

Quoted 13 lines

linux-user/syscall.c static int open_cpuinfo(CPUArchState *cpu_env, int fd) · line 8431

Quoted 10 lines
linux-user/syscall.c +2 -0
+
+static void show_cpuinfo(CPUArchState *cpu_env, int fd, unsigned

long n)

linux-user/syscall.c +7 -0
+{
+    if (n == 0) {
+        show_cpu_summary(cpu_env, fd);
+    }
+    dprintf(fd, "\ncpu number      : %ld\n", n);
+    show_cpu_ids(cpu_env, fd, n);
+}

Considering the n==0 special case, it might be cleaner to just place that code directly into open_cpuinfo and get rid of show_cpuinfo().

Will do.

This was copied from the kernel, where a similar check actually made sense, but in the QEMU context we don't really need it.

Quoted 33 lines
Quoted 26 lines
linux-user/syscall.c +13 -0
+
+static int open_cpuinfo(CPUArchState *cpu_env, int fd)
+{
+    int num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+    int i;
+
+    for (i = 0; i < num_cpus; i++) {
+        show_cpuinfo(cpu_env, fd, i);
+    }
+    return 0;
+}
+#endif
+

  #if defined(TARGET_M68K)
  static int open_hardware(CPUArchState *cpu_env, int fd) {

linux-user/syscall.c +2 -1
@@ -8364,7 +8467,8 @@ int do_guest_openat(CPUArchState *cpu_env,
 int dirfd, const char *pathname,
   #if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN
           { "/proc/net/route", open_net_route, is_proc },
   #endif
-#if defined(TARGET_SPARC) || defined(TARGET_HPPA) ||
 defined(TARGET_RISCV)
+#if defined(TARGET_SPARC) || defined(TARGET_HPPA) || \
+    defined(TARGET_RISCV) || defined(TARGET_S390X)
           { "/proc/cpuinfo", open_cpuinfo, is_proc },
Quoted 2 lines

  #endif
  #if defined(TARGET_M68K)

In general, looks very good to me, thanks! With the fixup: