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

Jason Gunthorpe
2026-04-10T17:45:55Z

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.

Jason