Skip to contentSkip to conversation

crypto: starfive - Add drivers for crypto engine

PATCH Superseded Jia Jie Ho 3 participants 13 messages Mar 13, 2023 – Mar 27, 2023

Subsystems (5)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Jia Jie Ho

author maintainer
#0 lore raw

v3 cover crypto: starfive - Add drivers for crypto engine

This patch series adds kernel driver support for StarFive JH7110 crypto engine. The first patch adds Documentations for the device and Patch 2 adds device probe and DMA init for the module. Patch 3 adds crypto and DMA dts node for VisionFive 2 board. Patch 4 adds hash/hmac support to the module.

Patch 3 needs to be applied on top of:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
https://patchwork.kernel.org/project/linux-riscv/cover/[email protected]/

Changes v2->v3:
- Only implement digest and use fallback for other ops (Herbert)
- Use interrupt instead of polling for hash complete (Herbert)
- Remove manual data copy from out-of-bound memory location as it will be handled by DMA API. (Christoph & Herbert)

Changes v1->v2:
- Fixed yaml filename and format (Krzysztof)
- Removed unnecessary property names in yaml (Krzysztof)
- Moved of_device_id table close to usage (Krzysztof)
- Use dev_err_probe for error returns (Krzysztof)
- Dropped redundant readl and writel wrappers (Krzysztof)
- Updated commit signed offs (Conor)
- Dropped redundant node in dts, module set to on in dtsi (Conor)

Jia Jie Ho (4):
dt-bindings: crypto: Add StarFive crypto module
crypto: starfive - Add crypto engine support
riscv: dts: starfive: Add crypto and DMA node for VisionFive 2
crypto: starfive - Add hash and HMAC support

 .../crypto/starfive,jh7110-crypto.yaml        |   70 ++
 MAINTAINERS                                   |    7 +
 arch/riscv/boot/dts/starfive/jh7110.dtsi      |   28 +
 drivers/crypto/Kconfig                        |    1 +
 drivers/crypto/Makefile                       |    1 +
 drivers/crypto/starfive/Kconfig               |   21 +
 drivers/crypto/starfive/Makefile              |    4 +
 drivers/crypto/starfive/jh7110-cryp.c         |  239 ++++
 drivers/crypto/starfive/jh7110-cryp.h         |  134 +++
 drivers/crypto/starfive/jh7110-hash.c         | 1041 +++++++++++++++++
 10 files changed, 1546 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/crypto/starfive,jh7110-crypto.yaml
 create mode 100644 drivers/crypto/starfive/Kconfig
 create mode 100644 drivers/crypto/starfive/Makefile
 create mode 100644 drivers/crypto/starfive/jh7110-cryp.c
 create mode 100644 drivers/crypto/starfive/jh7110-cryp.h
 create mode 100644 drivers/crypto/starfive/jh7110-hash.c
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH v3 1/4 dt-bindings: crypto: Add StarFive crypto module

Add documentation to describe StarFive cryptographic engine.

---
 .../crypto/starfive,jh7110-crypto.yaml        | 70 +++++++++++++++++++
 1 file changed, 70 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/crypto/starfive,jh7110-crypto.yaml
Documentation/devicetree/bindings/crypto/starfive,jh7110-crypto.yaml new file +70 -0
new file mode 100644
index 000000000000..71a2876bd6e4
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/crypto/starfive,jh7110-crypto.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: StarFive Cryptographic Module
+
+maintainers:
+  - Jia Jie Ho <[email protected]>
+  - William Qiu <[email protected]>
+
+properties:
+  compatible:
+    const: starfive,jh7110-crypto
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: Hardware reference clock
+      - description: AHB reference clock
+
+  clock-names:
+    items:
+      - const: hclk
+      - const: ahb
+
+  interrupts:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+  dmas:
+    items:
+      - description: TX DMA channel
+      - description: RX DMA channel
+
+  dma-names:
+    items:
+      - const: tx
+      - const: rx
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - resets
+  - dmas
+  - dma-names
+
+additionalProperties: false
+
+examples:
+  - |
+    crypto: crypto@16000000 {
+        compatible = "starfive,jh7110-crypto";
+        reg = <0x16000000 0x4000>;
+        clocks = <&clk 15>, <&clk 16>;
+        clock-names = "hclk", "ahb";
+        interrupts = <28>;
+        resets = <&reset 3>;
+        dmas = <&dma 1 2>,
+               <&dma 0 2>;
+        dma-names = "tx", "rx";
+    };
+...
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH v3 2/4 crypto: starfive - Add crypto engine support

In reply to Jia Jie Ho

Adding device probe and DMA init for StarFive cryptographic module.

---
 MAINTAINERS                           |   7 +
 drivers/crypto/Kconfig                |   1 +
 drivers/crypto/Makefile               |   1 +
 drivers/crypto/starfive/Kconfig       |  17 +++
 drivers/crypto/starfive/Makefile      |   4 +
 drivers/crypto/starfive/jh7110-cryp.c | 202 ++++++++++++++++++++++++++
 drivers/crypto/starfive/jh7110-cryp.h |  67 +++++++++
 7 files changed, 299 insertions(+)
 create mode 100644 drivers/crypto/starfive/Kconfig
 create mode 100644 drivers/crypto/starfive/Makefile
 create mode 100644 drivers/crypto/starfive/jh7110-cryp.c
 create mode 100644 drivers/crypto/starfive/jh7110-cryp.h
MAINTAINERS +7 -0
index 65140500d9f8..a6f7677db4db 100644
@@ -19609,6 +19609,13 @@ F:	Documentation/devicetree/bindings/clock/starfive*
 F:	drivers/clk/starfive/
 F:	include/dt-bindings/clock/starfive*
 
+STARFIVE CRYPTO DRIVER
+M:	Jia Jie Ho <[email protected]>
+M:	William Qiu <[email protected]>
+S:	Supported
+F:	Documentation/devicetree/bindings/crypto/starfive*
+F:	drivers/crypto/starfive/
+
 STARFIVE PINCTRL DRIVER
 M:	Emil Renner Berthing <[email protected]>
 M:	Jianlong Huang <[email protected]>
drivers/crypto/Kconfig +1 -0
index 55e75fbb658e..64b94376601c 100644
@@ -817,5 +817,6 @@ config CRYPTO_DEV_SA2UL
 
 source "drivers/crypto/keembay/Kconfig"
 source "drivers/crypto/aspeed/Kconfig"
+source "drivers/crypto/starfive/Kconfig"
 
 endif # CRYPTO_HW
drivers/crypto/Makefile +1 -0
index 116de173a66c..212931c84412 100644
@@ -53,3 +53,4 @@ obj-y += xilinx/
 obj-y += hisilicon/
 obj-$(CONFIG_CRYPTO_DEV_AMLOGIC_GXL) += amlogic/
 obj-y += keembay/
+obj-y += starfive/
drivers/crypto/starfive/Kconfig new file +17 -0
new file mode 100644
index 000000000000..73f39b6bc09f
@@ -0,0 +1,17 @@
+#
+# StarFive crypto drivers configuration
+#
+
+config CRYPTO_DEV_JH7110
+	tristate "StarFive JH7110 cryptographic engine driver"
+	depends on SOC_STARFIVE
+	select CRYPTO_ENGINE
+	select ARM_AMBA
+	select DMADEVICES
+	select AMBA_PL08X
+	help
+	  Support for StarFive JH7110 crypto hardware acceleration engine.
+	  This module provides acceleration for public key algo,
+	  skciphers, AEAD and hash functions.
+
+	  If you choose 'M' here, this module will be called starfive-crypto.
drivers/crypto/starfive/Makefile new file +4 -0
new file mode 100644
index 000000000000..071a4872fb5f
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_CRYPTO_DEV_JH7110) += jh7110-crypto.o
+starfive-crypto-objs := jh7110-cryp.o
drivers/crypto/starfive/jh7110-cryp.c new file +202 -0

202 lines not on this page · raw message

drivers/crypto/starfive/jh7110-cryp.h new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#3 lore raw

PATCH v3 3/4 riscv: dts: starfive: Add crypto and DMA node for VisionFive 2

In reply to Jia Jie Ho

Add StarFive cryptographic module and dedicated DMA controller node to VisionFive 2 SoCs.

---
 arch/riscv/boot/dts/starfive/jh7110.dtsi | 28 ++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
arch/riscv/boot/dts/starfive/jh7110.dtsi +28 -0
index 4ac159d79d66..591abe57ec31 100644
@@ -455,5 +455,33 @@ uart5: serial@12020000 {
 			reg-shift = <2>;
 			status = "disabled";
 		};
+
+		sdma: dma@16008000 {
+			compatible = "arm,pl080", "arm,primecell";
+			arm,primecell-periphid = <0x00041080>;
+			reg = <0x0 0x16008000 0x0 0x4000>;
+			interrupts = <29>;
+			clocks = <&stgcrg JH7110_STGCLK_SEC_HCLK>,
+				 <&stgcrg JH7110_STGCLK_SEC_MISCAHB>;
+			clock-names = "hclk", "apb_pclk";
+			resets = <&stgcrg JH7110_STGRST_SEC_TOP_HRESETN>;
+			lli-bus-interface-ahb1;
+			mem-bus-interface-ahb1;
+			memcpy-burst-size = <256>;
+			memcpy-bus-width = <32>;
+			#dma-cells = <2>;
+		};
+
+		crypto: crypto@16000000 {
+			compatible = "starfive,jh7110-crypto";
+			reg = <0x0 0x16000000 0x0 0x4000>;
+			clocks = <&stgcrg JH7110_STGCLK_SEC_HCLK>,
+				 <&stgcrg JH7110_STGCLK_SEC_MISCAHB>;
+			clock-names = "hclk", "ahb";
+			interrupts = <28>;
+			resets = <&stgcrg JH7110_STGRST_SEC_TOP_HRESETN>;
+			dmas = <&sdma 1 2>, <&sdma 0 2>;
+			dma-names = "tx", "rx";
+		};
 	};
 };
Signature · 1 line
2.25.1
author maintainer
#4 lore raw

PATCH v3 4/4 crypto: starfive - Add hash and HMAC support

In reply to Jia Jie Ho

Adding hash/HMAC support for SHA-2 and SM3 to StarFive cryptographic module.

---
 drivers/crypto/starfive/Kconfig       |    4 +
 drivers/crypto/starfive/Makefile      |    2 +-
 drivers/crypto/starfive/jh7110-cryp.c |   35 +
 drivers/crypto/starfive/jh7110-cryp.h |   69 +-
 drivers/crypto/starfive/jh7110-hash.c | 1041 +++++++++++++++++++++++++
 5 files changed, 1147 insertions(+), 4 deletions(-)
 create mode 100644 drivers/crypto/starfive/jh7110-hash.c
drivers/crypto/starfive/Kconfig +4 -0
index 73f39b6bc09f..cde485910f88 100644
@@ -6,6 +6,10 @@ config CRYPTO_DEV_JH7110
 	tristate "StarFive JH7110 cryptographic engine driver"
 	depends on SOC_STARFIVE
 	select CRYPTO_ENGINE
+	select CRYPTO_HMAC
+	select CRYPTO_SHA256
+	select CRYPTO_SHA512
+	select CRYPTO_SM3_GENERIC
 	select ARM_AMBA
 	select DMADEVICES
 	select AMBA_PL08X
drivers/crypto/starfive/Makefile +1 -1
index 071a4872fb5f..2af49062e36d 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_CRYPTO_DEV_JH7110) += jh7110-crypto.o
-starfive-crypto-objs := jh7110-cryp.o
+jh7110-crypto-objs := jh7110-cryp.o jh7110-hash.o
drivers/crypto/starfive/jh7110-cryp.c +35 -0
index abd500f3c1f3..94c99aab308f 100644
@@ -85,10 +85,25 @@ static void starfive_dma_cleanup(struct starfive_cryp_dev *cryp)
 	dma_release_channel(cryp->rx);
 }
 
+static irqreturn_t starfive_cryp_irq(int irq, void *priv)
+{
+	u32 status;
+	struct starfive_cryp_dev *cryp = (struct starfive_cryp_dev *)priv;
+
+	status = readl(cryp->base + STARFIVE_IE_FLAG_OFFSET);
+	if (status & STARFIVE_IE_FLAG_HASH_DONE) {
+		writel(STARFIVE_IE_MASK_HASH_DONE, cryp->base + STARFIVE_IE_MASK_OFFSET);
+		complete(&cryp->hash_done);
+	}
+
+	return IRQ_HANDLED;
+}
+
 static int starfive_cryp_probe(struct platform_device *pdev)
 {
 	struct starfive_cryp_dev *cryp;
 	struct resource *res;
+	int irq;
 	int ret;
 
 	cryp = devm_kzalloc(&pdev->dev, sizeof(*cryp), GFP_KERNEL);
@@ -121,6 +136,18 @@ static int starfive_cryp_probe(struct platform_device *pdev)
 		return dev_err_probe(&pdev->dev, PTR_ERR(cryp->rst),
 				     "Error getting hardware reset line\n");
 
+	init_completion(&cryp->hash_done);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
+
+	ret = devm_request_irq(&pdev->dev, irq, starfive_cryp_irq, 0, pdev->name,
+			       (void *)cryp);
+	if (ret)
+		return dev_err_probe(&pdev->dev, irq,
+				     "Failed to register interrupt handler\n");
+
 	clk_prepare_enable(cryp->hclk);
 	clk_prepare_enable(cryp->ahb);
 	reset_control_deassert(cryp->rst);
@@ -144,8 +171,14 @@ static int starfive_cryp_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_engine_start;
 
+	ret = starfive_hash_register_algs();
+	if (ret)
+		goto err_algs_hash;
+
 	return 0;
 
+err_algs_hash:
+	crypto_engine_stop(cryp->engine);
 err_engine_start:
 	crypto_engine_exit(cryp->engine);
 err_engine:
@@ -165,6 +198,8 @@ static int starfive_cryp_remove(struct platform_device *pdev)
 	if (!cryp)
 		return -ENODEV;
 
+	starfive_hash_unregister_algs();
+
 	crypto_engine_stop(cryp->engine);
 	crypto_engine_exit(cryp->engine);
 
drivers/crypto/starfive/jh7110-cryp.h +66 -3

105 lines not on this page · raw message

drivers/crypto/starfive/jh7110-hash.c new file +1041 -0

1,041 lines not on this page · raw message

Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH v3 4/4] crypto: starfive - Add hash and HMAC support

On 13 Mar 2023 21:56:46 +0800 Jia Jie Ho <[email protected]>

Quoted 36 lines
drivers/crypto/starfive/jh7110-hash.c new file +36 -0
+static int starfive_hash_xmit_dma(struct starfive_cryp_ctx *ctx)
+{
+	struct starfive_cryp_request_ctx *rctx = ctx->rctx;
+	struct starfive_cryp_dev *cryp = ctx->cryp;
+	struct dma_async_tx_descriptor	*in_desc;
+	dma_cookie_t cookie;
+	union  starfive_alg_cr alg_cr;
+	int total_len;
+	int ret;
+
+	if (!rctx->total)
+		return 0;
+
+	writel(rctx->total, cryp->base + STARFIVE_DMA_IN_LEN_OFFSET);
+
+	total_len = rctx->total;
+	total_len = (total_len & 0x3) ? (((total_len >> 2) + 1) << 2) : total_len;
+	sg_dma_len(rctx->in_sg) = total_len;
+
+	alg_cr.v = 0;
+	alg_cr.start = 1;
+	alg_cr.hash_dma_en = 1;
+
+	writel(alg_cr.v, cryp->base + STARFIVE_ALG_CR_OFFSET);
+
+	ret = dma_map_sg(cryp->dev, rctx->in_sg, rctx->in_sg_len, DMA_TO_DEVICE);
+	if (!ret)
+		return dev_err_probe(cryp->dev, -EINVAL, "dma_map_sg() error\n");
+
+	cryp->cfg_in.direction = DMA_MEM_TO_DEV;
+	cryp->cfg_in.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+	cryp->cfg_in.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+	cryp->cfg_in.src_maxburst = cryp->dma_maxburst;
+	cryp->cfg_in.dst_maxburst = cryp->dma_maxburst;
+	cryp->cfg_in.dst_addr = cryp->phys_base + STARFIVE_ALG_FIFO_OFFSET;
+

drivers/crypto/starfive/jh7110-hash.c line 155

Quoted 10 lines
drivers/crypto/starfive/jh7110-hash.c new file +10 -0
+	dmaengine_slave_config(cryp->tx, &cryp->cfg_in);
+
+	in_desc = dmaengine_prep_slave_sg(cryp->tx, rctx->in_sg,
+					  rctx->in_sg_len, DMA_MEM_TO_DEV,
+					  DMA_PREP_INTERRUPT  |  DMA_CTRL_ACK);
+
+	if (!in_desc)
+		return -EINVAL;
+
+	reinit_completion(&cryp->tx_comp);

What breaks without reinit?

drivers/crypto/starfive/jh7110-hash.c line 167

Quoted 12 lines
drivers/crypto/starfive/jh7110-hash.c new file +12 -0
+
+	in_desc->callback = starfive_hash_dma_callback;
+	in_desc->callback_param = cryp;
+
+	cookie = dmaengine_submit(in_desc);
+	dma_async_issue_pending(cryp->tx);
+
+	if (!wait_for_completion_timeout(&cryp->tx_comp,
+					 msecs_to_jiffies(10000))) {
+		dev_err(cryp->dev, "wait_for_completion_timeout error, cookie = %x\n",
+			dma_async_is_tx_complete(cryp->rx, cookie,
+						 NULL, NULL));

What prevents wakeup from coming in case of timeout?

drivers/crypto/starfive/jh7110-hash.c line 178

Quoted 11 lines
drivers/crypto/starfive/jh7110-hash.c new file +11 -0
+	}
+
+	dma_unmap_sg(cryp->dev, rctx->in_sg, rctx->in_sg_len, DMA_TO_DEVICE);
+
+	alg_cr.v = 0;
+	alg_cr.clear = 1;
+
+	writel(alg_cr.v, cryp->base + STARFIVE_ALG_CR_OFFSET);
+
+	return 0;
+}

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author maintainer
#6 lore raw

RE: [PATCH v3 4/4] crypto: starfive - Add hash and HMAC support

Quoted 2 lines

On 13 Mar 2023 21:56:46 +0800 Jia Jie Ho <[email protected]>

Quoted 1 line

+static int starfive_hash_xmit_dma(struct starfive_cryp_ctx *ctx) {

[...]

Quoted 7 lines

drivers/crypto/starfive/jh7110-hash.c

Quoted 4 lines
drivers/crypto/starfive/jh7110-hash.c new file +4 -0
+	dmaengine_slave_config(cryp->tx, &cryp->cfg_in);
+
+	in_desc = dmaengine_prep_slave_sg(cryp->tx, rctx->in_sg,
+					  rctx->in_sg_len,

DMA_MEM_TO_DEV,

Review

Quoted 1 line
(quoted diff) +1 -0
+					  DMA_PREP_INTERRUPT  |

DMA_CTRL_ACK);

Quoted 7 lines

drivers/crypto/starfive/jh7110-hash.c line 155

Quoted 5 lines
drivers/crypto/starfive/jh7110-hash.c new file +5 -0
+
+	if (!in_desc)
+		return -EINVAL;
+
+	reinit_completion(&cryp->tx_comp);

What breaks without reinit?

Hi Hillf,
So far, I don't see errors without the reinit.
I kept the reinit to reset the done field in case there is a prior transfer. I'll remove this if it is not needed.

Quoted 11 lines

drivers/crypto/starfive/jh7110-hash.c

Quoted 10 lines
drivers/crypto/starfive/jh7110-hash.c new file +10 -0
+
+	in_desc->callback = starfive_hash_dma_callback;
+	in_desc->callback_param = cryp;
+
+	cookie = dmaengine_submit(in_desc);
+	dma_async_issue_pending(cryp->tx);
+
+	if (!wait_for_completion_timeout(&cryp->tx_comp,
+					 msecs_to_jiffies(10000))) {
+		dev_err(cryp->dev, "wait_for_completion_timeout error,

cookie = %x\n",

Quoted 4 lines

drivers/crypto/starfive/jh7110-hash.c line 167

Quoted 2 lines
drivers/crypto/starfive/jh7110-hash.c new file +2 -0
+			dma_async_is_tx_complete(cryp->rx, cookie,
+						 NULL, NULL));

What prevents wakeup from coming in case of timeout?

Usually, timeout is caused by failure to complete all data transfer. It might be due to errors in dma chan setup or in case the hardware hangs.

Thanks for taking time looking into the patch.

Best regards,
Jia Jie

maintainer
#7 lore raw

Re: [PATCH v3 4/4] crypto: starfive - Add hash and HMAC support

In reply to Jia Jie Ho

drivers/crypto/starfive/jh7110-hash.c line 108

Quoted 7 lines · Jia Jie Ho
drivers/crypto/starfive/jh7110-hash.c new file +6 -0
+static void starfive_hash_dma_callback(void *param)
+{
+	struct starfive_cryp_dev *cryp = param;
+
+	complete(&cryp->tx_comp);
+}

Please get rid of tx_comp and do the rest of the processing here.

Thanks,

Signature · 8 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
author maintainer
#8 lore raw

RE: [PATCH v3 4/4] crypto: starfive - Add hash and HMAC support

Quoted 9 lines · Jia Jie Ho

drivers/crypto/starfive/jh7110-hash.c line 108

Quoted 6 lines
drivers/crypto/starfive/jh7110-hash.c new file +5 -0
+static void starfive_hash_dma_callback(void *param) {
+	struct starfive_cryp_dev *cryp = param;
+
+	complete(&cryp->tx_comp);
+}

Please get rid of tx_comp and do the rest of the processing here.

Hi Herbert,
Thanks for reviewing the patch.
I'll update this in next version.

Best regards,
Jia Jie

maintainer
#9 lore raw

Re: [PATCH v3 4/4] crypto: starfive - Add hash and HMAC support

In reply to Jia Jie Ho
Quoted 4 lines · Jia Jie Ho
drivers/crypto/starfive/jh7110-hash.c new file +3 -0
+static int starfive_hash_copy_sgs(struct starfive_cryp_request_ctx *rctx)
+{
+	void *buf_in;

drivers/crypto/starfive/jh7110-hash.c line 321

Quoted 10 lines
drivers/crypto/starfive/jh7110-hash.c new file +10 -0
+	int pages, total_in;
+
+	if (!starfive_hash_check_io_aligned(rctx)) {
+		rctx->sgs_copied = 0;
+		return 0;
+	}
+
+	total_in = ALIGN(rctx->total, rctx->blksize);
+	pages = total_in ? get_order(total_in) : 1;
+	buf_in = (void *)__get_free_pages(GFP_ATOMIC, pages);

Please don't allocate the whole thing because it could be unlimited in size (and triggered from user-space by untrusted users too).

If you have to copy, then just allocate a single page and copy that, hash, and then repeat until it's all done.

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer
#10 lore raw

Re: [PATCH v3 4/4] crypto: starfive - Add hash and HMAC support

Quoted 6 lines · Herbert Xu

Please don't allocate the whole thing because it could be unlimited in size (and triggered from user-space by untrusted users too).

If you have to copy, then just allocate a single page and copy that, hash, and then repeat until it's all done.

Nevermind, your hardware doesn't support hashing piece-meal.

So just use the fallback if it's not aligned.

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer
#11 lore raw

Re: [PATCH v3 4/4] crypto: starfive - Add hash and HMAC support

In reply to Jia Jie Ho

drivers/crypto/starfive/jh7110-hash.c line 396

Quoted 12 lines · Jia Jie Ho
drivers/crypto/starfive/jh7110-hash.c new file +11 -0
+static int starfive_hash_update(struct ahash_request *req)
+{
+	struct starfive_cryp_request_ctx *rctx = ahash_request_ctx(req);
+	struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
+	struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(tfm);
+
+	ahash_request_set_tfm(&rctx->ahash_fbk_req, ctx->ahash_fbk);
+	rctx->ahash_fbk_req.base.flags = req->base.flags
+		& CRYPTO_TFM_REQ_MAY_SLEEP;
+	rctx->ahash_fbk_req.nbytes = req->nbytes;
+	rctx->ahash_fbk_req.src = req->src;

Please don't modify the fields directly, use the ahash_request_set_* helpers. Since you allocated an async fallback, you should set the callbacks too.

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
author maintainer
#12 lore raw
In reply to Jia Jie Ho
Quoted 64 lines

-----Original Message-----
From: Jia Jie Ho <[email protected]>
Sent: 13 March, 2023 9:57 PM
To: Herbert Xu <[email protected]>; David S . Miller <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Emil Renner Berthing <[email protected]>; Conor Dooley <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: [PATCH v3 0/4] crypto: starfive - Add drivers for crypto engine

This patch series adds kernel driver support for StarFive JH7110 crypto engine. The first patch adds Documentations for the device and Patch 2 adds device probe and DMA init for the module. Patch 3 adds crypto and DMA dts node for VisionFive 2 board. Patch 4 adds hash/hmac support to the module.

Patch 3 needs to be applied on top of:
https://patchwork.kernel.org/project/linux-
riscv/patch/[email protected]/
https://patchwork.kernel.org/project/linux-
riscv/cover/[email protected]/

Changes v2->v3:
- Only implement digest and use fallback for other ops (Herbert)
- Use interrupt instead of polling for hash complete (Herbert)
- Remove manual data copy from out-of-bound memory location as it will be handled by DMA API. (Christoph & Herbert)

Changes v1->v2:
- Fixed yaml filename and format (Krzysztof)
- Removed unnecessary property names in yaml (Krzysztof)
- Moved of_device_id table close to usage (Krzysztof)
- Use dev_err_probe for error returns (Krzysztof)
- Dropped redundant readl and writel wrappers (Krzysztof)
- Updated commit signed offs (Conor)
- Dropped redundant node in dts, module set to on in dtsi (Conor)

Jia Jie Ho (4):
dt-bindings: crypto: Add StarFive crypto module
crypto: starfive - Add crypto engine support
riscv: dts: starfive: Add crypto and DMA node for VisionFive 2
crypto: starfive - Add hash and HMAC support

 .../crypto/starfive,jh7110-crypto.yaml        |   70 ++
 MAINTAINERS                                   |    7 +
 arch/riscv/boot/dts/starfive/jh7110.dtsi      |   28 +
 drivers/crypto/Kconfig                        |    1 +
 drivers/crypto/Makefile                       |    1 +
 drivers/crypto/starfive/Kconfig               |   21 +
 drivers/crypto/starfive/Makefile              |    4 +
 drivers/crypto/starfive/jh7110-cryp.c         |  239 ++++
 drivers/crypto/starfive/jh7110-cryp.h         |  134 +++
 drivers/crypto/starfive/jh7110-hash.c         | 1041 +++++++++++++++++
 10 files changed, 1546 insertions(+)
 create mode 100644
Documentation/devicetree/bindings/crypto/starfive,jh7110-crypto.yaml
 create mode 100644 drivers/crypto/starfive/Kconfig  create mode 100644
drivers/crypto/starfive/Makefile  create mode 100644
drivers/crypto/starfive/jh7110-cryp.c
 create mode 100644 drivers/crypto/starfive/jh7110-cryp.h
 create mode 100644 drivers/crypto/starfive/jh7110-hash.c
Quoted 2 lines

--
2.25.1

Hi Herbert/David,

Could you please help review this patch series?
Thanks in advance.

Best regards,
Jia Jie