From: Jim Mattson <jmattson@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kvm list <kvm@vger.kernel.org>
Subject: Re: [PATCH 2/4] KVM: nVMX: track dirty state of non-shadowed VMCS fields
Date: Thu, 21 Dec 2017 14:57:08 -0800 [thread overview]
Message-ID: <CALMp9eRHcho6LPQZ903EduMjLQF3Xd2AB7eWwVJCFSVi+8pzew@mail.gmail.com> (raw)
In-Reply-To: <1513860222-40944-3-git-send-email-pbonzini@redhat.com>
Reviewed-by: Jim Mattson <jmattson@google.com>
On Thu, Dec 21, 2017 at 4:43 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> VMCS12 fields that are not handled through shadow VMCS are rarely
> written, and thus they are also almost constant in the vmcs02. We can
> thus optimize prepare_vmcs02 by skipping all the work for non-shadowed
> fields in the common case.
>
> This patch introduces the (pretty simple) tracking infrastructure; the
> next patches will move work to prepare_vmcs02_full and save a few hundred
> clock cycles per VMRESUME on a Haswell Xeon E5 system:
>
> before after
> cpuid 14159 13869
> vmcall 15290 14951
> inl_from_kernel 17703 17447
> outl_to_kernel 16011 14692
> self_ipi_sti_nop 16763 15825
> self_ipi_tpr_sti_nop 17341 15935
> wr_tsc_adjust_msr 14510 14264
> rd_tsc_adjust_msr 15018 14311
> mmio-wildcard-eventfd:pci-mem 16381 14947
> mmio-datamatch-eventfd:pci-mem 18620 17858
> portio-wildcard-eventfd:pci-io 15121 14769
> portio-datamatch-eventfd:pci-io 15761 14831
>
> (average savings 748, stdev 460).
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> arch/x86/kvm/vmx.c | 29 ++++++++++++++++++++++++++++-
> 1 file changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 2ee842990976..8b6013b529b3 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -441,6 +441,7 @@ struct nested_vmx {
> * data hold by vmcs12
> */
> bool sync_shadow_vmcs;
> + bool dirty_vmcs12;
>
> bool change_vmcs01_virtual_x2apic_mode;
> /* L2 must run next, and mustn't decide to exit to L1. */
> @@ -7879,8 +7880,10 @@ static int handle_vmwrite(struct kvm_vcpu *vcpu)
> {
> unsigned long field;
> gva_t gva;
> + struct vcpu_vmx *vmx = to_vmx(vcpu);
> unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
> u32 vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO);
> +
> /* The value to write might be 32 or 64 bits, depending on L1's long
> * mode, and eventually we need to write that into a field of several
> * possible lengths. The code below first zero-extends the value to 64
> @@ -7923,6 +7926,20 @@ static int handle_vmwrite(struct kvm_vcpu *vcpu)
> return kvm_skip_emulated_instruction(vcpu);
> }
>
> + switch (field) {
> +#define SHADOW_FIELD_RW(x) case x:
> +#include "vmx_shadow_fields.h"
> + /*
> + * The fields that can be updated by L1 without a vmexit are
> + * always updated in the vmcs02, the others go down the slow
> + * path of prepare_vmcs02.
> + */
> + break;
> + default:
> + vmx->nested.dirty_vmcs12 = true;
> + break;
> + }
> +
> nested_vmx_succeed(vcpu);
> return kvm_skip_emulated_instruction(vcpu);
> }
> @@ -7937,6 +7954,7 @@ static void set_current_vmptr(struct vcpu_vmx *vmx, gpa_t vmptr)
> __pa(vmx->vmcs01.shadow_vmcs));
> vmx->nested.sync_shadow_vmcs = true;
> }
> + vmx->nested.dirty_vmcs12 = true;
> }
>
> /* Emulate the VMPTRLD instruction */
> @@ -10569,6 +10587,11 @@ static int nested_vmx_load_cr3(struct kvm_vcpu *vcpu, unsigned long cr3, bool ne
> return 0;
> }
>
> +static void prepare_vmcs02_full(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
> + bool from_vmentry)
> +{
> +}
> +
> /*
> * prepare_vmcs02 is called when the L1 guest hypervisor runs its nested
> * L2 guest. L1 has a vmcs for L2 (vmcs12), and this function "merges" it
> @@ -10864,7 +10887,6 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
> vmcs_write16(VIRTUAL_PROCESSOR_ID, vmx->vpid);
> vmx_flush_tlb(vcpu, true);
> }
> -
> }
>
> if (enable_pml) {
> @@ -10913,6 +10935,11 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
> /* Note: modifies VM_ENTRY/EXIT_CONTROLS and GUEST/HOST_IA32_EFER */
> vmx_set_efer(vcpu, vcpu->arch.efer);
>
> + if (vmx->nested.dirty_vmcs12) {
> + prepare_vmcs02_full(vcpu, vmcs12, from_vmentry);
> + vmx->nested.dirty_vmcs12 = false;
> + }
> +
> /* Shadow page tables on either EPT or shadow page tables. */
> if (nested_vmx_load_cr3(vcpu, vmcs12->guest_cr3, nested_cpu_has_ept(vmcs12),
> entry_failure_code))
> --
> 1.8.3.1
>
>
next prev parent reply other threads:[~2017-12-21 22:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-21 12:43 [PATCH 0/4] KVM: nVMX: prepare_vmcs02 optimizations Paolo Bonzini
2017-12-21 12:43 ` [PATCH 1/4] KVM: VMX: split list of shadowed VMCS field to a separate file Paolo Bonzini
2017-12-21 22:51 ` Jim Mattson
2017-12-21 12:43 ` [PATCH 2/4] KVM: nVMX: track dirty state of non-shadowed VMCS fields Paolo Bonzini
2017-12-21 22:57 ` Jim Mattson [this message]
2017-12-25 3:03 ` Wanpeng Li
2017-12-31 8:08 ` Paolo Bonzini
2017-12-31 22:48 ` Wanpeng Li
2017-12-21 12:43 ` [PATCH 3/4] KVM: nVMX: initialize descriptor cache fields in prepare_vmcs02_full Paolo Bonzini
2017-12-21 12:43 ` [PATCH 4/4] KVM: nVMX: initialize more non-shadowed " Paolo Bonzini
2017-12-25 3:09 ` Wanpeng Li
2017-12-27 9:54 ` Paolo Bonzini
2017-12-28 2:07 ` Wanpeng Li
2017-12-25 10:07 ` [PATCH 0/4] KVM: nVMX: prepare_vmcs02 optimizations Wanpeng Li
2017-12-25 10:08 ` Wanpeng Li
2017-12-27 14:28 ` Paolo Bonzini
2017-12-28 8:39 ` Wanpeng Li
2018-01-01 9:36 ` Paolo Bonzini
2018-01-01 23:01 ` Paolo Bonzini
2018-01-02 1:05 ` Wanpeng Li
2018-01-02 13:02 ` Paolo Bonzini
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=CALMp9eRHcho6LPQZ903EduMjLQF3Xd2AB7eWwVJCFSVi+8pzew@mail.gmail.com \
--to=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.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
all inboxes | Powered by JetHome®