public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: Ingo Molnar <mingo-X9Un+BFzKDI@public.gmane.org>
Cc: kvm-devel
	<kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [patch] KVM: always reload segment selectors
Date: Sun, 11 Mar 2007 15:04:08 +0200	[thread overview]
Message-ID: <45F3FE48.2040808@qumranet.com> (raw)
In-Reply-To: <20070311125233.GA17328-X9Un+BFzKDI@public.gmane.org>

Ingo Molnar wrote:
> Subject: [patch] KVM: always reload segment selectors
> From: Ingo Molnar <mingo-X9Un+BFzKDI@public.gmane.org>
>
> failed VM entry on VMX might still change %fs or %gs, thus make sure 
> that KVM always reloads the segment selectors. This is crutial on both 
> x86 and x86_64: x86 has __KERNEL_PDA in %fs on which things like 
> 'current' depends and x86_64 has 0 there and needs MSR_GS_BASE to work.
>
> Signed-off-by: Ingo Molnar <mingo-X9Un+BFzKDI@public.gmane.org>
> ---
>  drivers/kvm/vmx.c |   37 +++++++++++++++++++++----------------
>  1 file changed, 21 insertions(+), 16 deletions(-)
>
> Index: linux/drivers/kvm/vmx.c
> ===================================================================
> --- linux.orig/drivers/kvm/vmx.c
> +++ linux/drivers/kvm/vmx.c
> @@ -1896,6 +1896,27 @@ again:
>  		[cr2]"i"(offsetof(struct kvm_vcpu, cr2))
>  	      : "cc", "memory" );
>  
> +	/*
> +	 * Reload segment selectors ASAP. (it's needed for a functional
> +	 * kernel: x86 relies on having __KERNEL_PDA in %fs and x86_64
> +	 * relies on having 0 in %gs for the CPU PDA to work.)
> +	 */
> +	if (fs_gs_ldt_reload_needed) {
> +		load_ldt(ldt_sel);
> +		load_fs(fs_sel);
> +		/*
> +		 * If we have to reload gs, we must take care to
> +		 * preserve our gs base.
> +		 */
> +		local_irq_disable();
> +		load_gs(gs_sel);
> +#ifdef CONFIG_X86_64
> +		wrmsrl(MSR_GS_BASE, vmcs_readl(HOST_GS_BASE));
> +#endif
> +		local_irq_enable();
> +
> +		reload_tss();
> +	}
>  	++kvm_stat.exits;
>  
>  	save_msrs(vcpu->guest_msrs, NR_BAD_MSRS);

btw, looking at the code, we could just remove fs from the 
fs_gs_reload_needed and make in unconditional.  VT knows how to reload 
segments, except if they're user segments (groan).  In the case of fs, 
if it's used for the pda, it's obviously a kernel segment.

gs is different: since only the segment base is loaded (via swapgs), the 
selector part could well be a userspace selector, and thus the 
irq-protected reload is needed.

Anyway, I'm applying the patch as the above discourse is irrelevant to 
the fix.


-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

  parent reply	other threads:[~2007-03-11 13:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-11 12:24 %fs PDA & KVM Ingo Molnar
     [not found] ` <20070311122441.GA10774-X9Un+BFzKDI@public.gmane.org>
2007-03-11 12:38   ` Avi Kivity
     [not found]     ` <45F3F85D.7000509-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-03-11 12:41       ` Ingo Molnar
     [not found]         ` <20070311124146.GA15115-X9Un+BFzKDI@public.gmane.org>
2007-03-11 12:52           ` [patch] KVM: always reload segment selectors Ingo Molnar
     [not found]             ` <20070311125233.GA17328-X9Un+BFzKDI@public.gmane.org>
2007-03-11 13:04               ` Avi Kivity [this message]
2007-03-11 22:19   ` %fs PDA & KVM Rusty Russell

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=45F3FE48.2040808@qumranet.com \
    --to=avi-atkuwr5tajbwk0htik3j/w@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mingo-X9Un+BFzKDI@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