Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9987067ybi; Wed, 24 Jul 2019 13:36:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqx50KPQfdIPH41kx2/YuXGvBkL2xB6vy3OeFFZ3+hqbnyXWJ0EnBGYThLhgn2DmzWdPn23Q X-Received: by 2002:a63:1e0b:: with SMTP id e11mr77114881pge.402.1564000590144; Wed, 24 Jul 2019 13:36:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564000590; cv=none; d=google.com; s=arc-20160816; b=RQpKKN0unxTedvAwwHdRiAWBOwmOqsV7zyqM8FeEBW09W4A4O1sgyJSG4Ucn7+uM8n EL+CX3v7CeMJzJv8YgrjUjWLlAsgLruIRhkA5GQvbwtawSIve9rq+TSBBgUnThBfA8cr QFy9nCRaFYB4jhOSac70hUz4mz3vPnbB6r9G2NydCqLi/LuukMCdPhFa+rZoXZIXhHpN 61FnLBcijjr1NVHBBNu6/oVRtA3XK8cBAS93Vqwmc5oy6Xiwlh3fhGJ/HH8G7pN0T0Gm KWifxtusZcJUwrYd7MC+XTD9rGQ4n5e/6J+OeL2/nWh7Sq6UgsBmqVS2uIPyz2jvGf5G jPiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=A++hfk3azg9dEXuawmW+cNYS7pZwIirEg+qmaeGbwc0=; b=BUncNAoA+HkXt0QmB5ehFyax7MIThRYqIUne2kEQ47W5yw4gDA5PQ+xE4r/+UoiNxs 3hGsUzVLYM4duT/jKo58Nh3GFfpj3ukDwNANKzfiXPHAAarPURiBBJLKcD4ggqqj165d PFn11SyB1/tj9S9c4jVQizSRX0s3DDjsSp2tm29IqViVBEPGnBypHYMV7N6Php1phgEj IuepZeYkZTa5ArnqiXH0h2ng8iuQyU8S763JSTO+xJ2/ZxXJ59MCtjraotdPobbezY04 SHQHAZPv3u/dfHoysha9rJ1FRJp9pjlXiS+XAFFOFl3sb7IWDqQJ4PdYys6oi/HA84mI H12g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NOtdzoNa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c1si15895309pld.418.2019.07.24.13.36.15; Wed, 24 Jul 2019 13:36:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NOtdzoNa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388083AbfGXT0P (ORCPT + 99 others); Wed, 24 Jul 2019 15:26:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:43158 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728520AbfGXT0L (ORCPT ); Wed, 24 Jul 2019 15:26:11 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EC983218EA; Wed, 24 Jul 2019 19:26:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996370; bh=3Xf/8TxSP6B0nYj1zPugHalsqJuC9fbdKprx1zpdIOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NOtdzoNajXISlX5JFgZB1Chcy9GxaawHZCSU00bVzA7g1/3msSfT98/oLthIYrtiD WeWYuIf+XPeQryL9X9RzO9mSo6hM7SPKBi0EWgrRKm+bbKNzrN7TsH1UmeBNWchs0a bzUC/lButCkALhkZ6/Iu1FJ3eye854f8u8s8+Fj8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Antoine Tenart , Herbert Xu , Sasha Levin Subject: [PATCH 5.2 071/413] crypto: inside-secure - do not rely on the hardware last bit for result descriptors Date: Wed, 24 Jul 2019 21:16:02 +0200 Message-Id: <20190724191740.189970410@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 89332590427235680236b9470e851afc49b3caa1 ] When performing a transformation the hardware is given result descriptors to save the result data. Those result descriptors are batched using a 'first' and a 'last' bit. There are cases were more descriptors than needed are given to the engine, leading to the engine only using some of them, and not setting the last bit on the last descriptor we gave. This causes issues were the driver and the hardware aren't in sync anymore about the number of result descriptors given (as the driver do not give a pool of descriptor to use for any transformation, but a pool of descriptors to use *per* transformation). This patch fixes it by attaching the number of given result descriptors to the requests, and by using this number instead of the 'last' bit found on the descriptors to process them. Signed-off-by: Antoine Tenart Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- .../crypto/inside-secure/safexcel_cipher.c | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/inside-secure/safexcel_cipher.c b/drivers/crypto/inside-secure/safexcel_cipher.c index de4be10b172f..ccacdcf07ffc 100644 --- a/drivers/crypto/inside-secure/safexcel_cipher.c +++ b/drivers/crypto/inside-secure/safexcel_cipher.c @@ -51,6 +51,8 @@ struct safexcel_cipher_ctx { struct safexcel_cipher_req { enum safexcel_cipher_direction direction; + /* Number of result descriptors associated to the request */ + unsigned int rdescs; bool needs_inv; }; @@ -333,7 +335,10 @@ static int safexcel_handle_req_result(struct safexcel_crypto_priv *priv, int rin *ret = 0; - do { + if (unlikely(!sreq->rdescs)) + return 0; + + while (sreq->rdescs--) { rdesc = safexcel_ring_next_rptr(priv, &priv->ring[ring].rdr); if (IS_ERR(rdesc)) { dev_err(priv->dev, @@ -346,7 +351,7 @@ static int safexcel_handle_req_result(struct safexcel_crypto_priv *priv, int rin *ret = safexcel_rdesc_check_errors(priv, rdesc); ndesc++; - } while (!rdesc->last_seg); + } safexcel_complete(priv, ring); @@ -501,6 +506,7 @@ static int safexcel_send_req(struct crypto_async_request *base, int ring, static int safexcel_handle_inv_result(struct safexcel_crypto_priv *priv, int ring, struct crypto_async_request *base, + struct safexcel_cipher_req *sreq, bool *should_complete, int *ret) { struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(base->tfm); @@ -509,7 +515,10 @@ static int safexcel_handle_inv_result(struct safexcel_crypto_priv *priv, *ret = 0; - do { + if (unlikely(!sreq->rdescs)) + return 0; + + while (sreq->rdescs--) { rdesc = safexcel_ring_next_rptr(priv, &priv->ring[ring].rdr); if (IS_ERR(rdesc)) { dev_err(priv->dev, @@ -522,7 +531,7 @@ static int safexcel_handle_inv_result(struct safexcel_crypto_priv *priv, *ret = safexcel_rdesc_check_errors(priv, rdesc); ndesc++; - } while (!rdesc->last_seg); + } safexcel_complete(priv, ring); @@ -564,7 +573,7 @@ static int safexcel_skcipher_handle_result(struct safexcel_crypto_priv *priv, if (sreq->needs_inv) { sreq->needs_inv = false; - err = safexcel_handle_inv_result(priv, ring, async, + err = safexcel_handle_inv_result(priv, ring, async, sreq, should_complete, ret); } else { err = safexcel_handle_req_result(priv, ring, async, req->src, @@ -587,7 +596,7 @@ static int safexcel_aead_handle_result(struct safexcel_crypto_priv *priv, if (sreq->needs_inv) { sreq->needs_inv = false; - err = safexcel_handle_inv_result(priv, ring, async, + err = safexcel_handle_inv_result(priv, ring, async, sreq, should_complete, ret); } else { err = safexcel_handle_req_result(priv, ring, async, req->src, @@ -633,6 +642,8 @@ static int safexcel_skcipher_send(struct crypto_async_request *async, int ring, ret = safexcel_send_req(async, ring, sreq, req->src, req->dst, req->cryptlen, 0, 0, req->iv, commands, results); + + sreq->rdescs = *results; return ret; } @@ -655,6 +666,7 @@ static int safexcel_aead_send(struct crypto_async_request *async, int ring, req->cryptlen, req->assoclen, crypto_aead_authsize(tfm), req->iv, commands, results); + sreq->rdescs = *results; return ret; } -- 2.20.1