VFIO Core、设备组与 Container 模型

VFIO Core、设备组与 Container 模型

1. Device注册

VFIO driver:

1
2
3
4
5
6
7
vfio_init_group_dev()
-> initialize vfio_device/ref/completion
vfio_register_group_dev()
-> obtain iommu_group
-> create/find vfio_group
-> add device
-> create group cdev

现代 helper也可组合初始化/注册。

2. Group类型

包括正常 IOMMU group和 no-IOMMU/emulated等类型。类型影响 viable、container attach和安全语义。

3. Group节点

Core为 group创建字符设备,通常由 udev生成 /dev/vfio/N。Group fd处理:

  • GET_STATUS;
  • SET/UNSET_CONTAINER;
  • GET_DEVICE_FD。

4. Viable

本树 VFIO_GROUP_GET_STATUS在 group尚未挂 container时,以 IOMMU group的 DMA ownership是否已被其它主体 claim判断 viable;挂入 container后同时报告 container-set和 viable。实际部署仍必须确保组内相关设备已解绑 host DMA driver或由 VFIO接管。Bridge、multifunction function或同组设备遗漏可能阻止安全使用。

5. Container

打开 /dev/vfio/vfio获得 container fd:

1
2
3
VFIO_GET_API_VERSION
VFIO_CHECK_EXTENSION
VFIO_SET_IOMMU

Group通过 SET_CONTAINER挂入。多个 group可在兼容 domain条件下共享 container/IOVA空间。

6. Device fd

GET_DEVICE_FD:

-按 name查 group device;
-检查 viable/container;

  • open device;
    -创建 anon inode fd;
    -持有 device/group/container引用。

7. Open count

Core在首次 open调用 device open_device,最后 release调用 close_device。Device set可协调一组相关 device的打开计数和锁。

8. Unregister

Driver remove先阻止新打开,等待现有引用关闭,再从 group移除。若用户仍持 fd,错误的 remove顺序可能死锁或 use-after-free。

9. 锁

Group/container/device分别有 mutex/refcount;设备 open、group attach、driver unregister和 DMA map可并发。锁顺序必须遵循 Core路径。

10. 隔离含义

Group只是 IOMMU拓扑给出的最小边界,不保证 reset、interrupt remapping、firmware或 peer-to-peer路径一定安全;VFIO还依赖平台硬件质量。

文章互动

阅读 --

留言

0 条留言

正在加载留言…