<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Dec 9, 2010, at 12:34 AM, Brandon Fliflet wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>I am working on a project that provides a scatter/gather memory like logic for a virtual device. In this usage, the guest driver provides pinned memory that plugs into a PCI memory range such that accesses through that memory range get translated into the physical page provided by the guest driver. For the most part, things are working but there are some issues that make me wonder if something might be wrong with the implementation. To perform this behavior I needed to remap the HC physical page in the MMIO2 range with a new HC physical page (converted from the guest provided pinned memory). As such, we used the following interfaces.<br><br>//<br>// Remap page of memory region<br>//<br>// Inputs are GCPhys and regionOffset (offset from PCI BAR) where only 4K pages are mapped<br>rc = PGMPhysGCPhys2HCPhys(pVM, GCPhys, &HCPhys);<br>// Error handling<br>rc = PGMR3PhysMMIO2SetHCPhys(pVM, pDevIns, 0, regionOffset, HCPhys);<br>// Error handling<br><br>Where PGMR3PhysMMIO2SetHCPhys was adapted from PGMR3PhysMMIO2GetHCPhys.  Actual code used was in my forum post.<br><br>My questions to the devs here are: Do you forsee any issues with updating the HC physical page of an MMIO2 range? Is there a better way to remap a page in the MMIO2 given that the page is provided by the guest driver?</div></blockquote><br></div><div>Changing the host physical address of an MMIO2 page is not enough to make this work reliably. For instance take a look at what pgmPhysPageMapCommon in VMMAll/PGMAllPhys.cpp does when encountering an MMIO2 page: it calculates the ring-3/ring-0 mapping address of a page in an MMIO2 range by pRam->pvR3 + offset, i.e. it will access the original page and not the one you want it to. </div><div><br></div><div>What you're trying to do is not something we've modeled into the physical guest memory handling due to lack of use cases. What you could try is to copy the whole PGMPAGE structure and not just the physical address, that should change the page type and avoid the pgmPhysPageMapCommon pitfalls. Only, you need to save the original MMIO2 PGMPAGE entries somewhere as you must restore them on reset (all memory is replaced by zero pages) and possibly also power off.</div><div><br></div><div>-- </div><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>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>