* [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes
@ 2026-11-26 19:32 Jose Nieto
2026-11-26 19:32 ` [PATCH v13 01/25] dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines Jose Nieto
` (25 more replies)
0 siblings, 26 replies; 81+ messages in thread
From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw)
To: Corentin Labbe, Herbert Xu
Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree,
Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski,
Rob Herring, Conor Dooley, Jose Nieto
This is v13 of the Amlogic crypto driver series originally posted by
Alexey Romanov. It rebases the series onto linux-next (next-20261123) and
adds the fixes required for the current tree.
The series keeps Alexey's original implementation and commit split:
platform data, IRQ handling, MMIO helpers, multi-descriptor processing,
G12/AXG/A1 support, hasher, and the per-SoC DT bindings/DTS. While
rebasing, the fixes that landed in the driver since v12 are preserved
(IRQ handler return value and fallthrough, devm clock management, DMA SG
unmap on the cipher error path, probe cleanup and devm_kmalloc_obj
conversion).
On top of the rebased series, three patches add what is needed for the
current code:
- drop CRYPTO_ALG_ALLOCATES_MEMORY so dm-crypt can select the hardware
engine instead of silently falling back to software;
- add the ahash ->digest one-shot path and fix trailing-block handling
for digest requests;
- minor cleanup (unused fields/includes, stale kernel-doc).
Testing on Khadas VIM3 (A311D / G12B), booted with a linux-next kernel
built from this series:
- the crypto self-tests (known-answer tests) pass for ecb/cbc(aes) and
sha1/224/256;
- dm-crypt with aes-cbc-plain runs on top of cbc-aes-gxl and the driver's
request counter accounts for the I/O.
Attribution is preserved: the original 22 patches keep Alexey Romanov as
author and carry his Signed-off-by; the three additional patches are
authored by me.
Thanks,
Jose
Alexey Romanov (22):
dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt
lines
dt-bindings: crypto: amlogic,gxl-crypto: support new SoC's
crypto: amlogic - Don't hardcode IRQ count
crypto: amlogic - Add platform data
crypto: amlogic - Remove clock input
crypto: amlogic - Add MMIO helpers
crypto: amlogic - Move get_engine_number()
crypto: amlogic - Drop status field from meson_flow
crypto: amlogic - Move algs definition and cipher API to cipher.c
crypto: amlogic - Cleanup defines
crypto: amlogic - Process more than MAXDESCS descriptors
crypto: amlogic - Avoid kzalloc in engine thread
crypto: amlogic - Introduce hasher
crypto: amlogic - Use fallback for 192-bit keys
crypto: amlogic - Add support for G12-series
crypto: amlogic - Add support for AXG-series
crypto: amlogic - Add support for A1-series
arm64: dts: amlogic: gxl: correct crypto node definition
arm64: dts: amlogic: a1: add crypto node
arm64: dts: amlogic: s4: add crypto node
arm64: dts: amlogic: g12: add crypto node
arm64: dts: amlogic: axg: add crypto node
Jose Nieto (3):
crypto: amlogic: g12: drop CRYPTO_ALG_ALLOCATES_MEMORY
crypto: amlogic: hasher: add one-shot digest path
crypto: amlogic: drop unused field and stale includes
.../bindings/crypto/amlogic,gxl-crypto.yaml | 32 +-
arch/arm64/boot/dts/amlogic/meson-a1.dtsi | 14 +
arch/arm64/boot/dts/amlogic/meson-axg.dtsi | 7 +
.../boot/dts/amlogic/meson-g12-common.dtsi | 7 +
arch/arm64/boot/dts/amlogic/meson-gxl.dtsi | 6 +-
arch/arm64/boot/dts/amlogic/meson-s4.dtsi | 13 +
drivers/crypto/amlogic/Makefile | 2 +-
drivers/crypto/amlogic/amlogic-gxl-cipher.c | 605 ++++++++++++------
drivers/crypto/amlogic/amlogic-gxl-core.c | 281 ++++----
drivers/crypto/amlogic/amlogic-gxl-hasher.c | 510 +++++++++++++++
drivers/crypto/amlogic/amlogic-gxl.h | 120 +++-
11 files changed, 1219 insertions(+), 378 deletions(-)
create mode 100644 drivers/crypto/amlogic/amlogic-gxl-hasher.c
base-commit: 3191063649dbf7c0d0b768e1f3655e4c5fc6edb5
--
2.47.3
^ permalink raw reply [flat|nested] 81+ messages in thread* [PATCH v13 01/25] dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:43 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 02/25] dt-bindings: crypto: amlogic,gxl-crypto: support new SoC's Jose Nieto ` (24 subsequent siblings) 25 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> GXL and newer SoC's uses the DMA engine (not blkmv) for crypto HW. Crypto HW doesn't actually use the blkmv clk. At RTL level, crypto engine is hard-wired to a clk81 (CLKID_CLK81). Drop clock-names field from schema: name "blkmv" is invalid and "clk81" is confusing and sounds like something global. Also, GXL crypto IP isn't connected to the second interrupt line. This binding is useless, there are no users of this line. We must remove it from dt-bindings. Fixes: 7f7d115dfb51 ("dt-bindings: crypto: Add DT bindings documentation for amlogic-crypto") Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Rob Herring (Arm) <robh@kernel.org> --- .../devicetree/bindings/crypto/amlogic,gxl-crypto.yaml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml b/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml index 948e11ebe4ee..fdc39797a2a9 100644 --- a/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml +++ b/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml @@ -20,20 +20,15 @@ properties: interrupts: items: - description: Interrupt for flow 0 - - description: Interrupt for flow 1 clocks: maxItems: 1 - clock-names: - const: blkmv - required: - compatible - reg - interrupts - clocks - - clock-names additionalProperties: false @@ -46,7 +41,6 @@ examples: crypto: crypto-engine@c883e000 { compatible = "amlogic,gxl-crypto"; reg = <0xc883e000 0x36>; - interrupts = <GIC_SPI 188 IRQ_TYPE_EDGE_RISING>, <GIC_SPI 189 IRQ_TYPE_EDGE_RISING>; - clocks = <&clkc CLKID_BLKMV>; - clock-names = "blkmv"; + interrupts = <GIC_SPI 188 IRQ_TYPE_EDGE_RISING>; + clocks = <&clkc CLKID_CLK81>; }; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v13 01/25] dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines 2026-11-26 19:32 ` [PATCH v13 01/25] dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines Jose Nieto @ 2026-11-26 19:43 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-26 19:43 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] dt-bindings: crypto: amlogic,gxl-crypto: interrupts listed before clocks -- commit b4a68c4c1f0b87becd0da61f8fb2312014b9b3ee Author: Alexey Romanov <romanov.alexey2000@gmail.com> dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines This commit removes the clock-names property and the unused second interrupt line from the amlogic,gxl-crypto binding schema and updates the example clock to CLKID_CLK81. > diff --git a/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml b/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml > index 948e11ebe4eeb..fdc39797a2a9c 100644 > --- a/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml > +++ b/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml > @@ -20,20 +20,15 @@ properties: > interrupts: > items: > - description: Interrupt for flow 0 > - - description: Interrupt for flow 1 > > clocks: > maxItems: 1 > > - clock-names: > - const: blkmv > - > required: > - compatible > - reg > - interrupts > - clocks > - - clock-names > > additionalProperties: false > > @@ -46,7 +41,6 @@ examples: > crypto: crypto-engine@c883e000 { > compatible = "amlogic,gxl-crypto"; > reg = <0xc883e000 0x36>; > - interrupts = <GIC_SPI 188 IRQ_TYPE_EDGE_RISING>, <GIC_SPI 189 IRQ_TYPE_EDGE_RISING>; > - clocks = <&clkc CLKID_BLKMV>; > - clock-names = "blkmv"; > + interrupts = <GIC_SPI 188 IRQ_TYPE_EDGE_RISING>; > + clocks = <&clkc CLKID_CLK81>; > }; [Severity: Low] This isn't a bug, but the example node, properties, and required lists place interrupts before clocks instead of following the standard DT binding order (compatible, reg, clocks, interrupts). -- Sashiko AI review · https://sashiko.dev/#/patchset/20261126193241.1471372-1-jnieto.alaber@gmail.com?part=1 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v13 02/25] dt-bindings: crypto: amlogic,gxl-crypto: support new SoC's 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto 2026-11-26 19:32 ` [PATCH v13 01/25] dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:32 ` [PATCH v13 03/25] crypto: amlogic - Don't hardcode IRQ count Jose Nieto ` (23 subsequent siblings) 25 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Now crypto module available at G12A/G12B/S4/A1/SM1/AXG. 1. Add new compatibles: - amlogic,g12a-crypto - amlogic,axg-crypto - amlogic,a1-crypto - amlogic,s4-crypto (uses a1-crypto as fallback) Difference between this compatibles: * Different registers offset and the number of setup descriptors. * GXL doesn't support hashing like the others. * G12A/B and A1/S4 crypto HW don't support 192 AES key. * GXL, G12A/B and AXG require a reverse IV key before processing. 2. Add power-domains in schema, which is required only for A1. This is specific vendor design: in old SoC's power domain for crypto HW was not configurable, but in A1-series it is configurable. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Rob Herring (Arm) <robh@kernel.org> --- .../bindings/crypto/amlogic,gxl-crypto.yaml | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml b/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml index fdc39797a2a9..106a9d1fed69 100644 --- a/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml +++ b/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml @@ -11,8 +11,16 @@ maintainers: properties: compatible: - items: - - const: amlogic,gxl-crypto + oneOf: + - items: + - enum: + - amlogic,s4-crypto + - const: amlogic,a1-crypto + - enum: + - amlogic,gxl-crypto + - amlogic,axg-crypto + - amlogic,g12a-crypto + - amlogic,a1-crypto reg: maxItems: 1 @@ -24,12 +32,24 @@ properties: clocks: maxItems: 1 + power-domains: + maxItems: 1 + required: - compatible - reg - interrupts - clocks +allOf: + - if: + properties: + compatible: + const: amlogic,a1-crypto + then: + required: + - power-domains + additionalProperties: false examples: -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v13 03/25] crypto: amlogic - Don't hardcode IRQ count 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto 2026-11-26 19:32 ` [PATCH v13 01/25] dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines Jose Nieto 2026-11-26 19:32 ` [PATCH v13 02/25] dt-bindings: crypto: amlogic,gxl-crypto: support new SoC's Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:42 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 04/25] crypto: amlogic - Add platform data Jose Nieto ` (22 subsequent siblings) 25 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> IRQ count is no longer hardcoded, and make it part of struct meson_flow. We need this for extend driver support for other Amlogic SoC's. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 2 +- drivers/crypto/amlogic/amlogic-gxl-core.c | 48 +++++++++++---------- drivers/crypto/amlogic/amlogic-gxl.h | 8 ++-- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index d78815b0547d..bcaed2f413d3 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -19,7 +19,7 @@ static int get_engine_number(struct meson_dev *mc) { - return atomic_inc_return(&mc->flow) % MAXFLOW; + return atomic_inc_return(&mc->flow) % mc->flow_cnt; } static bool meson_cipher_need_fallback(struct skcipher_request *areq) diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 48dbdf452034..b6933be39a37 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -28,8 +28,8 @@ static irqreturn_t meson_irq_handler(int irq, void *data) int flow; u32 p; - for (flow = 0; flow < MAXFLOW; flow++) { - if (mc->irqs[flow] == irq) { + for (flow = 0; flow < mc->flow_cnt; flow++) { + if (mc->chanlist[flow].irq == irq) { p = readl(mc->base + ((0x04 + flow) << 2)); if (p) { writel_relaxed(0xF, mc->base + ((0x4 + flow) << 2)); @@ -111,7 +111,7 @@ static int meson_debugfs_show(struct seq_file *seq, void *v) struct meson_dev *mc __maybe_unused = seq->private; int i; - for (i = 0; i < MAXFLOW; i++) + for (i = 0; i < mc->flow_cnt; i++) seq_printf(seq, "Channel %d: nreq %lu\n", i, #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG mc->chanlist[i].stat_req); @@ -154,13 +154,31 @@ static void meson_free_chanlist(struct meson_dev *mc, int i) */ static int meson_allocate_chanlist(struct meson_dev *mc) { + struct platform_device *pdev = to_platform_device(mc->dev); int i, err; - mc->chanlist = devm_kzalloc_objs(mc->dev, struct meson_flow, MAXFLOW); + mc->flow_cnt = platform_irq_count(pdev); + if (mc->flow_cnt <= 0) { + dev_err(mc->dev, "No IRQs defined\n"); + return -ENODEV; + } + + mc->chanlist = devm_kzalloc_objs(mc->dev, struct meson_flow, mc->flow_cnt); if (!mc->chanlist) return -ENOMEM; - for (i = 0; i < MAXFLOW; i++) { + for (i = 0; i < mc->flow_cnt; i++) { + mc->chanlist[i].irq = platform_get_irq(pdev, i); + if (mc->chanlist[i].irq < 0) + return mc->chanlist[i].irq; + + err = devm_request_irq(mc->dev, mc->chanlist[i].irq, + meson_irq_handler, 0, "aml-crypto", mc); + if (err < 0) { + dev_err(mc->dev, "Cannot request IRQ for flow %d\n", i); + return err; + } + init_completion(&mc->chanlist[i].complete); mc->chanlist[i].engine = crypto_engine_alloc_init(mc->dev, true); @@ -230,7 +248,7 @@ static void meson_unregister_algs(struct meson_dev *mc) static int meson_crypto_probe(struct platform_device *pdev) { struct meson_dev *mc; - int err, i; + int err; mc = devm_kzalloc_obj(&pdev->dev, *mc); if (!mc) @@ -254,19 +272,6 @@ static int meson_crypto_probe(struct platform_device *pdev) if (err) return err; - for (i = 0; i < MAXFLOW; i++) { - mc->irqs[i] = platform_get_irq(pdev, i); - if (mc->irqs[i] < 0) { - err = mc->irqs[i]; - goto error_chanlist; - } - - err = devm_request_irq(&pdev->dev, mc->irqs[i], meson_irq_handler, 0, - "gxl-crypto", mc); - if (err < 0) - goto error_chanlist; - } - err = meson_register_algs(mc); if (err) goto error_alg; @@ -285,8 +290,7 @@ static int meson_crypto_probe(struct platform_device *pdev) return 0; error_alg: meson_unregister_algs(mc); -error_chanlist: - meson_free_chanlist(mc, MAXFLOW - 1); + meson_free_chanlist(mc, mc->flow_cnt - 1); return err; } @@ -300,7 +304,7 @@ static void meson_crypto_remove(struct platform_device *pdev) meson_unregister_algs(mc); - meson_free_chanlist(mc, MAXFLOW - 1); + meson_free_chanlist(mc, mc->flow_cnt - 1); } static const struct of_device_id meson_crypto_of_match_table[] = { diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index d68094ffb70a..9f1ef87333ae 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -22,8 +22,6 @@ #define MESON_OPMODE_ECB 0 #define MESON_OPMODE_CBC 1 -#define MAXFLOW 2 - #define MAXDESC 64 #define DESC_LAST BIT(18) @@ -62,6 +60,7 @@ struct meson_desc { * @keylen: keylen for this flow operation * @complete: completion for the current task on this flow * @status: set to 1 by interrupt if task is done + * @irq: IRQ number for amlogic-crypto * @t_phy: Physical address of task * @tl: pointer to the current ce_task for this flow * @stat_req: number of request done by this flow @@ -70,6 +69,7 @@ struct meson_flow { struct crypto_engine *engine; struct completion complete; int status; + int irq; unsigned int keylen; dma_addr_t t_phy; struct meson_desc *tl; @@ -85,7 +85,7 @@ struct meson_flow { * @dev: the platform device * @chanlist: array of all flow * @flow: flow to use in next request - * @irqs: IRQ numbers for amlogic-crypto + * @flow_cnt: flow count for amlogic-crypto * @dbgfs_dir: Debugfs dentry for statistic directory * @dbgfs_stats: Debugfs dentry for statistic counters */ @@ -95,7 +95,7 @@ struct meson_dev { struct device *dev; struct meson_flow *chanlist; atomic_t flow; - int irqs[MAXFLOW]; + int flow_cnt; #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG struct dentry *dbgfs_dir; #endif -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v13 03/25] crypto: amlogic - Don't hardcode IRQ count 2026-11-26 19:32 ` [PATCH v13 03/25] crypto: amlogic - Don't hardcode IRQ count Jose Nieto @ 2026-11-26 19:42 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-26 19:42 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] crypto: amlogic - leak on IRQ error in meson_allocate_chanlist() - [Medium] crypto: amlogic - IRQ enabled before init_completion() in probe - [Medium] crypto: amlogic - meson_allocate_chanlist() clobbers -EPROBE_DEFER -- commit b3f5f8c9ed61610fac3de12f0104aa644e360718 Author: Alexey Romanov <romanov.alexey2000@gmail.com> crypto: amlogic - Don't hardcode IRQ count This commit replaces the hardcoded MAXFLOW constant with a dynamic flow_cnt obtained via platform_irq_count() and moves per-flow IRQ lookup and registration into meson_allocate_chanlist(). > diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c > index 48dbdf4520348..b6933be39a377 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-core.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c [ ... ] > @@ -154,13 +154,31 @@ static void meson_free_chanlist(struct meson_dev *mc, int i) > */ > static int meson_allocate_chanlist(struct meson_dev *mc) > { > + struct platform_device *pdev = to_platform_device(mc->dev); > int i, err; > > - mc->chanlist = devm_kzalloc_objs(mc->dev, struct meson_flow, MAXFLOW); > + mc->flow_cnt = platform_irq_count(pdev); > + if (mc->flow_cnt <= 0) { > + dev_err(mc->dev, "No IRQs defined\n"); > + return -ENODEV; > + } [Severity: Medium] Does this overwrite -EPROBE_DEFER from platform_irq_count() with -ENODEV? When the interrupt controller is not ready yet, platform_irq_count() returns -EPROBE_DEFER, so returning -ENODEV breaks deferred probing and logs a false error. Returning mc->flow_cnt when mc->flow_cnt < 0 avoids this regression. > + > + mc->chanlist = devm_kzalloc_objs(mc->dev, struct meson_flow, mc->flow_cnt); > if (!mc->chanlist) > return -ENOMEM; > > - for (i = 0; i < MAXFLOW; i++) { > + for (i = 0; i < mc->flow_cnt; i++) { > + mc->chanlist[i].irq = platform_get_irq(pdev, i); > + if (mc->chanlist[i].irq < 0) > + return mc->chanlist[i].irq; > + > + err = devm_request_irq(mc->dev, mc->chanlist[i].irq, > + meson_irq_handler, 0, "aml-crypto", mc); > + if (err < 0) { > + dev_err(mc->dev, "Cannot request IRQ for flow %d\n", i); > + return err; > + } [Severity: Medium] If platform_get_irq() or devm_request_irq() fails on iteration i > 0, does returning directly skip meson_free_chanlist() for the earlier channels? Each completed iteration starts a crypto_engine kthread and allocates mc->chanlist[i].tl with dma_alloc_coherent(). Returning without unwinding channels 0 .. i - 1 leaks their coherent DMA buffers and leaves their kworker threads running after devres frees the struct crypto_engine objects on probe failure. Decrementing i and jumping to error_engine cleans up the initialized channels. > + > init_completion(&mc->chanlist[i].complete); [Severity: Medium] Can meson_irq_handler() fire before init_completion() initializes mc->chanlist[i].complete? devm_request_irq() enables the interrupt line while mc->chanlist[i].complete is still zero-initialized, and meson_irq_handler() calls complete(&mc->chanlist[flow].complete) when the flow status register is non-zero, which would dereference a NULL waitqueue pointer. Calling init_completion() before devm_request_irq() avoids this window. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261126193241.1471372-1-jnieto.alaber@gmail.com?part=3 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v13 04/25] crypto: amlogic - Add platform data 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (2 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 03/25] crypto: amlogic - Don't hardcode IRQ count Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:32 ` [PATCH v13 05/25] crypto: amlogic - Remove clock input Jose Nieto ` (21 subsequent siblings) 25 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> To support other Amlogic SoC's we have to use platform data: descriptors and status registers offsets are individual for each SoC series. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 2 +- drivers/crypto/amlogic/amlogic-gxl-core.c | 22 +++++++++++++++++---- drivers/crypto/amlogic/amlogic-gxl.h | 11 +++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index bcaed2f413d3..c458548f29b2 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -234,7 +234,7 @@ static int meson_cipher(struct skcipher_request *areq) reinit_completion(&mc->chanlist[flow].complete); mc->chanlist[flow].status = 0; - writel(mc->chanlist[flow].t_phy | 2, mc->base + (flow << 2)); + writel(mc->chanlist[flow].t_phy | 2, mc->base + ((mc->pdata->descs_reg + flow) << 2)); wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete, msecs_to_jiffies(500)); if (mc->chanlist[flow].status == 0) { diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index b6933be39a37..24ef7d5a5607 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -18,6 +18,7 @@ #include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/of_device.h> #include <linux/platform_device.h> #include "amlogic-gxl.h" @@ -30,9 +31,10 @@ static irqreturn_t meson_irq_handler(int irq, void *data) for (flow = 0; flow < mc->flow_cnt; flow++) { if (mc->chanlist[flow].irq == irq) { - p = readl(mc->base + ((0x04 + flow) << 2)); + p = readl(mc->base + ((mc->pdata->status_reg + flow) << 2)); if (p) { - writel_relaxed(0xF, mc->base + ((0x4 + flow) << 2)); + writel_relaxed(0xF, mc->base + + ((mc->pdata->status_reg + flow) << 2)); mc->chanlist[flow].status = 1; complete(&mc->chanlist[flow].complete); return IRQ_HANDLED; @@ -254,6 +256,10 @@ static int meson_crypto_probe(struct platform_device *pdev) if (!mc) return -ENOMEM; + mc->pdata = of_device_get_match_data(&pdev->dev); + if (!mc->pdata) + return -EINVAL; + mc->dev = &pdev->dev; platform_set_drvdata(pdev, mc); @@ -307,9 +313,17 @@ static void meson_crypto_remove(struct platform_device *pdev) meson_free_chanlist(mc, mc->flow_cnt - 1); } +static const struct meson_pdata meson_gxl_pdata = { + .descs_reg = 0x0, + .status_reg = 0x4, +}; + static const struct of_device_id meson_crypto_of_match_table[] = { - { .compatible = "amlogic,gxl-crypto", }, - {} + { + .compatible = "amlogic,gxl-crypto", + .data = &meson_gxl_pdata, + }, + {}, }; MODULE_DEVICE_TABLE(of, meson_crypto_of_match_table); diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index 9f1ef87333ae..e0bc5c39bf2c 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -78,6 +78,16 @@ struct meson_flow { #endif }; +/* + * struct meson_pdata - SoC series dependent data. + * @reg_descs: offset to descriptors register + * @reg_status: offset to status register + */ +struct meson_pdata { + u32 descs_reg; + u32 status_reg; +}; + /* * struct meson_dev - main container for all this driver information * @base: base address of amlogic-crypto @@ -93,6 +103,7 @@ struct meson_dev { void __iomem *base; struct clk *busclk; struct device *dev; + const struct meson_pdata *pdata; struct meson_flow *chanlist; atomic_t flow; int flow_cnt; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v13 05/25] crypto: amlogic - Remove clock input 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (3 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 04/25] crypto: amlogic - Add platform data Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:44 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 06/25] crypto: amlogic - Add MMIO helpers Jose Nieto ` (20 subsequent siblings) 25 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Amlogic crypto IP, which uses DMA crypto engine, doesn't take a clock input. Fixes: 48fe583fe541 ("crypto: amlogic - Add crypto accelerator for amlogic GXL") Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-core.c | 8 -------- drivers/crypto/amlogic/amlogic-gxl.h | 2 -- 2 files changed, 10 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 24ef7d5a5607..37224d75edfb 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -9,7 +9,6 @@ #include <crypto/engine.h> #include <crypto/internal/skcipher.h> -#include <linux/clk.h> #include <linux/dma-mapping.h> #include <linux/err.h> #include <linux/interrupt.h> @@ -267,13 +266,6 @@ static int meson_crypto_probe(struct platform_device *pdev) if (IS_ERR(mc->base)) return PTR_ERR(mc->base); - mc->busclk = devm_clk_get_enabled(&pdev->dev, "blkmv"); - if (IS_ERR(mc->busclk)) { - err = PTR_ERR(mc->busclk); - dev_err(&pdev->dev, "Cannot get/enable core clock err=%d\n", err); - return err; - } - err = meson_allocate_chanlist(mc); if (err) return err; diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index e0bc5c39bf2c..5149dc6e9f60 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -91,7 +91,6 @@ struct meson_pdata { /* * struct meson_dev - main container for all this driver information * @base: base address of amlogic-crypto - * @busclk: bus clock for amlogic-crypto * @dev: the platform device * @chanlist: array of all flow * @flow: flow to use in next request @@ -101,7 +100,6 @@ struct meson_pdata { */ struct meson_dev { void __iomem *base; - struct clk *busclk; struct device *dev; const struct meson_pdata *pdata; struct meson_flow *chanlist; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v13 05/25] crypto: amlogic - Remove clock input 2026-11-26 19:32 ` [PATCH v13 05/25] crypto: amlogic - Remove clock input Jose Nieto @ 2026-11-26 19:44 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-26 19:44 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] crypto: amlogic - meson_crypto_probe() drops required DT clock enablement -- commit 6e2a1b06482267078b47ff3e21fbdf1bbeb5d603 Author: Alexey Romanov <romanov.alexey2000@gmail.com> crypto: amlogic - Remove clock input This commit removes the "blkmv" clock acquisition and the busclk field from the Amlogic GXL crypto driver. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c > index 24ef7d5a56075..37224d75edfbf 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-core.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c [ ... ] > @@ -267,13 +266,6 @@ static int meson_crypto_probe(struct platform_device *pdev) > if (IS_ERR(mc->base)) > return PTR_ERR(mc->base); > > - mc->busclk = devm_clk_get_enabled(&pdev->dev, "blkmv"); > - if (IS_ERR(mc->busclk)) { > - err = PTR_ERR(mc->busclk); > - dev_err(&pdev->dev, "Cannot get/enable core clock err=%d\n", err); > - return err; > - } > - > err = meson_allocate_chanlist(mc); > if (err) > return err; [Severity: Medium] Should meson_crypto_probe() pass NULL to devm_clk_get_enabled() instead of dropping the clock enablement entirely? Earlier in this series, commit "dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines" removed clock-names because the crypto IP is clocked by clk81 rather than blkmv, but kept the unnamed clocks property required in the binding: Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml { ... required: - compatible - reg - interrupts - clocks } Removing devm_clk_get_enabled() leaves the required DT clock unclaimed and unenabled by the driver. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261126193241.1471372-1-jnieto.alaber@gmail.com?part=5 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v13 06/25] crypto: amlogic - Add MMIO helpers 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (4 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 05/25] crypto: amlogic - Remove clock input Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:32 ` [PATCH v13 07/25] crypto: amlogic - Move get_engine_number() Jose Nieto ` (19 subsequent siblings) 25 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Add MMIO access helpers: meson_dma_start() and meson_dma_ready(). Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 2 +- drivers/crypto/amlogic/amlogic-gxl-core.c | 24 ++++++++++++++++----- drivers/crypto/amlogic/amlogic-gxl.h | 2 ++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index c458548f29b2..62aa82e1cb5d 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -234,7 +234,7 @@ static int meson_cipher(struct skcipher_request *areq) reinit_completion(&mc->chanlist[flow].complete); mc->chanlist[flow].status = 0; - writel(mc->chanlist[flow].t_phy | 2, mc->base + ((mc->pdata->descs_reg + flow) << 2)); + meson_dma_start(mc, flow); wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete, msecs_to_jiffies(500)); if (mc->chanlist[flow].status == 0) { diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 37224d75edfb..b972df44e8b5 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -22,18 +22,32 @@ #include "amlogic-gxl.h" +void meson_dma_start(struct meson_dev *mc, int flow) +{ + u32 offset = (mc->pdata->descs_reg + flow) << 2; + + writel(mc->chanlist[flow].t_phy | 2, mc->base + offset); +} + +static bool meson_dma_ready(struct meson_dev *mc, int flow) +{ + u32 offset = (mc->pdata->status_reg + flow) << 2; + u32 data = readl(mc->base + offset); + + if (data) + writel_relaxed(0xF, mc->base + offset); + + return data; +} + static irqreturn_t meson_irq_handler(int irq, void *data) { struct meson_dev *mc = (struct meson_dev *)data; int flow; - u32 p; for (flow = 0; flow < mc->flow_cnt; flow++) { if (mc->chanlist[flow].irq == irq) { - p = readl(mc->base + ((mc->pdata->status_reg + flow) << 2)); - if (p) { - writel_relaxed(0xF, mc->base + - ((mc->pdata->status_reg + flow) << 2)); + if (meson_dma_ready(mc, flow)) { mc->chanlist[flow].status = 1; complete(&mc->chanlist[flow].complete); return IRQ_HANDLED; diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index 5149dc6e9f60..64f2f0e63f12 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -159,6 +159,8 @@ struct meson_alg_template { #endif }; +void meson_dma_start(struct meson_dev *mc, int flow); + int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen); int meson_cipher_init(struct crypto_tfm *tfm); -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v13 07/25] crypto: amlogic - Move get_engine_number() 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (5 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 06/25] crypto: amlogic - Add MMIO helpers Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:32 ` [PATCH v13 08/25] crypto: amlogic - Drop status field from meson_flow Jose Nieto ` (18 subsequent siblings) 25 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Move get_engine_number() function from cipher.c to core.c Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 9 ++------- drivers/crypto/amlogic/amlogic-gxl-core.c | 5 +++++ drivers/crypto/amlogic/amlogic-gxl.h | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index 62aa82e1cb5d..f6c13d8fcb47 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -17,11 +17,6 @@ #include <crypto/internal/skcipher.h> #include "amlogic-gxl.h" -static int get_engine_number(struct meson_dev *mc) -{ - return atomic_inc_return(&mc->flow) % mc->flow_cnt; -} - static bool meson_cipher_need_fallback(struct skcipher_request *areq) { struct scatterlist *src_sg = areq->src; @@ -297,7 +292,7 @@ int meson_skdecrypt(struct skcipher_request *areq) rctx->op_dir = MESON_DECRYPT; if (meson_cipher_need_fallback(areq)) return meson_cipher_do_fallback(areq); - e = get_engine_number(op->mc); + e = meson_get_engine_number(op->mc); engine = op->mc->chanlist[e].engine; rctx->flow = e; @@ -315,7 +310,7 @@ int meson_skencrypt(struct skcipher_request *areq) rctx->op_dir = MESON_ENCRYPT; if (meson_cipher_need_fallback(areq)) return meson_cipher_do_fallback(areq); - e = get_engine_number(op->mc); + e = meson_get_engine_number(op->mc); engine = op->mc->chanlist[e].engine; rctx->flow = e; diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index b972df44e8b5..58d56f352dd6 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -22,6 +22,11 @@ #include "amlogic-gxl.h" +int meson_get_engine_number(struct meson_dev *mc) +{ + return atomic_inc_return(&mc->flow) % mc->flow_cnt; +} + void meson_dma_start(struct meson_dev *mc, int flow) { u32 offset = (mc->pdata->descs_reg + flow) << 2; diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index 64f2f0e63f12..e14cd5021add 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -159,6 +159,8 @@ struct meson_alg_template { #endif }; +int meson_get_engine_number(struct meson_dev *mc); + void meson_dma_start(struct meson_dev *mc, int flow); int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v13 08/25] crypto: amlogic - Drop status field from meson_flow 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (6 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 07/25] crypto: amlogic - Move get_engine_number() Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:32 ` [PATCH v13 09/25] crypto: amlogic - Move algs definition and cipher API to cipher.c Jose Nieto ` (17 subsequent siblings) 25 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> This field is used only to check for timeout. But there is more convenient way to achive the same goal. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 13 +++++++++---- drivers/crypto/amlogic/amlogic-gxl-core.c | 1 - drivers/crypto/amlogic/amlogic-gxl.h | 2 -- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index f6c13d8fcb47..cd94296e4d9a 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -228,13 +228,18 @@ static int meson_cipher(struct skcipher_request *areq) } reinit_completion(&mc->chanlist[flow].complete); - mc->chanlist[flow].status = 0; meson_dma_start(mc, flow); - wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete, - msecs_to_jiffies(500)); - if (mc->chanlist[flow].status == 0) { + + err = wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete, + msecs_to_jiffies(500)); + if (err == 0) { dev_err(mc->dev, "DMA timeout for flow %d\n", flow); err = -EINVAL; + } else if (err < 0) { + dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", err); + } else { + /* No error */ + err = 0; } dma_unmap_single(mc->dev, phykeyiv, keyivlen, DMA_TO_DEVICE); diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 58d56f352dd6..81d0e8731ab1 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -53,7 +53,6 @@ static irqreturn_t meson_irq_handler(int irq, void *data) for (flow = 0; flow < mc->flow_cnt; flow++) { if (mc->chanlist[flow].irq == irq) { if (meson_dma_ready(mc, flow)) { - mc->chanlist[flow].status = 1; complete(&mc->chanlist[flow].complete); return IRQ_HANDLED; } diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index e14cd5021add..cf07c5fbc5bf 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -59,7 +59,6 @@ struct meson_desc { * @engine: ptr to the crypto_engine for this flow * @keylen: keylen for this flow operation * @complete: completion for the current task on this flow - * @status: set to 1 by interrupt if task is done * @irq: IRQ number for amlogic-crypto * @t_phy: Physical address of task * @tl: pointer to the current ce_task for this flow @@ -68,7 +67,6 @@ struct meson_desc { struct meson_flow { struct crypto_engine *engine; struct completion complete; - int status; int irq; unsigned int keylen; dma_addr_t t_phy; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v13 09/25] crypto: amlogic - Move algs definition and cipher API to cipher.c 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (7 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 08/25] crypto: amlogic - Drop status field from meson_flow Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:41 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 10/25] crypto: amlogic - Cleanup defines Jose Nieto ` (16 subsequent siblings) 25 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Because that is proper place for them. In particular, it takes less of exported symbol between compiling entities. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 98 +++++++++++++++-- drivers/crypto/amlogic/amlogic-gxl-core.c | 111 ++++---------------- drivers/crypto/amlogic/amlogic-gxl.h | 14 +-- 3 files changed, 120 insertions(+), 103 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index cd94296e4d9a..00d3247ebea1 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -286,7 +286,7 @@ int meson_handle_cipher_request(struct crypto_engine *engine, void *areq) return 0; } -int meson_skdecrypt(struct skcipher_request *areq) +static int meson_skdecrypt(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); @@ -304,7 +304,7 @@ int meson_skdecrypt(struct skcipher_request *areq) return crypto_transfer_skcipher_request_to_engine(engine, areq); } -int meson_skencrypt(struct skcipher_request *areq) +static int meson_skencrypt(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); @@ -322,7 +322,7 @@ int meson_skencrypt(struct skcipher_request *areq) return crypto_transfer_skcipher_request_to_engine(engine, areq); } -int meson_cipher_init(struct crypto_tfm *tfm) +static int meson_cipher_init(struct crypto_tfm *tfm) { struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm); struct meson_alg_template *algt; @@ -348,7 +348,7 @@ int meson_cipher_init(struct crypto_tfm *tfm) return 0; } -void meson_cipher_exit(struct crypto_tfm *tfm) +static void meson_cipher_exit(struct crypto_tfm *tfm) { struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm); @@ -356,8 +356,8 @@ void meson_cipher_exit(struct crypto_tfm *tfm) crypto_free_skcipher(op->fallback_tfm); } -int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, - unsigned int keylen) +static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, + unsigned int keylen) { struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); struct meson_dev *mc = op->mc; @@ -384,3 +384,89 @@ int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, return crypto_skcipher_setkey(op->fallback_tfm, key, keylen); } + +static struct meson_alg_template algs[] = { +{ + .type = CRYPTO_ALG_TYPE_SKCIPHER, + .blockmode = MESON_OPMODE_CBC, + .alg.skcipher.base = { + .base = { + .cra_name = "cbc(aes)", + .cra_driver_name = "cbc-aes-gxl", + .cra_priority = 400, + .cra_blocksize = AES_BLOCK_SIZE, + .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_NEED_FALLBACK, + .cra_ctxsize = sizeof(struct meson_cipher_tfm_ctx), + .cra_module = THIS_MODULE, + .cra_alignmask = 0xf, + .cra_init = meson_cipher_init, + .cra_exit = meson_cipher_exit, + }, + .min_keysize = AES_MIN_KEY_SIZE, + .max_keysize = AES_MAX_KEY_SIZE, + .ivsize = AES_BLOCK_SIZE, + .setkey = meson_aes_setkey, + .encrypt = meson_skencrypt, + .decrypt = meson_skdecrypt, + }, + .alg.skcipher.op = { + .do_one_request = meson_handle_cipher_request, + }, +}, +{ + .type = CRYPTO_ALG_TYPE_SKCIPHER, + .blockmode = MESON_OPMODE_ECB, + .alg.skcipher.base = { + .base = { + .cra_name = "ecb(aes)", + .cra_driver_name = "ecb-aes-gxl", + .cra_priority = 400, + .cra_blocksize = AES_BLOCK_SIZE, + .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_NEED_FALLBACK, + .cra_ctxsize = sizeof(struct meson_cipher_tfm_ctx), + .cra_module = THIS_MODULE, + .cra_alignmask = 0xf, + .cra_init = meson_cipher_init, + .cra_exit = meson_cipher_exit, + }, + .min_keysize = AES_MIN_KEY_SIZE, + .max_keysize = AES_MAX_KEY_SIZE, + .setkey = meson_aes_setkey, + .encrypt = meson_skencrypt, + .decrypt = meson_skdecrypt, + }, + .alg.skcipher.op = { + .do_one_request = meson_handle_cipher_request, + }, +}, +}; + +int meson_cipher_register(struct meson_dev *mc) +{ + return meson_register_algs(mc, algs, ARRAY_SIZE(algs)); +} + +void meson_cipher_unregister(struct meson_dev *mc) +{ + meson_unregister_algs(mc, algs, ARRAY_SIZE(algs)); +} + +void meson_cipher_debugfs_show(struct seq_file *seq, void *v) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(algs); i++) { + seq_printf(seq, "%s %s %lu %lu\n", + algs[i].alg.skcipher.base.base.cra_driver_name, + algs[i].alg.skcipher.base.base.cra_name, +#ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG + algs[i].stat_req, algs[i].stat_fb); +#else + 0ul, 0ul); +#endif + } +} diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 81d0e8731ab1..68d394e90f66 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -65,66 +65,6 @@ static irqreturn_t meson_irq_handler(int irq, void *data) return IRQ_NONE; } -static struct meson_alg_template mc_algs[] = { -{ - .type = CRYPTO_ALG_TYPE_SKCIPHER, - .blockmode = MESON_OPMODE_CBC, - .alg.skcipher.base = { - .base = { - .cra_name = "cbc(aes)", - .cra_driver_name = "cbc-aes-gxl", - .cra_priority = 400, - .cra_blocksize = AES_BLOCK_SIZE, - .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | - CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | - CRYPTO_ALG_NEED_FALLBACK, - .cra_ctxsize = sizeof(struct meson_cipher_tfm_ctx), - .cra_module = THIS_MODULE, - .cra_alignmask = 0xf, - .cra_init = meson_cipher_init, - .cra_exit = meson_cipher_exit, - }, - .min_keysize = AES_MIN_KEY_SIZE, - .max_keysize = AES_MAX_KEY_SIZE, - .ivsize = AES_BLOCK_SIZE, - .setkey = meson_aes_setkey, - .encrypt = meson_skencrypt, - .decrypt = meson_skdecrypt, - }, - .alg.skcipher.op = { - .do_one_request = meson_handle_cipher_request, - }, -}, -{ - .type = CRYPTO_ALG_TYPE_SKCIPHER, - .blockmode = MESON_OPMODE_ECB, - .alg.skcipher.base = { - .base = { - .cra_name = "ecb(aes)", - .cra_driver_name = "ecb-aes-gxl", - .cra_priority = 400, - .cra_blocksize = AES_BLOCK_SIZE, - .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | - CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | - CRYPTO_ALG_NEED_FALLBACK, - .cra_ctxsize = sizeof(struct meson_cipher_tfm_ctx), - .cra_module = THIS_MODULE, - .cra_alignmask = 0xf, - .cra_init = meson_cipher_init, - .cra_exit = meson_cipher_exit, - }, - .min_keysize = AES_MIN_KEY_SIZE, - .max_keysize = AES_MAX_KEY_SIZE, - .setkey = meson_aes_setkey, - .encrypt = meson_skencrypt, - .decrypt = meson_skdecrypt, - }, - .alg.skcipher.op = { - .do_one_request = meson_handle_cipher_request, - }, -}, -}; - static int meson_debugfs_show(struct seq_file *seq, void *v) { struct meson_dev *mc __maybe_unused = seq->private; @@ -138,20 +78,8 @@ static int meson_debugfs_show(struct seq_file *seq, void *v) 0ul); #endif - for (i = 0; i < ARRAY_SIZE(mc_algs); i++) { - switch (mc_algs[i].type) { - case CRYPTO_ALG_TYPE_SKCIPHER: - seq_printf(seq, "%s %s %lu %lu\n", - mc_algs[i].alg.skcipher.base.base.cra_driver_name, - mc_algs[i].alg.skcipher.base.base.cra_name, -#ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG - mc_algs[i].stat_req, mc_algs[i].stat_fb); -#else - 0ul, 0ul); -#endif - break; - } - } + meson_cipher_debugfs_show(seq, v); + return 0; } DEFINE_SHOW_ATTRIBUTE(meson_debugfs); @@ -227,19 +155,20 @@ static int meson_allocate_chanlist(struct meson_dev *mc) return err; } -static int meson_register_algs(struct meson_dev *mc) +int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *algs, + unsigned int count) { int err, i; - for (i = 0; i < ARRAY_SIZE(mc_algs); i++) { - mc_algs[i].mc = mc; - switch (mc_algs[i].type) { + for (i = 0; i < count; i++) { + algs[i].mc = mc; + switch (algs[i].type) { case CRYPTO_ALG_TYPE_SKCIPHER: - err = crypto_engine_register_skcipher(&mc_algs[i].alg.skcipher); + err = crypto_engine_register_skcipher(&algs[i].alg.skcipher); if (err) { dev_err(mc->dev, "Fail to register %s\n", - mc_algs[i].alg.skcipher.base.base.cra_name); - mc_algs[i].mc = NULL; + algs[i].alg.skcipher.base.base.cra_name); + meson_unregister_algs(mc, algs, count); return err; } break; @@ -249,16 +178,17 @@ static int meson_register_algs(struct meson_dev *mc) return 0; } -static void meson_unregister_algs(struct meson_dev *mc) +void meson_unregister_algs(struct meson_dev *mc, struct meson_alg_template *algs, + unsigned int count) { int i; - for (i = 0; i < ARRAY_SIZE(mc_algs); i++) { - if (!mc_algs[i].mc) + for (i = 0; i < count; i++) { + if (!algs[i].mc) continue; - switch (mc_algs[i].type) { + switch (algs[i].type) { case CRYPTO_ALG_TYPE_SKCIPHER: - crypto_engine_unregister_skcipher(&mc_algs[i].alg.skcipher); + crypto_engine_unregister_skcipher(&algs[i].alg.skcipher); break; } } @@ -288,9 +218,9 @@ static int meson_crypto_probe(struct platform_device *pdev) if (err) return err; - err = meson_register_algs(mc); + err = meson_cipher_register(mc); if (err) - goto error_alg; + goto error_flow; if (IS_ENABLED(CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG)) { struct dentry *dbgfs_dir; @@ -304,8 +234,7 @@ static int meson_crypto_probe(struct platform_device *pdev) } return 0; -error_alg: - meson_unregister_algs(mc); +error_flow: meson_free_chanlist(mc, mc->flow_cnt - 1); return err; } @@ -318,7 +247,7 @@ static void meson_crypto_remove(struct platform_device *pdev) debugfs_remove_recursive(mc->dbgfs_dir); #endif - meson_unregister_algs(mc); + meson_cipher_unregister(mc); meson_free_chanlist(mc, mc->flow_cnt - 1); } diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index cf07c5fbc5bf..608ce75f027a 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -161,10 +161,12 @@ int meson_get_engine_number(struct meson_dev *mc); void meson_dma_start(struct meson_dev *mc, int flow); -int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, - unsigned int keylen); -int meson_cipher_init(struct crypto_tfm *tfm); -void meson_cipher_exit(struct crypto_tfm *tfm); -int meson_skdecrypt(struct skcipher_request *areq); -int meson_skencrypt(struct skcipher_request *areq); +int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *algs, + unsigned int count); +void meson_unregister_algs(struct meson_dev *mc, struct meson_alg_template *algs, + unsigned int count); + +int meson_cipher_register(struct meson_dev *mc); +void meson_cipher_unregister(struct meson_dev *mc); +void meson_cipher_debugfs_show(struct seq_file *seq, void *v); int meson_handle_cipher_request(struct crypto_engine *engine, void *areq); -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v13 09/25] crypto: amlogic - Move algs definition and cipher API to cipher.c 2026-11-26 19:32 ` [PATCH v13 09/25] crypto: amlogic - Move algs definition and cipher API to cipher.c Jose Nieto @ 2026-11-26 19:41 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-26 19:41 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] crypto: amlogic - unregistering failed alg in meson_register_algs() - [Low] crypto: amlogic - meson_handle_cipher_request() left non-static -- commit 08352ca67e625f03f4ad6f02c380a0279142c7e8 Author: Alexey Romanov <romanov.alexey2000@gmail.com> crypto: amlogic - Move algs definition and cipher API to cipher.c This commit moves the skcipher algorithm templates and cipher callbacks from amlogic-gxl-core.c to amlogic-gxl-cipher.c and exposes registration and debugfs helpers. [ ... ] > diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c > index 81d0e8731ab16..68d394e90f660 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-core.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c [ ... ] > @@ -227,19 +155,20 @@ static int meson_allocate_chanlist(struct meson_dev *mc) > return err; > } > > -static int meson_register_algs(struct meson_dev *mc) > +int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *algs, > + unsigned int count) > { > int err, i; > > - for (i = 0; i < ARRAY_SIZE(mc_algs); i++) { > - mc_algs[i].mc = mc; > - switch (mc_algs[i].type) { > + for (i = 0; i < count; i++) { > + algs[i].mc = mc; > + switch (algs[i].type) { > case CRYPTO_ALG_TYPE_SKCIPHER: > - err = crypto_engine_register_skcipher(&mc_algs[i].alg.skcipher); > + err = crypto_engine_register_skcipher(&algs[i].alg.skcipher); > if (err) { > dev_err(mc->dev, "Fail to register %s\n", > - mc_algs[i].alg.skcipher.base.base.cra_name); > - mc_algs[i].mc = NULL; > + algs[i].alg.skcipher.base.base.cra_name); > + meson_unregister_algs(mc, algs, count); > return err; > } > break; > @@ -249,16 +178,17 @@ static int meson_register_algs(struct meson_dev *mc) > return 0; > } > > -static void meson_unregister_algs(struct meson_dev *mc) > +void meson_unregister_algs(struct meson_dev *mc, struct meson_alg_template *algs, > + unsigned int count) > { > int i; > > - for (i = 0; i < ARRAY_SIZE(mc_algs); i++) { > - if (!mc_algs[i].mc) > + for (i = 0; i < count; i++) { > + if (!algs[i].mc) > continue; > - switch (mc_algs[i].type) { > + switch (algs[i].type) { > case CRYPTO_ALG_TYPE_SKCIPHER: > - crypto_engine_unregister_skcipher(&mc_algs[i].alg.skcipher); > + crypto_engine_unregister_skcipher(&algs[i].alg.skcipher); > break; > } > } [Severity: Medium] Does meson_register_algs() end up calling crypto_engine_unregister_skcipher() on the algorithm whose registration just failed? algs[i].mc is set to mc before crypto_engine_register_skcipher(), and the error path no longer clears algs[i].mc = NULL before calling meson_unregister_algs(). Because meson_unregister_algs() unregisters every entry with a non-NULL algs[i].mc, it unregisters the failed entry at index i, whose zero-initialized cra_list causes a NULL pointer dereference in crypto_remove_alg() -> list_del_init(&alg->cra_list). meson_unregister_algs() also leaves algs[i].mc non-NULL after unregistering, so a failure on a later probe attempt would try to unregister entries that were already unregistered. [ ... ] > diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h > index cf07c5fbc5bf5..608ce75f027a3 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl.h > +++ b/drivers/crypto/amlogic/amlogic-gxl.h > @@ -161,10 +161,12 @@ int meson_get_engine_number(struct meson_dev *mc); > > void meson_dma_start(struct meson_dev *mc, int flow); > > -int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, > - unsigned int keylen); > -int meson_cipher_init(struct crypto_tfm *tfm); > -void meson_cipher_exit(struct crypto_tfm *tfm); > -int meson_skdecrypt(struct skcipher_request *areq); > -int meson_skencrypt(struct skcipher_request *areq); > +int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *algs, > + unsigned int count); > +void meson_unregister_algs(struct meson_dev *mc, struct meson_alg_template *algs, > + unsigned int count); > + > +int meson_cipher_register(struct meson_dev *mc); > +void meson_cipher_unregister(struct meson_dev *mc); > +void meson_cipher_debugfs_show(struct seq_file *seq, void *v); > int meson_handle_cipher_request(struct crypto_engine *engine, void *areq); [Severity: Low] This isn't a bug, but since algs[] moved to amlogic-gxl-cipher.c, meson_handle_cipher_request() is now only referenced in that file and can also be made static and dropped from amlogic-gxl.h. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261126193241.1471372-1-jnieto.alaber@gmail.com?part=9 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v13 10/25] crypto: amlogic - Cleanup defines 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (8 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 09/25] crypto: amlogic - Move algs definition and cipher API to cipher.c Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:32 ` [PATCH v13 11/25] crypto: amlogic - Process more than MAXDESCS descriptors Jose Nieto ` (15 subsequent siblings) 25 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> It is bad to use hardcoded values directly in the code. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 24 ++++++++++----------- drivers/crypto/amlogic/amlogic-gxl.h | 16 ++++++++------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index 00d3247ebea1..c17ce5cc70a8 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -141,8 +141,8 @@ static int meson_cipher(struct skcipher_request *areq) ivsize, 0); } } - if (keyivlen == 24) - keyivlen = 32; + if (keyivlen == AES_KEYSIZE_192) + keyivlen = AES_MAX_KEY_SIZE; phykeyiv = dma_map_single(mc->dev, bkeyiv, keyivlen, DMA_TO_DEVICE); @@ -161,7 +161,7 @@ static int meson_cipher(struct skcipher_request *areq) todo = min(keyivlen - eat, 16u); desc->t_src = cpu_to_le32(phykeyiv + i * 16); desc->t_dst = cpu_to_le32(i * 16); - v = (MODE_KEY << 20) | DESC_OWN | 16; + v = DESC_MODE_KEY | DESC_OWN | 16; desc->t_status = cpu_to_le32(v); eat += todo; @@ -214,7 +214,7 @@ static int meson_cipher(struct skcipher_request *areq) desc->t_src = cpu_to_le32(sg_dma_address(src_sg)); desc->t_dst = cpu_to_le32(sg_dma_address(dst_sg)); todo = min(len, sg_dma_len(src_sg)); - v = (op->keymode << 20) | DESC_OWN | todo | (algt->blockmode << 26); + v = op->keymode | DESC_OWN | todo | algt->blockmode; if (rctx->op_dir) v |= DESC_ENCRYPTION; len -= todo; @@ -363,14 +363,14 @@ static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, struct meson_dev *mc = op->mc; switch (keylen) { - case 128 / 8: - op->keymode = MODE_AES_128; + case AES_KEYSIZE_128: + op->keymode = DESC_MODE_AES_128; break; - case 192 / 8: - op->keymode = MODE_AES_192; + case AES_KEYSIZE_192: + op->keymode = DESC_MODE_AES_192; break; - case 256 / 8: - op->keymode = MODE_AES_256; + case AES_KEYSIZE_256: + op->keymode = DESC_MODE_AES_256; break; default: dev_dbg(mc->dev, "ERROR: Invalid keylen %u\n", keylen); @@ -388,7 +388,7 @@ static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, static struct meson_alg_template algs[] = { { .type = CRYPTO_ALG_TYPE_SKCIPHER, - .blockmode = MESON_OPMODE_CBC, + .blockmode = DESC_OPMODE_CBC, .alg.skcipher.base = { .base = { .cra_name = "cbc(aes)", @@ -417,7 +417,7 @@ static struct meson_alg_template algs[] = { }, { .type = CRYPTO_ALG_TYPE_SKCIPHER, - .blockmode = MESON_OPMODE_ECB, + .blockmode = DESC_OPMODE_ECB, .alg.skcipher.base = { .base = { .cra_name = "ecb(aes)", diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index 608ce75f027a..15b4335942d5 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -11,19 +11,21 @@ #include <linux/crypto.h> #include <linux/scatterlist.h> -#define MODE_KEY 1 -#define MODE_AES_128 0x8 -#define MODE_AES_192 0x9 -#define MODE_AES_256 0xa - #define MESON_DECRYPT 0 #define MESON_ENCRYPT 1 -#define MESON_OPMODE_ECB 0 -#define MESON_OPMODE_CBC 1 +#define DESC_MODE_KEY (0x1 << 20) +#define DESC_MODE_AES_128 (0x8 << 20) +#define DESC_MODE_AES_192 (0x9 << 20) +#define DESC_MODE_AES_256 (0xa << 20) #define MAXDESC 64 +#define DESC_OPMODE_ECB (0 << 26) +#define DESC_OPMODE_CBC (1 << 26) + +#define DESC_MAXLEN GENMASK(16, 0) + #define DESC_LAST BIT(18) #define DESC_ENCRYPTION BIT(28) #define DESC_OWN BIT(31) -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v13 11/25] crypto: amlogic - Process more than MAXDESCS descriptors 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (9 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 10/25] crypto: amlogic - Cleanup defines Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:45 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 12/25] crypto: amlogic - Avoid kzalloc in engine thread Jose Nieto ` (14 subsequent siblings) 25 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> 1. The old alhorithm was not designed to process a large amount of memory, and therefore gave incorrect results. 2. Not all Amlogic SoC's use 3 KEY/IV descriptors. Add keyiv descriptors count parameter to platform data. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 459 ++++++++++++-------- drivers/crypto/amlogic/amlogic-gxl-core.c | 1 + drivers/crypto/amlogic/amlogic-gxl.h | 2 + 3 files changed, 283 insertions(+), 179 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index c17ce5cc70a8..cb6b959bb1f9 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -17,35 +17,41 @@ #include <crypto/internal/skcipher.h> #include "amlogic-gxl.h" -static bool meson_cipher_need_fallback(struct skcipher_request *areq) +static bool meson_cipher_need_fallback_sg(struct skcipher_request *areq, + struct scatterlist *sg) { - struct scatterlist *src_sg = areq->src; - struct scatterlist *dst_sg = areq->dst; + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); + unsigned int blocksize = crypto_skcipher_blocksize(tfm); + unsigned int cryptlen = areq->cryptlen; + + while (cryptlen) { + unsigned int len = min(cryptlen, sg->length); + + if (!IS_ALIGNED(sg->offset, sizeof(u32))) + return true; + if (len % blocksize != 0) + return true; + + cryptlen -= len; + sg = sg_next(sg); + } + + return false; +} +static bool meson_cipher_need_fallback(struct skcipher_request *areq) +{ if (areq->cryptlen == 0) return true; - if (sg_nents(src_sg) != sg_nents(dst_sg)) + if (meson_cipher_need_fallback_sg(areq, areq->src)) return true; - /* KEY/IV descriptors use 3 desc */ - if (sg_nents(src_sg) > MAXDESC - 3 || sg_nents(dst_sg) > MAXDESC - 3) - return true; + if (areq->dst == areq->src) + return false; - while (src_sg && dst_sg) { - if ((src_sg->length % 16) != 0) - return true; - if ((dst_sg->length % 16) != 0) - return true; - if (src_sg->length != dst_sg->length) - return true; - if (!IS_ALIGNED(src_sg->offset, sizeof(u32))) - return true; - if (!IS_ALIGNED(dst_sg->offset, sizeof(u32))) - return true; - src_sg = sg_next(src_sg); - dst_sg = sg_next(dst_sg); - } + if (meson_cipher_need_fallback_sg(areq, areq->dst)) + return true; return false; } @@ -76,6 +82,213 @@ static int meson_cipher_do_fallback(struct skcipher_request *areq) return err; } +struct cipher_ctx { + struct { + dma_addr_t addr; + unsigned int len; + } keyiv; + + struct skcipher_request *areq; + struct scatterlist *src_sg; + struct scatterlist *dst_sg; + void *bkeyiv; + + unsigned int src_offset; + unsigned int dst_offset; + unsigned int cryptlen; + unsigned int tloffset; +}; + +static int meson_map_scatterlist(struct skcipher_request *areq, struct meson_dev *mc) +{ + int nr_sgs, nr_sgd; + + if (areq->src == areq->dst) { + nr_sgs = dma_map_sg(mc->dev, areq->src, sg_nents(areq->src), + DMA_BIDIRECTIONAL); + if (!nr_sgs) { + dev_err(mc->dev, "Invalid SG count %d\n", nr_sgs); + return -EINVAL; + } + } else { + nr_sgs = dma_map_sg(mc->dev, areq->src, sg_nents(areq->src), + DMA_TO_DEVICE); + if (!nr_sgs) { + dev_err(mc->dev, "Invalid SG count %d\n", nr_sgs); + return -EINVAL; + } + + nr_sgd = dma_map_sg(mc->dev, areq->dst, sg_nents(areq->dst), + DMA_FROM_DEVICE); + if (!nr_sgd) { + dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE); + dev_err(mc->dev, "Invalid SG count %d\n", nr_sgd); + return -EINVAL; + } + } + + return 0; +} + +static void meson_unmap_scatterlist(struct skcipher_request *areq, struct meson_dev *mc) +{ + if (areq->src == areq->dst) { + dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_BIDIRECTIONAL); + } else { + dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE); + dma_unmap_sg(mc->dev, areq->dst, sg_nents(areq->dst), DMA_FROM_DEVICE); + } +} + +static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) +{ + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); + struct meson_alg_template *algt = container_of(alg, + struct meson_alg_template, alg.skcipher.base); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_dev *mc = op->mc; + unsigned int ivsize = crypto_skcipher_ivsize(tfm); + unsigned int blockmode = algt->blockmode; + int i; + + if (ctx->tloffset) + return; + + if (blockmode == DESC_OPMODE_CBC) { + memcpy(ctx->bkeyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); + dma_sync_single_for_device(mc->dev, ctx->keyiv.addr, + ctx->keyiv.len, DMA_TO_DEVICE); + } + + for (i = 0; i < mc->pdata->setup_desc_cnt; i++) { + struct meson_desc *desc = + &mc->chanlist[rctx->flow].tl[ctx->tloffset]; + int offset = i * 16; + + desc->t_src = cpu_to_le32(ctx->keyiv.addr + offset); + desc->t_dst = cpu_to_le32(offset); + desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | ctx->keyiv.len); + + ctx->tloffset++; + } +} + +static bool meson_setup_data_descs(struct cipher_ctx *ctx) +{ + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); + struct meson_alg_template *algt = container_of(alg, + struct meson_alg_template, + alg.skcipher.base); + struct meson_dev *mc = op->mc; + struct meson_desc *desc = &mc->chanlist[rctx->flow].tl[ctx->tloffset]; + unsigned int blocksize = crypto_skcipher_blocksize(tfm); + unsigned int blockmode = algt->blockmode; + unsigned int maxlen = rounddown(DESC_MAXLEN, blocksize); + unsigned int todo; + u32 v; + + ctx->tloffset++; + + todo = min(ctx->cryptlen, maxlen); + todo = min(todo, ctx->cryptlen); + todo = min(todo, sg_dma_len(ctx->src_sg) - ctx->src_offset); + todo = min(todo, sg_dma_len(ctx->dst_sg) - ctx->dst_offset); + + desc->t_src = cpu_to_le32(sg_dma_address(ctx->src_sg) + ctx->src_offset); + desc->t_dst = cpu_to_le32(sg_dma_address(ctx->dst_sg) + ctx->dst_offset); + + ctx->cryptlen -= todo; + ctx->src_offset += todo; + ctx->dst_offset += todo; + + v = DESC_OWN | blockmode | op->keymode | todo; + if (rctx->op_dir == MESON_ENCRYPT) + v |= DESC_ENCRYPTION; + + if (!ctx->cryptlen || ctx->tloffset == MAXDESC) + v |= DESC_LAST; + + desc->t_status = cpu_to_le32(v); + + return v & DESC_LAST; +} + +static int meson_kick_hardware(struct cipher_ctx *ctx) +{ + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); + struct meson_alg_template *algt = container_of(alg, + struct meson_alg_template, + alg.skcipher.base); + struct meson_dev *mc = op->mc; + unsigned int ivsize = crypto_skcipher_ivsize(tfm); + unsigned int blockmode = algt->blockmode; + enum dma_data_direction new_iv_dir; + struct scatterlist *sg_head; + void *new_iv; + int err; + + if (blockmode == DESC_OPMODE_CBC) { + struct scatterlist *sg_current; + unsigned int offset; + + if (rctx->op_dir == MESON_ENCRYPT) { + sg_current = ctx->dst_sg; + sg_head = ctx->areq->dst; + offset = ctx->dst_offset; + new_iv_dir = DMA_FROM_DEVICE; + } else { + sg_current = ctx->src_sg; + sg_head = ctx->areq->src; + offset = ctx->src_offset; + new_iv_dir = DMA_TO_DEVICE; + } + + if (ctx->areq->src == ctx->areq->dst) + new_iv_dir = DMA_BIDIRECTIONAL; + + offset -= ivsize; + new_iv = sg_virt(sg_current) + offset; + } + + if (blockmode == DESC_OPMODE_CBC && + rctx->op_dir == MESON_DECRYPT) { + dma_sync_sg_for_cpu(mc->dev, sg_head, + sg_nents(sg_head), new_iv_dir); + memcpy(ctx->areq->iv, new_iv, ivsize); + } + + reinit_completion(&mc->chanlist[rctx->flow].complete); + meson_dma_start(mc, rctx->flow); + err = wait_for_completion_interruptible_timeout(&mc->chanlist[rctx->flow].complete, + msecs_to_jiffies(500)); + if (err == 0) { + dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); + return -EINVAL; + } else if (err < 0) { + dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", err); + return err; + } + + if (blockmode == DESC_OPMODE_CBC && + rctx->op_dir == MESON_ENCRYPT) { + dma_sync_sg_for_cpu(mc->dev, sg_head, + sg_nents(sg_head), new_iv_dir); + memcpy(ctx->areq->iv, new_iv, ivsize); + } + + ctx->tloffset = 0; + + return 0; +} + static int meson_cipher(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); @@ -84,191 +297,79 @@ static int meson_cipher(struct skcipher_request *areq) struct meson_dev *mc = op->mc; struct skcipher_alg *alg = crypto_skcipher_alg(tfm); struct meson_alg_template *algt; - int flow = rctx->flow; - unsigned int todo, eat, len; - struct scatterlist *src_sg = areq->src; - struct scatterlist *dst_sg = areq->dst; - struct meson_desc *desc; - int nr_sgs, nr_sgd; - int i, err = 0; - unsigned int keyivlen, ivsize, offset, tloffset; - dma_addr_t phykeyiv; - void *backup_iv = NULL, *bkeyiv; - u32 v; - - algt = container_of(alg, struct meson_alg_template, alg.skcipher.base); + struct cipher_ctx ctx = { + .areq = areq, + .src_offset = 0, + .dst_offset = 0, + .src_sg = areq->src, + .dst_sg = areq->dst, + .cryptlen = areq->cryptlen, + }; + int err; - dev_dbg(mc->dev, "%s %s %u %x IV(%u) key=%u flow=%d\n", __func__, + dev_dbg(mc->dev, "%s %s %u %x IV(%u) key=%u ctx.flow=%d\n", __func__, crypto_tfm_alg_name(areq->base.tfm), areq->cryptlen, rctx->op_dir, crypto_skcipher_ivsize(tfm), - op->keylen, flow); + op->keylen, rctx->flow); + + algt = container_of(alg, struct meson_alg_template, alg.skcipher.base); #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG algt->stat_req++; - mc->chanlist[flow].stat_req++; + mc->chanlist[rctx->flow].stat_req++; #endif - /* - * The hardware expect a list of meson_desc structures. - * The 2 first structures store key - * The third stores IV - */ - bkeyiv = kzalloc(48, GFP_KERNEL | GFP_DMA); - if (!bkeyiv) + ctx.bkeyiv = kzalloc(48, GFP_KERNEL | GFP_DMA); + if (!ctx.bkeyiv) return -ENOMEM; - memcpy(bkeyiv, op->key, op->keylen); - keyivlen = op->keylen; - - ivsize = crypto_skcipher_ivsize(tfm); - if (areq->iv && ivsize > 0) { - if (ivsize > areq->cryptlen) { - dev_err(mc->dev, "invalid ivsize=%d vs len=%d\n", ivsize, areq->cryptlen); - err = -EINVAL; - goto theend; - } - memcpy(bkeyiv + 32, areq->iv, ivsize); - keyivlen = 48; - if (rctx->op_dir == MESON_DECRYPT) { - backup_iv = kzalloc(ivsize, GFP_KERNEL); - if (!backup_iv) { - err = -ENOMEM; - goto theend; - } - offset = areq->cryptlen - ivsize; - scatterwalk_map_and_copy(backup_iv, areq->src, offset, - ivsize, 0); - } - } - if (keyivlen == AES_KEYSIZE_192) - keyivlen = AES_MAX_KEY_SIZE; + memcpy(ctx.bkeyiv, op->key, op->keylen); + ctx.keyiv.len = op->keylen; + if (ctx.keyiv.len == AES_KEYSIZE_192) + ctx.keyiv.len = AES_MAX_KEY_SIZE; - phykeyiv = dma_map_single(mc->dev, bkeyiv, keyivlen, - DMA_TO_DEVICE); - err = dma_mapping_error(mc->dev, phykeyiv); + ctx.keyiv.addr = dma_map_single(mc->dev, ctx.bkeyiv, ctx.keyiv.len, + DMA_TO_DEVICE); + err = dma_mapping_error(mc->dev, ctx.keyiv.addr); if (err) { dev_err(mc->dev, "Cannot DMA MAP KEY IV\n"); - goto theend; + goto free_keyiv; } - tloffset = 0; - eat = 0; - i = 0; - while (keyivlen > eat) { - desc = &mc->chanlist[flow].tl[tloffset]; - memset(desc, 0, sizeof(struct meson_desc)); - todo = min(keyivlen - eat, 16u); - desc->t_src = cpu_to_le32(phykeyiv + i * 16); - desc->t_dst = cpu_to_le32(i * 16); - v = DESC_MODE_KEY | DESC_OWN | 16; - desc->t_status = cpu_to_le32(v); - - eat += todo; - i++; - tloffset++; - } + err = meson_map_scatterlist(areq, mc); + if (err) + goto unmap_keyiv; - if (areq->src == areq->dst) { - nr_sgs = dma_map_sg(mc->dev, areq->src, sg_nents(areq->src), - DMA_BIDIRECTIONAL); - if (!nr_sgs || nr_sgs > MAXDESC - 3) { - dev_err(mc->dev, "Invalid BIDIR SG count %d\n", nr_sgs); - err = -EINVAL; + ctx.tloffset = 0; - if (nr_sgs) - dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_BIDIRECTIONAL); - goto error_keyiv; - } - nr_sgd = nr_sgs; - } else { - nr_sgs = dma_map_sg(mc->dev, areq->src, sg_nents(areq->src), - DMA_TO_DEVICE); - if (!nr_sgs || nr_sgs > MAXDESC - 3) { - dev_err(mc->dev, "Invalid SG count %d\n", nr_sgs); - err = -EINVAL; + while (ctx.cryptlen) { + meson_setup_keyiv_descs(&ctx); - if (nr_sgs) - dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE); - goto error_keyiv; + if (meson_setup_data_descs(&ctx)) { + err = meson_kick_hardware(&ctx); + if (err) + break; } - nr_sgd = dma_map_sg(mc->dev, areq->dst, sg_nents(areq->dst), - DMA_FROM_DEVICE); - if (!nr_sgd || nr_sgd > MAXDESC - 3) { - dev_err(mc->dev, "Invalid SG count %d\n", nr_sgd); - err = -EINVAL; - if (nr_sgd) - dma_unmap_sg(mc->dev, areq->dst, sg_nents(areq->dst), DMA_FROM_DEVICE); - goto error_src; + if (ctx.src_offset == sg_dma_len(ctx.src_sg)) { + ctx.src_offset = 0; + ctx.src_sg = sg_next(ctx.src_sg); } - } - src_sg = areq->src; - dst_sg = areq->dst; - len = areq->cryptlen; - while (src_sg) { - desc = &mc->chanlist[flow].tl[tloffset]; - memset(desc, 0, sizeof(struct meson_desc)); - - desc->t_src = cpu_to_le32(sg_dma_address(src_sg)); - desc->t_dst = cpu_to_le32(sg_dma_address(dst_sg)); - todo = min(len, sg_dma_len(src_sg)); - v = op->keymode | DESC_OWN | todo | algt->blockmode; - if (rctx->op_dir) - v |= DESC_ENCRYPTION; - len -= todo; - - if (!sg_next(src_sg)) - v |= DESC_LAST; - desc->t_status = cpu_to_le32(v); - tloffset++; - src_sg = sg_next(src_sg); - dst_sg = sg_next(dst_sg); + if (ctx.dst_offset == sg_dma_len(ctx.dst_sg)) { + ctx.dst_offset = 0; + ctx.dst_sg = sg_next(ctx.dst_sg); + } } - reinit_completion(&mc->chanlist[flow].complete); - meson_dma_start(mc, flow); - - err = wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete, - msecs_to_jiffies(500)); - if (err == 0) { - dev_err(mc->dev, "DMA timeout for flow %d\n", flow); - err = -EINVAL; - } else if (err < 0) { - dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", err); - } else { - /* No error */ - err = 0; - } + meson_unmap_scatterlist(areq, mc); - dma_unmap_single(mc->dev, phykeyiv, keyivlen, DMA_TO_DEVICE); +unmap_keyiv: + dma_unmap_single(mc->dev, ctx.keyiv.addr, ctx.keyiv.len, DMA_TO_DEVICE); - if (areq->src == areq->dst) { - dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_BIDIRECTIONAL); - } else { - dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE); - dma_unmap_sg(mc->dev, areq->dst, sg_nents(areq->dst), DMA_FROM_DEVICE); - } - - if (areq->iv && ivsize > 0) { - if (rctx->op_dir == MESON_DECRYPT) { - memcpy(areq->iv, backup_iv, ivsize); - } else { - scatterwalk_map_and_copy(areq->iv, areq->dst, - areq->cryptlen - ivsize, - ivsize, 0); - } - } - goto theend; - -error_src: - dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE); -error_keyiv: - dma_unmap_single(mc->dev, phykeyiv, keyivlen, DMA_TO_DEVICE); -theend: - kfree_sensitive(bkeyiv); - kfree_sensitive(backup_iv); +free_keyiv: + kfree_sensitive(ctx.bkeyiv); return err; } diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 68d394e90f66..0e17105520df 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -255,6 +255,7 @@ static void meson_crypto_remove(struct platform_device *pdev) static const struct meson_pdata meson_gxl_pdata = { .descs_reg = 0x0, .status_reg = 0x4, + .setup_desc_cnt = 3, }; static const struct of_device_id meson_crypto_of_match_table[] = { diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index 15b4335942d5..6797b44905d3 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -82,10 +82,12 @@ struct meson_flow { * struct meson_pdata - SoC series dependent data. * @reg_descs: offset to descriptors register * @reg_status: offset to status register + * @setup_desc_cnt: number of setup descriptor to configure. */ struct meson_pdata { u32 descs_reg; u32 status_reg; + u32 setup_desc_cnt; }; /* -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v13 11/25] crypto: amlogic - Process more than MAXDESCS descriptors 2026-11-26 19:32 ` [PATCH v13 11/25] crypto: amlogic - Process more than MAXDESCS descriptors Jose Nieto @ 2026-11-26 19:45 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-26 19:45 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] crypto: amlogic: unmapped IV and out-of-bounds keyiv DMA length in meson_cipher() - [High] crypto: amlogic: bad sg_virt() offset and DMA sync in meson_kick_hardware() -- commit 685ee7508ec6e6946361c6c3e2f5421b6188d69b Author: Alexey Romanov <romanov.alexey2000@gmail.com> crypto: amlogic - Process more than MAXDESCS descriptors This commit reworks descriptor setup in the Amlogic GXL crypto driver to process requests requiring more than MAXDESC descriptors in batches and makes the number of key/IV setup descriptors configurable via platform data. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c > index c17ce5cc70a87..cb6b959bb1f96 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c [ ... ] > @@ -76,6 +82,213 @@ static int meson_cipher_do_fallback(struct skcipher_request *areq) [ ... ] > +static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) > +{ > + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); > + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); > + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); > + struct meson_alg_template *algt = container_of(alg, > + struct meson_alg_template, alg.skcipher.base); > + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); > + struct meson_dev *mc = op->mc; > + unsigned int ivsize = crypto_skcipher_ivsize(tfm); > + unsigned int blockmode = algt->blockmode; > + int i; > + > + if (ctx->tloffset) > + return; > + > + if (blockmode == DESC_OPMODE_CBC) { > + memcpy(ctx->bkeyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); > + dma_sync_single_for_device(mc->dev, ctx->keyiv.addr, > + ctx->keyiv.len, DMA_TO_DEVICE); > + } > + > + for (i = 0; i < mc->pdata->setup_desc_cnt; i++) { > + struct meson_desc *desc = > + &mc->chanlist[rctx->flow].tl[ctx->tloffset]; > + int offset = i * 16; > + > + desc->t_src = cpu_to_le32(ctx->keyiv.addr + offset); > + desc->t_dst = cpu_to_le32(offset); > + desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | ctx->keyiv.len); > + > + ctx->tloffset++; > + } > +} [Severity: High] Does meson_setup_keyiv_descs() leave the CBC IV unmapped and program an out-of-bounds DMA length on each key/IV descriptor? In meson_cipher(), ctx.keyiv.len is set to 16 (AES-128) or 32 (AES-192/256) and passed to dma_map_single(), so bytes 32..47 of the 48-byte ctx->bkeyiv buffer where the CBC IV is copied are never mapped or flushed by dma_sync_single_for_device(). In addition, each of the setup_desc_cnt descriptors at offset = i * 16 sets its transfer length to ctx->keyiv.len instead of 16, causing hardware DMA to read past the DMA mapping and past the end of ctx->bkeyiv. A later patch in this series, commit "crypto: amlogic - Avoid kzalloc in engine thread", sets ctx.keyiv.len to AES_MAX_KEY_SIZE + ivsize (48) for CBC, but meson_setup_keyiv_descs() still encodes ctx->keyiv.len instead of 16 in each descriptor. > + > +static bool meson_setup_data_descs(struct cipher_ctx *ctx) > +{ [ ... ] > + todo = min(ctx->cryptlen, maxlen); > + todo = min(todo, ctx->cryptlen); > + todo = min(todo, sg_dma_len(ctx->src_sg) - ctx->src_offset); > + todo = min(todo, sg_dma_len(ctx->dst_sg) - ctx->dst_offset); > + > + desc->t_src = cpu_to_le32(sg_dma_address(ctx->src_sg) + ctx->src_offset); > + desc->t_dst = cpu_to_le32(sg_dma_address(ctx->dst_sg) + ctx->dst_offset); > + > + ctx->cryptlen -= todo; > + ctx->src_offset += todo; > + ctx->dst_offset += todo; [ ... ] > +} > + > +static int meson_kick_hardware(struct cipher_ctx *ctx) > +{ > + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); > + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); > + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); > + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); > + struct meson_alg_template *algt = container_of(alg, > + struct meson_alg_template, > + alg.skcipher.base); > + struct meson_dev *mc = op->mc; > + unsigned int ivsize = crypto_skcipher_ivsize(tfm); > + unsigned int blockmode = algt->blockmode; > + enum dma_data_direction new_iv_dir; > + struct scatterlist *sg_head; > + void *new_iv; > + int err; > + > + if (blockmode == DESC_OPMODE_CBC) { > + struct scatterlist *sg_current; > + unsigned int offset; > + > + if (rctx->op_dir == MESON_ENCRYPT) { > + sg_current = ctx->dst_sg; > + sg_head = ctx->areq->dst; > + offset = ctx->dst_offset; > + new_iv_dir = DMA_FROM_DEVICE; > + } else { > + sg_current = ctx->src_sg; > + sg_head = ctx->areq->src; > + offset = ctx->src_offset; > + new_iv_dir = DMA_TO_DEVICE; > + } > + > + if (ctx->areq->src == ctx->areq->dst) > + new_iv_dir = DMA_BIDIRECTIONAL; > + > + offset -= ivsize; > + new_iv = sg_virt(sg_current) + offset; > + } > + > + if (blockmode == DESC_OPMODE_CBC && > + rctx->op_dir == MESON_DECRYPT) { > + dma_sync_sg_for_cpu(mc->dev, sg_head, > + sg_nents(sg_head), new_iv_dir); > + memcpy(ctx->areq->iv, new_iv, ivsize); > + } > + > + reinit_completion(&mc->chanlist[rctx->flow].complete); > + meson_dma_start(mc, rctx->flow); > + err = wait_for_completion_interruptible_timeout(&mc->chanlist[rctx->flow].complete, > + msecs_to_jiffies(500)); > + if (err == 0) { > + dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); > + return -EINVAL; > + } else if (err < 0) { > + dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", err); > + return err; > + } > + > + if (blockmode == DESC_OPMODE_CBC && > + rctx->op_dir == MESON_ENCRYPT) { > + dma_sync_sg_for_cpu(mc->dev, sg_head, > + sg_nents(sg_head), new_iv_dir); > + memcpy(ctx->areq->iv, new_iv, ivsize); > + } > + > + ctx->tloffset = 0; > + > + return 0; > +} [Severity: High] Can sg_virt(sg_current) + offset read out of bounds when dma_map_sg() coalesces scatterlist entries? ctx->src_offset and ctx->dst_offset track offsets within the coalesced DMA segment of length sg_dma_len(sg_current), whereas sg_virt(sg_current) only maps the single uncoalesced page buffer of length sg_current->length. When dma_map_sg() merges contiguous entries, offset can exceed sg_current->length (or index the wrong entry), reading past the end of sg_current's virtual buffer. Also, meson_kick_hardware() calls dma_sync_sg_for_cpu() over the entire scatterlist on every batch without calling dma_sync_sg_for_device() to hand ownership back to the device before meson_dma_start() runs (including on in-place CBC decrypt and multi-batch CBC encrypt), and walks sg_nents(sg_head) on every batch. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261126193241.1471372-1-jnieto.alaber@gmail.com?part=11 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v13 12/25] crypto: amlogic - Avoid kzalloc in engine thread 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (10 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 11/25] crypto: amlogic - Process more than MAXDESCS descriptors Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:48 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 13/25] crypto: amlogic - Introduce hasher Jose Nieto ` (13 subsequent siblings) 25 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> It makes no sense to allocate memory via kzalloc, we can use static buffer, speedup data processing and don't think about kfree() calls. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 60 ++++++++++----------- drivers/crypto/amlogic/amlogic-gxl.h | 4 +- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index cb6b959bb1f9..df42940f1112 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -59,7 +59,7 @@ static bool meson_cipher_need_fallback(struct skcipher_request *areq) static int meson_cipher_do_fallback(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(areq); int err; #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG @@ -91,7 +91,6 @@ struct cipher_ctx { struct skcipher_request *areq; struct scatterlist *src_sg; struct scatterlist *dst_sg; - void *bkeyiv; unsigned int src_offset; unsigned int dst_offset; @@ -147,7 +146,7 @@ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) struct skcipher_alg *alg = crypto_skcipher_alg(tfm); struct meson_alg_template *algt = container_of(alg, struct meson_alg_template, alg.skcipher.base); - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct meson_dev *mc = op->mc; unsigned int ivsize = crypto_skcipher_ivsize(tfm); unsigned int blockmode = algt->blockmode; @@ -157,7 +156,7 @@ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) return; if (blockmode == DESC_OPMODE_CBC) { - memcpy(ctx->bkeyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); + memcpy(op->keyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); dma_sync_single_for_device(mc->dev, ctx->keyiv.addr, ctx->keyiv.len, DMA_TO_DEVICE); } @@ -179,7 +178,7 @@ static bool meson_setup_data_descs(struct cipher_ctx *ctx) { struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct skcipher_alg *alg = crypto_skcipher_alg(tfm); struct meson_alg_template *algt = container_of(alg, struct meson_alg_template, @@ -222,7 +221,7 @@ static int meson_kick_hardware(struct cipher_ctx *ctx) { struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct skcipher_alg *alg = crypto_skcipher_alg(tfm); struct meson_alg_template *algt = container_of(alg, struct meson_alg_template, @@ -292,7 +291,7 @@ static int meson_kick_hardware(struct cipher_ctx *ctx) static int meson_cipher(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(areq); struct meson_dev *mc = op->mc; struct skcipher_alg *alg = crypto_skcipher_alg(tfm); @@ -305,6 +304,7 @@ static int meson_cipher(struct skcipher_request *areq) .dst_sg = areq->dst, .cryptlen = areq->cryptlen, }; + unsigned int ivsize = crypto_skcipher_ivsize(tfm); int err; dev_dbg(mc->dev, "%s %s %u %x IV(%u) key=%u ctx.flow=%d\n", __func__, @@ -320,21 +320,21 @@ static int meson_cipher(struct skcipher_request *areq) mc->chanlist[rctx->flow].stat_req++; #endif - ctx.bkeyiv = kzalloc(48, GFP_KERNEL | GFP_DMA); - if (!ctx.bkeyiv) - return -ENOMEM; - - memcpy(ctx.bkeyiv, op->key, op->keylen); ctx.keyiv.len = op->keylen; if (ctx.keyiv.len == AES_KEYSIZE_192) ctx.keyiv.len = AES_MAX_KEY_SIZE; - ctx.keyiv.addr = dma_map_single(mc->dev, ctx.bkeyiv, ctx.keyiv.len, + if (algt->blockmode == DESC_OPMODE_CBC) { + memcpy(op->keyiv + AES_MAX_KEY_SIZE, areq->iv, ivsize); + ctx.keyiv.len = AES_MAX_KEY_SIZE + ivsize; + } + + ctx.keyiv.addr = dma_map_single(mc->dev, op->keyiv, ctx.keyiv.len, DMA_TO_DEVICE); err = dma_mapping_error(mc->dev, ctx.keyiv.addr); if (err) { dev_err(mc->dev, "Cannot DMA MAP KEY IV\n"); - goto free_keyiv; + return err; } err = meson_map_scatterlist(areq, mc); @@ -368,9 +368,6 @@ static int meson_cipher(struct skcipher_request *areq) unmap_keyiv: dma_unmap_single(mc->dev, ctx.keyiv.addr, ctx.keyiv.len, DMA_TO_DEVICE); -free_keyiv: - kfree_sensitive(ctx.bkeyiv); - return err; } @@ -390,7 +387,7 @@ int meson_handle_cipher_request(struct crypto_engine *engine, void *areq) static int meson_skdecrypt(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(areq); struct crypto_engine *engine; int e; @@ -408,7 +405,7 @@ static int meson_skdecrypt(struct skcipher_request *areq) static int meson_skencrypt(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(areq); struct crypto_engine *engine; int e; @@ -425,7 +422,7 @@ static int meson_skencrypt(struct skcipher_request *areq) static int meson_cipher_init(struct crypto_tfm *tfm) { - struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx_dma(tfm); struct meson_alg_template *algt; const char *name = crypto_tfm_alg_name(tfm); struct crypto_skcipher *sktfm = __crypto_skcipher_cast(tfm); @@ -443,7 +440,7 @@ static int meson_cipher_init(struct crypto_tfm *tfm) return PTR_ERR(op->fallback_tfm); } - crypto_skcipher_set_reqsize(sktfm, sizeof(struct meson_cipher_req_ctx) + + crypto_skcipher_set_reqsize_dma(sktfm, sizeof(struct meson_cipher_req_ctx) + crypto_skcipher_reqsize(op->fallback_tfm)); return 0; @@ -451,16 +448,15 @@ static int meson_cipher_init(struct crypto_tfm *tfm) static void meson_cipher_exit(struct crypto_tfm *tfm) { - struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx_dma(tfm); - kfree_sensitive(op->key); crypto_free_skcipher(op->fallback_tfm); } static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen) { - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct meson_dev *mc = op->mc; switch (keylen) { @@ -477,11 +473,9 @@ static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, dev_dbg(mc->dev, "ERROR: Invalid keylen %u\n", keylen); return -EINVAL; } - kfree_sensitive(op->key); + + memcpy(op->keyiv, key, keylen); op->keylen = keylen; - op->key = kmemdup(key, keylen, GFP_KERNEL | GFP_DMA); - if (!op->key) - return -ENOMEM; return crypto_skcipher_setkey(op->fallback_tfm, key, keylen); } @@ -499,7 +493,6 @@ static struct meson_alg_template algs[] = { .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | CRYPTO_ALG_NEED_FALLBACK, - .cra_ctxsize = sizeof(struct meson_cipher_tfm_ctx), .cra_module = THIS_MODULE, .cra_alignmask = 0xf, .cra_init = meson_cipher_init, @@ -528,7 +521,6 @@ static struct meson_alg_template algs[] = { .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | CRYPTO_ALG_NEED_FALLBACK, - .cra_ctxsize = sizeof(struct meson_cipher_tfm_ctx), .cra_module = THIS_MODULE, .cra_alignmask = 0xf, .cra_init = meson_cipher_init, @@ -548,6 +540,14 @@ static struct meson_alg_template algs[] = { int meson_cipher_register(struct meson_dev *mc) { + int i; + + for (i = 0; i < ARRAY_SIZE(algs); i++) { + struct skcipher_alg *alg = &algs[i].alg.skcipher.base; + + alg->base.cra_ctxsize = sizeof(struct meson_cipher_tfm_ctx) + crypto_dma_padding(); + } + return meson_register_algs(mc, algs, ARRAY_SIZE(algs)); } diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index 6797b44905d3..c401cbbadaa3 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -125,14 +125,14 @@ struct meson_cipher_req_ctx { /* * struct meson_cipher_tfm_ctx - context for a skcipher TFM - * @key: pointer to key data + * @keyiv: key data * @keylen: len of the key * @keymode: The keymode(type and size of key) associated with this TFM * @mc: pointer to the private data of driver handling this TFM * @fallback_tfm: pointer to the fallback TFM */ struct meson_cipher_tfm_ctx { - u32 *key; + u8 keyiv[AES_MAX_KEY_SIZE + AES_BLOCK_SIZE]; u32 keylen; u32 keymode; struct meson_dev *mc; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v13 12/25] crypto: amlogic - Avoid kzalloc in engine thread 2026-11-26 19:32 ` [PATCH v13 12/25] crypto: amlogic - Avoid kzalloc in engine thread Jose Nieto @ 2026-11-26 19:48 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-26 19:48 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [High] crypto: amlogic: shared TFM keyiv buffer races across concurrent requests - [Medium] crypto: amlogic: unsynced DMA write and duplicate IV copy in meson_cipher() - [Medium] crypto: amlogic: out-of-bounds keyiv DMA descriptors in meson_cipher() - [Low] crypto: amlogic: unused DMA reqsize padding in meson_cipher_init() - [Low] crypto: amlogic: stale trailing key bytes on re-key in meson_aes_setkey() -- commit 228a0fe250c8671b89954b4f55b91bfb1b59975f Author: Alexey Romanov <romanov.alexey2000@gmail.com> crypto: amlogic - Avoid kzalloc in engine thread This commit replaces the per-request kzalloc() key/IV buffer in meson_cipher() and the dynamically allocated key in struct meson_cipher_tfm_ctx with a fixed-size keyiv array in the transform context, and switches transform and request context accessors to their DMA-aligned variants. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c > index cb6b959bb1f96..df42940f1112a 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c [ ... ] > @@ -147,17 +146,17 @@ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) > struct skcipher_alg *alg = crypto_skcipher_alg(tfm); > struct meson_alg_template *algt = container_of(alg, > struct meson_alg_template, alg.skcipher.base); > - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); > + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); > struct meson_dev *mc = op->mc; > unsigned int ivsize = crypto_skcipher_ivsize(tfm); > unsigned int blockmode = algt->blockmode; > int i; > > if (ctx->tloffset) > return; > > if (blockmode == DESC_OPMODE_CBC) { > - memcpy(ctx->bkeyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); > + memcpy(op->keyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); > dma_sync_single_for_device(mc->dev, ctx->keyiv.addr, > ctx->keyiv.len, DMA_TO_DEVICE); > } [Severity: Medium] Does meson_setup_keyiv_descs() modify the DMA-mapped op->keyiv buffer without calling dma_sync_single_for_cpu() first, while also duplicating the initial IV copy and DMA sync already performed in meson_cipher()? In meson_cipher(), CBC requests copy areq->iv into op->keyiv and call dma_map_single(..., DMA_TO_DEVICE), transferring buffer ownership to the device before entering the loop with ctx.tloffset == 0. On the first loop iteration, meson_setup_keyiv_descs() immediately repeats that memcpy() and flushes the cache a second time via dma_sync_single_for_device(), and on every batch it writes to the mapped buffer from the CPU without a preceding dma_sync_single_for_cpu() call. [ ... ] > @@ -320,21 +320,21 @@ static int meson_cipher(struct skcipher_request *areq) > mc->chanlist[rctx->flow].stat_req++; > #endif > > - ctx.bkeyiv = kzalloc(48, GFP_KERNEL | GFP_DMA); > - if (!ctx.bkeyiv) > - return -ENOMEM; > - > - memcpy(ctx.bkeyiv, op->key, op->keylen); > ctx.keyiv.len = op->keylen; > if (ctx.keyiv.len == AES_KEYSIZE_192) > ctx.keyiv.len = AES_MAX_KEY_SIZE; > > - ctx.keyiv.addr = dma_map_single(mc->dev, ctx.bkeyiv, ctx.keyiv.len, > + if (algt->blockmode == DESC_OPMODE_CBC) { > + memcpy(op->keyiv + AES_MAX_KEY_SIZE, areq->iv, ivsize); > + ctx.keyiv.len = AES_MAX_KEY_SIZE + ivsize; > + } > + > + ctx.keyiv.addr = dma_map_single(mc->dev, op->keyiv, ctx.keyiv.len, > DMA_TO_DEVICE); [Severity: Medium] Does setting ctx.keyiv.len to 48 in CBC mode cause meson_setup_keyiv_descs() to program key/IV DMA descriptors that read past the end of op->keyiv? meson_setup_keyiv_descs() loops mc->pdata->setup_desc_cnt (3) times at 16-byte offsets (0, 16, 32) and sets each descriptor's length in t_status to ctx->keyiv.len: drivers/crypto/amlogic/amlogic-gxl-cipher.c:meson_setup_keyiv_descs() { ... for (i = 0; i < mc->pdata->setup_desc_cnt; i++) { struct meson_desc *desc = &mc->chanlist[rctx->flow].tl[ctx->tloffset]; int offset = i * 16; desc->t_src = cpu_to_le32(ctx->keyiv.addr + offset); desc->t_dst = cpu_to_le32(offset); desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | ctx->keyiv.len); ctx->tloffset++; } } With ctx.keyiv.len increased to 48 for CBC (and 16 or 32 for ECB, where dma_map_single() only maps ctx.keyiv.len bytes), the descriptors at offsets 16 and 32 instruct the DMA engine to read up to 32 bytes past the end of the 48-byte op->keyiv buffer and its DMA mapping. [ ... ] > @@ -425,40 +422,37 @@ static int meson_skencrypt(struct skcipher_request *areq) > > static int meson_cipher_init(struct crypto_tfm *tfm) > { [ ... ] > - crypto_skcipher_set_reqsize(sktfm, sizeof(struct meson_cipher_req_ctx) + > + crypto_skcipher_set_reqsize_dma(sktfm, sizeof(struct meson_cipher_req_ctx) + > crypto_skcipher_reqsize(op->fallback_tfm)); > > return 0; > } [Severity: Low] Is crypto_skcipher_set_reqsize_dma() needed here when struct meson_cipher_req_ctx holds no DMA buffers and all callers still access it via skcipher_request_ctx()? Unless the per-request DMA buffer is moved into struct meson_cipher_req_ctx and accessed with skcipher_request_ctx_dma(), this adds unused DMA alignment padding to every request allocation. > static void meson_cipher_exit(struct crypto_tfm *tfm) > { > - struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm); > + struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx_dma(tfm); > > - kfree_sensitive(op->key); > crypto_free_skcipher(op->fallback_tfm); > } > > static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, > unsigned int keylen) > { > - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); > + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); > struct meson_dev *mc = op->mc; > > switch (keylen) { > @@ -477,11 +473,9 @@ static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, > dev_dbg(mc->dev, "ERROR: Invalid keylen %u\n", keylen); > return -EINVAL; > } > - kfree_sensitive(op->key); > + > + memcpy(op->keyiv, key, keylen); > op->keylen = keylen; [Severity: Low] Can re-keying an existing transform with a shorter key leave stale key bytes in op->keyiv? Previously, meson_cipher() allocated a zeroed 48-byte buffer on each request. Because op->keyiv is now only zeroed once in meson_cipher_init(), re-keying a transform from AES-256 to AES-192 or AES-128 leaves the old key's trailing bytes in op->keyiv[keylen..AES_MAX_KEY_SIZE - 1], which are then DMA-mapped and sent to the hardware when ctx.keyiv.len is padded to AES_MAX_KEY_SIZE. > diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h > index 6797b44905d3e..c401cbbadaa34 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl.h > +++ b/drivers/crypto/amlogic/amlogic-gxl.h > @@ -125,14 +125,14 @@ struct meson_cipher_req_ctx { > > /* > * struct meson_cipher_tfm_ctx - context for a skcipher TFM > - * @key: pointer to key data > + * @keyiv: key data > * @keylen: len of the key > * @keymode: The keymode(type and size of key) associated with this TFM > * @mc: pointer to the private data of driver handling this TFM > * @fallback_tfm: pointer to the fallback TFM > */ > struct meson_cipher_tfm_ctx { > - u32 *key; > + u8 keyiv[AES_MAX_KEY_SIZE + AES_BLOCK_SIZE]; > u32 keylen; > u32 keymode; > struct meson_dev *mc; [Severity: High] Can moving the mutable key/IV DMA buffer into struct meson_cipher_tfm_ctx cause a data race and CBC data corruption when two requests share a transform? A single struct crypto_skcipher transform is shared across concurrent requests, and meson_skencrypt() / meson_skdecrypt() dispatch requests round-robin across mc->flow_cnt (2) crypto_engine worker threads via meson_get_engine_number(): flow 0 kworker flow 1 kworker meson_cipher(req1) memcpy(op->keyiv + 32, req1->iv, 16) dma_map_single(..., op->keyiv, ...) meson_cipher(req2) memcpy(op->keyiv + 32, req2->iv, 16) <-- overwrites IV dma_map_single(..., op->keyiv, ...) meson_kick_hardware() meson_dma_start() <-- DMA reads req2's IV for req1 dma_unmap_single(...) <-- unmaps while flow 1 DMA is active In addition, op->keyiv is not padded to a cacheline boundary inside struct meson_cipher_tfm_ctx, so it shares a cacheline with keylen, keymode, mc, and fallback_tfm during streaming DMA mappings. Should the per-request key/IV DMA buffer live in struct meson_cipher_req_ctx (accessed via skcipher_request_ctx_dma()) instead of the shared transform context? -- Sashiko AI review · https://sashiko.dev/#/patchset/20261126193241.1471372-1-jnieto.alaber@gmail.com?part=12 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v13 13/25] crypto: amlogic - Introduce hasher 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (11 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 12/25] crypto: amlogic - Avoid kzalloc in engine thread Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:56 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 14/25] crypto: amlogic - Use fallback for 192-bit keys Jose Nieto ` (12 subsequent siblings) 25 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Introduce support for SHA1/SHA224/SHA256 hash algos. Tested via tcrypt and custom tests. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/Makefile | 2 +- drivers/crypto/amlogic/amlogic-gxl-core.c | 25 +- drivers/crypto/amlogic/amlogic-gxl-hasher.c | 485 ++++++++++++++++++++ drivers/crypto/amlogic/amlogic-gxl.h | 48 ++ 4 files changed, 558 insertions(+), 2 deletions(-) create mode 100644 drivers/crypto/amlogic/amlogic-gxl-hasher.c diff --git a/drivers/crypto/amlogic/Makefile b/drivers/crypto/amlogic/Makefile index 39057e62c13e..4b6b388b7880 100644 --- a/drivers/crypto/amlogic/Makefile +++ b/drivers/crypto/amlogic/Makefile @@ -1,2 +1,2 @@ obj-$(CONFIG_CRYPTO_DEV_AMLOGIC_GXL) += amlogic-gxl-crypto.o -amlogic-gxl-crypto-y := amlogic-gxl-core.o amlogic-gxl-cipher.o +amlogic-gxl-crypto-y := amlogic-gxl-core.o amlogic-gxl-cipher.o amlogic-gxl-hasher.o diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 0e17105520df..9676b86a5089 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -19,6 +19,9 @@ #include <linux/of.h> #include <linux/of_device.h> #include <linux/platform_device.h> +#include <crypto/internal/skcipher.h> +#include <crypto/internal/hash.h> +#include <linux/dma-mapping.h> #include "amlogic-gxl.h" @@ -172,6 +175,15 @@ int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *algs, return err; } break; + case CRYPTO_ALG_TYPE_AHASH: + err = crypto_engine_register_ahash(&algs[i].alg.ahash); + if (err) { + dev_err(mc->dev, "Fail to register %s\n", + algs[i].alg.ahash.base.halg.base.cra_name); + meson_unregister_algs(mc, algs, count); + return err; + } + break; } } @@ -190,6 +202,9 @@ void meson_unregister_algs(struct meson_dev *mc, struct meson_alg_template *algs case CRYPTO_ALG_TYPE_SKCIPHER: crypto_engine_unregister_skcipher(&algs[i].alg.skcipher); break; + case CRYPTO_ALG_TYPE_AHASH: + crypto_engine_unregister_ahash(&algs[i].alg.ahash); + break; } } } @@ -227,13 +242,20 @@ static int meson_crypto_probe(struct platform_device *pdev) dbgfs_dir = debugfs_create_dir("gxl-crypto", NULL); debugfs_create_file("stats", 0444, dbgfs_dir, mc, &meson_debugfs_fops); - #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG mc->dbgfs_dir = dbgfs_dir; #endif } + err = meson_hasher_register(mc); + if (err) + goto error_hasher; + return 0; + +error_hasher: + meson_cipher_unregister(mc); + error_flow: meson_free_chanlist(mc, mc->flow_cnt - 1); return err; @@ -256,6 +278,7 @@ static const struct meson_pdata meson_gxl_pdata = { .descs_reg = 0x0, .status_reg = 0x4, .setup_desc_cnt = 3, + .hasher_supported = false, }; static const struct of_device_id meson_crypto_of_match_table[] = { diff --git a/drivers/crypto/amlogic/amlogic-gxl-hasher.c b/drivers/crypto/amlogic/amlogic-gxl-hasher.c new file mode 100644 index 000000000000..c83739ec3456 --- /dev/null +++ b/drivers/crypto/amlogic/amlogic-gxl-hasher.c @@ -0,0 +1,485 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Hardware asynchronous hasher for Amlogic SoC's. + * + * Author: Alexey Romanov <romanov.alexey2000@gmail.com> + */ + +#include <linux/crypto.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/err.h> +#include <crypto/internal/hash.h> +#include <crypto/sha1.h> +#include <crypto/sha2.h> + +#include "amlogic-gxl.h" + +static int meson_sha_init(struct ahash_request *req) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + + memset(rctx, 0, sizeof(struct meson_hasher_req_ctx)); + + rctx->flow = meson_get_engine_number(tctx->mc); + rctx->begin_req = true; + + return 0; +} + +static int meson_sha_update(struct ahash_request *req) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct crypto_engine *engine = tctx->mc->chanlist[rctx->flow].engine; + + return crypto_transfer_hash_request_to_engine(engine, req); +} + +static int meson_sha_final(struct ahash_request *req) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct crypto_engine *engine = tctx->mc->chanlist[rctx->flow].engine; + + rctx->final_req = true; + + return crypto_transfer_hash_request_to_engine(engine, req); +} + +static int meson_hasher_req_map(struct ahash_request *req) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_dev *mc = tctx->mc; + int ret; + + if (!req->nbytes) + return 0; + + ret = dma_map_sg(mc->dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); + if (!ret) { + dev_err(mc->dev, "Cannot DMA MAP request data\n"); + return -ENOMEM; + } + + return 0; +} + +static void meson_hasher_req_unmap(struct ahash_request *req) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_dev *mc = tctx->mc; + + if (!req->nbytes) + return; + + dma_unmap_sg(mc->dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); +} + +struct hasher_ctx { + struct crypto_async_request *areq; + + unsigned int tloffset; + unsigned int nbytes; + unsigned int todo; + + dma_addr_t state_addr; + dma_addr_t src_addr; + unsigned int src_offset; + struct scatterlist *src_sg; +}; + +static bool meson_final(struct hasher_ctx *ctx) +{ + struct ahash_request *req = ahash_request_cast(ctx->areq); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + + return !ctx->nbytes && rctx->final_req; +} + +static int meson_fill_partial_buffer(struct hasher_ctx *ctx, unsigned int len) +{ + struct ahash_request *req = ahash_request_cast(ctx->areq); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct meson_dev *mc = tctx->mc; + unsigned int blocksize = crypto_ahash_blocksize(tfm); + unsigned int copy; + + if (len) { + copy = min(blocksize - rctx->partial_size, len); + memcpy(rctx->partial + rctx->partial_size, + sg_virt(ctx->src_sg) + ctx->src_offset, copy); + + rctx->partial_size += copy; + ctx->nbytes -= copy; + ctx->src_offset += copy; + } + + if (rctx->partial_size == blocksize || meson_final(ctx)) { + rctx->partial_addr = dma_map_single(mc->dev, + rctx->partial, + rctx->partial_size, + DMA_TO_DEVICE); + if (dma_mapping_error(mc->dev, rctx->partial_addr)) { + dev_err(mc->dev, "Cannot DMA MAP SHA partial buffer\n"); + return -ENOMEM; + } + + rctx->partial_mapped = true; + ctx->todo = rctx->partial_size; + ctx->src_addr = rctx->partial_addr; + } + + return 0; +} + +static unsigned int meson_setup_data_descs(struct hasher_ctx *ctx) +{ + struct ahash_request *req = ahash_request_cast(ctx->areq); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_dev *mc = tctx->mc; + struct meson_flow *flow = &mc->chanlist[rctx->flow]; + struct hash_alg_common *alg = crypto_hash_alg_common(tfm); + struct meson_alg_template *algt = container_of(alg, + struct meson_alg_template, alg.ahash.base.halg); + struct meson_desc *desc = &flow->tl[ctx->tloffset]; + u32 v; + + ctx->tloffset++; + + v = DESC_OWN | DESC_ENCRYPTION | DESC_OPMODE_SHA | + ctx->todo | algt->blockmode; + if (rctx->begin_req) { + rctx->begin_req = false; + v |= DESC_BEGIN; + } + + if (!ctx->nbytes && rctx->final_req) { + rctx->final_req = false; + v |= DESC_END; + } + + if (!ctx->nbytes || ctx->tloffset == MAXDESC || rctx->partial_mapped) + v |= DESC_LAST; + + desc->t_src = cpu_to_le32(ctx->src_addr); + desc->t_dst = cpu_to_le32(ctx->state_addr); + desc->t_status = cpu_to_le32(v); + + return v & DESC_LAST; +} + +static int meson_kick_hardware(struct hasher_ctx *ctx) +{ + struct ahash_request *req = ahash_request_cast(ctx->areq); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_dev *mc = tctx->mc; + struct meson_flow *flow = &mc->chanlist[rctx->flow]; + int ret; + + reinit_completion(&flow->complete); + meson_dma_start(mc, rctx->flow); + + ret = wait_for_completion_timeout(&flow->complete, + msecs_to_jiffies(500)); + if (ret == 0) { + dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); + return -EINVAL; + } else if (ret < 0) { + dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", ret); + return ret; + } + + if (rctx->partial_mapped) { + dma_unmap_single(mc->dev, rctx->partial_addr, + rctx->partial_size, + DMA_TO_DEVICE); + rctx->partial_size = 0; + rctx->partial_mapped = false; + } + + ctx->tloffset = 0; + + return 0; +} + +static void meson_setup_state_descs(struct hasher_ctx *ctx) +{ + struct ahash_request *req = ahash_request_cast(ctx->areq); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_dev *mc = tctx->mc; + struct meson_desc *desc; + int i; + + if (ctx->tloffset || rctx->begin_req) + return; + + for (i = 0; i < mc->pdata->setup_desc_cnt; i++) { + int offset = i * 16; + + desc = &mc->chanlist[rctx->flow].tl[ctx->tloffset]; + desc->t_src = cpu_to_le32(ctx->state_addr + offset); + desc->t_dst = cpu_to_le32(offset); + desc->t_status = cpu_to_le32(MESON_SHA_BUFFER_SIZE | + DESC_MODE_KEY | DESC_OWN); + + ctx->tloffset++; + } +} + +static int meson_hasher_do_one_request(struct crypto_engine *engine, void *areq) +{ + struct ahash_request *req = ahash_request_cast(areq); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct meson_dev *mc = tctx->mc; + struct hasher_ctx ctx = { + .tloffset = 0, + .src_offset = 0, + .nbytes = rctx->final_req ? 0 : req->nbytes, + .src_sg = req->src, + .areq = areq, + }; + unsigned int blocksize = crypto_ahash_blocksize(tfm); + unsigned int digest_size = crypto_ahash_digestsize(tfm); + bool final_req = rctx->final_req; + int ret; + + ctx.state_addr = dma_map_single(mc->dev, rctx->state, + sizeof(rctx->state), DMA_BIDIRECTIONAL); + ret = dma_mapping_error(mc->dev, ctx.state_addr); + if (ret) { + dev_err(mc->dev, "Cannot DMA MAP SHA state buffer"); + goto fail_map_single; + } + + ret = meson_hasher_req_map(req); + if (ret) + goto fail_map_req; + + for (;;) { + unsigned int len = ctx.src_sg ? + min(sg_dma_len(ctx.src_sg) - ctx.src_offset, ctx.nbytes) : 0; + + ctx.src_addr = 0; + ctx.todo = 0; + + if (!rctx->final_req && !ctx.nbytes) + break; + + meson_setup_state_descs(&ctx); + + if (rctx->partial_size && rctx->partial_size < blocksize) { + ret = meson_fill_partial_buffer(&ctx, len); + if (ret) + goto fail; + } else if (len && len < blocksize) { + memcpy(rctx->partial, sg_virt(ctx.src_sg) + ctx.src_offset, len); + + rctx->partial_size = len; + ctx.nbytes -= len; + ctx.src_offset += len; + } else if (len) { + ctx.src_addr = sg_dma_address(ctx.src_sg) + ctx.src_offset; + ctx.todo = min(rounddown(DESC_MAXLEN, blocksize), + rounddown(len, blocksize)); + ctx.nbytes -= ctx.todo; + ctx.src_offset += ctx.todo; + } + + if (ctx.src_sg && ctx.src_offset == sg_dma_len(ctx.src_sg)) { + ctx.src_offset = 0; + ctx.src_sg = sg_next(ctx.src_sg); + } + + if (!ctx.todo && ctx.nbytes) + continue; + + if (!ctx.todo && !rctx->final_req && !ctx.tloffset) + continue; + + if (meson_setup_data_descs(&ctx)) { + ret = meson_kick_hardware(&ctx); + if (ret) + goto fail; + } + } + +fail: + meson_hasher_req_unmap(req); + +fail_map_req: + dma_unmap_single(mc->dev, ctx.state_addr, sizeof(rctx->state), + DMA_BIDIRECTIONAL); + +fail_map_single: + if (final_req && ret == 0) + memcpy(req->result, rctx->state, digest_size); + + local_bh_disable(); + crypto_finalize_hash_request(engine, req, ret); + local_bh_enable(); + + return ret; +} + +static int meson_hasher_export(struct ahash_request *req, void *out) +{ + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + + memcpy(out, rctx, sizeof(*rctx)); + return 0; +} + +static int meson_hasher_import(struct ahash_request *req, const void *in) +{ + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + + memcpy(rctx, in, sizeof(*rctx)); + return 0; +} + +static int meson_hasher_init(struct crypto_tfm *tfm) +{ + struct meson_hasher_tfm_ctx *tctx = crypto_tfm_ctx_dma(tfm); + struct crypto_ahash *atfm = __crypto_ahash_cast(tfm); + struct hash_alg_common *alg = crypto_hash_alg_common(atfm); + struct meson_alg_template *algt = container_of(alg, + struct meson_alg_template, alg.ahash.base.halg); + + crypto_ahash_set_reqsize_dma(atfm, crypto_ahash_statesize(atfm)); + + memset(tctx, 0, sizeof(struct meson_hasher_tfm_ctx)); + + tctx->mc = algt->mc; + + return 0; +} + +static struct meson_alg_template mc_algs[] = { +{ + .type = CRYPTO_ALG_TYPE_AHASH, + .blockmode = DESC_MODE_SHA1, + .alg.ahash.base = { + .halg = { + .base = { + .cra_name = "sha1", + .cra_driver_name = "sha1-gxl", + .cra_priority = 400, + .cra_blocksize = SHA1_BLOCK_SIZE, + .cra_flags = CRYPTO_ALG_ASYNC, + .cra_module = THIS_MODULE, + .cra_alignmask = 0, + .cra_init = meson_hasher_init, + }, + .digestsize = SHA1_DIGEST_SIZE, + .statesize = sizeof(struct meson_hasher_req_ctx), + }, + .init = meson_sha_init, + .update = meson_sha_update, + .final = meson_sha_final, + .export = meson_hasher_export, + .import = meson_hasher_import, + }, + .alg.ahash.op = { + .do_one_request = meson_hasher_do_one_request, + }, +}, +{ + .type = CRYPTO_ALG_TYPE_AHASH, + .blockmode = DESC_MODE_SHA224, + .alg.ahash.base = { + .halg = { + .base = { + .cra_name = "sha224", + .cra_driver_name = "sha224-gxl", + .cra_priority = 400, + .cra_blocksize = SHA224_BLOCK_SIZE, + .cra_flags = CRYPTO_ALG_ASYNC, + .cra_module = THIS_MODULE, + .cra_alignmask = 0, + .cra_init = meson_hasher_init, + }, + .digestsize = SHA224_DIGEST_SIZE, + .statesize = sizeof(struct meson_hasher_req_ctx), + }, + .init = meson_sha_init, + .update = meson_sha_update, + .final = meson_sha_final, + .export = meson_hasher_export, + .import = meson_hasher_import, + }, + .alg.ahash.op = { + .do_one_request = meson_hasher_do_one_request, + }, +}, +{ + .type = CRYPTO_ALG_TYPE_AHASH, + .blockmode = DESC_MODE_SHA256, + .alg.ahash.base = { + .halg = { + .base = { + .cra_name = "sha256", + .cra_driver_name = "sha256-gxl", + .cra_priority = 400, + .cra_blocksize = SHA256_BLOCK_SIZE, + .cra_flags = CRYPTO_ALG_ASYNC, + .cra_module = THIS_MODULE, + .cra_alignmask = 0, + .cra_init = meson_hasher_init, + }, + .digestsize = SHA256_DIGEST_SIZE, + .statesize = sizeof(struct meson_hasher_req_ctx), + }, + .init = meson_sha_init, + .update = meson_sha_update, + .final = meson_sha_final, + .export = meson_hasher_export, + .import = meson_hasher_import, + }, + .alg.ahash.op = { + .do_one_request = meson_hasher_do_one_request, + }, +}, +}; + +int meson_hasher_register(struct meson_dev *mc) +{ + int i; + + if (!mc->pdata->hasher_supported) { + pr_info("amlogic-gxl-hasher: hasher not supported at current platform"); + return 0; + } + + for (i = 0; i < ARRAY_SIZE(mc_algs); i++) { + struct hash_alg_common *alg = &mc_algs[i].alg.ahash.base.halg; + + alg->base.cra_ctxsize = sizeof(struct meson_hasher_tfm_ctx) + crypto_dma_padding(); + } + + return meson_register_algs(mc, mc_algs, ARRAY_SIZE(mc_algs)); +} + +void meson_hasher_unregister(struct meson_dev *mc) +{ + if (!mc->pdata->hasher_supported) + return; + + meson_unregister_algs(mc, mc_algs, ARRAY_SIZE(mc_algs)); +} diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index c401cbbadaa3..b092d0c89cd8 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -5,6 +5,7 @@ * Copyright (C) 2018-2019 Corentin LABBE <clabbe@baylibre.com> */ #include <crypto/aes.h> +#include <crypto/sha2.h> #include <crypto/engine.h> #include <crypto/skcipher.h> #include <linux/debugfs.h> @@ -23,13 +24,22 @@ #define DESC_OPMODE_ECB (0 << 26) #define DESC_OPMODE_CBC (1 << 26) +#define DESC_OPMODE_SHA (0 << 26) #define DESC_MAXLEN GENMASK(16, 0) +#define DESC_MODE_SHA1 (0x5 << 20) +#define DESC_MODE_SHA224 (0x7 << 20) +#define DESC_MODE_SHA256 (0x6 << 20) + #define DESC_LAST BIT(18) +#define DESC_BEGIN BIT(24) +#define DESC_END BIT(25) #define DESC_ENCRYPTION BIT(28) #define DESC_OWN BIT(31) +#define MESON_SHA_BUFFER_SIZE (SHA256_DIGEST_SIZE + 16) + /* * struct meson_desc - Descriptor for DMA operations * Note that without datasheet, some are unknown @@ -83,11 +93,13 @@ struct meson_flow { * @reg_descs: offset to descriptors register * @reg_status: offset to status register * @setup_desc_cnt: number of setup descriptor to configure. + * @hasher_supported: indecates whether hasher is supported. */ struct meson_pdata { u32 descs_reg; u32 status_reg; u32 setup_desc_cnt; + bool hasher_supported; }; /* @@ -139,6 +151,38 @@ struct meson_cipher_tfm_ctx { struct crypto_skcipher *fallback_tfm; }; +/* + * struct meson_hasher_req_ctx - context for a hasher request + * @state: state data + * @partial: partial buffer data. Contains sent data which + * size < blocksize + * @partial_size: size of the partial buffer + * @partial_addr: physical address of partial buffer + * @partial_mapped: indicates is partial buffer currently mapped or not + * @flags: request flags (for example, is this final req or not) + * @flow: the flow to use for this request + */ +struct meson_hasher_req_ctx { + u8 state[SHA256_DIGEST_SIZE + 16] ____cacheline_aligned; + u8 partial[SHA256_BLOCK_SIZE] ____cacheline_aligned; + unsigned int partial_size ____cacheline_aligned; + dma_addr_t partial_addr; + bool partial_mapped; + + bool begin_req; + bool final_req; + int flow; +}; + +/* + * struct meson_hasher_tfm_ctx - context for a hasher TFM + * @enginectx: crypto_engine used by this TFM + * @mc: pointer to the private data of driver handling this TFM + */ +struct meson_hasher_tfm_ctx { + struct meson_dev *mc; +}; + /* * struct meson_alg_template - crypto_alg template * @type: the CRYPTO_ALG_TYPE for this template @@ -153,6 +197,7 @@ struct meson_alg_template { u32 blockmode; union { struct skcipher_engine_alg skcipher; + struct ahash_engine_alg ahash; } alg; struct meson_dev *mc; #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG @@ -174,3 +219,6 @@ int meson_cipher_register(struct meson_dev *mc); void meson_cipher_unregister(struct meson_dev *mc); void meson_cipher_debugfs_show(struct seq_file *seq, void *v); int meson_handle_cipher_request(struct crypto_engine *engine, void *areq); + +int meson_hasher_register(struct meson_dev *mc); +void meson_hasher_unregister(struct meson_dev *mc); -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v13 13/25] crypto: amlogic - Introduce hasher 2026-11-26 19:32 ` [PATCH v13 13/25] crypto: amlogic - Introduce hasher Jose Nieto @ 2026-11-26 19:56 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-26 19:56 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 9 potential issues to consider: - [High] crypto: amlogic: 0-byte SHA DMA descriptor in meson_hasher_do_one_request() - [High] crypto: amlogic: double completion on error in meson_hasher_do_one_request() - [High] crypto: amlogic: invalid src DMA map on final in meson_hasher_req_map() - [High] crypto: amlogic: unaligned DMA request ctx via ahash_request_ctx() - [Medium] crypto: amlogic: debugfs leak and UAF on meson_hasher_register() error - [Medium] crypto: amlogic: leaked partial_addr DMA mapping in meson_kick_hardware() - [Medium] crypto: amlogic: meson_register_algs() unregisters failed ahash algorithm - [Medium] crypto: amlogic: partial buffer DMA mapping leak in meson_kick_hardware() - [Medium] crypto: amlogic: sg_virt() indexed by sg_dma_len() in amlogic-gxl-hasher -- commit 8f2023eba0fbe0a55f65e0dd07dde281e4bf36f0 Author: Alexey Romanov <romanov.alexey2000@gmail.com> crypto: amlogic - Introduce hasher This commit adds asynchronous hardware SHA1, SHA224, and SHA256 support to the Amlogic GXL crypto driver. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c > index 0e17105520dfb..9676b86a50891 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-core.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c [ ... ] > @@ -172,6 +175,15 @@ int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *algs, > return err; > } > break; > + case CRYPTO_ALG_TYPE_AHASH: > + err = crypto_engine_register_ahash(&algs[i].alg.ahash); > + if (err) { > + dev_err(mc->dev, "Fail to register %s\n", > + algs[i].alg.ahash.base.halg.base.cra_name); > + meson_unregister_algs(mc, algs, count); > + return err; > + } > + break; > } > } > > @@ -190,6 +202,9 @@ void meson_unregister_algs(struct meson_dev *mc, struct meson_alg_template *algs > case CRYPTO_ALG_TYPE_SKCIPHER: > crypto_engine_unregister_skcipher(&algs[i].alg.skcipher); > break; > + case CRYPTO_ALG_TYPE_AHASH: > + crypto_engine_unregister_ahash(&algs[i].alg.ahash); > + break; > } > } > } [Severity: Medium] Does meson_register_algs() unregister the entry that just failed to register? meson_register_algs() sets algs[i].mc = mc at the start of each loop iteration, and meson_unregister_algs() unregisters every entry with a non-NULL algs[i].mc without clearing it. If crypto_engine_register_ahash() fails, meson_unregister_algs() calls crypto_engine_unregister_ahash() on the unregistered algs[i], which can trigger a NULL pointer dereference in list_del_init(&alg->cra_list) or a WARN() in crypto_unregister_alg(). > @@ -227,13 +242,20 @@ static int meson_crypto_probe(struct platform_device *pdev) > > dbgfs_dir = debugfs_create_dir("gxl-crypto", NULL); > debugfs_create_file("stats", 0444, dbgfs_dir, mc, &meson_debugfs_fops); > - > #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG > mc->dbgfs_dir = dbgfs_dir; > #endif > } > > + err = meson_hasher_register(mc); > + if (err) > + goto error_hasher; > + > return 0; > + > +error_hasher: > + meson_cipher_unregister(mc); > + > error_flow: > meson_free_chanlist(mc, mc->flow_cnt - 1); > return err; [Severity: Medium] Does error_hasher leak mc->dbgfs_dir when meson_hasher_register() fails? Leaving the "gxl-crypto" debugfs directory and "stats" file registered blocks subsequent probes from creating the directory and leaves a dangling pointer to the devm-freed struct meson_dev in the file's private data, causing a use-after-free in meson_debugfs_show() if the file is read. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-hasher.c b/drivers/crypto/amlogic/amlogic-gxl-hasher.c > new file mode 100644 > index 0000000000000..c83739ec34566 > --- /dev/null > +++ b/drivers/crypto/amlogic/amlogic-gxl-hasher.c [ ... ] > +static int meson_hasher_req_map(struct ahash_request *req) > +{ > + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); > + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); > + struct meson_dev *mc = tctx->mc; > + int ret; > + > + if (!req->nbytes) > + return 0; > + > + ret = dma_map_sg(mc->dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); > + if (!ret) { > + dev_err(mc->dev, "Cannot DMA MAP request data\n"); > + return -ENOMEM; > + } > + > + return 0; > +} > + > +static void meson_hasher_req_unmap(struct ahash_request *req) > +{ > + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); > + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); > + struct meson_dev *mc = tctx->mc; > + > + if (!req->nbytes) > + return; > + > + dma_unmap_sg(mc->dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); > +} [Severity: High] Should meson_hasher_req_map(), meson_hasher_req_unmap(), and meson_hasher_do_one_request() skip touching req->src when rctx->final_req is set? In the ahash API, .final() only finalizes the hash state into req->result, and callers such as ahash_def_finup_finish1() invoke .final(req) after .update(req) without zeroing req->nbytes. Although meson_hasher_do_one_request() sets ctx.nbytes = 0 when rctx->final_req is true, it still sets ctx.src_sg = req->src (dereferenced via sg_dma_len(ctx.src_sg)) and calls meson_hasher_req_map() and meson_hasher_req_unmap(), which check !req->nbytes and DMA-map req->src. If the caller freed or cleared req->src after .update() completed without zeroing req->nbytes, sg_nents(req->src) and sg_dma_len(ctx.src_sg) will dereference an invalid or NULL scatterlist pointer. [ ... ] > +static int meson_kick_hardware(struct hasher_ctx *ctx) > +{ > + struct ahash_request *req = ahash_request_cast(ctx->areq); > + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); > + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); > + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); > + struct meson_dev *mc = tctx->mc; > + struct meson_flow *flow = &mc->chanlist[rctx->flow]; > + int ret; > + > + reinit_completion(&flow->complete); > + meson_dma_start(mc, rctx->flow); > + > + ret = wait_for_completion_timeout(&flow->complete, > + msecs_to_jiffies(500)); > + if (ret == 0) { > + dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); > + return -EINVAL; > + } else if (ret < 0) { > + dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", ret); > + return ret; > + } > + > + if (rctx->partial_mapped) { > + dma_unmap_single(mc->dev, rctx->partial_addr, > + rctx->partial_size, > + DMA_TO_DEVICE); > + rctx->partial_size = 0; > + rctx->partial_mapped = false; > + } [Severity: Medium] Does returning early on wait_for_completion_timeout() failure here leak the rctx->partial_addr DMA mapping when rctx->partial_mapped is true? [ ... ] > + for (;;) { > + unsigned int len = ctx.src_sg ? > + min(sg_dma_len(ctx.src_sg) - ctx.src_offset, ctx.nbytes) : 0; > + > + ctx.src_addr = 0; > + ctx.todo = 0; > + > + if (!rctx->final_req && !ctx.nbytes) > + break; > + > + meson_setup_state_descs(&ctx); > + > + if (rctx->partial_size && rctx->partial_size < blocksize) { > + ret = meson_fill_partial_buffer(&ctx, len); > + if (ret) > + goto fail; > + } else if (len && len < blocksize) { > + memcpy(rctx->partial, sg_virt(ctx.src_sg) + ctx.src_offset, len); [Severity: Medium] Can indexing sg_virt(ctx.src_sg) by ctx.src_offset read out of bounds when dma_map_sg() merges scatterlist entries? len and the sg_next() advance condition use sg_dma_len(ctx.src_sg), which can exceed ctx.src_sg->length when dma_map_sg() coalesces adjacent segments. If a trailing partial block falls after the first scatterlist entry in a coalesced DMA segment, ctx.src_offset advances past ctx.src_sg->length and memcpy() in both meson_hasher_do_one_request() and meson_fill_partial_buffer() reads past the end of ctx.src_sg's virtual buffer instead of the next scatterlist entry. > + > + rctx->partial_size = len; > + ctx.nbytes -= len; > + ctx.src_offset += len; > + } else if (len) { > + ctx.src_addr = sg_dma_address(ctx.src_sg) + ctx.src_offset; > + ctx.todo = min(rounddown(DESC_MAXLEN, blocksize), > + rounddown(len, blocksize)); > + ctx.nbytes -= ctx.todo; > + ctx.src_offset += ctx.todo; > + } > + > + if (ctx.src_sg && ctx.src_offset == sg_dma_len(ctx.src_sg)) { > + ctx.src_offset = 0; > + ctx.src_sg = sg_next(ctx.src_sg); > + } > + > + if (!ctx.todo && ctx.nbytes) > + continue; > + > + if (!ctx.todo && !rctx->final_req && !ctx.tloffset) > + continue; > + > + if (meson_setup_data_descs(&ctx)) { > + ret = meson_kick_hardware(&ctx); > + if (ret) > + goto fail; > + } > + } [Severity: High] Does a non-final update that ends with a partial block (< blocksize bytes) program and kick a 0-length SHA DMA descriptor with t_src = 0? This happens in two ways. First, meson_setup_state_descs() runs at the top of the loop before checking whether a full block is ready; on any non-initial update (rctx->begin_req == false), it writes the state setup descriptors and sets ctx.tloffset to setup_desc_cnt. Second, when an update has full blocks followed by trailing sub-block bytes (e.g. 74 bytes), meson_setup_data_descs() only sets DESC_LAST when !ctx->nbytes, ctx->tloffset == MAXDESC, or rctx->partial_mapped, so the full-block descriptor leaves ctx.tloffset > 0 without kicking hardware. On the iteration that buffers the trailing sub-block bytes into rctx->partial, ctx.nbytes becomes 0 while ctx.todo is 0 and ctx.tloffset > 0, so both continue guards are bypassed and meson_setup_data_descs() emits a bogus 0-byte descriptor at physical address 0 and kicks the DMA engine. > + > +fail: > + meson_hasher_req_unmap(req); > + > +fail_map_req: > + dma_unmap_single(mc->dev, ctx.state_addr, sizeof(rctx->state), > + DMA_BIDIRECTIONAL); [Severity: Medium] Should the fail cleanup path also unmap rctx->partial_addr when rctx->partial_mapped is true? If meson_kick_hardware() fails after meson_fill_partial_buffer() mapped rctx->partial, this unwind path only unmaps req->src and ctx.state_addr, leaking the streaming DMA mapping for rctx->partial. > + > +fail_map_single: > + if (final_req && ret == 0) > + memcpy(req->result, rctx->state, digest_size); > + > + local_bh_disable(); > + crypto_finalize_hash_request(engine, req, ret); > + local_bh_enable(); > + > + return ret; > +} [Severity: High] Does returning a negative ret after crypto_finalize_hash_request() complete the request twice on error? crypto_finalize_hash_request() completes req, and when do_one_request() returns a negative error code to crypto_pump_requests(), crypto_engine calls crypto_request_complete(async_req, ret) a second time, causing a double completion and potential use-after-free if the caller freed the request on the first completion. meson_handle_cipher_request() returns 0 after finalizing the request. [ ... ] > +static int meson_hasher_init(struct crypto_tfm *tfm) > +{ > + struct meson_hasher_tfm_ctx *tctx = crypto_tfm_ctx_dma(tfm); > + struct crypto_ahash *atfm = __crypto_ahash_cast(tfm); > + struct hash_alg_common *alg = crypto_hash_alg_common(atfm); > + struct meson_alg_template *algt = container_of(alg, > + struct meson_alg_template, alg.ahash.base.halg); > + > + crypto_ahash_set_reqsize_dma(atfm, crypto_ahash_statesize(atfm)); [Severity: High] meson_hasher_init() reserves DMA alignment padding via crypto_ahash_set_reqsize_dma(), but every request callback in this file retrieves rctx with ahash_request_ctx(req) instead of ahash_request_ctx_dma(req), and struct meson_hasher_req_ctx uses ____cacheline_aligned (64 bytes on arm64) rather than ARCH_DMA_MINALIGN (128 bytes on arm64). Because ahash_request_ctx(req) is only aligned to CRYPTO_MINALIGN (8 bytes on arm64), rctx->state (mapped with DMA_BIDIRECTIONAL) and rctx->partial are not cacheline-aligned and share DMA cachelines with adjacent struct ahash_request and struct meson_hasher_req_ctx fields, which can corrupt those fields on DMA cache invalidation. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261126193241.1471372-1-jnieto.alaber@gmail.com?part=13 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v13 14/25] crypto: amlogic - Use fallback for 192-bit keys 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (12 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 13/25] crypto: amlogic - Introduce hasher Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:32 ` [PATCH v13 15/25] crypto: amlogic - Add support for G12-series Jose Nieto ` (11 subsequent siblings) 25 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Unforunately, not all Amlogic SoC's have a 192-bit key support for AES algo. In this case, use fallback. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 7 +++++++ drivers/crypto/amlogic/amlogic-gxl-core.c | 1 + drivers/crypto/amlogic/amlogic-gxl.h | 2 ++ 3 files changed, 10 insertions(+) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index df42940f1112..6070ee6b488e 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -41,6 +41,13 @@ static bool meson_cipher_need_fallback_sg(struct skcipher_request *areq, static bool meson_cipher_need_fallback(struct skcipher_request *areq) { + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); + struct meson_dev *mc = op->mc; + + if (op->keymode == DESC_MODE_AES_192 && !mc->pdata->support_192bit_key) + return true; + if (areq->cryptlen == 0) return true; diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 9676b86a5089..f530e238812e 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -279,6 +279,7 @@ static const struct meson_pdata meson_gxl_pdata = { .status_reg = 0x4, .setup_desc_cnt = 3, .hasher_supported = false, + .support_192bit_key = true, }; static const struct of_device_id meson_crypto_of_match_table[] = { diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index b092d0c89cd8..a44290fcf3a0 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -94,12 +94,14 @@ struct meson_flow { * @reg_status: offset to status register * @setup_desc_cnt: number of setup descriptor to configure. * @hasher_supported: indecates whether hasher is supported. + * @support_192bit_key: indicates whether platform support AES 192-bit key */ struct meson_pdata { u32 descs_reg; u32 status_reg; u32 setup_desc_cnt; bool hasher_supported; + bool support_192bit_key; }; /* -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v13 15/25] crypto: amlogic - Add support for G12-series 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (13 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 14/25] crypto: amlogic - Use fallback for 192-bit keys Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:55 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 16/25] crypto: amlogic - Add support for AXG-series Jose Nieto ` (10 subsequent siblings) 25 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Tested via tcrypt module and with custom tests. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index f530e238812e..0fb0da20e06b 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -282,11 +282,23 @@ static const struct meson_pdata meson_gxl_pdata = { .support_192bit_key = true, }; +static const struct meson_pdata meson_g12a_pdata = { + .descs_reg = 0x0, + .status_reg = 0x8, + .setup_desc_cnt = 1, + .hasher_supported = true, + .support_192bit_key = false, +}; + static const struct of_device_id meson_crypto_of_match_table[] = { { .compatible = "amlogic,gxl-crypto", .data = &meson_gxl_pdata, }, + { + .compatible = "amlogic,g12a-crypto", + .data = &meson_g12a_pdata, + }, {}, }; MODULE_DEVICE_TABLE(of, meson_crypto_of_match_table); -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v13 15/25] crypto: amlogic - Add support for G12-series 2026-11-26 19:32 ` [PATCH v13 15/25] crypto: amlogic - Add support for G12-series Jose Nieto @ 2026-11-26 19:55 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-26 19:55 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] crypto: amlogic: 0-byte SHA DMA desc and double complete in hasher request - [High] crypto: amlogic: OOB DMA length and shared keyiv race in meson_cipher() - [Medium] crypto: amlogic: debugfs leak and UAF on error_hasher in meson_crypto_probe() - [Medium] crypto: amlogic: unregister of failed alg in meson_register_algs() rollback - [Medium] crypto: amlogic: partial_addr DMA leak on meson_kick_hardware() timeout - [Medium] crypto: amlogic: engine/DMA leak and early IRQ in meson_allocate_chanlist() -- commit df12ec18bc93360a5cdf078f04efac1cfd6bdee7 Author: Alexey Romanov <romanov.alexey2000@gmail.com> crypto: amlogic - Add support for G12-series This commit adds platform data and the "amlogic,g12a-crypto" device tree compatible entry to support the Amlogic G12-series crypto engine, including hardware hasher support. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c > index f530e238812eb..0fb0da20e06b2 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-core.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c > @@ -282,11 +282,23 @@ static const struct meson_pdata meson_gxl_pdata = { > .support_192bit_key = true, > }; > > +static const struct meson_pdata meson_g12a_pdata = { > + .descs_reg = 0x0, > + .status_reg = 0x8, > + .setup_desc_cnt = 1, > + .hasher_supported = true, [Severity: High] Can enabling hasher_supported emit a bogus 0-length DMA descriptor from physical address 0 during non-block-aligned update() requests, and double complete failed hash requests? In meson_hasher_do_one_request(), meson_setup_state_descs() writes a state descriptor and increments ctx.tloffset before checking whether the remaining bytes are shorter than blocksize and only buffered into rctx->partial. The same state is reached when a single update() contains one or more full blocks followed by a sub-block tail, because the full block increments ctx.tloffset without setting DESC_LAST (as ctx->nbytes is still non-zero). Once the trailing bytes are copied into rctx->partial, ctx.nbytes and ctx.todo are both 0 while ctx.tloffset is non-zero, so execution falls through to meson_setup_data_descs() and meson_kick_hardware() with ctx.src_addr == 0 and ctx.todo == 0: drivers/crypto/amlogic/amlogic-gxl-hasher.c:meson_hasher_do_one_request() { ... meson_setup_state_descs(&ctx); if (rctx->partial_size && rctx->partial_size < blocksize) { ret = meson_fill_partial_buffer(&ctx, len); if (ret) goto fail; } else if (len && len < blocksize) { memcpy(rctx->partial, sg_virt(ctx.src_sg) + ctx.src_offset, len); rctx->partial_size = len; ctx.nbytes -= len; ctx.src_offset += len; } ... if (!ctx.todo && !rctx->final_req && !ctx.tloffset) continue; if (meson_setup_data_descs(&ctx)) { ret = meson_kick_hardware(&ctx); ... } Also in the hasher path: - on final() requests (rctx->final_req == true), meson_hasher_do_one_request() forces ctx.nbytes = 0, but meson_hasher_req_map() and meson_hasher_req_unmap() only check !req->nbytes instead of (!req->nbytes || rctx->final_req), and the loop reads sg_dma_len(ctx.src_sg) whenever req->src is non-NULL even when req->nbytes == 0 and req->src was never DMA-mapped. - at the end of meson_hasher_do_one_request(), returning a negative ret after calling crypto_finalize_hash_request(engine, req, ret) causes crypto_pump_requests() to call crypto_request_complete() a second time on the same request; do_one_request callbacks must return 0 after finalizing the request. [Severity: Medium] Does meson_crypto_probe() leak mc->dbgfs_dir and leave a dangling mc pointer in debugfs if meson_hasher_register() fails? With hasher_supported set to true, meson_hasher_register() registers the ahash algorithms and can now fail and jump to error_hasher. meson_crypto_probe() creates the "gxl-crypto" debugfs directory and "stats" file (with mc as seq->private) before calling meson_hasher_register(), but the error_hasher unwind path does not call debugfs_remove_recursive(mc->dbgfs_dir): drivers/crypto/amlogic/amlogic-gxl-core.c:meson_crypto_probe() { ... err = meson_hasher_register(mc); if (err) goto error_hasher; return 0; error_hasher: meson_cipher_unregister(mc); error_alg: meson_free_chanlist(mc, mc->flow_cnt - 1); return err; } When probe fails, devres frees mc while /sys/kernel/debug/gxl-crypto/stats remains registered, causing a use-after-free in meson_debugfs_show() if the file is read. [Severity: Medium] Does meson_kick_hardware() leak the rctx->partial_addr DMA mapping when wait_for_completion_timeout() times out? meson_fill_partial_buffer() maps rctx->partial via dma_map_single() and sets rctx->partial_mapped = true. If wait_for_completion_timeout() returns 0 in meson_kick_hardware(), it returns -EINVAL before reaching the dma_unmap_single() block for rctx->partial_addr, and the fail label in meson_hasher_do_one_request() only unmaps req->src and ctx.state_addr: drivers/crypto/amlogic/amlogic-gxl-hasher.c:meson_kick_hardware() { ... if (ret == 0) { dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); return -EINVAL; } ... if (rctx->partial_mapped) { dma_unmap_single(mc->dev, rctx->partial_addr, rctx->partial_size, DMA_TO_DEVICE); rctx->partial_mapped = false; } ... } > + .support_192bit_key = false, > +}; > + > static const struct of_device_id meson_crypto_of_match_table[] = { > { > .compatible = "amlogic,gxl-crypto", > .data = &meson_gxl_pdata, > }, > + { > + .compatible = "amlogic,g12a-crypto", > + .data = &meson_g12a_pdata, > + }, [Severity: High] Can concurrent CBC requests on the same transform corrupt each other's IV and DMA mapping through op->keyiv, and does meson_setup_keyiv_descs() read past the end of op->keyiv when setup_desc_cnt > 1? op->keyiv lives in struct meson_cipher_tfm_ctx (per-TFM) rather than struct meson_cipher_req_ctx (per-request), while meson_skencrypt() and meson_skdecrypt() dispatch requests across mc->flow_cnt crypto_engine threads via meson_get_engine_number(). Concurrent CBC requests sharing a TFM overwrite op->keyiv + AES_MAX_KEY_SIZE with their own areq->iv and race on dma_map_single(), dma_sync_single_for_device(), and dma_unmap_single() in meson_cipher() and meson_setup_keyiv_descs(). In addition, meson_setup_keyiv_descs() programs every descriptor in the setup_desc_cnt loop with the full ctx->keyiv.len instead of the 16-byte chunk length at offset = i * 16: drivers/crypto/amlogic/amlogic-gxl-cipher.c:meson_setup_keyiv_descs() { ... for (i = 0; i < mc->pdata->setup_desc_cnt; i++) { struct meson_desc *desc = &mc->chanlist[rctx->flow].tl[ctx->tloffset]; int offset = i * 16; desc->t_src = cpu_to_le32(ctx->keyiv.addr + offset); desc->t_dst = cpu_to_le32(offset); desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | ctx->keyiv.len); ctx->tloffset++; } } When setup_desc_cnt is 3 (GXL), descriptors i = 1 and i = 2 read up to offset 32 + 48 = 80 bytes in CBC mode, 32 bytes past the 48-byte op->keyiv buffer and outside its DMA mapping. [Severity: Medium] Does meson_register_algs() attempt to unregister the algorithm that just failed to register on its error path? meson_register_algs() sets algs[i].mc = mc before calling crypto_engine_register_skcipher() or crypto_engine_register_ahash(). If registration fails for entry i, it calls meson_unregister_algs() without clearing algs[i].mc first: drivers/crypto/amlogic/amlogic-gxl-core.c:meson_register_algs() { ... for (i = 0; i < count; i++) { algs[i].mc = mc; switch (algs[i].type) { case CRYPTO_ALG_TYPE_SKCIPHER: err = crypto_engine_register_skcipher(&algs[i].alg.skcipher); if (err) { dev_err(mc->dev, "Fail to register %s\n", algs[i].alg.skcipher.base.base.cra_name); meson_unregister_algs(mc, algs, count); return err; } break; ... } Because meson_unregister_algs() unregisters every entry with a non-NULL algs[i].mc (and also never resets algs[i].mc = NULL afterward), it calls crypto_engine_unregister_skcipher() or crypto_engine_unregister_ahash() on the entry that failed registration, triggering a WARN() in crypto_unregister_alg(). [Severity: Medium] Does meson_allocate_chanlist() leak already-started crypto_engine threads and coherent DMA buffers if requesting an IRQ fails on channel i > 0, and can an early IRQ fire before init_completion()? In meson_allocate_chanlist(), if platform_get_irq() or devm_request_irq() fails on iteration i > 0, the function returns directly instead of unwinding channels 0 .. i - 1 via meson_free_chanlist(), leaking their running crypto_engine kthreads and dma_alloc_coherent() descriptor rings. In the same loop, devm_request_irq() is called before init_completion(&mc->chanlist[i].complete), so an interrupt arriving right after registration calls complete() in meson_irq_handler() on an uninitialized completion: drivers/crypto/amlogic/amlogic-gxl-core.c:meson_allocate_chanlist() { ... for (i = 0; i < mc->flow_cnt; i++) { mc->chanlist[i].irq = platform_get_irq(pdev, i); if (mc->chanlist[i].irq < 0) return mc->chanlist[i].irq; err = devm_request_irq(mc->dev, mc->chanlist[i].irq, meson_irq_handler, 0, "aml-crypto", mc); if (err < 0) { dev_err(mc->dev, "Cannot request IRQ for flow %d\n", i); return err; } init_completion(&mc->chanlist[i].complete); ... } -- Sashiko AI review · https://sashiko.dev/#/patchset/20261126193241.1471372-1-jnieto.alaber@gmail.com?part=15 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v13 16/25] crypto: amlogic - Add support for AXG-series 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (14 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 15/25] crypto: amlogic - Add support for G12-series Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:32 ` [PATCH v13 17/25] crypto: amlogic - Add support for A1-series Jose Nieto ` (9 subsequent siblings) 25 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Tested via tcrypt module and with custom tests. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 0fb0da20e06b..08d89db14788 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -290,6 +290,14 @@ static const struct meson_pdata meson_g12a_pdata = { .support_192bit_key = false, }; +static const struct meson_pdata meson_axg_pdata = { + .descs_reg = 0x0, + .status_reg = 0x8, + .setup_desc_cnt = 3, + .hasher_supported = true, + .support_192bit_key = true, +}; + static const struct of_device_id meson_crypto_of_match_table[] = { { .compatible = "amlogic,gxl-crypto", @@ -299,6 +307,10 @@ static const struct of_device_id meson_crypto_of_match_table[] = { .compatible = "amlogic,g12a-crypto", .data = &meson_g12a_pdata, }, + { + .compatible = "amlogic,axg-crypto", + .data = &meson_axg_pdata, + }, {}, }; MODULE_DEVICE_TABLE(of, meson_crypto_of_match_table); -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v13 17/25] crypto: amlogic - Add support for A1-series 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (15 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 16/25] crypto: amlogic - Add support for AXG-series Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:48 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 18/25] crypto: amlogic: g12: drop CRYPTO_ALG_ALLOCATES_MEMORY Jose Nieto ` (8 subsequent siblings) 25 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> This platform data also can be used for S4 as fallback. Tested via tcrypt module and with custom tests. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-core.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 08d89db14788..3a6bac10bb04 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -298,6 +298,14 @@ static const struct meson_pdata meson_axg_pdata = { .support_192bit_key = true, }; +static const struct meson_pdata meson_a1_pdata = { + .descs_reg = 0x0, + .status_reg = 0x8, + .setup_desc_cnt = 1, + .hasher_supported = true, + .support_192bit_key = false, +}; + static const struct of_device_id meson_crypto_of_match_table[] = { { .compatible = "amlogic,gxl-crypto", @@ -311,6 +319,14 @@ static const struct of_device_id meson_crypto_of_match_table[] = { .compatible = "amlogic,axg-crypto", .data = &meson_axg_pdata, }, + { + .compatible = "amlogic,a1-crypto", + .data = &meson_a1_pdata, + }, + { + .compatible = "amlogic,s4-crypto", + .data = &meson_a1_pdata, + }, {}, }; MODULE_DEVICE_TABLE(of, meson_crypto_of_match_table); -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v13 17/25] crypto: amlogic - Add support for A1-series 2026-11-26 19:32 ` [PATCH v13 17/25] crypto: amlogic - Add support for A1-series Jose Nieto @ 2026-11-26 19:48 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-26 19:48 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] crypto: amlogic - duplicate meson_a1_pdata and redundant s4-crypto match entry -- commit ce27d011d2b65868bfb43baa82ecbdb3f1fd55db Author: Alexey Romanov <romanov.alexey2000@gmail.com> crypto: amlogic - Add support for A1-series This commit adds platform data and device tree match entries for the Amlogic A1 and S4 crypto hardware. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c > index 08d89db14788a..3a6bac10bb04b 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-core.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c > @@ -298,6 +298,14 @@ static const struct meson_pdata meson_axg_pdata = { > .support_192bit_key = true, > }; > > +static const struct meson_pdata meson_a1_pdata = { > + .descs_reg = 0x0, > + .status_reg = 0x8, > + .setup_desc_cnt = 1, > + .hasher_supported = true, > + .support_192bit_key = false, > +}; > + > static const struct of_device_id meson_crypto_of_match_table[] = { > { > .compatible = "amlogic,gxl-crypto", > @@ -311,6 +319,14 @@ static const struct of_device_id meson_crypto_of_match_table[] = { > .compatible = "amlogic,axg-crypto", > .data = &meson_axg_pdata, > }, > + { > + .compatible = "amlogic,a1-crypto", > + .data = &meson_a1_pdata, > + }, > + { > + .compatible = "amlogic,s4-crypto", > + .data = &meson_a1_pdata, > + }, > {}, > }; [Severity: Low] This isn't a bug, but meson_a1_pdata has the exact same field values as meson_g12a_pdata defined right above it: drivers/crypto/amlogic/amlogic-gxl-core.c: static const struct meson_pdata meson_g12a_pdata = { .descs_reg = 0x0, .status_reg = 0x8, .setup_desc_cnt = 1, .hasher_supported = true, .support_192bit_key = false, }; Also, since Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml requires "amlogic,s4-crypto" nodes to specify "amlogic,a1-crypto" as a fallback compatible and both entries use the same platform data, is the separate "amlogic,s4-crypto" entry in meson_crypto_of_match_table[] needed? -- Sashiko AI review · https://sashiko.dev/#/patchset/20261126193241.1471372-1-jnieto.alaber@gmail.com?part=17 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v13 18/25] crypto: amlogic: g12: drop CRYPTO_ALG_ALLOCATES_MEMORY 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (16 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 17/25] crypto: amlogic - Add support for A1-series Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:32 ` [PATCH v13 19/25] crypto: amlogic: hasher: add one-shot digest path Jose Nieto ` (7 subsequent siblings) 25 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Jose Nieto The driver queues requests to a crypto_engine kthread and does not allocate memory per request, so CRYPTO_ALG_ALLOCATES_MEMORY is stale. dm-crypt allocates its skcipher with a mask that excludes implementations carrying CRYPTO_ALG_ALLOCATES_MEMORY, which prevented the hardware cipher from being selected. Dropping the flag lets dm-crypt bind to the engine. Signed-off-by: Jose Nieto <jnieto.alaber@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index 6070ee6b488e..72892fdcd55d 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -498,7 +498,7 @@ static struct meson_alg_template algs[] = { .cra_priority = 400, .cra_blocksize = AES_BLOCK_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | - CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK, .cra_module = THIS_MODULE, .cra_alignmask = 0xf, @@ -526,7 +526,7 @@ static struct meson_alg_template algs[] = { .cra_priority = 400, .cra_blocksize = AES_BLOCK_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | - CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK, .cra_module = THIS_MODULE, .cra_alignmask = 0xf, -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v13 19/25] crypto: amlogic: hasher: add one-shot digest path 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (17 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 18/25] crypto: amlogic: g12: drop CRYPTO_ALG_ALLOCATES_MEMORY Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:50 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 20/25] crypto: amlogic: drop unused field and stale includes Jose Nieto ` (6 subsequent siblings) 25 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Jose Nieto Implement the ahash ->digest callback so one-shot SHA requests are sent as a single engine transfer instead of the init/update/final sequence, and skip the spurious trailing block for digest requests. Also unregister the hasher on device removal and lower the "hasher not supported" message to dev_dbg. Signed-off-by: Jose Nieto <jnieto.alaber@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-core.c | 1 + drivers/crypto/amlogic/amlogic-gxl-hasher.c | 29 +++++++++++++++++++-- drivers/crypto/amlogic/amlogic-gxl.h | 5 +++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 3a6bac10bb04..e79175368d8c 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -269,6 +269,7 @@ static void meson_crypto_remove(struct platform_device *pdev) debugfs_remove_recursive(mc->dbgfs_dir); #endif + meson_hasher_unregister(mc); meson_cipher_unregister(mc); meson_free_chanlist(mc, mc->flow_cnt - 1); diff --git a/drivers/crypto/amlogic/amlogic-gxl-hasher.c b/drivers/crypto/amlogic/amlogic-gxl-hasher.c index c83739ec3456..978cdcd8a4f9 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-hasher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-hasher.c @@ -51,6 +51,25 @@ static int meson_sha_final(struct ahash_request *req) return crypto_transfer_hash_request_to_engine(engine, req); } +static int meson_sha_digest(struct ahash_request *req) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct crypto_engine *engine; + + memset(rctx, 0, sizeof(struct meson_hasher_req_ctx)); + + rctx->flow = meson_get_engine_number(tctx->mc); + rctx->begin_req = true; + rctx->final_req = true; + rctx->digest_req = true; + + engine = tctx->mc->chanlist[rctx->flow].engine; + + return crypto_transfer_hash_request_to_engine(engine, req); +} + static int meson_hasher_req_map(struct ahash_request *req) { struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); @@ -251,7 +270,7 @@ static int meson_hasher_do_one_request(struct crypto_engine *engine, void *areq) struct hasher_ctx ctx = { .tloffset = 0, .src_offset = 0, - .nbytes = rctx->final_req ? 0 : req->nbytes, + .nbytes = (rctx->final_req && !rctx->digest_req) ? 0 : req->nbytes, .src_sg = req->src, .areq = areq, }; @@ -310,6 +329,9 @@ static int meson_hasher_do_one_request(struct crypto_engine *engine, void *areq) if (!ctx.todo && ctx.nbytes) continue; + if (!ctx.todo && rctx->final_req && rctx->partial_size) + continue; + if (!ctx.todo && !rctx->final_req && !ctx.tloffset) continue; @@ -393,6 +415,7 @@ static struct meson_alg_template mc_algs[] = { .init = meson_sha_init, .update = meson_sha_update, .final = meson_sha_final, + .digest = meson_sha_digest, .export = meson_hasher_export, .import = meson_hasher_import, }, @@ -421,6 +444,7 @@ static struct meson_alg_template mc_algs[] = { .init = meson_sha_init, .update = meson_sha_update, .final = meson_sha_final, + .digest = meson_sha_digest, .export = meson_hasher_export, .import = meson_hasher_import, }, @@ -449,6 +473,7 @@ static struct meson_alg_template mc_algs[] = { .init = meson_sha_init, .update = meson_sha_update, .final = meson_sha_final, + .digest = meson_sha_digest, .export = meson_hasher_export, .import = meson_hasher_import, }, @@ -463,7 +488,7 @@ int meson_hasher_register(struct meson_dev *mc) int i; if (!mc->pdata->hasher_supported) { - pr_info("amlogic-gxl-hasher: hasher not supported at current platform"); + dev_dbg(mc->dev, "hasher is not supported on this platform\n"); return 0; } diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index a44290fcf3a0..3f1ce6c05558 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -161,7 +161,9 @@ struct meson_cipher_tfm_ctx { * @partial_size: size of the partial buffer * @partial_addr: physical address of partial buffer * @partial_mapped: indicates is partial buffer currently mapped or not - * @flags: request flags (for example, is this final req or not) + * @begin_req: indicates this is the first request + * @final_req: indicates this is the final request + * @digest_req: indicates a one-shot digest request * @flow: the flow to use for this request */ struct meson_hasher_req_ctx { @@ -173,6 +175,7 @@ struct meson_hasher_req_ctx { bool begin_req; bool final_req; + bool digest_req; int flow; }; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v13 19/25] crypto: amlogic: hasher: add one-shot digest path 2026-11-26 19:32 ` [PATCH v13 19/25] crypto: amlogic: hasher: add one-shot digest path Jose Nieto @ 2026-11-26 19:50 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-26 19:50 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] crypto: amlogic: unmapped partial_addr DMA buffer on meson_kick_hardware() error - [Medium] crypto: amlogic: unremoved debugfs dir on hasher init failure in meson_crypto_probe() -- commit 8c0248c4b7c9ffb36b968750cdcd5dfcb7a2b1f1 Author: Jose Nieto <jnieto.alaber@gmail.com> crypto: amlogic: hasher: add one-shot digest path This commit implements the ahash ->digest callback for one-shot SHA requests and unregisters the hasher algorithms on device removal. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c > index 3a6bac10bb04b..e79175368d8ce 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-core.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c > @@ -269,6 +269,7 @@ static void meson_crypto_remove(struct platform_device *pdev) > debugfs_remove_recursive(mc->dbgfs_dir); > #endif > > + meson_hasher_unregister(mc); > meson_cipher_unregister(mc); > > meson_free_chanlist(mc, mc->flow_cnt - 1); [Severity: Medium] Does meson_crypto_probe() leak mc->dbgfs_dir when meson_hasher_register() fails? drivers/crypto/amlogic/amlogic-gxl-core.c:meson_crypto_probe() { ... if (IS_ENABLED(CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG)) { struct dentry *dbgfs_dir; dbgfs_dir = debugfs_create_dir("gxl-crypto", NULL); debugfs_create_file("stats", 0444, dbgfs_dir, mc, &meson_debugfs_fops); #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG mc->dbgfs_dir = dbgfs_dir; #endif } err = meson_hasher_register(mc); if (err) goto error_hasher; return 0; error_hasher: meson_cipher_unregister(mc); ... } Unlike meson_crypto_remove(), the error_hasher unwind path does not call debugfs_remove_recursive(mc->dbgfs_dir). When probe fails, devres frees mc and leaves the debugfs stats file with a dangling private pointer, causing a use-after-free in meson_debugfs_show() if the file is read. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-hasher.c b/drivers/crypto/amlogic/amlogic-gxl-hasher.c > index c83739ec34566..978cdcd8a4f91 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-hasher.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-hasher.c [ ... ] > @@ -310,6 +329,9 @@ static int meson_hasher_do_one_request(struct crypto_engine *engine, void *areq) > if (!ctx.todo && ctx.nbytes) > continue; > > + if (!ctx.todo && rctx->final_req && rctx->partial_size) > + continue; > + > if (!ctx.todo && !rctx->final_req && !ctx.tloffset) > continue; [Severity: Medium] Does meson_hasher_do_one_request() leak the rctx->partial_addr DMA mapping when meson_kick_hardware() fails? meson_fill_partial_buffer() maps rctx->partial with dma_map_single() and sets rctx->partial_mapped = true. If wait_for_completion_timeout() times out in meson_kick_hardware(), it returns before unmapping rctx->partial_addr, and the fail path in meson_hasher_do_one_request() only unmaps req->src and ctx.state_addr: drivers/crypto/amlogic/amlogic-gxl-hasher.c:meson_kick_hardware() { ... ret = wait_for_completion_timeout(&flow->complete, msecs_to_jiffies(500)); if (ret == 0) { dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); return -EINVAL; } else if (ret < 0) { dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", ret); return ret; } if (rctx->partial_mapped) { dma_unmap_single(mc->dev, rctx->partial_addr, rctx->partial_size, DMA_TO_DEVICE); ... } When a DMA timeout occurs while flushing a partial block, rctx->partial_addr remains mapped. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261126193241.1471372-1-jnieto.alaber@gmail.com?part=19 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v13 20/25] crypto: amlogic: drop unused field and stale includes 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (18 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 19/25] crypto: amlogic: hasher: add one-shot digest path Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:32 ` [PATCH v13 21/25] arm64: dts: amlogic: gxl: correct crypto node definition Jose Nieto ` (5 subsequent siblings) 25 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Jose Nieto Remove the unused meson_flow.keylen field, drop unused includes in the cipher and core files, and fix stale kernel-doc field names. Signed-off-by: Jose Nieto <jnieto.alaber@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 3 --- drivers/crypto/amlogic/amlogic-gxl-core.c | 2 -- drivers/crypto/amlogic/amlogic-gxl.h | 10 +++------- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index 72892fdcd55d..c11ccbaf920d 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -9,9 +9,6 @@ */ #include <linux/crypto.h> -#include <linux/delay.h> -#include <linux/io.h> -#include <crypto/scatterwalk.h> #include <linux/scatterlist.h> #include <linux/dma-mapping.h> #include <crypto/internal/skcipher.h> diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index e79175368d8c..90c817e412ad 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -19,9 +19,7 @@ #include <linux/of.h> #include <linux/of_device.h> #include <linux/platform_device.h> -#include <crypto/internal/skcipher.h> #include <crypto/internal/hash.h> -#include <linux/dma-mapping.h> #include "amlogic-gxl.h" diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index 3f1ce6c05558..9c3df0d162b9 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -69,18 +69,16 @@ struct meson_desc { /* * struct meson_flow - Information used by each flow * @engine: ptr to the crypto_engine for this flow - * @keylen: keylen for this flow operation * @complete: completion for the current task on this flow * @irq: IRQ number for amlogic-crypto * @t_phy: Physical address of task - * @tl: pointer to the current ce_task for this flow + * @tl: pointer to the current descriptor for this flow * @stat_req: number of request done by this flow */ struct meson_flow { struct crypto_engine *engine; struct completion complete; int irq; - unsigned int keylen; dma_addr_t t_phy; struct meson_desc *tl; #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG @@ -90,8 +88,8 @@ struct meson_flow { /* * struct meson_pdata - SoC series dependent data. - * @reg_descs: offset to descriptors register - * @reg_status: offset to status register + * @descs_reg: offset to descriptors register + * @status_reg: offset to status register * @setup_desc_cnt: number of setup descriptor to configure. * @hasher_supported: indecates whether hasher is supported. * @support_192bit_key: indicates whether platform support AES 192-bit key @@ -112,7 +110,6 @@ struct meson_pdata { * @flow: flow to use in next request * @flow_cnt: flow count for amlogic-crypto * @dbgfs_dir: Debugfs dentry for statistic directory - * @dbgfs_stats: Debugfs dentry for statistic counters */ struct meson_dev { void __iomem *base; @@ -181,7 +178,6 @@ struct meson_hasher_req_ctx { /* * struct meson_hasher_tfm_ctx - context for a hasher TFM - * @enginectx: crypto_engine used by this TFM * @mc: pointer to the private data of driver handling this TFM */ struct meson_hasher_tfm_ctx { -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v13 21/25] arm64: dts: amlogic: gxl: correct crypto node definition 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (19 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 20/25] crypto: amlogic: drop unused field and stale includes Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:32 ` [PATCH v13 22/25] arm64: dts: amlogic: a1: add crypto node Jose Nieto ` (4 subsequent siblings) 25 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> GXL and newer SoC's uses the DMA engine (not blkmv) for crypto HW. Crypto HW doesn't actually use the blkmv clk. At RTL level, crypto engine is hard weired to clk81 (CLKID_CLK81). And remove clock-names field: according to the new dt-binding, it is no longer required. Also, GXL crypto IP isn't to seconnd interrput line. So we must remove it from dt-bindings. Fixes: c4a0457eb858 ("ARM64: dts: amlogic: adds crypto hardware node") Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- arch/arm64/boot/dts/amlogic/meson-gxl.dtsi | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/arm64/boot/dts/amlogic/meson-gxl.dtsi b/arch/arm64/boot/dts/amlogic/meson-gxl.dtsi index f257fe3860f7..5d0bffda8f19 100644 --- a/arch/arm64/boot/dts/amlogic/meson-gxl.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-gxl.dtsi @@ -68,10 +68,8 @@ acodec: audio-controller@c8832000 { crypto: crypto@c883e000 { compatible = "amlogic,gxl-crypto"; reg = <0x0 0xc883e000 0x0 0x36>; - interrupts = <GIC_SPI 188 IRQ_TYPE_EDGE_RISING>, - <GIC_SPI 189 IRQ_TYPE_EDGE_RISING>; - clocks = <&clkc CLKID_BLKMV>; - clock-names = "blkmv"; + interrupts = <GIC_SPI 188 IRQ_TYPE_EDGE_RISING>; + clocks = <&clkc CLKID_CLK81>; status = "okay"; }; }; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v13 22/25] arm64: dts: amlogic: a1: add crypto node 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (20 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 21/25] arm64: dts: amlogic: gxl: correct crypto node definition Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 20:01 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 23/25] arm64: dts: amlogic: s4: " Jose Nieto ` (3 subsequent siblings) 25 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> This patch adds a crypto node declaration. With the Amlogic crypto driver we can use HW implementation of SHA1/224/256 and AES algo. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- arch/arm64/boot/dts/amlogic/meson-a1.dtsi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/arm64/boot/dts/amlogic/meson-a1.dtsi b/arch/arm64/boot/dts/amlogic/meson-a1.dtsi index 6f6a6145cba1..396260b7b398 100644 --- a/arch/arm64/boot/dts/amlogic/meson-a1.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-a1.dtsi @@ -686,6 +686,14 @@ sd_emmc: mmc@10000 { assigned-clocks = <&clkc_periphs CLKID_SD_EMMC>; assigned-clock-rates = <24000000>; }; + + crypto: crypto@6000 { + compatible = "amlogic,a1-crypto"; + reg = <0x0 0x6000 0x0 0x48>; + interrupts = <GIC_SPI 120 IRQ_TYPE_EDGE_RISING>; + clocks = <&clk81>; + power-domains = <&pwrc PWRC_DMA_ID>; + }; }; usb: usb@fe004400 { @@ -767,4 +775,10 @@ xtal: xtal-clk { clock-output-names = "xtal"; #clock-cells = <0>; }; + + clk81: clk81 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <64000000>; + }; }; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v13 22/25] arm64: dts: amlogic: a1: add crypto node 2026-11-26 19:32 ` [PATCH v13 22/25] arm64: dts: amlogic: a1: add crypto node Jose Nieto @ 2026-11-26 20:01 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-26 20:01 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] arm64: dts: amlogic: a1: fake clk81 fixed-clock used instead of clkc_periphs -- commit f6324854d1c8642eee51ed11c0843bb81bd2ce76 Author: Alexey Romanov <romanov.alexey2000@gmail.com> arm64: dts: amlogic: a1: add crypto node This commit adds a crypto controller node and a fixed-clock clk81 node to the Amlogic Meson A1 devicetree. > diff --git a/arch/arm64/boot/dts/amlogic/meson-a1.dtsi b/arch/arm64/boot/dts/amlogic/meson-a1.dtsi > index 6f6a6145cba12..396260b7b3989 100644 > --- a/arch/arm64/boot/dts/amlogic/meson-a1.dtsi > +++ b/arch/arm64/boot/dts/amlogic/meson-a1.dtsi > @@ -686,6 +686,14 @@ sd_emmc: mmc@10000 { > assigned-clocks = <&clkc_periphs CLKID_SD_EMMC>; > assigned-clock-rates = <24000000>; > }; > + > + crypto: crypto@6000 { > + compatible = "amlogic,a1-crypto"; > + reg = <0x0 0x6000 0x0 0x48>; > + interrupts = <GIC_SPI 120 IRQ_TYPE_EDGE_RISING>; > + clocks = <&clk81>; > + power-domains = <&pwrc PWRC_DMA_ID>; > + }; > }; > > usb: usb@fe004400 { > @@ -767,4 +775,10 @@ xtal: xtal-clk { > clock-output-names = "xtal"; > #clock-cells = <0>; > }; > + > + clk81: clk81 { > + compatible = "fixed-clock"; > + #clock-cells = <0>; > + clock-frequency = <64000000>; > + }; > }; [Severity: Medium] Should crypto@6000 take its clock from &clkc_periphs instead of defining a separate root fixed-clock node? meson-a1.dtsi already defines clkc_periphs ("amlogic,a1-peripherals-clkc"), which registers the A1 system and DMA clocks (CLKID_SYS and CLKID_DMA). Adding a synthetic 64 MHz clk81 fixed-clock node bypasses the SoC clock controller and uses a non-generic node name that does not match the ^clock-([0-9]+|[a-z0-9-]+)$ pattern required by fixed-clock.yaml. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261126193241.1471372-1-jnieto.alaber@gmail.com?part=22 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v13 23/25] arm64: dts: amlogic: s4: add crypto node 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (21 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 22/25] arm64: dts: amlogic: a1: add crypto node Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 20:02 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 24/25] arm64: dts: amlogic: g12: " Jose Nieto ` (2 subsequent siblings) 25 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> This patch adds a crypto node declaration for Amlogic S4-series. With the Amlogic crypto driver we can use HW implementation of SHA1/224/256 and AES algo. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- arch/arm64/boot/dts/amlogic/meson-s4.dtsi | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/arm64/boot/dts/amlogic/meson-s4.dtsi b/arch/arm64/boot/dts/amlogic/meson-s4.dtsi index 2a6fbd530836..de173f40e15e 100644 --- a/arch/arm64/boot/dts/amlogic/meson-s4.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-s4.dtsi @@ -71,6 +71,12 @@ xtal: xtal-clk { #clock-cells = <0>; }; + clk81: clk81 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <166000000>; + }; + firmware { sm: secure-monitor { compatible = "amlogic,meson-gxbb-sm"; @@ -621,6 +627,13 @@ mux { }; + crypto: crypto@440400 { + compatible = "amlogic,s4-crypto", "amlogic,a1-crypto"; + reg = <0x0 0x440400 0x0 0x48>; + interrupts = <GIC_SPI 24 IRQ_TYPE_EDGE_RISING>; + clocks = <&clk81>; + }; + gpio_intc: interrupt-controller@4080 { compatible = "amlogic,meson-s4-gpio-intc", "amlogic,meson-gpio-intc"; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v13 23/25] arm64: dts: amlogic: s4: add crypto node 2026-11-26 19:32 ` [PATCH v13 23/25] arm64: dts: amlogic: s4: " Jose Nieto @ 2026-11-26 20:02 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-26 20:02 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] crypto: amlogic: bogus 0-byte DMA descriptor in meson_hasher_do_one_request() - [High] crypto: amlogic: unaligned ahash_request_ctx() used for DMA in hasher - [Medium] arm64: dts: amlogic: s4: fake clk81 fixed-clock instead of clkc_periphs CLKID_SYS - [Medium] crypto: amlogic: double completion on error in meson_hasher_do_one_request() - [Medium] crypto: amlogic: partial_addr DMA mapping leak in meson_kick_hardware() - [Medium] crypto: amlogic: meson_hasher_req_map() maps req->src on final() requests -- commit a7e6ec30c6bf850169c1198e33c98a237aa31006 Author: Alexey Romanov <romanov.alexey2000@gmail.com> arm64: dts: amlogic: s4: add crypto node This commit adds a fixed-clock clk81 node and a crypto device node to the Amlogic S4 SoC devicetree. > diff --git a/arch/arm64/boot/dts/amlogic/meson-s4.dtsi b/arch/arm64/boot/dts/amlogic/meson-s4.dtsi > index 2a6fbd5308362..de173f40e15ed 100644 > --- a/arch/arm64/boot/dts/amlogic/meson-s4.dtsi > +++ b/arch/arm64/boot/dts/amlogic/meson-s4.dtsi > @@ -71,6 +71,12 @@ xtal: xtal-clk { > #clock-cells = <0>; > }; > > + clk81: clk81 { > + compatible = "fixed-clock"; > + #clock-cells = <0>; > + clock-frequency = <166000000>; > + }; [Severity: Medium] Should crypto@440400 use <&clkc_periphs CLKID_SYS> instead of adding a separate root clk81 fixed-clock node? meson-s4.dtsi already includes dt-bindings/clock/amlogic,s4-peripherals-clkc.h and defines clkc_periphs: clock-controller@0, whose driver (drivers/clk/meson/s4-peripherals.c) registers the S4 system bus clock (s4_sys_clk) at CLKID_SYS. Adding a root fixed-clock duplicates that internal SoC clock with a hardcoded 166 MHz rate instead of deriving it from the hardware mux and divider registers, and the node name clk81 does not follow the Devicetree generic node naming convention. > @@ -621,6 +627,13 @@ mux { > > }; > > + crypto: crypto@440400 { > + compatible = "amlogic,s4-crypto", "amlogic,a1-crypto"; > + reg = <0x0 0x440400 0x0 0x48>; > + interrupts = <GIC_SPI 24 IRQ_TYPE_EDGE_RISING>; > + clocks = <&clk81>; > + }; [Severity: High] In the Amlogic SHA hasher driver enabled by this node (introduced earlier in this series in commit "crypto: amlogic - Introduce hasher" and commit "crypto: amlogic: hasher: add one-shot digest path"), can meson_hasher_do_one_request() emit a bogus 0-byte DMA descriptor with t_src = 0 when an update() request ends with a partial block? drivers/crypto/amlogic/amlogic-gxl-hasher.c:meson_hasher_do_one_request() { ... meson_setup_state_descs(&ctx); if (rctx->partial_size && rctx->partial_size < blocksize) { ret = meson_fill_partial_buffer(&ctx, len); if (ret) goto fail; } else if (len && len < blocksize) { memcpy(rctx->partial, sg_virt(ctx.src_sg) + ctx.src_offset, len); rctx->partial_size = len; ctx.nbytes -= len; ctx.src_offset += len; ... if (!ctx.todo && ctx.nbytes) continue; if (!ctx.todo && rctx->final_req && rctx->partial_size) continue; if (!ctx.todo && !rctx->final_req && !ctx.tloffset) continue; if (meson_setup_data_descs(&ctx)) { ret = meson_kick_hardware(&ctx); ... } If an update() call passes 74 bytes, the first iteration queues a 64-byte descriptor in flow->tl[0] (setting ctx.tloffset = 1 and ctx.nbytes = 10), and the second iteration copies the remaining 10 bytes into rctx->partial, leaving ctx.nbytes = 0, ctx.todo = 0, and ctx.src_addr = 0. The same state occurs on an update() smaller than 64 bytes after an earlier update() already ran, because meson_setup_state_descs() advances ctx.tloffset before the sub-block data is copied into rctx->partial. Because ctx.todo is 0, ctx.nbytes is 0, rctx->final_req is false, and ctx.tloffset is non-zero, none of the three continue checks match. meson_setup_data_descs() then appends a 0-byte SHA descriptor with t_src = 0 and DESC_LAST set, and meson_kick_hardware() starts DMA from physical address 0, corrupting the hash state or timing out. [Severity: Medium] Does meson_hasher_do_one_request() complete req twice when an error occurs? drivers/crypto/amlogic/amlogic-gxl-hasher.c:meson_hasher_do_one_request() { ... local_bh_disable(); crypto_finalize_hash_request(engine, req, ret); local_bh_enable(); return ret; } When ret is negative (such as on a DMA mapping failure or a DMA timeout in meson_kick_hardware()), crypto_finalize_hash_request() calls crypto_request_complete(&req->base, ret). Returning that negative ret to crypto_pump_requests() tells crypto_engine that do_one_request() failed without finalizing, so crypto_pump_requests() calls crypto_request_complete() on the same request a second time and can trigger a use-after-free. meson_handle_cipher_request() in amlogic-gxl-cipher.c returns 0 after finalizing the request. [Severity: Medium] Does meson_kick_hardware() leak the rctx->partial_addr DMA mapping when wait_for_completion_timeout() times out? drivers/crypto/amlogic/amlogic-gxl-hasher.c:meson_kick_hardware() { ... ret = wait_for_completion_timeout(&flow->complete, msecs_to_jiffies(500)); if (ret == 0) { dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); return -EINVAL; } else if (ret < 0) { dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", ret); return ret; } if (rctx->partial_mapped) { dma_unmap_single(mc->dev, rctx->partial_addr, rctx->partial_size, DMA_TO_DEVICE); ... } When meson_fill_partial_buffer() maps rctx->partial and sets rctx->partial_mapped = true, an early return on timeout skips the dma_unmap_single() block above, and the fail unwind path in meson_hasher_do_one_request() only unmaps req->src and ctx.state_addr. [Severity: High] Can using ahash_request_ctx(req) instead of ahash_request_ctx_dma(req) in amlogic-gxl-hasher.c cause DMA cacheline corruption on non-coherent arm64 platforms? drivers/crypto/amlogic/amlogic-gxl-hasher.c:meson_hasher_init() { ... crypto_ahash_set_reqsize_dma(atfm, crypto_ahash_statesize(atfm)); ... } meson_hasher_init() calls crypto_ahash_set_reqsize_dma(), which reserves padding for ahash_request_ctx_dma(req), but meson_hasher_do_one_request() and the other callbacks in amlogic-gxl-hasher.c retrieve rctx with ahash_request_ctx(req). ahash_request_ctx(req) is only aligned to crypto_tfm_ctx_alignment() (8 bytes) at offset 64 of struct ahash_request, not ARCH_DMA_MINALIGN (128 bytes on arm64), so rctx->state (mapped DMA_BIDIRECTIONAL) shares a 128-byte cacheline with struct ahash_request. [Severity: Medium] Can meson_hasher_req_map() and meson_hasher_req_unmap() access an unused or dangling req->src scatterlist during crypto_ahash_final()? drivers/crypto/amlogic/amlogic-gxl-hasher.c:meson_hasher_req_map() { ... if (!req->nbytes) return 0; ret = dma_map_sg(mc->dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); ... } meson_hasher_do_one_request() sets ctx.nbytes to 0 when rctx->final_req && !rctx->digest_req, because crypto_ahash_final() only writes the digest to req->result and ignores req->src and req->nbytes. However, meson_hasher_req_map() and meson_hasher_req_unmap() test req->nbytes directly instead of ctx.nbytes, so a final() call where req->nbytes was left non-zero from an earlier update() (including crypto_ahash_finup() via ahash_def_finup()) will DMA-map req->src again, or dereference a NULL or freed req->src in sg_nents(req->src). -- Sashiko AI review · https://sashiko.dev/#/patchset/20261126193241.1471372-1-jnieto.alaber@gmail.com?part=23 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v13 24/25] arm64: dts: amlogic: g12: add crypto node 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (22 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 23/25] arm64: dts: amlogic: s4: " Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 19:32 ` [PATCH v13 25/25] arm64: dts: amlogic: axg: " Jose Nieto 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto 25 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> This patch adds a crypto node declaration for Amlogic G12-series. With the Amlogic crypto driver we can use HW implementation of SHA1/224/256 and AES algo. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi b/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi index 3135566df880..df1383f86366 100644 --- a/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi @@ -1742,6 +1742,13 @@ internal_ephy: ethernet-phy@8 { }; }; }; + + crypto: crypto@3e000 { + compatible = "amlogic,g12a-crypto"; + reg = <0x0 0x3e000 0x0 0x48>; + interrupts = <GIC_SPI 180 IRQ_TYPE_EDGE_RISING>; + clocks = <&clkc CLKID_CLK81>; + }; }; aobus: bus@ff800000 { -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v13 25/25] arm64: dts: amlogic: axg: add crypto node 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (23 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 24/25] arm64: dts: amlogic: g12: " Jose Nieto @ 2026-11-26 19:32 ` Jose Nieto 2026-11-26 20:00 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto 25 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-26 19:32 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> This patch adds a crypto node declaration. With the Amlogic crypto driver we can use HW implementation of SHA1/224/256 and AES algo. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- arch/arm64/boot/dts/amlogic/meson-axg.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm64/boot/dts/amlogic/meson-axg.dtsi b/arch/arm64/boot/dts/amlogic/meson-axg.dtsi index 5b8ef98f6d03..e755a019b384 100644 --- a/arch/arm64/boot/dts/amlogic/meson-axg.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-axg.dtsi @@ -321,6 +321,13 @@ ethmac: ethernet@ff3f0000 { status = "disabled"; }; + crypto: crypto@ff63e000 { + compatible = "amlogic,axg-crypto"; + reg = <0x0 0xff63e000 0x0 0x48>; + interrupts = <GIC_SPI 180 IRQ_TYPE_EDGE_RISING>; + clocks = <&clkc CLKID_CLK81>; + }; + pcie_phy: phy@ff644000 { compatible = "amlogic,axg-pcie-phy"; reg = <0x0 0xff644000 0x0 0x1c>; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v13 25/25] arm64: dts: amlogic: axg: add crypto node 2026-11-26 19:32 ` [PATCH v13 25/25] arm64: dts: amlogic: axg: " Jose Nieto @ 2026-11-26 20:00 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-26 20:00 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 9 potential issues to consider: - [High] crypto: amlogic: spurious 0-byte DMA desc in meson_hasher_do_one_request() - [High] crypto: amlogic: double completion in meson_hasher_do_one_request() - [High] crypto: amlogic: unaligned DMA context via ahash_request_ctx() in hasher - [High] crypto: amlogic: out-of-bounds DMA setup descriptors and shared op->keyiv - [Medium] crypto: amlogic: leaked partial_addr DMA mapping on meson_kick_hardware() error - [Medium] crypto: amlogic: meson_register_algs() unregisters failed alg on error - [Medium] crypto: amlogic: debugfs leak and UAF on error_hasher in meson_crypto_probe() - [Medium] crypto: amlogic: channel leak and uninit completion in meson_allocate_chanlist() - [Medium] arm64: dts: amlogic: fake root clk81 fixed-clock node in meson-a1 and meson-s4 -- commit abed3b0054164bf8d148380dd2a8f605cf5fb64f Author: Alexey Romanov <romanov.alexey2000@gmail.com> arm64: dts: amlogic: axg: add crypto node This series reworks the Amlogic GXL crypto driver to support hardware SHA hashing and the G12A, AXG, A1, and S4 SoC families, and adds the corresponding Devicetree crypto nodes. > diff --git a/arch/arm64/boot/dts/amlogic/meson-a1.dtsi b/arch/arm64/boot/dts/amlogic/meson-a1.dtsi > index 6f6a6145cba12..396260b7b3989 100644 > --- a/arch/arm64/boot/dts/amlogic/meson-a1.dtsi > +++ b/arch/arm64/boot/dts/amlogic/meson-a1.dtsi > @@ -686,6 +686,14 @@ sd_emmc: mmc@10000 { > assigned-clocks = <&clkc_periphs CLKID_SD_EMMC>; > assigned-clock-rates = <24000000>; > }; > + > + crypto: crypto@6000 { > + compatible = "amlogic,a1-crypto"; > + reg = <0x0 0x6000 0x0 0x48>; > + interrupts = <GIC_SPI 120 IRQ_TYPE_EDGE_RISING>; > + clocks = <&clk81>; > + power-domains = <&pwrc PWRC_DMA_ID>; > + }; > }; > > usb: usb@fe004400 { > @@ -767,4 +775,10 @@ xtal: xtal-clk { > clock-output-names = "xtal"; > #clock-cells = <0>; > }; > + > + clk81: clk81 { > + compatible = "fixed-clock"; > + #clock-cells = <0>; > + clock-frequency = <64000000>; > + }; > }; [Severity: Medium] Should the crypto nodes in meson-a1.dtsi and meson-s4.dtsi use the system clock from the peripheral clock controller (<&clkc_periphs CLKID_SYS>) instead of adding a fake root clk81 fixed-clock node? Both A1 and S4 already expose their system bus clock through clkc_periphs, and the root node name clk81 is also not a generic Devicetree node name. [ ... ] > diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c > index d78815b0547d8..c11ccbaf920dd 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c [ ... ] > +static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) > +{ > + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); > + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); > + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); > + struct meson_alg_template *algt = container_of(alg, > + struct meson_alg_template, alg.skcipher.base); > + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); > + struct meson_dev *mc = op->mc; > + unsigned int ivsize = crypto_skcipher_ivsize(tfm); > + unsigned int blockmode = algt->blockmode; > + int i; > + > + if (ctx->tloffset) > + return; > + > + if (blockmode == DESC_OPMODE_CBC) { > + memcpy(op->keyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); > + dma_sync_single_for_device(mc->dev, ctx->keyiv.addr, > + ctx->keyiv.len, DMA_TO_DEVICE); > + } > + > + for (i = 0; i < mc->pdata->setup_desc_cnt; i++) { > + struct meson_desc *desc = > + &mc->chanlist[rctx->flow].tl[ctx->tloffset]; > + int offset = i * 16; > + > + desc->t_src = cpu_to_le32(ctx->keyiv.addr + offset); > + desc->t_dst = cpu_to_le32(offset); > + desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | ctx->keyiv.len); > + > + ctx->tloffset++; > + } > +} [Severity: High] Does meson_setup_keyiv_descs() program out-of-bounds DMA transfers on GXL and AXG, where setup_desc_cnt is 3? Previously, each key/IV setup descriptor transferred 16 bytes and the loop stopped once keyivlen bytes were consumed. Here, all three descriptors at offsets 0, 16, and 32 are given the full ctx->keyiv.len (16, 32, or 48 bytes), so descriptors 1 and 2 instruct the DMA engine to read past the end of the dma_map_single() mapping and past op->keyiv. The same issue exists in meson_setup_state_descs() in amlogic-gxl-hasher.c on AXG, where each of the 3 descriptors specifies MESON_SHA_BUFFER_SIZE (48) at offsets 0, 16, and 32 from ctx->state_addr. Also, in CBC mode, writing the per-request IV into the per-TFM op->keyiv buffer while ctx->keyiv.addr is mapped to the device without calling dma_sync_single_for_cpu() first violates the DMA API, and concurrent requests sharing a TFM across multiple flows can overwrite each other's IV in op->keyiv. In addition, meson_cipher_exit() no longer wipes the key material in op->keyiv on exit. [ ... ] > diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c > index 48dbdf4520348..90c817e412ad4 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-core.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c [ ... ] > static int meson_allocate_chanlist(struct meson_dev *mc) > { > + struct platform_device *pdev = to_platform_device(mc->dev); > int i, err; > > - mc->chanlist = devm_kzalloc_objs(mc->dev, struct meson_flow, MAXFLOW); > + mc->flow_cnt = platform_irq_count(pdev); > + if (mc->flow_cnt <= 0) { > + dev_err(mc->dev, "No IRQs defined\n"); > + return -ENODEV; > + } > + > + mc->chanlist = devm_kzalloc_objs(mc->dev, struct meson_flow, mc->flow_cnt); > if (!mc->chanlist) > return -ENOMEM; > > - for (i = 0; i < MAXFLOW; i++) { > + for (i = 0; i < mc->flow_cnt; i++) { > + mc->chanlist[i].irq = platform_get_irq(pdev, i); > + if (mc->chanlist[i].irq < 0) > + return mc->chanlist[i].irq; > + > + err = devm_request_irq(mc->dev, mc->chanlist[i].irq, > + meson_irq_handler, 0, "aml-crypto", mc); > + if (err < 0) { > + dev_err(mc->dev, "Cannot request IRQ for flow %d\n", i); > + return err; > + } > + > init_completion(&mc->chanlist[i].complete); [Severity: Medium] If platform_get_irq() or devm_request_irq() fails when i > 0, does this return leak the crypto_engine instances and coherent DMA buffers allocated for earlier channels 0 .. i - 1? In addition, devm_request_irq() registers meson_irq_handler() before init_completion(&mc->chanlist[i].complete) is called, so an early interrupt could call complete() on an uninitialized completion. [ ... ] > -static int meson_register_algs(struct meson_dev *mc) > +int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *algs, > + unsigned int count) > { > int err, i; > > - for (i = 0; i < ARRAY_SIZE(mc_algs); i++) { > - mc_algs[i].mc = mc; > - switch (mc_algs[i].type) { > + for (i = 0; i < count; i++) { > + algs[i].mc = mc; > + switch (algs[i].type) { > case CRYPTO_ALG_TYPE_SKCIPHER: > - err = crypto_engine_register_skcipher(&mc_algs[i].alg.skcipher); > + err = crypto_engine_register_skcipher(&algs[i].alg.skcipher); > if (err) { > dev_err(mc->dev, "Fail to register %s\n", > - mc_algs[i].alg.skcipher.base.base.cra_name); > - mc_algs[i].mc = NULL; > + algs[i].alg.skcipher.base.base.cra_name); > + meson_unregister_algs(mc, algs, count); > + return err; > + } > + break; > + case CRYPTO_ALG_TYPE_AHASH: > + err = crypto_engine_register_ahash(&algs[i].alg.ahash); > + if (err) { > + dev_err(mc->dev, "Fail to register %s\n", > + algs[i].alg.ahash.base.halg.base.cra_name); > + meson_unregister_algs(mc, algs, count); > return err; > } > break; > } > } > > return 0; > } > > -static void meson_unregister_algs(struct meson_dev *mc) > +void meson_unregister_algs(struct meson_dev *mc, struct meson_alg_template *algs, > + unsigned int count) > { > int i; > > - for (i = 0; i < ARRAY_SIZE(mc_algs); i++) { > - if (!mc_algs[i].mc) > + for (i = 0; i < count; i++) { > + if (!algs[i].mc) > continue; > - switch (mc_algs[i].type) { > + switch (algs[i].type) { > case CRYPTO_ALG_TYPE_SKCIPHER: > - crypto_engine_unregister_skcipher(&mc_algs[i].alg.skcipher); > + crypto_engine_unregister_skcipher(&algs[i].alg.skcipher); > + break; > + case CRYPTO_ALG_TYPE_AHASH: > + crypto_engine_unregister_ahash(&algs[i].alg.ahash); > break; > } > } > } [Severity: Medium] When crypto_engine_register_skcipher() or crypto_engine_register_ahash() fails, algs[i].mc has already been set to mc and is not cleared before calling meson_unregister_algs(). Won't meson_unregister_algs() then try to unregister the algorithm that just failed registration? meson_unregister_algs() also never clears algs[i].mc = NULL after unregistering, leaving stale mc pointers in the static algs arrays across probe failure or device removal. [ ... ] > @@ -243,50 +227,35 @@ static int meson_crypto_probe(struct platform_device *pdev) > if (IS_ERR(mc->base)) > return PTR_ERR(mc->base); > > - mc->busclk = devm_clk_get_enabled(&pdev->dev, "blkmv"); > - if (IS_ERR(mc->busclk)) { > - err = PTR_ERR(mc->busclk); > - dev_err(&pdev->dev, "Cannot get/enable core clock err=%d\n", err); > - return err; > - } > - > err = meson_allocate_chanlist(mc); > if (err) > return err; > > - for (i = 0; i < MAXFLOW; i++) { > - mc->irqs[i] = platform_get_irq(pdev, i); > - if (mc->irqs[i] < 0) { > - err = mc->irqs[i]; > - goto error_chanlist; > - } > - > - err = devm_request_irq(&pdev->dev, mc->irqs[i], meson_irq_handler, 0, > - "gxl-crypto", mc); > - if (err < 0) > - goto error_chanlist; > - } > - > - err = meson_register_algs(mc); > + err = meson_cipher_register(mc); > if (err) > - goto error_alg; > + goto error_flow; > > if (IS_ENABLED(CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG)) { > struct dentry *dbgfs_dir; > > dbgfs_dir = debugfs_create_dir("gxl-crypto", NULL); > debugfs_create_file("stats", 0444, dbgfs_dir, mc, &meson_debugfs_fops); > - > #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG > mc->dbgfs_dir = dbgfs_dir; > #endif > } > > + err = meson_hasher_register(mc); > + if (err) > + goto error_hasher; > + > return 0; > -error_alg: > - meson_unregister_algs(mc); > -error_chanlist: > - meson_free_chanlist(mc, MAXFLOW - 1); > + > +error_hasher: > + meson_cipher_unregister(mc); > + > +error_flow: > + meson_free_chanlist(mc, mc->flow_cnt - 1); > return err; > } [Severity: Medium] If meson_hasher_register() fails when CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG is enabled, does the error_hasher path leak mc->dbgfs_dir? Reading the leftover debugfs stats file afterwards would then dereference the freed struct meson_dev *mc. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-hasher.c b/drivers/crypto/amlogic/amlogic-gxl-hasher.c > new file mode 100644 > index 0000000000000..978cdcd8a4f91 > --- /dev/null > +++ b/drivers/crypto/amlogic/amlogic-gxl-hasher.c [ ... ] > +static int meson_kick_hardware(struct hasher_ctx *ctx) > +{ > + struct ahash_request *req = ahash_request_cast(ctx->areq); > + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); > + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); > + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); > + struct meson_dev *mc = tctx->mc; > + struct meson_flow *flow = &mc->chanlist[rctx->flow]; > + int ret; > + > + reinit_completion(&flow->complete); > + meson_dma_start(mc, rctx->flow); > + > + ret = wait_for_completion_timeout(&flow->complete, > + msecs_to_jiffies(500)); > + if (ret == 0) { > + dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); > + return -EINVAL; > + } else if (ret < 0) { > + dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", ret); > + return ret; > + } > + > + if (rctx->partial_mapped) { > + dma_unmap_single(mc->dev, rctx->partial_addr, > + rctx->partial_size, > + DMA_TO_DEVICE); > + rctx->partial_size = 0; > + rctx->partial_mapped = false; > + } [Severity: Medium] If wait_for_completion_timeout() times out while rctx->partial_mapped is true, does this leak the rctx->partial_addr DMA mapping? meson_kick_hardware() returns before reaching the dma_unmap_single() block, and the fail label in meson_hasher_do_one_request() only unmaps req->src and ctx.state_addr. [ ... ] > +static int meson_hasher_do_one_request(struct crypto_engine *engine, void *areq) > +{ > + struct ahash_request *req = ahash_request_cast(areq); > + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); > + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); > + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); [Severity: High] Should meson_hasher_do_one_request() and the other hasher helpers retrieve rctx with ahash_request_ctx_dma(req) instead of ahash_request_ctx(req)? meson_hasher_init() reserves DMA alignment padding via crypto_ahash_set_reqsize_dma(), but ahash_request_ctx(req) returns the unaligned req->__ctx pointer. As a result, the DMA-mapped buffers rctx->state (DMA_BIDIRECTIONAL) and rctx->partial (DMA_TO_DEVICE) are not aligned to ARCH_DMA_MINALIGN and can share cachelines with struct ahash_request fields, risking cacheline corruption during non-coherent DMA maintenance. > + struct meson_dev *mc = tctx->mc; > + struct hasher_ctx ctx = { > + .tloffset = 0, > + .src_offset = 0, > + .nbytes = (rctx->final_req && !rctx->digest_req) ? 0 : req->nbytes, > + .src_sg = req->src, > + .areq = areq, > + }; > + unsigned int blocksize = crypto_ahash_blocksize(tfm); > + unsigned int digest_size = crypto_ahash_digestsize(tfm); > + bool final_req = rctx->final_req; > + int ret; > + > + ctx.state_addr = dma_map_single(mc->dev, rctx->state, > + sizeof(rctx->state), DMA_BIDIRECTIONAL); > + ret = dma_mapping_error(mc->dev, ctx.state_addr); > + if (ret) { > + dev_err(mc->dev, "Cannot DMA MAP SHA state buffer"); > + goto fail_map_single; > + } > + > + ret = meson_hasher_req_map(req); > + if (ret) > + goto fail_map_req; > + > + for (;;) { > + unsigned int len = ctx.src_sg ? > + min(sg_dma_len(ctx.src_sg) - ctx.src_offset, ctx.nbytes) : 0; > + > + ctx.src_addr = 0; > + ctx.todo = 0; > + > + if (!rctx->final_req && !ctx.nbytes) > + break; > + > + meson_setup_state_descs(&ctx); > + > + if (rctx->partial_size && rctx->partial_size < blocksize) { > + ret = meson_fill_partial_buffer(&ctx, len); > + if (ret) > + goto fail; > + } else if (len && len < blocksize) { > + memcpy(rctx->partial, sg_virt(ctx.src_sg) + ctx.src_offset, len); > + > + rctx->partial_size = len; > + ctx.nbytes -= len; > + ctx.src_offset += len; > + } else if (len) { > + ctx.src_addr = sg_dma_address(ctx.src_sg) + ctx.src_offset; > + ctx.todo = min(rounddown(DESC_MAXLEN, blocksize), > + rounddown(len, blocksize)); > + ctx.nbytes -= ctx.todo; > + ctx.src_offset += ctx.todo; > + } > + > + if (ctx.src_sg && ctx.src_offset == sg_dma_len(ctx.src_sg)) { > + ctx.src_offset = 0; > + ctx.src_sg = sg_next(ctx.src_sg); > + } > + > + if (!ctx.todo && ctx.nbytes) > + continue; > + > + if (!ctx.todo && rctx->final_req && rctx->partial_size) > + continue; > + > + if (!ctx.todo && !rctx->final_req && !ctx.tloffset) > + continue; > + > + if (meson_setup_data_descs(&ctx)) { > + ret = meson_kick_hardware(&ctx); > + if (ret) > + goto fail; > + } > + } [Severity: High] Can non-final update requests emit a spurious 0-byte DMA descriptor with t_src = 0 when trailing bytes are buffered in rctx->partial? For example, on a non-final meson_sha_update() of 100 bytes (64 + 36), the first iteration queues the 64-byte block into descriptor 0 (incrementing ctx.tloffset to 1) without DESC_LAST because ctx.nbytes is 36. On the second iteration, the remaining 36 bytes are copied into rctx->partial and ctx.nbytes becomes 0 while ctx.todo and ctx.src_addr stay 0. Because ctx.tloffset is non-zero, none of the three continue conditions match, so meson_setup_data_descs() appends a 0-length descriptor reading from address 0 and kicks the hardware, corrupting the hash state. The same happens on a subsequent update with len < blocksize after rctx->begin_req has been cleared, because meson_setup_state_descs() increments ctx.tloffset before the partial-buffer check. > + > +fail: > + meson_hasher_req_unmap(req); > + > +fail_map_req: > + dma_unmap_single(mc->dev, ctx.state_addr, sizeof(rctx->state), > + DMA_BIDIRECTIONAL); > + > +fail_map_single: > + if (final_req && ret == 0) > + memcpy(req->result, rctx->state, digest_size); > + > + local_bh_disable(); > + crypto_finalize_hash_request(engine, req, ret); > + local_bh_enable(); > + > + return ret; > +} [Severity: High] Does returning a negative ret after calling crypto_finalize_hash_request() complete the request twice? crypto_finalize_hash_request() already completes req with ret. When do_one_request() returns a negative error to crypto_pump_requests() and engine->retry_support is false, crypto_pump_requests() calls crypto_request_complete(async_req, ret) a second time, which can trigger a double completion or use-after-free if the completion callback freed the request. Should this return 0 like meson_handle_cipher_request() does? -- Sashiko AI review · https://sashiko.dev/#/patchset/20261126193241.1471372-1-jnieto.alaber@gmail.com?part=25 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (24 preceding siblings ...) 2026-11-26 19:32 ` [PATCH v13 25/25] arm64: dts: amlogic: axg: " Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 01/30] dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines Jose Nieto ` (29 more replies) 25 siblings, 30 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Jose Nieto This is v14 of the Amlogic crypto driver series originally posted by Alexey Romanov. It rebases the series onto linux-next (next-20261123) and adds, on top of the original patches, the fixes required for the current tree and a few corrections raised during review. The original 22 patches by Alexey Romanov are kept untouched (authorship and Signed-off-by preserved). On top of them: - the fixes that landed in the driver since v12 are preserved (IRQ handler return value and fallthrough, devm clock management, DMA SG unmap on the cipher error path, probe cleanup, devm_kmalloc_obj conversion); - three patches add what is needed for the current code (drop CRYPTO_ALG_ALLOCATES_MEMORY so dm-crypt can select the hardware engine, the ahash ->digest one-shot path, and a small cleanup); - five patches fix issues found in review: probe/registration error paths, key/IV and SHA setup descriptor lengths (plus a duplicated CBC IV copy), the redundant A1 platform data, the A1/S4 crypto clock, and the binding property order. Testing on Khadas VIM3 (A311D / G12B), booted with a linux-next kernel built from this series: - the crypto self-tests (known-answer tests) pass for ecb/cbc(aes) and sha1/224/256; - dm-crypt with aes-cbc-plain runs on top of cbc-aes-gxl and the driver's request counter accounts for the I/O. Thanks, Jose Alexey Romanov (22): dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines dt-bindings: crypto: amlogic,gxl-crypto: support new SoC's crypto: amlogic - Don't hardcode IRQ count crypto: amlogic - Add platform data crypto: amlogic - Remove clock input crypto: amlogic - Add MMIO helpers crypto: amlogic - Move get_engine_number() crypto: amlogic - Drop status field from meson_flow crypto: amlogic - Move algs definition and cipher API to cipher.c crypto: amlogic - Cleanup defines crypto: amlogic - Process more than MAXDESCS descriptors crypto: amlogic - Avoid kzalloc in engine thread crypto: amlogic - Introduce hasher crypto: amlogic - Use fallback for 192-bit keys crypto: amlogic - Add support for G12-series crypto: amlogic - Add support for AXG-series crypto: amlogic - Add support for A1-series arm64: dts: amlogic: gxl: correct crypto node definition arm64: dts: amlogic: a1: add crypto node arm64: dts: amlogic: s4: add crypto node arm64: dts: amlogic: g12: add crypto node arm64: dts: amlogic: axg: add crypto node Jose Nieto (8): crypto: amlogic: g12: drop CRYPTO_ALG_ALLOCATES_MEMORY crypto: amlogic: hasher: add one-shot digest path crypto: amlogic: drop unused field and stale includes dt-bindings: crypto: amlogic,gxl-crypto: keep standard property order crypto: amlogic: fix probe and algorithm registration error paths crypto: amlogic: fix setup descriptor lengths and CBC IV copy crypto: amlogic: drop redundant A1 platform data arm64: dts: amlogic: use the system clock for A1/S4 crypto .../bindings/crypto/amlogic,gxl-crypto.yaml | 38 +- arch/arm64/boot/dts/amlogic/meson-a1.dtsi | 8 + arch/arm64/boot/dts/amlogic/meson-axg.dtsi | 7 + .../boot/dts/amlogic/meson-g12-common.dtsi | 7 + arch/arm64/boot/dts/amlogic/meson-gxl.dtsi | 6 +- arch/arm64/boot/dts/amlogic/meson-s4.dtsi | 7 + drivers/crypto/amlogic/Makefile | 2 +- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 596 ++++++++++++------ drivers/crypto/amlogic/amlogic-gxl-core.c | 279 ++++---- drivers/crypto/amlogic/amlogic-gxl-hasher.c | 511 +++++++++++++++ drivers/crypto/amlogic/amlogic-gxl.h | 120 +++- 11 files changed, 1201 insertions(+), 380 deletions(-) create mode 100644 drivers/crypto/amlogic/amlogic-gxl-hasher.c base-commit: 3191063649dbf7c0d0b768e1f3655e4c5fc6edb5 -- 2.47.3 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v14 01/30] dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 02/30] dt-bindings: crypto: amlogic,gxl-crypto: support new SoC's Jose Nieto ` (28 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> GXL and newer SoC's uses the DMA engine (not blkmv) for crypto HW. Crypto HW doesn't actually use the blkmv clk. At RTL level, crypto engine is hard-wired to a clk81 (CLKID_CLK81). Drop clock-names field from schema: name "blkmv" is invalid and "clk81" is confusing and sounds like something global. Also, GXL crypto IP isn't connected to the second interrupt line. This binding is useless, there are no users of this line. We must remove it from dt-bindings. Fixes: 7f7d115dfb51 ("dt-bindings: crypto: Add DT bindings documentation for amlogic-crypto") Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Rob Herring (Arm) <robh@kernel.org> --- .../devicetree/bindings/crypto/amlogic,gxl-crypto.yaml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml b/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml index 948e11ebe4ee..fdc39797a2a9 100644 --- a/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml +++ b/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml @@ -20,20 +20,15 @@ properties: interrupts: items: - description: Interrupt for flow 0 - - description: Interrupt for flow 1 clocks: maxItems: 1 - clock-names: - const: blkmv - required: - compatible - reg - interrupts - clocks - - clock-names additionalProperties: false @@ -46,7 +41,6 @@ examples: crypto: crypto-engine@c883e000 { compatible = "amlogic,gxl-crypto"; reg = <0xc883e000 0x36>; - interrupts = <GIC_SPI 188 IRQ_TYPE_EDGE_RISING>, <GIC_SPI 189 IRQ_TYPE_EDGE_RISING>; - clocks = <&clkc CLKID_BLKMV>; - clock-names = "blkmv"; + interrupts = <GIC_SPI 188 IRQ_TYPE_EDGE_RISING>; + clocks = <&clkc CLKID_CLK81>; }; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 02/30] dt-bindings: crypto: amlogic,gxl-crypto: support new SoC's 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto 2026-11-27 12:00 ` [PATCH v14 01/30] dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 03/30] crypto: amlogic - Don't hardcode IRQ count Jose Nieto ` (27 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Now crypto module available at G12A/G12B/S4/A1/SM1/AXG. 1. Add new compatibles: - amlogic,g12a-crypto - amlogic,axg-crypto - amlogic,a1-crypto - amlogic,s4-crypto (uses a1-crypto as fallback) Difference between this compatibles: * Different registers offset and the number of setup descriptors. * GXL doesn't support hashing like the others. * G12A/B and A1/S4 crypto HW don't support 192 AES key. * GXL, G12A/B and AXG require a reverse IV key before processing. 2. Add power-domains in schema, which is required only for A1. This is specific vendor design: in old SoC's power domain for crypto HW was not configurable, but in A1-series it is configurable. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Rob Herring (Arm) <robh@kernel.org> --- .../bindings/crypto/amlogic,gxl-crypto.yaml | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml b/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml index fdc39797a2a9..106a9d1fed69 100644 --- a/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml +++ b/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml @@ -11,8 +11,16 @@ maintainers: properties: compatible: - items: - - const: amlogic,gxl-crypto + oneOf: + - items: + - enum: + - amlogic,s4-crypto + - const: amlogic,a1-crypto + - enum: + - amlogic,gxl-crypto + - amlogic,axg-crypto + - amlogic,g12a-crypto + - amlogic,a1-crypto reg: maxItems: 1 @@ -24,12 +32,24 @@ properties: clocks: maxItems: 1 + power-domains: + maxItems: 1 + required: - compatible - reg - interrupts - clocks +allOf: + - if: + properties: + compatible: + const: amlogic,a1-crypto + then: + required: + - power-domains + additionalProperties: false examples: -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 03/30] crypto: amlogic - Don't hardcode IRQ count 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto 2026-11-27 12:00 ` [PATCH v14 01/30] dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines Jose Nieto 2026-11-27 12:00 ` [PATCH v14 02/30] dt-bindings: crypto: amlogic,gxl-crypto: support new SoC's Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:11 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 04/30] crypto: amlogic - Add platform data Jose Nieto ` (26 subsequent siblings) 29 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> IRQ count is no longer hardcoded, and make it part of struct meson_flow. We need this for extend driver support for other Amlogic SoC's. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 2 +- drivers/crypto/amlogic/amlogic-gxl-core.c | 48 +++++++++++---------- drivers/crypto/amlogic/amlogic-gxl.h | 8 ++-- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index d78815b0547d..bcaed2f413d3 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -19,7 +19,7 @@ static int get_engine_number(struct meson_dev *mc) { - return atomic_inc_return(&mc->flow) % MAXFLOW; + return atomic_inc_return(&mc->flow) % mc->flow_cnt; } static bool meson_cipher_need_fallback(struct skcipher_request *areq) diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 48dbdf452034..b6933be39a37 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -28,8 +28,8 @@ static irqreturn_t meson_irq_handler(int irq, void *data) int flow; u32 p; - for (flow = 0; flow < MAXFLOW; flow++) { - if (mc->irqs[flow] == irq) { + for (flow = 0; flow < mc->flow_cnt; flow++) { + if (mc->chanlist[flow].irq == irq) { p = readl(mc->base + ((0x04 + flow) << 2)); if (p) { writel_relaxed(0xF, mc->base + ((0x4 + flow) << 2)); @@ -111,7 +111,7 @@ static int meson_debugfs_show(struct seq_file *seq, void *v) struct meson_dev *mc __maybe_unused = seq->private; int i; - for (i = 0; i < MAXFLOW; i++) + for (i = 0; i < mc->flow_cnt; i++) seq_printf(seq, "Channel %d: nreq %lu\n", i, #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG mc->chanlist[i].stat_req); @@ -154,13 +154,31 @@ static void meson_free_chanlist(struct meson_dev *mc, int i) */ static int meson_allocate_chanlist(struct meson_dev *mc) { + struct platform_device *pdev = to_platform_device(mc->dev); int i, err; - mc->chanlist = devm_kzalloc_objs(mc->dev, struct meson_flow, MAXFLOW); + mc->flow_cnt = platform_irq_count(pdev); + if (mc->flow_cnt <= 0) { + dev_err(mc->dev, "No IRQs defined\n"); + return -ENODEV; + } + + mc->chanlist = devm_kzalloc_objs(mc->dev, struct meson_flow, mc->flow_cnt); if (!mc->chanlist) return -ENOMEM; - for (i = 0; i < MAXFLOW; i++) { + for (i = 0; i < mc->flow_cnt; i++) { + mc->chanlist[i].irq = platform_get_irq(pdev, i); + if (mc->chanlist[i].irq < 0) + return mc->chanlist[i].irq; + + err = devm_request_irq(mc->dev, mc->chanlist[i].irq, + meson_irq_handler, 0, "aml-crypto", mc); + if (err < 0) { + dev_err(mc->dev, "Cannot request IRQ for flow %d\n", i); + return err; + } + init_completion(&mc->chanlist[i].complete); mc->chanlist[i].engine = crypto_engine_alloc_init(mc->dev, true); @@ -230,7 +248,7 @@ static void meson_unregister_algs(struct meson_dev *mc) static int meson_crypto_probe(struct platform_device *pdev) { struct meson_dev *mc; - int err, i; + int err; mc = devm_kzalloc_obj(&pdev->dev, *mc); if (!mc) @@ -254,19 +272,6 @@ static int meson_crypto_probe(struct platform_device *pdev) if (err) return err; - for (i = 0; i < MAXFLOW; i++) { - mc->irqs[i] = platform_get_irq(pdev, i); - if (mc->irqs[i] < 0) { - err = mc->irqs[i]; - goto error_chanlist; - } - - err = devm_request_irq(&pdev->dev, mc->irqs[i], meson_irq_handler, 0, - "gxl-crypto", mc); - if (err < 0) - goto error_chanlist; - } - err = meson_register_algs(mc); if (err) goto error_alg; @@ -285,8 +290,7 @@ static int meson_crypto_probe(struct platform_device *pdev) return 0; error_alg: meson_unregister_algs(mc); -error_chanlist: - meson_free_chanlist(mc, MAXFLOW - 1); + meson_free_chanlist(mc, mc->flow_cnt - 1); return err; } @@ -300,7 +304,7 @@ static void meson_crypto_remove(struct platform_device *pdev) meson_unregister_algs(mc); - meson_free_chanlist(mc, MAXFLOW - 1); + meson_free_chanlist(mc, mc->flow_cnt - 1); } static const struct of_device_id meson_crypto_of_match_table[] = { diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index d68094ffb70a..9f1ef87333ae 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -22,8 +22,6 @@ #define MESON_OPMODE_ECB 0 #define MESON_OPMODE_CBC 1 -#define MAXFLOW 2 - #define MAXDESC 64 #define DESC_LAST BIT(18) @@ -62,6 +60,7 @@ struct meson_desc { * @keylen: keylen for this flow operation * @complete: completion for the current task on this flow * @status: set to 1 by interrupt if task is done + * @irq: IRQ number for amlogic-crypto * @t_phy: Physical address of task * @tl: pointer to the current ce_task for this flow * @stat_req: number of request done by this flow @@ -70,6 +69,7 @@ struct meson_flow { struct crypto_engine *engine; struct completion complete; int status; + int irq; unsigned int keylen; dma_addr_t t_phy; struct meson_desc *tl; @@ -85,7 +85,7 @@ struct meson_flow { * @dev: the platform device * @chanlist: array of all flow * @flow: flow to use in next request - * @irqs: IRQ numbers for amlogic-crypto + * @flow_cnt: flow count for amlogic-crypto * @dbgfs_dir: Debugfs dentry for statistic directory * @dbgfs_stats: Debugfs dentry for statistic counters */ @@ -95,7 +95,7 @@ struct meson_dev { struct device *dev; struct meson_flow *chanlist; atomic_t flow; - int irqs[MAXFLOW]; + int flow_cnt; #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG struct dentry *dbgfs_dir; #endif -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v14 03/30] crypto: amlogic - Don't hardcode IRQ count 2026-11-27 12:00 ` [PATCH v14 03/30] crypto: amlogic - Don't hardcode IRQ count Jose Nieto @ 2026-11-27 12:11 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-27 12:11 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] crypto: amlogic - IRQ requested before init_completion() in probe -- commit b42c58d2650be1044e0fec0a7ef8758413b304b6 Author: Alexey Romanov <romanov.alexey2000@gmail.com> crypto: amlogic - Don't hardcode IRQ count This commit replaces the hardcoded MAXFLOW constant with a dynamic flow count queried via platform_irq_count() and moves per-flow IRQ registration into meson_allocate_chanlist(). > diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c > index 48dbdf4520348..b6933be39a377 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-core.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c [ ... ] > @@ -154,13 +154,31 @@ static void meson_free_chanlist(struct meson_dev *mc, int i) > */ > static int meson_allocate_chanlist(struct meson_dev *mc) > { > + struct platform_device *pdev = to_platform_device(mc->dev); > int i, err; > > - mc->chanlist = devm_kzalloc_objs(mc->dev, struct meson_flow, MAXFLOW); > + mc->flow_cnt = platform_irq_count(pdev); > + if (mc->flow_cnt <= 0) { > + dev_err(mc->dev, "No IRQs defined\n"); > + return -ENODEV; > + } > + > + mc->chanlist = devm_kzalloc_objs(mc->dev, struct meson_flow, mc->flow_cnt); > if (!mc->chanlist) > return -ENOMEM; > > - for (i = 0; i < MAXFLOW; i++) { > + for (i = 0; i < mc->flow_cnt; i++) { > + mc->chanlist[i].irq = platform_get_irq(pdev, i); > + if (mc->chanlist[i].irq < 0) > + return mc->chanlist[i].irq; > + > + err = devm_request_irq(mc->dev, mc->chanlist[i].irq, > + meson_irq_handler, 0, "aml-crypto", mc); > + if (err < 0) { > + dev_err(mc->dev, "Cannot request IRQ for flow %d\n", i); > + return err; > + } > + > init_completion(&mc->chanlist[i].complete); [Severity: Medium] Can meson_irq_handler() fire before init_completion() initializes mc->chanlist[i].complete? Moving devm_request_irq() ahead of init_completion() enables the IRQ while mc->chanlist[i].complete is still zero-filled, so a pending interrupt with a non-zero flow status register will call complete() on an uninitialized swait_queue_head and dereference a NULL task_list.next pointer. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261127120103.1532882-1-jnieto.alaber@gmail.com?part=3 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v14 04/30] crypto: amlogic - Add platform data 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (2 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 03/30] crypto: amlogic - Don't hardcode IRQ count Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 05/30] crypto: amlogic - Remove clock input Jose Nieto ` (25 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> To support other Amlogic SoC's we have to use platform data: descriptors and status registers offsets are individual for each SoC series. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 2 +- drivers/crypto/amlogic/amlogic-gxl-core.c | 22 +++++++++++++++++---- drivers/crypto/amlogic/amlogic-gxl.h | 11 +++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index bcaed2f413d3..c458548f29b2 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -234,7 +234,7 @@ static int meson_cipher(struct skcipher_request *areq) reinit_completion(&mc->chanlist[flow].complete); mc->chanlist[flow].status = 0; - writel(mc->chanlist[flow].t_phy | 2, mc->base + (flow << 2)); + writel(mc->chanlist[flow].t_phy | 2, mc->base + ((mc->pdata->descs_reg + flow) << 2)); wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete, msecs_to_jiffies(500)); if (mc->chanlist[flow].status == 0) { diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index b6933be39a37..24ef7d5a5607 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -18,6 +18,7 @@ #include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/of_device.h> #include <linux/platform_device.h> #include "amlogic-gxl.h" @@ -30,9 +31,10 @@ static irqreturn_t meson_irq_handler(int irq, void *data) for (flow = 0; flow < mc->flow_cnt; flow++) { if (mc->chanlist[flow].irq == irq) { - p = readl(mc->base + ((0x04 + flow) << 2)); + p = readl(mc->base + ((mc->pdata->status_reg + flow) << 2)); if (p) { - writel_relaxed(0xF, mc->base + ((0x4 + flow) << 2)); + writel_relaxed(0xF, mc->base + + ((mc->pdata->status_reg + flow) << 2)); mc->chanlist[flow].status = 1; complete(&mc->chanlist[flow].complete); return IRQ_HANDLED; @@ -254,6 +256,10 @@ static int meson_crypto_probe(struct platform_device *pdev) if (!mc) return -ENOMEM; + mc->pdata = of_device_get_match_data(&pdev->dev); + if (!mc->pdata) + return -EINVAL; + mc->dev = &pdev->dev; platform_set_drvdata(pdev, mc); @@ -307,9 +313,17 @@ static void meson_crypto_remove(struct platform_device *pdev) meson_free_chanlist(mc, mc->flow_cnt - 1); } +static const struct meson_pdata meson_gxl_pdata = { + .descs_reg = 0x0, + .status_reg = 0x4, +}; + static const struct of_device_id meson_crypto_of_match_table[] = { - { .compatible = "amlogic,gxl-crypto", }, - {} + { + .compatible = "amlogic,gxl-crypto", + .data = &meson_gxl_pdata, + }, + {}, }; MODULE_DEVICE_TABLE(of, meson_crypto_of_match_table); diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index 9f1ef87333ae..e0bc5c39bf2c 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -78,6 +78,16 @@ struct meson_flow { #endif }; +/* + * struct meson_pdata - SoC series dependent data. + * @reg_descs: offset to descriptors register + * @reg_status: offset to status register + */ +struct meson_pdata { + u32 descs_reg; + u32 status_reg; +}; + /* * struct meson_dev - main container for all this driver information * @base: base address of amlogic-crypto @@ -93,6 +103,7 @@ struct meson_dev { void __iomem *base; struct clk *busclk; struct device *dev; + const struct meson_pdata *pdata; struct meson_flow *chanlist; atomic_t flow; int flow_cnt; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 05/30] crypto: amlogic - Remove clock input 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (3 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 04/30] crypto: amlogic - Add platform data Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:14 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 06/30] crypto: amlogic - Add MMIO helpers Jose Nieto ` (24 subsequent siblings) 29 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Amlogic crypto IP, which uses DMA crypto engine, doesn't take a clock input. Fixes: 48fe583fe541 ("crypto: amlogic - Add crypto accelerator for amlogic GXL") Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-core.c | 8 -------- drivers/crypto/amlogic/amlogic-gxl.h | 2 -- 2 files changed, 10 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 24ef7d5a5607..37224d75edfb 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -9,7 +9,6 @@ #include <crypto/engine.h> #include <crypto/internal/skcipher.h> -#include <linux/clk.h> #include <linux/dma-mapping.h> #include <linux/err.h> #include <linux/interrupt.h> @@ -267,13 +266,6 @@ static int meson_crypto_probe(struct platform_device *pdev) if (IS_ERR(mc->base)) return PTR_ERR(mc->base); - mc->busclk = devm_clk_get_enabled(&pdev->dev, "blkmv"); - if (IS_ERR(mc->busclk)) { - err = PTR_ERR(mc->busclk); - dev_err(&pdev->dev, "Cannot get/enable core clock err=%d\n", err); - return err; - } - err = meson_allocate_chanlist(mc); if (err) return err; diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index e0bc5c39bf2c..5149dc6e9f60 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -91,7 +91,6 @@ struct meson_pdata { /* * struct meson_dev - main container for all this driver information * @base: base address of amlogic-crypto - * @busclk: bus clock for amlogic-crypto * @dev: the platform device * @chanlist: array of all flow * @flow: flow to use in next request @@ -101,7 +100,6 @@ struct meson_pdata { */ struct meson_dev { void __iomem *base; - struct clk *busclk; struct device *dev; const struct meson_pdata *pdata; struct meson_flow *chanlist; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v14 05/30] crypto: amlogic - Remove clock input 2026-11-27 12:00 ` [PATCH v14 05/30] crypto: amlogic - Remove clock input Jose Nieto @ 2026-11-27 12:14 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-27 12:14 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] crypto: amlogic - meson_crypto_probe() drops required DT clock enablement -- commit 4232268afc2acbf7008e7d08e5f42bc81d020538 Author: Alexey Romanov <romanov.alexey2000@gmail.com> crypto: amlogic - Remove clock input This commit removes the devm_clk_get_enabled() call from meson_crypto_probe() and drops the busclk member from struct meson_dev. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c > index 24ef7d5a56075..37224d75edfbf 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-core.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c [ ... ] > @@ -267,13 +266,6 @@ static int meson_crypto_probe(struct platform_device *pdev) > if (IS_ERR(mc->base)) > return PTR_ERR(mc->base); > > - mc->busclk = devm_clk_get_enabled(&pdev->dev, "blkmv"); > - if (IS_ERR(mc->busclk)) { > - err = PTR_ERR(mc->busclk); > - dev_err(&pdev->dev, "Cannot get/enable core clock err=%d\n", err); > - return err; > - } > - > err = meson_allocate_chanlist(mc); > if (err) > return err; [Severity: Medium] Should meson_crypto_probe() pass NULL to devm_clk_get_enabled() instead of dropping clock enablement altogether? Earlier in this series, commit "dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines" states that the crypto block is clocked by clk81 rather than blkmv, removes only clock-names, and keeps clocks as a required property in Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml: required: - compatible - reg - interrupts - clocks Without devm_clk_get_enabled(&pdev->dev, NULL), the required clock defined in the binding and device tree nodes is never claimed or enabled by the driver, leaving the crypto DMA engine unclocked if the gate is not kept on by the bootloader or temporary CLK_IS_CRITICAL / CLK_IGNORE_UNUSED flags. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261127120103.1532882-1-jnieto.alaber@gmail.com?part=5 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v14 06/30] crypto: amlogic - Add MMIO helpers 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (4 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 05/30] crypto: amlogic - Remove clock input Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 07/30] crypto: amlogic - Move get_engine_number() Jose Nieto ` (23 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Add MMIO access helpers: meson_dma_start() and meson_dma_ready(). Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 2 +- drivers/crypto/amlogic/amlogic-gxl-core.c | 24 ++++++++++++++++----- drivers/crypto/amlogic/amlogic-gxl.h | 2 ++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index c458548f29b2..62aa82e1cb5d 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -234,7 +234,7 @@ static int meson_cipher(struct skcipher_request *areq) reinit_completion(&mc->chanlist[flow].complete); mc->chanlist[flow].status = 0; - writel(mc->chanlist[flow].t_phy | 2, mc->base + ((mc->pdata->descs_reg + flow) << 2)); + meson_dma_start(mc, flow); wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete, msecs_to_jiffies(500)); if (mc->chanlist[flow].status == 0) { diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 37224d75edfb..b972df44e8b5 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -22,18 +22,32 @@ #include "amlogic-gxl.h" +void meson_dma_start(struct meson_dev *mc, int flow) +{ + u32 offset = (mc->pdata->descs_reg + flow) << 2; + + writel(mc->chanlist[flow].t_phy | 2, mc->base + offset); +} + +static bool meson_dma_ready(struct meson_dev *mc, int flow) +{ + u32 offset = (mc->pdata->status_reg + flow) << 2; + u32 data = readl(mc->base + offset); + + if (data) + writel_relaxed(0xF, mc->base + offset); + + return data; +} + static irqreturn_t meson_irq_handler(int irq, void *data) { struct meson_dev *mc = (struct meson_dev *)data; int flow; - u32 p; for (flow = 0; flow < mc->flow_cnt; flow++) { if (mc->chanlist[flow].irq == irq) { - p = readl(mc->base + ((mc->pdata->status_reg + flow) << 2)); - if (p) { - writel_relaxed(0xF, mc->base + - ((mc->pdata->status_reg + flow) << 2)); + if (meson_dma_ready(mc, flow)) { mc->chanlist[flow].status = 1; complete(&mc->chanlist[flow].complete); return IRQ_HANDLED; diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index 5149dc6e9f60..64f2f0e63f12 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -159,6 +159,8 @@ struct meson_alg_template { #endif }; +void meson_dma_start(struct meson_dev *mc, int flow); + int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen); int meson_cipher_init(struct crypto_tfm *tfm); -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 07/30] crypto: amlogic - Move get_engine_number() 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (5 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 06/30] crypto: amlogic - Add MMIO helpers Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 08/30] crypto: amlogic - Drop status field from meson_flow Jose Nieto ` (22 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Move get_engine_number() function from cipher.c to core.c Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 9 ++------- drivers/crypto/amlogic/amlogic-gxl-core.c | 5 +++++ drivers/crypto/amlogic/amlogic-gxl.h | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index 62aa82e1cb5d..f6c13d8fcb47 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -17,11 +17,6 @@ #include <crypto/internal/skcipher.h> #include "amlogic-gxl.h" -static int get_engine_number(struct meson_dev *mc) -{ - return atomic_inc_return(&mc->flow) % mc->flow_cnt; -} - static bool meson_cipher_need_fallback(struct skcipher_request *areq) { struct scatterlist *src_sg = areq->src; @@ -297,7 +292,7 @@ int meson_skdecrypt(struct skcipher_request *areq) rctx->op_dir = MESON_DECRYPT; if (meson_cipher_need_fallback(areq)) return meson_cipher_do_fallback(areq); - e = get_engine_number(op->mc); + e = meson_get_engine_number(op->mc); engine = op->mc->chanlist[e].engine; rctx->flow = e; @@ -315,7 +310,7 @@ int meson_skencrypt(struct skcipher_request *areq) rctx->op_dir = MESON_ENCRYPT; if (meson_cipher_need_fallback(areq)) return meson_cipher_do_fallback(areq); - e = get_engine_number(op->mc); + e = meson_get_engine_number(op->mc); engine = op->mc->chanlist[e].engine; rctx->flow = e; diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index b972df44e8b5..58d56f352dd6 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -22,6 +22,11 @@ #include "amlogic-gxl.h" +int meson_get_engine_number(struct meson_dev *mc) +{ + return atomic_inc_return(&mc->flow) % mc->flow_cnt; +} + void meson_dma_start(struct meson_dev *mc, int flow) { u32 offset = (mc->pdata->descs_reg + flow) << 2; diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index 64f2f0e63f12..e14cd5021add 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -159,6 +159,8 @@ struct meson_alg_template { #endif }; +int meson_get_engine_number(struct meson_dev *mc); + void meson_dma_start(struct meson_dev *mc, int flow); int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 08/30] crypto: amlogic - Drop status field from meson_flow 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (6 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 07/30] crypto: amlogic - Move get_engine_number() Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 09/30] crypto: amlogic - Move algs definition and cipher API to cipher.c Jose Nieto ` (21 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> This field is used only to check for timeout. But there is more convenient way to achive the same goal. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 13 +++++++++---- drivers/crypto/amlogic/amlogic-gxl-core.c | 1 - drivers/crypto/amlogic/amlogic-gxl.h | 2 -- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index f6c13d8fcb47..cd94296e4d9a 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -228,13 +228,18 @@ static int meson_cipher(struct skcipher_request *areq) } reinit_completion(&mc->chanlist[flow].complete); - mc->chanlist[flow].status = 0; meson_dma_start(mc, flow); - wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete, - msecs_to_jiffies(500)); - if (mc->chanlist[flow].status == 0) { + + err = wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete, + msecs_to_jiffies(500)); + if (err == 0) { dev_err(mc->dev, "DMA timeout for flow %d\n", flow); err = -EINVAL; + } else if (err < 0) { + dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", err); + } else { + /* No error */ + err = 0; } dma_unmap_single(mc->dev, phykeyiv, keyivlen, DMA_TO_DEVICE); diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 58d56f352dd6..81d0e8731ab1 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -53,7 +53,6 @@ static irqreturn_t meson_irq_handler(int irq, void *data) for (flow = 0; flow < mc->flow_cnt; flow++) { if (mc->chanlist[flow].irq == irq) { if (meson_dma_ready(mc, flow)) { - mc->chanlist[flow].status = 1; complete(&mc->chanlist[flow].complete); return IRQ_HANDLED; } diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index e14cd5021add..cf07c5fbc5bf 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -59,7 +59,6 @@ struct meson_desc { * @engine: ptr to the crypto_engine for this flow * @keylen: keylen for this flow operation * @complete: completion for the current task on this flow - * @status: set to 1 by interrupt if task is done * @irq: IRQ number for amlogic-crypto * @t_phy: Physical address of task * @tl: pointer to the current ce_task for this flow @@ -68,7 +67,6 @@ struct meson_desc { struct meson_flow { struct crypto_engine *engine; struct completion complete; - int status; int irq; unsigned int keylen; dma_addr_t t_phy; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 09/30] crypto: amlogic - Move algs definition and cipher API to cipher.c 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (7 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 08/30] crypto: amlogic - Drop status field from meson_flow Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:14 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 10/30] crypto: amlogic - Cleanup defines Jose Nieto ` (20 subsequent siblings) 29 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Because that is proper place for them. In particular, it takes less of exported symbol between compiling entities. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 98 +++++++++++++++-- drivers/crypto/amlogic/amlogic-gxl-core.c | 111 ++++---------------- drivers/crypto/amlogic/amlogic-gxl.h | 14 +-- 3 files changed, 120 insertions(+), 103 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index cd94296e4d9a..00d3247ebea1 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -286,7 +286,7 @@ int meson_handle_cipher_request(struct crypto_engine *engine, void *areq) return 0; } -int meson_skdecrypt(struct skcipher_request *areq) +static int meson_skdecrypt(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); @@ -304,7 +304,7 @@ int meson_skdecrypt(struct skcipher_request *areq) return crypto_transfer_skcipher_request_to_engine(engine, areq); } -int meson_skencrypt(struct skcipher_request *areq) +static int meson_skencrypt(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); @@ -322,7 +322,7 @@ int meson_skencrypt(struct skcipher_request *areq) return crypto_transfer_skcipher_request_to_engine(engine, areq); } -int meson_cipher_init(struct crypto_tfm *tfm) +static int meson_cipher_init(struct crypto_tfm *tfm) { struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm); struct meson_alg_template *algt; @@ -348,7 +348,7 @@ int meson_cipher_init(struct crypto_tfm *tfm) return 0; } -void meson_cipher_exit(struct crypto_tfm *tfm) +static void meson_cipher_exit(struct crypto_tfm *tfm) { struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm); @@ -356,8 +356,8 @@ void meson_cipher_exit(struct crypto_tfm *tfm) crypto_free_skcipher(op->fallback_tfm); } -int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, - unsigned int keylen) +static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, + unsigned int keylen) { struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); struct meson_dev *mc = op->mc; @@ -384,3 +384,89 @@ int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, return crypto_skcipher_setkey(op->fallback_tfm, key, keylen); } + +static struct meson_alg_template algs[] = { +{ + .type = CRYPTO_ALG_TYPE_SKCIPHER, + .blockmode = MESON_OPMODE_CBC, + .alg.skcipher.base = { + .base = { + .cra_name = "cbc(aes)", + .cra_driver_name = "cbc-aes-gxl", + .cra_priority = 400, + .cra_blocksize = AES_BLOCK_SIZE, + .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_NEED_FALLBACK, + .cra_ctxsize = sizeof(struct meson_cipher_tfm_ctx), + .cra_module = THIS_MODULE, + .cra_alignmask = 0xf, + .cra_init = meson_cipher_init, + .cra_exit = meson_cipher_exit, + }, + .min_keysize = AES_MIN_KEY_SIZE, + .max_keysize = AES_MAX_KEY_SIZE, + .ivsize = AES_BLOCK_SIZE, + .setkey = meson_aes_setkey, + .encrypt = meson_skencrypt, + .decrypt = meson_skdecrypt, + }, + .alg.skcipher.op = { + .do_one_request = meson_handle_cipher_request, + }, +}, +{ + .type = CRYPTO_ALG_TYPE_SKCIPHER, + .blockmode = MESON_OPMODE_ECB, + .alg.skcipher.base = { + .base = { + .cra_name = "ecb(aes)", + .cra_driver_name = "ecb-aes-gxl", + .cra_priority = 400, + .cra_blocksize = AES_BLOCK_SIZE, + .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_NEED_FALLBACK, + .cra_ctxsize = sizeof(struct meson_cipher_tfm_ctx), + .cra_module = THIS_MODULE, + .cra_alignmask = 0xf, + .cra_init = meson_cipher_init, + .cra_exit = meson_cipher_exit, + }, + .min_keysize = AES_MIN_KEY_SIZE, + .max_keysize = AES_MAX_KEY_SIZE, + .setkey = meson_aes_setkey, + .encrypt = meson_skencrypt, + .decrypt = meson_skdecrypt, + }, + .alg.skcipher.op = { + .do_one_request = meson_handle_cipher_request, + }, +}, +}; + +int meson_cipher_register(struct meson_dev *mc) +{ + return meson_register_algs(mc, algs, ARRAY_SIZE(algs)); +} + +void meson_cipher_unregister(struct meson_dev *mc) +{ + meson_unregister_algs(mc, algs, ARRAY_SIZE(algs)); +} + +void meson_cipher_debugfs_show(struct seq_file *seq, void *v) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(algs); i++) { + seq_printf(seq, "%s %s %lu %lu\n", + algs[i].alg.skcipher.base.base.cra_driver_name, + algs[i].alg.skcipher.base.base.cra_name, +#ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG + algs[i].stat_req, algs[i].stat_fb); +#else + 0ul, 0ul); +#endif + } +} diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 81d0e8731ab1..68d394e90f66 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -65,66 +65,6 @@ static irqreturn_t meson_irq_handler(int irq, void *data) return IRQ_NONE; } -static struct meson_alg_template mc_algs[] = { -{ - .type = CRYPTO_ALG_TYPE_SKCIPHER, - .blockmode = MESON_OPMODE_CBC, - .alg.skcipher.base = { - .base = { - .cra_name = "cbc(aes)", - .cra_driver_name = "cbc-aes-gxl", - .cra_priority = 400, - .cra_blocksize = AES_BLOCK_SIZE, - .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | - CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | - CRYPTO_ALG_NEED_FALLBACK, - .cra_ctxsize = sizeof(struct meson_cipher_tfm_ctx), - .cra_module = THIS_MODULE, - .cra_alignmask = 0xf, - .cra_init = meson_cipher_init, - .cra_exit = meson_cipher_exit, - }, - .min_keysize = AES_MIN_KEY_SIZE, - .max_keysize = AES_MAX_KEY_SIZE, - .ivsize = AES_BLOCK_SIZE, - .setkey = meson_aes_setkey, - .encrypt = meson_skencrypt, - .decrypt = meson_skdecrypt, - }, - .alg.skcipher.op = { - .do_one_request = meson_handle_cipher_request, - }, -}, -{ - .type = CRYPTO_ALG_TYPE_SKCIPHER, - .blockmode = MESON_OPMODE_ECB, - .alg.skcipher.base = { - .base = { - .cra_name = "ecb(aes)", - .cra_driver_name = "ecb-aes-gxl", - .cra_priority = 400, - .cra_blocksize = AES_BLOCK_SIZE, - .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | - CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | - CRYPTO_ALG_NEED_FALLBACK, - .cra_ctxsize = sizeof(struct meson_cipher_tfm_ctx), - .cra_module = THIS_MODULE, - .cra_alignmask = 0xf, - .cra_init = meson_cipher_init, - .cra_exit = meson_cipher_exit, - }, - .min_keysize = AES_MIN_KEY_SIZE, - .max_keysize = AES_MAX_KEY_SIZE, - .setkey = meson_aes_setkey, - .encrypt = meson_skencrypt, - .decrypt = meson_skdecrypt, - }, - .alg.skcipher.op = { - .do_one_request = meson_handle_cipher_request, - }, -}, -}; - static int meson_debugfs_show(struct seq_file *seq, void *v) { struct meson_dev *mc __maybe_unused = seq->private; @@ -138,20 +78,8 @@ static int meson_debugfs_show(struct seq_file *seq, void *v) 0ul); #endif - for (i = 0; i < ARRAY_SIZE(mc_algs); i++) { - switch (mc_algs[i].type) { - case CRYPTO_ALG_TYPE_SKCIPHER: - seq_printf(seq, "%s %s %lu %lu\n", - mc_algs[i].alg.skcipher.base.base.cra_driver_name, - mc_algs[i].alg.skcipher.base.base.cra_name, -#ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG - mc_algs[i].stat_req, mc_algs[i].stat_fb); -#else - 0ul, 0ul); -#endif - break; - } - } + meson_cipher_debugfs_show(seq, v); + return 0; } DEFINE_SHOW_ATTRIBUTE(meson_debugfs); @@ -227,19 +155,20 @@ static int meson_allocate_chanlist(struct meson_dev *mc) return err; } -static int meson_register_algs(struct meson_dev *mc) +int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *algs, + unsigned int count) { int err, i; - for (i = 0; i < ARRAY_SIZE(mc_algs); i++) { - mc_algs[i].mc = mc; - switch (mc_algs[i].type) { + for (i = 0; i < count; i++) { + algs[i].mc = mc; + switch (algs[i].type) { case CRYPTO_ALG_TYPE_SKCIPHER: - err = crypto_engine_register_skcipher(&mc_algs[i].alg.skcipher); + err = crypto_engine_register_skcipher(&algs[i].alg.skcipher); if (err) { dev_err(mc->dev, "Fail to register %s\n", - mc_algs[i].alg.skcipher.base.base.cra_name); - mc_algs[i].mc = NULL; + algs[i].alg.skcipher.base.base.cra_name); + meson_unregister_algs(mc, algs, count); return err; } break; @@ -249,16 +178,17 @@ static int meson_register_algs(struct meson_dev *mc) return 0; } -static void meson_unregister_algs(struct meson_dev *mc) +void meson_unregister_algs(struct meson_dev *mc, struct meson_alg_template *algs, + unsigned int count) { int i; - for (i = 0; i < ARRAY_SIZE(mc_algs); i++) { - if (!mc_algs[i].mc) + for (i = 0; i < count; i++) { + if (!algs[i].mc) continue; - switch (mc_algs[i].type) { + switch (algs[i].type) { case CRYPTO_ALG_TYPE_SKCIPHER: - crypto_engine_unregister_skcipher(&mc_algs[i].alg.skcipher); + crypto_engine_unregister_skcipher(&algs[i].alg.skcipher); break; } } @@ -288,9 +218,9 @@ static int meson_crypto_probe(struct platform_device *pdev) if (err) return err; - err = meson_register_algs(mc); + err = meson_cipher_register(mc); if (err) - goto error_alg; + goto error_flow; if (IS_ENABLED(CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG)) { struct dentry *dbgfs_dir; @@ -304,8 +234,7 @@ static int meson_crypto_probe(struct platform_device *pdev) } return 0; -error_alg: - meson_unregister_algs(mc); +error_flow: meson_free_chanlist(mc, mc->flow_cnt - 1); return err; } @@ -318,7 +247,7 @@ static void meson_crypto_remove(struct platform_device *pdev) debugfs_remove_recursive(mc->dbgfs_dir); #endif - meson_unregister_algs(mc); + meson_cipher_unregister(mc); meson_free_chanlist(mc, mc->flow_cnt - 1); } diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index cf07c5fbc5bf..608ce75f027a 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -161,10 +161,12 @@ int meson_get_engine_number(struct meson_dev *mc); void meson_dma_start(struct meson_dev *mc, int flow); -int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, - unsigned int keylen); -int meson_cipher_init(struct crypto_tfm *tfm); -void meson_cipher_exit(struct crypto_tfm *tfm); -int meson_skdecrypt(struct skcipher_request *areq); -int meson_skencrypt(struct skcipher_request *areq); +int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *algs, + unsigned int count); +void meson_unregister_algs(struct meson_dev *mc, struct meson_alg_template *algs, + unsigned int count); + +int meson_cipher_register(struct meson_dev *mc); +void meson_cipher_unregister(struct meson_dev *mc); +void meson_cipher_debugfs_show(struct seq_file *seq, void *v); int meson_handle_cipher_request(struct crypto_engine *engine, void *areq); -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v14 09/30] crypto: amlogic - Move algs definition and cipher API to cipher.c 2026-11-27 12:00 ` [PATCH v14 09/30] crypto: amlogic - Move algs definition and cipher API to cipher.c Jose Nieto @ 2026-11-27 12:14 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-27 12:14 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] crypto: amlogic: meson_handle_cipher_request() left non-static -- commit 06a3afc67de49fb3af60963406f5095479bba895 Author: Alexey Romanov <romanov.alexey2000@gmail.com> crypto: amlogic - Move algs definition and cipher API to cipher.c This commit moves the skcipher algorithm templates and cipher registration helpers into amlogic-gxl-cipher.c, making the cipher callback functions static. [Severity: Low] In drivers/crypto/amlogic/amlogic-gxl-cipher.c (line 276) and drivers/crypto/amlogic/amlogic-gxl.h (line 172), should meson_handle_cipher_request() also be made static and have its declaration removed from amlogic-gxl.h? Like the other cipher callbacks, it is only referenced by the algs[] array in amlogic-gxl-cipher.c. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261127120103.1532882-1-jnieto.alaber@gmail.com?part=9 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v14 10/30] crypto: amlogic - Cleanup defines 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (8 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 09/30] crypto: amlogic - Move algs definition and cipher API to cipher.c Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 11/30] crypto: amlogic - Process more than MAXDESCS descriptors Jose Nieto ` (19 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> It is bad to use hardcoded values directly in the code. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 24 ++++++++++----------- drivers/crypto/amlogic/amlogic-gxl.h | 16 ++++++++------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index 00d3247ebea1..c17ce5cc70a8 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -141,8 +141,8 @@ static int meson_cipher(struct skcipher_request *areq) ivsize, 0); } } - if (keyivlen == 24) - keyivlen = 32; + if (keyivlen == AES_KEYSIZE_192) + keyivlen = AES_MAX_KEY_SIZE; phykeyiv = dma_map_single(mc->dev, bkeyiv, keyivlen, DMA_TO_DEVICE); @@ -161,7 +161,7 @@ static int meson_cipher(struct skcipher_request *areq) todo = min(keyivlen - eat, 16u); desc->t_src = cpu_to_le32(phykeyiv + i * 16); desc->t_dst = cpu_to_le32(i * 16); - v = (MODE_KEY << 20) | DESC_OWN | 16; + v = DESC_MODE_KEY | DESC_OWN | 16; desc->t_status = cpu_to_le32(v); eat += todo; @@ -214,7 +214,7 @@ static int meson_cipher(struct skcipher_request *areq) desc->t_src = cpu_to_le32(sg_dma_address(src_sg)); desc->t_dst = cpu_to_le32(sg_dma_address(dst_sg)); todo = min(len, sg_dma_len(src_sg)); - v = (op->keymode << 20) | DESC_OWN | todo | (algt->blockmode << 26); + v = op->keymode | DESC_OWN | todo | algt->blockmode; if (rctx->op_dir) v |= DESC_ENCRYPTION; len -= todo; @@ -363,14 +363,14 @@ static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, struct meson_dev *mc = op->mc; switch (keylen) { - case 128 / 8: - op->keymode = MODE_AES_128; + case AES_KEYSIZE_128: + op->keymode = DESC_MODE_AES_128; break; - case 192 / 8: - op->keymode = MODE_AES_192; + case AES_KEYSIZE_192: + op->keymode = DESC_MODE_AES_192; break; - case 256 / 8: - op->keymode = MODE_AES_256; + case AES_KEYSIZE_256: + op->keymode = DESC_MODE_AES_256; break; default: dev_dbg(mc->dev, "ERROR: Invalid keylen %u\n", keylen); @@ -388,7 +388,7 @@ static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, static struct meson_alg_template algs[] = { { .type = CRYPTO_ALG_TYPE_SKCIPHER, - .blockmode = MESON_OPMODE_CBC, + .blockmode = DESC_OPMODE_CBC, .alg.skcipher.base = { .base = { .cra_name = "cbc(aes)", @@ -417,7 +417,7 @@ static struct meson_alg_template algs[] = { }, { .type = CRYPTO_ALG_TYPE_SKCIPHER, - .blockmode = MESON_OPMODE_ECB, + .blockmode = DESC_OPMODE_ECB, .alg.skcipher.base = { .base = { .cra_name = "ecb(aes)", diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index 608ce75f027a..15b4335942d5 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -11,19 +11,21 @@ #include <linux/crypto.h> #include <linux/scatterlist.h> -#define MODE_KEY 1 -#define MODE_AES_128 0x8 -#define MODE_AES_192 0x9 -#define MODE_AES_256 0xa - #define MESON_DECRYPT 0 #define MESON_ENCRYPT 1 -#define MESON_OPMODE_ECB 0 -#define MESON_OPMODE_CBC 1 +#define DESC_MODE_KEY (0x1 << 20) +#define DESC_MODE_AES_128 (0x8 << 20) +#define DESC_MODE_AES_192 (0x9 << 20) +#define DESC_MODE_AES_256 (0xa << 20) #define MAXDESC 64 +#define DESC_OPMODE_ECB (0 << 26) +#define DESC_OPMODE_CBC (1 << 26) + +#define DESC_MAXLEN GENMASK(16, 0) + #define DESC_LAST BIT(18) #define DESC_ENCRYPTION BIT(28) #define DESC_OWN BIT(31) -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 11/30] crypto: amlogic - Process more than MAXDESCS descriptors 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (9 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 10/30] crypto: amlogic - Cleanup defines Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:13 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 12/30] crypto: amlogic - Avoid kzalloc in engine thread Jose Nieto ` (18 subsequent siblings) 29 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> 1. The old alhorithm was not designed to process a large amount of memory, and therefore gave incorrect results. 2. Not all Amlogic SoC's use 3 KEY/IV descriptors. Add keyiv descriptors count parameter to platform data. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 459 ++++++++++++-------- drivers/crypto/amlogic/amlogic-gxl-core.c | 1 + drivers/crypto/amlogic/amlogic-gxl.h | 2 + 3 files changed, 283 insertions(+), 179 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index c17ce5cc70a8..cb6b959bb1f9 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -17,35 +17,41 @@ #include <crypto/internal/skcipher.h> #include "amlogic-gxl.h" -static bool meson_cipher_need_fallback(struct skcipher_request *areq) +static bool meson_cipher_need_fallback_sg(struct skcipher_request *areq, + struct scatterlist *sg) { - struct scatterlist *src_sg = areq->src; - struct scatterlist *dst_sg = areq->dst; + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); + unsigned int blocksize = crypto_skcipher_blocksize(tfm); + unsigned int cryptlen = areq->cryptlen; + + while (cryptlen) { + unsigned int len = min(cryptlen, sg->length); + + if (!IS_ALIGNED(sg->offset, sizeof(u32))) + return true; + if (len % blocksize != 0) + return true; + + cryptlen -= len; + sg = sg_next(sg); + } + + return false; +} +static bool meson_cipher_need_fallback(struct skcipher_request *areq) +{ if (areq->cryptlen == 0) return true; - if (sg_nents(src_sg) != sg_nents(dst_sg)) + if (meson_cipher_need_fallback_sg(areq, areq->src)) return true; - /* KEY/IV descriptors use 3 desc */ - if (sg_nents(src_sg) > MAXDESC - 3 || sg_nents(dst_sg) > MAXDESC - 3) - return true; + if (areq->dst == areq->src) + return false; - while (src_sg && dst_sg) { - if ((src_sg->length % 16) != 0) - return true; - if ((dst_sg->length % 16) != 0) - return true; - if (src_sg->length != dst_sg->length) - return true; - if (!IS_ALIGNED(src_sg->offset, sizeof(u32))) - return true; - if (!IS_ALIGNED(dst_sg->offset, sizeof(u32))) - return true; - src_sg = sg_next(src_sg); - dst_sg = sg_next(dst_sg); - } + if (meson_cipher_need_fallback_sg(areq, areq->dst)) + return true; return false; } @@ -76,6 +82,213 @@ static int meson_cipher_do_fallback(struct skcipher_request *areq) return err; } +struct cipher_ctx { + struct { + dma_addr_t addr; + unsigned int len; + } keyiv; + + struct skcipher_request *areq; + struct scatterlist *src_sg; + struct scatterlist *dst_sg; + void *bkeyiv; + + unsigned int src_offset; + unsigned int dst_offset; + unsigned int cryptlen; + unsigned int tloffset; +}; + +static int meson_map_scatterlist(struct skcipher_request *areq, struct meson_dev *mc) +{ + int nr_sgs, nr_sgd; + + if (areq->src == areq->dst) { + nr_sgs = dma_map_sg(mc->dev, areq->src, sg_nents(areq->src), + DMA_BIDIRECTIONAL); + if (!nr_sgs) { + dev_err(mc->dev, "Invalid SG count %d\n", nr_sgs); + return -EINVAL; + } + } else { + nr_sgs = dma_map_sg(mc->dev, areq->src, sg_nents(areq->src), + DMA_TO_DEVICE); + if (!nr_sgs) { + dev_err(mc->dev, "Invalid SG count %d\n", nr_sgs); + return -EINVAL; + } + + nr_sgd = dma_map_sg(mc->dev, areq->dst, sg_nents(areq->dst), + DMA_FROM_DEVICE); + if (!nr_sgd) { + dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE); + dev_err(mc->dev, "Invalid SG count %d\n", nr_sgd); + return -EINVAL; + } + } + + return 0; +} + +static void meson_unmap_scatterlist(struct skcipher_request *areq, struct meson_dev *mc) +{ + if (areq->src == areq->dst) { + dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_BIDIRECTIONAL); + } else { + dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE); + dma_unmap_sg(mc->dev, areq->dst, sg_nents(areq->dst), DMA_FROM_DEVICE); + } +} + +static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) +{ + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); + struct meson_alg_template *algt = container_of(alg, + struct meson_alg_template, alg.skcipher.base); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_dev *mc = op->mc; + unsigned int ivsize = crypto_skcipher_ivsize(tfm); + unsigned int blockmode = algt->blockmode; + int i; + + if (ctx->tloffset) + return; + + if (blockmode == DESC_OPMODE_CBC) { + memcpy(ctx->bkeyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); + dma_sync_single_for_device(mc->dev, ctx->keyiv.addr, + ctx->keyiv.len, DMA_TO_DEVICE); + } + + for (i = 0; i < mc->pdata->setup_desc_cnt; i++) { + struct meson_desc *desc = + &mc->chanlist[rctx->flow].tl[ctx->tloffset]; + int offset = i * 16; + + desc->t_src = cpu_to_le32(ctx->keyiv.addr + offset); + desc->t_dst = cpu_to_le32(offset); + desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | ctx->keyiv.len); + + ctx->tloffset++; + } +} + +static bool meson_setup_data_descs(struct cipher_ctx *ctx) +{ + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); + struct meson_alg_template *algt = container_of(alg, + struct meson_alg_template, + alg.skcipher.base); + struct meson_dev *mc = op->mc; + struct meson_desc *desc = &mc->chanlist[rctx->flow].tl[ctx->tloffset]; + unsigned int blocksize = crypto_skcipher_blocksize(tfm); + unsigned int blockmode = algt->blockmode; + unsigned int maxlen = rounddown(DESC_MAXLEN, blocksize); + unsigned int todo; + u32 v; + + ctx->tloffset++; + + todo = min(ctx->cryptlen, maxlen); + todo = min(todo, ctx->cryptlen); + todo = min(todo, sg_dma_len(ctx->src_sg) - ctx->src_offset); + todo = min(todo, sg_dma_len(ctx->dst_sg) - ctx->dst_offset); + + desc->t_src = cpu_to_le32(sg_dma_address(ctx->src_sg) + ctx->src_offset); + desc->t_dst = cpu_to_le32(sg_dma_address(ctx->dst_sg) + ctx->dst_offset); + + ctx->cryptlen -= todo; + ctx->src_offset += todo; + ctx->dst_offset += todo; + + v = DESC_OWN | blockmode | op->keymode | todo; + if (rctx->op_dir == MESON_ENCRYPT) + v |= DESC_ENCRYPTION; + + if (!ctx->cryptlen || ctx->tloffset == MAXDESC) + v |= DESC_LAST; + + desc->t_status = cpu_to_le32(v); + + return v & DESC_LAST; +} + +static int meson_kick_hardware(struct cipher_ctx *ctx) +{ + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); + struct meson_alg_template *algt = container_of(alg, + struct meson_alg_template, + alg.skcipher.base); + struct meson_dev *mc = op->mc; + unsigned int ivsize = crypto_skcipher_ivsize(tfm); + unsigned int blockmode = algt->blockmode; + enum dma_data_direction new_iv_dir; + struct scatterlist *sg_head; + void *new_iv; + int err; + + if (blockmode == DESC_OPMODE_CBC) { + struct scatterlist *sg_current; + unsigned int offset; + + if (rctx->op_dir == MESON_ENCRYPT) { + sg_current = ctx->dst_sg; + sg_head = ctx->areq->dst; + offset = ctx->dst_offset; + new_iv_dir = DMA_FROM_DEVICE; + } else { + sg_current = ctx->src_sg; + sg_head = ctx->areq->src; + offset = ctx->src_offset; + new_iv_dir = DMA_TO_DEVICE; + } + + if (ctx->areq->src == ctx->areq->dst) + new_iv_dir = DMA_BIDIRECTIONAL; + + offset -= ivsize; + new_iv = sg_virt(sg_current) + offset; + } + + if (blockmode == DESC_OPMODE_CBC && + rctx->op_dir == MESON_DECRYPT) { + dma_sync_sg_for_cpu(mc->dev, sg_head, + sg_nents(sg_head), new_iv_dir); + memcpy(ctx->areq->iv, new_iv, ivsize); + } + + reinit_completion(&mc->chanlist[rctx->flow].complete); + meson_dma_start(mc, rctx->flow); + err = wait_for_completion_interruptible_timeout(&mc->chanlist[rctx->flow].complete, + msecs_to_jiffies(500)); + if (err == 0) { + dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); + return -EINVAL; + } else if (err < 0) { + dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", err); + return err; + } + + if (blockmode == DESC_OPMODE_CBC && + rctx->op_dir == MESON_ENCRYPT) { + dma_sync_sg_for_cpu(mc->dev, sg_head, + sg_nents(sg_head), new_iv_dir); + memcpy(ctx->areq->iv, new_iv, ivsize); + } + + ctx->tloffset = 0; + + return 0; +} + static int meson_cipher(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); @@ -84,191 +297,79 @@ static int meson_cipher(struct skcipher_request *areq) struct meson_dev *mc = op->mc; struct skcipher_alg *alg = crypto_skcipher_alg(tfm); struct meson_alg_template *algt; - int flow = rctx->flow; - unsigned int todo, eat, len; - struct scatterlist *src_sg = areq->src; - struct scatterlist *dst_sg = areq->dst; - struct meson_desc *desc; - int nr_sgs, nr_sgd; - int i, err = 0; - unsigned int keyivlen, ivsize, offset, tloffset; - dma_addr_t phykeyiv; - void *backup_iv = NULL, *bkeyiv; - u32 v; - - algt = container_of(alg, struct meson_alg_template, alg.skcipher.base); + struct cipher_ctx ctx = { + .areq = areq, + .src_offset = 0, + .dst_offset = 0, + .src_sg = areq->src, + .dst_sg = areq->dst, + .cryptlen = areq->cryptlen, + }; + int err; - dev_dbg(mc->dev, "%s %s %u %x IV(%u) key=%u flow=%d\n", __func__, + dev_dbg(mc->dev, "%s %s %u %x IV(%u) key=%u ctx.flow=%d\n", __func__, crypto_tfm_alg_name(areq->base.tfm), areq->cryptlen, rctx->op_dir, crypto_skcipher_ivsize(tfm), - op->keylen, flow); + op->keylen, rctx->flow); + + algt = container_of(alg, struct meson_alg_template, alg.skcipher.base); #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG algt->stat_req++; - mc->chanlist[flow].stat_req++; + mc->chanlist[rctx->flow].stat_req++; #endif - /* - * The hardware expect a list of meson_desc structures. - * The 2 first structures store key - * The third stores IV - */ - bkeyiv = kzalloc(48, GFP_KERNEL | GFP_DMA); - if (!bkeyiv) + ctx.bkeyiv = kzalloc(48, GFP_KERNEL | GFP_DMA); + if (!ctx.bkeyiv) return -ENOMEM; - memcpy(bkeyiv, op->key, op->keylen); - keyivlen = op->keylen; - - ivsize = crypto_skcipher_ivsize(tfm); - if (areq->iv && ivsize > 0) { - if (ivsize > areq->cryptlen) { - dev_err(mc->dev, "invalid ivsize=%d vs len=%d\n", ivsize, areq->cryptlen); - err = -EINVAL; - goto theend; - } - memcpy(bkeyiv + 32, areq->iv, ivsize); - keyivlen = 48; - if (rctx->op_dir == MESON_DECRYPT) { - backup_iv = kzalloc(ivsize, GFP_KERNEL); - if (!backup_iv) { - err = -ENOMEM; - goto theend; - } - offset = areq->cryptlen - ivsize; - scatterwalk_map_and_copy(backup_iv, areq->src, offset, - ivsize, 0); - } - } - if (keyivlen == AES_KEYSIZE_192) - keyivlen = AES_MAX_KEY_SIZE; + memcpy(ctx.bkeyiv, op->key, op->keylen); + ctx.keyiv.len = op->keylen; + if (ctx.keyiv.len == AES_KEYSIZE_192) + ctx.keyiv.len = AES_MAX_KEY_SIZE; - phykeyiv = dma_map_single(mc->dev, bkeyiv, keyivlen, - DMA_TO_DEVICE); - err = dma_mapping_error(mc->dev, phykeyiv); + ctx.keyiv.addr = dma_map_single(mc->dev, ctx.bkeyiv, ctx.keyiv.len, + DMA_TO_DEVICE); + err = dma_mapping_error(mc->dev, ctx.keyiv.addr); if (err) { dev_err(mc->dev, "Cannot DMA MAP KEY IV\n"); - goto theend; + goto free_keyiv; } - tloffset = 0; - eat = 0; - i = 0; - while (keyivlen > eat) { - desc = &mc->chanlist[flow].tl[tloffset]; - memset(desc, 0, sizeof(struct meson_desc)); - todo = min(keyivlen - eat, 16u); - desc->t_src = cpu_to_le32(phykeyiv + i * 16); - desc->t_dst = cpu_to_le32(i * 16); - v = DESC_MODE_KEY | DESC_OWN | 16; - desc->t_status = cpu_to_le32(v); - - eat += todo; - i++; - tloffset++; - } + err = meson_map_scatterlist(areq, mc); + if (err) + goto unmap_keyiv; - if (areq->src == areq->dst) { - nr_sgs = dma_map_sg(mc->dev, areq->src, sg_nents(areq->src), - DMA_BIDIRECTIONAL); - if (!nr_sgs || nr_sgs > MAXDESC - 3) { - dev_err(mc->dev, "Invalid BIDIR SG count %d\n", nr_sgs); - err = -EINVAL; + ctx.tloffset = 0; - if (nr_sgs) - dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_BIDIRECTIONAL); - goto error_keyiv; - } - nr_sgd = nr_sgs; - } else { - nr_sgs = dma_map_sg(mc->dev, areq->src, sg_nents(areq->src), - DMA_TO_DEVICE); - if (!nr_sgs || nr_sgs > MAXDESC - 3) { - dev_err(mc->dev, "Invalid SG count %d\n", nr_sgs); - err = -EINVAL; + while (ctx.cryptlen) { + meson_setup_keyiv_descs(&ctx); - if (nr_sgs) - dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE); - goto error_keyiv; + if (meson_setup_data_descs(&ctx)) { + err = meson_kick_hardware(&ctx); + if (err) + break; } - nr_sgd = dma_map_sg(mc->dev, areq->dst, sg_nents(areq->dst), - DMA_FROM_DEVICE); - if (!nr_sgd || nr_sgd > MAXDESC - 3) { - dev_err(mc->dev, "Invalid SG count %d\n", nr_sgd); - err = -EINVAL; - if (nr_sgd) - dma_unmap_sg(mc->dev, areq->dst, sg_nents(areq->dst), DMA_FROM_DEVICE); - goto error_src; + if (ctx.src_offset == sg_dma_len(ctx.src_sg)) { + ctx.src_offset = 0; + ctx.src_sg = sg_next(ctx.src_sg); } - } - src_sg = areq->src; - dst_sg = areq->dst; - len = areq->cryptlen; - while (src_sg) { - desc = &mc->chanlist[flow].tl[tloffset]; - memset(desc, 0, sizeof(struct meson_desc)); - - desc->t_src = cpu_to_le32(sg_dma_address(src_sg)); - desc->t_dst = cpu_to_le32(sg_dma_address(dst_sg)); - todo = min(len, sg_dma_len(src_sg)); - v = op->keymode | DESC_OWN | todo | algt->blockmode; - if (rctx->op_dir) - v |= DESC_ENCRYPTION; - len -= todo; - - if (!sg_next(src_sg)) - v |= DESC_LAST; - desc->t_status = cpu_to_le32(v); - tloffset++; - src_sg = sg_next(src_sg); - dst_sg = sg_next(dst_sg); + if (ctx.dst_offset == sg_dma_len(ctx.dst_sg)) { + ctx.dst_offset = 0; + ctx.dst_sg = sg_next(ctx.dst_sg); + } } - reinit_completion(&mc->chanlist[flow].complete); - meson_dma_start(mc, flow); - - err = wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete, - msecs_to_jiffies(500)); - if (err == 0) { - dev_err(mc->dev, "DMA timeout for flow %d\n", flow); - err = -EINVAL; - } else if (err < 0) { - dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", err); - } else { - /* No error */ - err = 0; - } + meson_unmap_scatterlist(areq, mc); - dma_unmap_single(mc->dev, phykeyiv, keyivlen, DMA_TO_DEVICE); +unmap_keyiv: + dma_unmap_single(mc->dev, ctx.keyiv.addr, ctx.keyiv.len, DMA_TO_DEVICE); - if (areq->src == areq->dst) { - dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_BIDIRECTIONAL); - } else { - dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE); - dma_unmap_sg(mc->dev, areq->dst, sg_nents(areq->dst), DMA_FROM_DEVICE); - } - - if (areq->iv && ivsize > 0) { - if (rctx->op_dir == MESON_DECRYPT) { - memcpy(areq->iv, backup_iv, ivsize); - } else { - scatterwalk_map_and_copy(areq->iv, areq->dst, - areq->cryptlen - ivsize, - ivsize, 0); - } - } - goto theend; - -error_src: - dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE); -error_keyiv: - dma_unmap_single(mc->dev, phykeyiv, keyivlen, DMA_TO_DEVICE); -theend: - kfree_sensitive(bkeyiv); - kfree_sensitive(backup_iv); +free_keyiv: + kfree_sensitive(ctx.bkeyiv); return err; } diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 68d394e90f66..0e17105520df 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -255,6 +255,7 @@ static void meson_crypto_remove(struct platform_device *pdev) static const struct meson_pdata meson_gxl_pdata = { .descs_reg = 0x0, .status_reg = 0x4, + .setup_desc_cnt = 3, }; static const struct of_device_id meson_crypto_of_match_table[] = { diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index 15b4335942d5..6797b44905d3 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -82,10 +82,12 @@ struct meson_flow { * struct meson_pdata - SoC series dependent data. * @reg_descs: offset to descriptors register * @reg_status: offset to status register + * @setup_desc_cnt: number of setup descriptor to configure. */ struct meson_pdata { u32 descs_reg; u32 status_reg; + u32 setup_desc_cnt; }; /* -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v14 11/30] crypto: amlogic - Process more than MAXDESCS descriptors 2026-11-27 12:00 ` [PATCH v14 11/30] crypto: amlogic - Process more than MAXDESCS descriptors Jose Nieto @ 2026-11-27 12:13 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-27 12:13 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] crypto: amlogic: unmapped IV and bad keyiv DMA length in meson_cipher() - [High] crypto: amlogic: bad sg_virt() offset and DMA sync in meson_kick_hardware() -- commit 4d7b0e2239c95f15cc0e337acf98505c54b39ed1 Author: Alexey Romanov <romanov.alexey2000@gmail.com> crypto: amlogic - Process more than MAXDESCS descriptors This commit rewrites the Amlogic GXL cipher descriptor handling to split large skcipher requests across multiple hardware batches and makes the number of key/IV setup descriptors configurable via platform data. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c > index c17ce5cc70a87..cb6b959bb1f96 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c [ ... ] > +static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) > +{ > + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); > + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); > + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); > + struct meson_alg_template *algt = container_of(alg, > + struct meson_alg_template, alg.skcipher.base); > + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); > + struct meson_dev *mc = op->mc; > + unsigned int ivsize = crypto_skcipher_ivsize(tfm); > + unsigned int blockmode = algt->blockmode; > + int i; > + > + if (ctx->tloffset) > + return; > + > + if (blockmode == DESC_OPMODE_CBC) { > + memcpy(ctx->bkeyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); > + dma_sync_single_for_device(mc->dev, ctx->keyiv.addr, > + ctx->keyiv.len, DMA_TO_DEVICE); > + } > + > + for (i = 0; i < mc->pdata->setup_desc_cnt; i++) { > + struct meson_desc *desc = > + &mc->chanlist[rctx->flow].tl[ctx->tloffset]; > + int offset = i * 16; > + > + desc->t_src = cpu_to_le32(ctx->keyiv.addr + offset); > + desc->t_dst = cpu_to_le32(offset); > + desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | ctx->keyiv.len); > + > + ctx->tloffset++; > + } > +} [Severity: High] Does meson_setup_keyiv_descs() leave the CBC IV outside the DMA mapping and program each setup descriptor with ctx->keyiv.len instead of 16 bytes? In meson_cipher(), ctx.keyiv.len is set to op->keylen (or AES_MAX_KEY_SIZE for AES-192), so dma_map_single() and dma_sync_single_for_device() only cover the first 16 or 32 bytes of ctx.bkeyiv and never map or flush the CBC IV copied to offset 32 (AES_MAX_KEY_SIZE). In addition, setting each of the setup_desc_cnt descriptors at offset = i * 16 to transfer ctx->keyiv.len bytes causes descriptors i > 0 to DMA-read outside the mapped range and up to offset 64, which is 16 bytes past the end of the 48-byte ctx.bkeyiv buffer. Later commits in this series ("crypto: amlogic - Avoid kzalloc in engine thread" and "crypto: amlogic: fix setup descriptor lengths and CBC IV copy") partially adjust this, but still leave ECB mode mapping 16 or 32 bytes while issuing 3 descriptors of length ctx->keyiv.len / 3 (5 or 10 bytes instead of 16) up to offset 32, and remove the IV update in meson_setup_keyiv_descs() needed between multi-batch CBC kicks. > +static bool meson_setup_data_descs(struct cipher_ctx *ctx) > +{ > + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); > + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); > + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); > + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); > + struct meson_alg_template *algt = container_of(alg, > + struct meson_alg_template, > + alg.skcipher.base); > + struct meson_dev *mc = op->mc; > + struct meson_desc *desc = &mc->chanlist[rctx->flow].tl[ctx->tloffset]; > + unsigned int blocksize = crypto_skcipher_blocksize(tfm); > + unsigned int blockmode = algt->blockmode; > + unsigned int maxlen = rounddown(DESC_MAXLEN, blocksize); > + unsigned int todo; > + u32 v; > + > + ctx->tloffset++; > + > + todo = min(ctx->cryptlen, maxlen); > + todo = min(todo, ctx->cryptlen); > + todo = min(todo, sg_dma_len(ctx->src_sg) - ctx->src_offset); > + todo = min(todo, sg_dma_len(ctx->dst_sg) - ctx->dst_offset); > + > + desc->t_src = cpu_to_le32(sg_dma_address(ctx->src_sg) + ctx->src_offset); > + desc->t_dst = cpu_to_le32(sg_dma_address(ctx->dst_sg) + ctx->dst_offset); > + > + ctx->cryptlen -= todo; > + ctx->src_offset += todo; > + ctx->dst_offset += todo; > + > + v = DESC_OWN | blockmode | op->keymode | todo; > + if (rctx->op_dir == MESON_ENCRYPT) > + v |= DESC_ENCRYPTION; > + > + if (!ctx->cryptlen || ctx->tloffset == MAXDESC) > + v |= DESC_LAST; > + > + desc->t_status = cpu_to_le32(v); > + > + return v & DESC_LAST; > +} > + > +static int meson_kick_hardware(struct cipher_ctx *ctx) > +{ > + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); > + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); > + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); > + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); > + struct meson_alg_template *algt = container_of(alg, > + struct meson_alg_template, > + alg.skcipher.base); > + struct meson_dev *mc = op->mc; > + unsigned int ivsize = crypto_skcipher_ivsize(tfm); > + unsigned int blockmode = algt->blockmode; > + enum dma_data_direction new_iv_dir; > + struct scatterlist *sg_head; > + void *new_iv; > + int err; > + > + if (blockmode == DESC_OPMODE_CBC) { > + struct scatterlist *sg_current; > + unsigned int offset; > + > + if (rctx->op_dir == MESON_ENCRYPT) { > + sg_current = ctx->dst_sg; > + sg_head = ctx->areq->dst; > + offset = ctx->dst_offset; > + new_iv_dir = DMA_FROM_DEVICE; > + } else { > + sg_current = ctx->src_sg; > + sg_head = ctx->areq->src; > + offset = ctx->src_offset; > + new_iv_dir = DMA_TO_DEVICE; > + } > + > + if (ctx->areq->src == ctx->areq->dst) > + new_iv_dir = DMA_BIDIRECTIONAL; > + > + offset -= ivsize; > + new_iv = sg_virt(sg_current) + offset; > + } > + > + if (blockmode == DESC_OPMODE_CBC && > + rctx->op_dir == MESON_DECRYPT) { > + dma_sync_sg_for_cpu(mc->dev, sg_head, > + sg_nents(sg_head), new_iv_dir); > + memcpy(ctx->areq->iv, new_iv, ivsize); > + } > + > + reinit_completion(&mc->chanlist[rctx->flow].complete); > + meson_dma_start(mc, rctx->flow); > + err = wait_for_completion_interruptible_timeout(&mc->chanlist[rctx->flow].complete, > + msecs_to_jiffies(500)); > + if (err == 0) { > + dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); > + return -EINVAL; > + } else if (err < 0) { > + dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", err); > + return err; > + } > + > + if (blockmode == DESC_OPMODE_CBC && > + rctx->op_dir == MESON_ENCRYPT) { > + dma_sync_sg_for_cpu(mc->dev, sg_head, > + sg_nents(sg_head), new_iv_dir); > + memcpy(ctx->areq->iv, new_iv, ivsize); > + } [Severity: High] Can computing new_iv as sg_virt(sg_current) + offset read past the end of sg_current's page when dma_map_sg() coalesces scatterlist entries? meson_setup_data_descs() and meson_cipher() advance ctx->src_offset and ctx->dst_offset using sg_dma_len(), which can exceed sg_current->length when adjacent entries are merged by dma_map_sg(). Indexing sg_virt(sg_current) by that DMA segment offset reads outside sg_current's virtual buffer (or from the wrong scatterlist entry after coalesced segments). Also, meson_kick_hardware() calls dma_sync_sg_for_cpu() over the entire scatterlist (walking sg_nents(sg_head) on every batch) to read new_iv without a matching dma_sync_sg_for_device() before meson_dma_start() on decrypt or before the next batch's meson_dma_start() on multi-batch encrypt, leaving dirty or stale CPU cache lines across the DMA transfer. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261127120103.1532882-1-jnieto.alaber@gmail.com?part=11 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v14 12/30] crypto: amlogic - Avoid kzalloc in engine thread 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (10 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 11/30] crypto: amlogic - Process more than MAXDESCS descriptors Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:18 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 13/30] crypto: amlogic - Introduce hasher Jose Nieto ` (17 subsequent siblings) 29 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> It makes no sense to allocate memory via kzalloc, we can use static buffer, speedup data processing and don't think about kfree() calls. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 60 ++++++++++----------- drivers/crypto/amlogic/amlogic-gxl.h | 4 +- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index cb6b959bb1f9..df42940f1112 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -59,7 +59,7 @@ static bool meson_cipher_need_fallback(struct skcipher_request *areq) static int meson_cipher_do_fallback(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(areq); int err; #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG @@ -91,7 +91,6 @@ struct cipher_ctx { struct skcipher_request *areq; struct scatterlist *src_sg; struct scatterlist *dst_sg; - void *bkeyiv; unsigned int src_offset; unsigned int dst_offset; @@ -147,7 +146,7 @@ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) struct skcipher_alg *alg = crypto_skcipher_alg(tfm); struct meson_alg_template *algt = container_of(alg, struct meson_alg_template, alg.skcipher.base); - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct meson_dev *mc = op->mc; unsigned int ivsize = crypto_skcipher_ivsize(tfm); unsigned int blockmode = algt->blockmode; @@ -157,7 +156,7 @@ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) return; if (blockmode == DESC_OPMODE_CBC) { - memcpy(ctx->bkeyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); + memcpy(op->keyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); dma_sync_single_for_device(mc->dev, ctx->keyiv.addr, ctx->keyiv.len, DMA_TO_DEVICE); } @@ -179,7 +178,7 @@ static bool meson_setup_data_descs(struct cipher_ctx *ctx) { struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct skcipher_alg *alg = crypto_skcipher_alg(tfm); struct meson_alg_template *algt = container_of(alg, struct meson_alg_template, @@ -222,7 +221,7 @@ static int meson_kick_hardware(struct cipher_ctx *ctx) { struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct skcipher_alg *alg = crypto_skcipher_alg(tfm); struct meson_alg_template *algt = container_of(alg, struct meson_alg_template, @@ -292,7 +291,7 @@ static int meson_kick_hardware(struct cipher_ctx *ctx) static int meson_cipher(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(areq); struct meson_dev *mc = op->mc; struct skcipher_alg *alg = crypto_skcipher_alg(tfm); @@ -305,6 +304,7 @@ static int meson_cipher(struct skcipher_request *areq) .dst_sg = areq->dst, .cryptlen = areq->cryptlen, }; + unsigned int ivsize = crypto_skcipher_ivsize(tfm); int err; dev_dbg(mc->dev, "%s %s %u %x IV(%u) key=%u ctx.flow=%d\n", __func__, @@ -320,21 +320,21 @@ static int meson_cipher(struct skcipher_request *areq) mc->chanlist[rctx->flow].stat_req++; #endif - ctx.bkeyiv = kzalloc(48, GFP_KERNEL | GFP_DMA); - if (!ctx.bkeyiv) - return -ENOMEM; - - memcpy(ctx.bkeyiv, op->key, op->keylen); ctx.keyiv.len = op->keylen; if (ctx.keyiv.len == AES_KEYSIZE_192) ctx.keyiv.len = AES_MAX_KEY_SIZE; - ctx.keyiv.addr = dma_map_single(mc->dev, ctx.bkeyiv, ctx.keyiv.len, + if (algt->blockmode == DESC_OPMODE_CBC) { + memcpy(op->keyiv + AES_MAX_KEY_SIZE, areq->iv, ivsize); + ctx.keyiv.len = AES_MAX_KEY_SIZE + ivsize; + } + + ctx.keyiv.addr = dma_map_single(mc->dev, op->keyiv, ctx.keyiv.len, DMA_TO_DEVICE); err = dma_mapping_error(mc->dev, ctx.keyiv.addr); if (err) { dev_err(mc->dev, "Cannot DMA MAP KEY IV\n"); - goto free_keyiv; + return err; } err = meson_map_scatterlist(areq, mc); @@ -368,9 +368,6 @@ static int meson_cipher(struct skcipher_request *areq) unmap_keyiv: dma_unmap_single(mc->dev, ctx.keyiv.addr, ctx.keyiv.len, DMA_TO_DEVICE); -free_keyiv: - kfree_sensitive(ctx.bkeyiv); - return err; } @@ -390,7 +387,7 @@ int meson_handle_cipher_request(struct crypto_engine *engine, void *areq) static int meson_skdecrypt(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(areq); struct crypto_engine *engine; int e; @@ -408,7 +405,7 @@ static int meson_skdecrypt(struct skcipher_request *areq) static int meson_skencrypt(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(areq); struct crypto_engine *engine; int e; @@ -425,7 +422,7 @@ static int meson_skencrypt(struct skcipher_request *areq) static int meson_cipher_init(struct crypto_tfm *tfm) { - struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx_dma(tfm); struct meson_alg_template *algt; const char *name = crypto_tfm_alg_name(tfm); struct crypto_skcipher *sktfm = __crypto_skcipher_cast(tfm); @@ -443,7 +440,7 @@ static int meson_cipher_init(struct crypto_tfm *tfm) return PTR_ERR(op->fallback_tfm); } - crypto_skcipher_set_reqsize(sktfm, sizeof(struct meson_cipher_req_ctx) + + crypto_skcipher_set_reqsize_dma(sktfm, sizeof(struct meson_cipher_req_ctx) + crypto_skcipher_reqsize(op->fallback_tfm)); return 0; @@ -451,16 +448,15 @@ static int meson_cipher_init(struct crypto_tfm *tfm) static void meson_cipher_exit(struct crypto_tfm *tfm) { - struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx_dma(tfm); - kfree_sensitive(op->key); crypto_free_skcipher(op->fallback_tfm); } static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen) { - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct meson_dev *mc = op->mc; switch (keylen) { @@ -477,11 +473,9 @@ static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, dev_dbg(mc->dev, "ERROR: Invalid keylen %u\n", keylen); return -EINVAL; } - kfree_sensitive(op->key); + + memcpy(op->keyiv, key, keylen); op->keylen = keylen; - op->key = kmemdup(key, keylen, GFP_KERNEL | GFP_DMA); - if (!op->key) - return -ENOMEM; return crypto_skcipher_setkey(op->fallback_tfm, key, keylen); } @@ -499,7 +493,6 @@ static struct meson_alg_template algs[] = { .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | CRYPTO_ALG_NEED_FALLBACK, - .cra_ctxsize = sizeof(struct meson_cipher_tfm_ctx), .cra_module = THIS_MODULE, .cra_alignmask = 0xf, .cra_init = meson_cipher_init, @@ -528,7 +521,6 @@ static struct meson_alg_template algs[] = { .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | CRYPTO_ALG_NEED_FALLBACK, - .cra_ctxsize = sizeof(struct meson_cipher_tfm_ctx), .cra_module = THIS_MODULE, .cra_alignmask = 0xf, .cra_init = meson_cipher_init, @@ -548,6 +540,14 @@ static struct meson_alg_template algs[] = { int meson_cipher_register(struct meson_dev *mc) { + int i; + + for (i = 0; i < ARRAY_SIZE(algs); i++) { + struct skcipher_alg *alg = &algs[i].alg.skcipher.base; + + alg->base.cra_ctxsize = sizeof(struct meson_cipher_tfm_ctx) + crypto_dma_padding(); + } + return meson_register_algs(mc, algs, ARRAY_SIZE(algs)); } diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index 6797b44905d3..c401cbbadaa3 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -125,14 +125,14 @@ struct meson_cipher_req_ctx { /* * struct meson_cipher_tfm_ctx - context for a skcipher TFM - * @key: pointer to key data + * @keyiv: key data * @keylen: len of the key * @keymode: The keymode(type and size of key) associated with this TFM * @mc: pointer to the private data of driver handling this TFM * @fallback_tfm: pointer to the fallback TFM */ struct meson_cipher_tfm_ctx { - u32 *key; + u8 keyiv[AES_MAX_KEY_SIZE + AES_BLOCK_SIZE]; u32 keylen; u32 keymode; struct meson_dev *mc; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v14 12/30] crypto: amlogic - Avoid kzalloc in engine thread 2026-11-27 12:00 ` [PATCH v14 12/30] crypto: amlogic - Avoid kzalloc in engine thread Jose Nieto @ 2026-11-27 12:18 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-27 12:18 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] crypto: amlogic: shared TFM keyiv buffer races across concurrent requests - [Medium] crypto: amlogic: keyiv DMA length mismatch in meson_cipher() - [Low] crypto: amlogic: unused DMA reqsize padding in meson_cipher_init() - [Low] crypto: amlogic: stale trailing key bytes on re-key in meson_aes_setkey() -- commit c0d41dfd052dda605b64b5392f2c86747ef3d026 Author: Alexey Romanov <romanov.alexey2000@gmail.com> crypto: amlogic - Avoid kzalloc in engine thread This commit replaces the per-request dynamically allocated key and IV buffer with a fixed keyiv buffer in struct meson_cipher_tfm_ctx and switches the transform context to DMA-aligned crypto helpers. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c > index cb6b959bb1f96..df42940f1112a 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c [ ... ] > @@ -147,17 +146,17 @@ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) > struct skcipher_alg *alg = crypto_skcipher_alg(tfm); > struct meson_alg_template *algt = container_of(alg, > struct meson_alg_template, alg.skcipher.base); > - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); > + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); > struct meson_dev *mc = op->mc; > unsigned int ivsize = crypto_skcipher_ivsize(tfm); > unsigned int blockmode = algt->blockmode; > int i; > > if (ctx->tloffset) > return; > > if (blockmode == DESC_OPMODE_CBC) { > - memcpy(ctx->bkeyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); > + memcpy(op->keyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); > dma_sync_single_for_device(mc->dev, ctx->keyiv.addr, > ctx->keyiv.len, DMA_TO_DEVICE); > } [ ... ] > @@ -320,21 +320,21 @@ static int meson_cipher(struct skcipher_request *areq) > mc->chanlist[rctx->flow].stat_req++; > #endif > > - ctx.bkeyiv = kzalloc(48, GFP_KERNEL | GFP_DMA); > - if (!ctx.bkeyiv) > - return -ENOMEM; > - > - memcpy(ctx.bkeyiv, op->key, op->keylen); > ctx.keyiv.len = op->keylen; > if (ctx.keyiv.len == AES_KEYSIZE_192) > ctx.keyiv.len = AES_MAX_KEY_SIZE; > > - ctx.keyiv.addr = dma_map_single(mc->dev, ctx.bkeyiv, ctx.keyiv.len, > + if (algt->blockmode == DESC_OPMODE_CBC) { > + memcpy(op->keyiv + AES_MAX_KEY_SIZE, areq->iv, ivsize); > + ctx.keyiv.len = AES_MAX_KEY_SIZE + ivsize; > + } > + > + ctx.keyiv.addr = dma_map_single(mc->dev, op->keyiv, ctx.keyiv.len, > DMA_TO_DEVICE); > err = dma_mapping_error(mc->dev, ctx.keyiv.addr); > if (err) { > dev_err(mc->dev, "Cannot DMA MAP KEY IV\n"); > - goto free_keyiv; > + return err; > } [Severity: High] Can two concurrent CBC requests sharing a crypto_skcipher transform race on op->keyiv? meson_skencrypt() and meson_skdecrypt() dispatch requests round-robin across mc->flow_cnt independent crypto_engine worker threads via meson_get_engine_number(). Because op is per-transform, two requests on the same transform can run meson_cipher() in parallel on different engine threads: flow 0 kworker flow 1 kworker meson_cipher(req0) memcpy(op->keyiv + 32, req0->iv, ivsize) dma_map_single(..., op->keyiv, ...) meson_cipher(req1) memcpy(op->keyiv + 32, req1->iv, ivsize) <-- overwrites IV dma_map_single(..., op->keyiv, ...) meson_kick_hardware() dma_unmap_single(...) meson_kick_hardware() <-- DMA on unmapped or corrupted IV Moving the mutable per-request DMA buffer into struct meson_cipher_req_ctx (or per-channel storage) would avoid sharing it across concurrent requests. [Severity: Medium] Does ctx.keyiv.len match the descriptors programmed in meson_setup_keyiv_descs()? In ECB mode, ctx.keyiv.len remains 16 (AES-128) or 32 (AES-192/256), and only ctx.keyiv.len bytes of op->keyiv are mapped with dma_map_single(). meson_setup_keyiv_descs() then unconditionally emits mc->pdata->setup_desc_cnt (3 on GXL and AXG) descriptors at offsets 0, 16, and 32, each transferring ctx->keyiv.len bytes: drivers/crypto/amlogic/amlogic-gxl-cipher.c:meson_setup_keyiv_descs() { ... for (i = 0; i < mc->pdata->setup_desc_cnt; i++) { struct meson_desc *desc = &mc->chanlist[rctx->flow].tl[ctx->tloffset]; int offset = i * 16; desc->t_src = cpu_to_le32(ctx->keyiv.addr + offset); desc->t_dst = cpu_to_le32(offset); desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | ctx->keyiv.len); ctx->tloffset++; } } At this commit, descriptors at offsets 16 and 32 read past the DMA mapping and past the 48-byte op->keyiv buffer. Even with the later commit "crypto: amlogic: fix setup descriptor lengths and CBC IV copy" in this series changing the descriptor length to ctx->keyiv.len / mc->pdata->setup_desc_cnt, ECB mode on GXL and AXG still divides 16 or 32 by 3 (truncating each descriptor length to 5 or 10 bytes) and accesses offsets up to 32 beyond a 16- or 32-byte DMA mapping. [ ... ] > @@ -425,42 +422,39 @@ static int meson_skencrypt(struct skcipher_request *areq) > > static int meson_cipher_init(struct crypto_tfm *tfm) > { > - struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm); > + struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx_dma(tfm); > struct meson_alg_template *algt; > const char *name = crypto_tfm_alg_name(tfm); > struct crypto_skcipher *sktfm = __crypto_skcipher_cast(tfm); > @@ -443,7 +440,7 @@ static int meson_cipher_init(struct crypto_tfm *tfm) > return PTR_ERR(op->fallback_tfm); > } > > - crypto_skcipher_set_reqsize(sktfm, sizeof(struct meson_cipher_req_ctx) + > + crypto_skcipher_set_reqsize_dma(sktfm, sizeof(struct meson_cipher_req_ctx) + > crypto_skcipher_reqsize(op->fallback_tfm)); > > return 0; > } [Severity: Low] Why use crypto_skcipher_set_reqsize_dma() here when struct meson_cipher_req_ctx holds no DMA buffers and every caller still retrieves it via skcipher_request_ctx() rather than skcipher_request_ctx_dma()? [ ... ] > static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, > unsigned int keylen) > { > - struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); > + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); > struct meson_dev *mc = op->mc; > > switch (keylen) { > @@ -477,11 +473,9 @@ static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, > dev_dbg(mc->dev, "ERROR: Invalid keylen %u\n", keylen); > return -EINVAL; > } > - kfree_sensitive(op->key); > + > + memcpy(op->keyiv, key, keylen); > op->keylen = keylen; > - op->key = kmemdup(key, keylen, GFP_KERNEL | GFP_DMA); > - if (!op->key) > - return -ENOMEM; > > return crypto_skcipher_setkey(op->fallback_tfm, key, keylen); > } [Severity: Low] If a transform is keyed with AES-256 and later re-keyed with AES-128 or AES-192, does op->keyiv retain stale key bytes in op->keyiv[keylen..AES_MAX_KEY_SIZE - 1]? Previously kzalloc() zeroed the 48-byte buffer on each request. Now op->keyiv is only zeroed in meson_cipher_init(), so re-keying with a shorter key leaves the old trailing bytes in place when meson_cipher() maps AES_MAX_KEY_SIZE (for AES-192) or AES_MAX_KEY_SIZE + ivsize (for CBC). -- Sashiko AI review · https://sashiko.dev/#/patchset/20261127120103.1532882-1-jnieto.alaber@gmail.com?part=12 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v14 13/30] crypto: amlogic - Introduce hasher 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (11 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 12/30] crypto: amlogic - Avoid kzalloc in engine thread Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:24 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 14/30] crypto: amlogic - Use fallback for 192-bit keys Jose Nieto ` (16 subsequent siblings) 29 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Introduce support for SHA1/SHA224/SHA256 hash algos. Tested via tcrypt and custom tests. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/Makefile | 2 +- drivers/crypto/amlogic/amlogic-gxl-core.c | 25 +- drivers/crypto/amlogic/amlogic-gxl-hasher.c | 485 ++++++++++++++++++++ drivers/crypto/amlogic/amlogic-gxl.h | 48 ++ 4 files changed, 558 insertions(+), 2 deletions(-) create mode 100644 drivers/crypto/amlogic/amlogic-gxl-hasher.c diff --git a/drivers/crypto/amlogic/Makefile b/drivers/crypto/amlogic/Makefile index 39057e62c13e..4b6b388b7880 100644 --- a/drivers/crypto/amlogic/Makefile +++ b/drivers/crypto/amlogic/Makefile @@ -1,2 +1,2 @@ obj-$(CONFIG_CRYPTO_DEV_AMLOGIC_GXL) += amlogic-gxl-crypto.o -amlogic-gxl-crypto-y := amlogic-gxl-core.o amlogic-gxl-cipher.o +amlogic-gxl-crypto-y := amlogic-gxl-core.o amlogic-gxl-cipher.o amlogic-gxl-hasher.o diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 0e17105520df..9676b86a5089 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -19,6 +19,9 @@ #include <linux/of.h> #include <linux/of_device.h> #include <linux/platform_device.h> +#include <crypto/internal/skcipher.h> +#include <crypto/internal/hash.h> +#include <linux/dma-mapping.h> #include "amlogic-gxl.h" @@ -172,6 +175,15 @@ int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *algs, return err; } break; + case CRYPTO_ALG_TYPE_AHASH: + err = crypto_engine_register_ahash(&algs[i].alg.ahash); + if (err) { + dev_err(mc->dev, "Fail to register %s\n", + algs[i].alg.ahash.base.halg.base.cra_name); + meson_unregister_algs(mc, algs, count); + return err; + } + break; } } @@ -190,6 +202,9 @@ void meson_unregister_algs(struct meson_dev *mc, struct meson_alg_template *algs case CRYPTO_ALG_TYPE_SKCIPHER: crypto_engine_unregister_skcipher(&algs[i].alg.skcipher); break; + case CRYPTO_ALG_TYPE_AHASH: + crypto_engine_unregister_ahash(&algs[i].alg.ahash); + break; } } } @@ -227,13 +242,20 @@ static int meson_crypto_probe(struct platform_device *pdev) dbgfs_dir = debugfs_create_dir("gxl-crypto", NULL); debugfs_create_file("stats", 0444, dbgfs_dir, mc, &meson_debugfs_fops); - #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG mc->dbgfs_dir = dbgfs_dir; #endif } + err = meson_hasher_register(mc); + if (err) + goto error_hasher; + return 0; + +error_hasher: + meson_cipher_unregister(mc); + error_flow: meson_free_chanlist(mc, mc->flow_cnt - 1); return err; @@ -256,6 +278,7 @@ static const struct meson_pdata meson_gxl_pdata = { .descs_reg = 0x0, .status_reg = 0x4, .setup_desc_cnt = 3, + .hasher_supported = false, }; static const struct of_device_id meson_crypto_of_match_table[] = { diff --git a/drivers/crypto/amlogic/amlogic-gxl-hasher.c b/drivers/crypto/amlogic/amlogic-gxl-hasher.c new file mode 100644 index 000000000000..c83739ec3456 --- /dev/null +++ b/drivers/crypto/amlogic/amlogic-gxl-hasher.c @@ -0,0 +1,485 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Hardware asynchronous hasher for Amlogic SoC's. + * + * Author: Alexey Romanov <romanov.alexey2000@gmail.com> + */ + +#include <linux/crypto.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/err.h> +#include <crypto/internal/hash.h> +#include <crypto/sha1.h> +#include <crypto/sha2.h> + +#include "amlogic-gxl.h" + +static int meson_sha_init(struct ahash_request *req) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + + memset(rctx, 0, sizeof(struct meson_hasher_req_ctx)); + + rctx->flow = meson_get_engine_number(tctx->mc); + rctx->begin_req = true; + + return 0; +} + +static int meson_sha_update(struct ahash_request *req) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct crypto_engine *engine = tctx->mc->chanlist[rctx->flow].engine; + + return crypto_transfer_hash_request_to_engine(engine, req); +} + +static int meson_sha_final(struct ahash_request *req) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct crypto_engine *engine = tctx->mc->chanlist[rctx->flow].engine; + + rctx->final_req = true; + + return crypto_transfer_hash_request_to_engine(engine, req); +} + +static int meson_hasher_req_map(struct ahash_request *req) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_dev *mc = tctx->mc; + int ret; + + if (!req->nbytes) + return 0; + + ret = dma_map_sg(mc->dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); + if (!ret) { + dev_err(mc->dev, "Cannot DMA MAP request data\n"); + return -ENOMEM; + } + + return 0; +} + +static void meson_hasher_req_unmap(struct ahash_request *req) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_dev *mc = tctx->mc; + + if (!req->nbytes) + return; + + dma_unmap_sg(mc->dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); +} + +struct hasher_ctx { + struct crypto_async_request *areq; + + unsigned int tloffset; + unsigned int nbytes; + unsigned int todo; + + dma_addr_t state_addr; + dma_addr_t src_addr; + unsigned int src_offset; + struct scatterlist *src_sg; +}; + +static bool meson_final(struct hasher_ctx *ctx) +{ + struct ahash_request *req = ahash_request_cast(ctx->areq); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + + return !ctx->nbytes && rctx->final_req; +} + +static int meson_fill_partial_buffer(struct hasher_ctx *ctx, unsigned int len) +{ + struct ahash_request *req = ahash_request_cast(ctx->areq); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct meson_dev *mc = tctx->mc; + unsigned int blocksize = crypto_ahash_blocksize(tfm); + unsigned int copy; + + if (len) { + copy = min(blocksize - rctx->partial_size, len); + memcpy(rctx->partial + rctx->partial_size, + sg_virt(ctx->src_sg) + ctx->src_offset, copy); + + rctx->partial_size += copy; + ctx->nbytes -= copy; + ctx->src_offset += copy; + } + + if (rctx->partial_size == blocksize || meson_final(ctx)) { + rctx->partial_addr = dma_map_single(mc->dev, + rctx->partial, + rctx->partial_size, + DMA_TO_DEVICE); + if (dma_mapping_error(mc->dev, rctx->partial_addr)) { + dev_err(mc->dev, "Cannot DMA MAP SHA partial buffer\n"); + return -ENOMEM; + } + + rctx->partial_mapped = true; + ctx->todo = rctx->partial_size; + ctx->src_addr = rctx->partial_addr; + } + + return 0; +} + +static unsigned int meson_setup_data_descs(struct hasher_ctx *ctx) +{ + struct ahash_request *req = ahash_request_cast(ctx->areq); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_dev *mc = tctx->mc; + struct meson_flow *flow = &mc->chanlist[rctx->flow]; + struct hash_alg_common *alg = crypto_hash_alg_common(tfm); + struct meson_alg_template *algt = container_of(alg, + struct meson_alg_template, alg.ahash.base.halg); + struct meson_desc *desc = &flow->tl[ctx->tloffset]; + u32 v; + + ctx->tloffset++; + + v = DESC_OWN | DESC_ENCRYPTION | DESC_OPMODE_SHA | + ctx->todo | algt->blockmode; + if (rctx->begin_req) { + rctx->begin_req = false; + v |= DESC_BEGIN; + } + + if (!ctx->nbytes && rctx->final_req) { + rctx->final_req = false; + v |= DESC_END; + } + + if (!ctx->nbytes || ctx->tloffset == MAXDESC || rctx->partial_mapped) + v |= DESC_LAST; + + desc->t_src = cpu_to_le32(ctx->src_addr); + desc->t_dst = cpu_to_le32(ctx->state_addr); + desc->t_status = cpu_to_le32(v); + + return v & DESC_LAST; +} + +static int meson_kick_hardware(struct hasher_ctx *ctx) +{ + struct ahash_request *req = ahash_request_cast(ctx->areq); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_dev *mc = tctx->mc; + struct meson_flow *flow = &mc->chanlist[rctx->flow]; + int ret; + + reinit_completion(&flow->complete); + meson_dma_start(mc, rctx->flow); + + ret = wait_for_completion_timeout(&flow->complete, + msecs_to_jiffies(500)); + if (ret == 0) { + dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); + return -EINVAL; + } else if (ret < 0) { + dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", ret); + return ret; + } + + if (rctx->partial_mapped) { + dma_unmap_single(mc->dev, rctx->partial_addr, + rctx->partial_size, + DMA_TO_DEVICE); + rctx->partial_size = 0; + rctx->partial_mapped = false; + } + + ctx->tloffset = 0; + + return 0; +} + +static void meson_setup_state_descs(struct hasher_ctx *ctx) +{ + struct ahash_request *req = ahash_request_cast(ctx->areq); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_dev *mc = tctx->mc; + struct meson_desc *desc; + int i; + + if (ctx->tloffset || rctx->begin_req) + return; + + for (i = 0; i < mc->pdata->setup_desc_cnt; i++) { + int offset = i * 16; + + desc = &mc->chanlist[rctx->flow].tl[ctx->tloffset]; + desc->t_src = cpu_to_le32(ctx->state_addr + offset); + desc->t_dst = cpu_to_le32(offset); + desc->t_status = cpu_to_le32(MESON_SHA_BUFFER_SIZE | + DESC_MODE_KEY | DESC_OWN); + + ctx->tloffset++; + } +} + +static int meson_hasher_do_one_request(struct crypto_engine *engine, void *areq) +{ + struct ahash_request *req = ahash_request_cast(areq); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct meson_dev *mc = tctx->mc; + struct hasher_ctx ctx = { + .tloffset = 0, + .src_offset = 0, + .nbytes = rctx->final_req ? 0 : req->nbytes, + .src_sg = req->src, + .areq = areq, + }; + unsigned int blocksize = crypto_ahash_blocksize(tfm); + unsigned int digest_size = crypto_ahash_digestsize(tfm); + bool final_req = rctx->final_req; + int ret; + + ctx.state_addr = dma_map_single(mc->dev, rctx->state, + sizeof(rctx->state), DMA_BIDIRECTIONAL); + ret = dma_mapping_error(mc->dev, ctx.state_addr); + if (ret) { + dev_err(mc->dev, "Cannot DMA MAP SHA state buffer"); + goto fail_map_single; + } + + ret = meson_hasher_req_map(req); + if (ret) + goto fail_map_req; + + for (;;) { + unsigned int len = ctx.src_sg ? + min(sg_dma_len(ctx.src_sg) - ctx.src_offset, ctx.nbytes) : 0; + + ctx.src_addr = 0; + ctx.todo = 0; + + if (!rctx->final_req && !ctx.nbytes) + break; + + meson_setup_state_descs(&ctx); + + if (rctx->partial_size && rctx->partial_size < blocksize) { + ret = meson_fill_partial_buffer(&ctx, len); + if (ret) + goto fail; + } else if (len && len < blocksize) { + memcpy(rctx->partial, sg_virt(ctx.src_sg) + ctx.src_offset, len); + + rctx->partial_size = len; + ctx.nbytes -= len; + ctx.src_offset += len; + } else if (len) { + ctx.src_addr = sg_dma_address(ctx.src_sg) + ctx.src_offset; + ctx.todo = min(rounddown(DESC_MAXLEN, blocksize), + rounddown(len, blocksize)); + ctx.nbytes -= ctx.todo; + ctx.src_offset += ctx.todo; + } + + if (ctx.src_sg && ctx.src_offset == sg_dma_len(ctx.src_sg)) { + ctx.src_offset = 0; + ctx.src_sg = sg_next(ctx.src_sg); + } + + if (!ctx.todo && ctx.nbytes) + continue; + + if (!ctx.todo && !rctx->final_req && !ctx.tloffset) + continue; + + if (meson_setup_data_descs(&ctx)) { + ret = meson_kick_hardware(&ctx); + if (ret) + goto fail; + } + } + +fail: + meson_hasher_req_unmap(req); + +fail_map_req: + dma_unmap_single(mc->dev, ctx.state_addr, sizeof(rctx->state), + DMA_BIDIRECTIONAL); + +fail_map_single: + if (final_req && ret == 0) + memcpy(req->result, rctx->state, digest_size); + + local_bh_disable(); + crypto_finalize_hash_request(engine, req, ret); + local_bh_enable(); + + return ret; +} + +static int meson_hasher_export(struct ahash_request *req, void *out) +{ + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + + memcpy(out, rctx, sizeof(*rctx)); + return 0; +} + +static int meson_hasher_import(struct ahash_request *req, const void *in) +{ + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + + memcpy(rctx, in, sizeof(*rctx)); + return 0; +} + +static int meson_hasher_init(struct crypto_tfm *tfm) +{ + struct meson_hasher_tfm_ctx *tctx = crypto_tfm_ctx_dma(tfm); + struct crypto_ahash *atfm = __crypto_ahash_cast(tfm); + struct hash_alg_common *alg = crypto_hash_alg_common(atfm); + struct meson_alg_template *algt = container_of(alg, + struct meson_alg_template, alg.ahash.base.halg); + + crypto_ahash_set_reqsize_dma(atfm, crypto_ahash_statesize(atfm)); + + memset(tctx, 0, sizeof(struct meson_hasher_tfm_ctx)); + + tctx->mc = algt->mc; + + return 0; +} + +static struct meson_alg_template mc_algs[] = { +{ + .type = CRYPTO_ALG_TYPE_AHASH, + .blockmode = DESC_MODE_SHA1, + .alg.ahash.base = { + .halg = { + .base = { + .cra_name = "sha1", + .cra_driver_name = "sha1-gxl", + .cra_priority = 400, + .cra_blocksize = SHA1_BLOCK_SIZE, + .cra_flags = CRYPTO_ALG_ASYNC, + .cra_module = THIS_MODULE, + .cra_alignmask = 0, + .cra_init = meson_hasher_init, + }, + .digestsize = SHA1_DIGEST_SIZE, + .statesize = sizeof(struct meson_hasher_req_ctx), + }, + .init = meson_sha_init, + .update = meson_sha_update, + .final = meson_sha_final, + .export = meson_hasher_export, + .import = meson_hasher_import, + }, + .alg.ahash.op = { + .do_one_request = meson_hasher_do_one_request, + }, +}, +{ + .type = CRYPTO_ALG_TYPE_AHASH, + .blockmode = DESC_MODE_SHA224, + .alg.ahash.base = { + .halg = { + .base = { + .cra_name = "sha224", + .cra_driver_name = "sha224-gxl", + .cra_priority = 400, + .cra_blocksize = SHA224_BLOCK_SIZE, + .cra_flags = CRYPTO_ALG_ASYNC, + .cra_module = THIS_MODULE, + .cra_alignmask = 0, + .cra_init = meson_hasher_init, + }, + .digestsize = SHA224_DIGEST_SIZE, + .statesize = sizeof(struct meson_hasher_req_ctx), + }, + .init = meson_sha_init, + .update = meson_sha_update, + .final = meson_sha_final, + .export = meson_hasher_export, + .import = meson_hasher_import, + }, + .alg.ahash.op = { + .do_one_request = meson_hasher_do_one_request, + }, +}, +{ + .type = CRYPTO_ALG_TYPE_AHASH, + .blockmode = DESC_MODE_SHA256, + .alg.ahash.base = { + .halg = { + .base = { + .cra_name = "sha256", + .cra_driver_name = "sha256-gxl", + .cra_priority = 400, + .cra_blocksize = SHA256_BLOCK_SIZE, + .cra_flags = CRYPTO_ALG_ASYNC, + .cra_module = THIS_MODULE, + .cra_alignmask = 0, + .cra_init = meson_hasher_init, + }, + .digestsize = SHA256_DIGEST_SIZE, + .statesize = sizeof(struct meson_hasher_req_ctx), + }, + .init = meson_sha_init, + .update = meson_sha_update, + .final = meson_sha_final, + .export = meson_hasher_export, + .import = meson_hasher_import, + }, + .alg.ahash.op = { + .do_one_request = meson_hasher_do_one_request, + }, +}, +}; + +int meson_hasher_register(struct meson_dev *mc) +{ + int i; + + if (!mc->pdata->hasher_supported) { + pr_info("amlogic-gxl-hasher: hasher not supported at current platform"); + return 0; + } + + for (i = 0; i < ARRAY_SIZE(mc_algs); i++) { + struct hash_alg_common *alg = &mc_algs[i].alg.ahash.base.halg; + + alg->base.cra_ctxsize = sizeof(struct meson_hasher_tfm_ctx) + crypto_dma_padding(); + } + + return meson_register_algs(mc, mc_algs, ARRAY_SIZE(mc_algs)); +} + +void meson_hasher_unregister(struct meson_dev *mc) +{ + if (!mc->pdata->hasher_supported) + return; + + meson_unregister_algs(mc, mc_algs, ARRAY_SIZE(mc_algs)); +} diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index c401cbbadaa3..b092d0c89cd8 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -5,6 +5,7 @@ * Copyright (C) 2018-2019 Corentin LABBE <clabbe@baylibre.com> */ #include <crypto/aes.h> +#include <crypto/sha2.h> #include <crypto/engine.h> #include <crypto/skcipher.h> #include <linux/debugfs.h> @@ -23,13 +24,22 @@ #define DESC_OPMODE_ECB (0 << 26) #define DESC_OPMODE_CBC (1 << 26) +#define DESC_OPMODE_SHA (0 << 26) #define DESC_MAXLEN GENMASK(16, 0) +#define DESC_MODE_SHA1 (0x5 << 20) +#define DESC_MODE_SHA224 (0x7 << 20) +#define DESC_MODE_SHA256 (0x6 << 20) + #define DESC_LAST BIT(18) +#define DESC_BEGIN BIT(24) +#define DESC_END BIT(25) #define DESC_ENCRYPTION BIT(28) #define DESC_OWN BIT(31) +#define MESON_SHA_BUFFER_SIZE (SHA256_DIGEST_SIZE + 16) + /* * struct meson_desc - Descriptor for DMA operations * Note that without datasheet, some are unknown @@ -83,11 +93,13 @@ struct meson_flow { * @reg_descs: offset to descriptors register * @reg_status: offset to status register * @setup_desc_cnt: number of setup descriptor to configure. + * @hasher_supported: indecates whether hasher is supported. */ struct meson_pdata { u32 descs_reg; u32 status_reg; u32 setup_desc_cnt; + bool hasher_supported; }; /* @@ -139,6 +151,38 @@ struct meson_cipher_tfm_ctx { struct crypto_skcipher *fallback_tfm; }; +/* + * struct meson_hasher_req_ctx - context for a hasher request + * @state: state data + * @partial: partial buffer data. Contains sent data which + * size < blocksize + * @partial_size: size of the partial buffer + * @partial_addr: physical address of partial buffer + * @partial_mapped: indicates is partial buffer currently mapped or not + * @flags: request flags (for example, is this final req or not) + * @flow: the flow to use for this request + */ +struct meson_hasher_req_ctx { + u8 state[SHA256_DIGEST_SIZE + 16] ____cacheline_aligned; + u8 partial[SHA256_BLOCK_SIZE] ____cacheline_aligned; + unsigned int partial_size ____cacheline_aligned; + dma_addr_t partial_addr; + bool partial_mapped; + + bool begin_req; + bool final_req; + int flow; +}; + +/* + * struct meson_hasher_tfm_ctx - context for a hasher TFM + * @enginectx: crypto_engine used by this TFM + * @mc: pointer to the private data of driver handling this TFM + */ +struct meson_hasher_tfm_ctx { + struct meson_dev *mc; +}; + /* * struct meson_alg_template - crypto_alg template * @type: the CRYPTO_ALG_TYPE for this template @@ -153,6 +197,7 @@ struct meson_alg_template { u32 blockmode; union { struct skcipher_engine_alg skcipher; + struct ahash_engine_alg ahash; } alg; struct meson_dev *mc; #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG @@ -174,3 +219,6 @@ int meson_cipher_register(struct meson_dev *mc); void meson_cipher_unregister(struct meson_dev *mc); void meson_cipher_debugfs_show(struct seq_file *seq, void *v); int meson_handle_cipher_request(struct crypto_engine *engine, void *areq); + +int meson_hasher_register(struct meson_dev *mc); +void meson_hasher_unregister(struct meson_dev *mc); -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v14 13/30] crypto: amlogic - Introduce hasher 2026-11-27 12:00 ` [PATCH v14 13/30] crypto: amlogic - Introduce hasher Jose Nieto @ 2026-11-27 12:24 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-27 12:24 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] crypto: amlogic: 0-byte SHA DMA descriptor in meson_hasher_do_one_request() - [High] crypto: amlogic: double completion on error in meson_hasher_do_one_request() - [High] crypto: amlogic: unaligned DMA request ctx via ahash_request_ctx() - [High] crypto: amlogic: invalid src DMA map on final in meson_hasher_req_map() - [Medium] crypto: amlogic: leaked partial_addr DMA mapping in meson_kick_hardware() - [Medium] crypto: amlogic: sg_virt() indexed by sg_dma_len() in amlogic-gxl-hasher -- commit 531139f52bee7e6e883c924298c554e02337a015 Author: Alexey Romanov <romanov.alexey2000@gmail.com> crypto: amlogic - Introduce hasher This commit adds hardware asynchronous SHA1, SHA224, and SHA256 hash algorithm support to the Amlogic GXL crypto driver. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-hasher.c b/drivers/crypto/amlogic/amlogic-gxl-hasher.c > new file mode 100644 > index 0000000000000..c83739ec34566 > --- /dev/null > +++ b/drivers/crypto/amlogic/amlogic-gxl-hasher.c [ ... ] > +static int meson_hasher_req_map(struct ahash_request *req) > +{ > + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); > + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); > + struct meson_dev *mc = tctx->mc; > + int ret; > + > + if (!req->nbytes) > + return 0; > + > + ret = dma_map_sg(mc->dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); > + if (!ret) { > + dev_err(mc->dev, "Cannot DMA MAP request data\n"); > + return -ENOMEM; > + } > + > + return 0; > +} > + > +static void meson_hasher_req_unmap(struct ahash_request *req) > +{ > + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); > + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); > + struct meson_dev *mc = tctx->mc; > + > + if (!req->nbytes) > + return; > + > + dma_unmap_sg(mc->dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); > +} [Severity: High] Can meson_hasher_req_map() and meson_hasher_req_unmap() dereference an invalid req->src during crypto_ahash_final()? The ahash final() callback does not consume input data, and callers such as ahash_def_finup_finish1() invoke final(req) after update(req) without clearing req->nbytes. Although meson_hasher_do_one_request() sets ctx.nbytes = 0 when rctx->final_req is true, it still sets ctx.src_sg = req->src and calls meson_hasher_req_map() and meson_hasher_req_unmap(), which check req->nbytes instead of rctx->final_req. If the caller freed or nulled req->src after update() completed, sg_nents(req->src) and sg_dma_len(ctx.src_sg) will dereference a dangling or NULL scatterlist pointer. [ ... ] > +static int meson_kick_hardware(struct hasher_ctx *ctx) > +{ > + struct ahash_request *req = ahash_request_cast(ctx->areq); > + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); > + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); > + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); > + struct meson_dev *mc = tctx->mc; > + struct meson_flow *flow = &mc->chanlist[rctx->flow]; > + int ret; > + > + reinit_completion(&flow->complete); > + meson_dma_start(mc, rctx->flow); > + > + ret = wait_for_completion_timeout(&flow->complete, > + msecs_to_jiffies(500)); > + if (ret == 0) { > + dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); > + return -EINVAL; > + } else if (ret < 0) { > + dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", ret); > + return ret; > + } > + > + if (rctx->partial_mapped) { > + dma_unmap_single(mc->dev, rctx->partial_addr, > + rctx->partial_size, > + DMA_TO_DEVICE); > + rctx->partial_size = 0; > + rctx->partial_mapped = false; > + } [Severity: Medium] Does meson_kick_hardware() leak the rctx->partial_addr DMA mapping when wait_for_completion_timeout() times out? When rctx->partial_mapped is true and the wait fails, returning early skips dma_unmap_single() here, and the fail label in meson_hasher_do_one_request() only unmaps req->src and ctx.state_addr. > + > + ctx->tloffset = 0; > + > + return 0; > +} [ ... ] > +static int meson_hasher_do_one_request(struct crypto_engine *engine, void *areq) > +{ > + struct ahash_request *req = ahash_request_cast(areq); > + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); > + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); > + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); > + struct meson_dev *mc = tctx->mc; > + struct hasher_ctx ctx = { > + .tloffset = 0, > + .src_offset = 0, > + .nbytes = rctx->final_req ? 0 : req->nbytes, > + .src_sg = req->src, > + .areq = areq, > + }; > + unsigned int blocksize = crypto_ahash_blocksize(tfm); > + unsigned int digest_size = crypto_ahash_digestsize(tfm); > + bool final_req = rctx->final_req; > + int ret; > + > + ctx.state_addr = dma_map_single(mc->dev, rctx->state, > + sizeof(rctx->state), DMA_BIDIRECTIONAL); > + ret = dma_mapping_error(mc->dev, ctx.state_addr); > + if (ret) { > + dev_err(mc->dev, "Cannot DMA MAP SHA state buffer"); > + goto fail_map_single; > + } > + > + ret = meson_hasher_req_map(req); > + if (ret) > + goto fail_map_req; > + > + for (;;) { > + unsigned int len = ctx.src_sg ? > + min(sg_dma_len(ctx.src_sg) - ctx.src_offset, ctx.nbytes) : 0; > + > + ctx.src_addr = 0; > + ctx.todo = 0; > + > + if (!rctx->final_req && !ctx.nbytes) > + break; > + > + meson_setup_state_descs(&ctx); > + > + if (rctx->partial_size && rctx->partial_size < blocksize) { > + ret = meson_fill_partial_buffer(&ctx, len); > + if (ret) > + goto fail; > + } else if (len && len < blocksize) { > + memcpy(rctx->partial, sg_virt(ctx.src_sg) + ctx.src_offset, len); [Severity: Medium] Can indexing sg_virt(ctx.src_sg) by ctx.src_offset read past the end of ctx.src_sg's virtual buffer when dma_map_sg() coalesces scatterlist entries? ctx.src_offset and len are bounded by sg_dma_len(ctx.src_sg), and ctx.src_sg only advances when ctx.src_offset reaches sg_dma_len(ctx.src_sg). If dma_map_sg() merges adjacent entries so that sg_dma_len(ctx.src_sg) exceeds ctx.src_sg->length, ctx.src_offset can grow larger than ctx.src_sg->length, causing memcpy() here and in meson_fill_partial_buffer() to read out of bounds from sg_virt(ctx.src_sg). > + > + rctx->partial_size = len; > + ctx.nbytes -= len; > + ctx.src_offset += len; > + } else if (len) { > + ctx.src_addr = sg_dma_address(ctx.src_sg) + ctx.src_offset; > + ctx.todo = min(rounddown(DESC_MAXLEN, blocksize), > + rounddown(len, blocksize)); > + ctx.nbytes -= ctx.todo; > + ctx.src_offset += ctx.todo; > + } > + > + if (ctx.src_sg && ctx.src_offset == sg_dma_len(ctx.src_sg)) { > + ctx.src_offset = 0; > + ctx.src_sg = sg_next(ctx.src_sg); > + } > + > + if (!ctx.todo && ctx.nbytes) > + continue; > + > + if (!ctx.todo && !rctx->final_req && !ctx.tloffset) > + continue; > + > + if (meson_setup_data_descs(&ctx)) { > + ret = meson_kick_hardware(&ctx); > + if (ret) > + goto fail; > + } > + } [Severity: High] Does meson_hasher_do_one_request() emit and kick a 0-byte SHA DMA descriptor with t_src = 0 when a non-final update() leaves trailing bytes in rctx->partial? When a non-final update() has trailing sub-block bytes, ctx.tloffset is already non-zero when those bytes are copied into rctx->partial: either meson_setup_state_descs() just queued state descriptors (when !rctx->begin_req), or an earlier iteration in the same request queued full blocks without setting DESC_LAST (because ctx.nbytes was still non-zero). Buffering the trailing bytes reduces ctx.nbytes to 0 while leaving ctx.todo = 0 and ctx.src_addr = 0. Because ctx.nbytes is 0, rctx->final_req is false, and ctx.tloffset > 0, neither continue guard triggers, so meson_setup_data_descs() and meson_kick_hardware() submit a 0-length descriptor at physical address 0 to the hardware. > + > +fail: > + meson_hasher_req_unmap(req); > + > +fail_map_req: > + dma_unmap_single(mc->dev, ctx.state_addr, sizeof(rctx->state), > + DMA_BIDIRECTIONAL); > + > +fail_map_single: > + if (final_req && ret == 0) > + memcpy(req->result, rctx->state, digest_size); > + > + local_bh_disable(); > + crypto_finalize_hash_request(engine, req, ret); > + local_bh_enable(); > + > + return ret; > +} [Severity: High] Does returning a negative ret after crypto_finalize_hash_request() complete req twice on error? crypto_finalize_hash_request() calls crypto_request_complete(), waking the caller who may free req. When do_one_request() then returns ret < 0, crypto_pump_requests() calls crypto_request_complete(async_req, ret) a second time on the already-completed request: crypto/crypto_engine.c:crypto_pump_requests() { ... ret = op->do_one_request(engine, async_req); /* Request unsuccessfully executed by hardware */ if (ret < 0) { if (!engine->retry_support || (ret != -ENOSPC)) { dev_err(engine->dev, "Failed to do one request from queue: %d\n", ret); goto req_err_1; } ... req_err_1: crypto_request_complete(async_req, ret); ... } meson_hasher_do_one_request() should return 0 after calling crypto_finalize_hash_request(), matching meson_handle_cipher_request(). [ ... ] > +static int meson_hasher_init(struct crypto_tfm *tfm) > +{ > + struct meson_hasher_tfm_ctx *tctx = crypto_tfm_ctx_dma(tfm); > + struct crypto_ahash *atfm = __crypto_ahash_cast(tfm); > + struct hash_alg_common *alg = crypto_hash_alg_common(atfm); > + struct meson_alg_template *algt = container_of(alg, > + struct meson_alg_template, alg.ahash.base.halg); > + > + crypto_ahash_set_reqsize_dma(atfm, crypto_ahash_statesize(atfm)); [Severity: High] Should the request callbacks retrieve rctx with ahash_request_ctx_dma(req) instead of ahash_request_ctx(req), and align the DMA buffers in struct meson_hasher_req_ctx to ARCH_DMA_MINALIGN? meson_hasher_init() reserves DMA alignment padding via crypto_ahash_set_reqsize_dma(), but every callback in this file uses ahash_request_ctx(req), which is only aligned to CRYPTO_MINALIGN (8 bytes on arm64), and struct meson_hasher_req_ctx marks state and partial with ____cacheline_aligned (64 bytes on arm64, smaller than ARCH_DMA_MINALIGN = 128). As a result, the DMA-mapped state and partial buffers share DMA cachelines with struct ahash_request and CPU-updated fields in struct meson_hasher_req_ctx, which can corrupt adjacent fields during DMA cacheline invalidation on non-coherent systems. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261127120103.1532882-1-jnieto.alaber@gmail.com?part=13 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v14 14/30] crypto: amlogic - Use fallback for 192-bit keys 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (12 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 13/30] crypto: amlogic - Introduce hasher Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 15/30] crypto: amlogic - Add support for G12-series Jose Nieto ` (15 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Unforunately, not all Amlogic SoC's have a 192-bit key support for AES algo. In this case, use fallback. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 7 +++++++ drivers/crypto/amlogic/amlogic-gxl-core.c | 1 + drivers/crypto/amlogic/amlogic-gxl.h | 2 ++ 3 files changed, 10 insertions(+) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index df42940f1112..6070ee6b488e 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -41,6 +41,13 @@ static bool meson_cipher_need_fallback_sg(struct skcipher_request *areq, static bool meson_cipher_need_fallback(struct skcipher_request *areq) { + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); + struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); + struct meson_dev *mc = op->mc; + + if (op->keymode == DESC_MODE_AES_192 && !mc->pdata->support_192bit_key) + return true; + if (areq->cryptlen == 0) return true; diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 9676b86a5089..f530e238812e 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -279,6 +279,7 @@ static const struct meson_pdata meson_gxl_pdata = { .status_reg = 0x4, .setup_desc_cnt = 3, .hasher_supported = false, + .support_192bit_key = true, }; static const struct of_device_id meson_crypto_of_match_table[] = { diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index b092d0c89cd8..a44290fcf3a0 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -94,12 +94,14 @@ struct meson_flow { * @reg_status: offset to status register * @setup_desc_cnt: number of setup descriptor to configure. * @hasher_supported: indecates whether hasher is supported. + * @support_192bit_key: indicates whether platform support AES 192-bit key */ struct meson_pdata { u32 descs_reg; u32 status_reg; u32 setup_desc_cnt; bool hasher_supported; + bool support_192bit_key; }; /* -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 15/30] crypto: amlogic - Add support for G12-series 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (13 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 14/30] crypto: amlogic - Use fallback for 192-bit keys Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:27 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 16/30] crypto: amlogic - Add support for AXG-series Jose Nieto ` (14 subsequent siblings) 29 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Tested via tcrypt module and with custom tests. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index f530e238812e..0fb0da20e06b 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -282,11 +282,23 @@ static const struct meson_pdata meson_gxl_pdata = { .support_192bit_key = true, }; +static const struct meson_pdata meson_g12a_pdata = { + .descs_reg = 0x0, + .status_reg = 0x8, + .setup_desc_cnt = 1, + .hasher_supported = true, + .support_192bit_key = false, +}; + static const struct of_device_id meson_crypto_of_match_table[] = { { .compatible = "amlogic,gxl-crypto", .data = &meson_gxl_pdata, }, + { + .compatible = "amlogic,g12a-crypto", + .data = &meson_g12a_pdata, + }, {}, }; MODULE_DEVICE_TABLE(of, meson_crypto_of_match_table); -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v14 15/30] crypto: amlogic - Add support for G12-series 2026-11-27 12:00 ` [PATCH v14 15/30] crypto: amlogic - Add support for G12-series Jose Nieto @ 2026-11-27 12:27 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-27 12:27 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] crypto: amlogic: 0-byte SHA DMA desc on partial update in meson_hasher_do_one_request() - [High] crypto: amlogic: double completion on error in meson_hasher_do_one_request() - [High] crypto: amlogic: broken key/IV descriptors and shared keyiv in meson_cipher() - [Medium] crypto: amlogic: partial_addr DMA leak on meson_kick_hardware() timeout -- commit 6d405eb12267511d2b1777a56617785870d3b0c4 Author: Alexey Romanov <romanov.alexey2000@gmail.com> crypto: amlogic - Add support for G12-series This commit adds platform data and the "amlogic,g12a-crypto" device tree match entry to support the crypto engine and hardware hasher on Amlogic G12-series SoCs. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c > index f530e238812eb..0fb0da20e06b2 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-core.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c > @@ -282,11 +282,23 @@ static const struct meson_pdata meson_gxl_pdata = { > .support_192bit_key = true, > }; > > +static const struct meson_pdata meson_g12a_pdata = { > + .descs_reg = 0x0, > + .status_reg = 0x8, > + .setup_desc_cnt = 1, > + .hasher_supported = true, > + .support_192bit_key = false, > +}; [Severity: High] Enabling hasher_supported on G12A activates meson_hasher_do_one_request(), where non-block-aligned crypto_ahash_update() calls can program a 0-length DMA descriptor from physical address 0x0. drivers/crypto/amlogic/amlogic-gxl-hasher.c:meson_hasher_do_one_request() { ... meson_setup_state_descs(&ctx); if (rctx->partial_size && rctx->partial_size < blocksize) { ret = meson_fill_partial_buffer(&ctx, len); if (ret) goto fail; } else if (len && len < blocksize) { memcpy(rctx->partial, sg_virt(ctx.src_sg) + ctx.src_offset, len); rctx->partial_size = len; ctx.nbytes -= len; ctx.src_offset += len; } ... if (!ctx.todo && ctx.nbytes) continue; if (!ctx.todo && !rctx->final_req && !ctx.tloffset) continue; if (meson_setup_data_descs(&ctx)) { ret = meson_kick_hardware(&ctx); ... } When an update request buffers a trailing sub-block tail (< blocksize) into rctx->partial while ctx.tloffset is already non-zero (either because an earlier iteration queued full blocks without setting DESC_LAST while ctx.nbytes was non-zero, or because meson_setup_state_descs() queued a state descriptor at the top of the loop when rctx->begin_req is false), ctx.nbytes becomes 0 while ctx.todo and ctx.src_addr remain 0. Both continue guards evaluate to false, so execution falls through to meson_setup_data_descs() and meson_kick_hardware() with a 0-byte descriptor at src_addr 0 (and the later commit "crypto: amlogic: hasher: add one-shot digest path" only guards the rctx->final_req case). In addition, on final() requests (where rctx->final_req is true and ctx.nbytes is forced to 0), meson_hasher_req_map() and meson_hasher_req_unmap() only check !req->nbytes, while the loop reads sg_dma_len(ctx.src_sg) whenever req->src is non-NULL even when ctx.nbytes is 0. [Severity: High] When meson_hasher_do_one_request() fails (for example on a DMA mapping error or a hardware timeout in meson_kick_hardware()), can returning a negative ret after crypto_finalize_hash_request() complete the request twice? drivers/crypto/amlogic/amlogic-gxl-hasher.c:meson_hasher_do_one_request() { ... local_bh_disable(); crypto_finalize_hash_request(engine, req, ret); local_bh_enable(); return ret; } Because engine->retry_support is false, crypto_pump_requests() treats a negative return from do_one_request() as an unfinalized error and calls crypto_request_complete() a second time, risking a use-after-free if the completion callback freed the request. Like meson_handle_cipher_request(), this should return 0 after calling crypto_finalize_hash_request(). [Severity: Medium] Does meson_kick_hardware() leak the rctx->partial_addr DMA mapping when wait_for_completion_timeout() fails? drivers/crypto/amlogic/amlogic-gxl-hasher.c:meson_kick_hardware() { ... ret = wait_for_completion_timeout(&flow->complete, msecs_to_jiffies(500)); if (ret == 0) { dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); return -EINVAL; } else if (ret < 0) { dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", ret); return ret; } if (rctx->partial_mapped) { dma_unmap_single(mc->dev, rctx->partial_addr, rctx->partial_size, DMA_TO_DEVICE); ... } When meson_fill_partial_buffer() DMA-maps rctx->partial, a timeout returns before reaching dma_unmap_single(), and the fail path in meson_hasher_do_one_request() only unmaps req->src and ctx.state_addr. [Severity: High] Can concurrent or multi-batch skcipher requests in meson_cipher() corrupt the key and IV or read outside the DMA mapping? drivers/crypto/amlogic/amlogic-gxl-cipher.c:meson_setup_keyiv_descs() { ... if (blockmode == DESC_OPMODE_CBC) { memcpy(op->keyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); dma_sync_single_for_device(mc->dev, ctx->keyiv.addr, ctx->keyiv.len, DMA_TO_DEVICE); } for (i = 0; i < mc->pdata->setup_desc_cnt; i++) { struct meson_desc *desc = &mc->chanlist[rctx->flow].tl[ctx->tloffset]; int offset = i * 16; desc->t_src = cpu_to_le32(ctx->keyiv.addr + offset); desc->t_dst = cpu_to_le32(offset); desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | ctx->keyiv.len); ctx->tloffset++; } } First, op->keyiv lives in struct meson_cipher_tfm_ctx rather than the per-request context, so concurrent CBC requests on the same transform dispatched across different hardware flows overwrite op->keyiv + AES_MAX_KEY_SIZE and race on dma_map_single() and dma_unmap_single() of op->keyiv. Second, each setup descriptor programs the full ctx->keyiv.len from ctx->keyiv.addr + i * 16, reading past the 48-byte op->keyiv buffer and DMA mapping when setup_desc_cnt is 3; the later commit "crypto: amlogic: fix setup descriptor lengths and CBC IV copy" divides ctx->keyiv.len by setup_desc_cnt, which in ECB mode (where ctx->keyiv.len is 16 or 32) truncates the descriptor length to 16 / 3 = 5 or 32 / 3 = 10 bytes and still accesses offsets 16 and 32 outside the DMA-mapped key buffer. Third, that later commit removes the CBC IV copy and DMA sync from meson_setup_keyiv_descs(), so multi-batch CBC requests exceeding MAXDESC descriptors reload the stale initial IV from op->keyiv on subsequent batches after meson_kick_hardware() updates ctx->areq->iv. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261127120103.1532882-1-jnieto.alaber@gmail.com?part=15 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v14 16/30] crypto: amlogic - Add support for AXG-series 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (14 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 15/30] crypto: amlogic - Add support for G12-series Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 17/30] crypto: amlogic - Add support for A1-series Jose Nieto ` (13 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> Tested via tcrypt module and with custom tests. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 0fb0da20e06b..08d89db14788 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -290,6 +290,14 @@ static const struct meson_pdata meson_g12a_pdata = { .support_192bit_key = false, }; +static const struct meson_pdata meson_axg_pdata = { + .descs_reg = 0x0, + .status_reg = 0x8, + .setup_desc_cnt = 3, + .hasher_supported = true, + .support_192bit_key = true, +}; + static const struct of_device_id meson_crypto_of_match_table[] = { { .compatible = "amlogic,gxl-crypto", @@ -299,6 +307,10 @@ static const struct of_device_id meson_crypto_of_match_table[] = { .compatible = "amlogic,g12a-crypto", .data = &meson_g12a_pdata, }, + { + .compatible = "amlogic,axg-crypto", + .data = &meson_axg_pdata, + }, {}, }; MODULE_DEVICE_TABLE(of, meson_crypto_of_match_table); -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 17/30] crypto: amlogic - Add support for A1-series 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (15 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 16/30] crypto: amlogic - Add support for AXG-series Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 18/30] crypto: amlogic: g12: drop CRYPTO_ALG_ALLOCATES_MEMORY Jose Nieto ` (12 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> This platform data also can be used for S4 as fallback. Tested via tcrypt module and with custom tests. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-core.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 08d89db14788..3a6bac10bb04 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -298,6 +298,14 @@ static const struct meson_pdata meson_axg_pdata = { .support_192bit_key = true, }; +static const struct meson_pdata meson_a1_pdata = { + .descs_reg = 0x0, + .status_reg = 0x8, + .setup_desc_cnt = 1, + .hasher_supported = true, + .support_192bit_key = false, +}; + static const struct of_device_id meson_crypto_of_match_table[] = { { .compatible = "amlogic,gxl-crypto", @@ -311,6 +319,14 @@ static const struct of_device_id meson_crypto_of_match_table[] = { .compatible = "amlogic,axg-crypto", .data = &meson_axg_pdata, }, + { + .compatible = "amlogic,a1-crypto", + .data = &meson_a1_pdata, + }, + { + .compatible = "amlogic,s4-crypto", + .data = &meson_a1_pdata, + }, {}, }; MODULE_DEVICE_TABLE(of, meson_crypto_of_match_table); -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 18/30] crypto: amlogic: g12: drop CRYPTO_ALG_ALLOCATES_MEMORY 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (16 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 17/30] crypto: amlogic - Add support for A1-series Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 19/30] crypto: amlogic: hasher: add one-shot digest path Jose Nieto ` (11 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Jose Nieto The driver queues requests to a crypto_engine kthread and does not allocate memory per request, so CRYPTO_ALG_ALLOCATES_MEMORY is stale. dm-crypt allocates its skcipher with a mask that excludes implementations carrying CRYPTO_ALG_ALLOCATES_MEMORY, which prevented the hardware cipher from being selected. Dropping the flag lets dm-crypt bind to the engine. Signed-off-by: Jose Nieto <jnieto.alaber@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index 6070ee6b488e..72892fdcd55d 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -498,7 +498,7 @@ static struct meson_alg_template algs[] = { .cra_priority = 400, .cra_blocksize = AES_BLOCK_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | - CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK, .cra_module = THIS_MODULE, .cra_alignmask = 0xf, @@ -526,7 +526,7 @@ static struct meson_alg_template algs[] = { .cra_priority = 400, .cra_blocksize = AES_BLOCK_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | - CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | + CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK, .cra_module = THIS_MODULE, .cra_alignmask = 0xf, -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 19/30] crypto: amlogic: hasher: add one-shot digest path 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (17 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 18/30] crypto: amlogic: g12: drop CRYPTO_ALG_ALLOCATES_MEMORY Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:22 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 20/30] crypto: amlogic: drop unused field and stale includes Jose Nieto ` (10 subsequent siblings) 29 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Jose Nieto Implement the ahash ->digest callback so one-shot SHA requests are sent as a single engine transfer instead of the init/update/final sequence, and skip the spurious trailing block for digest requests. Also unregister the hasher on device removal and lower the "hasher not supported" message to dev_dbg. Signed-off-by: Jose Nieto <jnieto.alaber@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-core.c | 9 ++++--- drivers/crypto/amlogic/amlogic-gxl-hasher.c | 29 +++++++++++++++++++-- drivers/crypto/amlogic/amlogic-gxl.h | 5 +++- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 3a6bac10bb04..38b9645386ae 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -237,6 +237,10 @@ static int meson_crypto_probe(struct platform_device *pdev) if (err) goto error_flow; + err = meson_hasher_register(mc); + if (err) + goto error_hasher; + if (IS_ENABLED(CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG)) { struct dentry *dbgfs_dir; @@ -247,10 +251,6 @@ static int meson_crypto_probe(struct platform_device *pdev) #endif } - err = meson_hasher_register(mc); - if (err) - goto error_hasher; - return 0; error_hasher: @@ -269,6 +269,7 @@ static void meson_crypto_remove(struct platform_device *pdev) debugfs_remove_recursive(mc->dbgfs_dir); #endif + meson_hasher_unregister(mc); meson_cipher_unregister(mc); meson_free_chanlist(mc, mc->flow_cnt - 1); diff --git a/drivers/crypto/amlogic/amlogic-gxl-hasher.c b/drivers/crypto/amlogic/amlogic-gxl-hasher.c index c83739ec3456..978cdcd8a4f9 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-hasher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-hasher.c @@ -51,6 +51,25 @@ static int meson_sha_final(struct ahash_request *req) return crypto_transfer_hash_request_to_engine(engine, req); } +static int meson_sha_digest(struct ahash_request *req) +{ + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); + struct crypto_engine *engine; + + memset(rctx, 0, sizeof(struct meson_hasher_req_ctx)); + + rctx->flow = meson_get_engine_number(tctx->mc); + rctx->begin_req = true; + rctx->final_req = true; + rctx->digest_req = true; + + engine = tctx->mc->chanlist[rctx->flow].engine; + + return crypto_transfer_hash_request_to_engine(engine, req); +} + static int meson_hasher_req_map(struct ahash_request *req) { struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); @@ -251,7 +270,7 @@ static int meson_hasher_do_one_request(struct crypto_engine *engine, void *areq) struct hasher_ctx ctx = { .tloffset = 0, .src_offset = 0, - .nbytes = rctx->final_req ? 0 : req->nbytes, + .nbytes = (rctx->final_req && !rctx->digest_req) ? 0 : req->nbytes, .src_sg = req->src, .areq = areq, }; @@ -310,6 +329,9 @@ static int meson_hasher_do_one_request(struct crypto_engine *engine, void *areq) if (!ctx.todo && ctx.nbytes) continue; + if (!ctx.todo && rctx->final_req && rctx->partial_size) + continue; + if (!ctx.todo && !rctx->final_req && !ctx.tloffset) continue; @@ -393,6 +415,7 @@ static struct meson_alg_template mc_algs[] = { .init = meson_sha_init, .update = meson_sha_update, .final = meson_sha_final, + .digest = meson_sha_digest, .export = meson_hasher_export, .import = meson_hasher_import, }, @@ -421,6 +444,7 @@ static struct meson_alg_template mc_algs[] = { .init = meson_sha_init, .update = meson_sha_update, .final = meson_sha_final, + .digest = meson_sha_digest, .export = meson_hasher_export, .import = meson_hasher_import, }, @@ -449,6 +473,7 @@ static struct meson_alg_template mc_algs[] = { .init = meson_sha_init, .update = meson_sha_update, .final = meson_sha_final, + .digest = meson_sha_digest, .export = meson_hasher_export, .import = meson_hasher_import, }, @@ -463,7 +488,7 @@ int meson_hasher_register(struct meson_dev *mc) int i; if (!mc->pdata->hasher_supported) { - pr_info("amlogic-gxl-hasher: hasher not supported at current platform"); + dev_dbg(mc->dev, "hasher is not supported on this platform\n"); return 0; } diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index a44290fcf3a0..3f1ce6c05558 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -161,7 +161,9 @@ struct meson_cipher_tfm_ctx { * @partial_size: size of the partial buffer * @partial_addr: physical address of partial buffer * @partial_mapped: indicates is partial buffer currently mapped or not - * @flags: request flags (for example, is this final req or not) + * @begin_req: indicates this is the first request + * @final_req: indicates this is the final request + * @digest_req: indicates a one-shot digest request * @flow: the flow to use for this request */ struct meson_hasher_req_ctx { @@ -173,6 +175,7 @@ struct meson_hasher_req_ctx { bool begin_req; bool final_req; + bool digest_req; int flow; }; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v14 19/30] crypto: amlogic: hasher: add one-shot digest path 2026-11-27 12:00 ` [PATCH v14 19/30] crypto: amlogic: hasher: add one-shot digest path Jose Nieto @ 2026-11-27 12:22 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-27 12:22 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] crypto: amlogic: unmapped partial_addr DMA buffer on meson_kick_hardware() error -- commit 3c19d4fb37e9f39951d2fec607a504c2dffee73a Author: Jose Nieto <jnieto.alaber@gmail.com> crypto: amlogic: hasher: add one-shot digest path This commit adds the ahash ->digest callback for one-shot SHA requests, unregisters the hasher on device removal, and lowers the unsupported platform message to dev_dbg. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-hasher.c b/drivers/crypto/amlogic/amlogic-gxl-hasher.c > index c83739ec34566..978cdcd8a4f91 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-hasher.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-hasher.c [ ... ] > @@ -310,6 +329,9 @@ static int meson_hasher_do_one_request(struct crypto_engine *engine, void *areq) > if (!ctx.todo && ctx.nbytes) > continue; > > + if (!ctx.todo && rctx->final_req && rctx->partial_size) > + continue; > + > if (!ctx.todo && !rctx->final_req && !ctx.tloffset) > continue; [Severity: Medium] Does meson_hasher_do_one_request() leak the rctx->partial_addr DMA mapping when meson_kick_hardware() fails or times out while flushing a partial block? When meson_fill_partial_buffer() maps rctx->partial, it sets rctx->partial_mapped = true. If wait_for_completion_timeout() fails in meson_kick_hardware(), it returns before reaching the dma_unmap_single() block for rctx->partial_addr, and the fail cleanup path in meson_hasher_do_one_request() only unmaps req->src and ctx.state_addr: drivers/crypto/amlogic/amlogic-gxl-hasher.c:meson_kick_hardware() { ... ret = wait_for_completion_timeout(&flow->complete, msecs_to_jiffies(500)); if (ret == 0) { dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); return -EINVAL; } else if (ret < 0) { dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", ret); return ret; } if (rctx->partial_mapped) { dma_unmap_single(mc->dev, rctx->partial_addr, rctx->partial_size, DMA_TO_DEVICE); ... } Unmapping rctx->partial_addr when rctx->partial_mapped is set in the error path (or before returning in meson_kick_hardware()) would avoid leaking the DMA mapping. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261127120103.1532882-1-jnieto.alaber@gmail.com?part=19 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v14 20/30] crypto: amlogic: drop unused field and stale includes 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (18 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 19/30] crypto: amlogic: hasher: add one-shot digest path Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 21/30] arm64: dts: amlogic: gxl: correct crypto node definition Jose Nieto ` (9 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Jose Nieto Remove the unused meson_flow.keylen field, drop unused includes in the cipher and core files, and fix stale kernel-doc field names. Signed-off-by: Jose Nieto <jnieto.alaber@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 3 --- drivers/crypto/amlogic/amlogic-gxl-core.c | 2 -- drivers/crypto/amlogic/amlogic-gxl.h | 10 +++------- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index 72892fdcd55d..c11ccbaf920d 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -9,9 +9,6 @@ */ #include <linux/crypto.h> -#include <linux/delay.h> -#include <linux/io.h> -#include <crypto/scatterwalk.h> #include <linux/scatterlist.h> #include <linux/dma-mapping.h> #include <crypto/internal/skcipher.h> diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 38b9645386ae..8ce3f6640753 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -19,9 +19,7 @@ #include <linux/of.h> #include <linux/of_device.h> #include <linux/platform_device.h> -#include <crypto/internal/skcipher.h> #include <crypto/internal/hash.h> -#include <linux/dma-mapping.h> #include "amlogic-gxl.h" diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index 3f1ce6c05558..9c3df0d162b9 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -69,18 +69,16 @@ struct meson_desc { /* * struct meson_flow - Information used by each flow * @engine: ptr to the crypto_engine for this flow - * @keylen: keylen for this flow operation * @complete: completion for the current task on this flow * @irq: IRQ number for amlogic-crypto * @t_phy: Physical address of task - * @tl: pointer to the current ce_task for this flow + * @tl: pointer to the current descriptor for this flow * @stat_req: number of request done by this flow */ struct meson_flow { struct crypto_engine *engine; struct completion complete; int irq; - unsigned int keylen; dma_addr_t t_phy; struct meson_desc *tl; #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG @@ -90,8 +88,8 @@ struct meson_flow { /* * struct meson_pdata - SoC series dependent data. - * @reg_descs: offset to descriptors register - * @reg_status: offset to status register + * @descs_reg: offset to descriptors register + * @status_reg: offset to status register * @setup_desc_cnt: number of setup descriptor to configure. * @hasher_supported: indecates whether hasher is supported. * @support_192bit_key: indicates whether platform support AES 192-bit key @@ -112,7 +110,6 @@ struct meson_pdata { * @flow: flow to use in next request * @flow_cnt: flow count for amlogic-crypto * @dbgfs_dir: Debugfs dentry for statistic directory - * @dbgfs_stats: Debugfs dentry for statistic counters */ struct meson_dev { void __iomem *base; @@ -181,7 +178,6 @@ struct meson_hasher_req_ctx { /* * struct meson_hasher_tfm_ctx - context for a hasher TFM - * @enginectx: crypto_engine used by this TFM * @mc: pointer to the private data of driver handling this TFM */ struct meson_hasher_tfm_ctx { -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 21/30] arm64: dts: amlogic: gxl: correct crypto node definition 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (19 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 20/30] crypto: amlogic: drop unused field and stale includes Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 22/30] arm64: dts: amlogic: a1: add crypto node Jose Nieto ` (8 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> GXL and newer SoC's uses the DMA engine (not blkmv) for crypto HW. Crypto HW doesn't actually use the blkmv clk. At RTL level, crypto engine is hard weired to clk81 (CLKID_CLK81). And remove clock-names field: according to the new dt-binding, it is no longer required. Also, GXL crypto IP isn't to seconnd interrput line. So we must remove it from dt-bindings. Fixes: c4a0457eb858 ("ARM64: dts: amlogic: adds crypto hardware node") Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- arch/arm64/boot/dts/amlogic/meson-gxl.dtsi | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/arm64/boot/dts/amlogic/meson-gxl.dtsi b/arch/arm64/boot/dts/amlogic/meson-gxl.dtsi index f257fe3860f7..5d0bffda8f19 100644 --- a/arch/arm64/boot/dts/amlogic/meson-gxl.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-gxl.dtsi @@ -68,10 +68,8 @@ acodec: audio-controller@c8832000 { crypto: crypto@c883e000 { compatible = "amlogic,gxl-crypto"; reg = <0x0 0xc883e000 0x0 0x36>; - interrupts = <GIC_SPI 188 IRQ_TYPE_EDGE_RISING>, - <GIC_SPI 189 IRQ_TYPE_EDGE_RISING>; - clocks = <&clkc CLKID_BLKMV>; - clock-names = "blkmv"; + interrupts = <GIC_SPI 188 IRQ_TYPE_EDGE_RISING>; + clocks = <&clkc CLKID_CLK81>; status = "okay"; }; }; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 22/30] arm64: dts: amlogic: a1: add crypto node 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (20 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 21/30] arm64: dts: amlogic: gxl: correct crypto node definition Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 23/30] arm64: dts: amlogic: s4: " Jose Nieto ` (7 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> This patch adds a crypto node declaration. With the Amlogic crypto driver we can use HW implementation of SHA1/224/256 and AES algo. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- arch/arm64/boot/dts/amlogic/meson-a1.dtsi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/arm64/boot/dts/amlogic/meson-a1.dtsi b/arch/arm64/boot/dts/amlogic/meson-a1.dtsi index 6f6a6145cba1..396260b7b398 100644 --- a/arch/arm64/boot/dts/amlogic/meson-a1.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-a1.dtsi @@ -686,6 +686,14 @@ sd_emmc: mmc@10000 { assigned-clocks = <&clkc_periphs CLKID_SD_EMMC>; assigned-clock-rates = <24000000>; }; + + crypto: crypto@6000 { + compatible = "amlogic,a1-crypto"; + reg = <0x0 0x6000 0x0 0x48>; + interrupts = <GIC_SPI 120 IRQ_TYPE_EDGE_RISING>; + clocks = <&clk81>; + power-domains = <&pwrc PWRC_DMA_ID>; + }; }; usb: usb@fe004400 { @@ -767,4 +775,10 @@ xtal: xtal-clk { clock-output-names = "xtal"; #clock-cells = <0>; }; + + clk81: clk81 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <64000000>; + }; }; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 23/30] arm64: dts: amlogic: s4: add crypto node 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (21 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 22/30] arm64: dts: amlogic: a1: add crypto node Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 24/30] arm64: dts: amlogic: g12: " Jose Nieto ` (6 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> This patch adds a crypto node declaration for Amlogic S4-series. With the Amlogic crypto driver we can use HW implementation of SHA1/224/256 and AES algo. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- arch/arm64/boot/dts/amlogic/meson-s4.dtsi | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/arm64/boot/dts/amlogic/meson-s4.dtsi b/arch/arm64/boot/dts/amlogic/meson-s4.dtsi index 2a6fbd530836..de173f40e15e 100644 --- a/arch/arm64/boot/dts/amlogic/meson-s4.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-s4.dtsi @@ -71,6 +71,12 @@ xtal: xtal-clk { #clock-cells = <0>; }; + clk81: clk81 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <166000000>; + }; + firmware { sm: secure-monitor { compatible = "amlogic,meson-gxbb-sm"; @@ -621,6 +627,13 @@ mux { }; + crypto: crypto@440400 { + compatible = "amlogic,s4-crypto", "amlogic,a1-crypto"; + reg = <0x0 0x440400 0x0 0x48>; + interrupts = <GIC_SPI 24 IRQ_TYPE_EDGE_RISING>; + clocks = <&clk81>; + }; + gpio_intc: interrupt-controller@4080 { compatible = "amlogic,meson-s4-gpio-intc", "amlogic,meson-gpio-intc"; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 24/30] arm64: dts: amlogic: g12: add crypto node 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (22 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 23/30] arm64: dts: amlogic: s4: " Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:36 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 25/30] arm64: dts: amlogic: axg: " Jose Nieto ` (5 subsequent siblings) 29 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> This patch adds a crypto node declaration for Amlogic G12-series. With the Amlogic crypto driver we can use HW implementation of SHA1/224/256 and AES algo. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi b/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi index 3135566df880..df1383f86366 100644 --- a/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi @@ -1742,6 +1742,13 @@ internal_ephy: ethernet-phy@8 { }; }; }; + + crypto: crypto@3e000 { + compatible = "amlogic,g12a-crypto"; + reg = <0x0 0x3e000 0x0 0x48>; + interrupts = <GIC_SPI 180 IRQ_TYPE_EDGE_RISING>; + clocks = <&clkc CLKID_CLK81>; + }; }; aobus: bus@ff800000 { -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v14 24/30] arm64: dts: amlogic: g12: add crypto node 2026-11-27 12:00 ` [PATCH v14 24/30] arm64: dts: amlogic: g12: " Jose Nieto @ 2026-11-27 12:36 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-27 12:36 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [High] crypto: amlogic: double completion on error in meson_hasher_do_one_request() - [High] crypto: amlogic: zero-byte SHA DMA descriptor in meson_hasher_do_one_request() - [High] crypto: amlogic: unaligned DMA request context in meson_hasher_do_one_request() - [Medium] crypto: amlogic: partial_addr DMA mapping leak in meson_kick_hardware() - [Medium] crypto: amlogic: unexpected req->src DMA map on final in meson_hasher_req_map() -- commit de440de738747f23777b7e1340e71b73e7c85fdd Author: Alexey Romanov <romanov.alexey2000@gmail.com> arm64: dts: amlogic: g12: add crypto node This series adds hardware SHA1/SHA224/SHA256 hashing support to the Amlogic crypto driver and enables the crypto node on Amlogic G12-series SoCs. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-hasher.c b/drivers/crypto/amlogic/amlogic-gxl-hasher.c > new file mode 100644 > index 0000000000000..978cdcd8a4f91 > --- /dev/null > +++ b/drivers/crypto/amlogic/amlogic-gxl-hasher.c > @@ -0,0 +1,510 @@ [ ... ] > +static int meson_hasher_req_map(struct ahash_request *req) > +{ > + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); > + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); > + struct meson_dev *mc = tctx->mc; > + int ret; > + > + if (!req->nbytes) > + return 0; > + > + ret = dma_map_sg(mc->dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); > + if (!ret) { > + dev_err(mc->dev, "Cannot DMA MAP request data\n"); > + return -ENOMEM; > + } > + > + return 0; > +} > + > +static void meson_hasher_req_unmap(struct ahash_request *req) > +{ > + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); > + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); > + struct meson_dev *mc = tctx->mc; > + > + if (!req->nbytes) > + return; > + > + dma_unmap_sg(mc->dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); > +} [Severity: Medium] Can meson_hasher_req_map() and meson_hasher_req_unmap() dereference a NULL or dangling req->src during crypto_ahash_final()? In meson_hasher_do_one_request(), ctx.nbytes is forced to 0 when rctx->final_req && !rctx->digest_req, because final() does not consume input from req->src. However, meson_hasher_req_map() and meson_hasher_req_unmap() check req->nbytes directly. If a caller leaves req->nbytes non-zero from an earlier update() (as ahash_def_finup() does) and releases or clears req->src before calling crypto_ahash_final(), sg_nents(req->src) and dma_map_sg() will access an invalid scatterlist. Checking ctx.nbytes instead of req->nbytes avoids mapping req->src on final requests. [ ... ] > +static int meson_kick_hardware(struct hasher_ctx *ctx) > +{ > + struct ahash_request *req = ahash_request_cast(ctx->areq); > + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); > + struct meson_hasher_req_ctx *rctx = ahash_request_ctx(req); > + struct meson_hasher_tfm_ctx *tctx = crypto_ahash_ctx_dma(tfm); > + struct meson_dev *mc = tctx->mc; > + struct meson_flow *flow = &mc->chanlist[rctx->flow]; > + int ret; > + > + reinit_completion(&flow->complete); > + meson_dma_start(mc, rctx->flow); > + > + ret = wait_for_completion_timeout(&flow->complete, > + msecs_to_jiffies(500)); > + if (ret == 0) { > + dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); > + return -EINVAL; > + } else if (ret < 0) { > + dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", ret); > + return ret; > + } > + > + if (rctx->partial_mapped) { > + dma_unmap_single(mc->dev, rctx->partial_addr, > + rctx->partial_size, > + DMA_TO_DEVICE); > + rctx->partial_size = 0; > + rctx->partial_mapped = false; > + } > + > + ctx->tloffset = 0; > + > + return 0; > +} [Severity: Medium] Does meson_kick_hardware() leak the rctx->partial_addr DMA mapping when wait_for_completion_timeout() times out? When rctx->partial_mapped is true and the wait times out, returning -EINVAL skips the dma_unmap_single() call below, and the fail path in meson_hasher_do_one_request() only unmaps req->src and ctx.state_addr. [ ... ] > + for (;;) { > + unsigned int len = ctx.src_sg ? > + min(sg_dma_len(ctx.src_sg) - ctx.src_offset, ctx.nbytes) : 0; > + > + ctx.src_addr = 0; > + ctx.todo = 0; > + > + if (!rctx->final_req && !ctx.nbytes) > + break; > + > + meson_setup_state_descs(&ctx); > + > + if (rctx->partial_size && rctx->partial_size < blocksize) { > + ret = meson_fill_partial_buffer(&ctx, len); > + if (ret) > + goto fail; > + } else if (len && len < blocksize) { > + memcpy(rctx->partial, sg_virt(ctx.src_sg) + ctx.src_offset, len); > + > + rctx->partial_size = len; > + ctx.nbytes -= len; > + ctx.src_offset += len; > + } else if (len) { > + ctx.src_addr = sg_dma_address(ctx.src_sg) + ctx.src_offset; > + ctx.todo = min(rounddown(DESC_MAXLEN, blocksize), > + rounddown(len, blocksize)); > + ctx.nbytes -= ctx.todo; > + ctx.src_offset += ctx.todo; > + } > + > + if (ctx.src_sg && ctx.src_offset == sg_dma_len(ctx.src_sg)) { > + ctx.src_offset = 0; > + ctx.src_sg = sg_next(ctx.src_sg); > + } > + > + if (!ctx.todo && ctx.nbytes) > + continue; > + > + if (!ctx.todo && rctx->final_req && rctx->partial_size) > + continue; > + > + if (!ctx.todo && !rctx->final_req && !ctx.tloffset) > + continue; > + > + if (meson_setup_data_descs(&ctx)) { > + ret = meson_kick_hardware(&ctx); > + if (ret) > + goto fail; > + } > + } [Severity: High] Can this loop submit a 0-byte SHA DMA descriptor with t_src = 0 during incremental crypto_ahash_update() calls, corrupting the hardware SHA state? There are two ways a non-final update() reaches meson_setup_data_descs() with ctx.todo == 0, ctx.src_addr == 0, ctx.nbytes == 0, and ctx.tloffset > 0: 1. If an update() request has full blocks followed by a trailing partial block (for example 70 bytes in one SG entry), the first iteration emits a 64-byte data descriptor without DESC_LAST (because ctx.nbytes is 6) and sets ctx.tloffset = 1. The second iteration copies the trailing 6 bytes into rctx->partial and sets ctx.nbytes = 0 while ctx.todo stays 0. 2. On a subsequent update() after an earlier hardware kick (so rctx->begin_req is false), meson_setup_state_descs() runs at the top of the loop and increments ctx.tloffset before checking whether the input will only be buffered into rctx->partial without filling a full block. In both cases, none of the three continue conditions match because ctx.tloffset is non-zero, so meson_setup_data_descs() appends a 0-length data descriptor at address 0 with DESC_LAST and kicks the DMA engine. > + > +fail: > + meson_hasher_req_unmap(req); > + > +fail_map_req: > + dma_unmap_single(mc->dev, ctx.state_addr, sizeof(rctx->state), > + DMA_BIDIRECTIONAL); > + > +fail_map_single: > + if (final_req && ret == 0) > + memcpy(req->result, rctx->state, digest_size); > + > + local_bh_disable(); > + crypto_finalize_hash_request(engine, req, ret); > + local_bh_enable(); > + > + return ret; > +} [Severity: High] Does returning a negative ret after crypto_finalize_hash_request() complete the request twice on error? crypto_finalize_hash_request() already completes req via crypto_request_complete(). Because the engine is initialized with crypto_engine_alloc_init(mc->dev, true) (so engine->retry_support is false), returning a negative error code from do_one_request() causes crypto_pump_requests() to call crypto_request_complete() a second time on the same request, leading to a double completion and use-after-free in callers that free the request in their completion callback. meson_hasher_do_one_request() should return 0 after finalizing the request, matching meson_handle_cipher_request(). [ ... ] > +static int meson_hasher_init(struct crypto_tfm *tfm) > +{ > + struct meson_hasher_tfm_ctx *tctx = crypto_tfm_ctx_dma(tfm); > + struct crypto_ahash *atfm = __crypto_ahash_cast(tfm); > + struct hash_alg_common *alg = crypto_hash_alg_common(atfm); > + struct meson_alg_template *algt = container_of(alg, > + struct meson_alg_template, alg.ahash.base.halg); > + > + crypto_ahash_set_reqsize_dma(atfm, crypto_ahash_statesize(atfm)); > + > + memset(tctx, 0, sizeof(struct meson_hasher_tfm_ctx)); > + > + tctx->mc = algt->mc; > + > + return 0; > +} [ ... ] > diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h > index d68094ffb70af..9c3df0d162b9b 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl.h > +++ b/drivers/crypto/amlogic/amlogic-gxl.h [ ... ] > +struct meson_hasher_req_ctx { > + u8 state[SHA256_DIGEST_SIZE + 16] ____cacheline_aligned; > + u8 partial[SHA256_BLOCK_SIZE] ____cacheline_aligned; > + unsigned int partial_size ____cacheline_aligned; > + dma_addr_t partial_addr; > + bool partial_mapped; > + > + bool begin_req; > + bool final_req; > + bool digest_req; > + int flow; > +}; [Severity: High] Can DMA cache maintenance on rctx->state and rctx->partial corrupt adjacent fields on non-coherent arm64 platforms? meson_hasher_init() reserves DMA alignment padding via crypto_ahash_set_reqsize_dma(), but the hasher callbacks retrieve the request context with ahash_request_ctx(req) instead of ahash_request_ctx_dma(req), leaving rctx only 8-byte aligned and sharing a cacheline with struct ahash_request. In addition, on arm64 ____cacheline_aligned is 64 bytes while ARCH_DMA_MINALIGN is 128 bytes. As a result, state (mapped DMA_BIDIRECTIONAL) and partial (written by the CPU while state is mapped, and mapped DMA_TO_DEVICE) share the same 128-byte DMA cacheline granule. Using ahash_request_ctx_dma() and aligning DMA buffers in struct meson_hasher_req_ctx with __aligned(ARCH_DMA_MINALIGN) avoids cacheline sharing during DMA unmap invalidation. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261127120103.1532882-1-jnieto.alaber@gmail.com?part=24 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v14 25/30] arm64: dts: amlogic: axg: add crypto node 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (23 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 24/30] arm64: dts: amlogic: g12: " Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:00 ` [PATCH v14 26/30] dt-bindings: crypto: amlogic,gxl-crypto: keep standard property order Jose Nieto ` (4 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Alexey Romanov From: Alexey Romanov <romanov.alexey2000@gmail.com> This patch adds a crypto node declaration. With the Amlogic crypto driver we can use HW implementation of SHA1/224/256 and AES algo. Signed-off-by: Alexey Romanov <romanov.alexey2000@gmail.com> --- arch/arm64/boot/dts/amlogic/meson-axg.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm64/boot/dts/amlogic/meson-axg.dtsi b/arch/arm64/boot/dts/amlogic/meson-axg.dtsi index 5b8ef98f6d03..e755a019b384 100644 --- a/arch/arm64/boot/dts/amlogic/meson-axg.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-axg.dtsi @@ -321,6 +321,13 @@ ethmac: ethernet@ff3f0000 { status = "disabled"; }; + crypto: crypto@ff63e000 { + compatible = "amlogic,axg-crypto"; + reg = <0x0 0xff63e000 0x0 0x48>; + interrupts = <GIC_SPI 180 IRQ_TYPE_EDGE_RISING>; + clocks = <&clkc CLKID_CLK81>; + }; + pcie_phy: phy@ff644000 { compatible = "amlogic,axg-pcie-phy"; reg = <0x0 0xff644000 0x0 0x1c>; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 26/30] dt-bindings: crypto: amlogic,gxl-crypto: keep standard property order 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (24 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 25/30] arm64: dts: amlogic: axg: " Jose Nieto @ 2026-11-27 12:00 ` Jose Nieto 2026-11-27 12:01 ` [PATCH v14 27/30] crypto: amlogic: fix probe and algorithm registration error paths Jose Nieto ` (3 subsequent siblings) 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:00 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Jose Nieto List clocks before interrupts, following the usual ordering of the crypto bindings. Signed-off-by: Jose Nieto <jnieto.alaber@gmail.com> --- .../devicetree/bindings/crypto/amlogic,gxl-crypto.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml b/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml index 106a9d1fed69..6f19e790ec0c 100644 --- a/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml +++ b/Documentation/devicetree/bindings/crypto/amlogic,gxl-crypto.yaml @@ -25,21 +25,21 @@ properties: reg: maxItems: 1 + clocks: + maxItems: 1 + interrupts: items: - description: Interrupt for flow 0 - clocks: - maxItems: 1 - power-domains: maxItems: 1 required: - compatible - reg - - interrupts - clocks + - interrupts allOf: - if: @@ -61,6 +61,6 @@ examples: crypto: crypto-engine@c883e000 { compatible = "amlogic,gxl-crypto"; reg = <0xc883e000 0x36>; - interrupts = <GIC_SPI 188 IRQ_TYPE_EDGE_RISING>; clocks = <&clkc CLKID_CLK81>; + interrupts = <GIC_SPI 188 IRQ_TYPE_EDGE_RISING>; }; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 27/30] crypto: amlogic: fix probe and algorithm registration error paths 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (25 preceding siblings ...) 2026-11-27 12:00 ` [PATCH v14 26/30] dt-bindings: crypto: amlogic,gxl-crypto: keep standard property order Jose Nieto @ 2026-11-27 12:01 ` Jose Nieto 2026-11-27 12:21 ` sashiko-bot 2026-11-27 12:01 ` [PATCH v14 28/30] crypto: amlogic: fix setup descriptor lengths and CBC IV copy Jose Nieto ` (2 subsequent siblings) 29 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:01 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Jose Nieto Fix error-path issues found during review: - meson_allocate_chanlist(): propagate a negative platform_irq_count() (e.g. -EPROBE_DEFER) instead of replacing it with -ENODEV, and unwind the channels already allocated when getting or requesting an IRQ fails. - meson_register_algs(): clear algs[i].mc before calling meson_unregister_algs(), so the entry that just failed to register is not unregistered again. Signed-off-by: Jose Nieto <jnieto.alaber@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-core.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index 8ce3f6640753..c11d7d8250ea 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -106,7 +106,9 @@ static int meson_allocate_chanlist(struct meson_dev *mc) int i, err; mc->flow_cnt = platform_irq_count(pdev); - if (mc->flow_cnt <= 0) { + if (mc->flow_cnt < 0) + return mc->flow_cnt; + if (mc->flow_cnt == 0) { dev_err(mc->dev, "No IRQs defined\n"); return -ENODEV; } @@ -117,14 +119,18 @@ static int meson_allocate_chanlist(struct meson_dev *mc) for (i = 0; i < mc->flow_cnt; i++) { mc->chanlist[i].irq = platform_get_irq(pdev, i); - if (mc->chanlist[i].irq < 0) - return mc->chanlist[i].irq; + if (mc->chanlist[i].irq < 0) { + err = mc->chanlist[i].irq; + i--; + goto error_engine; + } err = devm_request_irq(mc->dev, mc->chanlist[i].irq, meson_irq_handler, 0, "aml-crypto", mc); if (err < 0) { dev_err(mc->dev, "Cannot request IRQ for flow %d\n", i); - return err; + i--; + goto error_engine; } init_completion(&mc->chanlist[i].complete); @@ -169,6 +175,7 @@ int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *algs, if (err) { dev_err(mc->dev, "Fail to register %s\n", algs[i].alg.skcipher.base.base.cra_name); + algs[i].mc = NULL; meson_unregister_algs(mc, algs, count); return err; } @@ -178,6 +185,7 @@ int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *algs, if (err) { dev_err(mc->dev, "Fail to register %s\n", algs[i].alg.ahash.base.halg.base.cra_name); + algs[i].mc = NULL; meson_unregister_algs(mc, algs, count); return err; } -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v14 27/30] crypto: amlogic: fix probe and algorithm registration error paths 2026-11-27 12:01 ` [PATCH v14 27/30] crypto: amlogic: fix probe and algorithm registration error paths Jose Nieto @ 2026-11-27 12:21 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-27 12:21 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] crypto: amlogic: stale mc pointers left by meson_unregister_algs() - [Medium] crypto: amlogic: completion initialized after IRQ in meson_allocate_chanlist() -- commit 6f6ab6fadcd8280a6a563ddcf1e8fea62b447b00 Author: Jose Nieto <jnieto.alaber@gmail.com> crypto: amlogic: fix probe and algorithm registration error paths This commit updates meson_allocate_chanlist() to propagate negative return values from platform_irq_count() and unwind allocated channels on IRQ failure, and clears algs[i].mc on registration failure in meson_register_algs(). > diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c > index 8ce3f66407537..c11d7d8250eae 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-core.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c [ ... ] > @@ -117,14 +119,18 @@ static int meson_allocate_chanlist(struct meson_dev *mc) > > for (i = 0; i < mc->flow_cnt; i++) { > mc->chanlist[i].irq = platform_get_irq(pdev, i); > - if (mc->chanlist[i].irq < 0) > - return mc->chanlist[i].irq; > + if (mc->chanlist[i].irq < 0) { > + err = mc->chanlist[i].irq; > + i--; > + goto error_engine; > + } > > err = devm_request_irq(mc->dev, mc->chanlist[i].irq, > meson_irq_handler, 0, "aml-crypto", mc); > if (err < 0) { > dev_err(mc->dev, "Cannot request IRQ for flow %d\n", i); > - return err; > + i--; > + goto error_engine; > } > > init_completion(&mc->chanlist[i].complete); [Severity: Medium] Can meson_irq_handler() fire before mc->chanlist[i].complete is initialized? devm_request_irq() enables the interrupt before init_completion() runs. If a pending interrupt is raised in that window, meson_irq_handler() calls complete(&mc->chanlist[flow].complete) on a zeroed completion whose wait.task_list pointers are still NULL, causing a NULL pointer dereference in swake_up_locked(). Initializing the completion before requesting the IRQ avoids this window. > @@ -169,6 +175,7 @@ int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *algs, > if (err) { > dev_err(mc->dev, "Fail to register %s\n", > algs[i].alg.skcipher.base.base.cra_name); > + algs[i].mc = NULL; > meson_unregister_algs(mc, algs, count); > return err; > } > @@ -178,6 +185,7 @@ int meson_register_algs(struct meson_dev *mc, struct meson_alg_template *algs, > if (err) { > dev_err(mc->dev, "Fail to register %s\n", > algs[i].alg.ahash.base.halg.base.cra_name); > + algs[i].mc = NULL; > meson_unregister_algs(mc, algs, count); > return err; > } [Severity: Medium] Does meson_unregister_algs() leave stale non-NULL algs[i].mc pointers in the static algorithm template arrays? drivers/crypto/amlogic/amlogic-gxl-core.c:meson_unregister_algs() { for (i = 0; i < count; i++) { if (!algs[i].mc) continue; switch (algs[i].type) { case CRYPTO_ALG_TYPE_SKCIPHER: crypto_engine_unregister_skcipher(&algs[i].alg.skcipher); break; case CRYPTO_ALG_TYPE_AHASH: crypto_engine_unregister_ahash(&algs[i].alg.ahash); break; } } } Because the template arrays in amlogic-gxl-cipher.c and amlogic-gxl-hasher.c are static and meson_unregister_algs() does not clear algs[i].mc after unregistering, any unbind or probe rollback leaves dangling mc pointers across all entries. If a later probe fails partway through meson_register_algs() at index i < count - 1, clearing only algs[i].mc still leaves algs[i + 1 .. count - 1].mc non-NULL from the previous run, so meson_unregister_algs(mc, algs, count) will try to unregister algorithms that were not registered and hit WARN_ON() in crypto_unregister_alg(). Clearing algs[i].mc = NULL in meson_unregister_algs() (or passing i instead of count on rollback) would prevent this. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261127120103.1532882-1-jnieto.alaber@gmail.com?part=27 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v14 28/30] crypto: amlogic: fix setup descriptor lengths and CBC IV copy 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (26 preceding siblings ...) 2026-11-27 12:01 ` [PATCH v14 27/30] crypto: amlogic: fix probe and algorithm registration error paths Jose Nieto @ 2026-11-27 12:01 ` Jose Nieto 2026-11-27 12:20 ` sashiko-bot 2026-11-27 12:01 ` [PATCH v14 29/30] crypto: amlogic: drop redundant A1 platform data Jose Nieto 2026-11-27 12:01 ` [PATCH v14 30/30] arm64: dts: amlogic: use the system clock for A1/S4 crypto Jose Nieto 29 siblings, 1 reply; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:01 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Jose Nieto Fix the key/IV and SHA state setup descriptors and drop a duplicated CBC IV copy, found during review: - meson_setup_keyiv_descs(): program the per-descriptor length as keyiv.len / setup_desc_cnt instead of the full keyiv.len, so SoCs with more than one setup descriptor do not read past the key/IV buffer. - meson_setup_state_descs(): use MESON_SHA_BUFFER_SIZE / setup_desc_cnt for the same reason. - Drop the CBC IV memcpy() + dma_sync_single_for_device() in meson_setup_keyiv_descs(); the IV is already copied and the buffer mapped once in meson_cipher(). Signed-off-by: Jose Nieto <jnieto.alaber@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 15 +++------------ drivers/crypto/amlogic/amlogic-gxl-hasher.c | 3 ++- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index c11ccbaf920d..10815ffe3313 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -147,24 +147,13 @@ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) { struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); - struct skcipher_alg *alg = crypto_skcipher_alg(tfm); - struct meson_alg_template *algt = container_of(alg, - struct meson_alg_template, alg.skcipher.base); struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct meson_dev *mc = op->mc; - unsigned int ivsize = crypto_skcipher_ivsize(tfm); - unsigned int blockmode = algt->blockmode; int i; if (ctx->tloffset) return; - if (blockmode == DESC_OPMODE_CBC) { - memcpy(op->keyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); - dma_sync_single_for_device(mc->dev, ctx->keyiv.addr, - ctx->keyiv.len, DMA_TO_DEVICE); - } - for (i = 0; i < mc->pdata->setup_desc_cnt; i++) { struct meson_desc *desc = &mc->chanlist[rctx->flow].tl[ctx->tloffset]; @@ -172,7 +161,9 @@ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) desc->t_src = cpu_to_le32(ctx->keyiv.addr + offset); desc->t_dst = cpu_to_le32(offset); - desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | ctx->keyiv.len); + desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | + ctx->keyiv.len / + mc->pdata->setup_desc_cnt); ctx->tloffset++; } diff --git a/drivers/crypto/amlogic/amlogic-gxl-hasher.c b/drivers/crypto/amlogic/amlogic-gxl-hasher.c index 978cdcd8a4f9..710dd413bd51 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-hasher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-hasher.c @@ -253,7 +253,8 @@ static void meson_setup_state_descs(struct hasher_ctx *ctx) desc = &mc->chanlist[rctx->flow].tl[ctx->tloffset]; desc->t_src = cpu_to_le32(ctx->state_addr + offset); desc->t_dst = cpu_to_le32(offset); - desc->t_status = cpu_to_le32(MESON_SHA_BUFFER_SIZE | + desc->t_status = cpu_to_le32(MESON_SHA_BUFFER_SIZE / + mc->pdata->setup_desc_cnt | DESC_MODE_KEY | DESC_OWN); ctx->tloffset++; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* Re: [PATCH v14 28/30] crypto: amlogic: fix setup descriptor lengths and CBC IV copy 2026-11-27 12:01 ` [PATCH v14 28/30] crypto: amlogic: fix setup descriptor lengths and CBC IV copy Jose Nieto @ 2026-11-27 12:20 ` sashiko-bot 0 siblings, 0 replies; 81+ messages in thread From: sashiko-bot @ 2026-11-27 12:20 UTC (permalink / raw) To: Jose Nieto, Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] crypto: amlogic: ECB key truncation and DMA OOB in meson_setup_keyiv_descs() - [High] crypto: amlogic: broken multi-batch CBC IV update in meson_setup_keyiv_descs() -- commit 9246a121ba55b6e8c714e81736c007cdd1b7ad72 Author: Jose Nieto <jnieto.alaber@gmail.com> crypto: amlogic: fix setup descriptor lengths and CBC IV copy This commit divides the key/IV and SHA state setup descriptor lengths by setup_desc_cnt and drops the CBC IV copy and DMA sync from meson_setup_keyiv_descs(). > diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c > index c11ccbaf920dd..10815ffe33135 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c > @@ -147,24 +147,13 @@ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) > { > struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); > struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); > - struct skcipher_alg *alg = crypto_skcipher_alg(tfm); > - struct meson_alg_template *algt = container_of(alg, > - struct meson_alg_template, alg.skcipher.base); > struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); > struct meson_dev *mc = op->mc; > - unsigned int ivsize = crypto_skcipher_ivsize(tfm); > - unsigned int blockmode = algt->blockmode; > int i; > > if (ctx->tloffset) > return; > > - if (blockmode == DESC_OPMODE_CBC) { > - memcpy(op->keyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); > - dma_sync_single_for_device(mc->dev, ctx->keyiv.addr, > - ctx->keyiv.len, DMA_TO_DEVICE); > - } > - [Severity: High] Does removing this memcpy() and dma_sync_single_for_device() break CBC IV chaining when a request spans multiple descriptor batches? meson_cipher() copies the initial IV into op->keyiv before the while (ctx.cryptlen) loop, but when a batch fills MAXDESC descriptors, meson_kick_hardware() saves the chaining IV for the next batch into ctx->areq->iv and resets ctx->tloffset to 0: drivers/crypto/amlogic/amlogic-gxl-cipher.c:meson_kick_hardware() { ... if (blockmode == DESC_OPMODE_CBC && rctx->op_dir == MESON_ENCRYPT) { dma_sync_sg_for_cpu(mc->dev, sg_head, sg_nents(sg_head), new_iv_dir); memcpy(ctx->areq->iv, new_iv, ivsize); } ctx->tloffset = 0; ... } Without updating and syncing op->keyiv + AES_MAX_KEY_SIZE in meson_setup_keyiv_descs(), subsequent batches reload the initial IV instead of the updated ctx->areq->iv, corrupting multi-batch CBC encryption and decryption. > for (i = 0; i < mc->pdata->setup_desc_cnt; i++) { > struct meson_desc *desc = > &mc->chanlist[rctx->flow].tl[ctx->tloffset]; > @@ -172,7 +161,9 @@ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) > > desc->t_src = cpu_to_le32(ctx->keyiv.addr + offset); > desc->t_dst = cpu_to_le32(offset); > - desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | ctx->keyiv.len); > + desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | > + ctx->keyiv.len / > + mc->pdata->setup_desc_cnt); > > ctx->tloffset++; > } [Severity: High] Does dividing ctx->keyiv.len by mc->pdata->setup_desc_cnt truncate the AES key and read out of bounds in ECB mode on GXL and AXG? In meson_cipher(), ctx.keyiv.len is only extended to 48 bytes (AES_MAX_KEY_SIZE + ivsize) for DESC_OPMODE_CBC, so for ecb(aes) ctx.keyiv.len and its DMA mapping are 16 or 32 bytes: drivers/crypto/amlogic/amlogic-gxl-cipher.c:meson_cipher() { ... ctx.keyiv.len = op->keylen; if (ctx.keyiv.len == AES_KEYSIZE_192) ctx.keyiv.len = AES_MAX_KEY_SIZE; if (algt->blockmode == DESC_OPMODE_CBC) { memcpy(op->keyiv + AES_MAX_KEY_SIZE, areq->iv, ivsize); ctx.keyiv.len = AES_MAX_KEY_SIZE + ivsize; } ctx.keyiv.addr = dma_map_single(mc->dev, op->keyiv, ctx.keyiv.len, DMA_TO_DEVICE); ... } On GXL and AXG, setup_desc_cnt is 3. In ECB mode, ctx->keyiv.len / 3 evaluates to 5 bytes (AES-128) or 10 bytes (AES-192/256) per descriptor instead of 16, while the loop still emits 3 descriptors at offsets 0, 16 and 32, loading a truncated key and performing DMA reads past the mapped ctx.keyiv.len bytes. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261127120103.1532882-1-jnieto.alaber@gmail.com?part=28 ^ permalink raw reply [flat|nested] 81+ messages in thread
* [PATCH v14 29/30] crypto: amlogic: drop redundant A1 platform data 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (27 preceding siblings ...) 2026-11-27 12:01 ` [PATCH v14 28/30] crypto: amlogic: fix setup descriptor lengths and CBC IV copy Jose Nieto @ 2026-11-27 12:01 ` Jose Nieto 2026-11-27 12:01 ` [PATCH v14 30/30] arm64: dts: amlogic: use the system clock for A1/S4 crypto Jose Nieto 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:01 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Jose Nieto meson_a1_pdata is identical to meson_g12a_pdata; drop the duplicate and reuse meson_g12a_pdata for the A1 and S4 match entries. Signed-off-by: Jose Nieto <jnieto.alaber@gmail.com> --- drivers/crypto/amlogic/amlogic-gxl-core.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c index c11d7d8250ea..d11319425d5f 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-core.c +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c @@ -305,14 +305,6 @@ static const struct meson_pdata meson_axg_pdata = { .support_192bit_key = true, }; -static const struct meson_pdata meson_a1_pdata = { - .descs_reg = 0x0, - .status_reg = 0x8, - .setup_desc_cnt = 1, - .hasher_supported = true, - .support_192bit_key = false, -}; - static const struct of_device_id meson_crypto_of_match_table[] = { { .compatible = "amlogic,gxl-crypto", @@ -328,11 +320,11 @@ static const struct of_device_id meson_crypto_of_match_table[] = { }, { .compatible = "amlogic,a1-crypto", - .data = &meson_a1_pdata, + .data = &meson_g12a_pdata, }, { .compatible = "amlogic,s4-crypto", - .data = &meson_a1_pdata, + .data = &meson_g12a_pdata, }, {}, }; -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
* [PATCH v14 30/30] arm64: dts: amlogic: use the system clock for A1/S4 crypto 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto ` (28 preceding siblings ...) 2026-11-27 12:01 ` [PATCH v14 29/30] crypto: amlogic: drop redundant A1 platform data Jose Nieto @ 2026-11-27 12:01 ` Jose Nieto 29 siblings, 0 replies; 81+ messages in thread From: Jose Nieto @ 2026-11-27 12:01 UTC (permalink / raw) To: Corentin Labbe, Herbert Xu Cc: linux-crypto, linux-amlogic, linux-arm-kernel, devicetree, Neil Armstrong, Martin Blumenstingl, Krzysztof Kozlowski, Rob Herring, Conor Dooley, Jose Nieto The A1 and S4 crypto engines are clocked by the SoC system bus clock provided by the peripheral clock controller. Use <&clkc_periphs CLKID_SYS> and drop the synthetic 64/166 MHz clk81 fixed-clock nodes. Signed-off-by: Jose Nieto <jnieto.alaber@gmail.com> --- arch/arm64/boot/dts/amlogic/meson-a1.dtsi | 8 +------- arch/arm64/boot/dts/amlogic/meson-s4.dtsi | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/arch/arm64/boot/dts/amlogic/meson-a1.dtsi b/arch/arm64/boot/dts/amlogic/meson-a1.dtsi index 396260b7b398..1b064c556c68 100644 --- a/arch/arm64/boot/dts/amlogic/meson-a1.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-a1.dtsi @@ -691,7 +691,7 @@ crypto: crypto@6000 { compatible = "amlogic,a1-crypto"; reg = <0x0 0x6000 0x0 0x48>; interrupts = <GIC_SPI 120 IRQ_TYPE_EDGE_RISING>; - clocks = <&clk81>; + clocks = <&clkc_periphs CLKID_SYS>; power-domains = <&pwrc PWRC_DMA_ID>; }; }; @@ -775,10 +775,4 @@ xtal: xtal-clk { clock-output-names = "xtal"; #clock-cells = <0>; }; - - clk81: clk81 { - compatible = "fixed-clock"; - #clock-cells = <0>; - clock-frequency = <64000000>; - }; }; diff --git a/arch/arm64/boot/dts/amlogic/meson-s4.dtsi b/arch/arm64/boot/dts/amlogic/meson-s4.dtsi index de173f40e15e..c004ab7bbdfd 100644 --- a/arch/arm64/boot/dts/amlogic/meson-s4.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-s4.dtsi @@ -71,12 +71,6 @@ xtal: xtal-clk { #clock-cells = <0>; }; - clk81: clk81 { - compatible = "fixed-clock"; - #clock-cells = <0>; - clock-frequency = <166000000>; - }; - firmware { sm: secure-monitor { compatible = "amlogic,meson-gxbb-sm"; @@ -631,7 +625,7 @@ crypto: crypto@440400 { compatible = "amlogic,s4-crypto", "amlogic,a1-crypto"; reg = <0x0 0x440400 0x0 0x48>; interrupts = <GIC_SPI 24 IRQ_TYPE_EDGE_RISING>; - clocks = <&clk81>; + clocks = <&clkc_periphs CLKID_SYS>; }; gpio_intc: interrupt-controller@4080 { -- 2.47.3 ^ permalink raw reply related [flat|nested] 81+ messages in thread
end of thread, other threads:[~2026-11-27 12:36 UTC | newest] Thread overview: 81+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-26 19:32 [PATCH v13 00/25] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto 2026-11-26 19:32 ` [PATCH v13 01/25] dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines Jose Nieto 2026-11-26 19:43 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 02/25] dt-bindings: crypto: amlogic,gxl-crypto: support new SoC's Jose Nieto 2026-11-26 19:32 ` [PATCH v13 03/25] crypto: amlogic - Don't hardcode IRQ count Jose Nieto 2026-11-26 19:42 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 04/25] crypto: amlogic - Add platform data Jose Nieto 2026-11-26 19:32 ` [PATCH v13 05/25] crypto: amlogic - Remove clock input Jose Nieto 2026-11-26 19:44 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 06/25] crypto: amlogic - Add MMIO helpers Jose Nieto 2026-11-26 19:32 ` [PATCH v13 07/25] crypto: amlogic - Move get_engine_number() Jose Nieto 2026-11-26 19:32 ` [PATCH v13 08/25] crypto: amlogic - Drop status field from meson_flow Jose Nieto 2026-11-26 19:32 ` [PATCH v13 09/25] crypto: amlogic - Move algs definition and cipher API to cipher.c Jose Nieto 2026-11-26 19:41 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 10/25] crypto: amlogic - Cleanup defines Jose Nieto 2026-11-26 19:32 ` [PATCH v13 11/25] crypto: amlogic - Process more than MAXDESCS descriptors Jose Nieto 2026-11-26 19:45 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 12/25] crypto: amlogic - Avoid kzalloc in engine thread Jose Nieto 2026-11-26 19:48 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 13/25] crypto: amlogic - Introduce hasher Jose Nieto 2026-11-26 19:56 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 14/25] crypto: amlogic - Use fallback for 192-bit keys Jose Nieto 2026-11-26 19:32 ` [PATCH v13 15/25] crypto: amlogic - Add support for G12-series Jose Nieto 2026-11-26 19:55 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 16/25] crypto: amlogic - Add support for AXG-series Jose Nieto 2026-11-26 19:32 ` [PATCH v13 17/25] crypto: amlogic - Add support for A1-series Jose Nieto 2026-11-26 19:48 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 18/25] crypto: amlogic: g12: drop CRYPTO_ALG_ALLOCATES_MEMORY Jose Nieto 2026-11-26 19:32 ` [PATCH v13 19/25] crypto: amlogic: hasher: add one-shot digest path Jose Nieto 2026-11-26 19:50 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 20/25] crypto: amlogic: drop unused field and stale includes Jose Nieto 2026-11-26 19:32 ` [PATCH v13 21/25] arm64: dts: amlogic: gxl: correct crypto node definition Jose Nieto 2026-11-26 19:32 ` [PATCH v13 22/25] arm64: dts: amlogic: a1: add crypto node Jose Nieto 2026-11-26 20:01 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 23/25] arm64: dts: amlogic: s4: " Jose Nieto 2026-11-26 20:02 ` sashiko-bot 2026-11-26 19:32 ` [PATCH v13 24/25] arm64: dts: amlogic: g12: " Jose Nieto 2026-11-26 19:32 ` [PATCH v13 25/25] arm64: dts: amlogic: axg: " Jose Nieto 2026-11-26 20:00 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 00/30] crypto: amlogic: add support for G12/AXG/A1/S4 and misc fixes Jose Nieto 2026-11-27 12:00 ` [PATCH v14 01/30] dt-bindings: crypto: amlogic,gxl-crypto: correct clk and interrupt lines Jose Nieto 2026-11-27 12:00 ` [PATCH v14 02/30] dt-bindings: crypto: amlogic,gxl-crypto: support new SoC's Jose Nieto 2026-11-27 12:00 ` [PATCH v14 03/30] crypto: amlogic - Don't hardcode IRQ count Jose Nieto 2026-11-27 12:11 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 04/30] crypto: amlogic - Add platform data Jose Nieto 2026-11-27 12:00 ` [PATCH v14 05/30] crypto: amlogic - Remove clock input Jose Nieto 2026-11-27 12:14 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 06/30] crypto: amlogic - Add MMIO helpers Jose Nieto 2026-11-27 12:00 ` [PATCH v14 07/30] crypto: amlogic - Move get_engine_number() Jose Nieto 2026-11-27 12:00 ` [PATCH v14 08/30] crypto: amlogic - Drop status field from meson_flow Jose Nieto 2026-11-27 12:00 ` [PATCH v14 09/30] crypto: amlogic - Move algs definition and cipher API to cipher.c Jose Nieto 2026-11-27 12:14 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 10/30] crypto: amlogic - Cleanup defines Jose Nieto 2026-11-27 12:00 ` [PATCH v14 11/30] crypto: amlogic - Process more than MAXDESCS descriptors Jose Nieto 2026-11-27 12:13 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 12/30] crypto: amlogic - Avoid kzalloc in engine thread Jose Nieto 2026-11-27 12:18 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 13/30] crypto: amlogic - Introduce hasher Jose Nieto 2026-11-27 12:24 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 14/30] crypto: amlogic - Use fallback for 192-bit keys Jose Nieto 2026-11-27 12:00 ` [PATCH v14 15/30] crypto: amlogic - Add support for G12-series Jose Nieto 2026-11-27 12:27 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 16/30] crypto: amlogic - Add support for AXG-series Jose Nieto 2026-11-27 12:00 ` [PATCH v14 17/30] crypto: amlogic - Add support for A1-series Jose Nieto 2026-11-27 12:00 ` [PATCH v14 18/30] crypto: amlogic: g12: drop CRYPTO_ALG_ALLOCATES_MEMORY Jose Nieto 2026-11-27 12:00 ` [PATCH v14 19/30] crypto: amlogic: hasher: add one-shot digest path Jose Nieto 2026-11-27 12:22 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 20/30] crypto: amlogic: drop unused field and stale includes Jose Nieto 2026-11-27 12:00 ` [PATCH v14 21/30] arm64: dts: amlogic: gxl: correct crypto node definition Jose Nieto 2026-11-27 12:00 ` [PATCH v14 22/30] arm64: dts: amlogic: a1: add crypto node Jose Nieto 2026-11-27 12:00 ` [PATCH v14 23/30] arm64: dts: amlogic: s4: " Jose Nieto 2026-11-27 12:00 ` [PATCH v14 24/30] arm64: dts: amlogic: g12: " Jose Nieto 2026-11-27 12:36 ` sashiko-bot 2026-11-27 12:00 ` [PATCH v14 25/30] arm64: dts: amlogic: axg: " Jose Nieto 2026-11-27 12:00 ` [PATCH v14 26/30] dt-bindings: crypto: amlogic,gxl-crypto: keep standard property order Jose Nieto 2026-11-27 12:01 ` [PATCH v14 27/30] crypto: amlogic: fix probe and algorithm registration error paths Jose Nieto 2026-11-27 12:21 ` sashiko-bot 2026-11-27 12:01 ` [PATCH v14 28/30] crypto: amlogic: fix setup descriptor lengths and CBC IV copy Jose Nieto 2026-11-27 12:20 ` sashiko-bot 2026-11-27 12:01 ` [PATCH v14 29/30] crypto: amlogic: drop redundant A1 platform data Jose Nieto 2026-11-27 12:01 ` [PATCH v14 30/30] arm64: dts: amlogic: use the system clock for A1/S4 crypto Jose Nieto
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox