From nobody Mon Dec 15 21:58:23 2025 Received: from abb.hmeau.com (abb.hmeau.com [144.6.53.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4EB121170D; Thu, 8 May 2025 05:22:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=144.6.53.87 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746681743; cv=none; b=UYBbP8akYmS4LxHB7Xuwy1XNucUAXE9u40BYP5E/MPPSn6JFSU98G/tBgrgnAHintI2V19oOl5ZWf168kErqxMU6GEaiVxaZWeHcafFtJxUubpf75ZLQvgs1RfzuQr02TdguAshfUs9//OlTsdSF5h03MDH7EfYVl0RvWkhl0k4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746681743; c=relaxed/simple; bh=VnfzAszDJs6C3MTGH96Wn5SIno/KO76bixpJGo+tSng=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jV9f+LqfCAKhi2CNhF2TAjF4V0gHmW8lwLs6nEttzyWSre8vwKj6zh0MU/b6UOuEYmehDHPlFDOtm1mr7jAPAl5q0/HslVluexV28FENNgL9+SleJ3mY3xcWbbNFTlRvaqLU1BifeTygsbUeMIL+1lmjmQkIvs7ZeezsDim71PM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au; spf=pass smtp.mailfrom=gondor.apana.org.au; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b=QFiI4sTG; arc=none smtp.client-ip=144.6.53.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gondor.apana.org.au Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hmeau.com header.i=@hmeau.com header.b="QFiI4sTG" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hmeau.com; s=formenos; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=B1YflQXHgKTBvxl3yJJUFyz/5qdf/sizpnYgftr2KE8=; b=QFiI4sTGDzPUQVbXBOij/eCwrt wdylp2G1lSeJrOxS20JGXlOrBidZxszgwwn910003aRwJrCGcBwnfblZXOFKR5U8D6c9oU/EUuAwQ 833+brG7Nw4Rq0S9tko5+94OcS4Vbnzl5UCQE2tBGuHB3yrjwV3efQip5+7g+1sUa6j66YvBRO2CC JvZzWNNbNav63T/cwa1uav6bnLroE8z9vVVtCcgjKyAuHsnWvjdUjVlNHWCeDT3cz4onzQ84hZ/po A1mMWVUF7t9k4f8IXubLZU3UqSEabEFq31/Iufos6/vOnAP/QmomgJPhHFhk2Jq0WkopMZ0LmgYDG q7ucxNvQ==; Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.96 #2 (Debian)) id 1uCti4-004Ri1-2m; Thu, 08 May 2025 13:22:17 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Thu, 08 May 2025 13:22:16 +0800 Date: Thu, 8 May 2025 13:22:16 +0800 From: Herbert Xu To: Corentin Labbe Cc: Klaus Kudielka , regressions@lists.linux.dev, linux-kernel@vger.kernel.org, Linux Crypto Mailing List , Boris Brezillon , EBALARD Arnaud , Romain Perier Subject: [v3 PATCH] crypto: marvell/cesa - Do not chain submitted requests Message-ID: References: <15fadc356b73a1e8e24183f284b5c0a44a53e679.camel@gmail.com> <5db212655dc98945fa3f529925821879a03ff554.camel@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" v3 simplifies it a little bit: =20 Reported-by: Klaus Kudielka ---8<--- This driver tries to chain requests together before submitting them to hardware in order to reduce completion interrupts. However, it even extends chains that have already been submitted to hardware. This is dangerous because there is no way of knowing whether the hardware has already read the DMA memory in question or not. Fix this by splitting the chain list into two. One for submitted requests and one for requests that have not yet been submitted. Only extend the latter. Reported-by: Klaus Kudielka Fixes: 85030c5168f1 ("crypto: marvell - Add support for chaining crypto req= uests in TDMA mode") Cc: Signed-off-by: Herbert Xu --- drivers/crypto/marvell/cesa/cesa.c | 2 +- drivers/crypto/marvell/cesa/cesa.h | 9 +++-- drivers/crypto/marvell/cesa/tdma.c | 53 ++++++++++++++++++------------ 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/drivers/crypto/marvell/cesa/cesa.c b/drivers/crypto/marvell/ce= sa/cesa.c index fa08f10e6f3f..9c21f5d835d2 100644 --- a/drivers/crypto/marvell/cesa/cesa.c +++ b/drivers/crypto/marvell/cesa/cesa.c @@ -94,7 +94,7 @@ static int mv_cesa_std_process(struct mv_cesa_engine *eng= ine, u32 status) =20 static int mv_cesa_int_process(struct mv_cesa_engine *engine, u32 status) { - if (engine->chain.first && engine->chain.last) + if (engine->chain_hw.first && engine->chain_hw.last) return mv_cesa_tdma_process(engine, status); =20 return mv_cesa_std_process(engine, status); diff --git a/drivers/crypto/marvell/cesa/cesa.h b/drivers/crypto/marvell/ce= sa/cesa.h index d215a6bed6bc..50ca1039fdaa 100644 --- a/drivers/crypto/marvell/cesa/cesa.h +++ b/drivers/crypto/marvell/cesa/cesa.h @@ -440,8 +440,10 @@ struct mv_cesa_dev { * SRAM * @queue: fifo of the pending crypto requests * @load: engine load counter, useful for load balancing - * @chain: list of the current tdma descriptors being processed - * by this engine. + * @chain_hw: list of the current tdma descriptors being processed + * by the hardware. + * @chain_sw: list of the current tdma descriptors that will be + * submitted to the hardware. * @complete_queue: fifo of the processed requests by the engine * * Structure storing CESA engine information. @@ -463,7 +465,8 @@ struct mv_cesa_engine { struct gen_pool *pool; struct crypto_queue queue; atomic_t load; - struct mv_cesa_tdma_chain chain; + struct mv_cesa_tdma_chain chain_hw; + struct mv_cesa_tdma_chain chain_sw; struct list_head complete_queue; int irq; }; diff --git a/drivers/crypto/marvell/cesa/tdma.c b/drivers/crypto/marvell/ce= sa/tdma.c index 388a06e180d6..243305354420 100644 --- a/drivers/crypto/marvell/cesa/tdma.c +++ b/drivers/crypto/marvell/cesa/tdma.c @@ -38,6 +38,15 @@ void mv_cesa_dma_step(struct mv_cesa_req *dreq) { struct mv_cesa_engine *engine =3D dreq->engine; =20 + spin_lock_bh(&engine->lock); + if (engine->chain_sw.first =3D=3D dreq->chain.first) { + engine->chain_sw.first =3D NULL; + engine->chain_sw.last =3D NULL; + } + engine->chain_hw.first =3D dreq->chain.first; + engine->chain_hw.last =3D dreq->chain.last; + spin_unlock_bh(&engine->lock); + writel_relaxed(0, engine->regs + CESA_SA_CFG); =20 mv_cesa_set_int_mask(engine, CESA_SA_INT_ACC0_IDMA_DONE); @@ -96,25 +105,27 @@ void mv_cesa_dma_prepare(struct mv_cesa_req *dreq, void mv_cesa_tdma_chain(struct mv_cesa_engine *engine, struct mv_cesa_req *dreq) { - if (engine->chain.first =3D=3D NULL && engine->chain.last =3D=3D NULL) { - engine->chain.first =3D dreq->chain.first; - engine->chain.last =3D dreq->chain.last; - } else { - struct mv_cesa_tdma_desc *last; + struct mv_cesa_tdma_desc *last =3D engine->chain_sw.last; =20 - last =3D engine->chain.last; + /* + * Break the DMA chain if the request being queued needs the IV + * regs to be set before lauching the request. + */ + if (!last || dreq->chain.first->flags & CESA_TDMA_SET_STATE) + engine->chain_sw.first =3D dreq->chain.first; + else { last->next =3D dreq->chain.first; - engine->chain.last =3D dreq->chain.last; - - /* - * Break the DMA chain if the CESA_TDMA_BREAK_CHAIN is set on - * the last element of the current chain, or if the request - * being queued needs the IV regs to be set before lauching - * the request. - */ - if (!(last->flags & CESA_TDMA_BREAK_CHAIN) && - !(dreq->chain.first->flags & CESA_TDMA_SET_STATE)) - last->next_dma =3D cpu_to_le32(dreq->chain.first->cur_dma); + last->next_dma =3D cpu_to_le32(dreq->chain.first->cur_dma); + } + last =3D dreq->chain.last; + engine->chain_sw.last =3D last; + /* + * Break the DMA chain if the CESA_TDMA_BREAK_CHAIN is set on + * the last element of the current chain. + */ + if (last->flags & CESA_TDMA_BREAK_CHAIN) { + engine->chain_sw.first =3D NULL; + engine->chain_sw.last =3D NULL; } } =20 @@ -127,7 +138,7 @@ int mv_cesa_tdma_process(struct mv_cesa_engine *engine,= u32 status) =20 tdma_cur =3D readl(engine->regs + CESA_TDMA_CUR); =20 - for (tdma =3D engine->chain.first; tdma; tdma =3D next) { + for (tdma =3D engine->chain_hw.first; tdma; tdma =3D next) { spin_lock_bh(&engine->lock); next =3D tdma->next; spin_unlock_bh(&engine->lock); @@ -149,12 +160,12 @@ int mv_cesa_tdma_process(struct mv_cesa_engine *engin= e, u32 status) &backlog); =20 /* Re-chaining to the next request */ - engine->chain.first =3D tdma->next; + engine->chain_hw.first =3D tdma->next; tdma->next =3D NULL; =20 /* If this is the last request, clear the chain */ - if (engine->chain.first =3D=3D NULL) - engine->chain.last =3D NULL; + if (engine->chain_hw.first =3D=3D NULL) + engine->chain_hw.last =3D NULL; spin_unlock_bh(&engine->lock); =20 ctx =3D crypto_tfm_ctx(req->tfm); --=20 2.39.5 --=20 Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt