arm: Add support for 'info tlb' command
v4 cover arm: Add support for 'info tlb' command
This adds hmp 'info tlb' command support for the arm platform. The limitation is that this only implements a page walker for ARMv8-A AArch64 Long Descriptor format, 32bit addressing is not supported yet.
To reuse existing code, this patch also extracts some APIs from helper.c, including regime_translation_disabled(), pt_start_level_stage1(), regime_ttbr(), arm_ldq_ptw().
---
v4:
Dividing the patch into two parts.
Removed some of the previously described
problems by switching to arm_ldq_ptw().
v3: rebase to latest mainline.
v2:
o fix coding style
o extract common code pt_start_level_stage1()
---
---
Ivanov Arkady (2):
target/arm: Refactoring MMU helper function arm/monitor: Add support for 'info tlb' command
hmp-commands-info.hx | 3 + target/arm/helper.c | 35 +--------- target/arm/internals.h | 39 +++++++++++ target/arm/monitor.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 214 insertions(+), 33 deletions(-)
--
Ivanov Arkady
PATCH v4 1/2 target/arm: Refactoring MMU helper function
To reuse existing code for "tlb info", this patch also extracts some of the APIs from helper.c including mode_translation_disabled (), pt_start_level_stage1 (), mode_ttbr (), arm_ldq_ptw ().
--- target/arm/helper.c | 35 +++-------------------------------- target/arm/internals.h | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 32 deletions(-)
target/arm/helper.c +3 -32
@@ -10101,8 +10101,7 @@ static inline uint64_t regime_sctlr(CPUARMState *env, ARMMMUIdx mmu_idx)#ifndef CONFIG_USER_ONLY /* Return true if the specified stage of address translation is disabled */ -static inline bool regime_translation_disabled (CPUARMState *env, -ARMMMUIdx mmu_idx) +bool regime_translation_disabled (CPUARMState *env,ARMMMUIdx mmu_idx) {uint64_t hcr_el2;
@@ -10152,23 +10151,6 @@ static inline bool regime_translation_big_endian(CPUARMState *env, return (regime_sctlr(env, mmu_idx) & SCTLR_EE) != 0; } -/* Return the TTBR associated with this translation regime */ -static inline uint64_t regime_ttbr (CPUARMState *env,ARMMMUIdx mmu_idx, -int ttbrn) -{ -if (mmu_idx == ARMMMUIdx_Stage2) { -return env->cp15.vttbr_el2; - } -if (mmu_idx == ARMMMUIdx_Stage2_S) { -return env->cp15.vsttbr_el2; - } -if (ttbrn ==0 ) { -return env->cp15.ttbr0_el[regime_el (env, mmu_idx)]; - }else { -return env->cp15.ttbr1_el[regime_el (env, mmu_idx)]; - } -} -#endif /* !CONFIG_USER_ONLY */ /* Convert a possible stage1+2 MMU index into the appropriate
@@ -10564,7 +10546,7 @@ static uint32_t arm_ldl_ptw(CPUState *cs, hwaddr addr, bool is_secure,return 0 ; } -static uint64_t arm_ldq_ptw (CPUState *cs,hwaddr addr,bool is_secure, +uint64_t arm_ldq_ptw (CPUState *cs,hwaddr addr,bool is_secure,ARMMMUIdx mmu_idx,ARMMMUFaultInfo *fi) {ARMCPU *cpu =ARM_CPU (cs);
@@ -11246,18 +11228,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, }if (mmu_idx != ARMMMUIdx_Stage2 && mmu_idx != ARMMMUIdx_Stage2_S) { -/* The starting level depends on the virtual address size (which can -* be up to 48 bits) and the translation granule size. It indicates -* the number of strides (stride bits at a time) needed to -* consume the bits of the input address. In the pseudocode this is: -* level = 4 - RoundUp((inputsize - grainsize) / stride) -* where their 'inputsize' is our 'inputsize', 'grainsize' is -* our 'stride + 3' and 'stride' is our 'stride'. -* Applying the usual "rounded up m/n is (m+n-1)/n" and simplifying: -* = 4 - (inputsize - stride - 3 + stride - 1) / stride -* = 4 - (inputsize - 4) / stride; -*/ - level =4 - (inputsize -4 ) / stride; + level =pt_start_level_stage1 (inputsize, stride); }else {/* For stage 2 translations the starting level is specified by the * VTCR_EL2.SL0 field (whose interpretation depends on the page size)
target/arm/internals.h +39 -0
@@ -738,6 +738,8 @@ static inline uint32_t regime_el(CPUARMState *env, ARMMMUIdx mmu_idx) } } +bool regime_translation_disabled (CPUARMState *env,ARMMMUIdx mmu_idx); +/* Return the TCR controlling this translation regime */ static inline TCR *regime_tcr (CPUARMState *env,ARMMMUIdx mmu_idx) {
@@ -754,6 +756,23 @@ static inline TCR *regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx)return &env->cp15.tcr_el[regime_el (env, mmu_idx)]; } +/* Return the TTBR associated with this translation regime */ +static inline uint64_t regime_ttbr (CPUARMState *env,ARMMMUIdx mmu_idx, +int ttbrn) +{ +if (mmu_idx == ARMMMUIdx_Stage2) { +return env->cp15.vttbr_el2; + } +if (mmu_idx == ARMMMUIdx_Stage2_S) { +return env->cp15.vsttbr_el2; + } +if (ttbrn ==0 ) { +return env->cp15.ttbr0_el[regime_el (env, mmu_idx)]; + }else { +return env->cp15.ttbr1_el[regime_el (env, mmu_idx)]; + } +} +/* Return the FSR value for a debug exception (watchpoint, hardware * breakpoint or BKPT insn) targeting the specified exception level. */
@@ -1096,6 +1115,26 @@ typedef struct ARMCacheAttrs { unsigned int shareability:2; /* as in the SH field of the VMSAv8-64 PTEs */ } ARMCacheAttrs; +static inline int pt_start_level_stage1 (int inputsize,int stride) +{ +/* +* The starting level depends on the virtual address size (which can +* be up to 48 bits) and the translation granule size. It indicates +* the number of strides (stride bits at a time) needed to +* consume the bits of the input address. In the pseudocode this is: +* level = 4 - RoundUp((inputsize - grainsize) / stride) +* where their 'inputsize' is our 'inputsize', 'grainsize' is +* our 'stride + 3' and 'stride' is our 'stride'. +* Applying the usual "rounded up m/n is (m+n-1)/n" and simplifying: +* = 4 - (inputsize - stride - 3 + stride - 1) / stride +* = 4 - (inputsize - 4) / stride; +*/ +return 4 - (inputsize -4 ) / stride; +} + +uint64_t arm_ldq_ptw (CPUState *cs,hwaddr addr,bool is_secure, +ARMMMUIdx mmu_idx,ARMMMUFaultInfo *fi); + bool get_phys_addr(CPUARMState *env, target_ulong address, MMUAccessType access_type, ARMMMUIdx mmu_idx, hwaddr *phys_ptr, MemTxAttrs *attrs, int *prot,
PATCH v4 2/2 arm/monitor: Add support for 'info tlb' command
In reply to NDNFThis adds hmp 'info tlb' command support for the arm platform. The limitation is that this only implements a page walker for ARMv8-A AArch64 Long Descriptor format, 32bit addressing is not supported yet.
--- hmp-commands-info.hx | 3 + target/arm/monitor.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 1 deletion(-)
hmp-commands-info.hx +2 -1
@@ -222,7 +222,8 @@ SRST ERST #if defined(TARGET_I386) || defined(TARGET_SH4) || defined(TARGET_SPARC) || \ - defined(TARGET_PPC) || defined(TARGET_XTENSA) || defined(TARGET_M68K) + defined(TARGET_PPC) || defined(TARGET_XTENSA) || defined(TARGET_M68K) || \ + defined(TARGET_ARM) { .name = "tlb", .args_type = "",
target/arm/monitor.c +170 -0
179 lines not on this page · raw message
Re: [PATCH v4 2/2] arm/monitor: Add support for 'info tlb' command
Quoted 6 lines · NDNF
This adds hmp 'info tlb' command support for the arm platform. The limitation is that this only implements a page walker for ARMv8-A AArch64 Long Descriptor format, 32bit addressing is not supported yet.
Quoted 7 lines
Signed-off-by Changbin Du <[email protected]>Signed-off-by Ivanov Arkady <[email protected]>--- hmp-commands-info.hx | 3 + target/arm/monitor.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 1 deletion(-)
I believe this is not TLB on ARM, but PTE?
RISC-V implemented a "info mem" for page table walk.
Regards,
Bin
Re: [PATCH v4 2/2] arm/monitor: Add support for 'info tlb' command
Quoted 16 lines · Bin Meng
Quoted 6 lines · NDNF
This adds hmp 'info tlb' command support for the arm platform. The limitation is that this only implements a page walker for ARMv8-A AArch64 Long Descriptor format, 32bit addressing is not supported yet.
Quoted 7 lines
Signed-off-by Changbin Du <[email protected]>Signed-off-by Ivanov Arkady <[email protected]>--- hmp-commands-info.hx | 3 + target/arm/monitor.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 1 deletion(-)
Quoted 3 lines
I believe this is not TLB on ARM, but PTE?
RISC-V implemented a "info mem" for page table walk.
We call our "give page table walk" monitor command "info tlb" for some reason (probably historical). From the docs:
https://qemu-project.gitlab.io/qemu/system/monitor.html
info tlb
Show virtual to physical memory mappings
info mem
Show the active virtual memory mappings.
Looking at x86's output, "info tlb" gives lines like this:
ffffffffc04f6000: 00000000b2576000 -G-DA----ffffffffc04f7000: 00000000b2579000 -G-DA----ffffffffc04f8000: 00000000bac74000 XG-DA----ffffffffc04f9000: 00000000b258b000 XG-DA----ffffffffc04fa000: 00000000b248b000 XG-DA---Wffffffffc04fb000: 00000000b2431000 XG-DA---Wffffffffc0502000: 00000000bb69c000 -G-DA----ffffffffc0503000: 00000000b27d3000 XG-DA----
which is a dump of the page table, with one line per page, giving the vaddr, the physaddr and associated flag information.
"info mem" gives lines like this:
ffffffffc04f6000-ffffffffc04fa000 0000000000004000 -r- ffffffffc04fa000-ffffffffc04fc000 0000000000002000 -rw ffffffffc0502000-ffffffffc0504000 0000000000002000 -r-
which just give "this range of virtual addresses of this length have these permissions". You can see that it coalesces multiple adjacent pages with the same permissions into a single line.
The only architectures which implement "info mem" are i386 and riscv. If riscv has given the command different semantics to i386 that would be unfortunate.
"info tlb" is implemented by i386, m68k, nios2, ppc, sh4, sparc, xtensa.
It's not clear to me that "info mem" is all that useful -- you can figure out the same info from "info tlb".
-- PMM
Re: [PATCH v4 2/2] arm/monitor: Add support for 'info tlb' command
Quoted 30 lines · Peter Maydell
Quoted 16 lines · Bin Meng
Quoted 6 lines · NDNF
This adds hmp 'info tlb' command support for the arm platform. The limitation is that this only implements a page walker for ARMv8-A AArch64 Long Descriptor format, 32bit addressing is not supported yet.
Quoted 7 lines
Signed-off-by Changbin Du <[email protected]>Signed-off-by Ivanov Arkady <[email protected]>--- hmp-commands-info.hx | 3 + target/arm/monitor.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 1 deletion(-)Quoted 3 lines
I believe this is not TLB on ARM, but PTE?
RISC-V implemented a "info mem" for page table walk.
We call our "give page table walk" monitor command "info tlb" for some reason (probably historical). From the docs:
https://qemu-project.gitlab.io/qemu/system/monitor.html
info tlb
Show virtual to physical memory mappings
info mem
Show the active virtual memory mappings.
Quoted 1 line
Looking at x86's output, "info tlb" gives lines like this:
I don't know why x86 provides 2 almost the same things.
Quoted 10 lines
ffffffffc04f6000:00000000b2576000-G-DA----ffffffffc04f7000:00000000b2579000-G-DA----ffffffffc04f8000:00000000bac74000XG-DA----ffffffffc04f9000:00000000b258b000XG-DA----ffffffffc04fa000:00000000b248b000XG-DA---Wffffffffc04fb000:00000000b2431000XG-DA---Wffffffffc0502000:00000000bb69c000-G-DA----ffffffffc0503000:00000000b27d3000XG-DA----
Naming it to "tlb" really confuses people. On ppce500, "info tlb" gives the real processor TLBs, not the PTEs.
(qemu) info tlb
TLB0:
Effective Physical Size TID TS SRWX URWX WIMGE U0123
TLB1:
Effective Physical Size TID TS SRWX URWX WIMGE U0123 0x00000000e0000000 0x0000000fe0000000 1M 0 0 SRW-U--- -I-G- U---- 0x0000000000000000 0x0000000000000000 64M 0 0 SRWXU--- --M-- U---- 0x0000000004000000 0x0000000004000000 64M 0 0 SRWXU--- --M-- U---- 0x00000000f0000000 0x0000000f00000000 64M 0 0 SRW-U--- -I-G- U---- 0x0000000080000000 0x0000000c00000000 256M 0 0 SRW-U--- -I-G- U---- 0x0000000090000000 0x0000000c10000000 256M 0 0 SRW-U--- -I-G- U---- 0x00000000a0000000 0x0000000fe1000000 64K 0 0 SRW-U--- -I-G- U---- 0x00000000f4000000 0x0000000f04000000 64M 0 0 SRW-U--- -I-G- U----
So we are unfortunately inconsistent among these arches that support "info tlb".
Quoted 18 lines
which is a dump of the page table, with one line per page, giving the vaddr, the physaddr and associated flag information.
"info mem" gives lines like this:
ffffffffc04f6000-ffffffffc04fa000 0000000000004000 -r- ffffffffc04fa000-ffffffffc04fc000 0000000000002000 -rw ffffffffc0502000-ffffffffc0504000 0000000000002000 -r-
which just give "this range of virtual addresses of this length have these permissions". You can see that it coalesces multiple adjacent pages with the same permissions into a single line.
The only architectures which implement "info mem" are i386 and riscv. If riscv has given the command different semantics to i386 that would be unfortunate.
Quoted 5 lines
"info tlb" is implemented by i386, m68k, nios2, ppc, sh4, sparc, xtensa.
It's not clear to me that "info mem" is all that useful -- you can figure out the same info from "info tlb".
Yes. But I feel "info mem" is more a suitable name than "info tlb" unless we are really printing the TLB.
Regards,
Bin