WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] Is the Guest OS in non-paging protected mode when VM fir

To: henanwxr <henanwxr@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: Re: [Xen-devel] Is the Guest OS in non-paging protected mode when VM first execute vmlaunch?
From: Keir Fraser <keir.xen@xxxxxxxxx>
Date: Sat, 21 May 2011 23:08:08 +0100
Cc:
Delivery-date: Sat, 21 May 2011 15:08:57 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:user-agent:date:subject:from:to:message-id :thread-topic:thread-index:in-reply-to:mime-version:content-type :content-transfer-encoding; bh=iakf/FT2e+7uqUmQOihar7VRSt6PGLqTuEPZ2tJ18/8=; b=E71XJhpMX76Rl/JUGaSnEB4lyPvHxMvNQDBVMrUacc/y2V+BLLRz4dt4WB5Sb82GIv fCyfbj1OicSaUMGpiPkX2QLGdOsRPXjUVCoQgzn20gZiZFDfhssnFhyFIX4KUV4/MXBg ZCSUyI2spZa7zfampcC052PdinpybmJO50lo4=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=user-agent:date:subject:from:to:message-id:thread-topic :thread-index:in-reply-to:mime-version:content-type :content-transfer-encoding; b=UCiYJvxABDKEhSxX6mCVokD7wNCLSs6I363lz+L2uFp5W/imySHBm1Qcu/9ORIp5bI doJXZKScpNsuyNFPy56wMeiWznLDNR8R7J2uc2Uie05TQB5J1Aeo2IYRVIu3qkvdJuwN Svgm3KRpe9cO/+oByUNTZ2JuevC3KSFl+WmhM=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1305994127711-4415142.post@xxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Thread-index: AcwYA5DJ++QjQ+mpBUypBdlQRl4bjQ==
Thread-topic: [Xen-devel] Is the Guest OS in non-paging protected mode when VM first execute vmlaunch?
User-agent: Microsoft-Entourage/12.29.0.110113
On 21/05/2011 17:08, "henanwxr" <henanwxr@xxxxxxx> wrote:

> 1、Is the Guest OS in non-paging protected mode when VM first execute
> vmlaunch?
>    If it is so, why not set it in paging protected mode, could I do this?

I suppose, if you had reason to. Seems pointless though as you could set it
up more easily from within the guest.

> 2、I found guest os was set in paging and protected mode in function of
> construct_vmcs().

You are mixing up two things: the CR0 the guest *thinks* it is running with,
and the CR0 value it is *actually* running with. Actually we must always run
non-root mode with paging enabled, but we hide that from the guest by
running it on a hidden page table with 1:1 virt:phys mappings. So the
v->arch.hvm_vcpu.guest_cr[0] value in the code below is the cr0 value the
guest manages and sees. The v->arch.hvm_vcpu.hw_cr[0] is the value it
actually runs with. If you don't understand the difference between these
values, you'll get very confused!

 -- Keir

> The flow is:
> 
> //Xen-4.0/arch/x86/hvm/vmx/vmcs.c
> construct_vmcs()
> {
>   ………………..
>    //here set CR0.PE
>     v->arch.hvm_vcpu.guest_cr[0] = X86_CR0_PE | X86_CR0_ET;
>     hvm_update_guest_cr(v, 0);
> …………………
> }
> 
> 
> 
> 
> // Then it calls function of hvm_update_guest_cr() in
> /xen/include/asm-x86/hvm.h
>     static inline void hvm_update_guest_cr(struct vcpu *v, unsigned int cr)
> {
>     hvm_funcs.update_guest_cr(v, cr);
> }
> 
> 
> 
>     //hvm_funcs.update_guest_cr calls function of  vmx_updata_guest_cr()
>     //in /arch/x86/hvm/vmx/vmx.c
> static struct hvm_function_table __read_mostly vmx_function_table = {
>     .name                 = "VMX",
>     …………………………
>     .update_host_cr3      = vmx_update_host_cr3,
>     .update_guest_cr      = vmx_update_guest_cr,
>    ……………………..
> }
> 
> static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)
> {
>     vmx_vmcs_enter(v);
> 
>     switch ( cr )
>     {
>     case 0: {
>         int realmode;
>         unsigned long hw_cr0_mask = X86_CR0_NE;
>       
>  //here set CR0.PG and CR0.PE
>         if ( !vmx_unrestricted_guest(v) )
>          hw_cr0_mask |= X86_CR0_PG | X86_CR0_PE;
>           …………………………..
>           …………………………..
>          v->arch.hvm_vcpu.hw_cr[0] = v->arch.hvm_vcpu.guest_cr[0] |
> hw_cr0_mask;
>      //here write GUEST_CR0, is it in paging and protected mode ??
>      __vmwrite(GUEST_CR0, v->arch.hvm_vcpu.hw_cr[0]);
>      __vmwrite(CR0_READ_SHADOW, v->arch.hvm_vcpu.guest_cr[0]);
>       ………….      
> }
> 
> 
> --
> View this message in context:
> http://xen.1045712.n5.nabble.com/Is-the-Guest-OS-in-non-paging-protected-mode-
> when-VM-first-execute-vmlaunch-tp4415142p4415142.html
> Sent from the Xen - Dev mailing list archive at Nabble.com.
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@xxxxxxxxxxxxxxxxxxx
> http://lists.xensource.com/xen-devel



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>