2018-02-06 21:21:57

by Artem Savkov

[permalink] [raw]
Subject: [PATCH 0/2] sun4i_ss_prng fixes

IPSec hasn't been working on my a10 board since 4.14 and it turned out to be
caused by sun4i_ss_rng driver.

Artem Savkov (2):
sun4i_ss_prng: fix return value of sun4i_ss_prng_generate
sun4i_ss_prng: convert lock to _bh in sun4i_ss_prng_generate

drivers/crypto/sunxi-ss/sun4i-ss-prng.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

--
2.15.1



2018-02-06 21:22:03

by Artem Savkov

[permalink] [raw]
Subject: [PATCH 2/2] sun4i_ss_prng: convert lock to _bh in sun4i_ss_prng_generate

Lockdep detects a possible deadlock in sun4i_ss_prng_generate() and
throws an "inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage" warning.
Disabling softirqs to fix this.

Fixes: b8ae5c7387ad ("crypto: sun4i-ss - support the Security System PRNG")
Signed-off-by: Artem Savkov <[email protected]>
---
drivers/crypto/sunxi-ss/sun4i-ss-prng.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-prng.c b/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
index 5754e0b92fb0..63d636424161 100644
--- a/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
+++ b/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
@@ -28,7 +28,7 @@ int sun4i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src,
algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng);
ss = algt->ss;

- spin_lock(&ss->slock);
+ spin_lock_bh(&ss->slock);

writel(mode, ss->base + SS_CTL);

@@ -51,6 +51,6 @@ int sun4i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src,
}

writel(0, ss->base + SS_CTL);
- spin_unlock(&ss->slock);
+ spin_unlock_bh(&ss->slock);
return 0;
}
--
2.15.1


2018-02-06 21:23:23

by Artem Savkov

[permalink] [raw]
Subject: [PATCH 1/2] sun4i_ss_prng: fix return value of sun4i_ss_prng_generate

According to crypto/rng.h generate function should return 0 on success
and < 0 on error.

Fixes: b8ae5c7387ad ("crypto: sun4i-ss - support the Security System PRNG")
Signed-off-by: Artem Savkov <[email protected]>
---
drivers/crypto/sunxi-ss/sun4i-ss-prng.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-prng.c b/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
index 0d01d1624252..5754e0b92fb0 100644
--- a/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
+++ b/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
@@ -52,5 +52,5 @@ int sun4i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src,

writel(0, ss->base + SS_CTL);
spin_unlock(&ss->slock);
- return dlen;
+ return 0;
}
--
2.15.1


2018-02-07 09:59:20

by Corentin Labbe

[permalink] [raw]
Subject: Re: [PATCH 1/2] sun4i_ss_prng: fix return value of sun4i_ss_prng_generate

On Tue, Feb 06, 2018 at 10:20:21PM +0100, Artem Savkov wrote:
> According to crypto/rng.h generate function should return 0 on success
> and < 0 on error.
>
> Fixes: b8ae5c7387ad ("crypto: sun4i-ss - support the Security System PRNG")
> Signed-off-by: Artem Savkov <[email protected]>
> ---
> drivers/crypto/sunxi-ss/sun4i-ss-prng.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-prng.c b/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
> index 0d01d1624252..5754e0b92fb0 100644
> --- a/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
> +++ b/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
> @@ -52,5 +52,5 @@ int sun4i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src,
>
> writel(0, ss->base + SS_CTL);
> spin_unlock(&ss->slock);
> - return dlen;
> + return 0;
> }
> --
> 2.15.1
>

According to Documentation/crypto/api-samples.rst ("Code Example For Random Number Generator Usage")
you must return the length of data generated.

So crypto_rng_generate/crypto_rng_get_bytes documentation in crypto/rng.h must be fixed.

Herbert could you confirm ?

Regards

2018-02-07 10:53:12

by Artem Savkov

[permalink] [raw]
Subject: Re: [PATCH 1/2] sun4i_ss_prng: fix return value of sun4i_ss_prng_generate

On Wed, Feb 07, 2018 at 10:56:59AM +0100, Corentin Labbe wrote:
> On Tue, Feb 06, 2018 at 10:20:21PM +0100, Artem Savkov wrote:
> > According to crypto/rng.h generate function should return 0 on success
> > and < 0 on error.
> >
> > Fixes: b8ae5c7387ad ("crypto: sun4i-ss - support the Security System PRNG")
> > Signed-off-by: Artem Savkov <[email protected]>
> > ---
> > drivers/crypto/sunxi-ss/sun4i-ss-prng.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-prng.c b/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
> > index 0d01d1624252..5754e0b92fb0 100644
> > --- a/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
> > +++ b/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
> > @@ -52,5 +52,5 @@ int sun4i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src,
> >
> > writel(0, ss->base + SS_CTL);
> > spin_unlock(&ss->slock);
> > - return dlen;
> > + return 0;
> > }
> > --
> > 2.15.1
> >
>
> According to Documentation/crypto/api-samples.rst ("Code Example For Random Number Generator Usage")
> you must return the length of data generated.

I don't think that example is the same as rng_alg.generate, it has a
different protottype.

> So crypto_rng_generate/crypto_rng_get_bytes documentation in crypto/rng.h must be fixed.

It's not just documentation, every other rng driver returns it this way
and it gets aead_init_geniv() (and subsequently crypto_create_tfm())
really confused because they expect the return value to be 0 or < 0.

> Herbert could you confirm ?


--
Regards,
Artem

2018-02-07 13:13:33

by Corentin Labbe

[permalink] [raw]
Subject: Re: [PATCH 1/2] sun4i_ss_prng: fix return value of sun4i_ss_prng_generate

On Wed, Feb 07, 2018 at 11:52:01AM +0100, Artem Savkov wrote:
> On Wed, Feb 07, 2018 at 10:56:59AM +0100, Corentin Labbe wrote:
> > On Tue, Feb 06, 2018 at 10:20:21PM +0100, Artem Savkov wrote:
> > > According to crypto/rng.h generate function should return 0 on success
> > > and < 0 on error.
> > >
> > > Fixes: b8ae5c7387ad ("crypto: sun4i-ss - support the Security System PRNG")
> > > Signed-off-by: Artem Savkov <[email protected]>
> > > ---
> > > drivers/crypto/sunxi-ss/sun4i-ss-prng.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-prng.c b/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
> > > index 0d01d1624252..5754e0b92fb0 100644
> > > --- a/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
> > > +++ b/drivers/crypto/sunxi-ss/sun4i-ss-prng.c
> > > @@ -52,5 +52,5 @@ int sun4i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src,
> > >
> > > writel(0, ss->base + SS_CTL);
> > > spin_unlock(&ss->slock);
> > > - return dlen;
> > > + return 0;
> > > }
> > > --
> > > 2.15.1
> > >
> >
> > According to Documentation/crypto/api-samples.rst ("Code Example For Random Number Generator Usage")
> > you must return the length of data generated.
>
> I don't think that example is the same as rng_alg.generate, it has a
> different protottype.

crypto_rng_get_bytes() use crypto_rng_generate() which work on crypto_rng

>
> > So crypto_rng_generate/crypto_rng_get_bytes documentation in crypto/rng.h must be fixed.
>
> It's not just documentation, every other rng driver returns it this way
> and it gets aead_init_geniv() (and subsequently crypto_create_tfm())
> really confused because they expect the return value to be 0 or < 0.
>

Perhaps the example is wrong because "copied from/inspirated by" hwrng API which have this behavior.

After checking, other crypto_rng driver, you are probably right, so you can add:
Acked-by: Corentin Labbe <[email protected]>

Thanks
Regards

2018-02-09 15:53:41

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH 0/2] sun4i_ss_prng fixes

On Tue, Feb 06, 2018 at 10:20:20PM +0100, Artem Savkov wrote:
> IPSec hasn't been working on my a10 board since 4.14 and it turned out to be
> caused by sun4i_ss_rng driver.
>
> Artem Savkov (2):
> sun4i_ss_prng: fix return value of sun4i_ss_prng_generate
> sun4i_ss_prng: convert lock to _bh in sun4i_ss_prng_generate
>
> drivers/crypto/sunxi-ss/sun4i-ss-prng.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)

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