The patch titled KVM: make the hardware setup operations (non-percpu) arch operations has been added to the -mm tree. Its filename is kvm-make-the-hardware-setup-operations-non-percpu.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 the hardware setup operations (non-percpu) 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 | 2 + drivers/kvm/kvm_main.c | 67 +++++++++------------------------------ drivers/kvm/vmx.c | 59 ++++++++++++++++++++++++++++++++++ drivers/kvm/vmx.h | 2 + 4 files changed, 80 insertions(+), 50 deletions(-) diff -puN drivers/kvm/kvm.h~kvm-make-the-hardware-setup-operations-non-percpu drivers/kvm/kvm.h --- a/drivers/kvm/kvm.h~kvm-make-the-hardware-setup-operations-non-percpu +++ a/drivers/kvm/kvm.h @@ -240,6 +240,8 @@ struct kvm_arch_ops { int (*disabled_by_bios)(void); /* __init */ void (*hardware_enable)(void *dummy); /* __init */ void (*hardware_disable)(void *dummy); + int (*hardware_setup)(void); /* __init */ + void (*hardware_unsetup)(void); /* __exit */ }; extern struct kvm_stat kvm_stat; diff -puN drivers/kvm/kvm_main.c~kvm-make-the-hardware-setup-operations-non-percpu drivers/kvm/kvm_main.c --- a/drivers/kvm/kvm_main.c~kvm-make-the-hardware-setup-operations-non-percpu +++ a/drivers/kvm/kvm_main.c @@ -124,7 +124,6 @@ static const u32 vmx_msr_index[] = { #define MSR_IA32_TIME_STAMP_COUNTER 0x010 #define MSR_IA32_FEATURE_CONTROL 0x03a -#define MSR_IA32_VMX_BASIC_MSR 0x480 #define MSR_IA32_VMX_PINBASED_CTLS_MSR 0x481 #define MSR_IA32_VMX_PROCBASED_CTLS_MSR 0x482 #define MSR_IA32_VMX_EXIT_CTLS_MSR 0x483 @@ -303,11 +302,12 @@ DEFINE_PER_CPU(struct vmcs *, vmxarea); EXPORT_SYMBOL_GPL(per_cpu__vmxarea); /* temporary hack */ static DEFINE_PER_CPU(struct vmcs *, current_vmcs); -static struct vmcs_descriptor { +struct vmcs_descriptor { int size; int order; u32 revision_id; } vmcs_descriptor; +EXPORT_SYMBOL_GPL(vmcs_descriptor); #ifdef __x86_64__ static unsigned long read_msr(unsigned long msr) @@ -394,16 +394,6 @@ int kvm_write_guest(struct kvm_vcpu *vcp return req_size - size; } -static __init void setup_vmcs_descriptor(void) -{ - u32 vmx_msr_low, vmx_msr_high; - - rdmsr(MSR_IA32_VMX_BASIC_MSR, vmx_msr_low, vmx_msr_high); - vmcs_descriptor.size = vmx_msr_high & 0x1fff; - vmcs_descriptor.order = get_order(vmcs_descriptor.size); - vmcs_descriptor.revision_id = vmx_msr_low; -}; - static void vmcs_clear(struct vmcs *vmcs) { u64 phys_addr = __pa(vmcs); @@ -501,8 +491,7 @@ static void vcpu_put(struct kvm_vcpu *vc mutex_unlock(&vcpu->mutex); } - -static struct vmcs *alloc_vmcs_cpu(int cpu) +struct vmcs *alloc_vmcs_cpu(int cpu) { int node = cpu_to_node(cpu); struct page *pages; @@ -516,42 +505,18 @@ static struct vmcs *alloc_vmcs_cpu(int c 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()); } -static void free_vmcs(struct vmcs *vmcs) +void free_vmcs(struct vmcs *vmcs) { free_pages((unsigned long)vmcs, vmcs_descriptor.order); } - -static __exit void free_kvm_area(void) -{ - int cpu; - - for_each_online_cpu(cpu) - free_vmcs(per_cpu(vmxarea, cpu)); -} - -static __init int alloc_kvm_area(void) -{ - int cpu; - - for_each_online_cpu(cpu) { - struct vmcs *vmcs; - - vmcs = alloc_vmcs_cpu(cpu); - if (!vmcs) { - free_kvm_area(); - return -ENOMEM; - } - - per_cpu(vmxarea, cpu) = vmcs; - } - return 0; -} +EXPORT_SYMBOL_GPL(free_vmcs); static int kvm_dev_open(struct inode *inode, struct file *filp) { @@ -3592,6 +3557,10 @@ int kvm_init_arch(struct kvm_arch_ops *o return -EOPNOTSUPP; } + r = kvm_arch_ops->hardware_setup(); + if (r < 0) + return r; + on_each_cpu(kvm_arch_ops->hardware_enable, 0, 0, 1); register_reboot_notifier(&kvm_reboot_notifier); @@ -3603,7 +3572,12 @@ int kvm_init_arch(struct kvm_arch_ops *o goto out_free; } + return r; + out_free: + unregister_reboot_notifier(&kvm_reboot_notifier); + on_each_cpu(kvm_arch_ops->hardware_disable, 0, 0, 1); + kvm_arch_ops->hardware_unsetup(); return r; } @@ -3613,6 +3587,7 @@ void kvm_exit_arch(void) unregister_reboot_notifier(&kvm_reboot_notifier); on_each_cpu(kvm_arch_ops->hardware_disable, 0, 0, 1); + kvm_arch_ops->hardware_unsetup(); } static __init int kvm_init(void) @@ -3622,14 +3597,9 @@ static __init int kvm_init(void) kvm_init_debug(); - setup_vmcs_descriptor(); - r = alloc_kvm_area(); - if (r) - goto out; - if ((bad_page = alloc_page(GFP_KERNEL)) == NULL) { r = -ENOMEM; - goto out_free; + goto out; } bad_page_address = page_to_pfn(bad_page) << PAGE_SHIFT; @@ -3637,8 +3607,6 @@ static __init int kvm_init(void) return r; -out_free: - free_kvm_area(); out: kvm_exit_debug(); return r; @@ -3647,7 +3615,6 @@ out: static __exit void kvm_exit(void) { kvm_exit_debug(); - free_kvm_area(); __free_page(pfn_to_page(bad_page_address >> PAGE_SHIFT)); } diff -puN drivers/kvm/vmx.c~kvm-make-the-hardware-setup-operations-non-percpu drivers/kvm/vmx.c --- a/drivers/kvm/vmx.c~kvm-make-the-hardware-setup-operations-non-percpu +++ a/drivers/kvm/vmx.c @@ -25,6 +25,12 @@ MODULE_LICENSE("GPL"); DECLARE_PER_CPU(struct vmcs *, vmxarea); +extern struct vmcs_descriptor { + int size; + int order; + u32 revision_id; +} vmcs_descriptor; + static __init int cpu_has_kvm_support(void) { unsigned long ecx = cpuid_ecx(1); @@ -59,9 +65,62 @@ static void hardware_disable(void *garba asm volatile (ASM_VMX_VMXOFF : : : "cc"); } +static __init void setup_vmcs_descriptor(void) +{ + u32 vmx_msr_low, vmx_msr_high; + + rdmsr(MSR_IA32_VMX_BASIC_MSR, vmx_msr_low, vmx_msr_high); + vmcs_descriptor.size = vmx_msr_high & 0x1fff; + vmcs_descriptor.order = get_order(vmcs_descriptor.size); + vmcs_descriptor.revision_id = vmx_msr_low; +}; + +void free_vmcs(struct vmcs *vmcs); + +static __exit void free_kvm_area(void) +{ + int cpu; + + for_each_online_cpu(cpu) + free_vmcs(per_cpu(vmxarea, cpu)); +} + +extern struct vmcs *alloc_vmcs_cpu(int cpu); + +static __init int alloc_kvm_area(void) +{ + int cpu; + + for_each_online_cpu(cpu) { + struct vmcs *vmcs; + + vmcs = alloc_vmcs_cpu(cpu); + if (!vmcs) { + free_kvm_area(); + return -ENOMEM; + } + + per_cpu(vmxarea, cpu) = vmcs; + } + return 0; +} + +static __init int hardware_setup(void) +{ + setup_vmcs_descriptor(); + return alloc_kvm_area(); +} + +static __exit void hardware_unsetup(void) +{ + free_kvm_area(); +} + static struct kvm_arch_ops vmx_arch_ops = { .cpu_has_kvm_support = cpu_has_kvm_support, .disabled_by_bios = vmx_disabled_by_bios, + .hardware_setup = hardware_setup, + .hardware_unsetup = hardware_unsetup, .hardware_enable = hardware_enable, .hardware_disable = hardware_disable, }; diff -puN drivers/kvm/vmx.h~kvm-make-the-hardware-setup-operations-non-percpu drivers/kvm/vmx.h --- a/drivers/kvm/vmx.h~kvm-make-the-hardware-setup-operations-non-percpu +++ a/drivers/kvm/vmx.h @@ -286,4 +286,6 @@ enum vmcs_field { #define CR4_VMXE 0x2000 +#define MSR_IA32_VMX_BASIC_MSR 0x480 + #endif _ 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