diff options
author | Takuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp> | 2013-02-27 05:43:00 -0500 |
---|---|---|
committer | Marcelo Tosatti <mtosatti@redhat.com> | 2013-03-04 18:21:08 -0500 |
commit | 47ae31e257c548abdb199e0d26723139a9a967ba (patch) | |
tree | e2888e7839935423a3afc64c0296eb9e4eed23c4 | |
parent | 462fce46065ec4b200c08619c047b9e5a8fd154a (diff) |
KVM: set_memory_region: Drop user_alloc from set_memory_region()
Except ia64's stale code, KVM_SET_MEMORY_REGION support, this is only
used for sanity checks in __kvm_set_memory_region() which can easily
be changed to use slot id instead.
Signed-off-by: Takuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
-rw-r--r-- | arch/ia64/kvm/kvm-ia64.c | 18 | ||||
-rw-r--r-- | arch/x86/kvm/vmx.c | 6 | ||||
-rw-r--r-- | include/linux/kvm_host.h | 10 | ||||
-rw-r--r-- | virt/kvm/kvm_main.c | 18 |
4 files changed, 13 insertions, 39 deletions
diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c index cbc5b0417dab..43701f0c0f71 100644 --- a/arch/ia64/kvm/kvm-ia64.c +++ b/arch/ia64/kvm/kvm-ia64.c | |||
@@ -942,24 +942,6 @@ long kvm_arch_vm_ioctl(struct file *filp, | |||
942 | int r = -ENOTTY; | 942 | int r = -ENOTTY; |
943 | 943 | ||
944 | switch (ioctl) { | 944 | switch (ioctl) { |
945 | case KVM_SET_MEMORY_REGION: { | ||
946 | struct kvm_memory_region kvm_mem; | ||
947 | struct kvm_userspace_memory_region kvm_userspace_mem; | ||
948 | |||
949 | r = -EFAULT; | ||
950 | if (copy_from_user(&kvm_mem, argp, sizeof kvm_mem)) | ||
951 | goto out; | ||
952 | kvm_userspace_mem.slot = kvm_mem.slot; | ||
953 | kvm_userspace_mem.flags = kvm_mem.flags; | ||
954 | kvm_userspace_mem.guest_phys_addr = | ||
955 | kvm_mem.guest_phys_addr; | ||
956 | kvm_userspace_mem.memory_size = kvm_mem.memory_size; | ||
957 | r = kvm_vm_ioctl_set_memory_region(kvm, | ||
958 | &kvm_userspace_mem, false); | ||
959 | if (r) | ||
960 | goto out; | ||
961 | break; | ||
962 | } | ||
963 | case KVM_CREATE_IRQCHIP: | 945 | case KVM_CREATE_IRQCHIP: |
964 | r = -EFAULT; | 946 | r = -EFAULT; |
965 | r = kvm_ioapic_init(kvm); | 947 | r = kvm_ioapic_init(kvm); |
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 7cc566b09ff2..58fb7c27e3b5 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c | |||
@@ -3694,7 +3694,7 @@ static int alloc_apic_access_page(struct kvm *kvm) | |||
3694 | kvm_userspace_mem.flags = 0; | 3694 | kvm_userspace_mem.flags = 0; |
3695 | kvm_userspace_mem.guest_phys_addr = 0xfee00000ULL; | 3695 | kvm_userspace_mem.guest_phys_addr = 0xfee00000ULL; |
3696 | kvm_userspace_mem.memory_size = PAGE_SIZE; | 3696 | kvm_userspace_mem.memory_size = PAGE_SIZE; |
3697 | r = __kvm_set_memory_region(kvm, &kvm_userspace_mem, false); | 3697 | r = __kvm_set_memory_region(kvm, &kvm_userspace_mem); |
3698 | if (r) | 3698 | if (r) |
3699 | goto out; | 3699 | goto out; |
3700 | 3700 | ||
@@ -3724,7 +3724,7 @@ static int alloc_identity_pagetable(struct kvm *kvm) | |||
3724 | kvm_userspace_mem.guest_phys_addr = | 3724 | kvm_userspace_mem.guest_phys_addr = |
3725 | kvm->arch.ept_identity_map_addr; | 3725 | kvm->arch.ept_identity_map_addr; |
3726 | kvm_userspace_mem.memory_size = PAGE_SIZE; | 3726 | kvm_userspace_mem.memory_size = PAGE_SIZE; |
3727 | r = __kvm_set_memory_region(kvm, &kvm_userspace_mem, false); | 3727 | r = __kvm_set_memory_region(kvm, &kvm_userspace_mem); |
3728 | if (r) | 3728 | if (r) |
3729 | goto out; | 3729 | goto out; |
3730 | 3730 | ||
@@ -4364,7 +4364,7 @@ static int vmx_set_tss_addr(struct kvm *kvm, unsigned int addr) | |||
4364 | .flags = 0, | 4364 | .flags = 0, |
4365 | }; | 4365 | }; |
4366 | 4366 | ||
4367 | ret = kvm_set_memory_region(kvm, &tss_mem, false); | 4367 | ret = kvm_set_memory_region(kvm, &tss_mem); |
4368 | if (ret) | 4368 | if (ret) |
4369 | return ret; | 4369 | return ret; |
4370 | kvm->arch.tss_addr = addr; | 4370 | kvm->arch.tss_addr = addr; |
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index b4757a1cc4c4..84a994c7a5c5 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h | |||
@@ -453,11 +453,9 @@ id_to_memslot(struct kvm_memslots *slots, int id) | |||
453 | } | 453 | } |
454 | 454 | ||
455 | int kvm_set_memory_region(struct kvm *kvm, | 455 | int kvm_set_memory_region(struct kvm *kvm, |
456 | struct kvm_userspace_memory_region *mem, | 456 | struct kvm_userspace_memory_region *mem); |
457 | bool user_alloc); | ||
458 | int __kvm_set_memory_region(struct kvm *kvm, | 457 | int __kvm_set_memory_region(struct kvm *kvm, |
459 | struct kvm_userspace_memory_region *mem, | 458 | struct kvm_userspace_memory_region *mem); |
460 | bool user_alloc); | ||
461 | void kvm_arch_free_memslot(struct kvm_memory_slot *free, | 459 | void kvm_arch_free_memslot(struct kvm_memory_slot *free, |
462 | struct kvm_memory_slot *dont); | 460 | struct kvm_memory_slot *dont); |
463 | int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages); | 461 | int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages); |
@@ -553,9 +551,7 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, | |||
553 | struct kvm_dirty_log *log); | 551 | struct kvm_dirty_log *log); |
554 | 552 | ||
555 | int kvm_vm_ioctl_set_memory_region(struct kvm *kvm, | 553 | int kvm_vm_ioctl_set_memory_region(struct kvm *kvm, |
556 | struct | 554 | struct kvm_userspace_memory_region *mem); |
557 | kvm_userspace_memory_region *mem, | ||
558 | bool user_alloc); | ||
559 | int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level); | 555 | int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level); |
560 | long kvm_arch_vm_ioctl(struct file *filp, | 556 | long kvm_arch_vm_ioctl(struct file *filp, |
561 | unsigned int ioctl, unsigned long arg); | 557 | unsigned int ioctl, unsigned long arg); |
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index fd3037010e75..5b3e41b81f0d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -745,8 +745,7 @@ enum kvm_mr_change { | |||
745 | * Must be called holding mmap_sem for write. | 745 | * Must be called holding mmap_sem for write. |
746 | */ | 746 | */ |
747 | int __kvm_set_memory_region(struct kvm *kvm, | 747 | int __kvm_set_memory_region(struct kvm *kvm, |
748 | struct kvm_userspace_memory_region *mem, | 748 | struct kvm_userspace_memory_region *mem) |
749 | bool user_alloc) | ||
750 | { | 749 | { |
751 | int r; | 750 | int r; |
752 | gfn_t base_gfn; | 751 | gfn_t base_gfn; |
@@ -767,7 +766,7 @@ int __kvm_set_memory_region(struct kvm *kvm, | |||
767 | if (mem->guest_phys_addr & (PAGE_SIZE - 1)) | 766 | if (mem->guest_phys_addr & (PAGE_SIZE - 1)) |
768 | goto out; | 767 | goto out; |
769 | /* We can read the guest memory with __xxx_user() later on. */ | 768 | /* We can read the guest memory with __xxx_user() later on. */ |
770 | if (user_alloc && | 769 | if ((mem->slot < KVM_USER_MEM_SLOTS) && |
771 | ((mem->userspace_addr & (PAGE_SIZE - 1)) || | 770 | ((mem->userspace_addr & (PAGE_SIZE - 1)) || |
772 | !access_ok(VERIFY_WRITE, | 771 | !access_ok(VERIFY_WRITE, |
773 | (void __user *)(unsigned long)mem->userspace_addr, | 772 | (void __user *)(unsigned long)mem->userspace_addr, |
@@ -932,26 +931,23 @@ out: | |||
932 | EXPORT_SYMBOL_GPL(__kvm_set_memory_region); | 931 | EXPORT_SYMBOL_GPL(__kvm_set_memory_region); |
933 | 932 | ||
934 | int kvm_set_memory_region(struct kvm *kvm, | 933 | int kvm_set_memory_region(struct kvm *kvm, |
935 | struct kvm_userspace_memory_region *mem, | 934 | struct kvm_userspace_memory_region *mem) |
936 | bool user_alloc) | ||
937 | { | 935 | { |
938 | int r; | 936 | int r; |
939 | 937 | ||
940 | mutex_lock(&kvm->slots_lock); | 938 | mutex_lock(&kvm->slots_lock); |
941 | r = __kvm_set_memory_region(kvm, mem, user_alloc); | 939 | r = __kvm_set_memory_region(kvm, mem); |
942 | mutex_unlock(&kvm->slots_lock); | 940 | mutex_unlock(&kvm->slots_lock); |
943 | return r; | 941 | return r; |
944 | } | 942 | } |
945 | EXPORT_SYMBOL_GPL(kvm_set_memory_region); | 943 | EXPORT_SYMBOL_GPL(kvm_set_memory_region); |
946 | 944 | ||
947 | int kvm_vm_ioctl_set_memory_region(struct kvm *kvm, | 945 | int kvm_vm_ioctl_set_memory_region(struct kvm *kvm, |
948 | struct | 946 | struct kvm_userspace_memory_region *mem) |
949 | kvm_userspace_memory_region *mem, | ||
950 | bool user_alloc) | ||
951 | { | 947 | { |
952 | if (mem->slot >= KVM_USER_MEM_SLOTS) | 948 | if (mem->slot >= KVM_USER_MEM_SLOTS) |
953 | return -EINVAL; | 949 | return -EINVAL; |
954 | return kvm_set_memory_region(kvm, mem, user_alloc); | 950 | return kvm_set_memory_region(kvm, mem); |
955 | } | 951 | } |
956 | 952 | ||
957 | int kvm_get_dirty_log(struct kvm *kvm, | 953 | int kvm_get_dirty_log(struct kvm *kvm, |
@@ -2198,7 +2194,7 @@ static long kvm_vm_ioctl(struct file *filp, | |||
2198 | sizeof kvm_userspace_mem)) | 2194 | sizeof kvm_userspace_mem)) |
2199 | goto out; | 2195 | goto out; |
2200 | 2196 | ||
2201 | r = kvm_vm_ioctl_set_memory_region(kvm, &kvm_userspace_mem, true); | 2197 | r = kvm_vm_ioctl_set_memory_region(kvm, &kvm_userspace_mem); |
2202 | break; | 2198 | break; |
2203 | } | 2199 | } |
2204 | case KVM_GET_DIRTY_LOG: { | 2200 | case KVM_GET_DIRTY_LOG: { |