crypto: rockchip: Add RK356x/RK3588 cryptographic offloader
Subsystems (4)
v2 cover crypto: rockchip: Add RK356x/RK3588 cryptographic offloader
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
Changes in v2:
- dt-bindings: wrap example in a bus node with #address/#size-cells = 2 and add the SCMI clock/reset dt-binding includes so dt_binding_check passes (Rob Herring / Krzysztof Kozlowski review).
- crypto: fix Kconfig to select CRYPTO_SM3 instead of the non-existent CRYPTO_SM3_GENERIC.
- crypto: drop IRQF_SHARED (the line is dedicated) and request the IRQ only after clocks are enabled and the completion is initialised; reorder probe accordingly.
- crypto: set a 32-bit DMA mask before allocating the descriptor table.
- crypto: suspend the device explicitly on removal before disabling runtime PM to avoid leaking clocks.
- crypto: call synchronize_irq() on the DMA timeout paths to close a race with delayed interrupts.
- crypto: convert fallback statistics to atomic_long_t.
- crypto: use cpu_to_le32() for all LLI descriptor fields (big-endian correctness).
- crypto: read key/IV with get_unaligned_be32() to fix an alignment fault and a big-endian double-swap.
- crypto: fix the CBC/XTS IV backup offset to use the processed length instead of the scatterlist capacity.
- arm64: dts: rk356x: move the crypto node into unit-address order.
v1: https://patchwork.kernel.org/project/devicetree/cover/[email protected]/
Build/rebase fixes (not from review):
- crypto: use sizeof(struct sm3_ctx) for the SM3 statesize, as struct sm3_state was removed by the lib/crypto SM3 conversion.
- crypto: add the missing SHA-224 zero-message case.
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 | 75 ++ arch/arm64/boot/dts/rockchip/rk356x-base.dtsi | 12 + arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 12 + drivers/crypto/Kconfig | 32 + drivers/crypto/Makefile | 1 + drivers/crypto/rockchip/Makefile | 5 + drivers/crypto/rockchip/rk2_crypto.c | 746 ++++++++++++++++++ drivers/crypto/rockchip/rk2_crypto.h | 249 ++++++ drivers/crypto/rockchip/rk2_crypto_ahash.c | 565 +++++++++++++ drivers/crypto/rockchip/rk2_crypto_skcipher.c | 728 +++++++++++++++++ 10 files changed, 2425 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 v2 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 | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +75 -0
@@ -0,0 +1,75 @@ +# 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> + #include <dt-bindings/clock/rockchip,rk3588-cru.h> + #include <dt-bindings/reset/rockchip,rk3588-cru.h> + + bus { + #address-cells = <2>; + #size-cells = <2>; + + 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 v2 1/4] dt-bindings: crypto: rockchip: Add RK356x/RK3588 crypto engine binding
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The YAML binding artificially restricts the `resets` property to a single item (`maxItems: 1`)…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The YAML binding artificially restricts the resets property to a single item (maxItems: 1), which prevents the complete representation of the hardware's reset lines on both RK3568 and RK3588. --
--- Patch [1]: [PATCH v2 1/4] dt-bindings: crypto: rockchip: Add RK356x/RK3588 crypto engine binding --- commit d3ca14a283793e220819f2a5573b09896dfccc6d
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. The binding covers the rockchip,rk3568-crypto and rockchip,rk3588-crypto compatible strings.
Quoted 5 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +0
-0
[ ... ]
Quoted 8 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +8
-0+ clocks: + items: + - description: Core clock for the crypto IP internal logic + - description: AXI interconnect clock interface + - description: AHB interface clock + + clock-names: + items:
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml line 43
Quoted 10 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +10
-0+ - const: core + - const: aclk + - const: hclk + + resets: + maxItems: 1 + + reset-names: + items: + - const: core
[Severity: Medium]
Since the hardware block has AXI and AHB interfaces that require corresponding clocks, should the binding also accommodate reset lines for AXI and AHB (e.g., SCMI_SRST_A_CRYPTO and SCMI_SRST_H_CRYPTO on the RK3588)?
Restricting resets to maxItems: 1 prevents a complete device tree node from accurately describing the hardware's AXI and AHB resets alongside the core reset, which would cause schema validation failures.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v2 1/4] dt-bindings: crypto: rockchip: Add RK356x/RK3588 crypto engine binding
In reply to Dawid OlesinskiHi,
Quoted 7 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.
Quoted 8 lines
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.
Looking at the driver, the two implementations are compatible. The clocks/reset line source being different is not a reason for not being compatible. So the binding should look like this:
compatible:
oneOf:
- const: rockchip,rk3568-crypto
- items:
- enum:
- rockchip,rk3588-crypto
- const: rockchip,rk3568-crypto
and then in the RK3588 DTS, use
compatible = "rockchip,rk3588-crypto", "rockchip,rk3568-crypto";
finally in the driver only bind against "rockchip,rk3568-crypto". The RK3588 specific binding is only added in case a difference requiring custom RK3588 quirks is found in the future.
Greetings,
-- Sebastian
Quoted 91 lines
Signed-off-by Dawid Olesinski <[email protected]>--- .../crypto/rockchip,rk3588-crypto.yaml | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yamlDocumentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +75
-0@@ -0,0 +1,75 @@ +# 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> + #include <dt-bindings/clock/rockchip,rk3588-cru.h> + #include <dt-bindings/reset/rockchip,rk3588-cru.h> + + bus { + #address-cells = <2>; + #size-cells = <2>; + + 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
PATCH v2 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 | 32 + drivers/crypto/Makefile | 1 + drivers/crypto/rockchip/Makefile | 5 + drivers/crypto/rockchip/rk2_crypto.c | 746 ++++++++++++++++++ drivers/crypto/rockchip/rk2_crypto.h | 249 ++++++ drivers/crypto/rockchip/rk2_crypto_ahash.c | 565 +++++++++++++ drivers/crypto/rockchip/rk2_crypto_skcipher.c | 728 +++++++++++++++++ 7 files changed, 2326 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 +32 -0
@@ -690,6 +690,38 @@ 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 RK356x and RK3588 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 + 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
@@ -29,6 +29,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 +746 -0
746 lines not on this page · raw message
drivers/crypto/rockchip/rk2_crypto.h new file +249 -0
249 lines not on this page · raw message
drivers/crypto/rockchip/rk2_crypto_ahash.c new file +565 -0
565 lines not on this page · raw message
drivers/crypto/rockchip/rk2_crypto_skcipher.c new file +728 -0
728 lines not on this page · raw message
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 2/4] crypto: rockchip: Add RK356x/RK3588 cryptographic offloader driver
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] Missing SYSTEM_SLEEP_PM_OPS causes device state corruption across system suspend/resume. - [High]…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Missing SYSTEM_SLEEP_PM_OPS causes device state corruption across system suspend/resume.
- [High] The interrupt handler accesses hardware registers without checking if the device is active, leading to potential bus faults.
- [High] Driver structures managed by devres are destroyed when remove() returns, leading to Use-After-Free by active TFMs and background crypto_engine kworkers.
- [High] DMA memory is unmapped before stopping the hardware when a request times out, leading to memory corruption or IOMMU faults.
--
--- Patch [2]: [PATCH v2 2/4] crypto: rockchip: Add RK356x/RK3588 cryptographic offloader driver --- commit 81281ac8d9ab85c86e6148fdf22fdc86a62ad727
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 integrates with the crypto engine framework and implements automatic software fallbacks for requests that cannot be processed in hardware. The driver also utilizes runtime PM with an autosuspend delay to manage device clocks and power.
Quoted 3 lines
drivers/crypto/rockchip/rk2_crypto.c new file +0
-0
[ ... ]
Quoted 3 lines
static const struct
dev_pm_opsrk2_crypto_pm_ops= {
RUNTIME_PM_OPS(rk2_crypto_pm_suspend, rk2_crypto_pm_resume, NULL)
};
[Severity: High]
Does the rk2_crypto_pm_ops structure correctly handle system sleep (e.g., S3 suspend)?
By only using RUNTIME_PM_OPS and omitting SYSTEM_SLEEP_PM_OPS, the PM core may not suspend the hardware if the device is in the 2-second autosuspend window (RPM_ACTIVE) when the system goes to sleep.
On system resume, could pm_runtime_resume_and_get() incorrectly succeed without calling the driver's resume callback, causing the driver to program unclocked hardware?
[ ... ]
Quoted 6 lines
static
irqreturn_trk2_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]
Should this interrupt handler verify the device's runtime PM state before accessing hardware registers?
Because the IRQ is managed by devm_request_irq(), it remains active until after rk2_crypto_remove() returns, even though the device is powered down via pm_runtime_put_sync() earlier in the teardown.
If a spurious interrupt arrives during this window, could this readl() trigger a synchronous external abort (bus fault) by accessing unclocked hardware?
Would using pm_runtime_get_if_active() here prevent accessing powered-down hardware?
[ ... ]
Quoted 5 lines
static int
rk2_crypto_probe(struct platform_device *pdev){ struct device *dev = &pdev->dev; struct rk2_crypto_dev *rkc; int err = 0;
[ ... ]
Quoted 8 lines
/* * Duplicate the algorithms locally for this specific device. * There is exactly one crypto block per SoC (crypto@fe370000 / crypto@fe380000) * so -EEXIST cannot trigger on real hardware. */ 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 allocating the algorithm templates with devm_kmemdup() tie their lifetime strictly to the device's binding lifecycle rather than the crypto API's reference counting?
If an admin unbinds the driver while a process holds a crypto socket, crypto_unregister_alg() unlinks the algorithm but does not block.
Could this result in a use-after-free when the active TFM eventually accesses the freed template memory?
[ ... ]
Quoted 10 lines
static void
rk2_crypto_remove(struct platform_device *pdev){ struct rk2_crypto_dev *rkc = platform_get_drvdata(pdev); crypto_engine_stop(rkc->engine); rk2_crypto_unregister(rkc); #ifdef CONFIG_CRYPTO_DEV_ROCKCHIP2_DEBUG debugfs_remove_recursive(rkc->dbgfs_dir); #endif crypto_engine_exit(rkc->engine);
[Severity: High]
If the hardware is hung and crypto_engine_stop() times out, it returns -EBUSY and leaves the engine's kworker running.
When rk2_crypto_remove() subsequently returns, devres will automatically free the rk2_crypto_dev structure.
Can the still-running kworker access the freed crypto engine memory in this scenario?
Quoted 3 lines
drivers/crypto/rockchip/rk2_crypto_skcipher.c new file +0
-0
[ ... ]
Quoted 2 lines
int
rk2_cipher_run(struct crypto_engine *engine, void *async_req){
[ ... ]
Quoted 5 lines
timeout = wait_for_completion_timeout(&rkc->complete,
msecs_to_jiffies(2000));
if (sgs == sgd) {
dma_unmap_sg(rkc->dev, sgs, 1, DMA_BIDIRECTIONAL);
} else {Quoted 8 lines
dma_unmap_sg(rkc->dev, sgs, 1, DMA_TO_DEVICE);
dma_unmap_sg(rkc->dev, sgd, 1, DMA_FROM_DEVICE);
}
if (!timeout) {
dev_err(rkc->dev, "DMA timeout\n");
err = -ETIMEDOUT;
reset_control_assert(rkc->rst);[Severity: High]
When a request times out, does unmapping the scatterlist entries before calling reset_control_assert() introduce a race condition?
If the hardware is merely delayed and completes the transaction during this brief window, could it write to unmapped memory or recycle bounce buffers, triggering an IOMMU fault?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v2 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
@@ -1112,6 +1112,18 @@ sdhci: mmc@fe310000 { status = "disabled"; }; + 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"; + }; + /* * Testing showed that the HWRNG found in RK3566 produces unacceptably * low quality of random data, so the HWRNG isn't enabled for all RK356x
Signature · 1 line
2.47.3
Re: [PATCH v2 3/4] arm64: dts: rockchip: Add crypto node to rk356x-base
Hi,
Quoted 9 lines · Dawid Olesinski
Add 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.
Why is it disabled by default? It doesn't seem to be board specific at all to me (the same question applies to the RK3588 DT).
Greetings,
-- Sebastian
Quoted 33 lines
Signed-off-by Dawid Olesinski <[email protected]>--- arch/arm64/boot/dts/rockchip/rk356x-base.dtsi | 12 ++++++++++++ 1 file changed, 12 insertions(+)arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +12
-0@@ -1112,6 +1112,18 @@ sdhci: mmc@fe310000 { status = "disabled"; }; + 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"; + }; + /* * Testing showed that the HWRNG found in RK3566 produces unacceptably * low quality of random data, so the HWRNG isn't enabled for all RK356xSignature · 1 line
2.47.3
Heiko Stübner
maintainerRe: [PATCH v2 3/4] arm64: dts: rockchip: Add crypto node to rk356x-base
Am Donnerstag, 9. Juli 2026, 01:56:10 Mitteleuropäische Sommerzeit schrieb Sebastian Reichel:
Quoted 10 lines
Hi,
Quoted 7 lines · Dawid Olesinski
Add 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.
Quoted 5 lines
Quoted 2 lines
The node is disabled by default; board files that wish to use hardware crypto offload must enable it.
Why is it disabled by default? It doesn't seem to be board specific at all to me (the same question applies to the RK3588 DT).
You're definitly right about that ... there are no board specific resources needed, so Dawid please drop the status from both nodes.
Heiko
Quoted 14 lines
Quoted 14 lines
Signed-off-by Dawid Olesinski <[email protected]>--- arch/arm64/boot/dts/rockchip/rk356x-base.dtsi | 12 ++++++++++++ 1 file changed, 12 insertions(+)arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +0
-0@@ -1112,6 +1112,18 @@ sdhci: mmc@fe310000 { status = "disabled"; };
Quoted 16 lines
Quoted 5 lines
arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +5
-0+ 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>,arch/arm64/boot/dts/rockchip/rk356x-base.dtsi sdhci: mmc@fe310000 { · line 1129
Quoted 10 lines
arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +7
-0+ <&cru HCLK_CRYPTO_NS>; + clock-names = "core", "aclk", "hclk"; + resets = <&cru SRST_CRYPTO_NS_CORE>; + reset-names = "core"; + status = "disabled"; + }; + /* * Testing showed that the HWRNG found in RK3566 produces unacceptably * low quality of random data, so the HWRNG isn't enabled for all RK356x
_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
Re: [PATCH v2 3/4] arm64: dts: rockchip: Add crypto node to rk356x-base
Quoted 16 lines · On Thu, 09 Jul 2026 09:07:23 +0200 Heiko Stübner <[email protected]> wrote:
Am Donnerstag, 9. Juli 2026, 01:56:10 Mitteleuropäische Sommerzeit schrieb Sebastian Reichel:
Quoted 14 lines
Hi,
Quoted 10 lines · Dawid Olesinski
Add 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.
Quoted 9 lines
Quoted 2 lines
Why is it disabled by default? It doesn't seem to be board specific at all to me (the same question applies to the RK3588 DT).
You're definitly right about that ... there are no board specific resources needed, so Dawid please drop the status from both nodes.
Heiko
I'll drop the status = "disabled";
lines from both the RK356x and RK3588 device trees in v3.
Thanks for the review!
Dawid
Quoted 37 lines
Quoted 33 lines
Quoted 32 lines
Signed-off-by Dawid Olesinski <[email protected]>--- arch/arm64/boot/dts/rockchip/rk356x-base.dtsi | 12 ++++++++++++ 1 file changed, 12 insertions(+)(quoted diff) +0
-0
b/arch/arm64/boot/dts/rockchip/rk356x-base.dtsiindexa5832895bd39..9de7e7487ca1100644 ---a/arch/arm64/boot/dts/rockchip/rk356x-base.dtsi+++b/arch/arm64/boot/dts/rockchip/rk356x-base.dtsi@@ -1112,6 +1112,18 @@ sdhci: mmc@fe310000 { status = "disabled";arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +5
-0}; + 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>,arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +7
-0+ <&cru HCLK_CRYPTO_NS>; + clock-names = "core", "aclk", "hclk"; + resets = <&cru SRST_CRYPTO_NS_CORE>; + reset-names = "core"; + status = "disabled"; + }; + /* * Testing showed that the HWRNG found in RK3566produces unacceptably
* low quality of random data, so the HWRNG isn't
enabled for all RK356x
Re: [PATCH v2 3/4] arm64: dts: rockchip: Add crypto node to rk356x-base
Quoted 22 lines · Dawid Olesinski
Quoted 19 lines · On Thu, 09 Jul 2026 09:07:23 +0200 Heiko Stübner <[email protected]> wrote:
Am Donnerstag, 9. Juli 2026, 01:56:10 Mitteleuropäische Sommerzeit schrieb Sebastian Reichel:
Quoted 16 lines
Hi,
Quoted 10 lines · Dawid Olesinski
Add 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.
Why is it disabled by default? It doesn't seem to be board specific at all to me (the same question applies to the RK3588 DT).
Quoted 6 lines
Quoted 3 lines
You're definitly right about that ... there are no board specific resources needed, so Dawid please drop the status from both nodes.
I'll drop the
status = "disabled";
lines from both the RK356x and RK3588 device trees in v3.
That also means you can drop the label/phandle as there's no longer a need to reference it in board files.
Cheers,
Diederik
Quoted 47 lines
Thanks for the review!
Dawid
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Signed-off-by Dawid Olesinski <[email protected]>--- arch/arm64/boot/dts/rockchip/rk356x-base.dtsi | 12 ++++++++++++ 1 file changed, 12 insertions(+)(quoted diff) +0
-0
b/arch/arm64/boot/dts/rockchip/rk356x-base.dtsiindexa5832895bd39..9de7e7487ca1100644 ---a/arch/arm64/boot/dts/rockchip/rk356x-base.dtsi+++b/arch/arm64/boot/dts/rockchip/rk356x-base.dtsi@@ -1112,6 +1112,18 @@ sdhci: mmc@fe310000 { status = "disabled";arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +5
-0}; + 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>,arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +5
-0+ <&cru HCLK_CRYPTO_NS>; + clock-names = "core", "aclk", "hclk"; + resets = <&cru SRST_CRYPTO_NS_CORE>; + reset-names = "core"; + status = "disabled";Quoted 12 lines
Quoted 8 lines
Quoted 7 lines
arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +2
-0+ }; + /* * Testing showed that the HWRNG found in RK3566produces unacceptably
* low quality of random data, so the HWRNG isn't
enabled for all RK356x_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
PATCH v2 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
@@ -2447,6 +2447,18 @@ sdhci: mmc@fe2e0000 { status = "disabled"; }; + 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"; + }; + rng@fe378000 { compatible = "rockchip,rk3588-rng"; reg = <0x0 0xfe378000 0x0 0x200>;
Signature · 1 line
2.47.3
Hi Dawid,
Quoted 5 lines · Dawid Olesinski
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.
I build a 7.2-rc4 kernel (7.2-rc4-arm64-cknow) with CRYPTO_SELFTESTS_FULL and CRYPTO_BENCHMARK enabled (as module), but without this patch set. I also build another 7.2-rc4 kernel (7.2-rc4+unreleased-arm64-cknow) on top of that, but then with this patch set.
But I removed the ``status = disabled`` line so it would be enabled.
I had not (ie forgot to) enable the CRYPTO_SM4_GENERIC module, so no test wrt that, which IIUC should also be accelerated.
I added ``tcrypt.dyndbg`` to my cmdline.
I made the following test script/procedure:
```
root@sbc:~# uname -a
root@sbc:~# cat /proc/cmdline
root@sbc:~# cat /proc/crypto | grep -A5 "rk2" | grep -E "driver|selftest"
root@sbc:~# dmesg | grep -E "rk2|crypto|rk3[56]"
root@sbc:~# cat /sys/kernel/debug/fe3?0000.crypto/stats
root@sbc:~# cat /sys/kernel/debug/fe3?0000.crypto/info
root@sbc:~#
root@sbc:~# modprobe tcrypt mode=0
root@sbc:~# modprobe tcrypt mode=200
root@sbc:~# modprobe tcrypt mode=201
root@sbc:~# modprobe tcrypt mode=204
root@sbc:~# modprobe tcrypt mode=200 sec=1
root@sbc:~# modprobe tcrypt mode=201 sec=1
root@sbc:~# modprobe tcrypt mode=204 sec=1
root@sbc:~# for test_mode in {302..306} 313 {322..326}; do modprobe tcrypt mode=${test_mode}; sleep 3; done
root@sbc:~# for test_mode in {402..406} 413 {418..422}; do modprobe tcrypt mode=${test_mode}; sleep 3; done
root@sbc:~# for test_mode in {500..502}; do modprobe tcrypt mode=${test_mode}; sleep 3; done
root@sbc:~# cryptsetup benchmark
root@sbc:~# dmesg | grep -E "rk2|crypto|rk3[56]"
root@sbc:~# dmesg | grep -E "failed"
root@sbc:~#
```And then went on to test first without and then with your patch set on:
- Quartz64-B (RK3566)
- NanoPi R5S (RK3568)
- NanoPC-T6 LTS (RK3588)
crypto-rk3566-test-no-crypto-module-log.txt:
https://paste.sr.ht/~diederik/bb5dbfd59f244a6422b965b30f9796ebbfdb1fcb
crypto-rk3566-test-with-crypto-module-log.txt:
https://paste.sr.ht/~diederik/ea72297678e19cbbc987de9548f9884382e1d1cc
crypto-rk3568-test-no-crypto-module-log.txt:
https://paste.sr.ht/~diederik/309e519e6b1c31f4c1c5bcb1ea16cc8569a54830
crypto-rk3568-test-with-crypto-module-log.txt:
https://paste.sr.ht/~diederik/1e1e938ebbbae75128974fe0a7c240843bce04c8
crypto-rk3588-test-no-crypto-module-log.txt:
https://paste.sr.ht/~diederik/9a2adc2b2e42131445ce4576589e00ecf51ccb4b
crypto-rk3588-test-with-crypto-module-log.txt:
https://paste.sr.ht/~diederik/e04c11c8809031ca45662f7d4c227c1ba6162b65
I can confirm that all crypto test succeeded on all SoCs/SBCs.
I may have tested 'useless' things as I only saw a real change with
``for test_mode in {402..406} 413 {418..422}; do modprobe tcrypt mode=${test_mode}; sleep 3; done`` The rest appears to me all within margins of error (so to speak).
Then again, I don't actually understand the numbers, so it's likely
useful to take a look at the numbers yourself in the above links.
The SHA256 test f.e. has much higher ``cycles/operation`` values. I interpret that as an improvement as those numbers were also much higher on my AMD Ryzen 7 5800X.
But on f.e. ``cryptsetup benchmark`` I didn't see a relevant change. Idem on tests involving ECB, CBC, XTS. But maybe I did sth wrong?
There was another thing that caught my eye wrt RK3568 vs RK3588:
``` root@nanopi-r5s:~# cat /sys/kernel/debug/fe3?0000.crypto/info CRYPTO_CLK_CTL 1 CRYPTO_RST_CTL 0 CRYPTO_AES_VERSION 0 CRYPTO_DES_VERSION 0 CRYPTO_SM4_VERSION 0 CRYPTO_HASH_VERSION 0 CRYPTO_HMAC_VERSION 0 CRYPTO_RNG_VERSION 0 CRYPTO_PKA_VERSION 0 CRYPTO_CRYPTO_VERSION 1010010 ```
``` root@nanopc-t6-lts:~# cat /sys/kernel/debug/fe3?0000.crypto/info CRYPTO_CLK_CTL 1 CRYPTO_RST_CTL 0 CRYPTO_AES_VERSION 707ff AES 192 CRYPTO_DES_VERSION 30033 CRYPTO_SM4_VERSION 7ff CRYPTO_HASH_VERSION 1ff CRYPTO_HMAC_VERSION 1f CRYPTO_RNG_VERSION 1000000 CRYPTO_PKA_VERSION 1000000 CRYPTO_CRYPTO_VERSION 2000001 ```
Maybe there are more improvements possible, but I surely tested your patch set ;-) and at least various SHA* procedures seem significantly faster :-) So feel free to add my
Cheers,
Diederik
Quoted 96 lines
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 theHIWORD_UPDATEmask 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 RK3588Tested 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-baseSeparate patch for clk/reset tree:
clk: rockchip: rk3588: Remove SECURECRU reset definitionsChanges in v2:
- dt-bindings: wrap example in a bus node with #address/#size-cells = 2 and add the SCMI clock/reset dt-binding includes sodt_binding_checkpasses (Rob Herring / Krzysztof Kozlowski review).
- crypto: fixKconfigto selectCRYPTO_SM3instead of the non-existentCRYPTO_SM3_GENERIC.
- crypto: dropIRQF_SHARED(the line is dedicated) and request the IRQ only after clocks are enabled and the completion is initialised; reorder probe accordingly.
- crypto: set a 32-bit DMA mask before allocating the descriptor table.
- crypto: suspend the device explicitly on removal before disabling runtime PM to avoid leaking clocks.
- crypto: callsynchronize_irq()on the DMA timeout paths to close a race with delayed interrupts.
- crypto: convert fallback statistics toatomic_long_t.
- crypto: usecpu_to_le32()for all LLI descriptor fields (big-endian correctness).
- crypto: read key/IV withget_unaligned_be32()to fix an alignment fault and a big-endian double-swap.
- crypto: fix the CBC/XTS IV backup offset to use the processed length instead of the scatterlist capacity.
- arm64: dts: rk356x: move the crypto node into unit-address order.v1: https://patchwork.kernel.org/project/devicetree/cover/[email protected]/
Build/rebase fixes (not from review):
- crypto: usesizeof(struct sm3_ctx)for the SM3 statesize, as structsm3_statewas removed by the lib/crypto SM3 conversion.
- crypto: add the missing SHA-224 zero-message case.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 | 75 ++ arch/arm64/boot/dts/rockchip/rk356x-base.dtsi | 12 + arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 12 + drivers/crypto/Kconfig | 32 + drivers/crypto/Makefile | 1 + drivers/crypto/rockchip/Makefile | 5 + drivers/crypto/rockchip/rk2_crypto.c | 746 ++++++++++++++++++ drivers/crypto/rockchip/rk2_crypto.h | 249 ++++++ drivers/crypto/rockchip/rk2_crypto_ahash.c | 565 +++++++++++++ drivers/crypto/rockchip/rk2_crypto_skcipher.c | 728 +++++++++++++++++ 10 files changed, 2425 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
Quoted 4 lines · Diederik de Haas
crypto-rk3566-test-no-crypto-module-log.txt:
https://paste.sr.ht/~diederik/bb5dbfd59f244a6422b965b30f9796ebbfdb1fcb
crypto-rk3566-test-with-crypto-module-log.txt:
https://paste.sr.ht/~diederik/ea72297678e19cbbc987de9548f9884382e1d1cc
Quoted 8 lines
crypto-rk3568-test-no-crypto-module-log.txt:
https://paste.sr.ht/~diederik/309e519e6b1c31f4c1c5bcb1ea16cc8569a54830
crypto-rk3568-test-with-crypto-module-log.txt:
https://paste.sr.ht/~diederik/1e1e938ebbbae75128974fe0a7c240843bce04c8
crypto-rk3588-test-no-crypto-module-log.txt:
https://paste.sr.ht/~diederik/9a2adc2b2e42131445ce4576589e00ecf51ccb4b
crypto-rk3588-test-with-crypto-module-log.txt:
https://paste.sr.ht/~diederik/e04c11c8809031ca45662f7d4c227c1ba6162b65
Thanks for running some benchmarks!
Looking at your results for rk3566 for example, SHA-256 on 4096-byte blocks is 115 cycles/operation for sha256-lib (i.e. ARMv8 CE) or 3027 cycles/operation for rk2-sha256. So the Rockchip driver is 26 times slower than simply using the existing well-tested CPU-based code.
Don't you love "accelerators" that make things 26 times slower?
I guess we'll get the usual argument that this driver is really just for "testing" or whatever.
- Eric
Quoted 14 lines · Eric Biggers
Quoted 4 lines · Diederik de Haas
crypto-rk3566-test-no-crypto-module-log.txt:
https://paste.sr.ht/~diederik/bb5dbfd59f244a6422b965b30f9796ebbfdb1fcb
crypto-rk3566-test-with-crypto-module-log.txt:
https://paste.sr.ht/~diederik/ea72297678e19cbbc987de9548f9884382e1d1ccQuoted 8 lines
crypto-rk3568-test-no-crypto-module-log.txt:
https://paste.sr.ht/~diederik/309e519e6b1c31f4c1c5bcb1ea16cc8569a54830
crypto-rk3568-test-with-crypto-module-log.txt:
https://paste.sr.ht/~diederik/1e1e938ebbbae75128974fe0a7c240843bce04c8
crypto-rk3588-test-no-crypto-module-log.txt:
https://paste.sr.ht/~diederik/9a2adc2b2e42131445ce4576589e00ecf51ccb4b
crypto-rk3588-test-with-crypto-module-log.txt:
https://paste.sr.ht/~diederik/e04c11c8809031ca45662f7d4c227c1ba6162b65
Quoted 6 lines
Thanks for running some benchmarks!
Looking at your results for rk3566 for example, SHA-256 on 4096-byte blocks is 115 cycles/operation for sha256-lib (i.e. ARMv8 CE) or 3027 cycles/operation for rk2-sha256. So the Rockchip driver is 26 times slower than simply using the existing well-tested CPU-based code.
I shared the results because:
1) I figured it might be useful to have these numbers
2) I didn't know how to interpret the results.
Because a lower cycles/operations would IMO *logically* be better and your response above seems to confirm that.
Which makes the following results a 'bit' concerning? ``modprobe tcrypt mode=404``
[255753.686837] tcrypt: testing speed of async sha256 (sha256-lib) [255753.686841] tcrypt: test 0 ( 16 byte blocks, 16 bytes per update, 1 updates): 703 cycles/operation, 43 cycles/byte [255753.686848] tcrypt: test 1 ( 64 byte blocks, 16 bytes per update, 4 updates): 1101 cycles/operation, 17 cycles/byte [255753.686856] tcrypt: test 2 ( 64 byte blocks, 64 bytes per update, 1 updates): 869 cycles/operation, 13 cycles/byte [255753.686861] tcrypt: test 3 ( 256 byte blocks, 16 bytes per update, 16 updates): 1676 cycles/operation, 6 cycles/byte [255753.686871] tcrypt: test 4 ( 256 byte blocks, 64 bytes per update, 4 updates): 1059 cycles/operation, 4 cycles/byte [255753.686877] tcrypt: test 5 ( 256 byte blocks, 256 bytes per update, 1 updates): 1249 cycles/operation, 4 cycles/byte [255753.686884] tcrypt: test 6 ( 1024 byte blocks, 16 bytes per update, 64 updates): 4156 cycles/operation, 4 cycles/byte [255753.686904] tcrypt: test 7 ( 1024 byte blocks, 256 bytes per update, 4 updates): 1054 cycles/operation, 1 cycles/byte [255753.686911] tcrypt: test 8 ( 1024 byte blocks, 1024 bytes per update, 1 updates): 2826 cycles/operation, 2 cycles/byte [255753.686923] tcrypt: test 9 ( 2048 byte blocks, 16 bytes per update, 128 updates): 7438 cycles/operation, 3 cycles/byte [255753.686957] tcrypt: test 10 ( 2048 byte blocks, 256 bytes per update, 8 updates): 1263 cycles/operation, 0 cycles/byte [255753.686966] tcrypt: test 11 ( 2048 byte blocks, 1024 bytes per update, 2 updates): 940 cycles/operation, 0 cycles/byte [255753.686973] tcrypt: test 12 ( 2048 byte blocks, 2048 bytes per update, 1 updates): 4887 cycles/operation, 2 cycles/byte [255753.686991] tcrypt: test 13 ( 4096 byte blocks, 16 bytes per update, 256 updates): 14017 cycles/operation, 3 cycles/byte [255753.687054] tcrypt: test 14 ( 4096 byte blocks, 256 bytes per update, 16 updates): 1681 cycles/operation, 0 cycles/byte [255753.687065] tcrypt: test 15 ( 4096 byte blocks, 1024 bytes per update, 4 updates): 1059 cycles/operation, 0 cycles/byte [255753.687074] tcrypt: test 16 ( 4096 byte blocks, 4096 bytes per update, 1 updates): 9044 cycles/operation, 2 cycles/byte [255753.687105] tcrypt: test 17 ( 8192 byte blocks, 16 bytes per update, 512 updates): 27155 cycles/operation, 3 cycles/byte [255753.687224] tcrypt: test 18 ( 8192 byte blocks, 256 bytes per update, 32 updates): 2489 cycles/operation, 0 cycles/byte [255753.687241] tcrypt: test 19 ( 8192 byte blocks, 1024 bytes per update, 8 updates): 1268 cycles/operation, 0 cycles/byte [255753.687253] tcrypt: test 20 ( 8192 byte blocks, 4096 bytes per update, 2 updates): 959 cycles/operation, 0 cycles/byte [255753.687263] tcrypt: test 21 ( 8192 byte blocks, 8192 bytes per update, 1 updates): 17812 cycles/operation, 2 cycles/byte
This is on my AMD Ryzen 7 5800X which I would've expected to blow a simple RK3566 SBC out of the water ... :-/
Quoted 4 lines
Don't you love "accelerators" that make things 26 times slower?
I guess we'll get the usual argument that this driver is really just for "testing" or whatever.
Or someone spend a significant time implementing it trying to improve and extend SoC support in good faith, but without your insight.
Which is 'coincidentally' the exact reason why I suggested the patch series author to explicitly put you in To or CC.
I would not have used "pushing the driver as a checkbox feature" as argument. Especially since, apparently, the numbers show it performs poorly.
My 0.02
Quoted 56 lines · Diederik de Haas
Quoted 14 lines · Eric Biggers
Quoted 4 lines · Diederik de Haas
crypto-rk3566-test-no-crypto-module-log.txt:
https://paste.sr.ht/~diederik/bb5dbfd59f244a6422b965b30f9796ebbfdb1fcb
crypto-rk3566-test-with-crypto-module-log.txt:
https://paste.sr.ht/~diederik/ea72297678e19cbbc987de9548f9884382e1d1ccQuoted 8 lines
crypto-rk3568-test-no-crypto-module-log.txt:
https://paste.sr.ht/~diederik/309e519e6b1c31f4c1c5bcb1ea16cc8569a54830
crypto-rk3568-test-with-crypto-module-log.txt:
https://paste.sr.ht/~diederik/1e1e938ebbbae75128974fe0a7c240843bce04c8
crypto-rk3588-test-no-crypto-module-log.txt:
https://paste.sr.ht/~diederik/9a2adc2b2e42131445ce4576589e00ecf51ccb4b
crypto-rk3588-test-with-crypto-module-log.txt:
https://paste.sr.ht/~diederik/e04c11c8809031ca45662f7d4c227c1ba6162b65Quoted 6 lines
Thanks for running some benchmarks!
Looking at your results for rk3566 for example, SHA-256 on 4096-byte blocks is 115 cycles/operation for sha256-lib (i.e. ARMv8 CE) or 3027 cycles/operation for rk2-sha256. So the Rockchip driver is 26 times slower than simply using the existing well-tested CPU-based code.
I shared the results because:
1) I figured it might be useful to have these numbers
2) I didn't know how to interpret the results.Because a lower cycles/operations would IMO *logically* be better and your response above seems to confirm that.
Which makes the following results a 'bit' concerning? ``modprobe tcrypt mode=404``
[255753.686837] tcrypt: testing speed of async sha256 (sha256-lib) [255753.686841] tcrypt: test 0 ( 16 byte blocks, 16 bytes per update, 1 updates): 703 cycles/operation, 43 cycles/byte [255753.686848] tcrypt: test 1 ( 64 byte blocks, 16 bytes per update, 4 updates): 1101 cycles/operation, 17 cycles/byte [255753.686856] tcrypt: test 2 ( 64 byte blocks, 64 bytes per update, 1 updates): 869 cycles/operation, 13 cycles/byte [255753.686861] tcrypt: test 3 ( 256 byte blocks, 16 bytes per update, 16 updates): 1676 cycles/operation, 6 cycles/byte [255753.686871] tcrypt: test 4 ( 256 byte blocks, 64 bytes per update, 4 updates): 1059 cycles/operation, 4 cycles/byte [255753.686877] tcrypt: test 5 ( 256 byte blocks, 256 bytes per update, 1 updates): 1249 cycles/operation, 4 cycles/byte [255753.686884] tcrypt: test 6 ( 1024 byte blocks, 16 bytes per update, 64 updates): 4156 cycles/operation, 4 cycles/byte [255753.686904] tcrypt: test 7 ( 1024 byte blocks, 256 bytes per update, 4 updates): 1054 cycles/operation, 1 cycles/byte [255753.686911] tcrypt: test 8 ( 1024 byte blocks, 1024 bytes per update, 1 updates): 2826 cycles/operation, 2 cycles/byte [255753.686923] tcrypt: test 9 ( 2048 byte blocks, 16 bytes per update, 128 updates): 7438 cycles/operation, 3 cycles/byte [255753.686957] tcrypt: test 10 ( 2048 byte blocks, 256 bytes per update, 8 updates): 1263 cycles/operation, 0 cycles/byte [255753.686966] tcrypt: test 11 ( 2048 byte blocks, 1024 bytes per update, 2 updates): 940 cycles/operation, 0 cycles/byte [255753.686973] tcrypt: test 12 ( 2048 byte blocks, 2048 bytes per update, 1 updates): 4887 cycles/operation, 2 cycles/byte [255753.686991] tcrypt: test 13 ( 4096 byte blocks, 16 bytes per update, 256 updates): 14017 cycles/operation, 3 cycles/byte [255753.687054] tcrypt: test 14 ( 4096 byte blocks, 256 bytes per update, 16 updates): 1681 cycles/operation, 0 cycles/byte [255753.687065] tcrypt: test 15 ( 4096 byte blocks, 1024 bytes per update, 4 updates): 1059 cycles/operation, 0 cycles/byte [255753.687074] tcrypt: test 16 ( 4096 byte blocks, 4096 bytes per update, 1 updates): 9044 cycles/operation, 2 cycles/byte [255753.687105] tcrypt: test 17 ( 8192 byte blocks, 16 bytes per update, 512 updates): 27155 cycles/operation, 3 cycles/byte [255753.687224] tcrypt: test 18 ( 8192 byte blocks, 256 bytes per update, 32 updates): 2489 cycles/operation, 0 cycles/byte [255753.687241] tcrypt: test 19 ( 8192 byte blocks, 1024 bytes per update, 8 updates): 1268 cycles/operation, 0 cycles/byte [255753.687253] tcrypt: test 20 ( 8192 byte blocks, 4096 bytes per update, 2 updates): 959 cycles/operation, 0 cycles/byte [255753.687263] tcrypt: test 21 ( 8192 byte blocks, 8192 bytes per update, 1 updates): 17812 cycles/operation, 2 cycles/byte
Quoted 2 lines
This is on my AMD Ryzen 7 5800X which I would've expected to blow a simple RK3566 SBC out of the water ... :-/
tcrypt.c reports cycle counts from get_cycles(), which has an architecture-dependent meaning. On x86_64 it is something approximating the CPU cycles (3-5 GHz) whereas on arm64 it is the ARM Generic Timer which tends to be around 24 MHz or so, over 100 times slower than the actual CPU. So 9044 vs 115 "cycles" for x86_64 vs arm64 sounds about expected, and they suggest the real times are likely similar but slightly faster on x86_64 as expected.
This sort of thing is why benchmarks usually should measure real time. The legacy module tcrypt.c unfortunately uses get_cycles() instead.
Quoted 11 lines
Quoted 4 lines
Don't you love "accelerators" that make things 26 times slower?
I guess we'll get the usual argument that this driver is really just for "testing" or whatever.
Or someone spend a significant time implementing it trying to improve and extend SoC support in good faith, but without your insight.
Which is 'coincidentally' the exact reason why I suggested the patch series author to explicitly put you in To or CC.
I would not have used "pushing the driver as a checkbox feature" as argument. Especially since, apparently, the numbers show it performs poorly.
Well, hopefully that's the case and people actually care about reality for this one. The other drivers in drivers/crypto/ have the same problem but they are pushed anyway, so the track record isn't great.
- Eric
Quoted 7 lines · Eric Biggers
tcrypt.creports cycle counts fromget_cycles(), which has an architecture-dependent meaning. Onx86_64it is something approximating the CPU cycles (3-5 GHz) whereas on arm64 it is the ARM Generic Timer which tends to be around 24 MHz or so, over 100 times slower than the actual CPU. So 9044 vs 115 "cycles" forx86_64vs arm64 sounds about expected, and they suggest the real times are likely similar but slightly faster onx86_64as expected.
Phew, thanks for the explanation :-)
Quoted 2 lines
This sort of thing is why benchmarks usually should measure real time. The legacy module
tcrypt.cunfortunately usesget_cycles()instead.
What would be a better/non-legacy way to test crypto performance? Is that documented somewhere?
Cheers,
Diederik
Quoted 9 lines · Diederik de Haas
Quoted 7 lines · Eric Biggers
tcrypt.creports cycle counts fromget_cycles(), which has an architecture-dependent meaning. Onx86_64it is something approximating the CPU cycles (3-5 GHz) whereas on arm64 it is the ARM Generic Timer which tends to be around 24 MHz or so, over 100 times slower than the actual CPU. So 9044 vs 115 "cycles" forx86_64vs arm64 sounds about expected, and they suggest the real times are likely similar but slightly faster onx86_64as expected.
Quoted 7 lines
Phew, thanks for the explanation :-)
Quoted 2 lines
This sort of thing is why benchmarks usually should measure real time. The legacy module
tcrypt.cunfortunately usesget_cycles()instead.What would be a better/non-legacy way to test crypto performance? Is that documented somewhere?
The KUnit tests in lib/crypto/tests/ have benchmarks in them. They can be run like any other KUnit tests, though you do need to set CONFIG_CRYPTO_LIB_BENCHMARK=y to enable the benchmark test cases. I'll add some more information to libcrypto.rst about how to do this, but besides the extra option it's no different from any other KUnit tests.
Anyway, that is just for the code that actually matters, not legacy drivers like this one. So you're right to have used tcrypt.c to try to benchmark this legacy driver, as it is one of the ways to do so, just it is a bit pointless since this type of driver is known to be very slow.
- Eric
v3 cover crypto: rockchip: Add RK356x/RK3588 cryptographic offloader
In reply to Dawid OlesinskiThis 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
Quartz64-B (RK3566), NanoPi R5S (RK3568), NanoPC-T6 LTS (RK3588)
Tested on Orange Pi 5 Pro (RK3588S) and Banana Pi R2 Pro (RK3568).
All ten 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
Changes in v3:
Device tree binding (Sebastian Reichel, Heiko Stübner, sashiko-bot):
- Merge the compatibles: rk3588-crypto now falls back to rk3568-crypto (oneOf schema). The driver binds only against rockchip,rk3568-crypto; the rk3588 string is reserved for future quirks.
- Allow up to three reset lines (core/aclk/hclk) instead of a single reset, so a complete node describing the AXI and AHB resets validates.
- Drop "status = disabled" from the crypto nodes in both rk356x-base.dtsi and rk3588-base.dtsi; the block needs no board-specific resources.
Driver (sashiko-bot):
- Add SYSTEM_SLEEP_PM_OPS (pm_runtime_force_suspend / pm_runtime_force_resume) so the hardware is suspended correctly across system sleep even inside the autosuspend window.
- Guard the interrupt handler with pm_runtime_get_if_active() and balance pm_runtime_put() on all return paths, preventing register access to unclocked hardware during the teardown window.
- Allocate the per-device algorithm array with kmemdup() instead of devm_kmemdup() and free it explicitly in remove() after the engine is drained and algorithms are unregistered, so the templates outlive any in-flight teardown.
- Drop the explicit crypto_engine_stop() in remove(); rely on crypto_engine_exit() to stop and synchronously drain the kworker.
- On skcipher DMA timeout, assert reset and synchronize_irq() before unmapping the scatterlists, so delayed hardware cannot write to unmapped memory.
- Add CRYPTO_ALG_TYPE_AHASH support to rk2_crypto_debugfs_stats_show() to print request and fallback counters for hash algorithms.
Driver - cleanup (Diederik de Haas):
- Remove the redundant is_xts template field; test rk2_mode == RK2_CRYPTO_AES_XTS directly.
Driver — correctness and robustness (review round 2):
- Use explicit 32-bit DMA address handling: wrap sg_dma_address() and the LLI base in lower_32_bits() for both the skcipher and hash descriptor programming, making the hardware's 32-bit limitation explicit and silencing sparse on 64-bit builds.
- Fix AES-XTS IV handling: req->iv is the XTS tweak, not a CBC-style chaining IV, so it must not be overwritten with ciphertext. Gate the backup_iv save/restore on a single update_iv flag that excludes XTS, leaving the tweak untouched across chained requests.
- Zero ctx->key (memzero_explicit) and reset keylen when the fallback setkey fails, for both rk2_aes_setkey() and rk2_aes_xts_setkey().
- Harden the IRQ/PM suspend path: mask and clear DMA interrupts in rk2_crypto_pm_suspend() and re-clear/re-enable them in rk2_crypto_pm_resume(), so a pending level-triggered interrupt in the suspend window cannot storm.
- Use crypto_skcipher_set_reqsize() / crypto_ahash_set_reqsize() instead of assigning tfm->reqsize directly.
- Align DMA interrupt bit names in rk2_crypto.h (bits 1–6) with the TRM v1.0 specification.
- Update rk2_crypto_irq_handle() inline comment to reference DST_ITEM_DONE and SRC_ITEM_DONE.
Driver — cleanup:
- Simplify the hash path to a single scatterlist element (multi-SG hash already falls back), removing the now-dead LLI loop.
- Name the AES-192 capability bit (RK2_AES_VER_SUPP_192) and comment it, instead of a bare BIT(17) in the debug info dump.
v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- dt-bindings: wrap example in a bus node with #address/#size-cells = 2 and add the SCMI clock/reset dt-binding includes so dt_binding_check passes (Rob Herring / Krzysztof Kozlowski review).
- crypto: fix Kconfig to select CRYPTO_SM3 instead of the non-existent CRYPTO_SM3_GENERIC.
- crypto: drop IRQF_SHARED (the line is dedicated) and request the IRQ only after clocks are enabled and the completion is initialised; reorder probe accordingly.
- crypto: set a 32-bit DMA mask before allocating the descriptor table.
- crypto: suspend the device explicitly on removal before disabling runtime PM to avoid leaking clocks.
- crypto: call synchronize_irq() on the DMA timeout paths to close a race with delayed interrupts.
- crypto: convert fallback statistics to atomic_long_t.
- crypto: use cpu_to_le32() for all LLI descriptor fields (big-endian correctness).
- crypto: read key/IV with get_unaligned_be32() to fix an alignment fault and a big-endian double-swap.
- crypto: fix the CBC/XTS IV backup offset to use the processed length instead of the scatterlist capacity.
- arm64: dts: rk356x: move the crypto node into unit-address order.
v1: https://lore.kernel.org/r/[email protected]/
Build/rebase fixes (not from review):
- crypto: use sizeof(struct sm3_ctx) for the SM3 statesize, as struct sm3_state was removed by the lib/crypto SM3 conversion.
- crypto: add the missing SHA-224 zero-message case.
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 | 83 ++ MAINTAINERS | 2 + arch/arm64/boot/dts/rockchip/rk356x-base.dtsi | 11 + arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 11 + drivers/crypto/Kconfig | 32 + drivers/crypto/Makefile | 1 + drivers/crypto/rockchip/Makefile | 5 + drivers/crypto/rockchip/rk2_crypto.c | 783 ++++++++++++++++++ drivers/crypto/rockchip/rk2_crypto.h | 254 ++++++ drivers/crypto/rockchip/rk2_crypto_ahash.c | 541 ++++++++++++ drivers/crypto/rockchip/rk2_crypto_skcipher.c | 740 +++++++++++++++++ 11 files changed, 2463 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 v3 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.
NanoPi R5S, NanoPC-T6 LTS
--- .../crypto/rockchip,rk3588-crypto.yaml | 83 +++++++++++++++++++ MAINTAINERS | 2 + 2 files changed, 85 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +83 -0
@@ -0,0 +1,83 @@ +# 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: + oneOf: + - const: rockchip,rk3568-crypto + - items: + - enum: + - rockchip,rk3588-crypto + - const: rockchip,rk3568-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: + minItems: 1 + maxItems: 3 + + reset-names: + minItems: 1 + items: + - const: core + - const: aclk + - const: hclk + +required: + - compatible + - reg + - interrupts + - clocks + - clock-names + - resets + - reset-names + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/clock/rockchip,rk3588-cru.h> + #include <dt-bindings/reset/rockchip,rk3588-cru.h> + + bus { + #address-cells = <2>; + #size-cells = <2>; + + crypto@fe370000 { + compatible = "rockchip,rk3588-crypto", "rockchip,rk3568-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"; + }; + };
MAINTAINERS +2 -0
@@ -23131,9 +23131,11 @@ F: drivers/media/platform/rockchip/rkcif/ ROCKCHIP CRYPTO DRIVERS M: Corentin Labbe <[email protected]> +M: Dawid Olesinski <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/crypto/rockchip,rk3288-crypto.yaml +F: Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml F: drivers/crypto/rockchip/ ROCKCHIP I2S TDM DRIVER
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v3 1/4] dt-bindings: crypto: rockchip: Add RK356x/RK3588 crypto engine binding
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The schema fails to use conditional `if-then` blocks to enforce variant-specific resource…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The schema fails to use conditional if-then blocks to enforce variant-specific resource constraints for resets, allowing invalid configurations to silently pass validation.
- [Medium] The rockchip,rk3588-crypto compatible string incorrectly declares rockchip,rk3568-crypto as a fallback despite having incompatible hardware resource requirements. --
--- Patch [1]: [PATCH v3 1/4] dt-bindings: crypto: rockchip: Add RK356x/RK3588 crypto engine binding --- commit e7f36faa96ab3720550555cbd2cbc8b8549dc8d0
Author: Dawid Olesinski <[email protected]>
dt-bindings: crypto: rockchip: Add RK356x/RK3588 crypto engine binding
This commit adds a YAML device tree binding for the Rockchip V2 cryptographic hardware accelerator present on the RK3568 and RK3588 SoCs. It defines clocks, resets, and interrupts, noting that RK3588 accesses these via the ARM SCMI firmware interface while RK3568 uses direct CRU access.
Quoted 5 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +0
-0@@ -0,0 +1,83 @@
[ ... ]
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml line 21
Quoted 8 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +8
-0+properties: + compatible: + oneOf: + - const: rockchip,rk3568-crypto + - items: + - enum: + - rockchip,rk3588-crypto + - const: rockchip,rk3568-crypto
[Severity: Medium]
Is it safe to declare rockchip,rk3568-crypto as a fallback for rockchip,rk3588-crypto here?
Since the older RK3568 hardware requires 3 resets and the RK3588 provides only 1 (via SCMI), wouldn't an older OS probing the RK3588 device using this fallback string fail to probe due to missing resources?
Quoted 3 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +3
-0+ + reg: + maxItems: 1
[ ... ]
Quoted 6 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +6
-0+ clock-names: + items: + - const: core + - const: aclk + - const: hclk +
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml line 50
Quoted 10 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +10
-0+ resets: + minItems: 1 + maxItems: 3 + + reset-names: + minItems: 1 + items: + - const: core + - const: aclk + - const: hclk
[Severity: Medium]
Should there be an allOf with an if-then conditional block to enforce the exact number of resets based on the compatible string?
With minItems set to 1 globally, an incomplete device tree node for RK3568 with only one reset would silently pass dt_binding_check validation, even though the hardware requires all three.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v3 1/4] dt-bindings: crypto: rockchip: Add RK356x/RK3588 crypto engine binding
In reply to Dawid OlesinskiHi Dawid,
Quoted 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 5 lines
Co-developed-by Corentin Labbe <[email protected]>Signed-off-by Corentin Labbe <[email protected]>Signed-off-by Dawid Olesinski <[email protected]>NanoPi R5S, NanoPC-T6 LTS
AFAIK these lines should not have a line break, ie must be on one line.
Cheers,
Diederik
Quoted 111 lines
--- .../crypto/rockchip,rk3588-crypto.yaml | 83 +++++++++++++++++++ MAINTAINERS | 2 + 2 files changed, 85 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yamlDocumentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +83
-0@@ -0,0 +1,83 @@ +# 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: + oneOf: + - const: rockchip,rk3568-crypto + - items: + - enum: + - rockchip,rk3588-crypto + - const: rockchip,rk3568-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: + minItems: 1 + maxItems: 3 + + reset-names: + minItems: 1 + items: + - const: core + - const: aclk + - const: hclk + +required: + - compatible + - reg + - interrupts + - clocks + - clock-names + - resets + - reset-names + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/clock/rockchip,rk3588-cru.h> + #include <dt-bindings/reset/rockchip,rk3588-cru.h> + + bus { + #address-cells = <2>; + #size-cells = <2>; + + crypto@fe370000 { + compatible = "rockchip,rk3588-crypto", "rockchip,rk3568-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"; + }; + };MAINTAINERS +2
-0@@ -23131,9 +23131,11 @@ F: drivers/media/platform/rockchip/rkcif/ ROCKCHIP CRYPTO DRIVERS M: Corentin Labbe <[email protected]> +M: Dawid Olesinski <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/crypto/rockchip,rk3288-crypto.yaml +F: Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml F: drivers/crypto/rockchip/ ROCKCHIP I2S TDM DRIVER
Re: [PATCH v3 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 4 lines
Co-developed-by Corentin Labbe <[email protected]>Signed-off-by Corentin Labbe <[email protected]>Signed-off-by Dawid Olesinski <[email protected]>
Nope. Not possible. Drop non-applicable tags.
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml
Quoted 12 lines
NanoPi R5S, NanoPC-T6 LTS
--- .../crypto/rockchip,rk3588-crypto.yaml | 83 +++++++++++++++++++ MAINTAINERS | 2 + 2 files changed, 85 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yamlDocumentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +0
-0
Fallback should be used as the filename.
...
Quoted 8 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +8
-0+ clocks: + items: + - description: Core clock for the crypto IP internal logic + - description: AXI interconnect clock interface + - description: AHB interface clock + + clock-names: + items:
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml line 46
Quoted 10 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +10
-0+ - const: core + - const: aclk + - const: hclk + + resets: + minItems: 1 + maxItems: 3 + + reset-names: + minItems: 1
Why is this flexible?
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml line 59
Quoted 13 lines
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml new file +13
-0+ items: + - const: core + - const: aclk + - const: hclk + +required: + - compatible + - reg + - interrupts + - clocks + - clock-names + - resets + - reset-names
Binding looks the same as Documentation/devicetree/bindings/crypto/rockchip,rk3288-crypto.yaml. Why it cannot be added there?
Aren't the clocks and resets basically the same as in that file?
Best regards,
Krzysztof
PATCH v3 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).
NanoPi R5S, NanoPC-T6 LTS
--- drivers/crypto/Kconfig | 32 + drivers/crypto/Makefile | 1 + drivers/crypto/rockchip/Makefile | 5 + drivers/crypto/rockchip/rk2_crypto.c | 783 ++++++++++++++++++ drivers/crypto/rockchip/rk2_crypto.h | 254 ++++++ drivers/crypto/rockchip/rk2_crypto_ahash.c | 541 ++++++++++++ drivers/crypto/rockchip/rk2_crypto_skcipher.c | 740 +++++++++++++++++ 7 files changed, 2356 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 +32 -0
@@ -709,6 +709,38 @@ 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 RK356x and RK3588 cryptographic offloader" + depends on OF && ARCH_ROCKCHIP + depends on PM + select CRYPTO_AES + select CRYPTO_CBC + select CRYPTO_ECB + select CRYPTO_ENGINE + select CRYPTO_HASH + select CRYPTO_MD5 + select CRYPTO_SHA1 + select CRYPTO_SHA256 + select CRYPTO_SHA512 + select CRYPTO_SKCIPHER + select CRYPTO_SM3 + select CRYPTO_XTS + 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 workloads. + +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 +783 -0
783 lines not on this page · raw message
drivers/crypto/rockchip/rk2_crypto.h new file +254 -0
254 lines not on this page · raw message
drivers/crypto/rockchip/rk2_crypto_ahash.c new file +541 -0
541 lines not on this page · raw message
drivers/crypto/rockchip/rk2_crypto_skcipher.c new file +740 -0
740 lines not on this page · raw message
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v3 2/4] crypto: rockchip: Add RK356x/RK3588 cryptographic offloader driver
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] In `rk2_hash_run`, the DMA descriptor's source length is programmed with the full scatterlist node…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] In rk2_hash_run, the DMA descriptor's source length is programmed with the full scatterlist node length instead of the requested cryptographic payload length, causing a DMA hardware overrun and timeout.
- [High] The driver dynamically allocates its algorithm structures (rkc->algs) and explicitly frees them in rk2_crypto_remove(), leading to a use-after-free when active TFMs later access the freed memory.
- [High] In the DMA timeout error path, the hardware reset control is asserted without first disabling the device interrupt, causing a race condition with the IRQ handler.
- [Medium] The fallback checker rk2_ahash_need_fallback incorrectly evaluates unused scatterlist entries beyond the requested payload length, causing unnecessary software fallbacks. --
--- Patch [2]: [PATCH v3 2/4] crypto: rockchip: Add RK356x/RK3588 cryptographic offloader driver --- commit 4f54e41eac56e61deb80f3aed1c19c8ac7cba18a
Author: Dawid Olesinski <[email protected]>
crypto: rockchip: Add RK356x/RK3588 cryptographic offloader driver
Add a driver for the second-generation Rockchip cryptographic hardware accelerator found on RK3568 and RK3588 SoCs. It provides hardware acceleration for AES block ciphers and hashing functions via a DMA engine, falling back to software for unsupported requests.
drivers/crypto/rockchip/rk2_crypto.c +0 -0
[ ... ]
Quoted 5 lines
static void
rk2_crypto_remove(struct platform_device *pdev){ struct rk2_crypto_dev *rkc = platform_get_drvdata(pdev); rk2_crypto_unregister(rkc);
[ ... ]
Quoted 4 lines
dma_free_coherent(rkc->dev, sizeof(struct rk2_crypto_lli) * MAX_LLI,
rkc->tl, rkc->t_phy);
kfree(rkc->algs);[Severity: High]
Could this result in a use-after-free if active TFMs are still referencing the algorithm structures?
When a user opens a crypto session and allocates a TFM, the crypto_alg structure is pinned. If the device is unbound via sysfs, rk2_crypto_remove() is invoked and frees rkc->algs immediately without waiting for active TFMs to close.
When the session is later closed, the crypto core might access the freed alg structure, for example in crypto_alg_put(). Should the algorithm structures be statically allocated or managed differently to avoid this?
Quoted 1 line
}
drivers/crypto/rockchip/rk2_crypto_ahash.c +0 -0
[ ... ]
Quoted 2 lines
static bool
rk2_ahash_need_fallback(struct ahash_request *areq){
[ ... ]
Quoted 4 lines
sg = areq->src;
while (sg) {
if (!IS_ALIGNED(sg->offset, sizeof(u32))) {
atomic_long_inc(&algt->stat_fb_align);Quoted 8 lines
return true;
}
if (sg->length % 4) {
atomic_long_inc(&algt->stat_fb_sglen);
return true;
}
sg = sg_next(sg);
}[Severity: Medium]
Does this loop unnecessarily force a fallback for scatterlist entries that extend beyond the requested payload length?
If a request fits entirely within the first scatterlist entry, but the chain contains subsequent unused entries from the network stack that are unaligned or have lengths not a multiple of 4, this loop will still evaluate them and trigger a fallback.
Is there a way to limit this check to only the scatterlist length up to areq->nbytes to avoid performance degradation on hardware-capable requests?
[ ... ]
Quoted 2 lines
int
rk2_hash_run(struct crypto_engine *engine, void *breq){
[ ... ]
Quoted 7 lines
/*
* Multi-SG requests are forced into the software fallback path due to
* hardware padding limitations (HW_PAD). Therefore, we are guaranteed
* to only process a single scatterlist element here.
*/
dd->src_addr = cpu_to_le32(lower_32_bits(sg_dma_address(sgs)));
dd->src_len = cpu_to_le32(sg_dma_len(sgs));[Severity: High]
Will programming the DMA descriptor source length with the full scatterlist node length cause a hardware overrun?
If a caller submits an asynchronous hash request where the scatterlist element is larger than areq->nbytes, the hardware padding engine will expect exactly areq->nbytes. However, the DMA engine will push the entire sg_dma_len(sgs) into the FIFO.
Could this cause the DMA engine to stall when the hash engine stops reading, resulting in a timeout? Should this length be capped at areq->nbytes instead?
[ ... ]
Quoted 10 lines
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);
synchronize_irq(rkc->irq);
}[Severity: High]
Is there a race condition here between asserting the hardware reset and the interrupt handler?
If the DMA transfer times out and the hardware asserts an interrupt exactly as the timeout expires, rk2_crypto_irq_handle() might execute concurrently on another CPU.
If the interrupt handler attempts to read the RK2_CRYPTO_DMA_INT_ST register while reset_control_assert() is active, could this crash the system with a synchronous external abort?
Would it be safer to disable the interrupt before asserting the reset control?
drivers/crypto/rockchip/rk2_crypto_skcipher.c +0 -0
[ ... ]
Quoted 2 lines
int
rk2_cipher_run(struct crypto_engine *engine, void *async_req){
[ ... ]
Quoted 11 lines
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);
synchronize_irq(rkc->irq);
}[Severity: High]
Similar to the timeout path in rk2_hash_run(), does asserting the reset control before synchronizing and disabling the IRQ risk a race condition with rk2_crypto_irq_handle() here?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v3 2/4] crypto: rockchip: Add RK356x/RK3588 cryptographic offloader driver
In reply to Dawid OlesinskiQuoted 4 lines · Dawid Olesinski
Add 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").
Quoted 10 lines
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.
Hardware encryption drivers are being removed or at least tried to be removed multipled times, so would be nice to see here WHY this one should be added.
Best regards,
Krzysztof
Re: [PATCH v3 2/4] crypto: rockchip: Add RK356x/RK3588 cryptographic offloader driver
Quoted 16 lines · Krzysztof Kozlowski
Quoted 4 lines · Dawid Olesinski
Add 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").
Quoted 10 lines
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.
Quoted 3 lines
Hardware encryption drivers are being removed or at least tried to be removed multipled times, so would be nice to see here WHY this one should be added.
Well, it is the usual drivers/crypto/ pattern. It's being pushed as an "accelerator" despite the SoC already having ARMv8 CE which is almost certainly much faster (ARMv8 CE support is mentioned in the datasheet), MD5 (!) is being pushed for some reason, it's not properly tested, and no use case is described. These crypto driver submissions are basically spam at this point. Only thing that really saves them is that not many people have the hardware, so there tend not to be independent voices in the room besides the people pushing the driver as a checkbox feature.
- Eric
PATCH v3 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.
NanoPi R5S, NanoPC-T6 LTS
--- arch/arm64/boot/dts/rockchip/rk356x-base.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +11 -0
@@ -1111,6 +1111,17 @@ sdhci: mmc@fe310000 { status = "disabled"; }; + 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"; + }; + /* * Testing showed that the HWRNG found in RK3566 produces unacceptably * low quality of random data, so the HWRNG isn't enabled for all RK356x
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v3 3/4] arm64: dts: rockchip: Add crypto node to rk356x-base
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The `crypto` device tree node is missing the `status = "disabled";` property, contradicting the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The crypto device tree node is missing the status = "disabled"; property, contradicting the commit message and enabling it by default on all boards. --
--- Patch [3]: [PATCH v3 3/4] arm64: dts: rockchip: Add crypto node to rk356x-base --- commit 452b9449e76bd94304ad239887547298226d6bf8
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 to the base dtsi file. The commit message notes that the node is disabled by default and should be enabled by board files that wish to use hardware crypto offload.
Quoted 3 lines
arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +0
-0
[ ... ]
Quoted 4 lines
arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +0
-0@@ -1112,6 +1112,17 @@ sdhci: mmc@fe310000 { status = "disabled"; };
arch/arm64/boot/dts/rockchip/rk356x-base.dtsi sdhci: mmc@fe310000 { · line 1124
Quoted 10 lines
arch/arm64/boot/dts/rockchip/rk356x-base.dtsi +10
-0+ 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"; + };
[Severity: Medium]
Does this node need a status = "disabled"; property to match the commit message?
The commit message states: "The node is disabled by default; board files that wish to use hardware crypto offload must enable it."
Because device tree nodes default to "okay" when the status property is omitted, the lack of status = "disabled" here will cause the cryptographic offloader driver to automatically probe on all RK356x boards that include rk356x-base.dtsi, rather than requiring board files to enable it.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v3 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.
NanoPi R5S, NanoPC-T6 LTS
--- arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/arm64/boot/dts/rockchip/rk3588-base.dtsi +11 -0
@@ -2249,6 +2249,17 @@ sdhci: mmc@fe2e0000 { status = "disabled"; }; + crypto: crypto@fe370000 { + compatible = "rockchip,rk3588-crypto", "rockchip,rk3568-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"; + }; + rng@fe378000 { compatible = "rockchip,rk3588-rng"; reg = <0x0 0xfe378000 0x0 0x200>;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v3 4/4] arm64: dts: rockchip: Add crypto node to rk3588-base
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Missing `status = "disabled";` property in the device tree nodes, contradicting the commit…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Missing status = "disabled"; property in the device tree nodes, contradicting the commit message.
- [High] Unbounded DMA transfer length in hardware hash requests.
- [Medium] Software fallback logic unnecessarily evaluates unused scatterlist entries.
--
--- Patch [4]: [PATCH v3 4/4] arm64: dts: rockchip: Add crypto node to rk3588-base --- commit 02aef3c847464eaa142ef8468b37da657834130b
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 RK3588. It uses the ARM SCMI interface to obtain clocks and the reset line from TrustZone firmware to avoid asynchronous bus faults. The device tree node is intended to be disabled by default.
Quoted 2 lines
The node is disabled by default; board files that wish to use hardware crypto offload must enable it.
[Severity: High]
Does this commit message match the device tree node definition? The node is missing the status property, which means it will be enabled by default. Does this also apply to the crypto@fe380000 node in rk356x-base.dtsi?
arch/arm64/boot/dts/rockchip/rk3588-base.dtsi sdhci: mmc@fe2e0000 { · line 2453
Quoted 12 lines
arch/arm64/boot/dts/rockchip/rk3588-base.dtsi +4
-0@@ -2447,6 +2447,17 @@ sdhci: mmc@fe2e0000 { status = "disabled"; }; + crypto: crypto@fe370000 { + compatible = "rockchip,rk3588-crypto", "rockchip,rk3568-crypto"; + reg = <0x0 0xfe370000 0x0 0x2000>; + interrupts = <GIC_SPI 209 IRQ_TYPE_LEVEL_HIGH 0>;
[Severity: High]
Should there be a status = "disabled"; property included here? Probing the hardware crypto offloader on boards without proper firmware configuration can trigger asynchronous bus faults and boot failures.
[ ... ]
[Severity: High]
Can this hardware enablement trigger DMA transfer issues in the driver?
drivers/crypto/rockchip/rk2_crypto_ahash.c:rk2_hash_run() {
...
dd->src_addr = cpu_to_le32(lower_32_bits(sg_dma_address(sgs)));
dd->src_len = cpu_to_le32(sg_dma_len(sgs));
...
}If the crypto API submits an asynchronous hash request where the scatterlist element's mapped length (sg_dma_len(sgs)) is larger than the requested hash size (areq->nbytes), does this code program the DMA descriptor src_len to the full mapped length?
Because the hardware only expects areq->nbytes, commanding the DMA engine to push excess data could cause it to stall indefinitely when the crypto engine stops accepting data, leading to a timeout and operation failure.
[Severity: Medium]
Does the software fallback logic unnecessarily evaluate unused scatterlist entries?
drivers/crypto/rockchip/rk2_crypto_ahash.c:rk2_ahash_need_fallback() {
...
sg = areq->src;
while (sg) {
if (!IS_ALIGNED(sg->offset, sizeof(u32))) {
atomic_long_inc(&algt->stat_fb_align);
return true;
}
if (sg->length % 4) {
atomic_long_inc(&algt->stat_fb_sglen);
return true;
}
sg = sg_next(sg);
}
...
}If a hash request has an areq->nbytes that fits entirely within the first scatterlist entry (nents == 1), but the request includes a longer scatterlist chain with trailing, unused entries that have unaligned offsets or lengths, will this loop evaluate them and force an incorrect fallback to software hashing?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4