Re: [RFC PATCH v3 2/5] dma-mapping: Move encryption in __dma_direct_free_pages()

Jason Gunthorpe
2026-04-16T00:11:24Z

On Wed, Apr 15, 2026 at 08:49:08PM +0000, Mostafa Saleh wrote:
> On Fri, Apr 10, 2026 at 02:45:53PM -0300, Jason Gunthorpe wrote:
> > On Wed, Apr 08, 2026 at 07:47:39PM +0000, Mostafa Saleh wrote:
> > > In the next patches, we will need to avoid encrypting memory allocated
> > > from SWIOTLB, so instead of calling dma_set_encrypted() before
> > > __dma_direct_free_pages(), call it inside, conditional on the memory
> > > state passed to the function.
> > >
> > > Signed-off-by: Mostafa Saleh <smostafa@google.com>
> > > ---
> > > kernel/dma/direct.c | 22 +++++++++++-----------
> > > 1 file changed, 11 insertions(+), 11 deletions(-)
> > >
> > > diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> > > index 6efb5973fbd3..ce74f213ec40 100644
> > > --- a/kernel/dma/direct.c
> > > +++ b/kernel/dma/direct.c
> > > @@ -97,8 +97,11 @@ static int dma_set_encrypted(struct device *dev, void *vaddr, size_t size)
> > > }
> > >
> > > static void __dma_direct_free_pages(struct device *dev, struct page *page,
> > > - size_t size)
> > > + size_t size, bool encrypt)
> > > {
> >
> > This feels like it would be nicer if it could be the
> > swiotlb_page_state instead of a bool, maybe the enum needs a different
> > name.
>
> I am not sure I get this, at this point the swiotlb stuff is not
> introduced yet,

Just that using bool as a function argument for a flag is often
frowned on, and you already have an enum encoding the same flag
state.

Jason