Skip to content

crypto: eip93: add SafeXcel EIP-93 crypto engine support - #21499

Closed
namiltd wants to merge 2 commits into
openwrt:mainfrom
namiltd:eip93
Closed

namiltd wants to merge 2 commits into
openwrt:mainfrom
namiltd:eip93

Conversation

@namiltd

@namiltd namiltd commented Jan 11, 2026

Copy link
Copy Markdown
Contributor

Drop the downstream MTK EIP93 driver (ramips) and the partial Airoha driver (airoha) in favour of the single, upstream-quality SafeXcel EIP-93 implementation that is already queued for Linux 6.15.

The new driver:

  • supports MT7621, EN7512, EN7581 and future Airoha SoCs
  • offers AES/DES/3DES (ECB/CBC/CTR) and AEAD with HMAC-MD5/SHA1/SHA256
  • auto-detects available algorithms via hardware capability registers
  • fixes several long-standing stability and locking bugs present in the downstream code

All OpenWrt boards that previously relied on the old modules now receive the same functionality through the unified crypto-hw-eip93.ko module.

@ptpt52

ptpt52 commented Jan 11, 2026

Copy link
Copy Markdown
Contributor

mark.

@abajk

abajk commented Jan 11, 2026

Copy link
Copy Markdown
Contributor

Duplicate of #20130.

@abajk

abajk commented Jan 11, 2026 •

Copy link
Copy Markdown
Contributor

The new driver has deadlocks and panics during unloading. It also doesn't support software fallback, which is necessary to avoid performance loss. In fact, it is also 25% slower. Not to mention a few failed self-tests.

I've sent two fixes upstream, but we need more work.

[1] https://patchwork.kernel.org/project/linux-crypto/patch/[email protected]/
[2] https://patchwork.kernel.org/project/linux-crypto/patch/[email protected]/

@namiltd

namiltd commented Jan 11, 2026

Copy link
Copy Markdown
Contributor Author

@abajk Thank you very much for the information. I've prepared this PR to resolve a driver conflict with the upcoming 6.18 kernel, which already has eip93 integrated. I'll take a look at your changes and the previous drivers and try to optimize the code.

@github-actions github-actions Bot added target/bcm27xx pull request/issue for bcm27xx target kernel pull request/issue with Linux kernel related changes core packages pull request/issue for core (in-tree) packages target/ramips pull request/issue for ramips target target/ipq40xx pull request/issue for ipq40xx target target/mediatek pull request/issue for mediatek target target/realtek pull request/issue for realtek target target/starfive pull request/issue for starfive target target/microchipsw pull request/issue for microchipsw target labels Jan 11, 2026
@namiltd
namiltd force-pushed the eip93 branch 3 times, most recently from c2f7dd9 to 1113361 Compare January 11, 2026 17:02
@abajk

abajk commented Jan 11, 2026 •

Copy link
Copy Markdown
Contributor

Some numbers.

DES/3DES:
image

AES:
image

Hash:
image

@abajk

abajk commented Jan 11, 2026

Copy link
Copy Markdown
Contributor

These data show that the new driver is slower. Additionally, fallback should also be active for DES, 3DES, and AES-RFC3686. Hashes are also a big problem, as they are always slower than software for blocks up to 8k. Performance is easiest to compare using tcrypt:

insmod tcrypt mode=502 sec=1
insmod tcrypt mode=501 sec=1
insmod tcrypt mode=500 sec=1
insmod tcrypt mode=400 sec=1

@namiltd

namiltd commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor Author

@abajk I've created a new commit that should impact the module's performance.

  • Introduces a Kconfig option CONFIG_CRYPTO_DEV_EIP93_SA_RECORD_PER_KEY (default=y) to map the SA record once per key instead of per request. This reduces DMA mapping overhead and improves performance for workloads with many requests using the same key.
  • Replaces kzalloc with kmem_cache_alloc for hash blocks to align with the existing kmem_cache infrastructure.
  • Updates the cipher and aead contexts to maintain separate encryption and decryption SA records and their DMA addresses, enabling the per-key mapping optimization.
  • Batches descriptor doorbell writes: instead of issuing a separate MMIO write for every descriptor, the driver now counts them and writes the accumulated count to EIP93_REG_PE_CD_COUNT once EIP93_BATCH_THRESHOLD (8) is reached. This halves the number of MMIO writes on large requests, yielding a small but measurable throughput gain on MMIO-bound workloads.
  • Improves data alignment when using cache and DMA.
  • Adds comprehensive error handling and cleanup of all new paths to prevent memory leaks.
  • Introduces more robust DMA direction handling and buffer mapping/unmapping logic.
  • Introduces retry limits and a timeout error when the hardware ring is overloaded.

Need benchmarks with old version for CONFIG_CRYPTO_DEV_EIP93_SA_RECORD_PER_KEY=y and CONFIG_CRYPTO_DEV_EIP93_SA_RECORD_PER_KEY=n (also with zeroed CONFIG_CRYPTO_DEV_EIP93_AES_128_SW_MAX_LEN and CONFIG_CRYPTO_DEV_EIP93_GENERIC_SW_MAX_LEN).
Unfortunately, I don't have a router with eip93, so I can't test it.

@namiltd
namiltd force-pushed the eip93 branch 3 times, most recently from 5694ea9 to 507f3ef Compare January 13, 2026 13:00
@Linaro1985

Linaro1985 commented Jan 19, 2026 •

Copy link
Copy Markdown
Contributor

First, test without the target/linux/generic/hack-6.12/927-crypto-eip93-per-key-sa-mapping-and-dma-enhancements.patch file (delete this file).

dmesg_alg.txt
tcrypt_test.txt

P.S. hwrng is not supported on MT7621.

@namiltd
namiltd marked this pull request as draft January 19, 2026 19:18
@namiltd
namiltd marked this pull request as ready for review January 19, 2026 19:43
@namiltd
namiltd marked this pull request as draft January 19, 2026 21:53
@namiltd
namiltd force-pushed the eip93 branch 2 times, most recently from 10794f0 to 9618fa6 Compare January 20, 2026 19:04
@namiltd

namiltd commented Jan 20, 2026

Copy link
Copy Markdown
Contributor Author

@Linaro1985 Try new version.

@Linaro1985

Linaro1985 commented Jan 21, 2026 •

Copy link
Copy Markdown
Contributor

@Linaro1985 Try new version.

Done. However, there is a kernel panic in the logs. Is there anything else I can do to help diagnose the issue?
syslog.txt
syslog_without_per-key_sa_mapping.txt

P.S. It looks like there are still endianness issues in the code: Airoha is big-endian, while the MT7621 is little-endian.

@Rondom

Rondom commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

P.S. It looks like there are still endianness issues in the code: Airoha is big-endian, while the MT7621 is little-endian.

Airoha is little-endian ARM. Most Econet MIPS SoCs are big-endian, but there is one generation of little-endian MIPS SoCs as well.

@Linaro1985

Linaro1985 commented Jan 21, 2026 •

Copy link
Copy Markdown
Contributor

Airoha is little-endian ARM. Most Econet MIPS SoCs are big-endian, but there is one generation of little-endian MIPS SoCs as well.

Indeed. Until now, I had assumed that testing was mainly done on the big-endian version of Airoha/Econet. @Ansuel mentioned possible endianness issues, which is why I brought it up.
#10042 (comment)
#10042 (comment)

@namiltd

namiltd commented Jan 21, 2026 •

Copy link
Copy Markdown
Contributor Author

I decided to add only the first two commits and include the rest of the code in subsequent PRs.
The additional code requires a complete overhaul, with testing at every stage of the changes.
Testing requires hardware I don't have.

@namiltd namiltd closed this Jan 21, 2026
@namiltd namiltd reopened this Jan 21, 2026
@namiltd
namiltd force-pushed the eip93 branch 3 times, most recently from 42a2427 to 155bef9 Compare January 21, 2026 17:43
@namiltd
namiltd marked this pull request as ready for review January 21, 2026 17:47
@namiltd
namiltd force-pushed the eip93 branch 2 times, most recently from c1f509e to a5f4988 Compare January 21, 2026 18:04
Comment thread target/linux/ramips/dts/mt7621.dtsi Resolved
Comment thread package/kernel/linux/modules/crypto.mk Resolved
@abajk

abajk commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

My main concerns are three issues:

  • failing HMAC self-tests,
  • some deadlock during drivers detach/attach. The old mt7621 driver didn't have this issue,
  • slow hash algorithms. I'm thinking about reducing their priority. This can be fixed later.

Drop the downstream MTK EIP93 driver (ramips) and the partial Airoha
driver (airoha) in favour of the single, upstream-quality SafeXcel
EIP-93 implementation that is already queued for Linux 6.15.

The new driver:
 - supports MT7621, EN7512, EN7581 and future Airoha SoCs
 - offers AES/DES/3DES (ECB/CBC/CTR) and AEAD with HMAC-MD5/SHA1/SHA256
 - auto-detects available algorithms via hardware capability registers
 - fixes several long-standing stability and locking bugs present in the
   downstream code

All OpenWrt boards that previously relied on the old modules now receive
the same functionality through the unified crypto-hw-eip93.ko module.

Signed-off-by: Mieczyslaw Nalewaj <[email protected]>
This commit adds pending and hack patches for the EIP-93 crypto driver
in OpenWrt.

The pending patches address critical issues:
 - 880-crypto-eip93-fix-kernel-panic-in-driver-detach.patch
   Fixes a kernel panic triggered during driver detachment,
   which was caused by incorrect algorithm unregistration.
 - 881-crypto-eip93-unregister-only-available-algorithm.patch
   Ensures only hardware-supported algorithms are unregistered,
   preventing panics on platforms where certain crypto options
   are not implemented in silicon.
 - 88-crypto-eip93-fix-sleep-inside-atomic.patch
   Avoid GFP_KERNEL and usleep_range() if the flag
   CRYPTO_TFM_REQ_MAY_SLEEP is absent

The hack patch:
 - 926-crypto-eip93-use-AES-fallback-for-small-requests.patch
   Implements a fallback to software AES for small data blocks,
   improving performance by bypassing hardware acceleration when
   software is faster.

Additionally, two new kernel configuration options are introduced:
 - CRYPTO_DEV_EIP93_GENERIC_SW_MAX_LEN and CRYPTO_DEV_EIP93_AES_128_SW_MAX_LEN,
   allowing fine control over when software fallback is used for generic
   and AES-128 cipher requests, respectively.

These changes increase stability, performance, and flexibility for systems
using the EIP-93 crypto engine.

Signed-off-by: Mieczyslaw Nalewaj <[email protected]>
@namiltd

namiltd commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Closed to avoid duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core packages pull request/issue for core (in-tree) packages kernel pull request/issue with Linux kernel related changes target/bcm27xx pull request/issue for bcm27xx target target/ipq40xx pull request/issue for ipq40xx target target/mediatek pull request/issue for mediatek target target/microchipsw pull request/issue for microchipsw target target/ramips pull request/issue for ramips target target/realtek pull request/issue for realtek target target/starfive pull request/issue for starfive target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants