public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Nadav Amit <nadav.amit@gmail.com>, Joerg Roedel <joro@8bytes.org>
Cc: Will Deacon <will@kernel.org>, Jiajun Cao <caojiajun@vmware.com>,
	iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 0/4] iommu/amd: Enable page-selective flushes
Date: Fri, 4 Jun 2021 19:53:31 +0100	[thread overview]
Message-ID: <2ea809ef-beb5-a2c9-0739-cb236cab196b@arm.com> (raw)
In-Reply-To: <05098022-1ED6-44BE-931D-D16C2D0B2D09@gmail.com>

On 2021-06-04 18:10, Nadav Amit wrote:
> 
> 
>> On Jun 4, 2021, at 8:38 AM, Joerg Roedel <joro@8bytes.org> wrote:
>>
>> Hi Nadav,
>>
>> [Adding Robin]
>>
>> On Mon, May 24, 2021 at 03:41:55PM -0700, Nadav Amit wrote:
>>> Nadav Amit (4):
>>>   iommu/amd: Fix wrong parentheses on page-specific invalidations
>>
>> This patch is already upstream in v5.13-rc4. Please rebase to that
>> version.
> 
> I guess it would be rc5 by the time I send it.
> 
>>
>>>   iommu/amd: Selective flush on unmap
>>>   iommu/amd: Do not sync on page size changes
>>>   iommu/amd: Do not use flush-queue when NpCache is on
>>
>> And I think there have been objections from Robin Murphy on Patch 3,
>> have those been worked out?
> 
> I am still waiting for Robin’s feedback on my proposed changes. If he does not respond soon, I will drop this patch for now.

Apologies, it feels like I've spent most of this week fighting fires,
and a great deal of email got skimmed and mentally filed under "nothing
so wrong that I need to respond immediately"...

FWIW I would have written the simpler patch below, but beyond that I
think it might start descending into bikeshedding - if you still prefer
your more comprehensive refactoring, or something in between, then don't
let my personal preference in style/complexity trade-offs stand in the
way of getting a useful functional change into the AMD driver. Whichever
way, though, I *am* now sold on the idea of having some kerneldoc to
clarify these things.

Thanks,
Robin.

----->8-----
From: Robin Murphy <robin.murphy@arm.com>
Subject: [PATCH] iommu: Improve iommu_iotlb_gather helpers

The Mediatek driver is not the only one which might want a basic
address-based gathering behaviour, so although it's arguably simple
enough to open-code, let's factor it out for the sake of cleanliness.
Let's also take this opportunity to document the intent of these
helpers for clarity.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
  drivers/iommu/mtk_iommu.c |  6 +-----
  include/linux/iommu.h     | 32 ++++++++++++++++++++++++++++++++
  2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index e06b8a0e2b56..cd457487ce81 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -521,12 +521,8 @@ static size_t mtk_iommu_unmap(struct iommu_domain *domain,
  			      struct iommu_iotlb_gather *gather)
  {
  	struct mtk_iommu_domain *dom = to_mtk_domain(domain);
-	unsigned long end = iova + size - 1;
  
-	if (gather->start > iova)
-		gather->start = iova;
-	if (gather->end < end)
-		gather->end = end;
+	iommu_iotlb_gather_add_range(gather, iova, size);
  	return dom->iop->unmap(dom->iop, iova, size, gather);
  }
  
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 32d448050bf7..5f036e991937 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -497,6 +497,38 @@ static inline void iommu_iotlb_sync(struct iommu_domain *domain,
  	iommu_iotlb_gather_init(iotlb_gather);
  }
  
+/**
+ * iommu_iotlb_gather_add_range - Gather for address-based TLB invalidation
+ * @gather: TLB gather data
+ * @iova: start of page to invalidate
+ * @size: size of page to invalidate
+ *
+ * Helper for IOMMU drivers to build arbitrarily-sized invalidation commands
+ * where only the address range matters, and simply minimising intermediate
+ * syncs is preferred.
+ */
+static inline void iommu_iotlb_gather_add_range(struct iommu_iotlb_gather *gather,
+						unsigned long iova, size_t size)
+{
+	unsigned long end = iova + size - 1;
+
+	if (gather->start > iova)
+		gather->start = iova;
+	if (gather->end < end)
+		gather->end = end;
+}
+
+/**
+ * iommu_iotlb_gather_add_page - Gather for page-based TLB invalidation
+ * @domain: IOMMU domain to be invalidated
+ * @gather: TLB gather data
+ * @iova: start of page to invalidate
+ * @size: size of page to invalidate
+ *
+ * Helper for IOMMU drivers to build invalidation commands based on individual
+ * pages, or with page size/table level hints which cannot be gathered if they
+ * differ.
+ */
  static inline void iommu_iotlb_gather_add_page(struct iommu_domain *domain,
  					       struct iommu_iotlb_gather *gather,
  					       unsigned long iova, size_t size)
-- 
2.25.1

  reply	other threads:[~2021-06-04 18:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-24 22:41 [PATCH v2 0/4] iommu/amd: Enable page-selective flushes Nadav Amit
2021-05-24 22:41 ` [PATCH v2 1/4] iommu/amd: Fix wrong parentheses on page-specific invalidations Nadav Amit
2021-05-24 22:41 ` [PATCH v2 2/4] iommu/amd: Selective flush on unmap Nadav Amit
2021-05-24 22:41 ` [PATCH v2 3/4] iommu/amd: Do not sync on page size changes Nadav Amit
2021-05-24 22:41 ` [PATCH v2 4/4] iommu/amd: Do not use flush-queue when NpCache is on Nadav Amit
2021-06-04 15:38 ` [PATCH v2 0/4] iommu/amd: Enable page-selective flushes Joerg Roedel
2021-06-04 17:10   ` Nadav Amit
2021-06-04 18:53     ` Robin Murphy [this message]
2021-06-04 19:57       ` Nadav Amit

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=2ea809ef-beb5-a2c9-0739-cb236cab196b@arm.com \
    --to=robin.murphy@arm.com \
    --cc=caojiajun@vmware.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nadav.amit@gmail.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