From patchwork Tue Oct 31 11:56:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 117600 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3807724qgn; Tue, 31 Oct 2017 04:56:36 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QnCBtXjrP8uYfIfT7kCW45V/t7elIGf0Tf5dhYnIeBpit6x+KMxjH28VH033+RYHIdiPMw X-Received: by 10.98.64.141 with SMTP id f13mr1789524pfd.213.1509450996614; Tue, 31 Oct 2017 04:56:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509450996; cv=none; d=google.com; s=arc-20160816; b=h5lrMRIJIUz0HO6AVYAZZur5yov2ihDQ0SzgCbxK1ZQPgCrhdky1EEuL8Yj91vfCSL Ah8sf3jRYgMcBZ3D6Fb3oz52x3WtYIooRhqmI38Im4KAcHtlMPY8V4Og4epVvBtHg7gM g/y9f1MESJ/upJh0vVYYhtLT6HZrf1BXtKCLR+Rxj2HbVSdnk7tbCgHADxjmyDGZum6B rGjROLQHZ7UG3O0cOkzz6a5oohcZuZw9fDeYnr5hlXbk3Qt4b86YVw8A2cGtYI2Yhru5 fEnpaN9tCJ9tRlblVRAcG3IA1kATvWvMr7vq2fu2q6wDO80klh7SSHjwDnG16GwXGdxX hNpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=EyL3SN1xfenMH6xp6Tivrh0bXKnzTIHYbnPBkE3TEJU=; b=t6bbdy6QNkrKYd1vHLmxMFIAktkzjNGaXGod+FWW55NpQc5vge5X+L1quJVBnz9a+7 y8MY4y9HxgeNGMYG/944OWkK/JTWStkMtcBriegs53tz0ZsxhEHT7JIW6IERkhq7FcsX MGCm+JpnTRwDG2JouGyWX/r2j9eOh2q78NoN1AIakvrjO3ns46LS7af3quUOmw6Gib8Z e/01aJffI1N7tGl1H4Ezc3dXhTBGjOHdrOyA/sMibI5m0puVxjO4OcEMQRe2Gcy3DvTO Ug/ZNxeb440UNdfQmf955RTvJFomopIbdnpFBZ81MxQ2c6c1lTa1AmJdtV4WrSaXeR+L YqdA== 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 b91si1387044plb.819.2017.10.31.04.56.36; Tue, 31 Oct 2017 04:56:36 -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 S1752088AbdJaL4f (ORCPT + 27 others); Tue, 31 Oct 2017 07:56:35 -0400 Received: from foss.arm.com ([217.140.101.70]:34750 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750872AbdJaL4a (ORCPT ); Tue, 31 Oct 2017 07:56:30 -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 4E74B1435; Tue, 31 Oct 2017 04:56:30 -0700 (PDT) Received: from sugar.kfn.arm.com (unknown [10.45.48.167]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6182F3F483; Tue, 31 Oct 2017 04:56:27 -0700 (PDT) From: Gilad Ben-Yossef To: Greg Kroah-Hartman Cc: Ofir Drang , linux-crypto@vger.kernel.org, driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] staging: ccree: copy IV to DMAable memory Date: Tue, 31 Oct 2017 11:56:15 +0000 Message-Id: <1509450978-17784-2-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509450978-17784-1-git-send-email-gilad@benyossef.com> References: <1509450978-17784-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We are being passed an IV buffer from unknown origin, which may be stack allocated and thus not safe for DMA. Allocate a DMA safe buffer for the IV and use that instead. Signed-off-by: Gilad Ben-Yossef --- drivers/staging/ccree/ssi_cipher.c | 16 ++++++++++++++-- drivers/staging/ccree/ssi_cipher.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/staging/ccree/ssi_cipher.c b/drivers/staging/ccree/ssi_cipher.c index 78706f5..0784c86 100644 --- a/drivers/staging/ccree/ssi_cipher.c +++ b/drivers/staging/ccree/ssi_cipher.c @@ -695,6 +695,7 @@ static int ssi_blkcipher_complete(struct device *dev, struct ablkcipher_request *req = (struct ablkcipher_request *)areq; ssi_buffer_mgr_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst); + kfree(req_ctx->iv); /*Decrease the inflight counter*/ if (ctx_p->flow_mode == BYPASS && ctx_p->drvdata->inflight_counter > 0) @@ -757,6 +758,13 @@ static int ssi_blkcipher_process( rc = 0; goto exit_process; } + + /* The IV we are handed may be allocted from the stack so + * we must copy it to a DMAable buffer before use. + */ + req_ctx->iv = kmalloc(ivsize, GFP_KERNEL); + memcpy(req_ctx->iv, info, ivsize); + /*For CTS in case of data size aligned to 16 use CBC mode*/ if (((nbytes % AES_BLOCK_SIZE) == 0) && (ctx_p->cipher_mode == DRV_CIPHER_CBC_CTS)) { ctx_p->cipher_mode = DRV_CIPHER_CBC; @@ -778,7 +786,9 @@ static int ssi_blkcipher_process( /* STAT_PHASE_1: Map buffers */ - rc = ssi_buffer_mgr_map_blkcipher_request(ctx_p->drvdata, req_ctx, ivsize, nbytes, info, src, dst); + rc = ssi_buffer_mgr_map_blkcipher_request(ctx_p->drvdata, req_ctx, + ivsize, nbytes, req_ctx->iv, + src, dst); if (unlikely(rc != 0)) { dev_err(dev, "map_request() failed\n"); goto exit_process; @@ -830,8 +840,10 @@ static int ssi_blkcipher_process( if (cts_restore_flag != 0) ctx_p->cipher_mode = DRV_CIPHER_CBC_CTS; - if (rc != -EINPROGRESS) + if (rc != -EINPROGRESS) { kfree(req_ctx->backup_info); + kfree(req_ctx->iv); + } return rc; } diff --git a/drivers/staging/ccree/ssi_cipher.h b/drivers/staging/ccree/ssi_cipher.h index f499962..25e6335 100644 --- a/drivers/staging/ccree/ssi_cipher.h +++ b/drivers/staging/ccree/ssi_cipher.h @@ -43,6 +43,7 @@ struct blkcipher_req_ctx { u32 out_nents; u32 out_mlli_nents; u8 *backup_info; /*store iv for generated IV flow*/ + u8 *iv; bool is_giv; struct mlli_params mlli_params; }; From patchwork Tue Oct 31 11:56:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 117602 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3808057qgn; Tue, 31 Oct 2017 04:56:57 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QN0gyiGk1zMoJb1VXW5ONewwy8jzo1mzAWfAA9cf+l3c84jz1U0SoKJ4iTgNc/ht0uE0lZ X-Received: by 10.99.123.78 with SMTP id k14mr1592626pgn.351.1509451016980; Tue, 31 Oct 2017 04:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509451016; cv=none; d=google.com; s=arc-20160816; b=OlrblVeBzznPO4MEYDxofSM06psP8vr/ko7Inuo0Z5Hn8BnwT99F+5ItjgLoqC7cmA /DumsH21ZjkbrdYUj8W2bpGg1wAWfJC3L3sn5rjxrF6DtX2CfPsqSne3BFHG/HV23YlY Nm7+Mr3GnCNIhasbx7xv989Lxci9Y06kD3lkdhL8rkvRQFTGmR/bYl/t/D5Ih/yo+vnn Y6iWc/Hqmrfh3CJZKV/0CH7AlgUtRndJc3U9i66RrRQ5eSVXcDK7alKiueqBiLmlIqa7 cFErY7Qbw0jprGquktKLBU6x/SvqcgTP5gPUfSS/TtH0RH6gjocmhjdssc5PidjYAmVL oEgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=srNvpf5ixopc+gDcjAIDre1YqASWVPN/kM6NCPMAzco=; b=YlXBwNFvgi9n2gF4GL+xUxPyt2xKz8Tzt8KEVpoQam49Ju0fxfOdnEf65kPWo1/heW Gqq+rC5trmHgVRldXq5XONtNwQ+7WfnTqQFy0DZD2nUoL+eJ9+d+LVGH4pORenpmV6uQ Q8q7MCXXjb94g4VfZQhM7/FFmhqCP0dyRUqI0gFfAhDEo4kPCY6UA/Pz7Ioqm9wjbeEx kGEUtB0REzBo2DQ3KIm7VqUgUbCh8d5RypDPns5PCoo7hXu98HQGIv2fDnlSfmv2ONIM cpMdNrCIXQ9WhjT0Nml6+APvjpglm1Cx8DJjGPY8gvvb9YvOhQU7k17WJHGE+HLHEOFm TFUw== 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 g24si1559501pfd.403.2017.10.31.04.56.56; Tue, 31 Oct 2017 04:56:56 -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 S1752774AbdJaL4z (ORCPT + 27 others); Tue, 31 Oct 2017 07:56:55 -0400 Received: from foss.arm.com ([217.140.101.70]:34760 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751925AbdJaL4e (ORCPT ); Tue, 31 Oct 2017 07:56:34 -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 429101435; Tue, 31 Oct 2017 04:56:34 -0700 (PDT) Received: from sugar.kfn.arm.com (unknown [10.45.48.167]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A91483F483; Tue, 31 Oct 2017 04:56:31 -0700 (PDT) From: Gilad Ben-Yossef To: Greg Kroah-Hartman Cc: Ofir Drang , linux-crypto@vger.kernel.org, driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] staging: ccree: handle limiting of DMA masks Date: Tue, 31 Oct 2017 11:56:16 +0000 Message-Id: <1509450978-17784-3-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509450978-17784-1-git-send-email-gilad@benyossef.com> References: <1509450978-17784-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Properly handle limiting of DMA masks based on device and bus capabilities. Signed-off-by: Gilad Ben-Yossef --- drivers/staging/ccree/ssi_driver.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/drivers/staging/ccree/ssi_driver.c b/drivers/staging/ccree/ssi_driver.c index 5f03c25..6d4269f 100644 --- a/drivers/staging/ccree/ssi_driver.c +++ b/drivers/staging/ccree/ssi_driver.c @@ -208,6 +208,7 @@ static int init_cc_resources(struct platform_device *plat_dev) struct device *dev = &plat_dev->dev; struct device_node *np = dev->of_node; u32 signature_val; + dma_addr_t dma_mask; int rc = 0; new_drvdata = devm_kzalloc(dev, sizeof(*new_drvdata), GFP_KERNEL); @@ -260,11 +261,24 @@ static int init_cc_resources(struct platform_device *plat_dev) if (rc) goto post_drvdata_err; - if (!dev->dma_mask) - dev->dma_mask = &dev->coherent_dma_mask; + if (!plat_dev->dev.dma_mask) + plat_dev->dev.dma_mask = &plat_dev->dev.coherent_dma_mask; + + dma_mask = (dma_addr_t)(DMA_BIT_MASK(DMA_BIT_MASK_LEN)); + while (dma_mask > 0x7fffffffUL) { + if (dma_supported(&plat_dev->dev, dma_mask)) { + rc = dma_set_coherent_mask(&plat_dev->dev, dma_mask); + if (!rc) + break; + } + dma_mask >>= 1; + } - if (!dev->coherent_dma_mask) - dev->coherent_dma_mask = DMA_BIT_MASK(DMA_BIT_MASK_LEN); + if (rc) { + dev_err(dev, "Error: failed in dma_set_mask, mask=%par\n", + &dma_mask); + goto post_drvdata_err; + } /* Verify correct mapping */ signature_val = CC_HAL_READ_REGISTER(CC_REG_OFFSET(HOST_RGF, HOST_SIGNATURE)); From patchwork Tue Oct 31 11:56:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 117601 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3807824qgn; Tue, 31 Oct 2017 04:56:43 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RmxsbJYEKS9Veb5XYEZ3Ou5lROidji4op1k2TscNPYjjbeNJqYmUzNns1wCaZEj6OxR6Sw X-Received: by 10.84.195.3 with SMTP id i3mr1692332pld.322.1509451003005; Tue, 31 Oct 2017 04:56:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509451002; cv=none; d=google.com; s=arc-20160816; b=FqUhwU1cZbMspil+/+b8m7XpN+kdDK89XP7nsZKXnOGeA1JYpp1oQJ0JiLsbzNgQeR 5O8KEmlSAWvtzy8qgd7L8CYOz+JY5CMVWhP0iJLNEtQsaFcXmbY5GO3DJ/QM+53Btxyh nM+43a0z5n5Kg/WeOPjHSKHlU/gcMjh7VlDhY313d3tMpvHTXePpF16FKVM2QPsMuCvm XO2TQVCaN7cp/9lI20GDFVinDmA8J/uSamPfuLfi1hwpAk/sO1o9IHiJo8A43/ZX62Cy NQTA4MShVIoWnFdVY/HdDBwFUkfDvtWWE+hag18aDLbK5XkX6Ii+w+auJjSZ9uhgQJsH JOhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=X6a3qs9mhltJT9z5URJCv6CWyKFz6qolWejNqG9mNHs=; b=dj24MgJckcF9pi/lq1U8xnLrFZO80H2tDuMe+1hxz4sC06+NSvDDHjWw9gYv32t+Xw 8BNbb64keNluUrZ3vElh2hS8LrHTrR6OMtHnN4EcTwWiT5e4QI32xeqgKji7Sljf1l+W gJZ34zLf4OFTs3QFkbUCdzzSVgCQjdhRMJ8vwO4LUffoc15DCcC+kbG3Bi3vyk9pTUtH KtJLGGVW7Vm71tHI18z5diXnFgv48EdOwvIBOphwEun7wztzU1yx7olixg41dlO1cUfq ynmPHYTJuX3Qoca5QNhVNvfXY0+3DMNkAs9YdIDCRrpdAwxL+uj71WAs5WpXw2kNkjB/ XWLw== 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 k4si1373534pgs.459.2017.10.31.04.56.42; Tue, 31 Oct 2017 04:56:42 -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 S1752386AbdJaL4l (ORCPT + 27 others); Tue, 31 Oct 2017 07:56:41 -0400 Received: from foss.arm.com ([217.140.101.70]:34768 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752126AbdJaL4i (ORCPT ); Tue, 31 Oct 2017 07:56: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 DF2701435; Tue, 31 Oct 2017 04:56:37 -0700 (PDT) Received: from sugar.kfn.arm.com (unknown [10.45.48.167]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 85D093F483; Tue, 31 Oct 2017 04:56:35 -0700 (PDT) From: Gilad Ben-Yossef To: Greg Kroah-Hartman Cc: Ofir Drang , linux-crypto@vger.kernel.org, driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] staging: ccree: remove dead code Date: Tue, 31 Oct 2017 11:56:17 +0000 Message-Id: <1509450978-17784-4-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509450978-17784-1-git-send-email-gilad@benyossef.com> References: <1509450978-17784-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The inflight_counter field is updated in a single location and never used. Remove it. Signed-off-by: Gilad Ben-Yossef --- drivers/staging/ccree/ssi_cipher.c | 4 ---- drivers/staging/ccree/ssi_driver.h | 1 - 2 files changed, 5 deletions(-) -- 2.7.4 diff --git a/drivers/staging/ccree/ssi_cipher.c b/drivers/staging/ccree/ssi_cipher.c index 0784c86..42844ae 100644 --- a/drivers/staging/ccree/ssi_cipher.c +++ b/drivers/staging/ccree/ssi_cipher.c @@ -697,10 +697,6 @@ static int ssi_blkcipher_complete(struct device *dev, ssi_buffer_mgr_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst); kfree(req_ctx->iv); - /*Decrease the inflight counter*/ - if (ctx_p->flow_mode == BYPASS && ctx_p->drvdata->inflight_counter > 0) - ctx_p->drvdata->inflight_counter--; - if (areq) { /* * The crypto API expects us to set the req->info to the last diff --git a/drivers/staging/ccree/ssi_driver.h b/drivers/staging/ccree/ssi_driver.h index 488f665..e01c880 100644 --- a/drivers/staging/ccree/ssi_driver.h +++ b/drivers/staging/ccree/ssi_driver.h @@ -134,7 +134,6 @@ struct ssi_drvdata { void *fips_handle; void *ivgen_handle; void *sram_mgr_handle; - u32 inflight_counter; struct clk *clk; bool coherent; };