Hi,
Good that you could reproduce the cryptsetup issue.
The tee_crypt driver is only available in the linux-imx kernel and it was written by an NXP employee , it is not part of the mainline kernel.
Without being a kernel expert, I feel the fix for the driver is not correct. An application should not be able to crash the driver by using an unsupported parameter. Either it should be rejected, or the driver should handle the different parameters that can be used.
What if another application uses 128KB packets? I feel the driver should divide the work in smaller steps to handle any packet size or something similar.
RT-patch dmcrypt issue
When it comes to the dmcrypt issue we use this additional kernel config:
CONFIG_PREEMPT_RT=y
CONFIG_BLK_DEV_LOOP=y
CONFIG_DM_CRYPT=y
OP-TEE config should be the same as before.
I then use these two scripts.
dm-crypt-init.sh:
#!/bin/sh
# dm-crypt-init.sh
mkdir -p /data/crypt
KEYNAME=dm_trust_plainkey
KEY=$(keyctl add trusted $KEYNAME 'new 32' @s)
keyctl pipe $KEY > /data/$KEYNAME.blob
keyctl list @s
DEV=/dev/loop0
ALGO="capi:cbc-aes-tee-plain"
dd if=/dev/zero of=/data/crypt/encrypted.img bs=1M count=512 && losetup /dev/loop0 /data/crypt/encrypted.img
BLOCKS=$(blockdev --getsz /dev/loop0)
TABLE="0 $BLOCKS crypt $ALGO :32:trusted:$KEYNAME 0 $DEV 0 1 sector_size:512"
dmsetup -v create encrypted --table "$TABLE"
mkfs.ext4 /dev/mapper/encrypted
mkdir -p /data/mnt/encrypted
mount -t ext4 /dev/mapper/encrypted /data/mnt/encrypted
run-fio.sh
#!/bin/sh
# run-fio.sh
fio --filename=/data/mnt/encrypted/fio.bin --size=128MB --rw=rw --bs=8k --ioengine=sync --iodepth=1 --runtime=120 --numjobs=1 --time_based --group_reporting --name=throughput-test-job --eta-newline=1
Here is an example test run:
root@imx93:~# ./dm-crypt-init.sh
2 keys in keyring:
647505922: ----s-rv 0 0 user: invocation_id
160646651: --alswrv 0 0 trusted: dm_trust_plainkey
512+0 records in
512+0 records out
[ 31.367193] loop0: detected capacity change from 0 to 1048576
Name: encrypted
State: ACTIVE
Read Ahead: 256
Tables present: LIVE
Open count: 0
Event number: 0
Major, minor: 254, 1
Number of targets: 1
mke2fs 1.47.0 (5-Feb-2023)
Creating filesystem with 131072 4k blocks and 32768 inodes
Filesystem UUID: b18c61f8-6dfb-4407-bb71-b69f7bcd8a19
Superblock backups stored on blocks:
32768, 98304
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
[ 33.442700] EXT4-fs (dm-1): mounted filesystem b18c61f8-6dfb-4407-bb71-b69f7bcd8a19 r/w with ordered data mode. Quota mode: none.
root@imx93:~# ./run-fio.sh
throughput-test-job: (g=0): rw=rw, bs=(R) 8192B-8192B, (W) 8192B-8192B, (T) 8192B-8192B, ioengine=sync, iodepth=1
fio-3.36-117-gb2403
Starting 1 process
throughput-test-job: Laying out IO file (1 file / 128MiB)
Jobs: 1 (f=1): [M(1)][2.5%][r=14.1MiB/s,w=14.1MiB/s][r=1811,w=1810 IOPS][eta 01m:57s]
Jobs: 1 (f=1): [M(1)][3.3%][r=49.7MiB/s,w=51.2MiB/s][r=6359,w=6557 IOPS][eta 01m:56s]
Jobs: 1 (f=1): [M(1)][4.2%][r=71.8MiB/s,w=70.8MiB/s][r=9195,w=9064 IOPS][eta 01m:55s]
Jobs: 1 (f=1): [M(1)][5.0%][r=36.4MiB/s,w=36.1MiB/s][r=4658,w=4618 IOPS][eta 01m:54s]
Jobs: 1 (f=1): [M(1)][6.7%][r=21.1MiB/s,w=20.8MiB/s][r=2704,w=2658 IOPS][eta 01m:52s]
Jobs: 1 (f=1): [M(1)][7.5%][r=9262KiB/s,w=9190KiB/s][r=1157,w=1148 IOPS][eta 01m:51s]
Jobs: 1 (f=1): [M(1)][8.3%][r=58.4MiB/s,w=58.5MiB/s][r=7469,w=7487 IOPS][eta 01m:50s]
Jobs: 1 (f=1): [M(1)][9.2%][r=9.87MiB/s,w=9.79MiB/s][r=1263,w=1252 IOPS][eta 01m:49s]
Jobs: 1 (f=1): [M(1)][10.0%][r=6009KiB/s,w=6105KiB/s][r=751,w=763 IOPS][eta 01m:48s]
Jobs: 1 (f=1): [M(1)][10.8%][r=18.2MiB/s,w=18.9MiB/s][r=2328,w=2420 IOPS][eta 01m:47s]
Jobs: 1 (f=1): [M(1)][11.7%][r=2733KiB/s,w=3020KiB/s][r=341,w=377 IOPS][eta 01m:46s]
./run-fio.sh: line 3: 511 Segmentation fault (core dumped) fio --filename=/data/mnt/encrypted/fio.bin --size=128MB --rw=rw --bs=8k --ioengine=sync --iodepth=1 --runtime=120 --numjobs=1 --time_based --group_reporting --name=throughput-test-job --eta-newline=1
root@imx93:~# [ 106.152684] systemd[1]: sshd@1-10.2.2.130:22-10.2.2.128:59470.service: Deactivated successfully.
[ 106.172954] systemd[1]: session-c2.scope: Deactivated successfully.
[ 106.183417] systemd[1]: systemd-journald.service: Scheduled restart job, restart counter is at 1.
[ 106.200326] systemd[1]: Journal Audit Socket was skipped because of an unmet condition check (ConditionSecurity=audit).
[ 106.236436] systemd[1]: Starting Journal Service...
[ 106.263938] systemd-journald[534]: Collecting audit messages is disabled.
[ 106.273399] systemd-journald[534]: File /var/log/journal/3a5531c948cf48d58c1052782ba34b41/system.journal corrupted or uncleanly shut down, renaming and replacing.
[ 106.328301] systemd[1]: Started Journal Service.
This is when running from serial console, when running from SSH session I usually loose the SSH session. In this example I lost my separate SSH session, this is what systemd logs about. We have also seen other strange behavior from systemd. It all points to some kernel corruption. Sometimes the crash happens quickly and sometimes it takes longer.