From: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: "Dong, Eddie" <eddie.dong-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: kvm-devel <kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: Re: [PATCH] lighweight VM Exit
Date: Mon, 14 May 2007 18:14:31 +0300 [thread overview]
Message-ID: <46487CD7.8070408@qumranet.com> (raw)
In-Reply-To: <10EA09EFD8728347A513008B6B0DA77A016FBD91-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
Dong, Eddie wrote:
> OK, how about this patch which further reduce the light weight VM Exit
> MSR save/restore?
>
>
> diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
> index 1288cff..ef96fae 100644
> --- a/drivers/kvm/kvm_main.c
> +++ b/drivers/kvm/kvm_main.c
> @@ -1596,6 +1596,30 @@ void kvm_resched(struct kvm_vcpu *vcpu)
> }
> EXPORT_SYMBOL_GPL(kvm_resched);
>
> +void load_msrs_select(struct vmx_msr_entry *e, int bitmap)
> +{
> + unsigned long nr;
> +
> + while (bitmap) {
> + nr = __ffs(bitmap);
> + clear_bit(nr,&bitmap);
> + wrmsrl(e[nr].index, e[nr].data);
> + }
> +}
> +EXPORT_SYMBOL_GPL(load_msrs_select);
> +
> +void save_msrs_select(struct vmx_msr_entry *e, int bitmap)
> +{
> + unsigned long nr;
> +
> + while (bitmap) {
> + nr = __ffs(bitmap);
> + clear_bit(nr,&bitmap);
> + rdmsrl(e[nr].index, e[nr].data);
> + }
> +}
> +EXPORT_SYMBOL_GPL(save_msrs_select);
> +
>
__clear_bit() is faster here (no LOCK prefix). But maybe we can avoid
the entire thing by having a vcpu->active_msr_list (array of struct
vmx_msr_entry) which is re-constructed every time the mode changes
(instead of constructing the bitmap). vmx_get_msr() can first look at
the active msr list and then at the regular msr list.
>
> /*
> @@ -469,35 +466,51 @@ static void vmx_inject_gp(struct kvm_vcpu *vcpu,
> unsigned error_code)
> */
> static void setup_msrs(struct kvm_vcpu *vcpu)
> {
> - int nr_skip, nr_good_msrs;
> -
> - if (is_long_mode(vcpu))
> - nr_skip = NR_BAD_MSRS;
> - else
> - nr_skip = NR_64BIT_MSRS;
> - nr_good_msrs = vcpu->nmsrs - nr_skip;
> + int index,save_msrs;
>
space after comma
>
> - /*
> - * MSR_K6_STAR is only needed on long mode guests, and only
> - * if efer.sce is enabled.
> - */
> - if (find_msr_entry(vcpu, MSR_K6_STAR)) {
> - --nr_good_msrs;
> -#ifdef CONFIG_X86_64
> - if (is_long_mode(vcpu) && (vcpu->shadow_efer &
> EFER_SCE))
> - ++nr_good_msrs;
> + vcpu->smsrs_bitmap = 0;
> + if (is_long_mode(vcpu)) {
> + if ((index=__find_msr_index(vcpu, MSR_SYSCALL_MASK)) >=
> 0) {
> + set_bit(index, &vcpu->smsrs_bitmap);
> + }
>
Assignment outside if (), spaces around =, please. Single statements
without {}.
Also __set_bit() applies here.
> + /*
> + * MSR_K6_STAR is only needed on long mode guests, and
> only
> + * if efer.sce is enabled.
> + */
> + if ((index=__find_msr_index(vcpu, MSR_K6_STAR)) >= 0
> +#ifdef X86_64
> + && (vcpu->shadow_efer & EFER_SCE)
> #endif
> + ) {
> + set_bit(index, &vcpu->smsrs_bitmap);
>
You're saving MSR_K6_STAR unnecessarily on i386. Since we don't export
EFER on i386 (one day we should...), the guest can't use syscall.
> + }
> }
>
> + if ((index = __find_msr_index(vcpu, MSR_EFER)) >= 0) {
> + save_msrs = 1;
> + }
> + else {
> + save_msrs = 0;
> + index = 0;
> + }
>
Why not use hardware autoloading? Is it slower than software?
Otherwise looks good. Did you measure performance improvement? I
usually use user/test/vmexit.c from kvm-userspace.git.
--
error compiling committee.c: too many arguments to function
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
next prev parent reply other threads:[~2007-05-14 15:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-10 9:29 guest state leak into host Dong, Eddie
[not found] ` <10EA09EFD8728347A513008B6B0DA77A016AB9E3-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-05-13 10:51 ` Avi Kivity
[not found] ` <4646EDB3.6030602-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-14 14:57 ` [PATCH] lighweight VM Exit (was:RE: guest state leak into host) Dong, Eddie
[not found] ` <10EA09EFD8728347A513008B6B0DA77A016FBD91-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-05-14 15:14 ` Avi Kivity [this message]
[not found] ` <46487CD7.8070408-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-14 15:34 ` [PATCH] lighweight VM Exit Christoph Hellwig
2007-05-15 6:10 ` Dong, Eddie
[not found] ` <10EA09EFD8728347A513008B6B0DA77A016FC1F2-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-05-15 7:39 ` Avi Kivity
[not found] ` <464963A3.7090505-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-15 10:12 ` Dong, Eddie
[not found] ` <10EA09EFD8728347A513008B6B0DA77A016FC3CD-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-05-15 13:48 ` Dong, Eddie
[not found] ` <10EA09EFD8728347A513008B6B0DA77A016FC419-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-05-16 8:35 ` Avi Kivity
[not found] ` <464AC26D.8040901-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-16 15:23 ` Dong, Eddie
[not found] ` <10EA09EFD8728347A513008B6B0DA77A014E8AB2-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-05-16 15:40 ` Avi Kivity
[not found] <10EA09EFD8728347A513008B6B0DA77A014E8AB5@pdsmsx411.ccr.corp.intel.com>
[not found] ` <10EA09EFD8728347A513008B6B0DA77A014E8AB5-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-05-16 16:04 ` Avi Kivity
[not found] ` <464B2B89.3060009-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-17 14:22 ` Dong, Eddie
[not found] ` <10EA09EFD8728347A513008B6B0DA77A0174CB56-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-05-17 14:54 ` Avi Kivity
[not found] ` <464C6C96.9090202-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-17 15:56 ` 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=46487CD7.8070408@qumranet.com \
--to=avi-atkuwr5tajbwk0htik3j/w@public.gmane.org \
--cc=eddie.dong-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
/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