accel/tcg: Fix the comment for CPUTLBEntryFull
PATCH 1/1 accel/tcg: Fix the comment for CPUTLBEntryFull
When memory region is ram, the lower TARGET_PAGE_BITS is not the physical section number. Instead, its value is always 0.
Add comment and assert to make it clear.
--- accel/tcg/cputlb.c | 11 +++++++---- include/exec/cpu-defs.h | 12 ++++++------ 2 files changed, 13 insertions(+), 10 deletions(-)
accel/tcg/cputlb.c +7 -4
@@ -1192,6 +1192,7 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx, 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.
@@ -1254,10 +1255,12 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx,/* refill the tlb */ /* -* At this point iotlb contains a physical section number in the lower -* TARGET_PAGE_BITS, and either -* + the ram_addr_t of the page base of the target RAM (RAM) -* + the offset within section->mr of the page base (I/O, ROMD) +* When memory region is ram, iotlb contains a TARGET_PAGE_BITS +* aligned ram_addr_t of the page base of the target RAM. +* Otherwise, iotlb contains +* - a physical section number in the lower TARGET_PAGE_BITS +* - the offset within section->mr of the page base (I/O, ROMD) with the +* TARGET_PAGE_BITS masked off. * We subtract addr_page (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
include/exec/cpu-defs.h +6 -6
@@ -100,12 +100,12 @@ typedef struct CPUTLBEntryFull { /* * @xlat_section 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 ram_addr_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) + * - For ram, an offset which must be added to the virtual address + * to obtain the ram_addr_t of the target RAM + * - For other memory regions, + * + in the lower TARGET_PAGE_BITS, the physical section number + * + with the TARGET_PAGE_BITS masked off, the offset within + * the target MemoryRegion */ hwaddr xlat_section;
Signature · 1 line
2.17.1
Quoted 10 lines · LIU Zhiwei
When memory region is ram, the lower
TARGET_PAGE_BITSis not the physical section number. Instead, its value is always 0.Add comment and assert to make it clear.
Signed-off-by LIU Zhiwei<[email protected]>--- accel/tcg/cputlb.c | 11 +++++++---- include/exec/cpu-defs.h | 12 ++++++------ 2 files changed, 13 insertions(+), 10 deletions(-)
Queued to tcg-next.
r~
Quoted 52 lines · LIU Zhiwei
When memory region is ram, the lower
TARGET_PAGE_BITSis not the physical section number. Instead, its value is always 0.Add comment and assert to make it clear.
Signed-off-by LIU Zhiwei <[email protected]>--- accel/tcg/cputlb.c | 11 +++++++---- include/exec/cpu-defs.h | 12 ++++++------ 2 files changed, 13 insertions(+), 10 deletions(-)accel/tcg/cputlb.c +7
-4@@ -1192,6 +1192,7 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx, 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. @@ -1254,10 +1255,12 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx,/* refill the tlb */ /* -* At this point iotlb contains a physical section number in the lower -* TARGET_PAGE_BITS, and either -* + the ram_addr_t of the page base of the target RAM (RAM) -* + the offset within section->mr of the page base (I/O, ROMD) +* When memory region is ram, iotlb contains a TARGET_PAGE_BITS +* aligned ram_addr_t of the page base of the target RAM. +* Otherwise, iotlb contains +* - a physical section number in the lower TARGET_PAGE_BITS +* - the offset within section->mr of the page base (I/O, ROMD) with the +* TARGET_PAGE_BITS masked off. * We subtract addr_page (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 include/exec/cpu-defs.h +0
-4@@ -100,12 +100,12 @@ typedef struct CPUTLBEntryFull { /* * @xlat_section 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 ram_addr_t of the target RAM (if the physical section
include/exec/cpu-defs.h line 110
Quoted 10 lines
include/exec/cpu-defs.h +6
-2-* number is PHYS_SECTION_NOTDIRTY or PHYS_SECTION_ROM) -* + the offset within the target MemoryRegion (otherwise) +* - For ram, an offset which must be added to the virtual address +* to obtain the ram_addr_t of the target RAM +* - For other memory regions, +* + in the lower TARGET_PAGE_BITS, the physical section number +* + with the TARGET_PAGE_BITS masked off, the offset within +* the target MemoryRegion */ hwaddr xlat_section;
Someone sent me a test case that triggers the assert() introduced by this commit dff1ab6 ("accel/tcg: Fix the comment for CPUTLBEntryFull") for qemu-system-m68k which is still present in git master. The reproducer is easy:
1. Grab the machine ROM file from https://www.ilande.co.uk/tmp/qemu/tQuadra800.rom
2. Create an empty declaration ROM greater than 4K:
dd if=/dev/zero of=/tmp/badrom bs=512 count=12
3. Start QEMU like this:
qemu-system-m68k -M q800 -bios tQuadra800.rom \
-device nubus-macfb,romfile=/tmp/badromThe QEMU process hits the assert() with the following backtrace:
(gdb) bt
#0 0x00007ffff58a9d3c in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x00007ffff585af32 in raise () from /lib/x86_64-linux-gnu/libc.so.6 #2 0x00007ffff5845472 in abort () from /lib/x86_64-linux-gnu/libc.so.6 #3 0x00007ffff5845395 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #4 0x00007ffff5853e32 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6 #5 0x0000555555942e0a in tlb_set_page_full (cpu=0x55555618d4a0, mmu_idx=0, addr=4244631552, full=0x7fffe7d7f7c0) at ../accel/tcg/cputlb.c:1171 #6 0x00005555559432a0 in tlb_set_page_with_attrs (cpu=0x55555618d4a0, addr=4244631552, paddr=4244631552, attrs=..., prot=7, mmu_idx=0, size=4096) at ../accel/tcg/cputlb.c:1290 #7 0x0000555555943305 in tlb_set_page (cpu=0x55555618d4a0, addr=4244631552, paddr=4244631552, prot=7, mmu_idx=0, size=4096) at ../accel/tcg/cputlb.c:1297 #8 0x000055555588aade in m68k_cpu_tlb_fill (cs=0x55555618d4a0, address=4244635647, size=1, qemu_access_type=MMU_DATA_LOAD, mmu_idx=0, probe=false, retaddr=140734805255937) at ../target/m68k/helper.c:1018 #9 0x0000555555943367 in tlb_fill (cpu=0x55555618d4a0, addr=4244635647, size=1, access_type=MMU_DATA_LOAD, mmu_idx=0, retaddr=140734805255937) at ../accel/tcg/cputlb.c:1315
#10 0x0000555555945d78 in mmu_lookup1 (cpu=0x55555618d4a0, data=0x7fffe7d7fa00, mmu_idx=0, access_type=MMU_DATA_LOAD, ra=140734805255937) at ../accel/tcg/cputlb.c:1713 #11 0x0000555555946081 in mmu_lookup (cpu=0x55555618d4a0, addr=4244635647, oi=3712, ra=140734805255937, type=MMU_DATA_LOAD, l=0x7fffe7d7fa00) at ../accel/tcg/cputlb.c:1803 #12 0x000055555594742b in do_ld1_mmu (cpu=0x55555618d4a0, addr=4244635647, oi=3712, ra=140734805255937, access_type=MMU_DATA_LOAD) at ../accel/tcg/cputlb.c:2377 #13 0x0000555555948f17 in helper_ldub_mmu (env=0x55555618fc60, addr=4244635647, oi=3712, retaddr=140734805255937) at ../accel/tcg/ldst_common.c.inc:19 #14 0x00007fff6013286c in code_gen_buffer ()
#15 0x00005555559308ff in cpu_tb_exec (cpu=0x55555618d4a0, itb=0x7fffa0132480, tb_exit=0x7fffe7d80030) at ../accel/tcg/cpu-exec.c:458
#16 0x000055555593160a in cpu_loop_exec_tb (cpu=0x55555618d4a0, tb=0x7fffa0132480, pc=1082158370, last_tb=0x7fffe7d80040, tb_exit=0x7fffe7d80030) at ../accel/tcg/cpu-exec.c:920 #17 0x000055555593196a in cpu_exec_loop (cpu=0x55555618d4a0, sc=0x7fffe7d800c0) at ../accel/tcg/cpu-exec.c:1041
#18 0x0000555555931a28 in cpu_exec_setjmp (cpu=0x55555618d4a0, sc=0x7fffe7d800c0) at ../accel/tcg/cpu-exec.c:1058
#19 0x0000555555931aaf in cpu_exec (cpu=0x55555618d4a0) at ../accel/tcg/cpu-exec.c:1084
#20 0x00005555559560ad in tcg_cpus_exec (cpu=0x55555618d4a0) at ../accel/tcg/tcg-accel-ops.c:76
#21 0x00005555559575c2 in rr_cpu_thread_fn (arg=0x55555618d4a0) at ../accel/tcg/tcg-accel-ops-rr.c:261
#22 0x0000555555b61f25 in qemu_thread_start (args=0x555556347a10) at ../util/qemu-thread-posix.c:541
#23 0x00007ffff58a8044 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#24 0x00007ffff592861c in ?? () from /lib/x86_64-linux-gnu/libc.so.6
ATB,
Mark.
Quoted 100 lines · Mark Cave-Ayland
Quoted 54 lines · LIU Zhiwei
When memory region is ram, the lower
TARGET_PAGE_BITSis not the physical section number. Instead, its value is always 0.Add comment and assert to make it clear.
Signed-off-by LIU Zhiwei <[email protected]>---
accel/tcg/cputlb.c | 11 +++++++----
include/exec/cpu-defs.h| 12 ++++++------2 files changed, 13 insertions(+), 10 deletions(-)accel/tcg/cputlb.c +1
-1@@ -1192,6 +1192,7 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx, 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. @@ -1254,10 +1255,12 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx, /* refill the tlb */ /* -* At this point iotlb contains a physical section number in the lower
- *TARGET_PAGE_BITS, and either
- * + theram_addr_tof the page base of the target RAM (RAM) - * + the offset withinsection->mrof the page base (I/O, ROMD) + * When memory region is ram, iotlb contains aTARGET_PAGE_BITS+ * alignedram_addr_tof the page base of the target RAM. + * Otherwise, iotlb contains
+ * - a physical section number in the lowerTARGET_PAGE_BITS+ * - the offset withinsection->mrof the page base (I/O, ROMD) with the
+ *TARGET_PAGE_BITSmasked off.
* We subtractaddr_page(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 getinclude/exec/cpu-defs.h +0
-4@@ -100,12 +100,12 @@ typedef struct CPUTLBEntryFull { /* * @xlat_section 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 ram_addr_t of the target RAM (if the physical sectioninclude/exec/cpu-defs.h line 110
Quoted 10 lines
include/exec/cpu-defs.h +6
-2-* number is PHYS_SECTION_NOTDIRTY or PHYS_SECTION_ROM) -* + the offset within the target MemoryRegion (otherwise) +* - For ram, an offset which must be added to the virtual address +* to obtain the ram_addr_t of the target RAM +* - For other memory regions, +* + in the lower TARGET_PAGE_BITS, the physical section number +* + with the TARGET_PAGE_BITS masked off, the offset within +* the target MemoryRegion */ hwaddr xlat_section;Someone sent me a test case that triggers the
assert()introduced by this commit dff1ab6 ("accel/tcg: Fix the comment for CPUTLBEntryFull") for qemu-system-m68k which is still present in git master. The reproducer is easy:1. Grab the machine ROM file from https://www.ilande.co.uk/tmp/qemu/tQuadra800.rom
2. Create an empty declaration ROM greater than 4K:
dd if=/dev/zero of=/tmp/badrom bs=512 count=12
3. Start QEMU like this:
qemu-system-m68k -M q800 -bios tQuadra800.rom \
-device nubus-macfb,romfile=/tmp/badromThe QEMU process hits the
assert()with the following backtrace:(gdb) bt
#00x00007ffff58a9d3cin ?? () from/lib/x86_64-linux-gnu/libc.so.6
#10x00007ffff585af32in raise () from/lib/x86_64-linux-gnu/libc.so.6
#20x00007ffff5845472in abort () from/lib/x86_64-linux-gnu/libc.so.6
#30x00007ffff5845395in ?? () from/lib/x86_64-linux-gnu/libc.so.6
#40x00007ffff5853e32in__assert_fail() from/lib/x86_64-linux-gnu/libc.so.6
#50x0000555555942e0aintlb_set_page_full(cpu=0x55555618d4a0, mmu_idx=0, addr=4244631552, full=0x7fffe7d7f7c0) at../accel/tcg/cputlb.c:1171
#60x00005555559432a0intlb_set_page_with_attrs(cpu=0x55555618d4a0, addr=4244631552, paddr=4244631552, attrs=..., prot=7, mmu_idx=0, size=4096) at../accel/tcg/cputlb.c:1290#70x0000555555943305intlb_set_page(cpu=0x55555618d4a0, addr=4244631552, paddr=4244631552, prot=7, mmu_idx=0, size=4096) at../accel/tcg/cputlb.c:1297
#80x000055555588aadeinm68k_cpu_tlb_fill(cs=0x55555618d4a0, address=4244635647, size=1, qemu_access_type=MMU_DATA_LOAD, mmu_idx=0, probe=false, retaddr=140734805255937) at../target/m68k/helper.c:1018#90x0000555555943367intlb_fill(cpu=0x55555618d4a0, addr=4244635647, size=1, access_type=MMU_DATA_LOAD, mmu_idx=0, retaddr=140734805255937) at../accel/tcg/cputlb.c:1315#100x0000555555945d78inmmu_lookup1(cpu=0x55555618d4a0, data=0x7fffe7d7fa00, mmu_idx=0, access_type=MMU_DATA_LOAD, ra=140734805255937) at../accel/tcg/cputlb.c:1713#110x0000555555946081inmmu_lookup(cpu=0x55555618d4a0, addr=4244635647, oi=3712, ra=140734805255937, type=MMU_DATA_LOAD, l=0x7fffe7d7fa00) at../accel/tcg/cputlb.c:1803#120x000055555594742bindo_ld1_mmu(cpu=0x55555618d4a0, addr=4244635647, oi=3712, ra=140734805255937, access_type=MMU_DATA_LOAD) at../accel/tcg/cputlb.c:2377
#130x0000555555948f17inhelper_ldub_mmu(env=0x55555618fc60, addr=4244635647, oi=3712, retaddr=140734805255937) at ../accel/tcg/ldst_common.c.inc:19
#140x00007fff6013286cincode_gen_buffer()
#150x00005555559308ffincpu_tb_exec(cpu=0x55555618d4a0, itb=0x7fffa0132480, tb_exit=0x7fffe7d80030) at../accel/tcg/cpu-exec.c:458
#160x000055555593160aincpu_loop_exec_tb(cpu=0x55555618d4a0, tb=0x7fffa0132480, pc=1082158370, last_tb=0x7fffe7d80040, tb_exit=0x7fffe7d80030) at../accel/tcg/cpu-exec.c:920
Quoted 9 lines
#17
0x000055555593196aincpu_exec_loop(cpu=0x55555618d4a0, sc=0x7fffe7d800c0) at../accel/tcg/cpu-exec.c:1041#180x0000555555931a28incpu_exec_setjmp(cpu=0x55555618d4a0, sc=0x7fffe7d800c0) at../accel/tcg/cpu-exec.c:1058#190x0000555555931aafincpu_exec(cpu=0x55555618d4a0) at../accel/tcg/cpu-exec.c:1084
#200x00005555559560adintcg_cpus_exec(cpu=0x55555618d4a0) at../accel/tcg/tcg-accel-ops.c:76#210x00005555559575c2inrr_cpu_thread_fn(arg=0x55555618d4a0) at../accel/tcg/tcg-accel-ops-rr.c:261#220x0000555555b61f25inqemu_thread_start(args=0x555556347a10) at../util/qemu-thread-posix.c:541#230x00007ffff58a8044in ?? () from/lib/x86_64-linux-gnu/libc.so.6
#240x00007ffff592861cin ?? () from/lib/x86_64-linux-gnu/libc.so.6
Hi Mark,
The nubus-macfb device create a section not aligned to the TARGET_PAGE_BITS. That is the reason why it fails the assert. But that's OK. It is my error. I have sent a patch to de-assert it. I am not sure whether it can be merged into the 8.2.
Thanks,
Zhiwei
Quoted 4 lines
ATB,
Mark.