Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: caam - Prevent crash on suspend with iMX8QM / iMX8ULP

Since the CAAM on these SoCs is managed by another ARM core, called the
SECO (Security Controller) on iMX8QM and Secure Enclave on iMX8ULP, which
also reserves access to register page 0 suspend operations cannot touch
this page.

This is similar to when running OPTEE, where OPTEE will reserve page 0.

Track this situation using a new state variable no_page0, reflecting if
page 0 is reserved elsewhere, either by other management cores in SoC or
by OPTEE.

Replace the optee_en check in suspend/resume with the new check.

optee_en cannot go away as it's needed elsewhere to gate OPTEE specific
situations.

Fixes the following splat at suspend:

Internal error: synchronous external abort: 0000000096000010 [#1] SMP
Hardware name: Freescale i.MX8QXP ACU6C (DT)
pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : readl+0x0/0x18
lr : rd_reg32+0x18/0x3c
sp : ffffffc08192ba20
x29: ffffffc08192ba20 x28: ffffff8025190000 x27: 0000000000000000
x26: ffffffc0808ae808 x25: ffffffc080922338 x24: ffffff8020e89090
x23: 0000000000000000 x22: ffffffc080922000 x21: ffffff8020e89010
x20: ffffffc080387ef8 x19: ffffff8020e89010 x18: 000000005d8000d5
x17: 0000000030f35963 x16: 000000008f785f3f x15: 000000003b8ef57c
x14: 00000000c418aef8 x13: 00000000f5fea526 x12: 0000000000000001
x11: 0000000000000002 x10: 0000000000000001 x9 : 0000000000000000
x8 : ffffff8025190870 x7 : ffffff8021726880 x6 : 0000000000000002
x5 : ffffff80217268f0 x4 : ffffff8021726880 x3 : ffffffc081200000
x2 : 0000000000000001 x1 : ffffff8020e89010 x0 : ffffffc081200004
Call trace:
readl+0x0/0x18
caam_ctrl_suspend+0x30/0xdc
dpm_run_callback.constprop.0+0x24/0x5c
device_suspend+0x170/0x2e8
dpm_suspend+0xa0/0x104
dpm_suspend_start+0x48/0x50
suspend_devices_and_enter+0x7c/0x45c
pm_suspend+0x148/0x160
state_store+0xb4/0xf8
kobj_attr_store+0x14/0x24
sysfs_kf_write+0x38/0x48
kernfs_fop_write_iter+0xb4/0x178
vfs_write+0x118/0x178
ksys_write+0x6c/0xd0
__arm64_sys_write+0x14/0x1c
invoke_syscall.constprop.0+0x64/0xb0
do_el0_svc+0x90/0xb0
el0_svc+0x18/0x44
el0t_64_sync_handler+0x88/0x124
el0t_64_sync+0x150/0x154
Code: 88dffc21 88dffc21 5ac00800 d65f03c0 (b9400000)

Fixes: d2835701d93c ("crypto: caam - i.MX8ULP donot have CAAM page0 access")
Cc: stable@kernel.org # v6.10+
Signed-off-by: John Ernberg <john.ernberg@actia.se>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

John Ernberg and committed by
Herbert Xu
5ffc47fe d2b23a8d

+4 -2
+3 -2
drivers/crypto/caam/ctrl.c
··· 831 831 { 832 832 const struct caam_drv_private *ctrlpriv = dev_get_drvdata(dev); 833 833 834 - if (ctrlpriv->caam_off_during_pm && !ctrlpriv->optee_en) 834 + if (ctrlpriv->caam_off_during_pm && !ctrlpriv->no_page0) 835 835 caam_state_save(dev); 836 836 837 837 return 0; ··· 842 842 struct caam_drv_private *ctrlpriv = dev_get_drvdata(dev); 843 843 int ret = 0; 844 844 845 - if (ctrlpriv->caam_off_during_pm && !ctrlpriv->optee_en) { 845 + if (ctrlpriv->caam_off_during_pm && !ctrlpriv->no_page0) { 846 846 caam_state_restore(dev); 847 847 848 848 /* HW and rng will be reset so deinstantiation can be removed */ ··· 908 908 909 909 imx_soc_data = imx_soc_match->data; 910 910 reg_access = reg_access && imx_soc_data->page0_access; 911 + ctrlpriv->no_page0 = !reg_access; 911 912 /* 912 913 * CAAM clocks cannot be controlled from kernel. 913 914 */
+1
drivers/crypto/caam/intern.h
··· 115 115 u8 blob_present; /* Nonzero if BLOB support present in device */ 116 116 u8 mc_en; /* Nonzero if MC f/w is active */ 117 117 u8 optee_en; /* Nonzero if OP-TEE f/w is active */ 118 + u8 no_page0; /* Nonzero if register page 0 is not controlled by Linux */ 118 119 bool pr_support; /* RNG prediction resistance available */ 119 120 int secvio_irq; /* Security violation interrupt number */ 120 121 int virt_en; /* Virtualization enabled in CAAM */