[PATCH 0/3] crypto: sun4i-ss: fix SHA1 on A33 SecuritySystem

59 kali dilihat
Langsung ke pesan pertama yang belum dibaca

Corentin Labbe

belum dibaca,
14 Nov 2019, 09.48.3314/11/19
kepadada...@davemloft.net, her...@gondor.apana.org.au, mark.r...@arm.com, mri...@kernel.org, rob...@kernel.org, we...@csie.org, devic...@vger.kernel.org, linux-ar...@lists.infradead.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Corentin Labbe
Thanks to Igor Pecovnik, I have now in my kernelCI lab, a sun8i-a33-olinuxino.
Strange behavour, crypto selftests was failling but only for SHA1 on
this A33 SoC.

This is due to the A33 SS having a difference with all other SS, it give SHA1 digest directly in BE.
This serie handle this difference.

Corentin Labbe (3):
dt-bindings: crypto: add new compatible for A33 SS
ARM: dts: sun8i: a33: add the new SS compatible
crypto: sun4i-ss: add the A33 variant of SS

.../crypto/allwinner,sun4i-a10-crypto.yaml | 3 +++
arch/arm/boot/dts/sun8i-a33.dtsi | 3 ++-
.../crypto/allwinner/sun4i-ss/sun4i-ss-core.c | 22 ++++++++++++++++++-
.../crypto/allwinner/sun4i-ss/sun4i-ss-hash.c | 5 ++++-
drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h | 9 ++++++++
5 files changed, 39 insertions(+), 3 deletions(-)

--
2.23.0

Corentin Labbe

belum dibaca,
14 Nov 2019, 09.48.3414/11/19
kepadada...@davemloft.net, her...@gondor.apana.org.au, mark.r...@arm.com, mri...@kernel.org, rob...@kernel.org, we...@csie.org, devic...@vger.kernel.org, linux-ar...@lists.infradead.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Corentin Labbe
The A33 SecuritySystem has a difference with all other SS, it give SHA1 digest
directly in BE.
This difference need to be handlded by the driver and so need a new
compatible.

Signed-off-by: Corentin Labbe <clabbe....@gmail.com>
---
.../devicetree/bindings/crypto/allwinner,sun4i-a10-crypto.yaml | 3 +++
1 file changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/crypto/allwinner,sun4i-a10-crypto.yaml b/Documentation/devicetree/bindings/crypto/allwinner,sun4i-a10-crypto.yaml
index 80b3e7350a73..ae6dcfa795d1 100644
--- a/Documentation/devicetree/bindings/crypto/allwinner,sun4i-a10-crypto.yaml
+++ b/Documentation/devicetree/bindings/crypto/allwinner,sun4i-a10-crypto.yaml
@@ -23,6 +23,9 @@ properties:
- items:
- const: allwinner,sun7i-a20-crypto
- const: allwinner,sun4i-a10-crypto
+ - items:
+ - const: allwinner,sun8i-a33-crypto
+ - const: allwinner,sun4i-a10-crypto

reg:
maxItems: 1
--
2.23.0

Corentin Labbe

belum dibaca,
14 Nov 2019, 09.48.3514/11/19
kepadada...@davemloft.net, her...@gondor.apana.org.au, mark.r...@arm.com, mri...@kernel.org, rob...@kernel.org, we...@csie.org, devic...@vger.kernel.org, linux-ar...@lists.infradead.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Corentin Labbe
Add the new A33 SecuritySystem compatible to the crypto node.

Signed-off-by: Corentin Labbe <clabbe....@gmail.com>
---
arch/arm/boot/dts/sun8i-a33.dtsi | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/sun8i-a33.dtsi b/arch/arm/boot/dts/sun8i-a33.dtsi
index 1532a0e59af4..5680fa1de102 100644
--- a/arch/arm/boot/dts/sun8i-a33.dtsi
+++ b/arch/arm/boot/dts/sun8i-a33.dtsi
@@ -215,7 +215,8 @@
};

crypto: crypto-engine@1c15000 {
- compatible = "allwinner,sun4i-a10-crypto";
+ compatible = "allwinner,sun8i-a33-crypto",
+ "allwinner,sun4i-a10-crypto";
reg = <0x01c15000 0x1000>;
interrupts = <GIC_SPI 80 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&ccu CLK_BUS_SS>, <&ccu CLK_SS>;
--
2.23.0

Corentin Labbe

belum dibaca,
14 Nov 2019, 09.48.3614/11/19
kepadada...@davemloft.net, her...@gondor.apana.org.au, mark.r...@arm.com, mri...@kernel.org, rob...@kernel.org, we...@csie.org, devic...@vger.kernel.org, linux-ar...@lists.infradead.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Corentin Labbe
The A33 SecuritySystem has a difference with all other SS, it give SHA1 digest
directly in BE.
So this patch adds variant support in sun4i-ss.

Fixes: 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")
Signed-off-by: Corentin Labbe <clabbe....@gmail.com>
---
.../crypto/allwinner/sun4i-ss/sun4i-ss-core.c | 22 ++++++++++++++++++-
.../crypto/allwinner/sun4i-ss/sun4i-ss-hash.c | 5 ++++-
drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h | 9 ++++++++
3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
index 814cd12149a9..d35a05843c22 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
@@ -13,6 +13,7 @@
#include <linux/io.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <crypto/scatterwalk.h>
#include <linux/scatterlist.h>
@@ -22,6 +23,14 @@

#include "sun4i-ss.h"

+static const struct ss_variant ss_a10_variant = {
+ .sha1_in_be = false,
+};
+
+static const struct ss_variant ss_a33_variant = {
+ .sha1_in_be = true,
+};
+
static struct sun4i_ss_alg_template ss_algs[] = {
{ .type = CRYPTO_ALG_TYPE_AHASH,
.mode = SS_OP_MD5,
@@ -323,6 +332,12 @@ static int sun4i_ss_probe(struct platform_device *pdev)
return PTR_ERR(ss->base);
}

+ ss->variant = of_device_get_match_data(&pdev->dev);
+ if (!ss->variant) {
+ dev_err(&pdev->dev, "Missing Security System variant\n");
+ return -EINVAL;
+ }
+
ss->ssclk = devm_clk_get(&pdev->dev, "mod");
if (IS_ERR(ss->ssclk)) {
err = PTR_ERR(ss->ssclk);
@@ -484,7 +499,12 @@ static int sun4i_ss_remove(struct platform_device *pdev)
}

static const struct of_device_id a20ss_crypto_of_match_table[] = {
- { .compatible = "allwinner,sun4i-a10-crypto" },
+ { .compatible = "allwinner,sun4i-a10-crypto",
+ .data = &ss_a10_variant
+ },
+ { .compatible = "allwinner,sun8i-a33-crypto",
+ .data = &ss_a33_variant
+ },
{}
};
MODULE_DEVICE_TABLE(of, a20ss_crypto_of_match_table);
diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c
index 91cf58db3845..c791d6935c65 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c
@@ -478,7 +478,10 @@ static int sun4i_hash(struct ahash_request *areq)
/* Get the hash from the device */
if (op->mode == SS_OP_SHA1) {
for (i = 0; i < 5; i++) {
- v = cpu_to_be32(readl(ss->base + SS_MD0 + i * 4));
+ if (ss->variant->sha1_in_be)
+ v = cpu_to_le32(readl(ss->base + SS_MD0 + i * 4));
+ else
+ v = cpu_to_be32(readl(ss->base + SS_MD0 + i * 4));
memcpy(areq->result + i * 4, &v, 4);
}
} else {
diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h
index 60425ac75d90..2b4c6333eb67 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h
@@ -131,7 +131,16 @@
#define SS_SEED_LEN 192
#define SS_DATA_LEN 160

+/*
+ * struct ss_variant - Describe SS hardware variant
+ * @sha1_in_be: The SHA1 digest is given by SS in BE, and so need to be inverted.
+ */
+struct ss_variant {
+ bool sha1_in_be;
+};
+
struct sun4i_ss_ctx {
+ const struct ss_variant *variant;
void __iomem *base;
int irq;
struct clk *busclk;
--
2.23.0

Corentin Labbe

belum dibaca,
19 Nov 2019, 02.39.2919/11/19
kepadaMaxime Ripard, da...@davemloft.net, her...@gondor.apana.org.au, mark.r...@arm.com, rob...@kernel.org, we...@csie.org, devic...@vger.kernel.org, linux-ar...@lists.infradead.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com
On Mon, Nov 18, 2019 at 12:11:43PM +0100, Maxime Ripard wrote:
> Hi,
>
> On Thu, Nov 14, 2019 at 03:48:11PM +0100, Corentin Labbe wrote:
> > Add the new A33 SecuritySystem compatible to the crypto node.
> >
> > Signed-off-by: Corentin Labbe <clabbe....@gmail.com>
> > ---
> > arch/arm/boot/dts/sun8i-a33.dtsi | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/arm/boot/dts/sun8i-a33.dtsi b/arch/arm/boot/dts/sun8i-a33.dtsi
> > index 1532a0e59af4..5680fa1de102 100644
> > --- a/arch/arm/boot/dts/sun8i-a33.dtsi
> > +++ b/arch/arm/boot/dts/sun8i-a33.dtsi
> > @@ -215,7 +215,8 @@
> > };
> >
> > crypto: crypto-engine@1c15000 {
> > - compatible = "allwinner,sun4i-a10-crypto";
> > + compatible = "allwinner,sun8i-a33-crypto",
> > + "allwinner,sun4i-a10-crypto";
>
> If some algorithms aren't working properly, we can't really fall back
> to it, we should just use the a33 compatible.
>

Since crypto selftest detect the problem, the fallback could be used and SS will just be in degraded mode (no sha1).
But since nobody reported this problem since 4 years (when SS was added in a33 dts), the absence of sha1 is clearly not an issue.

Regards

Corentin Labbe

belum dibaca,
20 Nov 2019, 10.28.3920/11/19
kepadada...@davemloft.net, her...@gondor.apana.org.au, mark.r...@arm.com, mri...@kernel.org, rob...@kernel.org, we...@csie.org, devic...@vger.kernel.org, linux-ar...@lists.infradead.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Corentin Labbe
Thanks to Igor Pecovnik, I have now in my kernelCI lab, a sun8i-a33-olinuxino.
Strange behavour, crypto selftests was failling but only for SHA1 on
this A33 SoC.

This is due to the A33 SS having a difference with all other SS, it give SHA1 digest directly in BE.
This serie handle this difference.

Changes since v1:
- removed compatible fallback

Corentin Labbe (3):
dt-bindings: crypto: add new compatible for A33 SS
ARM: dts: sun8i: a33: add the new SS compatible
crypto: sun4i-ss: add the A33 variant of SS

.../crypto/allwinner,sun4i-a10-crypto.yaml | 2 ++
arch/arm/boot/dts/sun8i-a33.dtsi | 2 +-
.../crypto/allwinner/sun4i-ss/sun4i-ss-core.c | 22 ++++++++++++++++++-
.../crypto/allwinner/sun4i-ss/sun4i-ss-hash.c | 5 ++++-
drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h | 9 ++++++++
5 files changed, 37 insertions(+), 3 deletions(-)

--
2.23.0

Corentin Labbe

belum dibaca,
20 Nov 2019, 10.28.4020/11/19
kepadada...@davemloft.net, her...@gondor.apana.org.au, mark.r...@arm.com, mri...@kernel.org, rob...@kernel.org, we...@csie.org, devic...@vger.kernel.org, linux-ar...@lists.infradead.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Corentin Labbe
The A33 SS has a difference with all other SS, it give SHA1 digest
directly in BE.
This difference need to be handlded by the driver and so need a new
compatible.

Signed-off-by: Corentin Labbe <clabbe....@gmail.com>
---
.../devicetree/bindings/crypto/allwinner,sun4i-a10-crypto.yaml | 2 ++
1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/crypto/allwinner,sun4i-a10-crypto.yaml b/Documentation/devicetree/bindings/crypto/allwinner,sun4i-a10-crypto.yaml
index 80b3e7350a73..5fc88fb3a91b 100644
--- a/Documentation/devicetree/bindings/crypto/allwinner,sun4i-a10-crypto.yaml
+++ b/Documentation/devicetree/bindings/crypto/allwinner,sun4i-a10-crypto.yaml
@@ -23,6 +23,8 @@ properties:
- items:
- const: allwinner,sun7i-a20-crypto
- const: allwinner,sun4i-a10-crypto
+ - items:
+ - const: allwinner,sun8i-a33-crypto

Corentin Labbe

belum dibaca,
20 Nov 2019, 10.28.4220/11/19
kepadada...@davemloft.net, her...@gondor.apana.org.au, mark.r...@arm.com, mri...@kernel.org, rob...@kernel.org, we...@csie.org, devic...@vger.kernel.org, linux-ar...@lists.infradead.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Corentin Labbe
Add the new A33 SS compatible to the crypto node.

Signed-off-by: Corentin Labbe <clabbe....@gmail.com>
---
arch/arm/boot/dts/sun8i-a33.dtsi | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/sun8i-a33.dtsi b/arch/arm/boot/dts/sun8i-a33.dtsi
index 1532a0e59af4..a2c37adacf77 100644
--- a/arch/arm/boot/dts/sun8i-a33.dtsi
+++ b/arch/arm/boot/dts/sun8i-a33.dtsi
@@ -215,7 +215,7 @@
};

crypto: crypto-engine@1c15000 {
- compatible = "allwinner,sun4i-a10-crypto";
+ compatible = "allwinner,sun8i-a33-crypto";

Corentin Labbe

belum dibaca,
20 Nov 2019, 10.28.4320/11/19
kepadada...@davemloft.net, her...@gondor.apana.org.au, mark.r...@arm.com, mri...@kernel.org, rob...@kernel.org, we...@csie.org, devic...@vger.kernel.org, linux-ar...@lists.infradead.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Corentin Labbe
The A33 SS has a difference with all other SS, it give SHA1 digest
directly in BE.
So this patch adds variant support in sun4i-ss.

Fixes: 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")
Signed-off-by: Corentin Labbe <clabbe....@gmail.com>
---
.../crypto/allwinner/sun4i-ss/sun4i-ss-core.c | 22 ++++++++++++++++++-
.../crypto/allwinner/sun4i-ss/sun4i-ss-hash.c | 5 ++++-
drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h | 9 ++++++++

Rob Herring

belum dibaca,
4 Des 2019, 11.18.1604/12/19
kepadaCorentin Labbe, da...@davemloft.net, her...@gondor.apana.org.au, mark.r...@arm.com, mri...@kernel.org, rob...@kernel.org, we...@csie.org, devic...@vger.kernel.org, linux-ar...@lists.infradead.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com, Corentin Labbe
On Wed, 20 Nov 2019 16:28:31 +0100, Corentin Labbe wrote:
> The A33 SS has a difference with all other SS, it give SHA1 digest
> directly in BE.
> This difference need to be handlded by the driver and so need a new
> compatible.
>
> Signed-off-by: Corentin Labbe <clabbe....@gmail.com>
> ---
> .../devicetree/bindings/crypto/allwinner,sun4i-a10-crypto.yaml | 2 ++
> 1 file changed, 2 insertions(+)
>

Acked-by: Rob Herring <ro...@kernel.org>

Herbert Xu

belum dibaca,
11 Des 2019, 04.35.5611/12/19
kepadaCorentin Labbe, da...@davemloft.net, mark.r...@arm.com, mri...@kernel.org, rob...@kernel.org, we...@csie.org, devic...@vger.kernel.org, linux-ar...@lists.infradead.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, linux...@googlegroups.com
On Wed, Nov 20, 2019 at 04:28:33PM +0100, Corentin Labbe wrote:
> The A33 SS has a difference with all other SS, it give SHA1 digest
> directly in BE.
> So this patch adds variant support in sun4i-ss.
>
> Fixes: 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")
> Signed-off-by: Corentin Labbe <clabbe....@gmail.com>
> ---
> .../crypto/allwinner/sun4i-ss/sun4i-ss-core.c | 22 ++++++++++++++++++-
> .../crypto/allwinner/sun4i-ss/sun4i-ss-hash.c | 5 ++++-
> drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h | 9 ++++++++
> 3 files changed, 34 insertions(+), 2 deletions(-)

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

Chen-Yu Tsai

belum dibaca,
12 Mar 2020, 01.39.2012/03/20
kepadaLABBE Corentin, David Miller, Herbert Xu, Mark Rutland, Maxime Ripard, Rob Herring, devicetree, linux-arm-kernel, linux-...@vger.kernel.org, linux-kernel, linux-sunxi
On Wed, Nov 20, 2019 at 11:28 PM Corentin Labbe
<clabbe....@gmail.com> wrote:
>
> Thanks to Igor Pecovnik, I have now in my kernelCI lab, a sun8i-a33-olinuxino.
> Strange behavour, crypto selftests was failling but only for SHA1 on
> this A33 SoC.
>
> This is due to the A33 SS having a difference with all other SS, it give SHA1 digest directly in BE.
> This serie handle this difference.
>
> Changes since v1:
> - removed compatible fallback
>
> Corentin Labbe (3):
> dt-bindings: crypto: add new compatible for A33 SS
> ARM: dts: sun8i: a33: add the new SS compatible

Merged these two as fixes for v5.6, as the driver changes made it in v5.6-rc1.
Not sure if they will be accepted though.

ChenYu

> crypto: sun4i-ss: add the A33 variant of SS
>
> .../crypto/allwinner,sun4i-a10-crypto.yaml | 2 ++
> arch/arm/boot/dts/sun8i-a33.dtsi | 2 +-
> .../crypto/allwinner/sun4i-ss/sun4i-ss-core.c | 22 ++++++++++++++++++-
> .../crypto/allwinner/sun4i-ss/sun4i-ss-hash.c | 5 ++++-
> drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h | 9 ++++++++
> 5 files changed, 37 insertions(+), 3 deletions(-)
>
> --
> 2.23.0
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/20191120152833.20443-1-clabbe.montjoie%40gmail.com.
Balas ke semua
Balas ke penulis
Teruskan
0 pesan baru