virtio中guest notifier和host notifier为什么分别使用ioeventfd和irqfd?

In virtio, why does guest notifier and host notifier use ioeventfd and irqfd respectively?

我知道在 virtio 中,当来宾尝试通知主机时,它会写入设备 io 地址,这会导致 vm 退出并被管理程序捕获。写入操作将向 eventfd 结构发出信号,然后唤醒休眠的 vhost_worker 线程来处理 virtqueue 中的数据包。

当主机尝试通知客户机时,它也使用 eventfd 触发中断注入并需要 vm-exit。

我的问题是:这两个过程有必要这么复杂吗?我们为什么不把一个 eventfd 结构放到 virtio 前端和后端之间的共享内存中。然后如果一个guest试图通知host,它向eventfd发出信号,然后vhost_worker线程被唤醒,这似乎我们不需要vm-exit。对于访客通知者,可以用同样的方式完成。 为什么我们不能以这种简单的方式通知?

My question is: does these two process have to be so complicated?

简短回答:因为虚拟机很复杂。 :)

Why don't we just put a eventfd struct into the shared memory between virtio front-end and back-end.

顺便说一句,eventfd 不是结构。它只是一个整数,就像任何其他文件描述符一样。

Then if a guest try to notify the host, it signals to the eventfd…

它不能那样做。写入 eventfd 需要来宾内核在主机系统上进行系统调用,这不是它能够做的事情。类似地,主机无法向来宾内核创建的 eventfd 发送信号,因为主机系统上不存在 eventfd。

还要记住,来宾系统可能不是 运行 一个 Linux 内核! virtio 接口不是特定于内核的;它旨在适用于任何虚拟化 OS.