@@ -2444,94 +2444,90 @@ static bool valid_ept_address(struct kvm_vcpu *vcpu, u64 address)
2444
2444
return true;
2445
2445
}
2446
2446
2447
- static int nested_vmx_check_vmentry_prereqs (struct kvm_vcpu * vcpu ,
2448
- struct vmcs12 * vmcs12 )
2447
+ /*
2448
+ * Checks related to VM-Execution Control Fields
2449
+ */
2450
+ static int nested_check_vm_execution_controls (struct kvm_vcpu * vcpu ,
2451
+ struct vmcs12 * vmcs12 )
2449
2452
{
2450
2453
struct vcpu_vmx * vmx = to_vmx (vcpu );
2451
- bool ia32e ;
2452
-
2453
- if (vmcs12 -> guest_activity_state != GUEST_ACTIVITY_ACTIVE &&
2454
- vmcs12 -> guest_activity_state != GUEST_ACTIVITY_HLT )
2455
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2456
-
2457
- if (nested_cpu_has_vpid (vmcs12 ) && !vmcs12 -> virtual_processor_id )
2458
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2459
-
2460
- if (nested_vmx_check_io_bitmap_controls (vcpu , vmcs12 ))
2461
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2462
-
2463
- if (nested_vmx_check_msr_bitmap_controls (vcpu , vmcs12 ))
2464
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2465
-
2466
- if (nested_vmx_check_apic_access_controls (vcpu , vmcs12 ))
2467
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2468
-
2469
- if (nested_vmx_check_tpr_shadow_controls (vcpu , vmcs12 ))
2470
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2471
-
2472
- if (nested_vmx_check_apicv_controls (vcpu , vmcs12 ))
2473
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2474
2454
2475
- if (nested_vmx_check_msr_switch_controls (vcpu , vmcs12 ))
2476
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2477
-
2478
- if (!nested_cpu_has_preemption_timer (vmcs12 ) &&
2479
- nested_cpu_has_save_preemption_timer (vmcs12 ))
2480
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2481
-
2482
- if (nested_vmx_check_pml_controls (vcpu , vmcs12 ))
2483
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2484
-
2485
- if (nested_vmx_check_unrestricted_guest_controls (vcpu , vmcs12 ))
2486
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2487
-
2488
- if (nested_vmx_check_mode_based_ept_exec_controls (vcpu , vmcs12 ))
2489
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2490
-
2491
- if (nested_vmx_check_shadow_vmcs_controls (vcpu , vmcs12 ))
2492
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2493
-
2494
- if (!vmx_control_verify (vmcs12 -> cpu_based_vm_exec_control ,
2495
- vmx -> nested .msrs .procbased_ctls_low ,
2496
- vmx -> nested .msrs .procbased_ctls_high ) ||
2497
- (nested_cpu_has (vmcs12 , CPU_BASED_ACTIVATE_SECONDARY_CONTROLS ) &&
2498
- !vmx_control_verify (vmcs12 -> secondary_vm_exec_control ,
2499
- vmx -> nested .msrs .secondary_ctls_low ,
2500
- vmx -> nested .msrs .secondary_ctls_high )) ||
2501
- !vmx_control_verify (vmcs12 -> pin_based_vm_exec_control ,
2455
+ if (!vmx_control_verify (vmcs12 -> pin_based_vm_exec_control ,
2502
2456
vmx -> nested .msrs .pinbased_ctls_low ,
2503
2457
vmx -> nested .msrs .pinbased_ctls_high ) ||
2504
- !vmx_control_verify (vmcs12 -> vm_exit_controls ,
2505
- vmx -> nested .msrs .exit_ctls_low ,
2506
- vmx -> nested .msrs .exit_ctls_high ) ||
2507
- !vmx_control_verify (vmcs12 -> vm_entry_controls ,
2508
- vmx -> nested .msrs .entry_ctls_low ,
2509
- vmx -> nested .msrs .entry_ctls_high ))
2510
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2458
+ !vmx_control_verify (vmcs12 -> cpu_based_vm_exec_control ,
2459
+ vmx -> nested .msrs .procbased_ctls_low ,
2460
+ vmx -> nested .msrs .procbased_ctls_high ))
2461
+ return - EINVAL ;
2511
2462
2512
- if (nested_vmx_check_nmi_controls (vmcs12 ))
2513
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2463
+ if (nested_cpu_has (vmcs12 , CPU_BASED_ACTIVATE_SECONDARY_CONTROLS ) &&
2464
+ !vmx_control_verify (vmcs12 -> secondary_vm_exec_control ,
2465
+ vmx -> nested .msrs .secondary_ctls_low ,
2466
+ vmx -> nested .msrs .secondary_ctls_high ))
2467
+ return - EINVAL ;
2468
+
2469
+ if (vmcs12 -> cr3_target_count > nested_cpu_vmx_misc_cr3_count (vcpu ) ||
2470
+ nested_vmx_check_io_bitmap_controls (vcpu , vmcs12 ) ||
2471
+ nested_vmx_check_msr_bitmap_controls (vcpu , vmcs12 ) ||
2472
+ nested_vmx_check_tpr_shadow_controls (vcpu , vmcs12 ) ||
2473
+ nested_vmx_check_apic_access_controls (vcpu , vmcs12 ) ||
2474
+ nested_vmx_check_apicv_controls (vcpu , vmcs12 ) ||
2475
+ nested_vmx_check_nmi_controls (vmcs12 ) ||
2476
+ nested_vmx_check_pml_controls (vcpu , vmcs12 ) ||
2477
+ nested_vmx_check_unrestricted_guest_controls (vcpu , vmcs12 ) ||
2478
+ nested_vmx_check_mode_based_ept_exec_controls (vcpu , vmcs12 ) ||
2479
+ nested_vmx_check_shadow_vmcs_controls (vcpu , vmcs12 ) ||
2480
+ (nested_cpu_has_vpid (vmcs12 ) && !vmcs12 -> virtual_processor_id ))
2481
+ return - EINVAL ;
2482
+
2483
+ if (nested_cpu_has_ept (vmcs12 ) &&
2484
+ !valid_ept_address (vcpu , vmcs12 -> ept_pointer ))
2485
+ return - EINVAL ;
2514
2486
2515
2487
if (nested_cpu_has_vmfunc (vmcs12 )) {
2516
2488
if (vmcs12 -> vm_function_control &
2517
2489
~vmx -> nested .msrs .vmfunc_controls )
2518
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2490
+ return - EINVAL ;
2519
2491
2520
2492
if (nested_cpu_has_eptp_switching (vmcs12 )) {
2521
2493
if (!nested_cpu_has_ept (vmcs12 ) ||
2522
2494
!page_address_valid (vcpu , vmcs12 -> eptp_list_address ))
2523
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2495
+ return - EINVAL ;
2524
2496
}
2525
2497
}
2526
2498
2527
- if (vmcs12 -> cr3_target_count > nested_cpu_vmx_misc_cr3_count (vcpu ))
2499
+ return 0 ;
2500
+ }
2501
+
2502
+ static int nested_vmx_check_vmentry_prereqs (struct kvm_vcpu * vcpu ,
2503
+ struct vmcs12 * vmcs12 )
2504
+ {
2505
+ struct vcpu_vmx * vmx = to_vmx (vcpu );
2506
+ bool ia32e ;
2507
+
2508
+ if (vmcs12 -> guest_activity_state != GUEST_ACTIVITY_ACTIVE &&
2509
+ vmcs12 -> guest_activity_state != GUEST_ACTIVITY_HLT )
2510
+ return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2511
+
2512
+ if (nested_check_vm_execution_controls (vcpu , vmcs12 ))
2528
2513
return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2529
2514
2515
+ if (nested_vmx_check_msr_switch_controls (vcpu , vmcs12 ))
2516
+ return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2517
+
2530
2518
if (!nested_host_cr0_valid (vcpu , vmcs12 -> host_cr0 ) ||
2531
2519
!nested_host_cr4_valid (vcpu , vmcs12 -> host_cr4 ) ||
2532
2520
!nested_cr3_valid (vcpu , vmcs12 -> host_cr3 ))
2533
2521
return VMXERR_ENTRY_INVALID_HOST_STATE_FIELD ;
2534
2522
2523
+ if (!vmx_control_verify (vmcs12 -> vm_exit_controls ,
2524
+ vmx -> nested .msrs .exit_ctls_low ,
2525
+ vmx -> nested .msrs .exit_ctls_high ) ||
2526
+ !vmx_control_verify (vmcs12 -> vm_entry_controls ,
2527
+ vmx -> nested .msrs .entry_ctls_low ,
2528
+ vmx -> nested .msrs .entry_ctls_high ))
2529
+ return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2530
+
2535
2531
/*
2536
2532
* If the load IA32_EFER VM-exit control is 1, bits reserved in the
2537
2533
* IA32_EFER MSR must be 0 in the field for that register. In addition,
@@ -2603,10 +2599,6 @@ static int nested_vmx_check_vmentry_prereqs(struct kvm_vcpu *vcpu,
2603
2599
}
2604
2600
}
2605
2601
2606
- if (nested_cpu_has_ept (vmcs12 ) &&
2607
- !valid_ept_address (vcpu , vmcs12 -> ept_pointer ))
2608
- return VMXERR_ENTRY_INVALID_CONTROL_FIELD ;
2609
-
2610
2602
return 0 ;
2611
2603
}
2612
2604
@@ -2638,7 +2630,8 @@ static int nested_vmx_check_vmcs_link_ptr(struct kvm_vcpu *vcpu,
2638
2630
}
2639
2631
2640
2632
static int nested_vmx_check_vmentry_postreqs (struct kvm_vcpu * vcpu ,
2641
- struct vmcs12 * vmcs12 , u32 * exit_qual )
2633
+ struct vmcs12 * vmcs12 ,
2634
+ u32 * exit_qual )
2642
2635
{
2643
2636
bool ia32e ;
2644
2637
0 commit comments