2022-11-25 04:37:28

by Herbert Xu

[permalink] [raw]
Subject: [v2 PATCH 0/9] crypto: Add helpers for allocating with DMA alignment

This patch series adds helpers to allow drivers to explicitly
request ARCH_DMA_MINALIGN when allocating memory through the
Crypto API.

Note that I've only converted one file in one driver as this
is only meant to show how it's done and find out what else we
may need.

Other drivers will be added later.

Thanks,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


2022-11-25 12:18:46

by Ard Biesheuvel

[permalink] [raw]
Subject: Re: [v2 PATCH 0/9] crypto: Add helpers for allocating with DMA alignment

On Fri, 25 Nov 2022 at 05:35, Herbert Xu <[email protected]> wrote:
>
> This patch series adds helpers to allow drivers to explicitly
> request ARCH_DMA_MINALIGN when allocating memory through the
> Crypto API.
>
> Note that I've only converted one file in one driver as this
> is only meant to show how it's done and find out what else we
> may need.
>
> Other drivers will be added later.
>

Hi Herbert,

This approach seems conceptually similar to what I proposed a while ago:
https://lore.kernel.org/all/[email protected]/

If we agree that creating a distinction between ordinary allocations
and ones that are rounded up to DMA alignment is ok, I wonder if we
could minimize the churn by simply choosing between one or the other
by taking the CRYPTO_ALG_ASYNC flag into account. On x86 and other
arches that don't care about the distinction, none of this has any
effect anyway. And on arm64, only hardware implementations use the
CRYPTO_ALG_ASYNC flag, which makes its presence a reasonable heuristic
to decide whether an algo implementation is backed by hardware that
relies on DMA (the penalty for getting it wrong would be to use DMA
ailgnment unnecessarily, which we already do today anyway)

We'd still need changes in the generic crypto layer to distinguish the
two cases, but we wouldn't need any changes to the drivers, which
seems like a huge benefit to me

2022-11-28 04:08:01

by Herbert Xu

[permalink] [raw]
Subject: Re: [v2 PATCH 0/9] crypto: Add helpers for allocating with DMA alignment

On Fri, Nov 25, 2022 at 01:17:55PM +0100, Ard Biesheuvel wrote:
>
> We'd still need changes in the generic crypto layer to distinguish the
> two cases, but we wouldn't need any changes to the drivers, which
> seems like a huge benefit to me

I think we should go through the drivers anyway. Because it isn't
just allocations from the Crypto API that'll bite us.

When I'm working through the drivers, I'm actually looking at what
they're mapping for DMA and where it's coming from. Only when the
driver stores DMA-mapped data in the ctx structures am I changing
the drivers to add the extra padding.

Some of the drviers are doing small allocations for things like the
IV or keys with the GFP_DMA flag and hoping that it gives the correct
alignment.

Cheers,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt