@@ -3829,11 +3829,6 @@ static struct vmcs *alloc_vmcs_cpu(int cpu)
3829
3829
return vmcs ;
3830
3830
}
3831
3831
3832
- static struct vmcs * alloc_vmcs (void )
3833
- {
3834
- return alloc_vmcs_cpu (raw_smp_processor_id ());
3835
- }
3836
-
3837
3832
static void free_vmcs (struct vmcs * vmcs )
3838
3833
{
3839
3834
free_pages ((unsigned long )vmcs , vmcs_config .order );
@@ -3852,6 +3847,22 @@ static void free_loaded_vmcs(struct loaded_vmcs *loaded_vmcs)
3852
3847
WARN_ON (loaded_vmcs -> shadow_vmcs != NULL );
3853
3848
}
3854
3849
3850
+ static struct vmcs * alloc_vmcs (void )
3851
+ {
3852
+ return alloc_vmcs_cpu (raw_smp_processor_id ());
3853
+ }
3854
+
3855
+ static int alloc_loaded_vmcs (struct loaded_vmcs * loaded_vmcs )
3856
+ {
3857
+ loaded_vmcs -> vmcs = alloc_vmcs ();
3858
+ if (!loaded_vmcs -> vmcs )
3859
+ return - ENOMEM ;
3860
+
3861
+ loaded_vmcs -> shadow_vmcs = NULL ;
3862
+ loaded_vmcs_init (loaded_vmcs );
3863
+ return 0 ;
3864
+ }
3865
+
3855
3866
static void free_kvm_area (void )
3856
3867
{
3857
3868
int cpu ;
@@ -7145,12 +7156,11 @@ static int enter_vmx_operation(struct kvm_vcpu *vcpu)
7145
7156
{
7146
7157
struct vcpu_vmx * vmx = to_vmx (vcpu );
7147
7158
struct vmcs * shadow_vmcs ;
7159
+ int r ;
7148
7160
7149
- vmx -> nested .vmcs02 .vmcs = alloc_vmcs ();
7150
- vmx -> nested .vmcs02 .shadow_vmcs = NULL ;
7151
- if (!vmx -> nested .vmcs02 .vmcs )
7161
+ r = alloc_loaded_vmcs (& vmx -> nested .vmcs02 );
7162
+ if (r < 0 )
7152
7163
goto out_vmcs02 ;
7153
- loaded_vmcs_init (& vmx -> nested .vmcs02 );
7154
7164
7155
7165
if (cpu_has_vmx_msr_bitmap ()) {
7156
7166
vmx -> nested .msr_bitmap =
@@ -9545,13 +9555,11 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
9545
9555
if (!vmx -> guest_msrs )
9546
9556
goto free_pml ;
9547
9557
9548
- vmx -> loaded_vmcs = & vmx -> vmcs01 ;
9549
- vmx -> loaded_vmcs -> vmcs = alloc_vmcs ();
9550
- vmx -> loaded_vmcs -> shadow_vmcs = NULL ;
9551
- if (!vmx -> loaded_vmcs -> vmcs )
9558
+ err = alloc_loaded_vmcs (& vmx -> vmcs01 );
9559
+ if (err < 0 )
9552
9560
goto free_msrs ;
9553
- loaded_vmcs_init (vmx -> loaded_vmcs );
9554
9561
9562
+ vmx -> loaded_vmcs = & vmx -> vmcs01 ;
9555
9563
cpu = get_cpu ();
9556
9564
vmx_vcpu_load (& vmx -> vcpu , cpu );
9557
9565
vmx -> vcpu .cpu = cpu ;
0 commit comments