Skip to contentSkip to conversation

Svinval support for KVM RISC-V

PATCH In review Anup Patel 3 participants 6 messages Sep 2, 2022 – Sep 16, 2022

Subsystems (3)
lore
Share & tools
lore

Anup Patel

author
#0 lore raw

cover Svinval support for KVM RISC-V

This series adds Svinval extension support for both Host hypervisor and Guest.

These patches can also be found in riscv_kvm_svinval_v1 branch at:
https://github.com/avpatel/linux.git

The corresponding KVMTOOL patches are available in riscv_svinval_v1 branch at: https://github.com/avpatel/kvmtool.git

Anup Patel (2):
RISC-V: KVM: Use Svinval for local TLB maintenance when available
RISC-V: KVM: Allow Guest use Svinval extension

Mayuresh Chitale (1):
RISC-V: Probe Svinval extension form ISA string

 arch/riscv/include/asm/hwcap.h    |  4 +++
 arch/riscv/include/asm/insn-def.h | 20 +++++++++++
 arch/riscv/include/uapi/asm/kvm.h |  1 +
 arch/riscv/kernel/cpu.c           |  1 +
 arch/riscv/kernel/cpufeature.c    |  1 +
 arch/riscv/kvm/tlb.c              | 60 ++++++++++++++++++++++++-------
 arch/riscv/kvm/vcpu.c             |  2 ++
 7 files changed, 77 insertions(+), 12 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/3 RISC-V: Probe Svinval extension form ISA string

From: Mayuresh Chitale <[email protected]>

Just like other ISA extensions, we allow callers/users to detect the presence of Svinval extension from ISA string.

---
 arch/riscv/include/asm/hwcap.h | 4 ++++
 arch/riscv/kernel/cpu.c        | 1 +
 arch/riscv/kernel/cpufeature.c | 1 +
 3 files changed, 6 insertions(+)
arch/riscv/include/asm/hwcap.h +4 -0
index 6f59ec64175e..b22525290073 100644
@@ -58,6 +58,7 @@ enum riscv_isa_ext_id {
 	RISCV_ISA_EXT_ZICBOM,
 	RISCV_ISA_EXT_ZIHINTPAUSE,
 	RISCV_ISA_EXT_SSTC,
+	RISCV_ISA_EXT_SVINVAL,
 	RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX,
 };
 
@@ -69,6 +70,7 @@ enum riscv_isa_ext_id {
 enum riscv_isa_ext_key {
 	RISCV_ISA_EXT_KEY_FPU,		/* For 'F' and 'D' */
 	RISCV_ISA_EXT_KEY_ZIHINTPAUSE,
+	RISCV_ISA_EXT_KEY_SVINVAL,
 	RISCV_ISA_EXT_KEY_MAX,
 };
 
@@ -90,6 +92,8 @@ static __always_inline int riscv_isa_ext2key(int num)
 		return RISCV_ISA_EXT_KEY_FPU;
 	case RISCV_ISA_EXT_ZIHINTPAUSE:
 		return RISCV_ISA_EXT_KEY_ZIHINTPAUSE;
+	case RISCV_ISA_EXT_SVINVAL:
+		return RISCV_ISA_EXT_KEY_SVINVAL;
 	default:
 		return -EINVAL;
 	}
arch/riscv/kernel/cpu.c +1 -0
index 0be8a2403212..7d1cd653ca02 100644
@@ -96,6 +96,7 @@ static struct riscv_isa_ext_data isa_ext_arr[] = {
 	__RISCV_ISA_EXT_DATA(zicbom, RISCV_ISA_EXT_ZICBOM),
 	__RISCV_ISA_EXT_DATA(zihintpause, RISCV_ISA_EXT_ZIHINTPAUSE),
 	__RISCV_ISA_EXT_DATA(sstc, RISCV_ISA_EXT_SSTC),
+	__RISCV_ISA_EXT_DATA(svinval, RISCV_ISA_EXT_SVINVAL),
 	__RISCV_ISA_EXT_DATA("", RISCV_ISA_EXT_MAX),
 };
 
arch/riscv/kernel/cpufeature.c +1 -0
index 3b5583db9d80..9774f1271f93 100644
@@ -204,6 +204,7 @@ void __init riscv_fill_hwcap(void)
 				SET_ISA_EXT_MAP("zicbom", RISCV_ISA_EXT_ZICBOM);
 				SET_ISA_EXT_MAP("zihintpause", RISCV_ISA_EXT_ZIHINTPAUSE);
 				SET_ISA_EXT_MAP("sstc", RISCV_ISA_EXT_SSTC);
+				SET_ISA_EXT_MAP("svinval", RISCV_ISA_EXT_SVINVAL);
 			}
 #undef SET_ISA_EXT_MAP
 		}
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/3 RISC-V: KVM: Use Svinval for local TLB maintenance when available

In reply to Anup Patel

We should prefer HINVAL.GVMA and HINVAL.VVMA instruction for local TLB maintenance when underlying host supports Svinval extension.

---
 arch/riscv/include/asm/insn-def.h | 20 +++++++++++
 arch/riscv/kvm/tlb.c              | 60 ++++++++++++++++++++++++-------
 2 files changed, 68 insertions(+), 12 deletions(-)
arch/riscv/include/asm/insn-def.h +20 -0
index 8fe9036efb68..246a627d16ee 100644
@@ -110,4 +110,24 @@
 	__ASM_STR(.error "hlv.d requires 64-bit support")
 #endif
 
+#define SINVAL_VMA(vaddr, asid)					\
+	INSN_R(OPCODE_SYSTEM, FUNC3(0), FUNC7(11),		\
+	       __RD(0), RS1(vaddr), RS2(asid))
+
+#define SFENCE_W_INVAL()					\
+	INSN_R(OPCODE_SYSTEM, FUNC3(0), FUNC7(12),		\
+	       __RD(0), __RS1(0), __RS2(0))
+
+#define SFENCE_INVAL_IR()					\
+	INSN_R(OPCODE_SYSTEM, FUNC3(0), FUNC7(12),		\
+	       __RD(0), __RS1(0), __RS2(1))
+
+#define HINVAL_VVMA(vaddr, asid)				\
+	INSN_R(OPCODE_SYSTEM, FUNC3(0), FUNC7(19),		\
+	       __RD(0), RS1(vaddr), RS2(asid))
+
+#define HINVAL_GVMA(gaddr, vmid)				\
+	INSN_R(OPCODE_SYSTEM, FUNC3(0), FUNC7(51),		\
+	       __RD(0), RS1(gaddr), RS2(vmid))
+
 #endif /* __ASM_INSN_DEF_H */
arch/riscv/kvm/tlb.c +48 -12

92 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#3 lore raw

PATCH 3/3 RISC-V: KVM: Allow Guest use Svinval extension

In reply to Anup Patel

We should advertise Svinval ISA extension to KVM user-space whenever host supports it. This will allow KVM user-space (i.e. QEMU or KVMTOOL) to pass on this information to Guest via ISA string.

---
 arch/riscv/include/uapi/asm/kvm.h | 1 +
 arch/riscv/kvm/vcpu.c             | 2 ++
 2 files changed, 3 insertions(+)
arch/riscv/include/uapi/asm/kvm.h +1 -0
index 7351417afd62..b6770ee08872 100644
@@ -98,6 +98,7 @@ enum KVM_RISCV_ISA_EXT_ID {
 	KVM_RISCV_ISA_EXT_M,
 	KVM_RISCV_ISA_EXT_SVPBMT,
 	KVM_RISCV_ISA_EXT_SSTC,
+	KVM_RISCV_ISA_EXT_SVINVAL,
 	KVM_RISCV_ISA_EXT_MAX,
 };
 
arch/riscv/kvm/vcpu.c +2 -0
index d0f08d5b4282..901bb5c0cb50 100644
@@ -53,6 +53,7 @@ static const unsigned long kvm_isa_ext_arr[] = {
 	RISCV_ISA_EXT_m,
 	RISCV_ISA_EXT_SVPBMT,
 	RISCV_ISA_EXT_SSTC,
+	RISCV_ISA_EXT_SVINVAL,
 };
 
 static unsigned long kvm_riscv_vcpu_base2isa_ext(unsigned long base_ext)
@@ -87,6 +88,7 @@ static bool kvm_riscv_vcpu_isa_disable_allowed(unsigned long ext)
 	case KVM_RISCV_ISA_EXT_I:
 	case KVM_RISCV_ISA_EXT_M:
 	case KVM_RISCV_ISA_EXT_SSTC:
+	case KVM_RISCV_ISA_EXT_SVINVAL:
 		return false;
 	default:
 		break;
Signature · 1 line
2.34.1
Reviewed-by on the v1 series
#4 lore raw
In reply to Anup Patel
Quoted 16 lines · Anup Patel

This series adds Svinval extension support for both Host hypervisor and Guest.

These patches can also be found in riscv_kvm_svinval_v1 branch at:
https://github.com/avpatel/linux.git

The corresponding KVMTOOL patches are available in riscv_svinval_v1 branch at: https://github.com/avpatel/kvmtool.git

Anup Patel (2):
RISC-V: KVM: Use Svinval for local TLB maintenance when available
RISC-V: KVM: Allow Guest use Svinval extension

Mayuresh Chitale (1):
RISC-V: Probe Svinval extension form ISA string

Quoted 11 lines
 arch/riscv/include/asm/hwcap.h    |  4 +++
 arch/riscv/include/asm/insn-def.h | 20 +++++++++++
 arch/riscv/include/uapi/asm/kvm.h |  1 +
 arch/riscv/kernel/cpu.c           |  1 +
 arch/riscv/kernel/cpufeature.c    |  1 +
 arch/riscv/kvm/tlb.c              | 60 ++++++++++++++++++++++++-------
 arch/riscv/kvm/vcpu.c             |  2 ++
 7 files changed, 77 insertions(+), 12 deletions(-)
Signature · 1 line
2.34.1

For the series,

maintainer
#5 lore raw
In reply to Anup Patel
Quoted 10 lines · Anup Patel

This series adds Svinval extension support for both Host hypervisor and Guest.

These patches can also be found in riscv_kvm_svinval_v1 branch at:
https://github.com/avpatel/linux.git

The corresponding KVMTOOL patches are available in riscv_svinval_v1 branch at: https://github.com/avpatel/kvmtool.git

Quoted 6 lines

Anup Patel (2):
RISC-V: KVM: Use Svinval for local TLB maintenance when available
RISC-V: KVM: Allow Guest use Svinval extension

Mayuresh Chitale (1):
RISC-V: Probe Svinval extension form ISA string

I have queued this series for 6.1

Thanks,
Anup

Quoted 13 lines
 arch/riscv/include/asm/hwcap.h    |  4 +++
 arch/riscv/include/asm/insn-def.h | 20 +++++++++++
 arch/riscv/include/uapi/asm/kvm.h |  1 +
 arch/riscv/kernel/cpu.c           |  1 +
 arch/riscv/kernel/cpufeature.c    |  1 +
 arch/riscv/kvm/tlb.c              | 60 ++++++++++++++++++++++++-------
 arch/riscv/kvm/vcpu.c             |  2 ++
 7 files changed, 77 insertions(+), 12 deletions(-)

--
2.34.1