iommu: Add fast hook for getting DMA domains
authorRobin Murphy <robin.murphy@arm.com>
Wed, 12 Sep 2018 15:24:12 +0000 (16:24 +0100)
committerJoerg Roedel <jroedel@suse.de>
Tue, 25 Sep 2018 08:23:16 +0000 (10:23 +0200)
commit6af588fed39178c8e118fcf9cb6664e58a1fbe88
tree1d204c47e1b8e24936d8015ff6013228880dbc72
parentbee60e94a1e20ec0b8ffdafae270731d8fda4551
iommu: Add fast hook for getting DMA domains

While iommu_get_domain_for_dev() is the robust way for arbitrary IOMMU
API callers to retrieve the domain pointer, for DMA ops domains it
doesn't scale well for large systems and multi-queue devices, since the
momentary refcount adjustment will lead to exclusive cacheline contention
when multiple CPUs are operating in parallel on different mappings for
the same device.

In the case of DMA ops domains, however, this refcounting is actually
unnecessary, since they already imply that the group exists and is
managed by platform code and IOMMU internals (by virtue of
iommu_group_get_for_dev()) such that a reference will already be held
for the lifetime of the device. Thus we can avoid the bottleneck by
providing a fast lookup specifically for the DMA code to retrieve the
default domain it already knows it has set up - a simple read-only
dereference plays much nicer with cache-coherency protocols.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Tested-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/iommu.c
include/linux/iommu.h