VirtIO Specification
The device offers all the features it knows about, and the driver acknowledges those it understands and wishes to use.
A virtio device is discovered and identified by a bus-specific method (PCI, MMIO).
Each device consists of the following parts:
- Device status field
- Feature bits
- Notifications
- Device Configuration space
- One or more virtqueues
VIRTIO_F_IN_ORDER
所谓 inorder 特性是在后端使用 desc(消耗 avail desc)和释放 desc(更新 used desc)的顺序是一致的。这个特性的关键在于 device(后端)的行为;
当支持这种行为的时候 device 不必对每个消耗的 avail desc chain 都更新一个对应的 used desc entry,而是可用对一次消耗多个 avail desc chain 只更新一个 used desc,这个 used desc 中的 id 记录着这一批 avail desc chain 的最后一个 chain 的 head desc id。
从dpdk 1811实现看virtio 1.1——inorder特性支持-lvyilong316-ChinaUnix博客
VritIO Device Status Field
The driver MUST follow this sequence to initialize a device:
- Reset the device.
- Set the
ACKNOWLEDGE
status bit: the guest OS has noticed the device. - Set the
DRIVER
status bit: the guest OS knows how to drive the device. - Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
- Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step. 6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
- Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
- Set the DRIVER_OK status bit. At this point the device is “live”.
Status bits:
- ACKNOWLEDGE (1) Indicates that the guest OS has found the device and recognized it as a valid virtio device.
- DRIVER (2) Indicates that the guest OS knows how to drive the device. Note: There could be a significant (or infinite) delay before setting this bit. For example, under Linux, drivers can be loadable modules.
- FAILED (128):驱动错误。Indicates that something went wrong in the guest, and it has given up on the device. This could be an internal error, or the driver didn’t like the device for some reason, or even a fatal error during device operation.
- FEATURES_OK (8) Indicates that the driver has acknowledged all the features it understands, and feature negotiation is complete.
- DRIVER_OK (4) Indicates that the driver is set up and ready to drive the device.
- DEVICE_NEEDS_RESET (64):设备错误。Indicates that the device has experienced an error from which it can’t recover.
VirtIO IOMMU Device
现实中有 IOMMU 这个硬件,所以 IOMMU 也可以作为一个 virtio 设备?
VirtIO IOMMU 可以看作是一种 vIOMMU?
The virtio-iommu device manages DMA from one or more endpoints.
- It may act both as a proxy for physical IOMMUs managing devices assigned to the guest,
- and as virtual IOMMU managing emulated and paravirtualized devices.
也就是说这个可以 back 一个真正的 IOMMU,然后让这个 IOMMU 管理 passthrough 的设备;也可以直接管理一些虚拟的被模拟的设备(让 guest 以为这是 passthrough 的设备?)。