Skip to content

Commit f21f165

Browse files
committed
KVM: VMX: introduce alloc_loaded_vmcs
Group together the calls to alloc_vmcs and loaded_vmcs_init. Soon we'll also allocate an MSR bitmap there. Cc: [email protected] # prereq for Spectre mitigation Signed-off-by: Paolo Bonzini <[email protected]>
1 parent de3a002 commit f21f165

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

arch/x86/kvm/vmx.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,11 +3829,6 @@ static struct vmcs *alloc_vmcs_cpu(int cpu)
38293829
return vmcs;
38303830
}
38313831

3832-
static struct vmcs *alloc_vmcs(void)
3833-
{
3834-
return alloc_vmcs_cpu(raw_smp_processor_id());
3835-
}
3836-
38373832
static void free_vmcs(struct vmcs *vmcs)
38383833
{
38393834
free_pages((unsigned long)vmcs, vmcs_config.order);
@@ -3852,6 +3847,22 @@ static void free_loaded_vmcs(struct loaded_vmcs *loaded_vmcs)
38523847
WARN_ON(loaded_vmcs->shadow_vmcs != NULL);
38533848
}
38543849

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+
38553866
static void free_kvm_area(void)
38563867
{
38573868
int cpu;
@@ -7145,12 +7156,11 @@ static int enter_vmx_operation(struct kvm_vcpu *vcpu)
71457156
{
71467157
struct vcpu_vmx *vmx = to_vmx(vcpu);
71477158
struct vmcs *shadow_vmcs;
7159+
int r;
71487160

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)
71527163
goto out_vmcs02;
7153-
loaded_vmcs_init(&vmx->nested.vmcs02);
71547164

71557165
if (cpu_has_vmx_msr_bitmap()) {
71567166
vmx->nested.msr_bitmap =
@@ -9545,13 +9555,11 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
95459555
if (!vmx->guest_msrs)
95469556
goto free_pml;
95479557

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)
95529560
goto free_msrs;
9553-
loaded_vmcs_init(vmx->loaded_vmcs);
95549561

9562+
vmx->loaded_vmcs = &vmx->vmcs01;
95559563
cpu = get_cpu();
95569564
vmx_vcpu_load(&vmx->vcpu, cpu);
95579565
vmx->vcpu.cpu = cpu;

0 commit comments

Comments
 (0)