From patchwork Thu Jul 1 18:56:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 12354687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B34E5C11F64 for ; Thu, 1 Jul 2021 18:59:01 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 773DF61411 for ; Thu, 1 Jul 2021 18:59:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 773DF61411 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=seco.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mXJq/YrJUrW43HjzIS5Mdw59akrA/hOUKQaMOyMHBCc=; b=WwM1kIiywDcSLi +yYkNlHLiP1tI9ZvBATZkTIMm7OQuV4lO76sf7+TktqPLYkbQuQcUHg4hePYMBeCMCeoO10u0AQQC yAoCVsGywW+6Cc0rmFip9MXayZMIvS4BZxGfsacjEhJ9kd8n8UjVwoW3Izyon6ZPRiUMOA/SaAvIb 1WN9t0UPX8LkqlXJYrZB/k9Y4mtcGJ2jmpotV2eq5ZzIZylm3YYICkJMROm+auIkUMVDr/PXbXNzM fbnsTd/K8k3Ao61Z9hECib0jzd6AesllJDm8F1GU7rdOk+CfwB3fIx37zmwy+QG4t9fU7IjAR1OWV 6VQ/q/0z6RIbV9+9zYXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lz1ru-000oLN-FR; Thu, 01 Jul 2021 18:56:58 +0000 Received: from mail-vi1eur05on2057.outbound.protection.outlook.com ([40.107.21.57] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lz1rq-000oKR-BT for linux-arm-kernel@lists.infradead.org; Thu, 01 Jul 2021 18:56:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CMbPyVU97C/SauLt0jNoTCYwGtIpVrUdBwmnzV1kNBLjQ9jEFtrqWHW2vGnvEEpylh17bbQl0QyrSPgIvTRLc3NUMOM+Ib+Ed/MRo7jRU20PFHwDu8mGli3mB1A3hBBSxp02L27nl6GUQ+rpRjJ8Zknrq5qK8LGVLDgIqTXeBLpWtDqOtjl7MA3HGmu3N3rubXmr4coEk4oskVh6nGXNJ8RnJ5aBTWJ2rMq3F8/YB4CLPsi1ovrEDo+DTesdBZdBoZJ2JJ7CUoB9m92BH4Ay/phVelx62xAZ6C5slYouxxsMdOEA+7uAp3VvFSqIAC7WF72yW+AMe6CUsGPCxk4+1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YsY2HK1AjF8B0pLFtfaWenBEdRI/3UDtpvdK/k+UvMQ=; b=TUcnOz34j+5oDYrQr8zpLq/+Tll2Xw5KEPxDxEF99gQQScdQwRlWPSijstuw3LqCdyvMGXaBih05A/7w2MKvGBV8T/2TetScRng28KKgb1dQjzVUiF4Zw6j5DttRmFfAYFjmX1NwJPrqEcmbxvW/uQwmNy4jZ3mI2LCGlJBB/BULRam1wVafka7RR/rmG+XSFKqY9LylRC+PFeaZs4rLx1pSYX2U0rQsI8BhqUvXMG4AsoAIJ9kvjwLjylRs8XFfwd7hC7SF0pkGylgpcdL7lcymFn/ds9mXRfXaepeh0NDx7+bcH7sRP01WCsbm1rLzM0Bb9TZ92DRecNX++p6vuA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secospa.onmicrosoft.com; s=selector2-secospa-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YsY2HK1AjF8B0pLFtfaWenBEdRI/3UDtpvdK/k+UvMQ=; b=iiwlQB+4AdBdiNLg2BIHsspKUdxEvjq60SFfiPaa4ov0amW7Xw1LZFXCvMH1fp1RkFke+sv0isSOHuG87HZ5bSNZGm4+/F0H9f/+Hz5XoeIdmEX/2wqc7slHEvub/XsBOwPUoRROSVWH0tl0ywVbhIbXkjpIhGUY0c9p6EQBze0= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) by DB7PR03MB4618.eurprd03.prod.outlook.com (2603:10a6:10:18::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22; Thu, 1 Jul 2021 18:56:50 +0000 Received: from DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::40d5:3554:c709:6b1b]) by DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::40d5:3554:c709:6b1b%5]) with mapi id 15.20.4264.026; Thu, 1 Jul 2021 18:56:50 +0000 From: Sean Anderson To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: =?utf-8?q?Horia_Geant=C4=83?= , Aymen Sghaier , Richard Weinberger , linux-arm-kernel@lists.infradead.org, Marek Vasut , Sean Anderson Subject: [PATCH v2 1/2] crypto: mxs-dcp: Check for DMA mapping errors Date: Thu, 1 Jul 2021 14:56:37 -0400 Message-Id: <20210701185638.3437487-2-sean.anderson@seco.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210701185638.3437487-1-sean.anderson@seco.com> References: <20210701185638.3437487-1-sean.anderson@seco.com> X-Originating-IP: [50.195.82.171] X-ClientProxiedBy: MN2PR15CA0050.namprd15.prod.outlook.com (2603:10b6:208:237::19) To DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from plantagenet.inhand.com (50.195.82.171) by MN2PR15CA0050.namprd15.prod.outlook.com (2603:10b6:208:237::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22 via Frontend Transport; Thu, 1 Jul 2021 18:56:49 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8fb42a70-6398-4b8b-5fb0-08d93cc1fc3b X-MS-TrafficTypeDiagnostic: DB7PR03MB4618: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: M7m25XE1ZQUhpNLI4FYC4eZ3JVcRyMKoa0xJh5go9jtpw/xp1rxiegHS9uSzH+EwC2lDKYsuqHoPxWEHLEUEKyH0ibpAdQuzbLK9imrXUo4SpW5FEzpDpykvXjSgqEe/uhFhDipvPS6sKqqy+oaE9hvIh+wMThPnlTuNXJGPrxM59EIYFclq3vUr8EfUVssSEm1OHJcknGFMQ3ZN/qE2d6HFqsdhFhCT9JCUPl12uFvilIfCgElHQcoYZ8fsCwPPVmA83480v+VbVo/IiDNS+XgkioppYUsux8a6wwwTEFPO+ubIqXYdCJJZMJgA3tL6NwtCcAd8cwgW0ZIi2Pfqg9d7RnVveFR39MmT5EVyjLKrGdjHDh8XcfRS4sHU+xAwUYS/AM52Q0iTdIKiEMNKN8FFCNmx5CXRmIBCgQ5sGAhJiTx10x+TC4X1P+I/0hzwUZzU4yEoNF+GVb9YNJODbDoRhIxFiOHRKw94j+xzAfsbGZ/D1wZ4ZDhYNEMQH/4roQF4D8O+rLFVW8A1wbm9hxFd1lTKVccB8K0raX8zTC96jL2O1863gGW7lhTQIqqhfvFoEJWqYhoNP1ljy0jP27VFRoUS5t7GxymEUyUuo5x5kI1Hi9lDp4C4/7iZZBrUoAmUkO+zaD3hA4Wv9xzvDCCYkaM+41OdTtpnHEdI7f0YmkwSU+y49tOzZZcISNZmJAwv5t7GCI66Gsq8FFa6gg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4523.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(346002)(136003)(376002)(39830400003)(396003)(54906003)(6486002)(110136005)(6666004)(316002)(8676002)(66556008)(38350700002)(83380400001)(38100700002)(956004)(6506007)(66476007)(186003)(26005)(66946007)(16526019)(2616005)(478600001)(86362001)(2906002)(8936002)(1076003)(4326008)(5660300002)(6512007)(52116002)(44832011)(36756003)(107886003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JukDehaCacuDGCkppdNz1zsGbUGQbNuENVkq/V0YAb3BFzsleYMZvDVSYrec4wH+RX/6Yo8/sezHrn98wA+WH5AC7NYfxqD5+Q0X3LSMU49LshP7c3JmOVOfnHx2yjVzxpQ1GvXAgPaKK8vO5Lsr2FWzutv/FhMFL5rm8iuyE+9sc41PfkECmEZEo6A2lWHRl8mUKkzU2ht6iU8M9xrIHiw0Qt8iBBAGSEM4lF3IgEoBCAH6DRTznSNDYJPIJmWvOFsqDGMna+MevGFDsyig/RPo44zhQ1c9xhPDgkjdoBqNbH5mbO8CRMgCrb+pLuwn2leH1k6dohlUshk6Bn0YvxjhDnCQnlA1QEtzMrAyC/GCpvomlDbW0DKpfsQhVIvLNMU4rTyyR4GZQHNQ1NryVVAiFXDzDdXH9Ft+6k0gdk7774XAKHSSY5Wk/YvpInyCyCx21Yss2ICq6GzCEfwzyCccrbe8jv3zkgu3rfXq5fs8AAL2pyFy+JFKjGwbxSg/onX3u3kgOopE2hJMQleR6mxIbsOPGmCrEMzV8ob/wwK63WEU2Dhcg8UQKo9gXvIw8VcTeAoNc07+Y2OCpc1927wot/9iNB9jftIJ5FMZSrSni63Q2y3gFIAvcY+88p01hy8UE7onOBdy1apQBrS1fu3+eatmcAkT9/1Godwx8M845KjsPE+Jc2mBmJirA3PKmBV68voC5m03hQ3Lpdp4ICK9ZRirD/ISLlhqtVEgOxbVKMKBCLlyVz6aEcRBlUQ6b5SwGreCbpjbWxOWxh+JcK8wS4LPyErpE5ZwlmiaTMSIUMQ2T5BzzcInkBzhCqCgxET5fihRtw1wz/c+ZeRjdqS8CklqwpEbk++zfGHiwOxjY863Ea6p6wKwfVHG4taECixvq6hVkoChPdJtKz7mn+bQVy+NQRthqwhrZE/rHxc5QaXQwEzFvSN84mwnxC6ihx0tVwfaR0llwXvE6o1seLCPj2iXiNMbuJLqZ5X6FtS6jzbIFi+N73PLGbK9qL4U2GxEPSMFlKkyIizIbToAdi/rF5VkvHB3qNEX64+fDzCtxave3w98zDqwlCVqKZR7cFRplUGm2hXZ43i3KXVP8/eULmHqjsXZsnG5a/jWZI9JFn5tCDUNt+Mz80OP26JkgPOHV10Raj9j9FvHrIrLHeLBF1fOtdcJMdzBDKOGZaCyo3khevsWFA76aEYHcy7AvY0SgKyGxk2NNjelUDHgYrh81kK3vwxfxr+SDGOrKWy/fFRyo6FkrzJLYst0IEbAZ3g4Tdji8Ahn+SEE/SRxSh4FeE3QZWZP3qCpI20crXJ+TDW7ZpzbPHqfxNqPipd4 X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8fb42a70-6398-4b8b-5fb0-08d93cc1fc3b X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4523.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jul 2021 18:56:50.9079 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4a5hcidcNPrUQxLD9K9Wx5zmhsoxiKDEd4gcJiOimSJM2uaLphNy7ojMl6bhcEofUBMsbGFgnufGxDpSKolfcQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR03MB4618 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210701_115654_436461_1358775D X-CRM114-Status: GOOD ( 11.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org After calling dma_map_single(), we must also call dma_mapping_error(). This fixes the following warning when compiling with CONFIG_DMA_API_DEBUG: [ 311.241478] WARNING: CPU: 0 PID: 428 at kernel/dma/debug.c:1027 check_unmap+0x79c/0x96c [ 311.249547] DMA-API: mxs-dcp 2280000.crypto: device driver failed to check map error[device address=0x00000000860cb080] [size=32 bytes] [mapped as single] Signed-off-by: Sean Anderson Reviewed-by: Richard Weinberger --- (no changes since v1) drivers/crypto/mxs-dcp.c | 45 +++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c index d6a7784d2988..f397cc5bf102 100644 --- a/drivers/crypto/mxs-dcp.c +++ b/drivers/crypto/mxs-dcp.c @@ -170,15 +170,19 @@ static struct dcp *global_sdcp; static int mxs_dcp_start_dma(struct dcp_async_ctx *actx) { + int dma_err; struct dcp *sdcp = global_sdcp; const int chan = actx->chan; uint32_t stat; unsigned long ret; struct dcp_dma_desc *desc = &sdcp->coh->desc[actx->chan]; - dma_addr_t desc_phys = dma_map_single(sdcp->dev, desc, sizeof(*desc), DMA_TO_DEVICE); + dma_err = dma_mapping_error(sdcp->dev, desc_phys); + if (dma_err) + return dma_err; + reinit_completion(&sdcp->completion[chan]); /* Clear status register. */ @@ -216,18 +220,29 @@ static int mxs_dcp_start_dma(struct dcp_async_ctx *actx) static int mxs_dcp_run_aes(struct dcp_async_ctx *actx, struct skcipher_request *req, int init) { + dma_addr_t key_phys, src_phys, dst_phys; struct dcp *sdcp = global_sdcp; struct dcp_dma_desc *desc = &sdcp->coh->desc[actx->chan]; struct dcp_aes_req_ctx *rctx = skcipher_request_ctx(req); int ret; - dma_addr_t key_phys = dma_map_single(sdcp->dev, sdcp->coh->aes_key, - 2 * AES_KEYSIZE_128, - DMA_TO_DEVICE); - dma_addr_t src_phys = dma_map_single(sdcp->dev, sdcp->coh->aes_in_buf, - DCP_BUF_SZ, DMA_TO_DEVICE); - dma_addr_t dst_phys = dma_map_single(sdcp->dev, sdcp->coh->aes_out_buf, - DCP_BUF_SZ, DMA_FROM_DEVICE); + key_phys = dma_map_single(sdcp->dev, sdcp->coh->aes_key, + 2 * AES_KEYSIZE_128, DMA_TO_DEVICE); + ret = dma_mapping_error(sdcp->dev, key_phys); + if (ret) + return ret; + + src_phys = dma_map_single(sdcp->dev, sdcp->coh->aes_in_buf, + DCP_BUF_SZ, DMA_TO_DEVICE); + ret = dma_mapping_error(sdcp->dev, src_phys); + if (ret) + goto err_src; + + dst_phys = dma_map_single(sdcp->dev, sdcp->coh->aes_out_buf, + DCP_BUF_SZ, DMA_FROM_DEVICE); + ret = dma_mapping_error(sdcp->dev, dst_phys); + if (ret) + goto err_dst; if (actx->fill % AES_BLOCK_SIZE) { dev_err(sdcp->dev, "Invalid block size!\n"); @@ -265,10 +280,12 @@ static int mxs_dcp_run_aes(struct dcp_async_ctx *actx, ret = mxs_dcp_start_dma(actx); aes_done_run: + dma_unmap_single(sdcp->dev, dst_phys, DCP_BUF_SZ, DMA_FROM_DEVICE); +err_dst: + dma_unmap_single(sdcp->dev, src_phys, DCP_BUF_SZ, DMA_TO_DEVICE); +err_src: dma_unmap_single(sdcp->dev, key_phys, 2 * AES_KEYSIZE_128, DMA_TO_DEVICE); - dma_unmap_single(sdcp->dev, src_phys, DCP_BUF_SZ, DMA_TO_DEVICE); - dma_unmap_single(sdcp->dev, dst_phys, DCP_BUF_SZ, DMA_FROM_DEVICE); return ret; } @@ -557,6 +574,10 @@ static int mxs_dcp_run_sha(struct ahash_request *req) dma_addr_t buf_phys = dma_map_single(sdcp->dev, sdcp->coh->sha_in_buf, DCP_BUF_SZ, DMA_TO_DEVICE); + ret = dma_mapping_error(sdcp->dev, buf_phys); + if (ret) + return ret; + /* Fill in the DMA descriptor. */ desc->control0 = MXS_DCP_CONTROL0_DECR_SEMAPHORE | MXS_DCP_CONTROL0_INTERRUPT | @@ -589,6 +610,10 @@ static int mxs_dcp_run_sha(struct ahash_request *req) if (rctx->fini) { digest_phys = dma_map_single(sdcp->dev, sdcp->coh->sha_out_buf, DCP_SHA_PAY_SZ, DMA_FROM_DEVICE); + ret = dma_mapping_error(sdcp->dev, digest_phys); + if (ret) + goto done_run; + desc->control0 |= MXS_DCP_CONTROL0_HASH_TERM; desc->payload = digest_phys; } From patchwork Thu Jul 1 18:56:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 12354691 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10E01C11F64 for ; Thu, 1 Jul 2021 18:59:10 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C4BDA61410 for ; Thu, 1 Jul 2021 18:59:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4BDA61410 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=seco.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UXrik/eevOILE59LCsvZxkIcNalr48UWgVkBNfab6T8=; b=4lUlYYw/UMi70F wesDoh8d2LSVMSE9pv1/+SPy7CbxW2BC2qlDJThmrR+B9tii2wfBOk3RY0lGb0D1B4h0mox9XbgCl 5yRmfsqCmL7fZAtsnfLntYg8BLvdjmeETdSeUDTyjNu4dEz+TWnDwPCqh6cs5TIfBaXIp7a7lhJs5 S+aR7CR11W6jZSfgJBTIeCmAxVmufrKKeHfJTv7v16R4jV31NevxMuG/SqWtYMj2Ci6m4fye5AU8k mwZtIkKVzJB96RPZsSPAMkJkzO3+76hTPPqD537bPbdLJe1qAKK1hg1WU/V0Ka/heDq/KbjDoH0EY z1Owun2VryJpFAfEzCig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lz1sF-000oN2-8y; Thu, 01 Jul 2021 18:57:19 +0000 Received: from mail-vi1eur05on2057.outbound.protection.outlook.com ([40.107.21.57] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lz1rs-000oKR-Gm for linux-arm-kernel@lists.infradead.org; Thu, 01 Jul 2021 18:56:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MreYklSR3+DKNZmlXvVypsS1ihvlC+BRekFbDCInAOH36DaC7djahEKyNxYJ0jWinB6Qnn7aQodvsqm0qylYosx+VjH0BMBcpXnzw0D7nm5Q7N4UXIOxShNEzNqUxCYC+tDKnIvjyDokzPt4yNJoplZeU/UAFi0L6fmbJ/GPpetnON2+XI5GQLywl2pZPfp92DgUgJPJOOLW88JaztmqTMMzEaP64ANFfJ7Klrgt4rHtORNIb4lA2E00GjctyonQZPz9pwq3uVEchQt9809RwPJnUQqrgjkcD2RpHI25rgbSNu2VbeLnG13+sGF/+L6OyFfEc74O6LGl4Ue3fwaTEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Xh3qEABbhE8vLDtU0XdLAoYlnf2IRmU9F/WPjCprbpU=; b=ILbgpDsZdZdR8isxmd65iLyNCzqqQhzaXLs5mrQkQvWYN1Ym/JvTgMNjNATstWHUHapcJMOX1YC2NMsPC1e/hK7i/ilhHHQoiLI6P3xb7QKtJH/Xm8CRCyJBbhwyQ9h5jm/ERSGbj/DmC6qbQthw8N52D5icXI9fj0+B6o2tjTE6u9eV2jqa98EnHqYKhRnBYI0D1fyeZ3joNMgztNdBrpGgaT19JMHuCdClrhTHU1pxrtuJfSvi0T5hbN8I4kZPvPbA8TdbsyJ7khqlcKXt6AqGvHDlORSyxh15CFJ+ttUUK0SM6LOXSpu0jlCnqXmZ9QWNEss96kZN6LPDWHmHUA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secospa.onmicrosoft.com; s=selector2-secospa-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Xh3qEABbhE8vLDtU0XdLAoYlnf2IRmU9F/WPjCprbpU=; b=HuWywUeORy+xCTVhZTiwEoeNfSgn2z1+rgTdn9UgjcShD7RB2MMdSRNtRYcVJh/7scHPkRQYXhIgCncnbiwQCesrEcNFOAMntCoEjKGmDb1P23MxkLeAx/RPcOzyPH2XmNZOi0W+4T6+zrpEP3Xp0F+9TsztKbWcNqtRXcw3RCo= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) by DB7PR03MB4618.eurprd03.prod.outlook.com (2603:10a6:10:18::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22; Thu, 1 Jul 2021 18:56:52 +0000 Received: from DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::40d5:3554:c709:6b1b]) by DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::40d5:3554:c709:6b1b%5]) with mapi id 15.20.4264.026; Thu, 1 Jul 2021 18:56:52 +0000 From: Sean Anderson To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: =?utf-8?q?Horia_Geant=C4=83?= , Aymen Sghaier , Richard Weinberger , linux-arm-kernel@lists.infradead.org, Marek Vasut , Sean Anderson Subject: [PATCH v2 2/2] crypto: mxs_dcp: Use sg_mapping_iter to copy data Date: Thu, 1 Jul 2021 14:56:38 -0400 Message-Id: <20210701185638.3437487-3-sean.anderson@seco.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210701185638.3437487-1-sean.anderson@seco.com> References: <20210701185638.3437487-1-sean.anderson@seco.com> X-Originating-IP: [50.195.82.171] X-ClientProxiedBy: MN2PR15CA0050.namprd15.prod.outlook.com (2603:10b6:208:237::19) To DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from plantagenet.inhand.com (50.195.82.171) by MN2PR15CA0050.namprd15.prod.outlook.com (2603:10b6:208:237::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22 via Frontend Transport; Thu, 1 Jul 2021 18:56:51 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 831e7b3e-0f94-4570-5c75-08d93cc1fd28 X-MS-TrafficTypeDiagnostic: DB7PR03MB4618: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6x5BXGl+lxN+mUFBKAMspm/Jmf8QAldxB8SYT+WNPF+o5Y1gij7C1twZNXCdMdc6E8XFwNab7y6beAmyH0LbiK2JXfJIJHUFgYsA5rb78neCI6RQhuXYWdlZBY8+/245Zvgi4McJmEYJ00775JdWDY2D7o/fsfKfVZ+ng3mmKxIZoaoKQqNAn8G7hSCnYL8v2uZ0ikEI4M8zNYyzbueQwtPg2C2OdzV8k9fuNGtKF+secnhfplXun19RqoRiL7l8ua8y32W0mOUKu39lsPSmRNoWThnmHNEGm0VTuvBbTZ0proHSq2ZoszPBtZqvdA8pe8ClrkLhUuszuAxm/FxrW0Cwhwa8H2fRN0s9NaEeG90WWvgbzJe+6kLs4urnCi0jU9QybwPHsdW7/qi8oUi8U7YU3fPWcKNGWAGhiSlO84S+TW0WFgaR6hgXoTp0jqgsh/k43JFN2LKO1AzlIxU8FhNlfNDu3xWIyuk9sk8tV7E04x1OV2vTfRJXKYzccGvQIF4nGwN/qgHsTFCd495Taies9oEsvzoHFFvVFZiaACDEauL+Zx3sBWAMxN8YZmbiAKIEPbDWeWJuVb0SJBkv2mRM14jzYxFqMWQqZWbJrQlq8cMx0k9tBmTPKnmzqkxgZMFVEd0q7RzyjB83Cw/ABvD5xZOO6fhlKVGPJCB8IsMzWtfyhsgG6QCUdAkrsH1V0zHu7yKREYKyK1LkYTGiKg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4523.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(346002)(136003)(376002)(39830400003)(396003)(54906003)(6486002)(110136005)(6666004)(316002)(8676002)(66556008)(38350700002)(83380400001)(38100700002)(956004)(6506007)(66476007)(186003)(26005)(66946007)(16526019)(45080400002)(2616005)(478600001)(86362001)(2906002)(8936002)(1076003)(4326008)(5660300002)(6512007)(52116002)(44832011)(36756003)(107886003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?OwrhsmP2+1nyccpS6dxUushBhsU3?= =?utf-8?q?o/pss13NCQTahsb/9Tptv0bDzXmDnm2d52AhBRaoPn1ZpqZDGAxfRg2IKYai1rl09?= =?utf-8?q?4spEqd7H/3oke5rV3MAwH4qntC9iNvrdVveDBN8XphLfD01lHOTEu5mvcAP/brRTJ?= =?utf-8?q?e152wpiZgpb1U12nNcFISENaAWYA1yeLLr9+rVssrSr26tZGz2bn8v06NRR3xGQXX?= =?utf-8?q?fz0KS2/uEQ/7jcS3UXeZVtv6tvVv2QIpXOWVvrrASrCyuryUtxazp/3acNtjq5jP3?= =?utf-8?q?T8zDlRNCXA2NNIKV/4EGYTVrSL9mOzMxQ14ia6tWxJrwncJSWvJmSZio1PzdKXD1X?= =?utf-8?q?JWTmvHEM+M9wLeYp6BSmihtZcGkFSmD50uY7xa7ojIASMJXmKcuAIHgGhwgjG2BJQ?= =?utf-8?q?/nXAMvLkZRUjw+4O3TAPAbVQdavNLBsyxYPAQJdFRg2XJOkp3wQlszycRF7bLFlDh?= =?utf-8?q?5WFbkxSpENH3wLzCYPyHpoHqR5bm1QDi6CJC/7f6Nn2esbzehc/4S+qxUUQpodq5O?= =?utf-8?q?frP0aOYviIftnAwLD01AUhRqWj7YGD/AswZNJi1wWpJd9Uvs6T3/KOeCTQAvD3LIV?= =?utf-8?q?eL4mInqbhmHibPwMlz5hRlxb8FPmYPUSKCTjpFSPalgs1bpQWVk1y32UXgXpew705?= =?utf-8?q?iyi8/BgBCZwvDY0CV+JGJ5R327GyUk0VpY4+NkGcvJNpfUqV6L9g0LgGA+lDgEcPT?= =?utf-8?q?PumUpmMao6pAx5FgCIqwXxzRi56N+UNP24kq3WPP1RV8eYTEGiC0C9PZRcqL8CcKZ?= =?utf-8?q?4J6YeDVFMSPfWYuB5rRGmHUOD3W7ho4VDl/b0KilWviVhlYcjg6AqsWNZ6JJhIyTk?= =?utf-8?q?qU+aXP9Tlg9XJJ5IrXw1MvxGyOHo2GA2WVkxVbTktCw5l+La6SH1qt6WzIzjS5U2M?= =?utf-8?q?cUFqvgHRmoeCJKwVISFPoYg3TDgYtFbEimLGoHk44KkdV26ubSUlurDUpB2ZIsatZ?= =?utf-8?q?0HlwLfrRrZJLbG1EFHNjxGgF4cr9D6Xit0Dav5cehK6ck7X6xFtI10SDqzKJJ7aKD?= =?utf-8?q?/WUXVFP2ct1LDVeh7fxxHkEHNPC7PqNYME542cky9wc6omElw6Opak24JWDMg1PHs?= =?utf-8?q?c/8XDxTiBP6f8lkQPZ/ONczmvktKbq5+Ui0m+k4bTRv1fMBNAFtvtPsRTgxrb+h3T?= =?utf-8?q?RnCorL7tb+GbpGXCIWQfICInNC5Dpk1XflcCiXsufffgBeAKUfmo5gSRHEd7/YGLd?= =?utf-8?q?KutNoscMQ9eqyVKkmhTAjOUk3GWzX2nPBPv6EC6b4PeyZoJXSPsCFCq/DkJ5FbJV8?= =?utf-8?q?VGO0g66NcXT6Dwp/?= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 831e7b3e-0f94-4570-5c75-08d93cc1fd28 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4523.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jul 2021 18:56:52.4640 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dHZM0tNOxcHsqS7EKsaDvj/U1rgfA0v4sJBKzQe7cRswr+zL2x+SBPANk+G7LIe8wsNwUNoOenNQpJGCuEjyrw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR03MB4618 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210701_115656_586933_1BBCEA82 X-CRM114-Status: GOOD ( 15.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This uses the sg_miter_*() functions to copy data, instead of doing it ourselves. Using sg_copy_buffer() would be better, but this way we don't have to keep traversing the beginning of the scatterlist every time we do another copy. In addition to reducing code size, this fixes the following oops resulting from failing to kmap the page: [ 68.896381] Unable to handle kernel NULL pointer dereference at virtual address 00000ab8 [ 68.904539] pgd = 3561adb3 [ 68.907475] [00000ab8] *pgd=00000000 [ 68.911153] Internal error: Oops: 805 [#1] ARM [ 68.915618] Modules linked in: cfg80211 rfkill des_generic libdes arc4 libarc4 cbc ecb algif_skcipher sha256_generic libsha256 sha1_generic hmac aes_generic libaes cmac sha512_generic md5 md4 algif_hash af_alg i2c_imx i2c_core ci_hdrc_imx ci_hdrc mxs_dcp ulpi roles udc_core imx_sdma usbmisc_imx usb_common firmware_class virt_dma phy_mxs_usb nf_tables nfnetlink ip_tables x_tables ipv6 autofs4 [ 68.950741] CPU: 0 PID: 139 Comm: mxs_dcp_chan/ae Not tainted 5.10.34 #296 [ 68.958501] Hardware name: Freescale i.MX6 Ultralite (Device Tree) [ 68.964710] PC is at memcpy+0xa8/0x330 [ 68.968479] LR is at 0xd7b2bc9d [ 68.971638] pc : [] lr : [] psr: 000f0013 [ 68.977920] sp : c2cbbee4 ip : 00000010 fp : 00000010 [ 68.983159] r10: 00000000 r9 : c3283a40 r8 : 1a5a6f08 [ 68.988402] r7 : 4bfe0ecc r6 : 76d8a220 r5 : c32f9050 r4 : 00000001 [ 68.994945] r3 : 00000ab8 r2 : fffffff0 r1 : c32f9050 r0 : 00000ab8 [ 69.001492] Flags: nzcv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none [ 69.008646] Control: 10c53c7d Table: 83664059 DAC: 00000051 [ 69.014414] Process mxs_dcp_chan/ae (pid: 139, stack limit = 0x667b57ab) [ 69.021133] Stack: (0xc2cbbee4 to 0xc2cbc000) [ 69.025519] bee0: c32f9050 c3235408 00000010 00000010 00000ab8 00000001 bf10406c [ 69.033720] bf00: 00000000 00000000 00000010 00000000 c32355d0 832fb080 00000000 c13de2fc [ 69.041921] bf20: c3628010 00000010 c33d5780 00000ab8 bf1067e8 00000002 c21e5010 c2cba000 [ 69.050125] bf40: c32f8040 00000000 bf106a40 c32f9040 c3283a80 00000001 bf105240 c3234040 [ 69.058327] bf60: ffffe000 c3204100 c2c69800 c2cba000 00000000 bf103b84 00000000 c2eddc54 [ 69.066530] bf80: c3204144 c0140d1c c2cba000 c2c69800 c0140be8 00000000 00000000 00000000 [ 69.074730] bfa0: 00000000 00000000 00000000 c0100114 00000000 00000000 00000000 00000000 [ 69.082932] bfc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 69.091131] bfe0: 00000000 00000000 00000000 00000000 00000013 00000000 00000000 00000000 [ 69.099364] [] (memcpy) from [] (dcp_chan_thread_aes+0x4e8/0x840 [mxs_dcp]) [ 69.108117] [] (dcp_chan_thread_aes [mxs_dcp]) from [] (kthread+0x134/0x160) [ 69.116941] [] (kthread) from [] (ret_from_fork+0x14/0x20) [ 69.124178] Exception stack(0xc2cbbfb0 to 0xc2cbbff8) [ 69.129250] bfa0: 00000000 00000000 00000000 00000000 [ 69.137450] bfc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 69.145648] bfe0: 00000000 00000000 00000000 00000000 00000013 00000000 [ 69.152289] Code: e320f000 e4803004 e4804004 e4805004 (e4806004) Signed-off-by: Sean Anderson --- Changes in v2: - Fix warning when taking the minimum of a u32 and a size_t - Use sg_pcopy_from_buffer to properly deal with partial reads. drivers/crypto/mxs-dcp.c | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c index f397cc5bf102..d19e5ffb5104 100644 --- a/drivers/crypto/mxs-dcp.c +++ b/drivers/crypto/mxs-dcp.c @@ -300,21 +300,20 @@ static int mxs_dcp_aes_block_crypt(struct crypto_async_request *arq) struct scatterlist *dst = req->dst; struct scatterlist *src = req->src; - const int nents = sg_nents(req->src); + int dst_nents = sg_nents(dst); const int out_off = DCP_BUF_SZ; uint8_t *in_buf = sdcp->coh->aes_in_buf; uint8_t *out_buf = sdcp->coh->aes_out_buf; - uint8_t *out_tmp, *src_buf, *dst_buf = NULL; uint32_t dst_off = 0; + uint8_t *src_buf = NULL; uint32_t last_out_len = 0; uint8_t *key = sdcp->coh->aes_key; int ret = 0; - int split = 0; - unsigned int i, len, clen, rem = 0, tlen = 0; + unsigned int i, len, clen, tlen = 0; int init = 0; bool limit_hit = false; @@ -332,7 +331,7 @@ static int mxs_dcp_aes_block_crypt(struct crypto_async_request *arq) memset(key + AES_KEYSIZE_128, 0, AES_KEYSIZE_128); } - for_each_sg(req->src, src, nents, i) { + for_each_sg(req->src, src, sg_nents(src), i) { src_buf = sg_virt(src); len = sg_dma_len(src); tlen += len; @@ -357,34 +356,17 @@ static int mxs_dcp_aes_block_crypt(struct crypto_async_request *arq) * submit the buffer. */ if (actx->fill == out_off || sg_is_last(src) || - limit_hit) { + limit_hit) { ret = mxs_dcp_run_aes(actx, req, init); if (ret) return ret; init = 0; - out_tmp = out_buf; + sg_pcopy_from_buffer(dst, dst_nents, out_buf, + actx->fill, dst_off); + dst_off += actx->fill; last_out_len = actx->fill; - while (dst && actx->fill) { - if (!split) { - dst_buf = sg_virt(dst); - dst_off = 0; - } - rem = min(sg_dma_len(dst) - dst_off, - actx->fill); - - memcpy(dst_buf + dst_off, out_tmp, rem); - out_tmp += rem; - dst_off += rem; - actx->fill -= rem; - - if (dst_off == sg_dma_len(dst)) { - dst = sg_next(dst); - split = 0; - } else { - split = 1; - } - } + actx->fill = 0; } } while (len);