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 2/3] accel/kvm: Zero out mem explicitly in kvm_set_user_memory_region()
Date: Mon, 28 Jul 2025 19:57:06 +0800	[thread overview]
Message-ID: <20250728115707.1374614-3-xiaoyao.li@intel.com> (raw)
In-Reply-To: <20250728115707.1374614-1-xiaoyao.li@intel.com>

Zero out the entire mem explicitly before it's used, to ensure the unused
feilds (pad1, pad2) are all zeros. Otherwise, it might cause problem when
the pad fields are extended by future KVM.

Fixes: ce5a983233b4 ("kvm: Enable KVM_SET_USER_MEMORY_REGION2 for memslot")
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
changes in v2:
- using {} instead of memset(); (suggested by Philippe)
---
 accel/kvm/kvm-all.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 14d47246ca63..90f3b177a1ff 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -358,7 +358,7 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void *ram,
 static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slot, bool new)
 {
     KVMState *s = kvm_state;
-    struct kvm_userspace_memory_region2 mem;
+    struct kvm_userspace_memory_region2 mem = {};
     int ret;
 
     mem.slot = slot->slot | (kml->as_id << 16);
-- 
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 ` Xiaoyao Li [this message]
2025-07-28 11:57 ` [PATCH v2 3/3] accel/kvm: Set guest_memfd_offset to non-zero value only when guest_memfd is valid Xiaoyao Li
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-3-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).