All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5] crypto: caam - fix i.MX6SX entropy delay value
@ 2022-04-20 12:06 Fabio Estevam
       [not found] ` <HE1PR04MB29711AB352AE20A4A51B4C598EF49@HE1PR04MB2971.eurprd04.prod.outlook.com>
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Fabio Estevam @ 2022-04-20 12:06 UTC (permalink / raw)
  To: herbert
  Cc: horia.geanta, gaurav.jain, V.Sethi, linux-crypto, Fabio Estevam, stable

From: Fabio Estevam <festevam@denx.de>

Since commit 358ba762d9f1 ("crypto: caam - enable prediction resistance
in HRWNG") the following CAAM errors can be seen on i.MX6SX:

caam_jr 2101000.jr: 20003c5b: CCB: desc idx 60: RNG: Hardware error
hwrng: no data available

This error is due to an incorrect entropy delay for i.MX6SX.

Fix it by increasing the minimum entropy delay for i.MX6SX
as done in U-Boot:
https://patchwork.ozlabs.org/project/uboot/patch/20220415111049.2565744-1-gaurav.jain@nxp.com/

As explained in the U-Boot patch:

"RNG self tests are run to determine the correct entropy delay.
Such tests are executed with different voltages and temperatures to identify
the worst case value for the entropy delay. For i.MX6SX, it was determined
that after adding a margin value of 1000 the minimum entropy delay should be
at least 12000."

Cc: <stable@vger.kernel.org>
Fixes: 358ba762d9f1 ("crypto: caam - enable prediction resistance in HRWNG") 
Signed-off-by: Fabio Estevam <festevam@denx.de>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
---
Changes since v4:
- Change the function name to needs_entropy_delay_adjustment() - Vabhav
- Improve the commit log by adding the explanation from the U-Boot
patch - Vabhav

 drivers/crypto/caam/ctrl.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index ca0361b2dbb0..f87aa2169e5f 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -609,6 +609,13 @@ static bool check_version(struct fsl_mc_version *mc_version, u32 major,
 }
 #endif
 
+static bool needs_entropy_delay_adjustment(void)
+{
+	if (of_machine_is_compatible("fsl,imx6sx"))
+		return true;
+	return false;
+}
+
 /* Probe routine for CAAM top (controller) level */
 static int caam_probe(struct platform_device *pdev)
 {
@@ -855,6 +862,8 @@ static int caam_probe(struct platform_device *pdev)
 			 * Also, if a handle was instantiated, do not change
 			 * the TRNG parameters.
 			 */
+			if (needs_entropy_delay_adjustment())
+				ent_delay = 12000;
 			if (!(ctrlpriv->rng4_sh_init || inst_handles)) {
 				dev_info(dev,
 					 "Entropy delay = %u\n",
@@ -871,6 +880,15 @@ static int caam_probe(struct platform_device *pdev)
 			 */
 			ret = instantiate_rng(dev, inst_handles,
 					      gen_sk);
+			/*
+			 * Entropy delay is determined via TRNG characterization.
+			 * TRNG characterization is run across different voltages
+			 * and temperatures.
+			 * If worst case value for ent_dly is identified,
+			 * the loop can be skipped for that platform.
+			 */
+			if (needs_entropy_delay_adjustment())
+				break;
 			if (ret == -EAGAIN)
 				/*
 				 * if here, the loop will rerun,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: [PATCH v5] crypto: caam - fix i.MX6SX entropy delay value
       [not found] ` <HE1PR04MB29711AB352AE20A4A51B4C598EF49@HE1PR04MB2971.eurprd04.prod.outlook.com>
@ 2022-04-21 12:51   ` Vabhav Sharma
  0 siblings, 0 replies; 5+ messages in thread
From: Vabhav Sharma @ 2022-04-21 12:51 UTC (permalink / raw)
  To: herbert, Fabio Estevam
  Cc: Horia Geanta, Gaurav Jain, Varun Sethi, linux-crypto,
	Fabio Estevam, stable

Reviewed-by: Vabhav Sharma <vabhav.sharma@nxp.com>

> -----Original Message-----
> From: Fabio Estevam <festevam@gmail.com>
> Sent: Wednesday, April 20, 2022 5:36 PM
> To: herbert@gondor.apana.org.au
> Cc: Horia Geanta <horia.geanta@nxp.com>; Gaurav Jain
> <gaurav.jain@nxp.com>; Varun Sethi <V.Sethi@nxp.com>; linux-
> crypto@vger.kernel.org; Fabio Estevam <festevam@denx.de>;
> stable@vger.kernel.org
> Subject: [PATCH v5] crypto: caam - fix i.MX6SX entropy delay value
> 
> From: Fabio Estevam <festevam@denx.de>
> 
> Since commit 358ba762d9f1 ("crypto: caam - enable prediction resistance in
> HRWNG") the following CAAM errors can be seen on i.MX6SX:
> 
> caam_jr 2101000.jr: 20003c5b: CCB: desc idx 60: RNG: Hardware error
> hwrng: no data available
> 
> This error is due to an incorrect entropy delay for i.MX6SX.
> 
> Fix it by increasing the minimum entropy delay for i.MX6SX as done in U-Boot:
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatch
> work.ozlabs.org%2Fproject%2Fuboot%2Fpatch%2F20220415111049.2565744-
> 1-
> gaurav.jain%40nxp.com%2F&amp;data=05%7C01%7Cmeenakshi.aggarwal%4
> 0nxp.com%7Caf57d0186dde479aa9cf08da22c687d0%7C686ea1d3bc2b4c6fa92
> cd99c5c301635%7C0%7C0%7C637860533324307730%7CUnknown%7CTWFpb
> GZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI
> 6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=UhqjgESpgMhOhJS%2BT4ghI6y
> NIvyybOI8yEv5%2FjKNcDE%3D&amp;reserved=0
> 
> As explained in the U-Boot patch:
> 
> "RNG self tests are run to determine the correct entropy delay.
> Such tests are executed with different voltages and temperatures to identify
> the worst case value for the entropy delay. For i.MX6SX, it was determined
> that after adding a margin value of 1000 the minimum entropy delay should
> be at least 12000."
> 
> Cc: <stable@vger.kernel.org>
> Fixes: 358ba762d9f1 ("crypto: caam - enable prediction resistance in HRWNG")
> Signed-off-by: Fabio Estevam <festevam@denx.de>
> Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
> ---
> Changes since v4:
> - Change the function name to needs_entropy_delay_adjustment() -
> Vabhav
> - Improve the commit log by adding the explanation from the U-Boot patch -
> Vabhav
> 
>  drivers/crypto/caam/ctrl.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index
> ca0361b2dbb0..f87aa2169e5f 100644
> --- a/drivers/crypto/caam/ctrl.c
> +++ b/drivers/crypto/caam/ctrl.c
> @@ -609,6 +609,13 @@ static bool check_version(struct fsl_mc_version
> *mc_version, u32 major,  }  #endif
> 
> +static bool needs_entropy_delay_adjustment(void)
> +{
> +	if (of_machine_is_compatible("fsl,imx6sx"))
> +		return true;
> +	return false;
> +}
> +
>  /* Probe routine for CAAM top (controller) level */  static int
> caam_probe(struct platform_device *pdev)  { @@ -855,6 +862,8 @@ static
> int caam_probe(struct platform_device *pdev)
>  			 * Also, if a handle was instantiated, do not change
>  			 * the TRNG parameters.
>  			 */
> +			if (needs_entropy_delay_adjustment())
> +				ent_delay = 12000;
>  			if (!(ctrlpriv->rng4_sh_init || inst_handles)) {
>  				dev_info(dev,
>  					 "Entropy delay = %u\n",
> @@ -871,6 +880,15 @@ static int caam_probe(struct platform_device *pdev)
>  			 */
>  			ret = instantiate_rng(dev, inst_handles,
>  					      gen_sk);
> +			/*
> +			 * Entropy delay is determined via TRNG
> characterization.
> +			 * TRNG characterization is run across different
> voltages
> +			 * and temperatures.
> +			 * If worst case value for ent_dly is identified,
> +			 * the loop can be skipped for that platform.
> +			 */
> +			if (needs_entropy_delay_adjustment())
> +				break;
>  			if (ret == -EAGAIN)
>  				/*
>  				 * if here, the loop will rerun,
> --
> 2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [EXT] [PATCH v5] crypto: caam - fix i.MX6SX entropy delay value
  2022-04-20 12:06 [PATCH v5] crypto: caam - fix i.MX6SX entropy delay value Fabio Estevam
       [not found] ` <HE1PR04MB29711AB352AE20A4A51B4C598EF49@HE1PR04MB2971.eurprd04.prod.outlook.com>
@ 2022-04-27  6:05 ` Gaurav Jain
  2022-04-29  5:50 ` Herbert Xu
  2 siblings, 0 replies; 5+ messages in thread
From: Gaurav Jain @ 2022-04-27  6:05 UTC (permalink / raw)
  To: Fabio Estevam, herbert
  Cc: Horia Geanta, Varun Sethi, linux-crypto, Fabio Estevam, stable

Reviewed-by: Gaurav Jain <gaurav.jain@nxp.com>

> -----Original Message-----
> From: Fabio Estevam <festevam@gmail.com>
> Sent: Wednesday, April 20, 2022 5:36 PM
> To: herbert@gondor.apana.org.au
> Cc: Horia Geanta <horia.geanta@nxp.com>; Gaurav Jain
> <gaurav.jain@nxp.com>; Varun Sethi <V.Sethi@nxp.com>; linux-
> crypto@vger.kernel.org; Fabio Estevam <festevam@denx.de>;
> stable@vger.kernel.org
> Subject: [EXT] [PATCH v5] crypto: caam - fix i.MX6SX entropy delay value
> 
> Caution: EXT Email
> 
> From: Fabio Estevam <festevam@denx.de>
> 
> Since commit 358ba762d9f1 ("crypto: caam - enable prediction resistance in
> HRWNG") the following CAAM errors can be seen on i.MX6SX:
> 
> caam_jr 2101000.jr: 20003c5b: CCB: desc idx 60: RNG: Hardware error
> hwrng: no data available
> 
> This error is due to an incorrect entropy delay for i.MX6SX.
> 
> Fix it by increasing the minimum entropy delay for i.MX6SX as done in U-Boot:
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwo
> rk.ozlabs.org%2Fproject%2Fuboot%2Fpatch%2F20220415111049.2565744-1-
> gaurav.jain%40nxp.com%2F&amp;data=05%7C01%7Cgaurav.jain%40nxp.com%
> 7Cc2f2316c0db64170b59e08da22c62c4d%7C686ea1d3bc2b4c6fa92cd99c5c301
> 635%7C0%7C0%7C637860531804367821%7CUnknown%7CTWFpbGZsb3d8eyJ
> WIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C
> 3000%7C%7C%7C&amp;sdata=OTgUAquesUW39%2F0bhSnXHDe4UpCU8dQN%
> 2B7P0hlE6oiE%3D&amp;reserved=0
> 
> As explained in the U-Boot patch:
> 
> "RNG self tests are run to determine the correct entropy delay.
> Such tests are executed with different voltages and temperatures to identify the
> worst case value for the entropy delay. For i.MX6SX, it was determined that
> after adding a margin value of 1000 the minimum entropy delay should be at
> least 12000."
> 
> Cc: <stable@vger.kernel.org>
> Fixes: 358ba762d9f1 ("crypto: caam - enable prediction resistance in HRWNG")
> Signed-off-by: Fabio Estevam <festevam@denx.de>
> Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
> ---
> Changes since v4:
> - Change the function name to needs_entropy_delay_adjustment() - Vabhav
> - Improve the commit log by adding the explanation from the U-Boot patch -
> Vabhav
> 
>  drivers/crypto/caam/ctrl.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index
> ca0361b2dbb0..f87aa2169e5f 100644
> --- a/drivers/crypto/caam/ctrl.c
> +++ b/drivers/crypto/caam/ctrl.c
> @@ -609,6 +609,13 @@ static bool check_version(struct fsl_mc_version
> *mc_version, u32 major,  }  #endif
> 
> +static bool needs_entropy_delay_adjustment(void)
> +{
> +       if (of_machine_is_compatible("fsl,imx6sx"))
> +               return true;
> +       return false;
> +}
> +
>  /* Probe routine for CAAM top (controller) level */  static int caam_probe(struct
> platform_device *pdev)  { @@ -855,6 +862,8 @@ static int caam_probe(struct
> platform_device *pdev)
>                          * Also, if a handle was instantiated, do not change
>                          * the TRNG parameters.
>                          */
> +                       if (needs_entropy_delay_adjustment())
> +                               ent_delay = 12000;
>                         if (!(ctrlpriv->rng4_sh_init || inst_handles)) {
>                                 dev_info(dev,
>                                          "Entropy delay = %u\n", @@ -871,6 +880,15 @@ static
> int caam_probe(struct platform_device *pdev)
>                          */
>                         ret = instantiate_rng(dev, inst_handles,
>                                               gen_sk);
> +                       /*
> +                        * Entropy delay is determined via TRNG characterization.
> +                        * TRNG characterization is run across different voltages
> +                        * and temperatures.
> +                        * If worst case value for ent_dly is identified,
> +                        * the loop can be skipped for that platform.
> +                        */
> +                       if (needs_entropy_delay_adjustment())
> +                               break;
>                         if (ret == -EAGAIN)
>                                 /*
>                                  * if here, the loop will rerun,
> --
> 2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v5] crypto: caam - fix i.MX6SX entropy delay value
  2022-04-20 12:06 [PATCH v5] crypto: caam - fix i.MX6SX entropy delay value Fabio Estevam
       [not found] ` <HE1PR04MB29711AB352AE20A4A51B4C598EF49@HE1PR04MB2971.eurprd04.prod.outlook.com>
  2022-04-27  6:05 ` [EXT] " Gaurav Jain
@ 2022-04-29  5:50 ` Herbert Xu
  2022-06-09 13:45   ` Benjamin Bara
  2 siblings, 1 reply; 5+ messages in thread
From: Herbert Xu @ 2022-04-29  5:50 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: horia.geanta, gaurav.jain, V.Sethi, linux-crypto, Fabio Estevam, stable

On Wed, Apr 20, 2022 at 09:06:01AM -0300, Fabio Estevam wrote:
> From: Fabio Estevam <festevam@denx.de>
> 
> Since commit 358ba762d9f1 ("crypto: caam - enable prediction resistance
> in HRWNG") the following CAAM errors can be seen on i.MX6SX:
> 
> caam_jr 2101000.jr: 20003c5b: CCB: desc idx 60: RNG: Hardware error
> hwrng: no data available
> 
> This error is due to an incorrect entropy delay for i.MX6SX.
> 
> Fix it by increasing the minimum entropy delay for i.MX6SX
> as done in U-Boot:
> https://patchwork.ozlabs.org/project/uboot/patch/20220415111049.2565744-1-gaurav.jain@nxp.com/
> 
> As explained in the U-Boot patch:
> 
> "RNG self tests are run to determine the correct entropy delay.
> Such tests are executed with different voltages and temperatures to identify
> the worst case value for the entropy delay. For i.MX6SX, it was determined
> that after adding a margin value of 1000 the minimum entropy delay should be
> at least 12000."
> 
> Cc: <stable@vger.kernel.org>
> Fixes: 358ba762d9f1 ("crypto: caam - enable prediction resistance in HRWNG") 
> Signed-off-by: Fabio Estevam <festevam@denx.de>
> Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
> ---
> Changes since v4:
> - Change the function name to needs_entropy_delay_adjustment() - Vabhav
> - Improve the commit log by adding the explanation from the U-Boot
> patch - Vabhav
> 
>  drivers/crypto/caam/ctrl.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v5] crypto: caam - fix i.MX6SX entropy delay value
  2022-04-29  5:50 ` Herbert Xu
@ 2022-06-09 13:45   ` Benjamin Bara
  0 siblings, 0 replies; 5+ messages in thread
From: Benjamin Bara @ 2022-06-09 13:45 UTC (permalink / raw)
  To: herbert
  Cc: V.Sethi, festevam, festevam, gaurav.jain, horia.geanta,
	linux-crypto, stable, l.stach, robert.hancock, petr.benes,
	michal.vokac

Hi!

I found an older discussion on the same topic,
where it is mentioned that the same problem also occurs on imx6dl, imx6d and imx6s:

https://linuxlists.cc/l/4/linux-crypto/t/3843436/caam_rng_trouble#post4282922

I have also observed the problem on an imx6dl, running a 5.10.112 kernel.

Therefore, the problem might persist for the other variants.

BR
BB


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-06-09 13:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-20 12:06 [PATCH v5] crypto: caam - fix i.MX6SX entropy delay value Fabio Estevam
     [not found] ` <HE1PR04MB29711AB352AE20A4A51B4C598EF49@HE1PR04MB2971.eurprd04.prod.outlook.com>
2022-04-21 12:51   ` Vabhav Sharma
2022-04-27  6:05 ` [EXT] " Gaurav Jain
2022-04-29  5:50 ` Herbert Xu
2022-06-09 13:45   ` Benjamin Bara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.