From patchwork Thu Sep 17 18:35:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11783285 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 75BC66CA for ; Thu, 17 Sep 2020 18:38:10 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 376D5206D4 for ; Thu, 17 Sep 2020 18:38:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="yWlA+ZxL"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="Iu747+4n" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 376D5206D4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=CnOVV5RBSo5mfnzwx++Pe3kTeZc1Izw4cbw32xCBUts=; b=yWlA+ZxLc2F2Ask/xcpdXXZy4u BRujsN+nNma2KJX5aRRt2QFVF/VhWt2Jqg0velTsvGp8u3bzAjxmzJgMR3Ss+4vXsfqI1eZpMlgJS 5HBY+jiTEgroHetmjG4p9e+BF0fEK6eWj84+2+3IPye8ljbUMNQknE1v8XgYWYq3U16Om7gwig/07 n7u9SyoGEfjjJ5wrNXCnugh+xIj8IwQAjuvLvJJBABWGAkaJuu6gxyyqFqucxlLpnnx/Xs1NKIXGu 2Ujtow9KFeI+WLo2Z1Twn6VOjhd/eVgKiX0Epi0A0RiZ0o1+8uJWqNsEFmhkhulR+m00aME1cLzLp PcjgyH9g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIylh-0006AW-5h; Thu, 17 Sep 2020 18:36:29 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIylP-00064V-48 for linux-arm-kernel@lists.infradead.org; Thu, 17 Sep 2020 18:36:13 +0000 Received: by mail-wr1-x441.google.com with SMTP id j2so3116351wrx.7 for ; Thu, 17 Sep 2020 11:36:09 -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=Iu747+4nadzvDfyHCyTyuRJhiIU4JEOTx7wcl9fRZmk4C2hj26XLP/pLYoNWCXkNoa jOG8/8qUQh9csSVrxPpXSLZB7w7m2/mkvWFMko8b/zg/Z7ttLd1ZC+hExrJdPx60e0PY DGPFCHfb55pFL94T4GzExTONjciAmVl0VIYj29tldHOgshEBgmTCekX5f9FxIO8xVy93 TQrf1HjVu9cDXHHOMehhlpk8KxDRSZt7TDhRQoq66hjhfqUUWsDJC5vKyCqpCfaCHW+3 JhvQWkL851NyQoea13o8i1gW2piPvOrQirFTd+7HYoZIDSFRTpLgyuneoMGuurVSFMNa nHTg== 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=WcKx+tnG5CighdOYvHnlagGAPwIIDxai3IkG5pPgAGUL0/PsBPu28StaU8BVlY3j0B sPKT4k7sHF2mkzvWjsTijcoYa1J73d7lF2wPvuz0hjP+gByfhVwtZ+8avEGowaidDaO1 vsUFtnYRJUHTUuf2kZjVUOMAEXLfAxGAWCWkeaTK70Wes9mv3jf4LAMU59BulaGhvJ91 TnTEhtuB5+AqccGJuOUq/7f8ekmCNv5p7tbaZPIS84M0z/pcgzFOVQKV/RQM8LV5uUeb 1WRkpzdpwnIJVrUAtddCwnXLIFTTPGUh5j/LkPwgnekq28FZnOb8TKgY2snJw/qKdfO3 jXzw== X-Gm-Message-State: AOAM532bU46XZY6hh005kDq7Rs+ZubIhm5NmCI4+sDyrH4P4d2jcS4/b LNXNhi9DLTAAnPg5kewWn5VS7OobjVNILg== X-Google-Smtp-Source: ABdhPJwPR3kJwirxBvcg7+EKXYc7it131pIcBWGKU+Rwhgt8ETaSOml+RRDdd+wopE0SsNNZADqqUg== X-Received: by 2002:adf:cd0e:: with SMTP id w14mr36379858wrm.0.1600367768639; Thu, 17 Sep 2020 11:36:08 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id x16sm571901wrq.62.2020.09.17.11.36.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2020 11:36:07 -0700 (PDT) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org Subject: [PATCH 1/7] crypto: sun4i-ss: linearize buffers content must be kept Date: Thu, 17 Sep 2020 18:35:52 +0000 Message-Id: <1600367758-28589-2-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600367758-28589-1-git-send-email-clabbe@baylibre.com> References: <1600367758-28589-1-git-send-email-clabbe@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200917_143611_168933_ADFD1498 X-CRM114-Status: GOOD ( 15.46 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:441 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corentin Labbe , linux-sunxi@googlegroups.com, linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 Thu Sep 17 18:35:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11783259 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 3D4F41709 for ; Thu, 17 Sep 2020 18:36:28 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C9276206D4 for ; Thu, 17 Sep 2020 18:36:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TDqATUxr"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="Tc51Lgth" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C9276206D4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=l5h1ULD0kgmj0HziB3QSLBff/byxbdppbBbUDn5ANBE=; b=TDqATUxrmpCFyOVgWFpnHOWfQ6 VRTzhtP4hmfF6tLC27xIH1jbMRnYjweAYh0t8cq6OmZHd9+O4uePCemekAxnLB5SPho+fU5txk9Jg I/5tIVxOunsIYIJlhTV1sn5Za5BDs38sgS4jwoeOkZ1acIUSMY62Gjm3ZvTQTgkC7LxrF23xrB4Xb aCD5jRRlRKK17TxSaQcY5uPZI/aFH3KfDGrqpnoReIbO53pCbxZMYXZQfdoml/fo6ldReqhS3m4xN QPR8QKCLqyAY4EWNTP7+wWS9uho1o2fZIag3nElAB65peRlYLFz6Whh+dP025Z1htwOjkaroVY6I5 ahVyr81Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIylT-00067H-Mj; Thu, 17 Sep 2020 18:36:15 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIylO-00064b-Le for linux-arm-kernel@lists.infradead.org; Thu, 17 Sep 2020 18:36:12 +0000 Received: by mail-wr1-x442.google.com with SMTP id m6so3142673wrn.0 for ; Thu, 17 Sep 2020 11:36:10 -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=Tc51LgthYrtN/C0RNoGrtu6I9ssV8h9UwKdz0ft8yPntVgsb8RwIMw2tQjkL6VvUpx 3eWnFSDstKy+8h4FEmzSZWfBbdwSOxyvMAtKCO15lX8oQo0DLMpCcJMNkbzNdDP6KAi3 QJLSWItKrjv+Cm4ONO+v1GJ+LqrcYZVhQmFHXkhyR7kyAU2SCYQxnB4x0eSoWWZ3uiel 1g3XKPSUC1UWr6V9dk92C5vQKtCam+DPIaXUx+A2es6eobd/bm7rpS5BTk/1C2vUiO9U u2SfduQvAoDYEuIWH8kTUHfKZsnO/Z/9zSYmF07TWFeb8C0GQ6qEKJcYdgBjjtdcs0f4 w79A== 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=FM+OGYUrjPwc0xza9mtCxtRwQPuVK7ci0gHc38atUGXcjq/UTPIY7zSa4coq5u/PgF 6iihH4YZn4aCT0+NcaGksbNOPq7e5ET3yVej4/n1Vo0dEzgZqI6MQLX5Eaj2YzwfwJ1b y84kO2K+6eGg2295/HPRqkf+nN1QVtcdovkWa9ztVCW89EY0MiEqX/Tg9Kh6Kdu4LM/k 8O8oeVuXiQeiskQnYKyYs5GanDhzBSNwNRD1uNiPBdT5ngLnsfiWqjI59jvQCaCsFLu2 VI7Iz/ZwGT5IeQE5QgrihVRSRpJXANLTef2jbhXPqKvQQWH0RnusVVnOP9AIrq/XXtWn YolA== X-Gm-Message-State: AOAM530TL82yEaxdsDw1hx9Q3WOdJ8cE0cBMIahHTfgCsvNDcJKeygVo 0YB1i0GUtxhy1aqXTtYXx2+3xA== X-Google-Smtp-Source: ABdhPJwhXuvQa4gIHPDoUqZX+gQkmzaq030R+3DLkq1LnXlJRD7XmKmH+Ir4Od2FNbCImmKLAMzpSg== X-Received: by 2002:a5d:6cb1:: with SMTP id a17mr30001488wra.386.1600367769682; Thu, 17 Sep 2020 11:36:09 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id x16sm571901wrq.62.2020.09.17.11.36.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2020 11:36:09 -0700 (PDT) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org Subject: [PATCH 2/7] crypto: sun4i-ss: checking sg length is not sufficient Date: Thu, 17 Sep 2020 18:35:53 +0000 Message-Id: <1600367758-28589-3-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600367758-28589-1-git-send-email-clabbe@baylibre.com> References: <1600367758-28589-1-git-send-email-clabbe@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200917_143610_753451_A9F44E54 X-CRM114-Status: GOOD ( 16.46 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:442 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe , linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 Thu Sep 17 18:35:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11783261 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 8060F139A for ; Thu, 17 Sep 2020 18:36:36 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3748F206D4 for ; Thu, 17 Sep 2020 18:36:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MJ+TPvwD"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="JpjCYv5u" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3748F206D4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ltfFPPl0kjgzf7wpUnAOJQsXHzJY4AC2kIfaoFWEflo=; b=MJ+TPvwDrm+kSUQkLDoUp4Urih xgTOlqW5YKyeq+Zb+QwHu716JgKaSrfMWNsIhcUZ4g15GB8lqQ3RzlUJt/zPMJOw4tR4/mwYCw6x2 HY+cbO4xC2NZYFMyGL3ogelKj5+r3D6jcm/keTVJZMl5Xr8T/F44X9xzDUUSia/ghFUwwlArMYqBX htvH+VuZQJu3xensCxYuTuOiOdrNB63s0w0cJphao282dEYvgwMstwUGJNRYKnI+KeHSr+/sO6QsF 8QQ23MjV7Ff6BI4eqDv08PSIjLFVMS7LS6oHvNfjN7Mj1E4XaH1dzS4Oi7x/GuwJ1SaouoLo5NpZ+ Sf/IxrPQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIylc-00069Z-LN; Thu, 17 Sep 2020 18:36:24 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIylP-000659-GE for linux-arm-kernel@lists.infradead.org; Thu, 17 Sep 2020 18:36:13 +0000 Received: by mail-wr1-x441.google.com with SMTP id c18so3108096wrm.9 for ; Thu, 17 Sep 2020 11:36:11 -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=JpjCYv5upp6XL8vZw/alieu2cpaOwfleOy/rzX2ojjNYlwSuBLG2jlL+2+UQAk3mmW 3RfiYgv/kFFoG5lvbTqzYR7dY+MluotdcWjF7R3w9c7ozyM/dT0nt1blyP8CO3TpOa70 YyeoWH8e58UflQPQN7VnSizaeKpooddmUBw9cyMgRv8FYllSdvtaXEPjBrL7rv4dWnun f7exonzOVT/cBza580v3FOwbMcsktLa7oH+dRP3FPi4TKZhKxpyL+3vPJjHI2xzSD6f5 +YK+k97R2D7oMjJprQDPx5Jim0oq1XgwUTSlJAfX7bzURWSOTisdaEHtzm6HnJYb4uzR 6ing== 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=EtUtOMbuIbj97yw6GaUK9rahfr/y5YVP0DNdZBxZU5E6D0dFcQWEPlUVXzcI9UfdFc 5hrN2Le2ip2PDPnKxzVFdxrcBPqGTEkl/fRm2egJJikTcWM+SLNS7/xz3Z/506FrDa2h HXwNtNPpiCqYiZa5m01AdRj9AB0MdAcQfbz1gfSNdXx+jseESYnyqSR5pGs0lYasmDIr ZnDoXdCev1ccYxKYM/FKguhymaY8PAAd9j15tK/hgldT7L2OM87/JvChh07lQ96Izfcz DK8ceZk4mMZFSjs8SU2ZWITEnXifk/xf5Zog+FOJAEHgMUY6YnELCvCUI3PTE1ductic zXBA== X-Gm-Message-State: AOAM531aKZISUpITUDEXO14WRa62WheFbS03oIkCzhxrh7BltPSHK7UL NZG6KqppOwsU43wEGif5aFA2DA== X-Google-Smtp-Source: ABdhPJwEutMPermMhwz6o/ZA8isTCX7M2dtJokNUsR8uKvWZb3baKmYr/Mdbwerfm2Ba1S7xHFnLLQ== X-Received: by 2002:adf:a3d4:: with SMTP id m20mr30378089wrb.29.1600367770621; Thu, 17 Sep 2020 11:36:10 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id x16sm571901wrq.62.2020.09.17.11.36.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2020 11:36:10 -0700 (PDT) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org Subject: [PATCH 3/7] crypto: sun4i-ss: IV register does not work on A10 and A13 Date: Thu, 17 Sep 2020 18:35:54 +0000 Message-Id: <1600367758-28589-4-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600367758-28589-1-git-send-email-clabbe@baylibre.com> References: <1600367758-28589-1-git-send-email-clabbe@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200917_143611_562524_20762CB5 X-CRM114-Status: GOOD ( 18.55 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:441 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe , linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 Thu Sep 17 18:35:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11783273 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 86E81618 for ; Thu, 17 Sep 2020 18:36:56 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4A7D321973 for ; Thu, 17 Sep 2020 18:36:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LI0Sg5TP"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="nXYqabRM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A7D321973 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+IYRzPZSGSrW7IADli8Iqo40N63HBRMXF80eQF4oqYI=; b=LI0Sg5TPHNZfo8/1RGtFjdKVXQ nxPwa9lWp+yPjsAKDKbhZg4LfLy/nm+V/Pshz1A/pHwrJDrVTuO/MJsxJpOLyQD3DyRzoOY6OYs3s 3I4xaRa3aCYsxoM+JAGR9fVCjCueW+3xTzoeYwC63VQDEulToVYLq0AsD7uPaWFnX+Go3tGjsplwI VW/J/LZ2FRtgDE0T0bcpzEtR8uKCiwtJRz0HSQN4QObVe7NSgHrXwLlA5Pe69QNhGO6+fyM+5MMRr pl1LE8FtddDPgTavJ/YJpHicCiorYy1PfoF2cHigk8Qy82i9dE71Q4d9ATrXF2V3qgM2IhdQ7n51a ZdNQy9Sg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIylo-0006Cr-G9; Thu, 17 Sep 2020 18:36:36 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIylQ-00065j-Qq for linux-arm-kernel@lists.infradead.org; Thu, 17 Sep 2020 18:36:13 +0000 Received: by mail-wr1-x444.google.com with SMTP id z1so3131438wrt.3 for ; Thu, 17 Sep 2020 11:36:12 -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=9qViGrdUGpa0ThWB+YcFxDSbeYaJXJqK+FKlEA3vuxA=; b=nXYqabRMAd6ecAv6o7n+gbyP8lIEInIM1bduwtk6gkOAsnFCZFVNSEbxc4gjOhn2He ptpAwvp9f3TYVItGu0CWnX8YSH/bNnf0ThJJc04JiOHRtJMed/bQytK4fSDx4xLq5ZFy 2m4lN2B4zic6x4Z0W5EltglSFnAcB7ulIL3JEUQJH5Hr2l/z6JlRsNalfq6BcCfjKvAj A/ePNKMUbjPbVkZSg+jaPLF0FQ+UpFYLQ/Rcio52l545Dp9pyaJkaLSFTbVsYy8PWjf/ ffSH9+EovqeSe4kEUnRyjBJXUU1DtlGiKikA5V3fqYz9taWP5JG+htBaVRd3EDpVFT9l lffw== 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=9qViGrdUGpa0ThWB+YcFxDSbeYaJXJqK+FKlEA3vuxA=; b=IJILKwqc/eCb1ttSeEQT4wWtUseSRvEpSMYFSQmh8VqY6krOVZ430mkiIg5QHDPxQT GM95hRfrbUTY7tJEt+fYPWJUv97oqwn7Qs8upzGO7ossuue9cOHFiwDPpS8yOAikChQH ecSSawvsdbrmzARQ5cPklPDy5JNhonWEubPgLH5RZ7bfnxMrZNzpbZ2dd9loF7G4lpoD McMXHwnuleitN84+FZoq5JonCR4c4BN/tQ3quKrwy5wfhVWuU6NZnuA/0X3PLsLTjJbB NX/2t780uqj8J9vKHaRrQ/gOT39S6G8A+H6+y93wm60eFvHmrfZapfO2A5gS7ODcurIu Dabw== X-Gm-Message-State: AOAM533jH2iPsxLrW91a0U7BuTPWc+7x+T7oiSOtfsC80akudHDPDti3 lw8FQiWCwbOM7CId1fxCA3s0SA== X-Google-Smtp-Source: ABdhPJy7+7QERE4fHeCWidnhS46dr4Oq55POtQVLZeXG+8jIPa6GyhVDO/qNZvzRbwQjpN82CwAdSw== X-Received: by 2002:adf:81e6:: with SMTP id 93mr33456129wra.412.1600367771799; Thu, 17 Sep 2020 11:36:11 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id x16sm571901wrq.62.2020.09.17.11.36.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2020 11:36:11 -0700 (PDT) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org Subject: [PATCH 4/7] crypto: sun4i-ss: handle BigEndian for cipher Date: Thu, 17 Sep 2020 18:35:55 +0000 Message-Id: <1600367758-28589-5-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600367758-28589-1-git-send-email-clabbe@baylibre.com> References: <1600367758-28589-1-git-send-email-clabbe@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200917_143612_900171_EF8B4E60 X-CRM114-Status: GOOD ( 15.84 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:444 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe , linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Ciphers produce invalid results on BE. Key and IV need to be written in LE. Furthermore, the non-optimized function is too complicated to convert, let's simply fallback on BE for the moment. Fixes: 6298e948215f2 ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator") Cc: Signed-off-by: Corentin Labbe --- .../crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 17 +++++++++++------ 1 file changed, 11 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..d66bb9cf657c 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); @@ -213,6 +213,11 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) if (no_chunk == 1 && !need_fallback) return sun4i_ss_opti_poll(areq); +/* The non aligned function does not work on BE. Probably due to buf/bufo handling.*/ +#ifdef CONFIG_CPU_BIG_ENDIAN + need_fallback = true; +#endif + if (need_fallback) return sun4i_ss_cipher_poll_fallback(areq); @@ -225,13 +230,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 Thu Sep 17 18:35:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11783297 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 3B954618 for ; Thu, 17 Sep 2020 18:38:40 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ED386206D4 for ; Thu, 17 Sep 2020 18:38:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="04Hkp8fh"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="dy8qrGfB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ED386206D4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=0vQkeOtCmxrNOJGWk9iOzhiwn+h39u4Gbh4fG6Od6ac=; b=04Hkp8fhZpqUgVkGCjc6eAgABl m4Ycvh4n4xM/C4R8wIG6I4Gb5F1OOJUtLkSwpJI1zNTYUZ7zUiS3frH3dvyYWTlqxcTymkBXGb99S F8fW63qeBLMb31KJULWfSG+iByDc0RlT/7G33VtctuuBk4KaWSl6Vhn5F6AmUtlmG9+4JECGdAg3n 6/W/cjV36+NVGp9xtI4V3V81HISh16poAvaRvDaM4RQVbDCcQ2v+V9/4KLJtFanDzVa08/G1kS9qs zwQZk3DoEmylvaxVa8k/dDFRCCy84GkAq0kHLooQKJEAvvaPswcNDTOMmyE7Y+OcvK/QjX87xxXlM DA8OR/1g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIym8-0006I3-W9; Thu, 17 Sep 2020 18:36:57 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIylR-00066J-Ko for linux-arm-kernel@lists.infradead.org; Thu, 17 Sep 2020 18:36:14 +0000 Received: by mail-wr1-x442.google.com with SMTP id w5so3112063wrp.8 for ; Thu, 17 Sep 2020 11:36:13 -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=95zSQXucA3JVtCyytHmj0YY6t7Txi03VIMdUw17K6OY=; b=dy8qrGfBrIm415C/AKe+zhxMSYXEPCm5p9tVIbpQLxrIuNdaArcxZmfXZ2+/RjNVSr cePOmHKnEe8/oekKxsYVXhS0ri5fv0JFc85DA/dP2bKxJfQfndLjhVb+x/+zOD/HXyMn rj45ayusWqqcbZXaaPYBr297PIQka5gcTb11rNycGtej9/l27rxbt4x+xnzUFOmN+/6d QBYEM6og75J3XUgMb306Mumrb7sSofApnV8jTGgGvhykwNDPRHl3XBZwxQ9j+n/b/U/i rkWlL9qDydk04KgRl65sEpqnbosBla5cYMC5Mom2JtamY9zp/HfqYT1X2z+PJDfr6d5F Umlw== 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=95zSQXucA3JVtCyytHmj0YY6t7Txi03VIMdUw17K6OY=; b=t9HuzOebzfOnt4DpQ2Uc5hjCZA78r9P102ceVqP7M3n2JWPjHa4q0twpx6GJtx9yzG dqtTQ/1il23Hrhtr+EbatSsMv01KHoQJVBG7wfyUQwv2Lkxy+34oz3Q/Dk/x38eQHBba 2GgnGa2TL+uAqfJGcvTC/qj3rad4QrC2zYD4L7ZxHoDaQd/vUJCNlYujOCkj9a3F7acc Wzz/o9ltI8BKQpcU5NA5K3xlZ2QM7k5X5bRo/E7i6psKI0ykudh++VK4KG/tnRYQieqo PYlX0KmteBFgbulVu8iqKUHqqNn0D6b0BYFNbNssmSK6fVJe5UISwqcyqVK6reF7vnRi x0Rw== X-Gm-Message-State: AOAM530nXVD/o4KzP3clFRHLwhWtKo20s//lYkbgqYzNVBVtoP4TsqCP vfJK+W0aVZJrB5kUeFAaJj+Z1Q== X-Google-Smtp-Source: ABdhPJyOLICoWIu3123UpyJexAwTB9qPRSR1qGn78IXm3kL9cpE2LR7gh5Zt/pUtPXnwu2PxLEAwlQ== X-Received: by 2002:a5d:5261:: with SMTP id l1mr33249298wrc.193.1600367772844; Thu, 17 Sep 2020 11:36:12 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id x16sm571901wrq.62.2020.09.17.11.36.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2020 11:36:12 -0700 (PDT) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org Subject: [PATCH 5/7] crypto: sun4i-ss: initialize need_fallback Date: Thu, 17 Sep 2020 18:35:56 +0000 Message-Id: <1600367758-28589-6-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600367758-28589-1-git-send-email-clabbe@baylibre.com> References: <1600367758-28589-1-git-send-email-clabbe@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200917_143613_796778_8C48EC7A X-CRM114-Status: GOOD ( 16.88 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:442 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe , linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 d66bb9cf657c..c21a1a0a8b16 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 Thu Sep 17 18:35:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11783277 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 B2023618 for ; Thu, 17 Sep 2020 18:37:22 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6FDB4206D4 for ; Thu, 17 Sep 2020 18:37:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gdOvUYv2"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="XClmft36" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6FDB4206D4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HHtde9RrPjxT4fDmr7Pabws2pry08u8vAF+T6WiV9r4=; b=gdOvUYv2soU877z+yKxroRq558 Pk32wFJyo2Qw8HG+7KSB+FLjR5hCe7Bn2twAnXDsK3Uri+0iZq9vaz9wPX/lpWA1D+ft5p3ilc6wD TjrTlHhHL1klL08Pofi0XWYeeNTuzzaL+1i4ErDPlLzWSB8qK5PXJsfPKfHMfPG/oLp3sQ5s3jLN9 Ebsa5O64i11Q3TAzfYZek41WIykFKiWGA1ZFNvgG0Sx9iPWeJW04AtKKO5jkq47Bacll63eVQHM7i 50KKCBhjRxioZii3qjRzwKYvLFwu+2Tk5LBonRvD+kH3aThkcVZuk4aOHYThPKzn+eHd3QZbQJ69C 8RF+xKng==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIymJ-0006Oi-K0; Thu, 17 Sep 2020 18:37:07 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIylS-00066q-Mx for linux-arm-kernel@lists.infradead.org; Thu, 17 Sep 2020 18:36:16 +0000 Received: by mail-wr1-x441.google.com with SMTP id o5so3095107wrn.13 for ; Thu, 17 Sep 2020 11:36:14 -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=SdHelnHrIfhdBmXdug1FChKyG7T3Sv9OQk7JTWtycnw=; b=XClmft36wq66EBrOpv8lSS73dG/SktaF4Nc0VJZtC1/dzAUC/4zNXqLulkOXCikLpq UXrUZPpMwk0+lw9g6z5lZYQzF4eZS2hLDMxoK6rab3DjqDD32q6dN+fyCv9FLoF5YU6f BcM3AbfAJPogtKDBJ319T0X3XwzXa4PMyZ6O54SyFgdr4mn6kMooLmg717bujnbxJdU6 AkVnL8Szk1NEciRmmoQMMKAAmrEL/VDN9hmAu48b7q/FCmkXZLMZJAVzwbTFm0K2q0JL km0hMPTptvN1ai5/7pn7+miqaVWvwKq2PDJPd/Ka51lO1OLyZSVLoXhfK43r9N7601LM t2ng== 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=SdHelnHrIfhdBmXdug1FChKyG7T3Sv9OQk7JTWtycnw=; b=emmRMfVH08KOBTR7yYZi/COHjnofR0PbgpxDFdjJPUt0i4jQSla6AV6MlkQ6mdMD86 MZRskgtQ6DF6Bt8exokAycts3kBRUr+2Mf0jnUwCYfQh/GEzqB1qRk9uOjrbP0levyxw 3vjtgzsHwbeHdBKBa3aGGbWA/N3yMCrcWyFr1JB1HKAdBxRQXr853egyw84O21a5kj4Z YnUzkjAwxWkSzywVawI2bcZjIBO2u5pxvn6sXk6oTQVcNupnm1VfyemSAhVZjW5JlI39 HcQv2U1LpHPzXUZZEyug+gH89fhg9dbTD9hB2yxjPTvO8jiF0/H/Lb3th1sI0Lx0dyVT de1g== X-Gm-Message-State: AOAM531TtWqTb/WrzkTwXONimA4FMmnMVUVMkSRGy5XzYmD3qNZYCZnk JON2VXfaXCDbMz15R4A8uaAreA== X-Google-Smtp-Source: ABdhPJwfEu7lEY94WzW8h+jGsLcci6F5r/8iU0L+hzcDtJIrfCTxLwLochPoKHE13UDzQjktO/N2KQ== X-Received: by 2002:adf:8b48:: with SMTP id v8mr33777987wra.21.1600367773784; Thu, 17 Sep 2020 11:36:13 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id x16sm571901wrq.62.2020.09.17.11.36.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2020 11:36:13 -0700 (PDT) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org Subject: [PATCH 6/7] crypto: sun4i-ss: enabled stats via debugfs Date: Thu, 17 Sep 2020 18:35:57 +0000 Message-Id: <1600367758-28589-7-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600367758-28589-1-git-send-email-clabbe@baylibre.com> References: <1600367758-28589-1-git-send-email-clabbe@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200917_143614_798959_25D0C0E3 X-CRM114-Status: GOOD ( 24.23 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:441 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corentin Labbe , linux-sunxi@googlegroups.com, linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 c21a1a0a8b16..be6599220e9d 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); @@ -228,6 +244,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 Thu Sep 17 18:35:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11783299 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 980596CA for ; Thu, 17 Sep 2020 18:38:55 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5C57A206D4 for ; Thu, 17 Sep 2020 18:38:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HZtO9KTi"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="t1F4i2ut" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C57A206D4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kvWwVrfDakPRikXX0hnYXupBWUKPTzw4xmIwE/Gm5mM=; b=HZtO9KTiiit0UWX9bghar4QdQX /4ARrLYxMm458EsT256hSZDrFk4cjWAiX3wehxQcafeqzxQc4Wz90WgzzTVMAKvzOdeQuZVbxiNYK HxEUdutSaveuH1UnSr8LTkMkU/ESCAYIwWFRzthyC8GtBye4jm1PpZM5gonWsfvkDE65H4wJSZHuq S4n747ATYPx0ySDHs5DX7URqmYDvoFq8EM1DKxGZIzJMyceDAjEe+yoQtKtDAhvxF8/FMRGgCUdPt 42WVV3PFx73BzIj2LEepTs/VIDMbZpsaaj9MV7g0rKZUBMNMlIJfq7IiiUpz0QnlBpBdLqqPT3ww9 a0OafZ5w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIymQ-0006Rq-Nj; Thu, 17 Sep 2020 18:37:14 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIylU-00067I-Ar for linux-arm-kernel@lists.infradead.org; Thu, 17 Sep 2020 18:36:17 +0000 Received: by mail-wr1-x436.google.com with SMTP id j2so3116667wrx.7 for ; Thu, 17 Sep 2020 11:36:15 -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=XM0rn9lgSMh+/oP0wbhw4Z0Og4lOLAMikZRs+DnstJg=; b=t1F4i2utZ2d6rs6DCDEg4dyCXwYJlvBxt8DAK7YCJPHWLEuWYXH+YP7uoYpl016u8t R4PnzNq5M2D/veKMddKOixuoUYhHx0Ug4NcDn0Lq4wFCE0AlpgKfh9rf/6jG5dtNyR6R DOpOWrtTBqxl96lLAdOcxUVPkbt4v8lWwcTJpGp66IEn3Jg6jiLT0n7khrcG6R1nkY/e iUrlTNbDuw47FgRinC3Jlk4Nqi6JcZX7zeDcWOZSvyNib80nmJ7wJ6HAj1OjwjZrsRq6 lCv79+SzNgXnA0VhnjgiGBEAtTHLSyq+kQgc2XdhLMOurmIsXN0b9RbDLGKkktFjqb6/ TyXg== 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=XM0rn9lgSMh+/oP0wbhw4Z0Og4lOLAMikZRs+DnstJg=; b=s4aaRH7v5RclY9bZ4UB3YA9bx8dbx1KGXENWSXva4UlRdC49Vai5T9PTKlbNcHQhSx bo1Qp5v51+V8sTAS04JV6w7nWYmYgl9Kaer+OLCfiLMrVs/w6wvhDE+385CnrWFTbxZz aPZwgI3FIL9FEjt/EJO3QzuRzn+6k29ZL8+E3FB4pLwQcEy7kEnDV9RhpX6EogJDcSE3 SnxyTOIklYuMCCpb5a+PDOcmru5C4KpFH2wj0k7yIgz01K0ZjHsvySCtrQzmXBRe6/v+ aTQ37X3ie2c9Q8Z6Qy5hQ6khpCHHa+PtKwS86SM6WLAnOOxO3g6HmMavIZO4lJVMXumO 0B9Q== X-Gm-Message-State: AOAM530DWbEbRYm+neIsvhhktpHswRowo3ZaCps961NrW/9oYzHrf37d 9SdmhCeJRX09cHxEc11nUvig8Q== X-Google-Smtp-Source: ABdhPJxBCR6h6xFHou/Y3/DMQ76QCXKRZvp9f6aSU4/C91Y2zTMNW6ZBe33yJ+uulWo9T5gTTbvvuA== X-Received: by 2002:adf:edd2:: with SMTP id v18mr33152164wro.242.1600367774867; Thu, 17 Sep 2020 11:36:14 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id x16sm571901wrq.62.2020.09.17.11.36.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2020 11:36:14 -0700 (PDT) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org Subject: [PATCH 7/7] crypto: sun4i-ss: add SPDX header and remove blank lines Date: Thu, 17 Sep 2020 18:35:58 +0000 Message-Id: <1600367758-28589-8-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600367758-28589-1-git-send-email-clabbe@baylibre.com> References: <1600367758-28589-1-git-send-email-clabbe@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200917_143616_424205_E1D53478 X-CRM114-Status: GOOD ( 15.22 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:436 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corentin Labbe , linux-sunxi@googlegroups.com, linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 be6599220e9d..2011aa4f0415 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); @@ -549,7 +548,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; @@ -636,5 +634,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,