Skip to contentSkip to conversation

RISC-V: mm: Support huge page in vmalloc_fault()

PATCH Superseded Dylan Jhong 2 participants 3 messages Feb 24, 2023 – Mar 1, 2023 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RISC-V: mm: Support huge page in vmalloc_fault()

RISC-V supports ioremap() with huge page (pud/pmd) mapping, but vmalloc_fault() assumes that the vmalloc range is limited to pte mappings. Add huge page support to complete the vmalloc_fault() function.

Fixes 310f541a027b ("riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT")
---
 arch/riscv/mm/fault.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/riscv/mm/fault.c +5 -0
index eb0774d9c03b..4b9953b47d81 100644
@@ -143,6 +143,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
 		no_context(regs, addr);
 		return;
 	}
+	if (pud_leaf(*pud_k))
+		goto flush_tlb;
 
 	/*
 	 * Since the vmalloc area is global, it is unnecessary
@@ -153,6 +155,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
 		no_context(regs, addr);
 		return;
 	}
+	if (pmd_leaf(*pmd_k))
+		goto flush_tlb;
 
 	/*
 	 * Make sure the actual PTE exists as well to
@@ -172,6 +176,7 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
 	 * ordering constraint, not a cache flush; it is
 	 * necessary even after writing invalid entries.
 	 */
+flush_tlb:
 	local_flush_tlb_page(addr);
 }
 
Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
reviewer Reviewed-by on v1 1/1
#1 lore raw

Hi Dylan,

Quoted 35 lines · Dylan Jhong

RISC-V supports ioremap() with huge page (pud/pmd) mapping, but vmalloc_fault() assumes that the vmalloc range is limited to pte mappings. Add huge page support to complete the vmalloc_fault() function.

Fixes 310f541a027b ("riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT")
---
  arch/riscv/mm/fault.c | 5 +++++
  1 file changed, 5 insertions(+)
arch/riscv/mm/fault.c +4 -0
index eb0774d9c03b..4b9953b47d81 100644
@@ -143,6 +143,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
  		no_context(regs, addr);
  		return;
  	}
+	if (pud_leaf(*pud_k))
+		goto flush_tlb;
 
  	/*
  	 * Since the vmalloc area is global, it is unnecessary
@@ -153,6 +155,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
  		no_context(regs, addr);
  		return;
  	}
+	if (pmd_leaf(*pmd_k))
+		goto flush_tlb;
 
  	/*
  	 * Make sure the actual PTE exists as well to

arch/riscv/mm/fault.c static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a · line 182

Quoted 7 lines
arch/riscv/mm/fault.c +1 -0
@@ -172,6 +176,7 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
  	 * ordering constraint, not a cache flush; it is
  	 * necessary even after writing invalid entries.
  	 */
+flush_tlb:
  	local_flush_tlb_page(addr);
  }
 

This looks good to me, you can add:

One question: how did you encounter this bug?

Thanks,

Alex

#2 lore raw
Quoted 46 lines · Alexandre Ghiti

Hi Dylan,

Quoted 33 lines · Dylan Jhong

RISC-V supports ioremap() with huge page (pud/pmd) mapping, but vmalloc_fault() assumes that the vmalloc range is limited to pte mappings. Add huge page support to complete the vmalloc_fault() function.

Fixes 310f541a027b ("riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT")
---
  arch/riscv/mm/fault.c | 5 +++++
  1 file changed, 5 insertions(+)
arch/riscv/mm/fault.c +4 -0
index eb0774d9c03b..4b9953b47d81 100644
@@ -143,6 +143,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
  		no_context(regs, addr);
  		return;
  	}
+	if (pud_leaf(*pud_k))
+		goto flush_tlb;
  	/*
  	 * Since the vmalloc area is global, it is unnecessary
@@ -153,6 +155,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
  		no_context(regs, addr);
  		return;
  	}
+	if (pmd_leaf(*pmd_k))
+		goto flush_tlb;
  	/*
  	 * Make sure the actual PTE exists as well to

arch/riscv/mm/fault.c static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a · line 181

Quoted 6 lines
arch/riscv/mm/fault.c +1 -0
@@ -172,6 +176,7 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
  	 * ordering constraint, not a cache flush; it is
  	 * necessary even after writing invalid entries.
  	 */
+flush_tlb:
  	local_flush_tlb_page(addr);
  }

This looks good to me, you can add:

Quoted 8 lines

One question: how did you encounter this bug?

Thanks,

Alex

Hi Alex,

Quoted 1 line
Quoted 1 line
Quoted 1 line

One question: how did you encounter this bug?

This bug is caused by the combination of out-of-order excutiuon and ioremap(). The OoO excution will try to access the VA that is given by ioremap() and record a page fault in TLB before the mapping is created in ioremap(). When the CPU really accesses the VA after ioremap(), the CPU will trigger page fault because of the TLB already has the VA mapping.

We hope that the vmalloc_fault() in page fault handler will trigger sfence.vma to invalidate the TLB[1]. But since we do not support the huge page in vmalloc_fault(), we encountered the nested page faults in vmalloc_fault() while forcing the pmd/pud huge pages to resolve pte entry. This is the reason I send this patch.

ref:

    [1]: https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/