diff options
-rw-r--r-- | arch/arm64/kvm/hyp/sysreg-sr.c | 8 | ||||
-rw-r--r-- | arch/x86/kvm/mtrr.c | 1 | ||||
-rw-r--r-- | arch/x86/kvm/vmx.c | 76 | ||||
-rw-r--r-- | virt/kvm/kvm_main.c | 15 |
4 files changed, 60 insertions, 40 deletions
diff --git a/arch/arm64/kvm/hyp/sysreg-sr.c b/arch/arm64/kvm/hyp/sysreg-sr.c index 0f7c40eb3f53..934137647837 100644 --- a/arch/arm64/kvm/hyp/sysreg-sr.c +++ b/arch/arm64/kvm/hyp/sysreg-sr.c | |||
@@ -27,8 +27,8 @@ static void __hyp_text __sysreg_do_nothing(struct kvm_cpu_context *ctxt) { } | |||
27 | /* | 27 | /* |
28 | * Non-VHE: Both host and guest must save everything. | 28 | * Non-VHE: Both host and guest must save everything. |
29 | * | 29 | * |
30 | * VHE: Host must save tpidr*_el[01], actlr_el1, sp0, pc, pstate, and | 30 | * VHE: Host must save tpidr*_el[01], actlr_el1, mdscr_el1, sp0, pc, |
31 | * guest must save everything. | 31 | * pstate, and guest must save everything. |
32 | */ | 32 | */ |
33 | 33 | ||
34 | static void __hyp_text __sysreg_save_common_state(struct kvm_cpu_context *ctxt) | 34 | static void __hyp_text __sysreg_save_common_state(struct kvm_cpu_context *ctxt) |
@@ -37,6 +37,7 @@ static void __hyp_text __sysreg_save_common_state(struct kvm_cpu_context *ctxt) | |||
37 | ctxt->sys_regs[TPIDR_EL0] = read_sysreg(tpidr_el0); | 37 | ctxt->sys_regs[TPIDR_EL0] = read_sysreg(tpidr_el0); |
38 | ctxt->sys_regs[TPIDRRO_EL0] = read_sysreg(tpidrro_el0); | 38 | ctxt->sys_regs[TPIDRRO_EL0] = read_sysreg(tpidrro_el0); |
39 | ctxt->sys_regs[TPIDR_EL1] = read_sysreg(tpidr_el1); | 39 | ctxt->sys_regs[TPIDR_EL1] = read_sysreg(tpidr_el1); |
40 | ctxt->sys_regs[MDSCR_EL1] = read_sysreg(mdscr_el1); | ||
40 | ctxt->gp_regs.regs.sp = read_sysreg(sp_el0); | 41 | ctxt->gp_regs.regs.sp = read_sysreg(sp_el0); |
41 | ctxt->gp_regs.regs.pc = read_sysreg_el2(elr); | 42 | ctxt->gp_regs.regs.pc = read_sysreg_el2(elr); |
42 | ctxt->gp_regs.regs.pstate = read_sysreg_el2(spsr); | 43 | ctxt->gp_regs.regs.pstate = read_sysreg_el2(spsr); |
@@ -61,7 +62,6 @@ static void __hyp_text __sysreg_save_state(struct kvm_cpu_context *ctxt) | |||
61 | ctxt->sys_regs[AMAIR_EL1] = read_sysreg_el1(amair); | 62 | ctxt->sys_regs[AMAIR_EL1] = read_sysreg_el1(amair); |
62 | ctxt->sys_regs[CNTKCTL_EL1] = read_sysreg_el1(cntkctl); | 63 | ctxt->sys_regs[CNTKCTL_EL1] = read_sysreg_el1(cntkctl); |
63 | ctxt->sys_regs[PAR_EL1] = read_sysreg(par_el1); | 64 | ctxt->sys_regs[PAR_EL1] = read_sysreg(par_el1); |
64 | ctxt->sys_regs[MDSCR_EL1] = read_sysreg(mdscr_el1); | ||
65 | 65 | ||
66 | ctxt->gp_regs.sp_el1 = read_sysreg(sp_el1); | 66 | ctxt->gp_regs.sp_el1 = read_sysreg(sp_el1); |
67 | ctxt->gp_regs.elr_el1 = read_sysreg_el1(elr); | 67 | ctxt->gp_regs.elr_el1 = read_sysreg_el1(elr); |
@@ -90,6 +90,7 @@ static void __hyp_text __sysreg_restore_common_state(struct kvm_cpu_context *ctx | |||
90 | write_sysreg(ctxt->sys_regs[TPIDR_EL0], tpidr_el0); | 90 | write_sysreg(ctxt->sys_regs[TPIDR_EL0], tpidr_el0); |
91 | write_sysreg(ctxt->sys_regs[TPIDRRO_EL0], tpidrro_el0); | 91 | write_sysreg(ctxt->sys_regs[TPIDRRO_EL0], tpidrro_el0); |
92 | write_sysreg(ctxt->sys_regs[TPIDR_EL1], tpidr_el1); | 92 | write_sysreg(ctxt->sys_regs[TPIDR_EL1], tpidr_el1); |
93 | write_sysreg(ctxt->sys_regs[MDSCR_EL1], mdscr_el1); | ||
93 | write_sysreg(ctxt->gp_regs.regs.sp, sp_el0); | 94 | write_sysreg(ctxt->gp_regs.regs.sp, sp_el0); |
94 | write_sysreg_el2(ctxt->gp_regs.regs.pc, elr); | 95 | write_sysreg_el2(ctxt->gp_regs.regs.pc, elr); |
95 | write_sysreg_el2(ctxt->gp_regs.regs.pstate, spsr); | 96 | write_sysreg_el2(ctxt->gp_regs.regs.pstate, spsr); |
@@ -114,7 +115,6 @@ static void __hyp_text __sysreg_restore_state(struct kvm_cpu_context *ctxt) | |||
114 | write_sysreg_el1(ctxt->sys_regs[AMAIR_EL1], amair); | 115 | write_sysreg_el1(ctxt->sys_regs[AMAIR_EL1], amair); |
115 | write_sysreg_el1(ctxt->sys_regs[CNTKCTL_EL1], cntkctl); | 116 | write_sysreg_el1(ctxt->sys_regs[CNTKCTL_EL1], cntkctl); |
116 | write_sysreg(ctxt->sys_regs[PAR_EL1], par_el1); | 117 | write_sysreg(ctxt->sys_regs[PAR_EL1], par_el1); |
117 | write_sysreg(ctxt->sys_regs[MDSCR_EL1], mdscr_el1); | ||
118 | 118 | ||
119 | write_sysreg(ctxt->gp_regs.sp_el1, sp_el1); | 119 | write_sysreg(ctxt->gp_regs.sp_el1, sp_el1); |
120 | write_sysreg_el1(ctxt->gp_regs.elr_el1, elr); | 120 | write_sysreg_el1(ctxt->gp_regs.elr_el1, elr); |
diff --git a/arch/x86/kvm/mtrr.c b/arch/x86/kvm/mtrr.c index c146f3c262c3..0149ac59c273 100644 --- a/arch/x86/kvm/mtrr.c +++ b/arch/x86/kvm/mtrr.c | |||
@@ -539,6 +539,7 @@ static void mtrr_lookup_var_start(struct mtrr_iter *iter) | |||
539 | 539 | ||
540 | iter->fixed = false; | 540 | iter->fixed = false; |
541 | iter->start_max = iter->start; | 541 | iter->start_max = iter->start; |
542 | iter->range = NULL; | ||
542 | iter->range = list_prepare_entry(iter->range, &mtrr_state->head, node); | 543 | iter->range = list_prepare_entry(iter->range, &mtrr_state->head, node); |
543 | 544 | ||
544 | __mtrr_lookup_var_next(iter); | 545 | __mtrr_lookup_var_next(iter); |
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 64a79f271276..7758680db20b 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c | |||
@@ -4979,6 +4979,12 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx) | |||
4979 | if (vmx_xsaves_supported()) | 4979 | if (vmx_xsaves_supported()) |
4980 | vmcs_write64(XSS_EXIT_BITMAP, VMX_XSS_EXIT_BITMAP); | 4980 | vmcs_write64(XSS_EXIT_BITMAP, VMX_XSS_EXIT_BITMAP); |
4981 | 4981 | ||
4982 | if (enable_pml) { | ||
4983 | ASSERT(vmx->pml_pg); | ||
4984 | vmcs_write64(PML_ADDRESS, page_to_phys(vmx->pml_pg)); | ||
4985 | vmcs_write16(GUEST_PML_INDEX, PML_ENTITY_NUM - 1); | ||
4986 | } | ||
4987 | |||
4982 | return 0; | 4988 | return 0; |
4983 | } | 4989 | } |
4984 | 4990 | ||
@@ -7937,22 +7943,6 @@ static void vmx_get_exit_info(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2) | |||
7937 | *info2 = vmcs_read32(VM_EXIT_INTR_INFO); | 7943 | *info2 = vmcs_read32(VM_EXIT_INTR_INFO); |
7938 | } | 7944 | } |
7939 | 7945 | ||
7940 | static int vmx_create_pml_buffer(struct vcpu_vmx *vmx) | ||
7941 | { | ||
7942 | struct page *pml_pg; | ||
7943 | |||
7944 | pml_pg = alloc_page(GFP_KERNEL | __GFP_ZERO); | ||
7945 | if (!pml_pg) | ||
7946 | return -ENOMEM; | ||
7947 | |||
7948 | vmx->pml_pg = pml_pg; | ||
7949 | |||
7950 | vmcs_write64(PML_ADDRESS, page_to_phys(vmx->pml_pg)); | ||
7951 | vmcs_write16(GUEST_PML_INDEX, PML_ENTITY_NUM - 1); | ||
7952 | |||
7953 | return 0; | ||
7954 | } | ||
7955 | |||
7956 | static void vmx_destroy_pml_buffer(struct vcpu_vmx *vmx) | 7946 | static void vmx_destroy_pml_buffer(struct vcpu_vmx *vmx) |
7957 | { | 7947 | { |
7958 | if (vmx->pml_pg) { | 7948 | if (vmx->pml_pg) { |
@@ -8224,6 +8214,7 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu) | |||
8224 | if ((vectoring_info & VECTORING_INFO_VALID_MASK) && | 8214 | if ((vectoring_info & VECTORING_INFO_VALID_MASK) && |
8225 | (exit_reason != EXIT_REASON_EXCEPTION_NMI && | 8215 | (exit_reason != EXIT_REASON_EXCEPTION_NMI && |
8226 | exit_reason != EXIT_REASON_EPT_VIOLATION && | 8216 | exit_reason != EXIT_REASON_EPT_VIOLATION && |
8217 | exit_reason != EXIT_REASON_PML_FULL && | ||
8227 | exit_reason != EXIT_REASON_TASK_SWITCH)) { | 8218 | exit_reason != EXIT_REASON_TASK_SWITCH)) { |
8228 | vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; | 8219 | vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; |
8229 | vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_DELIVERY_EV; | 8220 | vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_DELIVERY_EV; |
@@ -8854,6 +8845,22 @@ static void vmx_load_vmcs01(struct kvm_vcpu *vcpu) | |||
8854 | put_cpu(); | 8845 | put_cpu(); |
8855 | } | 8846 | } |
8856 | 8847 | ||
8848 | /* | ||
8849 | * Ensure that the current vmcs of the logical processor is the | ||
8850 | * vmcs01 of the vcpu before calling free_nested(). | ||
8851 | */ | ||
8852 | static void vmx_free_vcpu_nested(struct kvm_vcpu *vcpu) | ||
8853 | { | ||
8854 | struct vcpu_vmx *vmx = to_vmx(vcpu); | ||
8855 | int r; | ||
8856 | |||
8857 | r = vcpu_load(vcpu); | ||
8858 | BUG_ON(r); | ||
8859 | vmx_load_vmcs01(vcpu); | ||
8860 | free_nested(vmx); | ||
8861 | vcpu_put(vcpu); | ||
8862 | } | ||
8863 | |||
8857 | static void vmx_free_vcpu(struct kvm_vcpu *vcpu) | 8864 | static void vmx_free_vcpu(struct kvm_vcpu *vcpu) |
8858 | { | 8865 | { |
8859 | struct vcpu_vmx *vmx = to_vmx(vcpu); | 8866 | struct vcpu_vmx *vmx = to_vmx(vcpu); |
@@ -8862,8 +8869,7 @@ static void vmx_free_vcpu(struct kvm_vcpu *vcpu) | |||
8862 | vmx_destroy_pml_buffer(vmx); | 8869 | vmx_destroy_pml_buffer(vmx); |
8863 | free_vpid(vmx->vpid); | 8870 | free_vpid(vmx->vpid); |
8864 | leave_guest_mode(vcpu); | 8871 | leave_guest_mode(vcpu); |
8865 | vmx_load_vmcs01(vcpu); | 8872 | vmx_free_vcpu_nested(vcpu); |
8866 | free_nested(vmx); | ||
8867 | free_loaded_vmcs(vmx->loaded_vmcs); | 8873 | free_loaded_vmcs(vmx->loaded_vmcs); |
8868 | kfree(vmx->guest_msrs); | 8874 | kfree(vmx->guest_msrs); |
8869 | kvm_vcpu_uninit(vcpu); | 8875 | kvm_vcpu_uninit(vcpu); |
@@ -8885,14 +8891,26 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) | |||
8885 | if (err) | 8891 | if (err) |
8886 | goto free_vcpu; | 8892 | goto free_vcpu; |
8887 | 8893 | ||
8894 | err = -ENOMEM; | ||
8895 | |||
8896 | /* | ||
8897 | * If PML is turned on, failure on enabling PML just results in failure | ||
8898 | * of creating the vcpu, therefore we can simplify PML logic (by | ||
8899 | * avoiding dealing with cases, such as enabling PML partially on vcpus | ||
8900 | * for the guest, etc. | ||
8901 | */ | ||
8902 | if (enable_pml) { | ||
8903 | vmx->pml_pg = alloc_page(GFP_KERNEL | __GFP_ZERO); | ||
8904 | if (!vmx->pml_pg) | ||
8905 | goto uninit_vcpu; | ||
8906 | } | ||
8907 | |||
8888 | vmx->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL); | 8908 | vmx->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL); |
8889 | BUILD_BUG_ON(ARRAY_SIZE(vmx_msr_index) * sizeof(vmx->guest_msrs[0]) | 8909 | BUILD_BUG_ON(ARRAY_SIZE(vmx_msr_index) * sizeof(vmx->guest_msrs[0]) |
8890 | > PAGE_SIZE); | 8910 | > PAGE_SIZE); |
8891 | 8911 | ||
8892 | err = -ENOMEM; | 8912 | if (!vmx->guest_msrs) |
8893 | if (!vmx->guest_msrs) { | 8913 | goto free_pml; |
8894 | goto uninit_vcpu; | ||
8895 | } | ||
8896 | 8914 | ||
8897 | vmx->loaded_vmcs = &vmx->vmcs01; | 8915 | vmx->loaded_vmcs = &vmx->vmcs01; |
8898 | vmx->loaded_vmcs->vmcs = alloc_vmcs(); | 8916 | vmx->loaded_vmcs->vmcs = alloc_vmcs(); |
@@ -8936,18 +8954,6 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) | |||
8936 | vmx->nested.current_vmptr = -1ull; | 8954 | vmx->nested.current_vmptr = -1ull; |
8937 | vmx->nested.current_vmcs12 = NULL; | 8955 | vmx->nested.current_vmcs12 = NULL; |
8938 | 8956 | ||
8939 | /* | ||
8940 | * If PML is turned on, failure on enabling PML just results in failure | ||
8941 | * of creating the vcpu, therefore we can simplify PML logic (by | ||
8942 | * avoiding dealing with cases, such as enabling PML partially on vcpus | ||
8943 | * for the guest, etc. | ||
8944 | */ | ||
8945 | if (enable_pml) { | ||
8946 | err = vmx_create_pml_buffer(vmx); | ||
8947 | if (err) | ||
8948 | goto free_vmcs; | ||
8949 | } | ||
8950 | |||
8951 | return &vmx->vcpu; | 8957 | return &vmx->vcpu; |
8952 | 8958 | ||
8953 | free_vmcs: | 8959 | free_vmcs: |
@@ -8955,6 +8961,8 @@ free_vmcs: | |||
8955 | free_loaded_vmcs(vmx->loaded_vmcs); | 8961 | free_loaded_vmcs(vmx->loaded_vmcs); |
8956 | free_msrs: | 8962 | free_msrs: |
8957 | kfree(vmx->guest_msrs); | 8963 | kfree(vmx->guest_msrs); |
8964 | free_pml: | ||
8965 | vmx_destroy_pml_buffer(vmx); | ||
8958 | uninit_vcpu: | 8966 | uninit_vcpu: |
8959 | kvm_vcpu_uninit(&vmx->vcpu); | 8967 | kvm_vcpu_uninit(&vmx->vcpu); |
8960 | free_vcpu: | 8968 | free_vcpu: |
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 48bd520fc702..ce3d8e5be73e 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -148,6 +148,7 @@ int vcpu_load(struct kvm_vcpu *vcpu) | |||
148 | put_cpu(); | 148 | put_cpu(); |
149 | return 0; | 149 | return 0; |
150 | } | 150 | } |
151 | EXPORT_SYMBOL_GPL(vcpu_load); | ||
151 | 152 | ||
152 | void vcpu_put(struct kvm_vcpu *vcpu) | 153 | void vcpu_put(struct kvm_vcpu *vcpu) |
153 | { | 154 | { |
@@ -157,6 +158,7 @@ void vcpu_put(struct kvm_vcpu *vcpu) | |||
157 | preempt_enable(); | 158 | preempt_enable(); |
158 | mutex_unlock(&vcpu->mutex); | 159 | mutex_unlock(&vcpu->mutex); |
159 | } | 160 | } |
161 | EXPORT_SYMBOL_GPL(vcpu_put); | ||
160 | 162 | ||
161 | static void ack_flush(void *_completed) | 163 | static void ack_flush(void *_completed) |
162 | { | 164 | { |
@@ -3048,6 +3050,7 @@ static int kvm_dev_ioctl_create_vm(unsigned long type) | |||
3048 | { | 3050 | { |
3049 | int r; | 3051 | int r; |
3050 | struct kvm *kvm; | 3052 | struct kvm *kvm; |
3053 | struct file *file; | ||
3051 | 3054 | ||
3052 | kvm = kvm_create_vm(type); | 3055 | kvm = kvm_create_vm(type); |
3053 | if (IS_ERR(kvm)) | 3056 | if (IS_ERR(kvm)) |
@@ -3059,17 +3062,25 @@ static int kvm_dev_ioctl_create_vm(unsigned long type) | |||
3059 | return r; | 3062 | return r; |
3060 | } | 3063 | } |
3061 | #endif | 3064 | #endif |
3062 | r = anon_inode_getfd("kvm-vm", &kvm_vm_fops, kvm, O_RDWR | O_CLOEXEC); | 3065 | r = get_unused_fd_flags(O_CLOEXEC); |
3063 | if (r < 0) { | 3066 | if (r < 0) { |
3064 | kvm_put_kvm(kvm); | 3067 | kvm_put_kvm(kvm); |
3065 | return r; | 3068 | return r; |
3066 | } | 3069 | } |
3070 | file = anon_inode_getfile("kvm-vm", &kvm_vm_fops, kvm, O_RDWR); | ||
3071 | if (IS_ERR(file)) { | ||
3072 | put_unused_fd(r); | ||
3073 | kvm_put_kvm(kvm); | ||
3074 | return PTR_ERR(file); | ||
3075 | } | ||
3067 | 3076 | ||
3068 | if (kvm_create_vm_debugfs(kvm, r) < 0) { | 3077 | if (kvm_create_vm_debugfs(kvm, r) < 0) { |
3069 | kvm_put_kvm(kvm); | 3078 | put_unused_fd(r); |
3079 | fput(file); | ||
3070 | return -ENOMEM; | 3080 | return -ENOMEM; |
3071 | } | 3081 | } |
3072 | 3082 | ||
3083 | fd_install(r, file); | ||
3073 | return r; | 3084 | return r; |
3074 | } | 3085 | } |
3075 | 3086 | ||