Skip to content

Commit 7d73710

Browse files
jsmattsonjrbonzini
authored andcommitted
kvm: vmx: Stop wasting a page for guest_msrs
We will never need more guest_msrs than there are indices in vmx_msr_index. Thus, at present, the guest_msrs array will not exceed 168 bytes. Signed-off-by: Jim Mattson <[email protected]> Reviewed-by: Liran Alon <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 433f4ba commit 7d73710

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6674,7 +6674,6 @@ static void vmx_free_vcpu(struct kvm_vcpu *vcpu)
66746674
free_vpid(vmx->vpid);
66756675
nested_vmx_free_vcpu(vcpu);
66766676
free_loaded_vmcs(vmx->loaded_vmcs);
6677-
kfree(vmx->guest_msrs);
66786677
kvm_vcpu_uninit(vcpu);
66796678
kmem_cache_free(x86_fpu_cache, vmx->vcpu.arch.user_fpu);
66806679
kmem_cache_free(x86_fpu_cache, vmx->vcpu.arch.guest_fpu);
@@ -6731,12 +6730,7 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
67316730
goto uninit_vcpu;
67326731
}
67336732

6734-
vmx->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL_ACCOUNT);
6735-
BUILD_BUG_ON(ARRAY_SIZE(vmx_msr_index) * sizeof(vmx->guest_msrs[0])
6736-
> PAGE_SIZE);
6737-
6738-
if (!vmx->guest_msrs)
6739-
goto free_pml;
6733+
BUILD_BUG_ON(ARRAY_SIZE(vmx_msr_index) != NR_SHARED_MSRS);
67406734

67416735
for (i = 0; i < ARRAY_SIZE(vmx_msr_index); ++i) {
67426736
u32 index = vmx_msr_index[i];
@@ -6768,7 +6762,7 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
67686762

67696763
err = alloc_loaded_vmcs(&vmx->vmcs01);
67706764
if (err < 0)
6771-
goto free_msrs;
6765+
goto free_pml;
67726766

67736767
msr_bitmap = vmx->vmcs01.msr_bitmap;
67746768
vmx_disable_intercept_for_msr(msr_bitmap, MSR_IA32_TSC, MSR_TYPE_R);
@@ -6830,8 +6824,6 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
68306824

68316825
free_vmcs:
68326826
free_loaded_vmcs(vmx->loaded_vmcs);
6833-
free_msrs:
6834-
kfree(vmx->guest_msrs);
68356827
free_pml:
68366828
vmx_destroy_pml_buffer(vmx);
68376829
uninit_vcpu:

arch/x86/kvm/vmx/vmx.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ extern u32 get_umwait_control_msr(void);
2222

2323
#define X2APIC_MSR(r) (APIC_BASE_MSR + ((r) >> 4))
2424

25+
#ifdef CONFIG_X86_64
26+
#define NR_SHARED_MSRS 7
27+
#else
28+
#define NR_SHARED_MSRS 4
29+
#endif
30+
2531
#define NR_LOADSTORE_MSRS 8
2632

2733
struct vmx_msrs {
@@ -206,7 +212,7 @@ struct vcpu_vmx {
206212
u32 idt_vectoring_info;
207213
ulong rflags;
208214

209-
struct shared_msr_entry *guest_msrs;
215+
struct shared_msr_entry guest_msrs[NR_SHARED_MSRS];
210216
int nmsrs;
211217
int save_nmsrs;
212218
bool guest_msrs_ready;

0 commit comments

Comments
 (0)