From patchwork Sun Sep 20 18:37:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11788075 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AAA066CB for ; Sun, 20 Sep 2020 18:37:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D3ED2158C for ; Sun, 20 Sep 2020 18:37:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="pT0FFND6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726384AbgITShc (ORCPT ); Sun, 20 Sep 2020 14:37:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726055AbgITSh1 (ORCPT ); Sun, 20 Sep 2020 14:37:27 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86704C061755 for ; Sun, 20 Sep 2020 11:37:26 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id d4so10005461wmd.5 for ; Sun, 20 Sep 2020 11:37:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jTdlzUzyc1hcRCjE509a2kDcbNHBKMDXHMkrLBJjCcg=; b=pT0FFND6nkoHYyotdgwU1JAtZKe+QpWMkWB0/vahBAzG/8Ld4jH7LOF+KhWyjcj83t 5Sx1nwXbpU0PNjl2Y003G0PYjPMwRiIqD5CYsm3Z0nBKnZ52AW5B3f5Hhj8p7itelMfp fvBatPUhYCOePXCZd1QIH91PiEHEvt+VDnDRsjG3ZauxunjMmzsJ+bmE99QNcPDxN6rS mKT67ZLBJo3J9fkL813BBeFdlQUanY2I2v07DKoQLz8k78j1GXzlghb79gZU2bah7KKg 4p4K2uuaQccbL2gIHbH3zwiC8/XjHX0tiV71d3nbLb9AJadcKfPh7hAuDZKn0Mj0E89F Hdqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jTdlzUzyc1hcRCjE509a2kDcbNHBKMDXHMkrLBJjCcg=; b=hO0nNSa2qNfRo8tfes7hPS5+BB0TdGysA09xMc3TIZeB5OlAElf2qgjQOkDGqYRQU8 MsayZ7pEx4BcgX0/eTAkHA7vb1b5gqrlknBm16EWut3mCDg4tnrGvckP6Ai6HtSYIuNm dEnvSTyyfq858IALgtagmgj6tQDoZdX+2OhF6mSHt/bKwycTVXG0rlCTICQvFmwlLW/U hnI0J+zB7kl1O4EjJQCniqfJfaVDq/QRrTi0o+yqRSlKKJXZVWA3I0tEvNxBO8qtZmC2 LXxmlPtzc8zhqz3td76tT2wvGv7CdQS1c1yRXGWgiVqA37CXvakn4IiV0/YPFhbHICb2 6kMw== X-Gm-Message-State: AOAM531Bd4+e4C+MIuC0uIsGrAc9Ec5DSgKnTOWFAicoBXzJe4NnZK5a cXutKAUSNubTt/AlbxLQmNQJ5Q== X-Google-Smtp-Source: ABdhPJznL0wnKPFRx+ll8rXF6fFCp51XOjtzRgf3arfEI4ScF5bVizdGKfVQJuxQR3n2Q1QXlekbrg== X-Received: by 2002:a05:600c:414b:: with SMTP id h11mr26441143wmm.20.1600627045206; Sun, 20 Sep 2020 11:37:25 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id e18sm16419841wrx.50.2020.09.20.11.37.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Sep 2020 11:37:24 -0700 (PDT) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH v2 1/7] crypto: sun4i-ss: linearize buffers content must be kept Date: Sun, 20 Sep 2020 18:37:12 +0000 Message-Id: <1600627038-40000-2-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> References: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org When running the non-optimized cipher function, SS produce partial random output. This is due to linearize buffers being reseted after each loop. Fixes: 8d3bcb9900ca ("crypto: sun4i-ss - reduce stack usage") Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c index b72de8939497..b92d175b5d2a 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -163,6 +163,8 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) unsigned int todo; struct sg_mapping_iter mi, mo; unsigned int oi, oo; /* offset for in and out */ + char buf[4 * SS_RX_MAX];/* buffer for linearize SG src */ + char bufo[4 * SS_TX_MAX]; /* buffer for linearize SG dst */ unsigned int ob = 0; /* offset in buf */ unsigned int obo = 0; /* offset in bufo*/ unsigned int obl = 0; /* length of data in bufo */ @@ -233,8 +235,6 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) while (oleft) { if (ileft) { - char buf[4 * SS_RX_MAX];/* buffer for linearize SG src */ - /* * todo is the number of consecutive 4byte word that we * can read from current SG @@ -295,8 +295,6 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) oo = 0; } } else { - char bufo[4 * SS_TX_MAX]; /* buffer for linearize SG dst */ - /* * read obl bytes in bufo, we read at maximum for * emptying the device From patchwork Sun Sep 20 18:37:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11788077 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B78C86CB for ; Sun, 20 Sep 2020 18:37:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C35920897 for ; Sun, 20 Sep 2020 18:37:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="o6uy/Y2f" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726367AbgITShc (ORCPT ); Sun, 20 Sep 2020 14:37:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726333AbgITSh2 (ORCPT ); Sun, 20 Sep 2020 14:37:28 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4D41C0613D1 for ; Sun, 20 Sep 2020 11:37:27 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id q9so10014662wmj.2 for ; Sun, 20 Sep 2020 11:37:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IhTFOXooJMFxAaaEHQf3e3fIzkNVzwZdrWDdh3u1EUQ=; b=o6uy/Y2fgeouP5kDFiEtEWyZQ7lXmtHPJbfEjxbGSTzWDHdn+eNakZ+Gzg/pGOLKnB RFzvEO05pGIiS64ev14813GpI23vjHFh1kGdEzHu4jfAQ1suDQBBG3Z37JOeLU30eDcP hhsGWK/W50Ftu/3407ErlSgOzEWqcuKJnnJvNPnM0eEPbsyljMStKuk4ATkcg5j2nO46 2i9lY+aF9IbsQGLP6HIpwTfHeXjJ5c5L+4C/MrE4n4r6fwNxv+sT5Ri080hVz8PKJ3bE 741Zm6Cj5gk3gbTyJmL9Py6XioTv7HDjqjwFSNnlijavF40vEiIxzUvIXIME6oH696qQ FAfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IhTFOXooJMFxAaaEHQf3e3fIzkNVzwZdrWDdh3u1EUQ=; b=aOaeU2X+2ADPejTvjp5FWAXK1LRNc/5G+8P5spqu6t/pw3cPQGAv4ib8ofM94ex/0J h2aukUjwR5GObSLCmDHkCNPSsAMSkf60CtMRb/yqFeRaxj/+9+klNxbNs4ih4Fo7bKMC MjDRfmmkNLhXVzm9jExPB4X5ZjQK5s4paLatT44/6PN3Xjc2DILwu/0a+ePGEnTxlGap vrDHr1/Q00oWgkkla5Nj8KeUPeBld3xBGwzWa4PUQrJGfJORL6N7UDBxSl83+oH0O45V j+Zb+krh34FokaDOgEUJHmm3S3k27DpMfQLdYRzZDcuimRhrZoQ21t2lkRjW89aDG3zZ ycvQ== X-Gm-Message-State: AOAM531UcgdB0EvzMfrT6kUADEwe9GJjEAIVsRxdcxNlFPbPNU9E5dQy Y1Asb3rHjOv0OuOXSsgEWnwVYA== X-Google-Smtp-Source: ABdhPJynWACDMHNpXhG0zgpk0FI5q7hOkyx5gYWEvchzv4bGQbq/PWLObDidNv2Zs0juQasUPbkAmQ== X-Received: by 2002:a1c:dd87:: with SMTP id u129mr26267083wmg.172.1600627046307; Sun, 20 Sep 2020 11:37:26 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id e18sm16419841wrx.50.2020.09.20.11.37.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Sep 2020 11:37:25 -0700 (PDT) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe , stable@vger.kernel.org Subject: [PATCH v2 2/7] crypto: sun4i-ss: checking sg length is not sufficient Date: Sun, 20 Sep 2020 18:37:13 +0000 Message-Id: <1600627038-40000-3-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> References: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The optimized cipher function need length multiple of 4 bytes. But it get sometimes odd length. This is due to SG data could be stored with an offset. So the fix is to check also if the offset is aligned with 4 bytes. Fixes: 6298e948215f2 ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator") Cc: Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c index b92d175b5d2a..2614640231dc 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -188,12 +188,12 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) * we can use the SS optimized function */ while (in_sg && no_chunk == 1) { - if (in_sg->length % 4) + if (in_sg->length % 4 || !IS_ALIGNED(in_sg->offset, sizeof(u32))) no_chunk = 0; in_sg = sg_next(in_sg); } while (out_sg && no_chunk == 1) { - if (out_sg->length % 4) + if (out_sg->length % 4 || !IS_ALIGNED(out_sg->offset, sizeof(u32))) no_chunk = 0; out_sg = sg_next(out_sg); } From patchwork Sun Sep 20 18:37:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11788083 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8DC3717C5 for ; Sun, 20 Sep 2020 18:37:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 73C732158C for ; Sun, 20 Sep 2020 18:37:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="NJyb9kIF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726445AbgITShr (ORCPT ); Sun, 20 Sep 2020 14:37:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726342AbgITShc (ORCPT ); Sun, 20 Sep 2020 14:37:32 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A0ECC0613D3 for ; Sun, 20 Sep 2020 11:37:28 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id z9so10367390wmk.1 for ; Sun, 20 Sep 2020 11:37:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=huiz4hWuEDAzBaczeTBJaesBVDz4VU4ls/AvOgJWeOk=; b=NJyb9kIFE/CthzhB4unI7Fmylr/83s0udqDUg2mdWAjKOkkMxeZcaiuYQNanTBeUJB GdfMBRs/1TR5EI7Fw7Spdcz6XKGxReckwGNC+dM5iviTrjJja2r5dGsaKCIS+BJli/BK QP1A8RsAko1XFRDsQE6TtGErG85J7k3ZHlf956ywSzC+huS0B8AQL+WmQL67SwCy0K9T PUv+Xq277PgRT4gKtsLqxjc58rynv0Ero3znor32MPMMcpLPezUJYXuxJ1/DDie4/AlS rT5jM4X1IFvqjIG1MdKk7E24u4X3klqR7C1G/t710ZHP+DkmX4sFmNCP4H8ZE4LKE3mJ uBsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=huiz4hWuEDAzBaczeTBJaesBVDz4VU4ls/AvOgJWeOk=; b=HP3Z9VrONW57pBJkmVet4M1xxr/bIEhT+8hto5Ng3WCMxZ0iY0cmozmRp7OmGxzoql ZPNY+Q0JIt1GVyLwqzJCrDGSWMcL8+IioDqZVZ6Mzqo9uHGff6pa+4zcJ5YQrWindyUV TiRbKTnxrZczAiq1jNu5h6hai1mPumaDEwuUwu5ZKeh5mSh27eRtFV+ALCfpT1GZXTsA fme3sVwRhelFq+sucdJ9DxVv/dReq4cwtJnfQLE3G3BBmHhrZyMsIIMIFFK6ckQCj0QS Kn1wasdFX+0/aCAK8Yk1ocWjfTfe4ToR5wOOJA6WNtPCY55DWjMRH9IqprkK6U7+MrFT TwOw== X-Gm-Message-State: AOAM5323NSVt5fQNjVVrhNnRKJc18DyL8khBs7pL8z/WBvnNe96sI19w Si1yR4P9hG4BrMtdDOSsVwUxdgPpp7/nkQ== X-Google-Smtp-Source: ABdhPJxlW7YndNuMU5bTLBRvti9rCp3LJ0Og/iDwJDuLz/GP8bWpCiL+y6oZwC3+DzIN4Mq+kjfm2g== X-Received: by 2002:a1c:23c8:: with SMTP id j191mr25370500wmj.64.1600627047323; Sun, 20 Sep 2020 11:37:27 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id e18sm16419841wrx.50.2020.09.20.11.37.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Sep 2020 11:37:26 -0700 (PDT) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe , stable@vger.kernel.org Subject: [PATCH v2 3/7] crypto: sun4i-ss: IV register does not work on A10 and A13 Date: Sun, 20 Sep 2020 18:37:14 +0000 Message-Id: <1600627038-40000-4-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> References: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Allwinner A10 and A13 SoC have a version of the SS which produce invalid IV in IVx register. Instead of adding a variant for those, let's convert SS to produce IV directly from data. Fixes: 6298e948215f2 ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator") Cc: Signed-off-by: Corentin Labbe --- .../allwinner/sun4i-ss/sun4i-ss-cipher.c | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c index 2614640231dc..c6c25204780d 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -20,6 +20,7 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) unsigned int ivsize = crypto_skcipher_ivsize(tfm); struct sun4i_cipher_req_ctx *ctx = skcipher_request_ctx(areq); u32 mode = ctx->mode; + void *backup_iv = NULL; /* when activating SS, the default FIFO space is SS_RX_DEFAULT(32) */ u32 rx_cnt = SS_RX_DEFAULT; u32 tx_cnt = 0; @@ -42,6 +43,13 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) return -EINVAL; } + if (areq->iv && ivsize > 0 && mode & SS_DECRYPTION) { + backup_iv = kzalloc(ivsize, GFP_KERNEL); + if (!backup_iv) + return -ENOMEM; + scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - ivsize, ivsize, 0); + } + spin_lock_irqsave(&ss->slock, flags); for (i = 0; i < op->keylen; i += 4) @@ -102,9 +110,12 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) } while (oleft); if (areq->iv) { - for (i = 0; i < 4 && i < ivsize / 4; i++) { - v = readl(ss->base + SS_IV0 + i * 4); - *(u32 *)(areq->iv + i * 4) = v; + if (mode & SS_DECRYPTION) { + memcpy(areq->iv, backup_iv, ivsize); + kfree_sensitive(backup_iv); + } else { + scatterwalk_map_and_copy(areq->iv, areq->dst, areq->cryptlen - ivsize, + ivsize, 0); } } @@ -161,6 +172,7 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) unsigned int ileft = areq->cryptlen; unsigned int oleft = areq->cryptlen; unsigned int todo; + void *backup_iv = NULL; struct sg_mapping_iter mi, mo; unsigned int oi, oo; /* offset for in and out */ char buf[4 * SS_RX_MAX];/* buffer for linearize SG src */ @@ -204,6 +216,13 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) if (need_fallback) return sun4i_ss_cipher_poll_fallback(areq); + if (areq->iv && ivsize > 0 && mode & SS_DECRYPTION) { + backup_iv = kzalloc(ivsize, GFP_KERNEL); + if (!backup_iv) + return -ENOMEM; + scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - ivsize, ivsize, 0); + } + spin_lock_irqsave(&ss->slock, flags); for (i = 0; i < op->keylen; i += 4) @@ -324,9 +343,12 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) } } if (areq->iv) { - for (i = 0; i < 4 && i < ivsize / 4; i++) { - v = readl(ss->base + SS_IV0 + i * 4); - *(u32 *)(areq->iv + i * 4) = v; + if (mode & SS_DECRYPTION) { + memcpy(areq->iv, backup_iv, ivsize); + kfree_sensitive(backup_iv); + } else { + scatterwalk_map_and_copy(areq->iv, areq->dst, areq->cryptlen - ivsize, + ivsize, 0); } } From patchwork Sun Sep 20 18:37:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11788079 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F37A86CB for ; Sun, 20 Sep 2020 18:37:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D90FC21789 for ; Sun, 20 Sep 2020 18:37:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="cxfwt+vj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726342AbgITShs (ORCPT ); Sun, 20 Sep 2020 14:37:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726353AbgITShc (ORCPT ); Sun, 20 Sep 2020 14:37:32 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AE6FC0613D7 for ; Sun, 20 Sep 2020 11:37:29 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id l15so10178051wmh.1 for ; Sun, 20 Sep 2020 11:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Gd2hvr/SAKzjKtmSl3X2mEioPmDAlGeI7zVBmc2l4K8=; b=cxfwt+vj0IMFYW+JQ/I7RatzPtFw1+jGLORAJybIyLwiBbd8P6wU5H00s9S1g4XMCY UtVX46Nx5geEh0rX6GT/R1NqCO0wAXNvq3PTMp5xIYww5KxBWgMxCm08fYTjWz8EDRly ORI6B+JW2+/ifJ9LxD6u6F21uUfuTr3CMQTPHbky+JTF7baBn+u9aYHI31U0DUYBtoPK Gku7/dytrVz3juRK5t7OQNxRwpCr840JqSDM2TwYFdt0VxmmGUHG41RSjfnRWNaCOPDB T0dou1BYOe5x7NuYgGSLZ8uaOHyw0lvLaQmG7zhUGOm7By0kKCa6jx/62Q5Gu59Csz3q Mhag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Gd2hvr/SAKzjKtmSl3X2mEioPmDAlGeI7zVBmc2l4K8=; b=V2nlRA7TFhKSzjwuXpM4EPnHmD6VDesqO8FpFdMt6xoUq1pAbq/x3eS1Ezdnm2TWz6 XEJDzLbaPvPeDOS/2vNiLdGHj2EUWjXo7AFEyFKiZ19OxJnu2kesnmO37u5BcRhruDG3 KpgnLOXKC13luuOLc2kELa9Tg6D7nF49JfV8ZCcErL+1B8z1Lssgc/cFO3fGAMYDohR4 Dp6SB05bXX+vx+nkg+0NJ1Qth+kvGwImUfnniS1atNz5Ba9qOyqFFnURXTClaDIQ3jg0 m2ubOinkoTgTv2DidJACo3qVe+2xiFyUYuQmE9dNK/4osXPpGkt5LjWTAiNSNsA4vH8v bdhg== X-Gm-Message-State: AOAM533tqNPwwBxY+k8F1cX1Je8sESgJOjJnjMGxhqXSlODuCpkq1+n8 ynYVCsoPM5obOVpfzdahVDvtHg== X-Google-Smtp-Source: ABdhPJxFgf7fh7vgfuCj7uPWgYnoR/9rCAgoeOSkNbbVfdIgvzC4Qjnot2R01IIEr2PfqXC84D6//w== X-Received: by 2002:a1c:f208:: with SMTP id s8mr27172664wmc.85.1600627048332; Sun, 20 Sep 2020 11:37:28 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id e18sm16419841wrx.50.2020.09.20.11.37.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Sep 2020 11:37:27 -0700 (PDT) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe , stable@vger.kernel.org Subject: [PATCH v2 4/7] crypto: sun4i-ss: handle BigEndian for cipher Date: Sun, 20 Sep 2020 18:37:15 +0000 Message-Id: <1600627038-40000-5-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> References: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Ciphers produce invalid results on BE. Key and IV need to be written in LE. Fixes: 6298e948215f2 ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator") Cc: Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c index c6c25204780d..a05889745097 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -52,13 +52,13 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) spin_lock_irqsave(&ss->slock, flags); - for (i = 0; i < op->keylen; i += 4) - writel(*(op->key + i / 4), ss->base + SS_KEY0 + i); + for (i = 0; i < op->keylen / 4; i++) + writel(cpu_to_le32(op->key[i]), ss->base + SS_KEY0 + i * 4); if (areq->iv) { for (i = 0; i < 4 && i < ivsize / 4; i++) { v = *(u32 *)(areq->iv + i * 4); - writel(v, ss->base + SS_IV0 + i * 4); + writel(cpu_to_le32(v), ss->base + SS_IV0 + i * 4); } } writel(mode, ss->base + SS_CTL); @@ -225,13 +225,13 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) spin_lock_irqsave(&ss->slock, flags); - for (i = 0; i < op->keylen; i += 4) - writel(*(op->key + i / 4), ss->base + SS_KEY0 + i); + for (i = 0; i < op->keylen / 4; i++) + writel(cpu_to_le32(op->key[i]), ss->base + SS_KEY0 + i * 4); if (areq->iv) { for (i = 0; i < 4 && i < ivsize / 4; i++) { v = *(u32 *)(areq->iv + i * 4); - writel(v, ss->base + SS_IV0 + i * 4); + writel(cpu_to_le32(v), ss->base + SS_IV0 + i * 4); } } writel(mode, ss->base + SS_CTL); From patchwork Sun Sep 20 18:37:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11788073 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3474716BC for ; Sun, 20 Sep 2020 18:37:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1200F20897 for ; Sun, 20 Sep 2020 18:37:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="RoIaqdq+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726303AbgITShc (ORCPT ); Sun, 20 Sep 2020 14:37:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726359AbgITShc (ORCPT ); Sun, 20 Sep 2020 14:37:32 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73D7CC0613D8 for ; Sun, 20 Sep 2020 11:37:30 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id x14so10475772wrl.12 for ; Sun, 20 Sep 2020 11:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3OyGuodJwZo3ZuRGej7X4SpPtHUnPs0FAyD9Ejylqzc=; b=RoIaqdq+e0795nGzWShgL380T4BXMnZSXrHw09SiRa8w9HbuTKl71pGS0QgH/OJ3xK nLUahSLe8gAbMiJimVsCuqjkAPxybtlKWXzXixZbr2Myp59+9ee+ARC/T9sJLR269Grf YhL0XBMnfoUH72cjtkCVwLHAVmm9Aa13p+VoKPslqNNKo6tgFyUPJdOXA+Qf9sEuWJwJ es9/Ow95Iv+UGuomjo0eIflGjp6rwtMR+XVH3bUXTMxrBYwpk7wSVf8WsHxI91tCWA+h eYJuF5rHLUkAnnf8k7Hq9BetVFQopgZa6ZhTg+t0hnd1J2hDjnekRp0WHbh0hOhsSEZw If7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3OyGuodJwZo3ZuRGej7X4SpPtHUnPs0FAyD9Ejylqzc=; b=mRfMKmUM0KWWZ0k81P6yR64KP5os/wjAvD2uQ/GkcG3O7cO9phLI51tJphsRr9FvVV mO68fr5RRK+mM3p84RMuL5ubJ0bxftEKzgv2fCGHjxyIAdI4hghkGI3JpC0OZq+Bletu tjzUtg6FopJm91aOmr8ejesii/C75jZyynrqGuwZs/X/eGdDmm7HUcq4z0/aXJe1PJrd NDptPE5DC+h0c1zsdJlhDRsQPUiSVYXYWEgQ3P0RrKuuNpahrV+kQ1dgygf2RK3V4Hv3 OCFUd2B+ccPofbqVat7aBXYVeRPOl8zhntxtAXXuJTfaW7y9MMNvOF342OJrXEYFe7m5 l3Lg== X-Gm-Message-State: AOAM533u9IFkMw2tgZK56HI/tqRUq2HE6x3MwKkc00kOjPXHsmQJaT3D Un3eRSypiIB6bOlaju6mf5hmAQ== X-Google-Smtp-Source: ABdhPJww+6NOi8GJs7+7r6z4gKijDA+FXf0aSA2CdHowZYjtNN8SgZILS8uTKvVlG8N477QqbY45ew== X-Received: by 2002:a5d:4591:: with SMTP id p17mr48173433wrq.408.1600627049213; Sun, 20 Sep 2020 11:37:29 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id e18sm16419841wrx.50.2020.09.20.11.37.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Sep 2020 11:37:28 -0700 (PDT) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe , stable@vger.kernel.org Subject: [PATCH v2 5/7] crypto: sun4i-ss: initialize need_fallback Date: Sun, 20 Sep 2020 18:37:16 +0000 Message-Id: <1600627038-40000-6-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> References: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The need_fallback is never initialized and seem to be always true at runtime. So all hardware operations are always bypassed. Fixes: 0ae1f46c55f87 ("crypto: sun4i-ss - fallback when length is not multiple of blocksize") Cc: Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c index a05889745097..f3bdf465b02e 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -181,7 +181,7 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) unsigned int obo = 0; /* offset in bufo*/ unsigned int obl = 0; /* length of data in bufo */ unsigned long flags; - bool need_fallback; + bool need_fallback = false; if (!areq->cryptlen) return 0; From patchwork Sun Sep 20 18:37:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11788069 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4317D6CB for ; Sun, 20 Sep 2020 18:37:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1851921789 for ; Sun, 20 Sep 2020 18:37:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="umtzhgm3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726397AbgITShd (ORCPT ); Sun, 20 Sep 2020 14:37:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726381AbgITShc (ORCPT ); Sun, 20 Sep 2020 14:37:32 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 859DFC0613DC for ; Sun, 20 Sep 2020 11:37:31 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id x23so9993576wmi.3 for ; Sun, 20 Sep 2020 11:37:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PfuX2llufHc6JPJBoO7/4snMovEOdNyPWliA8GWvlXg=; b=umtzhgm3utglbBDavWHCM7PELk/9I0gdJuF0+B5bhWyBZv7XY5rOpHLLEKaDz8WDZo 0yPiHNwNUAi1tqdK258koOX+x17k1MyLRbuzSK0AiYDnNseA/oKwc00Cg2jkfUVIc+lR 6YzhL+viq7kQSPcSwZCnID4WPtUcPFmLJQ9Tyxi6dDrpRaOOY5K6AibsN7PXPQUMuDg0 FxlVY5TsHtofOK9/v5Xmp4SrbOaGAAnjeElypdzXkTEHtcrMBAWE+jEN0EdRm5LNy1AR MmD3ElDA+vWvFMDkkq6L6JhEKTbpEHibtV2ZfFkhLuk76ub7lOl1m3NKrNSL537vLdN6 rDbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PfuX2llufHc6JPJBoO7/4snMovEOdNyPWliA8GWvlXg=; b=GjenstSqSUYs+sU/8pApq3DJTOc9Rf2mQhSnbtxb0vTm62Rlk1dBfZBG55+nhysgJO 5r3HHk542DRW08wELo75WuZRnP8kNJgzUEaD494cyOG7rdWHBnv/Slstpd59rttKkRZJ KRFhb8wVY2IN84lV+QarU9JBO63iT2ycpRDroqCq+k9PVK/TKvEpnChyrQM3uxCS9cbZ 317JXFqxQaF8aqjDE0RKI1ByQmYxPim7tEtpS/bqkzhEfeRh4aK91OzKx19bk8ODkcDZ WmafrT2Jsyx7jUtrBMWCHZsYcRvTdN0P5I0JT9X+Z+hfLWVyKS4Mz6tfHK/C1nrq2cjn YZFw== X-Gm-Message-State: AOAM530iJmzlVo/WfYG5nY7SekxUZYeIU8jeQ+y0JWnPPhBdXWw+GFHv o/attapfS4fKzrgbPKfcY4o2yQ== X-Google-Smtp-Source: ABdhPJw0kSnAEbNdwoks/vJl5Cx5jWBJh1SUn5HksGjIuzeiziMqi2nVYFafBnOSkv0lQl7CxLMHmg== X-Received: by 2002:a05:600c:414e:: with SMTP id h14mr25733695wmm.2.1600627050161; Sun, 20 Sep 2020 11:37:30 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id e18sm16419841wrx.50.2020.09.20.11.37.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Sep 2020 11:37:29 -0700 (PDT) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH v2 6/7] crypto: sun4i-ss: enabled stats via debugfs Date: Sun, 20 Sep 2020 18:37:17 +0000 Message-Id: <1600627038-40000-7-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> References: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This patch enable to access usage stats for each algorithm. Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/Kconfig | 9 ++++ .../allwinner/sun4i-ss/sun4i-ss-cipher.c | 21 ++++++++ .../crypto/allwinner/sun4i-ss/sun4i-ss-core.c | 54 +++++++++++++++++++ .../crypto/allwinner/sun4i-ss/sun4i-ss-hash.c | 8 +++ .../crypto/allwinner/sun4i-ss/sun4i-ss-prng.c | 5 ++ drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h | 11 ++++ 6 files changed, 108 insertions(+) diff --git a/drivers/crypto/allwinner/Kconfig b/drivers/crypto/allwinner/Kconfig index 0e72543ad1f1..e9b7f7e3d307 100644 --- a/drivers/crypto/allwinner/Kconfig +++ b/drivers/crypto/allwinner/Kconfig @@ -51,6 +51,15 @@ config CRYPTO_DEV_SUN4I_SS_PRNG Select this option if you want to provide kernel-side support for the Pseudo-Random Number Generator found in the Security System. +config CRYPTO_DEV_SUN4I_SS_DEBUG + bool "Enable sun4i-ss stats" + depends on CRYPTO_DEV_SUN4I_SS + depends on DEBUG_FS + help + Say y to enable sun4i-ss debug stats. + This will create /sys/kernel/debug/sun4i-ss/stats for displaying + the number of requests per algorithm. + config CRYPTO_DEV_SUN8I_CE tristate "Support for Allwinner Crypto Engine cryptographic offloader" select CRYPTO_SKCIPHER diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c index f3bdf465b02e..2ec359eaa4cf 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -34,6 +34,10 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) struct sg_mapping_iter mi, mo; unsigned int oi, oo; /* offset for in and out */ unsigned long flags; +#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); + struct sun4i_ss_alg_template *algt; +#endif if (!areq->cryptlen) return 0; @@ -50,6 +54,12 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - ivsize, ivsize, 0); } +#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG + algt = container_of(alg, struct sun4i_ss_alg_template, alg.crypto); + algt->stat_opti++; + algt->stat_bytes += areq->cryptlen; +#endif + spin_lock_irqsave(&ss->slock, flags); for (i = 0; i < op->keylen / 4; i++) @@ -134,7 +144,13 @@ static int noinline_for_stack sun4i_ss_cipher_poll_fallback(struct skcipher_requ struct sun4i_tfm_ctx *op = crypto_skcipher_ctx(tfm); struct sun4i_cipher_req_ctx *ctx = skcipher_request_ctx(areq); int err; +#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); + struct sun4i_ss_alg_template *algt; + algt = container_of(alg, struct sun4i_ss_alg_template, alg.crypto); + algt->stat_fb++; +#endif skcipher_request_set_tfm(&ctx->fallback_req, op->fallback_tfm); skcipher_request_set_callback(&ctx->fallback_req, areq->base.flags, areq->base.complete, areq->base.data); @@ -223,6 +239,11 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - ivsize, ivsize, 0); } +#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG + algt->stat_req++; + algt->stat_bytes += areq->cryptlen; +#endif + spin_lock_irqsave(&ss->slock, flags); for (i = 0; i < op->keylen / 4; i++) diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c index a2b67f7f8a81..d044eb8f88b6 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c @@ -234,6 +234,53 @@ static struct sun4i_ss_alg_template ss_algs[] = { #endif }; +#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG +static int sun4i_ss_dbgfs_read(struct seq_file *seq, void *v) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(ss_algs); i++) { + if (!ss_algs[i].ss) + continue; + switch (ss_algs[i].type) { + case CRYPTO_ALG_TYPE_SKCIPHER: + seq_printf(seq, "%s %s reqs=%lu opti=%lu fallback=%lu tsize=%lu\n", + ss_algs[i].alg.crypto.base.cra_driver_name, + ss_algs[i].alg.crypto.base.cra_name, + ss_algs[i].stat_req, ss_algs[i].stat_opti, ss_algs[i].stat_fb, + ss_algs[i].stat_bytes); + break; + case CRYPTO_ALG_TYPE_RNG: + seq_printf(seq, "%s %s reqs=%lu tsize=%lu\n", + ss_algs[i].alg.rng.base.cra_driver_name, + ss_algs[i].alg.rng.base.cra_name, + ss_algs[i].stat_req, ss_algs[i].stat_bytes); + break; + case CRYPTO_ALG_TYPE_AHASH: + seq_printf(seq, "%s %s reqs=%lu\n", + ss_algs[i].alg.hash.halg.base.cra_driver_name, + ss_algs[i].alg.hash.halg.base.cra_name, + ss_algs[i].stat_req); + break; + } + } + return 0; +} + +static int sun4i_ss_dbgfs_open(struct inode *inode, struct file *file) +{ + return single_open(file, sun4i_ss_dbgfs_read, inode->i_private); +} + +static const struct file_operations sun4i_ss_debugfs_fops = { + .owner = THIS_MODULE, + .open = sun4i_ss_dbgfs_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +#endif + /* * Power management strategy: The device is suspended unless a TFM exists for * one of the algorithms proposed by this driver. @@ -454,6 +501,13 @@ static int sun4i_ss_probe(struct platform_device *pdev) break; } } + +#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG + /* Ignore error of debugfs */ + ss->dbgfs_dir = debugfs_create_dir("sun4i-ss", NULL); + ss->dbgfs_stats = debugfs_create_file("stats", 0444, ss->dbgfs_dir, ss, + &sun4i_ss_debugfs_fops); +#endif return 0; error_alg: i--; diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c index dc35edd90034..3da60256f498 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c @@ -197,6 +197,10 @@ static int sun4i_hash(struct ahash_request *areq) int in_r, err = 0; size_t copied = 0; __le32 wb = 0; +#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG + struct ahash_alg *alg = __crypto_ahash_alg(tfm->base.__crt_alg); + struct sun4i_ss_alg_template *algt; +#endif dev_dbg(ss->dev, "%s %s bc=%llu len=%u mode=%x wl=%u h0=%0x", __func__, crypto_tfm_alg_name(areq->base.tfm), @@ -397,6 +401,10 @@ static int sun4i_hash(struct ahash_request *areq) */ hash_final: +#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG + algt = container_of(alg, struct sun4i_ss_alg_template, alg.hash); + algt->stat_req++; +#endif /* write the remaining words of the wait buffer */ if (op->len) { diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c index 729aafdbea84..102f8a90ce0f 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c @@ -32,6 +32,11 @@ int sun4i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src, if (err < 0) return err; +#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG + algt->stat_req++; + algt->stat_bytes += todo; +#endif + spin_lock_bh(&ss->slock); writel(mode, ss->base + SS_CTL); diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h index 163962f9e284..a98a2c05089b 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -152,6 +153,10 @@ struct sun4i_ss_ctx { #ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG u32 seed[SS_SEED_LEN / BITS_PER_LONG]; #endif +#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG + struct dentry *dbgfs_dir; + struct dentry *dbgfs_stats; +#endif }; struct sun4i_ss_alg_template { @@ -163,6 +168,12 @@ struct sun4i_ss_alg_template { struct rng_alg rng; } alg; struct sun4i_ss_ctx *ss; +#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG + unsigned long stat_req; + unsigned long stat_fb; + unsigned long stat_bytes; + unsigned long stat_opti; +#endif }; struct sun4i_tfm_ctx { From patchwork Sun Sep 20 18:37:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11788071 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 96EB76CB for ; Sun, 20 Sep 2020 18:37:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B25C207D3 for ; Sun, 20 Sep 2020 18:37:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="kqyC244Z" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726221AbgITShn (ORCPT ); Sun, 20 Sep 2020 14:37:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726326AbgITShd (ORCPT ); Sun, 20 Sep 2020 14:37:33 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E009CC061755 for ; Sun, 20 Sep 2020 11:37:32 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id z9so10367499wmk.1 for ; Sun, 20 Sep 2020 11:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ak5yUn/HwPwh2LarMLINzwpMFmwyFpMzNUg8yxcj+9E=; b=kqyC244ZUrr+OGvHrenlLr4NXJg0ICZFMRPzTVeKpgjPv3CwO0vDfsOqTHrf4/EOei mIMKqiJd5yVxd9TQzQ7IRQk8jI8yyBm3X+ryl82MxHKNLCuRxtc9OcelqfLrOGVLzGWG Jp0ta8tk8EYeFjCM3ToAFqxvHV20SZerE5CYbUZQIL3Ga8uwHjMSYdZmiqXAcFNuzeiq ON4H2d7wBoxixhIGpd59wZXq4nURMeaPp9ngqFvxLVMMyPb6p4+cLz8NKRvWfkaW9g7H C/Tm1UpwDuU9rbTyR6+ul5V/TnKmsw/kBtutElXRiqgk91oXuI3InCse7yLPrEZzJ+Cy z5XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ak5yUn/HwPwh2LarMLINzwpMFmwyFpMzNUg8yxcj+9E=; b=O+dqNkWeDR05PyokdBq+HXCxInxxXOBCxbKz/ImrbXLnOwXZjqh+AlD6c6Bbd21MNT jSjW9z/f/KnrlcxX+w2ScRngb+uzR2G+31Azk7jNkgCu2HtZsAPV1MNmEgKUaeem7V1x he8RfNzdYDDzwJJLVjxG0c5Lcy+Q1pHv3CwYOXCgv5qhXAgtdovuC6LhJz7DTKZnKF7+ v5P0zerYJOrOo1Ce12AZonfpzotGgxLx7nAlJRi867L+uavX3JC0VFY9R3HSaeTE0jK2 kdC44yuQQ09mUuIAU8m1GSeXmdw3o7flD8Wzr5RRQwBN6pmMOaLJy8+yugb1cwLHsABp RyMw== X-Gm-Message-State: AOAM5300mxPWN9MLgFKwZLcuiN4h+absbtE8CEWdKQZnoy0Si3i9eIc7 5xZl1o+ag3ECQoIj9gt4bBCZxQ== X-Google-Smtp-Source: ABdhPJxygsyfg5yVhWw6vSFMg8ycLN6WBvpVpQT8imbOMME8fIFWZPFMYhYGBdqb/exUcPjfaZQcig== X-Received: by 2002:a1c:3d44:: with SMTP id k65mr25521614wma.132.1600627051042; Sun, 20 Sep 2020 11:37:31 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id e18sm16419841wrx.50.2020.09.20.11.37.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Sep 2020 11:37:30 -0700 (PDT) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH v2 7/7] crypto: sun4i-ss: add SPDX header and remove blank lines Date: Sun, 20 Sep 2020 18:37:18 +0000 Message-Id: <1600627038-40000-8-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> References: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This patchs fixes some remaining style issue. Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 3 --- drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c index 2ec359eaa4cf..3f19c00f1b0b 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -137,7 +137,6 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) return err; } - static int noinline_for_stack sun4i_ss_cipher_poll_fallback(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); @@ -544,7 +543,6 @@ int sun4i_ss_cipher_init(struct crypto_tfm *tfm) sizeof(struct sun4i_cipher_req_ctx) + crypto_skcipher_reqsize(op->fallback_tfm)); - err = pm_runtime_get_sync(op->ss->dev); if (err < 0) goto error_pm; @@ -631,5 +629,4 @@ int sun4i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key, crypto_skcipher_set_flags(op->fallback_tfm, tfm->base.crt_flags & CRYPTO_TFM_REQ_MASK); return crypto_skcipher_setkey(op->fallback_tfm, key, keylen); - } diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c index 102f8a90ce0f..4d1610952e90 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later #include "sun4i-ss.h" int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed,