VFIO 子系统架构与源码总览

VFIO 子系统架构与源码总览

1. 目标

VFIO在 IOMMU隔离下把设备安全交给可信用户进程或虚拟机:

1
2
3
4
5
6
7
8
9
userspace/QEMU
| group fd / device fd / container fd
VFIO Core
| bus driver ops
vfio-pci / vfio-platform / mdev
| DMA map
Type1 IOMMU backend
|
IOMMU domain -> hardware

2. 三个对象

  • group:最小安全隔离单位;
  • device:region、IRQ、reset、migration等;
  • container:一个或多个 group共享的 IOMMU地址空间。

Legacy ABI节点:

1
2
/dev/vfio/vfio
/dev/vfio/<group-id>

Device fd由 VFIO_GROUP_GET_DEVICE_FD返回匿名 inode。

3. 为什么是Group

若同组设备可绕过 IOMMU隔离互相 DMA,单独交出一个设备仍不安全。本树还通过 IOMMU group DMA ownership控制 container接管;组内相关设备必须脱离会发起 DMA的 host driver或由 VFIO统一管理。

4. Type1 backend

vfio_iommu_type1.c

  • attach/detach group;
    -创建/复用 iommu domain;
  • user VA pin pages;
  • IOVA映射;
  • unmap/dirty bitmap;
  • notifier;
  • DMA ownership。

5. Device driver

VFIO bus driver实现 vfio_device_ops,Core转发:

  • open/close;
  • ioctl;
  • read/write;
  • mmap;
  • request;
  • match;
  • migration/dirty feature。

6. PCI

vfio-pci导出 config space、BAR、ROM、IRQ、reset和 power state,并拦截敏感配置寄存器,不能把 config space当普通 memory直接完全透传。

7. Platform

VFIO platform导出 platform resources和 IRQ,需要可用 reset方法确保交接前后设备状态可控。

8. 安全前提

-可用 IOMMU domain;
-完整 group;
-可信 reset;
-禁止 host driver并发;
-正确 pin/account;
-中断隔离;
-无 hidden DMA path;
-用户进程拥有高权限且可信。

9. RK3588

Rockchip IOMMU主要连接 VPU/ISP/VOP/NPU等集成 IP。PCIe DTS无 iommu-map,因此不能默认安全透传 PCIe endpoint;需硬件和 DT/driver完整支持。

文章互动

阅读 --

留言

0 条留言

正在加载留言…