@@ -1080,9 +1080,21 @@ static int __vfio_container_attach_groups(struct vfio_container *container,
int ret = -ENODEV;
list_for_each_entry(group, &container->group_list, container_next) {
+ if (driver->ops->set_vmid && container->vmid != VFIO_IOMMU_VMID_INVALID) {
+ ret = driver->ops->set_vmid(data, container->vmid);
+ if (ret)
+ goto unwind;
+ }
+
ret = driver->ops->attach_group(data, group->iommu_group);
if (ret)
goto unwind;
+
+ if (driver->ops->get_vmid && container->vmid == VFIO_IOMMU_VMID_INVALID) {
+ ret = driver->ops->get_vmid(data, &container->vmid);
+ if (ret)
+ goto unwind;
+ }
}
return ret;
@@ -126,6 +126,8 @@ struct vfio_iommu_driver_ops {
struct iommu_group *group);
void (*notify)(void *iommu_data,
enum vfio_iommu_notify_type event);
+ int (*set_vmid)(void *iommu_data, u32 vmid);
+ int (*get_vmid)(void *iommu_data, u32 *vmid);
};
extern int vfio_register_iommu_driver(const struct vfio_iommu_driver_ops *ops);
A VMID is generated in an IOMMU driver, being called from this ->attach_group() callback. So call ->get_vmid() right after it creates a new VMID, and call ->set_vmid() before it, to let it reuse the same VMID. Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> --- drivers/vfio/vfio.c | 12 ++++++++++++ include/linux/vfio.h | 2 ++ 2 files changed, 14 insertions(+)