[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aSV_Ap1RynBULiZM@google.com>
Date: Tue, 25 Nov 2025 10:03:46 +0000
From: Mostafa Saleh <smostafa@...gle.com>
To: Baolu Lu <baolu.lu@...ux.intel.com>
Cc: linux-mm@...ck.org, iommu@...ts.linux.dev, linux-kernel@...r.kernel.org,
linux-doc@...r.kernel.org, corbet@....net, joro@...tes.org,
will@...nel.org, robin.murphy@....com, akpm@...ux-foundation.org,
vbabka@...e.cz, surenb@...gle.com, mhocko@...e.com,
jackmanb@...gle.com, hannes@...xchg.org, ziy@...dia.com,
david@...hat.com, lorenzo.stoakes@...cle.com,
Liam.Howlett@...cle.com, rppt@...nel.org, xiaqinxin@...wei.com
Subject: Re: [PATCH v3 3/4] drivers/iommu-debug-pagealloc: Track IOMMU pages
On Tue, Nov 25, 2025 at 03:54:56PM +0800, Baolu Lu wrote:
> On 11/25/25 04:08, Mostafa Saleh wrote:
> > void __iommu_debug_unmap_end(struct iommu_domain *domain,
> > unsigned long iova, size_t size,
> > size_t unmapped)
> > {
> > + if (unmapped == size)
> > + return;
> > +
> > + /*
> > + * If unmap failed, re-increment the refcount, but if it unmapped
> > + * larger size, decrement the extra part.
> > + */
> > + if (unmapped < size)
> > + __iommu_debug_update_iova(domain, iova + unmapped,
> > + size - unmapped, true);
> > + else
> > + __iommu_debug_update_iova(domain, iova + size,
> > + unmapped - size, false);
>
> In any case, could the 'else' branch become a real operation?
>
> In the __iommu_unmap():
>
> /*
> * Keep iterating until we either unmap 'size' bytes (or more)
> * or we hit an area that isn't mapped.
> */
> while (unmapped < size) {
> size_t pgsize, count;
>
> pgsize = iommu_pgsize(domain, iova, iova, size - unmapped,
> &count);
> unmapped_page = ops->unmap_pages(domain, iova, pgsize,
> count, iotlb_gather);
> if (!unmapped_page)
> break;
>
> pr_debug("unmapped: iova 0x%lx size 0x%zx\n",
> iova, unmapped_page);
>
> iova += unmapped_page;
> unmapped += unmapped_page;
> }
>
> The comments say that it is possible to unmap more bytes than 'size',
> but isn't it a bug if this helper unmaps more than the caller desired?
I was wondering also why the core API allows that, I couldn't find
useful information from "git blame". But I vaguely remember that some
IOMMUs can't split blocks so they unmap the whole block when a smaller
size is requested.
Thanks,
Mostafa
>
> Thanks,
> baolu
Powered by blists - more mailing lists