Skip to content

Replacing rk35xx-montjoie-crypto-v2-rk35xx.patch with rk35xx-crypto-v3.patch for Linux kernel v6.18 v7.0 v7.1#9796

Open
Dawidro wants to merge 1 commit into
armbian:mainfrom
Dawidro:updat-rk35xx-crypto-v3-patch
Open

Replacing rk35xx-montjoie-crypto-v2-rk35xx.patch with rk35xx-crypto-v3.patch for Linux kernel v6.18 v7.0 v7.1#9796
Dawidro wants to merge 1 commit into
armbian:mainfrom
Dawidro:updat-rk35xx-crypto-v3-patch

Conversation

@Dawidro

@Dawidro Dawidro commented May 10, 2026

Copy link
Copy Markdown

Description

Fixes and updates to

This issue for instance:
[Bug]: rk3588 crypto unaccelerated #7703

Documentation summary for feature / change

  1. Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml

    Clock names corrected. Original had "a" and "h" as clock-names items. v3 corrects them to "core", "aclk", "hclk" matching the actual clock signal names in the hardware and passing make dt_binding_check.
    YAML example reg size fixed. Original example said 0x4000 (16KB). v3 corrects to 0x2000 (8KB) to match both DTS nodes and the actual hardware register map.

  2. drivers/crypto/Makefile

    Root Makefile hook added. v3 adds obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP2) += rockchip/ to the root crypto Makefile. Without this, if CONFIG_CRYPTO_DEV_ROCKCHIP (the V1 driver) is disabled, the build system never descends into drivers/crypto/rockchip/ and the V2 driver silently doesn't build regardless of Kconfig selection.

  3. rk2_crypto.h

    dbgfs_info field added to struct rockchip_ip. Original was missing it, causing register_debugfs to overwrite dbgfs_stats with the info file pointer. v3 adds struct dentry *dbgfs_info as the third debugfs member.
    #include <linux/reset.h> added. Moved from rk2_crypto.c so that rk2_crypto_ahash.c and rk2_crypto_skcipher.c can call reset_control_assert/deassert directly in their DMA error recovery paths.
    fallback_req ordering documented. Added // keep at the end comment on struct skcipher_request fallback_req in rk2_cipher_rctx. Same ordering maintained in rk2_ahash_rctx with struct ahash_request fallback_req as last member — required for the flexible array __ctx placement to work correctly.

  4. rk2_crypto.c

    pm_init return value fixed. Original returned err at the end, which after pm_runtime_enable would always be 0 but was misleading. v3 explicitly return 0.
    IRQ handler fires complete() only on LISTDONE or hard error. Original called complete() on any non-zero DMA_INT_ST. Intermediate SRC_INT per-LLI-entry interrupts would prematurely wake the hash path before all data was processed, producing wrong digests. v3 only signals completion for RK2_CRYPTO_DMA_INT_LISTDONE (BIT(0)) or error bits (0xF8).
    Consistent spin_lock_bh throughout. get_rk2_crypto(), probe, and remove all use spin_lock_bh/spin_unlock_bh. Original used plain spin_lock in get_rk2_crypto() and probe, risking deadlock if a crypto engine callback ran on the same CPU.
    Debugfs overwrite bug fixed. Original register_debugfs wrote to rocklist.dbgfs_stats twice — the second write (info file) overwrote the stats file pointer. v3 correctly uses rocklist.dbgfs_info for the second file.
    pm_runtime_resume_and_get return value checked in probe. Original ignored this return value. v3 checks it and jumps to err_pm on failure.
    PM reference count balanced on probe success. Original left usage count at 1 after successful registration, pinning the device ON forever. v3 calls pm_runtime_mark_last_busy + pm_runtime_put_autosuspend after successful registration.
    Separate err_register_alg label with list_del + pm_runtime_put_sync. Original jumped to err_pm on registration failure, which skipped both the list cleanup and the PM put. v3 has a dedicated label that removes the device from the list and decrements the PM count before falling through to rk2_crypto_pm_exit.
    crypto_engine_exit called before rk2_crypto_pm_exit in remove. Original order was reversed — clocks disabled before engine drained. v3 exits the engine first to flush all in-flight requests, then disables PM.
    algt->dev handoff on multi-device remove. When the registering device is removed while a second device survives, v3 iterates all algorithm templates and updates algt->dev to the surviving device, preventing use-after-free in tfm_init/tfm_exit logging.
    dma_free_coherent added to rk2_crypto_remove. The LLI table is a non-managed allocation. Original never freed it on normal remove, leaking it on every rmmod. v3 frees it at the end of remove.
    pm_resume does full assert/udelay/deassert cycle. Ensures hardware is cleanly initialised with clocks running on every PM wakeup, not just deassert.

  5. rk2_crypto_ahash.c

    Multi-SG hardware fallback. Added if (sg_nents(areq->src) > 1) check at the top of rk2_ahash_need_fallback. The RK3568/3588 hardware padding engine (HW_PAD) loses block-count state across LLI descriptor boundaries, producing wrong digests for any multi-SG request. Single-SG requests continue to use hardware; multi-SG routes to software fallback and increments stat_fb_sgdiff.
    Explicit payload length for hardware padding. Added writel(areq->nbytes, rkc->reg + RK2_CRYPTO_CH0_PC_LEN_0) before starting DMA. The HW_PAD bit requires the total message length to be programmed in advance so the hardware knows where to apply the Merkle–Damgård padding. Without this, single-SG hardware hashes would also produce wrong results.
    INT_EN write-enable mask fixed. Original wrote RK2_CRYPTO_DMA_INT_LISTDONE | 0x7F with no upper bits, which is silently discarded by the HIWORD_UPDATE register pattern. v3 first clears stale pending interrupts (writel(0x7F, DMA_INT_ST)), then writes 0x007F007F so enable bits and their write-enable mask are both set.
    LIST_INT added to last LLI descriptor. LISTDONE (BIT(0)) is only set in DMA_INT_ST when the last LLI entry has RK2_LLI_DMA_CTRL_LIST_INT (BIT(8)) set in dma_ctrl. Without it, DMA completes silently, no interrupt fires, 2-second timeout every request. v3 adds RK2_LLI_DMA_CTRL_LIST_INT | RK2_LLI_DMA_CTRL_SRC_INT to the last descriptor.
    Uninterruptible completion wait. Changed from wait_for_completion_interruptible_timeout to wait_for_completion_timeout. The interruptible variant can return early on SIGTERM/SIGKILL while DMA is still writing to memory, causing data corruption or use-after-free.
    timeout return value captured and checked. Original discarded the return value, making timeout undetectable. v3 stores the return in unsigned long timeout and checks !timeout for ETIMEDOUT, then separately checks !rkc->status for EIO.
    rctx->nrsgs = 0 initialised before dma_map_sg. Ensures rk2_hash_unprepare never calls dma_unmap_sg on an uninitialised count.
    Safe dma_unmap_sg in unprepare. Added if (rctx->nrsgs) guard before dma_unmap_sg, preventing a kernel panic if dma_map_sg failed in the prepare step.
    MAX_LLI overflow check. Added if (ddi >= MAX_LLI) at the top of the LLI build loop with dev_err and -EINVAL. Prevents overflowing the DMA-coherent LLI table with a scatter-list longer than 20 entries.
    readl_poll_timeout_atomic return value checked. Original discarded the return, allowing wrong digest output if HASH_VALID never set. v3 assigns to err and jumps to theend on timeout.
    be32_to_cpu in digest readback. Hardware outputs all digest words (SHA1, SHA256, SHA384, SHA512, SM3, MD5) in big-endian register format. readl() on LE ARM64 gives a byte-swapped value; be32_to_cpu corrects it before put_unaligned_le32.
    pm_runtime_mark_last_busy before put_autosuspend. Refreshes the autosuspend timer on each request completion so the device doesn't suspend between back-to-back requests.
    DMA error hardware reset. On !rkc->status (DMA error interrupt), v3 performs reset_control_assert/udelay(10)/reset_control_deassert to recover the DMA engine from a stuck state before returning -EIO.
    crypto_ahash_set_statesize promotion in rk2_hash_init_tfm. After allocating the fallback, v3 queries its statesize and promotes the template's statesize if the fallback needs more space. Fixes -EOVERFLOW on export()/import() when ARM Crypto Extensions drivers (sha1-ce, sha256-ce) advertise a larger statesize than the raw hash state.

  6. rk2_crypto_skcipher.c

    rk2_print gated with #ifdef CONFIG_CRYPTO_DEV_ROCKCHIP2_DEBUG. Register dumps on every DMA error flood production logs. v3 wraps the entire function and its callsite with the debug config guard.
    OTP KEY VALID bit corrected. Original checked BIT(2) for both HASH BUSY and OTP KEY VALID (copy-paste error). v3 uses BIT(3) for OTP KEY VALID.
    Multi-bit switch statements corrected. All field switches now use (v >> N) & mask before comparing case values, fixing cases that could never match after masking.
    dd->dma_ctrl = assignment not |=. The LLI table persists across requests. Using |= accumulates stale flag bits from previous requests. v3 uses = for the initial value.
    RK2_CRYPTO_DMA_CTL_START << 16 not literal 1 << 16. Ensures the write-enable mask is always correct regardless of the constant value.
    get_rk2_crypto() with null check for cipher. Original used algt->dev (always first device) for all cipher requests, bypassing load balancing. v3 uses get_rk2_crypto() matching the hash path, with if (!rkc) return -ENODEV.
    DMA unmap moved before timeout/error checks. Original goto theend on timeout bypassed dma_unmap_sg, permanently leaking the mapping. v3 unmaps unconditionally before checking results.
    wait_for_completion_timeout (uninterruptible). Same fix as hash — prevents signal interruption while DMA is active.
    Separate timeout/error errnos. ETIMEDOUT for timeout, EIO for DMA error with rk2_print debug dump.
    INT_EN write-enable mask + stale clear. Same fix as hash path: writel(0x7F, DMA_INT_ST) then writel(0x007F007F, DMA_INT_EN).
    LIST_INT added to cipher descriptor. RK2_LLI_DMA_CTRL_LIST_INT added to dd->dma_ctrl so LISTDONE fires in DMA_INT_ST.
    pm_runtime_mark_last_busy before put_autosuspend.
    DMA error hardware reset. Same reset_control_assert/deassert recovery as hash.
    Fallback log changed to dev_dbg. Original dev_info in rk2_cipher_tfm_init flooded logs during PM stress testing (hundreds of TFM allocations per second). v3 uses dev_dbg.
    Stricter XTS fallback check. Changed sg_nents(areq->src) > 1 to != 1 for the XTS-specific SG check. XTS requires exactly one contiguous buffer — more than one SG is wrong but so is zero.

  7. include/dt-bindings/reset/rockchip,rk3588-cru.h

    Patch correctly uses mainline SCMI for RK3588. mainline Linux kernel Commit 849d9db form Feb 22, 2025 "dt-bindings: reset: Add SCMI reset IDs for RK3588" so there is no reason to modify this file as entries exist already. Please note the patch still removes the entire RK3588_SECURECRU_RESET_OFFSET macro and all its entries as keeping them in rst-rk3588.c alongside SCMI would be redundant and potentially dangerous.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Please also note any relevant details for your test configuration.
CONFIG_CRYPTO_SELFTESTS=y
CONFIG_CRYPTO_SELFTESTS_FULL=y

modprobe tcrypt mode=38 # AES-ECB
modprobe tcrypt mode=39 # AES-CBC
modprobe tcrypt mode=400 # SHA-256
modprobe tcrypt mode=404 # SHA-512
modprobe tcrypt mode=405 # MD5
dmesg | grep -E "tcrypt|testing|passed|failed"

cat /proc/crypto | grep -A5 "rk2"
driver : rk2-sm3
module : rk_crypto2
priority : 300
refcnt : 1
selftest : passed
internal : no

driver : rk2-sha512
module : rk_crypto2
priority : 300
refcnt : 1
selftest : passed
internal : no

driver : rk2-sha384
module : rk_crypto2
priority : 300
refcnt : 1
selftest : passed
internal : no

driver : rk2-sha256
module : rk_crypto2
priority : 300
refcnt : 1
selftest : passed
internal : no

driver : rk2-sha1
module : rk_crypto2
priority : 300
refcnt : 1
selftest : passed
internal : no

driver : rk2-md5
module : rk_crypto2
priority : 300
refcnt : 1
selftest : passed
internal : no

driver : xts-aes-rk2
module : rk_crypto2
priority : 300
refcnt : 1
selftest : passed
internal : no

driver : cbc-aes-rk2
module : rk_crypto2
priority : 300
refcnt : 1
selftest : passed
internal : no

driver : ecb-aes-rk2
module : rk_crypto2
priority : 300
refcnt : 1
selftest : passed
internal : no

cat /sys/kernel/debug/rk2_crypto/stats
rk2-crypto fe370000.crypto requests: 738
ecb-aes-rk2 ecb(aes) reqs=144 fallback=1960
fallback due to length: 303
fallback due to alignment: 1651
fallback due to SGs: 0
cbc-aes-rk2 cbc(aes) reqs=183 fallback=2109
fallback due to length: 308
fallback due to alignment: 1790
fallback due to SGs: 7
xts-aes-rk2 xts(aes) reqs=174 fallback=2170
fallback due to length: 74
fallback due to alignment: 763
fallback due to SGs: 0
rk2-md5 md5 reqs=34 fallback=718
rk2-sha1 sha1 reqs=46 fallback=654
rk2-sha256 sha256 reqs=34 fallback=609
rk2-sha384 sha384 reqs=41 fallback=666
rk2-sha512 sha512 reqs=42 fallback=654
rk2-sm3 sm3 reqs=40 fallback=690

cat /sys/kernel/debug/rk2_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

cryptsetup benchmark --cipher aes-cbc --key-size 256

Tests are approximate using memory only (no storage IO).

Algorithm | Key | Encryption | Decryption

aes-cbc        256b       106.4 MiB/s        68.0 MiB/s

rapid suspend/resume

for i in $(seq 1 1000); do
echo -n "test$i" | sha256sum
sleep 0.003
done

for i in $(seq 1 20); do
modprobe rk_crypto2
sleep 1
rmmod rk_crypto2
sleep 0.5
done

Checklist:

Please delete options that are not relevant.

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features

    • Added hardware-accelerated cryptography for Rockchip RK3588/RK3566 devices.
    • Supports AES (ECB, CBC, XTS modes) and hash algorithms (MD5, SHA1, SHA256, SHA384, SHA512, SM3).
  • Bug Fixes

    • Fixed device-tree binding documentation and register mappings.
    • Improved hardware initialization and error handling for cryptographic operations.
  • Documentation

    • Updated device-tree binding specifications for proper crypto hardware configuration.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 10, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request adds Rockchip RK3588/RK3568 V2 crypto offloader support across three kernel versions (6.18, 7.0, 7.1) via device-tree bindings, DTS node integration, reset handling changes, and a new crypto engine driver supporting AES and hash algorithms with DMA acceleration and software fallback paths.

Changes

Rockchip RK2 Crypto V2 Driver Implementation

Layer / File(s) Summary
Device-Tree Binding & Build Config
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml, drivers/crypto/Kconfig
RK3588 crypto binding corrects clock-names to core/aclk/hclk and fixes example reg size to 0x2000. Kconfig introduces CRYPTO_DEV_ROCKCHIP2 option with optional debug mode.
DTS Node Integration
arch/arm64/boot/dts/rockchip/rk356x-base.dtsi, arch/arm64/boot/dts/rockchip/rk3588-base.dtsi
Crypto device nodes are added for RK3568 and RK3588 with corrected compatible strings, register addressing, interrupts, and corrected clock/reset naming aligned to binding.
Reset Control Architecture
drivers/clk/rockchip/rst-rk3588.c, include/dt-bindings/reset/rockchip,rk3588-cru.h
Secure CRU reset offsets are removed; crypto block resets now obtain via SCMI instead of direct kernel register access.
Makefile Integration
drivers/crypto/Makefile, drivers/crypto/rockchip/Makefile
Root and Rockchip subdirectory Makefiles wired to build rk_crypto2.o aggregate when CONFIG_CRYPTO_DEV_ROCKCHIP2 enabled.
Driver Header
drivers/crypto/rockchip/rk2_crypto.h
Header defines register map, device/request context structs, and exports cipher/hash functions. struct rockchip_ip gains dbgfs_info dentry; reset.h included for DMA error recovery.
Core Driver: Device Management & PM
drivers/crypto/rockchip/rk2_crypto.c
Device list management with BH-safe locking, runtime PM with autosuspend, explicit reset assert/deassert recovery on resume and DMA error, IRQ handler reading/clearing DMA status bits, debugfs stats/info creation, and probe/remove managing coherent DMA memory and algorithm ownership.
Hash Engine: AHASH Path
drivers/crypto/rockchip/rk2_crypto_ahash.c
Multi-SG inputs force software fallback; hardware path corrects DMA payload length programming, clears stale interrupts, sets LIST_INT for completion, uses uninterruptible waits with timeout detection, converts digest words via be32_to_cpu, guards SG unmap, performs reset recovery on DMA error, and promotes template statesize for fallback export/import.
Cipher Engine: SKCIPHER Path
drivers/crypto/rockchip/rk2_crypto_skcipher.c
AES ECB/CBC/XTS support with XTS-specific "exactly one SG" fallback requirement. Debug register dumps gated behind CONFIG_CRYPTO_DEV_ROCKCHIP2_DEBUG. Corrects hardware bitfield decoding, clears stale interrupt status, enables with correct masks, sets LIST_INT/DST bits, unmaps SG before timeout/error checks, performs reset recovery on DMA failure, manages fallback tfm lifecycle, and adjusts PM autosuspend bookkeeping.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Poem

🐰 A crypto engine hops with care,
With DMA lists and resets rare,
AES and hashes running fast,
While fallback paths ensure they last,
Three branches bloom with V2's might! 🔐

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: replacing an older crypto patch with a newer V3 version across multiple kernel versions (6.18, 7.0, 7.1).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added 05 Milestone: Second quarter release size/large PR with 250 lines or more Needs review Seeking for review Hardware Hardware related like kernel, U-Boot, ... Patches Patches related to kernel, U-Boot, ... labels May 10, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (6)
patch/kernel/archive/rockchip64-7.0/rk35xx-crypto-v3.patch (4)

1585-1589: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Mirror the -ENODEV guard from the skcipher path.

get_rk2_crypto() can return NULL during teardown because rk2_crypto_remove() drops the device from rocklist before unregistering the algorithms. The skcipher path already handles that, but the hash path dereferences dev->engine unconditionally.

Suggested fix
 	dev = get_rk2_crypto();
+	if (!dev)
+		return -ENODEV;
 
 	rctx->dev = dev;
 	engine = dev->engine;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@patch/kernel/archive/rockchip64-7.0/rk35xx-crypto-v3.patch` around lines 1585
- 1589, The hash path dereferences dev->engine after calling get_rk2_crypto()
without handling a NULL return; mirror the skcipher path by checking the return
value of get_rk2_crypto() and returning -ENODEV (or performing the same
cleanup/exit logic used in the skcipher path) when dev is NULL to avoid
dereferencing during teardown (reference functions/variables: get_rk2_crypto(),
rctx, dev, engine, rk2_crypto_remove(), and the skcipher code path which already
performs this guard).

1579-1583: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Handle empty-message digests before inspecting the scatterlist.

rk2_ahash_need_fallback() walks req->src before the zero-length fast path runs. A valid req->nbytes == 0 digest can come with req->src == NULL, so this can oops instead of returning the precomputed empty-message hash.

Suggested fix
-	if (rk2_ahash_need_fallback(req))
-		return rk2_ahash_digest_fb(req);
-
 	if (!req->nbytes)
 		return zero_message_process(req);
+
+	if (rk2_ahash_need_fallback(req))
+		return rk2_ahash_digest_fb(req);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@patch/kernel/archive/rockchip64-7.0/rk35xx-crypto-v3.patch` around lines 1579
- 1583, The code calls rk2_ahash_need_fallback(req) before checking for a
zero-length message, which can dereference req->src when nbytes == 0 and src is
NULL; reorder the checks so you handle the empty-message fast path first (if
(!req->nbytes) return zero_message_process(req);) and only then call
rk2_ahash_need_fallback(req) and rk2_ahash_digest_fb(req) to avoid walking the
scatterlist for zero-length requests.

2247-2251: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use the processed byte count when rolling the IV.

Both offsets are derived from the full SG element length, but this loop only processes todo = min(..., len) bytes per DMA step. If the request ends in the middle of an SG entry, CBC/XTS will pick the next IV from bytes that were never part of the operation.

Suggested fix
 		if (areq->iv && crypto_skcipher_ivsize(tfm) > 0) {
 			if (rctx->mode & RK2_CRYPTO_DEC) {
-				offset = sgs->length - ivsize;
+				offset = min(len, sgs->length) - ivsize;
 				scatterwalk_map_and_copy(rctx->backup_iv, sgs,
 							 offset, ivsize, 0);
 			}
 		}
@@
 		if (areq->iv && ivsize > 0) {
-			offset = sgd->length - ivsize;
+			offset = todo - ivsize;
 			if (rctx->mode & RK2_CRYPTO_DEC) {
 				memcpy(areq->iv, rctx->backup_iv, ivsize);
 				memzero_explicit(rctx->backup_iv, ivsize);

Also applies to: 2380-2387

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@patch/kernel/archive/rockchip64-7.0/rk35xx-crypto-v3.patch` around lines 2247
- 2251, The IV-roll code uses the full SG element length (sgs->length) to
compute offset which is wrong when the DMA step processed only todo/min(len)
bytes; update the logic in the decryption branch inside the IV handling (the
block referencing areq->iv, crypto_skcipher_ivsize(tfm), rctx->mode &
RK2_CRYPTO_DEC, offset, sgs and scatterwalk_map_and_copy) to compute offset from
the actual processed byte count (use the local processed/todo variable or
len_processed) instead of sgs->length so the backup_iv is copied from the bytes
that were actually consumed; apply the same fix to the analogous loop around the
other occurrence referenced in the comment (the block at the other occurrence
using the same symbols).

357-361: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Preserve the original clock acquisition errno.

If devm_clk_bulk_get_all() returns a negative errno such as -EPROBE_DEFER, the current code skips the error check and proceeds directly to the count comparison, incorrectly reporting "Missing clocks" instead of propagating the real error. This breaks deferred probing for late SCMI/CRU clock providers.

Add an explicit check for negative return values before the count comparison:

Suggested fix
 dev->num_clks = devm_clk_bulk_get_all(dev->dev, &dev->clks);
+if (dev->num_clks < 0)
+	return dev->num_clks;
+
 if (dev->num_clks < dev->variant->num_clks) {
 	dev_err(dev->dev, "Missing clocks, got %d instead of %d\n",
 		dev->num_clks, dev->variant->num_clks);
 	return -EINVAL;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@patch/kernel/archive/rockchip64-7.0/rk35xx-crypto-v3.patch` around lines 357
- 361, The code calls devm_clk_bulk_get_all() and immediately treats
dev->num_clks as a count; first check if the return value is negative and
propagate that errno instead of comparing counts—i.e. after calling
devm_clk_bulk_get_all(dev->dev, &dev->clks) inspect dev->num_clks for < 0 and
return that value (preserving -EPROBE_DEFER etc.); only then compare
dev->num_clks against dev->variant->num_clks and use dev_err for the "Missing
clocks" message when the count is insufficient.
patch/kernel/archive/rockchip64-7.1/rk35xx-crypto-v3.patch (2)

1585-1590: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Guard the ahash path against an empty device list.

get_rk2_crypto() can return NULL during teardown/error paths. Dereferencing dev->engine here would Oops the kernel; the skcipher path already handles the same case with -ENODEV.

Suggested fix
 	dev = get_rk2_crypto();
+	if (!dev)
+		return -ENODEV;
 
 	rctx->dev = dev;
 	engine = dev->engine;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@patch/kernel/archive/rockchip64-7.1/rk35xx-crypto-v3.patch` around lines 1585
- 1590, The ahash path must guard against get_rk2_crypto() returning NULL: call
get_rk2_crypto(), check if dev is NULL and return -ENODEV (matching the skcipher
path) before assigning rctx->dev or dereferencing dev->engine; only set
rctx->dev and read engine when dev is non-NULL, then call
crypto_transfer_hash_request_to_engine(engine, req).

357-362: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Propagate devm_clk_bulk_get_all() errors instead of collapsing them to -EINVAL.

The devm_clk_bulk_get_all() function returns negative errno codes on error, including -EPROBE_DEFER when clock providers are not yet available. The current code's if (dev->num_clks < dev->variant->num_clks) check does not guard against negative returns, so -EPROBE_DEFER (a negative value) passes the condition as true, causing return -EINVAL to suppress the error and convert a recoverable deferred probe into a permanent failure.

Suggested fix
 	dev->num_clks = devm_clk_bulk_get_all(dev->dev, &dev->clks);
+	if (dev->num_clks < 0)
+		return dev->num_clks;
+
 	if (dev->num_clks < dev->variant->num_clks) {
 		dev_err(dev->dev, "Missing clocks, got %d instead of %d\n",
 			dev->num_clks, dev->variant->num_clks);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@patch/kernel/archive/rockchip64-7.1/rk35xx-crypto-v3.patch` around lines 357
- 362, The code calls devm_clk_bulk_get_all() and compares dev->num_clks against
dev->variant->num_clks but fails to handle negative error returns (e.g.
-EPROBE_DEFER), collapsing all errors to -EINVAL; change the logic in the block
around devm_clk_bulk_get_all(), check the raw return value (store it in a
variable like ret), if ret < 0 return ret to propagate errors (or specifically
return -EPROBE_DEFER when seen), otherwise compare dev->num_clks to
dev->variant->num_clks and only return -EINVAL when the count is legitimately
too small; references: devm_clk_bulk_get_all, dev->num_clks,
dev->variant->num_clks, and the existing return -EINVAL.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@patch/kernel/archive/rockchip64-6.18/rk35xx-crypto-v3.patch`:
- Around line 5-27: The patch header contains a duplicated changelog block
describing changes to
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml,
drivers/crypto/Makefile and rk2_crypto.h; remove the repeated copy and keep a
single consolidated changelog paragraph that lists the three items once (retain
the corrected clock-names, reg size, root Makefile hook addition, and the
rk2_crypto.h additions like dbgfs_info, `#include` <linux/reset.h>, and the
fallback_req ordering comment). Ensure only one instance of that block remains
and that its text preserves all unique details from both copies.

In `@patch/kernel/archive/rockchip64-7.1/rk35xx-crypto-v3.patch`:
- Around line 1020-1027: crypto_engine_start(rkc->engine) is called without
checking its return value; capture its return (e.g., err =
crypto_engine_start(rkc->engine)), and if non-zero handle the failure by
cleaning up the allocated engine and jumping to the existing err_dma error path
so probe fails instead of continuing. Specifically, after
crypto_engine_alloc_init and before init_completion, check the return of
crypto_engine_start(rkc->engine); on error free/stop the engine via the same
cleanup used for rkc->engine (e.g., call the engine cleanup routine used
elsewhere in this file to release rkc->engine) and goto err_dma.

---

Outside diff comments:
In `@patch/kernel/archive/rockchip64-7.0/rk35xx-crypto-v3.patch`:
- Around line 1585-1589: The hash path dereferences dev->engine after calling
get_rk2_crypto() without handling a NULL return; mirror the skcipher path by
checking the return value of get_rk2_crypto() and returning -ENODEV (or
performing the same cleanup/exit logic used in the skcipher path) when dev is
NULL to avoid dereferencing during teardown (reference functions/variables:
get_rk2_crypto(), rctx, dev, engine, rk2_crypto_remove(), and the skcipher code
path which already performs this guard).
- Around line 1579-1583: The code calls rk2_ahash_need_fallback(req) before
checking for a zero-length message, which can dereference req->src when nbytes
== 0 and src is NULL; reorder the checks so you handle the empty-message fast
path first (if (!req->nbytes) return zero_message_process(req);) and only then
call rk2_ahash_need_fallback(req) and rk2_ahash_digest_fb(req) to avoid walking
the scatterlist for zero-length requests.
- Around line 2247-2251: The IV-roll code uses the full SG element length
(sgs->length) to compute offset which is wrong when the DMA step processed only
todo/min(len) bytes; update the logic in the decryption branch inside the IV
handling (the block referencing areq->iv, crypto_skcipher_ivsize(tfm),
rctx->mode & RK2_CRYPTO_DEC, offset, sgs and scatterwalk_map_and_copy) to
compute offset from the actual processed byte count (use the local
processed/todo variable or len_processed) instead of sgs->length so the
backup_iv is copied from the bytes that were actually consumed; apply the same
fix to the analogous loop around the other occurrence referenced in the comment
(the block at the other occurrence using the same symbols).
- Around line 357-361: The code calls devm_clk_bulk_get_all() and immediately
treats dev->num_clks as a count; first check if the return value is negative and
propagate that errno instead of comparing counts—i.e. after calling
devm_clk_bulk_get_all(dev->dev, &dev->clks) inspect dev->num_clks for < 0 and
return that value (preserving -EPROBE_DEFER etc.); only then compare
dev->num_clks against dev->variant->num_clks and use dev_err for the "Missing
clocks" message when the count is insufficient.

In `@patch/kernel/archive/rockchip64-7.1/rk35xx-crypto-v3.patch`:
- Around line 1585-1590: The ahash path must guard against get_rk2_crypto()
returning NULL: call get_rk2_crypto(), check if dev is NULL and return -ENODEV
(matching the skcipher path) before assigning rctx->dev or dereferencing
dev->engine; only set rctx->dev and read engine when dev is non-NULL, then call
crypto_transfer_hash_request_to_engine(engine, req).
- Around line 357-362: The code calls devm_clk_bulk_get_all() and compares
dev->num_clks against dev->variant->num_clks but fails to handle negative error
returns (e.g. -EPROBE_DEFER), collapsing all errors to -EINVAL; change the logic
in the block around devm_clk_bulk_get_all(), check the raw return value (store
it in a variable like ret), if ret < 0 return ret to propagate errors (or
specifically return -EPROBE_DEFER when seen), otherwise compare dev->num_clks to
dev->variant->num_clks and only return -EINVAL when the count is legitimately
too small; references: devm_clk_bulk_get_all, dev->num_clks,
dev->variant->num_clks, and the existing return -EINVAL.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3d6fa89a-1998-430f-82f6-5d97db4ff876

📥 Commits

Reviewing files that changed from the base of the PR and between 38c583f and a99f5f8.

📒 Files selected for processing (3)
  • patch/kernel/archive/rockchip64-6.18/rk35xx-crypto-v3.patch
  • patch/kernel/archive/rockchip64-7.0/rk35xx-crypto-v3.patch
  • patch/kernel/archive/rockchip64-7.1/rk35xx-crypto-v3.patch

Comment on lines +5 to +27
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml
Clock names corrected. Original had "a" and "h" as clock-names items. v3 corrects them to "core", "aclk", "hclk" matching the actual clock signal names in the hardware and passing make dt_binding_check.
YAML example reg size fixed. Original example said 0x4000 (16KB). v3 corrects to 0x2000 (8KB) to match both DTS nodes and the actual hardware register map.

Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
---
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml | 65 ++++++++++
1 file changed, 65 insertions(+)
drivers/crypto/Makefile
Root Makefile hook added. v3 adds obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP2) += rockchip/ to the root crypto Makefile. Without this, if CONFIG_CRYPTO_DEV_ROCKCHIP (the V1 driver) is disabled, the build system never descends into drivers/crypto/rockchip/ and the V2 driver silently doesn't build regardless of Kconfig selection.

rk2_crypto.h
dbgfs_info field added to struct rockchip_ip. Original was missing it, causing register_debugfs to overwrite dbgfs_stats with the info file pointer. v3 adds struct dentry *dbgfs_info as the third debugfs member.
#include <linux/reset.h> added. Moved from rk2_crypto.c so that rk2_crypto_ahash.c and rk2_crypto_skcipher.c can call reset_control_assert/deassert directly in their DMA error recovery paths.
fallback_req ordering documented. Added // keep at the end comment on struct skcipher_request fallback_req in rk2_cipher_rctx. Same ordering maintained in rk2_ahash_rctx with struct ahash_request fallback_req as last member — required for the flexible array __ctx placement to work correctly.

Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml
Clock names corrected. Original had "a" and "h" as clock-names items. v3 corrects them to "core", "aclk", "hclk" matching the actual clock signal names in the hardware and passing make dt_binding_check.
YAML example reg size fixed. Original example said 0x4000 (16KB). v3 corrects to 0x2000 (8KB) to match both DTS nodes and the actual hardware register map.

drivers/crypto/Makefile
Root Makefile hook added. v3 adds obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP2) += rockchip/ to the root crypto Makefile. Without this, if CONFIG_CRYPTO_DEV_ROCKCHIP (the V1 driver) is disabled, the build system never descends into drivers/crypto/rockchip/ and the V2 driver silently doesn't build regardless of Kconfig selection.

rk2_crypto.h
dbgfs_info field added to struct rockchip_ip. Original was missing it, causing register_debugfs to overwrite dbgfs_stats with the info file pointer. v3 adds struct dentry *dbgfs_info as the third debugfs member.
#include <linux/reset.h> added. Moved from rk2_crypto.c so that rk2_crypto_ahash.c and rk2_crypto_skcipher.c can call reset_control_assert/deassert directly in their DMA error recovery paths.
fallback_req ordering documented. Added // keep at the end comment on struct skcipher_request fallback_req in rk2_cipher_rctx. Same ordering maintained in rk2_ahash_rctx with struct ahash_request fallback_req as last member — required for the flexible array __ctx placement to work correctly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Duplicate changelog block in patch header.

Lines 5-15 and lines 17-27 are byte-identical (Documentation/devicetree/bindings, drivers/crypto/Makefile, rk2_crypto.h sections appear twice). Looks like a copy/paste leftover; please collapse to a single block to keep the prose changelog readable.

✏️ Proposed fix
@@
 fallback_req ordering documented. Added // keep at the end comment on struct skcipher_request fallback_req in rk2_cipher_rctx. Same ordering maintained in rk2_ahash_rctx with struct ahash_request fallback_req as last member — required for the flexible array __ctx placement to work correctly.
 
-Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml
-Clock names corrected. Original had "a" and "h" as clock-names items. v3 corrects them to "core", "aclk", "hclk" matching the actual clock signal names in the hardware and passing make dt_binding_check.
-YAML example reg size fixed. Original example said 0x4000 (16KB). v3 corrects to 0x2000 (8KB) to match both DTS nodes and the actual hardware register map.
-
-drivers/crypto/Makefile
-Root Makefile hook added. v3 adds obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP2) += rockchip/ to the root crypto Makefile. Without this, if CONFIG_CRYPTO_DEV_ROCKCHIP (the V1 driver) is disabled, the build system never descends into drivers/crypto/rockchip/ and the V2 driver silently doesn't build regardless of Kconfig selection.
-
-rk2_crypto.h
-dbgfs_info field added to struct rockchip_ip. Original was missing it, causing register_debugfs to overwrite dbgfs_stats with the info file pointer. v3 adds struct dentry *dbgfs_info as the third debugfs member.
-#include <linux/reset.h> added. Moved from rk2_crypto.c so that rk2_crypto_ahash.c and rk2_crypto_skcipher.c can call reset_control_assert/deassert directly in their DMA error recovery paths.
-fallback_req ordering documented. Added // keep at the end comment on struct skcipher_request fallback_req in rk2_cipher_rctx. Same ordering maintained in rk2_ahash_rctx with struct ahash_request fallback_req as last member — required for the flexible array __ctx placement to work correctly.
-
 rk2_crypto_ahash.c
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml
Clock names corrected. Original had "a" and "h" as clock-names items. v3 corrects them to "core", "aclk", "hclk" matching the actual clock signal names in the hardware and passing make dt_binding_check.
YAML example reg size fixed. Original example said 0x4000 (16KB). v3 corrects to 0x2000 (8KB) to match both DTS nodes and the actual hardware register map.
Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
---
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml | 65 ++++++++++
1 file changed, 65 insertions(+)
drivers/crypto/Makefile
Root Makefile hook added. v3 adds obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP2) += rockchip/ to the root crypto Makefile. Without this, if CONFIG_CRYPTO_DEV_ROCKCHIP (the V1 driver) is disabled, the build system never descends into drivers/crypto/rockchip/ and the V2 driver silently doesn't build regardless of Kconfig selection.
rk2_crypto.h
dbgfs_info field added to struct rockchip_ip. Original was missing it, causing register_debugfs to overwrite dbgfs_stats with the info file pointer. v3 adds struct dentry *dbgfs_info as the third debugfs member.
#include <linux/reset.h> added. Moved from rk2_crypto.c so that rk2_crypto_ahash.c and rk2_crypto_skcipher.c can call reset_control_assert/deassert directly in their DMA error recovery paths.
fallback_req ordering documented. Added // keep at the end comment on struct skcipher_request fallback_req in rk2_cipher_rctx. Same ordering maintained in rk2_ahash_rctx with struct ahash_request fallback_req as last member — required for the flexible array __ctx placement to work correctly.
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml
Clock names corrected. Original had "a" and "h" as clock-names items. v3 corrects them to "core", "aclk", "hclk" matching the actual clock signal names in the hardware and passing make dt_binding_check.
YAML example reg size fixed. Original example said 0x4000 (16KB). v3 corrects to 0x2000 (8KB) to match both DTS nodes and the actual hardware register map.
drivers/crypto/Makefile
Root Makefile hook added. v3 adds obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP2) += rockchip/ to the root crypto Makefile. Without this, if CONFIG_CRYPTO_DEV_ROCKCHIP (the V1 driver) is disabled, the build system never descends into drivers/crypto/rockchip/ and the V2 driver silently doesn't build regardless of Kconfig selection.
rk2_crypto.h
dbgfs_info field added to struct rockchip_ip. Original was missing it, causing register_debugfs to overwrite dbgfs_stats with the info file pointer. v3 adds struct dentry *dbgfs_info as the third debugfs member.
#include <linux/reset.h> added. Moved from rk2_crypto.c so that rk2_crypto_ahash.c and rk2_crypto_skcipher.c can call reset_control_assert/deassert directly in their DMA error recovery paths.
fallback_req ordering documented. Added // keep at the end comment on struct skcipher_request fallback_req in rk2_cipher_rctx. Same ordering maintained in rk2_ahash_rctx with struct ahash_request fallback_req as last member — required for the flexible array __ctx placement to work correctly.
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml
Clock names corrected. Original had "a" and "h" as clock-names items. v3 corrects them to "core", "aclk", "hclk" matching the actual clock signal names in the hardware and passing make dt_binding_check.
YAML example reg size fixed. Original example said 0x4000 (16KB). v3 corrects to 0x2000 (8KB) to match both DTS nodes and the actual hardware register map.
drivers/crypto/Makefile
Root Makefile hook added. v3 adds obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP2) += rockchip/ to the root crypto Makefile. Without this, if CONFIG_CRYPTO_DEV_ROCKCHIP (the V1 driver) is disabled, the build system never descends into drivers/crypto/rockchip/ and the V2 driver silently doesn't build regardless of Kconfig selection.
rk2_crypto.h
dbgfs_info field added to struct rockchip_ip. Original was missing it, causing register_debugfs to overwrite dbgfs_stats with the info file pointer. v3 adds struct dentry *dbgfs_info as the third debugfs member.
`#include` <linux/reset.h> added. Moved from rk2_crypto.c so that rk2_crypto_ahash.c and rk2_crypto_skcipher.c can call reset_control_assert/deassert directly in their DMA error recovery paths.
fallback_req ordering documented. Added // keep at the end comment on struct skcipher_request fallback_req in rk2_cipher_rctx. Same ordering maintained in rk2_ahash_rctx with struct ahash_request fallback_req as last member — required for the flexible array __ctx placement to work correctly.
rk2_crypto_ahash.c
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@patch/kernel/archive/rockchip64-6.18/rk35xx-crypto-v3.patch` around lines 5 -
27, The patch header contains a duplicated changelog block describing changes to
Documentation/devicetree/bindings/crypto/rockchip,rk3588-crypto.yaml,
drivers/crypto/Makefile and rk2_crypto.h; remove the repeated copy and keep a
single consolidated changelog paragraph that lists the three items once (retain
the corrected clock-names, reg size, root Makefile hook addition, and the
rk2_crypto.h additions like dbgfs_info, `#include` <linux/reset.h>, and the
fallback_req ordering comment). Ensure only one instance of that block remains
and that its text preserves all unique details from both copies.

Comment on lines +1020 to 1027
+ rkc->engine = crypto_engine_alloc_init(dev, true);
+ if (!rkc->engine) {
+ err = -ENOMEM;
+ goto err_dma;
+ }
+
+ rkc->engine = crypto_engine_alloc_init(&pdev->dev, true);
+ crypto_engine_start(rkc->engine);
+ init_completion(&rkc->complete);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

find . -name "rk35xx-crypto-v3.patch" -type f

Repository: armbian/build

Length of output: 241


🏁 Script executed:

cat -n ./patch/kernel/archive/rockchip64-7.1/rk35xx-crypto-v3.patch | sed -n '1015,1035p'

Repository: armbian/build

Length of output: 604


🌐 Web query:

crypto_engine_start linux kernel return value error handling

💡 Result:

The Linux kernel function crypto_engine_start(struct crypto_engine *engine) returns an int: 0 on success, or a negative errno code on failure [1][2]. The only explicit error condition in the source code is when the engine is already running or busy (engine->running || engine->busy), in which case it returns -EBUSY (-16) [1][2][3]. There are no other return paths shown in the implementation, so callers should check if the return value is 0; if negative, treat as failure, typically logging the errno or handling -EBUSY by retrying later. Official kernel documentation mentions starting the engine but does not detail return values or errors [4][5]. This behavior is consistent across mainline kernel sources [2].

Citations:


🏁 Script executed:

cat -n ./patch/kernel/archive/rockchip64-7.1/rk35xx-crypto-v3.patch | sed -n '980,1050p'

Repository: armbian/build

Length of output: 2263


🏁 Script executed:

cat -n ./patch/kernel/archive/rockchip64-7.1/rk35xx-crypto-v3.patch | grep -A 5 -B 5 "err_engine:"

Repository: armbian/build

Length of output: 484


Check the result of crypto_engine_start().

The engine is started without checking its return value. If crypto_engine_start() fails (e.g., returns -EBUSY), the probe continues and registers algorithms against a failed engine. This masks the error, causing the probe to succeed and deferring the failure to the first crypto request instead of failing cleanly at probe time.

Suggested fix
 	rkc->engine = crypto_engine_alloc_init(dev, true);
 	if (!rkc->engine) {
 		err = -ENOMEM;
 		goto err_dma;
 	}
 
-	crypto_engine_start(rkc->engine);
+	err = crypto_engine_start(rkc->engine);
+	if (err)
+		goto err_engine;
+
 	init_completion(&rkc->complete);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@patch/kernel/archive/rockchip64-7.1/rk35xx-crypto-v3.patch` around lines 1020
- 1027, crypto_engine_start(rkc->engine) is called without checking its return
value; capture its return (e.g., err = crypto_engine_start(rkc->engine)), and if
non-zero handle the failure by cleaning up the allocated engine and jumping to
the existing err_dma error path so probe fails instead of continuing.
Specifically, after crypto_engine_alloc_init and before init_completion, check
the return of crypto_engine_start(rkc->engine); on error free/stop the engine
via the same cleanup used for rkc->engine (e.g., call the engine cleanup routine
used elsewhere in this file to release rkc->engine) and goto err_dma.

@github-actions github-actions Bot added the Ready to merge Reviewed, tested and ready for merge label May 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ This PR has been reviewed and approved — all set for merge!

@github-actions github-actions Bot removed the Needs review Seeking for review label May 16, 2026

@igorpecovnik igorpecovnik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check / resolve AI comments.

@igorpecovnik igorpecovnik removed the Ready to merge Reviewed, tested and ready for merge label May 16, 2026
@EvilOlaf

Copy link
Copy Markdown
Member

I would not merge this before release because for once the v2 patch has proven to work or at least I am not aware of anything crypto related that has been reported problematic. And for the other on this v3 I guess nobody tested this yet. So I'd say merge right after release so testing happens more or less automatically in the upcoming development cycle.

@igorpecovnik igorpecovnik added 08 Milestone: Third quarter release and removed 05 Milestone: Second quarter release labels May 16, 2026
@Dawidro

Dawidro commented May 18, 2026

Copy link
Copy Markdown
Author

With all due respect, merging or maintaining a faulty driver is problematic. I previously flagged that there are critical issues with rk35xx-montjoie-crypto-v2-rk35xx.patch and provided a list of all the updates and fixes my patch introduces.
The most important bug in the current v2 patch is that it completely fails its asynchronous hash (ahash) self-tests during initialization. As soon as the kernel's cryptomgr runs the mandatory self-tests, all hardware hash-based algorithms immediately fail. Please see the specific errors for these hash types below:

alg: ahash: rk2-sha512 export() overran state buffer on test vector 0, cfg="import/export"
alg: ahash: rk2-sha256 export() overran state buffer on test vector 0, cfg="import/export"
alg: ahash: rk2-md5 export() overran state buffer on test vector 0, cfg="import/export"
alg: ahash: rk2-sm3 export() overran state buffer on test vector 0, cfg="import/export"
alg: ahash: rk2-sha384 export() overran state buffer on test vector 0, cfg="import/export"
alg: ahash: rk2-sha1 export() overran state buffer on test vector 0, cfg="import/export"

updated_driver_output.txt
original_rk2_crypto_patch_debug.txt

I provide two logs via pastebin for comparison: one for my updated driver (updated_driver_output) where all tests pass, and one for the original driver output (original_rk2_crypto_patch_debug) showing the failures. More information about Corentin Labbe's (Montjoie) original patch series can be found here:
https://patchew.org/linux/20231107155532.3747113-1-clabbe@baylibre.com/
Is my updated patch ready for the upstream mainline Linux kernel? Absolutely not yet (refer to the link above). Is my patch working correctly right now? Absolutely yes. I am still working on the driver to get it submitted to the mainline kernel, with about 95% of the work completed. To satisfy upstream kernel maintainers, I've had to rewrite most of the logic.
The way I see it, we have two viable options to handle the broken rk35xx-montjoie-crypto-v2-rk35xx.patch before the release:

  1. Remove the v2 patch entirely, rely on the software crypto engine for now, and wait until upstream maintainers accept the fully rewritten driver.
  2. Use my updated driver in the interim so that users actually have functioning hardware crypto acceleration. (I will submit a quick follow-up PR with the crypto_engine_start(rkc->engine) fix if needed).
    Leaving a driver in the release that silently fails its core self-tests on boot isn't ideal, which is why I recommend addressing this now rather than waiting for the next development cycle.

@rpardini

Copy link
Copy Markdown
Member

I am still working on the driver to get it submitted to the mainline kernel, with about 95% of the work completed. To satisfy upstream kernel maintainers, I've had to rewrite most of the logic.

I wouldn't mind mergeing WiP as long as it was submitted to the LKML -- can you share the lore link?

@Dawidro

Dawidro commented May 26, 2026

Copy link
Copy Markdown
Author

My apologies, I was bit busy last week but managed finalizing the patch. Patch series can be found at: https://github.com/Dawidro/linux/tree/rk3588-crypto It's ready for submission. I will let know about the progress in due course.

@EvilOlaf

Copy link
Copy Markdown
Member

open concerns from rabbit must be addressed or dismissed.
How's upstream submission process going?

@EvilOlaf EvilOlaf added the Can be closed? Ping developers on stalled issue / PR label Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

08 Milestone: Third quarter release Can be closed? Ping developers on stalled issue / PR Hardware Hardware related like kernel, U-Boot, ... Patches Patches related to kernel, U-Boot, ... size/large PR with 250 lines or more

Development

Successfully merging this pull request may close these issues.

4 participants