aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
authorAbel Gordon <abelg@il.ibm.com>2013-04-18 07:35:55 -0400
committerGleb Natapov <gleb@redhat.com>2013-04-22 03:51:34 -0400
commit4607c2d7a2ee90707de2b3b37e4d9156e05cdf29 (patch)
tree48220aa0ebca91a5f2c7ab0a4d6b2b9044684b23 /arch/x86
parentabc4fc58c5ba1a794092bcd97fdb1680b0b3398d (diff)
KVM: nVMX: Introduce vmread and vmwrite bitmaps
Prepare vmread and vmwrite bitmaps according to a pre-specified list of fields. These lists are intended to specifiy most frequent accessed fields so we can minimize the number of fields that are copied from/to the software controlled VMCS12 format to/from to processor-specific shadow vmcs. The lists were built measuring the VMCS fields access rate after L2 Ubuntu 12.04 booted when it was running on top of L1 KVM, also Ubuntu 12.04. Note that during boot there were additional fields which were frequently modified but they were not added to these lists because after boot these fields were not longer accessed by L1. Signed-off-by: Abel Gordon <abelg@il.ibm.com> Reviewed-by: Orit Wasserman <owasserm@redhat.com> Signed-off-by: Gleb Natapov <gleb@redhat.com>
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/kvm/vmx.c90
1 files changed, 89 insertions, 1 deletions
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 7042b6921961..7dc599630430 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -484,6 +484,64 @@ static inline struct vcpu_vmx *to_vmx(struct kvm_vcpu *vcpu)
484#define FIELD64(number, name) [number] = VMCS12_OFFSET(name), \ 484#define FIELD64(number, name) [number] = VMCS12_OFFSET(name), \
485 [number##_HIGH] = VMCS12_OFFSET(name)+4 485 [number##_HIGH] = VMCS12_OFFSET(name)+4
486 486
487
488static const unsigned long shadow_read_only_fields[] = {
489 /*
490 * We do NOT shadow fields that are modified when L0
491 * traps and emulates any vmx instruction (e.g. VMPTRLD,
492 * VMXON...) executed by L1.
493 * For example, VM_INSTRUCTION_ERROR is read
494 * by L1 if a vmx instruction fails (part of the error path).
495 * Note the code assumes this logic. If for some reason
496 * we start shadowing these fields then we need to
497 * force a shadow sync when L0 emulates vmx instructions
498 * (e.g. force a sync if VM_INSTRUCTION_ERROR is modified
499 * by nested_vmx_failValid)
500 */
501 VM_EXIT_REASON,
502 VM_EXIT_INTR_INFO,
503 VM_EXIT_INSTRUCTION_LEN,
504 IDT_VECTORING_INFO_FIELD,
505 IDT_VECTORING_ERROR_CODE,
506 VM_EXIT_INTR_ERROR_CODE,
507 EXIT_QUALIFICATION,
508 GUEST_LINEAR_ADDRESS,
509 GUEST_PHYSICAL_ADDRESS
510};
511static const int max_shadow_read_only_fields =
512 ARRAY_SIZE(shadow_read_only_fields);
513
514static const unsigned long shadow_read_write_fields[] = {
515 GUEST_RIP,
516 GUEST_RSP,
517 GUEST_CR0,
518 GUEST_CR3,
519 GUEST_CR4,
520 GUEST_INTERRUPTIBILITY_INFO,
521 GUEST_RFLAGS,
522 GUEST_CS_SELECTOR,
523 GUEST_CS_AR_BYTES,
524 GUEST_CS_LIMIT,
525 GUEST_CS_BASE,
526 GUEST_ES_BASE,
527 CR0_GUEST_HOST_MASK,
528 CR0_READ_SHADOW,
529 CR4_READ_SHADOW,
530 TSC_OFFSET,
531 EXCEPTION_BITMAP,
532 CPU_BASED_VM_EXEC_CONTROL,
533 VM_ENTRY_EXCEPTION_ERROR_CODE,
534 VM_ENTRY_INTR_INFO_FIELD,
535 VM_ENTRY_INSTRUCTION_LEN,
536 VM_ENTRY_EXCEPTION_ERROR_CODE,
537 HOST_FS_BASE,
538 HOST_GS_BASE,
539 HOST_FS_SELECTOR,
540 HOST_GS_SELECTOR
541};
542static const int max_shadow_read_write_fields =
543 ARRAY_SIZE(shadow_read_write_fields);
544
487static const unsigned short vmcs_field_to_offset_table[] = { 545static const unsigned short vmcs_field_to_offset_table[] = {
488 FIELD(VIRTUAL_PROCESSOR_ID, virtual_processor_id), 546 FIELD(VIRTUAL_PROCESSOR_ID, virtual_processor_id),
489 FIELD(GUEST_ES_SELECTOR, guest_es_selector), 547 FIELD(GUEST_ES_SELECTOR, guest_es_selector),
@@ -675,6 +733,8 @@ static unsigned long *vmx_msr_bitmap_legacy;
675static unsigned long *vmx_msr_bitmap_longmode; 733static unsigned long *vmx_msr_bitmap_longmode;
676static unsigned long *vmx_msr_bitmap_legacy_x2apic; 734static unsigned long *vmx_msr_bitmap_legacy_x2apic;
677static unsigned long *vmx_msr_bitmap_longmode_x2apic; 735static unsigned long *vmx_msr_bitmap_longmode_x2apic;
736static unsigned long *vmx_vmread_bitmap;
737static unsigned long *vmx_vmwrite_bitmap;
678 738
679static bool cpu_has_load_ia32_efer; 739static bool cpu_has_load_ia32_efer;
680static bool cpu_has_load_perf_global_ctrl; 740static bool cpu_has_load_perf_global_ctrl;
@@ -4128,6 +4188,10 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
4128 vmcs_write64(IO_BITMAP_A, __pa(vmx_io_bitmap_a)); 4188 vmcs_write64(IO_BITMAP_A, __pa(vmx_io_bitmap_a));
4129 vmcs_write64(IO_BITMAP_B, __pa(vmx_io_bitmap_b)); 4189 vmcs_write64(IO_BITMAP_B, __pa(vmx_io_bitmap_b));
4130 4190
4191 if (enable_shadow_vmcs) {
4192 vmcs_write64(VMREAD_BITMAP, __pa(vmx_vmread_bitmap));
4193 vmcs_write64(VMWRITE_BITMAP, __pa(vmx_vmwrite_bitmap));
4194 }
4131 if (cpu_has_vmx_msr_bitmap()) 4195 if (cpu_has_vmx_msr_bitmap())
4132 vmcs_write64(MSR_BITMAP, __pa(vmx_msr_bitmap_legacy)); 4196 vmcs_write64(MSR_BITMAP, __pa(vmx_msr_bitmap_legacy));
4133 4197
@@ -7941,6 +8005,24 @@ static int __init vmx_init(void)
7941 (unsigned long *)__get_free_page(GFP_KERNEL); 8005 (unsigned long *)__get_free_page(GFP_KERNEL);
7942 if (!vmx_msr_bitmap_longmode_x2apic) 8006 if (!vmx_msr_bitmap_longmode_x2apic)
7943 goto out4; 8007 goto out4;
8008 vmx_vmread_bitmap = (unsigned long *)__get_free_page(GFP_KERNEL);
8009 if (!vmx_vmread_bitmap)
8010 goto out5;
8011
8012 vmx_vmwrite_bitmap = (unsigned long *)__get_free_page(GFP_KERNEL);
8013 if (!vmx_vmwrite_bitmap)
8014 goto out6;
8015
8016 memset(vmx_vmread_bitmap, 0xff, PAGE_SIZE);
8017 memset(vmx_vmwrite_bitmap, 0xff, PAGE_SIZE);
8018 /* shadowed read/write fields */
8019 for (i = 0; i < max_shadow_read_write_fields; i++) {
8020 clear_bit(shadow_read_write_fields[i], vmx_vmwrite_bitmap);
8021 clear_bit(shadow_read_write_fields[i], vmx_vmread_bitmap);
8022 }
8023 /* shadowed read only fields */
8024 for (i = 0; i < max_shadow_read_only_fields; i++)
8025 clear_bit(shadow_read_only_fields[i], vmx_vmread_bitmap);
7944 8026
7945 /* 8027 /*
7946 * Allow direct access to the PC debug port (it is often used for I/O 8028 * Allow direct access to the PC debug port (it is often used for I/O
@@ -7959,7 +8041,7 @@ static int __init vmx_init(void)
7959 r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx), 8041 r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx),
7960 __alignof__(struct vcpu_vmx), THIS_MODULE); 8042 __alignof__(struct vcpu_vmx), THIS_MODULE);
7961 if (r) 8043 if (r)
7962 goto out5; 8044 goto out7;
7963 8045
7964#ifdef CONFIG_KEXEC 8046#ifdef CONFIG_KEXEC
7965 rcu_assign_pointer(crash_vmclear_loaded_vmcss, 8047 rcu_assign_pointer(crash_vmclear_loaded_vmcss,
@@ -8007,6 +8089,10 @@ static int __init vmx_init(void)
8007 8089
8008 return 0; 8090 return 0;
8009 8091
8092out7:
8093 free_page((unsigned long)vmx_vmwrite_bitmap);
8094out6:
8095 free_page((unsigned long)vmx_vmread_bitmap);
8010out5: 8096out5:
8011 free_page((unsigned long)vmx_msr_bitmap_longmode_x2apic); 8097 free_page((unsigned long)vmx_msr_bitmap_longmode_x2apic);
8012out4: 8098out4:
@@ -8030,6 +8116,8 @@ static void __exit vmx_exit(void)
8030 free_page((unsigned long)vmx_msr_bitmap_longmode); 8116 free_page((unsigned long)vmx_msr_bitmap_longmode);
8031 free_page((unsigned long)vmx_io_bitmap_b); 8117 free_page((unsigned long)vmx_io_bitmap_b);
8032 free_page((unsigned long)vmx_io_bitmap_a); 8118 free_page((unsigned long)vmx_io_bitmap_a);
8119 free_page((unsigned long)vmx_vmwrite_bitmap);
8120 free_page((unsigned long)vmx_vmread_bitmap);
8033 8121
8034#ifdef CONFIG_KEXEC 8122#ifdef CONFIG_KEXEC
8035 rcu_assign_pointer(crash_vmclear_loaded_vmcss, NULL); 8123 rcu_assign_pointer(crash_vmclear_loaded_vmcss, NULL);