Skip to content

ramips: add support for mtk eip93 crypto engine - #10042

Merged
openwrt-bot merged 1 commit into
openwrt:mainfrom
skbeh:mtk-eip93
Sep 12, 2023
Merged

openwrt-bot merged 1 commit into
openwrt:mainfrom
skbeh:mtk-eip93

Conversation

@skbeh

@skbeh skbeh commented Jun 12, 2022 •

Copy link
Copy Markdown
Contributor

Mediatek EIP93 Crypto engine is a crypto accelerator which
is available in the Mediatek MT7621 SoC.
Althrough it was submitted to upstream kernel, it is far away from being accepted by the upstream. To make it available in openwrt as soon as possible, I ported the package from immortalwrt with some adjustment to make it possible to be built with 5.10 kernel.

Thanks:
mtk-eip93
immortalwrt

@skbeh skbeh changed the title add support for mtk eip93 crypto engine mt7621: add support for mtk eip93 crypto engine Jun 12, 2022
@skbeh skbeh changed the title mt7621: add support for mtk eip93 crypto engine ramips: add support for mtk eip93 crypto engine Jun 12, 2022
@musashino205

musashino205 commented Jun 12, 2022 •

Copy link
Copy Markdown
Contributor

Please use your real email address for Signed-off-by line in the commit message instead of GitHub's address.

Guideline: https://openwrt.org/submitting-patches#submission_guidelines

@Ansuel Ansuel added the target/ramips pull request/issue for ramips target label Jun 12, 2022
Comment thread package/kernel/mtk-eip93/Makefile Resolved
@neheb

neheb commented Jun 12, 2022

Copy link
Copy Markdown
Contributor

I remember running this a long time ago with cryptsetup's benchmark. While there was a speedup with AES and such, it wasn't that dramatic. I also don't remember if openssl was faster. Should be slower for lower block sizes.

ping @cotequeiroz since he deals with this stuff.

@aiamadeus

Copy link
Copy Markdown
Contributor

No offense, but this looks like a copy of immortalwrt/immortalwrt@7fc2fd7 with author info stripped.

@skbeh

skbeh commented Jun 13, 2022 •

Copy link
Copy Markdown
Contributor Author

@AmadeusGhost I have not seen it before the notification therefore I reinvented the wheel🌚
Also please tell me if there is any good way to keep author information within Makefile.

@cotequeiroz

Copy link
Copy Markdown
Member

I remember running this a long time ago with cryptsetup's benchmark. While there was a speedup with AES and such, it wasn't that dramatic. I also don't remember if openssl was faster. Should be slower for lower block sizes.

ping @cotequeiroz since he deals with this stuff.

I've had some disappointing experiences with hw crypto, so my comments are probably discouraging. There are several drivers already included in openwrt, so I'm not going to be picky about adding another one. However, this driver does not appear to be ready for inclusion in the kernel. Just skimming through the code, I found some places needing changes. For example, the AES skcipher algos are registering themselves with CRYPTO_ALG_NEED_FALLBACK, which indicates that they need another driver to be used as a fallback for cases where this one cannot handle. Nowhere in the code there is a call to initialize a skcipher fallback driver, so that flag should not be there.

I would strongly suggest that the driver be tested with the kernel self-test, and also speed tested. A friend has a device that I could try to install the module to do speed tests, but it is used in production, so I probably won't be able to install an image there. I'll post the results if able.

Running the kernel self-tests

Openwrt disables the crypto self-tests to save space. To be able to run them, one must enable the self-tests in the kernel config: make kernel_menuconfig, under Cryptographic API, deselect Disable run-time self tests. It affects the crypto manager module. Even though there is a package for it, the crypto manager ends up being built into the kernel, so installing a custom image will probably be necessary.

The self-tests will run upon loading the tcrypt module: insmod tcrypt mode=<test>, where mode defaults to 0. The list of tests can be seen in crypto/tcrypt.c in the kernel. Note that the speed tests are also listed there, and run with the same command, but using different modes. Here's the list of supported self-tests for this driver:

  • mode=0 (default) run all self-tests
  • mode=3 DES self-tests
  • mode=4 3DES self-tests
  • mode=10 AES self-tests
  • mode=155 AES-128-SHA1 HMAC self-test
  • mode=181 DES-SHA1 HMAC self-test
  • mode=182 3DES-SHA1 HMAC self-test
  • mode=183 DES-SHA224 HMAC self-test
  • mode=184 3DES-SHA224 HMAC self-test
  • mode=185 DES-SHA256 HMAC self-test
  • mode=186 3DES-SHA256 HMAC self-test

Running the kernel speed tests

Speed testing can be done without the above change, by installing the kmod-crypto-test package, then running insmod tcrypt mode=<test> sec=<seconds>. I'll list some interesting ones to test. If you omit sec or run it with sec=0, it will do one operation and count CPU cycles instead. Sync tests will not use eip93, while async ones will--you may use the results of an async test (eip93) to compare the performance against the equivalent sync test without having to remove the eip93 module:

  • ´mode=200` sync AES speed test
  • mode=500 async AES speed test
  • mode=201 sync 3DES speed test
  • mode=501 async 3DES speed test
  • mode=204 sync DES speed test
  • mode=504 async DES speed test

At least on arm, using hw-crypto to perform AES on network packets is not worth it. There is a large latency to set up the hw crypto operation. For networking with MTU=1500, take a look at the speed of block size=1472. On mvebu, the CESA beats the arm-asm driver (regular arm, not the neon version), but not by much (128-bits AES: 23560 vs 26607 CPU cycles). Then the acks will kill most/all of the gain: for CESA, using 128-bit AES on a 1472B packet plus a 64B ack: 23560 + 9469 = 33029 CPU cycles; arm-asm: 26607 + 1355 = 27962 cycles, a 15% penalty.

I hope things on mips are different, and my expectations are just wrong.

@neheb

neheb commented Jun 13, 2022

Copy link
Copy Markdown
Contributor

@cotequeiroz IIRC the mvebu hardware stuff was created when the core clock was closer to 1.2ghz for the original WRT1900. It makes a little more sense there.

@cotequeiroz

Copy link
Copy Markdown
Member

It makes sense. With CBC pretty much out of the picture, and CESA not supporting CTR, I had 0 f1090000.crypto interrupts with over 40 days of uptime before running the tests above.

@skbeh

skbeh commented Jun 14, 2022

Copy link
Copy Markdown
Contributor Author

Here are the test logs.
test.log
speed.log

@cotequeiroz

Copy link
Copy Markdown
Member

Maybe you didn't enable openwrt cryptodev engine. Mine have 277000 in a day.

I was just illustrating how it was not being used in the kernel. I don't run or recommend running openssl or wolfssl with cryptodev or afalg, even if it works faster. Most user space programs are not aware of how openssl processes its requests--internal or using an engine. Cryptodev file descriptors must not be shared across processes, which happens when you call fork() after opening an openssl context. Openssh is known to fail with either engine because of this.


Thanks for the tests:

The speed tests indicate that it may speedup regular network encryption, which is good. The bad news is that the self tests showed one error that raised concern:

[  622.862190] alg: aead: ccm_base(ctr(aes-eip93),cbcmac(aes-generic)) decryption failed on test vector 7; expected_error=0, actual_error=-77, cfg="in-place"

77 is -EBADMSG for mips, indicating a message authentication failure.

The fact that it happened only in test vector 7 indicates it worked for vectors 0 through 6. 7 is the first vector without associated data--i.e. data not to be encrypted/decrypted, but that must be authenticated.

ccm(aes) is used in WPA. Since it passed most of the tests, a failure will not be easily detected during usage.

This should be investigated further. I would not trade reliability for speed. At the moment, this is a NAK for me.

@skbeh

skbeh commented Jun 15, 2022 •

Copy link
Copy Markdown
Contributor Author

I think it is relevant to https://github.com/vschagen/mtk-eip93/blob/ca08387bf8352652129019bb19e2423ab313d5cb/crypto/mtk-eip93/eip93-main.c#L165 .
I wonder if the problem is that the engine (on chip) can not handle the authentication of GCM (gash), according to https://forum.openwrt.org/t/mediatek-eip-93-crypto-driver-mt7621-finally-pushed-upstream-in-progress/111510 .
I think we can just fallback to software authentication in this situation.

@cotequeiroz

Copy link
Copy Markdown
Member

I would use an async crypto fallback for requests smaller than, say 512 bytes. I've done it with qce in torvalds/linux@ce163ba, although later with torvalds/linux@25b71d6, it was inadvertently? limited to XTS only.

After you do this, the self tests should pass, but beware that they will fall under the 512-byte threshold, so see if you can test it with other data.

@skbeh

skbeh commented Jun 21, 2022 •

Copy link
Copy Markdown
Contributor Author

I would use an async crypto fallback for requests smaller than, say 512 bytes. I've done it with qce in torvalds/linux@ce163ba, although later with torvalds/linux@25b71d6, it was inadvertently? limited to XTS only.

I applied similar changes in my stage tree. It works like a charm.
I will push the commit later.
There are the logs:
log.tar.gz

@jickding

jickding commented Jun 22, 2022 •

Copy link
Copy Markdown

please post your TEST method (test command or other)

this is my test log :
openssl speed -elapsed -evp aes-256-cbc -engine devcrypto

engine "devcrypto" set.
You have chosen to measure elapsed time instead of user CPU time.
Doing aes-256-cbc for 3s on 16 size blocks: 72548 aes-256-cbc's in 3.01s
Doing aes-256-cbc for 3s on 64 size blocks: 70679 aes-256-cbc's in 3.01s
Doing aes-256-cbc for 3s on 256 size blocks: 64339 aes-256-cbc's in 3.01s
Doing aes-256-cbc for 3s on 1024 size blocks: 47812 aes-256-cbc's in 3.01s
Doing aes-256-cbc for 3s on 8192 size blocks: 13709 aes-256-cbc's in 3.01s
Doing aes-256-cbc for 3s on 16384 size blocks: 7565 aes-256-cbc's in 3.01s
OpenSSL 1.1.1o 3 May 2022
built on: Mon Jun 20 15:07:21 2022 UTC
options:bn(64,32) rc4(char) des(long) aes(partial) blowfish(ptr)
compiler: mipsel-openwrt-linux-musl-gcc -fPIC -pthread -mabi=32 -Wa,--noexecstack -Wall -O3 -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -DPIC -fpic -ffunction-sections -fdata-sections -znow -zrelro -DOPENSSL_USE_NODELETE -DOPENSSL_PIC -DOPENSSL_BN_ASM_MONT -DSHA1_ASM -DSHA256_ASM -DAES_ASM -DNDEBUG -DOPENSSL_PREFER_CHACHA_OVER_GCM -DOPENSSL_SMALL_FOOTPRINT
The 'numbers' are in 1000s of bytes per second processed.
type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes 16384 bytes
aes-256-cbc 385.64k 1502.81k 5472.02k 16265.61k 37310.34k 41177.73k

@skbeh

skbeh commented Jun 22, 2022

Copy link
Copy Markdown
Contributor Author

insmod tcrypt mode=0 as mentioned above.

@jickding

Copy link
Copy Markdown

insmod tcrypt mode=0 as mentioned above.

i have tested . very great. EIP-93 work fine

@jickding jickding left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

building success and work fine at openwrt-22.03 branch

@skbeh

skbeh commented Jun 22, 2022

Copy link
Copy Markdown
Contributor Author

@cotequeiroz I implemented fallback in the driver. Therefore I saw a great speedup with small packets and the self tests passed.

@mgkiller7

Copy link
Copy Markdown

openssl speed -elapsed -evp aes-256-cbc -engine devcrypto

I did see the same test result as yours, but i note the CPU load is very high:
Tasks: 92 total, 2 running, 90 sleeping, 0 stopped, 0 zombie
%Cpu(s): 99.0 us, 1.0 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 488.2 total, 292.5 free, 63.8 used, 131.9 buff/cache
MiB Swap: 0.0 total, 0.0 free, 0.0 used. 395.7 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2431 root 20 0 4320 3416 3040 R 95.2 0.7 0:06.12 openssl
1 root 20 0 30856 7180 5396 S 1.0 1.4 0:37.29 systemd
2214 root 20 0 0 0 0 I 1.0 0.0 0:00.24 kworker/0+
2433 root 20 0 9300 2600 2216 R 1.0 0.5 0:00.14 top
2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd
3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp
4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp
8 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu+
9 root 20 0 0 0 0 S 0.0 0.0 0:02.37 ksoftirqd+
10 root 20 0 0 0 0 I 0.0 0.0 0:02.58 rcu_preem+
11 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration+
12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/0
13 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kdevtmpfs
14 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 netns
15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_tasks+
17 root 20 0 0 0 0 S 0.0 0.0 0:00.00 oom_reaper
18 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 writeback

Is it ok?

@skbeh

skbeh commented Jun 22, 2022

Copy link
Copy Markdown
Contributor Author

@mgkiller7

I did see the same test result as yours, but i note the CPU load is very high

It is the expected behaviour because there is a high overhead submitting data to the engine and getting it back.

@cotequeiroz

Copy link
Copy Markdown
Member

@cotequeiroz I implemented fallback in the driver. Therefore I saw a great speedup with small packets and the self tests passed.

Nice job! You've managed to get the best of both worlds with this:

Cipher block size generic eip-93 eip-93+fb fb/generic fb/pure
AES-128-CTR 16 1313 14915 1723.5 -24% 765%
AES-128-CTR 64 2576.5 12889 2648 -3% 387%
AES-128-CTR 256 10025.75 17183.5 12947.5 -23% 33%
AES-128-CTR 1024 36891.5 19410 20203.5 83% -4%
AES-128-CTR 1472 52833.75 24109.5 22868 131% 5%
AES-128-CTR 8192 292113.5 68983.5 68115 329% 1%
AES-192-CTR 16 942.5 13605.5 1843.5 -49% 638%
AES-192-CTR 64 4169 13128 3057 36% 329%
AES-192-CTR 256 10834.5 15618 10891.5 -1% 43%
AES-192-CTR 1024 42622 21249 21556.5 98% -1%
AES-192-CTR 1472 61164.75 24198.5 25188.5 143% -4%
AES-192-CTR 8192 344112.75 113832 111401.5 209% 2%
AES-256-CTR 16 1035 12765 1599.5 -35% 698%
AES-256-CTR 64 4906.75 13906 5165 -5% 169%
AES-256-CTR 256 12329 14868.5 18852 -35% -21%
AES-256-CTR 1024 48605 21865.5 21553.5 126% 1%
AES-256-CTR 1472 71290.5 25994.5 25996 174% 0%
AES-256-CTR 8192 390817 92178 88552 341% 4%

In the table above, I've averaged your test results, considering both encryption and decryption numbers (in counter-mode, they are the same operation).


TLDR: The following is just a nitpick. If you're happy with what you've got, leave it alone. If you want to tweak the results for extra efficiency, read on.

The mean absolute deviation of the block sizes <= 256 was quite large (34% of the avg for AES-256). Try to test this with sec=1, to get a better sample (you'll get thousands of operations in one second).

If these numbers are indeed consistent with what you get with sec=1, I would, perhaps, reduce the transition point from 512 to 256 bytes. AES-128 would suffer a little, while AES-256 will benefit. Considering that using eip-93 reduces CPU usage, I would opt for the smaller value. The good thing is that it can be configured. You can add it as a config option in the package, and people can always override it manually, if they don't use aes-256, for example. Before doing this, I strongly advise to gather better data.

I used this to get a table from the logs that I could just copy and paste to a spreadsheet:

sed -n -e '/ ctr(aes) /,+18{s/.*] .*.*(\([0-9]\{3\}\).* \([0-9]\+\) byte.*in \(.*\) cycles.*/AES-\1-CTR\t\2\t\3/;s/.* \(a\?sync\).*\(ctr(aes-\)/\1 \2/;p}'

Of course, using sec=1 will require some sed tweaking.

@Ansuel

Ansuel commented Sep 12, 2023 via email

Copy link
Copy Markdown
Member

@csharper2005

csharper2005 commented Sep 12, 2023 •

Copy link
Copy Markdown
Contributor

Question are we sure this is ok to backport to 23.05? (backport to 22.03 is too much)

Yeah. It would be nice to have this in 23.05 and even 22.03. Fix for the insufficient ikev2 performance. :)

@Ansuel

Ansuel commented Sep 12, 2023

Copy link
Copy Markdown
Member

I'm glad, this got merged 👍 I get your concerns and I would be OK with it not making the next release. But I won't be the biggest user of this new feature so you should wait for replies of others 😅

Let's think about the implications of backporting this now: If this commit were to cause issues, then what would be the implication? A fix could be as easy as reverting the commit in release, right? This feature could mostly break some (rarer) VPN's on just one target. But the tests all ran just fine. So it could be some devices where the acceleration chip is broken? If there are any issues with this feature, then I feel like we might not even catch it in master/snapshots. You could discuss this with other committers. But only if you feel like it.

We would wait a point release for the revert to be applied that is the main problem. It's ok for RC but if we don't catch any problem in RC stage then it will be problematic in the future

fengmushu pushed a commit to fengmushu/openwrt that referenced this pull request Nov 18, 2023
1. Fixes CPU and regulator boot problems
2. Enable CPUFREQ, I2C, RTC and THERMAL support
3. Disabled annoying debug logs, refresh kconfig
4. Fix compilation failure due to wrong kconfig

Fixes: openwrt#10042

Signed-off-by: AmadeusGhost <[email protected]>
@orangepizza

Copy link
Copy Markdown
Contributor

don't think libustream-mbedtls uses this engine even when included: (at least for gcm in tls) is there something more need to be done?

@neheb

neheb commented Jan 20, 2024

Copy link
Copy Markdown
Contributor

mbedtls does not support hardware offload

@Headcrabed

Headcrabed commented Jan 20, 2024 •

Copy link
Copy Markdown
Contributor

don't think libustream-mbedtls uses this engine even when included: (at least for gcm in tls) is there something more need to be done?

You need to remove luci-ssl and wpad-basic-mbedtls and libustream-openssl, then install luci-ssl-openssl, wpad-(basic)-openssl and libustream-openssl to switch to openssl-based implementation, and install libopenssl-devcrypto to enable hw crypto usage, don't forget to reboot your router after installing.
图片

@orangepizza

Copy link
Copy Markdown
Contributor

https://mbed-tls.readthedocs.io/en/latest/kb/development/hw_acc_guidelines/
looks like mbedtls have own extension to allow hw accel, but that looks massive can of worm

@Ansuel

Ansuel commented Oct 11, 2024 •

Copy link
Copy Markdown
Member

If anyone wants to waste some time... I'm working on upstreaming it but it's for a different SoC so the register are a bit different.

There is plenty of documentation around and I can help with some thing...

Code is here and currently RFC upstream
https://github.com/Ansuel/openwrt/tree/crypto-sync/target/linux/airoha/files/drivers/crypto/mtk-eip93

Would be good to check what is actually missing to make this core work on mips.... The main (and only) difference I notice were on the endian regs and ring configuration...

Would be interesting if anyone can try it on some ramips device and see if it works right away...

@neheb

neheb commented Oct 11, 2024

Copy link
Copy Markdown
Contributor

Should probably make a commit doing so. I tried and failed. It's not probing and dmesg shows nothing.

@Ansuel

Ansuel commented Oct 17, 2024

Copy link
Copy Markdown
Member

@neheb what do you mean not probing? No log at all? Not even an error?

@neheb

neheb commented Oct 17, 2024

Copy link
Copy Markdown
Contributor

Nope. I couldn’t replace the driver properly I guess.

@Ansuel

Ansuel commented Oct 21, 2024

Copy link
Copy Markdown
Member

@neheb what version di you use? Maybe I know the problem... In latest version I'm pushing upstream I dropped the mtk compatible so that needs to be changed... Can you try to use the airoha one or check the main file what are supported?

@neheb

neheb commented Oct 21, 2024

Copy link
Copy Markdown
Contributor
 20 static const struct of_device_id mtk_crypto_of_match[] = {
 19         { .compatible = "mediatek,mtk-eip93", },
 18         { .compatible = "airoha,mtk-eip93", },   
 17         {}
 16 };

Like I said, I messed something up.

@Linaro1985

Linaro1985 commented Nov 21, 2024 •

Copy link
Copy Markdown
Contributor

@Ansuel @neheb It works on MT7621 or not? I'm trying to get this running on OpenWrt 23.05 with some changes (corrected spinlock code for linux 5.15)
There is this line in kernel log: mtk-eip93 1e004000.crypto: EIP93:3:0:1,PE(0xfe007:0x41710041)
But any request to driver produces kernel crash. I try it on snapshot tomorrow.

@Ansuel

Ansuel commented Nov 21, 2024

Copy link
Copy Markdown
Member

What revision are you using? Also what is the kernel crash?
The log means that it's correctly loaded.

@Linaro1985

Linaro1985 commented Nov 21, 2024 •

Copy link
Copy Markdown
Contributor

@Ansuel this openwrt version https://github.com/Linaro1985/openwrt/commits/23.05.5_eip93

P.S. I'll try to provide the log tomorrow. I don't have that opportunity now. Thanks!

@garyttirn

garyttirn commented Nov 21, 2024 •

Copy link
Copy Markdown

I'm running this module on self-compiled 23.05.4 with this commit cherrypicked on D-Link DIR-860L B1
I also run snapshot r27796 on D-Link DIR-882 A1. I haven't tried on 23.05.5.

Both D-Links have MediaTek MT7621AT, no apparent issues for me.

@Linaro1985

Linaro1985 commented Nov 22, 2024 •

Copy link
Copy Markdown
Contributor

@Ansuel I ported v5 driver to openwrt-24.10. All crypto tests enabled in kernel. Crash log:

[   16.972701] alg: skcipher: skipping comparison tests for ebc(des-eip93) because ecb(des-generic) is unavailable
[   17.253516] alg: skcipher: skipping comparison tests for cbc(des-eip93) because cbc(des-generic) is unavailable
[   17.510447] alg: skcipher: skipping comparison tests for ecb(des3_ede-eip93) because ecb(des3_ede-generic) is unavailable
[   17.735101] alg: skcipher: skipping comparison tests for cbc(des3_ede-eip93) because cbc(des3_ede-generic) is unavailable
[   17.995257] alg: skcipher: skipping comparison tests for ecb(aes-eip93) because ecb(aes-generic) is unavailable
[   18.277100] alg: skcipher: skipping comparison tests for cbc(aes-eip93) because cbc(aes-generic) is unavailable
[   19.551503] alg: No test for authenc(hmac(md5),cbc(des)) (authenc(hmac(md5-eip93),cbc(des-eip93)))
[   19.677335] alg: aead: authenc(hmac(sha1-eip93),cbc(des-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   19.702591] alg: self-tests for authenc(hmac(sha1),cbc(des)) using authenc(hmac(sha1-eip93),cbc(des-eip93)) failed (rc=-2)
[   19.810022] alg: aead: authenc(hmac(sha224-eip93),cbc(des-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   19.857534] alg: self-tests for authenc(hmac(sha224),cbc(des)) using authenc(hmac(sha224-eip93),cbc(des-eip93)) failed (rc=-2)
[   19.965221] alg: aead: authenc(hmac(sha256-eip93),cbc(des-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   20.013449] alg: self-tests for authenc(hmac(sha256),cbc(des)) using authenc(hmac(sha256-eip93),cbc(des-eip93)) failed (rc=-2)
[   20.013857] alg: No test for authenc(hmac(md5),cbc(des3_ede)) (authenc(hmac(md5-eip93),cbc(des3_ede-eip93)))
[   20.163311] alg: aead: authenc(hmac(sha1-eip93),cbc(des3_ede-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   20.189361] alg: self-tests for authenc(hmac(sha1),cbc(des3_ede)) using authenc(hmac(sha1-eip93),cbc(des3_ede-eip93)) failed (rc=-2)
[   20.297144] alg: aead: authenc(hmac(sha224-eip93),cbc(des3_ede-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   20.347264] alg: self-tests for authenc(hmac(sha224),cbc(des3_ede)) using authenc(hmac(sha224-eip93),cbc(des3_ede-eip93)) failed (rc=-2)
[   20.455067] alg: aead: authenc(hmac(sha256-eip93),cbc(des3_ede-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   20.505882] alg: self-tests for authenc(hmac(sha256),cbc(des3_ede)) using authenc(hmac(sha256-eip93),cbc(des3_ede-eip93)) failed (rc=-2)
[   20.506291] alg: No test for authenc(hmac(md5),cbc(aes)) (authenc(hmac(md5-eip93), cbc(aes-eip93)))
[   20.656434] alg: aead: authenc(hmac(sha1-eip93),cbc(aes-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   20.681657] alg: self-tests for authenc(hmac(sha1),cbc(aes)) using authenc(hmac(sha1-eip93),cbc(aes-eip93)) failed (rc=-2)
[   20.682069] alg: No test for authenc(hmac(sha224),cbc(aes)) (authenc(hmac(sha224-eip93),cbc(aes-eip93)))
[   20.830131] alg: aead: authenc(hmac(sha256-eip93),cbc(aes-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   20.855684] alg: self-tests for authenc(hmac(sha256),cbc(aes)) using authenc(hmac(sha256-eip93),cbc(aes-eip93)) failed (rc=-2)
[   20.856082] alg: No test for authenc(hmac(md5),rfc3686(ctr(aes))) (authenc(hmac(md5-eip93),rfc3686(ctr(aes-eip93))))
[   20.900240] alg: No test for authenc(hmac(sha224),rfc3686(ctr(aes))) (authenc(hmac(sha224-eip93),rfc3686(ctr(aes-eip93))))
[   21.030070] Unhandled kernel unaligned access[#1]:
[   21.039639] CPU: 1 PID: 938 Comm: cryptomgr_test Tainted: G        W  O       6.6.60 #0
[   21.055569] $ 0   : 00000000 00000001 81d2f180 ff0ffff8
[   21.065992] $ 4   : 81d79180 00000000 00000000 00000100
[   21.076405] $ 8   : 12000000 00000000 00000020 000000c0
[   21.086816] $12   : 000000e0 00000002 c1059ed8 5be0cd19
[   21.097230] $16   : 83f79880 83e61500 81d79180 809fd1a4
[   21.107642] $20   : 81d79880 fefefefe 3a400fc3 6a09e667
[   21.118056] $24   : 1f83d9ab 9b05688c                  
[   21.128468] $28   : 83f6e000 83f6f8c0 c3d2e1f0 83debf48
[   21.138881] Hi    : 00000000
[   21.144601] Lo    : 00000002
[   21.150321] epc   : 83debf44 eip93_aead_handle_result+0xf50/0x177c [crypto_hw_eip93]
[   21.165768] ra    : 83debf48 eip93_aead_handle_result+0xf54/0x177c [crypto_hw_eip93]
[   21.181194] Status: 1100fc03	KERNEL EXL IE 
[   21.189525] Cause : c0800010 (ExcCode 04)
[   21.197495] BadVA : fefeff02
[   21.203215] PrId  : 0001992f (MIPS 1004Kc)
[   21.211357] Modules linked in: crypto_hw_eip93(+) sha1_generic seqiv sha3_generic sha512_generic sha256_generic drbg md5 hmac geniv des_generic libdes cmac authencesn authenc leds_gpio xhci_plat_hcd xhci_pci xhci_mtk_hcd xhci_hcd gpio_button_hotplug(O) usbcore nls_base usb_common mii crc32c_generic
[   21.264056] Process cryptomgr_test (pid: 938, threadinfo=3f672c25, task=db1a09ce, tls=00000000)
[   21.281384] Stack : 83f79880 809fd1a4 809a0cd8 00000000 83f6fa30 80a50000 81d79880 83e61500
[   21.298043]         83f79880 809fd1a4 81953810 3c6ef372 bb67ae85 6a09e667 c3d2e1f0 83dec4bc
[   21.314702]         00000000 00000000 01d79880 00000000 00000001 00000000 81d2f180 befa4fa4
[   21.331358]         00000000 67452301 efcdab89 98badcfe 10325476 67452301 efcdab89 98badcfe
[   21.348017]         10325476 c3d2e1f0 6a09e667 bb67ae85 3c6ef372 a54ff53a 510e527f 9b05688c
[   21.364676]         ...
[   21.369543] Call Trace:
[   21.374393] [<83debf44>] eip93_aead_handle_result+0xf50/0x177c [crypto_hw_eip93]
[   21.389148] 
[   21.392103] Code: ae220080  ae320084  0c071954 <8eb70004> 1440005d  7e438300  3c1e80c5  000310c0  8fc58fec 
[   21.411533] 
[   21.414549] ---[ end trace 0000000000000000 ]---
[   21.423752] Kernel panic - not syncing: Fatal exception
[   21.434161] Rebooting in 1 seconds..

Code is here and currently RFC upstream
https://github.com/Ansuel/openwrt/tree/crypto-sync/target/linux/airoha/files/drivers/crypto/mtk-eip93

Should I try this version? How can I help?

@Ansuel

Ansuel commented Nov 26, 2024 •

Copy link
Copy Markdown
Member

@Linaro1985 can you try v7?

Eventually we need to add some debug log to understand where is the unaligned error.

@Linaro1985

Linaro1985 commented Nov 27, 2024 •

Copy link
Copy Markdown
Contributor

@Ansuel I tried v7 version. No more crash, but there are still errors.

[   16.900745] alg: skcipher: skipping comparison tests for ebc(des-eip93) because ecb(des-generic) is unavailable
[   17.169879] alg: skcipher: skipping comparison tests for cbc(des-eip93) because cbc(des-generic) is unavailable
[   17.418344] alg: skcipher: skipping comparison tests for ecb(des3_ede-eip93) because ecb(des3_ede-generic) is unavailable
[   17.643089] alg: skcipher: skipping comparison tests for cbc(des3_ede-eip93) because cbc(des3_ede-generic) is unavailable
[   17.903059] alg: skcipher: skipping comparison tests for ecb(aes-eip93) because ecb(aes-generic) is unavailable
[   18.189087] alg: skcipher: skipping comparison tests for cbc(aes-eip93) because cbc(aes-generic) is unavailable
[   19.475082] alg: No test for authenc(hmac(md5),cbc(des)) (authenc(hmac(md5-eip93),cbc(des-eip93)))
[   19.600163] alg: aead: authenc(hmac(sha1-eip93),cbc(des-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   19.625388] alg: self-tests for authenc(hmac(sha1),cbc(des)) using authenc(hmac(sha1-eip93),cbc(des-eip93)) failed (rc=-2)
[   19.733205] alg: aead: authenc(hmac(sha224-eip93),cbc(des-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   19.780755] alg: self-tests for authenc(hmac(sha224),cbc(des)) using authenc(hmac(sha224-eip93),cbc(des-eip93)) failed (rc=-2)
[   19.889089] alg: aead: authenc(hmac(sha256-eip93),cbc(des-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   19.937301] alg: self-tests for authenc(hmac(sha256),cbc(des)) using authenc(hmac(sha256-eip93),cbc(des-eip93)) failed (rc=-2)
[   19.937698] alg: No test for authenc(hmac(md5),cbc(des3_ede)) (authenc(hmac(md5-eip93),cbc(des3_ede-eip93)))
[   20.087220] alg: aead: authenc(hmac(sha1-eip93),cbc(des3_ede-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   20.113285] alg: self-tests for authenc(hmac(sha1),cbc(des3_ede)) using authenc(hmac(sha1-eip93),cbc(des3_ede-eip93)) failed (rc=-2)
[   20.221389] alg: aead: authenc(hmac(sha224-eip93),cbc(des3_ede-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   20.271499] alg: self-tests for authenc(hmac(sha224),cbc(des3_ede)) using authenc(hmac(sha224-eip93),cbc(des3_ede-eip93)) failed (rc=-2)
[   20.379437] alg: aead: authenc(hmac(sha256-eip93),cbc(des3_ede-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   20.430240] alg: self-tests for authenc(hmac(sha256),cbc(des3_ede)) using authenc(hmac(sha256-eip93),cbc(des3_ede-eip93)) failed (rc=-2)
[   20.430658] alg: No test for authenc(hmac(md5),cbc(aes)) (authenc(hmac(md5-eip93), cbc(aes-eip93)))
[   20.580650] alg: aead: authenc(hmac(sha1-eip93),cbc(aes-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   20.605912] alg: self-tests for authenc(hmac(sha1),cbc(aes)) using authenc(hmac(sha1-eip93),cbc(aes-eip93)) failed (rc=-2)
[   20.606318] alg: No test for authenc(hmac(sha224),cbc(aes)) (authenc(hmac(sha224-eip93),cbc(aes-eip93)))
[   20.754788] alg: aead: authenc(hmac(sha256-eip93),cbc(aes-eip93)) setkey failed on test vector 0; expected_error=0, actual_error=-2, flags=0x1
[   20.780333] alg: self-tests for authenc(hmac(sha256),cbc(aes)) using authenc(hmac(sha256-eip93),cbc(aes-eip93)) failed (rc=-2)
[   20.780750] alg: No test for authenc(hmac(md5),rfc3686(ctr(aes))) (authenc(hmac(md5-eip93),rfc3686(ctr(aes-eip93))))
[   20.824877] alg: No test for authenc(hmac(sha224),rfc3686(ctr(aes))) (authenc(hmac(sha224-eip93),rfc3686(ctr(aes-eip93))))
[   25.531444] mtk-eip93 1e004000.crypto: EIP93:3:0:1,PE(0xfe007:0x41710041)

Installed crypto kernel modules:

root@OpenWrt:~# opkg list | grep kmod-crypto
kmod-crypto-acompress - 6.6.60-r1
kmod-crypto-aead - 6.6.60-r1
kmod-crypto-authenc - 6.6.60-r1
kmod-crypto-ccm - 6.6.60-r1
kmod-crypto-cmac - 6.6.60-r1
kmod-crypto-crc32c - 6.6.60-r1
kmod-crypto-ctr - 6.6.60-r1
kmod-crypto-des - 6.6.60-r1
kmod-crypto-gcm - 6.6.60-r1
kmod-crypto-geniv - 6.6.60-r1
kmod-crypto-gf128 - 6.6.60-r1
kmod-crypto-ghash - 6.6.60-r1
kmod-crypto-hash - 6.6.60-r1
kmod-crypto-hmac - 6.6.60-r1
kmod-crypto-hw-eip93 - 6.6.60-r1
kmod-crypto-manager - 6.6.60-r1
kmod-crypto-md5 - 6.6.60-r1
kmod-crypto-null - 6.6.60-r1
kmod-crypto-rng - 6.6.60-r1
kmod-crypto-seqiv - 6.6.60-r1
kmod-crypto-sha1 - 6.6.60-r1
kmod-crypto-sha256 - 6.6.60-r1
kmod-crypto-sha3 - 6.6.60-r1
kmod-crypto-sha512 - 6.6.60-r1

@Ansuel

Ansuel commented Dec 2, 2024

Copy link
Copy Markdown
Member

@Linaro1985 can you make changes to the code? There are 2-3 things where we swap bits maybe they are not endian dependent and needs to be always swapped...

@Linaro1985

Copy link
Copy Markdown
Contributor

@Ansuel no problem. What changes need to be made?

@Ansuel

Ansuel commented Dec 2, 2024

Copy link
Copy Markdown
Member

actually are you sure all the crypto module are installed? Can you post output of /proc/crypto ?

@Linaro1985

Copy link
Copy Markdown
Contributor

@Ansuel
proc_crypto.txt

@Ansuel

Ansuel commented Feb 9, 2025

Copy link
Copy Markdown
Member

btw the driver is now upstream... I think we should put some effort in making this work on mt7622...

the upstream version doesn't have the software fallback but that can be added with a downstream patch eventually.

@abajk

abajk commented Dec 31, 2025

Copy link
Copy Markdown
Contributor

@cotequeiroz I implemented fallback in the driver. Therefore I saw a great speedup with small packets and the self tests passed.

@skbeh Do you remember why you excluded AES (RFC3686) from the software fallback? The topic came up during the transition to the upstream driver. Benchmarks indicate that it should also use the fallback together with DES :)

@skbeh

skbeh commented Dec 31, 2025

Copy link
Copy Markdown
Contributor Author

@cotequeiroz I implemented fallback in the driver. Therefore I saw a great speedup with small packets and the self tests passed.

@skbeh Do you remember why you excluded AES (RFC3686) from the software fallback? The topic came up during the transition to the upstream driver. Benchmarks indicate that it should also use the fallback together with DES :)

@abajk Not really. The reason might be that I didn't test RFC3686, and I was not sure about whether it can be used with the same fallback.

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/ramips pull request/issue for ramips target

Projects

None yet

Development

Successfully merging this pull request may close these issues.