All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Jim Mattson <jmattson@google.com>,
	kvm@vger.kernel.org,
	Sean Christopherson <sean.j.christopherson@intel.com>
Cc: Liran Alon <liran.alon@oracle.com>
Subject: Re: [PATCH v2] kvm: vmx: Stop wasting a page for guest_msrs
Date: Wed, 4 Dec 2019 10:31:27 +0100	[thread overview]
Message-ID: <06b78b0c-56f8-ca63-c0f6-2623799c8a80@redhat.com> (raw)
In-Reply-To: <20191204002442.186018-1-jmattson@google.com>

On 04/12/19 01:24, Jim Mattson wrote:
> 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 <jmattson@google.com>
> Reviewed-by: Liran Alon <liran.alon@oracle.com>
> ---
> v1 -> v2:
>   Changed NR_GUEST_MSRS to NR_SHARED_MSRS.
>   Added BUILD_BUG_ON(ARRAY_SIZE(vmx_msr_index) != NR_SHARED_MSRS).
> 
>  arch/x86/kvm/vmx/vmx.c | 12 ++----------
>  arch/x86/kvm/vmx/vmx.h |  8 +++++++-
>  2 files changed, 9 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 1b9ab4166397d..e3394c839dea6 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -6666,7 +6666,6 @@ static void vmx_free_vcpu(struct kvm_vcpu *vcpu)
>  	free_vpid(vmx->vpid);
>  	nested_vmx_free_vcpu(vcpu);
>  	free_loaded_vmcs(vmx->loaded_vmcs);
> -	kfree(vmx->guest_msrs);
>  	kvm_vcpu_uninit(vcpu);
>  	kmem_cache_free(x86_fpu_cache, vmx->vcpu.arch.user_fpu);
>  	kmem_cache_free(x86_fpu_cache, vmx->vcpu.arch.guest_fpu);
> @@ -6723,12 +6722,7 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
>  			goto uninit_vcpu;
>  	}
>  
> -	vmx->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL_ACCOUNT);
> -	BUILD_BUG_ON(ARRAY_SIZE(vmx_msr_index) * sizeof(vmx->guest_msrs[0])
> -		     > PAGE_SIZE);
> -
> -	if (!vmx->guest_msrs)
> -		goto free_pml;
> +	BUILD_BUG_ON(ARRAY_SIZE(vmx_msr_index) != NR_SHARED_MSRS);
>  
>  	for (i = 0; i < ARRAY_SIZE(vmx_msr_index); ++i) {
>  		u32 index = vmx_msr_index[i];
> @@ -6760,7 +6754,7 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
>  
>  	err = alloc_loaded_vmcs(&vmx->vmcs01);
>  	if (err < 0)
> -		goto free_msrs;
> +		goto free_pml;
>  
>  	msr_bitmap = vmx->vmcs01.msr_bitmap;
>  	vmx_disable_intercept_for_msr(msr_bitmap, MSR_IA32_TSC, MSR_TYPE_R);
> @@ -6822,8 +6816,6 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
>  
>  free_vmcs:
>  	free_loaded_vmcs(vmx->loaded_vmcs);
> -free_msrs:
> -	kfree(vmx->guest_msrs);
>  free_pml:
>  	vmx_destroy_pml_buffer(vmx);
>  uninit_vcpu:
> diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
> index 7c1b978b2df44..a4f7f737c5d44 100644
> --- a/arch/x86/kvm/vmx/vmx.h
> +++ b/arch/x86/kvm/vmx/vmx.h
> @@ -22,6 +22,12 @@ extern u32 get_umwait_control_msr(void);
>  
>  #define X2APIC_MSR(r) (APIC_BASE_MSR + ((r) >> 4))
>  
> +#ifdef CONFIG_X86_64
> +#define NR_SHARED_MSRS	7
> +#else
> +#define NR_SHARED_MSRS	4
> +#endif
> +
>  #define NR_LOADSTORE_MSRS 8
>  
>  struct vmx_msrs {
> @@ -206,7 +212,7 @@ struct vcpu_vmx {
>  	u32                   idt_vectoring_info;
>  	ulong                 rflags;
>  
> -	struct shared_msr_entry *guest_msrs;
> +	struct shared_msr_entry guest_msrs[NR_SHARED_MSRS];
>  	int                   nmsrs;
>  	int                   save_nmsrs;
>  	bool                  guest_msrs_ready;
> 

Queued, thanks.

Paolo


      reply	other threads:[~2019-12-04  9:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-04  0:24 [PATCH v2] kvm: vmx: Stop wasting a page for guest_msrs Jim Mattson
2019-12-04  9:31 ` Paolo Bonzini [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=06b78b0c-56f8-ca63-c0f6-2623799c8a80@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=liran.alon@oracle.com \
    --cc=sean.j.christopherson@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.