[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230419222350.3604274-4-atishp@rivosinc.com>
Date: Wed, 19 Apr 2023 15:23:43 -0700
From: Atish Patra <atishp@...osinc.com>
To: linux-kernel@...r.kernel.org
Cc: Atish Patra <atishp@...osinc.com>, Alexandre Ghiti <alex@...ti.fr>,
Andrew Jones <ajones@...tanamicro.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Anup Patel <anup@...infault.org>,
Atish Patra <atishp@...shpatra.org>,
Suzuki K Poulose <suzuki.poulose@....com>,
Will Deacon <will@...nel.org>, Marc Zyngier <maz@...nel.org>,
Sean Christopherson <seanjc@...gle.com>,
linux-coco@...ts.linux.dev, Dylan Reid <dylan@...osinc.com>,
abrestic@...osinc.com, Samuel Ortiz <sameo@...osinc.com>,
Jiri Slaby <jirislaby@...nel.org>,
kvm-riscv@...ts.infradead.org, kvm@...r.kernel.org,
linux-mm@...ck.org, linux-riscv@...ts.infradead.org,
Palmer Dabbelt <palmer@...belt.com>,
Paolo Bonzini <pbonzini@...hat.com>,
Rajnesh Kanwal <rkanwal@...osinc.com>,
Uladzislau Rezki <urezki@...il.com>
Subject: [RFC kvmtool 03/10] riscv: Define a measure region IOCTL
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@...osinc.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
Powered by blists - more mailing lists