Risc-V Svinval support
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
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
@@ -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
@@ -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
RFC PATCH 2/2 riscv: mm: use svinval instructions instead of sfence.vma
In reply to Mayuresh ChitaleWhen 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
@@ -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
@@ -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
@@ -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
Re: [RFC PATCH 1/2] riscv: enum for svinval extension
In reply to Mayuresh ChitaleQuoted 5 lines · Mayuresh Chitale
Similar to the other ISA extensions, this patch enables callers to check for the presence for the svinval extension.
Signed-off-by Mayuresh Chitale <[email protected]>
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@@ -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@@ -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