From: Marcelo Tosatti <mtosatti@redhat.com>
To: "Nadav Har'El" <nyh@il.ibm.com>
Cc: kvm@vger.kernel.org, gleb@redhat.com, avi@redhat.com
Subject: Re: [PATCH 07/30] nVMX: Introduce vmcs02: VMCS used to run L2
Date: Mon, 16 May 2011 12:30:15 -0300 [thread overview]
Message-ID: <20110516153015.GC3814@amt.cnet> (raw)
In-Reply-To: <201105080818.p488IllC017945@rice.haifa.ibm.com>
On Sun, May 08, 2011 at 11:18:47AM +0300, Nadav Har'El wrote:
> We saw in a previous patch that L1 controls its L2 guest with a vcms12.
> L0 needs to create a real VMCS for running L2. We call that "vmcs02".
> A later patch will contain the code, prepare_vmcs02(), for filling the vmcs02
> fields. This patch only contains code for allocating vmcs02.
>
> In this version, prepare_vmcs02() sets *all* of vmcs02's fields each time we
> enter from L1 to L2, so keeping just one vmcs02 for the vcpu is enough: It can
> be reused even when L1 runs multiple L2 guests. However, in future versions
> we'll probably want to add an optimization where vmcs02 fields that rarely
> change will not be set each time. For that, we may want to keep around several
> vmcs02s of L2 guests that have recently run, so that potentially we could run
> these L2s again more quickly because less vmwrites to vmcs02 will be needed.
>
> This patch adds to each vcpu a vmcs02 pool, vmx->nested.vmcs02_pool,
> which remembers the vmcs02s last used to run up to VMCS02_POOL_SIZE L2s.
> As explained above, in the current version we choose VMCS02_POOL_SIZE=1,
> I.e., one vmcs02 is allocated (and loaded onto the processor), and it is
> reused to enter any L2 guest. In the future, when prepare_vmcs02() is
> optimized not to set all fields every time, VMCS02_POOL_SIZE should be
> increased.
>
> Signed-off-by: Nadav Har'El <nyh@il.ibm.com>
> ---
> arch/x86/kvm/vmx.c | 134 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 134 insertions(+)
>
> --- .before/arch/x86/kvm/vmx.c 2011-05-08 10:43:18.000000000 +0300
> +++ .after/arch/x86/kvm/vmx.c 2011-05-08 10:43:18.000000000 +0300
> @@ -117,6 +117,7 @@ static int ple_window = KVM_VMX_DEFAULT_
> module_param(ple_window, int, S_IRUGO);
>
> #define NR_AUTOLOAD_MSRS 1
> +#define VMCS02_POOL_SIZE 1
>
> struct vmcs {
> u32 revision_id;
> @@ -166,6 +167,30 @@ struct __packed vmcs12 {
> #define VMCS12_SIZE 0x1000
>
> /*
> + * When we temporarily switch a vcpu's VMCS (e.g., stop using an L1's VMCS
> + * while we use L2's VMCS), and we wish to save the previous VMCS, we must also
> + * remember on which CPU it was last loaded (vcpu->cpu), so when we return to
> + * using this VMCS we'll know if we're now running on a different CPU and need
> + * to clear the VMCS on the old CPU, and load it on the new one. Additionally,
> + * we need to remember whether this VMCS was launched (vmx->launched), so when
> + * we return to it we know if to VMLAUNCH or to VMRESUME it (we cannot deduce
> + * this from other state, because it's possible that this VMCS had once been
> + * launched, but has since been cleared after a CPU switch).
> + */
> +struct saved_vmcs {
> + struct vmcs *vmcs;
> + int cpu;
> + int launched;
> +};
> +
> +/* Used to remember the last vmcs02 used for some recently used vmcs12s */
> +struct vmcs02_list {
> + struct list_head list;
> + gpa_t vmcs12_addr;
> + struct saved_vmcs vmcs02;
> +};
> +
> +/*
> * The nested_vmx structure is part of vcpu_vmx, and holds information we need
> * for correct emulation of VMX (i.e., nested VMX) on this vcpu.
> */
> @@ -178,6 +203,10 @@ struct nested_vmx {
> /* The host-usable pointer to the above */
> struct page *current_vmcs12_page;
> struct vmcs12 *current_vmcs12;
> +
> + /* vmcs02_list cache of VMCSs recently used to run L2 guests */
> + struct list_head vmcs02_pool;
> + int vmcs02_num;
> };
>
> struct vcpu_vmx {
> @@ -4155,6 +4184,106 @@ static int handle_invalid_op(struct kvm_
> }
>
> /*
> + * To run an L2 guest, we need a vmcs02 based the L1-specified vmcs12.
> + * We could reuse a single VMCS for all the L2 guests, but we also want the
> + * option to allocate a separate vmcs02 for each separate loaded vmcs12 - this
> + * allows keeping them loaded on the processor, and in the future will allow
> + * optimizations where prepare_vmcs02 doesn't need to set all the fields on
> + * every entry if they never change.
> + * So we keep, in vmx->nested.vmcs02_pool, a cache of size VMCS02_POOL_SIZE
> + * (>=0) with a vmcs02 for each recently loaded vmcs12s, most recent first.
> + *
> + * The following functions allocate and free a vmcs02 in this pool.
> + */
> +
> +static void __nested_free_saved_vmcs(void *arg)
> +{
> + struct saved_vmcs *saved_vmcs = arg;
> +
> + vmcs_clear(saved_vmcs->vmcs);
> + if (per_cpu(current_vmcs, saved_vmcs->cpu) == saved_vmcs->vmcs)
> + per_cpu(current_vmcs, saved_vmcs->cpu) = NULL;
> +}
Should use raw_smp_processor_id instead of saved_vmcs->cpu.
next prev parent reply other threads:[~2011-05-16 17:51 UTC|newest]
Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-08 8:15 [PATCH 0/30] nVMX: Nested VMX, v9 Nadav Har'El
2011-05-08 8:15 ` [PATCH 01/30] nVMX: Add "nested" module option to kvm_intel Nadav Har'El
2011-05-08 8:16 ` [PATCH 02/30] nVMX: Implement VMXON and VMXOFF Nadav Har'El
2011-05-08 8:16 ` [PATCH 03/30] nVMX: Allow setting the VMXE bit in CR4 Nadav Har'El
2011-05-08 8:17 ` [PATCH 04/30] nVMX: Introduce vmcs12: a VMCS structure for L1 Nadav Har'El
2011-05-08 8:17 ` [PATCH 05/30] nVMX: Implement reading and writing of VMX MSRs Nadav Har'El
2011-05-08 8:18 ` [PATCH 06/30] nVMX: Decoding memory operands of VMX instructions Nadav Har'El
2011-05-09 9:47 ` Avi Kivity
2011-05-08 8:18 ` [PATCH 07/30] nVMX: Introduce vmcs02: VMCS used to run L2 Nadav Har'El
2011-05-16 15:30 ` Marcelo Tosatti [this message]
2011-05-16 18:32 ` Nadav Har'El
2011-05-17 13:20 ` Marcelo Tosatti
2011-05-08 8:19 ` [PATCH 08/30] nVMX: Fix local_vcpus_link handling Nadav Har'El
2011-05-08 8:19 ` [PATCH 09/30] nVMX: Add VMCS fields to the vmcs12 Nadav Har'El
2011-05-08 8:20 ` [PATCH 10/30] nVMX: Success/failure of VMX instructions Nadav Har'El
2011-05-08 8:20 ` [PATCH 11/30] nVMX: Implement VMCLEAR Nadav Har'El
2011-05-08 8:21 ` [PATCH 12/30] nVMX: Implement VMPTRLD Nadav Har'El
2011-05-16 14:34 ` Marcelo Tosatti
2011-05-16 18:58 ` Nadav Har'El
2011-05-16 19:09 ` Nadav Har'El
2011-05-08 8:21 ` [PATCH 13/30] nVMX: Implement VMPTRST Nadav Har'El
2011-05-08 8:22 ` [PATCH 14/30] nVMX: Implement VMREAD and VMWRITE Nadav Har'El
2011-05-08 8:22 ` [PATCH 15/30] nVMX: Move host-state field setup to a function Nadav Har'El
2011-05-09 9:56 ` Avi Kivity
2011-05-09 10:40 ` Nadav Har'El
2011-05-08 8:23 ` [PATCH 16/30] nVMX: Move control field setup to functions Nadav Har'El
2011-05-08 8:23 ` [PATCH 17/30] nVMX: Prepare vmcs02 from vmcs01 and vmcs12 Nadav Har'El
2011-05-09 10:12 ` Avi Kivity
2011-05-09 10:27 ` Nadav Har'El
2011-05-09 10:45 ` Avi Kivity
2011-05-08 8:24 ` [PATCH 18/30] nVMX: Implement VMLAUNCH and VMRESUME Nadav Har'El
2011-05-08 8:24 ` [PATCH 19/30] nVMX: No need for handle_vmx_insn function any more Nadav Har'El
2011-05-08 8:25 ` [PATCH 20/30] nVMX: Exiting from L2 to L1 Nadav Har'El
2011-05-09 10:45 ` Avi Kivity
2011-05-08 8:25 ` [PATCH 21/30] nVMX: Deciding if L0 or L1 should handle an L2 exit Nadav Har'El
2011-05-08 8:26 ` [PATCH 22/30] nVMX: Correct handling of interrupt injection Nadav Har'El
2011-05-09 10:57 ` Avi Kivity
2011-05-08 8:27 ` [PATCH 23/30] nVMX: Correct handling of exception injection Nadav Har'El
2011-05-08 8:27 ` [PATCH 24/30] nVMX: Correct handling of idt vectoring info Nadav Har'El
2011-05-09 11:04 ` Avi Kivity
2011-05-08 8:28 ` [PATCH 25/30] nVMX: Handling of CR0 and CR4 modifying instructions Nadav Har'El
2011-05-08 8:28 ` [PATCH 26/30] nVMX: Further fixes for lazy FPU loading Nadav Har'El
2011-05-08 8:29 ` [PATCH 27/30] nVMX: Additional TSC-offset handling Nadav Har'El
2011-05-09 17:27 ` Zachary Amsden
2011-05-08 8:29 ` [PATCH 28/30] nVMX: Add VMX to list of supported cpuid features Nadav Har'El
2011-05-08 8:30 ` [PATCH 29/30] nVMX: Miscellenous small corrections Nadav Har'El
2011-05-08 8:30 ` [PATCH 30/30] nVMX: Documentation Nadav Har'El
2011-05-09 11:18 ` [PATCH 0/30] nVMX: Nested VMX, v9 Avi Kivity
2011-05-09 11:37 ` Nadav Har'El
2011-05-11 8:20 ` Gleb Natapov
2011-05-12 15:42 ` Nadav Har'El
2011-05-12 15:57 ` Gleb Natapov
2011-05-12 16:08 ` Avi Kivity
2011-05-12 16:14 ` Gleb Natapov
2011-05-12 16:31 ` Nadav Har'El
2011-05-12 16:51 ` Gleb Natapov
2011-05-12 17:00 ` Avi Kivity
2011-05-15 23:11 ` Nadav Har'El
2011-05-16 6:38 ` Gleb Natapov
2011-05-16 7:44 ` Nadav Har'El
2011-05-16 7:57 ` Gleb Natapov
2011-05-16 9:50 ` Avi Kivity
2011-05-16 10:20 ` Avi Kivity
2011-05-22 19:32 ` Nadav Har'El
2011-05-23 9:37 ` Joerg Roedel
2011-05-23 9:52 ` Avi Kivity
2011-05-23 13:02 ` Joerg Roedel
2011-05-23 13:08 ` Avi Kivity
2011-05-23 13:40 ` Joerg Roedel
2011-05-23 13:52 ` Avi Kivity
2011-05-23 14:10 ` Nadav Har'El
2011-05-23 14:32 ` Avi Kivity
2011-05-23 14:44 ` Nadav Har'El
2011-05-23 15:23 ` Avi Kivity
2011-05-23 18:06 ` Alexander Graf
2011-05-24 11:09 ` Avi Kivity
2011-05-24 13:07 ` Joerg Roedel
2011-05-23 14:28 ` Joerg Roedel
2011-05-23 14:34 ` Avi Kivity
2011-05-23 14:58 ` Joerg Roedel
2011-05-23 15:19 ` Avi Kivity
2011-05-23 13:18 ` Nadav Har'El
2011-05-12 16:18 ` Avi Kivity
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=20110516153015.GC3814@amt.cnet \
--to=mtosatti@redhat.com \
--cc=avi@redhat.com \
--cc=gleb@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=nyh@il.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).