From: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
To: John Garry <john.garry-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>,
joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org,
will.deacon-5wv7dgnIgG8@public.gmane.org,
catalin.marinas-5wv7dgnIgG8@public.gmane.org
Cc: linuxarm-hv44wF8Li93QT0dZR+AlfA@public.gmane.org,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
guohanjun-hv44wF8Li93QT0dZR+AlfA@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH 1/3] iommu: Add fast hook for getting DMA domains
Date: Fri, 17 Aug 2018 12:11:57 +0100 [thread overview]
Message-ID: <29a126d2-4bbe-1750-5265-d3dbfcb658ae@arm.com> (raw)
In-Reply-To: <d31ca4b3-5cb3-8ba3-485b-3fee58807cae-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
On 17/08/18 10:36, John Garry wrote:
> On 14/08/2018 14:04, Robin Murphy wrote:
>> 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-5wv7dgnIgG8@public.gmane.org>
>> ---
>> drivers/iommu/iommu.c | 9 +++++++++
>> include/linux/iommu.h | 1 +
>> 2 files changed, 10 insertions(+)
>>
>> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
>> index 63b37563db7e..63c586875df5 100644
>> --- a/drivers/iommu/iommu.c
>> +++ b/drivers/iommu/iommu.c
>> @@ -1379,6 +1379,15 @@ struct iommu_domain
>> *iommu_get_domain_for_dev(struct device *dev)
>> }
>> EXPORT_SYMBOL_GPL(iommu_get_domain_for_dev);
>>
>> +/*
>> + * For IOMMU_DOMAIN_DMA implementations which already provide their own
>> + * guarantees that the group and its default domain are valid and
>> correct.
>> + */
>> +struct iommu_domain *iommu_get_dma_domain(struct device *dev)
>> +{
>> + return dev->iommu_group->default_domain;
>> +}
>> +
>> /*
>> * IOMMU groups are really the natrual working unit of the IOMMU, but
>> * the IOMMU API works on domains and devices. Bridge that gap by
>> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
>> index 19938ee6eb31..16f2172698e5 100644
>> --- a/include/linux/iommu.h
>> +++ b/include/linux/iommu.h
>> @@ -297,6 +297,7 @@ extern int iommu_attach_device(struct iommu_domain
>> *domain,
>> extern void iommu_detach_device(struct iommu_domain *domain,
>> struct device *dev);
>> extern struct iommu_domain *iommu_get_domain_for_dev(struct device
>> *dev);
>> +extern struct iommu_domain *iommu_get_dma_domain(struct device *dev);
>
> Hi Robin,
>
> I was wondering whether it's standard to provide a stubbed version of
> this function for !CONFIG_IOMMU_API?
Nope, that's deliberate - this is one of those hooks where any
legitimate caller will already be dependent on IOMMU_API itself.
Robin.
>
> Cheers,
> John
>
>> extern int iommu_map(struct iommu_domain *domain, unsigned long iova,
>> phys_addr_t paddr, size_t size, int prot);
>> extern size_t iommu_unmap(struct iommu_domain *domain, unsigned long
>> iova,
>>
>
>
next prev parent reply other threads:[~2018-08-17 11:11 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-14 13:04 [PATCH 0/3] iommu: Avoid DMA ops domain refcount contention Robin Murphy
[not found] ` <cover.1534250425.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2018-08-14 13:04 ` [PATCH 1/3] iommu: Add fast hook for getting DMA domains Robin Murphy
2018-08-17 9:36 ` John Garry
[not found] ` <d31ca4b3-5cb3-8ba3-485b-3fee58807cae-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2018-08-17 11:11 ` Robin Murphy [this message]
[not found] ` <4d50587e62c16f7b5cfc45dee808d774655155cf.1534250425.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2018-08-17 15:27 ` Laurentiu Tudor
2018-08-14 13:04 ` [PATCH 2/3] iommu/dma: Use fast DMA domain lookup Robin Murphy
2018-08-14 13:04 ` [PATCH 3/3] arm64/dma-mapping: Mildly optimise non-coherent IOMMU ops Robin Murphy
[not found] ` <52b017ead032f90e5f2b70b87747a49eb86209c8.1534250425.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2018-08-20 15:41 ` Robin Murphy
2018-08-14 13:38 ` [PATCH 0/3] iommu: Avoid DMA ops domain refcount contention John Garry
2018-08-17 13:03 ` John Garry
2018-08-17 7:24 ` Christoph Hellwig
[not found] ` <20180817072415.GA22241-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2018-08-17 9:03 ` Will Deacon
2018-08-17 11:30 ` Robin Murphy
2018-08-17 12:01 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=29a126d2-4bbe-1750-5265-d3dbfcb658ae@arm.com \
--to=robin.murphy-5wv7dgnigg8@public.gmane.org \
--cc=catalin.marinas-5wv7dgnIgG8@public.gmane.org \
--cc=guohanjun-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=john.garry-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
--cc=joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linuxarm-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
--cc=will.deacon-5wv7dgnIgG8@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox