From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 129BCC433F5 for ; Mon, 11 Apr 2022 08:43:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7MXIEsX4NPWiYcIWNxyhv7MCcu6YPmF8MJuCVdLP+9Q=; b=l0j/FF5OKT5FY3 gIYOMOMeaIazBHp0VPIHBCu75w+suhFvF1/NrotegwT77sE60C2Jbv1xMKad+L8lmqa5V0+SOau+q Y30i21LQChjme9iH21riizZdBP/b0w4o1EoWs5FK/mxXFihSsNFulMzUGgdjUcVykCF2hbI7agLML GKFwpp+JF+/VBKAJLFAeGUO5UiSmUsr1/6dHn+yxY+QMb7SjfOUjED/NE7p46Dlps/m0kVcmntYMw ur1fAFPlboZPAgKQkGXuEh46iaF+pxDdzcZfiYsyVRbT/S9gZBPX87FSK2lMq23Y6dZ3BJxFRjDn3 KL9UqmcYxmHKQglirLwQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndpd4-007blH-3I; Mon, 11 Apr 2022 08:42:34 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndpd1-007bkP-7F for linux-arm-kernel@lists.infradead.org; Mon, 11 Apr 2022 08:42:32 +0000 Received: by mail-wr1-x431.google.com with SMTP id e21so5393838wrc.8 for ; Mon, 11 Apr 2022 01:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=8C/eYgaWADBmXGolQTtkrHTLecaGjlBMq7BNuIlcZ8Q=; b=xeJcy/KGJE8E9dTJtbqIY8xwk3sT+9zWBdf3lwNQ3wiHwbo4fFi8C+BojzWUb7Nts5 YPHs4k4QJ+0sAnvMgpBPi22mDZOONbSIFtlnjK/F59s/8G5mPCd2VtQv5dvyliQPsxYp KmY7lSTcYSkZjPO7nyfaPW2MGED205fey3U79yIsgipqxg9s588DuLwxZoS624dnuMgM MHMyVZLpuUay/uFgMoPsgbusEwXdLTEqSSHSIgL/tziKq/jixkyvnP9IpacQh9Y4GqEV Rm3sXKIwUpMR9FpWp1I6M9UhCnaMeQFSP4Q/dXQ3qck3BCxgik8RLUyCr26oF7Q4kt7N JBRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=8C/eYgaWADBmXGolQTtkrHTLecaGjlBMq7BNuIlcZ8Q=; b=Z/6dCg9AJHfGDqQavo5S0YfarMRCHZjS4kqUMwGxpCqDp9So4qgrHowoop6zF3bJBX ouagZQo/eSVlBnVLbz0M3EgBvbI2FM7AKOq2ISwe4dDxjrJj1kMrU1BfMWyPH7uJApLN XChFIlaDcZd9I2ND0mCg1iHOlUBlm/UkfTbxUHbzK3rzI9IONKYb3gF0RSCJfL1/a0+Z DNoM65u1PT0159b7A7nb4POmjEgD6ydW79dADir2C1vI7K/5YMCndGQkdX1lh18YCrly 8VyOEroB5+qGj2EzoNKnyxahIXmMsFyFPOpOfoWay4aR+ydSGCFA+LGj3qaE+LNy6CHS IQzQ== X-Gm-Message-State: AOAM530czapJoQC0ZcA+ologH1fcGhaAbiZQTfYVE57aRnqRrKqTqb11 NmDNeXnh6L5XN+i7MfVP6rYhuQ== X-Google-Smtp-Source: ABdhPJwj2GX5sxFvKfF2plvDXxPFsbnq+9QtCMe/UP3BTx6ywnM8X9ZtvNekIgx0mHUmfcedMxPk8Q== X-Received: by 2002:a5d:5406:0:b0:205:a2c2:3530 with SMTP id g6-20020a5d5406000000b00205a2c23530mr23927622wrv.587.1649666549614; Mon, 11 Apr 2022 01:42:29 -0700 (PDT) Received: from Red ([2a01:cb1d:3d5:a100:264b:feff:fe03:2806]) by smtp.googlemail.com with ESMTPSA id c4-20020a056000184400b00207a55f712asm3337327wri.37.2022.04.11.01.42.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 01:42:29 -0700 (PDT) Date: Mon, 11 Apr 2022 10:42:26 +0200 From: LABBE Corentin To: John Keeping Cc: heiko@sntech.de, herbert@gondor.apana.org.au, krzk+dt@kernel.org, robh+dt@kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org Subject: Re: [PATCH v4 06/33] crypto: rockchip: add fallback for cipher Message-ID: References: <20220401201804.2867154-1-clabbe@baylibre.com> <20220401201804.2867154-7-clabbe@baylibre.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220411_014231_300863_5594E9AB X-CRM114-Status: GOOD ( 25.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Le Mon, Apr 04, 2022 at 12:26:15PM +0100, John Keeping a =E9crit : > On Fri, Apr 01, 2022 at 08:17:37PM +0000, Corentin Labbe wrote: > > The hardware does not handle 0 size length request, let's add a > > fallback. > > Furthermore fallback will be used for all unaligned case the hardware > > cannot handle. > > = > > Fixes: ce0183cb6464b ("crypto: rockchip - switch to skcipher API") > > Signed-off-by: Corentin Labbe > > --- > > diff --git a/drivers/crypto/rockchip/rk3288_crypto_skcipher.c b/drivers= /crypto/rockchip/rk3288_crypto_skcipher.c > > index bbd0bf52bf07..c6b601086c04 100644 > > --- a/drivers/crypto/rockchip/rk3288_crypto_skcipher.c > > +++ b/drivers/crypto/rockchip/rk3288_crypto_skcipher.c > > @@ -13,6 +13,71 @@ > > = > > #define RK_CRYPTO_DEC BIT(0) > > = > > +static int rk_cipher_need_fallback(struct skcipher_request *req) > > +{ > > + struct scatterlist *sgs, *sgd; > > + unsigned int todo, len; > > + unsigned int bs =3D crypto_skcipher_blocksize(tfm); > > + > > + if (!req->cryptlen) > > + return true; > > + > > + len =3D req->cryptlen; > > + sgs =3D req->src; > > + while (sgs) { > > + if (!IS_ALIGNED(sgs->offset, sizeof(u32))) { > > + return true; > > + } > > + todo =3D min(len, sgs->length); > > + if (todo % bs) { > > + return true; > > + } > > + len -=3D todo; > > + sgs =3D sg_next(sgs); > > + } > > + len =3D req->cryptlen; > > + sgd =3D req->dst; > > + while (sgd) { > > + if (!IS_ALIGNED(sgd->offset, sizeof(u32))) { > > + return true; > > + } > > + todo =3D min(len, sgd->length); > > + if (todo % bs) { > > + return true; > > + } > > + len -=3D todo; > > + sgd =3D sg_next(sgd); > > + } > > + sgs =3D req->src; > > + sgd =3D req->dst; > > + while (sgs && sgd) { > > + if (sgs->length !=3D sgd->length) > = > This check still seems to be triggering the fallback when it is not > needed. > = > I've done some testing with fscrypt and the series is working great, but > the stats show the fallback triggering more than I'd expect. With some > extra logging here I see output like: > = > sgs->length=3D32 sgd->length=3D255 req->cryptlen=3D16 > = > In this case sgs and sgd are both the first (and only) entries in the > list. Should this take account of req->cryptlen as well? > = > In fact, can't this whole function be folded into one loop over src and > dst at the same time, since all the checks must be the same? Something > like this (untested): > = > while (sgs && sgd) { > if (!IS_ALIGNED(sgs->offset, sizeof(u32)) || > !IS_ALIGNED(sgd->offset, sizeof(u32))) > return true; > = > todo =3D min(len, sgs->length); > if (todo % bs) > return true; > = > if (sgd->length < todo) > return true; > = > len -=3D todo; > sgs =3D sg_next(sgs); > sgd =3D sg_next(sgd); > } > = > if (len) > return true; > = Thanks, for this hint, I will use it. Regards _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel