Skip to contentSkip to conversation

Add zicboz support for riscv kvmtool

PATCH In review Ben Dooks 2 participants 7 messages Apr 18, 2023

Subsystems (2)
lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

This is two simple patches, the first to sync the defines to ensure that the struct kvm_riscv_config is sync with upstream and the second to allow zicboz support into the guest.

[PATCH kvmtool 1/2] riscv: add mvendorid/marchid/mimpid to sync [PATCH kvmtool 2/2] riscv: add zicboz support

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#1 lore raw

PATCH 1/2 riscv: add mvendorid/marchid/mimpid to sync kvm_riscv_config

Add the ONE_REG for the mvendorid/marchid/mimpid from the kernel commit 6ebbdecff6ae00557a52539287b681641f4f0d33, to ensure the struct is in sync with newer kernels for adding zicboz.

Ref: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/id=6ebbdecff6ae00557a52539287b681641f4f0d33

---
 riscv/include/asm/kvm.h | 3 +++
 1 file changed, 3 insertions(+)
riscv/include/asm/kvm.h +3 -0
index 8985ff2..92af6f3 100644
@@ -49,6 +49,9 @@ struct kvm_sregs {
 struct kvm_riscv_config {
 	unsigned long isa;
 	unsigned long zicbom_block_size;
+	unsigned long mvendorid;
+	unsigned long marchid;
+	unsigned long mimpid;
 };
 
 /* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
Signature · 7 lines
2.39.2


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#2 lore raw

Re: [PATCH kvmtool 1/2] riscv: add mvendorid/marchid/mimpid to sync kvm_riscv_config

Quoted 28 lines · Ben Dooks

Add the ONE_REG for the mvendorid/marchid/mimpid from the kernel commit 6ebbdecff6ae00557a52539287b681641f4f0d33, to ensure the struct is in sync with newer kernels for adding zicboz.

Ref: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/id=6ebbdecff6ae00557a52539287b681641f4f0d33

---
 riscv/include/asm/kvm.h | 3 +++
 1 file changed, 3 insertions(+)
riscv/include/asm/kvm.h +3 -0
index 8985ff2..92af6f3 100644
@@ -49,6 +49,9 @@ struct kvm_sregs {
 struct kvm_riscv_config {
 	unsigned long isa;
 	unsigned long zicbom_block_size;
+	unsigned long mvendorid;
+	unsigned long marchid;
+	unsigned long mimpid;
 };
 
 /* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
Signature · 1 line
2.39.2

These should get updated with a proper header update using util/update_headers.sh

Thanks,
drew

author
#3 lore raw

PATCH 2/2 riscv: add zicboz support

In reply to Ben Dooks

Like ZICBOM, the ZICBOZ extension requires passing extra information to the guest. Add the control to pass the information to the guest, get it from the kvm ioctl and pass into the guest via the device-tree info.

---
 riscv/fdt.c                         | 11 +++++++++++
 riscv/include/asm/kvm.h             |  2 ++
 riscv/include/kvm/kvm-config-arch.h |  3 +++
 3 files changed, 16 insertions(+)
riscv/fdt.c +11 -0
index 3cdb95c..fa6d153 100644
@@ -20,6 +20,7 @@ struct isa_ext_info isa_info_arr[] = {
 	{"svinval", KVM_RISCV_ISA_EXT_SVINVAL},
 	{"zihintpause", KVM_RISCV_ISA_EXT_ZIHINTPAUSE},
 	{"zicbom", KVM_RISCV_ISA_EXT_ZICBOM},
+	{"zicboz", KVM_RISCV_ISA_EXT_ZICBOZ},
 };
 
 static void dump_fdt(const char *dtb_file, void *fdt)
@@ -46,6 +47,7 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
 	const char *valid_isa_order = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 	int arr_sz = ARRAY_SIZE(isa_info_arr);
 	unsigned long cbom_blksz = 0;
+	unsigned long cboz_blksz = 0;
 
 	_FDT(fdt_begin_node(fdt, "cpus"));
 	_FDT(fdt_property_cell(fdt, "#address-cells", 0x1));
@@ -95,6 +97,13 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
 					die("KVM_GET_ONE_REG failed (config.zicbom_block_size)");
 			}
 
+			if (isa_info_arr[i].ext_id == KVM_RISCV_ISA_EXT_ZICBOZ && !cboz_blksz) {
+				reg.id = RISCV_CONFIG_REG(zicboz_block_size);
+				reg.addr = (unsigned long)&cboz_blksz;
+				if (ioctl(vcpu->vcpu_fd, KVM_GET_ONE_REG, &reg) < 0)
+					die("KVM_GET_ONE_REG failed (config.zicboz_block_size)");
+			}
+
 			if ((strlen(isa_info_arr[i].name) + pos + 1) >= CPU_ISA_MAX_LEN) {
 				pr_warning("Insufficient space to append ISA exension\n");
 				break;
@@ -116,6 +125,8 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
 		_FDT(fdt_property_string(fdt, "riscv,isa", cpu_isa));
 		if (cbom_blksz)
 			_FDT(fdt_property_cell(fdt, "riscv,cbom-block-size", cbom_blksz));
+		if (cboz_blksz)
+			_FDT(fdt_property_cell(fdt, "riscv,cboz-block-size", cboz_blksz));
 		_FDT(fdt_property_cell(fdt, "reg", cpu));
 		_FDT(fdt_property_string(fdt, "status", "okay"));
 
riscv/include/asm/kvm.h +2 -0
index 92af6f3..e44c1e9 100644
@@ -52,6 +52,7 @@ struct kvm_riscv_config {
 	unsigned long mvendorid;
 	unsigned long marchid;
 	unsigned long mimpid;
+	unsigned long zicboz_block_size;
 };
 
 /* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
@@ -105,6 +106,7 @@ enum KVM_RISCV_ISA_EXT_ID {
 	KVM_RISCV_ISA_EXT_SVINVAL,
 	KVM_RISCV_ISA_EXT_ZIHINTPAUSE,
 	KVM_RISCV_ISA_EXT_ZICBOM,
+	KVM_RISCV_ISA_EXT_ZICBOZ,
 	KVM_RISCV_ISA_EXT_MAX,
 };
 
riscv/include/kvm/kvm-config-arch.h +3 -0
index 188125c..46a774e 100644
@@ -24,6 +24,9 @@ struct kvm_config_arch {
 	OPT_BOOLEAN('\0', "disable-zicbom",				\
 		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZICBOM],	\
 		    "Disable Zicbom Extension"),			\
+	OPT_BOOLEAN('\0', "disable-zicboz",				\
+		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZICBOZ],	\
+		    "Disable Zicboz Extension"),			\
 	OPT_BOOLEAN('\0', "disable-zihintpause",			\
 		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZIHINTPAUSE],\
 		    "Disable Zihintpause Extension"),
Signature · 7 lines
2.39.2


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#4 lore raw

Re: [PATCH kvmtool 2/2] riscv: add zicboz support

Quoted 10 lines · Ben Dooks

Like ZICBOM, the ZICBOZ extension requires passing extra information to the guest. Add the control to pass the information to the guest, get it from the kvm ioctl and pass into the guest via the device-tree info.

---
 riscv/fdt.c                         | 11 +++++++++++
 riscv/include/asm/kvm.h             |  2 ++
 riscv/include/kvm/kvm-config-arch.h |  3 +++
 3 files changed, 16 insertions(+)

Hi Ben,

I have a patch almost identical to this one here

https://github.com/jones-drew/kvmtool/commit/f44010451e023b204bb1ef9767de20e0f20aca1c

The differences are that I don't add the header changes in this patch (as they'll come with a proper header update after Linux patches get merged), and I forgot to add the disable-zicboz, which you have.

I was planning on posting after the Linux patches get merged so I could do the proper header update first.

Thanks,
drew

Quoted 81 lines
riscv/fdt.c +11 -0
index 3cdb95c..fa6d153 100644
@@ -20,6 +20,7 @@ struct isa_ext_info isa_info_arr[] = {
 	{"svinval", KVM_RISCV_ISA_EXT_SVINVAL},
 	{"zihintpause", KVM_RISCV_ISA_EXT_ZIHINTPAUSE},
 	{"zicbom", KVM_RISCV_ISA_EXT_ZICBOM},
+	{"zicboz", KVM_RISCV_ISA_EXT_ZICBOZ},
 };
 
 static void dump_fdt(const char *dtb_file, void *fdt)
@@ -46,6 +47,7 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
 	const char *valid_isa_order = "IEMAFDQCLBJTPVNSUHKORWXYZG";
 	int arr_sz = ARRAY_SIZE(isa_info_arr);
 	unsigned long cbom_blksz = 0;
+	unsigned long cboz_blksz = 0;
 
 	_FDT(fdt_begin_node(fdt, "cpus"));
 	_FDT(fdt_property_cell(fdt, "#address-cells", 0x1));
@@ -95,6 +97,13 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
 					die("KVM_GET_ONE_REG failed (config.zicbom_block_size)");
 			}
 
+			if (isa_info_arr[i].ext_id == KVM_RISCV_ISA_EXT_ZICBOZ && !cboz_blksz) {
+				reg.id = RISCV_CONFIG_REG(zicboz_block_size);
+				reg.addr = (unsigned long)&cboz_blksz;
+				if (ioctl(vcpu->vcpu_fd, KVM_GET_ONE_REG, &reg) < 0)
+					die("KVM_GET_ONE_REG failed (config.zicboz_block_size)");
+			}
+
 			if ((strlen(isa_info_arr[i].name) + pos + 1) >= CPU_ISA_MAX_LEN) {
 				pr_warning("Insufficient space to append ISA exension\n");
 				break;
@@ -116,6 +125,8 @@ static void generate_cpu_nodes(void *fdt, struct kvm *kvm)
 		_FDT(fdt_property_string(fdt, "riscv,isa", cpu_isa));
 		if (cbom_blksz)
 			_FDT(fdt_property_cell(fdt, "riscv,cbom-block-size", cbom_blksz));
+		if (cboz_blksz)
+			_FDT(fdt_property_cell(fdt, "riscv,cboz-block-size", cboz_blksz));
 		_FDT(fdt_property_cell(fdt, "reg", cpu));
 		_FDT(fdt_property_string(fdt, "status", "okay"));
 
riscv/include/asm/kvm.h +2 -0
index 92af6f3..e44c1e9 100644
@@ -52,6 +52,7 @@ struct kvm_riscv_config {
 	unsigned long mvendorid;
 	unsigned long marchid;
 	unsigned long mimpid;
+	unsigned long zicboz_block_size;
 };
 
 /* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
@@ -105,6 +106,7 @@ enum KVM_RISCV_ISA_EXT_ID {
 	KVM_RISCV_ISA_EXT_SVINVAL,
 	KVM_RISCV_ISA_EXT_ZIHINTPAUSE,
 	KVM_RISCV_ISA_EXT_ZICBOM,
+	KVM_RISCV_ISA_EXT_ZICBOZ,
 	KVM_RISCV_ISA_EXT_MAX,
 };
 
riscv/include/kvm/kvm-config-arch.h +3 -0
index 188125c..46a774e 100644
@@ -24,6 +24,9 @@ struct kvm_config_arch {
 	OPT_BOOLEAN('\0', "disable-zicbom",				\
 		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZICBOM],	\
 		    "Disable Zicbom Extension"),			\
+	OPT_BOOLEAN('\0', "disable-zicboz",				\
+		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZICBOZ],	\
+		    "Disable Zicboz Extension"),			\
 	OPT_BOOLEAN('\0', "disable-zihintpause",			\
 		    &(cfg)->ext_disabled[KVM_RISCV_ISA_EXT_ZIHINTPAUSE],\
 		    "Disable Zihintpause Extension"),
Signature · 1 line
2.39.2
author
#5 lore raw

Re: [PATCH kvmtool 2/2] riscv: add zicboz support

Quoted 16 lines · Andrew Jones
Quoted 10 lines · Ben Dooks

Like ZICBOM, the ZICBOZ extension requires passing extra information to the guest. Add the control to pass the information to the guest, get it from the kvm ioctl and pass into the guest via the device-tree info.

---
  riscv/fdt.c                         | 11 +++++++++++
  riscv/include/asm/kvm.h             |  2 ++
  riscv/include/kvm/kvm-config-arch.h |  3 +++
  3 files changed, 16 insertions(+)

Hi Ben,

I have a patch almost identical to this one here

Quoted 9 lines

https://github.com/jones-drew/kvmtool/commit/f44010451e023b204bb1ef9767de20e0f20aca1c

The differences are that I don't add the header changes in this patch (as they'll come with a proper header update after Linux patches get merged), and I forgot to add the disable-zicboz, which you have.

I was planning on posting after the Linux patches get merged so I could do the proper header update first.

I thought they had been, I just cherry-picked them (although I may have just used linux-next instead of linux-upstream). I've been testing this under qemu so it seems to be working so far with what i've been doing.

Signature · 4 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html
#6 lore raw

Re: [PATCH kvmtool 2/2] riscv: add zicboz support

Quoted 23 lines · Ben Dooks
Quoted 22 lines · Andrew Jones
Quoted 10 lines · Ben Dooks

Like ZICBOM, the ZICBOZ extension requires passing extra information to the guest. Add the control to pass the information to the guest, get it from the kvm ioctl and pass into the guest via the device-tree info.

---
  riscv/fdt.c                         | 11 +++++++++++
  riscv/include/asm/kvm.h             |  2 ++
  riscv/include/kvm/kvm-config-arch.h |  3 +++
  3 files changed, 16 insertions(+)

Hi Ben,

I have a patch almost identical to this one here

https://github.com/jones-drew/kvmtool/commit/f44010451e023b204bb1ef9767de20e0f20aca1c

The differences are that I don't add the header changes in this patch (as they'll come with a proper header update after Linux patches get merged), and I forgot to add the disable-zicboz, which you have.

Quoted 8 lines
Quoted 3 lines

I was planning on posting after the Linux patches get merged so I could do the proper header update first.

I thought they had been, I just cherry-picked them (although I may have just used linux-next instead of linux-upstream). I've been testing this under qemu so it seems to be working so far with what i've been doing.

Yeah, just -next, so far. Thanks for the testing!

drew

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv