riscv-to-apply queue
Subsystems (2)
From: Alistair Francis <[email protected]>
The following changes since commit d73149283205645625bfa9fe029cfb68e4c4a9ae:
Merge tag 'samuel-thibault' of https://people.debian.org/~sthibault/qemu into staging (2026-10-24 16:09:37 +0200)
are available in the Git repository at:
https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20261027
for you to fetch changes up to bf67d56f282c1ee25b67dfda3f8ca54d2bd4648e:
target/riscv: Fix CPU state access on big-endian hosts (2026-10-27 10:26:46 +1000)
----------------------------------------------------------------
RISC-V PR for 11.2
* Add experimental Zvabd extension support
* Mask vsepc according to IALIGN
* Reset vCPU on VM reset via MP_STATE_INIT_RECEIVED
* Improve modeling of the Atlantis UART
* Fix IOMMU entry leak with ioatc-limit=0
* Fix integer handling issues in k230_gsdma and k230_decomp_gzip
* Reclaim invalidated IOATC entries for IOMMU
* Duct tape fix for QMP and RV profiles introspection
* Move RISC-V 'Z' CPU properties section to removed features
* Use TSO barriers instead of full barriers for Ztso
* Make mnstatus.MNPELP writable with Zicfilp
* Gate envcfg CBO fields on extensions
* Fix stale PMP state across reset
* Use 1ULL for a value we're going to shift by 63
* Remove unused IMISC macro
* Encode debug translation ranges in IOMMU
* Allow regular mstatus MPV/GVA writes again
* Fix uninitialised upper half in pmu_timer_trigger_irq
* Fix CPU state access on big-endian hosts
----------------------------------------------------------------
Anton Johansson (1):
target/riscv: Fix CPU state access on big-endian hosts
Daniel Henrique Barboza (3):
target/riscv/cpu.c: duct tape fix for QMP + RV profiles introspection include/hw/intc/riscv_imsic.h: remove unused macro target/riscv/csr.c: allow regular mstatus MPV/GVA writes again
Harshit Mukhedkar (1):
target/riscv: fix uninitialised upper half in pmu_timer_trigger_irq()
Mingliang Liu (2):
disas/riscv: Support vabs.v pseudo-instruction tests/tcg/riscv64: Add Zvabd extension tests
Peter Maydell (1):
target/riscv: Use 1ULL for a value we're going to shift by 63
Philippe Mathieu-Daudé (1):
docs: Move RISC-V 'Z' CPU properties section to removed features
Portia Stephens (3):
hw/riscv/atlantis: Use dw8250 UART model hw/riscv/atlantis: Add all UARTs for Atlantis SoC docs/atlantis: Update Atlantis UART documentation
Rick Richard (1):
target/riscv: Use TSO barriers instead of full barriers for Ztso
Sebastian Alba Vives (2):
target/riscv: pmp: clear A and L on every implemented PMP entry at reset target/riscv: pmp: reset the derived PMP bounds and rule count
Tan Chi (3):
hw/riscv/riscv-iommu: fix entry leak with ioatc-limit=0 hw/riscv/riscv-iommu: serialize IOATC accesses hw/riscv/riscv-iommu: reclaim invalidated IOATC entries
Tao Ding (5):
hw/misc: fix calculating output address overflow in k230_decomp_gzip hw/misc: fix calculating input address overflow in k230_decomp_gzip hw/misc: use hwaddr for the k230_decomp_gzip input address
qtest: fix k230_decomp_gzip test integer handling issues hw/dma: fix k230_gsdma integer handling issues
Wang Yechao (1):
target/riscv/kvm: Reset vCPU on VM reset via MP_STATE_INIT_RECEIVED
Zephyr Li (2):
target/riscv: mask vsepc according to IALIGN hw/riscv/riscv-iommu: encode debug translation ranges
Zhibo Hong (1):
target/riscv: Add support for the Zvabd extension
wangyang (2):
target/riscv: make mnstatus.MNPELP writable with Zicfilp target/riscv: gate envcfg CBO fields on extensions
docs/about/deprecated.rst | 24 - docs/about/removed-features.rst | 7 + docs/system/riscv/tt_atlantis.rst | 7 +- hw/riscv/riscv-iommu.h | 1 + include/hw/intc/riscv_imsic.h | 1 - include/hw/riscv/tt_atlantis.h | 13 +- target/riscv/helper.h | 26 ++ target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/insn32.decode | 10 + disas/riscv.c | 14 + hw/dma/k230_gsdma.c | 84 ++-- hw/misc/k230_decomp_gzip.c | 6 +- hw/riscv/riscv-iommu.c | 190 ++++---- hw/riscv/tt_atlantis.c | 68 +-- target/riscv/cpu.c | 22 +- target/riscv/kvm/kvm-cpu.c | 27 ++ target/riscv/tcg/csr.c | 50 ++- target/riscv/tcg/pmp.c | 10 +- target/riscv/tcg/pmu.c | 18 +- target/riscv/tcg/tcg-cpu.c | 6 + target/riscv/tcg/translate.c | 32 +- target/riscv/tcg/vector_helper.c | 56 +++ tests/qtest/iommu-riscv-test.c | 193 ++++++++ tests/qtest/k230-decomp-gzip-test.c | 2 +- disas/riscv-op.c.inc | 9 + target/riscv/tcg/insn_trans/trans_rvi.c.inc | 4 +- target/riscv/tcg/insn_trans/trans_rvv.c.inc | 49 ++- hw/riscv/Kconfig | 2 +- tests/tcg/riscv64/system/meson.build | 12 + tests/tcg/riscv64/test-vsepc-masking.S | 54 +++ tests/tcg/riscv64/test-zvabd.S | 659 ++++++++++++++++++++++++++++ 31 files changed, 1423 insertions(+), 234 deletions(-) create mode 100644 tests/tcg/riscv64/test-vsepc-masking.S create mode 100644 tests/tcg/riscv64/test-zvabd.S
[PULL 03/29] tests/tcg/riscv64: Add Zvabd extension tests
From: Mingliang Liu <[email protected]>
Add a RV64 TCG test covering the masked and unmasked vector-vector and vector-scalar forms of vabd, vabdu, vwabda, and vwabdau.
Assemblers do not yet support the version 0.9 instruction mnemonics, so the instruction encodings are hardcoded for the time being.
GNU binutils 2.47 supports the incompatible version 0.7 instruction encodings. Therefore, this test must not be built with that version, even after it is converted to use instruction mnemonics.
Co-Author: Daniel Henrique Barboza <[email protected]>
Message-ID: <[email protected]>
--- tests/tcg/riscv64/system/meson.build | 1 + tests/tcg/riscv64/test-zvabd.S | 659 +++++++++++++++++++++++++++ 2 files changed, 660 insertions(+) create mode 100644 tests/tcg/riscv64/test-zvabd.S
tests/tcg/riscv64/system/meson.build +1 -0
@@ -25,6 +25,7 @@ tests += { 'test-minstret-ecall.S': setup + {'qemu_args': ['-icount', 'shift=1', qemu_args]}, 'test-minstret-wfi.S': setup + {'qemu_args': ['-icount', 'shift=1', qemu_args]}, 'test-misa-w.S': setup + {'qemu_args': ['-cpu', 'rv64,x-misa-w=true,c=true,v=true', qemu_args]}, + 'test-zvabd.S': setup + {'qemu_args': ['-cpu', 'rv64,v=true,vlen=256,x-zvabd=true', qemu_args]}, } tests += {
tests/tcg/riscv64/test-zvabd.S new file +659 -0
659 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 01/29] target/riscv: Add support for the Zvabd extension
In reply to [email protected]From: Zhibo Hong <[email protected]>
The draft Zvabd extension version 0.9 provides vector integer absolute-difference operations for image, video, and other data-processing workloads. It introduces eight new instructions:
- vabd.vv, vabd.vx, vabdu.vv, and vabdu.vx support SEW values from 8 through ELEN, with SEW 64 requiring Zve64x.
- vwabda.vv, vwabda.vx, vwabdau.vv, and vwabdau.vx support SEW 8 and 16 and accumulate into a double-width destination.
This patch implements the extension, including instruction decoding, TCG translation, and helper functions. This implementation targets version 0.9, whose instruction encodings differ from version 0.7.
The specification is under review at:
https://github.com/riscv/riscv-isa-manual/pull/3279
Message-ID: <[email protected]>
--- target/riscv/helper.h | 26 ++++++++++ target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/insn32.decode | 10 ++++ disas/riscv.c | 8 +++ target/riscv/cpu.c | 1 + target/riscv/tcg/tcg-cpu.c | 6 +++ target/riscv/tcg/vector_helper.c | 56 +++++++++++++++++++++ disas/riscv-op.c.inc | 8 +++ target/riscv/tcg/insn_trans/trans_rvv.c.inc | 45 +++++++++++++++++ 9 files changed, 161 insertions(+)
target/riscv/helper.h +26 -0
@@ -1353,6 +1353,32 @@ DEF_HELPER_5(vsm4k_vi, void, ptr, ptr, i32, env, i32) DEF_HELPER_4(vsm4r_vv, void, ptr, ptr, env, i32)DEF_HELPER_4 (vsm4r_vs, void, ptr, ptr, env, i32) +/* Zvabd Extension */ +DEF_HELPER_6(vabd_vv_b, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vabd_vv_h, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vabd_vv_w, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vabd_vv_d, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vabd_vx_b, void, ptr, ptr, tl, ptr, env, i32) +DEF_HELPER_6(vabd_vx_h, void, ptr, ptr, tl, ptr, env, i32) +DEF_HELPER_6(vabd_vx_w, void, ptr, ptr, tl, ptr, env, i32) +DEF_HELPER_6(vabd_vx_d, void, ptr, ptr, tl, ptr, env, i32) +DEF_HELPER_6(vabdu_vv_b, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vabdu_vv_h, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vabdu_vv_w, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vabdu_vv_d, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vabdu_vx_b, void, ptr, ptr, tl, ptr, env, i32) +DEF_HELPER_6(vabdu_vx_h, void, ptr, ptr, tl, ptr, env, i32) +DEF_HELPER_6(vabdu_vx_w, void, ptr, ptr, tl, ptr, env, i32) +DEF_HELPER_6(vabdu_vx_d, void, ptr, ptr, tl, ptr, env, i32) +DEF_HELPER_6(vwabda_vv_b, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vwabda_vv_h, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vwabda_vx_b, void, ptr, ptr, tl, ptr, env, i32) +DEF_HELPER_6(vwabda_vx_h, void, ptr, ptr, tl, ptr, env, i32) +DEF_HELPER_6(vwabdau_vv_b, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vwabdau_vv_h, void, ptr, ptr, ptr, ptr, env, i32) +DEF_HELPER_6(vwabdau_vx_b, void, ptr, ptr, tl, ptr, env, i32) +DEF_HELPER_6 (vwabdau_vx_h, void, ptr, ptr, tl, ptr, env, i32) + /* CFI (zicfiss) helpers */#ifndef CONFIG_USER_ONLY DEF_HELPER_1 (ssamoswap_disabled, void, env)
target/riscv/cpu_cfg_fields.h.inc +1 -0
@@ -83,6 +83,7 @@ BOOL_FIELD(ext_zve32x) BOOL_FIELD(ext_zve64f) BOOL_FIELD(ext_zve64d) BOOL_FIELD(ext_zve64x) +BOOL_FIELD(ext_zvabd) BOOL_FIELD(ext_zvbb) BOOL_FIELD(ext_zvbc) BOOL_FIELD(ext_zvkb)
target/riscv/insn32.decode +10 -0
@@ -1087,3 +1087,13 @@ sb_aqrl 00111 . . ..... ..... 000 ..... 0101111 @atom_st sh_aqrl 00111 . . ..... ..... 001 ..... 0101111 @atom_st sw_aqrl 00111 . . ..... ..... 010 ..... 0101111 @atom_st sd_aqrl 00111 . . ..... ..... 011 ..... 0101111 @atom_st + +# *** Zvabd Extension *** +vabd_vv 010101 . ..... ..... 010 ..... 1010111 @r_vm +vabd_vx 010101 . ..... ..... 110 ..... 1010111 @r_vm +vabdu_vv 010110 . ..... ..... 010 ..... 1010111 @r_vm +vabdu_vx 010110 . ..... ..... 110 ..... 1010111 @r_vm +vwabda_vv 111101 . ..... ..... 000 ..... 1010111 @r_vm +vwabda_vx 111101 . ..... ..... 100 ..... 1010111 @r_vm +vwabdau_vv 111110 . ..... ..... 000 ..... 1010111 @r_vm +vwabdau_vx 111110 . ..... ..... 100 ..... 1010111 @r_vm
disas/riscv.c +8 -0
@@ -2025,6 +2025,8 @@ static const rv_opcode_data *decode_inst_opcode(rv_decode *dec, rv_isa isa)case 48 :return &op_vwredsumu_vs;case 49 :return &op_vwredsum_vs;case 53 :return &op_vwsll_vv; +case 61 :return &op_vwabda_vv; +case 62 :return &op_vwabdau_vv; }break ;case 1 :
@@ -2167,6 +2169,8 @@ static const rv_opcode_data *decode_inst_opcode(rv_decode *dec, rv_isa isa)break ; }break ; +case 21 :return &op_vabd_vv; +case 22 :return &op_vabdu_vv;case 23 :if ((inst >>25 ) &1 ) {return &op_vcompress_vm;
@@ -2352,6 +2356,8 @@ static const rv_opcode_data *decode_inst_opcode(rv_decode *dec, rv_isa isa)case 46 :return &op_vnclipu_wx;case 47 :return &op_vnclip_wx;case 53 :return &op_vwsll_vx; +case 61 :return &op_vwabda_vx; +case 62 :return &op_vwabdau_vx; }break ;case 5 :
@@ -2428,6 +2434,8 @@ static const rv_opcode_data *decode_inst_opcode(rv_decode *dec, rv_isa isa) } }break ; +case 21 :return &op_vabd_vx; +case 22 :return &op_vabdu_vx;case 32 :return &op_vdivu_vx;case 33 :return &op_vdiv_vx;case 34 :return &op_vremu_vx;
target/riscv/cpu.c +1 -0
@@ -222,6 +222,7 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (zksh,PRIV_VERSION_1_12_0 , ext_zksh),ISA_EXT_DATA_ENTRY (zkt,PRIV_VERSION_1_12_0 , ext_zkt),ISA_EXT_DATA_ENTRY (ztso,PRIV_VERSION_1_12_0 , ext_ztso), +ISA_EXPERIMENTAL_EXT_DATA_ENTRY (zvabd,PRIV_VERSION_1_13_0 , ext_zvabd),ISA_EXT_DATA_ENTRY (zvbb,PRIV_VERSION_1_12_0 , ext_zvbb),ISA_EXT_DATA_ENTRY (zvbc,PRIV_VERSION_1_12_0 , ext_zvbc), ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f),
target/riscv/tcg/tcg-cpu.c +6 -0
@@ -760,6 +760,12 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)return ; } +if ((cpu->cfg.ext_zvabd) && !cpu->cfg.ext_zve32x) { +error_setg (errp, +"Zvabd extensions require V or Zve* extensions" ); +return ; + } +if (cpu->cfg.ext_zicntr && !cpu->cfg.ext_zicsr) {if (cpu_cfg_ext_is_user_set (cpu,CPU_CFG_OFFSET (ext_zicntr))) {error_setg (errp,"zicntr requires zicsr" );
target/riscv/tcg/vector_helper.c +56 -0
59 lines not on this page · raw message
disas/riscv-op.c.inc +8 -0
@@ -490,6 +490,10 @@ OP(vaadd_vv, "vaadd.vv", rv_codec_v_r, rv_fmt_vd_vs2_vs1_vm) OP(vaadd_vx, "vaadd.vx", rv_codec_v_r, rv_fmt_vd_vs2_rs1_vm) OP(vaaddu_vv, "vaaddu.vv", rv_codec_v_r, rv_fmt_vd_vs2_vs1_vm) OP(vaaddu_vx, "vaaddu.vx", rv_codec_v_r, rv_fmt_vd_vs2_rs1_vm) +OP(vabd_vv, "vabd.vv", rv_codec_v_r, rv_fmt_vd_vs2_vs1_vm) +OP(vabd_vx, "vabd.vx", rv_codec_v_r, rv_fmt_vd_vs2_rs1_vm) +OP(vabdu_vv, "vabdu.vv", rv_codec_v_r, rv_fmt_vd_vs2_vs1_vm) +OP(vabdu_vx, "vabdu.vx", rv_codec_v_r, rv_fmt_vd_vs2_rs1_vm) OP(vadc_vim, "vadc.vim", rv_codec_v_i, rv_fmt_vd_vs2_imm_vl) OP(vadc_vvm, "vadc.vvm", rv_codec_v_r, rv_fmt_vd_vs2_vs1_vl) OP(vadc_vxm, "vadc.vxm", rv_codec_v_r, rv_fmt_vd_vs2_rs1_vl)
@@ -861,6 +865,10 @@ OP(vsuxei16_v, "vsuxei16.v", rv_codec_v_r, rv_fmt_ldst_vd_rs1_vs2_vm) OP(vsuxei32_v, "vsuxei32.v", rv_codec_v_r, rv_fmt_ldst_vd_rs1_vs2_vm) OP(vsuxei64_v, "vsuxei64.v", rv_codec_v_r, rv_fmt_ldst_vd_rs1_vs2_vm) OP(vsuxei8_v, "vsuxei8.v", rv_codec_v_r, rv_fmt_ldst_vd_rs1_vs2_vm) +OP(vwabda_vv, "vwabda.vv", rv_codec_v_r, rv_fmt_vd_vs2_vs1_vm) +OP(vwabda_vx, "vwabda.vx", rv_codec_v_r, rv_fmt_vd_vs2_rs1_vm) +OP(vwabdau_vv, "vwabdau.vv", rv_codec_v_r, rv_fmt_vd_vs2_vs1_vm) +OP(vwabdau_vx, "vwabdau.vx", rv_codec_v_r, rv_fmt_vd_vs2_rs1_vm) OP(vwadd_vv, "vwadd.vv", rv_codec_v_r, rv_fmt_vd_vs2_vs1_vm) OP(vwadd_vx, "vwadd.vx", rv_codec_v_r, rv_fmt_vd_vs2_rs1_vm) OP(vwadd_wv, "vwadd.wv", rv_codec_v_r, rv_fmt_vd_vs2_vs1_vm)
target/riscv/tcg/insn_trans/trans_rvv.c.inc +45 -0
48 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 12/29] hw/misc: use hwaddr for the k230_decomp_gzip input address
In reply to [email protected]From: Tao Ding <[email protected]>
Use hwaddr for address calculations to avoid 32-bit overflow and address truncation.
Message-ID: <[email protected]>
--- hw/misc/k230_decomp_gzip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/k230_decomp_gzip.c +1 -1
@@ -102,7 +102,7 @@ static void k230_decomp_gzip_finish(K230DecompGzipState *s, bool crc_ok) }static bool k230_decomp_gzip_load_input (K230DecompGzipState *s, -uint32_t addr,uint32_t size) +hwaddr addr,uint32_t size) { s->input.current_offset =0 ;
Signature · 1 line
2.55.0
[PULL 13/29] qtest: fix k230_decomp_gzip test integer handling issues
In reply to [email protected]From: Tao Ding <[email protected]>
Cast slot to hwaddr before multiplication to prevent 32-bit overflow when calculating the SRAM input address.
Resolves: Coverity CID 1685516
Message-ID: <[email protected]>
--- tests/qtest/k230-decomp-gzip-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/k230-decomp-gzip-test.c +1 -1
@@ -46,7 +46,7 @@ static inline hwaddr k230_sram_addr(hwaddr off)static inline hwaddr k230_sram_input_addr (unsigned int slot) {return k230_sram_addr (K230_DECOMP_GZIP_SRAM_IN_BASE + - slot *K230_DECOMP_GZIP_BLOCK_SIZE ); + (hwaddr ) slot *K230_DECOMP_GZIP_BLOCK_SIZE ); }/*
Signature · 1 line
2.55.0
[PULL 18/29] docs: Move RISC-V 'Z' CPU properties section to removed features
In reply to [email protected]From: Philippe Mathieu-Daudé <[email protected]>
RISC-V 'Z' CPU properties were removed in commit 455c0fa9eef, for the release v10.1.0. Move the corresponding section from deprecated.rst to removed-features.rst, adjusting the wording accordingly.
Message-ID: <[email protected]>
--- docs/about/deprecated.rst | 24 ------------------------ docs/about/removed-features.rst | 7 +++++++ 2 files changed, 7 insertions(+), 24 deletions(-)
docs/about/deprecated.rst +0 -24
@@ -362,30 +362,6 @@ the addition of volatile memory support, it is now necessary to distinguish between persistent and volatile memory backends. As such, memdev is deprecated in favor of persistent-memdev. - -RISC-V CPU properties which start with capital 'Z' (since 8.2) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -All RISC-V CPU properties which start with capital 'Z' are being deprecated -starting in 8.2. The reason is that they were wrongly added with capital 'Z' -in the past. CPU properties were later added with lower-case names, which -is the format we want to use from now on. - -Users which try to use these deprecated properties will receive a warning -recommending to switch to their stable counterparts: - -- "Zifencei" should be replaced with "zifencei" -- "Zicsr" should be replaced with "zicsr" -- "Zihintntl" should be replaced with "zihintntl" -- "Zihintpause" should be replaced with "zihintpause" -- "Zawrs" should be replaced with "zawrs" -- "Zfa" should be replaced with "zfa" -- "Zfh" should be replaced with "zfh" -- "Zfhmin" should be replaced with "zfhmin" -- "Zve32f" should be replaced with "zve32f" -- "Zve64f" should be replaced with "zve64f" -- "Zve64d" should be replaced with "zve64d" - Block device options ''''''''''''''''''''
docs/about/removed-features.rst +7 -0
@@ -1038,6 +1038,13 @@ initial RISC-V QEMU port. Its usage was always been unclear: users don't know what to expect from a CPU called 'any', and in fact the CPU does not do anything special that isn't already done by the default CPUs rv32/rv64. +RISC-V CPU properties which start with capital 'Z' (removed in 10.1) +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +All RISC-V CPU properties which start with capital 'Z' have been removed. +They were wrongly added with capital 'Z' in the past. CPU properties +with lower-case names are used instead. + Power8E and Power8NVL CPUs (removed in 11.1) ''''''''''''''''''''''''''''''''''''''''''''
Signature · 1 line
2.55.0
[PULL 02/29] disas/riscv: Support vabs.v pseudo-instruction
In reply to [email protected]From: Mingliang Liu <[email protected]>
Message-ID: <[email protected]>
--- disas/riscv.c | 6 ++++++ disas/riscv-op.c.inc | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-)
disas/riscv.c +6 -0
@@ -104,6 +104,7 @@ static const rvc_constraint rvcc_j[] = { rvc_rd_eq_x0, rvc_end };static const rvc_constraint rvcc_ret[] = { rvc_rs1_eq_ra, rvc_end };static const rvc_constraint rvcc_jr[] = { rvc_rd_eq_x0, rvc_imm_eq_zero, rvc_end }; +static const rvc_constraint rvcc_vabs_v[] = { rvc_rs1_eq_x0, rvc_end };static const rvc_constraint rvcc_true[] = { rvc_end };/* pseudo-instruction metadata */
@@ -243,6 +244,11 @@ static const rv_comp_data rvcp_fsgnjx_q[] = { { }, }; +static const rv_comp_data rvcp_vabd_vx[] = { + { &op_vabs_v, rvcc_vabs_v }, + { }, +}; +/* Convert compressed insns into normal insns via pseudo expansion. */ #define DECOMP (X ) &(const rv_comp_data){ &X, rvcc_true }
disas/riscv-op.c.inc +2 -1
@@ -491,9 +491,10 @@ OP(vaadd_vx, "vaadd.vx", rv_codec_v_r, rv_fmt_vd_vs2_rs1_vm) OP(vaaddu_vv, "vaaddu.vv", rv_codec_v_r, rv_fmt_vd_vs2_vs1_vm) OP(vaaddu_vx, "vaaddu.vx", rv_codec_v_r, rv_fmt_vd_vs2_rs1_vm) OP(vabd_vv, "vabd.vv", rv_codec_v_r, rv_fmt_vd_vs2_vs1_vm) -OP(vabd_vx, "vabd.vx", rv_codec_v_r, rv_fmt_vd_vs2_rs1_vm) +OP(vabd_vx, "vabd.vx", rv_codec_v_r, rv_fmt_vd_vs2_rs1_vm, rvcp_vabd_vx) OP(vabdu_vv, "vabdu.vv", rv_codec_v_r, rv_fmt_vd_vs2_vs1_vm) OP(vabdu_vx, "vabdu.vx", rv_codec_v_r, rv_fmt_vd_vs2_rs1_vm) +OP(vabs_v, "vabs.v", rv_codec_illegal, rv_fmt_vd_vs2_vm) OP(vadc_vim, "vadc.vim", rv_codec_v_i, rv_fmt_vd_vs2_imm_vl) OP(vadc_vvm, "vadc.vvm", rv_codec_v_r, rv_fmt_vd_vs2_vs1_vl) OP(vadc_vxm, "vadc.vxm", rv_codec_v_r, rv_fmt_vd_vs2_rs1_vl)
Signature · 1 line
2.55.0
[PULL 10/29] hw/misc: fix calculating output address overflow in k230_decomp_gzip
In reply to [email protected]From: Tao Ding <[email protected]>
Use hwaddr for address calculations to avoid 32-bit overflow.
Resolves: Coverity CID 1685515
Message-ID: <[email protected]>
--- hw/misc/k230_decomp_gzip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/k230_decomp_gzip.c +1 -1
@@ -53,7 +53,7 @@ static bool k230_decomp_gzip_write_mem(K230DecompGzipState *s, hwaddr addr,static hwaddr k230_decomp_gzip_output_addr (K230DecompGzipState *s) {return K230_DECOMP_GZIP_SRAM_OUT_BASE + - s->output.slot *K230_DECOMP_GZIP_BLOCK_SIZE + + (hwaddr ) s->output.slot *K230_DECOMP_GZIP_BLOCK_SIZE + s->output.current_offset; }
Signature · 1 line
2.55.0
[PULL 11/29] hw/misc: fix calculating input address overflow in k230_decomp_gzip
In reply to [email protected]From: Tao Ding <[email protected]>
Use hwaddr for address calculations to avoid 32-bit overflow.
Resolves: Coverity CID 1685517
Message-ID: <[email protected]>
--- hw/misc/k230_decomp_gzip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/k230_decomp_gzip.c +1 -1
@@ -59,7 +59,7 @@ static hwaddr k230_decomp_gzip_output_addr(K230DecompGzipState *s)static hwaddr k230_decomp_gzip_input_addr (K230DecompGzipState *s) { -return s->input.slot *K230_DECOMP_GZIP_BLOCK_SIZE + +return (hwaddr ) s->input.slot *K230_DECOMP_GZIP_BLOCK_SIZE +K230_DECOMP_GZIP_SRAM_IN_BASE ; }
Signature · 1 line
2.55.0
[PULL 25/29] include/hw/intc/riscv_imsic.h: remove unused macro
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
Found while reading IMSIC code.
Message-ID: <[email protected]>
--- include/hw/intc/riscv_imsic.h | 1 - 1 file changed, 1 deletion(-)
include/hw/intc/riscv_imsic.h +0 -1
@@ -31,7 +31,6 @@ DECLARE_INSTANCE_CHECKER(RISCVIMSICState, RISCV_IMSIC, TYPE_RISCV_IMSIC)#define IMSIC_MMIO_PAGE_SZ (1UL << IMSIC_MMIO_PAGE_SHIFT)#define IMSIC_MMIO_SIZE (__num_pages) ((__num_pages) * IMSIC_MMIO_PAGE_SZ) -#define IMSIC_MMIO_HART_GUEST_MAX_BTIS 6#define IMSIC_MMIO_GROUP_MIN_SHIFT 24#define IMSIC_HART_NUM_GUESTS (__guest_bits) \
Signature · 1 line
2.55.0
[PULL 29/29] target/riscv: Fix CPU state access on big-endian hosts
In reply to [email protected]From: Anton Johansson <[email protected]>
mstatus and mstatus_hs are uint64_t but accessed through
tcg_gen_[ld|st]_tl(..., offsetof(mstatus))
which on a big-endian host running riscv32 incorrectly accesses the top 32 bits rather than the lower bits.
Widen the operations to 64 bit so the lower bits are modified.
Message-ID: <[email protected]>
--- target/riscv/tcg/translate.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
target/riscv/tcg/translate.c +16 -16
@@ -693,7 +693,7 @@ static TCGv get_address_indexed(DisasContext *ctx, int rs1, TCGv offs)*/ static void mark_fs_dirty (DisasContext *ctx) { -TCGv tmp; +TCGv_i64 tmp;if (!has_ext (ctx,RVF )) {return ;
@@ -703,15 +703,15 @@ static void mark_fs_dirty(DisasContext *ctx)/* Remember the state change for the rest of the TB. */ ctx->mstatus_fs =EXT_STATUS_DIRTY ; - tmp =tcg_temp_new (); -tcg_gen_ld_tl (tmp, tcg_env, offsetof(CPURISCVState , mstatus)); -tcg_gen_ori_tl (tmp, tmp,MSTATUS_FS ); -tcg_gen_st_tl (tmp, tcg_env, offsetof(CPURISCVState , mstatus)); + tmp =tcg_temp_new_i64 (); +tcg_gen_ld_i64 (tmp, tcg_env, offsetof(CPURISCVState , mstatus)); +tcg_gen_ori_i64 (tmp, tmp,MSTATUS_FS ); +tcg_gen_st_i64 (tmp, tcg_env, offsetof(CPURISCVState , mstatus));if (ctx->virt_enabled) { -tcg_gen_ld_tl (tmp, tcg_env, offsetof(CPURISCVState , mstatus_hs)); -tcg_gen_ori_tl (tmp, tmp,MSTATUS_FS ); -tcg_gen_st_tl (tmp, tcg_env, offsetof(CPURISCVState , mstatus_hs)); +tcg_gen_ld_i64 (tmp, tcg_env, offsetof(CPURISCVState , mstatus_hs)); +tcg_gen_ori_i64 (tmp, tmp,MSTATUS_FS ); +tcg_gen_st_i64 (tmp, tcg_env, offsetof(CPURISCVState , mstatus_hs)); } } }
@@ -726,21 +726,21 @@ static inline void mark_fs_dirty(DisasContext *ctx) { }*/ static void mark_vs_dirty (DisasContext *ctx) { -TCGv tmp; +TCGv_i64 tmp;if (ctx->mstatus_vs !=EXT_STATUS_DIRTY ) {/* Remember the state change for the rest of the TB. */ ctx->mstatus_vs =EXT_STATUS_DIRTY ; - tmp =tcg_temp_new (); -tcg_gen_ld_tl (tmp, tcg_env, offsetof(CPURISCVState , mstatus)); -tcg_gen_ori_tl (tmp, tmp,MSTATUS_VS ); -tcg_gen_st_tl (tmp, tcg_env, offsetof(CPURISCVState , mstatus)); + tmp =tcg_temp_new_i64 (); +tcg_gen_ld_i64 (tmp, tcg_env, offsetof(CPURISCVState , mstatus)); +tcg_gen_ori_i64 (tmp, tmp,MSTATUS_VS ); +tcg_gen_st_i64 (tmp, tcg_env, offsetof(CPURISCVState , mstatus));if (ctx->virt_enabled) { -tcg_gen_ld_tl (tmp, tcg_env, offsetof(CPURISCVState , mstatus_hs)); -tcg_gen_ori_tl (tmp, tmp,MSTATUS_VS ); -tcg_gen_st_tl (tmp, tcg_env, offsetof(CPURISCVState , mstatus_hs)); +tcg_gen_ld_i64 (tmp, tcg_env, offsetof(CPURISCVState , mstatus_hs)); +tcg_gen_ori_i64 (tmp, tmp,MSTATUS_VS ); +tcg_gen_st_i64 (tmp, tcg_env, offsetof(CPURISCVState , mstatus_hs)); } } }
Signature · 1 line
2.55.0
[PULL 24/29] target/riscv: Use 1ULL for a value we're going to shift by 63
In reply to [email protected]From: Peter Maydell <[email protected]>
In prop_marchid_set() we set mxlen to either 32 or 64, and then calculate
invalid_val = 1LL << (mxlen - 1);
which shifts the signed value 1LL up into its sign bit when mxlen is 64, which Coverity complains about.
This is not UB for QEMU because we use -fwrapv, but it makes more sense to use an explicitly unsigned 1ULL here when we clearly want to be treating it as an unsigned value and the 'invalid_val' variable is of type uint64_t.
Resolves: Coverity CID 1547552
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/cpu.c +1 -1
@@ -2317,7 +2317,7 @@ static void prop_marchid_set(Object *obj, Visitor *v, const char *name,g_assert_not_reached (); } - invalid_val =1LL << (mxlen -1 ); + invalid_val =1ULL << (mxlen -1 );if (value == invalid_val) { error_setg(errp, "Unable to set marchid with MSB (%u) bit set "
Signature · 1 line
2.55.0
[PULL 27/29] target/riscv/csr.c: allow regular mstatus MPV/GVA writes again
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
In commit 18645f195789 we removed the capability of MPV/GVA writes by software, claiming that the ISA says that these bits are changed by the implementation (i.e. hardware).
This fact alone can't be interpret as "so software can't change them". The ISA never mentions that, and we shouldn't just assume read/write accesses based on whether hardware updates it or not. M-mode software can do whatever they want, unless clearly stated in the ISA, and that includes mstatus MPV and GVA updates.
And in fact existing software is writing to these bits, as reported by Fangyu in [1], and that change ended up causing real problems in the end.
Revert "target/riscv/csr.c: do not allow mstatus MPV/GVA writes".
This reverts commit 18645f19578955ec5ff2c40cd2c8753d6bc460c2.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Message-ID: <[email protected]>
--- target/riscv/tcg/csr.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
target/riscv/tcg/csr.c +4 -1
@@ -2108,6 +2108,9 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, }if (xl !=MXL_RV32 || env->debugger) { +if (riscv_has_ext (env,RVH )) { + mask |=MSTATUS_MPV |MSTATUS_GVA ; + }if ((val &MSTATUS64_SXL ) !=0 ) { mask |=MSTATUS64_SXL ; val =riscv_write_uxl (env, val,MSTATUS64_SXL );
@@ -2150,7 +2153,7 @@ static RISCVException write_mstatush(CPURISCVState *env, int csrno, target_ulong val, uintptr_t ra) { uint64_t valh = (uint64_t)val << 32; -uint64_t mask =0 ; +uint64_t mask =riscv_has_ext (env,RVH ) ?MSTATUS_MPV |MSTATUS_GVA :0 ;if (riscv_cpu_cfg (env)->ext_smdbltrp) { mask |=MSTATUS_MDT ;
Signature · 1 line
2.55.0
[PULL 28/29] target/riscv: fix uninitialised upper half in pmu_timer_trigger_irq()
In reply to [email protected]From: Harshit Mukhedkar <[email protected]>
pmu_timer_trigger_irq() reads the counter by passing (target_ulong *)&curr_ctr_val to riscv_pmu_read_ctr(). On RV32 that pointer is to a 32 bit type, so only half of the uint64_t gets written and the rest is whatever was on the stack. The high word read from riscv_pmu_read_ctr() is then ORed in on top of that, and the result is compared against the software written counter to decide whether to raise LCOFI. A stray bit in the garbage half can make that comparison wrong.
Read the low and high halves into their own target_ulong variables and assemble the 64-bit value explicitly.
This was found while looking at #4724, whose reported mhpmcounterh mismatch is fixed separately by 57b484e2d232.
Message-ID: <[email protected]>
--- target/riscv/tcg/pmu.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
target/riscv/tcg/pmu.c +13 -5
@@ -355,7 +355,8 @@ static void pmu_timer_trigger_irq(RISCVCPU *cpu,CPURISCVState *env = &cpu->env;PMUCTRState *counter;int64_t irq_trigger_at; -uint64_t curr_ctr_val, curr_ctrh_val; +target_ulong ctr_lo =0 , ctr_hi =0 ; +uint64_t curr_ctr_val;uint64_t ctr_val; if (evt_idx != RISCV_PMU_EVENT_HW_CPU_CYCLES &&
@@ -383,12 +384,19 @@ static void pmu_timer_trigger_irq(RISCVCPU *cpu,return ; } -riscv_pmu_read_ctr (env, (target_ulong *)&curr_ctr_val, false, ctr_idx); - ctr_val = counter->mhpmcounter_val; +/* +* riscv_pmu_read_ctr() stores a target_ulong, so on RV32 each call fills +* only 32 bits. Read each half into its own target_ulong and build the +* 64 bit value explicitly instead of passing a cast uint64_t pointer, +* which would leave the upper half uninitialised. +*/ +riscv_pmu_read_ctr (env, &ctr_lo, false, ctr_idx); + curr_ctr_val = ctr_lo;if (riscv_cpu_mxl (env) ==MXL_RV32 ) { -riscv_pmu_read_ctr (env, (target_ulong *)&curr_ctrh_val, true, ctr_idx); - curr_ctr_val = curr_ctr_val | (curr_ctrh_val <<32 ); +riscv_pmu_read_ctr (env, &ctr_hi, true, ctr_idx); + curr_ctr_val |= (uint64_t )ctr_hi <<32 ; } + ctr_val = counter->mhpmcounter_val;/* * We can not accommodate for inhibited modes when setting up timer. Check
Signature · 1 line
2.55.0
[PULL 09/29] hw/riscv/riscv-iommu: fix entry leak with ioatc-limit=0
In reply to [email protected]From: Tan Chi <[email protected]>
riscv_iommu_translate() allocates an IOATC entry before passing it to riscv_iommu_iot_update(). The update helper normally transfers ownership to the hash table.
When ioatc-limit is zero, however, the helper returns without inserting or freeing the entry. Every cacheable non-identity translation therefore leaks one RISCVIOMMUEntry.
Avoid this by disabling caching at the caller when ioatc-limit is zero, so riscv_iommu_translate() does not allocate an IOATC entry in the first place. This avoids special-casing entry freeing in riscv_iommu_iot_update() and keeps the ownership semantics simpler.
Message-ID: <[email protected]>
--- hw/riscv/riscv-iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/riscv/riscv-iommu.c +2 -1
@@ -2919,7 +2919,8 @@ static IOMMUTLBEntry riscv_iommu_memory_region_translate(/* Translation disabled or invalid. */ iotlb.addr_mask =0 ; iotlb.perm =IOMMU_NONE ; - }else if (riscv_iommu_translate (as->iommu, ctx, &iotlb, true)) { + }else if (riscv_iommu_translate (as->iommu, ctx, &iotlb, + as->iommu->iot_limit >0 )) {/* Translation disabled or fault reported. */ iotlb.addr_mask =0 ; iotlb.perm =IOMMU_NONE ;
Signature · 1 line
2.55.0
[PULL 26/29] hw/riscv/riscv-iommu: encode debug translation ranges
In reply to [email protected]From: Zephyr Li <[email protected]>
The debug translation response aligns the translated physical address to the effective translation range, but always reports S=0. For a request inside a superpage, the response therefore identifies the wrong 4 KiB physical page.
For effective ranges larger than 4 KiB, set S and encode the range size using trailing ones in the PPN field. Keep the existing response format for 4 KiB translations.
The RISC-V IOMMU specification permits reporting a 4 KiB translation even when the page tables use superpages. Reporting the effective range is an implementation choice; this change does not claim that S=1 is mandatory for every translation through a superpage mapping.
Add debug-response tests for S-stage-only 4 KiB, 64 KiB NAPOT, and 2 MiB translations, G-stage-only 2 MiB translations, and nested S4K/G2M, S2M/G4K, and S2M/G2M mappings. Check requests inside large ranges and at both ends. The mixed nested cases verify that the response uses the smaller effective translation granularity.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3552
Message-ID: <[email protected]>
--- hw/riscv/riscv-iommu.c | 14 ++- tests/qtest/iommu-riscv-test.c | 193 +++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+), 1 deletion(-)
hw/riscv/riscv-iommu.c +13 -1
@@ -2274,8 +2274,20 @@ static void riscv_iommu_process_dbg(RISCVIOMMUState *s)if (fault) { iova =RISCV_IOMMU_TR_RESPONSE_FAULT | (((uint64_t ) fault) <<10 ); }else { +uint64_t ppn; + iova = iotlb.translated_addr & ~iotlb.addr_mask; - iova =set_field (0 ,RISCV_IOMMU_TR_RESPONSE_PPN ,PPN_DOWN (iova)); + ppn =PPN_DOWN (iova); + +if (iotlb.addr_mask >TARGET_PAGE_SIZE -1 ) { +/* Encode the translation range as trailing ones in the PPN. */ + ppn |=PPN_DOWN (iotlb.addr_mask) >>1 ; + iova =RISCV_IOMMU_TR_RESPONSE_S ; + }else { + iova =0 ; + } + + iova =set_field (iova,RISCV_IOMMU_TR_RESPONSE_PPN , ppn); }riscv_iommu_reg_set64 (s,RISCV_IOMMU_REG_TR_RESPONSE , iova); }
tests/qtest/iommu-riscv-test.c +193 -0
216 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 17/29] target/riscv/cpu.c: duct tape fix for QMP + RV profiles introspection
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
Markus reported in [1] a problem with QMP introspection with qemu-system-riscv64 that happens after querying a profile CPU. QEMU crashes hitting an abort during satp_mode logic that, somehow, is being triggered via profile code.
For every profile CPU that goes through init we're setting an 'enabled' flag in the static RISCVProfile object. This sounded like an okay idea back when profiles were introduced, but now we've realized that QMP will querying CPUs without exiting the QEMU process while also going multiple times through cpu_init() and friends. The result is that we're in a situation where we have runtime information being stored in static arrays that persists between CPU definitions being introspected.
A proper fix is to get rid of profile->enabled and turn profiles into cpu->cfg flags like we do with every other extension. Unfortunately we've been using profile->enabled for lots of things and a redesign would be in order, one which I'm not comfortable doing right now - we're too close to the QEMU 11.2 code freeze for such a change.
For now let's silver tape a fix in cpu_init() to reset profile->enabled for all available profiles. We'll do a proper redesign in the next release cycle.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
target/riscv/cpu.c +19 -0
@@ -1550,6 +1550,25 @@ static void riscv_cpu_init(Object *obj) cpu->env.vext_ver =VEXT_VERSION_1_00_0 ; cpu->cfg.max_satp_mode =-1 ; +/* +* The way we're handling profiles does not cope well with QMP +* instropection. We have a static array that stores RISCVCPUProfiles +* objs that hold runtime state for the lifetime of the QEMU process. +* Thus setting profile->enabled once, e.g. when instropecting a +* profile CPU, will leave the flag set for subsequent intropections. +* +* For now, clear all 'enabled' flags to avoid misleading QMP w.r.t +* profiles being set. +* +* FIXME: a better long term solution is to remove profile->enabled +* and just use regular cpu->cfg flags, avoiding static variables +* storing dynamic state. This will help us not only with QMP but +* also single-binary support. +*/ +for (int i =0 ; riscv_profiles[i] !=NULL ; i++) { + riscv_profiles[i]->enabled = false; + } +if (mcc->def->profile) { mcc->def->profile->enabled = true; }
Signature · 1 line
2.55.0
[PULL 04/29] target/riscv: mask vsepc according to IALIGN
In reply to [email protected]From: Zephyr Li <[email protected]>
vsepc is the VS-mode counterpart of sepc and is a WARL register, but unlike mepc and sepc its accessors do not mask the low address bits according to IALIGN. As a result, values with invalid low bits can be observed through vsepc.
Apply get_xepc_mask() to both vsepc reads and writes, matching the existing mepc/sepc handling.
Add a TCG regression test covering both IALIGN=16 and IALIGN=32.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4420
Message-ID: <[email protected]>
--- target/riscv/tcg/csr.c | 4 +- tests/tcg/riscv64/system/meson.build | 11 ++++++ tests/tcg/riscv64/test-vsepc-masking.S | 54 ++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 tests/tcg/riscv64/test-vsepc-masking.S
target/riscv/tcg/csr.c +2 -2
@@ -5484,14 +5484,14 @@ static RISCVException write_vsscratch(CPURISCVState *env, int csrno,static RISCVException read_vsepc (CPURISCVState *env,int csrno,target_ulong *val) { - *val = env->vsepc; + *val = env->vsepc &get_xepc_mask (env);return RISCV_EXCP_NONE ; }static RISCVException write_vsepc (CPURISCVState *env,int csrno,target_ulong val,uintptr_t ra) { - env->vsepc = val; + env->vsepc = val &get_xepc_mask (env);return RISCV_EXCP_NONE ; }
tests/tcg/riscv64/system/meson.build +11 -0
@@ -26,6 +26,17 @@ tests += { 'test-minstret-wfi.S': setup + {'qemu_args': ['-icount', 'shift=1', qemu_args]}, 'test-misa-w.S': setup + {'qemu_args': ['-cpu', 'rv64,x-misa-w=true,c=true,v=true', qemu_args]}, 'test-zvabd.S': setup + {'qemu_args': ['-cpu', 'rv64,v=true,vlen=256,x-zvabd=true', qemu_args]}, + 'test-vsepc-masking.S': setup + { + 'test_name': 'test-vsepc-masking-c', + 'qemu_args': ['-cpu', 'rv64,h=true,c=true', qemu_args], + }, +} + +tests += { + 'test-vsepc-masking.S': { + 'test_name': 'test-vsepc-masking-no-c', + 'qemu_args': ['-cpu', 'rv64,h=true,c=false,zca=false', qemu_args], + }, } tests += {
tests/tcg/riscv64/test-vsepc-masking.S new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 22/29] target/riscv: pmp: clear A and L on every implemented PMP entry at reset
In reply to [email protected]From: Sebastian Alba Vives <[email protected]>
pmp_unlock_entries() bounds its loop with pmp_get_num_rules(), which returns the number of entries whose A field is not OFF rather than the number of implemented entries. With a sparse configuration the loop stops early: with entries 0 and 1 OFF and entries 2 and 3 locked, num_rules is 2, the loop covers i = 0 and i = 1, and entries 2 and 3 keep their lock and address-match bits across reset.
riscv_cpu_reset_hold() clears mseccfg, and with it RLB, before calling this, so pmp_is_readonly() then silently discards every subsequent pmpcfg write to those entries. The stale rules survive for the lifetime of the machine.
Bound the loop by the number of implemented regions instead.
Message-ID: <[email protected]>
--- target/riscv/tcg/pmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/tcg/pmp.c +1 -1
@@ -201,7 +201,7 @@ static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)void pmp_unlock_entries (CPURISCVState *env) { -uint32_t pmp_num =pmp_get_num_rules (env); +uint32_t pmp_num =riscv_cpu_cfg (env)->pmp_regions;int i;for (i =0 ; i < pmp_num; i++) {
Signature · 1 line
2.55.0
[PULL 07/29] hw/riscv/atlantis: Add all UARTs for Atlantis SoC
In reply to [email protected]From: Portia Stephens <[email protected]>
Previously only the Ascalon console UART was enabled, this enables all 5 UARTs on the SoC. Only UART1 is added to the serial interface for now.
Message-ID: <[email protected]>
--- include/hw/riscv/tt_atlantis.h | 11 ++++++++++- hw/riscv/tt_atlantis.c | 36 ++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 9 deletions(-)
include/hw/riscv/tt_atlantis.h +10 -1
@@ -25,6 +25,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(TTAtlantisSoCState, TT_ATLANTIS_SOC)#define TT_ATL_NUM_I2C 5#define TT_ATL_NUM_PRCM 4 +#define TT_ATL_NUM_UARTS 5struct TTAtlantisSoCState {/*< private >*/
@@ -41,7 +42,7 @@ struct TTAtlantisSoCState {RISCVHartArrayState cpus;DeviceState *irqchip;DesignWareI2CState i2c[TT_ATL_NUM_I2C ]; -DW8250State uart1; +DW8250State uart[TT_ATL_NUM_UARTS ];MemoryRegion bootrom;TTAtlantisPRCMState prcm[TT_ATL_NUM_PRCM ];
@@ -66,7 +67,11 @@ enum {TT_ATL_I2C2_IRQ =35 ,TT_ATL_I2C3_IRQ =36 ,TT_ATL_I2C4_IRQ =37 , +TT_ATL_UART0_IRQ =38 ,TT_ATL_UART1_IRQ =39 , +TT_ATL_UART2_IRQ =40 , +TT_ATL_UART3_IRQ =41 , + TT_ATL_UART4_IRQ = 42, }; enum {
@@ -83,7 +88,11 @@ enum {TT_ATL_MIMSIC ,TT_ATL_SAPLIC ,TT_ATL_SIMSIC , +TT_ATL_UART0 ,TT_ATL_UART1 , +TT_ATL_UART2 , +TT_ATL_UART3 , +TT_ATL_UART4 ,TT_ATL_PRCM_RCPU ,TT_ATL_PRCM_HSIO , TT_ATL_PRCM_PCIE,
hw/riscv/tt_atlantis.c +28 -8
@@ -64,7 +64,11 @@ static const MemMapEntry tt_atlantis_memmap[] = { [TT_ATL_I2C2] = { 0xd4060000, 0x10000 }, [TT_ATL_I2C3] = { 0xd4070000, 0x10000 }, [TT_ATL_I2C4] = { 0xd4080000, 0x10000 }, + [TT_ATL_UART0] = { 0xd4100000, 0x10000 }, [TT_ATL_UART1] = { 0xd4110000, 0x10000 }, + [TT_ATL_UART2] = { 0xd4120000, 0x10000 }, + [TT_ATL_UART3] = { 0xd4130000, 0x10000 }, + [TT_ATL_UART4] = { 0xd4140000, 0x10000 }, [TT_ATL_PRCM_PCIE] = { 0xd8000000, 0x100 }, [TT_ATL_PRCM_MM] = { 0xdc000000, 0x1000 }, [TT_ATL_PRCM_HSIO] = { 0xe00c0000, 0x510 },
@@ -531,13 +535,21 @@ static void tt_atlantis_machine_done(Notifier *n, void *data) fdt_load_addr); } +static inline int tt_atlantis_uart_index (int uart_dev) +{ +return uart_dev -TT_ATL_UART0 ; +} +static void tt_atlantis_soc_init (Object *obj) {TTAtlantisSoCState *s =TT_ATLANTIS_SOC (obj);object_initialize_child (obj,"cpus" , &s->cpus,TYPE_RISCV_HART_ARRAY ); -object_initialize_child (obj,"uart1" , &s->uart1,TYPE_DW8250 ); +for (int i =0 ; i <TT_ATL_NUM_UARTS ; i++) { +object_initialize_child (obj,"uart[*]" , &s->uart[i], +TYPE_DW8250 ); + } object_initialize_child(obj, "prcm-rcpu", &s->prcm[TT_ATLANTIS_PRCM_DOMAIN_RCPU],
@@ -682,13 +694,21 @@ static void tt_atlantis_soc_realize(DeviceState *dev, Error **errp) SYS_BUS_DEVICE(&s->prcm[TT_ATLANTIS_PRCM_DOMAIN_MM]), 0));/* UART1, the soc console (UART0 is for the boot microcontroller) */ -qdev_prop_set_chr (DEVICE (&s->uart1),"chardev" ,serial_hd (0 )); -sysbus_realize (SYS_BUS_DEVICE (&s->uart1), &error_fatal); -memory_region_add_subregion (s->memory, - s->memmap[TT_ATL_UART1 ].base, -sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->uart1),0 )); -sysbus_connect_irq (SYS_BUS_DEVICE (&s->uart1),0 , -qdev_get_gpio_in (s->irqchip,TT_ATL_UART1_IRQ )); +qdev_prop_set_chr (DEVICE (&s->uart[tt_atlantis_uart_index (TT_ATL_UART1 )]), +"chardev" ,serial_hd (0 )); + +for (int i =0 ; i <TT_ATL_NUM_UARTS ; i++) { +SysBusDevice *sbd =SYS_BUS_DEVICE (&s->uart[i]); +if (!sysbus_realize (sbd, errp)) { +return ; + } + +memory_region_add_subregion (s->memory, + s->memmap[TT_ATL_UART0 + i].base, +sysbus_mmio_get_region (sbd,0 )); +sysbus_connect_irq (sbd,0 , +qdev_get_gpio_in (s->irqchip,TT_ATL_UART0_IRQ + i)); + }/* I2C */ for (int i =0 ; i <TT_ATL_NUM_I2C ; i++) {
Signature · 1 line
2.55.0
[PULL 20/29] target/riscv: make mnstatus.MNPELP writable with Zicfilp
In reply to [email protected]From: wangyang <[email protected]>
Zicfilp adds MNPELP to mnstatus, and MNRET consumes it when restoring ELP. Include the field in write_mnstatus() when Zicfilp is implemented.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4222
Message-ID: <[email protected]>
--- target/riscv/tcg/csr.c | 4 ++++ 1 file changed, 4 insertions(+)
target/riscv/tcg/csr.c +4 -0
@@ -5766,6 +5766,10 @@ static RISCVException write_mnstatus(CPURISCVState *env, int csrno, mask |=MNSTATUS_MNPV ; } +if (env_archcpu (env)->cfg.ext_zicfilp) { + mask |=MNSTATUS_MNPELP ; + } +/* mnstatus.mnie can only be cleared by hardware. */ env->mnstatus = (env->mnstatus &MNSTATUS_NMIE ) | (val & mask);return RISCV_EXCP_NONE ;
Signature · 1 line
2.55.0
[PULL 05/29] target/riscv/kvm: Reset vCPU on VM reset via MP_STATE_INIT_RECEIVED
In reply to [email protected]From: Wang Yechao <[email protected]>
When a VM reset is requested, KVM needs to reset the register state of the vCPUs. Without this, stale KVM-internal vCPU state (such as the SBI STA shared memory address) is preserved across the reset, which can cause KVM to keep writing steal-time data to an address that now belongs to firmware code, corrupting it.
Add support for the KVM_CAP_RISCV_MP_STATE_RESET capability. When enabled, QEMU resets the vCPU by setting MP_STATE_INIT_RECEIVED through the KVM_SET_MP_STATE ioctl during the KVM_PUT_RESET_STATE phase of kvm_arch_put_registers(). KVM performs the register reset while preserving the original MP_STATE, so no state restoration is needed on the QEMU side.
This reset path is reached both when the guest initiates an SBI system reset and when userspace (e.g. the QEMU monitor) requests a VM reset, covering both reboot scenarios.
The capability is optional and only activated if the host kernel advertises KVM_CAP_RISCV_MP_STATE_RESET, ensuring backward compatibility with older kernels.
Message-ID: <[email protected]>
--- target/riscv/kvm/kvm-cpu.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
target/riscv/kvm/kvm-cpu.c +27 -0
@@ -57,6 +57,7 @@ void riscv_kvm_aplic_request(void *opaque, int irq, int level) }static bool cap_has_mp_state; +static bool mp_state_reset;#define KVM_RISCV_REG_ID_U32 (type, idx) (KVM_REG_RISCV | KVM_REG_SIZE_U32 | \ type | idx)
@@ -1443,10 +1444,31 @@ static int kvm_riscv_put_mp_state(CPUState *cs)return kvm_vcpu_ioctl (cs,KVM_SET_MP_STATE , &mp_state); } +static int kvm_riscv_mp_state_init_received (CPUState *cs) +{ +struct kvm_mp_state mp_state = { + .mp_state =KVM_MP_STATE_INIT_RECEIVED , + }; + +if (!cap_has_mp_state || !mp_state_reset) { +return 0 ; + } + +/* Let KVM resets the VCPU, The original MP_STATE is preserved*/ +return kvm_vcpu_ioctl (cs,KVM_SET_MP_STATE , &mp_state); +} +int kvm_arch_put_registers (CPUState *cs,KvmPutState level,Error **errp) {int ret =0 ; +if (KVM_PUT_RESET_STATE == level) { + ret =kvm_riscv_mp_state_init_received (cs); +if (ret) { +return ret; + } + } + ret =kvm_riscv_put_regs_core (cs);if (ret) {return ret;
@@ -1623,6 +1645,11 @@ int kvm_arch_get_default_type(MachineState *ms)int kvm_arch_init (MachineState *ms,KVMState *s) { cap_has_mp_state =kvm_check_extension (s,KVM_CAP_MP_STATE ); + +if (cap_has_mp_state) { + mp_state_reset = !kvm_vm_enable_cap (s,KVM_CAP_RISCV_MP_STATE_RESET ,0 ); + } +return 0 ; }
Signature · 1 line
2.55.0
[PULL 16/29] hw/riscv/riscv-iommu: reclaim invalidated IOATC entries
In reply to [email protected]From: Tan Chi <[email protected]>
IOTINVAL currently walks the IOATC hash table and invalidates matching entries by setting iot->perm to IOMMU_NONE. The invalidated entries remain in the hash table afterwards.
Under workloads with frequent DMA map/unmap activity, invalid entries can accumulate while only a smaller number of entries remain valid. Subsequent IOTINVAL operations continue to scan these entries. They are also included in g_hash_table_size(), causing the IOATC to reach iot_limit earlier and the entire cache to be flushed more frequently.
Remove matching entries during invalidation instead of leaving them in the hash table with IOMMU_NONE.
The measurements use a Linux 7.3-rc5 guest based on linux-iommu/next commit cec2dc7663e7 with v6 of the "iommu/riscv: Enable MSI remapping, IOMMU_DMA and VFIO" series applied. The QEMU behavior is not specific to this guest kernel; this configuration makes it easier to exercise through normal DMA map/unmap activity.
In a high-churn NVMe workload with frequent DMA map/unmap activity, runtime drops from 168 seconds to 35 seconds, a 4.8x speedup.
A short fio workload with a small working set remains within measurement noise. Across three runs for each version of a 300-second fio workload with a 4 GiB working set, median throughput improves from 68.6 MiB/s to 75.0 MiB/s, an increase of 9.3%.
Message-ID: <[email protected]>
--- hw/riscv/riscv-iommu.c | 122 +++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 66 deletions(-)
hw/riscv/riscv-iommu.c +56 -66
@@ -1582,104 +1582,93 @@ static guint riscv_iommu_iot_hash(gconstpointer v)/* GV: 0 AV: 0 PSCV: 0 GVMA: 0 */ /* GV: 0 AV: 0 GVMA: 1 */ static -void riscv_iommu_iot_inval_all (gpointer key,gpointer value,gpointer data) +gboolean riscv_iommu_iot_inval_all (gpointer key,gpointer value,gpointer data) {RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data; -if (iot->tag == arg->tag) { - iot->perm =IOMMU_NONE ; - } +return iot->tag == arg->tag; }/* GV: 0 AV: 0 PSCV: 1 GVMA: 0 */ static -void riscv_iommu_iot_inval_pscid (gpointer key,gpointer value,gpointer data) +gboolean riscv_iommu_iot_inval_pscid (gpointer key,gpointer value, +gpointer data) {RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data; -if (iot->tag == arg->tag && - iot->pscid == arg->pscid) { - iot->perm =IOMMU_NONE ; - } +return iot->tag == arg->tag && + iot->pscid == arg->pscid; }/* GV: 0 AV: 1 PSCV: 0 GVMA: 0 */ static -void riscv_iommu_iot_inval_iova (gpointer key,gpointer value,gpointer data) +gboolean riscv_iommu_iot_inval_iova (gpointer key,gpointer value,gpointer data) {RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data; -if (iot->tag == arg->tag && - iot->iova == arg->iova) { - iot->perm =IOMMU_NONE ; - } +return iot->tag == arg->tag && + iot->iova == arg->iova; }/* GV: 0 AV: 1 PSCV: 1 GVMA: 0 */ -static void riscv_iommu_iot_inval_pscid_iova (gpointer key,gpointer value, -gpointer data) +static gboolean riscv_iommu_iot_inval_pscid_iova (gpointer key, +gpointer value, +gpointer data) {RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data; -if (iot->tag == arg->tag && - iot->pscid == arg->pscid && - iot->iova == arg->iova) { - iot->perm =IOMMU_NONE ; - } +return iot->tag == arg->tag && + iot->pscid == arg->pscid && + iot->iova == arg->iova; }/* GV: 1 AV: 0 PSCV: 0 GVMA: 0 */ /* GV: 1 AV: 0 GVMA: 1 */ -static -void riscv_iommu_iot_inval_gscid (gpointer key,gpointer value,gpointer data) +static gboolean riscv_iommu_iot_inval_gscid (gpointer key,gpointer value, +gpointer data) {RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data; -if (iot->tag == arg->tag && - iot->gscid == arg->gscid) { - iot->perm =IOMMU_NONE ; - } +return iot->tag == arg->tag && + iot->gscid == arg->gscid; }/* GV: 1 AV: 0 PSCV: 1 GVMA: 0 */ -static void riscv_iommu_iot_inval_gscid_pscid (gpointer key,gpointer value, -gpointer data) +static gboolean riscv_iommu_iot_inval_gscid_pscid (gpointer key, +gpointer value, +gpointer data) {RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data; -if (iot->tag == arg->tag && - iot->gscid == arg->gscid && - iot->pscid == arg->pscid) { - iot->perm =IOMMU_NONE ; - } +return iot->tag == arg->tag && + iot->gscid == arg->gscid && + iot->pscid == arg->pscid; }/* GV: 1 AV: 1 PSCV: 0 GVMA: 0 */ /* GV: 1 AV: 1 GVMA: 1 */ -static void riscv_iommu_iot_inval_gscid_iova (gpointer key,gpointer value, -gpointer data) +static gboolean riscv_iommu_iot_inval_gscid_iova (gpointer key, +gpointer value, +gpointer data) {RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data; -if (iot->tag == arg->tag && - iot->gscid == arg->gscid && - iot->iova == arg->iova) { - iot->perm =IOMMU_NONE ; - } +return iot->tag == arg->tag && + iot->gscid == arg->gscid && + iot->iova == arg->iova; }/* GV: 1 AV: 1 PSCV: 1 GVMA: 0 */ -static void riscv_iommu_iot_inval_gscid_pscid_iova (gpointer key,gpointer value, -gpointer data) +static gboolean riscv_iommu_iot_inval_gscid_pscid_iova (gpointer key, +gpointer value, +gpointer data) {RISCVIOMMUEntry *iot = (RISCVIOMMUEntry *) value;RISCVIOMMUEntry *arg = (RISCVIOMMUEntry *) data; -if (iot->tag == arg->tag && - iot->gscid == arg->gscid && - iot->pscid == arg->pscid && - iot->iova == arg->iova) { - iot->perm =IOMMU_NONE ; - } +return iot->tag == arg->tag && + iot->gscid == arg->gscid && + iot->pscid == arg->pscid && + iot->iova == arg->iova; }/* caller must hold iot_lock */
@@ -1712,7 +1701,7 @@ static void riscv_iommu_iot_update(RISCVIOMMUState *s, RISCVIOMMUEntry *iot)g_hash_table_add (s->iot_cache, iot); } -static void riscv_iommu_iot_inval (RISCVIOMMUState *s,GHFunc func, +static void riscv_iommu_iot_inval (RISCVIOMMUState *s,GHRFunc func,uint32_t gscid,uint32_t pscid,hwaddr iova,RISCVIOMMUTransTag transtag) {RISCVIOMMUEntry key = {
@@ -1723,7 +1712,7 @@ static void riscv_iommu_iot_inval(RISCVIOMMUState *s, GHFunc func, };qemu_mutex_lock (&s->iot_lock); -g_hash_table_foreach (s->iot_cache, func, &key); +g_hash_table_foreach_remove (s->iot_cache, func, &key);qemu_mutex_unlock (&s->iot_lock); }
@@ -1972,7 +1961,8 @@ static void riscv_iommu_process_cq_tail(RISCVIOMMUState *s)dma_addr_t addr;uint32_t tail, head, ctrl;uint64_t cmd_opcode; -GHFunc func; +GHRFunc iot_func; +GHFunc ctx_func; ctrl =riscv_iommu_reg_get32 (s,RISCV_IOMMU_REG_CQCSR ); tail =riscv_iommu_reg_get32 (s,RISCV_IOMMU_REG_CQT ) & s->cq_mask;
@@ -2035,18 +2025,18 @@ static void riscv_iommu_process_cq_tail(RISCVIOMMUState *s) goto cmd_ill; } - func = riscv_iommu_iot_inval_all; + iot_func = riscv_iommu_iot_inval_all;if (gv) { - func = (av) ? riscv_iommu_iot_inval_gscid_iova : + iot_func = (av) ? riscv_iommu_iot_inval_gscid_iova : riscv_iommu_iot_inval_gscid; }riscv_iommu_iot_inval ( - s, func, gscid, pscid, iova,RISCV_IOMMU_TRANS_TAG_VG ); + s, iot_func, gscid, pscid, iova,RISCV_IOMMU_TRANS_TAG_VG );riscv_iommu_iot_inval ( - s, func, gscid, pscid, iova,RISCV_IOMMU_TRANS_TAG_VN ); + s, iot_func, gscid, pscid, iova,RISCV_IOMMU_TRANS_TAG_VN );break ; }
@@ -2066,24 +2056,24 @@ static void riscv_iommu_process_cq_tail(RISCVIOMMUState *s)if (gv) { transtag =RISCV_IOMMU_TRANS_TAG_VN ;if (pscv) { - func = (av) ? riscv_iommu_iot_inval_gscid_pscid_iova : + iot_func = (av) ? riscv_iommu_iot_inval_gscid_pscid_iova : riscv_iommu_iot_inval_gscid_pscid; }else { - func = (av) ? riscv_iommu_iot_inval_gscid_iova : + iot_func = (av) ? riscv_iommu_iot_inval_gscid_iova : riscv_iommu_iot_inval_gscid; } }else { transtag =RISCV_IOMMU_TRANS_TAG_SS ;if (pscv) { - func = (av) ? riscv_iommu_iot_inval_pscid_iova : + iot_func = (av) ? riscv_iommu_iot_inval_pscid_iova : riscv_iommu_iot_inval_pscid; }else { - func = (av) ? riscv_iommu_iot_inval_iova : + iot_func = (av) ? riscv_iommu_iot_inval_iova : riscv_iommu_iot_inval_all; } } -riscv_iommu_iot_inval (s, func, gscid, pscid, iova, transtag); +riscv_iommu_iot_inval (s, iot_func, gscid, pscid, iova, transtag);break ; }
@@ -2091,12 +2081,12 @@ static void riscv_iommu_process_cq_tail(RISCVIOMMUState *s) RISCV_IOMMU_CMD_IODIR_OPCODE):if (!(cmd.dword0 &RISCV_IOMMU_CMD_IODIR_DV )) {/* invalidate all device context cache mappings */ - func = riscv_iommu_ctx_inval_all; + ctx_func = riscv_iommu_ctx_inval_all; }else {/* invalidate all device context matching DID */ - func = riscv_iommu_ctx_inval_devid; + ctx_func = riscv_iommu_ctx_inval_devid; } -riscv_iommu_ctx_inval (s, func, +riscv_iommu_ctx_inval (s, ctx_func,get_field (cmd.dword0,RISCV_IOMMU_CMD_IODIR_DID ),0 );break ;
@@ -2106,9 +2096,9 @@ static void riscv_iommu_process_cq_tail(RISCVIOMMUState *s)/* illegal command arguments IODIR_PDT & DV == 0 */ goto cmd_ill; }else { - func = riscv_iommu_ctx_inval_devid_procid; + ctx_func = riscv_iommu_ctx_inval_devid_procid; } -riscv_iommu_ctx_inval (s, func, +riscv_iommu_ctx_inval (s, ctx_func,get_field (cmd.dword0,RISCV_IOMMU_CMD_IODIR_DID ),get_field (cmd.dword0,RISCV_IOMMU_CMD_IODIR_PID ));break ;
Signature · 1 line
2.55.0
[PULL 21/29] target/riscv: gate envcfg CBO fields on extensions
In reply to [email protected]From: wangyang <[email protected]>
The envcfg CBO fields are provided by Zicbom and Zicboz. Keep them read-only zero when the corresponding extension is absent in all three envcfg CSRs.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4225
Message-ID: <[email protected]>
--- target/riscv/tcg/csr.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-)
target/riscv/tcg/csr.c +33 -4
@@ -3388,10 +3388,19 @@ static RISCVException write_menvcfg(CPURISCVState *env, int csrno, target_ulong val, uintptr_t ra) {const RISCVCPUConfig *cfg =riscv_cpu_cfg (env); -uint64_t mask =MENVCFG_FIOM |MENVCFG_CBIE |MENVCFG_CBCFE | -MENVCFG_CBZE ; +uint64_t mask =MENVCFG_FIOM ;bool stce_changed = false; +/* CBIE/CBCFE are read-only zero when Zicbom is not implemented. */ +if (cfg->ext_zicbom) { + mask |=MENVCFG_CBIE |MENVCFG_CBCFE ; + } + +/* CBZE is read-only zero when Zicboz is not implemented. */ +if (cfg->ext_zicboz) { + mask |=MENVCFG_CBZE ; + } +/* * menvcfg.LPE (Zicfilp) and menvcfg.SSE (Zicfiss) reside in the low * 32 bits and are defined for both RV32 and RV64, so they must be
@@ -3492,8 +3501,18 @@ static RISCVException read_senvcfg(CPURISCVState *env, int csrno,static RISCVException write_senvcfg (CPURISCVState *env,int csrno,target_ulong val,uintptr_t ra) { -uint64_t mask =SENVCFG_FIOM |SENVCFG_CBIE |SENVCFG_CBCFE |SENVCFG_CBZE ; +uint64_t mask =SENVCFG_FIOM ;RISCVException ret; + +/* CBIE/CBCFE are read-only zero when Zicbom is not implemented. */ +if (env_archcpu (env)->cfg.ext_zicbom) { + mask |=SENVCFG_CBIE |SENVCFG_CBCFE ; + } + +/* CBZE is read-only zero when Zicboz is not implemented. */ +if (env_archcpu (env)->cfg.ext_zicboz) { + mask |=SENVCFG_CBZE ; + }/* Update PMM field only if the value is valid according to Zjpm v1.0 */ if (env_archcpu(env)->cfg.ext_ssnpm && riscv_cpu_mxl(env) == MXL_RV64 &&
@@ -3550,10 +3569,20 @@ static RISCVException write_henvcfg(CPURISCVState *env, int csrno, target_ulong val, uintptr_t ra) {const RISCVCPUConfig *cfg =riscv_cpu_cfg (env); -uint64_t mask =HENVCFG_FIOM |HENVCFG_CBIE |HENVCFG_CBCFE |HENVCFG_CBZE ; +uint64_t mask =HENVCFG_FIOM ;RISCVException ret;bool stce_changed = false; +/* CBIE/CBCFE are read-only zero when Zicbom is not implemented. */ +if (cfg->ext_zicbom) { + mask |=HENVCFG_CBIE |HENVCFG_CBCFE ; + } + +/* CBZE is read-only zero when Zicboz is not implemented. */ +if (cfg->ext_zicboz) { + mask |=HENVCFG_CBZE ; + } + ret =smstateen_acc_ok (env,0 ,SMSTATEEN0_HSENVCFG );if (ret !=RISCV_EXCP_NONE ) {return ret;
Signature · 1 line
2.55.0
[PULL 14/29] hw/dma: fix k230_gsdma integer handling issues
In reply to [email protected]From: Tao Ding <[email protected]>
Separate global and channel register handling to prevent unsigned address underflow when calculating GSDMA channel offsets.
Resolves: Coverity CID 1685514
Message-ID: <[email protected]>
--- hw/dma/k230_gsdma.c | 84 ++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 42 deletions(-)
hw/dma/k230_gsdma.c +42 -42
@@ -304,54 +304,54 @@ static uint64_t k230_gsdma_read(void *opaque, hwaddr addr, unsigned int size)hwaddr ch_off;uint64_t ret =0 ; -switch (addr) { -case K230_GSDMA_DMA_CH_EN : - ret = s->dma_ch_en; -break ; -case K230_GSDMA_DMA_INT_MASK : - ret = s->dma_int_mask; -break ; -case K230_GSDMA_DMA_INT_STAT : - ret = s->dma_int_stat; -break ; -case K230_GSDMA_DMA_CFG : - ret = s->dma_cfg; -break ; -case K230_GSDMA_DMA_WEIGHT : - ret = s->dma_weight; -break ; -default : -if (addr <K230_GSDMA_CH_BASE ) { -qemu_log_mask (LOG_GUEST_ERROR , -"%s: not implement gdma at offset 0x%" HWADDR_PRIx -"\n" , __func__, addr); - } -break ; - } - - ch = (addr -K230_GSDMA_CH_BASE ) /K230_GSDMA_CH_STRIDE ; - ch_off = (addr -K230_GSDMA_CH_BASE ) %K230_GSDMA_CH_STRIDE ; -if (ch <K230_GSDMA_NUM_SDMA_CHANNELS ) { -switch (ch_off) { -case K230_GSDMA_CH_CTL : -break ; -case K230_GSDMA_CH_STATUS : - ret = s->channels[ch].status; +if (addr <K230_GSDMA_CH_BASE ) { +switch (addr) { +case K230_GSDMA_DMA_CH_EN : + ret = s->dma_ch_en;break ; -case K230_GSDMA_CH_CFG : - ret = s->channels[ch].cfg; +case K230_GSDMA_DMA_INT_MASK : + ret = s->dma_int_mask;break ; -case K230_GSDMA_CH_USR_DATA : - ret = s->channels[ch].usr_data; +case K230_GSDMA_DMA_INT_STAT : + ret = s->dma_int_stat;break ; -case K230_GSDMA_CH_LLT_SADDR : - ret = s->channels[ch].llt_saddr; +case K230_GSDMA_DMA_CFG : + ret = s->dma_cfg;break ; -case K230_GSDMA_CH_CURRENT_LLT : - ret = s->channels[ch].current_llt; +case K230_GSDMA_DMA_WEIGHT : + ret = s->dma_weight;break ;default : -break ; +qemu_log_mask (LOG_GUEST_ERROR , +"%s: not implement gdma at offset 0x%" HWADDR_PRIx +"\n" , __func__, addr); +return ret; + } + }else { + ch = (addr -K230_GSDMA_CH_BASE ) /K230_GSDMA_CH_STRIDE ; + ch_off = (addr -K230_GSDMA_CH_BASE ) %K230_GSDMA_CH_STRIDE ; +if (ch <K230_GSDMA_NUM_SDMA_CHANNELS ) { +switch (ch_off) { +case K230_GSDMA_CH_CTL : +break ; +case K230_GSDMA_CH_STATUS : + ret = s->channels[ch].status; +break ; +case K230_GSDMA_CH_CFG : + ret = s->channels[ch].cfg; +break ; +case K230_GSDMA_CH_USR_DATA : + ret = s->channels[ch].usr_data; +break ; +case K230_GSDMA_CH_LLT_SADDR : + ret = s->channels[ch].llt_saddr; +break ; +case K230_GSDMA_CH_CURRENT_LLT : + ret = s->channels[ch].current_llt; +break ; +default : +break ; + } } }
Signature · 1 line
2.55.0
[PULL 06/29] hw/riscv/atlantis: Use dw8250 UART model
In reply to [email protected]From: Portia Stephens <[email protected]>
Replace the ns16550 UART with a Designware UART now that a model is available. The hack which sets the rest of the UART register space as unimplemented can be removed.
Message-ID: <[email protected]>
--- include/hw/riscv/tt_atlantis.h | 4 +-- hw/riscv/tt_atlantis.c | 48 +++++++++++----------------------- hw/riscv/Kconfig | 2 +- 3 files changed, 18 insertions(+), 36 deletions(-)
include/hw/riscv/tt_atlantis.h +2 -2
@@ -13,8 +13,8 @@#include "hw/core/sysbus.h" #include "hw/i2c/designware_i2c.h" #include "hw/intc/riscv_imsic.h" -#include "hw/misc/unimp.h" #include "hw/misc/tt_atlantis_prcm.h" +#include "hw/char/dw8250.h" #include "hw/riscv/riscv_hart.h" #define TYPE_TT_ATLANTIS_MACHINE MACHINE_TYPE_NAME("tt-atlantis")
@@ -41,7 +41,7 @@ struct TTAtlantisSoCState {RISCVHartArrayState cpus;DeviceState *irqchip;DesignWareI2CState i2c[TT_ATL_NUM_I2C ]; -UnimplementedDeviceState uart1; +DW8250State uart1;MemoryRegion bootrom;TTAtlantisPRCMState prcm[TT_ATL_NUM_PRCM ];
hw/riscv/tt_atlantis.c +15 -33
89 lines not on this page · raw message
hw/riscv/Kconfig +1 -1
@@ -144,7 +144,7 @@ config TENSTORRENT select RISCV_ACLINT select RISCV_APLIC select RISCV_IMSIC - select SERIAL_MM + select DW8250 select DEVICE_TREE select DESIGNWARE_I2C select DS1338
Signature · 1 line
2.55.0
[PULL 19/29] target/riscv: Use TSO barriers instead of full barriers for Ztso
In reply to [email protected]From: Rick Richard <[email protected]>
With Ztso, plain loads and stores follow RVTSO, but the barriers around them use TCG_MO_ALL. That also orders a store before a later load, which TSO doesn't require, and is expensive: on x86 hosts it adds a locked instruction around every load and store in a multi-threaded guest.
The barrier after a load now only keeps later loads and stores behind it, and the barrier before a store only keeps earlier loads and stores ahead of it. That is all TSO needs.
Message-ID: <[email protected]>
--- target/riscv/tcg/insn_trans/trans_rvi.c.inc | 4 ++-- target/riscv/tcg/insn_trans/trans_rvv.c.inc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
target/riscv/tcg/insn_trans/trans_rvi.c.inc +2 -2
@@ -424,7 +424,7 @@ static bool gen_load(DisasContext *ctx, arg_lb *a, MemOp memop) } if (ctx->ztso) { - tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); + tcg_gen_mb(TCG_MO_LD_LD | TCG_MO_LD_ST | TCG_BAR_LDAQ); } return out;
@@ -485,7 +485,7 @@ static bool gen_store_tl(DisasContext *ctx, arg_sb *a, MemOp memop) TCGv data = get_gpr(ctx, a->rs2, EXT_NONE); if (ctx->ztso) { - tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); + tcg_gen_mb(TCG_MO_LD_ST | TCG_MO_ST_ST | TCG_BAR_STRL); } tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, memop);
target/riscv/tcg/insn_trans/trans_rvv.c.inc +2 -2
@@ -731,7 +731,7 @@ static bool ldst_us_trans(uint32_t vd, uint32_t rs1, uint32_t data, * around the loop. */ if (is_store && s->ztso) { - tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); + tcg_gen_mb(TCG_MO_LD_ST | TCG_MO_ST_ST | TCG_BAR_STRL); } mark_vs_dirty(s);
@@ -739,7 +739,7 @@ static bool ldst_us_trans(uint32_t vd, uint32_t rs1, uint32_t data, fn(dest, mask, base, tcg_env, desc); if (!is_store && s->ztso) { - tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); + tcg_gen_mb(TCG_MO_LD_LD | TCG_MO_LD_ST | TCG_BAR_LDAQ); } finalize_rvv_inst(s);
Signature · 1 line
2.55.0
[PULL 08/29] docs/atlantis: Update Atlantis UART documentation
In reply to [email protected]From: Portia Stephens <[email protected]>
Update Atlantis documentation to describe the DesignWare UART used.
Message-ID: <[email protected]>
--- docs/system/riscv/tt_atlantis.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
docs/system/riscv/tt_atlantis.rst +3 -4
@@ -13,7 +13,7 @@ tt-atlantis QEMU model features * 8-core Ascalon-X CPU Cluster * RISC-V compliant Advanced Interrupt Architecture -* 16550A compatible UART +* DW8250 compatible UART x5 * 4 PRCMs (Clock and Reset Controllers) Known limitations
@@ -25,9 +25,8 @@ real platform. Notably: * There is no PCI host bridge, so virtio-pci devices cannot be attached. Boots that need block storage must use ``-initrd`` with an initramfs. -* The DesignWare UART is modelled with QEMU's ns16550-compatible - ``serial_mm`` device; DesignWare-specific registers beyond that - set return 0. +* The Atlantis platform has 5 UARTs but only ``UART1`` is currently exposed + on the command line serial interface. ``UART1`` is the Ascalon console. Supported software ------------------
Signature · 1 line
2.55.0
[PULL 15/29] hw/riscv/riscv-iommu: serialize IOATC accesses
In reply to [email protected]From: Tan Chi <[email protected]>
The IOATC currently keeps references to the hash table while cached entries are being used. The following change will remove matching entries during invalidation, which requires cached entry lifetime to be protected explicitly.
Add an iot_lock to serialize IOATC lookup, update, invalidation, and reset operations. Copy the fields needed by the translation path while holding the lock, then release it before updating the IOMMUTLBEntry.
Keep the page-table walk outside the critical section so the lock is not held across potentially expensive memory accesses.
Message-ID: <[email protected]>
--- hw/riscv/riscv-iommu.h | 1 + hw/riscv/riscv-iommu.c | 53 ++++++++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 22 deletions(-)
hw/riscv/riscv-iommu.h +1 -0
@@ -73,6 +73,7 @@ struct RISCVIOMMUState {GHashTable *iot_cache;/* IO Translated Address Cache */ unsigned iot_limit;/* IO Translation Cache size limit */ +QemuMutex iot_lock;/* MMIO Hardware Interface */ MemoryRegion regs_mr;
hw/riscv/riscv-iommu.c +31 -22
130 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 23/29] target/riscv: pmp: reset the derived PMP bounds and rule count
In reply to [email protected]From: Sebastian Alba Vives <[email protected]>
The priv spec only requires the A and L fields to be reset, which the previous patch now does for every implemented entry. QEMU additionally keeps derived state next to the architectural registers:
pmp_state.addr[] holds the decoded start and end address of each entry and pmp_state.num_rules caches the active rule count. Both are recomputed from the pmpaddr and pmpcfg write paths only, never at reset.
pmp_is_in_range() compares against addr[].sa and addr[].ea without consulting the A field, and the partially-inside check in pmp_hart_has_privs() runs before the A field is tested, so a range left over from before the reset can still deny an access that straddles its boundary once the guest configures any entry again.
Clear the derived state alongside the architectural fields so the two cannot disagree.
Message-ID: <[email protected]>
--- target/riscv/tcg/pmp.c | 8 ++++++++ 1 file changed, 8 insertions(+)
target/riscv/tcg/pmp.c +8 -0
@@ -207,6 +207,14 @@ void pmp_unlock_entries(CPURISCVState *env)for (i =0 ; i < pmp_num; i++) { env->pmp_state.pmp[i].cfg_reg &= ~(PMP_LOCK |PMP_AMATCH ); } + +/* +* addr[] and num_rules are derived from the pmpaddr and pmpcfg write +* paths and are not recomputed at reset. Clear them here so they +* cannot disagree with the architectural fields cleared above. +*/ +memset (env->pmp_state.addr,0 ,sizeof (env->pmp_state.addr)); + env->pmp_state.num_rules =0 ; }static void pmp_decode_napot (hwaddr a,hwaddr *sa,hwaddr *ea)
Signature · 1 line
2.55.0
Richard Henderson
AppliedQuoted 28 lines · On 10/27/26 01:27, [email protected] wrote:
From: Alistair Francis<[email protected]>
The following changes since commit
d73149283205645625bfa9fe029cfb68e4c4a9ae:Merge tag 'samuel-thibault' ofhttps://people.debian.org/~sthibault/qemu into staging (2026-10-24 16:09:37 +0200)are available in the Git repository at:
https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20261027for you to fetch changes up to
bf67d56f282c1ee25b67dfda3f8ca54d2bd4648e:target/riscv: Fix CPU state access on big-endian hosts (2026-10-27 10:26:46 +1000)----------------------------------------------------------------
RISC-V PR for 11.2* Add experimental Zvabd extension support
* Mask vsepc according to IALIGN
* Reset vCPU on VM reset viaMP_STATE_INIT_RECEIVED
* Improve modeling of the Atlantis UART
* Fix IOMMU entry leak with ioatc-limit=0
* Fix integer handling issues ink230_gsdmaandk230_decomp_gzip
* Reclaim invalidated IOATC entries for IOMMU
* Duct tape fix for QMP and RV profiles introspection
* Move RISC-V 'Z' CPU properties section to removed features
* Use TSO barriers instead of full barriers for Ztso
* Make mnstatus.MNPELP writable with Zicfilp
Quoted 8 lines
* Gate envcfg CBO fields on extensions
* Fix stale PMP state across reset
* Use 1ULL for a value we're going to shift by 63
* Remove unused IMISC macro
* Encode debug translation ranges in IOMMU
* Allow regular mstatus MPV/GVA writes again
* Fix uninitialised upper half inpmu_timer_trigger_irq
* Fix CPU state access on big-endian hosts
Applied, thanks.
r~