diff options
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r-- | arch/x86/kvm/x86.c | 125 |
1 files changed, 0 insertions, 125 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 8e60b6c9c0b0..62596d373a49 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -2740,115 +2740,6 @@ static int kvm_vm_ioctl_get_nr_mmu_pages(struct kvm *kvm) | |||
2740 | return kvm->arch.n_alloc_mmu_pages; | 2740 | return kvm->arch.n_alloc_mmu_pages; |
2741 | } | 2741 | } |
2742 | 2742 | ||
2743 | gfn_t unalias_gfn_instantiation(struct kvm *kvm, gfn_t gfn) | ||
2744 | { | ||
2745 | int i; | ||
2746 | struct kvm_mem_alias *alias; | ||
2747 | struct kvm_mem_aliases *aliases; | ||
2748 | |||
2749 | aliases = kvm_aliases(kvm); | ||
2750 | |||
2751 | for (i = 0; i < aliases->naliases; ++i) { | ||
2752 | alias = &aliases->aliases[i]; | ||
2753 | if (alias->flags & KVM_ALIAS_INVALID) | ||
2754 | continue; | ||
2755 | if (gfn >= alias->base_gfn | ||
2756 | && gfn < alias->base_gfn + alias->npages) | ||
2757 | return alias->target_gfn + gfn - alias->base_gfn; | ||
2758 | } | ||
2759 | return gfn; | ||
2760 | } | ||
2761 | |||
2762 | gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn) | ||
2763 | { | ||
2764 | int i; | ||
2765 | struct kvm_mem_alias *alias; | ||
2766 | struct kvm_mem_aliases *aliases; | ||
2767 | |||
2768 | aliases = kvm_aliases(kvm); | ||
2769 | |||
2770 | for (i = 0; i < aliases->naliases; ++i) { | ||
2771 | alias = &aliases->aliases[i]; | ||
2772 | if (gfn >= alias->base_gfn | ||
2773 | && gfn < alias->base_gfn + alias->npages) | ||
2774 | return alias->target_gfn + gfn - alias->base_gfn; | ||
2775 | } | ||
2776 | return gfn; | ||
2777 | } | ||
2778 | |||
2779 | /* | ||
2780 | * Set a new alias region. Aliases map a portion of physical memory into | ||
2781 | * another portion. This is useful for memory windows, for example the PC | ||
2782 | * VGA region. | ||
2783 | */ | ||
2784 | static int kvm_vm_ioctl_set_memory_alias(struct kvm *kvm, | ||
2785 | struct kvm_memory_alias *alias) | ||
2786 | { | ||
2787 | int r, n; | ||
2788 | struct kvm_mem_alias *p; | ||
2789 | struct kvm_mem_aliases *aliases, *old_aliases; | ||
2790 | |||
2791 | r = -EINVAL; | ||
2792 | /* General sanity checks */ | ||
2793 | if (alias->memory_size & (PAGE_SIZE - 1)) | ||
2794 | goto out; | ||
2795 | if (alias->guest_phys_addr & (PAGE_SIZE - 1)) | ||
2796 | goto out; | ||
2797 | if (alias->slot >= KVM_ALIAS_SLOTS) | ||
2798 | goto out; | ||
2799 | if (alias->guest_phys_addr + alias->memory_size | ||
2800 | < alias->guest_phys_addr) | ||
2801 | goto out; | ||
2802 | if (alias->target_phys_addr + alias->memory_size | ||
2803 | < alias->target_phys_addr) | ||
2804 | goto out; | ||
2805 | |||
2806 | r = -ENOMEM; | ||
2807 | aliases = kzalloc(sizeof(struct kvm_mem_aliases), GFP_KERNEL); | ||
2808 | if (!aliases) | ||
2809 | goto out; | ||
2810 | |||
2811 | mutex_lock(&kvm->slots_lock); | ||
2812 | |||
2813 | /* invalidate any gfn reference in case of deletion/shrinking */ | ||
2814 | memcpy(aliases, kvm->arch.aliases, sizeof(struct kvm_mem_aliases)); | ||
2815 | aliases->aliases[alias->slot].flags |= KVM_ALIAS_INVALID; | ||
2816 | old_aliases = kvm->arch.aliases; | ||
2817 | rcu_assign_pointer(kvm->arch.aliases, aliases); | ||
2818 | synchronize_srcu_expedited(&kvm->srcu); | ||
2819 | kvm_mmu_zap_all(kvm); | ||
2820 | kfree(old_aliases); | ||
2821 | |||
2822 | r = -ENOMEM; | ||
2823 | aliases = kzalloc(sizeof(struct kvm_mem_aliases), GFP_KERNEL); | ||
2824 | if (!aliases) | ||
2825 | goto out_unlock; | ||
2826 | |||
2827 | memcpy(aliases, kvm->arch.aliases, sizeof(struct kvm_mem_aliases)); | ||
2828 | |||
2829 | p = &aliases->aliases[alias->slot]; | ||
2830 | p->base_gfn = alias->guest_phys_addr >> PAGE_SHIFT; | ||
2831 | p->npages = alias->memory_size >> PAGE_SHIFT; | ||
2832 | p->target_gfn = alias->target_phys_addr >> PAGE_SHIFT; | ||
2833 | p->flags &= ~(KVM_ALIAS_INVALID); | ||
2834 | |||
2835 | for (n = KVM_ALIAS_SLOTS; n > 0; --n) | ||
2836 | if (aliases->aliases[n - 1].npages) | ||
2837 | break; | ||
2838 | aliases->naliases = n; | ||
2839 | |||
2840 | old_aliases = kvm->arch.aliases; | ||
2841 | rcu_assign_pointer(kvm->arch.aliases, aliases); | ||
2842 | synchronize_srcu_expedited(&kvm->srcu); | ||
2843 | kfree(old_aliases); | ||
2844 | r = 0; | ||
2845 | |||
2846 | out_unlock: | ||
2847 | mutex_unlock(&kvm->slots_lock); | ||
2848 | out: | ||
2849 | return r; | ||
2850 | } | ||
2851 | |||
2852 | static int kvm_vm_ioctl_get_irqchip(struct kvm *kvm, struct kvm_irqchip *chip) | 2743 | static int kvm_vm_ioctl_get_irqchip(struct kvm *kvm, struct kvm_irqchip *chip) |
2853 | { | 2744 | { |
2854 | int r; | 2745 | int r; |
@@ -3056,7 +2947,6 @@ long kvm_arch_vm_ioctl(struct file *filp, | |||
3056 | union { | 2947 | union { |
3057 | struct kvm_pit_state ps; | 2948 | struct kvm_pit_state ps; |
3058 | struct kvm_pit_state2 ps2; | 2949 | struct kvm_pit_state2 ps2; |
3059 | struct kvm_memory_alias alias; | ||
3060 | struct kvm_pit_config pit_config; | 2950 | struct kvm_pit_config pit_config; |
3061 | } u; | 2951 | } u; |
3062 | 2952 | ||
@@ -3101,14 +2991,6 @@ long kvm_arch_vm_ioctl(struct file *filp, | |||
3101 | case KVM_GET_NR_MMU_PAGES: | 2991 | case KVM_GET_NR_MMU_PAGES: |
3102 | r = kvm_vm_ioctl_get_nr_mmu_pages(kvm); | 2992 | r = kvm_vm_ioctl_get_nr_mmu_pages(kvm); |
3103 | break; | 2993 | break; |
3104 | case KVM_SET_MEMORY_ALIAS: | ||
3105 | r = -EFAULT; | ||
3106 | if (copy_from_user(&u.alias, argp, sizeof(struct kvm_memory_alias))) | ||
3107 | goto out; | ||
3108 | r = kvm_vm_ioctl_set_memory_alias(kvm, &u.alias); | ||
3109 | if (r) | ||
3110 | goto out; | ||
3111 | break; | ||
3112 | case KVM_CREATE_IRQCHIP: { | 2994 | case KVM_CREATE_IRQCHIP: { |
3113 | struct kvm_pic *vpic; | 2995 | struct kvm_pic *vpic; |
3114 | 2996 | ||
@@ -5559,12 +5441,6 @@ struct kvm *kvm_arch_create_vm(void) | |||
5559 | if (!kvm) | 5441 | if (!kvm) |
5560 | return ERR_PTR(-ENOMEM); | 5442 | return ERR_PTR(-ENOMEM); |
5561 | 5443 | ||
5562 | kvm->arch.aliases = kzalloc(sizeof(struct kvm_mem_aliases), GFP_KERNEL); | ||
5563 | if (!kvm->arch.aliases) { | ||
5564 | kfree(kvm); | ||
5565 | return ERR_PTR(-ENOMEM); | ||
5566 | } | ||
5567 | |||
5568 | INIT_LIST_HEAD(&kvm->arch.active_mmu_pages); | 5444 | INIT_LIST_HEAD(&kvm->arch.active_mmu_pages); |
5569 | INIT_LIST_HEAD(&kvm->arch.assigned_dev_head); | 5445 | INIT_LIST_HEAD(&kvm->arch.assigned_dev_head); |
5570 | 5446 | ||
@@ -5622,7 +5498,6 @@ void kvm_arch_destroy_vm(struct kvm *kvm) | |||
5622 | if (kvm->arch.ept_identity_pagetable) | 5498 | if (kvm->arch.ept_identity_pagetable) |
5623 | put_page(kvm->arch.ept_identity_pagetable); | 5499 | put_page(kvm->arch.ept_identity_pagetable); |
5624 | cleanup_srcu_struct(&kvm->srcu); | 5500 | cleanup_srcu_struct(&kvm->srcu); |
5625 | kfree(kvm->arch.aliases); | ||
5626 | kfree(kvm); | 5501 | kfree(kvm); |
5627 | } | 5502 | } |
5628 | 5503 | ||