131382 Commits

Author SHA1 Message Date
Daniel Henrique Barboza
ce7fb32827 hw/riscv/riscv-iommu.c: set ftype and iova in riscv_iommu_ctx()
We're hardcoding faulting type as READ, where it could very well be a
write access, and we're not recording the faulting addr/iova.

A note was added in the fault_type logic because I wasn't able to
trivially handle a probable code repeitition it in this same patch.
Something to do in a later date.

Fixes: 0c54acb824 ("hw/riscv: add RISC-V IOMMU base emulation")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3564
Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Message-ID: <20260701092241.307801-1-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 15:35:24 +10:00
Daniel Henrique Barboza
6d2b9d542f hw/riscv/riscv-iommu: forbid GATE/SADE if caps.AMO_HWADD is zero
When capabilities.AMO_HWADD isn't set, DC.tc.GADE and DC.tc.SADE are
reserved bits and setting them throws a DDT_MISCONFIGURED error.

Fixes: 0c54acb824 ("hw/riscv: add RISC-V IOMMU base emulation")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3549
Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>
Message-ID: <20260630172110.1866951-1-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 15:33:37 +10:00
Daniel Henrique Barboza
79616dd6e4 hw/riscv/riscv-iommu.c: update ioval2 when faulting in spa_fetch()
riscv_iommu_translate(), the only caller of riscv_iommu_spa_fetch(),
will use riscv_iommu_report_fault() for all faults it detects.  And it
will use iotlb->translated_addr as 'iotval2' every time.

At this moment we're updating iotlb->translated_addr only after a
translation step is completed, meaning any fault that occur before that
will have a zeroed iotlb->translated_addr, and as a result iotval2 will
also be zero later on.

Keep iotlb->translated_addr updated with the latest translated addr we
have.

Fixes: 0c54acb824 ("hw/riscv: add RISC-V IOMMU base emulation")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3559
Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260702171202.1322493-1-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 15:31:50 +10:00
Daniel Henrique Barboza
bf274c5429 hw/riscv/riscv-iommu.c: check for misaligned IOHGATP_PPN
We must check if IOHGATP_PPN is 16kb aligned for non-bare GATP modes.

Fixes: 69a9ae4836 ("hw/riscv/riscv-iommu: add ATS support")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3550
Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>
Message-ID: <20260702203616.1795588-2-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 15:30:03 +10:00
Zephyr Li
e2512b2291 gitlab-ci.d/crossbuilds: add riscv64 KVM-only build job
Add CI coverage for a riscv64 --disable-tcg cross build. This ensures that
RISC-V no-TCG/KVM-only builds keep working and prevents TCG-only code from
being accidentally pulled into common RISC-V sources again.

The cross_accel_build_job template enables KVM by default via
--enable-${ACCEL:-kvm}, so the extra options only need to disable TCG.

Signed-off-by: Zephyr Li <fritchleybohrer@gmail.com>
Reviewed-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260703180538.3346781-25-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
6dd762b415 target/riscv: move riscv_cpu_set_aia_ireg_rmw_cb() to riscv_imsic
riscv_imsic.c is the only caller.  Having it sitting in the TCG only
cpu_helper.c gets in the way of --disable-tcg for no good reason.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260703180538.3346781-24-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
beecb30958 target/riscv: move riscv_cpu_set_geilen() to riscv-imsic
riscv_imsic.c is the only caller.  Having it sitting in the TCG only
cpu_helper.c gets in the way of --disable-tcg for no good reason.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260703180538.3346781-23-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
466c59145f target/riscv/tcg: remove unused riscv_cpu_get_geilen()
No one uses it.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Message-ID: <20260703180538.3346781-22-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
cb1b461838 target/riscv: move riscv_cpu_set_rdtime_fn to riscv_aclint
There's no need for it to be in cpu_helper since riscv_aclint is the
only caller.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260703180538.3346781-21-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
002749d230 target/riscv/gdbstub.c: isolate TCG only checks
The following functions are TCG only and are broken, if they were ever
usable in the first place, with KVM:

- riscv_gdb_(get|se)t_csr
- riscv_gdb_(get|set)_virtual
- riscv_gen_dynamic_csr_feature

Gate everything with TCG enabled to at least get them out of the way to
enable --disable-tcg.

As a note for the future: other archs have distincts gdbstub files for
each accelerator.  There's a strong case for RISC-V to do the same.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Message-ID: <20260703180538.3346781-20-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
a0b0643890 hw/riscv/riscv_hart.c isolate tcg only bits
riscv_cpu_register_csr_qtest_callback(), vcsr_call() and
csr_qtest_callback() are all TCG only and are not available in
--disable-tcg builds.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Message-ID: <20260703180538.3346781-19-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
209638d448 target/riscv/cpu.c: filter TCG only bits in riscv_cpu_reset_hold()
We have a lot of TCG only initialization in the common cpu_reset_hold
callback that prevents --disable-tcg to work.

Put a CONFIG_TCG ifdef around those bits to make the build work.
Eventually we'll create a TCG specific reset function in tcg-cpu.c but
for now this suffices.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260703180538.3346781-18-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
6c91b423a9 target/riscv: gate riscv_cpu_update_mip with tcg_enabled()
riscv_cpu_update_mip() is a TCG only call.  Its KVM equivalent is
kvm_riscv_set_irq().  cpu.c gates the KVM only function with a
kvm_enabled() check, making it unavailable for TCG only builds.  We need
to do the same for riscv_cpu_update_mip() otherwise a KVM only build
will fail because it doesn't know what this function is.

Use tcg_enabled() for the couple of riscv_cpu_update_mip() calls we have
unguarded in cpu.c.

We have way more calls to deal with in time_helper.c which isn't using
kvm_riscv_set_irq() at all, so create a riscv_accel_set_irq() local
helper that will choose whether to use the KVM or TCG API.

The reason we're going through all this hassle in time_helper.c is
because hw/int/riscv_aclint.c uses it, and if we don't do something
about we won't have riscv_aclint working for KVM.  Whether this is a
real problem or not and we should remove aclint support for KVM is
question for another day.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260703180538.3346781-17-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
5fa9e8597b target/riscv/cpu.c: handle TCG bits of riscv_cpu_dump_state
riscv_dump_csr() is a TCG only function but we'll have to implement it
at some capacity for KVM eventually, therefore put it under a CONFIG_TCG
ifdef while making a note that this function is unimplemented in KVM.

The csr_ops array is also TCG specific, thus the for loop inside
dump_state that iterates it is also TCG only business.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Message-ID: <20260703180538.3346781-16-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
705fe3819b target/riscv: move riscv_cpu_claim_interrupts to cpu.c
The function is used by hw/intc/ files that KVM cares about like
riscv_aplic.c.  Move it to cpu.c to be accessible for --disable-tcg
builds.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260703180538.3346781-15-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
e49b1e25fa target/riscv: move some irq helpers to cpu.c
riscv_cpu_has_work() uses a handful of irq pending functions from
cpu_helper.c.  There is a very high possibility that KVM doesn't need
the current implermentation of has_work(), but the common accel code
needs an implementation of this callback (see cpu_exec_class_post_init)
otherwise the KVM driver won't initialize.

Move the relevant irq helpers to cpu.c to allow KVM to keep using the
current has_work implementation, allowing --disable-tcg to work.  We'll
circle it back to evaluate a proper KVM implementation for it in a later
date.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260703180538.3346781-14-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
e26e53b4ab target/riscv: move riscv_cpu_set_nmi() to tcg-cpu.c
This function is related to Smrnmi and non-masked interrupts, firing up
interrupts via env->rnmip from riscv_cpu_local_irq_pending().

This is all TCG only code.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260703180538.3346781-13-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
5b9e32dd5c target/riscv: move custom_csrs logic to tcg-cpu.c
We have a couple of CPUs that has a set of custom CSRs that uses TCG
specific APIs.  Move the related code to tcg-cpu.c and do not set
.custom_csrs if we're not in a TCG build.

What we'll end up doing, sooner or later, is punting all these CPUs to
tcg-cpu.c since they're all TCG specific and KVM has nothing to do with
them.  Another time.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260703180538.3346781-12-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
458630c430 target/riscv: move csr.h to tcg subdir
After KVM is no longer reliant on csr.h move it to the TGC only land.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260703180538.3346781-11-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
2dc5b9d4ef target/riscv: remove csr.h from kvm-cpu.c
Move riscv_new_csr_seed from csr.c to cpu.c since this function is
shared with KVM.  With that we can remove the csr.h from kvm-cpu.c.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260703180538.3346781-10-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
8eaa5b73ab target/riscv: move debug.h to tcg subdir
riscv_trigger_* APIs are TCG only.  Wrap the usages we have of them
in cpu.c with CONFIG_TCG.

After that we can move the header to the tcg subdir.  This will be
enough to get this out of the way for the --disable-tcg build.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260703180538.3346781-9-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
6bf66f0b5a target/riscv: tidy up riscv_sysemu_ops
monitor_get_register at this moment has a TCG exclusive implementation
for RISC-V, even though the callback is supposed to be arch independent.
Until we address how KVM is going to implement it we need to filter it out
in cpu.c.

Same goes for get_phys_addr_debug - it has a TCG only implementation and
KVM can't use it for now.  It would also need to be filtered out, but
since we're at it, let's convert it to the newer 'translate_for_debug'
API too.  Same restrictions apply.

Suggested-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Message-ID: <20260703180538.3346781-8-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
5739b967ba target/riscv: move pmp files to tcg subdir
A trivial header change is required too.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Message-ID: <20260703180538.3346781-7-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
6f6f6aaa26 target/riscv/machine.c: do not migrate pmp state with kvm
The PMP emulation isn't present in the KVM driver.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260703180538.3346781-6-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
d45b9bc655 target/riscv: move TCG only files to tcg subdir
We have *way* too much TCG-only code hanging around in target/riscv,
where ideally we would have things that are shared between accelerators.

We'll follow the example of other targets like i386 and loongarch and
move everything to the tcg subir.  This will not only cleanup target/riscv
but it will also expose what is common code but it's buried inside a TCG
helper.

We're leaving some stuff behind because these require a little more
case to not end up breaking KVM.  We'll take care of them next.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Message-ID: <20260703180538.3346781-5-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:03 +10:00
Daniel Henrique Barboza
ba0b4e84ae hw/riscv, target/riscv: move pmu fdt function to fdt-common.c
riscv_pmu_generate_fdt_node() can be moved to fdt_common.c since it has
no PMU TCG internals.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Message-ID: <20260703180538.3346781-4-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:02 +10:00
Daniel Henrique Barboza
05f9c29e8d target/riscv: move valid_vm_* satp arrays to cpu.c
These satp arrays are used internally in both csr.c and in cpu.c.  csr.c
is going to be moved to the TCG subdir in the next patch, and we want
the satp logic to be available for KVM with --disable-tcg builds.

Move these arrays to cpu.c to keep them available for KVM with
--disable-tcg.

Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Message-ID: <20260703180538.3346781-3-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:02 +10:00
Zephyr Li
27acdd6c3f target/riscv: Remove unused tcg/tcg.h include
Signed-off-by: Zephyr Li <fritchleybohrer@gmail.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Message-ID: <20260703180538.3346781-2-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:02 +10:00
Daniel Henrique Barboza
58e801f74e hw/riscv/riscv-iommu-sys.c: record fault on IOMMU-generated MSI write
The riscv-iommu spec requires that the IOMMU records its own generated
MSI write faults.

Fixes: 01c1caa9d1 ("hw/riscv/virt.c, riscv-iommu-sys.c: add MSIx support")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3572
Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>
Message-ID: <20260629165954.1018123-1-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:02 +10:00
Daniel Henrique Barboza
11486349ad hw/riscv/riscv-iommu.c: check reserved MSI PTE basic bits
We need to throw an MSI_MISCONFIGURED error when any of the reserved PTE
bits (first doubleword only) are set.

Fixes: Fixes: 0c54acb824 ("hw/riscv: add RISC-V IOMMU base emulation")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3563
Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>
Message-ID: <20260629125719.679626-1-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:02 +10:00
Daniel Henrique Barboza
9158c900ab hw/riscv/riscv-iommu.c: fault for non-user PTE in G_STAGE
riscv-iommu spec 1.0 says:

"When checking the U bit in a second-stage PTE, the transaction
 is treated as not requesting supervisor privilege."

We need to *always* fault in case we're on G_STAGE and PTE_U is cleared
since we can't be on supervisor mode at this point.

Fixes: 0c54acb824 ("hw/riscv: add RISC-V IOMMU base emulation")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3555
Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Message-ID: <20260701121111.537654-4-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:02 +10:00
Daniel Henrique Barboza
b795ea0ba4 hw/riscv/riscv-iommu.c: fault when !PTE_U and no priv access
All IOMMU accesses are assumed to be user mode unless told otherwise,
i.e. we have a process_id.  In case we have a non-user mode leaf PTE
(PTE_U isn't set) and we are running in user mode, we need to throw a
fault.

This also reflects on qos-riscv-iommu tests: the tests always run in
user mode so our PTEs must have PTE_U (bit 0x10) set.

Fixes: 0c54acb824 ("hw/riscv: add RISC-V IOMMU base emulation")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3553
Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Message-ID: <20260701121111.537654-3-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:02 +10:00
Daniel Henrique Barboza
c1d5ec3a2f hw/riscv/riscv-iommu.c: check for reserved PTE bits
We need to fault if reserved PTE bits (60:54) are set.

Fixes: 0c54acb824 ("hw/riscv: add RISC-V IOMMU base emulation")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3554
Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>
Message-ID: <20260701121111.537654-2-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:02 +10:00
Daniel Henrique Barboza
b18e3f0e2d hw/riscv/riscv-iommu.c: fix fault type for spa_fetch() faults
Under certain circunstances, like the one described in [1] and [2],
a read operation that faults will be logged as a write fault instead,
and vice-versa, if they happen after the translation phase in
riscv_iommu_spa_fetch().

The first problem is that we're overwriting iotlb->perm with PTE flags,
so an IOMMU_RO access flag can be overwritten by whatever flags
the PTE has.  This will cause the wrong fault type to be thrown at
the end of the function in case a fault happens.

To solve the iotlb->perm overwrite we'll bit_and the original
iotlb->perm access flags with the PTE access flags, preserving the
original access type.  So a IOMMU_RO access in a R+W PTE will result in
a IOMMU_RO perm.

Second, the resulting fault is received by riscv_iommu_translate(), which
will then report the fault.  To do that we require a transaction type
(ttype).  We're prioritizing checking "perm & IOMMU_RW" to set a
UADDR_WR ttype, and then checking "perm & IOMMU_RO" to set UADDR_RD
ttype.  The issue with that is IOMMU_RO=1 and IOMMU_RW=3, thus checking
"perm & IOMMU_RW" for a write then "perm & IOMMU_RO" for a read will
cause the read fault to always be diagnosed as write.

Make the iotlb->perm matches more strict: "perm & IOMMU_RW" must be
exactly IOMMU_RW, ensuring that 'perm' has both flags.  Then we can
check perm & IOMMU_WO and perm & IOMMU_RO without worrying about
overlapping with the RW flag.

[1] https://gitlab.com/qemu-project/qemu/-/work_items/3557
[2] https://gitlab.com/qemu-project/qemu/-/work_items/3577

Fixes: 69a9ae4836 ("hw/riscv/riscv-iommu: add ATS support")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3557
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3577
Signed-off-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260701124034.552271-1-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2026-07-09 14:58:02 +10:00
Jia Jia
90aacd5bc4 hw/ufs: avoid double unref of wrapped scsi-hd
ufs_init_scsi_device() creates an internal scsi-hd and adds it as a
child of lu->bus. qdev_realize_and_unref() then drops the construction
reference, leaving the bus child ownership to tear it down.

ufs_lu_unrealize() still unrefs lu->scsi_dev directly. If the UFS
controller is ejected through ACPI PCI hotplug, the scsi-hd object can be
finalized there and then the bus child removal RCU callback later unrefs
the same object again.

Keep lu->scsi_dev as a borrowed pointer and clear it during unrealize
without unreffing it.

Add a qtest that ejects the UFS controller through the x86 ACPI PCI
hotplug eject register. On an ASAN build, the test reproduces the UAF
before the fix.

Fixes: 096434fea1 ("hw/ufs: Modify lu.c to share codes with SCSI subsystem")
Cc: qemu-stable@nongnu.org
Signed-off-by: Jia Jia <physicalmtea@gmail.com>
Signed-off-by: Jeuk Kim <jeuk20.kim@samsung.com>
2026-07-09 07:58:38 +09:00
Pierrick Bouvier
7d9493a331 tests/docker/dockerfiles/debian-all-test-cross.docker: add missing apt update
RUN statements should always use apt update && apt install together:
https://docs.docker.com/build/building/best-practices/#apt-get

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20260707214655.1138626-5-pierrick.bouvier@oss.qualcomm.com
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
2026-07-08 09:40:43 -07:00
Pierrick Bouvier
334566dfc4 tests/docker/dockerfiles/debian.docker: add missing apt update
RUN statements should always use apt update && apt install together:
https://docs.docker.com/build/building/best-practices/#apt-get

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20260707214655.1138626-4-pierrick.bouvier@oss.qualcomm.com
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
2026-07-08 09:40:43 -07:00
Pierrick Bouvier
81994f1990 tests/docker/dockerfiles/ubuntu2404.docker: add missing apt update
RUN statements should always use apt update && apt install together:
https://docs.docker.com/build/building/best-practices/#apt-get

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Link: https://lore.kernel.org/qemu-devel/20260707214655.1138626-3-pierrick.bouvier@oss.qualcomm.com
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
2026-07-08 09:40:43 -07:00
Pierrick Bouvier
532e8eeb11 tests/lcitool/refresh: use raw string literal for trailers
Using a list of string is not convenient, as users need to escape it
manually and handle end of lines. By using a raw string literal,
what you see is what you get.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20260707214655.1138626-2-pierrick.bouvier@oss.qualcomm.com
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
2026-07-08 09:40:43 -07:00
Stefan Hajnoczi
f893c46c39 Merge tag 'qemu-openbios-20260707' of https://github.com/mcayland/qemu into staging
qemu-openbios queue

# -----BEGIN PGP SIGNATURE-----
#
# iQFSBAABCgA8FiEEzGIauY6CIA2RXMnEW8LFb64PMh8FAmpNaoweHG1hcmsuY2F2
# ZS1heWxhbmRAaWxhbmRlLmNvLnVrAAoJEFvCxW+uDzIfk7EH/AtFkwEY8/VO1i2I
# LyolB3gs0Mr24OS0SPxq0qrBJn4NNwJy5ZSJDiooG46NHgBQPOq5xCdaHI02NkGp
# UM+16m/Kr8E3N562xxx04kCHgtlD7M/jif6wNQxKLYY6bEVc1ckenfgOmsLllJx5
# bJLGWhwQWeJlCFeWxgNEM0ioRL34l5UfjKM1jXisfBbhh0GuhUz9hU7w9pGNDNky
# Wx6S+wjRiqmhzzaVI8PfXJzMqfnzG6ecrHIYJXSByiLTh5w6mzzKWHYLJDgYckj6
# 4S+/Yr7FkTJYmHWPZ/uB91GkQoVvTXmApE9gku56tiMydJOk/c0hK220ajTgxkMF
# hN9l2T4=
# =DSMJ
# -----END PGP SIGNATURE-----
# gpg: Signature made Tue 07 Jul 2026 23:07:24 CEST
# gpg:                using RSA key CC621AB98E82200D915CC9C45BC2C56FAE0F321F
# gpg:                issuer "mark.cave-ayland@ilande.co.uk"
# gpg: Good signature from "Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>" [full]
# Primary key fingerprint: CC62 1AB9 8E82 200D 915C  C9C4 5BC2 C56F AE0F 321F

* tag 'qemu-openbios-20260707' of https://github.com/mcayland/qemu:
  Update OpenBIOS images to e5ac46dd built from submodule.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2026-07-08 16:01:29 +02:00
Stefan Hajnoczi
8dcbb339f5 Merge tag 'pull-tcg-20260707' of https://gitlab.com/rth7680/qemu into staging
tcg/loongarch64: Fix cmp_vec with TCG_COND_NE
tcg/x86_64: declare MO_ATOM_WITHIN16 host atomicity support
accel/tcg: Make PageFlagsNodes' start and last immutable
accel/tcg: Use TLB_FORCE_SLOW not TLB_MMIO for user-only plugins

# -----BEGIN PGP SIGNATURE-----
#
# iQFRBAABCgA7FiEEekgeeIaLTbaoWgXAZN846K9+IV8FAmpNaDIdHHJpY2hhcmQu
# aGVuZGVyc29uQGxpbmFyby5vcmcACgkQZN846K9+IV8qlwgAqFBxRHQFzeNrivul
# 9u4jrEqsQS2wu2pL/rKfr7DTBTzmbibmzTT229yru8yahvpONrbYOantxjikAW6z
# tRgaKaLlFOw2Ll6VKbOxdu2OL+nemOAW3ehiHutuPLtxFSGWQsFtC38Qz51sC1K9
# nTX8vkuYkkIKyVU0Klinu2rjqZW3h1yIwKwC6tieh08y6YYeOODYoAfpEJ+hGus1
# 33hMlE1zEj9j4JVpsDR3Rl3zXUbnV3FMeikTd8Xkl9fBDeWs/aFVLVLXWQ0BYULC
# 62/ZOghnfbrM7p2osLAhkNSL020vn/G1c2O8ofSa0pXj+I7YM80H2m7zsyiBa685
# rm7IKg==
# =0LKf
# -----END PGP SIGNATURE-----
# gpg: Signature made Tue 07 Jul 2026 22:57:22 CEST
# gpg:                using RSA key 7A481E78868B4DB6A85A05C064DF38E8AF7E215F
# gpg:                issuer "richard.henderson@linaro.org"
# gpg: Good signature from "Richard Henderson <richard.henderson@linaro.org>" [full]
# Primary key fingerprint: 7A48 1E78 868B 4DB6 A85A  05C0 64DF 38E8 AF7E 215F

* tag 'pull-tcg-20260707' of https://gitlab.com/rth7680/qemu:
  tcg/loongarch64: Fix cmp_vec with TCG_COND_NE
  tcg/x86_64: declare MO_ATOM_WITHIN16 host atomicity support
  Revert "tests/tcg: skip the vma-pthread test on CI"
  tests/tcg/multiarch: Improve mutator randomness
  accel/tcg: Make PageFlagsNodes' start and last immutable
  accel/tcg: Use TLB_FORCE_SLOW not TLB_MMIO for user-only plugins

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2026-07-08 16:00:20 +02:00
Stefan Hajnoczi
2c8cf1f16d Merge tag 'mips-20260707' of https://github.com/philmd/qemu into staging
MIPS and SuperH patches queue

- MIPS Octeon COP2 crypto opcodes
- Fix for SH4 FIPR/FTRV vector math opcodes

# -----BEGIN PGP SIGNATURE-----
#
# iQIzBAABCAAdFiEE+qvnXhKRciHc/Wuy4+MsLN6twN4FAmpNQigACgkQ4+MsLN6t
# wN5BHA//R59P7ivsi6dET3DDD6KgF5RLXRxa6uEqbFABUc0faXrSyDhBfoL4Bym5
# FTeFdNfOWgq+c5Rj9xSf51nmPCXyhxBFnXRhrGiAwyE0sLUZ5pli2uhQ81AaBpHT
# ZtSjNt2pHTr+tIShtDOpaGNFcPyg2w1xGfTUKdlIUAmm7ibjx1qMr5ZKwnMKSMEO
# 35SsFkPQaD2b8kInQeefnvs9Qgn50hQxYuY96EJzbNj4GL2pZe+LtKW1tmRDihhY
# kMu4EXeXBsew0zPZ9EtGl6CTyE9kViOsH+aG5wxwtvSfTv40lSgLPbPyVJz2cVcN
# wg+lzWs7e7+SFLCCnGJiM0PRdaD38KTpGdS7GRrRkgF/FjmpDGXIbWkaavNU2nQ9
# RZ5UAh+6J5LVdUleeBvJg/e5L2LNnpdFbc5YtdN3gAYoNezaUAapUgBKlbGqQ9x/
# MOS+XidI4uA9jtSv91IL2480vDdtDr2u9/K/lEq2ZFCAYRTHkFbnGOKpq0pzPu0l
# voev2Xx4R+PNG7VadCJPkDIDUGVIhcjEHNr1ZuCa5SIQyDdgy5Bzh5WyCtgFtTyh
# MEVyMkdUS9V94z+1A6XM7zK3r6xLdkn5RcIXhWmbgCHda2a5XlyqqgdP/ZQQzy7l
# LyZH0Ji6XShbcwUDQXvRuvuzEfD05CAzFrUjSYrYhQsUWsV5FfM=
# =WfqR
# -----END PGP SIGNATURE-----
# gpg: Signature made Tue 07 Jul 2026 20:15:04 CEST
# gpg:                using RSA key FAABE75E12917221DCFD6BB2E3E32C2CDEADC0DE
# gpg: Good signature from "Philippe Mathieu-Daudé (F4BUG) <f4bug@amsat.org>" [full]
# Primary key fingerprint: FAAB E75E 1291 7221 DCFD  6BB2 E3E3 2C2C DEAD C0DE

* tag 'mips-20260707' of https://github.com/philmd/qemu: (23 commits)
  qemu-options: Do not list -enable-kvm on MIPS binaries
  target/sh4: fixup tcg for sh4 fipr/ftrv instructions
  tests/tcg/mips: cover Octeon QMAC instructions
  target/mips: add Octeon CvmCount RDHWR support
  target/mips: decode Octeon CHORD and LLM COP2 selectors
  target/mips: decode Octeon block-cipher COP2 selectors
  target/mips: decode Octeon ZUC and SNOW3G COP2 selectors
  target/mips: decode Octeon HSH and SHA3 COP2 selectors
  target/mips: decode Octeon CRC and GFM COP2 selectors
  target/mips: decode Octeon COP2 register selectors
  target/mips: add Octeon CHORD and LLM COP2 helpers
  target/mips: add Octeon HSH COP2 helpers
  target/mips: add Octeon Camellia COP2 helpers
  target/mips: add Octeon 3DES and KASUMI COP2 helpers
  target/mips: add Octeon SMS4 COP2 helpers
  target/mips: add Octeon AES COP2 helpers
  target/mips: add Octeon SNOW3G COP2 helpers
  target/mips: add Octeon ZUC COP2 helpers
  target/mips: add Octeon SHA3 COP2 helpers
  target/mips: add Octeon GFM COP2 helpers
  ...

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2026-07-08 15:59:51 +02:00
Peter Maydell
a47e3c26b1 linux-user: Validate guest-passed dm_ioctl data_size
In do_ioctl_dm() we work with a struct dm_ioctl from the guest.  This
has a fixed initial part, and then a variable data part; the guest
tells us how long that part is by setting the data_size field.  The
data_size is supposed to include the length of the fixed parts of the
struct dm_ioctl.  Currently we don't validate anything about the
guest-provided data_size, and we use it to allocate a buffer which we
then copy the fixed part of the dm_ioctl struct into.  This means
that if the guest passes a very small data_size the copy of the fixed
part will overrun the buffer.

Perform the same sanitizing of the minimum and maximum limits of the
data_size that the kernel does in drivers/md/dm-ioctl.c in the
copy_params() function.

Cc: qemu-stable@nongnu.org
Fixes: 56e904ecb2 ("linux-user: implement device mapper ioctls")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3736
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Helge Deller <deller@gmx.de>
Signed-off-by: Helge Deller <deller@gmx.de>
2026-07-07 23:49:35 +02:00
Mark Cave-Ayland
9e3508dce0 Update OpenBIOS images to e5ac46dd built from submodule.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
2026-07-07 22:07:16 +01:00
Richard Henderson
c56ebd64b8 tcg/loongarch64: Fix cmp_vec with TCG_COND_NE
For NE we need to invert EQ, not swap operands.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3589
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20260623140609.645445-1-richard.henderson@linaro.org>
2026-07-07 11:16:05 -07:00
Philippe Mathieu-Daudé
f086625548 qemu-options: Do not list -enable-kvm on MIPS binaries
When removing KVM support in commit 630decdfcc we forgot
to remove MIPS of the '-enable-kvm' option help. Do it now.

Fixes: 630decdfcc ("buildsys: Remove MIPS KVM")
Inspired-by: Miao Wang <shankerwangmiao@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20260707095723.36591-1-philmd@oss.qualcomm.com>
2026-07-07 20:14:51 +02:00
Randy Schifflin
614a52cf54 target/sh4: fixup tcg for sh4 fipr/ftrv instructions
Fixes TCG generation for sh4 `fipr` and `ftrv` instructions.
Updates the current logic for these instructions to check the
FPSCR register appropriately (according to the sh4 cpu manual, `fipr`
and `ftrv` are only defined when the FPSCR register PR flag is 0).
Also fixes the mth/nth-vector operands by multiplying by 4 to convert
to the correct floating point register offset.

Signed-off-by: Randy Schifflin <randy.schifflin@gmail.com>
Reviewed-by: Yoshinori Sato <yoshinori.sato@nifty.com>
Message-ID: <20260629-fixup-sh4-tcg-fpu-instructions-b4-v1-2-4356b305f971@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
2026-07-07 20:14:51 +02:00
James Hilliard
b6726871b9 tests/tcg/mips: cover Octeon QMAC instructions
Add smoke coverage for Octeon QMAC and QMACS fixed-point accumulator
instruction paths.

The coverage exercises normal accumulation, saturating accumulation, and
the sticky saturation flag.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20260608-mips-octeon-missing-insns-v2-v16-21-daef7a0d8b04@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
2026-07-07 20:14:51 +02:00
James Hilliard
c2fd17ec64 target/mips: add Octeon CvmCount RDHWR support
Octeon exposes CvmCount through RDHWR register 31. Add the Octeon-only
decode path, enable the corresponding HWREna bit for linux-user, and use
an unsigned mask when checking HWREna so bit 31 is handled safely.

For user-mode emulation, return host ticks as a monotonic counter source
suitable for existing Octeon userspace code. In system mode, fall back to
the existing CP0 Count value.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Message-ID: <20260608-mips-octeon-missing-insns-v2-v16-20-daef7a0d8b04@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
2026-07-07 20:14:46 +02:00
James Hilliard
8d399e3e03 target/mips: decode Octeon CHORD and LLM COP2 selectors
Add explicit decodetree entries and translator bindings for the Octeon
CHORD and sparse LLM COP2 selectors.  CHORD and LLM use their own COP2
selector window rather than the crypto engine windows covered by the
preceding decode patches.

This completes the explicit COP2 selector coverage by adding the
remaining CHORD and LLM register and operation selectors.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Acked-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20260608-mips-octeon-missing-insns-v2-v16-19-daef7a0d8b04@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
2026-07-07 20:14:46 +02:00