Re: [RFC PATCH v3 4/5] dma-mapping: Encapsulate memory state during allocation

From: Catalin Marinas

Date: Thu May 07 2026 - 13:36:57 EST


On Fri, Apr 17, 2026 at 03:45:11PM +0000, Mostafa Saleh wrote:
> On Fri, Apr 10, 2026 at 03:05:04PM -0300, Jason Gunthorpe wrote:
> > On Wed, Apr 08, 2026 at 07:47:41PM +0000, Mostafa Saleh wrote:
> > > Introduce a new dma-direct internal type dma_page which is
> > > "struct page" and a bit indicate whether the memory has been decrypted
> > > or not.
> > > This is useful to pass such information encapsulated through
> > > allocation functions, which is currently set from swiotlb_alloc().
> > >
> > > No functional changes.
> > >
> > > Signed-off-by: Mostafa Saleh <smostafa@xxxxxxxxxx>
> > > ---
> > > kernel/dma/direct.c | 58 +++++++++++++++++++++++++++++++++++----------
> > > 1 file changed, 46 insertions(+), 12 deletions(-)
> > >
> > > diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> > > index de63e0449700..204bc566480c 100644
> > > --- a/kernel/dma/direct.c
> > > +++ b/kernel/dma/direct.c
> > > @@ -16,6 +16,33 @@
> > > #include <linux/pci-p2pdma.h>
> > > #include "direct.h"
> > >
> > > +/*
> > > + * Represent DMA allocation and 1 bit flag for it's state
> > > + */
> >
> > I'd explain this wrappers a pointer and uses the low PAGE_SHIFT bits
> > for flags..
> >
> > > +struct dma_page {
> > > + unsigned long val;
> >
> > unintptr_t ?
>
> I thought about that, but I don’t see unintptr_t anywhere in the
> kernel, it seems similar cases use “unsigned long” as in xarray.h

Jason meant uintptr_t. However, we have a similar pattern with struct
encoded_page as an incomplete type and encode_page() adds the bits
directly to the pointer. I'd use something similar as there's precedent
already.

--
Catalin