Fix SEV VM device assignment
v2 cover Fix SEV VM device assignment
Fix: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
Since v1:
* check the error code from memory_region_from_host() before accessing the mr.
Brijesh Singh (2):
memory: Fix the memory region type assignment order target/i386: sev: Do not pin the ram device memory region
memory.c | 9 ++++++++- target/i386/sev.c | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
PATCH v2 1/2 memory: Fix the memory region type assignment order
Currently, a callback registered through the RAMBlock notifier is not able to get the memory region type (i.e callback is not able to use memory_region_is_ram_device function). This is because mr->ram assignment happens _after_ the memory is allocated whereas the callback is executed during allocation.
--- memory.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
memory.c +8 -1
@@ -1652,10 +1652,17 @@ void memory_region_init_ram_device_ptr(MemoryRegion *mr,uint64_t size, void *ptr) { -memory_region_init_ram_ptr (mr ,owner ,name ,size ,ptr ); +memory_region_init (mr ,owner ,name ,size ); + mr->ram = true; + mr->terminates = true; mr->ram_device = true; mr->ops = &ram_device_mem_ops; mr->opaque = mr; + mr->destructor = memory_region_destructor_ram; + mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ; +/* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL. */ +assert (ptr !=NULL ); + mr->ram_block =qemu_ram_alloc_from_ptr (size, ptr, mr, &error_fatal); } void memory_region_init_alias(MemoryRegion *mr,
Signature · 1 line
2.17.1
PATCH v2 2/2 target/i386: sev: Do not pin the ram device memory region
In reply to Singh, BrijeshThe RAM device presents a memory region that should be handled as an IO region and should not be pinned.
In the case of the vfio-pci, RAM device represents a MMIO BAR and the memory region is not backed by pages hence KVM_MEMORY_ENCRYPT_REG_REGION fails to lock the memory range.
--- target/i386/sev.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
target/i386/sev.c +11 -0
@@ -131,6 +131,17 @@ sev_ram_block_added(RAMBlockNotifier *n, void *host, size_t size) {int r;struct kvm_enc_region range; +ram_addr_t offset; +MemoryRegion *mr; + +/* +* The RAM device presents a memory region that should be treated +* as IO region and should not be pinned. +*/ + mr =memory_region_from_host (host, &offset); +if (mr &&memory_region_is_ram_device (mr)) { +return ; + } range.addr = (__u64 )(unsigned long )host; range.size = size;
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH v2 2/2] target/i386: sev: Do not pin the ram device memory region
Quoted 27 lines · Brijesh
The RAM device presents a memory region that should be handled as an IO region and should not be pinned.
In the case of the vfio-pci, RAM device represents a MMIO BAR and the memory region is not backed by pages hence
KVM_MEMORY_ENCRYPT_REG_REGIONfails to lock the memory range.Cc Alex Williamson <[email protected]>Cc Paolo Bonzini <[email protected]>Signed-off-by Brijesh Singh <[email protected]>--- target/i386/sev.c | 11 +++++++++++ 1 file changed, 11 insertions(+)target/i386/sev.c +4
-0@@ -131,6 +131,17 @@ sev_ram_block_added(RAMBlockNotifier *n, void *host, size_t size) {int r;struct kvm_enc_region range; +ram_addr_t offset; +MemoryRegion *mr; + +/*
target/i386/sev.c sev_ram_block_added(RAMBlockNotifier *n, void *host, size_t size) · line 147
Quoted 10 lines
target/i386/sev.c +7
-0+* The RAM device presents a memory region that should be treated +* as IO region and should not be pinned. +*/ + mr =memory_region_from_host (host, &offset); +if (mr &&memory_region_is_ram_device (mr)) { +return ; + } range.addr = (__u64 )(unsigned long )host; range.size = size;
Hi Paolo,
Any comment on this series. Currently, device pass-through is broken for the SEV guests. I am wondering if we can queue the patches.
thanks
Brijesh
Quoted 14 lines · Brijesh
Fix: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
Since v1:
* check the error code frommemory_region_from_host()before accessing the mr.Brijesh Singh (2):
memory: Fix the memory region type assignment order target/i386: sev: Do not pin the ram device memory regionmemory.c | 9 ++++++++- target/i386/sev.c | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-)