From nobody Sat Jun 13 12:37:23 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 5AF7C3FBEDE for ; Thu, 7 May 2026 14:42:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164931; cv=none; b=B+gVeUeO+1ypptdIFP5snKJPcswlD5NfD0gFERlPY/s8ac1mtTN2HVAk+F4dkaqKnPYFmKADHOrvKx6wPtjk+eJ6uXSGUcALa6U4SyW7MI+kE/Q+SAuaF7jCpfkDQbDETHrUgCQPjCnMt6jzPCqHkaQdh9gDRvei6hSlpRz0Y3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164931; c=relaxed/simple; bh=aU/Voa/23EwpoAQsQuLJnYhLnVVV+SQ1H30DtJET1O8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YFTjjDrir+oUz1o710Nt4LT4OGjeoDEtb7iA4OIR8mjj9mdphMXX5mHVZ8pRgO9cNjy5291OO5wfXxADnbEFRFb0KImfkjHG+w2qTd/fi9Kciwi+4vDmSxvZi1H9yJZPp6wRsVzaTLhX3jJAbgKaOC9Em6HGOwneHG8o6+Lt5ws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=s6UIUO03; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="s6UIUO03" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id DFD5DC5DC5E; Thu, 7 May 2026 14:42:55 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 2B41A60495; Thu, 7 May 2026 14:42:08 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id DE072108194E5; Thu, 7 May 2026 16:42:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778164927; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=uUZeM/Mxnjiq6YpoyfU3hvFjy7+Al1VqF2S2MvM685c=; b=s6UIUO03hIL1YWRKIZnAWVzoiVZS9cpkxRsho5SK55JvwxX0NEazxYu2zFmSw34W8hvrJm vT6wT9/I06uqqxl2bH8oTZCBiVVSwENcrCVJ/TNYizcWzuEZFtuUBkY3rA+rchYHL3/Zf8 xgFdX+rhvV+YYnlUzTZD2wZnUvKL1hWG5zjWtc/sEJvXQqCU2dpCk7oVMHVwSy9cMzeAWq Nx5biL1MxpcLsEgzsyEgmy7CeQhUGw2+kMMcWEmr0JlFiiDqvhQ2sa5kt8ZMNoC2As0BJl enz8eMhzxEL2nmRTb3S8eY1O3yA3BEXqsqbna78LPbzDmQ6fxI4aEWx9vbY0QA== From: Paul Louvel Date: Thu, 07 May 2026 16:41:47 +0200 Subject: [PATCH v3 01/11] crypto: talitos - use dma_sync_single_for_cpu() before reading descriptor header Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-1-c98d7589b942@bootlin.com> References: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> In-Reply-To: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> To: Herbert Xu , "David S. Miller" , Paolo Abeni , David Howells , Kim Phillips , Christophe Leroy Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Herve Codina , Paul Louvel , stable@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164923; l=2350; i=paul.louvel@bootlin.com; s=20260313; h=from:subject:message-id; bh=aU/Voa/23EwpoAQsQuLJnYhLnVVV+SQ1H30DtJET1O8=; b=5AAuBKjlNTaNPDFblQxG1Fpk8Q7doDGojKq9KZdDf+KPZFxfqzSQsRL60CVEQ7N0suetyVns9 Awh2ntMsHyGCCxhjKlrK1G8fEH4fP5Q3sXyPOi5gH83aveAy4BBnn+e X-Developer-Key: i=paul.louvel@bootlin.com; a=ed25519; pk=eLW50NT18UAvUT5cAcYf88zNbBCZDLFXuptpyLVhVIU= X-Last-TLS-Session-Version: TLSv1.3 In order to know if a descriptor has been processed by the device, the driver polls the FIFO to see if DESC_HDR_DONE is set on a descriptor header to confirm completion. The current code does not make sure that the CPU gets up to date data before reading the descriptor. Fix this by calling dma_sync_single_for_cpu() before reading memory written by the device. Cc: stable@vger.kernel.org Fixes: 58cdbc6d2263 ("crypto: talitos - fix hash on SEC1.") Signed-off-by: Paul Louvel --- drivers/crypto/talitos.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index bc61d0fe3514..440e19dc8de6 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -322,19 +322,31 @@ static int talitos_submit(struct device *dev, int ch,= struct talitos_desc *desc, return -EINPROGRESS; } =20 -static __be32 get_request_hdr(struct talitos_request *request, bool is_sec= 1) +static __be32 get_request_hdr(struct device *dev, + struct talitos_request *request, bool is_sec1) { struct talitos_edesc *edesc; =20 - if (!is_sec1) + if (!is_sec1) { + dma_sync_single_for_cpu(dev, request->dma_desc, + TALITOS_DESC_SIZE, DMA_BIDIRECTIONAL); + return request->desc->hdr; + } =20 - if (!request->desc->next_desc) + if (!request->desc->next_desc) { + dma_sync_single_for_cpu(dev, request->dma_desc, + TALITOS_DESC_SIZE, DMA_BIDIRECTIONAL); return request->desc->hdr1; + } else { + dma_sync_single_for_cpu(dev, + be32_to_cpu(request->desc->next_desc), + TALITOS_DESC_SIZE, DMA_BIDIRECTIONAL); + edesc =3D container_of(request->desc, struct talitos_edesc, desc); =20 - edesc =3D container_of(request->desc, struct talitos_edesc, desc); - - return ((struct talitos_desc *)(edesc->buf + edesc->dma_len))->hdr1; + return ((struct talitos_desc *)(edesc->buf + edesc->dma_len)) + ->hdr1; + } } =20 /* @@ -358,7 +370,7 @@ static void flush_channel(struct device *dev, int ch, i= nt error, int reset_ch) =20 /* descriptors with their done bits set don't get the error */ rmb(); - hdr =3D get_request_hdr(request, is_sec1); + hdr =3D get_request_hdr(dev, request, is_sec1); =20 if ((hdr & DESC_HDR_DONE) =3D=3D DESC_HDR_DONE) status =3D 0; --=20 2.54.0 From nobody Sat Jun 13 12:37:23 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 7C50D40626E; Thu, 7 May 2026 14:42:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164933; cv=none; b=tohk3PE/vHIT1ORXB9wamBx2CZd1wI0HajK41HAqKeAtOWCTR65fLv7vjEWFXw3RWHUiZESZ0AL8VS5pwOop6OwEJF56VhHrRiSWx02T3DaULo4TwCCepGmvTq/YnJT/hijwwojzVcLKhy2G8A6yynal0Km6mX8vuGJn5iYAODA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164933; c=relaxed/simple; bh=tgmSAC1yYrk9dsR4lgtNRiHwRKbEITfm7NYGKudZCXo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Gr9w8dL1YYDlw818DnuO8zNLupqmIBGTYmMJ657KNVOz6zRa3mEd3uSndFja+FwgUlO1jJG3QMl9vgsDx6pkPQi1U5lsdnnJxrAZM15C0OIq9E5VygP1dJGep15yKNeUhLuRsBRYQIIZhi8mbbj1WCmIbfsJB99kxGFJIAyVBlA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=vuAWxa2f; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="vuAWxa2f" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 230191A3565; Thu, 7 May 2026 14:42:10 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id EBB1960495; Thu, 7 May 2026 14:42:09 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 79D45108194E8; Thu, 7 May 2026 16:42:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778164928; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=jkYIjWyWUk1nzGdUkssHblSGwBhJnrnDMZzy6dHJu+U=; b=vuAWxa2f4vESND0eRl6nvXKdbcdRVvefu0hXn3o07fpLUy4ENyb466S/bSBzFyN+I7d0WL EwUSjZweA7F2CeSvQq1RT9dIUGnnO33LfZtV75l66Vu/Rl823U0/RLKR70dzMD7daNsl14 CMMliMlbE4vr4eCOMMtgIiRCxnNpCyWQgtaevsoekIs1EJqm8pTovUOfA6B1bJ6SYyd+oc kpUpIEda7tv1r7W33eWVyn+Wx0tmxjFMmUx/jkcQWOe4DjbQUiCDEP+zRdwxSNqJ8qeXNr B671Mu9S8ugNcYZelKKEsaPDK2xIUpMR8sld4ShhWPxZelWRx8F1anAuER/V5Q== From: Paul Louvel Date: Thu, 07 May 2026 16:41:48 +0200 Subject: [PATCH v3 02/11] crypto: talitos - add chaining of arbitrary number of descriptor for the SEC1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-2-c98d7589b942@bootlin.com> References: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> In-Reply-To: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> To: Herbert Xu , "David S. Miller" , Paolo Abeni , David Howells , Kim Phillips , Christophe Leroy Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Herve Codina , Paul Louvel , stable@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164923; l=11196; i=paul.louvel@bootlin.com; s=20260313; h=from:subject:message-id; bh=tgmSAC1yYrk9dsR4lgtNRiHwRKbEITfm7NYGKudZCXo=; b=YoMe0enSv4jbBT1YPnZjByuC7a8np3dAq4SXpf1w4fCwBRQbMd0FMpCRPGQnzlsJgV7hnN0v8 rLTadHrlGFsCD21t3Ccz/HUo+6FrmTGB/Ajt4dvgEMwobl3L5PVKYiX X-Developer-Key: i=paul.louvel@bootlin.com; a=ed25519; pk=eLW50NT18UAvUT5cAcYf88zNbBCZDLFXuptpyLVhVIU= X-Last-TLS-Session-Version: TLSv1.3 The SEC1 hardware can process a chain of descriptors without host intervention. Only the hash implementation currently use this feature, but with a chain of at most 2 descriptors added in commit 37b5e8897eb5 ("crypto: talitos - chain in buffered data for ahash on SEC1"). Add supports for chaining an arbitrary number of descriptors in a chain. Adapt the ahash implementation to make it compatible. Cc: stable@vger.kernel.org Signed-off-by: Paul Louvel --- drivers/crypto/talitos.c | 180 ++++++++++++++++++++++++++++++++-----------= ---- drivers/crypto/talitos.h | 2 + 2 files changed, 124 insertions(+), 58 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 440e19dc8de6..b0ebf99b94f5 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -273,7 +273,10 @@ static int talitos_submit(struct device *dev, int ch, = struct talitos_desc *desc, void *context, int error), void *context) { + struct talitos_edesc *edesc =3D container_of(desc, struct talitos_edesc, = desc); struct talitos_private *priv =3D dev_get_drvdata(dev); + dma_addr_t dma_desc, prev_dma_desc; + struct talitos_edesc *prev_edesc =3D NULL; struct talitos_request *request; unsigned long flags; int head; @@ -292,10 +295,31 @@ static int talitos_submit(struct device *dev, int ch,= struct talitos_desc *desc, =20 /* map descriptor and save caller data */ if (is_sec1) { - desc->hdr1 =3D desc->hdr; - request->dma_desc =3D dma_map_single(dev, &desc->hdr1, + while (edesc) { + edesc->desc.hdr1 =3D edesc->desc.hdr; + + dma_desc =3D dma_map_single(dev, &edesc->desc.hdr1, + TALITOS_DESC_SIZE, + DMA_BIDIRECTIONAL); + + if (!prev_edesc) { + request->dma_desc =3D dma_desc; + goto next; + } + + /* Chain in any previous descriptors. */ + + prev_edesc->desc.next_desc =3D cpu_to_be32(dma_desc); + + dma_sync_single_for_device(dev, prev_dma_desc, TALITOS_DESC_SIZE, - DMA_BIDIRECTIONAL); + DMA_TO_DEVICE); + +next: + prev_edesc =3D edesc; + prev_dma_desc =3D dma_desc; + edesc =3D edesc->next_desc; + } } else { request->dma_desc =3D dma_map_single(dev, desc, TALITOS_DESC_SIZE, @@ -326,6 +350,7 @@ static __be32 get_request_hdr(struct device *dev, struct talitos_request *request, bool is_sec1) { struct talitos_edesc *edesc; + dma_addr_t dma_desc; =20 if (!is_sec1) { dma_sync_single_for_cpu(dev, request->dma_desc, @@ -334,19 +359,17 @@ static __be32 get_request_hdr(struct device *dev, return request->desc->hdr; } =20 - if (!request->desc->next_desc) { - dma_sync_single_for_cpu(dev, request->dma_desc, - TALITOS_DESC_SIZE, DMA_BIDIRECTIONAL); - return request->desc->hdr1; - } else { - dma_sync_single_for_cpu(dev, - be32_to_cpu(request->desc->next_desc), - TALITOS_DESC_SIZE, DMA_BIDIRECTIONAL); - edesc =3D container_of(request->desc, struct talitos_edesc, desc); - - return ((struct talitos_desc *)(edesc->buf + edesc->dma_len)) - ->hdr1; + edesc =3D container_of(request->desc, struct talitos_edesc, desc); + dma_desc =3D request->dma_desc; + while (edesc->next_desc) { + dma_desc =3D be32_to_cpu(edesc->desc.next_desc); + edesc =3D edesc->next_desc; } + + dma_sync_single_for_cpu(dev, dma_desc, TALITOS_DESC_SIZE, + DMA_BIDIRECTIONAL); + + return edesc->desc.hdr1; } =20 /* @@ -356,6 +379,7 @@ static void flush_channel(struct device *dev, int ch, i= nt error, int reset_ch) { struct talitos_private *priv =3D dev_get_drvdata(dev); struct talitos_request *request, saved_req; + struct talitos_edesc *edesc; unsigned long flags; int tail, status; bool is_sec1 =3D has_ftr_sec1(priv); @@ -380,9 +404,22 @@ static void flush_channel(struct device *dev, int ch, = int error, int reset_ch) else status =3D error; =20 - dma_unmap_single(dev, request->dma_desc, - TALITOS_DESC_SIZE, - DMA_BIDIRECTIONAL); + if (is_sec1) { + dma_unmap_single(dev, request->dma_desc, + TALITOS_DESC_SIZE, DMA_BIDIRECTIONAL); + edesc =3D container_of(request->desc, + struct talitos_edesc, desc); + while (edesc->next_desc) { + dma_unmap_single( + dev, be32_to_cpu(edesc->desc.next_desc), + TALITOS_DESC_SIZE, DMA_BIDIRECTIONAL); + edesc =3D edesc->next_desc; + } + } else { + dma_unmap_single(dev, request->dma_desc, + TALITOS_DESC_SIZE, + DMA_BIDIRECTIONAL); + } =20 /* copy entries so we can call callback outside lock */ saved_req.desc =3D request->desc; @@ -477,8 +514,12 @@ DEF_TALITOS2_DONE(ch1_3, TALITOS2_ISR_CH_1_3_DONE) static __be32 current_desc_hdr(struct device *dev, int ch) { struct talitos_private *priv =3D dev_get_drvdata(dev); + bool is_sec1 =3D has_ftr_sec1(priv); + struct talitos_request *request; + struct talitos_edesc *edesc; int tail, iter; dma_addr_t cur_desc; + __be32 hdr =3D 0; =20 cur_desc =3D ((u64)in_be32(priv->chan[ch].reg + TALITOS_CDPR)) << 32; cur_desc |=3D in_be32(priv->chan[ch].reg + TALITOS_CDPR_LO); @@ -489,27 +530,35 @@ static __be32 current_desc_hdr(struct device *dev, in= t ch) } =20 tail =3D priv->chan[ch].tail; - iter =3D tail; - while (priv->chan[ch].fifo[iter].dma_desc !=3D cur_desc && - priv->chan[ch].fifo[iter].desc->next_desc !=3D cpu_to_be32(cur_des= c)) { - iter =3D (iter + 1) & (priv->fifo_len - 1); - if (iter =3D=3D tail) { - dev_err(dev, "couldn't locate current descriptor\n"); - return 0; + do { + request =3D &priv->chan[ch].fifo[iter]; + + if (request->dma_desc =3D=3D cur_desc) { + hdr =3D request->desc->hdr; + } else if (is_sec1) { + edesc =3D container_of(request->desc, + struct talitos_edesc, desc); + while (edesc->next_desc) { + if (edesc->desc.next_desc =3D=3D + cpu_to_be32(cur_desc)) { + hdr =3D edesc->next_desc->desc.hdr1; + break; + } + edesc =3D edesc->next_desc; + } } - } =20 - if (priv->chan[ch].fifo[iter].desc->next_desc =3D=3D cpu_to_be32(cur_desc= )) { - struct talitos_edesc *edesc; + if (hdr) + break; =20 - edesc =3D container_of(priv->chan[ch].fifo[iter].desc, - struct talitos_edesc, desc); - return ((struct talitos_desc *) - (edesc->buf + edesc->dma_len))->hdr; - } + iter =3D (iter + 1) & (priv->fifo_len - 1); + } while (iter !=3D tail); + + if (!hdr) + dev_err(dev, "couldn't locate current descriptor\n"); =20 - return priv->chan[ch].fifo[iter].desc->hdr; + return hdr; } =20 /* @@ -1408,10 +1457,6 @@ static struct talitos_edesc *talitos_edesc_alloc(str= uct device *dev, dma_len =3D 0; } alloc_len +=3D icv_stashing ? authsize : 0; - - /* if its a ahash, add space for a second desc next to the first one */ - if (is_sec1 && !dst) - alloc_len +=3D sizeof(struct talitos_desc); alloc_len +=3D ivsize; =20 edesc =3D kmalloc(ALIGN(alloc_len, dma_get_cache_alignment()), flags); @@ -1427,6 +1472,7 @@ static struct talitos_edesc *talitos_edesc_alloc(stru= ct device *dev, edesc->dst_nents =3D dst_nents; edesc->iv_dma =3D iv_dma; edesc->dma_len =3D dma_len; + edesc->next_desc =3D NULL; if (dma_len) edesc->dma_link_tbl =3D dma_map_single(dev, &edesc->link_tbl[0], edesc->dma_len, @@ -1727,8 +1773,10 @@ static void common_nonsnoop_hash_unmap(struct device= *dev, struct talitos_private *priv =3D dev_get_drvdata(dev); bool is_sec1 =3D has_ftr_sec1(priv); struct talitos_desc *desc =3D &edesc->desc; - struct talitos_desc *desc2 =3D (struct talitos_desc *) - (edesc->buf + edesc->dma_len); + struct talitos_desc *desc2; + + if (desc->next_desc) + desc2 =3D &edesc->next_desc->desc; =20 unmap_single_talitos_ptr(dev, &desc->ptr[5], DMA_FROM_DEVICE); if (desc->next_desc && @@ -1756,10 +1804,17 @@ static void common_nonsnoop_hash_unmap(struct devic= e *dev, if (edesc->dma_len) dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len, DMA_BIDIRECTIONAL); +} =20 - if (desc->next_desc) - dma_unmap_single(dev, be32_to_cpu(desc->next_desc), - TALITOS_DESC_SIZE, DMA_BIDIRECTIONAL); +static void free_edesc_list_from(struct talitos_edesc *edesc) +{ + struct talitos_edesc *next; + + while (edesc) { + next =3D edesc->next_desc; + kfree(edesc); + edesc =3D next; + } } =20 static void ahash_done(struct device *dev, @@ -1778,7 +1833,7 @@ static void ahash_done(struct device *dev, } common_nonsnoop_hash_unmap(dev, edesc, areq); =20 - kfree(edesc); + free_edesc_list_from(edesc); =20 if (err) { ahash_request_complete(areq, err); @@ -1894,14 +1949,23 @@ static int common_nonsnoop_hash(struct talitos_edes= c *edesc, talitos_handle_buggy_hash(ctx, edesc, &desc->ptr[3]); =20 if (is_sec1 && req_ctx->nbuf && length) { - struct talitos_desc *desc2 =3D (struct talitos_desc *) - (edesc->buf + edesc->dma_len); - dma_addr_t next_desc; + struct talitos_edesc *edesc2; + struct talitos_desc *desc2; + + edesc2 =3D kzalloc(sizeof(*edesc2), + areq->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ? + GFP_KERNEL : + GFP_ATOMIC); + if (!edesc2) { + ret =3D -ENOMEM; + goto err; + } + edesc->next_desc =3D edesc2; + + desc2 =3D &edesc2->desc; =20 - memset(desc2, 0, sizeof(*desc2)); desc2->hdr =3D desc->hdr; desc2->hdr &=3D ~DESC_HDR_MODE0_MDEU_INIT; - desc2->hdr1 =3D desc2->hdr; desc->hdr &=3D ~DESC_HDR_MODE0_MDEU_PAD; desc->hdr |=3D DESC_HDR_MODE0_MDEU_CONT; desc->hdr &=3D ~DESC_HDR_DONE_NOTIFY; @@ -1925,21 +1989,21 @@ static int common_nonsnoop_hash(struct talitos_edes= c *edesc, req_ctx->hw_context_size, req_ctx->hw_context, DMA_FROM_DEVICE); - - next_desc =3D dma_map_single(dev, &desc2->hdr1, TALITOS_DESC_SIZE, - DMA_BIDIRECTIONAL); - desc->next_desc =3D cpu_to_be32(next_desc); } =20 if (sync_needed) dma_sync_single_for_device(dev, edesc->dma_link_tbl, edesc->dma_len, DMA_BIDIRECTIONAL); =20 - ret =3D talitos_submit(dev, ctx->ch, desc, callback, areq); - if (ret !=3D -EINPROGRESS) { - common_nonsnoop_hash_unmap(dev, edesc, areq); - kfree(edesc); - } + ret =3D talitos_submit(dev, ctx->ch, desc, callback, + areq); + if (ret !=3D -EINPROGRESS) + goto err; + + return -EINPROGRESS; +err: + common_nonsnoop_hash_unmap(dev, edesc, areq); + kfree(edesc); return ret; } =20 diff --git a/drivers/crypto/talitos.h b/drivers/crypto/talitos.h index 1a93ee355929..596f96bba3ef 100644 --- a/drivers/crypto/talitos.h +++ b/drivers/crypto/talitos.h @@ -49,6 +49,7 @@ struct talitos_desc { * @iv_dma: dma address of iv for checking continuity and link table * @dma_len: length of dma mapped link_tbl space * @dma_link_tbl: bus physical address of link_tbl/buf + * @next_desc: next descriptor * @desc: h/w descriptor * @link_tbl: input and output h/w link tables (if {src,dst}_nents > 1) (S= EC2) * @buf: input and output buffeur (if {src,dst}_nents > 1) (SEC1) @@ -63,6 +64,7 @@ struct talitos_edesc { dma_addr_t iv_dma; int dma_len; dma_addr_t dma_link_tbl; + struct talitos_edesc *next_desc; struct talitos_desc desc; union { DECLARE_FLEX_ARRAY(struct talitos_ptr, link_tbl); --=20 2.54.0 From nobody Sat Jun 13 12:37:23 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 9C2A7410D3A for ; Thu, 7 May 2026 14:42:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164936; cv=none; b=EsggsfCUT1olD90TAcq3y1I3cXeGFZtQP4E4aUfDXpf0yaL6Bx7za8w57pcnhQeitJskvvykaflHSCo0GcgG9pOX1Lm70ky9MQc0wo75enqmvMAaaSUeY08/7zdo+3SFbpinuB68FkDP6bjaKgGWYxigZnojxkwzViqYLi8yOu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164936; c=relaxed/simple; bh=EUCn4yRIq2JhyN/rWupn3xcECvK8Wf/hUel5shyMxtU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GYIPNbMTpDVayGTpTh/ggcy8G9amSkyOvXvKPlJn0fEJjdB0ZBiaWQR9SEsp/5raXbWAMzRymQATGkPfY5v+7hej6M17xbaErZfb3Oj3iTIcRyCSjIJMcftiYxzPGIwJl3zCWotO48HjHPuSBkjCi7GEEfVM5eIMHhTL3bFH0XY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=u2yWVPEl; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="u2yWVPEl" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 3A8D54E42C00; Thu, 7 May 2026 14:42:12 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 0FD3260495; Thu, 7 May 2026 14:42:12 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 362BD108194E6; Thu, 7 May 2026 16:42:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778164930; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=nJBg05tOx6ZkBxNNGx0RcyrPmBgZQOvBTvKUU1sK3Vk=; b=u2yWVPElGVkLIiuVBeVI8qgCChJx3XnokdAwj23c40k0naM5xmVfyFTQXHPZ+0W49a4gjs 8SQKTXFgMOzl/HTIXbu6dWzio64gv1yKb4gyOIybpGCMhuNsZ6z0vE6En4FXl4vjoZwTX7 fmMZW+c5LoiNH3P49M5Kuo/dL/a5GUVxLGkTEwwszNIF9AAP2zmlUrzDz77PX3vYD1bJsF DBmi3jOVMkSj4PcDzI0EfYDmfbQAIKiD+AH9BeDypohrRUs28eY3qFSXzo+8xao0in5HO9 nzH1LHQP2mPYcqB1E4jwHajyZOt3I9fjT8bB5iImUo0F4DvxxCo4X5v3hwbcvw== From: Paul Louvel Date: Thu, 07 May 2026 16:41:49 +0200 Subject: [PATCH v3 03/11] crypto: talitos - move dma unmapping code in flush_channel() into a standalone dma_unmap_request() function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-3-c98d7589b942@bootlin.com> References: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> In-Reply-To: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> To: Herbert Xu , "David S. Miller" , Paolo Abeni , David Howells , Kim Phillips , Christophe Leroy Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Herve Codina , Paul Louvel , stable@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164923; l=2463; i=paul.louvel@bootlin.com; s=20260313; h=from:subject:message-id; bh=EUCn4yRIq2JhyN/rWupn3xcECvK8Wf/hUel5shyMxtU=; b=B70G+R7oWuIVMY8Ei3jKA9qBOWFagWwlxCkeOEAqbcb+Jg3Z0wKnv2rL5+iUya+nvbAf7bpxx lIzrPKuorouCC6FCFHb/Ek72dm+5ajwAc4cN8AmRZ5Gdjh6NhPrlWlA X-Developer-Key: i=paul.louvel@bootlin.com; a=ed25519; pk=eLW50NT18UAvUT5cAcYf88zNbBCZDLFXuptpyLVhVIU= X-Last-TLS-Session-Version: TLSv1.3 Previously added code to flush_channel() in order to unmap an entire descriptor. Move that code into a standalone function to improve readability. Cc: stable@vger.kernel.org Signed-off-by: Paul Louvel --- drivers/crypto/talitos.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index b0ebf99b94f5..a98b40f566dd 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -372,6 +372,27 @@ static __be32 get_request_hdr(struct device *dev, return edesc->desc.hdr1; } =20 +static void dma_unmap_request(struct device *dev, + struct talitos_request *request, bool is_sec1) +{ + struct talitos_edesc *edesc; + + if (is_sec1) { + dma_unmap_single(dev, request->dma_desc, TALITOS_DESC_SIZE, + DMA_BIDIRECTIONAL); + edesc =3D container_of(request->desc, struct talitos_edesc, desc); + while (edesc->next_desc) { + dma_unmap_single(dev, + be32_to_cpu(edesc->desc.next_desc), + TALITOS_DESC_SIZE, DMA_BIDIRECTIONAL); + edesc =3D edesc->next_desc; + } + } else { + dma_unmap_single(dev, request->dma_desc, TALITOS_DESC_SIZE, + DMA_BIDIRECTIONAL); + } +} + /* * process what was done, notify callback of error if not */ @@ -379,7 +400,6 @@ static void flush_channel(struct device *dev, int ch, i= nt error, int reset_ch) { struct talitos_private *priv =3D dev_get_drvdata(dev); struct talitos_request *request, saved_req; - struct talitos_edesc *edesc; unsigned long flags; int tail, status; bool is_sec1 =3D has_ftr_sec1(priv); @@ -404,22 +424,7 @@ static void flush_channel(struct device *dev, int ch, = int error, int reset_ch) else status =3D error; =20 - if (is_sec1) { - dma_unmap_single(dev, request->dma_desc, - TALITOS_DESC_SIZE, DMA_BIDIRECTIONAL); - edesc =3D container_of(request->desc, - struct talitos_edesc, desc); - while (edesc->next_desc) { - dma_unmap_single( - dev, be32_to_cpu(edesc->desc.next_desc), - TALITOS_DESC_SIZE, DMA_BIDIRECTIONAL); - edesc =3D edesc->next_desc; - } - } else { - dma_unmap_single(dev, request->dma_desc, - TALITOS_DESC_SIZE, - DMA_BIDIRECTIONAL); - } + dma_unmap_request(dev, request, is_sec1); =20 /* copy entries so we can call callback outside lock */ saved_req.desc =3D request->desc; --=20 2.54.0 From nobody Sat Jun 13 12:37:23 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 8804841C2E0; Thu, 7 May 2026 14:42:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164937; cv=none; b=JMsUWtPYZuiUmd494MJjcymuqBWSDjrOTILQdHACGWOcWIWiTN1fqQRuBDvBgESgcfTwUP9v5WOdt3aih6yQRqgan6F8F1kL7za8g32SToEjvs8XaAwAj8F3PQGfvF13tf1dx+i6P4CEmBOW0jqopMHFcNi/4Ry85fKk3NsJS4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164937; c=relaxed/simple; bh=4inkjgK57GRCXPdo6HgDUyXjwG29KDKGiIYu2SvycOo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ijtNKNeZq4yPFrbhrv4wkuZbbcKPB20OIZ70RSxYD9WrW9lirt2gJuznOfpN0eisuWeENz0eBdVVR6nzdnSNqUFIv4VlQ7YvbXkfh51poi8A8sLiFb+OLw0jBg5W+cxR13PbxnXDlrR1dxz90P4kiEOKvk0u/wDHFo5vUhq0WkY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=orF+Gwk7; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="orF+Gwk7" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id BBE35C5DC60; Thu, 7 May 2026 14:43:01 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 07FF360495; Thu, 7 May 2026 14:42:14 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 58C81108194E9; Thu, 7 May 2026 16:42:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778164932; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=X/CWkPVSOvCEZvE/cf6kjT7+8Jx1BQbx/MToQJY3NP0=; b=orF+Gwk7e4Sl5kyfRnp7g+hv2214eeNJxbgg0ZPNwtVfy8seOzcFyqQxEytLYlfpCTl+NM 8ic//DiDG5OI89QV2v2hLw7RzOmiY62t/RZgWLsBFfSN77F9WQvPahwk2Sa/9q2CpcUrcT ivWYGEgitEqlR2VUs4qB4ZWRhveilkvB563umjML9x1niN8vKJ8M75/VhehEEGj53uFsWd JAv7YNNS24eket+yZPsUdWXGR5WGpLHvmQiM+EqC+8QGXqSc0GUW3rG9ZXZvjhY1O5CJ7p OkOYimvupWLS20mCcp5HdbSv8Ms6xxXB2Muj8+cBMEe5AC/mZadx/yiEy1P2Kg== From: Paul Louvel Date: Thu, 07 May 2026 16:41:50 +0200 Subject: [PATCH v3 04/11] crypto: talitos - move dma mapping code in talitos_submit() into a standalone dma_map_request() function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-4-c98d7589b942@bootlin.com> References: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> In-Reply-To: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> To: Herbert Xu , "David S. Miller" , Paolo Abeni , David Howells , Kim Phillips , Christophe Leroy Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Herve Codina , Paul Louvel , stable@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164923; l=3310; i=paul.louvel@bootlin.com; s=20260313; h=from:subject:message-id; bh=4inkjgK57GRCXPdo6HgDUyXjwG29KDKGiIYu2SvycOo=; b=AZgruyy06M/fEoj/rmn1fE5AXdrHbfYol+hcbfg8z6w+kd1I0TfDoi4JyT1tWR4/IuMOfFqRI VIR0Ec/JlMeAP+6KcOX5VrvIPPDHw+/ReK6KhI6uru7Zz/Vc3IzuakS X-Developer-Key: i=paul.louvel@bootlin.com; a=ed25519; pk=eLW50NT18UAvUT5cAcYf88zNbBCZDLFXuptpyLVhVIU= X-Last-TLS-Session-Version: TLSv1.3 Previously added code to talitos_submit() in order to map an entire descriptor chain. Move that code into a standalone function to improve readability. Cc: stable@vger.kernel.org Signed-off-by: Paul Louvel --- drivers/crypto/talitos.c | 75 ++++++++++++++++++++++++++------------------= ---- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index a98b40f566dd..183d51fa9a4a 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -255,6 +255,46 @@ static int init_device(struct device *dev) return 0; } =20 +static void dma_map_request(struct device *dev, struct talitos_request *re= quest, + struct talitos_desc *desc, bool is_sec1) +{ + struct talitos_edesc *edesc =3D + container_of(desc, struct talitos_edesc, desc); + dma_addr_t dma_desc, prev_dma_desc; + struct talitos_edesc *prev_edesc =3D NULL; + + if (is_sec1) { + while (edesc) { + edesc->desc.hdr1 =3D edesc->desc.hdr; + + dma_desc =3D dma_map_single(dev, &edesc->desc.hdr1, + TALITOS_DESC_SIZE, + DMA_BIDIRECTIONAL); + + if (!prev_edesc) { + request->dma_desc =3D dma_desc; + goto next; + } + + /* Chain in any previous descriptors. */ + + prev_edesc->desc.next_desc =3D cpu_to_be32(dma_desc); + + dma_sync_single_for_device(dev, prev_dma_desc, + TALITOS_DESC_SIZE, + DMA_TO_DEVICE); + +next: + prev_edesc =3D edesc; + prev_dma_desc =3D dma_desc; + edesc =3D edesc->next_desc; + } + } else { + request->dma_desc =3D dma_map_single(dev, desc, TALITOS_DESC_SIZE, + DMA_BIDIRECTIONAL); + } +} + /** * talitos_submit - submits a descriptor to the device for processing * @dev: the SEC device to be used @@ -273,10 +313,7 @@ static int talitos_submit(struct device *dev, int ch, = struct talitos_desc *desc, void *context, int error), void *context) { - struct talitos_edesc *edesc =3D container_of(desc, struct talitos_edesc, = desc); struct talitos_private *priv =3D dev_get_drvdata(dev); - dma_addr_t dma_desc, prev_dma_desc; - struct talitos_edesc *prev_edesc =3D NULL; struct talitos_request *request; unsigned long flags; int head; @@ -294,37 +331,7 @@ static int talitos_submit(struct device *dev, int ch, = struct talitos_desc *desc, request =3D &priv->chan[ch].fifo[head]; =20 /* map descriptor and save caller data */ - if (is_sec1) { - while (edesc) { - edesc->desc.hdr1 =3D edesc->desc.hdr; - - dma_desc =3D dma_map_single(dev, &edesc->desc.hdr1, - TALITOS_DESC_SIZE, - DMA_BIDIRECTIONAL); - - if (!prev_edesc) { - request->dma_desc =3D dma_desc; - goto next; - } - - /* Chain in any previous descriptors. */ - - prev_edesc->desc.next_desc =3D cpu_to_be32(dma_desc); - - dma_sync_single_for_device(dev, prev_dma_desc, - TALITOS_DESC_SIZE, - DMA_TO_DEVICE); - -next: - prev_edesc =3D edesc; - prev_dma_desc =3D dma_desc; - edesc =3D edesc->next_desc; - } - } else { - request->dma_desc =3D dma_map_single(dev, desc, - TALITOS_DESC_SIZE, - DMA_BIDIRECTIONAL); - } + dma_map_request(dev, request, desc, is_sec1); request->callback =3D callback; request->context =3D context; =20 --=20 2.54.0 From nobody Sat Jun 13 12:37:23 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 88E9D41B362; Thu, 7 May 2026 14:42:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164939; cv=none; b=EjPcYhM+mIxLkl1RkFjSzvNJLKC10Ope3X9IN9LxGZxtPNgbgM+/bNBh2bipm8CCa0LT8vghuQiFepnPvRgiYh+Cga2H2on2uFia1H1sCWSkxFizoRqE3iaWFrRKLQ7sKlNOr0nRKUmWZ0LbaEQ/pZxRfPN0s7r5Fy3YDi5+HJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164939; c=relaxed/simple; bh=qO0tsxQ0b6EGI/EGaaoUlVQrUdwdEVZt2kdJRh6FnNk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZaFauxInzXk+wceEKADgOzYKA9h7H2U7AHdp77LW2uzcKpwAwa2zXoqG9mOe02a01I8T+TSFIIplUl8cxoG3qkOR2f5Gr1Q5DHory6E7OXNZJw72VmRsjch/X4zr6fINsY27NBLM0V/N1aqMZD7kpYDKa7DTblXnipvkNUJqhKU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=nJvlDnE2; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="nJvlDnE2" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 8F5131A3562; Thu, 7 May 2026 14:42:15 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 64B4860495; Thu, 7 May 2026 14:42:15 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 4D011108194E5; Thu, 7 May 2026 16:42:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778164934; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=Kit7VWOE4/kosaJUfI5BQRbHDaPqPffXvb+g/mMS7XI=; b=nJvlDnE2AcW7HOqmFZhvoDHJh4RjDXgD4kKLxRV/fRzfEkQjyZliJQD7vi5pKQVDBe5XgF Hs9PdB+RQkA2LvSTHGpOkgJn0uQOR13rgFvvC1oDfo1DiGOl4gvji9gNRxGq6fi/gxl4LZ VmrcUCNDnFn6Pcds6RPk3RWNoJ9GzucRt2PIeDiibDphY9cW+rIdNGZQBxcZUcRMtMJfBe NWflFYKu3ICgyMGqKo8T8yt6qYy0sG44sWEEE1Kgd8kiA7TYCzeIm1PSXlPZLw0z7nVL2i I99AsyGq5LyTa0YVAyhWmnCtiUY2nXgWiJxQ62KrGbcDFFxbO3cC3P5CD4gknA== From: Paul Louvel Date: Thu, 07 May 2026 16:41:51 +0200 Subject: [PATCH v3 05/11] crypto: talitos - move code in current_desc_hdr() into a standalone function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-5-c98d7589b942@bootlin.com> References: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> In-Reply-To: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> To: Herbert Xu , "David S. Miller" , Paolo Abeni , David Howells , Kim Phillips , Christophe Leroy Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Herve Codina , Paul Louvel , stable@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164923; l=2274; i=paul.louvel@bootlin.com; s=20260313; h=from:subject:message-id; bh=qO0tsxQ0b6EGI/EGaaoUlVQrUdwdEVZt2kdJRh6FnNk=; b=1Uq1OVb55Es/GZfCmuxeSe1FDKSQEEGybif04lCAI80QN7rLIoqEQ2mVGWwHRVJUK4Gw/K5SJ l6T788GMfrABn0GjAoqk9hNXf3tNBY5unjKAcQTWLPCapx4gCI5/QkP X-Developer-Key: i=paul.louvel@bootlin.com; a=ed25519; pk=eLW50NT18UAvUT5cAcYf88zNbBCZDLFXuptpyLVhVIU= X-Last-TLS-Session-Version: TLSv1.3 Previously added code in current_desc_hdr() in order to add support for searching an offending descriptor inside a descriptor chain. Move that code into a standalone function to improve readability. Cc: stable@vger.kernel.org Signed-off-by: Paul Louvel --- drivers/crypto/talitos.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 183d51fa9a4a..b808833d18ef 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -520,6 +520,24 @@ DEF_TALITOS2_DONE(ch0, TALITOS2_ISR_CH_0_DONE) DEF_TALITOS2_DONE(ch0_2, TALITOS2_ISR_CH_0_2_DONE) DEF_TALITOS2_DONE(ch1_3, TALITOS2_ISR_CH_1_3_DONE) =20 +static __be32 search_desc_hdr_in_request(struct talitos_request *request, + dma_addr_t cur_desc, bool is_sec1) +{ + struct talitos_edesc *edesc; + + if (request->dma_desc =3D=3D cur_desc) { + return request->desc->hdr; + } else if (is_sec1) { + edesc =3D container_of(request->desc, struct talitos_edesc, desc); + while (edesc->next_desc) { + if (edesc->desc.next_desc =3D=3D cpu_to_be32(cur_desc)) + return edesc->next_desc->desc.hdr1; + edesc =3D edesc->next_desc; + } + } + return 0; +} + /* * locate current (offending) descriptor */ @@ -528,7 +546,6 @@ static __be32 current_desc_hdr(struct device *dev, int = ch) struct talitos_private *priv =3D dev_get_drvdata(dev); bool is_sec1 =3D has_ftr_sec1(priv); struct talitos_request *request; - struct talitos_edesc *edesc; int tail, iter; dma_addr_t cur_desc; __be32 hdr =3D 0; @@ -546,21 +563,7 @@ static __be32 current_desc_hdr(struct device *dev, int= ch) do { request =3D &priv->chan[ch].fifo[iter]; =20 - if (request->dma_desc =3D=3D cur_desc) { - hdr =3D request->desc->hdr; - } else if (is_sec1) { - edesc =3D container_of(request->desc, - struct talitos_edesc, desc); - while (edesc->next_desc) { - if (edesc->desc.next_desc =3D=3D - cpu_to_be32(cur_desc)) { - hdr =3D edesc->next_desc->desc.hdr1; - break; - } - edesc =3D edesc->next_desc; - } - } - + hdr =3D search_desc_hdr_in_request(request, cur_desc, is_sec1); if (hdr) break; =20 --=20 2.54.0 From nobody Sat Jun 13 12:37:23 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 7973A4218AD; Thu, 7 May 2026 14:42:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164940; cv=none; b=WMu4hKIjYSO0K7QEoAhA+6RfLI+e6rRWBs2ue5Bloo23C8TsWxCWPK9mHoaUxJsLm3iabIkTIO+cBaqFHUnKDrOcj38Ma4FpwQzFxLTC9FuVkhdCBAOuy9cF+vFrd/PypXNYmfWoacjZgKAQ3X8ue14F5pNT+Kv1N7ZbOkXoNgQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164940; c=relaxed/simple; bh=Pj/omQS8/bnTGU/YHn5DhQ94ALBQvuhcRU0l5aTvIWk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PvtliGxyoTOFonn1mGqPIGgu+9QZhPs681H0g52EzUhBcshqfJqcW3oke+0nyoyP2Ira+2JuiNGaBS/ZL2BqupLQOE9wHb+0THIWI2IkzXClCLGeUC1QNqzb/kDb8n59cnUXu+NIV5d5BO1u9DSyqMc5stMeFIDB+c783QA3K0I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=USM5dhI4; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="USM5dhI4" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 33C214E42C2D; Thu, 7 May 2026 14:42:17 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 014FF60495; Thu, 7 May 2026 14:42:17 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id D7B83108194E7; Thu, 7 May 2026 16:42:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778164936; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=SUFudVvJ9y35/3htDCJOCx8HpvSqlyO19b81VfH+tro=; b=USM5dhI4B5VL2AwCb2vDkRAchNWRO0BSbpqxN0jz0tqD/vgtnuUMS6FTqsc1M3hh1pmEbZ +dQdYH6UDfEigm0K5+DyBEVlDrNB8yTTpG/SVikYcNghXOlRFB8eC7rgypGfbUObiAm/2x pSn/gwnCMwq1yGTppwLjn7jbZULuh2iw1rZwJPNTUSD9IeJrqTRl3zNZzRVFPDOs2AVDCg aPvrjhcckzBKRn890XfMauAmiZxHZ9YB07H77b/+htR6HOULZEc35VqHvJwdNUSeI/V+ms SOEVMkqTH+a1gyy9WWJTz8dyaOjE4OydLSn5iP0EUCHMrTD4zEUdb3JQPxJKjw== From: Paul Louvel Date: Thu, 07 May 2026 16:41:52 +0200 Subject: [PATCH v3 06/11] crypto: talitos/hash - prepare SEC1 descriptor chaining, remove additional descriptor Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-6-c98d7589b942@bootlin.com> References: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> In-Reply-To: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> To: Herbert Xu , "David S. Miller" , Paolo Abeni , David Howells , Kim Phillips , Christophe Leroy Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Herve Codina , Paul Louvel , stable@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164923; l=6752; i=paul.louvel@bootlin.com; s=20260313; h=from:subject:message-id; bh=Pj/omQS8/bnTGU/YHn5DhQ94ALBQvuhcRU0l5aTvIWk=; b=TZ1UadA+3UJb9EiayuVvPQqP0NnSvjT8hU1y9cQeOx14DrzbZtDYl/RrSoL7uTw8pZIRZcOP2 Tue1TZDzH6hAhPuoTsGQjYBoA/HS+ieLERbixmU84RvToP6wnbZ+yNQ X-Developer-Key: i=paul.louvel@bootlin.com; a=ed25519; pk=eLW50NT18UAvUT5cAcYf88zNbBCZDLFXuptpyLVhVIU= X-Last-TLS-Session-Version: TLSv1.3 Currently, when SEC1 has buffered data (nbuf !=3D 0), the ahash code creates an additional descriptor on the fly inside common_nonsnoop_hash() to handle the remainder of the data. This approach is incompatible with the arbitrary-length descriptor chaining that follows. Remove the "additional descriptor" logic from common_nonsnoop_hash() and common_nonsnoop_hash_unmap(). Also remove the nbytes adjustment for SEC1 in ahash_edesc_alloc() that subtracted nbuf. Cc: stable@vger.kernel.org Signed-off-by: Paul Louvel --- drivers/crypto/talitos.c | 101 +++----------------------------------------= ---- 1 file changed, 6 insertions(+), 95 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index b808833d18ef..0184982cb39b 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -1788,15 +1788,9 @@ static void common_nonsnoop_hash_unmap(struct device= *dev, struct talitos_private *priv =3D dev_get_drvdata(dev); bool is_sec1 =3D has_ftr_sec1(priv); struct talitos_desc *desc =3D &edesc->desc; - struct talitos_desc *desc2; - - if (desc->next_desc) - desc2 =3D &edesc->next_desc->desc; =20 unmap_single_talitos_ptr(dev, &desc->ptr[5], DMA_FROM_DEVICE); - if (desc->next_desc && - desc->ptr[5].ptr !=3D desc2->ptr[5].ptr) - unmap_single_talitos_ptr(dev, &desc2->ptr[5], DMA_FROM_DEVICE); + if (req_ctx->last_desc) memcpy(areq->result, req_ctx->hw_context, crypto_ahash_digestsize(tfm)); @@ -1808,13 +1802,6 @@ static void common_nonsnoop_hash_unmap(struct device= *dev, if (from_talitos_ptr_len(&desc->ptr[1], is_sec1)) unmap_single_talitos_ptr(dev, &desc->ptr[1], DMA_TO_DEVICE); - else if (desc->next_desc) - unmap_single_talitos_ptr(dev, &desc2->ptr[1], - DMA_TO_DEVICE); - - if (is_sec1 && req_ctx->nbuf) - unmap_single_talitos_ptr(dev, &desc->ptr[3], - DMA_TO_DEVICE); =20 if (edesc->dma_len) dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len, @@ -1922,9 +1909,6 @@ static int common_nonsnoop_hash(struct talitos_edesc = *edesc, to_talitos_ptr(&desc->ptr[2], ctx->dma_key, ctx->keylen, is_sec1); =20 - if (is_sec1 && req_ctx->nbuf) - length -=3D req_ctx->nbuf; - sg_count =3D edesc->src_nents ?: 1; if (is_sec1 && sg_count > 1) sg_copy_to_buffer(req_ctx->psrc, sg_count, edesc->buf, length); @@ -1934,16 +1918,10 @@ static int common_nonsnoop_hash(struct talitos_edes= c *edesc, /* * data in */ - if (is_sec1 && req_ctx->nbuf) { - map_single_talitos_ptr(dev, &desc->ptr[3], req_ctx->nbuf, - req_ctx->buf[req_ctx->buf_idx], - DMA_TO_DEVICE); - } else { - sg_count =3D talitos_sg_map(dev, req_ctx->psrc, length, edesc, - &desc->ptr[3], sg_count, 0, 0); - if (sg_count > 1) - sync_needed =3D true; - } + sg_count =3D talitos_sg_map(dev, req_ctx->psrc, length, edesc, + &desc->ptr[3], sg_count, 0, 0); + if (sg_count > 1) + sync_needed =3D true; =20 /* fifth DWORD empty */ =20 @@ -1963,49 +1941,6 @@ static int common_nonsnoop_hash(struct talitos_edesc= *edesc, if (is_sec1 && from_talitos_ptr_len(&desc->ptr[3], true) =3D=3D 0) talitos_handle_buggy_hash(ctx, edesc, &desc->ptr[3]); =20 - if (is_sec1 && req_ctx->nbuf && length) { - struct talitos_edesc *edesc2; - struct talitos_desc *desc2; - - edesc2 =3D kzalloc(sizeof(*edesc2), - areq->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ? - GFP_KERNEL : - GFP_ATOMIC); - if (!edesc2) { - ret =3D -ENOMEM; - goto err; - } - edesc->next_desc =3D edesc2; - - desc2 =3D &edesc2->desc; - - desc2->hdr =3D desc->hdr; - desc2->hdr &=3D ~DESC_HDR_MODE0_MDEU_INIT; - desc->hdr &=3D ~DESC_HDR_MODE0_MDEU_PAD; - desc->hdr |=3D DESC_HDR_MODE0_MDEU_CONT; - desc->hdr &=3D ~DESC_HDR_DONE_NOTIFY; - - if (desc->ptr[1].ptr) - copy_talitos_ptr(&desc2->ptr[1], &desc->ptr[1], - is_sec1); - else - map_single_talitos_ptr_nosync(dev, &desc2->ptr[1], - req_ctx->hw_context_size, - req_ctx->hw_context, - DMA_TO_DEVICE); - copy_talitos_ptr(&desc2->ptr[2], &desc->ptr[2], is_sec1); - sg_count =3D talitos_sg_map(dev, req_ctx->psrc, length, edesc, - &desc2->ptr[3], sg_count, 0, 0); - if (sg_count > 1) - sync_needed =3D true; - copy_talitos_ptr(&desc2->ptr[5], &desc->ptr[5], is_sec1); - if (req_ctx->last_desc) - map_single_talitos_ptr_nosync(dev, &desc->ptr[5], - req_ctx->hw_context_size, - req_ctx->hw_context, - DMA_FROM_DEVICE); - } - if (sync_needed) dma_sync_single_for_device(dev, edesc->dma_link_tbl, edesc->dma_len, DMA_BIDIRECTIONAL); @@ -2028,11 +1963,6 @@ static struct talitos_edesc *ahash_edesc_alloc(struc= t ahash_request *areq, struct crypto_ahash *tfm =3D crypto_ahash_reqtfm(areq); struct talitos_ctx *ctx =3D crypto_ahash_ctx(tfm); struct talitos_ahash_req_ctx *req_ctx =3D ahash_request_ctx(areq); - struct talitos_private *priv =3D dev_get_drvdata(ctx->dev); - bool is_sec1 =3D has_ftr_sec1(priv); - - if (is_sec1) - nbytes -=3D req_ctx->nbuf; =20 return talitos_edesc_alloc(ctx->dev, req_ctx->psrc, NULL, NULL, 0, nbytes, 0, 0, 0, areq->base.flags, false); @@ -2051,8 +1981,6 @@ static int ahash_process_req_one(struct ahash_request= *areq, unsigned int nbytes unsigned int nsg; int nents; struct device *dev =3D ctx->dev; - struct talitos_private *priv =3D dev_get_drvdata(dev); - bool is_sec1 =3D has_ftr_sec1(priv); u8 *ctx_buf =3D req_ctx->buf[req_ctx->buf_idx]; =20 if (!req_ctx->last_desc && (nbytes + req_ctx->nbuf <=3D blocksize)) { @@ -2084,30 +2012,13 @@ static int ahash_process_req_one(struct ahash_reque= st *areq, unsigned int nbytes } =20 /* Chain in any previously buffered data */ - if (!is_sec1 && req_ctx->nbuf) { + if (req_ctx->nbuf) { nsg =3D (req_ctx->nbuf < nbytes_to_hash) ? 2 : 1; sg_init_table(req_ctx->bufsl, nsg); sg_set_buf(req_ctx->bufsl, ctx_buf, req_ctx->nbuf); if (nsg > 1) sg_chain(req_ctx->bufsl, 2, req_ctx->request_sl); req_ctx->psrc =3D req_ctx->bufsl; - } else if (is_sec1 && req_ctx->nbuf && req_ctx->nbuf < blocksize) { - int offset; - - if (nbytes_to_hash > blocksize) - offset =3D blocksize - req_ctx->nbuf; - else - offset =3D nbytes_to_hash - req_ctx->nbuf; - nents =3D sg_nents_for_len(req_ctx->request_sl, offset); - if (nents < 0) { - dev_err(dev, "Invalid number of src SG.\n"); - return nents; - } - sg_copy_to_buffer(req_ctx->request_sl, nents, - ctx_buf + req_ctx->nbuf, offset); - req_ctx->nbuf +=3D offset; - req_ctx->psrc =3D scatterwalk_ffwd(req_ctx->bufsl, req_ctx->request_sl, - offset); } else req_ctx->psrc =3D req_ctx->request_sl; =20 --=20 2.54.0 From nobody Sat Jun 13 12:37:23 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 42FDF401A11; Thu, 7 May 2026 14:42:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164942; cv=none; b=prLrrkwGkWIcKKltAjWHoxvxQHZM0NLV3ibSb8iECvy52IRDZC25jVCw8eN79eVeZV0wcicMLYJIGtlggaHNMjJBp4YSriN0ueSs9EaZDl1G1lCg/i8aupLWSrZdZbQmawErCUiOTY1jdSHuDSOb7hdeExRoFo25SsL9MQkkVN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164942; c=relaxed/simple; bh=r4oWaVJibYZrPknMo62+zsusCSWvuFjUGR1UmIBGJb4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Pd54zvoyeklruhWmTFeFKWxbG+9v5HyBmKZlQXQfYyyerpA3RBGhbHX4VjVmHlUhzDFm/87clbfq8j9E6RVQnY1ZSZY7Mzbrz/A/QI+0BX29NYFJusk0Y3ocqHO19AYcwXQ8hT43bacf8t6Z1LzkTbwf2Po82pbVoE22sLWulGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=TnV8DNLY; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="TnV8DNLY" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id BFE361A3565; Thu, 7 May 2026 14:42:18 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 8EBBE605D0; Thu, 7 May 2026 14:42:18 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 8028C108194EA; Thu, 7 May 2026 16:42:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778164937; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=20gk6DUhYfnL8EJ806yf8Wc4c5MD9o0qn/el8R1v5T4=; b=TnV8DNLYl5DUbYZEnUhEkvEgnX94W/chP7INkIjeazhNNHIqLYDOKOTkY+B/wTh6jQmnAu gVxK2Tpr5OhsWCIcCKGzim+gHs4sASpB9C5+PlcIrk0ig5HjvzP23y6E09nCFq2dj4hLkT 5aIjVKwyPtV4xlixNnDLvkNxidkkl8kbmvKZbaRgtpTXz0W2Lo9+DLe2zQQjDy1DHu5/qP Y/DJmYvQa83B4nU7bIlDKjCQ8TsyCuDk6tQCBXTbF4lqxF2K3WPD0Rat34ocpuWo3c8pVa a/AJDBIwOX0FV2diLIO7g+PeALM7EExlW5BNYRcNP+KhW+qzds60lWsZThRYbA== From: Paul Louvel Date: Thu, 07 May 2026 16:41:53 +0200 Subject: [PATCH v3 07/11] crypto: talitos/hash - use descriptor chaining for SEC1 instead of workqueue Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-7-c98d7589b942@bootlin.com> References: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> In-Reply-To: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> To: Herbert Xu , "David S. Miller" , Paolo Abeni , David Howells , Kim Phillips , Christophe Leroy Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Herve Codina , Paul Louvel , stable@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164923; l=13442; i=paul.louvel@bootlin.com; s=20260313; h=from:subject:message-id; bh=r4oWaVJibYZrPknMo62+zsusCSWvuFjUGR1UmIBGJb4=; b=HceUKOWD8aoSV/WnnHsJKC6PMN8vwre98552kr9MQ7pqHHJMUAoZQT3bPzsOT4UE9GFXAk25Z 2K9/9LdscgLB+68orzxIKYr+oL1dGpVLKVff0fyEGAvhQByYYNDfo5l X-Developer-Key: i=paul.louvel@bootlin.com; a=ed25519; pk=eLW50NT18UAvUT5cAcYf88zNbBCZDLFXuptpyLVhVIU= X-Last-TLS-Session-Version: TLSv1.3 Rework the SEC1 ahash implementation to build a chain of hardware descriptors, replacing the previous approach of submitting one descriptor at a time via a workqueue, introduced by commit 655ef638a2bc ("crypto: talitos - fix SEC1 32k ahash request limitation"). Introduce ahash_process_req_prepare() which iterates over the request data, allocating enough descriptors to cover the entire ahash request. The new fields (bufsl, src, first, last) are added to talitos_edesc for this purpose. common_nonsnoop_hash() no longer calls talitos_submit(); it only maps and sets up the descriptor. Submission is now done by the caller after the chain is built. ahash_free_desc_list_from() takes over calling common_nonsnoop_hash_unmap() for each descriptor during cleanup. Compared to the workqueue based solution, request are slightly faster since there is no more scheduling latency induced by the workqueue, and only one interrupt is generated by the device at the end of a chain. Commit 655ef638a2bc ("crypto: talitos - fix SEC1 32k ahash request limitation") : $ /usr/libexec/libkcapi/sha256sum ./test_5M.bin 013c5609d63c... ./test_5M.bin real 0m 0.41s user 0m 0.01s sys 0m 0.07s Now : $ /usr/libexec/libkcapi/sha256sum ./test_5M.bin 013c5609d63c... ./test_5M.bin real 0m 0.33s user 0m 0.01s sys 0m 0.20s Tested on a system with an MPC885 SoC featuring the SEC1 Lite. The increase in sys time is due to the fact that commit 37b5e8897eb5 ("crypto: talitos - chain in buffered data for ahash on SEC1") can no longer be applied. Cc: stable@vger.kernel.org Signed-off-by: Paul Louvel --- drivers/crypto/talitos.c | 168 +++++++++++++++++++++++++++++--------------= ---- drivers/crypto/talitos.h | 10 +++ 2 files changed, 115 insertions(+), 63 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 0184982cb39b..883115d66fc4 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -1791,12 +1791,12 @@ static void common_nonsnoop_hash_unmap(struct devic= e *dev, =20 unmap_single_talitos_ptr(dev, &desc->ptr[5], DMA_FROM_DEVICE); =20 - if (req_ctx->last_desc) + if (edesc->last && req_ctx->last_request) memcpy(areq->result, req_ctx->hw_context, crypto_ahash_digestsize(tfm)); =20 - if (req_ctx->psrc) - talitos_sg_unmap(dev, edesc, req_ctx->psrc, NULL, 0, 0); + if (edesc->src) + talitos_sg_unmap(dev, edesc, edesc->src, NULL, 0, 0); =20 /* When using hashctx-in, must unmap it. */ if (from_talitos_ptr_len(&desc->ptr[1], is_sec1)) @@ -1808,12 +1808,14 @@ static void common_nonsnoop_hash_unmap(struct devic= e *dev, DMA_BIDIRECTIONAL); } =20 -static void free_edesc_list_from(struct talitos_edesc *edesc) +static void free_edesc_list_from(struct ahash_request *areq, struct talito= s_edesc *edesc) { + struct talitos_ctx *ctx =3D crypto_ahash_ctx(crypto_ahash_reqtfm(areq)); struct talitos_edesc *next; =20 while (edesc) { next =3D edesc->next_desc; + common_nonsnoop_hash_unmap(ctx->dev, edesc, areq); kfree(edesc); edesc =3D next; } @@ -1828,19 +1830,18 @@ static void ahash_done(struct device *dev, container_of(desc, struct talitos_edesc, desc); struct talitos_ahash_req_ctx *req_ctx =3D ahash_request_ctx(areq); =20 + if (!req_ctx->last_desc && req_ctx->to_hash_later) { /* Position any partial block for next update/final/finup */ req_ctx->buf_idx =3D (req_ctx->buf_idx + 1) & 1; req_ctx->nbuf =3D req_ctx->to_hash_later; } - common_nonsnoop_hash_unmap(dev, edesc, areq); =20 - free_edesc_list_from(edesc); + free_edesc_list_from(areq, edesc); =20 - if (err) { - ahash_request_complete(areq, err); - return; - } + ahash_request_complete(areq, err); + + return; =20 req_ctx->remaining_ahash_request_bytes -=3D req_ctx->current_ahash_request_bytes; @@ -1874,18 +1875,15 @@ static void talitos_handle_buggy_hash(struct talito= s_ctx *ctx, (char *)padded_hash, DMA_TO_DEVICE); } =20 -static int common_nonsnoop_hash(struct talitos_edesc *edesc, - struct ahash_request *areq, unsigned int length, - void (*callback) (struct device *dev, - struct talitos_desc *desc, - void *context, int error)) +static void common_nonsnoop_hash(struct talitos_edesc *edesc, + struct ahash_request *areq, + unsigned int length) { struct crypto_ahash *tfm =3D crypto_ahash_reqtfm(areq); struct talitos_ctx *ctx =3D crypto_ahash_ctx(tfm); struct talitos_ahash_req_ctx *req_ctx =3D ahash_request_ctx(areq); struct device *dev =3D ctx->dev; struct talitos_desc *desc =3D &edesc->desc; - int ret; bool sync_needed =3D false; struct talitos_private *priv =3D dev_get_drvdata(dev); bool is_sec1 =3D has_ftr_sec1(priv); @@ -1894,7 +1892,7 @@ static int common_nonsnoop_hash(struct talitos_edesc = *edesc, /* first DWORD empty */ =20 /* hash context in */ - if (!req_ctx->first_desc || req_ctx->swinit) { + if (!edesc->first || !req_ctx->first_desc || req_ctx->swinit) { map_single_talitos_ptr_nosync(dev, &desc->ptr[1], req_ctx->hw_context_size, req_ctx->hw_context, @@ -1911,22 +1909,22 @@ static int common_nonsnoop_hash(struct talitos_edes= c *edesc, =20 sg_count =3D edesc->src_nents ?: 1; if (is_sec1 && sg_count > 1) - sg_copy_to_buffer(req_ctx->psrc, sg_count, edesc->buf, length); + sg_copy_to_buffer(edesc->src, sg_count, edesc->buf, length); else if (length) - sg_count =3D dma_map_sg(dev, req_ctx->psrc, sg_count, - DMA_TO_DEVICE); + sg_count =3D dma_map_sg(dev, edesc->src, sg_count, DMA_TO_DEVICE); + /* * data in */ - sg_count =3D talitos_sg_map(dev, req_ctx->psrc, length, edesc, - &desc->ptr[3], sg_count, 0, 0); + sg_count =3D talitos_sg_map(dev, edesc->src, length, edesc, &desc->ptr[3], + sg_count, 0, 0); if (sg_count > 1) sync_needed =3D true; =20 /* fifth DWORD empty */ =20 /* hash/HMAC out -or- hash context out */ - if (req_ctx->last_desc) + if (edesc->last && req_ctx->last_request) map_single_talitos_ptr(dev, &desc->ptr[5], crypto_ahash_digestsize(tfm), req_ctx->hw_context, DMA_FROM_DEVICE); @@ -1944,30 +1942,89 @@ static int common_nonsnoop_hash(struct talitos_edes= c *edesc, if (sync_needed) dma_sync_single_for_device(dev, edesc->dma_link_tbl, edesc->dma_len, DMA_BIDIRECTIONAL); - - ret =3D talitos_submit(dev, ctx->ch, desc, callback, - areq); - if (ret !=3D -EINPROGRESS) - goto err; - - return -EINPROGRESS; -err: - common_nonsnoop_hash_unmap(dev, edesc, areq); - kfree(edesc); - return ret; } =20 static struct talitos_edesc *ahash_edesc_alloc(struct ahash_request *areq, + struct scatterlist *src, unsigned int nbytes) { struct crypto_ahash *tfm =3D crypto_ahash_reqtfm(areq); struct talitos_ctx *ctx =3D crypto_ahash_ctx(tfm); - struct talitos_ahash_req_ctx *req_ctx =3D ahash_request_ctx(areq); =20 - return talitos_edesc_alloc(ctx->dev, req_ctx->psrc, NULL, NULL, 0, + return talitos_edesc_alloc(ctx->dev, src, NULL, NULL, 0, nbytes, 0, 0, 0, areq->base.flags, false); } =20 +static struct talitos_edesc * +ahash_process_req_prepare(struct ahash_request *areq, unsigned int nbytes, + unsigned int blocksize, bool is_sec1) +{ + struct talitos_ctx *ctx =3D crypto_ahash_ctx(crypto_ahash_reqtfm(areq)); + struct talitos_ahash_req_ctx *req_ctx =3D ahash_request_ctx(areq); + struct talitos_edesc *first =3D NULL, *prev_edesc =3D NULL, *edesc; + size_t desc_max =3D is_sec1 ? TALITOS1_MAX_DATA_LEN : SIZE_MAX; + struct scatterlist tmp[2]; + size_t to_hash_this_desc; + struct scatterlist *src; + size_t offset =3D 0; + + do { + src =3D scatterwalk_ffwd(tmp, req_ctx->psrc, offset); + + to_hash_this_desc =3D + min(nbytes, ALIGN_DOWN(desc_max, blocksize)); + + /* Allocate extended descriptor */ + edesc =3D ahash_edesc_alloc(areq, src, to_hash_this_desc); + if (IS_ERR(edesc)) { + if (first) + free_edesc_list_from(areq, first); + return edesc; + } + + edesc->src =3D + scatterwalk_ffwd(edesc->bufsl, req_ctx->psrc, offset); + edesc->desc.hdr =3D ctx->desc_hdr_template; + edesc->first =3D offset =3D=3D 0; + edesc->last =3D nbytes - to_hash_this_desc =3D=3D 0; + + /* On last one, request SEC to pad; otherwise continue */ + if (req_ctx->last_request && edesc->last) + edesc->desc.hdr |=3D DESC_HDR_MODE0_MDEU_PAD; + else + edesc->desc.hdr |=3D DESC_HDR_MODE0_MDEU_CONT; + + /* request SEC to INIT hash. */ + if (req_ctx->first_desc && edesc->first && !req_ctx->swinit) + edesc->desc.hdr |=3D DESC_HDR_MODE0_MDEU_INIT; + + /* + * When the tfm context has a keylen, it's an HMAC. + * A first or last (ie. not middle) descriptor must request HMAC. + */ + if (ctx->keylen && ((req_ctx->first_desc && edesc->first) || + (req_ctx->last_request && edesc->last))) + edesc->desc.hdr |=3D DESC_HDR_MODE0_MDEU_HMAC; + + /* clear the DN bit */ + if (is_sec1 && !edesc->last) + edesc->desc.hdr &=3D ~DESC_HDR_DONE_NOTIFY; + + common_nonsnoop_hash(edesc, areq, to_hash_this_desc); + + offset +=3D to_hash_this_desc; + nbytes -=3D to_hash_this_desc; + + if (!prev_edesc) + first =3D edesc; + else + prev_edesc->next_desc =3D edesc; + prev_edesc =3D edesc; + } while (nbytes); + + return first; +} + static int ahash_process_req_one(struct ahash_request *areq, unsigned int = nbytes) { struct crypto_ahash *tfm =3D crypto_ahash_reqtfm(areq); @@ -1976,14 +2033,16 @@ static int ahash_process_req_one(struct ahash_reque= st *areq, unsigned int nbytes struct talitos_edesc *edesc; unsigned int blocksize =3D crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm)); + bool is_sec1 =3D has_ftr_sec1(dev_get_drvdata(ctx->dev)); unsigned int nbytes_to_hash; unsigned int to_hash_later; unsigned int nsg; int nents; struct device *dev =3D ctx->dev; u8 *ctx_buf =3D req_ctx->buf[req_ctx->buf_idx]; + int ret; =20 - if (!req_ctx->last_desc && (nbytes + req_ctx->nbuf <=3D blocksize)) { + if (!req_ctx->last_request && (nbytes + req_ctx->nbuf <=3D blocksize)) { /* Buffer up to one whole block */ nents =3D sg_nents_for_len(req_ctx->request_sl, nbytes); if (nents < 0) { @@ -2000,7 +2059,7 @@ static int ahash_process_req_one(struct ahash_request= *areq, unsigned int nbytes nbytes_to_hash =3D nbytes + req_ctx->nbuf; to_hash_later =3D nbytes_to_hash & (blocksize - 1); =20 - if (req_ctx->last_desc) + if (req_ctx->last_request) to_hash_later =3D 0; else if (to_hash_later) /* There is a partial block. Hash the full block(s) now */ @@ -2035,30 +2094,16 @@ static int ahash_process_req_one(struct ahash_reque= st *areq, unsigned int nbytes } req_ctx->to_hash_later =3D to_hash_later; =20 - /* Allocate extended descriptor */ - edesc =3D ahash_edesc_alloc(req_ctx->areq, nbytes_to_hash); + edesc =3D ahash_process_req_prepare(areq, nbytes_to_hash, blocksize, + is_sec1); if (IS_ERR(edesc)) return PTR_ERR(edesc); =20 - edesc->desc.hdr =3D ctx->desc_hdr_template; - - /* On last one, request SEC to pad; otherwise continue */ - if (req_ctx->last_desc) - edesc->desc.hdr |=3D DESC_HDR_MODE0_MDEU_PAD; - else - edesc->desc.hdr |=3D DESC_HDR_MODE0_MDEU_CONT; - - /* request SEC to INIT hash. */ - if (req_ctx->first_desc && !req_ctx->swinit) - edesc->desc.hdr |=3D DESC_HDR_MODE0_MDEU_INIT; - - /* When the tfm context has a keylen, it's an HMAC. - * A first or last (ie. not middle) descriptor must request HMAC. - */ - if (ctx->keylen && (req_ctx->first_desc || req_ctx->last_desc)) - edesc->desc.hdr |=3D DESC_HDR_MODE0_MDEU_HMAC; + ret =3D talitos_submit(dev, ctx->ch, &edesc->desc, ahash_done, areq); + if (ret !=3D -EINPROGRESS) + free_edesc_list_from(areq, edesc); =20 - return common_nonsnoop_hash(edesc, req_ctx->areq, nbytes_to_hash, ahash_d= one); + return ret; } =20 static void sec1_ahash_process_remaining(struct work_struct *work) @@ -2102,16 +2147,13 @@ static int ahash_process_req(struct ahash_request *= areq, unsigned int nbytes) req_ctx->remaining_ahash_request_bytes =3D nbytes; =20 if (is_sec1) { - if (nbytes > TALITOS1_MAX_DATA_LEN) - nbytes =3D TALITOS1_MAX_DATA_LEN; - else if (req_ctx->last_request) + if (req_ctx->last_request) req_ctx->last_desc =3D 1; } =20 req_ctx->current_ahash_request_bytes =3D nbytes; =20 - return ahash_process_req_one(req_ctx->areq, - req_ctx->current_ahash_request_bytes); + return ahash_process_req_one(req_ctx->areq, nbytes); } =20 static int ahash_init(struct ahash_request *areq) diff --git a/drivers/crypto/talitos.h b/drivers/crypto/talitos.h index 596f96bba3ef..11f0eb6a41db 100644 --- a/drivers/crypto/talitos.h +++ b/drivers/crypto/talitos.h @@ -44,6 +44,11 @@ struct talitos_desc { =20 /* * talitos_edesc - s/w-extended descriptor + * @bufsl: scatterlist buffer + * @src: pointer to input scatterlist + * @first: first descriptor of a chain + * @last: last descriptor of a chain + * * @src_nents: number of segments in input scatterlist * @dst_nents: number of segments in output scatterlist * @iv_dma: dma address of iv for checking continuity and link table @@ -59,6 +64,11 @@ struct talitos_desc { * of link_tbl data */ struct talitos_edesc { + struct scatterlist bufsl[2]; + struct scatterlist *src; + int first; + int last; + int src_nents; int dst_nents; dma_addr_t iv_dma; --=20 2.54.0 From nobody Sat Jun 13 12:37:23 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 D484D410D3A; Thu, 7 May 2026 14:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164943; cv=none; b=XOwV1YIKEfblyP/6RTBTWHUfEmRtLQhVJs6Owe634yctmjfKAFJXYXL/Yrb35JfjXf0ANymNZcXuKaFX6hkyH7bY3AP66xjfrWpaioGuUMj7CBQ4OWaffMaVqISvirG/rYTkuRINkPeSJjWzReOCt7yi/BXdNLKuNOnFQMlp++k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164943; c=relaxed/simple; bh=j+6PCvRTp7SKVC0FT4iIhWmOSLwnJZVWRVkYosMNe5g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hrtW1TrGlQTlg0YdiWa6RA2rwEEskrxd2rQg6gp+H+SOExI7fGMqSv5yfjQR5RloKmqAUEdm/XsAvVSpfrjG+K8xwGWf/v4V/t9Z2AkrydL2lTY3v5GzH+rX5oH8+T11WnolngPOlQBHlOcF8DDKRx2815hOT4gsQNQzqaQWDro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=fV0dpV/t; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="fV0dpV/t" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 59C074E42C32; Thu, 7 May 2026 14:42:20 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 2929960644; Thu, 7 May 2026 14:42:20 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 0E01A108194EB; Thu, 7 May 2026 16:42:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778164939; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=EPpVeeYRNfJpuG0W8Z2Qz9u0mF8TkZfJzfXE8v1oTgw=; b=fV0dpV/t1N5DHZemuQr8eEbAuT23/nNXS6tHJjFA9cjW4l8cXeNo1yVJ9NMiKOPhMtpJdM 4sQiEL1UzjEot5pwG+MdHRk30V9t8vxZ16iCjJOY1G/0eEay9pEVLm9r0PRvL6FIgj1vbi rq9HF61xYb+4at1sOWV1VQlUHdardBdWrPonPa2ZfKP+tTFOMd/NReRyNKm/FiUDF596ai cAN6NJmH6EMw8MtpkR6Y+cQHIzNK5Bw045p1Pcimg4ivQL3UKNoXeLWXUcpK7gYW0JAMCJ ZPOAnRsOtuSKxHInnQQnjC/un4L+bthbDgT3+LEr0ykAuXZNRdfJTAtvmivoKA== From: Paul Louvel Date: Thu, 07 May 2026 16:41:54 +0200 Subject: [PATCH v3 08/11] crypto: talitos/hash - drop workqueue mechanism for SEC1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-8-c98d7589b942@bootlin.com> References: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> In-Reply-To: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> To: Herbert Xu , "David S. Miller" , Paolo Abeni , David Howells , Kim Phillips , Christophe Leroy Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Herve Codina , Paul Louvel , stable@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164923; l=5598; i=paul.louvel@bootlin.com; s=20260313; h=from:subject:message-id; bh=j+6PCvRTp7SKVC0FT4iIhWmOSLwnJZVWRVkYosMNe5g=; b=icD8Uu9DauD9AuKCQw2a7OKmDOvXnJSFZ5ut44g5/7pqJHeCefetRTAt1H9Bfm10qdlUx+MDJ cLfQCGPxadKARw89Mq0Hdt+MMU+xqzk+9BvIYEwbhtpMHThW6GLj8Je X-Developer-Key: i=paul.louvel@bootlin.com; a=ed25519; pk=eLW50NT18UAvUT5cAcYf88zNbBCZDLFXuptpyLVhVIU= X-Last-TLS-Session-Version: TLSv1.3 Now that SEC1 hash uses hardware descriptor chaining instead of a workqueue to process requests exceeding TALITOS1_MAX_DATA_LEN, the workqueue code is no longer needed. Remove sec1_ahash_process_remaining(), the related fields from talitos_ahash_req_ctx (request_bufsl, areq, request_sl, remaining_ahash_request_bytes, current_ahash_request_bytes, sec1_ahash_process_remaining), the dead code in ahash_done(), and simplify ahash_process_req() to call ahash_process_req_one() directly with the original areq->src and areq->nbytes. Cc: stable@vger.kernel.org Signed-off-by: Paul Louvel --- drivers/crypto/talitos.c | 80 +++++---------------------------------------= ---- 1 file changed, 7 insertions(+), 73 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 883115d66fc4..1f497930800b 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -12,7 +12,6 @@ * All rights reserved. */ =20 -#include #include #include #include @@ -952,13 +951,6 @@ struct talitos_ahash_req_ctx { unsigned int nbuf; struct scatterlist bufsl[2]; struct scatterlist *psrc; - - struct scatterlist request_bufsl[2]; - struct ahash_request *areq; - struct scatterlist *request_sl; - unsigned int remaining_ahash_request_bytes; - unsigned int current_ahash_request_bytes; - struct work_struct sec1_ahash_process_remaining; }; =20 struct talitos_export_state { @@ -1840,18 +1832,6 @@ static void ahash_done(struct device *dev, free_edesc_list_from(areq, edesc); =20 ahash_request_complete(areq, err); - - return; - - req_ctx->remaining_ahash_request_bytes -=3D - req_ctx->current_ahash_request_bytes; - - if (!req_ctx->remaining_ahash_request_bytes) { - ahash_request_complete(areq, 0); - return; - } - - schedule_work(&req_ctx->sec1_ahash_process_remaining); } =20 /* @@ -2044,12 +2024,12 @@ static int ahash_process_req_one(struct ahash_reque= st *areq, unsigned int nbytes =20 if (!req_ctx->last_request && (nbytes + req_ctx->nbuf <=3D blocksize)) { /* Buffer up to one whole block */ - nents =3D sg_nents_for_len(req_ctx->request_sl, nbytes); + nents =3D sg_nents_for_len(areq->src, nbytes); if (nents < 0) { dev_err(dev, "Invalid number of src SG.\n"); return nents; } - sg_copy_to_buffer(req_ctx->request_sl, nents, + sg_copy_to_buffer(areq->src, nents, ctx_buf + req_ctx->nbuf, nbytes); req_ctx->nbuf +=3D nbytes; return 0; @@ -2076,18 +2056,18 @@ static int ahash_process_req_one(struct ahash_reque= st *areq, unsigned int nbytes sg_init_table(req_ctx->bufsl, nsg); sg_set_buf(req_ctx->bufsl, ctx_buf, req_ctx->nbuf); if (nsg > 1) - sg_chain(req_ctx->bufsl, 2, req_ctx->request_sl); + sg_chain(req_ctx->bufsl, 2, areq->src); req_ctx->psrc =3D req_ctx->bufsl; } else - req_ctx->psrc =3D req_ctx->request_sl; + req_ctx->psrc =3D areq->src; =20 if (to_hash_later) { - nents =3D sg_nents_for_len(req_ctx->request_sl, nbytes); + nents =3D sg_nents_for_len(areq->src, nbytes); if (nents < 0) { dev_err(dev, "Invalid number of src SG.\n"); return nents; } - sg_pcopy_to_buffer(req_ctx->request_sl, nents, + sg_pcopy_to_buffer(areq->src, nents, req_ctx->buf[(req_ctx->buf_idx + 1) & 1], to_hash_later, nbytes - to_hash_later); @@ -2106,54 +2086,9 @@ static int ahash_process_req_one(struct ahash_reques= t *areq, unsigned int nbytes return ret; } =20 -static void sec1_ahash_process_remaining(struct work_struct *work) -{ - struct talitos_ahash_req_ctx *req_ctx =3D - container_of(work, struct talitos_ahash_req_ctx, - sec1_ahash_process_remaining); - int err =3D 0; - - req_ctx->request_sl =3D scatterwalk_ffwd(req_ctx->request_bufsl, - req_ctx->request_sl, TALITOS1_MAX_DATA_LEN); - - if (req_ctx->remaining_ahash_request_bytes > TALITOS1_MAX_DATA_LEN) - req_ctx->current_ahash_request_bytes =3D TALITOS1_MAX_DATA_LEN; - else { - req_ctx->current_ahash_request_bytes =3D - req_ctx->remaining_ahash_request_bytes; - - if (req_ctx->last_request) - req_ctx->last_desc =3D 1; - } - - err =3D ahash_process_req_one(req_ctx->areq, - req_ctx->current_ahash_request_bytes); - - if (err !=3D -EINPROGRESS) - ahash_request_complete(req_ctx->areq, err); -} - static int ahash_process_req(struct ahash_request *areq, unsigned int nbyt= es) { - struct crypto_ahash *tfm =3D crypto_ahash_reqtfm(areq); - struct talitos_ctx *ctx =3D crypto_ahash_ctx(tfm); - struct device *dev =3D ctx->dev; - struct talitos_ahash_req_ctx *req_ctx =3D ahash_request_ctx(areq); - struct talitos_private *priv =3D dev_get_drvdata(dev); - bool is_sec1 =3D has_ftr_sec1(priv); - - req_ctx->areq =3D areq; - req_ctx->request_sl =3D areq->src; - req_ctx->remaining_ahash_request_bytes =3D nbytes; - - if (is_sec1) { - if (req_ctx->last_request) - req_ctx->last_desc =3D 1; - } - - req_ctx->current_ahash_request_bytes =3D nbytes; - - return ahash_process_req_one(req_ctx->areq, nbytes); + return ahash_process_req_one(areq, nbytes); } =20 static int ahash_init(struct ahash_request *areq) @@ -2176,7 +2111,6 @@ static int ahash_init(struct ahash_request *areq) req_ctx->hw_context_size =3D size; req_ctx->last_request =3D 0; req_ctx->last_desc =3D 0; - INIT_WORK(&req_ctx->sec1_ahash_process_remaining, sec1_ahash_process_rema= ining); =20 dma =3D dma_map_single(dev, req_ctx->hw_context, req_ctx->hw_context_size, DMA_TO_DEVICE); --=20 2.54.0 From nobody Sat Jun 13 12:37:23 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 DEBF142883B; Thu, 7 May 2026 14:42:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164945; cv=none; b=byLNDEo3TS84/QwTOxy3GNhrF35iI+vWncW7NC8y4Np1FBC2VwtmHCoA12fy55shzYuPoauPJlOUfz1oyR5DXakp6CQy190XsVv+QAzNHt/hvN+u8UsUdSALTZG01lQh2mZcbbQaRyYAjf0OA7iWtrqb4emG1Fi7SE+OiwDE6Hs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164945; c=relaxed/simple; bh=hSkB/ToOSucAybkXhmloG2Iy73IAWltint0+kMWv33M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=K0+19pQMSXpm8f3qwYnnbM8gKktkDvEda1/c5nkf4RazwqpDgtm1bMjqFMkMk2LTxgwuEdhKFy+fRhYT5PEZZQ1F5PGcS1Qatp3apb9XQ/UkM55gw5iJr1npZe195L15EQopVEk9u6ThTPCF2XUn0EFtXV3cjpoR+x/czZFYlkk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=K9REKb0N; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="K9REKb0N" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id B25C91A3568; Thu, 7 May 2026 14:42:21 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 873C660646; Thu, 7 May 2026 14:42:21 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 89833108194EC; Thu, 7 May 2026 16:42:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778164940; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=uGyL4NeIjSoNBGK/yQ5ULcrXkbDaktVYoKhNYCw/tzs=; b=K9REKb0NCFbqeAuaBmO+Q3RGW/7+tbgpqSb39+dVVT9+gQVFByet5DcfvdyDXsFxG0iB9v Dyizg+mmogJQvZ+kE5UgcGLUi+dMUfrHQ7DLJX/fXfNj59hsgJy1Ye/zpKsXkGRiGLruEU xe30mLVcl1fW34ctMXk56Qojp1Rqo1XwRqvvmD2o2b/LKjlM6TbKyAYZX69ivJ2+kMpfOw c37xZM1K8DIXnD0HLK/AdEyesqkefSlEgeiDbJrG1pvcKggJpRztgZQthhEhQCzGHWbKyL Pwb825zfjrUD6Mzlbi8qT0EO+Qo1l7ybWNv7/PNY98pxNAW+qKTBc7bNpgFmpg== From: Paul Louvel Date: Thu, 07 May 2026 16:41:55 +0200 Subject: [PATCH v3 09/11] crypto: talitos/hash - rename first_desc/last_desc to first_request/last_request Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-9-c98d7589b942@bootlin.com> References: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> In-Reply-To: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> To: Herbert Xu , "David S. Miller" , Paolo Abeni , David Howells , Kim Phillips , Christophe Leroy Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Herve Codina , Paul Louvel , stable@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164923; l=4902; i=paul.louvel@bootlin.com; s=20260313; h=from:subject:message-id; bh=hSkB/ToOSucAybkXhmloG2Iy73IAWltint0+kMWv33M=; b=xHTyZu7Ps6N9uU+Deb4Rf7dXYFRZEgs2on+Ulii1Hem62k/P4Dxlo5LDbEhXUexu6RQvYUDbm gvsemm51tHJBNE/u5DpNUPPc/Nbqypl/VNB+kc7TSg0uqHzcBxzKoSG X-Developer-Key: i=paul.louvel@bootlin.com; a=ed25519; pk=eLW50NT18UAvUT5cAcYf88zNbBCZDLFXuptpyLVhVIU= X-Last-TLS-Session-Version: TLSv1.3 In talitos_ahash_req_ctx and talitos_export_state, the fields first_desc and last_desc describe request-level (not descriptor-level) state. Rename them to first_request and last_request for clarity. last_desc is also removed from talitos_ahash_req_ctx as it is no longer used. Cc: stable@vger.kernel.org Signed-off-by: Paul Louvel --- drivers/crypto/talitos.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 1f497930800b..6be42935068a 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -944,8 +944,7 @@ struct talitos_ahash_req_ctx { u8 buf[2][HASH_MAX_BLOCK_SIZE]; int buf_idx; unsigned int swinit; - unsigned int first_desc; - unsigned int last_desc; + unsigned int first_request; unsigned int last_request; unsigned int to_hash_later; unsigned int nbuf; @@ -957,8 +956,8 @@ struct talitos_export_state { u32 hw_context[TALITOS_MDEU_MAX_CONTEXT_SIZE / sizeof(u32)]; u8 buf[HASH_MAX_BLOCK_SIZE]; unsigned int swinit; - unsigned int first_desc; - unsigned int last_desc; + unsigned int first_request; + unsigned int last_request; unsigned int to_hash_later; unsigned int nbuf; }; @@ -1822,8 +1821,7 @@ static void ahash_done(struct device *dev, container_of(desc, struct talitos_edesc, desc); struct talitos_ahash_req_ctx *req_ctx =3D ahash_request_ctx(areq); =20 - - if (!req_ctx->last_desc && req_ctx->to_hash_later) { + if (!req_ctx->last_request && req_ctx->to_hash_later) { /* Position any partial block for next update/final/finup */ req_ctx->buf_idx =3D (req_ctx->buf_idx + 1) & 1; req_ctx->nbuf =3D req_ctx->to_hash_later; @@ -1872,7 +1870,7 @@ static void common_nonsnoop_hash(struct talitos_edesc= *edesc, /* first DWORD empty */ =20 /* hash context in */ - if (!edesc->first || !req_ctx->first_desc || req_ctx->swinit) { + if (!edesc->first || !req_ctx->first_request || req_ctx->swinit) { map_single_talitos_ptr_nosync(dev, &desc->ptr[1], req_ctx->hw_context_size, req_ctx->hw_context, @@ -1880,7 +1878,7 @@ static void common_nonsnoop_hash(struct talitos_edesc= *edesc, req_ctx->swinit =3D 0; } /* Indicate next op is not the first. */ - req_ctx->first_desc =3D 0; + req_ctx->first_request =3D 0; =20 /* HMAC key */ if (ctx->keylen) @@ -1975,14 +1973,14 @@ ahash_process_req_prepare(struct ahash_request *are= q, unsigned int nbytes, edesc->desc.hdr |=3D DESC_HDR_MODE0_MDEU_CONT; =20 /* request SEC to INIT hash. */ - if (req_ctx->first_desc && edesc->first && !req_ctx->swinit) + if (req_ctx->first_request && edesc->first && !req_ctx->swinit) edesc->desc.hdr |=3D DESC_HDR_MODE0_MDEU_INIT; =20 /* * When the tfm context has a keylen, it's an HMAC. * A first or last (ie. not middle) descriptor must request HMAC. */ - if (ctx->keylen && ((req_ctx->first_desc && edesc->first) || + if (ctx->keylen && ((req_ctx->first_request && edesc->first) || (req_ctx->last_request && edesc->last))) edesc->desc.hdr |=3D DESC_HDR_MODE0_MDEU_HMAC; =20 @@ -2103,14 +2101,13 @@ static int ahash_init(struct ahash_request *areq) /* Initialize the context */ req_ctx->buf_idx =3D 0; req_ctx->nbuf =3D 0; - req_ctx->first_desc =3D 1; /* first_desc indicates h/w must init its cont= ext */ + req_ctx->first_request =3D 1; req_ctx->swinit =3D 0; /* assume h/w init of context */ size =3D (crypto_ahash_digestsize(tfm) <=3D SHA256_DIGEST_SIZE) ? TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256 : TALITOS_MDEU_CONTEXT_SIZE_SHA384_SHA512; req_ctx->hw_context_size =3D size; req_ctx->last_request =3D 0; - req_ctx->last_desc =3D 0; =20 dma =3D dma_map_single(dev, req_ctx->hw_context, req_ctx->hw_context_size, DMA_TO_DEVICE); @@ -2202,8 +2199,8 @@ static int ahash_export(struct ahash_request *areq, v= oid *out) req_ctx->hw_context_size); memcpy(export->buf, req_ctx->buf[req_ctx->buf_idx], req_ctx->nbuf); export->swinit =3D req_ctx->swinit; - export->first_desc =3D req_ctx->first_desc; - export->last_desc =3D req_ctx->last_desc; + export->first_request =3D req_ctx->first_request; + export->last_request =3D req_ctx->last_request; export->to_hash_later =3D req_ctx->to_hash_later; export->nbuf =3D req_ctx->nbuf; =20 @@ -2228,8 +2225,8 @@ static int ahash_import(struct ahash_request *areq, c= onst void *in) memcpy(req_ctx->hw_context, export->hw_context, size); memcpy(req_ctx->buf[0], export->buf, export->nbuf); req_ctx->swinit =3D export->swinit; - req_ctx->first_desc =3D export->first_desc; - req_ctx->last_desc =3D export->last_desc; + req_ctx->first_request =3D export->first_request; + req_ctx->last_request =3D export->last_request; req_ctx->to_hash_later =3D export->to_hash_later; req_ctx->nbuf =3D export->nbuf; =20 --=20 2.54.0 From nobody Sat Jun 13 12:37:23 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 BBFAE42E001; Thu, 7 May 2026 14:42:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164946; cv=none; b=Z+Liw3As/a9lof6eIhldit38C7o5U1tkwnJisZx8DPpKFPhp+Xo5gvg5oIaV7D7JoBoZnVrDGNw8IfiP15wzIdj54WFZ2xEFXPg902Mv8O7blD1fbkMtG2ocdPorDQIttTehPYsmT2CqUSec/Yv9VHRaawE1X5GUgWgGHJHZt9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164946; c=relaxed/simple; bh=iNY1bV6sEU6UZySxVCoMKc1UN0Cns0l8ZB7lYYXZRGE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Z1X7K+ZN25Ek8vIma8YIjSmjSMCc312zMbS2W9nS2Kr/6/PGlEU89hVKntBJyg2M/iHAFo3r9aY4gAGe0r7P6u7+SAYuFRLommAMpIUmwOHyuEMxZDP6iR/xl7t/Gs07sxgatGyafbZjq7qOT02uJI2HuGshmC+6XFLypSb4YGI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=dS4Xlwf0; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="dS4Xlwf0" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 5E7B71A3565; Thu, 7 May 2026 14:42:23 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 33F6760495; Thu, 7 May 2026 14:42:23 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 029AE108194EE; Thu, 7 May 2026 16:42:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778164942; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=KkM/TUCrKEGYPN5lXa8hKMsrHIbcVv/R/bnS/meaV8s=; b=dS4Xlwf0bHOj5W2ScVjDaQrNgFoh7t/Rpno7Vv++WlAgbd6Sw4fFNMpS29XoqM4vXQ/3zB Gd/Lm5qQkmONngxdxSgCshKewKWtqQw1CP8DFUW1x2PVB/VDKMmkPAuhlLMuAoGJdFIuTh KQOv/3cidtkQaXkD6VOKQbUdrh1uS0yil7+ixZ9DlrWaNumehgbKnUDABnGrdhW+FX9GNq lqXOURJiggIY8cty0tOgZDP5QGmdxQFdJmbSHeRn4yTGZCA2RMgE9W7PlFlTHaLW7ep3GS PEhh+5WyC5EhDSVJ3K1EfYGWIw3MFe8Fb2llOVFx2BGCOfDgkm32Pq5DSEjY5A== From: Paul Louvel Date: Thu, 07 May 2026 16:41:56 +0200 Subject: [PATCH v3 10/11] crypto: talitos/hash - remove useless wrapper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-10-c98d7589b942@bootlin.com> References: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> In-Reply-To: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> To: Herbert Xu , "David S. Miller" , Paolo Abeni , David Howells , Kim Phillips , Christophe Leroy Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Herve Codina , Paul Louvel , stable@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164923; l=1346; i=paul.louvel@bootlin.com; s=20260313; h=from:subject:message-id; bh=iNY1bV6sEU6UZySxVCoMKc1UN0Cns0l8ZB7lYYXZRGE=; b=mbtLfy80Hkz69Dn7hQb06P6+OIr6Bw2GBBKEJK74retGcF5Pi2GLrJyfgrc7u7PPkhoLj//dO 8IvIU8dPseND5VrKLVlFsWaxs2duZCeb4MzhdOx9/ys2zq+GOCUi+9s X-Developer-Key: i=paul.louvel@bootlin.com; a=ed25519; pk=eLW50NT18UAvUT5cAcYf88zNbBCZDLFXuptpyLVhVIU= X-Last-TLS-Session-Version: TLSv1.3 ahash_process_req() was a wrapper used in commit 655ef638a2bc ("crypto: talitos - fix SEC1 32k ahash request limitation"). Rename ahash_process_req_one() to ahash_process_req() and remove the wrapper. Cc: stable@vger.kernel.org Signed-off-by: Paul Louvel --- drivers/crypto/talitos.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 6be42935068a..b4283b6c18ef 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -2003,7 +2003,7 @@ ahash_process_req_prepare(struct ahash_request *areq,= unsigned int nbytes, return first; } =20 -static int ahash_process_req_one(struct ahash_request *areq, unsigned int = nbytes) +static int ahash_process_req(struct ahash_request *areq, unsigned int nbyt= es) { struct crypto_ahash *tfm =3D crypto_ahash_reqtfm(areq); struct talitos_ctx *ctx =3D crypto_ahash_ctx(tfm); @@ -2084,11 +2084,6 @@ static int ahash_process_req_one(struct ahash_reques= t *areq, unsigned int nbytes return ret; } =20 -static int ahash_process_req(struct ahash_request *areq, unsigned int nbyt= es) -{ - return ahash_process_req_one(areq, nbytes); -} - static int ahash_init(struct ahash_request *areq) { struct crypto_ahash *tfm =3D crypto_ahash_reqtfm(areq); --=20 2.54.0 From nobody Sat Jun 13 12:37:23 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 7BFCD439015 for ; Thu, 7 May 2026 14:42:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164948; cv=none; b=JN5rnvu0YBQk7xYIcwnhrop1gb2OUyIR0kjjaUWk2hEySpwXG168SwG/QSodsjDJYoTbj5K0LZSgPu8q/rytQVAUoZajxb/MTjhSckN76bSqfMyo3GLFdw0xp/1Z+0o4H8tYeoaImOIPg6FNqEjrCYrOwYpxUR2Kg7wBU9Bxfds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164948; c=relaxed/simple; bh=h69OuocOka0lEOTpvPZEVhUi/eh/0IH/isa5KRgbLeI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YUjb1E7egJqh9daWbSuh5s2O8KHwr2IV24NPzvtUE5ELUv0iPuhVivD7LV58G0RmVSXWvHLJl70O60oK9vG40ryhVM2aIIpouKmBKCWK3thwIdle2LwobPIhok4/l0dSXVH/DcdKOqmOz0q5W3RncP4k+uG9J27ksxKSHVeJtRc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=APliv8x5; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="APliv8x5" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 2D8EA1A3569; Thu, 7 May 2026 14:42:25 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 021AB60495; Thu, 7 May 2026 14:42:25 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 82105108194F0; Thu, 7 May 2026 16:42:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778164943; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=mQBLgnhCwiV4EhzA5f7CQH8UsRD9gPGq4MrWHe/TNzk=; b=APliv8x5fqkKbkLpr6WhDKfwELIg/L843L1Tt+LZ4WntWmPzy0RuHxkk7jU84pEy91npIH syJ6kE/5VJRIQZ2vKA0ouH7urB8EJ4iG2oXu1t0BM9193rUm0KP6rMV8RSzXaslAMn9kuK 4+NlRVNdcf75Z0xUdPgJK/iQg+PzJN5Af2pjp2H493oyGuK0RvKMe0qWaPl1MGzAIl4Q40 /dTtrMc/dpXj/JiWPDEjnr8my6ITGQ83ZIsKXI/hXlKUayww+03Ikfg0LmUAd1fa1xCsX/ R6YFlk45YCg9QwXAb4DLk+rQownWZ8ts9jnjHxLK+nPeWQu1g0Jnhar1FgpQJA== From: Paul Louvel Date: Thu, 07 May 2026 16:41:57 +0200 Subject: [PATCH v3 11/11] crypto: talitos/hash - fix SEC2 64k - 1 ahash request limitation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-11-c98d7589b942@bootlin.com> References: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> In-Reply-To: <20260507-bootlin_test-7-1-rc1_sec_bugfix-v3-0-c98d7589b942@bootlin.com> To: Herbert Xu , "David S. Miller" , Paolo Abeni , David Howells , Kim Phillips , Christophe Leroy Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Herve Codina , Paul Louvel , stable@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164923; l=3206; i=paul.louvel@bootlin.com; s=20260313; h=from:subject:message-id; bh=h69OuocOka0lEOTpvPZEVhUi/eh/0IH/isa5KRgbLeI=; b=734tPEih8sT/JGATidG+dSYYbcroS8aRJTkRuYEqAw4loRz9BVp1dhw9MENVdq9x5mqWWTHqe ew+DI03md/OCz765mpuuXY+LUk9fNcUeXSA0jFePBRB3PUSHYVQdE/9 X-Developer-Key: i=paul.louvel@bootlin.com; a=ed25519; pk=eLW50NT18UAvUT5cAcYf88zNbBCZDLFXuptpyLVhVIU= X-Last-TLS-Session-Version: TLSv1.3 The problem described in commit 655ef638a2bc ("crypto: talitos - fix SEC1 32k ahash request limitation") also apply for the SEC2 hardware, but with a limitation of 64k - 1 bytes. Split ahash_done() into SEC1 and SEC2 paths: SEC1 continues to free the whole descriptor list at once, while SEC2 now iterates through descriptors one by one, submitting the next only after the previous completes, which is required since SEC2 cannot chain descriptors in hardware. Cc: stable@vger.kernel.org Fixes: c662b043cdca ("crypto: af_alg/hash: Support MSG_SPLICE_PAGES") Signed-off-by: Paul Louvel --- drivers/crypto/talitos.c | 47 +++++++++++++++++++++++++++++++++++++++-----= --- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index b4283b6c18ef..4b53b13f96d9 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -1820,16 +1820,46 @@ static void ahash_done(struct device *dev, struct talitos_edesc *edesc =3D container_of(desc, struct talitos_edesc, desc); struct talitos_ahash_req_ctx *req_ctx =3D ahash_request_ctx(areq); + struct crypto_ahash *tfm =3D crypto_ahash_reqtfm(areq); + bool is_sec1 =3D has_ftr_sec1(dev_get_drvdata(dev)); + struct talitos_ctx *ctx =3D crypto_ahash_ctx(tfm); + struct talitos_edesc *next; =20 - if (!req_ctx->last_request && req_ctx->to_hash_later) { - /* Position any partial block for next update/final/finup */ - req_ctx->buf_idx =3D (req_ctx->buf_idx + 1) & 1; - req_ctx->nbuf =3D req_ctx->to_hash_later; - } + if (is_sec1) { + if (!req_ctx->last_request && req_ctx->to_hash_later) { + /* Position any partial block for next update/final/finup */ + req_ctx->buf_idx =3D (req_ctx->buf_idx + 1) & 1; + req_ctx->nbuf =3D req_ctx->to_hash_later; + } + + free_edesc_list_from(areq, edesc); + ahash_request_complete(areq, err); + } else { + next =3D edesc->next_desc; =20 - free_edesc_list_from(areq, edesc); + common_nonsnoop_hash_unmap(dev, edesc, areq); + kfree(edesc); =20 - ahash_request_complete(areq, err); + if (err) + goto out; + + if (next) { + err =3D talitos_submit(dev, ctx->ch, &next->desc, + ahash_done, areq); + if (err !=3D -EINPROGRESS) + goto out; + return; + } +out: + if (!req_ctx->last_request && req_ctx->to_hash_later) { + /* Position any partial block for next update/final/finup */ + req_ctx->buf_idx =3D (req_ctx->buf_idx + 1) & 1; + req_ctx->nbuf =3D req_ctx->to_hash_later; + } + if (err && next) + free_edesc_list_from(areq, next); + ahash_request_complete(areq, err); + } } =20 /* @@ -1940,7 +1970,8 @@ ahash_process_req_prepare(struct ahash_request *areq,= unsigned int nbytes, struct talitos_ctx *ctx =3D crypto_ahash_ctx(crypto_ahash_reqtfm(areq)); struct talitos_ahash_req_ctx *req_ctx =3D ahash_request_ctx(areq); struct talitos_edesc *first =3D NULL, *prev_edesc =3D NULL, *edesc; - size_t desc_max =3D is_sec1 ? TALITOS1_MAX_DATA_LEN : SIZE_MAX; + size_t desc_max =3D is_sec1 ? TALITOS1_MAX_DATA_LEN : + TALITOS2_MAX_DATA_LEN; struct scatterlist tmp[2]; size_t to_hash_this_desc; struct scatterlist *src; --=20 2.54.0