Commit f4bae29
committed
vfio-ioctls: Support hardware-accelerated nested HWPT via iommufd
Add infrastructure to enable VFIO devices to leverage hardware IOMMU
acceleration through iommufd's uAPIs. This allows userspace VMMs to
attach VFIO devices to hardware-accelerated virtual IOMMUs, particularly
enabling userspace to configure stage-1 (guest-managed) page tables that
are composed with stage-2 (host-managed) page tables in hardware.
This depends on the IommufdVIOMMU and IommufdVDevice abstractions
introduced in the iommufd-ioctls crate [1].
New Public Interfaces:
1. VfioIommufd::new() signature change:
- Added `s1_hwpt_data_type: Option<iommu_hwpt_data_type>` parameter
- When `Some`, enables nested translation mode for subsequently attached
VFIO devices
- Supported types: IOMMU_HWPT_DATA_ARM_SMMUV3, IOMMU_HWPT_DATA_VTD_S1
2. VfioDevice::new_with_iommufd():
- New constructor for vfio devices backed by iommufd with
hardware-accelerated nested HWPT support
- Automatically creates IommufdVIommu/IommufdVDevice when nested mode
is enabled via `VfioIommufd`
- Supports sharing a single `IommufdVIommu` instance across multiple
VFIO devices
- Returns `IommufdVDevice` handle for subsequent S1 HWPT operations
- Attaches device to bypass HWPT by default (until guest enables IOMMU)
3. VfioDevice::install_s1_hwpt():
- Install guest-configured stage-1 page tables into hardware
- Called when guest writes to virtual IOMMU stream table entries
- Atomically replaces existing S1 HWPT if present
- Uses `IommufdHwptData` enum for type-safe hardware-specific configuration
4. VfioDevice::uninstall_s1_hwpt():
- Revert device to bypass or abort mode
- abort=true: Use abort HWPT (fault all DMA)
- abort=false: Use bypass HWPT (passthrough translation)
- Called during guest IOMMU reset or shutdown
Dependencies on iommufd-ioctls:
This implementation builds upon three types from iommufd-ioctls [1]:
- `IommufdVIommu`: Represents a physical IOMMU slice managing S2 HWPT
and default S1 HWPTs (bypass/abort). Shared across devices behind the
same virtual IOMMU.
- `IommufdVDevice`: Represents a device attached to a `IommufdVIommu`.
Handles dynamic S1 HWPT allocation and lifecycle management.
- `IommufdHwptData`: Type-safe enum for architecture-specific HWPT
configuration (SMMUv3 STE data, VT-d context entries).
Integration Notes for VMMs:
1. VMM creates `VfioIommufd` with `s1_hwpt_data_type` if hardware
accelerated virtual IOMMUs are enabled and used to manage
VFIO devices
2. VMM calls `VfioDevice::new_with_iommufd()` per passthrough device
- The same instance of virtual IOMMU should reuse the same instance
of `IommufdVIommu`
- Each VFIO device will has its own `VfioDevice` and `IommufdVDevice`
instance
3. VMM need to make sure the virtual IOMMU is compatible with the
physical IOMMU:
- `IommufdVDevice::get_hw_info` is used to retrieve hardware
information of the physical IOMMU
3. VMM traps guest IOMMU commands and calls:
- `install_s1_hwpt()` when guest enables IOMMU
- `uninstall_s1_hwpt()` when guest disables IOMMU
- `IommufdVIommu::invalidate_hwpt()` when guest invalidate IOTLB
entries
This enables VMM to enable hardware-accelerated IOMMU to manage VFIO
devices and use physical IOMMU hardware to directly process guest page
tables.
[1] cloud-hypervisor/iommufd#5
Signed-off-by: Bo Chen <bchen@crusoe.ai>1 parent c437d21 commit f4bae29
3 files changed
+212
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
| 39 | + | |
| 40 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
170 | 185 | | |
171 | 186 | | |
172 | 187 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
561 | 561 | | |
562 | 562 | | |
563 | 563 | | |
| 564 | + | |
564 | 565 | | |
565 | 566 | | |
566 | 567 | | |
| |||
572 | 573 | | |
573 | 574 | | |
574 | 575 | | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
575 | 579 | | |
576 | 580 | | |
577 | 581 | | |
578 | 582 | | |
| 583 | + | |
579 | 584 | | |
580 | 585 | | |
581 | 586 | | |
| |||
599 | 604 | | |
600 | 605 | | |
601 | 606 | | |
| 607 | + | |
602 | 608 | | |
603 | 609 | | |
604 | 610 | | |
| |||
1120 | 1126 | | |
1121 | 1127 | | |
1122 | 1128 | | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
1123 | 1317 | | |
1124 | 1318 | | |
1125 | 1319 | | |
| |||
0 commit comments