[RFC PATCH v1 13/17] accel/kvm: only register the DRAM slot of a CoVE guest
Baolong Duan <[email protected]> Fri, 31 Jul 2026 11:50:07 +0800
| Newsgroups | org.nongnu.qemu-riscv,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
The TSM tracks the confidential region of a TEE VM itself. Registering the remaining memory slots of the machine, such as the mask ROM or the flash, overwrites that region and the guest fails to start. Filtering them by slot number is a workaround rather than a solution: the machine should describe which regions belong to the confidential guest instead. Suggestions on how to express that are very welcome. Signed-off-by: Baolong Duan <[email protected]> --- accel/kvm/kvm-all.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 005abb1c54..2753bf8b8b 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -26,6 +26,7 @@ #include "qapi/error.h" #include "hw/pci/msi.h" #include "hw/pci/msix.h" +#include "hw/riscv/cove.h" #include "hw/s390x/adapter.h" #include "gdbstub/enums.h" #include "system/kvm_int.h" @@ -393,6 +394,16 @@ static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slot, boo struct kvm_userspace_memory_region2 mem = {}; int ret; + /* + * Only the DRAM slot is registered with KVM for a CoVE guest: the TSM + * tracks the confidential region of the TVM itself and registering the + * other slots (MROM, flash, ...) would overwrite it. + */ + if (riscv_cove_vm_active() && (slot->slot & 0xffff) != 0 && + slot->memory_size > 0) { + return 0; + } + mem.slot = slot->slot | (kml->as_id << 16); mem.guest_phys_addr = slot->start_addr; mem.userspace_addr = (unsigned long)slot->ram; -- 2.34.1