From patchwork Mon Nov 16 13:53:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11908571 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97544C64E7C for ; Mon, 16 Nov 2020 13:54:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B861222B9 for ; Mon, 16 Nov 2020 13:54:24 +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="Ic5PMkRX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729264AbgKPNyS (ORCPT ); Mon, 16 Nov 2020 08:54:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728717AbgKPNyR (ORCPT ); Mon, 16 Nov 2020 08:54:17 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A816C0613D1 for ; Mon, 16 Nov 2020 05:54:17 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id v21so565787pgi.2 for ; Mon, 16 Nov 2020 05:54:17 -0800 (PST) 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=9KimMFHuJMnM9grT5G3KxuUOgh3PH0P48I8p4U+udaQ=; b=Ic5PMkRXlhVdSn1pWSmS1kPdU/KqAU1PUu1PX3YtldYe+Sw12gskyReuGYmw6982BL h3IUS/2dQ5DOb4jgGf0L/9FmfAkNhg6w+MXRznImvmZlRbWDeYLX16b5hhcJtBVTyp35 an1y3QibWAPeRLmxXPV61hNeNpKixqczEROZ1WIhOPukNVFOUD+zjgmShh8Oml8bO5ez BLKrrkl6bUcHWBrGb/kF9ML1NNdaL53IAZAaAi5v57ZLvM7UnX0nD/antZWiZzK4kV3b kO67GdiNCqmHYFUFb1qlHlxKKwCW/X7OcbMEPJZWSrvWFcZHXCdSEb6q7ula/jvqvAu/ v+oQ== 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=9KimMFHuJMnM9grT5G3KxuUOgh3PH0P48I8p4U+udaQ=; b=dDWCKDj34n8+cWcdbqzfR0pf91keUJXkgETVan8qVNttP5Q2oIS3Mx57LO5a2D6kbM sIn6jfyoim8w12ZU2WZbS7z4IABU/NRS3fMA/gL/6OEmXj+3tRkUV16tewmukQ90FaHb peXyNI+eFRenyfNX1PtAupht5hAG07nqI+5pasfgo7eTX0GuJuOj61orHEUfDTUC3CCh Tu26sKsz6EFjAfz0KR6pOuIzZSqdgGvoxZtiRZVjVR6lLvexzyeq0EOD1YgwfjHahi/8 pY2Fgsj9GPEunzeMWE0L8jUqL3V9wWXhPWzIlBNLaxaJHV0ZTO/bJwFR9n59kjzTZ0C8 UOaQ== X-Gm-Message-State: AOAM533kTMRACOWwY1uZcbL3KM1sBJA16ca6B5idm2ca/AwJ0BErg66O ZWXYGlLQXv039DZfT3fBn0e01g== X-Google-Smtp-Source: ABdhPJwLmogq1AEKcuBJffxz+FZsXEOnjKY5VgObBdJzLoVsYhFPTClW06qKFMqUsrtUFUhBgorTuQ== X-Received: by 2002:a63:154e:: with SMTP id 14mr13036618pgv.49.1605534857019; Mon, 16 Nov 2020 05:54:17 -0800 (PST) Received: from localhost.localdomain ([163.172.76.58]) by smtp.googlemail.com with ESMTPSA id u22sm15864031pgf.24.2020.11.16.05.54.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 05:54:16 -0800 (PST) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@siol.net, 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 v3 1/7] crypto: sun4i-ss: linearize buffers content must be kept Date: Mon, 16 Nov 2020 13:53:39 +0000 Message-Id: <20201116135345.11834-2-clabbe@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201116135345.11834-1-clabbe@baylibre.com> References: <20201116135345.11834-1-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. For preserving stack, instead of moving them back to start of function, I move them in sun4i_ss_ctx. Fixes: 8d3bcb9900ca ("crypto: sun4i-ss - reduce stack usage") Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 12 ++++-------- drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h | 2 ++ 2 files changed, 6 insertions(+), 8 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..19f1aa577ed4 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -233,8 +233,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 @@ -256,12 +254,12 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) */ todo = min(rx_cnt * 4 - ob, ileft); todo = min_t(size_t, todo, mi.length - oi); - memcpy(buf + ob, mi.addr + oi, todo); + memcpy(ss->buf + ob, mi.addr + oi, todo); ileft -= todo; oi += todo; ob += todo; if (!(ob % 4)) { - writesl(ss->base + SS_RXFIFO, buf, + writesl(ss->base + SS_RXFIFO, ss->buf, ob / 4); ob = 0; } @@ -295,13 +293,11 @@ 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 */ - readsl(ss->base + SS_TXFIFO, bufo, tx_cnt); + readsl(ss->base + SS_TXFIFO, ss->bufo, tx_cnt); obl = tx_cnt * 4; obo = 0; do { @@ -313,7 +309,7 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) */ todo = min_t(size_t, mo.length - oo, obl - obo); - memcpy(mo.addr + oo, bufo + obo, todo); + memcpy(mo.addr + oo, ss->bufo + obo, todo); oleft -= todo; obo += todo; oo += todo; diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h index 163962f9e284..02105b39fbfe 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h @@ -148,6 +148,8 @@ struct sun4i_ss_ctx { struct reset_control *reset; struct device *dev; struct resource *res; + char buf[4 * SS_RX_MAX];/* buffer for linearize SG src */ + char bufo[4 * SS_TX_MAX]; /* buffer for linearize SG dst */ spinlock_t slock; /* control the use of the device */ #ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG u32 seed[SS_SEED_LEN / BITS_PER_LONG]; From patchwork Mon Nov 16 13:53:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11908565 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD384C61DD8 for ; Mon, 16 Nov 2020 13:55:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9872922280 for ; Mon, 16 Nov 2020 13:55:23 +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="uhrUcNEK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729753AbgKPNy3 (ORCPT ); Mon, 16 Nov 2020 08:54:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729740AbgKPNyZ (ORCPT ); Mon, 16 Nov 2020 08:54:25 -0500 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1599FC0613CF for ; Mon, 16 Nov 2020 05:54:25 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id j19so6490749pgg.5 for ; Mon, 16 Nov 2020 05:54:25 -0800 (PST) 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=+A359lF42tZa73dPiOWZxYbdDHUjaoA4SP1/TVC6kqw=; b=uhrUcNEKOBNJHazYbkL0/WF/jWRl6a4lPtR5yUmS/9ZGu9nIeJeSBAYW7AixeYsajJ MdTINMXr78JkR3QHYkXVFW6bU/3iPm5GOEoxaIBRV34IVfhMC3DOPR2d5Ij1wyOFHxw7 SSIcAwr0NphdpCzUpdzlLNuimTIpEcRFEmh/FA5qPhCTPu4xUNW7VYhvfJykv/9jV4Pa +y2GKPkUqDCS/I2AYrEUDrv6LpFFe/iBpLAPRTF2wTaUP0kYvhfFKCrAoMR3WucUC5UJ unoa8iDF+ShqImnC7uASDcgwnvpRL3fhpyjSjNysN6bM6c12EhXhdAGpHyPP5wWYRlFT OoAw== 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=+A359lF42tZa73dPiOWZxYbdDHUjaoA4SP1/TVC6kqw=; b=W52bJsYH6g37QkqNbOXh29XIgAqeBJcaHPz+y1HcHkUL8We8RINcBUbJ2p9iwfr10C C2g3GXyzM9y/bPENuY++1Eww0Symve+hQ6prydU7X+JyE5DgkHZPg33Vyjs3Bim1FHq/ /1nwqZBjVeQtj4Og1/bx7ZLbzu2monPI0g0mzC9jqHM44506gNpdhFe1D/157mWh5Emx BYEmLJXBJ03Wp2UCBpT/mZRzXzW5VDbiBajnvme/ajvhFn5+IwZ1EUEyr7JMm5jUAYE4 3FxlacD/qeqk4avj1WEfpOfQ9flQoDI+ILUvPXbs0tLkqEDonrSqWjp8swKXxGEvT6of 3/Iw== X-Gm-Message-State: AOAM530ndeLceOAe85yZ7YZwgvOca/O1ovsKBPNvNqwOoXAOMlsqodPQ SiYe4rpnF7NxC+pUAMQJFH0ABQ== X-Google-Smtp-Source: ABdhPJx7zPBrpHujwVU2oFB8zrUqJuJFYi0hZX7sx2UK8bvDlOvTG38tK788gR3212Yjzqoa2hpXLg== X-Received: by 2002:a63:4759:: with SMTP id w25mr12628446pgk.414.1605534864664; Mon, 16 Nov 2020 05:54:24 -0800 (PST) Received: from localhost.localdomain ([163.172.76.58]) by smtp.googlemail.com with ESMTPSA id u22sm15864031pgf.24.2020.11.16.05.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 05:54:24 -0800 (PST) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@siol.net, 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 v3 2/7] crypto: sun4i-ss: checking sg length is not sufficient Date: Mon, 16 Nov 2020 13:53:40 +0000 Message-Id: <20201116135345.11834-3-clabbe@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201116135345.11834-1-clabbe@baylibre.com> References: <20201116135345.11834-1-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 19f1aa577ed4..4dd736ee5a4d 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -186,12 +186,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 Mon Nov 16 13:53:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11908569 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50925C63777 for ; Mon, 16 Nov 2020 13:55:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1AADB222E8 for ; Mon, 16 Nov 2020 13:55:24 +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="khITfdpV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729770AbgKPNye (ORCPT ); Mon, 16 Nov 2020 08:54:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729765AbgKPNyd (ORCPT ); Mon, 16 Nov 2020 08:54:33 -0500 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFFD3C0613D2 for ; Mon, 16 Nov 2020 05:54:32 -0800 (PST) Received: by mail-pl1-x642.google.com with SMTP id g11so8408619pll.13 for ; Mon, 16 Nov 2020 05:54:32 -0800 (PST) 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=mVzZeX/xHmC7db3jb+d+RTV9mPod+mGCeVwxUA/QzHc=; b=khITfdpV7TkpTI3z7ek6WPFVnE/hkdUS1kE3iVr+zubshbicRf3ouAsQNOcAGmsXFR aZVJP1dw8wraRpfHz05MmqGSK0WgIJnQ/oaLCI9/zHAHO+skG9QQFuDHQcTYmCCsiWRR bkM5pajDBxam1DhN9q6MaPj8L8mUPxWadt5A3M/xtnLXo0byO2upaIcjoTgK5oP60RKu mGR5ZB/HXca1A+3cbn6Y8chlsZtyNx8qgLI7hrBxZyDCg2SPFmDvzg0t537yHMT3EysE RgW3wgZtmZ/ApXOOXn1kTXICBOoL3JK+ZQEWnRgDvBiEh7K0AUAOWzLxD8qJPueWapu1 uj3g== 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=mVzZeX/xHmC7db3jb+d+RTV9mPod+mGCeVwxUA/QzHc=; b=p6M2ZQN/GpDvkB7szyiUiyrywqPjnJeQsNAGvOECSlTCwsLaE/ojNAXJrXbbdmXeaS leh1b8dx5HUVhlsVuKN/jFzEaTpHhow4t9QMC5hJs/WbyuYVdmw4LXUxq/+9dPwgJR0a BZqprkWcWfJmIRowHq889SwWPczAgxbFWxHdDqrjLR7/nS4FOwrby5Uh7+VPzZBiUmd8 IbGCQ7fMlzf9dAAXG9PJR08gdENrXWBIWuUHPEwP7U0KQpSnxYKJbFAw8yfEy1r4CQG1 /rd9EszjSih4mwCDqL/046z4L1iQeX3ORTjcgrFNVFB/eK1Scyc8sb4OChyqjGRZD6+H 5qEQ== X-Gm-Message-State: AOAM532QOGkAwYqpkIQOjHi+sL279t4fmYf14cbbN525W/abJo4WclRS w5n77h6Zmrqxx55N0iDDfPeyQw== X-Google-Smtp-Source: ABdhPJycsJpsHxxQgUQikdHZHQq+B46p3AfeivU5IrTPRF+X2sx8pQsUDBuZgBM8ImvHOT/pMe+oCA== X-Received: by 2002:a17:902:70cc:b029:d7:e8ad:26d4 with SMTP id l12-20020a17090270ccb02900d7e8ad26d4mr13298602plt.33.1605534872355; Mon, 16 Nov 2020 05:54:32 -0800 (PST) Received: from localhost.localdomain ([163.172.76.58]) by smtp.googlemail.com with ESMTPSA id u22sm15864031pgf.24.2020.11.16.05.54.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 05:54:31 -0800 (PST) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@siol.net, 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 v3 3/7] crypto: sun4i-ss: IV register does not work on A10 and A13 Date: Mon, 16 Nov 2020 13:53:41 +0000 Message-Id: <20201116135345.11834-4-clabbe@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201116135345.11834-1-clabbe@baylibre.com> References: <20201116135345.11834-1-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 4dd736ee5a4d..53478c3feca6 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 */ unsigned int ob = 0; /* offset in buf */ @@ -202,6 +214,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) @@ -322,9 +341,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 Mon Nov 16 13:53:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11908575 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA118C64E69 for ; Mon, 16 Nov 2020 13:55:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B251F222E8 for ; Mon, 16 Nov 2020 13:55:24 +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="pHOAjGIM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729817AbgKPNym (ORCPT ); Mon, 16 Nov 2020 08:54:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729743AbgKPNyl (ORCPT ); Mon, 16 Nov 2020 08:54:41 -0500 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F66AC0613D1 for ; Mon, 16 Nov 2020 05:54:40 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id w6so14215624pfu.1 for ; Mon, 16 Nov 2020 05:54:40 -0800 (PST) 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=oFmZrd7NE3HbQX/Lo8F4S5lrtb+Hwz8PmiBSdug9JUU=; b=pHOAjGIMcO3pLa2qipnYk3+0D2U6SBY246HUqsvNSSKyA64ULFAc9XPKYhAZ3LHVpx iPgKQZpjGbafyU9mGED3WvU93MWI/URKOqhaMClTUTIn5idMEr2WMSm3Pl8FknUgF1Lg CExg8xMsGbpFjRBHBoMMVdF/gYdSI0DhTuIVIWxDb2ey4h6sT2bdJGrK1DoRfgH6hQAA n3X7Amu4u+9on2FeaWIWIe5pqxXuhNMOQMaKqGkC3ZgzAZaPiCyNU020+uGezPvE0k5V 0hgIf0Cai09dErI+/YhhtctQbKZt4QyLsudO4N1DSOMVF5Fc90speRF9uoGNgAk6DwaJ JUSg== 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=oFmZrd7NE3HbQX/Lo8F4S5lrtb+Hwz8PmiBSdug9JUU=; b=pK9H3pQW8yNK3BQ4+l+I3fk9AENBce9v0D0PrK+Yad/Am4lH7OInurL0OKRg0Vuwh/ KV9jgeE4ERvQ7Dkqb3JtIhvTKKGNETWK/IIygbHTiKgqokt4xUlVS8xLPXKuD00yAB9O FBrfThrB2tQs/dIxYSZ4vqKS8svrxES8Nd6ucJ/MFtTZQwSiYWyNoOpKk4Mk6OEtlqXB WsAFa6eTehcI/LxSlemMm7wRdDYM6hzZjyoXaiZf9wrOpZaEmm42/6YVlt9n/2Wft2qV ENT3Q3KUYSC0hkcGg4pjIdFsWsYhj6uR/0XPsX6JRjPbnVdeqHdrvsswabWiw/EO6pK4 9x4Q== X-Gm-Message-State: AOAM530tDUvv4U1MTO8WNKOdJO00uGCs+sjFV9wqLuPe1RLRtwrldzXm G+1YnWu5ztUBdxQhkjACmYAiOA== X-Google-Smtp-Source: ABdhPJwG3dyo/34EnfPSLxxDmG2RWghKRkJ6P0GIJZkqnwDVqvPCn01dXaEjThZARmuMLjbRAn1Y7w== X-Received: by 2002:a17:90b:78d:: with SMTP id l13mr16238310pjz.57.1605534879998; Mon, 16 Nov 2020 05:54:39 -0800 (PST) Received: from localhost.localdomain ([163.172.76.58]) by smtp.googlemail.com with ESMTPSA id u22sm15864031pgf.24.2020.11.16.05.54.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 05:54:39 -0800 (PST) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@siol.net, 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 v3 4/7] crypto: sun4i-ss: handle BigEndian for cipher Date: Mon, 16 Nov 2020 13:53:42 +0000 Message-Id: <20201116135345.11834-5-clabbe@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201116135345.11834-1-clabbe@baylibre.com> References: <20201116135345.11834-1-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 53478c3feca6..8f4621826330 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++) + writesl(ss->base + SS_KEY0 + i * 4, &op->key[i], 1); 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); + writesl(ss->base + SS_IV0 + i * 4, &v, 1); } } writel(mode, ss->base + SS_CTL); @@ -223,13 +223,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++) + writesl(ss->base + SS_KEY0 + i * 4, &op->key[i], 1); 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); + writesl(ss->base + SS_IV0 + i * 4, &v, 1); } } writel(mode, ss->base + SS_CTL); From patchwork Mon Nov 16 13:53:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11908567 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6054CC64E7C for ; Mon, 16 Nov 2020 13:55:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A45422280 for ; Mon, 16 Nov 2020 13:55:25 +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="iblwlVcd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729849AbgKPNyv (ORCPT ); Mon, 16 Nov 2020 08:54:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729825AbgKPNyt (ORCPT ); Mon, 16 Nov 2020 08:54:49 -0500 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1D2CC0613D1 for ; Mon, 16 Nov 2020 05:54:47 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id v12so14160075pfm.13 for ; Mon, 16 Nov 2020 05:54:47 -0800 (PST) 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=LA6HiyjtrQWg93rXzUxCKFCbWr20SEsMu/GK7GDnTM4=; b=iblwlVcd2lUD/gwKL5jWgNtBU8xtXkfkke8Of+1dHqmGyy37nax0rkrq4lAXptvJVb AXqrTry0jNdofQ+ymr26F5xvtaGj2ALrfbMCnUWvEynp27GBSifY99vEi2dweI6enESU vy36OwiE+cI6m+WwQAamyl1AOUTuLz4liMHynQe16YSSqU+JdC4W2cKigHXBhsY+lJfD df9hu4J1U6K00TDaQluTa930RJUmRhNzpxugl2rmno4CG3ZBTDMbYQWTfAJdDl9Vm86E zQDaMD03Wj8qHlYlgW3jmyS7s2L/bHD9blRaKnd4GVwAh71hLJPRRdAdhXjqbvQRg633 0j2g== 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=LA6HiyjtrQWg93rXzUxCKFCbWr20SEsMu/GK7GDnTM4=; b=tWlx6+1E7/IypBCOUn0ZEa5tqMJG/hucMP84Kn7rOfoPra1W4QeHUDUYR/g8Pd7Nrr IJCbtns2TlOi2c7ZNeslhTFo5GP1mbE0o0xE4cCju4IX3hqH9SUF51OTQA3CcSYO2goI /MD1sqz9NProMW1Dq0Vc7dMEW7OQaldi3D35EL16C/8vwDHj1hh/0Y0UrXZJLk831q0q 6ELlqaoY12cX0v+1+87lG/iG5j2bys68jYMOSdDA0UfjPsYoegPct0LCFAbfroNfAki5 MRmpRaPa5sJ02hVxtwyA/vIJ+BBmJxnCO5uZzU5BXn4p7MjnmvKi9g3HdGmCRkmtM10m naJg== X-Gm-Message-State: AOAM531WLCwUlCK+dxrBnJddHsDZ7rCiFM77OgGwdC9MKU04Ka7N+cO6 nArhuIIqpweC7Z9INX2+lFAuLA== X-Google-Smtp-Source: ABdhPJxtV8S3t14TtRMP1LjRfXosxCQyIdl5lzyfHOzvv6zyR1P0pO6Y21nlXDj/H4LetTS7oza29Q== X-Received: by 2002:a17:90b:4c0b:: with SMTP id na11mr3329213pjb.0.1605534887618; Mon, 16 Nov 2020 05:54:47 -0800 (PST) Received: from localhost.localdomain ([163.172.76.58]) by smtp.googlemail.com with ESMTPSA id u22sm15864031pgf.24.2020.11.16.05.54.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 05:54:47 -0800 (PST) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@siol.net, 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 v3 5/7] crypto: sun4i-ss: initialize need_fallback Date: Mon, 16 Nov 2020 13:53:43 +0000 Message-Id: <20201116135345.11834-6-clabbe@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201116135345.11834-1-clabbe@baylibre.com> References: <20201116135345.11834-1-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 8f4621826330..7f4c97cc9627 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -179,7 +179,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 Mon Nov 16 13:53:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11908577 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8508BC64E7B for ; Mon, 16 Nov 2020 13:55:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 53048222E8 for ; Mon, 16 Nov 2020 13:55:25 +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="QIvhzR8K" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729850AbgKPNyz (ORCPT ); Mon, 16 Nov 2020 08:54:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729825AbgKPNyz (ORCPT ); Mon, 16 Nov 2020 08:54:55 -0500 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BD72C0613CF for ; Mon, 16 Nov 2020 05:54:55 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id p68so2831193pga.6 for ; Mon, 16 Nov 2020 05:54:55 -0800 (PST) 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=Xj+we/CZSSQ2b1f+Ofjy3j7GAiNPdJUEj3m5LkQW+Z8=; b=QIvhzR8Ka+4MVosZB5z2vAfqoBtB9TzQ48d6m+EVplyYd3cOKx846k4a1eO+P2R6RN AlrAPatTxO16vwFQoU0OPKP//FY9Z7wREd0Nw90AtWoSK4hp5cOGzXzq4w1vnYBuO/j0 IQ3NErQ9Jd5jrIrb1c5EPzyI9rAw5QD3NUzI4e2IxvKffA/WXNQWAm4D1ZeH5lqWNilC cupOvUrSlmXyizE4EnOWgIfgZRHIBhWi/vlkIUI4Aq2PM6iP+pQ1eoW7wHKJyVpXLDLa ZsIx9a+PAKKTPylxGYpnAh2oYX4wZs7H4Xa7gFv9I7pEyPuRTBKpUuNvOf6KVptyAM96 uWww== 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=Xj+we/CZSSQ2b1f+Ofjy3j7GAiNPdJUEj3m5LkQW+Z8=; b=BNB5amUGFHpdJYmbfchs/MYLBYs4aoMs3S3f+RcazAqBcSunB8ARhSLoXWP30krNVH DJeJfozmFn1tisxsR/N92FLM90PfEs8kp1MVpncRsGJgXUGuGJP+aIj1M76f+yL3xKY1 lNd1BOqgLQhSqubQOnVzYIL9yCPH08UGhl3SMlnJVZNhndy8g/8qYnYKfjCbZS3HWDd3 ZIQPWqZ3kpgjSl4rgy9r7JyW59BKLfxYwwoI3oMVbIIn3EkP8o9o8pPdJDi7xWdZIATF Mi6X8L22/cXRL/gjVFRmcUKwMjOKU3/dbdzd9ZXQGHsIwxLGdHTicRQvwPY/qTMnchD6 p22A== X-Gm-Message-State: AOAM533W+6IzIh6vu+A619OeLTV0O2eUtWWvSiCCxm42A1yIi2qJPwuh JKBnvEO32csN/V65aYqsFdAwSw== X-Google-Smtp-Source: ABdhPJzp+Q2E1KWWfQx1H88HJTfsPtYT+sc+K9CT+oksYihVeFDXfoypPeVKyNox3TqdS+rOt6k3Dw== X-Received: by 2002:a17:90a:1b44:: with SMTP id q62mr15651522pjq.59.1605534894775; Mon, 16 Nov 2020 05:54:54 -0800 (PST) Received: from localhost.localdomain ([163.172.76.58]) by smtp.googlemail.com with ESMTPSA id u22sm15864031pgf.24.2020.11.16.05.54.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 05:54:54 -0800 (PST) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@siol.net, 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 v3 6/7] crypto: sun4i-ss: enabled stats via debugfs Date: Mon, 16 Nov 2020 13:53:44 +0000 Message-Id: <20201116135345.11834-7-clabbe@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201116135345.11834-1-clabbe@baylibre.com> References: <20201116135345.11834-1-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 | 20 +++++++ .../crypto/allwinner/sun4i-ss/sun4i-ss-core.c | 56 +++++++++++++++++++ .../crypto/allwinner/sun4i-ss/sun4i-ss-hash.c | 6 ++ .../crypto/allwinner/sun4i-ss/sun4i-ss-prng.c | 5 ++ drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h | 6 ++ 6 files changed, 102 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 7f4c97cc9627..5af404f74a98 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -34,6 +34,8 @@ 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; + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); + struct sun4i_ss_alg_template *algt; if (!areq->cryptlen) return 0; @@ -50,6 +52,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); } + if (IS_ENABLED(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; + } + spin_lock_irqsave(&ss->slock, flags); for (i = 0; i < op->keylen / 4; i++) @@ -134,6 +142,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; + struct skcipher_alg *alg = crypto_skcipher_alg(tfm); + struct sun4i_ss_alg_template *algt; + + if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) { + algt = container_of(alg, struct sun4i_ss_alg_template, alg.crypto); + algt->stat_fb++; + } skcipher_request_set_tfm(&ctx->fallback_req, op->fallback_tfm); skcipher_request_set_callback(&ctx->fallback_req, areq->base.flags, @@ -221,6 +236,11 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - ivsize, ivsize, 0); } + if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) { + algt->stat_req++; + algt->stat_bytes += areq->cryptlen; + } + 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..9a8a5e246d87 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c @@ -10,6 +10,7 @@ */ #include #include +#include #include #include #include @@ -234,6 +235,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 +502,14 @@ 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 1dff48558f53..c1b4585e9bbc 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-hash.c @@ -191,8 +191,10 @@ static int sun4i_hash(struct ahash_request *areq) u32 spaces, rx_cnt = SS_RX_DEFAULT, bf[32] = {0}, v, ivmode = 0; struct sun4i_req_ctx *op = ahash_request_ctx(areq); struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); + struct ahash_alg *alg = __crypto_ahash_alg(tfm->base.__crt_alg); struct sun4i_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm); struct sun4i_ss_ctx *ss = tfmctx->ss; + struct sun4i_ss_alg_template *algt; struct scatterlist *in_sg = areq->src; struct sg_mapping_iter mi; int in_r, err = 0; @@ -398,6 +400,10 @@ static int sun4i_hash(struct ahash_request *areq) */ hash_final: + if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) { + algt = container_of(alg, struct sun4i_ss_alg_template, alg.hash); + algt->stat_req++; + } /* 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..152841076e3a 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; + if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) { + algt->stat_req++; + algt->stat_bytes += todo; + } + 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 02105b39fbfe..e3e6cddf64af 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h @@ -154,6 +154,8 @@ struct sun4i_ss_ctx { #ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG u32 seed[SS_SEED_LEN / BITS_PER_LONG]; #endif + struct dentry *dbgfs_dir; + struct dentry *dbgfs_stats; }; struct sun4i_ss_alg_template { @@ -165,6 +167,10 @@ struct sun4i_ss_alg_template { struct rng_alg rng; } alg; struct sun4i_ss_ctx *ss; + unsigned long stat_req; + unsigned long stat_fb; + unsigned long stat_bytes; + unsigned long stat_opti; }; struct sun4i_tfm_ctx { From patchwork Mon Nov 16 13:53:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11908573 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01524C64E90 for ; Mon, 16 Nov 2020 13:55:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4DC32244C for ; Mon, 16 Nov 2020 13:55:25 +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="yNbRJg4H" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729888AbgKPNzE (ORCPT ); Mon, 16 Nov 2020 08:55:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729877AbgKPNzD (ORCPT ); Mon, 16 Nov 2020 08:55:03 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58D30C0613CF for ; Mon, 16 Nov 2020 05:55:02 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id q28so2777108pgk.1 for ; Mon, 16 Nov 2020 05:55:02 -0800 (PST) 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=oZw0k++w9vCloWy1RavM8WR5A4PN64leIv/MQNgMwVE=; b=yNbRJg4HiOvMln/cy5i68Vh9bezm3f9qSMImulPHzT6yNgmfKS4Fy/ZeIiAoujt9Pu 8eKHZ5FzSSTLkx87rEi15KdfPiUrFoBzKmShA+p4YaBWqGUCXsMn2zX1w4GylddXBWV3 ekpdR9KK+Pv8qiQj1Goz2Y4hXnKsS1ibZUSJqGJa/O5JMlZqREWKOO8PvMfIbpWHDdnu 5H9Y9q67y+e9h+kbER/F7ORLqabBIoELPkE7Ub9DGO7UJFKo/ibjR8jHq+aTj15HsADa fkzcB43rdFBGuH6zbWIZX7vZScsdLrtKFbGK1zaPljatHXGiLg2QeXtMufVxfvMlKifo MPvA== 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=oZw0k++w9vCloWy1RavM8WR5A4PN64leIv/MQNgMwVE=; b=f1eM9XhG0yGqWuPpHFqxxgpZ19Wl8ulSBOEyYlxf5nj+X8m6V8OQOiTfu38LptXEJj NfZMYT+amYKHtPZVfLRW9fK+LE7LPeode3aCgPyM7WRlIy8X4hzOXNzG+Vwx1I4WNEgv 2/fvcr75nvmh0DGQsTgbIWznK8xwNHC0OBCi1knlvA3W7FIQz+CZiIu567w1bPuwjZwA s338nMnfzYs7AUrVkvwq221ld5OVYqooVcJ+lt4CC83C1wvWyRx1Lezkjcr+LI1vlDC3 YGAealU7KMPXmV1ue9qEJC2ppOCTzv1VmBc4q3gOjpaCJImeO0Bg9+grcEYPfS232zFh ZnVw== X-Gm-Message-State: AOAM5307/GvHa4hmmZgZiP0bwPR0qM+T1JPnbpPSzUiuD1l/L/Lfe4SL 8D3PHUOIcmAa0AsUbTOgBx2QVQ== X-Google-Smtp-Source: ABdhPJzrn1D2lGmE0O6FoIvkmcUXsZwgWET0G+7+CvYHDb549HsqpYYeIyHzseFh6ejoq+TvEPHieA== X-Received: by 2002:a62:84d2:0:b029:18a:f574:fded with SMTP id k201-20020a6284d20000b029018af574fdedmr14426220pfd.31.1605534901958; Mon, 16 Nov 2020 05:55:01 -0800 (PST) Received: from localhost.localdomain ([163.172.76.58]) by smtp.googlemail.com with ESMTPSA id u22sm15864031pgf.24.2020.11.16.05.54.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 05:55:01 -0800 (PST) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@siol.net, 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 v3 7/7] crypto: sun4i-ss: add SPDX header and remove blank lines Date: Mon, 16 Nov 2020 13:53:45 +0000 Message-Id: <20201116135345.11834-8-clabbe@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201116135345.11834-1-clabbe@baylibre.com> References: <20201116135345.11834-1-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 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 5af404f74a98..94b9952b16f3 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -135,7 +135,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); @@ -541,7 +540,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; @@ -628,5 +626,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 152841076e3a..443160a114bb 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,