All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] riscv: mm: synchronize MMU after pte change
@ 2019-06-17  4:26 ` ShihPo Hung
  0 siblings, 0 replies; 8+ messages in thread
From: ShihPo Hung @ 2019-06-17  4:26 UTC (permalink / raw)
  To: linux-riscv; +Cc: Albert Ou, Palmer Dabbelt, stable, Paul Walmsley

Because RISC-V compliant implementations can cache invalid entries
in TLB, an SFENCE.VMA is necessary after changes to the page table.
This patch adds an SFENCE.vma for the vmalloc_fault path.

Signed-off-by: ShihPo Hung <shihpo.hung@sifive.com>
Cc: Palmer Dabbelt <palmer@sifive.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: linux-riscv@lists.infradead.org
Cc: stable@vger.kernel.org
---
 arch/riscv/mm/fault.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c
index 88401d5..a1c7b39 100644
--- a/arch/riscv/mm/fault.c
+++ b/arch/riscv/mm/fault.c
@@ -29,6 +29,7 @@

 #include <asm/pgalloc.h>
 #include <asm/ptrace.h>
+#include <asm/tlbflush.h>

 /*
  * This routine handles page faults.  It determines the address and the
@@ -281,6 +282,16 @@ asmlinkage void do_page_fault(struct pt_regs *regs)
        pte_k = pte_offset_kernel(pmd_k, addr);
        if (!pte_present(*pte_k))
            goto no_context;
+
+       /*
+        * The kernel assumes that TLBs don't cache invalid entries, but
+        * in RISC-V, SFENCE.VMA specifies an ordering constraint, not a
+        * cache flush; it is necessary even after writing invalid entries.
+        * Relying on flush_tlb_fix_spurious_fault would suffice, but
+        * the extra traps reduce performance.  So, eagerly SFENCE.VMA.
+        */
+       local_flush_tlb_page(addr);
+
        return;
    }
 }
--
2.7.4

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-06-19  8:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-17  4:26 [PATCH v2] riscv: mm: synchronize MMU after pte change ShihPo Hung
2019-06-17  4:26 ` ShihPo Hung
2019-06-17 10:32 ` Paul Walmsley
2019-06-17 10:32   ` Paul Walmsley
2019-06-19  1:51   ` Gary Guo
2019-06-19  1:51     ` Gary Guo
2019-06-19  7:44     ` Alan Kao
2019-06-19  7:44       ` Alan Kao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.