linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwrng: omap - Fix RNG wait loop timeout
@ 2019-10-14 12:02 Sumit Garg
  2019-10-14 12:27 ` Daniel Thompson
  2019-10-25 15:18 ` Herbert Xu
  0 siblings, 2 replies; 4+ messages in thread
From: Sumit Garg @ 2019-10-14 12:02 UTC (permalink / raw)
  To: linux-crypto
  Cc: dsaxena, herbert, mpm, romain.perier, arnd, gregkh,
	daniel.thompson, ralph.siemsen, milan.stevanovic, ryan.harkin,
	linux-kernel, Sumit Garg, stable

Existing RNG data read timeout is 200us but it doesn't cover EIP76 RNG
data rate which takes approx. 700us to produce 16 bytes of output data
as per testing results. So configure the timeout as 1000us to also take
account of lack of udelay()'s reliability.

Fixes: 383212425c92 ("hwrng: omap - Add device variant for SafeXcel IP-76 found in Armada 8K")
Cc: <stable@vger.kernel.org>
Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
 drivers/char/hw_random/omap-rng.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c
index b27f396..e329f82 100644
--- a/drivers/char/hw_random/omap-rng.c
+++ b/drivers/char/hw_random/omap-rng.c
@@ -66,6 +66,13 @@
 #define OMAP4_RNG_OUTPUT_SIZE			0x8
 #define EIP76_RNG_OUTPUT_SIZE			0x10
 
+/*
+ * EIP76 RNG takes approx. 700us to produce 16 bytes of output data
+ * as per testing results. And to account for the lack of udelay()'s
+ * reliability, we keep the timeout as 1000us.
+ */
+#define RNG_DATA_FILL_TIMEOUT			100
+
 enum {
 	RNG_OUTPUT_0_REG = 0,
 	RNG_OUTPUT_1_REG,
@@ -176,7 +183,7 @@ static int omap_rng_do_read(struct hwrng *rng, void *data, size_t max,
 	if (max < priv->pdata->data_size)
 		return 0;
 
-	for (i = 0; i < 20; i++) {
+	for (i = 0; i < RNG_DATA_FILL_TIMEOUT; i++) {
 		present = priv->pdata->data_present(priv);
 		if (present || !wait)
 			break;
-- 
2.7.4


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

* Re: [PATCH] hwrng: omap - Fix RNG wait loop timeout
  2019-10-14 12:02 [PATCH] hwrng: omap - Fix RNG wait loop timeout Sumit Garg
@ 2019-10-14 12:27 ` Daniel Thompson
  2019-10-14 13:38   ` Sumit Garg
  2019-10-25 15:18 ` Herbert Xu
  1 sibling, 1 reply; 4+ messages in thread
From: Daniel Thompson @ 2019-10-14 12:27 UTC (permalink / raw)
  To: Sumit Garg
  Cc: linux-crypto, dsaxena, herbert, mpm, romain.perier, arnd, gregkh,
	ralph.siemsen, milan.stevanovic, ryan.harkin, linux-kernel,
	stable

On Mon, Oct 14, 2019 at 05:32:45PM +0530, Sumit Garg wrote:
> Existing RNG data read timeout is 200us but it doesn't cover EIP76 RNG
> data rate which takes approx. 700us to produce 16 bytes of output data
> as per testing results. So configure the timeout as 1000us to also take
> account of lack of udelay()'s reliability.

What "lack of udelay()'s reliability" are you concerned about?


Daniel.

> 
> Fixes: 383212425c92 ("hwrng: omap - Add device variant for SafeXcel IP-76 found in Armada 8K")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
> ---
>  drivers/char/hw_random/omap-rng.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c
> index b27f396..e329f82 100644
> --- a/drivers/char/hw_random/omap-rng.c
> +++ b/drivers/char/hw_random/omap-rng.c
> @@ -66,6 +66,13 @@
>  #define OMAP4_RNG_OUTPUT_SIZE			0x8
>  #define EIP76_RNG_OUTPUT_SIZE			0x10
>  
> +/*
> + * EIP76 RNG takes approx. 700us to produce 16 bytes of output data
> + * as per testing results. And to account for the lack of udelay()'s
> + * reliability, we keep the timeout as 1000us.
> + */
> +#define RNG_DATA_FILL_TIMEOUT			100
> +
>  enum {
>  	RNG_OUTPUT_0_REG = 0,
>  	RNG_OUTPUT_1_REG,
> @@ -176,7 +183,7 @@ static int omap_rng_do_read(struct hwrng *rng, void *data, size_t max,
>  	if (max < priv->pdata->data_size)
>  		return 0;
>  
> -	for (i = 0; i < 20; i++) {
> +	for (i = 0; i < RNG_DATA_FILL_TIMEOUT; i++) {
>  		present = priv->pdata->data_present(priv);
>  		if (present || !wait)
>  			break;
> -- 
> 2.7.4
> 

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

* Re: [PATCH] hwrng: omap - Fix RNG wait loop timeout
  2019-10-14 12:27 ` Daniel Thompson
@ 2019-10-14 13:38   ` Sumit Garg
  0 siblings, 0 replies; 4+ messages in thread
From: Sumit Garg @ 2019-10-14 13:38 UTC (permalink / raw)
  To: Daniel Thompson
  Cc: open list:HARDWARE RANDOM NUMBER GENERATOR CORE, dsaxena,
	Herbert Xu, Matt Mackall, romain.perier, Arnd Bergmann,
	Greg Kroah-Hartman, Ralph Siemsen, Milan STEVANOVIC, Ryan Harkin,
	Linux Kernel Mailing List, stable

On Mon, 14 Oct 2019 at 17:57, Daniel Thompson
<daniel.thompson@linaro.org> wrote:
>
> On Mon, Oct 14, 2019 at 05:32:45PM +0530, Sumit Garg wrote:
> > Existing RNG data read timeout is 200us but it doesn't cover EIP76 RNG
> > data rate which takes approx. 700us to produce 16 bytes of output data
> > as per testing results. So configure the timeout as 1000us to also take
> > account of lack of udelay()'s reliability.
>
> What "lack of udelay()'s reliability" are you concerned about?
>

For this I took reference from "drivers/char/hw_random/st-rng.c +33".
I think it's probably safe to take additional timeout rather than
relying on accuracy of udelay() based measurements. Specifically if
udelay() returns early than the expected delay (see:
include/linux/delay.h).

-Sumit

>
> Daniel.
>
> >
> > Fixes: 383212425c92 ("hwrng: omap - Add device variant for SafeXcel IP-76 found in Armada 8K")
> > Cc: <stable@vger.kernel.org>
> > Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
> > ---
> >  drivers/char/hw_random/omap-rng.c | 9 ++++++++-
> >  1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c
> > index b27f396..e329f82 100644
> > --- a/drivers/char/hw_random/omap-rng.c
> > +++ b/drivers/char/hw_random/omap-rng.c
> > @@ -66,6 +66,13 @@
> >  #define OMAP4_RNG_OUTPUT_SIZE                        0x8
> >  #define EIP76_RNG_OUTPUT_SIZE                        0x10
> >
> > +/*
> > + * EIP76 RNG takes approx. 700us to produce 16 bytes of output data
> > + * as per testing results. And to account for the lack of udelay()'s
> > + * reliability, we keep the timeout as 1000us.
> > + */
> > +#define RNG_DATA_FILL_TIMEOUT                        100
> > +
> >  enum {
> >       RNG_OUTPUT_0_REG = 0,
> >       RNG_OUTPUT_1_REG,
> > @@ -176,7 +183,7 @@ static int omap_rng_do_read(struct hwrng *rng, void *data, size_t max,
> >       if (max < priv->pdata->data_size)
> >               return 0;
> >
> > -     for (i = 0; i < 20; i++) {
> > +     for (i = 0; i < RNG_DATA_FILL_TIMEOUT; i++) {
> >               present = priv->pdata->data_present(priv);
> >               if (present || !wait)
> >                       break;
> > --
> > 2.7.4
> >

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

* Re: [PATCH] hwrng: omap - Fix RNG wait loop timeout
  2019-10-14 12:02 [PATCH] hwrng: omap - Fix RNG wait loop timeout Sumit Garg
  2019-10-14 12:27 ` Daniel Thompson
@ 2019-10-25 15:18 ` Herbert Xu
  1 sibling, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2019-10-25 15:18 UTC (permalink / raw)
  To: Sumit Garg
  Cc: linux-crypto, dsaxena, mpm, romain.perier, arnd, gregkh,
	daniel.thompson, ralph.siemsen, milan.stevanovic, ryan.harkin,
	linux-kernel, stable

On Mon, Oct 14, 2019 at 05:32:45PM +0530, Sumit Garg wrote:
> Existing RNG data read timeout is 200us but it doesn't cover EIP76 RNG
> data rate which takes approx. 700us to produce 16 bytes of output data
> as per testing results. So configure the timeout as 1000us to also take
> account of lack of udelay()'s reliability.
> 
> Fixes: 383212425c92 ("hwrng: omap - Add device variant for SafeXcel IP-76 found in Armada 8K")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
> ---
>  drivers/char/hw_random/omap-rng.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)

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] 4+ messages in thread

end of thread, other threads:[~2019-10-25 15:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-14 12:02 [PATCH] hwrng: omap - Fix RNG wait loop timeout Sumit Garg
2019-10-14 12:27 ` Daniel Thompson
2019-10-14 13:38   ` Sumit Garg
2019-10-25 15:18 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).