We can't always support mmap across an entire device region, for example we deny mmaps covering the MSI-X table of PCI devices, but we don't really have a way to report it. We expect the user to implicitly know this restriction. We also can't split the region because vfio-pci defines an API with fixed region index to BAR number mapping. We therefore define a new capability which lists areas within the region that may be mmap'd. In addition to the MSI-X case, this potentially enables in-kernel emulation and extensions to devices.
Unified · Split
| @@ -221,13 +221,37 @@ struct vfio_region_info { · 220 unmodified lines | ||
| 221 | 221 | #define VFIO_REGION_INFO_FLAG_READ (1 << 0) /* Region supports read */ |
| 222 | 222 | #define VFIO_REGION_INFO_FLAG_WRITE (1 << 1) /* Region supports write */ |
| 223 | 223 | #define VFIO_REGION_INFO_FLAG_MMAP (1 << 2) /* Region supports mmap */ |
| 224 | +#define VFIO_REGION_INFO_FLAG_CAPS (1 << 3) /* Info supports caps */ | |
| 224 | 225 | __u32 index; /* Region index */ |
| 225 | − __u32 resv; /* Reserved for alignment */ | |
| 226 | + __u32 cap_offset; /* Offset within info struct of first cap */ | |
| 226 | 227 | __u64 size; /* Region size (bytes) */ |
| 227 | 228 | __u64 offset; /* Region offset from start of device fd */ |
| 228 | 229 | }; |
| 229 | 230 | #define VFIO_DEVICE_GET_REGION_INFO _IO(VFIO_TYPE, VFIO_BASE + 8) |
| 230 | 231 | |
| 232 | +/* | |
| 233 | + * The sparse mmap capability allows finer granularity of specifying areas | |
| 234 | + * within a region with mmap support. When specified, the user should only | |
| 235 | + * mmap the offset ranges specified by the areas array. mmaps outside of the | |
| 236 | + * areas specified may fail (such as the range covering a PCI MSI-X table) or | |
| 237 | + * may result in improper device behavior. | |
| 238 | + * | |
| 239 | + * The structures below define version 1 of this capability. | |
| 240 | + */ | |
| 241 | +#define VFIO_REGION_INFO_CAP_SPARSE_MMAP 1 | |
| 242 | + | |
| 243 | +struct vfio_region_sparse_mmap_area { | |
| 244 | + __u64 offset; /* Offset of mmap'able area within region */ | |
| 245 | + __u64 size; /* Size of mmap'able area */ | |
| 246 | +}; | |
| 247 | + | |
| 248 | +struct vfio_region_info_cap_sparse_mmap { | |
| 249 | + struct vfio_info_cap_header header; | |
| 250 | + __u32 nr_areas; | |
| 251 | + __u32 reserved; | |
| 252 | + struct vfio_region_sparse_mmap_area areas[]; | |
| 253 | +}; | |
| 254 | + | |
| 231 | 255 | /** |
| 232 | 256 | * VFIO_DEVICE_GET_IRQ_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 9, |
| 233 | 257 | * struct vfio_irq_info) |