mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iommu: Remove redundant null check in iommu_iotlb_gather_queued
@ 2025-11-11  5:19 Aashish Sharma
  2025-11-24 17:03 ` Will Deacon
  0 siblings, 1 reply; 4+ messages in thread
From: Aashish Sharma @ 2025-11-11  5:19 UTC (permalink / raw)
  To: Vineeth Pillai, Dmytro Maluka, Joerg Roedel, Will Deacon
  Cc: Robin Murphy, iommu, linux-kernel, Aashish Sharma, Aashish Sharma

The callers of 'iommu_iotlb_gather_queued' always have a non-null
'gather', so we don't need to check for the same in the function.

Signed-off-by: Aashish Sharma (Google) <aashish@aashishsharma.net>
---
 include/linux/iommu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index c30d12e16473..f66f25051584 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -1057,7 +1057,7 @@ 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 gather && gather->queued;
+	return gather->queued;
 }
 
 static inline void iommu_dirty_bitmap_init(struct iommu_dirty_bitmap *dirty,
-- 
2.51.2.1041.gc1ab5b90ca-goog


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

* Re: [PATCH] iommu: Remove redundant null check in iommu_iotlb_gather_queued
  2025-11-11  5:19 [PATCH] iommu: Remove redundant null check in iommu_iotlb_gather_queued Aashish Sharma
@ 2025-11-24 17:03 ` Will Deacon
  2025-11-24 17:16   ` Robin Murphy
  0 siblings, 1 reply; 4+ messages in thread
From: Will Deacon @ 2025-11-24 17:03 UTC (permalink / raw)
  To: Aashish Sharma
  Cc: Vineeth Pillai, Dmytro Maluka, Joerg Roedel, Robin Murphy, iommu,
	linux-kernel, Aashish Sharma

On Mon, Nov 10, 2025 at 09:19:52PM -0800, Aashish Sharma wrote:
> The callers of 'iommu_iotlb_gather_queued' always have a non-null
> 'gather', so we don't need to check for the same in the function.

That's not obviously true to me, how did you check it?

For example, msm_iommu_pagetable_unmap() appears to call into
io_pgtable_ops::unmap_pages() with a NULL gather pointer.

Will

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

* Re: [PATCH] iommu: Remove redundant null check in iommu_iotlb_gather_queued
  2025-11-24 17:03 ` Will Deacon
@ 2025-11-24 17:16   ` Robin Murphy
  2025-11-25  1:07     ` Aashish Sharma
  0 siblings, 1 reply; 4+ messages in thread
From: Robin Murphy @ 2025-11-24 17:16 UTC (permalink / raw)
  To: Will Deacon, Aashish Sharma
  Cc: Vineeth Pillai, Dmytro Maluka, Joerg Roedel, iommu, linux-kernel,
	Aashish Sharma

On 2025-11-24 5:03 pm, Will Deacon wrote:
> On Mon, Nov 10, 2025 at 09:19:52PM -0800, Aashish Sharma wrote:
>> The callers of 'iommu_iotlb_gather_queued' always have a non-null
>> 'gather', so we don't need to check for the same in the function.
> 
> That's not obviously true to me, how did you check it?
> 
> For example, msm_iommu_pagetable_unmap() appears to call into
> io_pgtable_ops::unmap_pages() with a NULL gather pointer.

Indeed I think the only redundant check is the one which seems to have 
snuck into __arm_lpae_unmap() not so long ago (which the other callers 
never had and still don't.)

Thanks,
Robin.

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

* Re: [PATCH] iommu: Remove redundant null check in iommu_iotlb_gather_queued
  2025-11-24 17:16   ` Robin Murphy
@ 2025-11-25  1:07     ` Aashish Sharma
  0 siblings, 0 replies; 4+ messages in thread
From: Aashish Sharma @ 2025-11-25  1:07 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Will Deacon, Vineeth Pillai, Dmytro Maluka, Joerg Roedel, iommu,
	linux-kernel, Aashish Sharma

On Mon, Nov 24, 2025 at 9:16 AM Robin Murphy <robin.murphy@arm.com> wrote:
>
> On 2025-11-24 5:03 pm, Will Deacon wrote:
> > On Mon, Nov 10, 2025 at 09:19:52PM -0800, Aashish Sharma wrote:
> >> The callers of 'iommu_iotlb_gather_queued' always have a non-null
> >> 'gather', so we don't need to check for the same in the function.
> >
> > That's not obviously true to me, how did you check it?
> >
> > For example, msm_iommu_pagetable_unmap() appears to call into
> > io_pgtable_ops::unmap_pages() with a NULL gather pointer.
>
> Indeed I think the only redundant check is the one which seems to have
> snuck into __arm_lpae_unmap() not so long ago (which the other callers
> never had and still don't.)

Apologies, you are correct; I missed the invocations where gather can
indeed be NULL. Please disregard the patch in its current form.

However, I'd like to share the motivation behind the change, as it
might point to a semantic fragility in the current API.

While auditing the ARM io-pgtable code, I noticed that whenever
iommu_iotlb_gather_queued() returns false, the code immediately calls
io_pgtable_tlb_add_page(), except in __arm_lpae_unmap(). This
eventually invokes iommu_flush_ops::tlb_add_page(). Many
implementations of this op assume gather is non-NULL and dereference
it directly.

This creates a confusing situation: iommu_iotlb_gather_queued()
returns false for two distinct conditions:
1. gather is NULL.
2. gather is valid but the queue is empty.

The callers, however, seem to implicitly assume the second case (empty
queue) and proceed to operations that would crash if gather were
actually NULL. For example, if __arm_v7s_unmap() is called with a NULL
gather, it can lead to a crash:

__arm_v7s_unmap -> io_pgtable_tlb_add_page ->
arm_smmu_tlb_inv_page_nosync -> iommu_iotlb_gather_add_page -> crash

While the lack of reported crashes suggests gather isn't NULL in these
specific paths, relying on iommu_iotlb_gather_queued() to handle NULL
pointers feels inherently risky given how the return value is
interpreted.

Do you think it would be valuable to refactor this so that the helper
strictly checks the queue status, making the callers explicitly
responsible for NULL checks, like in __arm_lpae_unmap()?

Thanks
Aashish

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

end of thread, other threads:[~2025-11-25  1:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-11  5:19 [PATCH] iommu: Remove redundant null check in iommu_iotlb_gather_queued Aashish Sharma
2025-11-24 17:03 ` Will Deacon
2025-11-24 17:16   ` Robin Murphy
2025-11-25  1:07     ` Aashish Sharma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®