crypto: rockchip: Add RK356x/RK3588 cryptographic
Subsystems (4)
cover crypto: rockchip: Add RK356x/RK3588 cryptographic
This series adds support for the second-generation (V2) Rockchip cryptographic hardware accelerator found on RK3568 and RK3588 SoCs.
The IP block provides AES (ECB, CBC, XTS) and hash (SHA-1, SHA-256, SHA-384, SHA-512, MD5, SM3) offload via an LLI-based DMA engine.
The series is ordered as required: binding first, then driver, then the two DTS nodes that reference the binding.
A prerequisite patch removing SECURECRU reset definitions from the non-secure CRU driver is sent separately to the clk/reset tree, as it touches a different subsystem. That patch is not a hard dependency for the driver to build or load, but it is needed for correctness on RK3588:
those register offsets map into TrustZone-protected MMIO and must not be accessed directly by Linux.
This work started from unmerged patches by Corentin Labbe <[email protected]> posted at:
https://patchew.org/linux/[email protected]/
The implementation has been substantially reworked. Notable changes from Corentin's original series:
- DMA descriptor race condition and DMA mapping leak on timeout fixed
- Per-device algorithm copy replaces global device list, removing a locking bottleneck and correctly supporting multiple instances
- Runtime PM autosuspend added; clocks and reset gated between requests
- Multi-SG hash requests routed to software fallback (hardware padding engine requires total message length upfront and cannot maintain state across LLI boundaries)
- Hardware interrupt enable register write corrected to use the HIWORD_UPDATE mask that the hardware requires
- Software fallback for all registered algorithms; statesize promotion for export/import compatibility with ARM Crypto Extensions drivers
- SCMI reset and clock references in DTS corrected for RK3588
Tested on Orange Pi 5 Pro (RK3588S). All nine algorithm selftests pass. AES-CBC throughput measured at ~100 MiB/s with cryptsetup. PM autosuspend/resume verified over 1000 consecutive hash requests with no errors. 20 modprobe/rmmod cycles produce no DMA coherent memory leaks.
Patch series for the crypto subsystem:
[1/4] dt-bindings: crypto: rockchip: Add RK356x/RK3588 crypto engine binding
[2/4] crypto: rockchip: Add RK356x/RK3588 cryptographic offloader driver [3/4] arm64: dts: rockchip: Add crypto node to rk356x-base [4/4] arm64: dts: rockchip: Add crypto node to rk3588-base
Separate patch for clk/reset tree:
clk: rockchip: rk3588: Remove SECURECRU reset definitions
Dawid Olesinski (4):
dt-bindings: crypto: rockchip: Add RK356x/RK3588 crypto engine binding
crypto: rockchip: Add RK356x/RK3588 cryptographic offloader driver
arm64: dts: rockchip: Add crypto node to rk356x-base
arm64: dts: rockchip: Add crypto node to rk3588-base
.../crypto/rockchip,rk3588-crypto.yaml | 69 ++ arch/arm64/boot/dts/rockchip/rk356x-base.dtsi | 12 + arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 12 + drivers/crypto/Kconfig | 33 + drivers/crypto/Makefile | 1 + drivers/crypto/rockchip/Makefile | 5 + drivers/crypto/rockchip/rk2_crypto.c | 740 ++++++++++++++++++ drivers/crypto/rockchip/rk2_crypto.h | 243 ++++++ drivers/crypto/rockchip/rk2_crypto_ahash.c | 547 +++++++++++++ drivers/crypto/rockchip/rk2_crypto_skcipher.c | 724 +++++++++++++++++ 10 files changed, 2386 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml create mode 100644 drivers/crypto/rockchip/rk2_crypto.c create mode 100644 drivers/crypto/rockchip/rk2_crypto.h create mode 100644 drivers/crypto/rockchip/rk2_crypto_ahash.c create mode 100644 drivers/crypto/rockchip/rk2_crypto_skcipher.c
Signature · 1 line
2.47.3
PATCH 1/4 dt-bindings: crypto: rockchip: Add RK356x/RK3588 crypto engine binding
Add a YAML device tree binding for the Rockchip second-generation (V2) cryptographic hardware accelerator present on the RK3568 and RK3588 SoCs.
The IP block exposes AES-ECB, AES-CBC, AES-XTS block ciphers, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, MD5, and SM3 hash algorithms, each with a hardware DMA engine controlled via linked-list descriptors.
The binding covers two compatible strings:
- rockchip,rk3568-crypto: clocks and resets are driven directly by the non-secure CRU (accessible to Linux at EL1).
- rockchip,rk3588-crypto: clocks and resets live in SECURECRU, a register bank sandboxed to TrustZone. Linux must request them through the ARM SCMI firmware interface (scmi_clk / scmi_reset), as direct MMIO access to SECURECRU from EL1 triggers a bus fault.
--- .../crypto/rockchip,rk3588-crypto.yaml | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +69 -0
@@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/crypto/rockchip,rk3588-crypto.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Rockchip cryptographic offloader + +maintainers: + - Heiko Stuebner <[email protected]> + - Corentin Labbe <[email protected]> + - Dawid Olesinski <[email protected]> + +properties: + compatible: + enum: + - rockchip,rk3568-crypto + - rockchip,rk3588-crypto + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + items: + - description: Core clock for the crypto IP internal logic + - description: AXI interconnect clock interface + - description: AHB interface clock + + clock-names: + items: + - const: core + - const: aclk + - const: hclk + + resets: + maxItems: 1 + + reset-names: + items: + - const: core + +required: + - compatible + - reg + - interrupts + - clocks + - clock-names + - resets + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + + crypto@fe370000 { + compatible = "rockchip,rk3588-crypto"; + reg = <0x0 0xfe370000 0x0 0x2000>; + interrupts = <GIC_SPI 209 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&scmi_clk SCMI_CRYPTO_CORE>, + <&scmi_clk SCMI_ACLK_SECURE_NS>, + <&scmi_clk SCMI_HCLK_SECURE_NS>; + clock-names = "core", "aclk", "hclk"; + resets = <&scmi_reset SCMI_SRST_CRYPTO_CORE>; + reset-names = "core"; + };
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 1/4] dt-bindings: crypto: rockchip: Add RK356x/RK3588 crypto engine binding
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Shared interrupt is registered before hardware clocks are enabled and driver structures are…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Shared interrupt is registered before hardware clocks are enabled and driver structures are initialized, risking an unhandled bus fault.
- [Low] The device tree example fails to compile with dtc and dt_binding_check due to undefined SCMI macros.
- [Low] The device tree example will fail validation in dt_binding_check due to a mismatch between the reg property length and the default #address-cells/#size-cells. --
commit e90ad76061a5abfb6bd1bbdaa25b14862d6be7d3
Author: Dawid Olesinski <[email protected]>
dt-bindings: crypto: rockchip: Add RK356x/RK3588 crypto engine binding
Add a YAML device tree binding for the Rockchip second-generation (V2) cryptographic hardware accelerator present on the RK3568 and RK3588 SoCs.
Quoted 5 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +0
-0
[ ... ]
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml line 61
Quoted 7 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +7
-0+examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + + crypto@fe370000 { + compatible = "rockchip,rk3588-crypto"; + reg = <0x0 0xfe370000 0x0 0x2000>;
[Severity: Low]
Does this node need to be wrapped in a parent block that specifies #address-cells = <2> and #size-cells = <2>?
Since this node is at the top level of the example, dt_binding_check defaults both properties to 1, which causes a length mismatch with this 4-cell reg property. This will trigger a dtc invalid length warning and cause dt-validate to fail.
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml line 65
Quoted 4 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +4
-0+ interrupts = <GIC_SPI 209 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&scmi_clk SCMI_CRYPTO_CORE>, + <&scmi_clk SCMI_ACLK_SECURE_NS>, + <&scmi_clk SCMI_HCLK_SECURE_NS>;
[Severity: Low]
Are the SCMI clock macros defined anywhere in this example?
It looks like the #include directives for the SCMI headers (e.g., <dt-bindings/clock/rockchip,rk3588-cru.h>) are missing. During make dt_binding_check, these macros are left unexpanded, resulting in dtc syntax errors because bare strings are invalid inside a < > array.
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml line 67
Quoted 2 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +2
-0+ clock-names = "core", "aclk", "hclk"; + resets = <&scmi_reset SCMI_SRST_CRYPTO_CORE>;
[Severity: Low]
Are the SCMI reset macros defined anywhere in this example?
Similar to the clocks property, the reset macro #include is missing (e.g., <dt-bindings/reset/rockchip,rk3588-cru.h>), which will cause dtc and dt_binding_check to fail.
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml line 69
Quoted 2 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +2
-0+ reset-names = "core"; + };
[ ... ]
Also, looking at the driver code added later in this patch series:
Quoted 5 lines
drivers/crypto/rockchip/rk2_crypto.c new file +0
-0
[ ... ]
Quoted 5 lines
drivers/crypto/rockchip/rk2_crypto.c new file +5
-0+static int rk2_crypto_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct rk2_crypto_dev *rkc; +int err =0 ;
[ ... ]
Quoted 20 lines
drivers/crypto/rockchip/rk2_crypto.c new file +20
-0+ err =devm_request_irq (dev, rkc->irq, + rk2_crypto_irq_handle,IRQF_SHARED , +"rk-crypto" , pdev); + +if (err) { + err =dev_err_probe (dev, err,"irq request failed.\n" ); + goto err_dma; + } + + rkc->engine =crypto_engine_alloc_init (dev, true); +if (!rkc->engine) { + err = -ENOMEM ; + goto err_dma; + } + + err =crypto_engine_start (rkc->engine); +if (err) { + err =dev_err_probe (dev, err,"Failed to start crypto engine\n" ); + goto err_engine; + }
drivers/crypto/rockchip/rk2_crypto.c
Quoted 10 lines
drivers/crypto/rockchip/rk2_crypto.c new file +10
-0+ +init_completion (&rkc->complete); + + err =rk2_crypto_pm_init (rkc); +if (err) { + err =dev_err_probe (dev, err,"Failed to initialize runtime PM\n" ); + goto err_engine; + } + + err =pm_runtime_resume_and_get (dev);
[Severity: High]
Is it safe to request the shared IRQ before the hardware clocks are enabled and rkc->complete is initialized?
If another device sharing this IRQ triggers an interrupt during this window, rk2_crypto_irq_handle() could be invoked. Reading RK2_CRYPTO_DMA_INT_ST without clocks enabled would trigger a synchronous external abort (bus fault), leading to a kernel panic. It would also attempt to call complete() on an uninitialized structure.
[ ... ]
Quoted 11 lines
drivers/crypto/rockchip/rk2_crypto.c new file +11
-0+static void rk2_crypto_remove (struct platform_device *pdev) +{ +struct rk2_crypto_dev *rkc =platform_get_drvdata (pdev); + +/* Stop engine to prevent new requests */ +crypto_engine_stop (rkc->engine); + +/* Unregister algorithms for this specific device */ +rk2_crypto_unregister (rkc); + +#ifdef CONFIG_CRYPTO_DEV_ROCKCHIP2_DEBUG
drivers/crypto/rockchip/rk2_crypto.c
Quoted 10 lines
drivers/crypto/rockchip/rk2_crypto.c new file +10
-0+debugfs_remove_recursive (rkc->dbgfs_dir); +#endif + +/* Safe to kill the engine completely */ +crypto_engine_exit (rkc->engine); + +rk2_crypto_pm_exit (rkc); +dma_free_coherent (rkc->dev,sizeof (struct rk2_crypto_lli ) *MAX_LLI , + rkc->tl, rkc->t_phy); +}
[Severity: High]
Can rk2_crypto_pm_exit(rkc) disable runtime PM (gating clocks) while the devres-managed shared IRQ is still active?
This would reopen the bus fault window during module unload, as the IRQ is not freed until devres cleanup occurs after rk2_crypto_remove() returns.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Rob Herring (Arm)
maintainerRe: [PATCH 1/4] dt-bindings: crypto: rockchip: Add RK356x/RK3588 crypto engine binding
In reply to Dawid OlesinskiQuoted 16 lines · Dawid Olesinski
Add a YAML device tree binding for the Rockchip second-generation (V2) cryptographic hardware accelerator present on the RK3568 and RK3588 SoCs.
The IP block exposes AES-ECB, AES-CBC, AES-XTS block ciphers, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, MD5, and SM3 hash algorithms, each with a hardware DMA engine controlled via linked-list descriptors.
The binding covers two compatible strings:
- rockchip,rk3568-crypto: clocks and resets are driven directly by the non-secure CRU (accessible to Linux at EL1).
- rockchip,rk3588-crypto: clocks and resets live in SECURECRU, a register bank sandboxed to TrustZone. Linux must request them through the ARM SCMI firmware interface (scmi_clk/scmi_reset), as direct MMIO access to SECURECRU from EL1 triggers a bus fault.
Quoted 6 lines
Signed-off-by Dawid Olesinski <[email protected]>--- .../crypto/rockchip,rk3588-crypto.yaml | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:
dtschema/dtc warnings/errors:
Lexical error: Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.example.dts:30.33-49 Unexpected 'SCMI_CRYPTO_CORE' Lexical error: Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.example.dts:31.33-52 Unexpected 'SCMI_ACLK_SECURE_NS' Lexical error: Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.example.dts:32.33-52 Unexpected 'SCMI_HCLK_SECURE_NS' Lexical error: Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.example.dts:34.35-56 Unexpected 'SCMI_SRST_CRYPTO_CORE' FATAL ERROR: Syntax error parsing input tree
make[2]: *** [scripts/Makefile.dtbs:140: Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.example.dtb] Error 1 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/builds/robherring/dt-review-ci/linux/Makefile:1660: dt_binding_check] Error 2
make: *** [Makefile:248: __sub-make] Error 2
doc reference errors (make refcheckdocs):
See https://patchwork.kernel.org/project/devicetree/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
PATCH 2/4 crypto: rockchip: Add RK356x/RK3588 cryptographic offloader driver
In reply to Dawid OlesinskiAdd a driver for the second-generation Rockchip cryptographic hardware accelerator found on RK3568 and RK3588 SoCs (compatible strings "rockchip,rk3568-crypto" and "rockchip,rk3588-crypto").
The hardware provides:
- AES block cipher engine: ECB, CBC, and XTS modes, 128/192/256-bit keys. XTS hardware is limited to single-SG requests.
- Hash engine: SHA-1, SHA-256, SHA-384, SHA-512, MD5, SM3. The hardware padding engine (HW_PAD) requires the total message length upfront and cannot maintain state across LLI descriptor boundaries, so multi-SG and unaligned requests are routed to a software fallback.
- DMA engine: linked-list descriptor (LLI) based, with a 20-entry coherent descriptor table.
Design overview:
- Built on top of the crypto engine framework (crypto/engine.h) for serialised hardware request dispatch and automatic fallback handling.
- Each platform device gets its own private copy of the algorithm descriptor table at probe time (devm_kmemdup), so the dev pointer in each template always refers to the correct hardware instance. This avoids a global device list without any locking overhead.
- Runtime PM with autosuspend (2 s idle timeout) gates clocks and asserts reset between requests to save power.
- Symmetric software fallback for all registered algorithms handles requests that cannot be processed in hardware (misaligned buffers, multi-SG inputs for hash, zero-length payloads).
--- drivers/crypto/Kconfig | 33 + drivers/crypto/Makefile | 1 + drivers/crypto/rockchip/Makefile | 5 + drivers/crypto/rockchip/rk2_crypto.c | 740 ++++++++++++++++++ drivers/crypto/rockchip/rk2_crypto.h | 243 ++++++ drivers/crypto/rockchip/rk2_crypto_ahash.c | 547 +++++++++++++ drivers/crypto/rockchip/rk2_crypto_skcipher.c | 724 +++++++++++++++++ 7 files changed, 2293 insertions(+) create mode 100644 drivers/crypto/rockchip/rk2_crypto.c create mode 100644 drivers/crypto/rockchip/rk2_crypto.h create mode 100644 drivers/crypto/rockchip/rk2_crypto_ahash.c create mode 100644 drivers/crypto/rockchip/rk2_crypto_skcipher.c
drivers/crypto/Kconfig +33 -0
@@ -709,6 +709,39 @@ config CRYPTO_DEV_ROCKCHIP_DEBUG This will create /sys/kernel/debug/rk3288_crypto/stats for displaying the number of requests per algorithm and other internal stats. +config CRYPTO_DEV_ROCKCHIP2 + tristate "Rockchip's cryptographic offloader" + depends on OF && ARCH_ROCKCHIP + depends on PM + select CRYPTO_ECB + select CRYPTO_CBC + select CRYPTO_AES + select CRYPTO_MD5 + select CRYPTO_SHA1 + select CRYPTO_SHA256 + select CRYPTO_SHA512 + select CRYPTO_SM3_GENERIC + select CRYPTO_HASH + select CRYPTO_XTS + select CRYPTO_SKCIPHER + select CRYPTO_ENGINE + + help + This driver interfaces with the hardware crypto offloader present + on RK3566, RK3568 and RK3588 SoCs. It provides hardware acceleration + for symmetric block ciphers and hashing functions, offloading the + main CPU cores during heavy cryptographic workflows. + +config CRYPTO_DEV_ROCKCHIP2_DEBUG + bool "Enable Rockchip crypto stats" + depends on CRYPTO_DEV_ROCKCHIP2 + depends on DEBUG_FS + help + Say y to enable Rockchip crypto debug stats. + This will create a directory using the device name + (e.g., /sys/kernel/debug/fe370000.crypto/stats) for displaying + the number of requests per algorithm and other internal stats. + config CRYPTO_DEV_TEGRA tristate "Enable Tegra Security Engine" depends on TEGRA_HOST1X
drivers/crypto/Makefile +1 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_CRYPTO_DEV_PPC4XX) += amcc/ obj-$(CONFIG_CRYPTO_DEV_QCE) += qce/ obj-$(CONFIG_CRYPTO_DEV_QCOM_RNG) += qcom-rng.o obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rockchip/ +obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP2) += rockchip/ obj-$(CONFIG_CRYPTO_DEV_S5P) += s5p-sss.o obj-$(CONFIG_CRYPTO_DEV_SA2UL) += sa2ul.o obj-$(CONFIG_CRYPTO_DEV_SAHARA) += sahara.o
drivers/crypto/rockchip/Makefile +5 -0
@@ -3,3 +3,8 @@ obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rk_crypto.o rk_crypto-objs := rk3288_crypto.o \ rk3288_crypto_skcipher.o \ rk3288_crypto_ahash.o + +obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP2) += rk_crypto2.o +rk_crypto2-objs := rk2_crypto.o \ + rk2_crypto_skcipher.o \ + rk2_crypto_ahash.o
drivers/crypto/rockchip/rk2_crypto.c new file +740 -0
740 lines not on this page · raw message
drivers/crypto/rockchip/rk2_crypto.h new file +243 -0
243 lines not on this page · raw message
drivers/crypto/rockchip/rk2_crypto_ahash.c new file +547 -0
547 lines not on this page · raw message
drivers/crypto/rockchip/rk2_crypto_skcipher.c new file +724 -0
724 lines not on this page · raw message
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 2/4] crypto: rockchip: Add RK356x/RK3588 cryptographic offloader driver
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider: - [High] Kconfig selects a non-existent symbol `CRYPTO_SM3_GENERIC`. - [High] Incorrect IV offset…
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider:
- [High] Kconfig selects a non-existent symbol CRYPTO_SM3_GENERIC.
- [High] Incorrect IV offset calculation uses full scatterlist element capacity instead of the processed length, causing out-of-bounds reads and breaking cipher chaining.
- [High] The shared interrupt handler accesses hardware unconditionally without verifying PM state, causing fatal aborts.
- [High] Device removal cancels pending autosuspend timers without explicitly suspending the hardware, leading to permanent clock and power leakage.
- [High] Algorithm registration copies templates blindly without generating unique cra_driver_names, preventing multi-instance probing.
- [High] A race condition between DMA timeout handling and delayed interrupts can cause spurious completions and memory corruption.
- [High] Hardware descriptors and parameters are assigned using CPU-native integers instead of fixed-endian types, breaking the driver on big-endian architectures.
- [High] 64-bit DMA addresses are silently truncated to 32 bits, risking memory corruption on systems with >4GB of RAM.
- [Medium] Algorithm fallback statistics are updated without atomics in highly concurrent code paths, leading to data races.
--
commit a4f5122cb83b084e2414510f88a5efed52b14807
Author: Dawid Olesinski <[email protected]>
crypto: rockchip: Add RK356x/RK3588 cryptographic offloader driver
This commit adds a driver for the second-generation Rockchip cryptographic hardware accelerator found on RK3568 and RK3588 SoCs. It provides hardware acceleration for symmetric block ciphers and hashing functions.
Quoted 4 lines
drivers/crypto/Kconfig +0
-0
[ ... ]
Quoted 6 lines
drivers/crypto/Kconfig +2
-0@@ -709,6 +709,39 @@ config CRYPTO_DEV_ROCKCHIP_DEBUG This will create /sys/kernel/debug/rk3288_crypto/stats for displaying the number of requests per algorithm and other internal stats. +config CRYPTO_DEV_ROCKCHIP2 + tristate "Rockchip's cryptographic offloader"
drivers/crypto/Kconfig config CRYPTO_DEV_ROCKCHIP_DEBUG · line 723
Quoted 10 lines
drivers/crypto/Kconfig +10
-0+ depends on OF && ARCH_ROCKCHIP + depends on PM + select CRYPTO_ECB + select CRYPTO_CBC + select CRYPTO_AES + select CRYPTO_MD5 + select CRYPTO_SHA1 + select CRYPTO_SHA256 + select CRYPTO_SHA512 + select CRYPTO_SM3_GENERIC
[Severity: High]
Does this select a nonexistent config symbol? The symbol CRYPTO_SM3_GENERIC does not seem to exist in the kernel tree (the correct symbol is CRYPTO_SM3).
Selecting a nonexistent symbol is silently ignored by Kconfig, potentially leaving the generic SM3 algorithm disabled. Since the driver unconditionally attempts to allocate a fallback for sm3 in rk2_hash_init_tfm(), could this cause runtime allocation failures and prevent the hashing algorithm from instantiating?
Quoted 5 lines
drivers/crypto/rockchip/rk2_crypto.c new file +0
-0
[ ... ]
drivers/crypto/rockchip/rk2_crypto.c line 50
Quoted 10 lines
drivers/crypto/rockchip/rk2_crypto.c new file +10
-0+static int rk2_crypto_pm_suspend (struct device *dev) +{ +struct rk2_crypto_dev *rkdev =dev_get_drvdata (dev); + +reset_control_assert (rkdev->rst); +udelay (10 ); +clk_bulk_disable_unprepare (rkdev->num_clks, rkdev->clks); + +return 0 ; +}
[Severity: High]
Should this suspend path call synchronize_irq() before gating the clocks?
Since the device requests its interrupt with IRQF_SHARED, another device sharing the IRQ line could trigger the handler. If the clocks are disabled while the shared interrupt handler is running or about to run, could this lead to a system crash when the handler accesses powered-down registers?
[ ... ]
drivers/crypto/rockchip/rk2_crypto.c line 89
Quoted 4 lines
drivers/crypto/rockchip/rk2_crypto.c new file +4
-0+static void rk2_crypto_pm_exit (struct rk2_crypto_dev *rkdev) +{ +pm_runtime_disable (rkdev->dev); +}
[Severity: High]
Is it safe to unconditionally call pm_runtime_disable() here without ensuring the hardware is suspended?
During removal, pm_runtime_disable() will cancel any pending asynchronous suspends. Without a preceding pm_runtime_put_sync() or explicit hardware shutdown in the removal path, the hardware might remain permanently locked in the RPM_ACTIVE state, leaking clocks indefinitely.
[ ... ]
drivers/crypto/rockchip/rk2_crypto.c line 96
Quoted 6 lines
drivers/crypto/rockchip/rk2_crypto.c new file +6
-0+static irqreturn_t rk2_crypto_irq_handle (int irq,void *dev_id) +{ +struct rk2_crypto_dev *rkc =platform_get_drvdata (dev_id); +u32 v; + + v =readl (rkc->reg +RK2_CRYPTO_DMA_INT_ST );
[Severity: High]
Can this unconditional register read cause an external abort?
For a shared interrupt handler, the handler might be invoked when the device is runtime-suspended. Reading from the register without first verifying the device is active (e.g., using pm_runtime_get_if_active()) could cause a crash or return 0xffffffff, which might generate a spurious completion.
[ ... ]
Quoted 2 lines
drivers/crypto/rockchip/rk2_crypto.c new file +2
-0+static int rk2_crypto_probe (struct platform_device *pdev) +{
[ ... ]
drivers/crypto/rockchip/rk2_crypto.c line 605
Quoted 3 lines
drivers/crypto/rockchip/rk2_crypto.c new file +3
-0+ rkc->num_algs =ARRAY_SIZE (rk2_crypto_algs_template); + rkc->algs =devm_kmemdup (dev, rk2_crypto_algs_template, +sizeof (rk2_crypto_algs_template),GFP_KERNEL );
[Severity: High]
Does duplicating the static templates preserve identical cra_driver_name values across multiple device instances?
If a second hardware instance probes (such as on RK3588 SoCs with multiple crypto cores), submitting these copies to the crypto subsystem without modifying their cra_driver_name strings will result in a global name collision. Could this cause crypto_engine_register_skcipher() to fail with -EEXIST, aborting the probe for subsequent instances?
[ ... ]
drivers/crypto/rockchip/rk2_crypto.c line 620
Quoted 3 lines
drivers/crypto/rockchip/rk2_crypto.c new file +3
-0+ rkc->tl =dma_alloc_coherent (dev, +sizeof (struct rk2_crypto_lli ) *MAX_LLI , + &rkc->t_phy,GFP_KERNEL );
[Severity: High]
Is a DMA mask needed before performing allocations?
The driver programs hardware descriptors using 32-bit DMA fields and writes the LLI table base address into a 32-bit hardware register. Because the driver never limits the allocation mask via dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) during initialization, the allocator might provide physical addresses above 4GB on systems with large RAM.
If the upper 32 bits of the 64-bit dma_addr_t are discarded, could this cause the DMA controller to read or write random regions of low memory?
Quoted 5 lines
drivers/crypto/rockchip/rk2_crypto_ahash.c new file +0
-0
[ ... ]
Quoted 2 lines
drivers/crypto/rockchip/rk2_crypto_ahash.c new file +2
-0+static bool rk2_ahash_need_fallback (struct ahash_request *areq) +{
[ ... ]
drivers/crypto/rockchip/rk2_crypto_ahash.c line 49
Quoted 4 lines
drivers/crypto/rockchip/rk2_crypto_ahash.c new file +4
-0+if (nents >1 ) { + algt->stat_fb_sgdiff++; +return true; + }
[Severity: Medium]
Is it safe to increment these statistics without atomic protection?
Software fallback functions increment performance statistics directly inside frontend operations. Since these fallbacks bypass the serialized crypto_engine kthread queue, they can be executed concurrently by multiple threads on the same algorithm template instance.
Concurrent load-add-store operations on an unsigned long might create a data race, resulting in lost updates. Should these counters use atomic types or be protected by locks?
[ ... ]
Quoted 2 lines
drivers/crypto/rockchip/rk2_crypto_ahash.c new file +2
-0+int rk2_hash_run (struct crypto_engine *engine,void *breq) +{
[ ... ]
Quoted 1 line
drivers/crypto/rockchip/rk2_crypto_ahash.c new file +1
-0+while (sgs && len >0 ) {
[ ... ]
drivers/crypto/rockchip/rk2_crypto_ahash.c line 398
Quoted 3 lines
drivers/crypto/rockchip/rk2_crypto_ahash.c new file +3
-0+ todo =min (sg_dma_len (sgs), len); + dd->src_addr =sg_dma_address (sgs); + dd->src_len = todo;
[Severity: High]
Does this directly assign native types to __le32 LLI descriptor fields?
Fields in struct rk2_crypto_lli like src_addr and src_len are defined as __le32. Assigning CPU-native values to them directly without using the required cpu_to_le32() conversions will break the driver on big-endian architectures, as the hardware receives corrupted addresses.
[ ... ]
drivers/crypto/rockchip/rk2_crypto_ahash.c line 458
Quoted 10 lines
drivers/crypto/rockchip/rk2_crypto_ahash.c new file +10
-0+ timeout =wait_for_completion_timeout (&rkc->complete, +msecs_to_jiffies (2000 )); +if (!timeout) { +dev_err (rkc->dev,"DMA timeout\n" ); + err = -ETIMEDOUT ; +reset_control_assert (rkc->rst); +udelay (10 ); +reset_control_deassert (rkc->rst); + goto exit; + }
[Severity: High]
Does the timeout error path need to synchronize with the interrupt handler?
When wait_for_completion_timeout() expires, the driver resets the hardware and exits. The crypto framework then submits the next request, resetting the completion structure. If the timed-out request's interrupt was delayed and fires concurrently on another CPU, it will trigger complete() on the newly initialized completion.
Could this spurious completion cause the next request to return from wait immediately, unmapping buffers prematurely while the DMA engine is still actively reading/writing memory?
Quoted 5 lines
drivers/crypto/rockchip/rk2_crypto_skcipher.c new file +0
-0
[ ... ]
Quoted 2 lines
drivers/crypto/rockchip/rk2_crypto_skcipher.c new file +2
-0+int rk2_cipher_run (struct crypto_engine *engine,void *async_req) +{
[ ... ]
drivers/crypto/rockchip/rk2_crypto_skcipher.c line 519
Quoted 3 lines
drivers/crypto/rockchip/rk2_crypto_skcipher.c new file +3
-0+if (areq->iv &&crypto_skcipher_ivsize (tfm) >0 ) { +if (rctx->mode &RK2_CRYPTO_DEC ) { + offset = sgs->length - ivsize;
[Severity: High]
Does this calculate the IV offset using the full scatterlist element capacity instead of the processed length?
The driver attempts to back up the output IV by copying the last processed block. However, scatterlist lengths (sgs->length) represent buffer capacities, which are often larger than the requested cryptlen or the processed todo amount.
By using offset = sgs->length - ivsize, the driver might read uninitialized or unrelated memory from the end of the scatterlist buffer instead of reading the newly generated ciphertext at todo - ivsize. Could this corrupt the IV, silently break subsequent chained block operations, and risk leaking unrelated memory?
[ ... ]
drivers/crypto/rockchip/rk2_crypto_skcipher.c line 559
Quoted 4 lines
drivers/crypto/rockchip/rk2_crypto_skcipher.c new file +4
-0+if (algt->is_xts) { +for (i =0 ; i < ctx->keylen /8 ; i++) { + v =cpu_to_be32 (rkey[i]); +writel (v, rkc->reg +RK2_CRYPTO_KEY0 + i *4 );
[Severity: High]
Does combining cpu_to_be32() with writel() incorrectly byte-swap on big-endian systems?
The writel() function already performs a native-to-little-endian swap. By pre-swapping the value with cpu_to_be32(), this code creates a double-swap issue on big-endian architectures. Additionally, casting the key byte array to u32* violates strict aliasing. Will this result in the hardware receiving a corrupted key?
[ ... ]
drivers/crypto/rockchip/rk2_crypto_skcipher.c
Quoted 2 lines
drivers/crypto/rockchip/rk2_crypto_skcipher.c new file +2
-0+ dd->src_addr =sg_dma_address (sgs); + dd->src_len = todo;
[Severity: High]
Are CPU-native values being assigned directly to __le32 LLI descriptor fields here as well?
Like in the ahash implementation, these fields require cpu_to_le32() conversions to function correctly on big-endian systems.
[ ... ]
Quoted 7 lines
drivers/crypto/rockchip/rk2_crypto_skcipher.c new file +7
-0+ timeout =wait_for_completion_timeout (&rkc->complete, +msecs_to_jiffies (2000 )); +if (sgs == sgd) { +dma_unmap_sg (rkc->dev, sgs,1 ,DMA_BIDIRECTIONAL ); + }else { +dma_unmap_sg (rkc->dev, sgs,1 ,DMA_TO_DEVICE ); +dma_unmap_sg (rkc->dev, sgd,1 ,DMA_FROM_DEVICE );
drivers/crypto/rockchip/rk2_crypto_skcipher.c line 636
Quoted 10 lines
drivers/crypto/rockchip/rk2_crypto_skcipher.c new file +10
-0+ } + +if (!timeout) { +dev_err (rkc->dev,"DMA timeout\n" ); + err = -ETIMEDOUT ; +reset_control_assert (rkc->rst); +udelay (10 ); +reset_control_deassert (rkc->rst); + goto exit; + }
[Severity: High]
Is this timeout error path subject to the same race condition with delayed interrupts as in the ahash implementation?
Without a call to synchronize_irq(), a delayed interrupt from this request could fire during the next request, causing spurious completions and memory corruption when buffers are unmapped prematurely.
[ ... ]
drivers/crypto/rockchip/rk2_crypto_skcipher.c line 651
Quoted 2 lines
drivers/crypto/rockchip/rk2_crypto_skcipher.c new file +2
-0+if (areq->iv && ivsize >0 ) { + offset = sgd->length - ivsize;
[Severity: High]
Is the IV offset calculated incorrectly on the encryption path as well?
Using sgd->length instead of the processed length (todo) can read out of bounds and corrupt the IV for chained block operations.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH 3/4 arm64: dts: rockchip: Add crypto node to rk356x-base
In reply to Dawid OlesinskiAdd the device tree node for the V2 cryptographic hardware accelerator on RK356x SoCs (RK3566, RK3568).
The IP block sits in the non-secure peripheral domain. Its three clocks (core, aclk, hclk) and reset line are accessible directly through the main non-secure CRU, so no firmware intermediary is required.
The node is disabled by default; board files that wish to use hardware crypto offload must enable it.
--- arch/arm64/boot/dts/rockchip/rk356x-base.dtsi | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +12 -0
@@ -1171,6 +1171,18 @@ gpu_leakage: gpu-leakage@1d { }; }; + crypto: crypto@fe380000 { + compatible = "rockchip,rk3568-crypto"; + reg = <0x0 0xfe380000 0x0 0x2000>; + interrupts = <GIC_SPI 4 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cru CLK_CRYPTO_NS_CORE>, <&cru ACLK_CRYPTO_NS>, + <&cru HCLK_CRYPTO_NS>; + clock-names = "core", "aclk", "hclk"; + resets = <&cru SRST_CRYPTO_NS_CORE>; + reset-names = "core"; + status = "disabled"; + }; + i2s0_8ch: i2s@fe400000 { compatible = "rockchip,rk3568-i2s-tdm"; reg = <0x0 0xfe400000 0x0 0x1000>;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 3/4] arm64: dts: rockchip: Add crypto node to rk356x-base
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Low] The crypto@fe380000 device tree node is placed out of order with respect to its unit address.
Pre-existing issues:
- [High] The driver requests a shared interrupt before device clocks are enabled, and its ISR does not check the power state, leading to a potential fatal unclocked register access. --
commit 30c6ac6a0076f1ce31fb0365a3eee2a85dadf551
Author: Dawid Olesinski <[email protected]>
arm64: dts: rockchip: Add crypto node to rk356x-base
This commit adds the device tree node for the V2 cryptographic hardware accelerator on RK356x SoCs. The IP block sits in the non-secure peripheral domain and is disabled by default.
arch/arm64/boot/dts/rockchip/rk356x-base.dtsi gpu_leakage: gpu-leakage@1d { · line 1174
Quoted 9 lines
arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +1
-0@@ -1171,6 +1171,18 @@ gpu_leakage: gpu-leakage@1d { }; }; + crypto: crypto@fe380000 {
[Severity: Low]
Is this device tree node placed out of order?
Device tree nodes with unit addresses are typically sorted numerically by their physical base address. Would it be better to place this node before the rng@fe388000 node to maintain the established sorting order?
arch/arm64/boot/dts/rockchip/rk356x-base.dtsi gpu_leakage: gpu-leakage@1d { · line 1184
Quoted 10 lines
arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +10
-0+ compatible = "rockchip,rk3568-crypto"; + reg = <0x0 0xfe380000 0x0 0x2000>; + interrupts = <GIC_SPI 4 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cru CLK_CRYPTO_NS_CORE>, <&cru ACLK_CRYPTO_NS>, + <&cru HCLK_CRYPTO_NS>; + clock-names = "core", "aclk", "hclk"; + resets = <&cru SRST_CRYPTO_NS_CORE>; + reset-names = "core"; + status = "disabled"; + };
[Severity: High]
This isn't a bug introduced by this patch, but I noticed a potential issue in the driver code that this DT node enables in drivers/crypto/rockchip/rk2_crypto.c.
The driver requests a shared interrupt in rk2_crypto_probe() before device clocks are enabled via runtime PM:
rk2_crypto_probe() {
...
err = devm_request_irq(dev, rkc->irq,
rk2_crypto_irq_handle, IRQF_SHARED,
"rk-crypto", pdev);
...
}If a shared device triggers the interrupt, or a spurious interrupt occurs while the device clocks are disabled, the ISR rk2_crypto_irq_handle() will execute and blindly read from the hardware status register:
rk2_crypto_irq_handle() {
...
v = readl(rkc->reg + RK2_CRYPTO_DMA_INT_ST);
...
}Could this cause a fatal external abort (SError) if the MMIO register is accessed while the clock domain is unpowered?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH 4/4 arm64: dts: rockchip: Add crypto node to rk3588-base
In reply to Dawid OlesinskiAdd the device tree node for the V2 cryptographic hardware accelerator on RK3588.
On RK3588 the crypto IP sits inside the secure domain controlled by SECURECRU, a register bank that is exclusively accessible to the TrustZone firmware (TF-A). Linux must therefore obtain its clocks and reset line through the ARM SCMI interface provided by the firmware rather than mapping the CRU registers directly. Attempting direct MMIO access to SECURECRU from the non-secure world triggers an asynchronous bus fault.
The interrupt uses the four-cell GICv3 format as required by the RK3588 GIC node definition (the fourth cell is the CPU affinity/partition specifier; 0 means no affinity constraint).
The node is disabled by default; board files that wish to use hardware crypto offload must enable it.
--- arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/arm64/boot/dts/rockchip/rk3588-base.dtsi +12 -0
@@ -2257,6 +2257,18 @@ rng@fe378000 { resets = <&scmi_reset SCMI_SRST_H_TRNG_NS>; }; + crypto: crypto@fe370000 { + compatible = "rockchip,rk3588-crypto"; + reg = <0x0 0xfe370000 0x0 0x2000>; + interrupts = <GIC_SPI 209 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&scmi_clk SCMI_CRYPTO_CORE>, <&scmi_clk SCMI_ACLK_SECURE_NS>, + <&scmi_clk SCMI_HCLK_SECURE_NS>; + clock-names = "core", "aclk", "hclk"; + resets = <&scmi_reset SCMI_SRST_CRYPTO_CORE>; + reset-names = "core"; + status = "disabled"; + }; + i2s0_8ch: i2s@fe470000 { compatible = "rockchip,rk3588-i2s-tdm"; reg = <0x0 0xfe470000 0x0 0x1000>;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 4/4] arm64: dts: rockchip: Add crypto node to rk3588-base
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The shared interrupt handler accesses device registers without ensuring the device's clocks are enabled, which will trigger an asynchronous bus fault (SError) if a shared or spurious interrupt occurs while suspended.
- [High] The driver dereferences the areq->iv byte array as a u32 *, which can cause an alignment fault.
--
commit 7f6218b80827dfe5983e50e2564e2a7bc74c81f8
Author: Dawid Olesinski <[email protected]>
arm64: dts: rockchip: Add crypto node to rk3588-base
This commit adds the device tree node for the V2 cryptographic hardware accelerator on the RK3588. The node is disabled by default and uses the ARM SCMI interface for clocks and resets because the IP is in the secure domain.
arch/arm64/boot/dts/rockchip/rk3588-base.dtsi rng@fe378000 { · line 2261
Quoted 10 lines
arch/arm64/boot/dts/rockchip/rk3588-base.dtsi +2
-0@@ -2257,6 +2257,18 @@ rng@fe378000 { resets = <&scmi_reset SCMI_SRST_H_TRNG_NS>; }; + crypto: crypto@fe370000 { + compatible = "rockchip,rk3588-crypto";
[Severity: High]
This isn't a bug introduced by this patch, but enabling this device exposes an alignment fault issue in the driver.
The driver dereferences the areq->iv byte array as a u32 pointer, which can cause an alignment fault. The block cipher algorithms set .base.cra_alignmask to 0, meaning the crypto subsystem makes no guarantees about the memory alignment of the areq->iv buffer. However, in rk2_cipher_run() (drivers/crypto/rockchip/rk2_crypto_skcipher.c):
writel(cpu_to_be32(riv[i]), rkc->reg + RK2_CRYPTO_CH0_IV_0 + i * 4);
the driver casts areq->iv to a u32 pointer and reads from it directly via riv[i]. If the IV buffer is unaligned, this dereference is undefined behavior in C. On ARM64, if the compiler assumes alignment and emits an instruction that strictly requires it, this will trigger an alignment fault exception and crash the kernel.
Should the driver be updated to either use get_unaligned() to read the IV bytes or set cra_alignmask = 3 to enforce 4-byte alignment?
arch/arm64/boot/dts/rockchip/rk3588-base.dtsi rng@fe378000 { · line 2263
Quoted 2 lines
arch/arm64/boot/dts/rockchip/rk3588-base.dtsi +2
-0+ reg = <0x0 0xfe370000 0x0 0x2000>; + interrupts = <GIC_SPI 209 IRQ_TYPE_LEVEL_HIGH 0>;
[Severity: High]
This isn't a bug introduced by this patch, but enabling this device via device tree will expose a shared interrupt handling issue in the driver.
The shared interrupt handler accesses device registers without ensuring the device's clocks are enabled.
The driver requests the interrupt with IRQF_SHARED while placing the device into runtime suspend (disabling its clocks and asserting reset) when idle. If another device on the same IRQ line fires, or a spurious interrupt occurs, rk2_crypto_irq_handle() in drivers/crypto/rockchip/rk2_crypto.c will execute:
v = readl(rkc->reg + RK2_CRYPTO_DMA_INT_ST); if (!v) return IRQ_NONE;
Accessing an unclocked APB/AHB target on Rockchip SoCs triggers an asynchronous bus fault (SError), crashing the kernel.
Could the handler verify the device is active (e.g., via a driver-specific software flag) before touching hardware registers?
Quoted 7 lines
arch/arm64/boot/dts/rockchip/rk3588-base.dtsi +7
-0+ clocks = <&scmi_clk SCMI_CRYPTO_CORE>, <&scmi_clk SCMI_ACLK_SECURE_NS>, + <&scmi_clk SCMI_HCLK_SECURE_NS>; + clock-names = "core", "aclk", "hclk"; + resets = <&scmi_reset SCMI_SRST_CRYPTO_CORE>; + reset-names = "core"; + status = "disabled"; + };
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4