This patch adds a pair of callbacks of iommu_set_nesting_vmid() and iommu_get_nesting_vmid() to exchange VMID with the IOMMU core (then an IOMMU driver). As a VMID is generated in an IOMMU driver, which is called from the vfio_iommu_attach_group() function call, add iommu_get_nesting_vmid right after it creates a VMID and add iommu_set_nesting_vmid before it to let IOMMU driver reuse it. Signed-off-by: Nicolin Chen <nicolinc@xxxxxxxxxx> --- drivers/vfio/vfio_iommu_type1.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index bb5d949bc1af..9e72d74dedcd 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -2322,12 +2322,24 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, ret = iommu_enable_nesting(domain->domain); if (ret) goto out_domain; + + if (iommu->vmid != VFIO_IOMMU_VMID_INVALID) { + ret = iommu_set_nesting_vmid(domain->domain, iommu->vmid); + if (ret) + goto out_domain; + } } ret = vfio_iommu_attach_group(domain, group); if (ret) goto out_domain; + if (iommu->nesting && iommu->vmid == VFIO_IOMMU_VMID_INVALID) { + ret = iommu_get_nesting_vmid(domain->domain, &iommu->vmid); + if (ret) + goto out_domain; + } + /* Get aperture info */ geo = &domain->domain->geometry; if (vfio_iommu_aper_conflict(iommu, geo->aperture_start, -- 2.17.1