From patchwork Thu Nov 2 08:10:21 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: 117759 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp1746251edm; Thu, 2 Nov 2017 01:12:02 -0700 (PDT) X-Google-Smtp-Source: ABhQp+R973VN2b0Pu/6MbA+Gvxdko8cMH40IgduWs5gGlDEpx4kC5jtpgn69cuMZ33yLSf30cU44 X-Received: by 10.84.224.200 with SMTP id k8mr2399669pln.403.1509610321846; Thu, 02 Nov 2017 01:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509610321; cv=none; d=google.com; s=arc-20160816; b=BtPQ9coYvglRnEAo6DAvUBE1R6B3W9bPIj0F0AxBO6V08NHXrdqr2/D3QFGGHrPpLp FLRBj0Thx+HvbRr64wrMXVqDrZ1K1xkHpzzhxMgmsQak6s306jiwprfWLB7zH7AShtXs oz5CxbT2qhnGt2Dtb9MuAR2T8L7tbqhjcnE0AaAkNi73h3EvJMDzelxJW/EK8xhmuyFz GRlgXdyA1+wIsVg58k1D9XArs+dXGsoofYDzL+nYazKtIIHob8kzB698L4p9pvQqvPj7 G5d9SyWbBvSE7lbrHbuOanemUVLkOZVr+pH3V0qUUmgQmDQqqutxafxYC+BgIUIdg13s XDTg== 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=z7iIpuGcet01SlxaATsjvbt4+s9df2izgYYQcmLtqfA=; b=xLd+R2YKOcqvfry2hPkgUsrceRD3kt+zIbgJ8dsq6mSfRtPKTtJ8fTvYnRgNjC7b6a kWnzvuMQ7Q/7xMMfO/HHZjLrVALnw2rB0qOVYFXMdyO74Gijn5ZCghBLDeP34zgqml44 pGFQx5DaD2e6Ae+xmB0w7yVQRXLtkK1dujvs2TX4nibatY1lTmdeuqtFPceUKGRsmyAB tVylXxeo2ZyqZ8MgNo75xuNNUbU+zTWFAJxxpRVCI9A5SYJEY350hRNHxvh1DxYi7tVm Zqk5ZiA0K8OJR+aJIv0csEYanSs9LFUW/n/3UlsRBP9WHRXiBcidxgvHJSlh2dBZjdxG oI7g== 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 s10si3119470pgd.559.2017.11.02.01.12.01; Thu, 02 Nov 2017 01:12:01 -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 S1755362AbdKBIL7 (ORCPT + 26 others); Thu, 2 Nov 2017 04:11:59 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:55736 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755436AbdKBIKe (ORCPT ); Thu, 2 Nov 2017 04:10: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 4BD351529; Thu, 2 Nov 2017 01:10: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 ABA543F483; Thu, 2 Nov 2017 01:10:32 -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 v2 1/3] staging: ccree: copy IV to DMAable memory Date: Thu, 2 Nov 2017 08:10:21 +0000 Message-Id: <1509610224-14708-2-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509610224-14708-1-git-send-email-gilad@benyossef.com> References: <1509610224-14708-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 | 20 ++++++++++++++++++-- drivers/staging/ccree/ssi_cipher.h | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/staging/ccree/ssi_cipher.c b/drivers/staging/ccree/ssi_cipher.c index 78706f5..0b69103 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,17 @@ 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); + if (!req_ctx->iv) { + rc = -ENOMEM; + goto exit_process; + } + 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 +790,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 +844,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 Thu Nov 2 08:10:22 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: 117756 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp1745030edm; Thu, 2 Nov 2017 01:10:43 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RjrMDQQZl001TfHYxFgKgn2sfG/6GxkTCt18sqh4EylOQIyIjrREG12cMPEuy7ci6zqo5t X-Received: by 10.99.56.19 with SMTP id f19mr2707410pga.328.1509610243479; Thu, 02 Nov 2017 01:10:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509610243; cv=none; d=google.com; s=arc-20160816; b=hv+2t0ZYPhO/NjWOe7sqnrIWrcL4GdBR18M+5iZoC7ywzlyFG7De71o/dw/syvjwrc 7qHFN40Dhd4jO19mgzCFJDodQ1jGxHOGvKi4SrAno0QoCOom6W7vWHZSN8W9rmSzM/J8 dCaHjtQqGDvzEO0cyc9ehMvk9aeU1b7YBgs1Ra51TQR2U8Evcoc2UO7k5qPGtcI26m2v ZGD/tGR4aw0A5bRShpiY4Eak2iHifh+sw158bcjX+bwd+XhhZww77o36EqcBTmAJ7to+ LKI6KB05O0oHbfpvfveWxTINOpdNlVLnKnEtLtVnOFwfVYw14M46AoBOO4Gkpbq5pYVx toFw== 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=RhWSaA8jTxGH+KheblKatZKgv1CT5z7MrX9RS6thXGs=; b=AT8yEr6vspx+jxas2RsZFM/B1Y3PgzoCu2GNnA/Umh8KaDcB1Is7hbC6tkb93jLSme b01pt44uwiVnKPOTwU1BKmuODWdpxSO9hjpiZ/mQ9GB2srJBjDo/0SFeRGcO62d+f7dw vMOE1BCoYtg7+mKZquZvOVlmQyhMmOMuDD4fUJ/nbmZk6pDqpEaWqlfML0WfyjrEwGHt HTQnm+ygzhCMdv48vkLxFbg3Djq1yLNk4KdXWmkmHGVKVxDnqjU0oNmkw1krXYs0iMie aALR2aulJGRgKPmjsE8yCJb9nUHEqxCZdIfyPsRzgA9dZ5qHmCzTuVNbTphwmawx1U8B bMmQ== 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 o15si2908503pgf.485.2017.11.02.01.10.43; Thu, 02 Nov 2017 01:10: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 S1755501AbdKBIKk (ORCPT + 26 others); Thu, 2 Nov 2017 04:10:40 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:55746 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752759AbdKBIKh (ORCPT ); Thu, 2 Nov 2017 04:10:37 -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 488EB1529; Thu, 2 Nov 2017 01:10: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 A61F93F483; Thu, 2 Nov 2017 01:10: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 v2 2/3] staging: ccree: handle limiting of DMA masks Date: Thu, 2 Nov 2017 08:10:22 +0000 Message-Id: <1509610224-14708-3-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509610224-14708-1-git-send-email-gilad@benyossef.com> References: <1509610224-14708-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 | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/drivers/staging/ccree/ssi_driver.c b/drivers/staging/ccree/ssi_driver.c index 5f03c25..1d4c7bb 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); @@ -256,15 +257,29 @@ static int init_cc_resources(struct platform_device *plat_dev) } dev_dbg(dev, "Registered to IRQ: %d\n", new_drvdata->irq); + 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 (rc) { + dev_err(dev, "Error: failed in dma_set_mask, mask=%par\n", + &dma_mask); + goto post_drvdata_err; + } + rc = cc_clk_on(new_drvdata); if (rc) goto post_drvdata_err; - if (!dev->dma_mask) - dev->dma_mask = &dev->coherent_dma_mask; - - if (!dev->coherent_dma_mask) - dev->coherent_dma_mask = DMA_BIT_MASK(DMA_BIT_MASK_LEN); /* Verify correct mapping */ signature_val = CC_HAL_READ_REGISTER(CC_REG_OFFSET(HOST_RGF, HOST_SIGNATURE)); From patchwork Thu Nov 2 08:10:23 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: 117758 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp1745146edm; Thu, 2 Nov 2017 01:10:50 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RGRprHCq174mkf+bE4+CwnikyHjnCvdiX51SZFvd4ob2aG72a9z8P04uluyn8uLpjNL7nz X-Received: by 10.84.164.165 with SMTP id w34mr2375211pla.308.1509610250190; Thu, 02 Nov 2017 01:10:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509610250; cv=none; d=google.com; s=arc-20160816; b=Q7K1cTs0yrqjD62Nhuq+/e7kT1q7UQt9tEP9mW6SW6zpnrHnbCE+rsSnh8Jepw+j+s kHYAdyfO1lrbofAMkfUATFycwM6aXDUVXus6O+pnEv1c9L1TSilQiObgGPlSQYiv4Fvc TxsjHicINzMxcD6qH/9LStWlaOrS4CJwCzZ+ImK4/u48K9g/JSKB0hi6b3b6OuuAaiPh dbsp0o1pygNJqQLK83wUBP8WCacwbyIRg3n5JFgz1OG1sWIUV1Xuj0GyI0qwQHyQgw/T Bay8+DhyfpCBnxZoVP7oF4IRf78iDM7enWdIgLM7Cln1euJ6yHS5NqG8pkf0h+TI5ajL 8kMQ== 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=BhdqPDg0k6JRD5mCC0kje5kGlL6OogCRgqXtYFax08I=; b=hqwJEBbRzQXTY5T5od4r95QWLNVu1Cu9Puw5X9rSyc+Fq2qfoY2w3w4rN8QSqso+71 KotUWTIkZe8tYtNZuXWs+jr02sfxBuhnB4Zp8MI2toxJAO222ixdbKEI9fxw/M7y3IvE mtesNAVeaXw45K54NfrEtmhvuur4wUEqIIbmU5P+WUwFUMm/1ZHajutIFbchf+n0lBDH SIRwo+PhlTsCKTLmLATbDsDCosVmbj27jgP4mSL6hK7PYsHRLo4ljH4KdW43V+p5ClIG dIHA4yrZVz383h9DHQQXPOd+iDHLSEXvx3C8tAquwb9X2euwkQP8nmHq4isG2mm/uSBU dJsg== 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 r1si1709573plb.314.2017.11.02.01.10.49; Thu, 02 Nov 2017 01:10:50 -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 S932705AbdKBIKq (ORCPT + 26 others); Thu, 2 Nov 2017 04:10:46 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:55756 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755504AbdKBIKk (ORCPT ); Thu, 2 Nov 2017 04:10: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 3E5C81529; Thu, 2 Nov 2017 01:10:40 -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 9E1E53F483; Thu, 2 Nov 2017 01:10:38 -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 v2 3/3] staging: ccree: remove dead code Date: Thu, 2 Nov 2017 08:10:23 +0000 Message-Id: <1509610224-14708-4-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509610224-14708-1-git-send-email-gilad@benyossef.com> References: <1509610224-14708-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 0b69103..ee85cbf 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; };