diff options
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r-- | arch/x86/kvm/x86.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 9b42673df4af..53bc06a68105 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -1306,15 +1306,15 @@ static int __msr_io(struct kvm_vcpu *vcpu, struct kvm_msrs *msrs, | |||
1306 | int (*do_msr)(struct kvm_vcpu *vcpu, | 1306 | int (*do_msr)(struct kvm_vcpu *vcpu, |
1307 | unsigned index, u64 *data)) | 1307 | unsigned index, u64 *data)) |
1308 | { | 1308 | { |
1309 | int i; | 1309 | int i, idx; |
1310 | 1310 | ||
1311 | vcpu_load(vcpu); | 1311 | vcpu_load(vcpu); |
1312 | 1312 | ||
1313 | down_read(&vcpu->kvm->slots_lock); | 1313 | idx = srcu_read_lock(&vcpu->kvm->srcu); |
1314 | for (i = 0; i < msrs->nmsrs; ++i) | 1314 | for (i = 0; i < msrs->nmsrs; ++i) |
1315 | if (do_msr(vcpu, entries[i].index, &entries[i].data)) | 1315 | if (do_msr(vcpu, entries[i].index, &entries[i].data)) |
1316 | break; | 1316 | break; |
1317 | up_read(&vcpu->kvm->slots_lock); | 1317 | srcu_read_unlock(&vcpu->kvm->srcu, idx); |
1318 | 1318 | ||
1319 | vcpu_put(vcpu); | 1319 | vcpu_put(vcpu); |
1320 | 1320 | ||
@@ -3900,14 +3900,15 @@ static void vapic_enter(struct kvm_vcpu *vcpu) | |||
3900 | static void vapic_exit(struct kvm_vcpu *vcpu) | 3900 | static void vapic_exit(struct kvm_vcpu *vcpu) |
3901 | { | 3901 | { |
3902 | struct kvm_lapic *apic = vcpu->arch.apic; | 3902 | struct kvm_lapic *apic = vcpu->arch.apic; |
3903 | int idx; | ||
3903 | 3904 | ||
3904 | if (!apic || !apic->vapic_addr) | 3905 | if (!apic || !apic->vapic_addr) |
3905 | return; | 3906 | return; |
3906 | 3907 | ||
3907 | down_read(&vcpu->kvm->slots_lock); | 3908 | idx = srcu_read_lock(&vcpu->kvm->srcu); |
3908 | kvm_release_page_dirty(apic->vapic_page); | 3909 | kvm_release_page_dirty(apic->vapic_page); |
3909 | mark_page_dirty(vcpu->kvm, apic->vapic_addr >> PAGE_SHIFT); | 3910 | mark_page_dirty(vcpu->kvm, apic->vapic_addr >> PAGE_SHIFT); |
3910 | up_read(&vcpu->kvm->slots_lock); | 3911 | srcu_read_unlock(&vcpu->kvm->srcu, idx); |
3911 | } | 3912 | } |
3912 | 3913 | ||
3913 | static void update_cr8_intercept(struct kvm_vcpu *vcpu) | 3914 | static void update_cr8_intercept(struct kvm_vcpu *vcpu) |
@@ -4036,7 +4037,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) | |||
4036 | kvm_lapic_sync_to_vapic(vcpu); | 4037 | kvm_lapic_sync_to_vapic(vcpu); |
4037 | } | 4038 | } |
4038 | 4039 | ||
4039 | up_read(&vcpu->kvm->slots_lock); | 4040 | srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); |
4040 | 4041 | ||
4041 | kvm_guest_enter(); | 4042 | kvm_guest_enter(); |
4042 | 4043 | ||
@@ -4078,7 +4079,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) | |||
4078 | 4079 | ||
4079 | preempt_enable(); | 4080 | preempt_enable(); |
4080 | 4081 | ||
4081 | down_read(&vcpu->kvm->slots_lock); | 4082 | vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); |
4082 | 4083 | ||
4083 | /* | 4084 | /* |
4084 | * Profile KVM exit RIPs: | 4085 | * Profile KVM exit RIPs: |
@@ -4100,6 +4101,7 @@ out: | |||
4100 | static int __vcpu_run(struct kvm_vcpu *vcpu) | 4101 | static int __vcpu_run(struct kvm_vcpu *vcpu) |
4101 | { | 4102 | { |
4102 | int r; | 4103 | int r; |
4104 | struct kvm *kvm = vcpu->kvm; | ||
4103 | 4105 | ||
4104 | if (unlikely(vcpu->arch.mp_state == KVM_MP_STATE_SIPI_RECEIVED)) { | 4106 | if (unlikely(vcpu->arch.mp_state == KVM_MP_STATE_SIPI_RECEIVED)) { |
4105 | pr_debug("vcpu %d received sipi with vector # %x\n", | 4107 | pr_debug("vcpu %d received sipi with vector # %x\n", |
@@ -4111,7 +4113,7 @@ static int __vcpu_run(struct kvm_vcpu *vcpu) | |||
4111 | vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; | 4113 | vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; |
4112 | } | 4114 | } |
4113 | 4115 | ||
4114 | down_read(&vcpu->kvm->slots_lock); | 4116 | vcpu->srcu_idx = srcu_read_lock(&kvm->srcu); |
4115 | vapic_enter(vcpu); | 4117 | vapic_enter(vcpu); |
4116 | 4118 | ||
4117 | r = 1; | 4119 | r = 1; |
@@ -4119,9 +4121,9 @@ static int __vcpu_run(struct kvm_vcpu *vcpu) | |||
4119 | if (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE) | 4121 | if (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE) |
4120 | r = vcpu_enter_guest(vcpu); | 4122 | r = vcpu_enter_guest(vcpu); |
4121 | else { | 4123 | else { |
4122 | up_read(&vcpu->kvm->slots_lock); | 4124 | srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx); |
4123 | kvm_vcpu_block(vcpu); | 4125 | kvm_vcpu_block(vcpu); |
4124 | down_read(&vcpu->kvm->slots_lock); | 4126 | vcpu->srcu_idx = srcu_read_lock(&kvm->srcu); |
4125 | if (test_and_clear_bit(KVM_REQ_UNHALT, &vcpu->requests)) | 4127 | if (test_and_clear_bit(KVM_REQ_UNHALT, &vcpu->requests)) |
4126 | { | 4128 | { |
4127 | switch(vcpu->arch.mp_state) { | 4129 | switch(vcpu->arch.mp_state) { |
@@ -4156,13 +4158,13 @@ static int __vcpu_run(struct kvm_vcpu *vcpu) | |||
4156 | ++vcpu->stat.signal_exits; | 4158 | ++vcpu->stat.signal_exits; |
4157 | } | 4159 | } |
4158 | if (need_resched()) { | 4160 | if (need_resched()) { |
4159 | up_read(&vcpu->kvm->slots_lock); | 4161 | srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx); |
4160 | kvm_resched(vcpu); | 4162 | kvm_resched(vcpu); |
4161 | down_read(&vcpu->kvm->slots_lock); | 4163 | vcpu->srcu_idx = srcu_read_lock(&kvm->srcu); |
4162 | } | 4164 | } |
4163 | } | 4165 | } |
4164 | 4166 | ||
4165 | up_read(&vcpu->kvm->slots_lock); | 4167 | srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx); |
4166 | post_kvm_run_save(vcpu); | 4168 | post_kvm_run_save(vcpu); |
4167 | 4169 | ||
4168 | vapic_exit(vcpu); | 4170 | vapic_exit(vcpu); |
@@ -4201,10 +4203,10 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
4201 | vcpu->mmio_read_completed = 1; | 4203 | vcpu->mmio_read_completed = 1; |
4202 | vcpu->mmio_needed = 0; | 4204 | vcpu->mmio_needed = 0; |
4203 | 4205 | ||
4204 | down_read(&vcpu->kvm->slots_lock); | 4206 | vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); |
4205 | r = emulate_instruction(vcpu, vcpu->arch.mmio_fault_cr2, 0, | 4207 | r = emulate_instruction(vcpu, vcpu->arch.mmio_fault_cr2, 0, |
4206 | EMULTYPE_NO_DECODE); | 4208 | EMULTYPE_NO_DECODE); |
4207 | up_read(&vcpu->kvm->slots_lock); | 4209 | srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); |
4208 | if (r == EMULATE_DO_MMIO) { | 4210 | if (r == EMULATE_DO_MMIO) { |
4209 | /* | 4211 | /* |
4210 | * Read-modify-write. Back to userspace. | 4212 | * Read-modify-write. Back to userspace. |
@@ -4967,11 +4969,12 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, | |||
4967 | { | 4969 | { |
4968 | unsigned long vaddr = tr->linear_address; | 4970 | unsigned long vaddr = tr->linear_address; |
4969 | gpa_t gpa; | 4971 | gpa_t gpa; |
4972 | int idx; | ||
4970 | 4973 | ||
4971 | vcpu_load(vcpu); | 4974 | vcpu_load(vcpu); |
4972 | down_read(&vcpu->kvm->slots_lock); | 4975 | idx = srcu_read_lock(&vcpu->kvm->srcu); |
4973 | gpa = vcpu->arch.mmu.gva_to_gpa(vcpu, vaddr); | 4976 | gpa = vcpu->arch.mmu.gva_to_gpa(vcpu, vaddr); |
4974 | up_read(&vcpu->kvm->slots_lock); | 4977 | srcu_read_unlock(&vcpu->kvm->srcu, idx); |
4975 | tr->physical_address = gpa; | 4978 | tr->physical_address = gpa; |
4976 | tr->valid = gpa != UNMAPPED_GVA; | 4979 | tr->valid = gpa != UNMAPPED_GVA; |
4977 | tr->writeable = 1; | 4980 | tr->writeable = 1; |
@@ -5223,11 +5226,13 @@ fail: | |||
5223 | 5226 | ||
5224 | void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) | 5227 | void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) |
5225 | { | 5228 | { |
5229 | int idx; | ||
5230 | |||
5226 | kfree(vcpu->arch.mce_banks); | 5231 | kfree(vcpu->arch.mce_banks); |
5227 | kvm_free_lapic(vcpu); | 5232 | kvm_free_lapic(vcpu); |
5228 | down_read(&vcpu->kvm->slots_lock); | 5233 | idx = srcu_read_lock(&vcpu->kvm->srcu); |
5229 | kvm_mmu_destroy(vcpu); | 5234 | kvm_mmu_destroy(vcpu); |
5230 | up_read(&vcpu->kvm->slots_lock); | 5235 | srcu_read_unlock(&vcpu->kvm->srcu, idx); |
5231 | free_page((unsigned long)vcpu->arch.pio_data); | 5236 | free_page((unsigned long)vcpu->arch.pio_data); |
5232 | } | 5237 | } |
5233 | 5238 | ||