@@ -5,7 +5,7 @@ index b472301637..c39c09b16b 100644
55@@ -2527,6 +2527,13 @@ static int kvm_init(MachineState *ms)
66 type = kvm_arch_get_default_type(ms);
77 }
8-
8+
99+ if (object_property_find(OBJECT(current_machine), "cove")) {
1010+ if (object_property_get_bool(OBJECT(current_machine), "cove", &error_abort)) {
1111+ type = 1UL << 10;
@@ -32,7 +32,7 @@ index 52bf8e67de..7f4550bbf1 100644
3232@@ -205,6 +205,18 @@ static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry)
3333 }
3434 }
35-
35+
3636+ #if defined(CONFIG_KVM)
3737+ struct kvm_riscv_cove_measure_region mr = {
3838+ .user_addr = 0,
@@ -53,9 +53,9 @@ index 52bf8e67de..7f4550bbf1 100644
5353 uint64_t kernel_load_base, kernel_entry;
5454 void *fdt = machine->fdt;
5555+ ssize_t kernel_size;
56-
56+
5757 g_assert(kernel_filename != NULL);
58-
58+
5959@@ -232,20 +245,23 @@ target_ulong riscv_load_kernel(MachineState *machine,
6060 * the (expected) load address load address. This allows kernels to have
6161 * separate SBI and ELF entry points (used by FreeBSD, for example).
@@ -69,15 +69,15 @@ index 52bf8e67de..7f4550bbf1 100644
6969 kernel_entry = kernel_load_base;
7070 goto out;
7171 }
72-
72+
7373- if (load_uimage_as(kernel_filename, &kernel_entry, NULL, NULL,
7474- NULL, NULL, NULL) > 0) {
7575+ kernel_size = load_uimage_as(kernel_filename, &kernel_entry, NULL, NULL,
7676+ NULL, NULL, NULL);
7777+ if (kernel_size > 0) {
7878 goto out;
7979 }
80-
80+
8181- if (load_image_targphys_as(kernel_filename, kernel_start_addr,
8282- current_machine->ram_size, NULL) > 0) {
8383+ kernel_size = load_image_targphys_as(kernel_filename, kernel_start_addr,
@@ -89,7 +89,7 @@ index 52bf8e67de..7f4550bbf1 100644
8989@@ -262,6 +278,35 @@ out:
9090 kernel_entry = extract64(kernel_entry, 0, 32);
9191 }
92-
92+
9393+ #if defined(CONFIG_KVM)
9494+ struct kvm_riscv_cove_measure_region mr = {
9595+ .user_addr = 0,
@@ -139,7 +139,7 @@ index 505a36dff6..40a41eb9ee 100644
139139@@ -1312,6 +1313,17 @@ static void virt_machine_done(Notifier *notifier, void *data)
140140 machine);
141141 riscv_load_fdt(fdt_load_addr, machine->fdt);
142-
142+
143143+ #if defined(CONFIG_KVM)
144144+ uint32_t fdtsize = fdt_totalsize(machine->fdt);
145145+ struct kvm_riscv_cove_measure_region mr = {
@@ -165,12 +165,12 @@ index 505a36dff6..40a41eb9ee 100644
165165+ kvm_vm_ioctl(KVM_STATE(machine->accelerator), KVM_RISCV_COVE_VM_FINALIZE, &finalize);
166166+ #endif
167167 }
168-
168+
169169 static void virt_machine_init(MachineState *machine)
170170@@ -1540,6 +1558,33 @@ static void virt_machine_instance_init(Object *obj)
171171 s->acpi = ON_OFF_AUTO_AUTO;
172172 }
173-
173+
174174+ static bool virt_get_cove(Object *obj, Error **errp)
175175+ {
176176+ RISCVVirtState *s = RISCV_VIRT_MACHINE(obj);
@@ -210,7 +210,7 @@ index 505a36dff6..40a41eb9ee 100644
210210+ object_class_property_add_str(oc, "cove-tap-filename", virt_get_cove_tap_filename,
211211+ virt_set_cove_tap_filename);
212212 }
213-
213+
214214 static const TypeInfo virt_machine_typeinfo = {
215215diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h
216216index e5c474b26e..c01e733b34 100644
@@ -223,7 +223,7 @@ index e5c474b26e..c01e733b34 100644
223223+ bool cove;
224224+ char *cove_tap_filename;
225225 };
226-
226+
227227 enum {
228228diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
229229index 1f3f3333a4..9dc12996ef 100644
@@ -232,7 +232,7 @@ index 1f3f3333a4..9dc12996ef 100644
232232@@ -2245,4 +2245,24 @@ struct kvm_s390_zpci_op {
233233 /* flags for kvm_s390_zpci_op->u.reg_aen.flags */
234234 #define KVM_S390_ZPCIOP_REGAEN_HOST (1 << 0)
235-
235+
236236+ enum KVM_RISCV_COVE_REGION {
237237+ KVM_RISCV_COVE_REGION_FIRMWARE = 0,
238238+ KVM_RISCV_COVE_REGION_KERNEL,
0 commit comments