From: Robin Murphy <robin.murphy@arm.com>
To: Ashish Mhetre <amhetre@nvidia.com>,
will@kernel.org, joro@8bytes.org,
linux-arm-kernel@lists.infradead.org,
Rob Clark <robdclark@gmail.com>,
Boris Brezillon <boris.brezillon@collabora.com>
Cc: vdumpa@nvidia.com, linux-tegra@vger.kernel.org,
treding@nvidia.com, jonathanh@nvidia.com, iommu@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] iommu: Optimize IOMMU UnMap
Date: Thu, 23 May 2024 14:41:12 +0100 [thread overview]
Message-ID: <6b707eb4-5cf3-4b66-8152-5ba252f5df39@arm.com> (raw)
In-Reply-To: <20240523031935.90856-1-amhetre@nvidia.com>
On 23/05/2024 4:19 am, Ashish Mhetre wrote:
> The current __arm_lpae_unmap() function calls dma_sync() on individual
> PTEs after clearing them. By updating the __arm_lpae_unmap() to call
> dma_sync() once for all cleared PTEs, the overall performance can be
> improved 25% for large buffer sizes.
> Below is detailed analysis of average unmap latency(in us) with and
> without this optimization obtained by running dma_map_benchmark for
> different buffer sizes.
>
> Size Time W/O Time With % Improvement
> Optimization Optimization
> (us) (us)
>
> 4KB 3.0 3.1 -3.33
> 1MB 250.3 187.9 24.93
This seems highly suspect - the smallest possible block size is 2MB so a
1MB unmap should not be affected by this path at all.
> 2MB 493.7 368.7 25.32
> 4MB 974.7 723.4 25.78
I'm guessing this is on Tegra with the workaround to force everything to
PAGE_SIZE? In the normal case a 2MB unmap should be nominally *faster*
than 4KB, since it would also be a single PTE, but with one fewer level
of table to walk to reach it. The 25% figure is rather misleading if
it's only a mitigation of an existing erratum workaround, and the actual
impact on the majority of non-broken systems is unmeasured.
(As an aside, I think that workaround itself is a bit broken, since at
least on Tegra234 with Cortex-A78, PAGE_SIZE could be 16KB which MMU-500
doesn't support.)
> Signed-off-by: Ashish Mhetre <amhetre@nvidia.com>
> ---
> drivers/iommu/io-pgtable-arm.c | 34 +++++++++++++++++++++++++---------
> 1 file changed, 25 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c
> index 3d23b924cec1..94094b711cba 100644
> --- a/drivers/iommu/io-pgtable-arm.c
> +++ b/drivers/iommu/io-pgtable-arm.c
> @@ -256,13 +256,15 @@ static void __arm_lpae_sync_pte(arm_lpae_iopte *ptep, int num_entries,
> sizeof(*ptep) * num_entries, DMA_TO_DEVICE);
> }
>
> -static void __arm_lpae_clear_pte(arm_lpae_iopte *ptep, struct io_pgtable_cfg *cfg)
> +static void __arm_lpae_clear_pte(arm_lpae_iopte *ptep, struct io_pgtable_cfg *cfg, int num_entries)
> {
> + int i;
>
> - *ptep = 0;
> + for (i = 0; i < num_entries; i++)
> + ptep[i] = 0;
>
> if (!cfg->coherent_walk)
> - __arm_lpae_sync_pte(ptep, 1, cfg);
> + __arm_lpae_sync_pte(ptep, num_entries, cfg);
> }
>
> static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
> @@ -633,13 +635,25 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
> if (size == ARM_LPAE_BLOCK_SIZE(lvl, data)) {
> max_entries = ARM_LPAE_PTES_PER_TABLE(data) - unmap_idx_start;
> num_entries = min_t(int, pgcount, max_entries);
> -
> - while (i < num_entries) {
> - pte = READ_ONCE(*ptep);
> + arm_lpae_iopte *pte_flush;
> + int j = 0;
> +
> + pte_flush = kvcalloc(num_entries, sizeof(*pte_flush), GFP_ATOMIC);
kvmalloc() with GFP_ATOMIC isn't valid. However, I'm not sure if there
isn't a more fundamental problem here - Rob, Boris; was it just the map
path, or would any allocation on unmap risk the GPU reclaim deadlock
thing as well?
Thanks,
Robin.
> + if (pte_flush) {
> + for (j = 0; j < num_entries; j++) {
> + pte_flush[j] = READ_ONCE(ptep[j]);
> + if (WARN_ON(!pte_flush[j]))
> + break;
> + }
> + __arm_lpae_clear_pte(ptep, &iop->cfg, j);
> + }
> + while (i < (pte_flush ? j : num_entries)) {
> + pte = pte_flush ? pte_flush[i] : READ_ONCE(*ptep);
> if (WARN_ON(!pte))
> break;
>
> - __arm_lpae_clear_pte(ptep, &iop->cfg);
> + if (!pte_flush)
> + __arm_lpae_clear_pte(ptep, &iop->cfg, 1);
>
> if (!iopte_leaf(pte, lvl, iop->fmt)) {
> /* Also flush any partial walks */
> @@ -649,10 +663,12 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
> } else if (!iommu_iotlb_gather_queued(gather)) {
> io_pgtable_tlb_add_page(iop, gather, iova + i * size, size);
> }
> -
> - ptep++;
> + if (!pte_flush)
> + ptep++;
> i++;
> }
> + if (pte_flush)
> + kvfree(pte_flush);
>
> return i * size;
> } else if (iopte_leaf(pte, lvl, iop->fmt)) {
next prev parent reply other threads:[~2024-05-23 13:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-23 3:19 [RFC PATCH] iommu: Optimize IOMMU UnMap Ashish Mhetre
2024-05-23 13:41 ` Robin Murphy [this message]
2024-05-23 14:36 ` Boris Brezillon
2024-05-24 12:39 ` Ashish Mhetre
2024-05-31 9:22 ` Ashish Mhetre
2024-07-01 7:49 ` Ashish Mhetre
2024-07-03 15:35 ` Robin Murphy
2024-07-09 4:39 ` Ashish Mhetre
2024-07-09 17:01 ` Robin Murphy
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=6b707eb4-5cf3-4b66-8152-5ba252f5df39@arm.com \
--to=robin.murphy@arm.com \
--cc=amhetre@nvidia.com \
--cc=boris.brezillon@collabora.com \
--cc=iommu@lists.linux.dev \
--cc=jonathanh@nvidia.com \
--cc=joro@8bytes.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=robdclark@gmail.com \
--cc=treding@nvidia.com \
--cc=vdumpa@nvidia.com \
--cc=will@kernel.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