<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi,</div><div><br></div><div>it's not an entirely trivial matter you're brining up here... </div><div><br></div><div>VirtualBox support two different ways of translating guest physical address to host physical addresses: 1. shadow page tables, and 2. nested page tables.  The 2nd way relies on VT-x and AMD-V features and are much less complicated. The 1st is what we have to use for traditional software virtualization (the code path you located) and for hardware that does not support nested page tables.</div><div><br></div><div>In the nested page table case (2), we construct a page table like mapping of guest physical addresses to host physical addresses as the guest accesses its physical pages. The first time a page is accessed we will allocate it. </div><div><br></div><div>In the shadow page table case (1), we construct a shadow of the guest page tables with the guest physical addresses replaced by the actual host physical addresses. The current approach will create these tables lazily when the guest accesses them, i.e. on #PFs. Just like above, the first time a page is accessed (or shadowed thru a mapping), we will allocate it. The code responsible for creating and maintaing the shadow page tables is complicated because there are 3 basic paging modes (32-bit legacy, PAE and AMD64) and the guest and host might use different ones (host=PAE, guest=32-bit legacy).</div><div><br></div><div>Too answer your question: CR3 holds the root address of the guest page table hierarchy and is therefore fundamental when constructing shadow page tables. When a #PF is raised because the guest accesses some address without a shadow page table entry, we have to walk the guest page hierarchy from CR3 and down to the guest entry to figure out whether (a) it's a valid access, (b) the physical address, and (c) the effective access mask of the page.</div><div><br></div><div>Hope this helps a bit..</div><br><div><div>On Jun 7, 2011, at 4:39 AM, Francesco Di Paolo wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">
<div dir="ltr">
<div style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<div>hello,</div>
<div>i’m trying to understand how paging works on VirtualBox. So far, and in a 
general way, i’ve understand that(and correct me if i’m wrong)when the guest OS 
tries to allocate a page, a #PF is generated and this is handled by 
trpmtrap0ehandler() in TRPM.cpp that relies on pgmtrap0ehandler(). This function 
gives the control to the hypervisor that uses functions in the MM and PGM group 
in order to allocate the page. Now i dont’ want anyone to explain me the all 
process(i wish...but no). I’m looking for advices in order to better understand 
the second part(what the hypervisor does)such as:could it be useful to see the 
content of the CR3 register and why?</div>
<div>What i need are the right questions i have to ask to myself.</div>
<div>Any kind of help will be more than appreciated.</div>
<div>Thank you</div>
<div> </div></div></div></div>
_______________________________________________<br>vbox-dev mailing list<br><a href="mailto:vbox-dev@virtualbox.org">vbox-dev@virtualbox.org</a><br>http://vbox.innotek.de/mailman/listinfo/vbox-dev<br></blockquote></div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>-- <br><br>Kind regards / Mit freundlichen Gruessen / Vennlig hilsen,<br> bird<br><br>--<br><br>ORACLE Deutschland B.V. & Co. KG  Knut St. Osmundsen<br>Werkstrasse 24                    Senior Staff Engineer, VirtualBox<br>71384 Weinstadt, Germany          <a href="mailto:bird@sun.com">mailto:bird@sun.com</a><br><br>Hauptverwaltung: Riesstr. 25, D-80992 Muenchen<br>Registergericht: Amtsgericht Muenchen, HRA 95603<br><br>Komplementaerin: ORACLE Deutschland Verwaltung B.V.<br>Rijnzathe 6, 3454PV De Meern, Niederlande<br>Handelsregister der Handelskammer Midden-Niederlande, Nr. 30143697<br>Geschaeftsfuehrer: J. Kunz, M. van de Molen, A. van der Ven</div></div></div></span></span>
</div>
<br></body></html>