[vbox-dev] Using Sockets in Device emulation

Knut St. Osmundsen knut.osmundsen at oracle.com
Tue Sep 20 20:15:40 GMT 2011


Hi Arpit,

ok, so you wish to forward SATA commands received by DevAHCI.cpp. That's doable.

In VirtualBox's pluggable device/driver model (PDM) we usually try to put code accessing host OS services or similar in drivers.  A typical device emulation will have one or more drivers attached to its ports (called LUNs by PDM - don't ask why). The storage related drivers are shared among all storage device emulations, saving code duplication. With one exception (DrvIntNet.cpp) all drivers lives exclusively in ring-3 context and can do socket calls and almost whatever else they wish.

In your case, I'm not sure if implementing a driver is the best solution though, since you probably want the SATA commands that the guest sends and not stuff broken down into generic storage driver method calls. This is a bit more work though...  And there are no examples of devices doing socket I/O or similar at the moment.

I can see two way of approaching the task of making DevAHCI.cpp forward SATA commands:
 1. Disable the ring-0 and raw-mode context compilation and execution completion, forcing the 
     entire device emulation to be executed in ring-3:
      1a. Remove DevAHCI.cpp and ATAController.cpp from the VBoxDDGC and 
          VBoxDDR0 targets in the src/VBox/Devices/Makefile.kmk.
      1b. Force fR0Enabled and fGCEnabled in ahciR3Construct to false.
    This approach is potentially slower than the next one as it may result it lots of context 
    switching between ring-0 and ring-3 to service AHCI accesses.
 2.  Put the #ifdef IN_RING3 around all the socket code. If some code path requiring 
    socket activity is executed in ring-0 (or raw-mode), force it to return to ring-3 and be
    serviced there.  This approach is much trickier and but may perform better. 

Hope this was of some help,
 Knut.

On Sep 20, 2011, at 6:23 PM, Arpit Patel wrote:

> Thanks for your reply. I need to talk to some socket level application/server(which can possibly be running on another system) that is simulating SATA behavior and I need to generate those SATA commands via socket comm from within AHCI emulation code.  Since this is done for some new AHCI hardware development as well as some new storage hw protocol emulation, I am using the AHCI emulation to test my drivers and on the back end would like to generate SATA commands via socket comm to the simulation app. running on other end. That's why I want to initiate this socket comm from  AHCI emulation code. Is there any other better approach to this problem you can suggest in virtualbox?
> Thanks.
> Arpit.
> 
> From: Klaus Espenlaub <klaus.espenlaub at oracle.com>
> To: vbox-dev at virtualbox.org
> Sent: Monday, September 19, 2011 10:34 AM
> Subject: Re: [vbox-dev] Using Sockets in Device emulation
> 
> On 16.09.2011 22:20, Arpit Patel wrote:
> > Hi,
> > I wanted to use tcp sockets from Device Emulation (eg. DevAHCI.cpp) and
> > connect to a socket server running on one of the Guest OS or to another
> > system on the network. I have following questions -
> 
> DevAHCI is a rather complex device... which means it's not the ideal starting point.
> 
> What do you actually want to achieve? Accessing remote storage? It would help a lot of you'd say a few words about your general idea before setting out to implement it.
> 
> > 1. Would this kind of socket comm possible from Device Emulation code?
> > 2. As device emulation code runs in Ring0 mode, if I try to even include
> > iprt/sockets.h file, it complains that RTSocket APIs are not available
> > in Ring-0 context. If that is so, what sockets can I use from within
> > Device Emulation code?
> > 3. How do I know which code of Virtualbox is running in Ring0 and which
> > is running in Ring3? I was under the impression that the vbox host
> > drivers that are built and installed on the host OS is the only code
> > that runs in Ring0 and everything else should be Ring3.
> > 4. Is there any sample code of this socket comm that can be used from
> > device emulation in virtualbox, that you can point me to?.
> 
> In general you need to make sure that the socket code is ONLY used by Ring3 code, then it would compile. However this all may be unnecessary if you actually want a new storage "format".
> 
> Klaus
> 
> 
> > Thanks.
> > Arpit.
> > 
> > 
> > 
> > 
> > _______________________________________________
> > vbox-dev mailing list
> > vbox-dev at virtualbox.org
> > http://vbox.innotek.de/mailman/listinfo/vbox-dev
> 
> 
> -- Oracle <http://www.oracle.com>
> Dr. Klaus Espenlaub | Snr. Manager Software Development Desktop
> Virtualization
> Phone: +49 7151 60405 205 <tel:+49715160405205>
> Oracle VM VirtualBox
> 
> ORACLE Deutschland B.V. & Co. KG | Werkstr. 24 | 71384 Weinstadt
> 
> ORACLE Deutschland B.V. & Co. KG
> Hauptverwaltung: Riesstr. 25, D-80992 München
> Registergericht: Amtsgericht München, HRA 95603
> 
> Komplementärin: ORACLE Deutschland Verwaltung B.V.
> Hertogswetering 163/167, 3543 AS Utrecht, Niederlande
> Handelsregister der Handelskammer Midden-Niederlande, Nr. 30143697
> Geschäftsführer: Jürgen Kunz, Marcel van de Molen, Alexander van der Ven
> 
> Green Oracle <http://www.oracle.com/commitment>     Oracle is committed to
> developing practices and products that help protect the environment
> 
> 
> _______________________________________________
> vbox-dev mailing list
> vbox-dev at virtualbox.org
> http://vbox.innotek.de/mailman/listinfo/vbox-dev
> 
> 
> _______________________________________________
> vbox-dev mailing list
> vbox-dev at virtualbox.org
> http://vbox.innotek.de/mailman/listinfo/vbox-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.virtualbox.org/pipermail/vbox-dev/attachments/20110920/f83ae18a/attachment.html>


More information about the vbox-dev mailing list