]> git.baikalelectronics.ru Git - kernel.git/commit
iommu/vt-d: Fix VM domain ID leak
authorAlex Williamson <alex.williamson@redhat.com>
Tue, 14 Jul 2015 20:48:53 +0000 (14:48 -0600)
committerJoerg Roedel <jroedel@suse.de>
Thu, 23 Jul 2015 12:17:39 +0000 (14:17 +0200)
commit22a0bc52924e48dc1d0954b698cc1c613a6c5a98
treedc37a623c47ba0aa7a09ca6702faf59ac93e13dd
parentb0996bb4429bfed0bc9c246daf4e0da0f84a1ccf
iommu/vt-d: Fix VM domain ID leak

This continues the attempt to fix commit 93f4611b3270 ("iommu/vt-d:
Introduce helper functions to make code symmetric for readability").
The previous attempt in commit 0354e1a8d1fe ("iommu/vt-d: Detach
domain *only* from attached iommus") overlooked the fact that
dmar_domain.iommu_bmp gets cleared for VM domains when devices are
detached:

intel_iommu_detach_device
  domain_remove_one_dev_info
    domain_detach_iommu

The domain is detached from the iommu, but the iommu is still attached
to the domain, for whatever reason.  Thus when we get to domain_exit(),
we can't rely on iommu_bmp for VM domains to find the active iommus,
we must check them all.  Without that, the corresponding bit in
intel_iommu.domain_ids doesn't get cleared and repeated VM domain
creation and destruction will run out of domain IDs.  Meanwhile we
still can't call iommu_detach_domain() on arbitrary non-VM domains or
we risk clearing in-use domain IDs, as 0354e1a8d1fe attempted to
address.

It's tempting to modify iommu_detach_domain() to test the domain
iommu_bmp, but the call ordering from domain_remove_one_dev_info()
prevents it being able to work as 93f4611b3270 seems to have intended.
Caching of unused VM domains on the iommu object seems to be the root
of the problem, but this code is far too fragile for that kind of
rework to be proposed for stable, so we simply revert this chunk to
its state prior to 93f4611b3270.

Fixes: 93f4611b3270 ("iommu/vt-d: Introduce helper functions to make
                      code symmetric for readability")
Fixes: 0354e1a8d1fe ("iommu/vt-d: Detach domain *only* from attached
                      iommus")
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Cc: Jiang Liu <jiang.liu@linux.intel.com>
Cc: stable@vger.kernel.org # v3.17+
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/intel-iommu.c