qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Xiaoyao Li <xiaoyao.li@intel.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org, Xiaoyao Li <xiaoyao.li@intel.com>
Subject: [PATCH v2 3/3] accel/kvm: Set guest_memfd_offset to non-zero value only when guest_memfd is valid
Date: Mon, 28 Jul 2025 19:57:07 +0800	[thread overview]
Message-ID: <20250728115707.1374614-4-xiaoyao.li@intel.com> (raw)
In-Reply-To: <20250728115707.1374614-1-xiaoyao.li@intel.com>

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>
---
Changes in v2:
- initialize guest_memfd_offset in kvm_set_phys_mem(); (Phillippe)
---
 accel/kvm/kvm-all.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 90f3b177a1ff..cc694fe3c3a9 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);
-- 
2.43.0



  parent reply	other threads:[~2025-07-28 12:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-28 11:57 [PATCH v2 0/3] kvm: guest_memfd enhancement and fix for KVM_SET_USER_MEMORY_REGION2 Xiaoyao Li
2025-07-28 11:57 ` [PATCH v2 1/3] accel/kvm: Switch to check KVM_CAP_GUEST_MEMFD and KVM_CAP_USER_MEMORY2 on VM Xiaoyao Li
2025-07-28 11:57 ` [PATCH v2 2/3] accel/kvm: Zero out mem explicitly in kvm_set_user_memory_region() Xiaoyao Li
2025-07-28 11:57 ` Xiaoyao Li [this message]
2025-09-12  5:47 ` [PATCH v2 0/3] kvm: guest_memfd enhancement and fix for KVM_SET_USER_MEMORY_REGION2 Xiaoyao Li
2025-09-13  4:35 ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250728115707.1374614-4-xiaoyao.li@intel.com \
    --to=xiaoyao.li@intel.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).