crypto: tegra: Update crypto_engine_ctx handling

In Linux v6.6, the crypto_engine_ctx structure was removed and the
crypto_engine_ops was moved from this structure to the crypto_alg
structure. The Tegra Security Engine driver was updated accordingly to
populate the crypto_engine_ops in the appropriate structure depending
on whether the crypto_engine_ctx structure is present or not.

Currently conftest is using the presence of the crypto_engine_ctx
structure to decide where to populate the crypto_engine_ops. While
this works, it is possible that a kernel older than v6.6 also includes
a backport of commit e5e7eb023f24 ("crypto: engine - Move
crypto_engine_ops from request into crypto_alg") that moves the ops
to the crypto_alg structure. Although backporting this commit alone
should not cause any problems, it is better to detect if this commit
is present rather than relying on the presence of crypto_engine_ctx
structure.

To detect the presence of commit e5e7eb023f24 we can simply detect if
one of the functions added and exported by this commit is present.
For example, the function crypto_engine_register_aead() was added and
exported by this commit. Therefore, update conftest to detect if
commit e5e7eb023f24 is present and then update the Tegra Security
Engine accordingly.

Bug 5564561

Change-Id: I3f7688e6e954a158094a9a2fdf73354f765ed680
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3499816
(cherry picked from commit c1631d32f8d80cd31f54e7297c542f308a281d25)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3508186
GVS: buildbot_gerritrpt <buildbot_gerritrpt@nvidia.com>
Reviewed-by: Brad Griffis <bgriffis@nvidia.com>
This commit is contained in:
Jon Hunter
2025-11-13 18:28:18 +00:00
committed by mobile promotions
parent bc32d4b5bd
commit 005042f3eb
6 changed files with 97 additions and 115 deletions

View File

@@ -25,7 +25,7 @@
#include "tegra-se.h"
struct tegra_sm4_ctx {
#ifndef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifndef NV_CRYPTO_ENGINE_OPS_PRESENT
struct crypto_engine_ctx enginectx;
#endif
struct tegra_se *se;
@@ -49,7 +49,7 @@ struct tegra_sm4_reqctx {
};
struct tegra_sm4_gcm_ctx {
#ifndef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifndef NV_CRYPTO_ENGINE_OPS_PRESENT
struct crypto_engine_ctx enginectx;
#endif
struct tegra_se *se;
@@ -80,7 +80,7 @@ struct tegra_sm4_gcm_reqctx {
};
struct tegra_sm4_cmac_ctx {
#ifndef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifndef NV_CRYPTO_ENGINE_OPS_PRESENT
struct crypto_engine_ctx enginectx;
#endif
struct tegra_se *se;
@@ -293,7 +293,7 @@ static int tegra_sm4_cra_init(struct crypto_skcipher *tfm)
const char *algname;
int ret;
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
se_alg = container_of(alg, struct tegra_se_alg, alg.skcipher.base);
#else
se_alg = container_of(alg, struct tegra_se_alg, alg.skcipher);
@@ -316,7 +316,7 @@ static int tegra_sm4_cra_init(struct crypto_skcipher *tfm)
ctx->alg = ret;
#ifndef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifndef NV_CRYPTO_ENGINE_OPS_PRESENT
ctx->enginectx.op.do_one_request = tegra_sm4_do_one_req;
#endif
@@ -548,7 +548,7 @@ static int tegra_sm4_decrypt(struct skcipher_request *req)
static struct tegra_se_alg tegra_sm4_algs[] = {
{
.alg.skcipher = {
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
.base = {
#endif
.init = tegra_sm4_cra_init,
@@ -570,14 +570,14 @@ static struct tegra_se_alg tegra_sm4_algs[] = {
.cra_alignmask = 0,
.cra_module = THIS_MODULE,
},
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
},
.op.do_one_request = tegra_sm4_do_one_req,
#endif
}
}, {
.alg.skcipher = {
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
.base = {
#endif
.init = tegra_sm4_cra_init,
@@ -599,14 +599,14 @@ static struct tegra_se_alg tegra_sm4_algs[] = {
.cra_alignmask = 0,
.cra_module = THIS_MODULE,
},
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
},
.op.do_one_request = tegra_sm4_do_one_req,
#endif
}
}, {
.alg.skcipher = {
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
.base = {
#endif
.init = tegra_sm4_cra_init,
@@ -628,14 +628,14 @@ static struct tegra_se_alg tegra_sm4_algs[] = {
.cra_alignmask = 0,
.cra_module = THIS_MODULE,
},
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
},
.op.do_one_request = tegra_sm4_do_one_req,
#endif
}
}, {
.alg.skcipher = {
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
.base = {
#endif
.init = tegra_sm4_cra_init,
@@ -657,14 +657,14 @@ static struct tegra_se_alg tegra_sm4_algs[] = {
.cra_alignmask = 0,
.cra_module = THIS_MODULE,
},
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
},
.op.do_one_request = tegra_sm4_do_one_req,
#endif
}
}, {
.alg.skcipher = {
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
.base = {
#endif
.init = tegra_sm4_cra_init,
@@ -686,7 +686,7 @@ static struct tegra_se_alg tegra_sm4_algs[] = {
.cra_alignmask = 0,
.cra_module = THIS_MODULE,
},
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
},
.op.do_one_request = tegra_sm4_do_one_req,
#endif
@@ -1067,7 +1067,7 @@ static int tegra_sm4_gcm_cra_init(struct crypto_aead *tfm)
struct aead_alg *alg = crypto_aead_alg(tfm);
struct tegra_se_alg *se_alg;
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
se_alg = container_of(alg, struct tegra_se_alg, alg.aead.base);
#else
se_alg = container_of(alg, struct tegra_se_alg, alg.aead);
@@ -1083,7 +1083,7 @@ static int tegra_sm4_gcm_cra_init(struct crypto_aead *tfm)
ctx->verify_alg = SE_ALG_SM4_GCM_VERIFY;
ctx->mac_alg = SE_ALG_SM4_GMAC;
#ifndef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifndef NV_CRYPTO_ENGINE_OPS_PRESENT
ctx->enginectx.op.do_one_request = tegra_sm4_gcm_do_one_req;
#endif
@@ -1457,7 +1457,7 @@ static int tegra_sm4_cmac_cra_init(struct crypto_tfm *tfm)
algname = crypto_tfm_alg_name(tfm);
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
se_alg = container_of(alg, struct tegra_se_alg, alg.ahash.base);
#else
se_alg = container_of(alg, struct tegra_se_alg, alg.ahash);
@@ -1471,7 +1471,7 @@ static int tegra_sm4_cmac_cra_init(struct crypto_tfm *tfm)
ctx->alg = SE_ALG_SM4_CMAC;
ctx->final_alg = SE_ALG_SM4_CMAC_FINAL;
#ifndef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifndef NV_CRYPTO_ENGINE_OPS_PRESENT
ctx->enginectx.op.do_one_request = tegra_sm4_cmac_do_one_req;
#endif
@@ -1581,7 +1581,7 @@ static int tegra_sm4_cmac_import(struct ahash_request *req, const void *in)
static struct tegra_se_alg tegra_sm4_gcm_algs[] = {
{
.alg.aead = {
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
.base = {
#endif
@@ -1602,7 +1602,7 @@ static struct tegra_se_alg tegra_sm4_gcm_algs[] = {
.cra_alignmask = 0,
.cra_module = THIS_MODULE,
},
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
},
.op.do_one_request = tegra_sm4_gcm_do_one_req,
#endif
@@ -1613,7 +1613,7 @@ static struct tegra_se_alg tegra_sm4_gcm_algs[] = {
static struct tegra_se_alg tegra_sm4_cmac_algs[] = {
{
.alg.ahash = {
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
.base = {
#endif
.init = tegra_sm4_cmac_init,
@@ -1639,7 +1639,7 @@ static struct tegra_se_alg tegra_sm4_cmac_algs[] = {
.cra_init = tegra_sm4_cmac_cra_init,
.cra_exit = tegra_sm4_cmac_cra_exit,
},
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
},
.op.do_one_request = tegra_sm4_cmac_do_one_req,
#endif
@@ -1653,7 +1653,7 @@ struct tegra_se_regcfg tegra264_sm4_regcfg = {
.manifest = tegra_sm4_kac2_manifest
};
#ifdef NV_CONFTEST_REMOVE_STRUCT_CRYPTO_ENGINE_CTX
#ifdef NV_CRYPTO_ENGINE_OPS_PRESENT
int tegra_init_sm4(struct tegra_se *se)
{
struct aead_engine_alg *aead_alg;