Skip to contentSkip to conversation

Risc-V Svinval support

RFC PATCH In review Mayuresh Chitale 2 participants 4 messages Feb 16, 2022 – Feb 28, 2022 RISC-V

lore
Share & tools
lore
#0 lore raw

cover Risc-V Svinval support

This patch adds support for the Svinval extension version 1.0 as defined in the Risc V Privileged specification. It depends on and needs to be applied on the following patchsets from Atish and Anup respectively:

https://patchwork.kernel.org/project/linux-riscv/list/?series=613234
https://patchwork.kernel.org/project/linux-riscv/list/?series=609361

The feature was tested with qemu from latest staging branch with following additional patch:
https://lists.nongnu.org/archive/html/qemu-riscv/2022-02/msg00100.html

Mayuresh Chitale (2):
riscv: enum for svinval extension
riscv: mm: use svinval instructions instead of sfence.vma

 arch/riscv/include/asm/hwcap.h    |  1 +
 arch/riscv/include/asm/tlbflush.h | 14 +++++++
 arch/riscv/kernel/cpu.c           |  1 +
 arch/riscv/kernel/setup.c         |  1 +
 arch/riscv/mm/Makefile            |  1 +
 arch/riscv/mm/tlb.S               | 53 +++++++++++++++++++++++
 arch/riscv/mm/tlbflush.c          | 70 ++++++++++++++++++++++++++++---
 7 files changed, 135 insertions(+), 6 deletions(-)
 create mode 100644 arch/riscv/mm/tlb.S
Signature · 1 line
2.25.1
#1 lore raw

RFC PATCH 1/2 riscv: enum for svinval extension

Similar to the other ISA extensions, this patch enables callers to check for the presence for the svinval extension.

---
 arch/riscv/include/asm/hwcap.h | 1 +
 arch/riscv/kernel/cpu.c        | 1 +
 2 files changed, 2 insertions(+)
arch/riscv/include/asm/hwcap.h +1 -0
index 691fc9c8099b..bbff7cb279ea 100644
@@ -51,6 +51,7 @@ extern unsigned long elf_hwcap;
  * available logical extension id.
  */
 enum riscv_isa_ext_id {
+	RISCV_ISA_EXT_SVINVAL = RISCV_ISA_EXT_BASE,
 	RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX,
 };
 
arch/riscv/kernel/cpu.c +1 -0
index ced7e5be8641..ff0613f8cc39 100644
@@ -71,6 +71,7 @@ int riscv_of_parent_hartid(struct device_node *node)
 	}
 
 static struct riscv_isa_ext_data isa_ext_arr[] = {
+	__RISCV_ISA_EXT_DATA(svinval, RISCV_ISA_EXT_SVINVAL),
 	__RISCV_ISA_EXT_DATA("", RISCV_ISA_EXT_MAX),
 };
 
Signature · 1 line
2.25.1
#2 lore raw

Re: [RFC PATCH 1/2] riscv: enum for svinval extension

Quoted 5 lines · Mayuresh Chitale

Similar to the other ISA extensions, this patch enables callers to check for the presence for the svinval extension.

Please update riscv_fill_hwcap() in arch/riscv/kernel/cpufeature.c to probe Svinval extension.

Regards,
Anup

Quoted 32 lines
---
 arch/riscv/include/asm/hwcap.h | 1 +
 arch/riscv/kernel/cpu.c        | 1 +
 2 files changed, 2 insertions(+)
arch/riscv/include/asm/hwcap.h +1 -0
index 691fc9c8099b..bbff7cb279ea 100644
@@ -51,6 +51,7 @@ extern unsigned long elf_hwcap;
  * available logical extension id.
  */
 enum riscv_isa_ext_id {
+       RISCV_ISA_EXT_SVINVAL = RISCV_ISA_EXT_BASE,
        RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX,
 };
 
arch/riscv/kernel/cpu.c +1 -1
index ced7e5be8641..ff0613f8cc39 100644
@@ -71,6 +71,7 @@ int riscv_of_parent_hartid(struct device_node *node)
        }
 
 static struct riscv_isa_ext_data isa_ext_arr[] = {
+       __RISCV_ISA_EXT_DATA(svinval, RISCV_ISA_EXT_SVINVAL),
        __RISCV_ISA_EXT_DATA("", RISCV_ISA_EXT_MAX),
 };
 
--

2.25.1

#3 lore raw

RFC PATCH 2/2 riscv: mm: use svinval instructions instead of sfence.vma

In reply to Mayuresh Chitale

When svinval is supported the local_flush_tlb_page* functions would prefer to use the following sequence to optimize the tlb flushes instead of a simple sfence.vma:

sfence.w.inval
svinval.vma
.
.
svinval.vma
sfence.inval.ir

The maximum number of consecutive svinval.vma instructions that can be executed in local_flush_tlb_page* functions is limited to PTRS_PER_PTE. This is required to avoid soft lockups and the approach is similar to that used in arm64.

---
 arch/riscv/include/asm/tlbflush.h | 14 +++++++
 arch/riscv/kernel/setup.c         |  1 +
 arch/riscv/mm/Makefile            |  1 +
 arch/riscv/mm/tlb.S               | 53 +++++++++++++++++++++++
 arch/riscv/mm/tlbflush.c          | 70 ++++++++++++++++++++++++++++---
 5 files changed, 133 insertions(+), 6 deletions(-)
 create mode 100644 arch/riscv/mm/tlb.S
arch/riscv/include/asm/tlbflush.h +14 -0
index 801019381dea..9256a1c2ee03 100644
@@ -22,9 +22,23 @@ static inline void local_flush_tlb_page(unsigned long addr)
 {
 	ALT_FLUSH_TLB_PAGE(__asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory"));
 }
+
+void riscv_tlbflush_init(void);
+void __riscv_sfence_w_inval(void);
+void __riscv_sfence_inval_ir(void);
+void __riscv_sinval_vma(unsigned long addr);
+void __riscv_sinval_vma_asid(unsigned long addr, unsigned long asid);
+
+/* Check if we can use sinval for tlb flush */
+DECLARE_STATIC_KEY_FALSE(riscv_flush_tlb_svinval);
+#define riscv_use_flush_tlb_svinval() \
+	static_branch_unlikely(&riscv_flush_tlb_svinval)
+
 #else /* CONFIG_MMU */
 #define local_flush_tlb_all()			do { } while (0)
 #define local_flush_tlb_page(addr)		do { } while (0)
+#define riscv_use_flush_tlb_svinval()		do { } while (0)
+#define riscv_tlbflush_init()			do { } while (0)
 #endif /* CONFIG_MMU */
 
 #if defined(CONFIG_SMP) && defined(CONFIG_MMU)
arch/riscv/kernel/setup.c +1 -0
index b42bfdc67482..5dc79288b0ad 100644
@@ -295,6 +295,7 @@ void __init setup_arch(char **cmdline_p)
 #endif
 
 	riscv_fill_hwcap();
+	riscv_tlbflush_init();
 }
 
 static int __init topology_init(void)
arch/riscv/mm/Makefile +1 -0
index 7ebaef10ea1b..d3a14d4d144e 100644
@@ -16,6 +16,7 @@ obj-y += context.o
 
 ifeq ($(CONFIG_MMU),y)
 obj-$(CONFIG_SMP) += tlbflush.o
+obj-$(CONFIG_SMP) += tlb.o
 endif
 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
 obj-$(CONFIG_PTDUMP_CORE) += ptdump.o
arch/riscv/mm/tlb.S new file +53 -0

53 lines not on this page · raw message

arch/riscv/mm/tlbflush.c +64 -6

97 lines not on this page · raw message

Signature · 1 line
2.25.1