<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br><div><div>On Dec 8, 2010, at 11:02 PM, Huihong Luo wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><table cellspacing="0" cellpadding="0" border="0" style="position: static; z-index: auto; "><tbody><tr><td valign="top" style="font: inherit;"><div id="yiv1888725648">
<table class="yiv1888725648" id="yiv1888725648bodyDrftID" cellspacing="0" cellpadding="0" border="0" style="position: static; z-index: auto; ">
<tbody>
<tr>
<td id="yiv1888725648drftMsgContent" style="FONT-SIZE: 10pt; FONT-FAMILY: arial">
<div>I wonder if anyone can provide some detailed info as how guest i/o comes to the host emulation layer (user space). For example, how does "outb port_num, val" instruction travel from guest kernel to host user space on AMD64 with VT-x/AMD-V?</div>
<div> </div>
<div>The reason I aksed is that I was wondering if performance would be further improved if moving some emulation layer from host user space to host kernel layer? that should at least saves two context switches.</div>
<div> </div>
<div>KVM provides some callbacks, any similar api exists for VBox? </div></td></tr></tbody></table></div></td></tr></tbody></table></blockquote><div><table cellspacing="0" cellpadding="0" border="0" style="position: static; z-index: auto; "><tbody><tr><td valign="top" style="font: inherit;"><div id="yiv1888725648"><table class="yiv1888725648" id="yiv1888725648bodyDrftID" cellspacing="0" cellpadding="0" border="0" style="position: static; z-index: auto; "><tbody><tr><td id="yiv1888725648drftMsgContent" style="FONT-SIZE: 10pt; FONT-FAMILY: arial"><div><br></div><div></div></td></tr></tbody></table>For I/O ports we have had PDMDevHlpIOPortRegister, PDMDevHlpIOPortRegisterR0 and PDMDevHlpIOPortRegisterRC since day one. All performance critical devices registers ring-3, ring-0 (R0) and raw-mode context (RC) callbacks for their I/O ports and will handle exits (R0 (VT-x/AMD-V)) and virtualization traps (RC) directly without switching the context when possible.</div><div id="yiv1888725648"><br></div><div id="yiv1888725648">For memory mapped I/O (MMIO) ranges there are similar APIs: PDMDevHlpMMIORegister, PDMDevHlpMMIORegisterR0 and PDMDevHlpMMIORegisterRC.</div></td></tr></tbody></table></div></div></div><div><br class="webkit-block-placeholder"></div><div>What happens when we take an I/O port access exit in VT-x or AMD-V mode is that we use as much information as the hardware provides and tells the I/O manager (IOM) to dispatch it to the relevant callback.  Usually the IOM can dispatch this directly without having to switch back to user mode (ring-3).</div><div><br></div><div>In raw-mode the trap manager's (TRPM) general protection fault handler will catch the IN/OUT/INSx/OUTSx instruction and decode it. Seeing that it's an port I/O instruction it will hand it on to EMInterpretPortIO which will interpret the instruction with the help of IOM like in the VT-x/AMD-V case.</div><div><br></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><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>