mbox series

[v4,00/13] crypto: permit asynchronous skciphers as driver fallbacks

Message ID 20200707063203.5018-1-ardb@kernel.org (mailing list archive)
Headers show
Series crypto: permit asynchronous skciphers as driver fallbacks | expand

Message

Ard Biesheuvel July 7, 2020, 6:31 a.m. UTC
The drivers for crypto accelerators in drivers/crypto all implement skciphers
of an asynchronous nature, given that they are backed by hardware DMA that
completes asynchronously wrt the execution flow.

However, in many cases, any fallbacks they allocate are limited to the
synchronous variety, which rules out the use of SIMD implementations of
AES in ECB, CBC and XTS modes, given that they are usually built on top
of the asynchronous SIMD helper, which queues requests for asynchronous
completion if they are issued from a context that does not permit the use
of the SIMD register file.

This may result in sub-optimal AES implementations to be selected as
fallbacks, or even less secure ones if the only synchronous alternative
is table based, and therefore not time invariant.

So switch all these cases over to the asynchronous API, by moving the
subrequest into the skcipher request context, and permitting it to
complete asynchronously via the caller provided completion function.

Patch #1 is not related, but touches the same driver as #2 so it is
included anyway. Patch #13 removes another sync skcipher allocation by
switching to the AES library interface.

v4:
- add missing kerneldoc updates for sun8i-ce and sun8i-ss
- add acks from Horia, Jamie and Corentin
- rebase onto cryptodev/master

v3:
- disregard the fallback skcipher_request when taking the request context size
  for TFMs that don't need the fallback at all (picoxcell, qce)
- fix error handling in fallback skcipher allocation and remove pointless
  memset()s (qce)

v2:
- address issue found by build robot in patch #7
- add patch #13
- rebase onto cryptodev/master

Cc: Corentin Labbe <clabbe.montjoie@gmail.com>
Cc: Corentin Labbe <clabbe@baylibre.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Chen-Yu Tsai <wens@csie.org>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: John Allen <john.allen@amd.com>
Cc: Ayush Sawal <ayush.sawal@chelsio.com>
Cc: Vinay Kumar Yadav <vinay.yadav@chelsio.com>
Cc: Rohit Maheshwari <rohitm@chelsio.com>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: NXP Linux Team <linux-imx@nxp.com>
Cc: Jamie Iles <jamie@jamieiles.com>
Cc: Eric Biggers <ebiggers@google.com>
Cc: Tero Kristo <t-kristo@ti.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: Horia Geantă <horia.geanta@nxp.com>

Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-omap@vger.kernel.org
Cc: linux-amlogic@lists.infradead.org

Ard Biesheuvel (13):
  crypto: amlogic-gxl - default to build as module
  crypto: amlogic-gxl - permit async skcipher as fallback
  crypto: omap-aes - permit asynchronous skcipher as fallback
  crypto: sun4i - permit asynchronous skcipher as fallback
  crypto: sun8i-ce - permit asynchronous skcipher as fallback
  crypto: sun8i-ss - permit asynchronous skcipher as fallback
  crypto: ccp - permit asynchronous skcipher as fallback
  crypto: chelsio - permit asynchronous skcipher as fallback
  crypto: mxs-dcp - permit asynchronous skcipher as fallback
  crypto: picoxcell - permit asynchronous skcipher as fallback
  crypto: qce - permit asynchronous skcipher as fallback
  crypto: sahara - permit asynchronous skcipher as fallback
  crypto: mediatek - use AES library for GCM key derivation

 drivers/crypto/Kconfig                        |  3 +-
 .../allwinner/sun4i-ss/sun4i-ss-cipher.c      | 46 ++++-----
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h  |  3 +-
 .../allwinner/sun8i-ce/sun8i-ce-cipher.c      | 41 ++++----
 drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h  |  8 +-
 .../allwinner/sun8i-ss/sun8i-ss-cipher.c      | 39 ++++----
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h  | 26 ++---
 drivers/crypto/amlogic/Kconfig                |  2 +-
 drivers/crypto/amlogic/amlogic-gxl-cipher.c   | 27 +++---
 drivers/crypto/amlogic/amlogic-gxl.h          |  3 +-
 drivers/crypto/ccp/ccp-crypto-aes-xts.c       | 33 ++++---
 drivers/crypto/ccp/ccp-crypto.h               |  4 +-
 drivers/crypto/chelsio/chcr_algo.c            | 57 +++++------
 drivers/crypto/chelsio/chcr_crypto.h          |  3 +-
 drivers/crypto/mediatek/mtk-aes.c             | 63 ++----------
 drivers/crypto/mxs-dcp.c                      | 33 +++----
 drivers/crypto/omap-aes.c                     | 35 ++++---
 drivers/crypto/omap-aes.h                     |  3 +-
 drivers/crypto/picoxcell_crypto.c             | 38 ++++----
 drivers/crypto/qce/cipher.h                   |  3 +-
 drivers/crypto/qce/skcipher.c                 | 42 ++++----
 drivers/crypto/sahara.c                       | 96 +++++++++----------
 22 files changed, 280 insertions(+), 328 deletions(-)

Comments

Herbert Xu July 16, 2020, 11:53 a.m. UTC | #1
On Tue, Jul 07, 2020 at 09:31:50AM +0300, Ard Biesheuvel wrote:
> The drivers for crypto accelerators in drivers/crypto all implement skciphers
> of an asynchronous nature, given that they are backed by hardware DMA that
> completes asynchronously wrt the execution flow.
> 
> However, in many cases, any fallbacks they allocate are limited to the
> synchronous variety, which rules out the use of SIMD implementations of
> AES in ECB, CBC and XTS modes, given that they are usually built on top
> of the asynchronous SIMD helper, which queues requests for asynchronous
> completion if they are issued from a context that does not permit the use
> of the SIMD register file.
> 
> This may result in sub-optimal AES implementations to be selected as
> fallbacks, or even less secure ones if the only synchronous alternative
> is table based, and therefore not time invariant.
> 
> So switch all these cases over to the asynchronous API, by moving the
> subrequest into the skcipher request context, and permitting it to
> complete asynchronously via the caller provided completion function.
> 
> Patch #1 is not related, but touches the same driver as #2 so it is
> included anyway. Patch #13 removes another sync skcipher allocation by
> switching to the AES library interface.
> 
> v4:
> - add missing kerneldoc updates for sun8i-ce and sun8i-ss
> - add acks from Horia, Jamie and Corentin
> - rebase onto cryptodev/master
> 
> v3:
> - disregard the fallback skcipher_request when taking the request context size
>   for TFMs that don't need the fallback at all (picoxcell, qce)
> - fix error handling in fallback skcipher allocation and remove pointless
>   memset()s (qce)
> 
> v2:
> - address issue found by build robot in patch #7
> - add patch #13
> - rebase onto cryptodev/master
> 
> Cc: Corentin Labbe <clabbe.montjoie@gmail.com>
> Cc: Corentin Labbe <clabbe@baylibre.com>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Maxime Ripard <mripard@kernel.org>
> Cc: Chen-Yu Tsai <wens@csie.org>
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Cc: John Allen <john.allen@amd.com>
> Cc: Ayush Sawal <ayush.sawal@chelsio.com>
> Cc: Vinay Kumar Yadav <vinay.yadav@chelsio.com>
> Cc: Rohit Maheshwari <rohitm@chelsio.com>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: NXP Linux Team <linux-imx@nxp.com>
> Cc: Jamie Iles <jamie@jamieiles.com>
> Cc: Eric Biggers <ebiggers@google.com>
> Cc: Tero Kristo <t-kristo@ti.com>
> Cc: Matthias Brugger <matthias.bgg@gmail.com>
> Cc: Horia Geantă <horia.geanta@nxp.com>
> 
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-omap@vger.kernel.org
> Cc: linux-amlogic@lists.infradead.org
> 
> Ard Biesheuvel (13):
>   crypto: amlogic-gxl - default to build as module
>   crypto: amlogic-gxl - permit async skcipher as fallback
>   crypto: omap-aes - permit asynchronous skcipher as fallback
>   crypto: sun4i - permit asynchronous skcipher as fallback
>   crypto: sun8i-ce - permit asynchronous skcipher as fallback
>   crypto: sun8i-ss - permit asynchronous skcipher as fallback
>   crypto: ccp - permit asynchronous skcipher as fallback
>   crypto: chelsio - permit asynchronous skcipher as fallback
>   crypto: mxs-dcp - permit asynchronous skcipher as fallback
>   crypto: picoxcell - permit asynchronous skcipher as fallback
>   crypto: qce - permit asynchronous skcipher as fallback
>   crypto: sahara - permit asynchronous skcipher as fallback
>   crypto: mediatek - use AES library for GCM key derivation
> 
>  drivers/crypto/Kconfig                        |  3 +-
>  .../allwinner/sun4i-ss/sun4i-ss-cipher.c      | 46 ++++-----
>  drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h  |  3 +-
>  .../allwinner/sun8i-ce/sun8i-ce-cipher.c      | 41 ++++----
>  drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h  |  8 +-
>  .../allwinner/sun8i-ss/sun8i-ss-cipher.c      | 39 ++++----
>  drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h  | 26 ++---
>  drivers/crypto/amlogic/Kconfig                |  2 +-
>  drivers/crypto/amlogic/amlogic-gxl-cipher.c   | 27 +++---
>  drivers/crypto/amlogic/amlogic-gxl.h          |  3 +-
>  drivers/crypto/ccp/ccp-crypto-aes-xts.c       | 33 ++++---
>  drivers/crypto/ccp/ccp-crypto.h               |  4 +-
>  drivers/crypto/chelsio/chcr_algo.c            | 57 +++++------
>  drivers/crypto/chelsio/chcr_crypto.h          |  3 +-
>  drivers/crypto/mediatek/mtk-aes.c             | 63 ++----------
>  drivers/crypto/mxs-dcp.c                      | 33 +++----
>  drivers/crypto/omap-aes.c                     | 35 ++++---
>  drivers/crypto/omap-aes.h                     |  3 +-
>  drivers/crypto/picoxcell_crypto.c             | 38 ++++----
>  drivers/crypto/qce/cipher.h                   |  3 +-
>  drivers/crypto/qce/skcipher.c                 | 42 ++++----
>  drivers/crypto/sahara.c                       | 96 +++++++++----------
>  22 files changed, 280 insertions(+), 328 deletions(-)

All applied.  Thanks.
patchwork-bot+linux-amlogic@kernel.org Aug. 17, 2020, 5:48 p.m. UTC | #2
Hello:

This series was applied to khilman/linux-amlogic.git (refs/heads/for-next).

On Tue,  7 Jul 2020 09:31:50 +0300 you wrote:
> The drivers for crypto accelerators in drivers/crypto all implement skciphers
> of an asynchronous nature, given that they are backed by hardware DMA that
> completes asynchronously wrt the execution flow.
> 
> However, in many cases, any fallbacks they allocate are limited to the
> synchronous variety, which rules out the use of SIMD implementations of
> AES in ECB, CBC and XTS modes, given that they are usually built on top
> of the asynchronous SIMD helper, which queues requests for asynchronous
> completion if they are issued from a context that does not permit the use
> of the SIMD register file.
> 
> [...]


Here is a summary with links:
  - [v4,01/13] crypto: amlogic-gxl - default to build as module
    https://git.kernel.org/khilman/linux-amlogic/c/3f368b886e95080daf811d228795c28716495279
  - [v4,02/13] crypto: amlogic-gxl - permit async skcipher as fallback
    https://git.kernel.org/khilman/linux-amlogic/c/1d63e4557f0d11fd795c7acd50a241da2d8bf89f
  - [v4,03/13] crypto: omap-aes - permit asynchronous skcipher as fallback
    https://git.kernel.org/khilman/linux-amlogic/c/6a99d7a2d73cbeaa0b93551fc8ec887295821bbe
  - [v4,04/13] crypto: sun4i - permit asynchronous skcipher as fallback
    https://git.kernel.org/khilman/linux-amlogic/c/89fb00f245681d0c951cd889d3d165cf9959d70c
  - [v4,05/13] crypto: sun8i-ce - permit asynchronous skcipher as fallback
    https://git.kernel.org/khilman/linux-amlogic/c/31abd3eb3df6bd520fece598e31047a0f377953e
  - [v4,06/13] crypto: sun8i-ss - permit asynchronous skcipher as fallback
    https://git.kernel.org/khilman/linux-amlogic/c/44b591753731f12dcf5d8e72df69baa9f3c48921
  - [v4,07/13] crypto: ccp - permit asynchronous skcipher as fallback
    https://git.kernel.org/khilman/linux-amlogic/c/413b61ce0b4de0e55a9f8cf91bbce1ad7e0870cd
  - [v4,08/13] crypto: chelsio - permit asynchronous skcipher as fallback
    https://git.kernel.org/khilman/linux-amlogic/c/d8c6d1886c8f436da96c0d91010040ca7caae9ac
  - [v4,09/13] crypto: mxs-dcp - permit asynchronous skcipher as fallback
    https://git.kernel.org/khilman/linux-amlogic/c/c9598d4e13ca0a6747235257a8e38cdef6973d8e
  - [v4,10/13] crypto: picoxcell - permit asynchronous skcipher as fallback
    https://git.kernel.org/khilman/linux-amlogic/c/dc6e71c9d9cfef98b95cb6e7e91ed2bb64b63e76
  - [v4,11/13] crypto: qce - permit asynchronous skcipher as fallback
    https://git.kernel.org/khilman/linux-amlogic/c/90e2f782719fc5ad2af63096815a69c5320704cb
  - [v4,12/13] crypto: sahara - permit asynchronous skcipher as fallback
    https://git.kernel.org/khilman/linux-amlogic/c/56ca499f1b58235d5b3f247a887cc636d849d351
  - [v4,13/13] crypto: mediatek - use AES library for GCM key derivation
    https://git.kernel.org/khilman/linux-amlogic/c/f441ba2ad34102692b9836923776f017b40afc88

You are awesome, thank you!