From 70a998e918ab052dd0d1c14adb4d2aa0fa1914f4 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Thu, 16 Feb 2023 23:03:45 -0500 Subject: [PATCH 48/52] mips: Handle concurrent pmap demotions in TLB exception handlers The handlers run with a paucity of registers, so have to reload the PDE multiple times. This can give inconsistent results, since pmap_update_pde() clears PDEs before raising an IPI which synchronizes with exception handlers. Check the PDE each time we dereference and go to the slow path if it's nul. --- sys/mips/mips/exception.S | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sys/mips/mips/exception.S b/sys/mips/mips/exception.S index f7b1523a05dc..090cb92f6d30 100644 --- a/sys/mips/mips/exception.S +++ b/sys/mips/mips/exception.S @@ -184,11 +184,15 @@ MipsDoTLBMiss: PTR_SRL k0, pdeshift + PTRSHIFT ;\ PTR_SLL k0, pdeshift + PTRSHIFT ;\ PTR_L k1, 0(k0) ;\ + beq k1, zero, 2f ;\ + nop ;\ CLEAR_PTE_SWBITS(k1) ;\ PTE_MTC0 k1, MIPS_COP_0_TLB_LO0 ;\ COP0_SYNC ;\ GET_ODD_PFN_FROM_EVEN(size, k1) ;\ PTR_L k0, 0(k0) ;\ + beq k0, zero, 2f ;\ + nop ;\ GET_HW_TLB_FLAGS(k0) ;\ or k1, k1, k0 ;\ CLEAR_PTE_SWBITS(k1) ;\ @@ -210,6 +214,8 @@ MipsDoTLBMiss: andi k1, k1, SW_RSV bne k1, zero, not_superpage PTR_L k1, 0(k0) # k1=pde entry + beq k1, zero, 2f + nop GET_SUPERPAGE_IDX(k1) # k1=superpage index from PTE beq k1, zero, not_superpage # ==0 -- not superpage nop # branch delay slot @@ -1029,6 +1035,8 @@ LEAF_NOPROFILE(MipsTLBInvalidException) COP0_SYNC ;\ GET_ODD_PFN_FROM_EVEN(size, k1) ;\ PTR_L k0, 0(k0) ;\ + beqz k0, 3f ;\ + nop ;\ GET_HW_TLB_FLAGS(k0) ;\ or k1, k1, k0 ;\ CLEAR_PTE_SWBITS(k1) ;\ @@ -1047,6 +1055,8 @@ LEAF_NOPROFILE(MipsTLBInvalidException) andi k1, k1, SW_RSV bne k1, zero, not_spg PTR_L k1, 0(k0) # k1=pde entry + beqz k1, 3f + nop GET_SUPERPAGE_IDX(k1) # k1=superpage index from PTE beq k1, zero, not_spg # ==0 -- not superpage nop # branch delay slot -- 2.41.0