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

Mostafa Saleh
2026-04-15T20:49:14Z

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, I try to refactor the free path to make is easier
to modify next, the bool encrypt here is typically set to false
from the error path.
I can replace that with a wrapper doing the encryption and calling
the free function.

Thanks,
Mostafa

>
> Jason