cputlb: document iotlb.addr, fix txfail physaddr
cover cputlb: document iotlb.addr, fix txfail physaddr
This patchset is two vaguely related patches that I wrote while I was trying to understand the cputlb code enough to add support for small-MPU-regions for v7M/v8M.
Patch 1 is just a docs comment patch, describing what the CPUIOTLBEntry 'addr' field actually contains.
Patch 2 fixes a bug that doesn't yet have any visible effects (we were passing cpu_transaction_failed() the wrong value for the physaddr) roughly as suggested by Paolo back in
https://lists.gnu.org/archive/html/qemu-devel/2017-12/msg02419.html
thanks
-- PMM
Peter Maydell (2):
cpu-defs.h: Document CPUIOTLBEntry 'addr' field
cputlb: Pass cpu_transaction_failed() the correct physaddr
include/exec/cpu-defs.h | 9 +++++++ include/exec/exec-all.h | 13 ++++++++-- accel/tcg/cputlb.c | 56 +++++++++++++++++++++++++++++++---------- exec.c | 5 ++-- 4 files changed, 66 insertions(+), 17 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/2 cpu-defs.h: Document CPUIOTLBEntry 'addr' field
The 'addr' field in the CPUIOTLBEntry struct has a rather non-obvious use; add a comment documenting it (reverse-engineered from what the code that sets it is doing).
--- include/exec/cpu-defs.h | 9 +++++++++ accel/tcg/cputlb.c | 12 ++++++++++++ 2 files changed, 21 insertions(+)
include/exec/cpu-defs.h +9 -0
@@ -127,6 +127,15 @@ QEMU_BUILD_BUG_ON(sizeof(CPUTLBEntry) != (1 << CPU_TLB_ENTRY_BITS));* structs into one.) */ typedef struct CPUIOTLBEntry { +/* +* @addr contains: +* - in the lower TARGET_PAGE_BITS, a physical section number +* - with the lower TARGET_PAGE_BITS masked off, an offset which +* must be added to the virtual address to obtain: +* + the ramaddr_t of the target RAM (if the physical section +* number is PHYS_SECTION_NOTDIRTY or PHYS_SECTION_ROM) +* + the offset within the target MemoryRegion (otherwise) +*/ hwaddr addr;MemTxAttrs attrs; }CPUIOTLBEntry ;
accel/tcg/cputlb.c +12 -0
@@ -664,6 +664,18 @@ void tlb_set_page_with_attrs(CPUState *cpu, target_ulong vaddr, env->iotlb_v[mmu_idx][vidx] = env->iotlb[mmu_idx][index];/* refill the tlb */ +/* +* At this point iotlb contains a physical section number in the lower +* TARGET_PAGE_BITS, and either +* + the ramaddr_t of the page base of the target RAM (if NOTDIRTY or ROM) +* + the offset within section->mr of the page base (otherwise) +* We subtract the vaddr (which is page aligned and thus won't +* disturb the low bits) to give an offset which can be added to the +* (non-page-aligned) vaddr of the eventual memory access to get +* the MemoryRegion offset for the access. Note that the vaddr we +* subtract here is that of the page base, and not the same as the +* vaddr we add back in io_readx()/io_writex()/get_page_addr_code(). +*/ env->iotlb[mmu_idx][index].addr = iotlb - vaddr; env->iotlb[mmu_idx][index].attrs = attrs;
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 1/2] cpu-defs.h: Document CPUIOTLBEntry 'addr' field
Quoted 9 lines · Peter Maydell
The 'addr' field in the CPUIOTLBEntry struct has a rather non-obvious use; add a comment documenting it (reverse-engineered from what the code that sets it is doing).
Signed-off-by Peter Maydell <[email protected]>--- include/exec/cpu-defs.h | 9 +++++++++ accel/tcg/cputlb.c | 12 ++++++++++++ 2 files changed, 21 insertions(+)
r~
Re: [Qemu-devel] [PATCH 1/2] cpu-defs.h: Document CPUIOTLBEntry 'addr' field
In reply to Peter Maydellinclude/exec/cpu-defs.h QEMU_BUILD_BUG_ON(sizeof(CPUTLBEntry) != (1 << CPU_TLB_ENTRY_BITS)); · line 135
Quoted 7 lines · Peter Maydell
typedef struct CPUIOTLBEntry {
include/exec/cpu-defs.h +6
-0+/* +* @addr contains: +* - in the lower TARGET_PAGE_BITS, a physical section number +* - with the lower TARGET_PAGE_BITS masked off, an offset which +* must be added to the virtual address to obtain: +* + the ramaddr_t of the target RAM (if the physical section
s/ramaddr_t/ram_addr_t/ ? Also in cputlb.c:
accel/tcg/cputlb.c void tlb_set_page_with_attrs(CPUState *cpu, target_ulong vaddr, · line 670
Quoted 2 lines
accel/tcg/cputlb.c +2
-0+* TARGET_PAGE_BITS, and either +* + the ramaddr_t of the page base of the target RAM (if NOTDIRTY or ROM)
Thanks,
Emilio
PATCH 2/2 cputlb: Pass cpu_transaction_failed() the correct physaddr
In reply to Peter MaydellThe API for cpu_transaction_failed() says that it takes the physical address for the failed transaction. However we were actually passing it the offset within the target MemoryRegion. We don't currently have any target CPU implementations of this hook that require the physical address; fix this bug so we don't get confused if we ever do add one.
--- include/exec/exec-all.h | 13 ++++++++++-- accel/tcg/cputlb.c | 44 +++++++++++++++++++++++++++++------------ exec.c | 5 +++-- 3 files changed, 45 insertions(+), 17 deletions(-)
include/exec/exec-all.h +11 -2
@@ -437,8 +437,17 @@ void tb_lock_reset(void);#if !defined(CONFIG_USER_ONLY ) -struct MemoryRegion *iotlb_to_region (CPUState *cpu, -hwaddr index,MemTxAttrs attrs); +/** +* iotlb_to_section: +* @cpu: CPU performing the access +* @index: TCG CPU IOTLB entry +* +* Given a TCG CPU IOTLB entry, return the MemoryRegionSection that +* it refers to. @index will have been initially created and returned +* by memory_region_section_get_iotlb(). +*/ +struct MemoryRegionSection *iotlb_to_section (CPUState *cpu, +hwaddr index,MemTxAttrs attrs);void tlb_fill (CPUState *cpu,target_ulong addr,int size,MMUAccessType access_type,int mmu_idx,uintptr_t retaddr);
accel/tcg/cputlb.c +31 -13
101 lines not on this page · raw message
exec.c +3 -2
@@ -2897,14 +2897,15 @@ static const MemoryRegionOps readonly_mem_ops = { }, }; -MemoryRegion *iotlb_to_region (CPUState *cpu,hwaddr index,MemTxAttrs attrs) +MemoryRegionSection *iotlb_to_section (CPUState *cpu, +hwaddr index,MemTxAttrs attrs) {int asidx =cpu_asidx_from_attrs (cpu, attrs);CPUAddressSpace *cpuas = &cpu->cpu_ases[asidx];AddressSpaceDispatch *d =atomic_rcu_read (&cpuas->memory_dispatch);MemoryRegionSection *sections = d->map.sections; -return sections[index & ~TARGET_PAGE_MASK ].mr; +return §ions[index & ~TARGET_PAGE_MASK ]; }static void io_mem_init (void )
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 2/2] cputlb: Pass cpu_transaction_failed() the correct physaddr
Quoted 7 lines · Peter Maydell
The API for
cpu_transaction_failed()says that it takes the physical address for the failed transaction. However we were actually passing it the offset within the target MemoryRegion. We don't currently have any target CPU implementations of this hook that require the physical address; fix this bug so we don't get confused if we ever do add one.
Quoted 7 lines
Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Peter Maydell <[email protected]>--- include/exec/exec-all.h | 13 ++++++++++-- accel/tcg/cputlb.c | 44 +++++++++++++++++++++++++++++------------ exec.c | 5 +++-- 3 files changed, 45 insertions(+), 17 deletions(-)
r~
Quoted 7 lines · Peter Maydell
This patchset is two vaguely related patches that I wrote while I was trying to understand the cputlb code enough to add support for small-MPU-regions for v7M/v8M.
Patch 1 is just a docs comment patch, describing what the CPUIOTLBEntry 'addr' field actually contains.
Quoted 7 lines
Patch 2 fixes a bug that doesn't yet have any visible effects (we were passing
cpu_transaction_failed()the wrong value for the physaddr) roughly as suggested by Paolo back in
https://lists.gnu.org/archive/html/qemu-devel/2017-12/msg02419.htmlthanks
-- PMM
Both patches
Quoted 12 lines · Peter Maydell
This patchset is two vaguely related patches that I wrote while I was trying to understand the cputlb code enough to add support for small-MPU-regions for v7M/v8M.
Patch 1 is just a docs comment patch, describing what the CPUIOTLBEntry 'addr' field actually contains.
Patch 2 fixes a bug that doesn't yet have any visible effects (we were passing
cpu_transaction_failed()the wrong value for the physaddr) roughly as suggested by Paolo back in
https://lists.gnu.org/archive/html/qemu-devel/2017-12/msg02419.html
Quoted 6 lines
thanks
-- PMMPeter Maydell (2):
cpu-defs.h: Document CPUIOTLBEntry 'addr' field
cputlb: Passcpu_transaction_failed()the correct physaddr
I'll put these in via target-arm.next (with the ramaddr_t/ram_addr_t typo fixed), unless anybody would prefer them to go via another route.
thanks
-- PMM
Quoted 6 lines · Peter Maydell
Quoted 3 lines
Peter Maydell (2):
cpu-defs.h: Document CPUIOTLBEntry 'addr' field
cputlb: Passcpu_transaction_failed()the correct physaddrI'll put these in via target-arm.next (with the ramaddr_t/ram_addr_t typo fixed), unless anybody would prefer them to go via another route.
Perfect, thanks.
r~