From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Afonso Bordado <afonsobordado@gmail.com>,
Palmer Dabbelt <palmer@rivosinc.com>,
Laurent Vivier <laurent@vivier.eu>,
Alistair Francis <alistair.francis@wdc.com>,
LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
Subject: [PULL 1/9] linux-user: Emulate /proc/cpuinfo output for riscv
Date: Wed, 17 May 2023 10:01:44 +0200 [thread overview]
Message-ID: <20230517080152.108660-2-laurent@vivier.eu> (raw)
In-Reply-To: <20230517080152.108660-1-laurent@vivier.eu>
From: Afonso Bordado <afonsobordado@gmail.com>
RISC-V does not expose all extensions via hwcaps, thus some userspace
applications may want to query these via /proc/cpuinfo.
Currently when querying this file the host's file is shown instead
which is slightly confusing. Emulate a basic /proc/cpuinfo file
with mmu info and an ISA string.
Signed-off-by: Afonso Bordado <afonsobordado@gmail.com>
Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
Message-Id: <167873059442.9885.15152085316575248452-0@git.sr.ht>
[lv: removed the test that fails in CI for unknown reason]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 69f740ff98c8..085ce530213e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8231,7 +8231,8 @@ void target_exception_dump(CPUArchState *env, const char *fmt, int code)
}
#if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN || \
- defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA)
+ defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA) || \
+ defined(TARGET_RISCV)
static int is_proc(const char *filename, const char *entry)
{
return strcmp(filename, entry) == 0;
@@ -8309,6 +8310,35 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd)
}
#endif
+#if defined(TARGET_RISCV)
+static int open_cpuinfo(CPUArchState *cpu_env, int fd)
+{
+ int i;
+ int num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+ RISCVCPU *cpu = env_archcpu(cpu_env);
+ const RISCVCPUConfig *cfg = riscv_cpu_cfg((CPURISCVState *) cpu_env);
+ char *isa_string = riscv_isa_string(cpu);
+ const char *mmu;
+
+ if (cfg->mmu) {
+ mmu = (cpu_env->xl == MXL_RV32) ? "sv32" : "sv48";
+ } else {
+ mmu = "none";
+ }
+
+ for (i = 0; i < num_cpus; i++) {
+ dprintf(fd, "processor\t: %d\n", i);
+ dprintf(fd, "hart\t\t: %d\n", i);
+ dprintf(fd, "isa\t\t: %s\n", isa_string);
+ dprintf(fd, "mmu\t\t: %s\n", mmu);
+ dprintf(fd, "uarch\t\t: qemu\n\n");
+ }
+
+ g_free(isa_string);
+ return 0;
+}
+#endif
+
#if defined(TARGET_M68K)
static int open_hardware(CPUArchState *cpu_env, int fd)
{
@@ -8333,7 +8363,7 @@ static int do_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, int
#if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN
{ "/proc/net/route", open_net_route, is_proc },
#endif
-#if defined(TARGET_SPARC) || defined(TARGET_HPPA)
+#if defined(TARGET_SPARC) || defined(TARGET_HPPA) || defined(TARGET_RISCV)
{ "/proc/cpuinfo", open_cpuinfo, is_proc },
#endif
#if defined(TARGET_M68K)
--
2.40.1
next prev parent reply other threads:[~2023-05-17 8:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-17 8:01 [PULL 0/9] Linux user for 8.1 patches Laurent Vivier
2023-05-17 8:01 ` Laurent Vivier [this message]
2023-05-17 8:01 ` [PULL 2/9] linux-user: report ENOTTY for unknown ioctls Laurent Vivier
2023-05-17 8:01 ` [PULL 3/9] linux-user: Add move_mount() syscall Laurent Vivier
2023-05-17 8:01 ` [PULL 4/9] linux-user: Add open_tree() syscall Laurent Vivier
2023-05-17 8:01 ` [PULL 5/9] linux-user/main: Use list_cpus() instead of cpu_list() Laurent Vivier
2023-05-17 8:01 ` [PULL 6/9] linux-user: Add new flag VERIFY_NONE Laurent Vivier
2023-05-17 8:01 ` [PULL 7/9] linux-user: Don't require PROT_READ for mincore Laurent Vivier
2023-05-17 8:01 ` [PULL 8/9] linux-user: Fix mips fp64 executables loading Laurent Vivier
2023-05-17 8:01 ` [PULL 9/9] linux-user: fix getgroups/setgroups allocations Laurent Vivier
2023-05-17 16:04 ` [PULL 0/9] Linux user for 8.1 patches Richard Henderson
-- strict thread matches above, loose matches on Subject: below --
2023-05-16 12:48 Laurent Vivier
2023-05-16 12:48 ` [PULL 1/9] linux-user: Emulate /proc/cpuinfo output for riscv Laurent Vivier
2023-05-15 8:31 [PULL 0/9] Linux user for 8.1 patches Laurent Vivier
2023-05-15 8:31 ` [PULL 1/9] linux-user: Emulate /proc/cpuinfo output for riscv Laurent Vivier
2023-05-12 11:22 [PULL 0/9] Linux user for 8.1 patches Laurent Vivier
2023-05-12 11:22 ` [PULL 1/9] linux-user: Emulate /proc/cpuinfo output for riscv Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230517080152.108660-2-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=afonsobordado@gmail.com \
--cc=alistair.francis@wdc.com \
--cc=palmer@rivosinc.com \
--cc=qemu-devel@nongnu.org \
--cc=zhiwei_liu@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).