Re: [PATCH v2 13/22] iommufd: Add mmap interface

Nicolin Chen
2025-05-06T23:48:09Z

On Tue, May 06, 2025 at 09:52:22AM -0300, Jason Gunthorpe wrote:
> On Mon, May 05, 2025 at 12:50:56PM -0700, Nicolin Chen wrote:
>
> > I wanted to ask: what should we pass in to the "entry"? An mmap
> > structure that hold the pfn range? Or just pfn_start?
>
> Some kind of struct telling you what is behind that pfn range so you
> can invoke the right driver callback and retun the right pfns..

I see.

> > With that being said, it seems that I have been misusing the
> > mtree data structure, treating it as an xarray. In your very
> > first email suggesting the mmap design, where you mentioned
> > "xarray" first and "maple tree" following. So, I thought they
> > can be used in the similar way, especially after reading this:
> > https://lwn.net/Articles/846175/
>
> This job requires a range based datastructure. Meaning you insert PFNs
> A->B and then a lookup would search for any intersection with A->B.
>
> In maple tree you can do this rather directly since it is inherently
> range based.
>
> In xarray you can do it with the multi-order feature or you can do it
> by replicating the entry across the whole range.

So, if I understand it correctly, what we want to achieve is to
have maple tree to manage all PFN ranges. And each range holds
the same entry, a structure that we can use to verify the sanity
of an mmap? Let's say for PFNs A->B, the tree should store the
structure between index A and index B (inclusive)?

If this is correct, mtree_alloc_range() that is given a range of
[0, ULONG_MAX] would allocate the PFN range from the lowest index
(i.e. 0) instead of PFN A?

Thanks
Nicolin