Defer the IOMMU translation and support access_type
v2 cover Defer the IOMMU translation and support access_type
Note: v1 title is "accel/tcg: Pass the access_type to IOMMUMemoryRegion"
Incoming security protection devices feature more complex IOMMUMemoryRegion implementation in the CPU path than ARM MPC device. For example, RISC-V wgChecker [1] may permit the access with only RO/WO permissions. Consequently, the IOMMUMemoryRegion could return different sections for read & write access.
To support such IOMMUMemoryRegion behavior in the CPU path, the design of IOMMU translation must be updated:
1. address_space_translate*() must now pass the access_type to IOMMUMemoryRegion.
2. Since IOMMU translation results are too complex to be fully stored in the CPU TLB. we will defer the translation until the actual access occurs. Also, TLB is allowed to store the untranslated IOMMU region.
To implement deferred IOMMU translation, this patchset introduces the following changes:
1. tlb_set_page_full() no longer translates the IOMMU region immediately. Instead, it stores the untranslated region directly in the TLB. A new slow-path flag, TLB_IOMMU, is introduced to force access into the slow path when a region has not yet been translated in the TLB entry.
2. When the CPU utilizes a TLB entry in the slow path, it should perform the lazy IOMMU translation of the access_type first. The resulting translated region and access type are stored in CPUTLBEntryFull. Since the slow path always performs lazy translation first, we can switch the CPUTLBEntryFull content to the correct access type before use.
3. To accelerate memory access in the fast path, lazy translation can update the addend of the CPUTLBEntry when translating the region to a host memory region. We restrict the IOMMU region to have a single non-zero 'addend' across all permissions. If a second 'addend' is present for a CPUTLBEntry, QEMU will trigger an assertion. This limitation is sufficient for security devices, as their "secondary" region is typically an IO region used to emulate device error handling when access is rejected.
4. To support non-slow TLB flags, lazy translation can update the TLB flags in the 'addr_idx' of the CPUTLBEntry. Lazy translation only updates the flags for the permissions specified in @prot. This ensures that each access_type of a translated region to maintains independent TLB flags. For example, TLB_DIRTY of memory region will not be "polluted" from other permission that translated to different region.
Both RISC-V wgChecker [1] and RISC-V IOPMP [2] devices require this feature.
[1] RISC-V WG:
https://patchew.org/QEMU/[email protected]/
[2] RISC-V IOPMP:
https://patchew.org/QEMU/[email protected]/
Changed since v1:
- Remove the ping-pong TLB entry behavior. Instead, defer the IOMMU translation until actual access in the CPU path. Provide a IOMMU lazy translation function with the special handling of 'addend' and 'addr_idx' fields of CPUTLBEntry.
- Fix the checkpatch warning.
Jim Shu (5):
accel/tcg: Pass access_type as an argument of tlb_set_page*() accel/tcg: address_space_translate*() will pass the correct
iommu_flags
accel/tcg: Provide early AS translate function accel/tcg: Add IOMMU lazy translation function accel/tcg: Support IOMMU lazy translation in CPU TLB
accel/tcg/cputlb.c | 247 +++++++++++++++++++++++++-- include/accel/tcg/iommu.h | 17 +- include/exec/cputlb.h | 11 +- include/exec/tlb-flags.h | 4 +- include/hw/core/cpu.h | 15 ++ system/physmem.c | 60 ++++++- target/alpha/helper.c | 2 +- target/avr/helper.c | 3 +- target/hppa/mem_helper.c | 1 - target/i386/tcg/system/excp_helper.c | 3 +- target/loongarch/tcg/tlb_helper.c | 2 +- target/m68k/helper.c | 10 +- target/microblaze/helper.c | 8 +- target/mips/tcg/system/tlb_helper.c | 4 +- target/or1k/mmu.c | 2 +- target/ppc/mmu_helper.c | 2 +- target/riscv/cpu_helper.c | 2 +- target/rx/cpu.c | 3 +- target/s390x/tcg/excp_helper.c | 2 +- target/sh4/helper.c | 3 +- target/sparc/mmu_helper.c | 6 +- target/tricore/helper.c | 2 +- target/xtensa/helper.c | 3 +- 23 files changed, 354 insertions(+), 58 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/5 accel/tcg: Pass access_type as an argument of tlb_set_page*()
Pass the access_type so that we could know CPU will do the read or write access. Then, CPU can fill the CPUTLBEntry[Full] of the specific permission (@prot).
It is fine for address_space_translate*() to return different section of read and write access. tlb_set_page*() only sets 'CPUTLBEntry.addr_*' for specific @prot, so access from another @prot will only get TLB miss and start to overwrite 'CPUTLBEntry[Full]' with new @prot.
It is the preliminary patch of next commit to pass the iommu_flags to IOMMUMemoryRegion from access_type.
--- accel/tcg/cputlb.c | 14 ++++++++------ include/exec/cputlb.h | 11 +++++++---- target/alpha/helper.c | 2 +- target/avr/helper.c | 3 ++- target/hppa/mem_helper.c | 1 - target/i386/tcg/system/excp_helper.c | 3 ++- target/loongarch/tcg/tlb_helper.c | 2 +- target/m68k/helper.c | 10 +++++++--- target/microblaze/helper.c | 8 ++++---- target/mips/tcg/system/tlb_helper.c | 4 ++-- target/or1k/mmu.c | 2 +- target/ppc/mmu_helper.c | 2 +- target/riscv/cpu_helper.c | 2 +- target/rx/cpu.c | 3 ++- target/s390x/tcg/excp_helper.c | 2 +- target/sh4/helper.c | 3 ++- target/sparc/mmu_helper.c | 6 +++--- target/tricore/helper.c | 2 +- target/xtensa/helper.c | 3 ++- 19 files changed, 48 insertions(+), 35 deletions(-)
accel/tcg/cputlb.c +8 -6
@@ -1022,7 +1022,8 @@ static inline void tlb_set_compare(CPUTLBEntryFull *full, CPUTLBEntry *ent,* critical section. */ void tlb_set_page_full (CPUState *cpu,int mmu_idx, -vaddr addr,CPUTLBEntryFull *full) +vaddr addr,MMUAccessType access_type, +CPUTLBEntryFull *full) {CPUTLB *tlb = &cpu->neg.tlb;CPUTLBDesc *desc = &tlb->d[mmu_idx];
@@ -1185,7 +1186,8 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx,void tlb_set_page_with_attrs (CPUState *cpu,vaddr addr,hwaddr paddr,MemTxAttrs attrs,int prot, -int mmu_idx,vaddr size) +MMUAccessType access_type,int mmu_idx, +vaddr size) {CPUTLBEntryFull full = { .phys_addr = paddr,
@@ -1195,15 +1197,15 @@ void tlb_set_page_with_attrs(CPUState *cpu, vaddr addr, };assert (is_power_of_2 (size)); -tlb_set_page_full (cpu, mmu_idx, addr, &full); +tlb_set_page_full (cpu, mmu_idx, addr, access_type, &full); }void tlb_set_page (CPUState *cpu,vaddr addr, -hwaddr paddr,int prot, +hwaddr paddr,int prot,MMUAccessType access_type,int mmu_idx,vaddr size) {tlb_set_page_with_attrs (cpu, addr, paddr,MEMTXATTRS_UNSPECIFIED , - prot, mmu_idx, size); + prot, access_type, mmu_idx, size); }/**
@@ -1245,7 +1247,7 @@ static bool tlb_fill_align(CPUState *cpu, vaddr addr, MMUAccessType type,if (ops->tlb_fill_align) {if (ops->tlb_fill_align (cpu, &full, addr, type, mmu_idx, memop, size, probe, ra)) { -tlb_set_page_full (cpu, mmu_idx, addr, &full); +tlb_set_page_full (cpu, mmu_idx, addr, type, &full);return true; } }else {
include/exec/cputlb.h +7 -4
@@ -41,6 +41,7 @@ void tlb_reset_dirty_range_all(ram_addr_t start, ram_addr_t length);* @cpu: CPU context * @mmu_idx: mmu index of the tlb to modify * @addr: virtual address of the entry to add +* @access_type: access was read/write/execute * @full: the details of the tlb entry * * Add an entry to @cpu tlb index @mmu_idx. All of the fields of
@@ -56,6 +57,7 @@ void tlb_reset_dirty_range_all(ram_addr_t start, ram_addr_t length);* used by tlb_flush_page. */ void tlb_set_page_full (CPUState *cpu,int mmu_idx,vaddr addr, +MMUAccessType access_type,CPUTLBEntryFull *full);/**
@@ -65,6 +67,7 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx, vaddr addr,* @paddr: physical address of the page * @attrs: memory transaction attributes * @prot: access permissions (PAGE_READ/PAGE_WRITE/PAGE_EXEC bits) +* @access_type: access was read/write/execute * @mmu_idx: MMU index to insert TLB entry for * @size: size of the page in bytes *
@@ -81,9 +84,9 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx, vaddr addr,* used by tlb_flush_page. */ void tlb_set_page_with_attrs (CPUState *cpu,vaddr addr, -hwaddr paddr,MemTxAttrs attrs, -int prot,int mmu_idx,vaddr size); - +hwaddr paddr,MemTxAttrs attrs,int prot, +MMUAccessType access_type,int mmu_idx, +vaddr size);/** * tlb_set_page: *
@@ -92,7 +95,7 @@ void tlb_set_page_with_attrs(CPUState *cpu, vaddr addr,* as a convenience for CPUs which don't use memory transaction attributes. */ void tlb_set_page (CPUState *cpu,vaddr addr, -hwaddr paddr,int prot, +hwaddr paddr,int prot,MMUAccessType access_type,int mmu_idx,vaddr size);#if defined(CONFIG_TCG ) && !defined(CONFIG_USER_ONLY )
target/alpha/helper.c +1 -1
@@ -328,7 +328,7 @@ bool alpha_cpu_tlb_fill(CPUState *cs, vaddr addr, int size, }tlb_set_page (cs, addr &TARGET_PAGE_MASK , phys &TARGET_PAGE_MASK , - prot, mmu_idx,TARGET_PAGE_SIZE ); + prot, access_type, mmu_idx,TARGET_PAGE_SIZE );return true; }
target/avr/helper.c +2 -1
@@ -143,7 +143,8 @@ bool avr_cpu_tlb_fill(CPUState *cs, vaddr address, int size, prot =PAGE_READ |PAGE_WRITE ; } -tlb_set_page (cs, address, paddr, prot, mmu_idx,TARGET_PAGE_SIZE ); +tlb_set_page (cs, address, paddr, prot, access_type, mmu_idx, +TARGET_PAGE_SIZE );return true; }
target/hppa/mem_helper.c +0 -1
@@ -482,7 +482,6 @@ bool hppa_cpu_tlb_fill_align(CPUState *cs, CPUTLBEntryFull *out, vaddr addr, out->prot = prot; out->attrs =MEMTXATTRS_UNSPECIFIED ; out->lg_page_size =TARGET_PAGE_BITS ; -return true; }
target/i386/tcg/system/excp_helper.c +2 -1
@@ -628,7 +628,8 @@ bool x86_cpu_tlb_fill(CPUState *cs, vaddr addr, int size,tlb_set_page_with_attrs (cs, addr &TARGET_PAGE_MASK , out.paddr &TARGET_PAGE_MASK ,cpu_get_mem_attrs (env), - out.prot, mmu_idx, out.page_size); + out.prot, access_type, mmu_idx, + out.page_size);return true; }
target/loongarch/tcg/tlb_helper.c +1 -1
@@ -669,7 +669,7 @@ bool loongarch_cpu_tlb_fill(CPUState *cs, vaddr address, int size, prot = context.prot;tlb_set_page (cs, address &TARGET_PAGE_MASK , physical &TARGET_PAGE_MASK , prot, - mmu_idx,TARGET_PAGE_SIZE ); + access_type, mmu_idx,TARGET_PAGE_SIZE );qemu_log_mask (CPU_LOG_MMU ,"%s address=%" VADDR_PRIx" physical " HWADDR_FMT_plx" prot %d\n" , __func__, address, physical, prot);
target/m68k/helper.c +7 -3
@@ -969,7 +969,7 @@ bool m68k_cpu_tlb_fill(CPUState *cs, vaddr address, int size,tlb_set_page (cs, address &TARGET_PAGE_MASK , address &TARGET_PAGE_MASK ,PAGE_READ |PAGE_WRITE |PAGE_EXEC , - mmu_idx,TARGET_PAGE_SIZE ); + qemu_access_type, mmu_idx,TARGET_PAGE_SIZE );return true; }
@@ -989,7 +989,8 @@ bool m68k_cpu_tlb_fill(CPUState *cs, vaddr address, int size, address, access_type, &page_size);if (likely (ret ==0 )) {tlb_set_page (cs, address &TARGET_PAGE_MASK , - physical &TARGET_PAGE_MASK , prot, mmu_idx, page_size); + physical &TARGET_PAGE_MASK , prot, qemu_access_type, + mmu_idx, page_size);return true; }
@@ -1461,6 +1462,7 @@ void HELPER(ptest)(CPUM68KState *env, uint32_t addr, uint32_t is_read)int prot;int ret;target_ulong page_size; +MMUAccessType qemu_access_type; access_type =ACCESS_PTEST ;if (env->dfc &4 ) {
@@ -1468,9 +1470,11 @@ void HELPER(ptest)(CPUM68KState *env, uint32_t addr, uint32_t is_read) }if ((env->dfc &3 ) ==2 ) { access_type |=ACCESS_CODE ; + qemu_access_type =MMU_INST_FETCH ; }if (!is_read) { access_type |=ACCESS_STORE ; + qemu_access_type =MMU_DATA_STORE ; } env->mmu.mmusr =0 ;
@@ -1480,7 +1484,7 @@ void HELPER(ptest)(CPUM68KState *env, uint32_t addr, uint32_t is_read)if (ret ==0 ) {tlb_set_page (env_cpu (env), addr &TARGET_PAGE_MASK , physical &TARGET_PAGE_MASK , - prot, access_type &ACCESS_SUPER ? + prot, qemu_access_type, access_type &ACCESS_SUPER ?MMU_KERNEL_IDX :MMU_USER_IDX , page_size); } }
target/microblaze/helper.c +4 -4
@@ -101,8 +101,8 @@ bool mb_cpu_tlb_fill(CPUState *cs, vaddr address, int size,/* MMU disabled or not available. */ address &=TARGET_PAGE_MASK ; prot =PAGE_RWX ; -tlb_set_page_with_attrs (cs, address, address, attrs, prot, mmu_idx, -TARGET_PAGE_SIZE ); +tlb_set_page_with_attrs (cs, address, address, attrs, prot, access_type, + mmu_idx,TARGET_PAGE_SIZE );return true; }
@@ -113,8 +113,8 @@ bool mb_cpu_tlb_fill(CPUState *cs, vaddr address, int size,qemu_log_mask (CPU_LOG_MMU ,"MMU map mmu=%d v=%x p=%x prot=%x\n" , mmu_idx, vaddr, paddr, lu.prot); -tlb_set_page_with_attrs (cs, vaddr, paddr, attrs, lu.prot, mmu_idx, -TARGET_PAGE_SIZE ); +tlb_set_page_with_attrs (cs, vaddr, paddr, attrs, lu.prot, access_type, + mmu_idx,TARGET_PAGE_SIZE );return true; }
target/mips/tcg/system/tlb_helper.c +2 -2
@@ -934,7 +934,7 @@ bool mips_cpu_tlb_fill(CPUState *cs, vaddr address, int size,if (ret ==TLBRET_MATCH ) {tlb_set_page (cs, address &TARGET_PAGE_MASK , physical &TARGET_PAGE_MASK , prot, - mmu_idx,TARGET_PAGE_SIZE ); + access_type, mmu_idx,TARGET_PAGE_SIZE );return true; }#if !defined(TARGET_MIPS64 )
@@ -952,7 +952,7 @@ bool mips_cpu_tlb_fill(CPUState *cs, vaddr address, int size,if (ret ==TLBRET_MATCH ) {tlb_set_page (cs, address &TARGET_PAGE_MASK , physical &TARGET_PAGE_MASK , prot, - mmu_idx,TARGET_PAGE_SIZE ); + access_type, mmu_idx,TARGET_PAGE_SIZE );return true; } }
target/or1k/mmu.c +1 -1
@@ -127,7 +127,7 @@ bool openrisc_cpu_tlb_fill(CPUState *cs, vaddr addr, int size,if (likely (excp ==0 )) {tlb_set_page (cs, addr &TARGET_PAGE_MASK , phys_addr &TARGET_PAGE_MASK , prot, - mmu_idx,TARGET_PAGE_SIZE ); + access_type, mmu_idx,TARGET_PAGE_SIZE );return true; }if (probe) {
target/ppc/mmu_helper.c +1 -1
@@ -1369,7 +1369,7 @@ bool ppc_cpu_tlb_fill(CPUState *cs, vaddr eaddr, int size,if (ppc_xlate (cpu, eaddr, access_type, &raddr, &page_size, &prot, mmu_idx, !probe)) {tlb_set_page (cs, eaddr &TARGET_PAGE_MASK , raddr &TARGET_PAGE_MASK , - prot, mmu_idx,1UL << page_size); + prot, access_type, mmu_idx,1UL << page_size);return true; }if (probe) {
target/riscv/cpu_helper.c +1 -1
@@ -1874,7 +1874,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,if (ret ==TRANSLATE_SUCCESS ) {tlb_set_page (cs, address & ~(tlb_size -1 ), pa & ~(tlb_size -1 ), - prot, mmu_idx, tlb_size); + prot, access_type, mmu_idx, tlb_size);return true; }else if (probe) {return false;
target/rx/cpu.c +2 -1
@@ -194,7 +194,8 @@ static bool rx_cpu_tlb_fill(CPUState *cs, vaddr addr, int size,/* Linear mapping */ address = physical = addr &TARGET_PAGE_MASK ; prot =PAGE_READ |PAGE_WRITE |PAGE_EXEC ; -tlb_set_page (cs, address, physical, prot, mmu_idx,TARGET_PAGE_SIZE ); +tlb_set_page (cs, address, physical, prot, access_type, + mmu_idx,TARGET_PAGE_SIZE );return true; }
target/s390x/tcg/excp_helper.c +1 -1
@@ -182,7 +182,7 @@ bool s390_cpu_tlb_fill(CPUState *cs, vaddr address, int size,"%s: set tlb %" PRIx64" -> %" PRIx64" (%x)\n" , __func__, (uint64_t)vaddr, (uint64_t)raddr, prot);tlb_set_page (cs, address &TARGET_PAGE_MASK , raddr, prot, - mmu_idx,TARGET_PAGE_SIZE ); + access_type, mmu_idx,TARGET_PAGE_SIZE );return true; }if (probe) {
target/sh4/helper.c +2 -1
@@ -812,7 +812,8 @@ bool superh_cpu_tlb_fill(CPUState *cs, vaddr address, int size,if (ret ==MMU_OK ) { address &=TARGET_PAGE_MASK ; physical &=TARGET_PAGE_MASK ; -tlb_set_page (cs, address, physical, prot, mmu_idx,TARGET_PAGE_SIZE ); +tlb_set_page (cs, address, physical, prot, access_type, mmu_idx, +TARGET_PAGE_SIZE );return true; }if (probe) {
target/sparc/mmu_helper.c +3 -3
@@ -236,7 +236,7 @@ bool sparc_cpu_tlb_fill(CPUState *cs, vaddr address, int size,"Translate at %" VADDR_PRIx" -> " HWADDR_FMT_plx", vaddr " TARGET_FMT_lx"\n" , address, full.phys_addr, vaddr); -tlb_set_page_full (cs, mmu_idx, vaddr, &full); +tlb_set_page_full (cs, mmu_idx, vaddr, access_type, &full);return true; }
@@ -252,7 +252,7 @@ bool sparc_cpu_tlb_fill(CPUState *cs, vaddr address, int size,neverland. Fake/overridden mappings will be flushed when switching to normal mode. */ full.prot =PAGE_READ |PAGE_WRITE |PAGE_EXEC ; -tlb_set_page_full (cs, mmu_idx, vaddr, &full); +tlb_set_page_full (cs, mmu_idx, vaddr, access_type, &full);return true; }else {if (access_type ==MMU_INST_FETCH ) {
@@ -777,7 +777,7 @@ bool sparc_cpu_tlb_fill(CPUState *cs, vaddr address, int size,trace_mmu_helper_mmu_fault (address, full.phys_addr, mmu_idx, env->tl, env->dmmu.mmu_primary_context, env->dmmu.mmu_secondary_context); -tlb_set_page_full (cs, mmu_idx, address, &full); +tlb_set_page_full (cs, mmu_idx, address, access_type, &full);return true; }if (probe) {
target/tricore/helper.c +1 -1
@@ -86,7 +86,7 @@ bool tricore_cpu_tlb_fill(CPUState *cs, vaddr address, int size,if (ret ==TLBRET_MATCH ) {tlb_set_page (cs, address &TARGET_PAGE_MASK , physical &TARGET_PAGE_MASK , prot |PAGE_EXEC , - mmu_idx,TARGET_PAGE_SIZE ); + rw, mmu_idx,TARGET_PAGE_SIZE );return true; }else {assert (ret <0 );
target/xtensa/helper.c +2 -1
@@ -282,7 +282,8 @@ bool xtensa_cpu_tlb_fill(CPUState *cs, vaddr address, int size,tlb_set_page (cs, address &TARGET_PAGE_MASK , paddr &TARGET_PAGE_MASK , - access, mmu_idx, page_size); + access, access_type, mmu_idx, + page_size);return true; }else if (probe) {return false;
Signature · 1 line
2.43.0
Re: [PATCH v2 1/5] accel/tcg: Pass access_type as an argument of tlb_set_page*()
Quoted 35 lines · Jim Shu
Pass the
access_typeso that we could know CPU will do the read or write access. Then, CPU can fill the CPUTLBEntry[Full] of the specific permission (@prot).It is fine for address_space_translate*() to return different section of read and write access. tlb_set_page*() only sets 'CPUTLBEntry.addr_*' for specific @prot, so access from another @prot will only get TLB miss and start to overwrite 'CPUTLBEntry[Full]' with new @prot.
It is the preliminary patch of next commit to pass the
iommu_flagsto IOMMUMemoryRegion fromaccess_type.Signed-off-by Jim Shu <[email protected]>--- accel/tcg/cputlb.c | 14 ++++++++------ include/exec/cputlb.h | 11 +++++++---- target/alpha/helper.c | 2 +- target/avr/helper.c | 3 ++- target/hppa/mem_helper.c | 1 - target/i386/tcg/system/excp_helper.c | 3 ++- target/loongarch/tcg/tlb_helper.c | 2 +- target/m68k/helper.c | 10 +++++++--- target/microblaze/helper.c | 8 ++++---- target/mips/tcg/system/tlb_helper.c | 4 ++-- target/or1k/mmu.c | 2 +- target/ppc/mmu_helper.c | 2 +- target/riscv/cpu_helper.c | 2 +- target/rx/cpu.c | 3 ++- target/s390x/tcg/excp_helper.c | 2 +- target/sh4/helper.c | 3 ++- target/sparc/mmu_helper.c | 6 +++--- target/tricore/helper.c | 2 +- target/xtensa/helper.c | 3 ++- 19 files changed, 48 insertions(+), 35 deletions(-)
[...]
target/hppa/mem_helper.c bool hppa_cpu_tlb_fill_align(CPUState *cs, CPUTLBEntryFull *out, vaddr addr, · line 486
Quoted 11 lines
target/hppa/mem_helper.c +0
-1@@ -482,7 +482,6 @@ bool hppa_cpu_tlb_fill_align(CPUState *cs, CPUTLBEntryFull *out, vaddr addr, out->prot = prot; out->attrs =MEMTXATTRS_UNSPECIFIED ; out->lg_page_size =TARGET_PAGE_BITS ; -return true; }
This whitespace change looks unnecessary.
target/hppa/mem_helper.c void HELPER(ptest)(CPUM68KState *env, uint32_t addr, uint32_t is_read) · line 1465
Quoted 5 lines
target/hppa/mem_helper.c +1
-0@@ -1461,6 +1462,7 @@ void HELPER(ptest)(CPUM68KState *env, uint32_t addr, uint32_t is_read)int prot;int ret;target_ulong page_size; +MMUAccessType qemu_access_type;
Do we need to assign MMU_DATA_LOAD as a default here?
Quoted 15 lines
target/hppa/mem_helper.c +2
-0access_type =ACCESS_PTEST ;if (env->dfc &4 ) {@@ -1468,9 +1470,11 @@ void HELPER(ptest)(CPUM68KState *env, uint32_t addr, uint32_t is_read) }if ((env->dfc &3 ) ==2 ) { access_type |=ACCESS_CODE ; + qemu_access_type =MMU_INST_FETCH ; }if (!is_read) { access_type |=ACCESS_STORE ; + qemu_access_type =MMU_DATA_STORE ; } env->mmu.mmusr =0 ;
target/hppa/mem_helper.c void HELPER(ptest)(CPUM68KState *env, uint32_t addr, uint32_t is_read) · line 1490
Quoted 8 lines
target/hppa/mem_helper.c +1
-1@@ -1480,7 +1484,7 @@ void HELPER(ptest)(CPUM68KState *env, uint32_t addr, uint32_t is_read)if (ret ==0 ) {tlb_set_page (env_cpu (env), addr &TARGET_PAGE_MASK , physical &TARGET_PAGE_MASK , - prot, access_type &ACCESS_SUPER ? + prot, qemu_access_type, access_type &ACCESS_SUPER ?MMU_KERNEL_IDX :MMU_USER_IDX , page_size); } }
Otherwise it may be used uninitialized here.
Re: [PATCH v2 1/5] accel/tcg: Pass access_type as an argument of tlb_set_page*()
Quoted 41 lines · Ilya Leoshkevich
Quoted 35 lines · Jim Shu
Pass the
access_typeso that we could know CPU will do the read or write access. Then, CPU can fill the CPUTLBEntry[Full] of the specific permission (@prot).It is fine for address_space_translate*() to return different section of read and write access. tlb_set_page*() only sets 'CPUTLBEntry.addr_*' for specific @prot, so access from another @prot will only get TLB miss and start to overwrite 'CPUTLBEntry[Full]' with new @prot.
It is the preliminary patch of next commit to pass the
iommu_flagsto IOMMUMemoryRegion fromaccess_type.Signed-off-by Jim Shu <[email protected]>--- accel/tcg/cputlb.c | 14 ++++++++------ include/exec/cputlb.h | 11 +++++++---- target/alpha/helper.c | 2 +- target/avr/helper.c | 3 ++- target/hppa/mem_helper.c | 1 - target/i386/tcg/system/excp_helper.c | 3 ++- target/loongarch/tcg/tlb_helper.c | 2 +- target/m68k/helper.c | 10 +++++++--- target/microblaze/helper.c | 8 ++++---- target/mips/tcg/system/tlb_helper.c | 4 ++-- target/or1k/mmu.c | 2 +- target/ppc/mmu_helper.c | 2 +- target/riscv/cpu_helper.c | 2 +- target/rx/cpu.c | 3 ++- target/s390x/tcg/excp_helper.c | 2 +- target/sh4/helper.c | 3 ++- target/sparc/mmu_helper.c | 6 +++--- target/tricore/helper.c | 2 +- target/xtensa/helper.c | 3 ++- 19 files changed, 48 insertions(+), 35 deletions(-)[...]
Quoted 13 lines
target/hppa/mem_helper.c bool hppa_cpu_tlb_fill_align(CPUState *cs, CPUTLBEntryFull *out, vaddr addr, · line 486
Quoted 11 lines
target/hppa/mem_helper.c +0
-1@@ -482,7 +482,6 @@ bool hppa_cpu_tlb_fill_align(CPUState *cs, CPUTLBEntryFull *out, vaddr addr, out->prot = prot; out->attrs =MEMTXATTRS_UNSPECIFIED ; out->lg_page_size =TARGET_PAGE_BITS ; -return true; }This whitespace change looks unnecessary.
I will remove it in the next series.
Quoted 8 lines
target/hppa/mem_helper.c void HELPER(ptest)(CPUM68KState *env, uint32_t addr, uint32_t is_read) · line 1465
Quoted 6 lines
target/hppa/mem_helper.c +1
-0@@ -1461,6 +1462,7 @@ void HELPER(ptest)(CPUM68KState *env, uint32_t addr, uint32_t is_read)int prot;int ret;target_ulong page_size; +MMUAccessType qemu_access_type;Do we need to assign
MMU_DATA_LOADas a default here?
Yes, LOAD should be the default value.
I will add it in the next series.
Quoted 14 lines
Quoted 14 lines
target/hppa/mem_helper.c +2
-0access_type =ACCESS_PTEST ;if (env->dfc &4 ) {@@ -1468,9 +1470,11 @@ void HELPER(ptest)(CPUM68KState *env, uint32_t addr, uint32_t is_read) }if ((env->dfc &3 ) ==2 ) { access_type |=ACCESS_CODE ; + qemu_access_type =MMU_INST_FETCH ; }if (!is_read) { access_type |=ACCESS_STORE ; + qemu_access_type =MMU_DATA_STORE ; }
Quoted 11 lines
target/hppa/mem_helper.c void HELPER(ptest)(CPUM68KState *env, uint32_t addr, uint32_t is_read) · line 1490
Quoted 10 lines
target/hppa/mem_helper.c +1
-1env->mmu.mmusr =0 ;@@ -1480,7 +1484,7 @@ void HELPER(ptest)(CPUM68KState *env, uint32_t addr, uint32_t is_read)if (ret ==0 ) {tlb_set_page (env_cpu (env), addr &TARGET_PAGE_MASK , physical &TARGET_PAGE_MASK , - prot, access_type &ACCESS_SUPER ? + prot, qemu_access_type, access_type &ACCESS_SUPER ?MMU_KERNEL_IDX :MMU_USER_IDX , page_size); } }Otherwise it may be used uninitialized here.
Have fixed them in v3 branches:
https://github.com/cwshu/qemu/tree/iotlb-add-type-v3-alpha
Next series will contain these fixes.
Regards,
Jim
PATCH v2 2/5 accel/tcg: address_space_translate*() will pass the correct iommu_flags
In reply to Jim ShuInstead of IOMMU_NONE, address_space_translate_for_iotlb() now can pass the correct iommu_flags to the IOMMU translate function from the access_type.
Since RISC-V wgChecker [1] could permit access in RO or WO permission only, the IOMMUMemoryRegion could return different section for read and write access. To support this kind of IOMMUMemoryRegion in the path of CPU access, we should pass correct iommu_flags here.
[1] RISC-V WG:
https://patchew.org/QEMU/[email protected]/
--- accel/tcg/cputlb.c | 3 ++- include/accel/tcg/iommu.h | 12 +++++------- system/physmem.c | 16 +++++++++++----- 3 files changed, 18 insertions(+), 13 deletions(-)
accel/tcg/cputlb.c +2 -1
@@ -1050,7 +1050,8 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx, prot = full->prot; asidx =cpu_asidx_from_attrs (cpu, full->attrs); section =address_space_translate_for_iotlb (cpu, asidx, paddr_page, - &xlat, &sz, full->attrs, &prot); + &xlat, &sz, full->attrs, &prot, + access_type);assert (sz >=TARGET_PAGE_SIZE ); tlb_debug("vaddr=%016" VADDR_PRIx " paddr=0x" HWADDR_FMT_plx
include/accel/tcg/iommu.h +5 -7
@@ -14,13 +14,11 @@#include "exec/hwaddr.h" #include "exec/memattrs.h" -MemoryRegionSection *address_space_translate_for_iotlb (CPUState *cpu, -int asidx, -hwaddr addr, -hwaddr *xlat, -hwaddr *plen, -MemTxAttrs attrs, -int *prot); +MemoryRegionSection * +address_space_translate_for_iotlb (CPUState *cpu,int asidx,hwaddr addr, +hwaddr *xlat,hwaddr *plen, +MemTxAttrs attrs,int *prot, +MMUAccessType access_type);#endif
system/physmem.c +11 -5
@@ -685,12 +685,14 @@ void tcg_iommu_init_notifier_list(CPUState *cpu)MemoryRegionSection *address_space_translate_for_iotlb (CPUState *cpu,int asidx,hwaddr orig_addr,hwaddr *xlat,hwaddr *plen, -MemTxAttrs attrs,int *prot) +MemTxAttrs attrs,int *prot, +MMUAccessType access_type) {MemoryRegionSection *section;IOMMUMemoryRegion *iommu_mr;IOMMUMemoryRegionClass *imrc;IOMMUTLBEntry iotlb; +IOMMUAccessFlags iommu_flags;int iommu_idx;hwaddr addr = orig_addr;AddressSpaceDispatch *d =address_space_to_dispatch (cpu->cpu_ases[asidx].as);
@@ -707,10 +709,14 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr orig_addr, iommu_idx = imrc->attrs_to_index (iommu_mr, attrs);tcg_register_iommu_notifier (cpu, iommu_mr, iommu_idx); -/* We need all the permissions, so pass IOMMU_NONE so the IOMMU -* doesn't short-cut its translation table walk. -*/ - iotlb = imrc->translate (iommu_mr, addr,IOMMU_NONE , iommu_idx); + +if (access_type ==MMU_DATA_STORE ) { + iommu_flags =IOMMU_WO ; + }else { + iommu_flags =IOMMU_RO ; + } + + iotlb = imrc->translate (iommu_mr, addr, iommu_flags, iommu_idx); addr = ((iotlb.translated_addr & ~iotlb.addr_mask) | (addr & iotlb.addr_mask));/* Update the caller's prot bits to remove permissions the IOMMU
Signature · 1 line
2.43.0
PATCH v2 3/5 accel/tcg: Provide early AS translate function
In reply to Jim ShuNew early AS translate function will skip IOMMU translation. It will return IOMMU region if finding it. Original function is renamed to the late translate function.
It is preparation commit of IOMMU lazy translation.
--- accel/tcg/cputlb.c | 6 ++--- include/accel/tcg/iommu.h | 13 +++++++---- system/physmem.c | 46 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 10 deletions(-)
accel/tcg/cputlb.c +3 -3
@@ -1049,9 +1049,9 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx, prot = full->prot; asidx =cpu_asidx_from_attrs (cpu, full->attrs); - section =address_space_translate_for_iotlb (cpu, asidx, paddr_page, - &xlat, &sz, full->attrs, &prot, - access_type); + section =address_space_translate_for_iotlb_late (cpu, asidx, paddr_page, + &xlat, &sz, full->attrs, + &prot);assert (sz >=TARGET_PAGE_SIZE ); tlb_debug("vaddr=%016" VADDR_PRIx " paddr=0x" HWADDR_FMT_plx
include/accel/tcg/iommu.h +9 -4
@@ -15,10 +15,15 @@#include "exec/memattrs.h" MemoryRegionSection * -address_space_translate_for_iotlb (CPUState *cpu,int asidx,hwaddr addr, -hwaddr *xlat,hwaddr *plen, -MemTxAttrs attrs,int *prot, -MMUAccessType access_type); +address_space_translate_for_iotlb_early (CPUState *cpu,int asidx,hwaddr addr, +hwaddr *xlat,hwaddr *plen, +MemTxAttrs attrs,int *prot); + +MemoryRegionSection * +address_space_translate_for_iotlb_late (CPUState *cpu,int asidx,hwaddr addr, +hwaddr *xlat,hwaddr *plen, +MemTxAttrs attrs,int *prot, +MMUAccessType access_type);#endif
system/physmem.c +43 -3
73 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 4/5 accel/tcg: Add IOMMU lazy translation function
In reply to Jim ShuThe lazy translation will translate IOMMU regions of the specific access_type and store the result into the CPUTLBEntryFull.
For CPUTLBEntry, lazy translation may update 'addend' and 'addr_idx' array. We restrict IOMMU region to have a single non-zero 'addend' across all permissions. Also, lazy translation only updates the 'addr_idx' for the permissions specified in @prot.
--- accel/tcg/cputlb.c | 168 ++++++++++++++++++++++++++++++++++++++++++ include/hw/core/cpu.h | 15 ++++ 2 files changed, 183 insertions(+)
accel/tcg/cputlb.c +168 -0
@@ -1272,6 +1272,174 @@ static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr, mmu_idx, retaddr); } +/* +* Perform lazy IOMMU translation for a CPUTLBEntry/CPUTLBEntryFull. +* This is called when CPU utilize the TLB entry in the slow path. +* Updates both entry and full entry to IOMMU translated data for the +* specific access type. +*/ +static void +tlb_translate_iommu (CPUState *cpu,int mmu_idx, +vaddr addr,MMUAccessType access_type, +CPUTLBEntryFull *full) +{ +CPUTLB *tlb = &cpu->neg.tlb; +MemoryRegionSection *section; +unsigned int read_flags, write_flags; +uintptr_t addend; +CPUTLBEntry *te; +hwaddr iotlb, xlat, sz, paddr_page; +vaddr addr_page; +int asidx, wp_flags, prot; +bool is_ram, is_romd; + +if (!full->is_iommu || (full->iommu_last_at == access_type)) { +return ; + } + +assert_cpu_is_self (cpu); + +if (full->lg_page_size <=TARGET_PAGE_BITS ) { + sz =TARGET_PAGE_SIZE ; + }else { + sz = (hwaddr )1 << full->lg_page_size; +tlb_add_large_page (cpu, mmu_idx, addr, sz); + } + addr_page = addr &TARGET_PAGE_MASK ; + paddr_page = full->phys_addr &TARGET_PAGE_MASK ; + + prot = full->prot; + asidx =cpu_asidx_from_attrs (cpu, full->attrs); + + section =address_space_translate_for_iotlb_late (cpu, asidx, paddr_page, + &xlat, &sz, full->attrs, + &prot, access_type); + +assert (sz >=TARGET_PAGE_SIZE ); + +tlb_debug ("vaddr=%016" VADDR_PRIx" paddr=0x" HWADDR_FMT_plx +" prot=%x idx=%d\n" , + addr, full->phys_addr, prot, mmu_idx); + + is_ram =memory_region_is_ram (section->mr); + is_romd =memory_region_is_romd (section->mr); + + read_flags = full->tlb_fill_flags; +if (full->lg_page_size <TARGET_PAGE_BITS ) { +/* Repeat the MMU check and TLB fill on every access. */ + read_flags |=TLB_INVALID_MASK ; + } + +if (is_ram || is_romd) { +/* RAM and ROMD both have associated host memory. */ + addend = (uintptr_t )memory_region_get_ram_ptr (section->mr) + xlat; + }else { +/* I/O and IOMMU does not; force the host address to NULL. */ + addend =0 ; + } + + write_flags = read_flags; + +if (is_ram) { + iotlb =memory_region_get_ram_addr (section->mr) + xlat; +assert (!(iotlb & ~TARGET_PAGE_MASK )); +/* +* Computing is_clean is expensive; avoid all that unless +* the page is actually writable. +*/ +if (prot &PAGE_WRITE ) { +if (section->readonly) { + write_flags |=TLB_DISCARD_WRITE ; + }else if (physical_memory_is_clean (iotlb)) { + write_flags |=TLB_NOTDIRTY ; + } + } + }else { +/* I/O or ROMD */ + iotlb = xlat; +/* +* Writes to romd devices must go through MMIO to enable write. +* Reads to romd devices go through the ram_ptr found above, +* but of course reads to I/O must go through MMIO. +*/ + write_flags |=TLB_MMIO ; +if (!is_romd) { + read_flags = write_flags; + } + } + + wp_flags =cpu_watchpoint_address_matches (cpu, addr_page, +TARGET_PAGE_SIZE ); + +/* Update the CPUTLBEntryFull for this access type. */ + full->iommu_last_at = access_type; + full->xlat_offset = iotlb - addr_page; + full->section = section; + full->phys_addr = paddr_page; + +/* Update the CPUTLBEntry: addend and addr_idx */ + tlb = &cpu->neg.tlb; + te =tlb_entry (cpu, mmu_idx, addr_page); + +qemu_spin_lock (&tlb->c.lock); + +/* +* If IOMMU region is translated to the memories (has associated +* host memory), it will update the 'addend' to access memories in the +* fast path. Otherwise, IO region do not update the 'addend' because +* it might be already used by memory region from the other permissions. +* It is fine since IO region do not use addend. +*/ +if (is_ram || is_romd) { +if (te->addend + addr_page) { +/* addend of untranslated IOMMU region is 0 - addr_page. */ + +/* +* CPUTLBEntry only has 1 addend across all permissions. +* We don't support the IOMMUMemoryRegion to be translated to +* 2 different host memories from the different permissions. +* QEMU will trigger an assertion for such case. +*/ +g_assert (addend == te->addend + addr_page); + }else { + te->addend = addend - addr_page; + } + } + +/* +* In the IOMMU lazy translation, we only update TLB flags for the +* permissions specified in @prot. For other permissions, we still +* keep the original TLB flags (e.g. TLB_IOMMU if not translated). +*/ +if (prot &PAGE_EXEC ) { +tlb_set_compare (full, te, addr_page, read_flags, +MMU_INST_FETCH , prot &PAGE_EXEC ); + } + +if (wp_flags &BP_MEM_READ ) { + read_flags |=TLB_WATCHPOINT ; + } +if (prot &PAGE_READ ) { +tlb_set_compare (full, te, addr_page, read_flags, +MMU_DATA_LOAD , prot &PAGE_READ ); + } + +if (prot &PAGE_WRITE_INV ) { + write_flags |=TLB_INVALID_MASK ; + } +if (wp_flags &BP_MEM_WRITE ) { + write_flags |=TLB_WATCHPOINT ; + } +if (prot &PAGE_WRITE ) { +tlb_set_compare (full, te, addr_page, write_flags, +MMU_DATA_STORE , prot &PAGE_WRITE ); + } + +qemu_spin_unlock (&tlb->c.lock); + +return ; +} +static MemoryRegionSection *io_prepare (hwaddr *out_offset,CPUState *cpu,CPUTLBEntryFull *full,vaddr addr,uintptr_t retaddr)
include/hw/core/cpu.h +15 -0
@@ -254,6 +254,21 @@ struct CPUTLBEntryFull {*/ uint8_t slow_flags[MMU_ACCESS_COUNT ]; +/* +* @is_iommu indicates if the MemoryRegion is an IOMMU. +* When true, IOMMU translation is deferred until the entry is used. +*/ +bool is_iommu; + +/* +* @iommu_last_at contains the access_type of last IOMMU translation. +* It means that this entry currently stores the translated data of +* IOMMU region with this access_type. +* When it is MMU_ACCESS_COUNT, the entry stores untranslated data of +* IOMMU region. +*/ +MMUAccessType iommu_last_at; +/* * Allow target-specific additions to this structure. * This may be used to cache items from the guest cpu
Signature · 1 line
2.43.0
PATCH v2 5/5 accel/tcg: Support IOMMU lazy translation in CPU TLB
In reply to Jim Shutlb_set_page_full() no longer translates IOMMU region, but only stores untranslated IOMMU region in the CPUTLBEntryFull. Then, when CPU uses CPUTLBEntryFull in the slow path. it should perform the lazy translation via tlb_translate_iommu().
The untranslated IOMMU region in TLB always requires to run in the slow path to trigger the lazy translation, so the IOMMU region will contain a new TLB flag, TLB_IOMMU, to force the slow path. Lazy translation will overwrite the TLB flags to the flags of the translated region. The host memory region from IOMMU region can still run in the fast path to accelerate the performance.
--- accel/tcg/cputlb.c | 66 ++++++++++++++++++++++++++++++++++------ include/exec/tlb-flags.h | 4 ++- 2 files changed, 60 insertions(+), 10 deletions(-)
accel/tcg/cputlb.c +57 -9
@@ -1034,7 +1034,7 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx,hwaddr iotlb, xlat, sz, paddr_page;vaddr addr_page;int asidx, wp_flags, prot; -bool is_ram, is_romd; +bool is_ram, is_romd, is_iommu;assert_cpu_is_self (cpu);
@@ -1049,29 +1049,38 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx, prot = full->prot; asidx =cpu_asidx_from_attrs (cpu, full->attrs); - section =address_space_translate_for_iotlb_late (cpu, asidx, paddr_page, - &xlat, &sz, full->attrs, - &prot); + +/* +* Use the early translation to check if it is an IOMMU region. +* This function stops at IOMMU regions without translating through them. +*/ + section =address_space_translate_for_iotlb_early (cpu, asidx, paddr_page, + &xlat, &sz, full->attrs, + &prot);assert (sz >=TARGET_PAGE_SIZE );tlb_debug ("vaddr=%016" VADDR_PRIx" paddr=0x" HWADDR_FMT_plx" prot=%x idx=%d\n" , addr, full->phys_addr, prot, mmu_idx); + is_iommu =memory_region_is_iommu (section->mr); + is_ram =memory_region_is_ram (section->mr); + is_romd =memory_region_is_romd (section->mr); + + full->is_iommu = is_iommu; + full->iommu_last_at =MMU_ACCESS_COUNT ; + read_flags = full->tlb_fill_flags;if (full->lg_page_size <TARGET_PAGE_BITS ) {/* Repeat the MMU check and TLB fill on every access. */ read_flags |=TLB_INVALID_MASK ; } - is_ram =memory_region_is_ram (section->mr); - is_romd =memory_region_is_romd (section->mr); -if (is_ram || is_romd) {/* RAM and ROMD both have associated host memory. */ addend = (uintptr_t )memory_region_get_ram_ptr (section->mr) + xlat; }else { -/* I/O does not; force the host address to NULL. */ +/* I/O and IOMMU does not; force the host address to NULL. */ addend =0 ; }
@@ -1090,6 +1099,15 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx, write_flags |=TLB_NOTDIRTY ; } } + }else if (is_iommu) { +/* IOMMU */ + iotlb = xlat; +/* +* If IOMMU region is not translated, any access will go to +* the slow path and do the lazy IOMMU translation. +*/ + read_flags |=TLB_IOMMU ; + write_flags |=TLB_IOMMU ; }else {/* I/O or ROMD */ iotlb = xlat;
@@ -1568,6 +1586,11 @@ static int probe_access_internal(CPUState *cpu, vaddr addr, flags &= tlb_addr; *pfull = full = &cpu->neg.tlb.d[mmu_idx].fulltlb[index]; + +if (full->is_iommu) { +tlb_translate_iommu (cpu, mmu_idx, addr, access_type, full); + } + flags |= full->slow_flags[access_type];/* Fold all "mmio-like" bits into TLB_MMIO. This is not RAM. */
@@ -1760,6 +1783,11 @@ bool tlb_plugin_lookup(CPUState *cpu, vaddr addr, int mmu_idx, } full = &cpu->neg.tlb.d[mmu_idx].fulltlb[index]; + +if (full->is_iommu) { +tlb_translate_iommu (cpu, mmu_idx, addr, access_type, full); + } + data->phys_addr = full->phys_addr | (addr & ~TARGET_PAGE_MASK );/* We must have an iotlb entry for MMIO */
@@ -1833,6 +1861,11 @@ static bool mmu_lookup1(CPUState *cpu, MMULookupPageData *data, MemOp memop, } full = &cpu->neg.tlb.d[mmu_idx].fulltlb[index]; + +if (full->is_iommu) { +tlb_translate_iommu (cpu, mmu_idx, addr, access_type, full); + } + flags = tlb_addr & (TLB_FLAGS_MASK & ~TLB_FORCE_SLOW ); flags |= full->slow_flags[access_type];
@@ -1944,6 +1977,11 @@ static bool mmu_lookup(CPUState *cpu, vaddr addr, MemOpIdx oi,if (mmu_lookup1 (cpu, &l->page[1 ],0 , l->mmu_idx, type, ra)) {uintptr_t index =tlb_index (cpu, l->mmu_idx, addr); l->page[0 ].full = &cpu->neg.tlb.d[l->mmu_idx].fulltlb[index]; + +if (l->page[0 ].full->is_iommu) { +tlb_translate_iommu (cpu, l->mmu_idx, addr, type, + l->page[0 ].full); + } } flags = l->page[0 ].flags | l->page[1 ].flags;
@@ -2001,6 +2039,17 @@ static void *atomic_mmu_lookup(CPUState *cpu, vaddr addr, MemOpIdx oi, tlb_addr =tlb_addr_write (tlbe) & ~TLB_INVALID_MASK ; } + full = &cpu->neg.tlb.d[mmu_idx].fulltlb[index]; + +if (full->is_iommu) { +/* +* Do IOMMU lazy translation before accessing addr_idx and TLB flags. +* Generate TLB flags for both read and write. +*/ +tlb_translate_iommu (cpu, mmu_idx, addr,MMU_DATA_LOAD , full); +tlb_translate_iommu (cpu, mmu_idx, addr,MMU_DATA_STORE , full); + } +/* * Let the guest notice RMW on a write-only page. * We have just verified that the page is writable.
@@ -2035,7 +2084,6 @@ static void *atomic_mmu_lookup(CPUState *cpu, vaddr addr, MemOpIdx oi, }/* Finish collecting tlb flags for both read and write. */ - full = &cpu->neg.tlb.d[mmu_idx].fulltlb[index]; tlb_addr |= tlbe->addr_read; tlb_addr &=TLB_FLAGS_MASK & ~TLB_FORCE_SLOW ; tlb_addr |= full->slow_flags[MMU_DATA_STORE ];
include/exec/tlb-flags.h +3 -1
@@ -52,10 +52,12 @@#define TLB_DISCARD_WRITE (1 << 3)/* Set if TLB entry is an IO callback. */ #define TLB_MMIO (1 << 4) +/* Set if TLB entry is a IOMMU region which requires lazy translation. */ +#define TLB_IOMMU (1 << 5)#define TLB_SLOW_FLAGS_MASK \ (TLB_BSWAP | TLB_WATCHPOINT | TLB_CHECK_ALIGNED | \ - TLB_DISCARD_WRITE | TLB_MMIO) + TLB_DISCARD_WRITE | TLB_MMIO | TLB_IOMMU)/* * Flags stored in CPUTLBEntry.addr_idx[x].
Signature · 1 line
2.43.0
Cc'ing Pierrick & Mark
Quoted 73 lines · Jim Shu
Note: v1 title is "accel/tcg: Pass the
access_typeto IOMMUMemoryRegion"Incoming security protection devices feature more complex IOMMUMemoryRegion implementation in the CPU path than ARM MPC device. For example, RISC-V wgChecker [1] may permit the access with only RO/WO permissions. Consequently, the IOMMUMemoryRegion could return different sections for read & write access.
To support such IOMMUMemoryRegion behavior in the CPU path, the design of IOMMU translation must be updated:
1. address_space_translate*() must now pass the
access_typeto IOMMUMemoryRegion.
2. Since IOMMU translation results are too complex to be fully stored in the CPU TLB. we will defer the translation until the actual access occurs. Also, TLB is allowed to store the untranslated IOMMU region.To implement deferred IOMMU translation, this patchset introduces the following changes:
1.
tlb_set_page_full()no longer translates the IOMMU region immediately. Instead, it stores the untranslated region directly in the TLB. A new slow-path flag,TLB_IOMMU, is introduced to force access into the slow path when a region has not yet been translated in the TLB entry.2. When the CPU utilizes a TLB entry in the slow path, it should perform the lazy IOMMU translation of the
access_typefirst. The resulting translated region and access type are stored in CPUTLBEntryFull. Since the slow path always performs lazy translation first, we can switch the CPUTLBEntryFull content to the correct access type before use.3. To accelerate memory access in the fast path, lazy translation can update the addend of the CPUTLBEntry when translating the region to a host memory region. We restrict the IOMMU region to have a single non-zero 'addend' across all permissions. If a second 'addend' is present for a CPUTLBEntry, QEMU will trigger an assertion. This limitation is sufficient for security devices, as their "secondary" region is typically an IO region used to emulate device error handling when access is rejected.
4. To support non-slow TLB flags, lazy translation can update the TLB flags in the '
addr_idx' of the CPUTLBEntry. Lazy translation only updates the flags for the permissions specified in @prot. This ensures that eachaccess_typeof a translated region to maintains independent TLB flags. For example,TLB_DIRTYof memory region will not be "polluted" from other permission that translated to different region.Both RISC-V wgChecker [1] and RISC-V IOPMP [2] devices require this feature.
[1] RISC-V WG:
https://patchew.org/QEMU/[email protected]/
[2] RISC-V IOPMP:
https://patchew.org/QEMU/[email protected]/Changed since v1:
- Remove the ping-pong TLB entry behavior. Instead, defer the IOMMU translation until actual access in the CPU path. Provide a IOMMU lazy translation function with the special handling of 'addend' and 'addr_idx' fields of CPUTLBEntry.
- Fix the checkpatch warning.Jim Shu (5):
accel/tcg: Passaccess_typeas an argument of tlb_set_page*() accel/tcg: address_space_translate*() will pass the correct
iommu_flags
accel/tcg: Provide early AS translate function accel/tcg: Add IOMMU lazy translation function accel/tcg: Support IOMMU lazy translation in CPU TLB
Hi Jim,
Quoted 8 lines · Jim Shu
Note: v1 title is "accel/tcg: Pass the
access_typeto IOMMUMemoryRegion"Incoming security protection devices feature more complex IOMMUMemoryRegion implementation in the CPU path than ARM MPC device. For example, RISC-V wgChecker [1] may permit the access with only RO/WO permissions. Consequently, the IOMMUMemoryRegion could return different sections for read & write access.
The consequence is not directly implied for me.
Why having a single translation and page protection handle read/write access is not enough here?
What is the (real world) use case to return different physical memory locations depending on read/write access for a given virtual address?
I'm not against the goal of this series, but trying to understand why it went in this direction, which complexify this already complex code path.
Quoted 91 lines
To support such IOMMUMemoryRegion behavior in the CPU path, the design of IOMMU translation must be updated:
1. address_space_translate*() must now pass the
access_typeto IOMMUMemoryRegion.
2. Since IOMMU translation results are too complex to be fully stored in the CPU TLB. we will defer the translation until the actual access occurs. Also, TLB is allowed to store the untranslated IOMMU region.To implement deferred IOMMU translation, this patchset introduces the following changes:
1.
tlb_set_page_full()no longer translates the IOMMU region immediately. Instead, it stores the untranslated region directly in the TLB. A new slow-path flag,TLB_IOMMU, is introduced to force access into the slow path when a region has not yet been translated in the TLB entry.2. When the CPU utilizes a TLB entry in the slow path, it should perform the lazy IOMMU translation of the
access_typefirst. The resulting translated region and access type are stored in CPUTLBEntryFull. Since the slow path always performs lazy translation first, we can switch the CPUTLBEntryFull content to the correct access type before use.3. To accelerate memory access in the fast path, lazy translation can update the addend of the CPUTLBEntry when translating the region to a host memory region. We restrict the IOMMU region to have a single non-zero 'addend' across all permissions. If a second 'addend' is present for a CPUTLBEntry, QEMU will trigger an assertion. This limitation is sufficient for security devices, as their "secondary" region is typically an IO region used to emulate device error handling when access is rejected.
4. To support non-slow TLB flags, lazy translation can update the TLB flags in the '
addr_idx' of the CPUTLBEntry. Lazy translation only updates the flags for the permissions specified in @prot. This ensures that eachaccess_typeof a translated region to maintains independent TLB flags. For example,TLB_DIRTYof memory region will not be "polluted" from other permission that translated to different region.Both RISC-V wgChecker [1] and RISC-V IOPMP [2] devices require this feature.
[1] RISC-V WG:
https://patchew.org/QEMU/[email protected]/
[2] RISC-V IOPMP:
https://patchew.org/QEMU/[email protected]/Changed since v1:
- Remove the ping-pong TLB entry behavior. Instead, defer the IOMMU translation until actual access in the CPU path. Provide a IOMMU lazy translation function with the special handling of 'addend' and 'addr_idx' fields of CPUTLBEntry.
- Fix the checkpatch warning.Jim Shu (5):
accel/tcg: Passaccess_typeas an argument of tlb_set_page*() accel/tcg: address_space_translate*() will pass the correct
iommu_flags
accel/tcg: Provide early AS translate function accel/tcg: Add IOMMU lazy translation function accel/tcg: Support IOMMU lazy translation in CPU TLBaccel/tcg/cputlb.c | 247 +++++++++++++++++++++++++-- include/accel/tcg/iommu.h | 17 +- include/exec/cputlb.h | 11 +- include/exec/tlb-flags.h | 4 +- include/hw/core/cpu.h | 15 ++ system/physmem.c | 60 ++++++- target/alpha/helper.c | 2 +- target/avr/helper.c | 3 +- target/hppa/mem_helper.c | 1 - target/i386/tcg/system/excp_helper.c | 3 +- target/loongarch/tcg/tlb_helper.c | 2 +- target/m68k/helper.c | 10 +- target/microblaze/helper.c | 8 +- target/mips/tcg/system/tlb_helper.c | 4 +- target/or1k/mmu.c | 2 +- target/ppc/mmu_helper.c | 2 +- target/riscv/cpu_helper.c | 2 +- target/rx/cpu.c | 3 +- target/s390x/tcg/excp_helper.c | 2 +- target/sh4/helper.c | 3 +- target/sparc/mmu_helper.c | 6 +- target/tricore/helper.c | 2 +- target/xtensa/helper.c | 3 +- 23 files changed, 354 insertions(+), 58 deletions(-)
On Thu, Apr 23, 2026 at 12:01 AM Pierrick Bouvier
<[email protected]> wrote:
Hi Pierrick,
Thanks for discussing the design!
Quoted 13 lines
Hi Jim,
Quoted 8 lines · Jim Shu
Note: v1 title is "accel/tcg: Pass the
access_typeto IOMMUMemoryRegion"Incoming security protection devices feature more complex IOMMUMemoryRegion implementation in the CPU path than ARM MPC device. For example, RISC-V wgChecker [1] may permit the access with only RO/WO permissions. Consequently, the IOMMUMemoryRegion could return different sections for read & write access.
Quoted 7 lines
The consequence is not directly implied for me.
Why having a single translation and page protection handle read/write access is not enough here?
What is the (real world) use case to return different physical memory locations depending on read/write access for a given virtual address?
When permission is granted, the wgChecker device returns the original region of the address, called the downstream region
When permission is denied, the wgChecker device returns a special MemoryRegion for error handling, called the blocked_io region). This region may trigger an IRQ and a bus error. Additionally, memory accesses to this region will result in 'read 0, write ignored' rather than triggering exceptions from the MMU or MPU.
Consequently, implementing RWX permission checks on security protection devices may return different regions (either downstream or blocked_io) depending on the access type.
This design is similar to the existing ARM MPC device (hw/misc/tz-mpc.c). The primary difference is that the MPC only checks the physical address rather than RWX permissions, meaning it returns either the downstream or blocked_io region for a single address regardless of the access type.
I also considered an alternative design where CPUTLBEntryFull stores both the successful permission and the blocked_io region of the IOMMU region.
In this scenario, the slow-path code utilizing CPUTLBEntryFull would check permissions and return the blocked_io region if access is denied
However, the address_space_translate_iommu() implementation supports recursive IOMMU region translation.
if multiple IOMMU regions are encountered during a single address translation, storing only the first region's permissions is insufficient.
Ultimately, we still face a situation where RWX permissions might return different regions separately (e.g., downstream, blocked_io_iommu1, and blocked_io_iommu2).
Quoted 96 lines
I'm not against the goal of this series, but trying to understand why it went in this direction, which complexify this already complex code path.
Quoted 91 lines
To support such IOMMUMemoryRegion behavior in the CPU path, the design of IOMMU translation must be updated:
1. address_space_translate*() must now pass the
access_typeto IOMMUMemoryRegion.
2. Since IOMMU translation results are too complex to be fully stored in the CPU TLB. we will defer the translation until the actual access occurs. Also, TLB is allowed to store the untranslated IOMMU region.To implement deferred IOMMU translation, this patchset introduces the following changes:
1.
tlb_set_page_full()no longer translates the IOMMU region immediately. Instead, it stores the untranslated region directly in the TLB. A new slow-path flag,TLB_IOMMU, is introduced to force access into the slow path when a region has not yet been translated in the TLB entry.2. When the CPU utilizes a TLB entry in the slow path, it should perform the lazy IOMMU translation of the
access_typefirst. The resulting translated region and access type are stored in CPUTLBEntryFull. Since the slow path always performs lazy translation first, we can switch the CPUTLBEntryFull content to the correct access type before use.3. To accelerate memory access in the fast path, lazy translation can update the addend of the CPUTLBEntry when translating the region to a host memory region. We restrict the IOMMU region to have a single non-zero 'addend' across all permissions. If a second 'addend' is present for a CPUTLBEntry, QEMU will trigger an assertion. This limitation is sufficient for security devices, as their "secondary" region is typically an IO region used to emulate device error handling when access is rejected.
4. To support non-slow TLB flags, lazy translation can update the TLB flags in the '
addr_idx' of the CPUTLBEntry. Lazy translation only updates the flags for the permissions specified in @prot. This ensures that eachaccess_typeof a translated region to maintains independent TLB flags. For example,TLB_DIRTYof memory region will not be "polluted" from other permission that translated to different region.Both RISC-V wgChecker [1] and RISC-V IOPMP [2] devices require this feature.
[1] RISC-V WG:
https://patchew.org/QEMU/[email protected]/
[2] RISC-V IOPMP:
https://patchew.org/QEMU/[email protected]/Changed since v1:
- Remove the ping-pong TLB entry behavior. Instead, defer the IOMMU translation until actual access in the CPU path. Provide a IOMMU lazy translation function with the special handling of 'addend' and 'addr_idx' fields of CPUTLBEntry.
- Fix the checkpatch warning.Jim Shu (5):
accel/tcg: Passaccess_typeas an argument of tlb_set_page*() accel/tcg: address_space_translate*() will pass the correct
iommu_flags
accel/tcg: Provide early AS translate function accel/tcg: Add IOMMU lazy translation function accel/tcg: Support IOMMU lazy translation in CPU TLBaccel/tcg/cputlb.c | 247 +++++++++++++++++++++++++-- include/accel/tcg/iommu.h | 17 +- include/exec/cputlb.h | 11 +- include/exec/tlb-flags.h | 4 +- include/hw/core/cpu.h | 15 ++ system/physmem.c | 60 ++++++- target/alpha/helper.c | 2 +- target/avr/helper.c | 3 +- target/hppa/mem_helper.c | 1 - target/i386/tcg/system/excp_helper.c | 3 +- target/loongarch/tcg/tlb_helper.c | 2 +- target/m68k/helper.c | 10 +- target/microblaze/helper.c | 8 +- target/mips/tcg/system/tlb_helper.c | 4 +- target/or1k/mmu.c | 2 +- target/ppc/mmu_helper.c | 2 +- target/riscv/cpu_helper.c | 2 +- target/rx/cpu.c | 3 +- target/s390x/tcg/excp_helper.c | 2 +- target/sh4/helper.c | 3 +- target/sparc/mmu_helper.c | 6 +- target/tricore/helper.c | 2 +- target/xtensa/helper.c | 3 +- 23 files changed, 354 insertions(+), 58 deletions(-)
Regards,
Jim
Quoted 36 lines · Jim Shu
On Thu, Apr 23, 2026 at 12:01 AM Pierrick Bouvier
<[email protected]> wrote:Hi Pierrick,
Thanks for discussing the design!
Quoted 13 lines
Hi Jim,
Quoted 8 lines · Jim Shu
Note: v1 title is "accel/tcg: Pass the
access_typeto IOMMUMemoryRegion"Incoming security protection devices feature more complex IOMMUMemoryRegion implementation in the CPU path than ARM MPC device. For example, RISC-V wgChecker [1] may permit the access with only RO/WO permissions. Consequently, the IOMMUMemoryRegion could return different sections for read & write access.
Quoted 7 lines
The consequence is not directly implied for me.
Why having a single translation and page protection handle read/write access is not enough here?
What is the (real world) use case to return different physical memory locations depending on read/write access for a given virtual address?
When permission is granted, the wgChecker device returns the original region of the address, called the downstream region
When permission is denied, the wgChecker device returns a special MemoryRegion for error handling, called theblocked_ioregion). This region may trigger an IRQ and a bus error. Additionally, memory accesses to this region will result in 'read 0, write ignored' rather than triggering exceptions from the MMU or MPU.
Quoted 9 lines
Consequently, implementing RWX permission checks on security protection devices may return different regions (either downstream or
blocked_io) depending on the access type.
This design is similar to the existing ARM MPC device (hw/misc/tz-mpc.c). The primary difference is that the MPC only checks the physical address rather than RWX permissions, meaning it returns either the downstream orblocked_ioregion for a single address regardless of the access type.
It is indeed, a big difference. Translation with MPC device still results in a single address space being chosen.
Quoted 6 lines
I also considered an alternative design where CPUTLBEntryFull stores both the successful permission and the
blocked_ioregion of the IOMMU region.
In this scenario, the slow-path code utilizing CPUTLBEntryFull would check permissions and return theblocked_ioregion if access is denied
Quoted 9 lines
However, the
address_space_translate_iommu()implementation supports recursive IOMMU region translation.
if multiple IOMMU regions are encountered during a single address translation, storing only the first region's permissions is insufficient.
Ultimately, we still face a situation where RWX permissions might return different regions separately (e.g., downstream,blocked_io_iommu1, andblocked_io_iommu2).
The "blocked_io_iommu_X" is a consequence of the current choice of implementation, but I still don't see why it's an absolute necessity.
An alternative would be to treat all accesses as MMIO, but I guess your goal here is to optimize the code path where we access RAM?
Why can't you reuse existing page protection mechanism for this, authorizing read or write? WorldChecker just seems to be an additional check on top of existing translation. The fact it's an "additional" device is a design/implementation details, and could simply be part of page protection mechanism. It might require some additional plumbing when an interrupt is raised though, to redirect this correctly instead of signaling CPU like it would normally do.
The fact is does different action based on read/write attribute does not really fit very well with existing implementation, as you noticed. And I wonder if it's worth changing the global design just to optimize this (optional) use case for RISC-V.
Quoted 99 lines
Quoted 96 lines
I'm not against the goal of this series, but trying to understand why it went in this direction, which complexify this already complex code path.
Quoted 91 lines
To support such IOMMUMemoryRegion behavior in the CPU path, the design of IOMMU translation must be updated:
1. address_space_translate*() must now pass the
access_typeto IOMMUMemoryRegion.
2. Since IOMMU translation results are too complex to be fully stored in the CPU TLB. we will defer the translation until the actual access occurs. Also, TLB is allowed to store the untranslated IOMMU region.To implement deferred IOMMU translation, this patchset introduces the following changes:
1.
tlb_set_page_full()no longer translates the IOMMU region immediately. Instead, it stores the untranslated region directly in the TLB. A new slow-path flag,TLB_IOMMU, is introduced to force access into the slow path when a region has not yet been translated in the TLB entry.2. When the CPU utilizes a TLB entry in the slow path, it should perform the lazy IOMMU translation of the
access_typefirst. The resulting translated region and access type are stored in CPUTLBEntryFull. Since the slow path always performs lazy translation first, we can switch the CPUTLBEntryFull content to the correct access type before use.3. To accelerate memory access in the fast path, lazy translation can update the addend of the CPUTLBEntry when translating the region to a host memory region. We restrict the IOMMU region to have a single non-zero 'addend' across all permissions. If a second 'addend' is present for a CPUTLBEntry, QEMU will trigger an assertion. This limitation is sufficient for security devices, as their "secondary" region is typically an IO region used to emulate device error handling when access is rejected.
4. To support non-slow TLB flags, lazy translation can update the TLB flags in the '
addr_idx' of the CPUTLBEntry. Lazy translation only updates the flags for the permissions specified in @prot. This ensures that eachaccess_typeof a translated region to maintains independent TLB flags. For example,TLB_DIRTYof memory region will not be "polluted" from other permission that translated to different region.Both RISC-V wgChecker [1] and RISC-V IOPMP [2] devices require this feature.
[1] RISC-V WG:
https://patchew.org/QEMU/[email protected]/
[2] RISC-V IOPMP:
https://patchew.org/QEMU/[email protected]/Changed since v1:
- Remove the ping-pong TLB entry behavior. Instead, defer the IOMMU translation until actual access in the CPU path. Provide a IOMMU lazy translation function with the special handling of 'addend' and 'addr_idx' fields of CPUTLBEntry.
- Fix the checkpatch warning.Jim Shu (5):
accel/tcg: Passaccess_typeas an argument of tlb_set_page*() accel/tcg: address_space_translate*() will pass the correct
iommu_flags
accel/tcg: Provide early AS translate function accel/tcg: Add IOMMU lazy translation function accel/tcg: Support IOMMU lazy translation in CPU TLBaccel/tcg/cputlb.c | 247 +++++++++++++++++++++++++-- include/accel/tcg/iommu.h | 17 +- include/exec/cputlb.h | 11 +- include/exec/tlb-flags.h | 4 +- include/hw/core/cpu.h | 15 ++ system/physmem.c | 60 ++++++- target/alpha/helper.c | 2 +- target/avr/helper.c | 3 +- target/hppa/mem_helper.c | 1 - target/i386/tcg/system/excp_helper.c | 3 +- target/loongarch/tcg/tlb_helper.c | 2 +- target/m68k/helper.c | 10 +- target/microblaze/helper.c | 8 +- target/mips/tcg/system/tlb_helper.c | 4 +- target/or1k/mmu.c | 2 +- target/ppc/mmu_helper.c | 2 +- target/riscv/cpu_helper.c | 2 +- target/rx/cpu.c | 3 +- target/s390x/tcg/excp_helper.c | 2 +- target/sh4/helper.c | 3 +- target/sparc/mmu_helper.c | 6 +- target/tricore/helper.c | 2 +- target/xtensa/helper.c | 3 +- 23 files changed, 354 insertions(+), 58 deletions(-)Regards,
Jim
Quoted 67 lines · Pierrick Bouvier
Quoted 36 lines · Jim Shu
On Thu, Apr 23, 2026 at 12:01 AM Pierrick Bouvier
<[email protected]> wrote:Hi Pierrick,
Thanks for discussing the design!
Quoted 13 lines
Hi Jim,
Quoted 8 lines · Jim Shu
Note: v1 title is "accel/tcg: Pass the
access_typeto IOMMUMemoryRegion"Incoming security protection devices feature more complex IOMMUMemoryRegion implementation in the CPU path than ARM MPC device. For example, RISC-V wgChecker [1] may permit the access with only RO/WO permissions. Consequently, the IOMMUMemoryRegion could return different sections for read & write access.
Quoted 7 lines
The consequence is not directly implied for me.
Why having a single translation and page protection handle read/write access is not enough here?
What is the (real world) use case to return different physical memory locations depending on read/write access for a given virtual address?
When permission is granted, the wgChecker device returns the original region of the address, called the downstream region
When permission is denied, the wgChecker device returns a special MemoryRegion for error handling, called theblocked_ioregion). This region may trigger an IRQ and a bus error. Additionally, memory accesses to this region will result in 'read 0, write ignored' rather than triggering exceptions from the MMU or MPU.Quoted 9 lines
Consequently, implementing RWX permission checks on security protection devices may return different regions (either downstream or
blocked_io) depending on the access type.
This design is similar to the existing ARM MPC device (hw/misc/tz-mpc.c). The primary difference is that the MPC only checks the physical address rather than RWX permissions, meaning it returns either the downstream orblocked_ioregion for a single address regardless of the access type.It is indeed, a big difference. Translation with MPC device still results in a single address space being chosen.
Quoted 6 lines
I also considered an alternative design where CPUTLBEntryFull stores both the successful permission and the
blocked_ioregion of the IOMMU region.
In this scenario, the slow-path code utilizing CPUTLBEntryFull would check permissions and return theblocked_ioregion if access is deniedQuoted 9 lines
However, the
address_space_translate_iommu()implementation supports recursive IOMMU region translation.
if multiple IOMMU regions are encountered during a single address translation, storing only the first region's permissions is insufficient.
Ultimately, we still face a situation where RWX permissions might return different regions separately (e.g., downstream,blocked_io_iommu1, andblocked_io_iommu2).
Quoted 3 lines
The "
blocked_io_iommu_X" is a consequence of the current choice of implementation, but I still don't see why it's an absolute necessity.
I am open to removing it if the community agrees. I believe platforms with the ARM MPC do not use multiple IOMMU regions when translating a single address.
Quoted 3 lines
An alternative would be to treat all accesses as MMIO, but I guess your goal here is to optimize the code path where we access RAM?
If the downstream region is a memory region, it will update the TLB flags and vaddr in addr_idx for the successful permissions of IOMMU region.
To explain further: In the alternative approach, we would obtain the downstream region, IOMMU permissions, and the blocked_io region from the IOMMU translation function (which would require an additional return value or API to get the blocked_io region). The TLB entry will handle the downstream region as a non-IOMMU region but will only update the TLB flags for the IOMMU permissions; it will also store the permissions and the blocked_io region. The slow-path code checks the IOMMU permissions. If permission is denied, it will perform the transaction on the blocked_io region instead.
We can remove the lazy IOMMU translation if using an alternative approach.
Quoted 8 lines
Why can't you reuse existing page protection mechanism for this, authorizing read or write? WorldChecker just seems to be an additional check on top of existing translation. The fact it's an "additional" device is a design/implementation details, and could simply be part of page protection mechanism. It might require some additional plumbing when an interrupt is raised though, to redirect this correctly instead of signaling CPU like it would normally do.
Quoted 5 lines
The fact is does different action based on read/write attribute does not really fit very well with existing implementation, as you noticed. And I wonder if it's worth changing the global design just to optimize this (optional) use case for RISC-V.
In the SoC architecture, the wgCheckers are positioned in front of devices (either memory or MMIO). When the CPU or DMA sends transactions to the device, the device's wgChecker first performs a permission check to determine if the transaction should be forwarded. If we move this check to the architecture's tlb_fill() function, how would the CPU code determine if transactions were sent to the device (or to the upstream region of the wgChecker)? The CPU code would need to be aware of the memory tree hierarchy to do that, which I believe is more difficult to implement.
In the current QEMU architecture, when a security protection device sits in front of a device, placing it within the memory tree seems to be the most suitable approach, similar to the ARM MPC device. The address_space*() API can check if a transaction will be forwarded to the device and perform the permission check via the IOMMU region. Both the CPU-side address_space_translate_for_iotlb() and the DMA-side address_space_translate_iommu() handle this. The only missing component is that the CPU TLB cannot handle RWX permission checks for IOMMU regions within the memory tree.
Quoted 100 lines
Quoted 99 lines
Quoted 96 lines
I'm not against the goal of this series, but trying to understand why it went in this direction, which complexify this already complex code path.
Quoted 91 lines
To support such IOMMUMemoryRegion behavior in the CPU path, the design of IOMMU translation must be updated:
1. address_space_translate*() must now pass the
access_typeto IOMMUMemoryRegion.
2. Since IOMMU translation results are too complex to be fully stored in the CPU TLB. we will defer the translation until the actual access occurs. Also, TLB is allowed to store the untranslated IOMMU region.To implement deferred IOMMU translation, this patchset introduces the following changes:
1.
tlb_set_page_full()no longer translates the IOMMU region immediately. Instead, it stores the untranslated region directly in the TLB. A new slow-path flag,TLB_IOMMU, is introduced to force access into the slow path when a region has not yet been translated in the TLB entry.2. When the CPU utilizes a TLB entry in the slow path, it should perform the lazy IOMMU translation of the
access_typefirst. The resulting translated region and access type are stored in CPUTLBEntryFull. Since the slow path always performs lazy translation first, we can switch the CPUTLBEntryFull content to the correct access type before use.3. To accelerate memory access in the fast path, lazy translation can update the addend of the CPUTLBEntry when translating the region to a host memory region. We restrict the IOMMU region to have a single non-zero 'addend' across all permissions. If a second 'addend' is present for a CPUTLBEntry, QEMU will trigger an assertion. This limitation is sufficient for security devices, as their "secondary" region is typically an IO region used to emulate device error handling when access is rejected.
4. To support non-slow TLB flags, lazy translation can update the TLB flags in the '
addr_idx' of the CPUTLBEntry. Lazy translation only updates the flags for the permissions specified in @prot. This ensures that eachaccess_typeof a translated region to maintains independent TLB flags. For example,TLB_DIRTYof memory region will not be "polluted" from other permission that translated to different region.Both RISC-V wgChecker [1] and RISC-V IOPMP [2] devices require this feature.
[1] RISC-V WG:
https://patchew.org/QEMU/[email protected]/
[2] RISC-V IOPMP:
https://patchew.org/QEMU/[email protected]/Changed since v1:
- Remove the ping-pong TLB entry behavior. Instead, defer the IOMMU translation until actual access in the CPU path. Provide a IOMMU lazy translation function with the special handling of 'addend' and 'addr_idx' fields of CPUTLBEntry.
- Fix the checkpatch warning.Jim Shu (5):
accel/tcg: Passaccess_typeas an argument of tlb_set_page*() accel/tcg: address_space_translate*() will pass the correct
iommu_flags
accel/tcg: Provide early AS translate function accel/tcg: Add IOMMU lazy translation function accel/tcg: Support IOMMU lazy translation in CPU TLBaccel/tcg/cputlb.c | 247 +++++++++++++++++++++++++-- include/accel/tcg/iommu.h | 17 +- include/exec/cputlb.h | 11 +- include/exec/tlb-flags.h | 4 +- include/hw/core/cpu.h | 15 ++ system/physmem.c | 60 ++++++- target/alpha/helper.c | 2 +- target/avr/helper.c | 3 +- target/hppa/mem_helper.c | 1 - target/i386/tcg/system/excp_helper.c | 3 +- target/loongarch/tcg/tlb_helper.c | 2 +- target/m68k/helper.c | 10 +- target/microblaze/helper.c | 8 +- target/mips/tcg/system/tlb_helper.c | 4 +- target/or1k/mmu.c | 2 +- target/ppc/mmu_helper.c | 2 +- target/riscv/cpu_helper.c | 2 +- target/rx/cpu.c | 3 +- target/s390x/tcg/excp_helper.c | 2 +- target/sh4/helper.c | 3 +- target/sparc/mmu_helper.c | 6 +- target/tricore/helper.c | 2 +- target/xtensa/helper.c | 3 +- 23 files changed, 354 insertions(+), 58 deletions(-)Regards,
Jim
Quoted 69 lines · Jim Shu
Quoted 67 lines · Pierrick Bouvier
Quoted 36 lines · Jim Shu
On Thu, Apr 23, 2026 at 12:01 AM Pierrick Bouvier
<[email protected]> wrote:Hi Pierrick,
Thanks for discussing the design!
Quoted 13 lines
Hi Jim,
Quoted 8 lines · Jim Shu
Note: v1 title is "accel/tcg: Pass the
access_typeto IOMMUMemoryRegion"Incoming security protection devices feature more complex IOMMUMemoryRegion implementation in the CPU path than ARM MPC device. For example, RISC-V wgChecker [1] may permit the access with only RO/WO permissions. Consequently, the IOMMUMemoryRegion could return different sections for read & write access.
Quoted 7 lines
The consequence is not directly implied for me.
Why having a single translation and page protection handle read/write access is not enough here?
What is the (real world) use case to return different physical memory locations depending on read/write access for a given virtual address?
When permission is granted, the wgChecker device returns the original region of the address, called the downstream region
When permission is denied, the wgChecker device returns a special MemoryRegion for error handling, called theblocked_ioregion). This region may trigger an IRQ and a bus error. Additionally, memory accesses to this region will result in 'read 0, write ignored' rather than triggering exceptions from the MMU or MPU.Quoted 9 lines
Consequently, implementing RWX permission checks on security protection devices may return different regions (either downstream or
blocked_io) depending on the access type.
This design is similar to the existing ARM MPC device (hw/misc/tz-mpc.c). The primary difference is that the MPC only checks the physical address rather than RWX permissions, meaning it returns either the downstream orblocked_ioregion for a single address regardless of the access type.It is indeed, a big difference. Translation with MPC device still results in a single address space being chosen.
Quoted 15 lines
I also considered an alternative design where CPUTLBEntryFull stores both the successful permission and the
blocked_ioregion of the IOMMU region.
In this scenario, the slow-path code utilizing CPUTLBEntryFull would check permissions and return theblocked_ioregion if access is deniedHowever, the
address_space_translate_iommu()implementation supports recursive IOMMU region translation.
if multiple IOMMU regions are encountered during a single address translation, storing only the first region's permissions is insufficient.
Ultimately, we still face a situation where RWX permissions might return different regions separately (e.g., downstream,blocked_io_iommu1, andblocked_io_iommu2).
Quoted 8 lines
Quoted 3 lines
The "
blocked_io_iommu_X" is a consequence of the current choice of implementation, but I still don't see why it's an absolute necessity.I am open to removing it if the community agrees. I believe platforms with the ARM MPC do not use multiple IOMMU regions when translating a single address.
I am not expert on the topic, but it seems MPC is mostly used with microcontrollers with trustzone and is much more limited in scope than WorldChecker. WorldChecker seems to be a mix of MMU + IOMMU + something like Arm Granule Protection Table in a single external component.
I am probably biased by Arm "World" implementation of this (out of MPC), where CPU and SMMU play this role, instead of an external component.
Going back to MPC, the translation is still deterministic and not based on type of access. From what I understand, MPC can statically forbid accesses to specific blocks, simply based on original address.
Quoted 4 lines
Quoted 3 lines
An alternative would be to treat all accesses as MMIO, but I guess your goal here is to optimize the code path where we access RAM?
Quoted 14 lines
If the downstream region is a memory region, it will update the TLB flags and vaddr in
addr_idxfor the successful permissions of IOMMU region.
To explain further: In the alternative approach, we would obtain the downstream region, IOMMU permissions, and theblocked_ioregion from the IOMMU translation function (which would require an additional return value or API to get theblocked_ioregion). The TLB entry will handle the downstream region as a non-IOMMU region but will only update the TLB flags for the IOMMU permissions; it will also store the permissions and theblocked_ioregion. The slow-path code checks the IOMMU permissions. If permission is denied, it will perform the transaction on theblocked_ioregion instead.
We can remove the lazy IOMMU translation if using an alternative approach.
What I was suggesting in my question was to force any access to a MemoryRegion handled by a wgChecker to go through a read or write callback, and to do the actual check there.
For instance, MPC redirects blocked calls to:
static const MemoryRegionOps tz_mpc_mem_blocked_ops = {
.read_with_attrs = tz_mpc_mem_blocked_read, .write_with_attrs = tz_mpc_mem_blocked_write,
So I was suggesting something like:
static const MemoryRegionOps wgchecker_ops = {
.read_with_attrs = wgchecker_mem_read,
.write_with_attrs = wgchecker_mem_write,
And redirect all read/write to those callbacks, thus turning the whole range into an MMIO range. Thus my original question to understand if your main concern is runtime performance or not.
Quoted 14 lines
Quoted 8 lines
Why can't you reuse existing page protection mechanism for this, authorizing read or write? WorldChecker just seems to be an additional check on top of existing translation. The fact it's an "additional" device is a design/implementation details, and could simply be part of page protection mechanism. It might require some additional plumbing when an interrupt is raised though, to redirect this correctly instead of signaling CPU like it would normally do.
Quoted 5 lines
The fact is does different action based on read/write attribute does not really fit very well with existing implementation, as you noticed. And I wonder if it's worth changing the global design just to optimize this (optional) use case for RISC-V.
Quoted 10 lines
In the SoC architecture, the wgCheckers are positioned in front of devices (either memory or MMIO). When the CPU or DMA sends transactions to the device, the device's wgChecker first performs a permission check to determine if the transaction should be forwarded. If we move this check to the architecture's
tlb_fill()function, how would the CPU code determine if transactions were sent to the device (or to the upstream region of the wgChecker)? The CPU code would need to be aware of the memory tree hierarchy to do that, which I believe is more difficult to implement.
The memory hierarchy has to be known anyway by the component dealing with that. Currently, TLB is responsible for it, iterating through the different regions. However, it could be wgChecker code that does that, or tlb_fill() for RISC-V.
My only concern with existing design is that it pushes all that on generic TLB code, for a feature that is optional and only used by RISC-V, but still impacting all architectures.
It's not a no, I don't have any authority on this part of codebase, but just a question to understand why it can't be solved another way that would be RISC-V specific.
Quoted 10 lines
In the current QEMU architecture, when a security protection device sits in front of a device, placing it within the memory tree seems to be the most suitable approach, similar to the ARM MPC device. The address_space*() API can check if a transaction will be forwarded to the device and perform the permission check via the IOMMU region. Both the CPU-side
address_space_translate_for_iotlb()and the DMA-sideaddress_space_translate_iommu()handle this. The only missing component is that the CPU TLB cannot handle RWX permission checks for IOMMU regions within the memory tree.
I understand this and what you want.
I'm really open to it if anyone else has feedback on this, and help decide if it's worth changing generic TLB code for this use case.
Quoted 100 lines
Quoted 100 lines
Quoted 100 lines
Quoted 99 lines
I'm not against the goal of this series, but trying to understand why it went in this direction, which complexify this already complex code path.
Quoted 91 lines
To support such IOMMUMemoryRegion behavior in the CPU path, the design of IOMMU translation must be updated:
1. address_space_translate*() must now pass the
access_typeto IOMMUMemoryRegion.
2. Since IOMMU translation results are too complex to be fully stored in the CPU TLB. we will defer the translation until the actual access occurs. Also, TLB is allowed to store the untranslated IOMMU region.To implement deferred IOMMU translation, this patchset introduces the following changes:
1.
tlb_set_page_full()no longer translates the IOMMU region immediately. Instead, it stores the untranslated region directly in the TLB. A new slow-path flag,TLB_IOMMU, is introduced to force access into the slow path when a region has not yet been translated in the TLB entry.2. When the CPU utilizes a TLB entry in the slow path, it should perform the lazy IOMMU translation of the
access_typefirst. The resulting translated region and access type are stored in CPUTLBEntryFull. Since the slow path always performs lazy translation first, we can switch the CPUTLBEntryFull content to the correct access type before use.3. To accelerate memory access in the fast path, lazy translation can update the addend of the CPUTLBEntry when translating the region to a host memory region. We restrict the IOMMU region to have a single non-zero 'addend' across all permissions. If a second 'addend' is present for a CPUTLBEntry, QEMU will trigger an assertion. This limitation is sufficient for security devices, as their "secondary" region is typically an IO region used to emulate device error handling when access is rejected.
4. To support non-slow TLB flags, lazy translation can update the TLB flags in the '
addr_idx' of the CPUTLBEntry. Lazy translation only updates the flags for the permissions specified in @prot. This ensures that eachaccess_typeof a translated region to maintains independent TLB flags. For example,TLB_DIRTYof memory region will not be "polluted" from other permission that translated to different region.Both RISC-V wgChecker [1] and RISC-V IOPMP [2] devices require this feature.
[1] RISC-V WG:
https://patchew.org/QEMU/[email protected]/
[2] RISC-V IOPMP:
https://patchew.org/QEMU/[email protected]/Changed since v1:
- Remove the ping-pong TLB entry behavior. Instead, defer the IOMMU translation until actual access in the CPU path. Provide a IOMMU lazy translation function with the special handling of 'addend' and 'addr_idx' fields of CPUTLBEntry.
- Fix the checkpatch warning.Jim Shu (5):
accel/tcg: Passaccess_typeas an argument of tlb_set_page*() accel/tcg: address_space_translate*() will pass the correct
iommu_flags
accel/tcg: Provide early AS translate function accel/tcg: Add IOMMU lazy translation function accel/tcg: Support IOMMU lazy translation in CPU TLB
accel/tcg/cputlb.c| 247 +++++++++++++++++++++++++--
include/accel/tcg/iommu.h| 17 +-
include/exec/cputlb.h| 11 +-
include/exec/tlb-flags.h| 4 +-
include/hw/core/cpu.h| 15 ++
system/physmem.c| 60 ++++++-
target/alpha/helper.c| 2 +-
target/avr/helper.c| 3 +-
target/hppa/mem_helper.c| 1 -
target/i386/tcg/system/excp_helper.c| 3 +-
target/loongarch/tcg/tlb_helper.c| 2 +-
target/m68k/helper.c| 10 +-
target/microblaze/helper.c| 8 +-
target/mips/tcg/system/tlb_helper.c| 4 +-
target/or1k/mmu.c| 2 +-
target/ppc/mmu_helper.c| 2 +-
target/riscv/cpu_helper.c| 2 +-
target/rx/cpu.c| 3 +-
target/s390x/tcg/excp_helper.c| 2 +-
target/sh4/helper.c| 3 +-
target/sparc/mmu_helper.c| 6 +-
target/tricore/helper.c| 2 +-
target/xtensa/helper.c| 3 +-
23 files changed, 354 insertions(+), 58 deletions(-)
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Regards,
Jim
Regards,
Pierrick
Quoted 85 lines · Pierrick Bouvier
Quoted 69 lines · Jim Shu
Quoted 67 lines · Pierrick Bouvier
Quoted 36 lines · Jim Shu
On Thu, Apr 23, 2026 at 12:01 AM Pierrick Bouvier
<[email protected]> wrote:Hi Pierrick,
Thanks for discussing the design!
Quoted 13 lines
Hi Jim,
Quoted 8 lines · Jim Shu
Note: v1 title is "accel/tcg: Pass the
access_typeto IOMMUMemoryRegion"Incoming security protection devices feature more complex IOMMUMemoryRegion implementation in the CPU path than ARM MPC device. For example, RISC-V wgChecker [1] may permit the access with only RO/WO permissions. Consequently, the IOMMUMemoryRegion could return different sections for read & write access.
Quoted 7 lines
The consequence is not directly implied for me.
Why having a single translation and page protection handle read/write access is not enough here?
What is the (real world) use case to return different physical memory locations depending on read/write access for a given virtual address?
When permission is granted, the wgChecker device returns the original region of the address, called the downstream region
When permission is denied, the wgChecker device returns a special MemoryRegion for error handling, called theblocked_ioregion). This region may trigger an IRQ and a bus error. Additionally, memory accesses to this region will result in 'read 0, write ignored' rather than triggering exceptions from the MMU or MPU.Quoted 9 lines
Consequently, implementing RWX permission checks on security protection devices may return different regions (either downstream or
blocked_io) depending on the access type.
This design is similar to the existing ARM MPC device (hw/misc/tz-mpc.c). The primary difference is that the MPC only checks the physical address rather than RWX permissions, meaning it returns either the downstream orblocked_ioregion for a single address regardless of the access type.It is indeed, a big difference. Translation with MPC device still results in a single address space being chosen.
Quoted 15 lines
I also considered an alternative design where CPUTLBEntryFull stores both the successful permission and the
blocked_ioregion of the IOMMU region.
In this scenario, the slow-path code utilizing CPUTLBEntryFull would check permissions and return theblocked_ioregion if access is deniedHowever, the
address_space_translate_iommu()implementation supports recursive IOMMU region translation.
if multiple IOMMU regions are encountered during a single address translation, storing only the first region's permissions is insufficient.
Ultimately, we still face a situation where RWX permissions might return different regions separately (e.g., downstream,blocked_io_iommu1, andblocked_io_iommu2).Quoted 8 lines
Quoted 3 lines
The "
blocked_io_iommu_X" is a consequence of the current choice of implementation, but I still don't see why it's an absolute necessity.I am open to removing it if the community agrees. I believe platforms with the ARM MPC do not use multiple IOMMU regions when translating a single address.
I am not expert on the topic, but it seems MPC is mostly used with microcontrollers with trustzone and is much more limited in scope than WorldChecker. WorldChecker seems to be a mix of MMU + IOMMU + something like Arm Granule Protection Table in a single external component.
Quoted 6 lines
I am probably biased by Arm "World" implementation of this (out of MPC), where CPU and SMMU play this role, instead of an external component.
Going back to MPC, the translation is still deterministic and not based on type of access. From what I understand, MPC can statically forbid accesses to specific blocks, simply based on original address.
ARMv9-A GPC verifies permission within the CPU MMU and IOMMU. It performs checks when the memory transaction is travel from the source (such as a CPU or DMA) toward the system bus. In contrast, RISC-V wgChecker is positioned directly in front of peripheral devices. It performs checks when the transcations travel from the bus toward the target devices. In this regard, the ARMv8-A TZASC [1] and ARMv8-M MPC are architecturally similar to the RISC-V wgChecker.
We can monitor all memory transactions in the SoC by implementing security filters at either every transaction source or every transaction device. These 2 designs are both reasonable, representing different approaches to SoC security architecture.
ARMv8-A TZASC [1] is also the target-side filter and includes RW permission checks. While the TZASC device is not supported in QEMU now, it could also leverage these generic code changes when implementing it. Target-side filtering with RW permission checks is not a RISC-V only design.
Quoted 29 lines
Quoted 5 lines
Quoted 4 lines
An alternative would be to treat all accesses as MMIO, but I guess your goal here is to optimize the code path where we access RAM?
Quoted 14 lines
If the downstream region is a memory region, it will update the TLB flags and vaddr in
addr_idxfor the successful permissions of IOMMU region.
To explain further: In the alternative approach, we would obtain the downstream region, IOMMU permissions, and theblocked_ioregion from the IOMMU translation function (which would require an additional return value or API to get theblocked_ioregion). The TLB entry will handle the downstream region as a non-IOMMU region but will only update the TLB flags for the IOMMU permissions; it will also store the permissions and theblocked_ioregion. The slow-path code checks the IOMMU permissions. If permission is denied, it will perform the transaction on theblocked_ioregion instead.
We can remove the lazy IOMMU translation if using an alternative approach.What I was suggesting in my question was to force any access to a MemoryRegion handled by a wgChecker to go through a read or write callback, and to do the actual check there.
For instance, MPC redirects blocked calls to:
static const MemoryRegionOpstz_mpc_mem_blocked_ops= {
.read_with_attrs =tz_mpc_mem_blocked_read, .write_with_attrs =tz_mpc_mem_blocked_write,
Quoted 8 lines
So I was suggesting something like:
static const MemoryRegionOpswgchecker_ops= {
.read_with_attrs =wgchecker_mem_read,
.write_with_attrs =wgchecker_mem_write,And redirect all read/write to those callbacks, thus turning the whole range into an MMIO range. Thus my original question to understand if your main concern is runtime performance or not.
Yes, runtime performance is also critical to us.
We have positioned the wgChecker in front of the DRAM [2] to partition the memory for each world.
If using the slow path for DRAM access, Linux will be too slow to boot.
[2] Add WG support to virt machine:
https://patchew.org/QEMU/[email protected]/[email protected]/
Quoted 25 lines
Quoted 14 lines
Quoted 8 lines
Why can't you reuse existing page protection mechanism for this, authorizing read or write? WorldChecker just seems to be an additional check on top of existing translation. The fact it's an "additional" device is a design/implementation details, and could simply be part of page protection mechanism. It might require some additional plumbing when an interrupt is raised though, to redirect this correctly instead of signaling CPU like it would normally do.
Quoted 5 lines
The fact is does different action based on read/write attribute does not really fit very well with existing implementation, as you noticed. And I wonder if it's worth changing the global design just to optimize this (optional) use case for RISC-V.
Quoted 10 lines
In the SoC architecture, the wgCheckers are positioned in front of devices (either memory or MMIO). When the CPU or DMA sends transactions to the device, the device's wgChecker first performs a permission check to determine if the transaction should be forwarded. If we move this check to the architecture's
tlb_fill()function, how would the CPU code determine if transactions were sent to the device (or to the upstream region of the wgChecker)? The CPU code would need to be aware of the memory tree hierarchy to do that, which I believe is more difficult to implement.
Quoted 9 lines
The memory hierarchy has to be known anyway by the component dealing with that. Currently, TLB is responsible for it, iterating through the different regions. However, it could be wgChecker code that does that, or
tlb_fill()for RISC-V.My only concern with existing design is that it pushes all that on generic TLB code, for a feature that is optional and only used by RISC-V, but still impacting all architectures.
I don't think current address_space/flatview APIs can determine if a PA will access an IOMMUMemoryRegion and return that specific region. To perform this check in the tlb_fill() or wgChecker device, I would need to add this new API to get the correct wgChecker instance and perform the permission check of it. Thus, this approach still requires modifying the generic code to add the new address_space API.
I can try my best to minimize the changes of generic TLB code, but it is impossible to support wgChecker w/o any modification of generic code. Original MPC patchset also adds the CPU-side IOMMU region support to address_space_translate_for_iotlb() [3] and adds the TCGIOMMUNotifier.
My v1 patchset has fewer modifications of generic TLB code, but it relies on ping-pong TLB entries for RW permission seperately. It is a little tricky and may not be easy to maintain. I tried to formalize the changes of TLB entry for the IOMMU region with RW permission in v2 patchset via lazy IOMMU translation.
[3] https://lists.gnu.org/archive/html/qemu-devel/2018-06/msg00666.html
Quoted 3 lines
It's not a no, I don't have any authority on this part of codebase, but just a question to understand why it can't be solved another way that would be RISC-V specific.
As I mentioned above, ARMv8-A TZASC also has a similar design.
Quoted 116 lines
Quoted 11 lines
In the current QEMU architecture, when a security protection device sits in front of a device, placing it within the memory tree seems to be the most suitable approach, similar to the ARM MPC device. The address_space*() API can check if a transaction will be forwarded to the device and perform the permission check via the IOMMU region. Both the CPU-side
address_space_translate_for_iotlb()and the DMA-sideaddress_space_translate_iommu()handle this. The only missing component is that the CPU TLB cannot handle RWX permission checks for IOMMU regions within the memory tree.I understand this and what you want.
I'm really open to it if anyone else has feedback on this, and help decide if it's worth changing generic TLB code for this use case.Quoted 100 lines
Quoted 100 lines
Quoted 100 lines
Quoted 99 lines
I'm not against the goal of this series, but trying to understand why it went in this direction, which complexify this already complex code path.
Quoted 91 lines
To support such IOMMUMemoryRegion behavior in the CPU path, the design of IOMMU translation must be updated:
1. address_space_translate*() must now pass the
access_typeto IOMMUMemoryRegion.
2. Since IOMMU translation results are too complex to be fully stored in the CPU TLB. we will defer the translation until the actual access occurs. Also, TLB is allowed to store the untranslated IOMMU region.To implement deferred IOMMU translation, this patchset introduces the following changes:
1.
tlb_set_page_full()no longer translates the IOMMU region immediately. Instead, it stores the untranslated region directly in the TLB. A new slow-path flag,TLB_IOMMU, is introduced to force access into the slow path when a region has not yet been translated in the TLB entry.2. When the CPU utilizes a TLB entry in the slow path, it should perform the lazy IOMMU translation of the
access_typefirst. The resulting translated region and access type are stored in CPUTLBEntryFull. Since the slow path always performs lazy translation first, we can switch the CPUTLBEntryFull content to the correct access type before use.3. To accelerate memory access in the fast path, lazy translation can update the addend of the CPUTLBEntry when translating the region to a host memory region. We restrict the IOMMU region to have a single non-zero 'addend' across all permissions. If a second 'addend' is present for a CPUTLBEntry, QEMU will trigger an assertion. This limitation is sufficient for security devices, as their "secondary" region is typically an IO region used to emulate device error handling when access is rejected.
4. To support non-slow TLB flags, lazy translation can update the TLB flags in the '
addr_idx' of the CPUTLBEntry. Lazy translation only updates the flags for the permissions specified in @prot. This ensures that eachaccess_typeof a translated region to maintains independent TLB flags. For example,TLB_DIRTYof memory region will not be "polluted" from other permission that translated to different region.Both RISC-V wgChecker [1] and RISC-V IOPMP [2] devices require this feature.
[1] RISC-V WG:
https://patchew.org/QEMU/[email protected]/
[2] RISC-V IOPMP:
https://patchew.org/QEMU/[email protected]/Changed since v1:
- Remove the ping-pong TLB entry behavior. Instead, defer the IOMMU translation until actual access in the CPU path. Provide a IOMMU lazy translation function with the special handling of 'addend' and 'addr_idx' fields of CPUTLBEntry.
- Fix the checkpatch warning.Jim Shu (5):
accel/tcg: Passaccess_typeas an argument of tlb_set_page*() accel/tcg: address_space_translate*() will pass the correct
iommu_flags
accel/tcg: Provide early AS translate function accel/tcg: Add IOMMU lazy translation function accel/tcg: Support IOMMU lazy translation in CPU TLB
accel/tcg/cputlb.c| 247 +++++++++++++++++++++++++--
include/accel/tcg/iommu.h| 17 +-
include/exec/cputlb.h| 11 +-
include/exec/tlb-flags.h| 4 +-
include/hw/core/cpu.h| 15 ++
system/physmem.c| 60 ++++++-
target/alpha/helper.c| 2 +-
target/avr/helper.c| 3 +-
target/hppa/mem_helper.c| 1 -
target/i386/tcg/system/excp_helper.c| 3 +-
target/loongarch/tcg/tlb_helper.c| 2 +-
target/m68k/helper.c| 10 +-
target/microblaze/helper.c| 8 +-
target/mips/tcg/system/tlb_helper.c| 4 +-
target/or1k/mmu.c| 2 +-
target/ppc/mmu_helper.c| 2 +-
target/riscv/cpu_helper.c| 2 +-
target/rx/cpu.c| 3 +-
target/s390x/tcg/excp_helper.c| 2 +-
target/sh4/helper.c| 3 +-
target/sparc/mmu_helper.c| 6 +-
target/tricore/helper.c| 2 +-
target/xtensa/helper.c| 3 +-
23 files changed, 354 insertions(+), 58 deletions(-)
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Regards,
JimRegards,
Pierrick
Regards,
Jim
Quoted 102 lines · Jim Shu
Quoted 85 lines · Pierrick Bouvier
Quoted 69 lines · Jim Shu
Quoted 67 lines · Pierrick Bouvier
Quoted 36 lines · Jim Shu
On Thu, Apr 23, 2026 at 12:01 AM Pierrick Bouvier
<[email protected]> wrote:Hi Pierrick,
Thanks for discussing the design!
Quoted 13 lines
Hi Jim,
Quoted 8 lines · Jim Shu
Note: v1 title is "accel/tcg: Pass the
access_typeto IOMMUMemoryRegion"Incoming security protection devices feature more complex IOMMUMemoryRegion implementation in the CPU path than ARM MPC device. For example, RISC-V wgChecker [1] may permit the access with only RO/WO permissions. Consequently, the IOMMUMemoryRegion could return different sections for read & write access.
Quoted 7 lines
The consequence is not directly implied for me.
Why having a single translation and page protection handle read/write access is not enough here?
What is the (real world) use case to return different physical memory locations depending on read/write access for a given virtual address?
When permission is granted, the wgChecker device returns the original region of the address, called the downstream region
When permission is denied, the wgChecker device returns a special MemoryRegion for error handling, called theblocked_ioregion). This region may trigger an IRQ and a bus error. Additionally, memory accesses to this region will result in 'read 0, write ignored' rather than triggering exceptions from the MMU or MPU.Quoted 9 lines
Consequently, implementing RWX permission checks on security protection devices may return different regions (either downstream or
blocked_io) depending on the access type.
This design is similar to the existing ARM MPC device (hw/misc/tz-mpc.c). The primary difference is that the MPC only checks the physical address rather than RWX permissions, meaning it returns either the downstream orblocked_ioregion for a single address regardless of the access type.It is indeed, a big difference. Translation with MPC device still results in a single address space being chosen.
Quoted 15 lines
I also considered an alternative design where CPUTLBEntryFull stores both the successful permission and the
blocked_ioregion of the IOMMU region.
In this scenario, the slow-path code utilizing CPUTLBEntryFull would check permissions and return theblocked_ioregion if access is deniedHowever, the
address_space_translate_iommu()implementation supports recursive IOMMU region translation.
if multiple IOMMU regions are encountered during a single address translation, storing only the first region's permissions is insufficient.
Ultimately, we still face a situation where RWX permissions might return different regions separately (e.g., downstream,blocked_io_iommu1, andblocked_io_iommu2).Quoted 8 lines
Quoted 3 lines
The "
blocked_io_iommu_X" is a consequence of the current choice of implementation, but I still don't see why it's an absolute necessity.I am open to removing it if the community agrees. I believe platforms with the ARM MPC do not use multiple IOMMU regions when translating a single address.
I am not expert on the topic, but it seems MPC is mostly used with microcontrollers with trustzone and is much more limited in scope than WorldChecker. WorldChecker seems to be a mix of MMU + IOMMU + something like Arm Granule Protection Table in a single external component.
Quoted 6 lines
I am probably biased by Arm "World" implementation of this (out of MPC), where CPU and SMMU play this role, instead of an external component.
Going back to MPC, the translation is still deterministic and not based on type of access. From what I understand, MPC can statically forbid accesses to specific blocks, simply based on original address.
ARMv9-A GPC verifies permission within the CPU MMU and IOMMU. It performs checks when the memory transaction is travel from the source (such as a CPU or DMA) toward the system bus. In contrast, RISC-V wgChecker is positioned directly in front of peripheral devices. It performs checks when the transcations travel from the bus toward the target devices. In this regard, the ARMv8-A TZASC [1] and ARMv8-M MPC are architecturally similar to the RISC-V wgChecker.
Quoted 5 lines
We can monitor all memory transactions in the SoC by implementing security filters at either every transaction source or every transaction device. These 2 designs are both reasonable, representing different approaches to SoC security architecture.
Sure, I was not implying anything is wrong here, just questioning on why it was implemented this particular way in QEMU, and which alternatives are possible.
Quoted 6 lines
ARMv8-A TZASC [1] is also the target-side filter and includes RW permission checks. While the TZASC device is not supported in QEMU now, it could also leverage these generic code changes when implementing it. Target-side filtering with RW permission checks is not a RISC-V only design.
That's an excellent argument for bringing this in generic TLB management 👍!
Quoted 40 lines
Quoted 29 lines
Quoted 5 lines
Quoted 4 lines
An alternative would be to treat all accesses as MMIO, but I guess your goal here is to optimize the code path where we access RAM?
Quoted 14 lines
If the downstream region is a memory region, it will update the TLB flags and vaddr in
addr_idxfor the successful permissions of IOMMU region.
To explain further: In the alternative approach, we would obtain the downstream region, IOMMU permissions, and theblocked_ioregion from the IOMMU translation function (which would require an additional return value or API to get theblocked_ioregion). The TLB entry will handle the downstream region as a non-IOMMU region but will only update the TLB flags for the IOMMU permissions; it will also store the permissions and theblocked_ioregion. The slow-path code checks the IOMMU permissions. If permission is denied, it will perform the transaction on theblocked_ioregion instead.
We can remove the lazy IOMMU translation if using an alternative approach.What I was suggesting in my question was to force any access to a MemoryRegion handled by a wgChecker to go through a read or write callback, and to do the actual check there.
For instance, MPC redirects blocked calls to:
static const MemoryRegionOpstz_mpc_mem_blocked_ops= {
.read_with_attrs =tz_mpc_mem_blocked_read, .write_with_attrs =tz_mpc_mem_blocked_write,Quoted 8 lines
So I was suggesting something like:
static const MemoryRegionOpswgchecker_ops= {
.read_with_attrs =wgchecker_mem_read,
.write_with_attrs =wgchecker_mem_write,And redirect all read/write to those callbacks, thus turning the whole range into an MMIO range. Thus my original question to understand if your main concern is runtime performance or not.
Quoted 8 lines
Yes, runtime performance is also critical to us.
We have positioned the wgChecker in front of the DRAM [2] to partition the memory for each world.
If using the slow path for DRAM access, Linux will be too slow to boot.[2] Add WG support to virt machine:
https://patchew.org/QEMU/[email protected]/[email protected]/
Sure, makes sense.
Quoted 48 lines
Quoted 25 lines
Quoted 14 lines
Quoted 8 lines
Why can't you reuse existing page protection mechanism for this, authorizing read or write? WorldChecker just seems to be an additional check on top of existing translation. The fact it's an "additional" device is a design/implementation details, and could simply be part of page protection mechanism. It might require some additional plumbing when an interrupt is raised though, to redirect this correctly instead of signaling CPU like it would normally do.
Quoted 5 lines
The fact is does different action based on read/write attribute does not really fit very well with existing implementation, as you noticed. And I wonder if it's worth changing the global design just to optimize this (optional) use case for RISC-V.
Quoted 10 lines
In the SoC architecture, the wgCheckers are positioned in front of devices (either memory or MMIO). When the CPU or DMA sends transactions to the device, the device's wgChecker first performs a permission check to determine if the transaction should be forwarded. If we move this check to the architecture's
tlb_fill()function, how would the CPU code determine if transactions were sent to the device (or to the upstream region of the wgChecker)? The CPU code would need to be aware of the memory tree hierarchy to do that, which I believe is more difficult to implement.Quoted 9 lines
The memory hierarchy has to be known anyway by the component dealing with that. Currently, TLB is responsible for it, iterating through the different regions. However, it could be wgChecker code that does that, or
tlb_fill()for RISC-V.My only concern with existing design is that it pushes all that on generic TLB code, for a feature that is optional and only used by RISC-V, but still impacting all architectures.
I don't think current address_space/flatview APIs can determine if a PA will access an IOMMUMemoryRegion and return that specific region. To perform this check in the
tlb_fill()or wgChecker device, I would need to add this new API to get the correct wgChecker instance and perform the permission check of it. Thus, this approach still requires modifying the generic code to add the newaddress_spaceAPI.I can try my best to minimize the changes of generic TLB code, but it is impossible to support wgChecker w/o any modification of generic code. Original MPC patchset also adds the CPU-side IOMMU region support to
address_space_translate_for_iotlb()[3] and adds the TCGIOMMUNotifier.
Quoted 6 lines
My v1 patchset has fewer modifications of generic TLB code, but it relies on ping-pong TLB entries for RW permission seperately. It is a little tricky and may not be easy to maintain. I tried to formalize the changes of TLB entry for the IOMMU region with RW permission in v2 patchset via lazy IOMMU translation.
Your approach is good, and I was just wanted to understand why it's the right way to go, and potential other use cases for this.
Quoted 129 lines
[3] https://lists.gnu.org/archive/html/qemu-devel/2018-06/msg00666.html
Quoted 3 lines
It's not a no, I don't have any authority on this part of codebase, but just a question to understand why it can't be solved another way that would be RISC-V specific.
As I mentioned above, ARMv8-A TZASC also has a similar design.
Quoted 120 lines
Quoted 11 lines
In the current QEMU architecture, when a security protection device sits in front of a device, placing it within the memory tree seems to be the most suitable approach, similar to the ARM MPC device. The address_space*() API can check if a transaction will be forwarded to the device and perform the permission check via the IOMMU region. Both the CPU-side
address_space_translate_for_iotlb()and the DMA-sideaddress_space_translate_iommu()handle this. The only missing component is that the CPU TLB cannot handle RWX permission checks for IOMMU regions within the memory tree.I understand this and what you want.
I'm really open to it if anyone else has feedback on this, and help decide if it's worth changing generic TLB code for this use case.Quoted 103 lines
Quoted 103 lines
Quoted 102 lines
Quoted 4 lines
Quoted 95 lines
I'm not against the goal of this series, but trying to understand why it went in this direction, which complexify this already complex code path.
Quoted 91 lines
To support such IOMMUMemoryRegion behavior in the CPU path, the design of IOMMU translation must be updated:
1. address_space_translate*() must now pass the
access_typeto IOMMUMemoryRegion.
2. Since IOMMU translation results are too complex to be fully stored in the CPU TLB. we will defer the translation until the actual access occurs. Also, TLB is allowed to store the untranslated IOMMU region.To implement deferred IOMMU translation, this patchset introduces the following changes:
1.
tlb_set_page_full()no longer translates the IOMMU region immediately. Instead, it stores the untranslated region directly in the TLB. A new slow-path flag,TLB_IOMMU, is introduced to force access into the slow path when a region has not yet been translated in the TLB entry.2. When the CPU utilizes a TLB entry in the slow path, it should perform the lazy IOMMU translation of the
access_typefirst. The resulting translated region and access type are stored in CPUTLBEntryFull. Since the slow path always performs lazy translation first, we can switch the CPUTLBEntryFull content to the correct access type before use.3. To accelerate memory access in the fast path, lazy translation can update the addend of the CPUTLBEntry when translating the region to a host memory region. We restrict the IOMMU region to have a single non-zero 'addend' across all permissions. If a second 'addend' is present for a CPUTLBEntry, QEMU will trigger an assertion. This limitation is sufficient for security devices, as their "secondary" region is typically an IO region used to emulate device error handling when access is rejected.
4. To support non-slow TLB flags, lazy translation can update the TLB flags in the '
addr_idx' of the CPUTLBEntry. Lazy translation only updates the flags for the permissions specified in @prot. This ensures that eachaccess_typeof a translated region to maintains independent TLB flags. For example,TLB_DIRTYof memory region will not be "polluted" from other permission that translated to different region.Both RISC-V wgChecker [1] and RISC-V IOPMP [2] devices require this feature.
[1] RISC-V WG:
https://patchew.org/QEMU/[email protected]/
[2] RISC-V IOPMP:
https://patchew.org/QEMU/[email protected]/Changed since v1:
- Remove the ping-pong TLB entry behavior. Instead, defer the IOMMU translation until actual access in the CPU path. Provide a IOMMU lazy translation function with the special handling of 'addend' and 'addr_idx' fields of CPUTLBEntry.
- Fix the checkpatch warning.Jim Shu (5):
accel/tcg: Passaccess_typeas an argument of tlb_set_page*() accel/tcg: address_space_translate*() will pass the correct
iommu_flags
accel/tcg: Provide early AS translate function accel/tcg: Add IOMMU lazy translation function accel/tcg: Support IOMMU lazy translation in CPU TLB
accel/tcg/cputlb.c| 247 +++++++++++++++++++++++++--
include/accel/tcg/iommu.h| 17 +-
include/exec/cputlb.h| 11 +-
include/exec/tlb-flags.h| 4 +-
include/hw/core/cpu.h| 15 ++
system/physmem.c| 60 ++++++-
target/alpha/helper.c| 2 +-
target/avr/helper.c| 3 +-
target/hppa/mem_helper.c| 1 -
target/i386/tcg/system/excp_helper.c| 3 +-
target/loongarch/tcg/tlb_helper.c| 2 +-
target/m68k/helper.c| 10 +-
target/microblaze/helper.c| 8 +-
target/mips/tcg/system/tlb_helper.c| 4 +-
target/or1k/mmu.c| 2 +-
target/ppc/mmu_helper.c| 2 +-
target/riscv/cpu_helper.c| 2 +-
target/rx/cpu.c| 3 +-
target/s390x/tcg/excp_helper.c| 2 +-
target/sh4/helper.c| 3 +-
target/sparc/mmu_helper.c| 6 +-
target/tricore/helper.c| 2 +-
target/xtensa/helper.c| 3 +-
23 files changed, 354 insertions(+), 58 deletions(-)Regards,
Jim
Quoted 5 lines
Quoted 2 lines
Regards,
PierrickRegards,
Jim
Regards,
Pierrick
Adding Peter, who might have a good opinion on it since he worked on MPC implementation.
Quoted 99 lines · Jim Shu
Note: v1 title is "accel/tcg: Pass the
access_typeto IOMMUMemoryRegion"Incoming security protection devices feature more complex IOMMUMemoryRegion implementation in the CPU path than ARM MPC device. For example, RISC-V wgChecker [1] may permit the access with only RO/WO permissions. Consequently, the IOMMUMemoryRegion could return different sections for read & write access.
To support such IOMMUMemoryRegion behavior in the CPU path, the design of IOMMU translation must be updated:
1. address_space_translate*() must now pass the
access_typeto IOMMUMemoryRegion.
2. Since IOMMU translation results are too complex to be fully stored in the CPU TLB. we will defer the translation until the actual access occurs. Also, TLB is allowed to store the untranslated IOMMU region.To implement deferred IOMMU translation, this patchset introduces the following changes:
1.
tlb_set_page_full()no longer translates the IOMMU region immediately. Instead, it stores the untranslated region directly in the TLB. A new slow-path flag,TLB_IOMMU, is introduced to force access into the slow path when a region has not yet been translated in the TLB entry.2. When the CPU utilizes a TLB entry in the slow path, it should perform the lazy IOMMU translation of the
access_typefirst. The resulting translated region and access type are stored in CPUTLBEntryFull. Since the slow path always performs lazy translation first, we can switch the CPUTLBEntryFull content to the correct access type before use.3. To accelerate memory access in the fast path, lazy translation can update the addend of the CPUTLBEntry when translating the region to a host memory region. We restrict the IOMMU region to have a single non-zero 'addend' across all permissions. If a second 'addend' is present for a CPUTLBEntry, QEMU will trigger an assertion. This limitation is sufficient for security devices, as their "secondary" region is typically an IO region used to emulate device error handling when access is rejected.
4. To support non-slow TLB flags, lazy translation can update the TLB flags in the '
addr_idx' of the CPUTLBEntry. Lazy translation only updates the flags for the permissions specified in @prot. This ensures that eachaccess_typeof a translated region to maintains independent TLB flags. For example,TLB_DIRTYof memory region will not be "polluted" from other permission that translated to different region.Both RISC-V wgChecker [1] and RISC-V IOPMP [2] devices require this feature.
[1] RISC-V WG:
https://patchew.org/QEMU/[email protected]/
[2] RISC-V IOPMP:
https://patchew.org/QEMU/[email protected]/Changed since v1:
- Remove the ping-pong TLB entry behavior. Instead, defer the IOMMU translation until actual access in the CPU path. Provide a IOMMU lazy translation function with the special handling of 'addend' and 'addr_idx' fields of CPUTLBEntry.
- Fix the checkpatch warning.Jim Shu (5):
accel/tcg: Passaccess_typeas an argument of tlb_set_page*() accel/tcg: address_space_translate*() will pass the correct
iommu_flags
accel/tcg: Provide early AS translate function accel/tcg: Add IOMMU lazy translation function accel/tcg: Support IOMMU lazy translation in CPU TLBaccel/tcg/cputlb.c | 247 +++++++++++++++++++++++++-- include/accel/tcg/iommu.h | 17 +- include/exec/cputlb.h | 11 +- include/exec/tlb-flags.h | 4 +- include/hw/core/cpu.h | 15 ++ system/physmem.c | 60 ++++++- target/alpha/helper.c | 2 +- target/avr/helper.c | 3 +- target/hppa/mem_helper.c | 1 - target/i386/tcg/system/excp_helper.c | 3 +- target/loongarch/tcg/tlb_helper.c | 2 +- target/m68k/helper.c | 10 +- target/microblaze/helper.c | 8 +- target/mips/tcg/system/tlb_helper.c | 4 +- target/or1k/mmu.c | 2 +- target/ppc/mmu_helper.c | 2 +- target/riscv/cpu_helper.c | 2 +- target/rx/cpu.c | 3 +- target/s390x/tcg/excp_helper.c | 2 +- target/sh4/helper.c | 3 +- target/sparc/mmu_helper.c | 6 +- target/tricore/helper.c | 2 +- target/xtensa/helper.c | 3 +- 23 files changed, 354 insertions(+), 58 deletions(-)
Quoted 90 lines · Jim Shu
Note: v1 title is "accel/tcg: Pass the
access_typeto IOMMUMemoryRegion"Incoming security protection devices feature more complex IOMMUMemoryRegion implementation in the CPU path than ARM MPC device. For example, RISC-V wgChecker [1] may permit the access with only RO/WO permissions. Consequently, the IOMMUMemoryRegion could return different sections for read & write access.
To support such IOMMUMemoryRegion behavior in the CPU path, the design of IOMMU translation must be updated:
1. address_space_translate*() must now pass the
access_typeto IOMMUMemoryRegion.
2. Since IOMMU translation results are too complex to be fully stored in the CPU TLB. we will defer the translation until the actual access occurs. Also, TLB is allowed to store the untranslated IOMMU region.To implement deferred IOMMU translation, this patchset introduces the following changes:
1.
tlb_set_page_full()no longer translates the IOMMU region immediately. Instead, it stores the untranslated region directly in the TLB. A new slow-path flag,TLB_IOMMU, is introduced to force access into the slow path when a region has not yet been translated in the TLB entry.2. When the CPU utilizes a TLB entry in the slow path, it should perform the lazy IOMMU translation of the
access_typefirst. The resulting translated region and access type are stored in CPUTLBEntryFull. Since the slow path always performs lazy translation first, we can switch the CPUTLBEntryFull content to the correct access type before use.3. To accelerate memory access in the fast path, lazy translation can update the addend of the CPUTLBEntry when translating the region to a host memory region. We restrict the IOMMU region to have a single non-zero 'addend' across all permissions. If a second 'addend' is present for a CPUTLBEntry, QEMU will trigger an assertion. This limitation is sufficient for security devices, as their "secondary" region is typically an IO region used to emulate device error handling when access is rejected.
4. To support non-slow TLB flags, lazy translation can update the TLB flags in the '
addr_idx' of the CPUTLBEntry. Lazy translation only updates the flags for the permissions specified in @prot. This ensures that eachaccess_typeof a translated region to maintains independent TLB flags. For example,TLB_DIRTYof memory region will not be "polluted" from other permission that translated to different region.Both RISC-V wgChecker [1] and RISC-V IOPMP [2] devices require this feature.
[1] RISC-V WG:
https://patchew.org/QEMU/[email protected]/
[2] RISC-V IOPMP:
https://patchew.org/QEMU/[email protected]/Changed since v1:
- Remove the ping-pong TLB entry behavior. Instead, defer the IOMMU translation until actual access in the CPU path. Provide a IOMMU lazy translation function with the special handling of 'addend' and 'addr_idx' fields of CPUTLBEntry.
- Fix the checkpatch warning.Jim Shu (5):
accel/tcg: Passaccess_typeas an argument of tlb_set_page*() accel/tcg: address_space_translate*() will pass the correct
iommu_flags
accel/tcg: Provide early AS translate function accel/tcg: Add IOMMU lazy translation function accel/tcg: Support IOMMU lazy translation in CPU TLBaccel/tcg/cputlb.c | 247 +++++++++++++++++++++++++-- include/accel/tcg/iommu.h | 17 +- include/exec/cputlb.h | 11 +- include/exec/tlb-flags.h | 4 +- include/hw/core/cpu.h | 15 ++ system/physmem.c | 60 ++++++- target/alpha/helper.c | 2 +- target/avr/helper.c | 3 +- target/hppa/mem_helper.c | 1 - target/i386/tcg/system/excp_helper.c | 3 +- target/loongarch/tcg/tlb_helper.c | 2 +- target/m68k/helper.c | 10 +- target/microblaze/helper.c | 8 +- target/mips/tcg/system/tlb_helper.c | 4 +- target/or1k/mmu.c | 2 +- target/ppc/mmu_helper.c | 2 +-
Quoted 9 lines
target/riscv/cpu_helper.c | 2 +- target/rx/cpu.c | 3 +- target/s390x/tcg/excp_helper.c | 2 +- target/sh4/helper.c | 3 +- target/sparc/mmu_helper.c | 6 +- target/tricore/helper.c | 2 +- target/xtensa/helper.c | 3 +- 23 files changed, 354 insertions(+), 58 deletions(-)
For the series: