From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796288953; b=Nql8YFD7eIJ/U+H6ljKtDZyHfmbZX365FcNhjqu9qnBoQfA+5yRLzpL54qQH83QocV14 y4UD9GcW2bDzQAvAj4oWCTMBaRxOadkjHkzfHbcfmr/dSokhlrgV3e5F3KUgOsFbM4/9L /U3zLQZpIDsSZRAradShod8qnmWERRmQvV2P9j8eny+i1ELq0lnWoEuI6iNUEoni8lBJq H1huUHcgpM/O05oiNbM8/s+QzJb6l7d4LpMhT9+zXoxZaLO+pbVkOn7uiRg24Bp/i2Ato eBBWrdxcNV6vG5hIafUTIA5W+9uxfXZini+4179vx8lp0PuZgItnfHSkgTg9tYAdZnQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796288953; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=tcPwk3NgaBYFjgxWIPNpM6X4VX9Zm5Gp3qYT/FcRTWc=; b=sl9YcLFJQtIt1TFMbNGXjs47eSx3nSz+AAkVd2rDHEiY8WWLvnEA656E/H4RUndmDcgE pbXJNYcVI35BI+AwZoqtYuK5FrsqLQgYMuUtIzfzG5mMJjYjYBsdW6EuYgAu62yQ91UbA iMzsttgxgSMiNVLdy1sc0tf6QQ7/5wPu0E3DSh3eKh9vtljAYOB3/WP6WFOgrM6zblOUJ gvTzjuujZuN4695cqo7ZhWDjZiQuUqXoDWBgORHbAlj9xGNOJ3xfJsgZ0bIZw0FJdc1xg uDS8yX2wI1mm/iT/pfHynzUPx+EdTKbHDqEg0Pieg9ELi4Hv935fWqhM5BywiQCQ7MA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Lk/JPP0z"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 563B1606A322 for ; Thu, 3 Dec 2026 09:09:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Lk/JPP0z Received: by smtp.kernel.org (Postfix) with ESMTPSA id B48981F000C1; Thu, 3 Dec 2026 09:09:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796288953; bh=tcPwk3NgaBYFjgxWIPNpM6X4VX9Zm5Gp3qYT/FcRTWc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Lk/JPP0zJOLm3NqShxIQRt7oS3NwS39ERQUPy3WqUQhBnNfDKQBImNaSYw/2bwJZN NZCRHKkWn1wwvrdA/AJIuCixZ0A2Hf05eQ/06O2NnZATsl0LpnIKoKh+ON2nYx90Oo cnzZvwfuMTLHgnA4JSXVnIoV9dPrst/l5fjICaxnuFd/H56ysUmsXy6tXt5wMi/q5c fUfogLet0jLvebZOx6b2uyyd0B+LAwXbf38EQunDsz9r5flPePGEDCZwaMEKrt/Dyx sHI9748XZGsiw0hy+tHnaOLYnmBgLvxsYlncAbbQ8O2JZ+01PL2z2gzGMQ3RxxcyYs J40G+RS7/hrMA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH crypto v2 2/2] crypto: safexcel - Map AEAD buffers with accurate DMA directions Reply-To: sashiko-reviews@lists.linux.dev To: "Ralf Lici" , linux-crypto@vger.kernel.org Cc: "Antoine Tenart" , "Herbert Xu" , "David S. Miller" , "Nikita Zhandarovich" , "Antonio Quartulli" In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 09:09:12 +0000 X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] crypto: safexcel: per-entry AEAD DMA mapping regresses coherent/IOMMU paths - [Medium] crypto: safexcel: safexcel_aead_dma_dir() over-maps out-of-place dst buffers - [Low] crypto: safexcel: duplicated DMA unmap dispatch in cipher req paths -- commit 0fc5903031a933ef50a45baa1e600103db377d61 Author: Ralf Lici crypto: safexcel - Map AEAD buffers with accurate DMA directions This commit replaces batched dma_map_sg() and dma_unmap_sg() calls on AEAD scatterlists with per-entry dma_map_page() and dma_unmap_page() helpers that select the DMA direction from each entry's overlap with the logical output range. > diff --git a/drivers/crypto/inside-secure/safexcel_cipher.c b/drivers/cry= pto/inside-secure/safexcel_cipher.c > index b9d8f5179de6c..78f90ba6c1365 100644 > --- a/drivers/crypto/inside-secure/safexcel_cipher.c > +++ b/drivers/crypto/inside-secure/safexcel_cipher.c [ ... ] > @@ -606,6 +608,71 @@ static int safexcel_context_control(struct safexcel_= cipher_ctx *ctx, > return 0; > } > =20 > +/* classify each scatterlist entry by its overlap with the logical outpu= t */ > +static enum dma_data_direction safexcel_aead_dma_dir(unsigned int offset, > + unsigned int len, > + unsigned int output_offset, > + unsigned int output_len, > + bool inplace) > +{ > + unsigned int end =3D offset + len; > + unsigned int output_end =3D output_offset + output_len; > + > + if (!output_len || offset >=3D output_end || output_offset >=3D end) > + return DMA_TO_DEVICE; > + > + if (inplace || offset < output_offset || end > output_end) > + return DMA_BIDIRECTIONAL; > + > + return DMA_FROM_DEVICE; > +} [Severity: Medium] Should safexcel_aead_dma_dir() map out-of-place destination entries with DMA_TO_DEVICE or DMA_BIDIRECTIONAL when the hardware never reads dst? When inplace is false, safexcel_send_req() skips pure-AAD dst entries in the result descriptor loop without using their DMA addresses. Mapping and unmapping those entries with DMA_TO_DEVICE adds unnecessary cache maintenance and barriers on non-coherent ARM64 and redundant IOMMU mappings on hot out-of-place paths such as kTLS. Mapping uninitialized out-of-place dst buffers with DMA_TO_DEVICE or DMA_BIDIRECTIONAL also triggers kmsan_internal_check_memory() under KMSAN, regressing callers like generate_aead_message() in crypto/testmgr.c that pass uninitialized kmalloc() buffers. Skipping non-overlapping out-of-place entries (while still setting sg_dma_len()) and mapping only the written sub-range of partial-overlap entries with DMA_FROM_DEVICE would avoid both issues. > +static void safexcel_unmap_aead(struct device *dev, struct scatterlist *= sgl, > + int nents, unsigned int output_offset, > + unsigned int output_len, bool inplace) > +{ > + struct scatterlist *sg; > + unsigned int offset =3D 0; > + int i; > + > + for_each_sg(sgl, sg, nents, i) { > + enum dma_data_direction dir; > + > + dir =3D safexcel_aead_dma_dir(offset, sg->length, output_offset, > + output_len, inplace); > + dma_unmap_page(dev, sg_dma_address(sg), sg_dma_len(sg), dir); > + offset +=3D sg->length; > + } > +} > + > +static int safexcel_map_aead(struct device *dev, struct scatterlist *sgl, > + int nents, unsigned int output_offset, > + unsigned int output_len, bool inplace) > +{ > + struct scatterlist *sg; > + unsigned int offset =3D 0; > + int i; > + > + for_each_sg(sgl, sg, nents, i) { > + enum dma_data_direction dir; > + > + dir =3D safexcel_aead_dma_dir(offset, sg->length, output_offset, > + output_len, inplace); > + sg_dma_address(sg) =3D dma_map_page(dev, sg_page(sg), sg->offset, > + sg->length, dir); > + if (dma_mapping_error(dev, sg_dma_address(sg))) > + goto err_unmap; > + sg_dma_len(sg) =3D sg->length; > + offset +=3D sg->length; > + } > + > + return nents; > + > +err_unmap: > + safexcel_unmap_aead(dev, sgl, i, output_offset, output_len, inplace); > + return 0; > +} [Severity: Medium] Does unconditionally replacing dma_map_sg() and dma_unmap_sg() with per-entry dma_map_page() and dma_unmap_page() regress AEAD throughput on DMA-coherent and IOMMU-backed devices? dma_kmalloc_safe() returns true when dev_is_dma_coherent(dev) is set, so coherent platforms do not bounce through SWIOTLB or hit the non-coherent cacheline corruption. On IOMMU-backed safexcel devices (such as PCIe EIP197 boards or coherent Armada CP11x), per-entry calls lose batched IOVA allocation and segment coalescing and perform an iommu_iova_to_phys() walk plus a separate __iommu_dma_unmap() per entry. On non-coherent ARM64 dma-direct platforms, per-entry dma_map_page() and dma_unmap_page() also execute arch_sync_dma_flush() (dsb(sy)) on every entry, including DMA_TO_DEVICE unmaps, instead of once per scatterlist. Gating the per-entry path on !dev_is_dma_coherent(priv->dev) would preserve batched dma_map_sg() performance on coherent and IOMMU-backed devices. [ ... ] > @@ -911,16 +1014,30 @@ static int safexcel_send_req(struct crypto_async_r= equest *base, int ring, > safexcel_ring_rollback_wptr(priv, &priv->ring[ring].cdr); > unmap: > if (src =3D=3D dst) { > - if (src_mapped) > - dma_unmap_sg(priv->dev, src, sreq->nr_src, > - DMA_BIDIRECTIONAL); > + if (src_mapped) { > + if (ctx->aead) > + safexcel_unmap_aead(priv->dev, src, > + sreq->nr_src, > + sreq->output_offset, > + sreq->output_len, true); > + else > + dma_unmap_sg(priv->dev, src, sreq->nr_src, > + DMA_BIDIRECTIONAL); > + } > } else { > if (src_mapped) > dma_unmap_sg(priv->dev, src, sreq->nr_src, > DMA_TO_DEVICE); > - if (dst_mapped) > - dma_unmap_sg(priv->dev, dst, sreq->nr_dst, > - DMA_FROM_DEVICE); > + if (dst_mapped) { > + if (ctx->aead) > + safexcel_unmap_aead(priv->dev, dst, > + sreq->nr_dst, > + sreq->output_offset, > + sreq->output_len, false); > + else > + dma_unmap_sg(priv->dev, dst, sreq->nr_dst, > + DMA_FROM_DEVICE); > + } > } [Severity: Low] This isn't a bug, but this unmap block duplicates the same nested if (src =3D=3D dst) / if (ctx->aead) dispatch in safexcel_handle_req_result= (), differing only in checking src_mapped/dst_mapped versus sreq->nr_src > 0 / sreq->nr_dst > 0. Extracting a shared helper would avoid keeping both copies in sync. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796286347.gi= t.ralf@mandelbit.com?part=3D2