The patch titled KVM: make vcpu creation and destruction arch operations has been added to the -mm tree. Its filename is kvm-make-vcpu-creation-and-destruction-arch-operations.patch See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find out what to do about this ------------------------------------------------------ Subject: KVM: make vcpu creation and destruction arch operations From: Avi Kivity <avi@xxxxxxxxxxxx> Signed-off-by: Avi Kivity <avi@xxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxx> --- drivers/kvm/kvm.h | 5 +- drivers/kvm/kvm_main.c | 74 +----------------------------------- drivers/kvm/vmx.c | 79 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 73 deletions(-) diff -puN drivers/kvm/kvm.h~kvm-make-vcpu-creation-and-destruction-arch-operations drivers/kvm/kvm.h --- a/drivers/kvm/kvm.h~kvm-make-vcpu-creation-and-destruction-arch-operations +++ a/drivers/kvm/kvm.h @@ -260,6 +260,9 @@ struct kvm_arch_ops { int (*hardware_setup)(void); /* __init */ void (*hardware_unsetup)(void); /* __exit */ + int (*vcpu_create)(struct kvm_vcpu *vcpu); + void (*vcpu_free)(struct kvm_vcpu *vcpu); + struct kvm_vcpu *(*vcpu_load)(struct kvm_vcpu *vcpu); void (*vcpu_put)(struct kvm_vcpu *vcpu); @@ -299,8 +302,6 @@ struct kvm_arch_ops { void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu); }; -void __vcpu_clear(void *arg); /* temporary hack */ - extern struct kvm_stat kvm_stat; extern struct kvm_arch_ops *kvm_arch_ops; diff -puN drivers/kvm/kvm_main.c~kvm-make-vcpu-creation-and-destruction-arch-operations drivers/kvm/kvm_main.c --- a/drivers/kvm/kvm_main.c~kvm-make-vcpu-creation-and-destruction-arch-operations +++ a/drivers/kvm/kvm_main.c @@ -219,31 +219,6 @@ int kvm_write_guest(struct kvm_vcpu *vcp } EXPORT_SYMBOL_GPL(kvm_write_guest); -static void vmcs_clear(struct vmcs *vmcs) -{ - u64 phys_addr = __pa(vmcs); - u8 error; - - asm volatile (ASM_VMX_VMCLEAR_RAX "; setna %0" - : "=g"(error) : "a"(&phys_addr), "m"(phys_addr) - : "cc", "memory"); - if (error) - printk(KERN_ERR "kvm: vmclear fail: %p/%llx\n", - vmcs, phys_addr); -} - -void __vcpu_clear(void *arg) -{ - struct kvm_vcpu *vcpu = arg; - int cpu = smp_processor_id(); - - if (vcpu->cpu == cpu) - vmcs_clear(vcpu->vmcs); - if (per_cpu(current_vmcs, cpu) == vcpu->vmcs) - per_cpu(current_vmcs, cpu) = 0; -} -EXPORT_SYMBOL_GPL(__vcpu_clear); - static int vcpu_slot(struct kvm_vcpu *vcpu) { return vcpu - vcpu->kvm->vcpus; @@ -271,33 +246,6 @@ static void vcpu_put(struct kvm_vcpu *vc mutex_unlock(&vcpu->mutex); } -struct vmcs *alloc_vmcs_cpu(int cpu) -{ - int node = cpu_to_node(cpu); - struct page *pages; - struct vmcs *vmcs; - - pages = alloc_pages_node(node, GFP_KERNEL, vmcs_descriptor.order); - if (!pages) - return 0; - vmcs = page_address(pages); - memset(vmcs, 0, vmcs_descriptor.size); - vmcs->revision_id = vmcs_descriptor.revision_id; /* vmcs revision id */ - return vmcs; -} -EXPORT_SYMBOL_GPL(alloc_vmcs_cpu); - -static struct vmcs *alloc_vmcs(void) -{ - return alloc_vmcs_cpu(smp_processor_id()); -} - -void free_vmcs(struct vmcs *vmcs) -{ - free_pages((unsigned long)vmcs, vmcs_descriptor.order); -} -EXPORT_SYMBOL_GPL(free_vmcs); - static int kvm_dev_open(struct inode *inode, struct file *filp) { struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL); @@ -350,18 +298,9 @@ static void kvm_free_physmem(struct kvm kvm_free_physmem_slot(&kvm->memslots[i], 0); } -static void kvm_free_vmcs(struct kvm_vcpu *vcpu) -{ - if (vcpu->vmcs) { - on_each_cpu(__vcpu_clear, vcpu, 0, 1); - free_vmcs(vcpu->vmcs); - vcpu->vmcs = 0; - } -} - static void kvm_free_vcpu(struct kvm_vcpu *vcpu) { - kvm_free_vmcs(vcpu); + kvm_arch_ops->vcpu_free(vcpu); kvm_mmu_destroy(vcpu); } @@ -613,7 +552,6 @@ static int kvm_dev_ioctl_create_vcpu(str { int r; struct kvm_vcpu *vcpu; - struct vmcs *vmcs; r = -EINVAL; if (n < 0 || n >= KVM_MAX_VCPUS) @@ -634,14 +572,9 @@ static int kvm_dev_ioctl_create_vcpu(str vcpu->cpu = -1; /* First load will set up TR */ vcpu->kvm = kvm; - vmcs = alloc_vmcs(); - if (!vmcs) { - mutex_unlock(&vcpu->mutex); + r = kvm_arch_ops->vcpu_create(vcpu); + if (r < 0) goto out_free_vcpus; - } - vmcs_clear(vmcs); - vcpu->vmcs = vmcs; - vcpu->launched = 0; kvm_arch_ops->vcpu_load(vcpu); @@ -658,6 +591,7 @@ static int kvm_dev_ioctl_create_vcpu(str out_free_vcpus: kvm_free_vcpu(vcpu); + mutex_unlock(&vcpu->mutex); out: return r; } diff -puN drivers/kvm/vmx.c~kvm-make-vcpu-creation-and-destruction-arch-operations drivers/kvm/vmx.c --- a/drivers/kvm/vmx.c~kvm-make-vcpu-creation-and-destruction-arch-operations +++ a/drivers/kvm/vmx.c @@ -77,6 +77,30 @@ static const u32 vmx_msr_index[] = { struct vmx_msr_entry *find_msr_entry(struct kvm_vcpu *vcpu, u32 msr); +static void vmcs_clear(struct vmcs *vmcs) +{ + u64 phys_addr = __pa(vmcs); + u8 error; + + asm volatile (ASM_VMX_VMCLEAR_RAX "; setna %0" + : "=g"(error) : "a"(&phys_addr), "m"(phys_addr) + : "cc", "memory"); + if (error) + printk(KERN_ERR "kvm: vmclear fail: %p/%llx\n", + vmcs, phys_addr); +} + +static void __vcpu_clear(void *arg) +{ + struct kvm_vcpu *vcpu = arg; + int cpu = smp_processor_id(); + + if (vcpu->cpu == cpu) + vmcs_clear(vcpu->vmcs); + if (per_cpu(current_vmcs, cpu) == vcpu->vmcs) + per_cpu(current_vmcs, cpu) = 0; +} + /* * Switches to specified vcpu, until a matching vcpu_put(), but assumes * vcpu mutex is already taken. @@ -449,7 +473,30 @@ static __init void setup_vmcs_descriptor vmcs_descriptor.revision_id = vmx_msr_low; }; -void free_vmcs(struct vmcs *vmcs); +static struct vmcs *alloc_vmcs_cpu(int cpu) +{ + int node = cpu_to_node(cpu); + struct page *pages; + struct vmcs *vmcs; + + pages = alloc_pages_node(node, GFP_KERNEL, vmcs_descriptor.order); + if (!pages) + return 0; + vmcs = page_address(pages); + memset(vmcs, 0, vmcs_descriptor.size); + vmcs->revision_id = vmcs_descriptor.revision_id; /* vmcs revision id */ + return vmcs; +} + +static struct vmcs *alloc_vmcs(void) +{ + return alloc_vmcs_cpu(smp_processor_id()); +} + +static void free_vmcs(struct vmcs *vmcs) +{ + free_pages((unsigned long)vmcs, vmcs_descriptor.order); +} static __exit void free_kvm_area(void) { @@ -1790,6 +1837,33 @@ static void vmx_inject_page_fault(struct } +static void vmx_free_vmcs(struct kvm_vcpu *vcpu) +{ + if (vcpu->vmcs) { + on_each_cpu(__vcpu_clear, vcpu, 0, 1); + free_vmcs(vcpu->vmcs); + vcpu->vmcs = 0; + } +} + +static void vmx_free_vcpu(struct kvm_vcpu *vcpu) +{ + vmx_free_vmcs(vcpu); +} + +static int vmx_create_vcpu(struct kvm_vcpu *vcpu) +{ + struct vmcs *vmcs; + + vmcs = alloc_vmcs(); + if (!vmcs) + return -ENOMEM; + vmcs_clear(vmcs); + vcpu->vmcs = vmcs; + vcpu->launched = 0; + return 0; +} + static struct kvm_arch_ops vmx_arch_ops = { .cpu_has_kvm_support = cpu_has_kvm_support, .disabled_by_bios = vmx_disabled_by_bios, @@ -1798,6 +1872,9 @@ static struct kvm_arch_ops vmx_arch_ops .hardware_enable = hardware_enable, .hardware_disable = hardware_disable, + .vcpu_create = vmx_create_vcpu, + .vcpu_free = vmx_free_vcpu, + .vcpu_load = vmx_vcpu_load, .vcpu_put = vmx_vcpu_put, _ Patches currently in -mm which might be from avi@xxxxxxxxxxxx are kvm-userspace-interface.patch kvm-userspace-interface-make-enum-values-in-userspace-interface-explicit.patch kvm-intel-virtual-mode-extensions-definitions.patch kvm-kvm-data-structures.patch kvm-random-accessors-and-constants.patch kvm-virtualization-infrastructure.patch kvm-virtualization-infrastructure-kvm-fix-guest-cr4-corruption.patch kvm-virtualization-infrastructure-include-desch.patch kvm-virtualization-infrastructure-fix-segment-state-changes-across-processor-mode-switches.patch kvm-virtualization-infrastructure-fix-asm-constraints-for-segment-loads.patch kvm-virtualization-infrastructure-fix-mmu-reset-locking-when-setting-cr0.patch kvm-memory-slot-management.patch kvm-vcpu-creation-and-maintenance.patch kvm-vcpu-creation-and-maintenance-segment-access-cleanup.patch kvm-workaround-cr0cd-cache-disable-bit-leak-from-guest-to.patch kvm-vcpu-execution-loop.patch kvm-define-exit-handlers.patch kvm-define-exit-handlers-pass-fs-gs-segment-bases-to-x86-emulator.patch kvm-less-common-exit-handlers.patch kvm-less-common-exit-handlers-handle-rdmsrmsr_efer.patch kvm-mmu.patch kvm-x86-emulator.patch kvm-clarify-licensing.patch kvm-x86-emulator-fix-emulator-mov-cr-decoding.patch kvm-plumbing.patch kvm-dynamically-determine-which-msrs-to-load-and-save.patch kvm-fix-calculation-of-initial-value-of-rdx-register.patch kvm-avoid-using-vmx-instruction-directly.patch kvm-avoid-using-vmx-instruction-directly-fix-asm-constraints.patch kvm-expose-interrupt-bitmap.patch kvm-add-time-stamp-counter-msr-and-accessors.patch kvm-expose-msrs-to-userspace.patch kvm-expose-msrs-to-userspace-v2.patch kvm-create-kvm-intelko-module.patch kvm-make-dev-registration-happen-when-the-arch.patch kvm-make-hardware-detection-an-arch-operation.patch kvm-make-the-per-cpu-enable-disable-functions-arch.patch kvm-make-the-hardware-setup-operations-non-percpu.patch kvm-make-the-guest-debugger-an-arch-operation.patch kvm-make-msr-accessors-arch-operations.patch kvm-make-the-segment-accessors-arch-operations.patch kvm-cache-guest-cr4-in-vcpu-structure.patch kvm-cache-guest-cr0-in-vcpu-structure.patch kvm-add-get_segment_base-arch-accessor.patch kvm-add-idt-and-gdt-descriptor-accessors.patch kvm-make-syncing-the-register-file-to-the-vcpu.patch kvm-make-the-vcpu-execution-loop-an-arch-operation.patch kvm-move-the-vmx-exit-handlers-to-vmxc.patch kvm-make-vcpu_setup-an-arch-operation.patch kvm-make-__set_cr0-and-dependencies-arch-operations.patch kvm-make-__set_cr4-an-arch-operation.patch kvm-make-__set_efer-an-arch-operation.patch kvm-make-set_cr3-and-tlb-flushing-arch-operations.patch kvm-make-inject_page_fault-an-arch-operation.patch kvm-make-inject_gp-an-arch-operation.patch kvm-use-the-idt-and-gdt-accessors-in-realmode-emulation.patch kvm-use-the-general-purpose-register-accessors-rather.patch kvm-move-the-vmx-tsc-accessors-to-vmxc.patch kvm-access-rflags-through-an-arch-operation.patch kvm-move-the-vmx-segment-field-definitions-to-vmxc.patch kvm-add-an-arch-accessor-for-cs-d-b-and-l-bits.patch kvm-add-a-set_cr0_no_modeswitch-arch-accessor.patch kvm-make-vcpu_load-and-vcpu_put-arch-operations.patch kvm-make-vcpu-creation-and-destruction-arch-operations.patch kvm-move-vmcs-static-variables-to-vmxc.patch kvm-make-is_long_mode-an-arch-operation.patch kvm-use-the-tlb-flush-arch-operation-instead-of-an.patch kvm-remove-guest_cpl.patch kvm-move-vmcs-accessors-to-vmxc.patch kvm-move-vmx-helper-inlines-to-vmxc.patch kvm-remove-vmx-includes-from-arch-independent-code.patch - To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html