From patchwork Fri Jul 12 08:59:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 168912 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp589069ilk; Fri, 12 Jul 2019 02:00:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqxQS5GTg+37dld/SMzhOaX3tG5fiPNEtIZ67ugj8i+8/fSFX8Z04dy6C4YAALTyHScEJfeC X-Received: by 2002:a17:90a:bb01:: with SMTP id u1mr10157670pjr.92.1562922003184; Fri, 12 Jul 2019 02:00:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562922003; cv=none; d=google.com; s=arc-20160816; b=NoBNMD9O0BQSYbNkUkwpCOzRizALgtxVcHrXsrEVckzveZvdq0bVBfMCIcOyrgeAQh Xmjjtf9b21nXFox382JjiIbM5QTAGNIiEDechTGO8+g77ea6+tv384oqauzkKxlqZkJC kGl3rh0bInninzt5+f9JnLIrSU01uEMB+J8yCAj2C+sg/1cFoUfsxF3IM/ZkqLx5XGes rJnHYNQ7pPTXPX0GH4lrqD8PYZQhkJHcGD/nUAmeZn7Wv7C7ARKbIAvWMkKp2h1DuJR2 OMOcOq0vERalyvpI6m4Oc+7OPovY2jhxnYgI4fN5WSKVQ0ennHWIEZQQFhnKpLLahM1W sGjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=1NGVddU00XJCWTNKPsYik+SS52DmCPmmJb8X2D/rW7Q=; b=lGt9U8aqseJ+YplfplzOdHzn4HmTYzQrGlDU7g9uy0+grro6SKkGG3yL0iNUKxBfaR BgJLff9/K1Gj0zjiYE2HGyPms/XnXPw5tdUvY3JqLyt0PyegwsPJ1A1W0yBbS2IfCXgJ TRJJUOGy4/6mpiXIATBRKLDgEDosqGPDDHUlDl8db+hhpOY4YmXrxxRZKzMV3whCXtN3 RJIN0+PkqkgmoK10XOm7Gezt20FHdEeGlqzd8ksm9BgE0RBBoksq7Q+6ZFv6PPaIVqVP hmVy5QG/oImHPwFS2pniYPQ+XrMIFkMQQS6c7pukGX58trrYYoUGL5xfDphViqN02Pxj HlxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d25si7832512pge.301.2019.07.12.02.00.02; Fri, 12 Jul 2019 02:00:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726260AbfGLJAB (ORCPT + 29 others); Fri, 12 Jul 2019 05:00:01 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:38493 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725935AbfGLI75 (ORCPT ); Fri, 12 Jul 2019 04:59:57 -0400 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.129]) with ESMTPA (Nemesis) id 1N4Qbu-1iVbzR3VIc-011OpO; Fri, 12 Jul 2019 10:59:39 +0200 From: Arnd Bergmann To: Tom Lendacky , Gary Hook , Herbert Xu , "David S. Miller" Cc: Arnd Bergmann , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: [PATCH] crypto: ccp - Reduce maximum stack usage Date: Fri, 12 Jul 2019 10:59:24 +0200 Message-Id: <20190712085937.4157934-1-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 MIME-Version: 1.0 X-Provags-ID: V03:K1:Kt7iHIJWTD2G3ZP7f3E2Ekz43XUmhSis8pfRbUBqvqmKY1ev+bq B2vyuXP2z+t/wzjoOMQfdx/a5aAbVb1khAMxuQDdLE4LtpQZsATlljn8YdzVvN8cGyRLyRj P9QXaanE1g63g6FjIdW8gZ2mOah9QbmWbwmx3u7lPjt/8ePhbMx/FSG6FffXIJiRBTR6gdu fRXmal2pdtKLGdS8kG7Iw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:CCo7Fc+q2h0=:rfuJA/iKw/fHc5K6vbfK8J 1AUtVqIpCK2SL5xZXEhEhv1BEjU5DBfTaSJHJ6vEaRGUfmFIIt5fdbbopMI9oqzC6Nevqta2P 1O2sAVw3J/vqEFosukHdcY9VugwyugamnGy456/W28KlJyqm1jzqCTubTch/3F1cJNHLtc9AN ap8nCHddNgrozLpIk9pXvh6rBvtdjVRvctTQ3Rw+dYTmV2DiR5yEIwyzkrJpuwkS2AEt3CZP4 T4dJBe2TC2xLpLbFh96a/U73I3FMHsWlkOCR7w9q0Xa/zp8kYLFmShVPtQW0QMgTrOm9J1KP2 RwpOqVB6JZ1uF/OYYHO1232/6DVjM6pJI7+piiXKejBi90V37IiXDpOxqKz8UlywQqczBQo+l JaL5pAaRWRRqgADATUukNYBl9VpU9naN5BsbrBoB2epp1NY2hDusbUR+6ztp4YYSr0vc/FQ56 gkUlMpO00mZYz23fOOmErPi4JE5C9ZZw/MQSReS7CZ0kx+VXAWrDa3Rl4xANHPq21Bx5VqQo4 gkE4aYZjZhg1lHQZuPiXTBSsElcPD0il6BNfYHG38ioUhEv34kg4q/Ydb/eoQLuOXCJftfcrF skgn2ypCCTIIw7o0Zye3YZAnKCYLAtBaKYOrH+imxGgm4Z1fIjrO9RvyTTDSegHneO20c6xKv N/M0Px853cuFYqfS0WvwnehnMYxd6tWFgeQl/HHN1sOnoCnIehYNkDxWT1jTJgFrumjNsCZ47 uLQH0waVFB/+nu5jp6MhZgFf2QahwPIOn+dkgg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: 63b945091a07 ("crypto: ccp - CCP device driver and interface support") Signed-off-by: Arnd Bergmann --- drivers/crypto/ccp/ccp-ops.c | 52 +++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 21 deletions(-) -- 2.20.0 diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c index 866b2e05ca77..97293d05a759 100644 --- a/drivers/crypto/ccp/ccp-ops.c +++ b/drivers/crypto/ccp/ccp-ops.c @@ -455,8 +455,8 @@ static int ccp_copy_from_sb(struct ccp_cmd_queue *cmd_q, return ccp_copy_to_from_sb(cmd_q, wa, jobid, sb, byte_swap, true); } -static int ccp_run_aes_cmac_cmd(struct ccp_cmd_queue *cmd_q, - struct ccp_cmd *cmd) +static noinline_for_stack int +ccp_run_aes_cmac_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) { struct ccp_aes_engine *aes = &cmd->u.aes; struct ccp_dm_workarea key, ctx; @@ -611,8 +611,8 @@ static int ccp_run_aes_cmac_cmd(struct ccp_cmd_queue *cmd_q, return ret; } -static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q, - struct ccp_cmd *cmd) +static noinline_for_stack int +ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) { struct ccp_aes_engine *aes = &cmd->u.aes; struct ccp_dm_workarea key, ctx, final_wa, tag; @@ -868,7 +868,8 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q, return ret; } -static int ccp_run_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) +static noinline_for_stack int +ccp_run_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) { struct ccp_aes_engine *aes = &cmd->u.aes; struct ccp_dm_workarea key, ctx; @@ -878,12 +879,6 @@ static int ccp_run_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) bool in_place = false; int ret; - if (aes->mode == CCP_AES_MODE_CMAC) - return ccp_run_aes_cmac_cmd(cmd_q, cmd); - - if (aes->mode == CCP_AES_MODE_GCM) - return ccp_run_aes_gcm_cmd(cmd_q, cmd); - if (!((aes->key_len == AES_KEYSIZE_128) || (aes->key_len == AES_KEYSIZE_192) || (aes->key_len == AES_KEYSIZE_256))) @@ -1050,8 +1045,8 @@ static int ccp_run_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) return ret; } -static int ccp_run_xts_aes_cmd(struct ccp_cmd_queue *cmd_q, - struct ccp_cmd *cmd) +static noinline_for_stack int +ccp_run_xts_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) { struct ccp_xts_aes_engine *xts = &cmd->u.xts; struct ccp_dm_workarea key, ctx; @@ -1250,7 +1245,8 @@ static int ccp_run_xts_aes_cmd(struct ccp_cmd_queue *cmd_q, return ret; } -static int ccp_run_des3_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) +static noinline_for_stack int +ccp_run_des3_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) { struct ccp_des3_engine *des3 = &cmd->u.des3; @@ -1446,7 +1442,8 @@ static int ccp_run_des3_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) return ret; } -static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) +static noinline_for_stack int +ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) { struct ccp_sha_engine *sha = &cmd->u.sha; struct ccp_dm_workarea ctx; @@ -1790,7 +1787,8 @@ static int ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) return ret; } -static int ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) +static noinline_for_stack int +ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) { struct ccp_rsa_engine *rsa = &cmd->u.rsa; struct ccp_dm_workarea exp, src, dst; @@ -1921,8 +1919,8 @@ static int ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) return ret; } -static int ccp_run_passthru_cmd(struct ccp_cmd_queue *cmd_q, - struct ccp_cmd *cmd) +static noinline_for_stack int +ccp_run_passthru_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) { struct ccp_passthru_engine *pt = &cmd->u.passthru; struct ccp_dm_workarea mask; @@ -2053,7 +2051,8 @@ static int ccp_run_passthru_cmd(struct ccp_cmd_queue *cmd_q, return ret; } -static int ccp_run_passthru_nomap_cmd(struct ccp_cmd_queue *cmd_q, +static noinline_for_stack int +ccp_run_passthru_nomap_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) { struct ccp_passthru_nomap_engine *pt = &cmd->u.passthru_nomap; @@ -2394,7 +2393,8 @@ static int ccp_run_ecc_pm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) return ret; } -static int ccp_run_ecc_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) +static noinline_for_stack int +ccp_run_ecc_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) { struct ccp_ecc_engine *ecc = &cmd->u.ecc; @@ -2431,7 +2431,17 @@ int ccp_run_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) switch (cmd->engine) { case CCP_ENGINE_AES: - ret = ccp_run_aes_cmd(cmd_q, cmd); + switch (cmd->u.aes.mode) { + case CCP_AES_MODE_CMAC: + ret = ccp_run_aes_cmac_cmd(cmd_q, cmd); + break; + case CCP_AES_MODE_GCM: + ret = ccp_run_aes_gcm_cmd(cmd_q, cmd); + break; + default: + ret = ccp_run_aes_cmd(cmd_q, cmd); + break; + } break; case CCP_ENGINE_XTS_AES_128: ret = ccp_run_xts_aes_cmd(cmd_q, cmd);