aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>2013-02-07 04:55:57 -0500
committerGleb Natapov <gleb@redhat.com>2013-02-11 04:52:00 -0500
commit7a905b1485adf863607b5fc9e32a3fa3838bcc23 (patch)
tree8f61239e5d74bd58e9972bdc4da27e01fd725419
parent257090f70233084488f7b3ebe99be8c159a23281 (diff)
KVM: Remove user_alloc from struct kvm_memory_slot
This field was needed to differentiate memory slots created by the new API, KVM_SET_USER_MEMORY_REGION, from those by the old equivalent, KVM_SET_MEMORY_REGION, whose support was dropped long before: commit b74a07beed0e64bfba413dcb70dd6749c57f43dc KVM: Remove kernel-allocated memory regions Although we also have private memory slots to which KVM allocates memory with vm_mmap(), !user_alloc slots in other words, the slot id should be enough for differentiating them. Note: corresponding function parameters will be removed later. Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Takuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp> Signed-off-by: Gleb Natapov <gleb@redhat.com>
-rw-r--r--arch/x86/kvm/x86.c37
-rw-r--r--include/linux/kvm_host.h1
-rw-r--r--virt/kvm/kvm_main.c1
3 files changed, 16 insertions, 23 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 373e17a0d398..3c5bb6fe5280 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6897,33 +6897,28 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
6897 bool user_alloc) 6897 bool user_alloc)
6898{ 6898{
6899 int npages = memslot->npages; 6899 int npages = memslot->npages;
6900 int map_flags = MAP_PRIVATE | MAP_ANONYMOUS;
6901 6900
6902 /* Prevent internal slot pages from being moved by fork()/COW. */ 6901 /*
6903 if (memslot->id >= KVM_USER_MEM_SLOTS) 6902 * Only private memory slots need to be mapped here since
6904 map_flags = MAP_SHARED | MAP_ANONYMOUS; 6903 * KVM_SET_MEMORY_REGION ioctl is no longer supported.
6905
6906 /*To keep backward compatibility with older userspace,
6907 *x86 needs to handle !user_alloc case.
6908 */ 6904 */
6909 if (!user_alloc) { 6905 if ((memslot->id >= KVM_USER_MEM_SLOTS) && npages && !old.npages) {
6910 if (npages && !old.npages) { 6906 unsigned long userspace_addr;
6911 unsigned long userspace_addr;
6912 6907
6913 userspace_addr = vm_mmap(NULL, 0, 6908 /*
6914 npages * PAGE_SIZE, 6909 * MAP_SHARED to prevent internal slot pages from being moved
6915 PROT_READ | PROT_WRITE, 6910 * by fork()/COW.
6916 map_flags, 6911 */
6917 0); 6912 userspace_addr = vm_mmap(NULL, 0, npages * PAGE_SIZE,
6913 PROT_READ | PROT_WRITE,
6914 MAP_SHARED | MAP_ANONYMOUS, 0);
6918 6915
6919 if (IS_ERR((void *)userspace_addr)) 6916 if (IS_ERR((void *)userspace_addr))
6920 return PTR_ERR((void *)userspace_addr); 6917 return PTR_ERR((void *)userspace_addr);
6921 6918
6922 memslot->userspace_addr = userspace_addr; 6919 memslot->userspace_addr = userspace_addr;
6923 }
6924 } 6920 }
6925 6921
6926
6927 return 0; 6922 return 0;
6928} 6923}
6929 6924
@@ -6935,7 +6930,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
6935 6930
6936 int nr_mmu_pages = 0, npages = mem->memory_size >> PAGE_SHIFT; 6931 int nr_mmu_pages = 0, npages = mem->memory_size >> PAGE_SHIFT;
6937 6932
6938 if (!user_alloc && !old.user_alloc && old.npages && !npages) { 6933 if ((mem->slot >= KVM_USER_MEM_SLOTS) && old.npages && !npages) {
6939 int ret; 6934 int ret;
6940 6935
6941 ret = vm_munmap(old.userspace_addr, 6936 ret = vm_munmap(old.userspace_addr,
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 0350e0d5e031..722cae78bbc4 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -273,7 +273,6 @@ struct kvm_memory_slot {
273 unsigned long userspace_addr; 273 unsigned long userspace_addr;
274 u32 flags; 274 u32 flags;
275 short id; 275 short id;
276 bool user_alloc;
277}; 276};
278 277
279static inline unsigned long kvm_dirty_bitmap_bytes(struct kvm_memory_slot *memslot) 278static inline unsigned long kvm_dirty_bitmap_bytes(struct kvm_memory_slot *memslot)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 2e93630b4add..adc68feb5c5a 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -839,7 +839,6 @@ int __kvm_set_memory_region(struct kvm *kvm,
839 839
840 r = -ENOMEM; 840 r = -ENOMEM;
841 if (change == KVM_MR_CREATE) { 841 if (change == KVM_MR_CREATE) {
842 new.user_alloc = user_alloc;
843 new.userspace_addr = mem->userspace_addr; 842 new.userspace_addr = mem->userspace_addr;
844 843
845 if (kvm_arch_create_memslot(&new, npages)) 844 if (kvm_arch_create_memslot(&new, npages))