vhost net

Stefan Hajnoczi - QEMU Internals: vhost architecture

  • overview

    • vhost driver provide in-kernel virtio devices for KVM. compare to QEMU, it can directly call into kernel subsystem without system call.

    • vhost-net driver emulate virtio network card in the host kernel. (driver/vhost/)

  • driver model

    • /dev/vhost-net, QEMU open and init it if parameter has -netdev tap,vhost=on

    • vhost-worker-thread (vhost-<pid>): (1) handle IO event (2) perform device emulation

      • create at initialization time.

  • in-kernel virtio emulation

    • vhost doesn’t emulate complete virtio PCI adapter, it restrict itself to virtqueue ops only.

    • vhost worker thread do IO:

      • wait virtqueue kick, recieve packet from tx virtqueue. transmit over tap fd.

      • do fd polling, wake up when packets come in over the tap fd. place packets to rx virtqueue

  • vhost as a userspace interface

    • guest kick host 時, 需要有個方法通知 vhost worker thread.

    • virtio 不依賴 KVM module. 所以要透過 eventfd 來通知.

    • ioeventfd:

    • irqfd: allow eventfd to trigger guest interrupts