From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Cornelia Huck" <cohuck@redhat.com>,
"Peter Xu" <peterx@redhat.com>,
"David Hildenbrand" <david@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Maxim Levitsky" <mlevitsk@redhat.com>,
kvm@vger.kernel.org,
"Emanuele Giuseppe Esposito" <eesposit@redhat.com>
Subject: [RFC PATCH v2 2/3] accel/kvm/kvm-all.c: pass kvm_userspace_memory_region_entry instead
Date: Fri, 9 Sep 2022 04:11:49 -0400 [thread overview]
Message-ID: <20220909081150.709060-3-eesposit@redhat.com> (raw)
In-Reply-To: <20220909081150.709060-1-eesposit@redhat.com>
It won't change anything from the kernel side, but prepares the logic
for KVM_SET_USER_MEMORY_REGION_LIST ioctl, where all requests are sent
at once.
Because QEMU does not send any memslot MOVE request to KVM, simplify
mem.invalidate_slot logic to only detect DELETE requests.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
accel/kvm/kvm-all.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 645f0a249a..e9947ec18b 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -360,7 +360,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_region mem;
+ struct kvm_userspace_memory_region_entry mem;
int ret;
mem.slot = slot->slot | (kml->as_id << 16);
@@ -372,12 +372,29 @@ static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slot, boo
/* Set the slot size to 0 before setting the slot to the desired
* value. This is needed based on KVM commit 75d61fbc. */
mem.memory_size = 0;
+ mem.invalidate_slot = 1;
+ /*
+ * Note that mem is struct kvm_userspace_memory_region_entry, while the
+ * kernel expects a kvm_userspace_memory_region, so it will currently
+ * ignore mem->invalidate_slot and mem->padding.
+ */
ret = kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
if (ret < 0) {
goto err;
}
}
mem.memory_size = slot->memory_size;
+ /*
+ * Invalidate if it's a kvm memslot MOVE or DELETE operation, but
+ * currently QEMU does not perform any memslot MOVE operation.
+ */
+ mem.invalidate_slot = slot->memory_size == 0;
+
+ /*
+ * Note that mem is struct kvm_userspace_memory_region_entry, while the
+ * kernel expects a kvm_userspace_memory_region, so it will currently
+ * ignore mem->invalidate_slot and mem->padding.
+ */
ret = kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
slot->old_flags = mem.flags;
err:
--
2.31.1
next prev parent reply other threads:[~2022-09-09 8:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-09 8:11 [RFC PATCH v2 0/3] accel/kvm: extend kvm memory listener to support Emanuele Giuseppe Esposito
2022-09-09 8:11 ` [RFC PATCH v2 1/3] linux-headers/linux/kvm.h: introduce kvm_userspace_memory_region_list ioctl Emanuele Giuseppe Esposito
2022-09-09 8:11 ` Emanuele Giuseppe Esposito [this message]
2022-09-09 8:11 ` [RFC PATCH v2 3/3] kvm/kvm-all.c: listener should delay kvm_vm_ioctl to the commit phase Emanuele Giuseppe Esposito
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=20220909081150.709060-3-eesposit@redhat.com \
--to=eesposit@redhat.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=f4bug@amsat.org \
--cc=kvm@vger.kernel.org \
--cc=mlevitsk@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--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).