From: Marcelo Tosatti <mtosatti@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [RFC PATCH 1/5] KVM: vmx: speed up emulation of invalid guest state
Date: Wed, 16 Apr 2014 19:52:58 -0300 [thread overview]
Message-ID: <20140416225258.GA19597@amt.cnet> (raw)
In-Reply-To: <1395919838-18466-2-git-send-email-pbonzini@redhat.com>
On Thu, Mar 27, 2014 at 12:30:34PM +0100, Paolo Bonzini wrote:
> About 25% of the time spent in emulation of invalid guest state
> is wasted in checking whether emulation is required for the next
> instruction. However, this almost never changes except when a
> segment register (or TR or LDTR) changes, or when there is a mode
> transition (i.e. CR0 changes).
>
> In fact, vmx_set_segment and vmx_set_cr0 already modify
> vmx->emulation_required (except that the former for some reason
> uses |= instead of just an assignment). So there is no need to
> call guest_state_valid in the emulation loop.
>
> Emulation performance test results indicate 530-870 cycles
> for common instructions, versus 740-1110 before this patch.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> arch/x86/kvm/vmx.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 1320e0f8e611..73aa522db47b 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -3629,7 +3629,7 @@ static void vmx_set_segment(struct kvm_vcpu *vcpu,
> vmcs_write32(sf->ar_bytes, vmx_segment_access_rights(var));
>
> out:
> - vmx->emulation_required |= emulation_required(vcpu);
> + vmx->emulation_required = emulation_required(vcpu);
> }
>
> static void vmx_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l)
> @@ -5580,7 +5580,7 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
> cpu_exec_ctrl = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
> intr_window_requested = cpu_exec_ctrl & CPU_BASED_VIRTUAL_INTR_PENDING;
>
> - while (!guest_state_valid(vcpu) && count-- != 0) {
> + while (vmx->emulation_required && count-- != 0) {
> if (intr_window_requested && vmx_interrupt_allowed(vcpu))
> return handle_interrupt_window(&vmx->vcpu);
>
> @@ -5614,7 +5614,6 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
> schedule();
> }
>
> - vmx->emulation_required = emulation_required(vcpu);
> out:
> return ret;
> }
> --
> 1.8.3.1
How about handling VM-entry error due to invalid state with
vmx->emulation_required = true;
continue to main vcpu loop;
next prev parent reply other threads:[~2014-04-16 23:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-27 11:30 [RFC PATCH 0/5] KVM: speed up invalid guest state emulation Paolo Bonzini
2014-03-27 11:30 ` [RFC PATCH 1/5] KVM: vmx: speed up emulation of invalid guest state Paolo Bonzini
2014-04-16 22:52 ` Marcelo Tosatti [this message]
2014-04-18 4:19 ` Paolo Bonzini
2014-04-21 2:13 ` Marcelo Tosatti
2014-04-22 3:25 ` Paolo Bonzini
2014-03-27 11:30 ` [RFC PATCH 2/5] KVM: x86: avoid useless set of KVM_REQ_EVENT after emulation Paolo Bonzini
2014-03-28 12:44 ` Paolo Bonzini
2014-03-27 11:30 ` [RFC PATCH 3/5] KVM: x86: move around some checks Paolo Bonzini
2014-03-27 11:30 ` [RFC PATCH 4/5] KVM: x86: protect checks on ctxt->d by a common "if (unlikely())" Paolo Bonzini
2014-03-27 11:30 ` [RFC PATCH 5/5] KVM: x86: speed up emulated moves 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=20140416225258.GA19597@amt.cnet \
--to=mtosatti@redhat.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