summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorXiaoyao Li <xiaoyao.li@intel.com>2025-07-28 19:57:07 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2025-09-17 19:01:57 +0200
commit00c0911c68e5bd664de1a261b74c390f4c0be83d (patch)
tree64c622cfe588118c7cadb74709162e06836873bd
parent80030f66ad15c1534f5e3700b0acefd6d0d92e37 (diff)
downloadfocaccia-qemu-00c0911c68e5bd664de1a261b74c390f4c0be83d.tar.gz
focaccia-qemu-00c0911c68e5bd664de1a261b74c390f4c0be83d.zip
accel/kvm: Set guest_memfd_offset to non-zero value only when guest_memfd is valid
Current QEMU unconditionally sets the guest_memfd_offset of KVMSlot in
kvm_set_phys_mem(), which leads to the trace of kvm_set_user_memory looks:

kvm_set_user_memory AddrSpace#0 Slot#4 flags=0x2 gpa=0xe0000 size=0x20000 ua=0x7f5840de0000 guest_memfd=-1 guest_memfd_offset=0x3e0000 ret=0

It's confusing that the guest_memfd_offset has a non-zero value while
the guest_memfd is invalid (-1).

Change to only set guest_memfd_offset when guest_memfd is valid and
leave it as 0 when no valid guest_memfd.

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/r/20250728115707.1374614-4-xiaoyao.li@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--accel/kvm/kvm-all.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 72b571a697..9060599cd7 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -1595,7 +1595,8 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
         mem->ram = ram;
         mem->flags = kvm_mem_flags(mr);
         mem->guest_memfd = mr->ram_block->guest_memfd;
-        mem->guest_memfd_offset = (uint8_t*)ram - mr->ram_block->host;
+        mem->guest_memfd_offset = mem->guest_memfd >= 0 ?
+                                  (uint8_t*)ram - mr->ram_block->host : 0;
 
         kvm_slot_init_dirty_bitmap(mem);
         err = kvm_set_user_memory_region(kml, mem, true);