diff options
Diffstat (limited to 'arch/x86/kvm/svm.c')
-rw-r--r-- | arch/x86/kvm/svm.c | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 944cc9c04b3c..6c79a14a3b6f 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c | |||
@@ -319,7 +319,7 @@ static void svm_hardware_disable(void *garbage) | |||
319 | static void svm_hardware_enable(void *garbage) | 319 | static void svm_hardware_enable(void *garbage) |
320 | { | 320 | { |
321 | 321 | ||
322 | struct svm_cpu_data *svm_data; | 322 | struct svm_cpu_data *sd; |
323 | uint64_t efer; | 323 | uint64_t efer; |
324 | struct descriptor_table gdt_descr; | 324 | struct descriptor_table gdt_descr; |
325 | struct desc_struct *gdt; | 325 | struct desc_struct *gdt; |
@@ -329,62 +329,61 @@ static void svm_hardware_enable(void *garbage) | |||
329 | printk(KERN_ERR "svm_cpu_init: err EOPNOTSUPP on %d\n", me); | 329 | printk(KERN_ERR "svm_cpu_init: err EOPNOTSUPP on %d\n", me); |
330 | return; | 330 | return; |
331 | } | 331 | } |
332 | svm_data = per_cpu(svm_data, me); | 332 | sd = per_cpu(svm_data, me); |
333 | 333 | ||
334 | if (!svm_data) { | 334 | if (!sd) { |
335 | printk(KERN_ERR "svm_cpu_init: svm_data is NULL on %d\n", | 335 | printk(KERN_ERR "svm_cpu_init: svm_data is NULL on %d\n", |
336 | me); | 336 | me); |
337 | return; | 337 | return; |
338 | } | 338 | } |
339 | 339 | ||
340 | svm_data->asid_generation = 1; | 340 | sd->asid_generation = 1; |
341 | svm_data->max_asid = cpuid_ebx(SVM_CPUID_FUNC) - 1; | 341 | sd->max_asid = cpuid_ebx(SVM_CPUID_FUNC) - 1; |
342 | svm_data->next_asid = svm_data->max_asid + 1; | 342 | sd->next_asid = sd->max_asid + 1; |
343 | 343 | ||
344 | kvm_get_gdt(&gdt_descr); | 344 | kvm_get_gdt(&gdt_descr); |
345 | gdt = (struct desc_struct *)gdt_descr.base; | 345 | gdt = (struct desc_struct *)gdt_descr.base; |
346 | svm_data->tss_desc = (struct kvm_ldttss_desc *)(gdt + GDT_ENTRY_TSS); | 346 | sd->tss_desc = (struct kvm_ldttss_desc *)(gdt + GDT_ENTRY_TSS); |
347 | 347 | ||
348 | rdmsrl(MSR_EFER, efer); | 348 | rdmsrl(MSR_EFER, efer); |
349 | wrmsrl(MSR_EFER, efer | EFER_SVME); | 349 | wrmsrl(MSR_EFER, efer | EFER_SVME); |
350 | 350 | ||
351 | wrmsrl(MSR_VM_HSAVE_PA, | 351 | wrmsrl(MSR_VM_HSAVE_PA, |
352 | page_to_pfn(svm_data->save_area) << PAGE_SHIFT); | 352 | page_to_pfn(sd->save_area) << PAGE_SHIFT); |
353 | } | 353 | } |
354 | 354 | ||
355 | static void svm_cpu_uninit(int cpu) | 355 | static void svm_cpu_uninit(int cpu) |
356 | { | 356 | { |
357 | struct svm_cpu_data *svm_data | 357 | struct svm_cpu_data *sd = per_cpu(svm_data, raw_smp_processor_id()); |
358 | = per_cpu(svm_data, raw_smp_processor_id()); | ||
359 | 358 | ||
360 | if (!svm_data) | 359 | if (!sd) |
361 | return; | 360 | return; |
362 | 361 | ||
363 | per_cpu(svm_data, raw_smp_processor_id()) = NULL; | 362 | per_cpu(svm_data, raw_smp_processor_id()) = NULL; |
364 | __free_page(svm_data->save_area); | 363 | __free_page(sd->save_area); |
365 | kfree(svm_data); | 364 | kfree(sd); |
366 | } | 365 | } |
367 | 366 | ||
368 | static int svm_cpu_init(int cpu) | 367 | static int svm_cpu_init(int cpu) |
369 | { | 368 | { |
370 | struct svm_cpu_data *svm_data; | 369 | struct svm_cpu_data *sd; |
371 | int r; | 370 | int r; |
372 | 371 | ||
373 | svm_data = kzalloc(sizeof(struct svm_cpu_data), GFP_KERNEL); | 372 | sd = kzalloc(sizeof(struct svm_cpu_data), GFP_KERNEL); |
374 | if (!svm_data) | 373 | if (!sd) |
375 | return -ENOMEM; | 374 | return -ENOMEM; |
376 | svm_data->cpu = cpu; | 375 | sd->cpu = cpu; |
377 | svm_data->save_area = alloc_page(GFP_KERNEL); | 376 | sd->save_area = alloc_page(GFP_KERNEL); |
378 | r = -ENOMEM; | 377 | r = -ENOMEM; |
379 | if (!svm_data->save_area) | 378 | if (!sd->save_area) |
380 | goto err_1; | 379 | goto err_1; |
381 | 380 | ||
382 | per_cpu(svm_data, cpu) = svm_data; | 381 | per_cpu(svm_data, cpu) = sd; |
383 | 382 | ||
384 | return 0; | 383 | return 0; |
385 | 384 | ||
386 | err_1: | 385 | err_1: |
387 | kfree(svm_data); | 386 | kfree(sd); |
388 | return r; | 387 | return r; |
389 | 388 | ||
390 | } | 389 | } |
@@ -1094,16 +1093,16 @@ static void save_host_msrs(struct kvm_vcpu *vcpu) | |||
1094 | #endif | 1093 | #endif |
1095 | } | 1094 | } |
1096 | 1095 | ||
1097 | static void new_asid(struct vcpu_svm *svm, struct svm_cpu_data *svm_data) | 1096 | static void new_asid(struct vcpu_svm *svm, struct svm_cpu_data *sd) |
1098 | { | 1097 | { |
1099 | if (svm_data->next_asid > svm_data->max_asid) { | 1098 | if (sd->next_asid > sd->max_asid) { |
1100 | ++svm_data->asid_generation; | 1099 | ++sd->asid_generation; |
1101 | svm_data->next_asid = 1; | 1100 | sd->next_asid = 1; |
1102 | svm->vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ALL_ASID; | 1101 | svm->vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ALL_ASID; |
1103 | } | 1102 | } |
1104 | 1103 | ||
1105 | svm->asid_generation = svm_data->asid_generation; | 1104 | svm->asid_generation = sd->asid_generation; |
1106 | svm->vmcb->control.asid = svm_data->next_asid++; | 1105 | svm->vmcb->control.asid = sd->next_asid++; |
1107 | } | 1106 | } |
1108 | 1107 | ||
1109 | static unsigned long svm_get_dr(struct kvm_vcpu *vcpu, int dr) | 1108 | static unsigned long svm_get_dr(struct kvm_vcpu *vcpu, int dr) |
@@ -2377,8 +2376,8 @@ static void reload_tss(struct kvm_vcpu *vcpu) | |||
2377 | { | 2376 | { |
2378 | int cpu = raw_smp_processor_id(); | 2377 | int cpu = raw_smp_processor_id(); |
2379 | 2378 | ||
2380 | struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu); | 2379 | struct svm_cpu_data *sd = per_cpu(svm_data, cpu); |
2381 | svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */ | 2380 | sd->tss_desc->type = 9; /* available 32/64-bit TSS */ |
2382 | load_TR_desc(); | 2381 | load_TR_desc(); |
2383 | } | 2382 | } |
2384 | 2383 | ||
@@ -2386,12 +2385,12 @@ static void pre_svm_run(struct vcpu_svm *svm) | |||
2386 | { | 2385 | { |
2387 | int cpu = raw_smp_processor_id(); | 2386 | int cpu = raw_smp_processor_id(); |
2388 | 2387 | ||
2389 | struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu); | 2388 | struct svm_cpu_data *sd = per_cpu(svm_data, cpu); |
2390 | 2389 | ||
2391 | svm->vmcb->control.tlb_ctl = TLB_CONTROL_DO_NOTHING; | 2390 | svm->vmcb->control.tlb_ctl = TLB_CONTROL_DO_NOTHING; |
2392 | /* FIXME: handle wraparound of asid_generation */ | 2391 | /* FIXME: handle wraparound of asid_generation */ |
2393 | if (svm->asid_generation != svm_data->asid_generation) | 2392 | if (svm->asid_generation != sd->asid_generation) |
2394 | new_asid(svm, svm_data); | 2393 | new_asid(svm, sd); |
2395 | } | 2394 | } |
2396 | 2395 | ||
2397 | static void svm_inject_nmi(struct kvm_vcpu *vcpu) | 2396 | static void svm_inject_nmi(struct kvm_vcpu *vcpu) |