Skip to content

Commit 72c8117

Browse files
arndbherbertx
authored andcommitted
crypto: ccp - Reduce maximum stack usage
Each of the operations in ccp_run_cmd() needs several hundred bytes of kernel stack. Depending on the inlining, these may need separate stack slots that add up to more than the warning limit, as shown in this clang based build: drivers/crypto/ccp/ccp-ops.c:871:12: error: stack frame size of 1164 bytes in function 'ccp_run_aes_cmd' [-Werror,-Wframe-larger-than=] static int ccp_run_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) The problem may also happen when there is no warning, e.g. in the ccp_run_cmd()->ccp_run_aes_cmd()->ccp_run_aes_gcm_cmd() call chain with over 2000 bytes. Mark each individual function as 'noinline_for_stack' to prevent this from happening, and move the calls to the two special cases for aes into the top-level function. This will keep the actual combined stack usage to the mimimum: 828 bytes for ccp_run_aes_gcm_cmd() and at most 524 bytes for each of the other cases. Fixes: 63b9450 ("crypto: ccp - CCP device driver and interface support") Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 2a03e3a commit 72c8117

1 file changed

Lines changed: 31 additions & 21 deletions

File tree

drivers/crypto/ccp/ccp-ops.c

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ static int ccp_copy_from_sb(struct ccp_cmd_queue *cmd_q,
455455
return ccp_copy_to_from_sb(cmd_q, wa, jobid, sb, byte_swap, true);
456456
}
457457

458-
static int ccp_run_aes_cmac_cmd(struct ccp_cmd_queue *cmd_q,
459-
struct ccp_cmd *cmd)
458+
static noinline_for_stack int
459+
ccp_run_aes_cmac_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
460460
{
461461
struct ccp_aes_engine *aes = &cmd->u.aes;
462462
struct ccp_dm_workarea key, ctx;
@@ -611,8 +611,8 @@ static int ccp_run_aes_cmac_cmd(struct ccp_cmd_queue *cmd_q,
611611
return ret;
612612
}
613613

614-
static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
615-
struct ccp_cmd *cmd)
614+
static noinline_for_stack int
615+
ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
616616
{
617617
struct ccp_aes_engine *aes = &cmd->u.aes;
618618
struct ccp_dm_workarea key, ctx, final_wa, tag;
@@ -879,7 +879,8 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
879879
return ret;
880880
}
881881

882-
static int ccp_run_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
882+
static noinline_for_stack int
883+
ccp_run_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
883884
{
884885
struct ccp_aes_engine *aes = &cmd->u.aes;
885886
struct ccp_dm_workarea key, ctx;
@@ -889,12 +890,6 @@ static int ccp_run_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
889890
bool in_place = false;
890891
int ret;
891892

892-
if (aes->mode == CCP_AES_MODE_CMAC)
893-
return ccp_run_aes_cmac_cmd(cmd_q, cmd);
894-
895-
if (aes->mode == CCP_AES_MODE_GCM)
896-
return ccp_run_aes_gcm_cmd(cmd_q, cmd);
897-
898893
if (!((aes->key_len == AES_KEYSIZE_128) ||
899894
(aes->key_len == AES_KEYSIZE_192) ||
900895
(aes->key_len == AES_KEYSIZE_256)))
@@ -1061,8 +1056,8 @@ static int ccp_run_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
10611056
return ret;
10621057
}
10631058

1064-
static int ccp_run_xts_aes_cmd(struct ccp_cmd_queue *cmd_q,
1065-
struct ccp_cmd *cmd)
1059+
static noinline_for_stack int
1060+
ccp_run_xts_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
10661061
{
10671062
struct ccp_xts_aes_engine *xts = &cmd->u.xts;
10681063
struct ccp_dm_workarea key, ctx;
@@ -1261,7 +1256,8 @@ static int ccp_run_xts_aes_cmd(struct ccp_cmd_queue *cmd_q,
12611256
return ret;
12621257
}
12631258

1264-
static int ccp_run_des3_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
1259+
static noinline_for_stack int
1260+
ccp_run_des3_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
12651261
{
12661262
struct ccp_des3_engine *des3 = &cmd->u.des3;
12671263

@@ -1457,7 +1453,8 @@ static int ccp_run_des3_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
14571453
return ret;
14581454
}
14591455

1460-
static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
1456+
static noinline_for_stack int
1457+
ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
14611458
{
14621459
struct ccp_sha_engine *sha = &cmd->u.sha;
14631460
struct ccp_dm_workarea ctx;
@@ -1801,7 +1798,8 @@ static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
18011798
return ret;
18021799
}
18031800

1804-
static int ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
1801+
static noinline_for_stack int
1802+
ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
18051803
{
18061804
struct ccp_rsa_engine *rsa = &cmd->u.rsa;
18071805
struct ccp_dm_workarea exp, src, dst;
@@ -1932,8 +1930,8 @@ static int ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
19321930
return ret;
19331931
}
19341932

1935-
static int ccp_run_passthru_cmd(struct ccp_cmd_queue *cmd_q,
1936-
struct ccp_cmd *cmd)
1933+
static noinline_for_stack int
1934+
ccp_run_passthru_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
19371935
{
19381936
struct ccp_passthru_engine *pt = &cmd->u.passthru;
19391937
struct ccp_dm_workarea mask;
@@ -2064,7 +2062,8 @@ static int ccp_run_passthru_cmd(struct ccp_cmd_queue *cmd_q,
20642062
return ret;
20652063
}
20662064

2067-
static int ccp_run_passthru_nomap_cmd(struct ccp_cmd_queue *cmd_q,
2065+
static noinline_for_stack int
2066+
ccp_run_passthru_nomap_cmd(struct ccp_cmd_queue *cmd_q,
20682067
struct ccp_cmd *cmd)
20692068
{
20702069
struct ccp_passthru_nomap_engine *pt = &cmd->u.passthru_nomap;
@@ -2405,7 +2404,8 @@ static int ccp_run_ecc_pm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
24052404
return ret;
24062405
}
24072406

2408-
static int ccp_run_ecc_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
2407+
static noinline_for_stack int
2408+
ccp_run_ecc_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
24092409
{
24102410
struct ccp_ecc_engine *ecc = &cmd->u.ecc;
24112411

@@ -2442,7 +2442,17 @@ int ccp_run_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
24422442

24432443
switch (cmd->engine) {
24442444
case CCP_ENGINE_AES:
2445-
ret = ccp_run_aes_cmd(cmd_q, cmd);
2445+
switch (cmd->u.aes.mode) {
2446+
case CCP_AES_MODE_CMAC:
2447+
ret = ccp_run_aes_cmac_cmd(cmd_q, cmd);
2448+
break;
2449+
case CCP_AES_MODE_GCM:
2450+
ret = ccp_run_aes_gcm_cmd(cmd_q, cmd);
2451+
break;
2452+
default:
2453+
ret = ccp_run_aes_cmd(cmd_q, cmd);
2454+
break;
2455+
}
24462456
break;
24472457
case CCP_ENGINE_XTS_AES_128:
24482458
ret = ccp_run_xts_aes_cmd(cmd_q, cmd);

0 commit comments

Comments
 (0)