Skip to contentSkip to conversation

target/riscv: Report QEMU CPU archid as 42

PATCH In review Charlie Jenkins 3 participants 4 messages Jun 26 – Jun 29 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 target/riscv: Report QEMU CPU archid as 42

When a non-vendor CPU is used, report the archid as 42 which has been allocated for QEMU in the riscv isa manual [1]. This can help software check if it is running in QEMU.

[1] https://github.com/riscv/riscv-isa-manual/blob/main/marchid.md

---
This series was original proposed by Palmer Dabbelt [1] with a follow up by Daniel Henrique Barboza. This patch implement's Daniel's suggestion.

When booting with a non-vendor CPU such as with the qemu arg "-cpu rv64" marchid will now be reported as 42.

Quoted 1 line

qemu-system-riscv64 ... -cpu rv64

processor : 0
hart : 0
isa : rv64imafdch_zicbom_zicbop_zicboz_ziccrse_zicntr_zicsr_zifencei_zihintntl_zihintpause_zihpm_zaamo_zalrsc_zawrs_zfa_zca_zcd_zba_zbb_zbc_zbs_sstc_svadu_svvptc
mmu : sv57
mvendorid : 0x0
marchid : 0x2a
mimpid : 0x0
hart isa : rv64imafdch_zicbom_zicbop_zicboz_ziccrse_zicntr_zicsr_zifencei_zihintntl_zihintpause_zihpm_zaamo_zalrsc_zawrs_zfa_zca_zcd_zba_zbb_zbc_zbs_sstc_svadu_svvptc

When booting with a vendor CPU like veyron-v1, the proper marchid will still appear.

Quoted 1 line

qemu-system-riscv64 ... -cpu veyron-v1

processor : 0
hart : 0
isa : rv64imafdch_zicbom_zicboz_ziccrse_zicntr_zicsr_zifencei_zihpm_zaamo_zalrsc_zca_zcd_zba_zbb_zbc_zbs_smaia_smstateen_ssaia_sscofpmf_sstc_svinval_svnapot_svpbmt
mmu : sv48
mvendorid : 0x61f
marchid : 0x8000000000010000
mimpid : 0x111
hart isa : rv64imafdch_zicbom_zicboz_ziccrse_zicntr_zicsr_zifencei_zihpm_zaamo_zalrsc_zca_zcd_zba_zbb_zbc_zbs_smaia_smstateen_ssaia_sscofpmf_sstc_svinval_svnapot_svpbmt

[1] https://lore.kernel.org/all/[email protected]/
---
Changes in v2:
- Added comment linking the spec allocating 42 to marchid
- Cleaned up the id setting
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]

---
 target/riscv/cpu.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
target/riscv/cpu.c +11 -0
index fa497e5e8a..94946d335f 100644
@@ -47,6 +47,13 @@
 static const char riscv_single_letter_exts[] = "IEMAFDQCBPVH";
 const uint32_t misa_bits[] = {RVI, RVE, RVM, RVA, RVF, RVD, RVV,
                               RVC, RVS, RVU, RVH, RVG, RVB, 0};
+#define RISCV_CPU_MVENDORID 0
+#define RISCV_CPU_MIMPID 0
+/*
+ * marchid allocated for qemu:
+ * https://github.com/riscv/riscv-isa-manual/blob/main/marchid.md
+ */
+#define RISCV_CPU_MARCHID 42
 
 /*
  * From vector_helper.c
@@ -1183,6 +1190,10 @@ static void riscv_cpu_init(Object *obj)
         mcc->def->profile->enabled = true;
     }
 
+    cpu->cfg.mvendorid = RISCV_CPU_MVENDORID;
+    cpu->cfg.marchid = RISCV_CPU_MARCHID;
+    cpu->cfg.mimpid = RISCV_CPU_MIMPID;
+
     env->misa_ext_mask = env->misa_ext = mcc->def->misa_ext;
     riscv_cpu_cfg_merge(&cpu->cfg, &mcc->def->cfg);
 

---
base-commit: b83371668192a705b878e909c5ae9c1233cbd5fb
change-id: 20260624-marchid-80d176b873d8

Best regards,

Signature · 1 line
- Charlie
Reviewed-by on v2 1/1
#1 lore raw
Quoted 68 lines · Charlie Jenkins

When a non-vendor CPU is used, report the archid as 42 which has been allocated for QEMU in the riscv isa manual [1]. This can help software check if it is running in QEMU.

[1] https://github.com/riscv/riscv-isa-manual/blob/main/marchid.md

---
This series was original proposed by Palmer Dabbelt [1] with a follow up by Daniel Henrique Barboza. This patch implement's Daniel's suggestion.

When booting with a non-vendor CPU such as with the qemu arg "-cpu rv64" marchid will now be reported as 42.

Quoted 1 line

qemu-system-riscv64 ... -cpu rv64

processor : 0
hart : 0
isa : rv64imafdch_zicbom_zicbop_zicboz_ziccrse_zicntr_zicsr_zifencei_zihintntl_zihintpause_zihpm_zaamo_zalrsc_zawrs_zfa_zca_zcd_zba_zbb_zbc_zbs_sstc_svadu_svvptc
mmu : sv57
mvendorid : 0x0
marchid : 0x2a
mimpid : 0x0
hart isa : rv64imafdch_zicbom_zicbop_zicboz_ziccrse_zicntr_zicsr_zifencei_zihintntl_zihintpause_zihpm_zaamo_zalrsc_zawrs_zfa_zca_zcd_zba_zbb_zbc_zbs_sstc_svadu_svvptc

When booting with a vendor CPU like veyron-v1, the proper marchid will still appear.

Quoted 1 line

qemu-system-riscv64 ... -cpu veyron-v1

processor : 0
hart : 0
isa : rv64imafdch_zicbom_zicboz_ziccrse_zicntr_zicsr_zifencei_zihpm_zaamo_zalrsc_zca_zcd_zba_zbb_zbc_zbs_smaia_smstateen_ssaia_sscofpmf_sstc_svinval_svnapot_svpbmt
mmu : sv48
mvendorid : 0x61f
marchid : 0x8000000000010000
mimpid : 0x111
hart isa : rv64imafdch_zicbom_zicboz_ziccrse_zicntr_zicsr_zifencei_zihpm_zaamo_zalrsc_zca_zcd_zba_zbb_zbc_zbs_smaia_smstateen_ssaia_sscofpmf_sstc_svinval_svnapot_svpbmt

[1] https://lore.kernel.org/all/[email protected]/
---
Changes in v2:
- Added comment linking the spec allocating 42 to marchid
- Cleaned up the id setting
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]

---
  target/riscv/cpu.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
target/riscv/cpu.c +7 -0
index fa497e5e8a..94946d335f 100644
@@ -47,6 +47,13 @@
  static const char riscv_single_letter_exts[] = "IEMAFDQCBPVH";
  const uint32_t misa_bits[] = {RVI, RVE, RVM, RVA, RVF, RVD, RVV,
                                RVC, RVS, RVU, RVH, RVG, RVB, 0};
+#define RISCV_CPU_MVENDORID 0
+#define RISCV_CPU_MIMPID 0
+/*
+ * marchid allocated for qemu:
+ * https://github.com/riscv/riscv-isa-manual/blob/main/marchid.md
+ */
+#define RISCV_CPU_MARCHID 42
 
  /*
   * From vector_helper.c

target/riscv/cpu.c static void riscv_cpu_init(Object *obj) · line 1197

Quoted 8 lines
target/riscv/cpu.c +4 -0
@@ -1183,6 +1190,10 @@ static void riscv_cpu_init(Object *obj)
          mcc->def->profile->enabled = true;
      }
 
+    cpu->cfg.mvendorid = RISCV_CPU_MVENDORID;
+    cpu->cfg.marchid = RISCV_CPU_MARCHID;
+    cpu->cfg.mimpid = RISCV_CPU_MIMPID;
+
      env->misa_ext_mask = env->misa_ext = mcc->def->misa_ext;

I'd have put it here, then followed by a comment such:

        /* Let vendor override defaults */

target/riscv/cpu.c static void riscv_cpu_init(Object *obj) · line 1198

Quoted 1 line
target/riscv/cpu.c +0 -0
      riscv_cpu_cfg_merge(&cpu->cfg, &mcc->def->cfg);

Regardless,

Quoted 10 lines
target/riscv/cpu.c +0 -1
---

base-commit: b83371668192a705b878e909c5ae9c1233cbd5fb
change-id: 20260624-marchid-80d176b873d8

Best regards,
--
- Charlie

Reviewed-by on v2 1/1
#2 lore raw
In reply to Charlie Jenkins
Quoted 8 lines · Charlie Jenkins

When a non-vendor CPU is used, report the archid as 42 which has been allocated for QEMU in the riscv isa manual [1]. This can help software check if it is running in QEMU.

[1] https://github.com/riscv/riscv-isa-manual/blob/main/marchid.md

Alistair

Quoted 81 lines

---
This series was original proposed by Palmer Dabbelt [1] with a follow up by Daniel Henrique Barboza. This patch implement's Daniel's suggestion.

When booting with a non-vendor CPU such as with the qemu arg "-cpu rv64" marchid will now be reported as 42.

Quoted 1 line

qemu-system-riscv64 ... -cpu rv64

processor : 0
hart : 0
isa : rv64imafdch_zicbom_zicbop_zicboz_ziccrse_zicntr_zicsr_zifencei_zihintntl_zihintpause_zihpm_zaamo_zalrsc_zawrs_zfa_zca_zcd_zba_zbb_zbc_zbs_sstc_svadu_svvptc
mmu : sv57
mvendorid : 0x0
marchid : 0x2a
mimpid : 0x0
hart isa : rv64imafdch_zicbom_zicbop_zicboz_ziccrse_zicntr_zicsr_zifencei_zihintntl_zihintpause_zihpm_zaamo_zalrsc_zawrs_zfa_zca_zcd_zba_zbb_zbc_zbs_sstc_svadu_svvptc

When booting with a vendor CPU like veyron-v1, the proper marchid will still appear.

Quoted 1 line

qemu-system-riscv64 ... -cpu veyron-v1

processor : 0
hart : 0
isa : rv64imafdch_zicbom_zicboz_ziccrse_zicntr_zicsr_zifencei_zihpm_zaamo_zalrsc_zca_zcd_zba_zbb_zbc_zbs_smaia_smstateen_ssaia_sscofpmf_sstc_svinval_svnapot_svpbmt
mmu : sv48
mvendorid : 0x61f
marchid : 0x8000000000010000
mimpid : 0x111
hart isa : rv64imafdch_zicbom_zicboz_ziccrse_zicntr_zicsr_zifencei_zihpm_zaamo_zalrsc_zca_zcd_zba_zbb_zbc_zbs_smaia_smstateen_ssaia_sscofpmf_sstc_svinval_svnapot_svpbmt

[1] https://lore.kernel.org/all/[email protected]/
---
Changes in v2:
- Added comment linking the spec allocating 42 to marchid
- Cleaned up the id setting
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]

---
 target/riscv/cpu.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
target/riscv/cpu.c +11 -1
index fa497e5e8a..94946d335f 100644
@@ -47,6 +47,13 @@
 static const char riscv_single_letter_exts[] = "IEMAFDQCBPVH";
 const uint32_t misa_bits[] = {RVI, RVE, RVM, RVA, RVF, RVD, RVV,
                               RVC, RVS, RVU, RVH, RVG, RVB, 0};
+#define RISCV_CPU_MVENDORID 0
+#define RISCV_CPU_MIMPID 0
+/*
+ * marchid allocated for qemu:
+ * https://github.com/riscv/riscv-isa-manual/blob/main/marchid.md
+ */
+#define RISCV_CPU_MARCHID 42
 
 /*
  * From vector_helper.c
@@ -1183,6 +1190,10 @@ static void riscv_cpu_init(Object *obj)
         mcc->def->profile->enabled = true;
     }
 
+    cpu->cfg.mvendorid = RISCV_CPU_MVENDORID;
+    cpu->cfg.marchid = RISCV_CPU_MARCHID;
+    cpu->cfg.mimpid = RISCV_CPU_MIMPID;
+
     env->misa_ext_mask = env->misa_ext = mcc->def->misa_ext;
     riscv_cpu_cfg_merge(&cpu->cfg, &mcc->def->cfg);
 
 
---

base-commit: b83371668192a705b878e909c5ae9c1233cbd5fb
change-id: 20260624-marchid-80d176b873d8

Best regards,
--
- Charlie

Acked-by on v2 1/1
#3 lore raw
In reply to Charlie Jenkins
Quoted 8 lines · Charlie Jenkins

When a non-vendor CPU is used, report the archid as 42 which has been allocated for QEMU in the riscv isa manual [1]. This can help software check if it is running in QEMU.

[1] https://github.com/riscv/riscv-isa-manual/blob/main/marchid.md

Alistair

Quoted 81 lines

---
This series was original proposed by Palmer Dabbelt [1] with a follow up by Daniel Henrique Barboza. This patch implement's Daniel's suggestion.

When booting with a non-vendor CPU such as with the qemu arg "-cpu rv64" marchid will now be reported as 42.

Quoted 1 line

qemu-system-riscv64 ... -cpu rv64

processor : 0
hart : 0
isa : rv64imafdch_zicbom_zicbop_zicboz_ziccrse_zicntr_zicsr_zifencei_zihintntl_zihintpause_zihpm_zaamo_zalrsc_zawrs_zfa_zca_zcd_zba_zbb_zbc_zbs_sstc_svadu_svvptc
mmu : sv57
mvendorid : 0x0
marchid : 0x2a
mimpid : 0x0
hart isa : rv64imafdch_zicbom_zicbop_zicboz_ziccrse_zicntr_zicsr_zifencei_zihintntl_zihintpause_zihpm_zaamo_zalrsc_zawrs_zfa_zca_zcd_zba_zbb_zbc_zbs_sstc_svadu_svvptc

When booting with a vendor CPU like veyron-v1, the proper marchid will still appear.

Quoted 1 line

qemu-system-riscv64 ... -cpu veyron-v1

processor : 0
hart : 0
isa : rv64imafdch_zicbom_zicboz_ziccrse_zicntr_zicsr_zifencei_zihpm_zaamo_zalrsc_zca_zcd_zba_zbb_zbc_zbs_smaia_smstateen_ssaia_sscofpmf_sstc_svinval_svnapot_svpbmt
mmu : sv48
mvendorid : 0x61f
marchid : 0x8000000000010000
mimpid : 0x111
hart isa : rv64imafdch_zicbom_zicboz_ziccrse_zicntr_zicsr_zifencei_zihpm_zaamo_zalrsc_zca_zcd_zba_zbb_zbc_zbs_smaia_smstateen_ssaia_sscofpmf_sstc_svinval_svnapot_svpbmt

[1] https://lore.kernel.org/all/[email protected]/
---
Changes in v2:
- Added comment linking the spec allocating 42 to marchid
- Cleaned up the id setting
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]

---
 target/riscv/cpu.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
target/riscv/cpu.c +11 -1
index fa497e5e8a..94946d335f 100644
@@ -47,6 +47,13 @@
 static const char riscv_single_letter_exts[] = "IEMAFDQCBPVH";
 const uint32_t misa_bits[] = {RVI, RVE, RVM, RVA, RVF, RVD, RVV,
                               RVC, RVS, RVU, RVH, RVG, RVB, 0};
+#define RISCV_CPU_MVENDORID 0
+#define RISCV_CPU_MIMPID 0
+/*
+ * marchid allocated for qemu:
+ * https://github.com/riscv/riscv-isa-manual/blob/main/marchid.md
+ */
+#define RISCV_CPU_MARCHID 42
 
 /*
  * From vector_helper.c
@@ -1183,6 +1190,10 @@ static void riscv_cpu_init(Object *obj)
         mcc->def->profile->enabled = true;
     }
 
+    cpu->cfg.mvendorid = RISCV_CPU_MVENDORID;
+    cpu->cfg.marchid = RISCV_CPU_MARCHID;
+    cpu->cfg.mimpid = RISCV_CPU_MIMPID;
+
     env->misa_ext_mask = env->misa_ext = mcc->def->misa_ext;
     riscv_cpu_cfg_merge(&cpu->cfg, &mcc->def->cfg);
 
 
---

base-commit: b83371668192a705b878e909c5ae9c1233cbd5fb
change-id: 20260624-marchid-80d176b873d8

Best regards,
--
- Charlie