From: benami@il.ibm.com
To: avi@qumranet.com
Cc: kvm@vger.kernel.org, amit.shah@qumranet.com--cc, muli@il.ibm.com,
Ben-Ami Yassour <benami@il.ibm.com>
Subject: [PATCH] KVM: fix destroy userspace physical memory slot
Date: Sun, 8 Jun 2008 15:08:00 +0300 [thread overview]
Message-ID: <1212926880-24916-2-git-send-email-benami@il.ibm.com> (raw)
In-Reply-To: <1212926880-24916-1-git-send-email-benami@il.ibm.com>
From: Ben-Ami Yassour <benami@il.ibm.com>
Signed-off-by: Ben-Ami Yassour <benami@il.ibm.com>
---
libkvm/libkvm.c | 34 +++++++++++++++++++++++++++++++++-
1 files changed, 33 insertions(+), 1 deletions(-)
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index 1e7bbed..a49cbdc 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -431,6 +431,32 @@ void *kvm_create_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start,
return ptr;
}
+void kvm_destroy_userspace_phys_mem(kvm_context_t kvm,
+ unsigned long phys_start)
+{
+ int r;
+ struct kvm_userspace_memory_region memory = {
+ .memory_size = 0,
+ .guest_phys_addr = phys_start,
+ .flags = 0,
+ };
+
+ memory.userspace_addr = 0;
+ memory.slot = get_slot(phys_start);
+
+ if (memory.slot == -1)
+ return;
+
+ r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &memory);
+ if (r == -1) {
+ fprintf(stderr, "destroy_userspace_phys_mem: %s",
+ strerror(errno));
+ return;
+ }
+
+ free_slot(memory.slot);
+}
+
#endif
void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start,
@@ -584,7 +610,13 @@ void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start,
__FUNCTION__, phys_start, slots[slot].phys_addr);
phys_start = slots[slot].phys_addr;
}
- kvm_create_phys_mem(kvm, phys_start, 0, 0, 0);
+
+#ifdef KVM_CAP_USER_MEMORY
+ if (ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY) > 0)
+ kvm_destroy_userspace_phys_mem(kvm, phys_start);
+ else
+#endif
+ kvm_create_kernel_phys_mem(kvm, phys_start, 0, 0, 0);
}
static int kvm_get_map(kvm_context_t kvm, int ioctl_num, int slot, void *buf)
--
1.5.5.1
next prev parent reply other threads:[~2008-06-08 12:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-08 8:23 [PATCH] fix destroying a userspace physical memory slot Ben-Ami Yassour
2008-06-08 10:31 ` Avi Kivity
2008-06-08 12:07 ` fix destroy " benami
2008-06-08 12:08 ` benami [this message]
2008-06-09 15:55 ` [PATCH] KVM: " Avi Kivity
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=1212926880-24916-2-git-send-email-benami@il.ibm.com \
--to=benami@il.ibm.com \
--cc=amit.shah@qumranet.com--cc \
--cc=avi@qumranet.com \
--cc=kvm@vger.kernel.org \
--cc=muli@il.ibm.com \
/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