From: Jan Kiszka <jan.kiszka@siemens.com>
To: "Tian, Kevin" <kevin.tian@intel.com>
Cc: Avi Kivity <avi@redhat.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"Nakajima, Jun" <jun.nakajima@intel.com>,
"Dong, Eddie" <eddie.dong@intel.com>,
Marcelo Tosatti <mtosatti@redhat.com>
Subject: Re: [PATCH] KVM: APIC: avoid instruction emulation for EOI writes
Date: Mon, 29 Aug 2011 12:24:26 +0200 [thread overview]
Message-ID: <4E5B68DA.1090208@siemens.com> (raw)
In-Reply-To: <625BA99ED14B2D499DC4E29D8138F15063045B0C0C@shsmsx502.ccr.corp.intel.com>
On 2011-08-29 08:09, Tian, Kevin wrote:
> Hi, Avi,
>
> Here comes the patch:
>
> KVM: APIC: avoid instruction emulation for EOI writes
>
> Instruction emulation for EOI writes can be skipped, since sane
> guest simply uses MOV instead of string operations. This is a nice
> improvement when guest doesn't support x2apic or hyper-V EOI
> support.
>
> a single VM bandwidth is observed with ~8% bandwidth improvement
> (7.4Gbps->8Gbps), by saving ~5% cycles from EOI emulation.
>
> Signed-off-by: Kevin Tian <kevin.tian@intel.com>
> <Based on earlier work from>:
> Signed-off-by: Eddie Dong <eddie.dong@intel.com>
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index 57dcbd4..933187e 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -864,6 +864,15 @@ static int apic_mmio_write(struct kvm_io_device *this,
> return 0;
> }
>
> +void kvm_lapic_set_eoi(struct kvm_vcpu *vcpu)
> +{
> + struct kvm_lapic *apic = vcpu->arch.apic;
> +
> + if (apic)
> + apic_set_eoi(vcpu->arch.apic);
> +}
> +EXPORT_SYMBOL_GPL(kvm_lapic_set_eoi);
> +
> void kvm_free_lapic(struct kvm_vcpu *vcpu)
> {
> if (!vcpu->arch.apic)
> diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
> index 52c9e6b..8287243 100644
> --- a/arch/x86/kvm/lapic.h
> +++ b/arch/x86/kvm/lapic.h
> @@ -26,6 +26,7 @@ int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu);
> void kvm_lapic_reset(struct kvm_vcpu *vcpu);
> u64 kvm_lapic_get_cr8(struct kvm_vcpu *vcpu);
> void kvm_lapic_set_tpr(struct kvm_vcpu *vcpu, unsigned long cr8);
> +void kvm_lapic_set_eoi(struct kvm_vcpu *vcpu);
> void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value);
> u64 kvm_lapic_get_base(struct kvm_vcpu *vcpu);
> void kvm_apic_set_version(struct kvm_vcpu *vcpu);
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 5e8d411..35e4af7 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -4540,6 +4540,22 @@ static int handle_xsetbv(struct kvm_vcpu *vcpu)
>
> static int handle_apic_access(struct kvm_vcpu *vcpu)
> {
> + unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
> + int access_type, offset;
> +
> + access_type = (exit_qualification >> 12) & 0xf;
> + offset = exit_qualification & 0xfff;
> + /*
> + * Sane guest uses MOV instead of string operations to
> + * write EOI, with written value not cared. So make a
> + * short-circuit here by avoiding heavy instruction
> + * emulation.
> + */
Is there no cheap way to validate this assumption and fall back to the
slow path in case it doesn't apply? E.g. reading the first instruction
byte and matching it against a whitelist? Even if the ignored scenarios
are highly unlikely, I think we so far tried hard to provide both fast
and accurate results to the guest in all cases.
> + if ((access_type == 1) && (offset == APIC_EOI)) {
> + kvm_lapic_set_eoi(vcpu);
> + skip_emulated_instruction(vcpu);
> + return 1;
> + }
> return emulate_instruction(vcpu, 0) == EMULATE_DONE;
> }
>
> Thanks
> Kevin
Nice optimization otherwise!
Jan
--
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
next prev parent reply other threads:[~2011-08-29 10:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-29 6:09 [PATCH] KVM: APIC: avoid instruction emulation for EOI writes Tian, Kevin
2011-08-29 7:23 ` Avi Kivity
2011-08-29 7:35 ` Tian, Kevin
2011-08-29 8:15 ` Sasha Levin
2011-08-29 8:51 ` Avi Kivity
2011-08-29 10:24 ` Jan Kiszka [this message]
2011-08-29 10:59 ` Avi Kivity
2011-08-29 11:03 ` Jan Kiszka
2011-08-29 11:11 ` Avi Kivity
2011-08-29 13:55 ` Jan Kiszka
2011-08-29 14:14 ` Avi Kivity
2011-09-10 8:41 ` ya su
2011-09-11 7:11 ` Avi Kivity
2011-09-11 8:05 ` Jan Kiszka
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=4E5B68DA.1090208@siemens.com \
--to=jan.kiszka@siemens.com \
--cc=avi@redhat.com \
--cc=eddie.dong@intel.com \
--cc=jun.nakajima@intel.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@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 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.