mbox series

[v6,0/7] enable CAAM's HWRNG as default

Message ID 20200108154047.12526-1-andrew.smirnov@gmail.com (mailing list archive)
Headers show
Series enable CAAM's HWRNG as default | expand

Message

Andrey Smirnov Jan. 8, 2020, 3:40 p.m. UTC
Everyone:

This series is a continuation of original [discussion]. I don't know
if what's in the series is enough to use CAAMs HWRNG system wide, but
I am hoping that with enough iterations and feedback it will be.

Changes since [v1]:

    - Original hw_random replaced with the one using output of TRNG directly

    - SEC4 DRNG IP block exposed via crypto API

    - Small fix regarding use of GFP_DMA added to the series

Chagnes since [v2]:

    - msleep in polling loop to avoid wasting CPU cycles

    - caam_trng_read() bails out early if 'wait' is set to 'false'

    - fixed typo in ZII's name

Changes since [v3]:

    - DRNG's .cra_name is now "stdrng"

    - collected Reviewd-by tag from Lucas

    - typo fixes in commit messages of the series

Changes since [v4]:

    - Dropped "crypto: caam - RNG4 TRNG errata" and "crypto: caam -
      enable prediction resistance in HRWNG" to limit the scope of the
      series. Those two patches are not yet ready and can be submitted
      separately later.

    - Collected Tested-by from Chris

Changes since [v5]:

    - Series is converted back to implementing HWRNG using a job ring
      as per feedback from Horia.

Feedback is welcome!

Thanks,
Andrey Smirnov

[discussion] https://patchwork.kernel.org/patch/9850669/
[v1] https://lore.kernel.org/lkml/20191029162916.26579-1-andrew.smirnov@gmail.com
[v2] https://lore.kernel.org/lkml/20191118153843.28136-1-andrew.smirnov@gmail.com
[v3] https://lore.kernel.org/lkml/20191120165341.32669-1-andrew.smirnov@gmail.com
[v4] https://lore.kernel.org/lkml/20191121155554.1227-1-andrew.smirnov@gmail.com
[v5] https://lore.kernel.org/lkml/20191203162357.21942-1-andrew.smirnov@gmail.com

Andrey Smirnov (7):
  crypto: caam - use struct hwrng's .init for initialization
  crypto: caam - drop global context pointer and init_done
  crypto: caam - simplify RNG implementation
  crypto: caam - check if RNG job failed
  crypto: caam - invalidate entropy register during RNG initialization
  crypto: caam - enable prediction resistance in HRWNG
  crypto: caam - limit single JD RNG output to maximum of 16 bytes

 drivers/crypto/caam/caamrng.c | 391 ++++++++++++----------------------
 drivers/crypto/caam/ctrl.c    |  33 ++-
 drivers/crypto/caam/desc.h    |   2 +
 drivers/crypto/caam/intern.h  |   5 -
 drivers/crypto/caam/jr.c      |   1 -
 drivers/crypto/caam/regs.h    |   7 +-
 6 files changed, 174 insertions(+), 265 deletions(-)

--
2.21.0

Comments

Horia Geanta Jan. 22, 2020, 3:11 p.m. UTC | #1
On 1/8/2020 5:41 PM, Andrey Smirnov wrote:
> Everyone:
> 
> This series is a continuation of original [discussion]. I don't know
> if what's in the series is enough to use CAAMs HWRNG system wide, but
> I am hoping that with enough iterations and feedback it will be.
> 
Testing on DPAA2-based Layerscape platforms, for e.g. LS1088A:
[...]
[   12.379136] caam_jr 8010000.jr: 20000256: CCB: desc idx 2: RNG: Prediction resistance
[   12.387036] hwrng: no data available
[...]

caamrng driver fails, because RNG initialization is skipped
in ctrl.c - caam_probe():
	[...]
	np = of_find_compatible_node(NULL, NULL, "fsl,qoriq-mc");
	ctrlpriv->mc_en = !!np;
	[...]
	/*
	 * If SEC has RNG version >= 4 and RNG state handle has not been
	 * already instantiated, do RNG instantiation
	 * In case of SoCs with Management Complex, RNG is managed by MC f/w.
	 */
	if (!ctrlpriv->mc_en && rng_vid >= 4) {
	[...]

NXP is working at adding RNG Prediction Resistance support in MC f/w
(will be available in v10.20.1).

However, there's a backwards-compatibility requirement: kernel should work
with older MC f/w versions.
To fix this, my suggestion is to force RNG (re)initialization in case
MC f/w is present and its version is < 10.20.1, i.e.:
	if ((!ctrlpriv->mc_en || (fsl_mc_get_version() < "10.20.1")) &&
	    rng_vid >= 4) {
	[...]

fsl_mc_get_version() - I've made this up, it currently doesn't exist,
it should be added in fsl-mc bus driver (drivers/bus/fsl-mc).
We will provide this shortly, the plan being to integrate this change
as part of this series.

Thanks,
Horia