virtio 1.0 简介
2016-03-10 17:09
357 查看
Introduction This article aims to offer a different view of virtio devices from most of the other articles available online. It is neither a complete reference to the virtio 1.0 spec, nor a high-level overview, but rather aims at providing the reader with an idea of how a virtio driver and device implementation work and communicate with each other, through the use of diagrams. That information could then be used as a starting point in cases where it becomes necessary to delve into a virtio device implementation's code for troubleshooting purposes. Throughout the text, we will assume PCI is the transport mechanism used, ignoring MMIO or channel I/O, and choose virtio-net as our example device type. Accordingly, all the elements that are device type-specific in the figures below pertain to virtio-net devices. Device Discovery Below is a diagram that describes what the configuration space of a virtio 1.0 net pci device would look like. Note, for legacy devices, It could be guest native endianess instead of PCI’s little-endian.
area, queue notify location, and ISR status to the driver. Below is a typical layout for the IO/Memory region mapped by the BAR. Again, for legacy device, the layout of virtio header and device specific area is quite different. For detail of the layout for legacy device, please refer to virtio 1.0 spec.
The driver needs to negotiate for the supported features with the device. And another important thing is to setup the virtqueue. It writes the virtqueue index to the queue_select field in common configuration section, and reads the virtqueue size from the queue_size field there. Then it allocates the descriptor table, available ring, and used ring in a single page, and writes the address of each part to queue_desc, queue_avail, and queue_used fields. So the device can find them. Virtqueue Data Structure Each virtqueue consists of three parts – descriptor table, available ring, and used ring. Simple virtio net device has one virtqueue for transmit and one for receive. It can also have multiple send/receive virtqueue pairs depends on the setup[3]. Each queue has a 16-bit queue size parameter, which sets the number of entries and implies the total size of the queue according to '2.4 Virtqueues' from virtio 1.0 spec. 'The descriptor table refers to the buffers the driver is using for the device. The addresses are physical addresses, and the buffers can be chained via the next field.' (from '2.4.4 The Virtqueue Descriptor Table') Actual descriptor buffers are allocated in the guest, and the addr below is GPA. KVM can locate it because it maintains a mapping between GPA and HVA. Below is a descriptor table entry.
Supplying Buffers to The Device: The buffers are put into free descriptor in the descriptor table, and multiply buffers can be chained together throught the next field of the descriptor. The index of the first descriptor in the chain is then put into the next ring entry (pointed by idx field) of the available ring. And the drive needs to increase the idx field of the available ring. If notification is on, the driver notifies the device of the new available buffers by writing to the queue notify entry in the queue notify section. Below is an example where a chain of two buffers is placed onto the available ring. Descriptor table:
The descriptor number is written to the next field (pointed by idx field) in the used ring by the device. And the used ring index (idx field) is updated by the device as well. The device sends an interrupt to guest if required according to feature negotiation and per ring flag in available ring structure. Below is an example where the above available ring is consumed and returned back. Descriptor table:
|
相关文章推荐
- 指针数组和数组指针的区别
- 虚拟机和主机ping不通解决办法
- hadoop1.X安装
- day8 - isinstance--issubclass-异常处理-自定义异常
- BZOJ4417: [Shoi2013]超级跳马
- 默认参数的构造函数
- 在Ubuntu下编程出现的Q&A
- TP框架微信支付目录
- 高效网页截图编辑插件(Web page screenshot editor)
- Codeforces--630I--Parking Lot(规律)
- LEETCODE 155
- 利用100行代码动态创建并部署流程
- NGUI相关注意事项
- Usefull Links
- 登山-C#-DataGridView在不使用数据库时,实现增加删除操作,在Row上右击可以编辑或删除
- LeapMotion+Processing+Arduino 控制LED灯的亮与灭
- iOS 关于Block的使用及循环引用
- 《C专家编程》读书笔记之第1~4章
- [Leetcode]@python 106. Construct Binary Tree from Inorder and Postorder Traversal
- 使用 CUDA范例精解通用GPU编程 配套程序的方法