Virtio(Virtual I/O)

It is a paravirtualized I/O solution that implements a set of communication framework for I/O interaction between guest applications and hypervisor. Compared to full-virtualized devices which uses trap for actual I/O operations, paravirtualized devices can reduce a lot of wasted cycles with direct communication between guest and host, hence it is faster.

Untitled

相比于全虚拟化通过特权指令的捕获(vmexit)

// Kernels device communication with VMware (emulated, full-virtualization):
void nic_write_buffer(char *buf, int size) {
  for (; size > 0; size--) {
    nic_poll_ready();               // many traps
    outb(NIC_TX_BUF, *buf++);       // many traps
  }
}

// Kernels device communication with hypervisor (hypercall, para-virtualization):
void nic_write_buffer(char *buf, int size) {
  vmm_write(NIC_TX_BUF, buf, size); // one trap
}

Architecture

Untitled

Untitled

Virtio spec

参考文献

https://insujang.github.io/2021-03-10/virtio-and-vhost-architecture-part-1/