accel/tcg: fix get_page_addr_code() victim TLB lookups
cover accel/tcg: fix get_page_addr_code() victim TLB lookups
This patchset fixes a bug in get_page_addr_code()'s lookup of the address in the victim TLB, which was another source of "we end up with an invalid TLB entry even after we've done a TLB fill for it".
The second patch then removes a check that we had that was working around the existence of the bug patch 1 fixes and the bug that commit 68fea038553039e fixes, and instead puts in an assertion that we definitely do have a valid TLB.
Tested with Laurent's m68k image to check we didn't regress that.
thanks
-- PMM
Peter Maydell (2):
accel/tcg: Use correct test when looking in victim TLB for code accel/tcg: Assert that tlb fill gave us a valid TLB entry
accel/tcg/cputlb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/2 accel/tcg: Use correct test when looking in victim TLB for code
In get_page_addr_code(), we were incorrectly looking in the victim TLB for an entry which matched the target address for reads, not for code accesses. This meant that we could hit on a victim TLB entry that indicated that the address was readable but not executable, and incorrectly bypass the call to tlb_fill() which should generate the guest MMU exception. Fix this bug.
--- accel/tcg/cputlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
accel/tcg/cputlb.c +1 -1
@@ -967,7 +967,7 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr) index = (addr >>TARGET_PAGE_BITS ) & (CPU_TLB_SIZE -1 ); mmu_idx =cpu_mmu_index (env, true);if (unlikely (!tlb_hit (env->tlb_table[mmu_idx][index].addr_code, addr))) { -if (!VICTIM_TLB_HIT (addr_read, addr)) { +if (!VICTIM_TLB_HIT (addr_code, addr)) {tlb_fill (ENV_GET_CPU (env), addr,0 ,MMU_INST_FETCH , mmu_idx,0 ); } }
Signature · 1 line
2.17.1
Re: [Qemu-arm] [Qemu-devel] [PATCH for-3.0 1/2] accel/tcg: Use correct test when looking in victim TLB for code
accel/tcg/cputlb.c tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr) · line 970
Quoted 6 lines · Peter Maydell
accel/tcg/cputlb.c +1
-1@@ -967,7 +967,7 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr) index = (addr >>TARGET_PAGE_BITS ) & (CPU_TLB_SIZE -1 ); mmu_idx =cpu_mmu_index (env, true);if (unlikely (!tlb_hit (env->tlb_table[mmu_idx][index].addr_code, addr))) { -if (!VICTIM_TLB_HIT (addr_read, addr)) { +if (!VICTIM_TLB_HIT (addr_code, addr)) {
Oh geez.
r~
PATCH 2/2 accel/tcg: Assert that tlb fill gave us a valid TLB entry
In reply to Peter MaydellIn commit 4b1a3e1e34ad97 we added a check for whether the TLB entry we had following a tlb_fill had the INVALID bit set. This could happen in some circumstances because a stale or wrong TLB entry was pulled out of the victim cache. However, after commit 68fea038553039e (which prevents stale entries being in the victim cache) and the previous commit (which ensures we don't incorrectly hit in the victim cache)) this should never be possible.
Drop the check on TLB_INVALID_MASK from the "is this a TLB_RECHECK?" condition, and instead assert that the tlb fill procedure has given us a valid TLB entry (or longjumped out with a guest exception).
--- accel/tcg/cputlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
accel/tcg/cputlb.c +2 -2
@@ -970,10 +970,10 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr)if (!VICTIM_TLB_HIT (addr_code, addr)) {tlb_fill (ENV_GET_CPU (env), addr,0 ,MMU_INST_FETCH , mmu_idx,0 ); } +assert (tlb_hit (env->tlb_table[mmu_idx][index].addr_code, addr)); } -if (unlikely ((env->tlb_table[mmu_idx][index].addr_code & - (TLB_RECHECK |TLB_INVALID_MASK )) ==TLB_RECHECK )) { +if (unlikely (env->tlb_table[mmu_idx][index].addr_code &TLB_RECHECK )) {/* * This is a TLB_RECHECK access, where the MMU protection * covers a smaller range than a target page, and we must
Signature · 1 line
2.17.1
Re: [Qemu-arm] [Qemu-devel] [PATCH for-3.0 2/2] accel/tcg: Assert that tlb fill gave us a valid TLB entry
Quoted 8 lines · Peter Maydell
In commit
4b1a3e1e34ad97we added a check for whether the TLB entry we had following atlb_fillhad the INVALID bit set. This could happen in some circumstances because a stale or wrong TLB entry was pulled out of the victim cache. However, after commit68fea038553039e(which prevents stale entries being in the victim cache) and the previous commit (which ensures we don't incorrectly hit in the victim cache)) this should never be possible.
Quoted 8 lines
Drop the check on
TLB_INVALID_MASKfrom the "is this aTLB_RECHECK?" condition, and instead assert that the tlb fill procedure has given us a valid TLB entry (or longjumped out with a guest exception).Signed-off-by Peter Maydell <[email protected]>--- accel/tcg/cputlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
r~
Quoted 11 lines · Peter Maydell
This patchset fixes a bug in get_page_addr_code()'s lookup of the address in the victim TLB, which was another source of "we end up with an invalid TLB entry even after we've done a TLB fill for it".
The second patch then removes a check that we had that was working around the existence of the bug patch 1 fixes and the bug that commit
68fea038553039efixes, and instead puts in an assertion that we definitely do have a valid TLB.Tested with Laurent's m68k image to check we didn't regress that.
Thanks for the review -- I'll take these via target-arm.next since RTH doesn't have any other tcg patches for rc1.
-- PMM