Answers inline

On Thu 08-Dec-2016 1:32 AM, Robert VanVossen wrote:

Hello,

 

We are looking to add another virtio device to camkes-vm for guests to use. I have been looking through the code at how virtio_net works and I have a pretty decent understanding of how it is configured and used. I have a few design/philosophical questions though.

 

1.      Was any of this (libethdriver, libpci, Ethdriver component, virtio_net.c, virtio_emul.c) ported from somewhere else, or was it all written from scratch?

All of this was written from scratch. Porting virtio drivers between operating systems is no easier than porting any other kind of driver unfortunately.

2.      Why is components/Init/src/virtio_net.c used in conjunction with vm0_config.init_cons instead of just using the VMNet templates?

The init constructors is just very generic way to tell the VMM about additional things it should do during the initialization process. If everything was just in the VMNet templates then how does the init code know if there is a thing to initialize or not? Could be done with weak symbols or something, but but the init constructors is just a nicer already existing way to do this.

3.      Looks like pci handling was decoupled from drivers like libethdriver and it is left up to the VM Init component to configure PCI. What is the reason for that?

It is useful on CAmkES systems to not have to come up with a way to give all drivers access to the PCI configuration space. Not only do you need a driver to perform demultiplexing, but you now need some kind of access control logic to only let a given client access regions for its device. All of this complexity can be avoided by just telling the driver its relevant information from the PCI configuration space. This does provide some limitations if you want to configure MSI delivery, which requires access to the config space.

4.      Virtio_emul.c appears to be the layer that actually provides the virtio interface to the VM. Would it make more sense to make this more generic to cover more devices, or should new emulation files be created for each device?

It would be nice for it to be made more generic. I wrote this extremely quickly and cut some corners in the abstractions to just get it to work for network devices. There does need to be some device specific sides to the emulation, but large portions of ring management etc should be common.

Adrian