]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xtensa: fix TLB sanity checker
authorMax Filippov <jcmvbkbc@gmail.com>
Wed, 13 Nov 2019 21:18:31 +0000 (13:18 -0800)
committerMax Filippov <jcmvbkbc@gmail.com>
Tue, 26 Nov 2019 19:33:39 +0000 (11:33 -0800)
Virtual and translated addresses retrieved by the xtensa TLB sanity
checker must be consistent, i.e. correspond to the same state of the
checked TLB entry. KASAN shadow memory is mapped dynamically using
auto-refill TLB entries and thus may change TLB state between the
virtual and translated address retrieval, resulting in false TLB
insanity report.
Move read_xtlb_translation close to read_xtlb_virtual to make sure that
read values are consistent.

Cc: stable@vger.kernel.org
Fixes: a99e07ee5e88 ("xtensa: check TLB sanity on return to userspace")
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
arch/xtensa/mm/tlb.c

index ec82209732529b1f35ed03aa22aaebd0cb8c4a7c..f436cf2efd8b7aa2213d7c2e73496b41ba6d4e3d 100644 (file)
@@ -224,6 +224,8 @@ static int check_tlb_entry(unsigned w, unsigned e, bool dtlb)
        unsigned tlbidx = w | (e << PAGE_SHIFT);
        unsigned r0 = dtlb ?
                read_dtlb_virtual(tlbidx) : read_itlb_virtual(tlbidx);
+       unsigned r1 = dtlb ?
+               read_dtlb_translation(tlbidx) : read_itlb_translation(tlbidx);
        unsigned vpn = (r0 & PAGE_MASK) | (e << PAGE_SHIFT);
        unsigned pte = get_pte_for_vaddr(vpn);
        unsigned mm_asid = (get_rasid_register() >> 8) & ASID_MASK;
@@ -239,8 +241,6 @@ static int check_tlb_entry(unsigned w, unsigned e, bool dtlb)
        }
 
        if (tlb_asid == mm_asid) {
-               unsigned r1 = dtlb ? read_dtlb_translation(tlbidx) :
-                       read_itlb_translation(tlbidx);
                if ((pte ^ r1) & PAGE_MASK) {
                        pr_err("%cTLB: way: %u, entry: %u, mapping: %08x->%08x, PTE: %08x\n",
                                        dtlb ? 'D' : 'I', w, e, r0, r1, pte);