summaryrefslogtreecommitdiff
path: root/libkvm
diff options
context:
space:
mode:
authorBen-Ami Yassour <benami@il.ibm.com>2008-06-08 15:08:00 +0300
committerAvi Kivity <avi@qumranet.com>2008-06-09 18:55:37 +0300
commit5dbb9a744fb9c0d16d0fc9398d0bf308495b5545 (patch)
tree773772069a38db14e207a6a3e8b81539a7fda188 /libkvm
parenteb2fd67cbecdb573f908697ed41b81ee312372bd (diff)
kvm: libkvm: add API for destroying userspace physical memory slot
Signed-off-by: Ben-Ami Yassour <benami@il.ibm.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'libkvm')
-rw-r--r--libkvm/libkvm.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index 1e7bbede..a49cbdc6 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)