linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu/io-pgtable: Abstract iommu_iotlb_gather access
@ 2021-08-20 13:14 Robin Murphy
  2021-08-20 15:19 ` Joerg Roedel
  2021-08-24 13:55 ` Geert Uytterhoeven
  0 siblings, 2 replies; 5+ messages in thread
From: Robin Murphy @ 2021-08-20 13:14 UTC (permalink / raw)
  To: will, joro; +Cc: iommu, linux-arm-kernel, kernel test robot

Previously io-pgtable merely passed the iommu_iotlb_gather pointer
through to helpers, but now it has grown its own direct dereference.
This turns out to break the build for !IOMMU_API configs where the
structure only has a dummy definition. It will probably also crash
drivers who don't use the gather mechanism and simply pass in NULL.

Wrap this dereference in a suitable helper which can both be stubbed
out for !IOMMU_API and encapsulate a NULL check otherwise.

Fixes: 7a7c5badf858 ("iommu: Indicate queued flushes via gather data")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
 drivers/iommu/io-pgtable-arm-v7s.c |  2 +-
 drivers/iommu/io-pgtable-arm.c     |  2 +-
 include/linux/iommu.h              | 10 ++++++++++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c
index e84478d39705..bfb6acb651e5 100644
--- a/drivers/iommu/io-pgtable-arm-v7s.c
+++ b/drivers/iommu/io-pgtable-arm-v7s.c
@@ -700,7 +700,7 @@ static size_t __arm_v7s_unmap(struct arm_v7s_io_pgtable *data,
 						ARM_V7S_BLOCK_SIZE(lvl + 1));
 				ptep = iopte_deref(pte[i], lvl, data);
 				__arm_v7s_free_table(ptep, lvl + 1, data);
-			} else if (!gather->queued) {
+			} else if (!iommu_iotlb_gather_queued(gather)) {
 				io_pgtable_tlb_add_page(iop, gather, iova, blk_size);
 			}
 			iova += blk_size;
diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c
index 9e3beace0470..dd9e47189d0d 100644
--- a/drivers/iommu/io-pgtable-arm.c
+++ b/drivers/iommu/io-pgtable-arm.c
@@ -650,7 +650,7 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
 				io_pgtable_tlb_flush_walk(iop, iova + i * size, size,
 							  ARM_LPAE_GRANULE(data));
 				__arm_lpae_free_pgtable(data, lvl + 1, iopte_deref(pte, data));
-			} else if (!gather->queued) {
+			} else if (!iommu_iotlb_gather_queued(gather)) {
 				io_pgtable_tlb_add_page(iop, gather, iova + i * size, size);
 			}
 
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index e7581c39f2df..6633040a13f9 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -594,6 +594,11 @@ static inline void iommu_iotlb_gather_add_page(struct iommu_domain *domain,
 	iommu_iotlb_gather_add_range(gather, iova, size);
 }
 
+static inline bool iommu_iotlb_gather_queued(struct iommu_iotlb_gather *gather)
+{
+	return gather && gather->queued;
+}
+
 /* PCI device grouping function */
 extern struct iommu_group *pci_device_group(struct device *dev);
 /* Generic device grouping function */
@@ -942,6 +947,11 @@ static inline void iommu_iotlb_gather_add_page(struct iommu_domain *domain,
 {
 }
 
+static inline bool iommu_iotlb_gather_queued(struct iommu_iotlb_gather *gather)
+{
+	return false;
+}
+
 static inline void iommu_device_unregister(struct iommu_device *iommu)
 {
 }
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] iommu/io-pgtable: Abstract iommu_iotlb_gather access
  2021-08-20 13:14 [PATCH] iommu/io-pgtable: Abstract iommu_iotlb_gather access Robin Murphy
@ 2021-08-20 15:19 ` Joerg Roedel
  2021-08-24 13:55 ` Geert Uytterhoeven
  1 sibling, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2021-08-20 15:19 UTC (permalink / raw)
  To: Robin Murphy; +Cc: will, iommu, linux-arm-kernel, kernel test robot

On Fri, Aug 20, 2021 at 02:14:42PM +0100, Robin Murphy wrote:
>  drivers/iommu/io-pgtable-arm-v7s.c |  2 +-
>  drivers/iommu/io-pgtable-arm.c     |  2 +-
>  include/linux/iommu.h              | 10 ++++++++++
>  3 files changed, 12 insertions(+), 2 deletions(-)

Applied, thanks Robin.


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iommu/io-pgtable: Abstract iommu_iotlb_gather access
  2021-08-20 13:14 [PATCH] iommu/io-pgtable: Abstract iommu_iotlb_gather access Robin Murphy
  2021-08-20 15:19 ` Joerg Roedel
@ 2021-08-24 13:55 ` Geert Uytterhoeven
  2021-08-24 15:33   ` Robin Murphy
  1 sibling, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2021-08-24 13:55 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Will Deacon, Joerg Roedel, Linux IOMMU, Linux ARM,
	kernel test robot, Linux-Renesas

Hi Robin,

On Fri, Aug 20, 2021 at 3:22 PM Robin Murphy <robin.murphy@arm.com> wrote:
> Previously io-pgtable merely passed the iommu_iotlb_gather pointer
> through to helpers, but now it has grown its own direct dereference.
> This turns out to break the build for !IOMMU_API configs where the
> structure only has a dummy definition. It will probably also crash
> drivers who don't use the gather mechanism and simply pass in NULL.
>
> Wrap this dereference in a suitable helper which can both be stubbed
> out for !IOMMU_API and encapsulate a NULL check otherwise.
>
> Fixes: 7a7c5badf858 ("iommu: Indicate queued flushes via gather data")

Is this the right Fixes tag?

The build issue was introduced by:
Fixes: a8e5f04458c4e496 ("iommu/io-pgtable: Remove non-strict quirk")

> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>

Thanks, this fixes the build issues I was seeing.

Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iommu/io-pgtable: Abstract iommu_iotlb_gather access
  2021-08-24 13:55 ` Geert Uytterhoeven
@ 2021-08-24 15:33   ` Robin Murphy
  2021-08-25 15:43     ` Joerg Roedel
  0 siblings, 1 reply; 5+ messages in thread
From: Robin Murphy @ 2021-08-24 15:33 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Will Deacon, Joerg Roedel, Linux IOMMU, Linux ARM,
	kernel test robot, Linux-Renesas

On 2021-08-24 14:55, Geert Uytterhoeven wrote:
> Hi Robin,
> 
> On Fri, Aug 20, 2021 at 3:22 PM Robin Murphy <robin.murphy@arm.com> wrote:
>> Previously io-pgtable merely passed the iommu_iotlb_gather pointer
>> through to helpers, but now it has grown its own direct dereference.
>> This turns out to break the build for !IOMMU_API configs where the
>> structure only has a dummy definition. It will probably also crash
>> drivers who don't use the gather mechanism and simply pass in NULL.
>>
>> Wrap this dereference in a suitable helper which can both be stubbed
>> out for !IOMMU_API and encapsulate a NULL check otherwise.
>>
>> Fixes: 7a7c5badf858 ("iommu: Indicate queued flushes via gather data")
> 
> Is this the right Fixes tag?

Conceptually, yes - that's where the new member was introduced, so 
that's where its accessor should have been introduced as well, had I not 
managed to overlook the structure being conditionally defined and assume 
it didn't need anything special doing. Of course it's not going to make 
much difference in practice since they are immediately adjacent commits 
anyway, but it felt right to point at where I made the fundamental 
mistake rather than where the symptom appeared :)

> The build issue was introduced by:
> Fixes: a8e5f04458c4e496 ("iommu/io-pgtable: Remove non-strict quirk")
> 
>> Reported-by: kernel test robot <lkp@intel.com>
>> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> 
> Thanks, this fixes the build issues I was seeing.
> 
> Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>

Thanks for confirming!

Robin.

> 
> Gr{oetje,eeting}s,
> 
>                          Geert
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iommu/io-pgtable: Abstract iommu_iotlb_gather access
  2021-08-24 15:33   ` Robin Murphy
@ 2021-08-25 15:43     ` Joerg Roedel
  0 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2021-08-25 15:43 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Geert Uytterhoeven, Will Deacon, Linux IOMMU, Linux ARM,
	kernel test robot, Linux-Renesas

On Tue, Aug 24, 2021 at 04:33:16PM +0100, Robin Murphy wrote:
> > Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
> 
> Thanks for confirming!

Sorry for the delay, the new tree containing this fix has been pushed
out now.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-25 15:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-20 13:14 [PATCH] iommu/io-pgtable: Abstract iommu_iotlb_gather access Robin Murphy
2021-08-20 15:19 ` Joerg Roedel
2021-08-24 13:55 ` Geert Uytterhoeven
2021-08-24 15:33   ` Robin Murphy
2021-08-25 15:43     ` Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).