linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC kvmtool 00/10] RISC-V CoVE support
@ 2023-04-19 22:23 Atish Patra
  2023-04-19 22:23 ` [RFC kvmtool 01/10] riscv: Add a CoVE VM type Atish Patra
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Atish Patra @ 2023-04-19 22:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: Atish Patra, Alexandre Ghiti, Andrew Jones, Andrew Morton,
	Anup Patel, Atish Patra, Suzuki K Poulose, Will Deacon,
	Marc Zyngier, Sean Christopherson, linux-coco, Dylan Reid,
	abrestic, Samuel Ortiz, Jiri Slaby, kvm-riscv, kvm, linux-mm,
	linux-riscv, Palmer Dabbelt, Paolo Bonzini, Rajnesh Kanwal,
	Uladzislau Rezki

This series is an initial version of the support for running confidential VMs on
riscv architecture. This is to get feedback on the proposed COVH, COVI and COVG
extensions for running Confidential VMs on riscv. The specification is available
here [0]. Make sure to build it to get the latest changes as it gets updated
from time to time.

We have added a new option, `--cove-vm` to the `run` command to mark the VM as
a confidential VM.

The host including the kernel and kvmtool, must not access any memory allocated
to the confidential VM. The TSM is responsible for providing all the required
information to handle faults and emulate devices.

The series adds support to manage CoVE VMs, which includes:
   * Configuration
   * Creation of CoVE VM and VCPUs.
   * Load initial memory images using measurement ioctls.
   * Virtio support for CoVE VMs.

We don't yet support APLIC and thus no line based interrupts. So we use pci
transport for all the virtio devices. As serial and rtc devices are only mmio
based so we don't yet support those as well.

virtio for the CoVE enforces VIRTIO_F_ACCESS_PLATFORM flag to force SWIOTLB
bounce buffers in confidential linux guest. The SWIOTLB buffers are shared
with the host using share/unshare calls in COVG extension. Thus host can
directly write to those buffers without TSM involvement.

This series depends on few RISC-V series which are not yet upstream.

* AIA support[1]
* SBI DBCN extension[2] 

It also reuses the arch specific virtio host flag hook from CCA series[4].

The patches are also available here:

	https://github.com/rivosinc/kvmtool/commits/cove-integration-03072023

The corresponding linux patches are also available here:
https://github.com/rivosinc/linux/tree/cove-integration

Running a CoVE VM
------------------

Extra options needed:
--cove-vm: Launches a confidential VM.
--virtio-transport: We don't yet support MMIO devices so we need to
                    force virtio device to use pci transport.


 $ lkvm run						\
	 --cove-vm					\
	 --virtio-transport=pci                         \
	 <normal-VM options>

The details instructions can be found at [5]

Links
============
[0] CoVE architecture Specification.
    https://github.com/riscv-non-isa/riscv-ap-tee/blob/main/specification/riscv-aptee-spec.pdf
[1] https://github.com/avpatel/kvmtool/tree/riscv_aia_v1
[2] https://github.com/avpatel/kvmtool/tree/riscv_sbi_dbcn_v1
[4] https://lore.kernel.org/lkml/20230127113932.166089-28-suzuki.poulose@arm.com/
[5] https://github.com/rivosinc/cove/wiki/CoVE-KVM-RISCV64-on-QEMU

Atish Patra (7):
riscv: Add a CoVE VM type.
riscv: Define a command line option for CoVE VM
riscv: Define a measure region IOCTL
riscv: Invoke measure region for VM images
riscv: Do not create APLIC for TVMs
riscv: Change initrd alignment to a page size
riscv: Define riscv specific vm_type function

Rajnesh Kanwal (3):
riscv: virtio: Enforce VIRTIO_F_ACCESS_PLATFORM feature flag.
riscv: Don't emit MMIO devices for CoVE VM.
riscv: cove: Don't emit interrupt_map for pci devices in fdt.

include/linux/kvm.h                 |  4 ++
riscv/aia.c                         | 31 +++++++----
riscv/fdt.c                         | 38 +++++++------
riscv/include/asm/kvm.h             |  6 +++
riscv/include/kvm/kvm-arch.h        |  4 +-
riscv/include/kvm/kvm-config-arch.h |  4 +-
riscv/kvm.c                         | 51 +++++++++++++++++-
riscv/pci.c                         | 83 +++++++++++++++--------------
8 files changed, 152 insertions(+), 69 deletions(-)

--
2.25.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [RFC kvmtool 01/10] riscv: Add a CoVE VM type.
  2023-04-19 22:23 [RFC kvmtool 00/10] RISC-V CoVE support Atish Patra
@ 2023-04-19 22:23 ` Atish Patra
  2023-04-19 22:23 ` [RFC kvmtool 02/10] riscv: Define a command line option for CoVE VM Atish Patra
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Atish Patra @ 2023-04-19 22:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: Atish Patra, Alexandre Ghiti, Andrew Jones, Andrew Morton,
	Anup Patel, Atish Patra, Suzuki K Poulose, Will Deacon,
	Marc Zyngier, Sean Christopherson, linux-coco, Dylan Reid,
	abrestic, Samuel Ortiz, Jiri Slaby, kvm-riscv, kvm, linux-mm,
	linux-riscv, Palmer Dabbelt, Paolo Bonzini, Rajnesh Kanwal,
	Uladzislau Rezki

The KVM needs to distinguish if an user wants to create a CoVE VM instead
of a traditional VM. Define a RISC-V specific CoVE VM type that can be
passed as a VM type.

Signed-off-by: Atish Patra <atishp@rivosinc.com>
---
 include/linux/kvm.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index ba4c4b0..000d2b9 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -911,6 +911,8 @@ struct kvm_ppc_resize_hpt {
 #define KVM_VM_TYPE_ARM_IPA_SIZE_MASK	0xffULL
 #define KVM_VM_TYPE_ARM_IPA_SIZE(x)		\
 	((x) & KVM_VM_TYPE_ARM_IPA_SIZE_MASK)
+
+#define KVM_VM_TYPE_RISCV_COVE  (1UL << 9)
 /*
  * ioctls for /dev/kvm fds:
  */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC kvmtool 02/10] riscv: Define a command line option for CoVE VM
  2023-04-19 22:23 [RFC kvmtool 00/10] RISC-V CoVE support Atish Patra
  2023-04-19 22:23 ` [RFC kvmtool 01/10] riscv: Add a CoVE VM type Atish Patra
@ 2023-04-19 22:23 ` Atish Patra
  2023-04-19 22:23 ` [RFC kvmtool 03/10] riscv: Define a measure region IOCTL Atish Patra
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Atish Patra @ 2023-04-19 22:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: Atish Patra, Alexandre Ghiti, Andrew Jones, Andrew Morton,
	Anup Patel, Atish Patra, Suzuki K Poulose, Will Deacon,
	Marc Zyngier, Sean Christopherson, linux-coco, Dylan Reid,
	abrestic, Samuel Ortiz, Jiri Slaby, kvm-riscv, kvm, linux-mm,
	linux-riscv, Palmer Dabbelt, Paolo Bonzini, Rajnesh Kanwal,
	Uladzislau Rezki

The user should be able configure the VMM to instantiate a CoVE VM via
a command line. Add the new option cove-vm.

Signed-off-by: Atish Patra <atishp@rivosinc.com>
---
 riscv/include/kvm/kvm-config-arch.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h
index aed4fbf..01276ea 100644
--- a/riscv/include/kvm/kvm-config-arch.h
+++ b/riscv/include/kvm/kvm-config-arch.h
@@ -10,6 +10,7 @@ struct kvm_config_arch {
 	u64		custom_mimpid;
 	bool		ext_disabled[KVM_RISCV_ISA_EXT_MAX];
 	bool		sbi_ext_disabled[KVM_RISCV_SBI_EXT_MAX];
+	bool		cove_vm;
 };
 
 #define OPT_ARCH_RUN(pfx, cfg)						\
@@ -66,6 +67,7 @@ struct kvm_config_arch {
 		    "Disable SBI Experimental Extensions"),		\
 	OPT_BOOLEAN('\0', "disable-sbi-vendor",				\
 		    &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_VENDOR],	\
-		    "Disable SBI Vendor Extensions"),
+		    "Disable SBI Vendor Extensions"),			\
+	OPT_BOOLEAN('\0', "cove-vm", &(cfg)->cove_vm, "CoVE VM"),
 
 #endif /* KVM__KVM_CONFIG_ARCH_H */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC kvmtool 03/10] riscv: Define a measure region IOCTL
  2023-04-19 22:23 [RFC kvmtool 00/10] RISC-V CoVE support Atish Patra
  2023-04-19 22:23 ` [RFC kvmtool 01/10] riscv: Add a CoVE VM type Atish Patra
  2023-04-19 22:23 ` [RFC kvmtool 02/10] riscv: Define a command line option for CoVE VM Atish Patra
@ 2023-04-19 22:23 ` Atish Patra
  2023-04-19 22:23 ` [RFC kvmtool 04/10] riscv: Invoke measure region for VM images Atish Patra
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Atish Patra @ 2023-04-19 22:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: Atish Patra, Alexandre Ghiti, Andrew Jones, Andrew Morton,
	Anup Patel, Atish Patra, Suzuki K Poulose, Will Deacon,
	Marc Zyngier, Sean Christopherson, linux-coco, Dylan Reid,
	abrestic, Samuel Ortiz, Jiri Slaby, kvm-riscv, kvm, linux-mm,
	linux-riscv, Palmer Dabbelt, Paolo Bonzini, Rajnesh Kanwal,
	Uladzislau Rezki

CoVE VM images needs to be measured by the TSM. The VMM updates
the host about these images via a new IOCTL. The host makes appropriate
ecalls for TSM to perform the measurement.

Signed-off-by: Atish Patra <atishp@rivosinc.com>
---
 include/linux/kvm.h          |  2 ++
 riscv/include/asm/kvm.h      |  6 ++++++
 riscv/include/kvm/kvm-arch.h |  2 ++
 riscv/kvm.c                  | 21 +++++++++++++++++++++
 4 files changed, 31 insertions(+)

diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 000d2b9..d4969a0 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -1547,6 +1547,8 @@ struct kvm_s390_ucas_mapping {
 #define KVM_PPC_SVM_OFF		  _IO(KVMIO,  0xb3)
 #define KVM_ARM_MTE_COPY_TAGS	  _IOR(KVMIO,  0xb4, struct kvm_arm_copy_mte_tags)
 
+#define KVM_RISCV_COVE_MEASURE_REGION _IOR(KVMIO, 0xb5, struct kvm_riscv_cove_measure_region)
+
 /* ioctl for vm fd */
 #define KVM_CREATE_DEVICE	  _IOWR(KVMIO,  0xe0, struct kvm_create_device)
 
diff --git a/riscv/include/asm/kvm.h b/riscv/include/asm/kvm.h
index 1dce9a4..2bacc38 100644
--- a/riscv/include/asm/kvm.h
+++ b/riscv/include/asm/kvm.h
@@ -98,6 +98,12 @@ struct kvm_riscv_timer {
 	__u64 state;
 };
 
+struct kvm_riscv_cove_measure_region {
+	unsigned long user_addr;
+	unsigned long gpa;
+	unsigned long size;
+};
+
 /*
  * ISA extension IDs specific to KVM. This is not the same as the host ISA
  * extension IDs as that is internal to the host and should not be exposed
diff --git a/riscv/include/kvm/kvm-arch.h b/riscv/include/kvm/kvm-arch.h
index 9f2159f..08ac54a 100644
--- a/riscv/include/kvm/kvm-arch.h
+++ b/riscv/include/kvm/kvm-arch.h
@@ -120,4 +120,6 @@ void riscv__generate_irq_prop(void *fdt, u8 irq, enum irq_type irq_type);
 
 void riscv__irqchip_create(struct kvm *kvm);
 
+void kvm_cove_measure_region(struct kvm *kvm, unsigned long uaddr,
+			      unsigned long gpa, unsigned long rsize);
 #endif /* KVM__KVM_ARCH_H */
diff --git a/riscv/kvm.c b/riscv/kvm.c
index a9ade1f..99b253e 100644
--- a/riscv/kvm.c
+++ b/riscv/kvm.c
@@ -13,6 +13,27 @@ struct kvm_ext kvm_req_ext[] = {
 	{ 0, 0 },
 };
 
+void kvm_cove_measure_region(struct kvm *kvm, unsigned long uaddr,
+			      unsigned long gpa, unsigned long rsize)
+{
+	int ret;
+
+	if (!kvm->cfg.arch.cove_vm)
+		return;
+
+	struct kvm_riscv_cove_measure_region mr = {
+		.user_addr = uaddr,
+		.gpa = gpa,
+		.size = rsize,
+	};
+
+	ret = ioctl(kvm->vm_fd, KVM_RISCV_COVE_MEASURE_REGION, &mr);
+	if (ret < 0) {
+		ret = -errno;
+		die("Setting measure region failed for CoVE VM\n");
+	}
+}
+
 u64 kvm__arch_default_ram_address(void)
 {
 	return RISCV_RAM;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC kvmtool 04/10] riscv: Invoke measure region for VM images
  2023-04-19 22:23 [RFC kvmtool 00/10] RISC-V CoVE support Atish Patra
                   ` (2 preceding siblings ...)
  2023-04-19 22:23 ` [RFC kvmtool 03/10] riscv: Define a measure region IOCTL Atish Patra
@ 2023-04-19 22:23 ` Atish Patra
  2023-04-19 22:23 ` [RFC kvmtool 05/10] riscv: Do not create APLIC for TVMs Atish Patra
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Atish Patra @ 2023-04-19 22:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: Atish Patra, Alexandre Ghiti, Andrew Jones, Andrew Morton,
	Anup Patel, Atish Patra, Suzuki K Poulose, Will Deacon,
	Marc Zyngier, Sean Christopherson, linux-coco, Dylan Reid,
	abrestic, Samuel Ortiz, Jiri Slaby, kvm-riscv, kvm, linux-mm,
	linux-riscv, Palmer Dabbelt, Paolo Bonzini, Rajnesh Kanwal,
	Uladzislau Rezki

The DT, initrd and kernel images needs to be measured before a CoVE VM
can be started to validate its authenticity.

Hookup the measure region API for these three components.

Signed-off-by: Atish Patra <atishp@rivosinc.com>
---
 riscv/fdt.c | 3 +++
 riscv/kvm.c | 4 ++++
 2 files changed, 7 insertions(+)

diff --git a/riscv/fdt.c b/riscv/fdt.c
index 61a28bb..07ec336 100644
--- a/riscv/fdt.c
+++ b/riscv/fdt.c
@@ -254,6 +254,9 @@ static int setup_fdt(struct kvm *kvm)
 
 	if (kvm->cfg.arch.dump_dtb_filename)
 		dump_fdt(kvm->cfg.arch.dump_dtb_filename, fdt_dest);
+
+	kvm_cove_measure_region(kvm, (unsigned long)fdt_dest,
+				kvm->arch.dtb_guest_start, FDT_MAX_SIZE);
 	return 0;
 }
 late_init(setup_fdt);
diff --git a/riscv/kvm.c b/riscv/kvm.c
index 99b253e..d59e8bc 100644
--- a/riscv/kvm.c
+++ b/riscv/kvm.c
@@ -148,6 +148,8 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd,
 	pr_debug("Loaded kernel to 0x%llx (%zd bytes)",
 		 kvm->arch.kern_guest_start, file_size);
 
+	kvm_cove_measure_region(kvm, (unsigned long)pos, kvm->arch.kern_guest_start,
+			       file_size);
 	/* Place FDT just after kernel at FDT_ALIGN address */
 	pos = kernel_end + FDT_ALIGN;
 	guest_addr = ALIGN(host_to_guest_flat(kvm, pos), FDT_ALIGN);
@@ -188,6 +190,8 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd,
 		pr_debug("Loaded initrd to 0x%llx (%llu bytes)",
 			 kvm->arch.initrd_guest_start,
 			 kvm->arch.initrd_size);
+		kvm_cove_measure_region(kvm, (unsigned long)pos, initrd_start,
+				       file_size);
 	} else {
 		kvm->arch.initrd_size = 0;
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC kvmtool 05/10] riscv: Do not create APLIC for TVMs
  2023-04-19 22:23 [RFC kvmtool 00/10] RISC-V CoVE support Atish Patra
                   ` (3 preceding siblings ...)
  2023-04-19 22:23 ` [RFC kvmtool 04/10] riscv: Invoke measure region for VM images Atish Patra
@ 2023-04-19 22:23 ` Atish Patra
  2023-04-19 22:23 ` [RFC kvmtool 06/10] riscv: Change initrd alignment to a page size Atish Patra
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Atish Patra @ 2023-04-19 22:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: Atish Patra, Alexandre Ghiti, Andrew Jones, Andrew Morton,
	Anup Patel, Atish Patra, Suzuki K Poulose, Will Deacon,
	Marc Zyngier, Sean Christopherson, linux-coco, Dylan Reid,
	abrestic, Samuel Ortiz, Jiri Slaby, kvm-riscv, kvm, linux-mm,
	linux-riscv, Palmer Dabbelt, Paolo Bonzini, Rajnesh Kanwal,
	Uladzislau Rezki

The CoVE VMs do not support wired interrupts. Thus no need of APLIC at
this point.

Signed-off-by: Atish Patra <atishp@rivosinc.com>
---
 riscv/aia.c | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/riscv/aia.c b/riscv/aia.c
index 8c85b3f..a3b8618 100644
--- a/riscv/aia.c
+++ b/riscv/aia.c
@@ -143,6 +143,11 @@ static int aia__init(struct kvm *kvm)
 		.attr	= KVM_DEV_RISCV_AIA_CTRL_INIT,
 	};
 
+
+	/* CoVE VM only supports hardware with physical guest interrupt file */
+	if (kvm->cfg.arch.cove_vm)
+		aia_mode = KVM_DEV_RISCV_AIA_MODE_HWACCEL;
+
 	/* Setup global device attribute variables */
 	aia_mode_attr.addr = (u64)(unsigned long)&aia_mode;
 	aia_nr_ids_attr.addr = (u64)(unsigned long)&aia_nr_ids;
@@ -160,10 +165,7 @@ static int aia__init(struct kvm *kvm)
 	ret = ioctl(aia_fd, KVM_GET_DEVICE_ATTR, &aia_nr_ids_attr);
 	if (ret)
 		return ret;
-	aia_nr_sources = irq__get_nr_allocated_lines();
-	ret = ioctl(aia_fd, KVM_SET_DEVICE_ATTR, &aia_nr_sources_attr);
-	if (ret)
-		return ret;
+
 	aia_hart_bits = fls_long(kvm->nrcpus);
 	ret = ioctl(aia_fd, KVM_SET_DEVICE_ATTR, &aia_hart_bits_attr);
 	if (ret)
@@ -172,12 +174,21 @@ static int aia__init(struct kvm *kvm)
 	/* Save number of HARTs for FDT generation */
 	aia_nr_harts = kvm->nrcpus;
 
-	/* Set AIA device addresses */
-	aia_addr = AIA_APLIC_ADDR(aia_nr_harts);
-	aia_addr_attr.attr = KVM_DEV_RISCV_AIA_ADDR_APLIC;
-	ret = ioctl(aia_fd, KVM_SET_DEVICE_ATTR, &aia_addr_attr);
-	if (ret)
-		return ret;
+	/* CoVE VMs do not support APLIC yet */
+	if (!kvm->cfg.arch.cove_vm) {
+		aia_nr_sources = irq__get_nr_allocated_lines();
+		ret = ioctl(aia_fd, KVM_SET_DEVICE_ATTR, &aia_nr_sources_attr);
+		if (ret)
+			return ret;
+
+		/* Set AIA device addresses */
+		aia_addr = AIA_APLIC_ADDR(aia_nr_harts);
+		aia_addr_attr.attr = KVM_DEV_RISCV_AIA_ADDR_APLIC;
+		ret = ioctl(aia_fd, KVM_SET_DEVICE_ATTR, &aia_addr_attr);
+		if (ret)
+			return ret;
+	}
+
 	for (i = 0; i < kvm->nrcpus; i++) {
 		aia_addr = AIA_IMSIC_ADDR(i);
 		aia_addr_attr.attr = KVM_DEV_RISCV_AIA_ADDR_IMSIC(i);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC kvmtool 06/10] riscv: Change initrd alignment to a page size
  2023-04-19 22:23 [RFC kvmtool 00/10] RISC-V CoVE support Atish Patra
                   ` (4 preceding siblings ...)
  2023-04-19 22:23 ` [RFC kvmtool 05/10] riscv: Do not create APLIC for TVMs Atish Patra
@ 2023-04-19 22:23 ` Atish Patra
  2023-04-19 22:23 ` [RFC kvmtool 07/10] riscv: Define riscv specific vm_type function Atish Patra
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Atish Patra @ 2023-04-19 22:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: Atish Patra, Alexandre Ghiti, Andrew Jones, Andrew Morton,
	Anup Patel, Atish Patra, Suzuki K Poulose, Will Deacon,
	Marc Zyngier, Sean Christopherson, linux-coco, Dylan Reid,
	abrestic, Samuel Ortiz, Jiri Slaby, kvm-riscv, kvm, linux-mm,
	linux-riscv, Palmer Dabbelt, Paolo Bonzini, Rajnesh Kanwal,
	Uladzislau Rezki

Currently, the initrd image is aligned to 8. This is problematic for
CoVE where the image is expected to be aligned at page granularity level.

Thus, align it to 4k. This can be done only if user requested a TVM.
However, initrd usually much bigger (in MBs at least). Thus, aligning
to a page for everything should not matter much.

Signed-off-by: Atish Patra <atishp@rivosinc.com>
---
 riscv/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/riscv/kvm.c b/riscv/kvm.c
index d59e8bc..5f9b0d5 100644
--- a/riscv/kvm.c
+++ b/riscv/kvm.c
@@ -113,7 +113,7 @@ void kvm__arch_init(struct kvm *kvm)
 }
 
 #define FDT_ALIGN	SZ_4M
-#define INITRD_ALIGN	8
+#define INITRD_ALIGN	SZ_4K
 bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd,
 				 const char *kernel_cmdline)
 {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC kvmtool 07/10] riscv: Define riscv specific vm_type function
  2023-04-19 22:23 [RFC kvmtool 00/10] RISC-V CoVE support Atish Patra
                   ` (5 preceding siblings ...)
  2023-04-19 22:23 ` [RFC kvmtool 06/10] riscv: Change initrd alignment to a page size Atish Patra
@ 2023-04-19 22:23 ` Atish Patra
  2023-04-19 22:23 ` [RFC kvmtool 08/10] riscv: virtio: Enforce VIRTIO_F_ACCESS_PLATFORM feature flag Atish Patra
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Atish Patra @ 2023-04-19 22:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: Atish Patra, Alexandre Ghiti, Andrew Jones, Andrew Morton,
	Anup Patel, Atish Patra, Suzuki K Poulose, Will Deacon,
	Marc Zyngier, Sean Christopherson, linux-coco, Dylan Reid,
	abrestic, Samuel Ortiz, Jiri Slaby, kvm-riscv, kvm, linux-mm,
	linux-riscv, Palmer Dabbelt, Paolo Bonzini, Rajnesh Kanwal,
	Uladzislau Rezki

RISC-V supports CoVE VMs now. It needs to setup correct VM type if the
user requests it.

Signed-off-by: Atish Patra <atishp@rivosinc.com>
---
 riscv/kvm.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/riscv/kvm.c b/riscv/kvm.c
index 5f9b0d5..e728790 100644
--- a/riscv/kvm.c
+++ b/riscv/kvm.c
@@ -39,6 +39,18 @@ u64 kvm__arch_default_ram_address(void)
 	return RISCV_RAM;
 }
 
+int kvm__get_vm_type(struct kvm *kvm)
+{
+	if (kvm->cfg.arch.cove_vm) {
+		if (__riscv_xlen == 64)
+			return KVM_VM_TYPE_RISCV_COVE;
+		else
+			die("CoVE VM is not supported in RV32\n");
+	} else {
+		return KVM_VM_TYPE;
+	}
+}
+
 void kvm__arch_validate_cfg(struct kvm *kvm)
 {
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC kvmtool 08/10] riscv: virtio: Enforce VIRTIO_F_ACCESS_PLATFORM feature flag.
  2023-04-19 22:23 [RFC kvmtool 00/10] RISC-V CoVE support Atish Patra
                   ` (6 preceding siblings ...)
  2023-04-19 22:23 ` [RFC kvmtool 07/10] riscv: Define riscv specific vm_type function Atish Patra
@ 2023-04-19 22:23 ` Atish Patra
  2023-04-19 22:23 ` [RFC kvmtool 09/10] riscv: Don't emit MMIO devices for CoVE VM Atish Patra
  2023-04-19 22:23 ` [RFC kvmtool 10/10] riscv: cove: Don't emit interrupt_map for pci devices in fdt Atish Patra
  9 siblings, 0 replies; 11+ messages in thread
From: Atish Patra @ 2023-04-19 22:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: Rajnesh Kanwal, Alexandre Ghiti, Andrew Jones, Andrew Morton,
	Anup Patel, Atish Patra, Suzuki K Poulose, Will Deacon,
	Marc Zyngier, Sean Christopherson, linux-coco, Dylan Reid,
	abrestic, Samuel Ortiz, Jiri Slaby, kvm-riscv, kvm, linux-mm,
	linux-riscv, Palmer Dabbelt, Paolo Bonzini, Uladzislau Rezki

From: Rajnesh Kanwal <rkanwal@rivosinc.com>

VIRTIO_F_ACCESS_PLATFORM feature tells the guest that device will
be using DMA for transfers. This forces the guest to use DMA API
to allow the host to successfully access guest memory as needed.

This is needed for CoVE VMs.

Signed-off-by: Rajnesh Kanwal <rkanwal@rivosinc.com>
---
 riscv/kvm.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/riscv/kvm.c b/riscv/kvm.c
index e728790..aebb6bd 100644
--- a/riscv/kvm.c
+++ b/riscv/kvm.c
@@ -7,6 +7,7 @@
 #include <linux/kernel.h>
 #include <linux/kvm.h>
 #include <linux/sizes.h>
+#include <linux/virtio_config.h>
 
 struct kvm_ext kvm_req_ext[] = {
 	{ DEFINE_KVM_EXT(KVM_CAP_ONE_REG) },
@@ -224,5 +225,14 @@ int kvm__arch_setup_firmware(struct kvm *kvm)
 
 u64 kvm__arch_get_virtio_host_features(struct kvm *kvm)
 {
-	return 0;
+	u64 features = 0;
+
+	/* CoVE VMs mandate VIRTIO_F_ACCESS_PLATFORM feature to force use of
+	 * SWIOTLB bounce buffers through DMA API. Without this device probe
+	 * will fail for CoVE VMs.
+	 */
+	if (kvm->cfg.arch.cove_vm)
+		features |= (1ULL << VIRTIO_F_ACCESS_PLATFORM);
+
+	return features;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC kvmtool 09/10] riscv: Don't emit MMIO devices for CoVE VM.
  2023-04-19 22:23 [RFC kvmtool 00/10] RISC-V CoVE support Atish Patra
                   ` (7 preceding siblings ...)
  2023-04-19 22:23 ` [RFC kvmtool 08/10] riscv: virtio: Enforce VIRTIO_F_ACCESS_PLATFORM feature flag Atish Patra
@ 2023-04-19 22:23 ` Atish Patra
  2023-04-19 22:23 ` [RFC kvmtool 10/10] riscv: cove: Don't emit interrupt_map for pci devices in fdt Atish Patra
  9 siblings, 0 replies; 11+ messages in thread
From: Atish Patra @ 2023-04-19 22:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: Rajnesh Kanwal, Alexandre Ghiti, Andrew Jones, Andrew Morton,
	Anup Patel, Atish Patra, Suzuki K Poulose, Will Deacon,
	Marc Zyngier, Sean Christopherson, linux-coco, Dylan Reid,
	abrestic, Samuel Ortiz, Jiri Slaby, kvm-riscv, kvm, linux-mm,
	linux-riscv, Palmer Dabbelt, Paolo Bonzini, Uladzislau Rezki

From: Rajnesh Kanwal <rkanwal@rivosinc.com>

The CoVE VMs do not support MMIO devices yet. Do not emit
MMIO device nodes for CoVE VMs.

Signed-off-by: Rajnesh Kanwal <rkanwal@rivosinc.com>
---
 riscv/fdt.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/riscv/fdt.c b/riscv/fdt.c
index 07ec336..a7d32b3 100644
--- a/riscv/fdt.c
+++ b/riscv/fdt.c
@@ -210,22 +210,25 @@ static int setup_fdt(struct kvm *kvm)
 			       riscv_irqchip_phandle));
 	_FDT(fdt_property(fdt, "ranges", NULL, 0));
 
-	/* Virtio MMIO devices */
-	dev_hdr = device__first_dev(DEVICE_BUS_MMIO);
-	while (dev_hdr) {
-		generate_mmio_fdt_nodes = dev_hdr->data;
-		generate_mmio_fdt_nodes(fdt, dev_hdr,
-					riscv__generate_irq_prop);
-		dev_hdr = device__next_dev(dev_hdr);
-	}
+	/* CoVE VMs do not support MMIO devices yet */
+	if (!kvm->cfg.arch.cove_vm) {
+		/* Virtio MMIO devices */
+		dev_hdr = device__first_dev(DEVICE_BUS_MMIO);
+		while (dev_hdr) {
+			generate_mmio_fdt_nodes = dev_hdr->data;
+			generate_mmio_fdt_nodes(fdt, dev_hdr,
+						riscv__generate_irq_prop);
+			dev_hdr = device__next_dev(dev_hdr);
+		}
 
-	/* IOPORT devices */
-	dev_hdr = device__first_dev(DEVICE_BUS_IOPORT);
-	while (dev_hdr) {
-		generate_mmio_fdt_nodes = dev_hdr->data;
-		generate_mmio_fdt_nodes(fdt, dev_hdr,
-					riscv__generate_irq_prop);
-		dev_hdr = device__next_dev(dev_hdr);
+		/* IOPORT devices */
+		dev_hdr = device__first_dev(DEVICE_BUS_IOPORT);
+		while (dev_hdr) {
+			generate_mmio_fdt_nodes = dev_hdr->data;
+			generate_mmio_fdt_nodes(fdt, dev_hdr,
+						riscv__generate_irq_prop);
+			dev_hdr = device__next_dev(dev_hdr);
+		}
 	}
 
 	/* PCI host controller */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC kvmtool 10/10] riscv: cove: Don't emit interrupt_map for pci devices in fdt.
  2023-04-19 22:23 [RFC kvmtool 00/10] RISC-V CoVE support Atish Patra
                   ` (8 preceding siblings ...)
  2023-04-19 22:23 ` [RFC kvmtool 09/10] riscv: Don't emit MMIO devices for CoVE VM Atish Patra
@ 2023-04-19 22:23 ` Atish Patra
  9 siblings, 0 replies; 11+ messages in thread
From: Atish Patra @ 2023-04-19 22:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: Rajnesh Kanwal, Alexandre Ghiti, Andrew Jones, Andrew Morton,
	Anup Patel, Atish Patra, Suzuki K Poulose, Will Deacon,
	Marc Zyngier, Sean Christopherson, linux-coco, Dylan Reid,
	abrestic, Samuel Ortiz, Jiri Slaby, kvm-riscv, kvm, linux-mm,
	linux-riscv, Palmer Dabbelt, Paolo Bonzini, Uladzislau Rezki

From: Rajnesh Kanwal <rkanwal@rivosinc.com>

CoVE VMs don't support pin based interrupts yet as APLIC isn't
supported.

Signed-off-by: Rajnesh Kanwal <rkanwal@rivosinc.com>
---
 riscv/fdt.c                  |  2 +-
 riscv/include/kvm/kvm-arch.h |  2 +-
 riscv/pci.c                  | 83 +++++++++++++++++++-----------------
 3 files changed, 46 insertions(+), 41 deletions(-)

diff --git a/riscv/fdt.c b/riscv/fdt.c
index a7d32b3..115ae17 100644
--- a/riscv/fdt.c
+++ b/riscv/fdt.c
@@ -232,7 +232,7 @@ static int setup_fdt(struct kvm *kvm)
 	}
 
 	/* PCI host controller */
-	pci__generate_fdt_nodes(fdt);
+	pci__generate_fdt_nodes(fdt, kvm);
 
 	_FDT(fdt_end_node(fdt));
 
diff --git a/riscv/include/kvm/kvm-arch.h b/riscv/include/kvm/kvm-arch.h
index 08ac54a..9f6967f 100644
--- a/riscv/include/kvm/kvm-arch.h
+++ b/riscv/include/kvm/kvm-arch.h
@@ -104,7 +104,7 @@ void aia__create(struct kvm *kvm);
 
 void plic__create(struct kvm *kvm);
 
-void pci__generate_fdt_nodes(void *fdt);
+void pci__generate_fdt_nodes(void *fdt, struct kvm *kvm);
 
 int riscv__add_irqfd(struct kvm *kvm, unsigned int gsi, int trigger_fd,
 		     int resample_fd);
diff --git a/riscv/pci.c b/riscv/pci.c
index 9760ca3..31ea286 100644
--- a/riscv/pci.c
+++ b/riscv/pci.c
@@ -17,7 +17,7 @@ struct of_interrupt_map_entry {
 	u32				irqchip_sense;
 } __attribute__((packed));
 
-void pci__generate_fdt_nodes(void *fdt)
+void pci__generate_fdt_nodes(void *fdt, struct kvm *kvm)
 {
 	struct device_header *dev_hdr;
 	struct of_interrupt_map_entry irq_map[OF_PCI_IRQ_MAP_MAX];
@@ -67,51 +67,56 @@ void pci__generate_fdt_nodes(void *fdt)
 	_FDT(fdt_property(fdt, "reg", &cfg_reg_prop, sizeof(cfg_reg_prop)));
 	_FDT(fdt_property(fdt, "ranges", ranges, sizeof(ranges)));
 
-	/* Generate the interrupt map ... */
-	dev_hdr = device__first_dev(DEVICE_BUS_PCI);
-	while (dev_hdr && nentries < ARRAY_SIZE(irq_map)) {
-		struct of_interrupt_map_entry *entry;
-		struct pci_device_header *pci_hdr = dev_hdr->data;
-		u8 dev_num = dev_hdr->dev_num;
-		u8 pin = pci_hdr->irq_pin;
-		u8 irq = pci_hdr->irq_line;
+	/* CoVE VMs do not support pin based interrupts yet as APLIC isn't
+	 * supported.
+	 */
+	if (!kvm->cfg.arch.cove_vm) {
+		/* Generate the interrupt map ... */
+		dev_hdr = device__first_dev(DEVICE_BUS_PCI);
+		while (dev_hdr && nentries < ARRAY_SIZE(irq_map)) {
+			struct of_interrupt_map_entry *entry;
+			struct pci_device_header *pci_hdr = dev_hdr->data;
+			u8 dev_num = dev_hdr->dev_num;
+			u8 pin = pci_hdr->irq_pin;
+			u8 irq = pci_hdr->irq_line;
 
-		entry = ((void *)irq_map) + (nsize * nentries);
-		*entry = (struct of_interrupt_map_entry) {
-			.pci_irq_mask = {
-				.pci_addr = {
-					.hi	= cpu_to_fdt32(of_pci_b_ddddd(dev_num)),
-					.mid	= 0,
-					.lo	= 0,
+			entry = ((void *)irq_map) + (nsize * nentries);
+			*entry = (struct of_interrupt_map_entry) {
+				.pci_irq_mask = {
+					.pci_addr = {
+						.hi	= cpu_to_fdt32(of_pci_b_ddddd(dev_num)),
+						.mid	= 0,
+						.lo	= 0,
+					},
+					.pci_pin	= cpu_to_fdt32(pin),
 				},
-				.pci_pin	= cpu_to_fdt32(pin),
-			},
-			.irqchip_phandle	= cpu_to_fdt32(riscv_irqchip_phandle),
-			.irqchip_line		= cpu_to_fdt32(irq),
-		};
+				.irqchip_phandle	= cpu_to_fdt32(riscv_irqchip_phandle),
+				.irqchip_line		= cpu_to_fdt32(irq),
+			};
 
-		if (riscv_irqchip_line_sensing)
-			entry->irqchip_sense = cpu_to_fdt32(IRQ_TYPE_LEVEL_HIGH);
+			if (riscv_irqchip_line_sensing)
+				entry->irqchip_sense = cpu_to_fdt32(IRQ_TYPE_LEVEL_HIGH);
 
-		nentries++;
-		dev_hdr = device__next_dev(dev_hdr);
-	}
+			nentries++;
+			dev_hdr = device__next_dev(dev_hdr);
+		}
 
-	_FDT(fdt_property(fdt, "interrupt-map", irq_map, nsize * nentries));
+		_FDT(fdt_property(fdt, "interrupt-map", irq_map, nsize * nentries));
 
-	/* ... and the corresponding mask. */
-	if (nentries) {
-		struct of_pci_irq_mask irq_mask = {
-			.pci_addr = {
-				.hi	= cpu_to_fdt32(of_pci_b_ddddd(-1)),
-				.mid	= 0,
-				.lo	= 0,
-			},
-			.pci_pin	= cpu_to_fdt32(7),
-		};
+		/* ... and the corresponding mask. */
+		if (nentries) {
+			struct of_pci_irq_mask irq_mask = {
+				.pci_addr = {
+					.hi	= cpu_to_fdt32(of_pci_b_ddddd(-1)),
+					.mid	= 0,
+					.lo	= 0,
+				},
+				.pci_pin	= cpu_to_fdt32(7),
+			};
 
-		_FDT(fdt_property(fdt, "interrupt-map-mask", &irq_mask,
-				  sizeof(irq_mask)));
+			_FDT(fdt_property(fdt, "interrupt-map-mask", &irq_mask,
+					  sizeof(irq_mask)));
+		}
 	}
 
 	/* Set MSI parent if available */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-04-19 22:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-19 22:23 [RFC kvmtool 00/10] RISC-V CoVE support Atish Patra
2023-04-19 22:23 ` [RFC kvmtool 01/10] riscv: Add a CoVE VM type Atish Patra
2023-04-19 22:23 ` [RFC kvmtool 02/10] riscv: Define a command line option for CoVE VM Atish Patra
2023-04-19 22:23 ` [RFC kvmtool 03/10] riscv: Define a measure region IOCTL Atish Patra
2023-04-19 22:23 ` [RFC kvmtool 04/10] riscv: Invoke measure region for VM images Atish Patra
2023-04-19 22:23 ` [RFC kvmtool 05/10] riscv: Do not create APLIC for TVMs Atish Patra
2023-04-19 22:23 ` [RFC kvmtool 06/10] riscv: Change initrd alignment to a page size Atish Patra
2023-04-19 22:23 ` [RFC kvmtool 07/10] riscv: Define riscv specific vm_type function Atish Patra
2023-04-19 22:23 ` [RFC kvmtool 08/10] riscv: virtio: Enforce VIRTIO_F_ACCESS_PLATFORM feature flag Atish Patra
2023-04-19 22:23 ` [RFC kvmtool 09/10] riscv: Don't emit MMIO devices for CoVE VM Atish Patra
2023-04-19 22:23 ` [RFC kvmtool 10/10] riscv: cove: Don't emit interrupt_map for pci devices in fdt Atish Patra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).