From patchwork Mon May 20 11:50:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 164599 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp184082ili; Mon, 20 May 2019 04:50:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwLGzvTazRr1JfzkX7TRHjMgWdwnAGVxXYD1MCbJ0og5CmkTAPeAyIh7uyGa8DoxDQdIi60 X-Received: by 2002:aa7:9afc:: with SMTP id y28mr80038931pfp.101.1558353040277; Mon, 20 May 2019 04:50:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558353040; cv=none; d=google.com; s=arc-20160816; b=plZeVbDkeoP9S3jDXhwtWaq2n0+vLQcdIGxa7rzWHW2liNTOx2vqDtrzZbXWHOXJLA qgr+oXzEzU2h1YIQHZg1iQnvTrpecHxa92OoA/aIpxqoXW0Z3HS+JQdo5xONJUF14CNh HQ5AM/pAKP+mX2LAAN7vdAAv4hISit92ifPrTpTgzLRXdtFDnjUbbXjGzFW2HWh35PP8 k6q/mhCt5a71DFSO7PBqkCyNElkDB/Vg2Wo0ipAhqrPGlktTraPTgF7MJuS39JUeAfwH fgSe7ux4Kp/vL8Edx9LNDMv1qXTLCM342kjrf1h1J7KNM4p5F2uxiv3eXxzVhZgXHCr2 jNRw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jBa/4lfxlhySIR6mrJWQlih1J8FM1zKWUV9zS3y3E/E=; b=tBcvHorTHBAzRAYm8zdxLzfAxYjiho04q1kDr7C5hNMZV3dFAWKFxv0Rsv9HZSnasW D9qhaegbpBgHlz3vWhz6TjM/rHwbP9lBf1Il3u/mo50ydOv+ACtoyk2F1FzpfBYxxtA0 drAZanjYpkVhc5a5ncWLLWDX2jRk275ElsYyi5fGS/tHsyHb00IE1tCeLw1j/FxeLrPb XCu+MSwzt1TYMawbOiyro7Ek1CZ4hSTvlsgLoYRyCjObV7GOSpRiZIBdmwugJIK7lREQ JPKMQlnrM/Ns2HTLawac3jqynqoGUn9uhkL2UZAUTvtwwNZUs/n1HdmEzhxN1vP4IZO5 Us8Q== 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 f90si18377478plb.25.2019.05.20.04.50.39; Mon, 20 May 2019 04:50:40 -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 S1731770AbfETLuj (ORCPT + 30 others); Mon, 20 May 2019 07:50:39 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:43982 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730606AbfETLui (ORCPT ); Mon, 20 May 2019 07:50:38 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8030015AB; Mon, 20 May 2019 04:50:37 -0700 (PDT) Received: from e110176-lin.kfn.arm.com (unknown [10.50.4.178]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D7BE13F5AF; Mon, 20 May 2019 04:50:35 -0700 (PDT) From: Gilad Ben-Yossef To: gregkh@linuxfoundation.org, Herbert Xu , "David S. Miller" Cc: stable@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [STABLE PATCH 1/2] crypto: ccree: zap entire sg on aead request unmap Date: Mon, 20 May 2019 14:50:23 +0300 Message-Id: <20190520115025.16457-2-gilad@benyossef.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115025.16457-1-gilad@benyossef.com> References: <20190520115025.16457-1-gilad@benyossef.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We were trying to be clever zapping out of the cache only the required length out of scatter list on AEAD request completion and getting it wrong. As Knuth said: "when in douby, use brute force". Zap the whole length of the scatter list. Signed-off-by: Gilad Ben-Yossef --- drivers/crypto/ccree/cc_buffer_mgr.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) -- 2.21.0 diff --git a/drivers/crypto/ccree/cc_buffer_mgr.c b/drivers/crypto/ccree/cc_buffer_mgr.c index 0ee1c52da0a4..0774bf54fcab 100644 --- a/drivers/crypto/ccree/cc_buffer_mgr.c +++ b/drivers/crypto/ccree/cc_buffer_mgr.c @@ -568,11 +568,7 @@ void cc_unmap_aead_request(struct device *dev, struct aead_request *req) { struct aead_req_ctx *areq_ctx = aead_request_ctx(req); unsigned int hw_iv_size = areq_ctx->hw_iv_size; - struct crypto_aead *tfm = crypto_aead_reqtfm(req); struct cc_drvdata *drvdata = dev_get_drvdata(dev); - u32 dummy; - bool chained; - u32 size_to_unmap = 0; if (areq_ctx->mac_buf_dma_addr) { dma_unmap_single(dev, areq_ctx->mac_buf_dma_addr, @@ -629,22 +625,12 @@ void cc_unmap_aead_request(struct device *dev, struct aead_request *req) dev_dbg(dev, "Unmapping src sgl: req->src=%pK areq_ctx->src.nents=%u areq_ctx->assoc.nents=%u assoclen:%u cryptlen=%u\n", sg_virt(req->src), areq_ctx->src.nents, areq_ctx->assoc.nents, req->assoclen, req->cryptlen); - size_to_unmap = req->assoclen + req->cryptlen; - if (areq_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_ENCRYPT) - size_to_unmap += areq_ctx->req_authsize; - if (areq_ctx->is_gcm4543) - size_to_unmap += crypto_aead_ivsize(tfm); - dma_unmap_sg(dev, req->src, - cc_get_sgl_nents(dev, req->src, size_to_unmap, - &dummy, &chained), - DMA_BIDIRECTIONAL); + dma_unmap_sg(dev, req->src, sg_nents(req->src), DMA_BIDIRECTIONAL); if (req->src != req->dst) { dev_dbg(dev, "Unmapping dst sgl: req->dst=%pK\n", sg_virt(req->dst)); - dma_unmap_sg(dev, req->dst, - cc_get_sgl_nents(dev, req->dst, size_to_unmap, - &dummy, &chained), + dma_unmap_sg(dev, req->dst, sg_nents(req->dst), DMA_BIDIRECTIONAL); } if (drvdata->coherent && From patchwork Mon May 20 11:50:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 164600 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp184115ili; Mon, 20 May 2019 04:50:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqweTR1Be8D/k9F+9aQabHn8AbG53FNLWkGvB8Dkgyj4DQAiOEqHW0+w6VMFuNJqPezrbuPy X-Received: by 2002:a17:902:ac1:: with SMTP id 59mr75194343plp.294.1558353043186; Mon, 20 May 2019 04:50:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558353043; cv=none; d=google.com; s=arc-20160816; b=otrLGdJCDuMa8Z48x9sEFQtonqXv887PIFpj+mOsW+UaQmQpJaRB9quP6t87/1xugy qL27wZaPotuSx++U17aNutQBuDjy0iuZYTQFch7lm2t0atLPpRmFEVucHDCyG1atMZsE 7NP7aYaA/Mq6tFo5yPSNhQU2v/azpZgwuqaL3xwBfRRA8mx/3aoN+ZF4Hfm5jNlydZsF TZYPNU+fGV/ircrHkweUNfUvsPDXark6NOR4aQptQ7NHFLn03lsv+UY5oFYLgT0IUNYX 5Uta2oaHGb75RoNJ263RiA2XbADlsEkKv32UuR+yHn/AnVAFN8RT9SN9mIcTcDk1Pe0Q eE6A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=9sHd1U8vSNuHF67stiUZrWXu+cErGIkJmpE1J+L4mLU=; b=XP8HpIWlhGJwgwzuHrPq0PH+OaysDFZEhqMbZEhcD9Voe35rSlHav8JTYisJe6uguQ YWu7lkVwAW+1y+lNBBEtWs6DhyXQuQS3KrdeFJQaypmBLEItuxdLMVedkstJtSz2ioEp fnJlM5XQkyOKCjDylOBTMB65GL/p3TVA5iretQvKvDc+djQ1oJ19JCcElpfm9wnySLWN hfGtMmvmKU15CLbGDZUDqaCaOupWJI8VfQcQSURkczjolDb3LQQkX56KIvLAsUQLbclo qptAjxgRwelYACv7ix8Cn9vx/iTW2IBuCopjqBhAiW0urDQbSCGaQ1zBAUlcxR6BoyHK NGBw== 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 v25si10342863pgn.566.2019.05.20.04.50.42; Mon, 20 May 2019 04:50:43 -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 S1731916AbfETLum (ORCPT + 30 others); Mon, 20 May 2019 07:50:42 -0400 Received: from foss.arm.com ([217.140.101.70]:43990 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731777AbfETLuk (ORCPT ); Mon, 20 May 2019 07:50:40 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1E45715AD; Mon, 20 May 2019 04:50:40 -0700 (PDT) Received: from e110176-lin.kfn.arm.com (unknown [10.50.4.178]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7584D3F5AF; Mon, 20 May 2019 04:50:38 -0700 (PDT) From: Gilad Ben-Yossef To: gregkh@linuxfoundation.org, Herbert Xu , "David S. Miller" Cc: stable@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [STABLE PATCH 2/2] crypto: ccree: fix backlog notifications Date: Mon, 20 May 2019 14:50:24 +0300 Message-Id: <20190520115025.16457-3-gilad@benyossef.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115025.16457-1-gilad@benyossef.com> References: <20190520115025.16457-1-gilad@benyossef.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We were doing backlog notification callbacks via a cipher/hash/aead request structure cast to the base structure, which may or may not work based on how the structure is laid in memory and is not safe. Fix it by delegating the backlog notification to the appropriate internal callbacks which are type aware. Signed-off-by: Gilad Ben-Yossef --- drivers/crypto/ccree/cc_aead.c | 4 ++++ drivers/crypto/ccree/cc_cipher.c | 4 ++++ drivers/crypto/ccree/cc_hash.c | 28 +++++++++++++++++++-------- drivers/crypto/ccree/cc_request_mgr.c | 11 ++++++++--- 4 files changed, 36 insertions(+), 11 deletions(-) -- 2.21.0 diff --git a/drivers/crypto/ccree/cc_aead.c b/drivers/crypto/ccree/cc_aead.c index a3527c00b29a..8c08a50a4008 100644 --- a/drivers/crypto/ccree/cc_aead.c +++ b/drivers/crypto/ccree/cc_aead.c @@ -220,6 +220,10 @@ static void cc_aead_complete(struct device *dev, void *cc_req, int err) struct crypto_aead *tfm = crypto_aead_reqtfm(cc_req); struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm); + /* BACKLOG notification */ + if (err == -EINPROGRESS) + goto done; + cc_unmap_aead_request(dev, areq); /* Restore ordinary iv pointer */ diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c index d9c17078517b..202526648e4a 100644 --- a/drivers/crypto/ccree/cc_cipher.c +++ b/drivers/crypto/ccree/cc_cipher.c @@ -654,6 +654,9 @@ static void cc_cipher_complete(struct device *dev, void *cc_req, int err) unsigned int ivsize = crypto_skcipher_ivsize(sk_tfm); unsigned int len; + if (err == -EINPROGRESS) + goto done; + cc_unmap_cipher_request(dev, req_ctx, ivsize, src, dst); switch (ctx_p->cipher_mode) { @@ -687,6 +690,7 @@ static void cc_cipher_complete(struct device *dev, void *cc_req, int err) kzfree(req_ctx->iv); +done: skcipher_request_complete(req, err); } diff --git a/drivers/crypto/ccree/cc_hash.c b/drivers/crypto/ccree/cc_hash.c index 2c4ddc8fb76b..e824ab60b59c 100644 --- a/drivers/crypto/ccree/cc_hash.c +++ b/drivers/crypto/ccree/cc_hash.c @@ -280,8 +280,12 @@ static void cc_update_complete(struct device *dev, void *cc_req, int err) dev_dbg(dev, "req=%pK\n", req); - cc_unmap_hash_request(dev, state, req->src, false); - cc_unmap_req(dev, state, ctx); + if (err != -EINPROGRESS) { + /* Not a BACKLOG notification */ + cc_unmap_hash_request(dev, state, req->src, false); + cc_unmap_req(dev, state, ctx); + } + req->base.complete(&req->base, err); } @@ -295,9 +299,13 @@ static void cc_digest_complete(struct device *dev, void *cc_req, int err) dev_dbg(dev, "req=%pK\n", req); - cc_unmap_hash_request(dev, state, req->src, false); - cc_unmap_result(dev, state, digestsize, req->result); - cc_unmap_req(dev, state, ctx); + if (err != -EINPROGRESS) { + /* Not a BACKLOG notification */ + cc_unmap_hash_request(dev, state, req->src, false); + cc_unmap_result(dev, state, digestsize, req->result); + cc_unmap_req(dev, state, ctx); + } + req->base.complete(&req->base, err); } @@ -311,9 +319,13 @@ static void cc_hash_complete(struct device *dev, void *cc_req, int err) dev_dbg(dev, "req=%pK\n", req); - cc_unmap_hash_request(dev, state, req->src, false); - cc_unmap_result(dev, state, digestsize, req->result); - cc_unmap_req(dev, state, ctx); + if (err != -EINPROGRESS) { + /* Not a BACKLOG notification */ + cc_unmap_hash_request(dev, state, req->src, false); + cc_unmap_result(dev, state, digestsize, req->result); + cc_unmap_req(dev, state, ctx); + } + req->base.complete(&req->base, err); } diff --git a/drivers/crypto/ccree/cc_request_mgr.c b/drivers/crypto/ccree/cc_request_mgr.c index 83a8aaae61c7..ddaa41de7ae7 100644 --- a/drivers/crypto/ccree/cc_request_mgr.c +++ b/drivers/crypto/ccree/cc_request_mgr.c @@ -336,10 +336,12 @@ static void cc_enqueue_backlog(struct cc_drvdata *drvdata, struct cc_bl_item *bli) { struct cc_req_mgr_handle *mgr = drvdata->request_mgr_handle; + struct device *dev = drvdata_to_dev(drvdata); spin_lock_bh(&mgr->bl_lock); list_add_tail(&bli->list, &mgr->backlog); ++mgr->bl_len; + dev_dbg(dev, "+++bl len: %d\n", mgr->bl_len); spin_unlock_bh(&mgr->bl_lock); tasklet_schedule(&mgr->comptask); } @@ -349,7 +351,7 @@ static void cc_proc_backlog(struct cc_drvdata *drvdata) struct cc_req_mgr_handle *mgr = drvdata->request_mgr_handle; struct cc_bl_item *bli; struct cc_crypto_req *creq; - struct crypto_async_request *req; + void *req; bool ivgen; unsigned int total_len; struct device *dev = drvdata_to_dev(drvdata); @@ -359,17 +361,20 @@ static void cc_proc_backlog(struct cc_drvdata *drvdata) while (mgr->bl_len) { bli = list_first_entry(&mgr->backlog, struct cc_bl_item, list); + dev_dbg(dev, "---bl len: %d\n", mgr->bl_len); + spin_unlock(&mgr->bl_lock); + creq = &bli->creq; - req = (struct crypto_async_request *)creq->user_arg; + req = creq->user_arg; /* * Notify the request we're moving out of the backlog * but only if we haven't done so already. */ if (!bli->notif) { - req->complete(req, -EINPROGRESS); + creq->user_cb(dev, req, -EINPROGRESS); bli->notif = true; }