target-xtensa MMU fixes
Hello.
This series fixes subtle bugs in the xtensa hardware pagewalking implementation and adds more MMU test cases.
The following changes since commit aeb29b6459cb9496b38c820f3faff64cf2369d0d:
audio: Always call fini on exit (2012-05-24 19:35:27 +0400)
are available in the git repository at:
git://jcmvbkbc.spb.ru/dumb/qemu-xtensa.git xtensa
Max Filippov (6):
target-xtensa: flush TLB page for new MMU mapping
target-xtensa: update EXCVADDR in case of page table lookup
target-xtensa: extract TLB entry setting method
target-xtensa: update autorefill TLB entries conditionally
target-xtensa: control page table lookup explicitly
target-xtensa: add MMU pagewalking tests
target-xtensa/cpu.h | 5 +- target-xtensa/helper.c | 61 +++++++----- target-xtensa/op_helper.c | 20 +++- tests/tcg/xtensa/test_mmu.S | 221 ++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 260 insertions(+), 47 deletions(-)
Signature · 1 line
1.7.7.6
PATCH 1/6 target-xtensa: flush TLB page for new MMU mapping
Both old and new mappings need flushing because their VPN may be different in MMU case.
--- target-xtensa/op_helper.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
target-xtensa/op_helper.c +1 -0
@@ -669,6 +669,7 @@ void xtensa_tlb_set_entry(CPUXtensaState *env, bool dtlb, entry->paddr = pte &xtensa_tlb_get_addr_mask (env, dtlb, wi); entry->asid = (env->sregs[RASID ] >> ((pte >>1 ) &0x18 )) &0xff ; entry->attr = pte &0xf ; +tlb_flush_page (env, entry->vaddr); }else {qemu_log ("%s %d, %d, %d trying to set immutable entry\n" , __func__, dtlb, wi, ei);
Signature · 1 line
1.7.7.6
PATCH 2/6 target-xtensa: update EXCVADDR in case of page table lookup
In reply to Max FilippovAccording to ISA, 4.4.2.6, EXCVADDR may be changed by any TLB miss, even if the miss is handled entirely by processor hardware.
--- target-xtensa/helper.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
target-xtensa/helper.c +1 -0
@@ -516,6 +516,7 @@ static int autorefill_mmu(CPUXtensaState *env, uint32_t vaddr, bool dtlb, *wi = (++env->autorefill_idx) &0x3 ;split_tlb_entry_spec_way (env, vaddr, dtlb, &vpn, *wi, ei);xtensa_tlb_set_entry (env, dtlb, *wi, *ei, vpn, pte); + env->sregs[EXCVADDR ] = vaddr;qemu_log ("%s: autorefill(%08x): %08x -> %08x\n" , __func__, vaddr, vpn, pte); }
Signature · 1 line
1.7.7.6
PATCH 3/6 target-xtensa: extract TLB entry setting method
In reply to Max Filippov--- target-xtensa/cpu.h | 3 +++ target-xtensa/op_helper.c | 15 +++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-)
target-xtensa/cpu.h +3 -0
@@ -370,6 +370,9 @@ void split_tlb_entry_spec_way(const CPUXtensaState *env, uint32_t v, bool dtlb, uint32_t *vpn, uint32_t wi, uint32_t *ei);int xtensa_tlb_lookup (const CPUXtensaState *env,uint32_t addr,bool dtlb,uint32_t *pwi,uint32_t *pei,uint8_t *pring); +void xtensa_tlb_set_entry_mmu (const CPUXtensaState *env, +xtensa_tlb_entry *entry,bool dtlb, +unsigned wi,unsigned ei,uint32_t vpn,uint32_t pte);void xtensa_tlb_set_entry (CPUXtensaState *env,bool dtlb,unsigned wi,unsigned ei,uint32_t vpn,uint32_t pte); int xtensa_get_physical_addr(CPUXtensaState *env,
target-xtensa/op_helper.c +11 -4
@@ -655,6 +655,16 @@ uint32_t HELPER(ptlb)(uint32_t v, uint32_t dtlb) } } +void xtensa_tlb_set_entry_mmu (const CPUXtensaState *env, +xtensa_tlb_entry *entry,bool dtlb, +unsigned wi,unsigned ei,uint32_t vpn,uint32_t pte) +{ + entry->vaddr = vpn; + entry->paddr = pte &xtensa_tlb_get_addr_mask (env, dtlb, wi); + entry->asid = (env->sregs[RASID ] >> ((pte >>1 ) &0x18 )) &0xff ; + entry->attr = pte &0xf ; +} +void xtensa_tlb_set_entry (CPUXtensaState *env,bool dtlb,unsigned wi,unsigned ei,uint32_t vpn,uint32_t pte) {
@@ -665,10 +675,7 @@ void xtensa_tlb_set_entry(CPUXtensaState *env, bool dtlb,if (entry->asid) {tlb_flush_page (env, entry->vaddr); } - entry->vaddr = vpn; - entry->paddr = pte &xtensa_tlb_get_addr_mask (env, dtlb, wi); - entry->asid = (env->sregs[RASID ] >> ((pte >>1 ) &0x18 )) &0xff ; - entry->attr = pte &0xf ; +xtensa_tlb_set_entry_mmu (env, entry, dtlb, wi, ei, vpn, pte);tlb_flush_page (env, entry->vaddr); }else { qemu_log("%s %d, %d, %d trying to set immutable entry\n",
Signature · 1 line
1.7.7.6
PATCH 4/6 target-xtensa: update autorefill TLB entries conditionally
In reply to Max FilippovThis is to avoid interference of internal QEMU helpers (cpu_get_phys_page_debug, tb_invalidate_virtual_addr) with guest-visible TLB state.
--- target-xtensa/cpu.h | 2 +- target-xtensa/helper.c | 56 +++++++++++++++++++++++++------------------- target-xtensa/op_helper.c | 4 +- 3 files changed, 35 insertions(+), 27 deletions(-)
target-xtensa/cpu.h +1 -1
@@ -375,7 +375,7 @@ void xtensa_tlb_set_entry_mmu(const CPUXtensaState *env, unsigned wi, unsigned ei, uint32_t vpn, uint32_t pte);void xtensa_tlb_set_entry (CPUXtensaState *env,bool dtlb,unsigned wi,unsigned ei,uint32_t vpn,uint32_t pte); -int xtensa_get_physical_addr (CPUXtensaState *env, +int xtensa_get_physical_addr (CPUXtensaState *env,bool update_tlb,uint32_t vaddr,int is_write,int mmu_idx,uint32_t *paddr,uint32_t *page_size,unsigned *access);void reset_mmu (CPUXtensaState *env);
target-xtensa/helper.c +32 -24
116 lines not on this page · raw message
target-xtensa/op_helper.c +2 -2
@@ -79,7 +79,7 @@ void tlb_fill(CPUXtensaState *env1, target_ulong vaddr, int is_write, int mmu_iduint32_t paddr;uint32_t page_size;unsigned access; -int ret =xtensa_get_physical_addr (env, vaddr, is_write, mmu_idx, +int ret =xtensa_get_physical_addr (env, true, vaddr, is_write, mmu_idx, &paddr, &page_size, &access); qemu_log("%s(%08x, %d, %d) -> %08x, ret = %d\n", __func__,
@@ -103,7 +103,7 @@ static void tb_invalidate_virtual_addr(CPUXtensaState *env, uint32_t vaddr)uint32_t paddr;uint32_t page_size;unsigned access; -int ret =xtensa_get_physical_addr (env, vaddr,2 ,0 , +int ret =xtensa_get_physical_addr (env, false, vaddr,2 ,0 , &paddr, &page_size, &access);if (ret ==0 ) {tb_invalidate_phys_addr (paddr);
Signature · 1 line
1.7.7.6
PATCH 5/6 target-xtensa: control page table lookup explicitly
In reply to Max FilippovHardware pagetable walking may not be nested. Stop guessing and pass explicit flag to the get_physical_addr_mmu function that controls page table lookup.
--- target-xtensa/helper.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
target-xtensa/helper.c +5 -5
@@ -452,7 +452,8 @@ static int get_pte(CPUXtensaState *env, uint32_t vaddr, uint32_t *pte);static int get_physical_addr_mmu (CPUXtensaState *env,bool update_tlb,uint32_t vaddr,int is_write,int mmu_idx, -uint32_t *paddr,uint32_t *page_size,unsigned *access) +uint32_t *paddr,uint32_t *page_size,unsigned *access, +bool may_lookup_pt) {bool dtlb = is_write !=2 ;uint32_t wi;
@@ -465,8 +466,7 @@ static int get_physical_addr_mmu(CPUXtensaState *env, bool update_tlb,int ret =xtensa_tlb_lookup (env, vaddr, dtlb, &wi, &ei, &ring);if ((ret ==INST_TLB_MISS_CAUSE || ret ==LOAD_STORE_TLB_MISS_CAUSE ) && - (mmu_idx !=0 || ((vaddr ^ env->sregs[PTEVADDR ]) &0xffc00000 )) && -get_pte (env, vaddr, &pte) ==0 ) { + may_lookup_pt &&get_pte (env, vaddr, &pte) ==0 ) { ring = (pte >>4 ) &0x3 ; wi =0 ;split_tlb_entry_spec_way (env, vaddr, dtlb, &vpn, wi, &ei);
@@ -520,7 +520,7 @@ static int get_pte(CPUXtensaState *env, uint32_t vaddr, uint32_t *pte)uint32_t pt_vaddr = (env->sregs[PTEVADDR ] | (vaddr >>10 )) &0xfffffffc ;int ret =get_physical_addr_mmu (env, false, pt_vaddr,0 ,0 , - &paddr, &page_size, &access); + &paddr, &page_size, &access, false);qemu_log ("%s: trying autorefill(%08x) -> %08x\n" , __func__, vaddr, ret ? ~0 : paddr);
@@ -568,7 +568,7 @@ int xtensa_get_physical_addr(CPUXtensaState *env, bool update_tlb, {if (xtensa_option_enabled (env->config,XTENSA_OPTION_MMU )) {return get_physical_addr_mmu (env, update_tlb, - vaddr, is_write, mmu_idx, paddr, page_size, access); + vaddr, is_write, mmu_idx, paddr, page_size, access, true); }else if (xtensa_option_bits_enabled (env->config,XTENSA_OPTION_BIT (XTENSA_OPTION_REGION_PROTECTION ) |XTENSA_OPTION_BIT (XTENSA_OPTION_REGION_TRANSLATION ))) {
Signature · 1 line
1.7.7.6
PATCH 6/6 target-xtensa: add MMU pagewalking tests
In reply to Max Filippov--- tests/tcg/xtensa/test_mmu.S | 221 ++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 207 insertions(+), 14 deletions(-)
tests/tcg/xtensa/test_mmu.S +207 -14
@@ -293,26 +293,219 @@ test store_prohibited assert eq, a2, a3 test_end -test dtlb_autoload - set_vector kernel, 0 - - movi a2, 0xd4000000 +/* Set up page table entry vaddr->paddr, ring=pte_ring, attr=pte_attr + * and DTLB way 7 to cover this PTE, ring=pt_ring, attr=pt_attr + */ +.macro pt_setup pt_ring, pt_attr, pte_ring, vaddr, paddr, pte_attr + movi a2, 0x80000000 wsr a2, ptevaddr - movi a3, 0x00001013 - s32i a3, a2, 4 + + movi a3, 0x80000007 | (((\vaddr) >> 10) & 0xfffff000) /* way 7 */ + movi a4, 0x04000003 | ((\pt_ring) << 4) /* PADDR 64M */ + wdtlb a4, a3 + isync + + movi a3, ((\paddr) & 0xfffff000) | ((\pte_ring) << 4) | (\pte_attr) + movi a1, ((\vaddr) >> 12) << 2 + add a2, a1, a2 + s32i a3, a2, 0 + + movi a3, 0x80000007 | (((\vaddr) >> 10) & 0xfffff000) /* way 7 */ + movi a4, 0x04000000 | ((\pt_ring) << 4) | (\pt_attr) /* PADDR 64M */ + wdtlb a4, a3 + isync + + movi a3, (\vaddr) +.endm + +/* out: PS.RING=ring, PS.EXCM=excm, a3=vaddr */ +.macro go_ring ring, excm, vaddr + movi a3, 10f + pitlb a3, a3 + ritlb1 a2, a3 + movi a1, 0x10 + or a2, a2, a1 + movi a1, 0x000ff000 + and a3, a3, a1 + movi a1, 4 + or a3, a3, a1 + witlb a2, a3 + movi a3, 10f + movi a1, 0x000fffff + and a1, a3, a1 + + movi a2, 0 + wsr a2, excvaddr + + movi a3, \vaddr + movi a2, 0x4000f | ((\ring) << 6) | ((\excm) << 4) + jx a1 +10: + wsr a2, ps + isync +.endm + +/* in: a3 -- virtual address to test */ +.macro assert_auto_tlb + movi a2, 0x4000f + wsr a2, ps + isync + pdtlb a2, a3 + movi a1, 0xfffff01f + and a2, a2, a1 + movi a1, 0xfffff000 + and a1, a1, a3 + xor a1, a1, a2 + assert gei, a1, 0x10 + movi a2, 0x14 + assert lt, a1, a2 +.endm + +/* in: a3 -- virtual address to test */ +.macro assert_no_auto_tlb + movi a2, 0x4000f + wsr a2, ps + isync pdtlb a2, a3 movi a1, 0x10 and a1, a1, a2 assert eqi, a1, 0 - l8ui a1, a3, 0 - pdtlb a2, a3 - movi a1, 0xfffff010 - and a1, a1, a2 - movi a3, 0x00001010 - assert eq, a1, a3 - movi a1, 0xf +.endm + +.macro assert_sr sr, v + rsr a2, \sr + movi a1, (\v) + assert eq, a1, a2 +.endm + +.macro assert_epc1_1m vaddr + movi a2, (\vaddr) + movi a1, 0xfffff and a1, a1, a2 - assert lti, a1, 4 + rsr a2, epc1 + assert eq, a1, a2 +.endm + +test dtlb_autoload + set_vector kernel, 0 + + pt_setup 0, 3, 1, 0x1000, 0x1000, 3 + assert_no_auto_tlb + + l8ui a1, a3, 0 + + rsr a2, excvaddr + assert eq, a2, a3 + + assert_auto_tlb +test_end + +test autoload_load_store_privilege + set_vector kernel, 0 + set_vector double, 2f + + pt_setup 0, 3, 0, 0x2000, 0x2000, 3 + movi a3, 0x2004 + assert_no_auto_tlb + + movi a2, 0x4005f /* ring 1 + excm => cring == 0 */ + wsr a2, ps + isync +1: + l32e a2, a3, -4 /* ring used */ + test_fail +2: + rsr a2, excvaddr + addi a1, a3, -4 + assert eq, a1, a2 + + assert_auto_tlb + assert_sr depc, 1b + assert_sr exccause, 26 +test_end + +test autoload_pte_load_prohibited + set_vector kernel, 2f + + pt_setup 0, 3, 0, 0x3000, 0, 0xc + assert_no_auto_tlb +1: + l32i a2, a3, 0 + test_fail +2: + rsr a2, excvaddr + assert eq, a2, a3 + + assert_auto_tlb + assert_sr epc1, 1b + assert_sr exccause, 28 +test_end + +test autoload_pt_load_prohibited + set_vector kernel, 2f + + pt_setup 0, 0xc, 0, 0x4000, 0x4000, 3 + assert_no_auto_tlb +1: + l32i a2, a3, 0 + test_fail +2: + rsr a2, excvaddr + assert eq, a2, a3 + + assert_no_auto_tlb + assert_sr epc1, 1b + assert_sr exccause, 24 +test_end + +test autoload_pt_privilege + set_vector kernel, 2f + pt_setup 0, 3, 1, 0x5000, 0, 3 + go_ring 1, 0, 0x5001 + + l8ui a2, a3, 0 +1: + syscall +2: + rsr a2, excvaddr + assert eq, a2, a3 + + assert_auto_tlb + assert_epc1_1m 1b + assert_sr exccause, 1 +test_end + +test autoload_pte_privilege + set_vector kernel, 2f + pt_setup 0, 3, 0, 0x6000, 0, 3 + go_ring 1, 0, 0x6001 +1: + l8ui a2, a3, 0 + syscall +2: + rsr a2, excvaddr + assert eq, a2, a3 + + assert_auto_tlb + assert_epc1_1m 1b + assert_sr exccause, 26 +test_end + +test autoload_3_level_pt + set_vector kernel, 2f + pt_setup 1, 3, 1, 0x00400000, 0, 3 + pt_setup 1, 3, 1, 0x80001000, 0x2000000, 3 + go_ring 1, 0, 0x00400001 +1: + l8ui a2, a3, 0 + syscall +2: + rsr a2, excvaddr + assert eq, a2, a3 + + assert_no_auto_tlb + assert_epc1_1m 1b + assert_sr exccause, 24 test_end test_suite_end
Signature · 1 line
1.7.7.6
Am 27.05.2012 16:34, schrieb Max Filippov:
Quoted 7 lines
Hello.
This series fixes subtle bugs in the xtensa hardware pagewalking implementation and adds more MMU test cases.
The following changes since commit
aeb29b6459cb9496b38c820f3faff64cf2369d0d:
Quoted 7 lines
audio: Always call fini on exit (2012-05-24 19:35:27 +0400)
are available in the git repository at:
git://jcmvbkbc.spb.ru/dumb/qemu-xtensa.gitxtensaMax Filippov (6):
target-xtensa: flush TLB page for new MMU mapping
At least this patch seems to have never reached my inbox before. The expected procedure is to first patches on the list, wait for review and only after acks have been received or sufficient time passed and a ping remained without acks, post a PULL request that can then be applied without review of contents, only making sure it doesn't break the build or significantly regresses the target(s).
This patch itself looks okay, but I'm pointing it out since the list seems to be lagging once again and because you're sending it for the final RC.
Regards,
Andreas
Quoted 11 lines
target-xtensa: update EXCVADDR in case of page table lookup
target-xtensa: extract TLB entry setting method
target-xtensa: update autorefill TLB entries conditionally
target-xtensa: control page table lookup explicitly
target-xtensa: add MMU pagewalking teststarget-xtensa/cpu.h | 5 +- target-xtensa/helper.c | 61 +++++++----- target-xtensa/op_helper.c | 20 +++- tests/tcg/xtensa/test_mmu.S | 221 ++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 260 insertions(+), 47 deletions(-)
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Quoted 10 lines · Andreas Färber
Am 27.05.2012 16:34, schrieb Max Filippov:
Quoted 9 lines
Hello.
This series fixes subtle bugs in the xtensa hardware pagewalking implementation and adds more MMU test cases.
The following changes since commit
aeb29b6459cb9496b38c820f3faff64cf2369d0d:audio: Always call fini on exit (2012-05-24 19:35:27 +0400)
Quoted 7 lines
Quoted 5 lines
are available in the git repository at:
git://jcmvbkbc.spb.ru/dumb/qemu-xtensa.gitxtensaMax Filippov (6):
target-xtensa: flush TLB page for new MMU mappingAt least this patch seems to have never reached my inbox before. The
My bad, actually I send it for the first time, should have been mere patch series. Please review.
Quoted 9 lines
expected procedure is to first patches on the list, wait for review and only after acks have been received or sufficient time passed and a ping remained without acks, post a PULL request that can then be applied without review of contents, only making sure it doesn't break the build or significantly regresses the target(s).
This patch itself looks okay, but I'm pointing it out since the list seems to be lagging once again and because you're sending it for the final RC.
Signature · 2 lines
Thanks. -- Max
Blue Swirl
AppliedThanks, applied all.
Quoted 28 lines · Max Filippov
Hello.
This series fixes subtle bugs in the xtensa hardware pagewalking implementation and adds more MMU test cases.
The following changes since commit
aeb29b6459cb9496b38c820f3faff64cf2369d0d:audio: Always call fini on exit (2012-05-24 19:35:27 +0400)
are available in the git repository at:
git://jcmvbkbc.spb.ru/dumb/qemu-xtensa.git xtensaMax Filippov (6):
target-xtensa: flush TLB page for new MMU mapping
target-xtensa: update EXCVADDR in case of page table lookup
target-xtensa: extract TLB entry setting method
target-xtensa: update autorefill TLB entries conditionally
target-xtensa: control page table lookup explicitly
target-xtensa: add MMU pagewalking teststarget-xtensa/cpu.h | 5 +-
target-xtensa/helper.c | 61 +++++++-----target-xtensa/op_helper.c| 20 +++-tests/tcg/xtensa/test_mmu.S| 221 ++++++++++++++++++++++++++++++++++++++++---4 files changed, 260 insertions(+), 47 deletions(-)--
1.7.7.6