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] Readonly memory for guest domain

To: "pradeep singh rautela" <rautelap@xxxxxxxxx>
Subject: Re: [Xen-devel] Readonly memory for guest domain
From: "Peter Teoh" <htmldeveloper@xxxxxxxxx>
Date: Thu, 13 Sep 2007 14:36:14 +0800
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Wed, 12 Sep 2007 23:36:42 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; bh=3ud0weuCCVuTkBmozcPJgf0aj4YSvtQjuR2HkSyuGeg=; b=EjjE98zmUfKDA/Jig3XEMDdvtfrDw4wIpzNBQOGgnf6Mco8rejAQwh8uXo6u7dECDSkIessg2TyXs0v64blCHjtEX+Psmy7SUAKLG0FjvtP3tJr4WKBObfqKXFPwWGB+6ujxICdlrmM1cvROzAMP3O+Gn2rPVR6Tqf3T3iyv3yQ=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=W2eIEUaOS2uHNA3VuRuKNG+dTNMsB4fva3wlZRhA5xwohEV1yBGL7je4P6NgnnOJ3uSF/zJSlDgrlDIyxiircTqwyP5FR/Ds1iVT7am30n9qBSshY3xfcSzT4MQ0RCFTpjWEkkGIqD/Cy98SK26ifqxt/+YQ4t2WHdw3OP041Ro=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <6bc632150709122140j7a8e1dddq9e8d72b7dd74a5c6@xxxxxxxxxxxxxx>
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/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <00ca01c7f4db$69d991f0$9a010a0a@eeyore> <C30D53BF.D73B%Keir.Fraser@xxxxxxxxxxxx> <804dabb00709121859te561d2cjdfeac95876b9778@xxxxxxxxxxxxxx> <6bc632150709122140j7a8e1dddq9e8d72b7dd74a5c6@xxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Thank you for the answer, but I am still totally confused....apologies here.
 
On 9/13/07, pradeep singh rautela <rautelap@xxxxxxxxx> wrote:
On 9/13/07, Peter Teoh <htmldeveloper@xxxxxxxxx> wrote:
[...]
> Thank you for the answer.   In the first place, we will not know what is
> pagetable or non-pagetable memory.   For example, during dom0/domU
> initialisation, the guest OS will query the e820 bios mechanism for physical
> memory  availability, and the guest OS (paravirt or HVM) will then assign
> different parts of the physical memory for pagetable construction.   Then
> after all the pagetable is completely constructed, the CR3 is loaded, which
> started the hardware MMU operation.    So therefore, before the CR3 is
> loaded the entire physical memory is marked as readonly, and after the CR3
> is loaded, only those memory not involved in pagetable mapping are unmarked
> readonly?
>
> Does not seem right, as guest OS can change the CR3 anytime subsequently as
> well.

Any writes to CR3 'll be trapped to the Xen itself AFAIK. So, yes any
guest can change the CR3 anytime but there is always Xen to see what
it is writing in the CR3 .Anything beyond the memory assigned to
domain is illegal, xen knows the limits of the domains.
 
This part I fully understand.   But the guest OS, knowing that he owns the entire memory range, will attempt to partition the entire blocks of memory in any design he wants to - whether it be pagetable memories or not.   And so the contents in memory can be anything, there is no concept of "invalid frame number" to the guest OS, and will remain as what the guest OS has written - no change, ie hypervisor cannot change its content.
 
But the hypervisor will implement a shadow memory (apologies if I am wrong, just describing based on the all the materials I have read so far) - this construction (done in hypervisor) is triggered immediately upon loading of CR3 by the guest.   And the purpose of the shadow memory is to rewrite all the pagetable entries in the guest to its real/physical values, so that it can be used for pagetable mapping by MMU.    This rewriting process is done in hypervisor, based on the memory assigned to the guest, and so it has to be ALWAYS valid values.   It is needed because hypervisor cannot change the content of the guest pagetable.   The guest should always be able to write ANYTHING he wants to, to his own guest memory.   And the hypervisor will always generate the VALID mapping values to put into the shadow memory.  
 
So throughout the entire chain of reasoning, there is no way for the guest to corrupt the shadow table in the hypervisor.   The only reason I can think of, that pagetable in guest must be made readonly, is so that it will trigger the corresponding pagetable update in the shadow memory in the hypervisor.   Nothing to do with valid/invalid frames numbers here, or "unsafe" values either.   Does it sound logical?
 
Please correct me if I am wrong.
 
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel