CAAM refcount warnings
Hi all,
I see the following warnings when booting net-next/main with U-Boot 2022.07 on a LS1046ARDB:
[ 2.724435] alg: No test for echainiv(authenc(hmac(sha512),cbc(des))) (echainiv-authenc-hmac-sha512-cbc-des-caam-qi) [ 2.724507] alg: No test for echainiv(authenc(hmac(sha384),cbc(des))) (echainiv-authenc-hmac-sha384-cbc-des-caam-qi) [ 2.730102] alg: No test for echainiv(authenc(hmac(sha256),cbc(des))) (echainiv-authenc-hmac-sha256-cbc-des-caam-qi) [ 2.730189] alg: No test for echainiv(authenc(hmac(sha224),cbc(des))) (echainiv-authenc-hmac-sha224-cbc-des-caam-qi) [ 2.730314] alg: No test for echainiv(authenc(hmac(sha1),cbc(des))) (echainiv-authenc-hmac-sha1-cbc-des-caam-qi) [ 2.730369] alg: No test for echainiv(authenc(hmac(md5),cbc(des))) (echainiv-authenc-hmac-md5-cbc-des-caam-qi) [ 2.730456] alg: No test for authenc(hmac(md5),cbc(des)) (authenc-hmac-md5-cbc-des-caam-qi) [ 2.730475] alg: No test for echainiv(authenc(hmac(sha512),cbc(des3_ede))) (echainiv-authenc-hmac-sha512-cbc-des3_ede-caam-qi) [ 2.730589] alg: No test for echainiv(authenc(hmac(sha384),cbc(des3_ede))) (echainiv-authenc-hmac-sha384-cbc-des3_ede-caam-qi) [ 2.730731] alg: No test for echainiv(authenc(hmac(sha256),cbc(des3_ede))) (echainiv-authenc-hmac-sha256-cbc-des3_ede-caam-qi) [ 2.731078] alg: No test for echainiv(authenc(hmac(sha224),cbc(des3_ede))) (echainiv-authenc-hmac-sha224-cbc-des3_ede-caam-qi) [ 2.731342] ------------[ cut here ]------------ [ 2.731344] refcount_t: decrement hit 0; leaking memory. [ 2.731378] WARNING: CPU: 1 PID: 127 at lib/refcount.c:31 refcount_warn_saturate (lib/refcount.c:31 (discriminator 1)) [ 2.731394] Modules linked in: [ 2.731400] CPU: 1 UID: 0 PID: 127 Comm: cryptomgr_test Not tainted 6.14.0-seco+ #162 NONE [ 2.731405] Hardware name: LS1046A RDB Board (DT) [ 2.731407] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 2.731411] pc : refcount_warn_saturate (lib/refcount.c:31 (discriminator 1)) [ 2.731417] lr : refcount_warn_saturate (lib/refcount.c:31 (discriminator 1)) [ 2.731421] sp : ffffffc08000bd10 [ 2.731423] x29: ffffffc08000bd10 x28: ffffff8b7a7a5380 x27: ffffffc08000beb8 [ 2.731430] x26: 0000000000000005 x25: ffffff8b7a7a4240 x24: 0000000000000000 [ 2.731438] x23: 00000000000031c0 x22: ffffffc08207e208 x21: ffffff8800ef3530 [ 2.731444] x20: ffffffc082ea53c0 x19: ffffff88017fc680 x18: 0000000000000000 [ 2.731450] x17: ffffffcaf8e84000 x16: ffffffc080008000 x15: 04040b1e4d004284 [ 2.731456] x14: ffffff880213c280 x13: 0a2e79726f6d656d x12: 20676e696b61656c [ 2.731462] x11: 203b302074696820 x10: ffffffc081dbdef8 x9 : ffffffc081d91ef8 [ 2.731469] x8 : ffffffc08000ba08 x7 : ffffffc081d91ef8 x6 : 00000000fffff7ff [ 2.731475] x5 : 000000000000015f x4 : 0000000000000000 x3 : 0000000000000000 [ 2.731481] x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffffff8802143180 [ 2.731487] Call trace: [ 2.731489] refcount_warn_saturate (lib/refcount.c:31 (discriminator 1)) (P) [ 2.731496] caam_rsp_fq_dqrr_cb (include/linux/refcount.h:336 include/linux/refcount.h:351 drivers/crypto/caam/qi.c:593) [ 2.731502] qman_p_poll_dqrr (drivers/soc/fsl/qbman/qman.c:1652 drivers/soc/fsl/qbman/qman.c:1759) [ 2.731510] caam_qi_poll (drivers/crypto/caam/qi.c:491) [ 2.731514] __napi_poll (net/core/dev.c:7328) [ 2.731520] net_rx_action (net/core/dev.c:7394 net/core/dev.c:7514) [ 2.731524] handle_softirqs (arch/arm64/include/asm/jump_label.h:36 include/trace/events/irq.h:142 kernel/softirq.c:562) [ 2.731530] __do_softirq (kernel/softirq.c:596) [ 2.731533] ____do_softirq (arch/arm64/kernel/irq.c:82) [ 2.731538] call_on_irq_stack (arch/arm64/kernel/entry.S:897) [ 2.731542] do_softirq_own_stack (arch/arm64/kernel/irq.c:87) [ 2.731547] __irq_exit_rcu (kernel/softirq.c:442 kernel/softirq.c:662) [ 2.731550] irq_exit_rcu (kernel/softirq.c:681) [ 2.731554] el1_interrupt (arch/arm64/kernel/entry-common.c:565 arch/arm64/kernel/entry-common.c:575) [ 2.731561] el1h_64_irq_handler (arch/arm64/kernel/entry-common.c:581) [ 2.731567] el1h_64_irq (arch/arm64/kernel/entry.S:596) [ 2.731570] qman_enqueue (drivers/soc/fsl/qbman/qman.c:2354) (P) [ 2.731576] caam_qi_enqueue (drivers/crypto/caam/qi.c:125) [ 2.731580] aead_encrypt (drivers/crypto/caam/caamalg.c:1515 drivers/crypto/caam/caamalg.c:1532) [ 2.731586] crypto_aead_encrypt (crypto/aead.c:91) [ 2.731593] test_aead_vec_cfg (crypto/testmgr.c:2151 (discriminator 1)) [ 2.731600] test_aead (crypto/testmgr.c:2262 crypto/testmgr.c:2691) [ 2.731604] alg_test_aead (crypto/testmgr.c:2739) [ 2.731610] alg_test (crypto/testmgr.c:5996) [ 2.731615] cryptomgr_test (crypto/algboss.c:181) [ 2.731620] kthread (kernel/kthread.c:464) [ 2.731626] ret_from_fork (arch/arm64/kernel/entry.S:863) [ 2.731630] ---[ end trace 0000000000000000 ]--- [ 2.731638] ------------[ cut here ]------------ [ 2.731639] refcount_t: saturated; leaking memory. [ 2.731649] WARNING: CPU: 1 PID: 127 at lib/refcount.c:22 refcount_warn_saturate (lib/refcount.c:22 (discriminator 1)) [ 2.731656] Modules linked in: [ 2.731660] CPU: 1 UID: 0 PID: 127 Comm: cryptomgr_test Tainted: G W 6.14.0-seco+ #162 NONE [ 2.731665] Tainted: [W]=WARN [ 2.731667] Hardware name: LS1046A RDB Board (DT) [ 2.731669] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 2.731672] pc : refcount_warn_saturate (lib/refcount.c:22 (discriminator 1)) [ 2.731677] lr : refcount_warn_saturate (lib/refcount.c:22 (discriminator 1)) [ 2.731682] sp : ffffffc08607b900 [ 2.731684] x29: ffffffc08607b900 x28: 0000000000000400 x27: ffffffc08607bb00 [ 2.731690] x26: ffffffc08068dc70 x25: ffffffc0812b20e0 x24: ffffffc08607ba50 [ 2.731696] x23: 0000000000000001 x22: 0000000000002710 x21: 0000000000000000 [ 2.731702] x20: ffffff8800e99410 x19: ffffff88017fc680 x18: 0000000000000000 [ 2.731708] x17: 637253657920616e x16: 204d6f6f20547473 x15: 04040b1e4d004284 [ 2.731714] x14: e8db9514e884c2ea x13: 0a2e79726f6d656d x12: 20676e696b61656c [ 2.731720] x11: 203b646574617275 x10: ffffffc081dbdef8 x9 : ffffffc081d91ef8 [ 2.731726] x8 : ffffffc08607b5f8 x7 : ffffffc081d91ef8 x6 : 00000000fffff7ff [ 2.731732] x5 : 0000000000000190 x4 : 0000000000000000 x3 : 0000000000000000 [ 2.731738] x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffffff8802143180 [ 2.731744] Call trace: [ 2.731745] refcount_warn_saturate (lib/refcount.c:22 (discriminator 1)) (P) [ 2.731751] caam_qi_enqueue (include/linux/refcount.h:192 include/linux/refcount.h:241 include/linux/refcount.h:258 drivers/crypto/caam/qi.c:127) [ 2.731755] aead_encrypt (drivers/crypto/caam/caamalg.c:1515 drivers/crypto/caam/caamalg.c:1532) [ 2.731761] crypto_aead_encrypt (crypto/aead.c:91) [ 2.731766] test_aead_vec_cfg (crypto/testmgr.c:2151 (discriminator 1)) [ 2.731771] test_aead (crypto/testmgr.c:2262 crypto/testmgr.c:2691) [ 2.731776] alg_test_aead (crypto/testmgr.c:2739) [ 2.731781] alg_test (crypto/testmgr.c:5996) [ 2.731786] cryptomgr_test (crypto/algboss.c:181) [ 2.731791] kthread (kernel/kthread.c:464) [ 2.731796] ret_from_fork (arch/arm64/kernel/entry.S:863) [ 2.731801] ---[ end trace 0000000000000000 ]--- [ 2.731913] alg: No test for echainiv(authenc(hmac(sha1),cbc(des3_ede))) (echainiv-authenc-hmac-sha1-cbc-des3_ede-caam-qi) [ 2.732339] alg: No test for authenc(hmac(md5),cbc(des3_ede)) (authenc-hmac-md5-cbc-des3_ede-caam-qi) [ 2.732389] alg: No test for echainiv(authenc(hmac(md5),cbc(des3_ede))) (echainiv-authenc-hmac-md5-cbc-des3_ede-caam-qi) [ 2.732491] alg: No test for echainiv(authenc(hmac(sha512),cbc(aes))) (echainiv-authenc-hmac-sha512-cbc-aes-caam-qi) [ 2.732768] alg: No test for echainiv(authenc(hmac(sha384),cbc(aes))) (echainiv-authenc-hmac-sha384-cbc-aes-caam-qi) [ 2.732977] alg: No test for authenc(hmac(sha384),cbc(aes)) (authenc-hmac-sha384-cbc-aes-caam-qi) [ 2.732999] alg: No test for echainiv(authenc(hmac(sha256),cbc(aes))) (echainiv-authenc-hmac-sha256-cbc-aes-caam-qi) [ 2.733141] alg: No test for echainiv(authenc(hmac(sha224),cbc(aes))) (echainiv-authenc-hmac-sha224-cbc-aes-caam-qi) [ 2.733261] alg: No test for authenc(hmac(sha224),cbc(aes)) (authenc-hmac-sha224-cbc-aes-caam-qi) [ 2.733316] alg: No test for echainiv(authenc(hmac(sha1),cbc(aes))) (echainiv-authenc-hmac-sha1-cbc-aes-caam-qi) [ 2.733448] alg: No test for echainiv(authenc(hmac(md5),cbc(aes))) (echainiv-authenc-hmac-md5-cbc-aes-caam-qi) [ 2.733550] alg: No test for authenc(hmac(md5),cbc(aes)) (authenc-hmac-md5-cbc-aes-caam-qi) [ 2.735042] alg: No test for stdrng (prng-caam) [ 2.747764] alg: No test for seqiv(authenc(hmac(sha512),rfc3686(ctr(aes)))) (seqiv-authenc-hmac-sha512-rfc3686-ctr-aes-caam) [ 2.770224] alg: No test for seqiv(authenc(hmac(sha384),rfc3686(ctr(aes)))) (seqiv-authenc-hmac-sha384-rfc3686-ctr-aes-caam) [ 2.770777] alg: No test for seqiv(authenc(hmac(sha256),rfc3686(ctr(aes)))) (seqiv-authenc-hmac-sha256-rfc3686-ctr-aes-caam) [ 2.770948] alg: No test for seqiv(authenc(hmac(sha224),rfc3686(ctr(aes)))) (seqiv-authenc-hmac-sha224-rfc3686-ctr-aes-caam) [ 2.771083] alg: No test for authenc(hmac(sha224),rfc3686(ctr(aes))) (authenc-hmac-sha224-rfc3686-ctr-aes-caam) [ 2.771148] alg: No test for seqiv(authenc(hmac(sha1),rfc3686(ctr(aes)))) (seqiv-authenc-hmac-sha1-rfc3686-ctr-aes-caam) [ 2.771282] alg: No test for seqiv(authenc(hmac(md5),rfc3686(ctr(aes)))) (seqiv-authenc-hmac-md5-rfc3686-ctr-aes-caam) [ 2.771380] alg: No test for authenc(hmac(md5),rfc3686(ctr(aes))) (authenc-hmac-md5-rfc3686-ctr-aes-caam) [ 2.771422] alg: No test for echainiv(authenc(hmac(sha512),cbc(des))) (echainiv-authenc-hmac-sha512-cbc-des-caam) [ 2.771587] alg: No test for echainiv(authenc(hmac(sha384),cbc(des))) (echainiv-authenc-hmac-sha384-cbc-des-caam) [ 2.776945] alg: No test for echainiv(authenc(hmac(sha256),cbc(des))) (echainiv-authenc-hmac-sha256-cbc-des-caam) [ 2.777103] alg: No test for echainiv(authenc(hmac(sha224),cbc(des))) (echainiv-authenc-hmac-sha224-cbc-des-caam) [ 2.777217] alg: No test for echainiv(authenc(hmac(sha1),cbc(des))) (echainiv-authenc-hmac-sha1-cbc-des-caam) [ 2.777382] alg: No test for echainiv(authenc(hmac(md5),cbc(des))) (echainiv-authenc-hmac-md5-cbc-des-caam) [ 2.777447] alg: No test for authenc(hmac(md5),cbc(des)) (authenc-hmac-md5-cbc-des-caam) [ 2.777498] alg: No test for echainiv(authenc(hmac(sha512),cbc(des3_ede))) (echainiv-authenc-hmac-sha512-cbc-des3_ede-caam) [ 2.777685] alg: No test for echainiv(authenc(hmac(sha384),cbc(des3_ede))) (echainiv-authenc-hmac-sha384-cbc-des3_ede-caam) [ 2.777933] alg: No test for echainiv(authenc(hmac(sha256),cbc(des3_ede))) (echainiv-authenc-hmac-sha256-cbc-des3_ede-caam) [ 2.778148] alg: No test for echainiv(authenc(hmac(sha224),cbc(des3_ede))) (echainiv-authenc-hmac-sha224-cbc-des3_ede-caam) [ 2.778281] alg: No test for echainiv(authenc(hmac(sha1),cbc(des3_ede))) (echainiv-authenc-hmac-sha1-cbc-des3_ede-caam) [ 2.778422] alg: No test for echainiv(authenc(hmac(md5),cbc(des3_ede))) (echainiv-authenc-hmac-md5-cbc-des3_ede-caam) [ 2.778502] alg: No test for authenc(hmac(md5),cbc(des3_ede)) (authenc-hmac-md5-cbc-des3_ede-caam) [ 2.778580] alg: No test for echainiv(authenc(hmac(sha512),cbc(aes))) (echainiv-authenc-hmac-sha512-cbc-aes-caam) [ 2.778717] alg: No test for echainiv(authenc(hmac(sha384),cbc(aes))) (echainiv-authenc-hmac-sha384-cbc-aes-caam) [ 2.778812] alg: No test for authenc(hmac(sha384),cbc(aes)) (authenc-hmac-sha384-cbc-aes-caam) [ 2.778887] alg: No test for echainiv(authenc(hmac(sha256),cbc(aes))) (echainiv-authenc-hmac-sha256-cbc-aes-caam) [ 2.779038] alg: No test for echainiv(authenc(hmac(sha224),cbc(aes))) (echainiv-authenc-hmac-sha224-cbc-aes-caam) [ 2.779135] alg: No test for authenc(hmac(sha224),cbc(aes)) (authenc-hmac-sha224-cbc-aes-caam) [ 2.779244] alg: No test for echainiv(authenc(hmac(sha1),cbc(aes))) (echainiv-authenc-hmac-sha1-cbc-aes-caam) [ 2.779314] alg: No test for echainiv(authenc(hmac(md5),cbc(aes))) (echainiv-authenc-hmac-md5-cbc-aes-caam) [ 2.779404] alg: No test for authenc(hmac(md5),cbc(aes)) (authenc-hmac-md5-cbc-aes-caam) [ 2.779474] alg: No test for authenc(hmac(sha512),ecb(cipher_null)) (authenc-hmac-sha512-ecb-cipher_null-caam) [ 2.779519] alg: No test for authenc(hmac(sha384),ecb(cipher_null)) (authenc-hmac-sha384-ecb-cipher_null-caam) [ 2.779555] alg: No test for authenc(hmac(sha256),ecb(cipher_null)) (authenc-hmac-sha256-ecb-cipher_null-caam) [ 2.779625] alg: No test for authenc(hmac(sha224),ecb(cipher_null)) (authenc-hmac-sha224-ecb-cipher_null-caam) [ 2.807182] cfg80211: Loading compiled-in X.509 certificates for regulatory database [ 3.002053] caam 1700000.crypto: -1073741824 frames from FQID 15 still pending in CAAM [ 3.020733] alg: sig: sign test failed: invalid output [ 3.753748] 00000000: 68 e4 b7 d5 2e 12 d4 9b ca a5 a7 fc 50 2f d2 f6 [ 3.760192] 00000010: 6b 01 58 1e b7 72 2c 0f 66 a4 c9 1e b9 49 21 a7 [ 3.766636] 00000020: 53 62 26 6d bb 69 62 a2 7e 3b 8d 80 6f 2d 21 9d [ 3.773079] 00000030: cd 6f 92 e5 a9 03 e4 b3 b0 fc e7 4f ec a7 23 5c [ 3.779522] 00000040: 1d dc 08 13 c3 2e 8b d9 fa ab e0 6f 2b a0 9d 2b [ 3.785965] 00000050: 32 47 d5 ad ec 65 5a ce b3 13 35 95 37 0e f1 b0 [ 3.792407] 00000060: c3 8e 22 0d c9 a2 b3 31 58 ea 74 18 18 d2 9f 7e [ 3.798848] 00000070: 04 fe 3b f1 5e 40 6c 39 3f 38 a2 71 58 fa da 1a [ 3.805291] 00000080: ed 02 70 7c 9e 72 93 a3 66 25 f2 35 e9 82 00 49 [ 3.811734] 00000090: 8e 09 b9 f0 52 76 b2 9e b4 06 b0 60 f2 15 a1 78 [ 3.818176] 000000a0: 74 3c 9b 87 17 f6 e8 ff ca fe 41 ed 73 c8 28 70 [ 3.824619] 000000b0: 33 cc a2 de d6 04 7a b5 85 81 a3 46 16 46 66 af [ 3.831060] 000000c0: 26 84 bc 9e 70 68 7c b3 68 44 73 4c c2 a4 70 45 [ 3.837503] 000000d0: a5 af a3 b3 9c cb b5 c8 bf 7d 8a 17 97 f6 33 0c [ 3.843944] 000000e0: 94 cc d3 fd ee e7 ba 8b dc 6f c7 3b 3b 67 14 ae [ 3.850387] 000000f0: 6a 00 33 90 df c5 f9 a2 6c b8 93 f7 cf 6b 0d 0d [ 3.856828] alg: sig: test 1 failed for pkcs1(rsa-caam,sha256): err -22 [ 3.863447] alg: self-tests for pkcs1(rsa,sha256) using pkcs1(rsa-caam,sha256) failed (rc=-22) [ 3.863451] ------------[ cut here ]------------ [ 3.876680] alg: self-tests for pkcs1(rsa,sha256) using pkcs1(rsa-caam,sha256) failed (rc=-22) [ 3.876705] WARNING: CPU: 3 PID: 319 at crypto/testmgr.c:6012 alg_test (crypto/testmgr.c:6012 (discriminator 1)) [ 3.892894] Modules linked in: [ 3.895946] CPU: 3 UID: 0 PID: 319 Comm: cryptomgr_test Tainted: G W 6.14.0-seco+ #162 NONE [ 3.905778] Tainted: [W]=WARN [ 3.908739] Hardware name: LS1046A RDB Board (DT) [ 3.913439] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 3.920401] pc : alg_test (crypto/testmgr.c:6012 (discriminator 1)) [ 3.924060] lr : alg_test (crypto/testmgr.c:6012 (discriminator 1)) [ 3.927720] sp : ffffffc086e2bd40 [ 3.931028] x29: ffffffc086e2bd40 x28: 0000000000000000 x27: 0000000000000000 [ 3.938168] x26: 00000000ffffffea x25: 00000000ffffffff x24: ffffffc082066470 [ 3.945307] x23: 0000000000000159 x22: 0000000000000807 x21: ffffff88010fe280 [ 3.952446] x20: ffffff88010fe200 x19: ffffffc081290df0 x18: 0000000000000000 [ 3.959584] x17: 35326168732c6d61 x16: 61632d6173722831 x15: 000000000000002d [ 3.966723] x14: 0000000000000000 x13: 00000000fffffffe x12: 65742d666c657320 [ 3.973862] x11: 656820747563205b x10: ffffffc081dc0df0 x9 : ffffffc081d91ef8 [ 3.981000] x8 : ffffffc086e2bb28 x7 : ffffffc081d91ef8 x6 : 00000000fffff7ff [ 3.988138] x5 : 00000000000001f6 x4 : 0000000000000000 x3 : 0000000000000000 [ 3.995276] x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffffff8800f6e300 [ 4.002414] Call trace: [ 4.004853] alg_test (crypto/testmgr.c:6012 (discriminator 1)) (P) [ 4.008513] cryptomgr_test (crypto/algboss.c:181) [ 4.012172] kthread (kernel/kthread.c:464) [ 4.015311] ret_from_fork (arch/arm64/kernel/entry.S:863) [ 4.018884] ---[ end trace 0000000000000000 ]---
I can retry with a newer U-Boot if you think it may affect things.
--Sean
Herbert Xu
maintainerPATCH 1/1 crypto: caam/qi - Fix drv_ctx refcount bug
Quoted 2 lines · Sean Anderson
[ 2.731344] refcount_t: decrement hit 0; leaking memory.
...
Quoted 9 lines
[ 2.731496] caam_rsp_fq_dqrr_cb (include/linux/refcount.h:336 include/linux/refcount.h:351 drivers/crypto/caam/qi.c:593) [ 2.731502] qman_p_poll_dqrr (drivers/soc/fsl/qbman/qman.c:1652 drivers/soc/fsl/qbman/qman.c:1759) [ 2.731510] caam_qi_poll (drivers/crypto/caam/qi.c:491) [ 2.731514] __napi_poll (net/core/dev.c:7328) [ 2.731520] net_rx_action (net/core/dev.c:7394 net/core/dev.c:7514) [ 2.731524] handle_softirqs (arch/arm64/include/asm/jump_label.h:36 include/trace/events/irq.h:142 kernel/softirq.c:562) [ 2.731530] __do_softirq (kernel/softirq.c:596) [ 2.731533] ____do_softirq (arch/arm64/kernel/irq.c:82) [ 2.731538] call_on_irq_stack (arch/arm64/kernel/entry.S:897)
Quoted 8 lines
[ 2.731542] do_softirq_own_stack (arch/arm64/kernel/irq.c:87) [ 2.731547] __irq_exit_rcu (kernel/softirq.c:442 kernel/softirq.c:662) [ 2.731550] irq_exit_rcu (kernel/softirq.c:681) [ 2.731554] el1_interrupt (arch/arm64/kernel/entry-common.c:565 arch/arm64/kernel/entry-common.c:575) [ 2.731561] el1h_64_irq_handler (arch/arm64/kernel/entry-common.c:581) [ 2.731567] el1h_64_irq (arch/arm64/kernel/entry.S:596) [ 2.731570] qman_enqueue (drivers/soc/fsl/qbman/qman.c:2354) (P) [ 2.731576] caam_qi_enqueue (drivers/crypto/caam/qi.c:125)
So caam_qi_enqueue hasn't had a chance to increment the refcount and the IRQ already came in to decrement it. Lesson is that you should always increment your refcount before you give it away.
---8<---
Ensure refcount is raised before request is enqueued since it could be dequeued before the call returns.
drivers/crypto/caam/qi.c +3 -3
@@ -122,12 +122,12 @@ int caam_qi_enqueue(struct device *qidev, struct caam_drv_req *req)qm_fd_addr_set64 (&fd, addr); do { + refcount_inc(&req->drv_ctx->refcnt); ret = qman_enqueue(req->drv_ctx->req_fq, &fd); - if (likely(!ret)) { - refcount_inc(&req->drv_ctx->refcnt); + if (likely(!ret)) return 0; - } + refcount_dec(&req->drv_ctx->refcnt); if (ret != -EBUSY) break; num_retries++;
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH] crypto: caam/qi - Fix drv_ctx refcount bug
Quoted 7 lines · Herbert Xu
Ensure refcount is raised before request is enqueued since it could be dequeued before the call returns.
Reported-by Sean Anderson <[email protected]>Cc <[email protected]>Fixes 11144416a755 ("crypto: caam/qi - optimize frame queue cleanup")Signed-off-by Herbert Xu <[email protected]>
Thanks!
Horia
Re: [PATCH] crypto: caam/qi - Fix drv_ctx refcount bug
In reply to Herbert XuQuoted 47 lines · Herbert Xu
Quoted 2 lines · Sean Anderson
[ 2.731344] refcount_t: decrement hit 0; leaking memory....
Quoted 9 lines
[ 2.731496] caam_rsp_fq_dqrr_cb (include/linux/refcount.h:336 include/linux/refcount.h:351 drivers/crypto/caam/qi.c:593) [ 2.731502] qman_p_poll_dqrr (drivers/soc/fsl/qbman/qman.c:1652 drivers/soc/fsl/qbman/qman.c:1759) [ 2.731510] caam_qi_poll (drivers/crypto/caam/qi.c:491) [ 2.731514] __napi_poll (net/core/dev.c:7328) [ 2.731520] net_rx_action (net/core/dev.c:7394 net/core/dev.c:7514) [ 2.731524] handle_softirqs (arch/arm64/include/asm/jump_label.h:36 include/trace/events/irq.h:142 kernel/softirq.c:562) [ 2.731530] __do_softirq (kernel/softirq.c:596) [ 2.731533] ____do_softirq (arch/arm64/kernel/irq.c:82) [ 2.731538] call_on_irq_stack (arch/arm64/kernel/entry.S:897)Quoted 8 lines
[ 2.731542] do_softirq_own_stack (arch/arm64/kernel/irq.c:87) [ 2.731547] __irq_exit_rcu (kernel/softirq.c:442 kernel/softirq.c:662) [ 2.731550] irq_exit_rcu (kernel/softirq.c:681) [ 2.731554] el1_interrupt (arch/arm64/kernel/entry-common.c:565 arch/arm64/kernel/entry-common.c:575) [ 2.731561] el1h_64_irq_handler (arch/arm64/kernel/entry-common.c:581) [ 2.731567] el1h_64_irq (arch/arm64/kernel/entry.S:596) [ 2.731570] qman_enqueue (drivers/soc/fsl/qbman/qman.c:2354) (P) [ 2.731576] caam_qi_enqueue (drivers/crypto/caam/qi.c:125)So
caam_qi_enqueuehasn't had a chance to increment the refcount and the IRQ already came in to decrement it. Lesson is that you should always increment your refcount before you give it away.---8<---
Ensure refcount is raised before request is enqueued since it could be dequeued before the call returns.Reported-by Sean Anderson <[email protected]>Cc <[email protected]>Fixes 11144416a755 ("crypto: caam/qi - optimize frame queue cleanup")Signed-off-by Herbert Xu <[email protected]>drivers/crypto/caam/qi.c +1
-0@@ -122,12 +122,12 @@ int caam_qi_enqueue(struct device *qidev, struct caam_drv_req *req)qm_fd_addr_set64 (&fd, addr); do { + refcount_inc(&req->drv_ctx->refcnt); ret = qman_enqueue(req->drv_ctx->req_fq, &fd);
drivers/crypto/caam/qi.c int caam_qi_enqueue(struct device *qidev, struct caam_drv_req *req) · line 133
Quoted 10 lines
drivers/crypto/caam/qi.c +2
-3-if (likely (!ret)) { -refcount_inc (&req->drv_ctx->refcnt); +if (likely (!ret))return 0 ; - } +refcount_dec (&req->drv_ctx->refcnt);if (ret != -EBUSY )break ; num_retries++;
However, note that the following error is still present:
[ 3.294978] alg: sig: sign test failed: invalid output [ 3.300128] 00000000: 68 e4 b7 d5 2e 12 d4 9b ca a5 a7 fc 50 2f d2 f6 [ 3.306573] 00000010: 6b 01 58 1e b7 72 2c 0f 66 a4 c9 1e b9 49 21 a7 [ 3.313016] 00000020: 53 62 26 6d bb 69 62 a2 7e 3b 8d 80 6f 2d 21 9d [ 3.319458] 00000030: cd 6f 92 e5 a9 03 e4 b3 b0 fc e7 4f ec a7 23 5c [ 3.325902] 00000040: 1d dc 08 13 c3 2e 8b d9 fa ab e0 6f 2b a0 9d 2b [ 3.332345] 00000050: 32 47 d5 ad ec 65 5a ce b3 13 35 95 37 0e f1 b0 [ 3.338788] 00000060: c3 8e 22 0d c9 a2 b3 31 58 ea 74 18 18 d2 9f 7e [ 3.345230] 00000070: 04 fe 3b f1 5e 40 6c 39 3f 38 a2 71 58 fa da 1a [ 3.351672] 00000080: ed 02 70 7c 9e 72 93 a3 66 25 f2 35 e9 82 00 49 [ 3.358114] 00000090: 8e 09 b9 f0 52 76 b2 9e b4 06 b0 60 f2 15 a1 78 [ 3.364556] 000000a0: 74 3c 9b 87 17 f6 e8 ff ca fe 41 ed 73 c8 28 70 [ 3.370999] 000000b0: 33 cc a2 de d6 04 7a b5 85 81 a3 46 16 46 66 af [ 3.377442] 000000c0: 26 84 bc 9e 70 68 7c b3 68 44 73 4c c2 a4 70 45 [ 3.383887] 000000d0: a5 af a3 b3 9c cb b5 c8 bf 7d 8a 17 97 f6 33 0c [ 3.390329] 000000e0: 94 cc d3 fd ee e7 ba 8b dc 6f c7 3b 3b 67 14 ae [ 3.396771] 000000f0: 6a 00 33 90 df c5 f9 a2 6c b8 93 f7 cf 6b 0d 0d [ 3.403214] alg: sig: test 1 failed for pkcs1(rsa-caam,sha256): err -22 [ 3.409833] alg: self-tests for pkcs1(rsa,sha256) using pkcs1(rsa-caam,sha256) failed (rc=-22) [ 3.409836] ------------[ cut here ]------------ [ 3.423067] alg: self-tests for pkcs1(rsa,sha256) using pkcs1(rsa-caam,sha256) failed (rc=-22) [ 3.423094] WARNING: CPU: 3 PID: 337 at crypto/testmgr.c:6012 alg_test (crypto/testmgr.c:6012 (discriminator 1)) [ 3.439282] Modules linked in: [ 3.442334] CPU: 3 UID: 0 PID: 337 Comm: cryptomgr_test Not tainted 6.14.0-seco+ #163 NONE [ 3.450687] Hardware name: LS1046A RDB Board (DT) [ 3.455387] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 3.462349] pc : alg_test (crypto/testmgr.c:6012 (discriminator 1)) [ 3.466008] lr : alg_test (crypto/testmgr.c:6012 (discriminator 1)) [ 3.469667] sp : ffffffc086ebbd40 [ 3.472974] x29: ffffffc086ebbd40 x28: 0000000000000000 x27: 0000000000000000 [ 3.480114] x26: 00000000ffffffea x25: 00000000ffffffff x24: ffffffc082066470 [ 3.487253] x23: 0000000000000159 x22: 0000000000000807 x21: ffffff8801ce2a80 [ 3.494392] x20: ffffff8801ce2a00 x19: ffffffc081290df0 x18: 0000000000000000 [ 3.501531] x17: 35326168732c6d61 x16: 61632d6173722831 x15: 000000000000002d [ 3.508670] x14: 0000000000000000 x13: 00000000fffffffe x12: 65742d666c657320 [ 3.515808] x11: 656820747563205b x10: ffffffc081dc0640 x9 : ffffffc081d91ef8 [ 3.522946] x8 : ffffffc086ebbb28 x7 : ffffffc081d91ef8 x6 : 00000000fffff7ff [ 3.530085] x5 : 00000000000001a4 x4 : 0000000000000000 x3 : 0000000000000000 [ 3.537224] x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffffff88023fc200 [ 3.544362] Call trace: [ 3.546801] alg_test (crypto/testmgr.c:6012 (discriminator 1)) (P) [ 3.550461] cryptomgr_test (crypto/algboss.c:181) [ 3.554122] kthread (kernel/kthread.c:464) [ 3.557261] ret_from_fork (arch/arm64/kernel/entry.S:863) [ 3.560833] ---[ end trace 0000000000000000 ]---
as well as another error on reboot (present before but I forgot to post it):
[ 98.514208] ------------[ cut here ]------------ [ 98.518823] WARNING: CPU: 3 PID: 1 at crypto/algapi.c:464 crypto_unregister_alg (crypto/algapi.c:464 (discriminator 1)) [ 98.527100] Modules linked in: [ 98.530153] CPU: 3 UID: 0 PID: 1 Comm: systemd-shutdow Tainted: G W 6.14.0-seco+ #163 NONE [ 98.539899] Tainted: [W]=WARN [ 98.542859] Hardware name: LS1046A RDB Board (DT) [ 98.547559] pstate: 20000005 (nzCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 98.554520] pc : crypto_unregister_alg (crypto/algapi.c:464 (discriminator 1)) [ 98.559224] lr : crypto_unregister_alg (include/linux/atomic/atomic-arch-fallback.h:457 include/linux/atomic/atomic-instrumented.h:33 include/linux/refcount.h:136 crypto/algapi.c:464) [ 98.563926] sp : ffffffc0820dbb80 [ 98.567234] x29: ffffffc0820dbb80 x28: ffffff8800160000 x27: ffffff8801787090 [ 98.574374] x26: 0000000000000000 x25: ffffffc082022030 x24: 0000000000000000 [ 98.581513] x23: 0000000000000001 x22: ffffffc081efa4e0 x21: ffffffc0820dbbb8 [ 98.588652] x20: ffffffc081e80cc8 x19: ffffffc081f095c0 x18: 0000000000000000 [ 98.595791] x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000001 [ 98.602929] x14: ffffff8800160080 x13: 00000000000001b6 x12: 0000000000000001 [ 98.610069] x11: 0000000000000000 x10: 000000000000042c x9 : 0000000000000001 [ 98.617207] x8 : ffffffc0820dbb68 x7 : ffffffc081f095d0 x6 : ffffffc0820dbb58 [ 98.624346] x5 : ffffffc081f095c0 x4 : 0000000000000000 x3 : 0000000000000000 [ 98.631484] x2 : ffffffffffffffff x1 : 0000000000000001 x0 : 0000000000000002 [ 98.638623] Call trace: [ 98.641062] crypto_unregister_alg (crypto/algapi.c:464 (discriminator 1)) (P) [ 98.645765] crypto_unregister_rng (crypto/rng.c:188) [ 98.650035] caam_prng_unregister (drivers/crypto/caam/caamprng.c:207) [ 98.654216] caam_jr_remove (drivers/crypto/caam/jr.c:59 drivers/crypto/caam/jr.c:207) [ 98.657963] platform_shutdown (drivers/base/platform.c:1439) [ 98.661883] device_shutdown (include/linux/device.h:937 drivers/base/core.c:4823) [ 98.665804] kernel_restart (kernel/reboot.c:271 kernel/reboot.c:285) [ 98.669465] __do_sys_reboot (kernel/reboot.c:725) [ 98.673384] __arm64_sys_reboot (kernel/reboot.c:723) [ 98.677390] invoke_syscall (arch/arm64/include/asm/current.h:19 arch/arm64/kernel/syscall.c:54) [ 98.681137] el0_svc_common.constprop.0 (include/linux/thread_info.h:135 (discriminator 2) arch/arm64/kernel/syscall.c:140 (discriminator 2)) [ 98.685841] do_el0_svc (arch/arm64/kernel/syscall.c:152) [ 98.689152] el0_svc (arch/arm64/include/asm/irqflags.h:55 arch/arm64/include/asm/irqflags.h:76 arch/arm64/kernel/entry-common.c:165 arch/arm64/kernel/entry-common.c:178 arch/arm64/kernel/entry-common.c:745) [ 98.692204] el0t_64_sync_handler (arch/arm64/kernel/entry-common.c:763) [ 98.696559] el0t_64_sync (arch/arm64/kernel/entry.S:600) [ 98.700217] ---[ end trace 0000000000000000 ]---
--Sean
Herbert Xu
maintainerPATCH 1/1 crypto: api - Allow delayed algorithm destruction
In reply to Herbert XuQuoted 5 lines · Herbert Xu
What I'll do is make the
crypto_unregistercall wait for the users to go away. That matches how the network device unregistration works and hopefully should solve this problem. But keep your eyes for dead locks that used to plague netdev unregistration :)
That was a dumb idea. All it would do is make the shutdown hang. So here is a different tack. Let the algorithms stick around, by allocating them dynamically instead. Then we could simply kfree them when the user finally disappears (if ever).
Note to make this work, caam needs to be modified to allocate the algorithms dynamically (kmemdup should work), and add a cra_destroy function to kfree the memory.
---8<---
The current algorithm unregistration mechanism originated from software crypto. The code relies on module reference counts to stop in-use algorithms from being unregistered. Therefore if the unregistration function is reached, it is assumed that the module reference count has hit zero and thus the algorithm reference count should be exactly 1.
This is completely broken for hardware devices, which can be unplugged at random.
Fix this by allowing algorithms to be destroyed later if a destroy callback is provided.
crypto/algapi.c +4 -4
@@ -481,10 +481,10 @@ void crypto_unregister_alg(struct crypto_alg *alg)if (WARN (ret,"Algorithm %s is not registered" , alg->cra_driver_name))return ; -if (WARN_ON (refcount_read (&alg->cra_refcnt) !=1 )) -return ; - -if (alg->cra_type && alg->cra_type->destroy) +if (alg->cra_destroy) +crypto_alg_put (alg); +else if (!WARN_ON (refcount_read (&alg->cra_refcnt) !=1 ) && + alg->cra_type && alg->cra_type->destroy) alg->cra_type->destroy (alg);crypto_remove_final (&list);
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Herbert Xu
maintainerRe: [PATCH] crypto: caam/qi - Fix drv_ctx refcount bug
In reply to Sean AndersonQuoted 4 lines · Sean Anderson
However, note that the following error is still present:
[ 3.294978] alg: sig: sign test failed: invalid output
That just looks like a bug in the driver. I'll leave it in the caam maintainers' capable hands :)
Quoted 11 lines
as well as another error on reboot (present before but I forgot to post it):
[ 98.514208] ------------[ cut here ]------------ [ 98.518823] WARNING: CPU: 3 PID: 1 at crypto/algapi.c:464 crypto_unregister_alg (crypto/algapi.c:464 (discriminator 1)) [ 98.527100] Modules linked in: [ 98.530153] CPU: 3 UID: 0 PID: 1 Comm: systemd-shutdow Tainted: G W 6.14.0-seco+ #163 NONE [ 98.539899] Tainted: [W]=WARN [ 98.542859] Hardware name: LS1046A RDB Board (DT) [ 98.547559] pstate: 20000005 (nzCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 98.554520] pc : crypto_unregister_alg (crypto/algapi.c:464 (discriminator 1)) [ 98.559224] lr : crypto_unregister_alg (include/linux/atomic/atomic-arch-fallback.h:457 include/linux/atomic/atomic-instrumented.h:33 include/linux/refcount.h:136 crypto/algapi.c:464)
Yes that's a long-standing design fault in the crypto_unregister mechanism for drivers.
The unregister mechanism was designed for software crypto, so it relied on module refcounts to prevent unregistering something that's still in use. For hardware that follows the device model where things get unplugged at random, this obviously doesn't work.
What I'll do is make the crypto_unregister call wait for the users to go away. That matches how the network device unregistration works and hopefully should solve this problem. But keep your eyes for dead locks that used to plague netdev unregistration :)
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH] crypto: api - Allow delayed algorithm destruction
In reply to Herbert XuQuoted 42 lines · Herbert Xu
Quoted 5 lines · Herbert Xu
What I'll do is make the
crypto_unregistercall wait for the users to go away. That matches how the network device unregistration works and hopefully should solve this problem. But keep your eyes for dead locks that used to plague netdev unregistration :)That was a dumb idea. All it would do is make the shutdown hang. So here is a different tack. Let the algorithms stick around, by allocating them dynamically instead. Then we could simply kfree them when the user finally disappears (if ever).
Note to make this work, caam needs to be modified to allocate the algorithms dynamically (kmemdup should work), and add a
cra_destroyfunction to kfree the memory.---8<---
The current algorithm unregistration mechanism originated from software crypto. The code relies on module reference counts to stop in-use algorithms from being unregistered. Therefore if the unregistration function is reached, it is assumed that the module reference count has hit zero and thus the algorithm reference count should be exactly 1.This is completely broken for hardware devices, which can be unplugged at random.
Fix this by allowing algorithms to be destroyed later if a destroy callback is provided.
Reported-by Sean Anderson <[email protected]>Signed-off-by Herbert Xu <[email protected]>crypto/algapi.c +0
-1@@ -481,10 +481,10 @@ void crypto_unregister_alg(struct crypto_alg *alg)if (WARN (ret,"Algorithm %s is not registered" , alg->cra_driver_name))return ; -if (WARN_ON (refcount_read (&alg->cra_refcnt) !=1 ))
crypto/algapi.c void crypto_unregister_alg(struct crypto_alg *alg) · line 490
Quoted 10 lines
crypto/algapi.c +4
-3-return ; - -if (alg->cra_type && alg->cra_type->destroy) +if (alg->cra_destroy) +crypto_alg_put (alg); +else if (!WARN_ON (refcount_read (&alg->cra_refcnt) !=1 ) && + alg->cra_type && alg->cra_type->destroy) alg->cra_type->destroy (alg);crypto_remove_final (&list);
The above patch didn't apply cleanly. I seem to be missing cra_type. What tree should I test with?
--Sean
Herbert Xu
maintainerRe: [PATCH] crypto: api - Allow delayed algorithm destruction
Quoted 3 lines · Sean Anderson
The above patch didn't apply cleanly. I seem to be missing
cra_type. What tree should I test with?
The patch goes on top of cryptodev. But it won't do anything without a corresponding patch to caam that moves the algorithm data structures into dynamically allocated memory, and adds a cra_destroy hook to free that memory.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Herbert Xu
maintainerPATCH 1/1 crypto: api - Add support for duplicating algorithms before registration
Quoted 5 lines · Herbert Xu
The patch goes on top of cryptodev. But it won't do anything without a corresponding patch to caam that moves the algorithm data structures into dynamically allocated memory, and adds a
cra_destroyhook to free that memory.
Here's a patch on top that allows drivers to do this easily. Unfortunately it still won't help caam because it embeds the algorithm in a bigger structure, so the duplication needs to be done by hand.
---8<---
If the bit CRYPTO_ALG_DUP_FIRST is set, an algorithm will be duplicated by kmemdup before registration. This is inteded for hardware-based algorithms that may be unplugged at will.
Do not use this if the algorithm data structure is embedded in a bigger data structure. Perform the duplication in the driver instead.
--- crypto/acompress.c | 1 + crypto/aead.c | 1 + crypto/ahash.c | 1 + crypto/akcipher.c | 1 + crypto/algapi.c | 41 ++++++++++++++++++++++++++++------------- crypto/api.c | 9 +++++++++ crypto/internal.h | 5 ++++- crypto/kpp.c | 1 + crypto/lskcipher.c | 1 + crypto/rng.c | 1 + crypto/scompress.c | 1 + crypto/shash.c | 1 + crypto/sig.c | 1 + crypto/skcipher.c | 1 + include/linux/crypto.h | 9 +++++++++ 15 files changed, 61 insertions(+), 14 deletions(-)
crypto/acompress.c +1 -0
@@ -152,6 +152,7 @@ static const struct crypto_type crypto_acomp_type = { .maskset = CRYPTO_ALG_TYPE_ACOMPRESS_MASK, .type = CRYPTO_ALG_TYPE_ACOMPRESS, .tfmsize = offsetof(struct crypto_acomp, base), + .algsize = offsetof(struct acomp_alg, base), }; struct crypto_acomp *crypto_alloc_acomp(const char *alg_name, u32 type,
crypto/aead.c +1 -0
@@ -186,6 +186,7 @@ static const struct crypto_type crypto_aead_type = { .maskset = CRYPTO_ALG_TYPE_MASK, .type = CRYPTO_ALG_TYPE_AEAD, .tfmsize = offsetof(struct crypto_aead, base), + .algsize = offsetof(struct aead_alg, base), }; int crypto_grab_aead(struct crypto_aead_spawn *spawn,
crypto/ahash.c +1 -0
@@ -897,6 +897,7 @@ static const struct crypto_type crypto_ahash_type = { .maskset = CRYPTO_ALG_TYPE_AHASH_MASK, .type = CRYPTO_ALG_TYPE_AHASH, .tfmsize = offsetof(struct crypto_ahash, base), + .algsize = offsetof(struct ahash_alg, halg.base), }; int crypto_grab_ahash(struct crypto_ahash_spawn *spawn,
crypto/akcipher.c +1 -0
@@ -97,6 +97,7 @@ static const struct crypto_type crypto_akcipher_type = { .maskset = CRYPTO_ALG_TYPE_AHASH_MASK, .type = CRYPTO_ALG_TYPE_AKCIPHER, .tfmsize = offsetof(struct crypto_akcipher, base), + .algsize = offsetof(struct akcipher_alg, base), }; int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn,
crypto/algapi.c +28 -13
73 lines not on this page · raw message
crypto/api.c +9 -0
@@ -703,5 +703,14 @@ void crypto_req_done(void *data, int err) }EXPORT_SYMBOL_GPL (crypto_req_done); +void crypto_destroy_alg (struct crypto_alg *alg) +{ +if (alg->cra_type && alg->cra_type->destroy) + alg->cra_type->destroy (alg); +if (alg->cra_destroy) + alg->cra_destroy (alg); +} +EXPORT_SYMBOL_GPL (crypto_destroy_alg); +MODULE_DESCRIPTION ("Cryptographic core API" );MODULE_LICENSE ("GPL" );
crypto/internal.h +4 -1
@@ -46,6 +46,7 @@ struct crypto_type {unsigned int maskclear;unsigned int maskset;unsigned int tfmsize; +unsigned int algsize; };enum {
@@ -162,10 +163,12 @@ static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg)return alg; } +void crypto_destroy_alg (struct crypto_alg *alg); +static inline void crypto_alg_put (struct crypto_alg *alg) {if (refcount_dec_and_test (&alg->cra_refcnt)) - alg->cra_destroy (alg); +crypto_destroy_alg (alg); }static inline int crypto_tmpl_get (struct crypto_template *tmpl)
crypto/kpp.c +1 -0
@@ -80,6 +80,7 @@ static const struct crypto_type crypto_kpp_type = { .maskset = CRYPTO_ALG_TYPE_MASK, .type = CRYPTO_ALG_TYPE_KPP, .tfmsize = offsetof(struct crypto_kpp, base), + .algsize = offsetof(struct kpp_alg, base), };struct crypto_kpp *crypto_alloc_kpp (const char *alg_name,u32 type,u32 mask)
crypto/lskcipher.c +1 -0
@@ -294,6 +294,7 @@ static const struct crypto_type crypto_lskcipher_type = { .maskset = CRYPTO_ALG_TYPE_MASK, .type = CRYPTO_ALG_TYPE_LSKCIPHER, .tfmsize = offsetof(struct crypto_lskcipher, base), + .algsize = offsetof(struct lskcipher_alg, co.base), };static void crypto_lskcipher_exit_tfm_sg (struct crypto_tfm *tfm)
crypto/rng.c +1 -0
@@ -98,6 +98,7 @@ static const struct crypto_type crypto_rng_type = { .maskset = CRYPTO_ALG_TYPE_MASK, .type = CRYPTO_ALG_TYPE_RNG, .tfmsize = offsetof(struct crypto_rng, base), + .algsize = offsetof(struct rng_alg, base), };struct crypto_rng *crypto_alloc_rng (const char *alg_name,u32 type,u32 mask)
crypto/scompress.c +1 -0
@@ -367,6 +367,7 @@ static const struct crypto_type crypto_scomp_type = { .maskset = CRYPTO_ALG_TYPE_MASK, .type = CRYPTO_ALG_TYPE_SCOMPRESS, .tfmsize = offsetof(struct crypto_scomp, base), + .algsize = offsetof(struct scomp_alg, base), };static void scomp_prepare_alg (struct scomp_alg *alg)
crypto/shash.c +1 -0
@@ -227,6 +227,7 @@ const struct crypto_type crypto_shash_type = { .maskset = CRYPTO_ALG_TYPE_MASK, .type = CRYPTO_ALG_TYPE_SHASH, .tfmsize = offsetof(struct crypto_shash, base), + .algsize = offsetof(struct shash_alg, base), }; int crypto_grab_shash(struct crypto_shash_spawn *spawn,
crypto/sig.c +1 -0
@@ -74,6 +74,7 @@ static const struct crypto_type crypto_sig_type = { .maskset = CRYPTO_ALG_TYPE_MASK, .type = CRYPTO_ALG_TYPE_SIG, .tfmsize = offsetof(struct crypto_sig, base), + .algsize = offsetof(struct sig_alg, base), };struct crypto_sig *crypto_alloc_sig (const char *alg_name,u32 type,u32 mask)
crypto/skcipher.c +1 -0
@@ -620,6 +620,7 @@ static const struct crypto_type crypto_skcipher_type = { .maskset = CRYPTO_ALG_TYPE_SKCIPHER_MASK, .type = CRYPTO_ALG_TYPE_SKCIPHER, .tfmsize = offsetof(struct crypto_skcipher, base), + .algsize = offsetof(struct skcipher_alg, base), }; int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn,
include/linux/crypto.h +9 -0
@@ -50,6 +50,15 @@*/ #define CRYPTO_ALG_NEED_FALLBACK 0x00000100 +/* +* Set if the algorithm data structure should be duplicated into +* kmalloc memory before registration. This is useful for hardware +* that can be disconnected at will. Do not use this if the data +* structure is embedded into a bigger one. Duplicate the overall +* data structure in the driver in that case. +*/ +#define CRYPTO_ALG_DUP_FIRST 0x00000200 +/* * Set if the algorithm has passed automated run-time testing. Note that * if there is no run-time testing for a given algorithm it is considered
Signature · 6 lines
2.39.5 -- Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH] crypto: api - Add support for duplicating algorithms before registration
Quoted 17 lines · Herbert Xu
Quoted 5 lines · Herbert Xu
The patch goes on top of cryptodev. But it won't do anything without a corresponding patch to caam that moves the algorithm data structures into dynamically allocated memory, and adds a
cra_destroyhook to free that memory.Here's a patch on top that allows drivers to do this easily. Unfortunately it still won't help caam because it embeds the algorithm in a bigger structure, so the duplication needs to be done by hand.
---8<---
If the bitCRYPTO_ALG_DUP_FIRSTis set, an algorithm will be duplicated by kmemdup before registration. This is inteded for hardware-based algorithms that may be unplugged at will.
Quoted 5 lines
Do not use this if the algorithm data structure is embedded in a bigger data structure. Perform the duplication in the driver instead.
Signed-off-by Herbert Xu <[email protected]>
Why does this make any sense? The lifetime of the algorithm struct memory should be the same as that of the owning module, and drivers should ensure that. In which case hacks like this are not needed.
- Eric
Herbert Xu
maintainerRe: [PATCH] crypto: api - Add support for duplicating algorithms before registration
Quoted 4 lines · Eric Biggers
Why does this make any sense? The lifetime of the algorithm struct memory should be the same as that of the owning module, and drivers should ensure that. In which case hacks like this are not needed.
Hardware can be unplugged at any time. Once all hardware backing a driver has been removed, you need to unregister that algorithm.
Please read my explanation for the prior patch:
https://patchwork.kernel.org/project/linux-crypto/patch/[email protected]/
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt