On Thu, Nov 20, 2025 at 08:47:20PM -0400, Jason Gunthorpe wrote:
> On Thu, Nov 20, 2025 at 08:04:37AM +0000, Tian, Kevin wrote:
> > > From: Jason Gunthorpe <[email protected]>
> > > Sent: Saturday, November 8, 2025 12:50 AM
> > > +
> > > +static int pfn_reader_fill_dmabuf(struct pfn_reader_dmabuf *dmabuf,
> > > + struct pfn_batch *batch,
> > > + unsigned long start_index,
> > > + unsigned long last_index)
> > > +{
> > > + unsigned long start = dmabuf->start_offset + start_index * PAGE_SIZE;
> > > +
> > > + /*
> > > + * This works in PAGE_SIZE indexes, if the dmabuf is sliced and
> > > + * starts/ends at a sub page offset then the batch to domain code will
> > > + * adjust it.
> > > + */
> >
> > dmabuf->start_offset comes from pages->dmabuf.start, which is initialized
> > as:
> >
> > pages->dmabuf.start = start - start_byte;
> >
> > so it's always page-aligned. Where is the sub-page offset coming from?
>
> I need to go over this again to check it, this sub-page stuff is
> a bit convoluted. start_offset should include the sub page offset
> here..
So in the pfn reader section everything is page aligned, that means
the start location is also page aligned. The comment is just a bit
confusing, maybe this is better:
/*
* start/last_index and start_offset are all PAGE_SIZE aligned, the
* batch is always filled using page size aligned PFNs just like the
* other types. If the dmabuf has been sliced with a sub page offset
* then the common batch to domain code will adjust it before mapping to
* the domain.
*/
The adjustment is this code in batch_to_domain():
/* The first index might be a partial page */
if (start_index == iopt_area_index(area))
page_offset = area->page_offset;
Thanks,
Jason