Skip to contentSkip to conversation

Add RISC-V ISA extensions based on Linux-6.10

PATCH Applied Anup Patel 2 participants 7 messages Aug 21, 2024 – Aug 30, 2024

Subsystems (5)
lore
Share & tools
lore

Anup Patel

author
#0 lore raw

v3 cover Add RISC-V ISA extensions based on Linux-6.10

This series adds support for new ISA extensions based on Linux-6.10 namely:
Sscofpmf.

These patches can also be found in the riscv_more_exts_round3_v3 branch
at: https://github.com/avpatel/kvmtool.git

Changes since v2:
- Include a fix to correct number of hart bits for AIA

Changes since v1:
- Included a fix for DBCN

Andrew Jones (2):
riscv: Set SBI_SUCCESS on successful DBCN call
riscv: Correct number of hart bits

Anup Patel (1):
Sync-up headers with Linux-6.10 kernel

Atish Patra (1):
riscv: Add Sscofpmf extensiona support

 include/linux/kvm.h                 |   4 +-
 include/linux/virtio_net.h          | 143 ++++++++++++++++++++++++++++
 riscv/aia.c                         |   2 +-
 riscv/fdt.c                         |   1 +
 riscv/include/asm/kvm.h             |   1 +
 riscv/include/kvm/kvm-config-arch.h |   3 +
 riscv/kvm-cpu.c                     |   1 +
 x86/include/asm/kvm.h               |  22 ++++-
 8 files changed, 172 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v3 1/4 Sync-up headers with Linux-6.10 kernel

We sync-up Linux headers to get latest KVM RISC-V headers having Sscofpmf support.

---
 include/linux/kvm.h        |   4 +-
 include/linux/virtio_net.h | 143 +++++++++++++++++++++++++++++++++++++
 riscv/include/asm/kvm.h    |   1 +
 x86/include/asm/kvm.h      |  22 +++++-
 4 files changed, 166 insertions(+), 4 deletions(-)
include/linux/kvm.h +2 -2
index 2190adb..d03842a 100644
@@ -1221,9 +1221,9 @@ struct kvm_vfio_spapr_tce {
 /* Available with KVM_CAP_SPAPR_RESIZE_HPT */
 #define KVM_PPC_RESIZE_HPT_PREPARE _IOR(KVMIO, 0xad, struct kvm_ppc_resize_hpt)
 #define KVM_PPC_RESIZE_HPT_COMMIT  _IOR(KVMIO, 0xae, struct kvm_ppc_resize_hpt)
-/* Available with KVM_CAP_PPC_RADIX_MMU or KVM_CAP_PPC_HASH_MMU_V3 */
+/* Available with KVM_CAP_PPC_MMU_RADIX or KVM_CAP_PPC_MMU_HASH_V3 */
 #define KVM_PPC_CONFIGURE_V3_MMU  _IOW(KVMIO,  0xaf, struct kvm_ppc_mmuv3_cfg)
-/* Available with KVM_CAP_PPC_RADIX_MMU */
+/* Available with KVM_CAP_PPC_MMU_RADIX */
 #define KVM_PPC_GET_RMMU_INFO	  _IOW(KVMIO,  0xb0, struct kvm_ppc_rmmu_info)
 /* Available with KVM_CAP_PPC_GET_CPU_CHAR */
 #define KVM_PPC_GET_CPU_CHAR	  _IOR(KVMIO,  0xb1, struct kvm_ppc_cpu_char)
include/linux/virtio_net.h +143 -0

153 lines not on this page · raw message

riscv/include/asm/kvm.h +1 -0
index b1c503c..e878e7c 100644
@@ -167,6 +167,7 @@ enum KVM_RISCV_ISA_EXT_ID {
 	KVM_RISCV_ISA_EXT_ZFA,
 	KVM_RISCV_ISA_EXT_ZTSO,
 	KVM_RISCV_ISA_EXT_ZACAS,
+	KVM_RISCV_ISA_EXT_SSCOFPMF,
 	KVM_RISCV_ISA_EXT_MAX,
 };
 
x86/include/asm/kvm.h +20 -2
index ef11aa4..9fae1b7 100644
@@ -457,8 +457,13 @@ struct kvm_sync_regs {
 
 #define KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE	0x00000001
 
-/* attributes for system fd (group 0) */
-#define KVM_X86_XCOMP_GUEST_SUPP	0
+/* vendor-independent attributes for system fd (group 0) */
+#define KVM_X86_GRP_SYSTEM		0
+#  define KVM_X86_XCOMP_GUEST_SUPP	0
+
+/* vendor-specific groups and attributes for system fd */
+#define KVM_X86_GRP_SEV			1
+#  define KVM_X86_SEV_VMSA_FEATURES	0
 
 struct kvm_vmx_nested_state_data {
 	__u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
@@ -689,6 +694,9 @@ enum sev_cmd_id {
 	/* Guest Migration Extension */
 	KVM_SEV_SEND_CANCEL,
 
+	/* Second time is the charm; improved versions of the above ioctls.  */
+	KVM_SEV_INIT2,
+
 	KVM_SEV_NR_MAX,
 };
 
@@ -700,6 +708,14 @@ struct kvm_sev_cmd {
 	__u32 sev_fd;
 };
 
+struct kvm_sev_init {
+	__u64 vmsa_features;
+	__u32 flags;
+	__u16 ghcb_version;
+	__u16 pad1;
+	__u32 pad2[8];
+};
+
 struct kvm_sev_launch_start {
 	__u32 handle;
 	__u32 policy;
@@ -856,5 +872,7 @@ struct kvm_hyperv_eventfd {
 
 #define KVM_X86_DEFAULT_VM	0
 #define KVM_X86_SW_PROTECTED_VM	1
+#define KVM_X86_SEV_VM		2
+#define KVM_X86_SEV_ES_VM	3
 
 #endif /* _ASM_X86_KVM_H */
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v3 2/4 riscv: Add Sscofpmf extensiona support

In reply to Anup Patel

From: Atish Patra <[email protected]>

When the Sscofpmf extension is available expose it to the guest via device tree so that guest can use it.

---
 riscv/fdt.c                         | 1 +
 riscv/include/kvm/kvm-config-arch.h | 3 +++
 2 files changed, 4 insertions(+)
riscv/fdt.c +1 -0
index cf367b9..e331f80 100644
@@ -18,6 +18,7 @@ struct isa_ext_info isa_info_arr[] = {
 	/* sorted alphabetically */
 	{"smstateen", KVM_RISCV_ISA_EXT_SMSTATEEN},
 	{"ssaia", KVM_RISCV_ISA_EXT_SSAIA},
+	{"sscofpmf", KVM_RISCV_ISA_EXT_SSCOFPMF},
 	{"sstc", KVM_RISCV_ISA_EXT_SSTC},
 	{"svinval", KVM_RISCV_ISA_EXT_SVINVAL},
 	{"svnapot", KVM_RISCV_ISA_EXT_SVNAPOT},
riscv/include/kvm/kvm-config-arch.h +3 -0
index 17f0ceb..3fbc4f7 100644
@@ -31,6 +31,9 @@ struct kvm_config_arch {
 	OPT_BOOLEAN('\0', "disable-ssaia",				\
 		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SSAIA],	\
 		    "Disable Ssaia Extension"),				\
+	OPT_BOOLEAN('\0', "disable-sscofpmf",				\
+		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SSCOFPMF],	\
+		    "Disable Sscofpmf Extension"),			\
 	OPT_BOOLEAN('\0', "disable-sstc",				\
 		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_SSTC],	\
 		    "Disable Sstc Extension"),				\
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v3 3/4 riscv: Set SBI_SUCCESS on successful DBCN call

In reply to Anup Patel

From: Andrew Jones <[email protected]>

Ensure we explicitly set SBI_SUCCESS on a successful SBI calls since KVM will not initialize it to zero for us. Only DBCN was neglecting to do so.

Fixes 4ddaa4249e0c ("riscv: Handle SBI DBCN calls from Guest/VM")
---
 riscv/kvm-cpu.c | 1 +
 1 file changed, 1 insertion(+)
riscv/kvm-cpu.c +1 -0
index ae87848..0c171da 100644
@@ -162,6 +162,7 @@ static bool kvm_cpu_riscv_sbi(struct kvm_cpu *vcpu)
 		switch (vcpu->kvm_run->riscv_sbi.function_id) {
 		case SBI_EXT_DBCN_CONSOLE_WRITE:
 		case SBI_EXT_DBCN_CONSOLE_READ:
+			vcpu->kvm_run->riscv_sbi.ret[0] = SBI_SUCCESS;
 			addr = vcpu->kvm_run->riscv_sbi.args[1];
 #if __riscv_xlen == 32
 			addr |= (u64)vcpu->kvm_run->riscv_sbi.args[2] << 32;
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH v3 4/4 riscv: Correct number of hart bits

In reply to Anup Patel

From: Andrew Jones <[email protected]>

The number of hart bits should be obtained from the highest hart ID, not the number of harts. For example, if a guest has 2 harts, then the number of bits should be fls(1) == 1.

---
 riscv/aia.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
riscv/aia.c +1 -1
index fe9399a..21d9704 100644
@@ -164,7 +164,7 @@ static int aia__init(struct kvm *kvm)
 	ret = ioctl(aia_fd, KVM_SET_DEVICE_ATTR, &aia_nr_sources_attr);
 	if (ret)
 		return ret;
-	aia_hart_bits = fls_long(kvm->nrcpus);
+	aia_hart_bits = fls_long(kvm->nrcpus - 1);
 	ret = ioctl(aia_fd, KVM_SET_DEVICE_ATTR, &aia_hart_bits_attr);
 	if (ret)
 		return ret;
Signature · 1 line
2.34.1
author
#5 lore raw
In reply to Anup Patel

Hi Will,

Quoted 23 lines · On Wed, Aug 21, 2024 at 7:56?PM Anup Patel <[email protected]> wrote:

This series adds support for new ISA extensions based on Linux-6.10 namely:
Sscofpmf.

These patches can also be found in the riscv_more_exts_round3_v3 branch
at: https://github.com/avpatel/kvmtool.git

Changes since v2:
- Include a fix to correct number of hart bits for AIA

Changes since v1:
- Included a fix for DBCN

Andrew Jones (2):
riscv: Set SBI_SUCCESS on successful DBCN call
riscv: Correct number of hart bits

Anup Patel (1):
Sync-up headers with Linux-6.10 kernel

Atish Patra (1):
riscv: Add Sscofpmf extensiona support

Quoted 9 lines
 include/linux/kvm.h                 |   4 +-
 include/linux/virtio_net.h          | 143 ++++++++++++++++++++++++++++
 riscv/aia.c                         |   2 +-
 riscv/fdt.c                         |   1 +
 riscv/include/asm/kvm.h             |   1 +
 riscv/include/kvm/kvm-config-arch.h |   3 +
 riscv/kvm-cpu.c                     |   1 +
 x86/include/asm/kvm.h               |  22 ++++-
 8 files changed, 172 insertions(+), 5 deletions(-)

Friendly ping !

Regards,
Anup

Applied
#6 lore raw
In reply to Anup Patel
Quoted 10 lines · Anup Patel

This series adds support for new ISA extensions based on Linux-6.10 namely:
Sscofpmf.

These patches can also be found in the riscv_more_exts_round3_v3 branch
at: https://github.com/avpatel/kvmtool.git

Changes since v2:
- Include a fix to correct number of hart bits for AIA

[...]

Applied to kvmtool (master), thanks!

[1/4] Sync-up headers with Linux-6.10 kernel

      https://git.kernel.org/will/kvmtool/c/01171537bcc0
[2/4] riscv: Add Sscofpmf extensiona support
      https://git.kernel.org/will/kvmtool/c/fa958fb68cfb
[3/4] riscv: Set SBI_SUCCESS on successful DBCN call
      https://git.kernel.org/will/kvmtool/c/027784f4c67e
[4/4] riscv: Correct number of hart bits
      https://git.kernel.org/will/kvmtool/c/100fade1ac13

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev