From: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
To: Corentin Labbe <clabbe.montjoie@gmail.com>,
herbert@gondor.apana.org.au, jernej.skrabec@gmail.com,
samuel@sholland.org, wens@csie.org
Cc: linux-arm-kernel@lists.infradead.org,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-sunxi@lists.linux.dev
Subject: Re: [PATCH RESEND] crypto: sun8i-ss: do not use sg_dma_len before calling DMA functions
Date: Sun, 27 Apr 2025 21:23:40 +0300 [thread overview]
Message-ID: <e147c220-92e1-40cb-920b-916cf6703b40@gmail.com> (raw)
In-Reply-To: <20250427111236.25668-1-clabbe.montjoie@gmail.com>
Hi,
On 4/27/25 2:12 PM, Corentin Labbe wrote:
> When testing sun8i-ss with multi_v7_defconfig, all CBC algorithm fail crypto
> selftests.
> This is strange since on sunxi_defconfig, everything was ok.
> The problem was in the IV setup loop which never run because sg_dma_len
> was 0.
>
> Fixes: 359e893e8af4 ("crypto: sun8i-ss - rework handling of IV")
> Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
> ---
>
> If someone know why sunxi_defconfig have sg_dma_len() which always works
> even with any DMA call not done.
>
It seems that sunxi_defconfig has CONFIG_NEED_SG_DMA_LENGTH disabled, so
sg_dma_len() defaults to sg->length.
From include/linux/scatterlist.h:
/*
* These macros should be used after a dma_map_sg call has been done
* to get bus addresses of each of the SG entries and their lengths.
* You should only work with the number of sg entries dma_map_sg
* returns, or alternatively stop on the first sg_dma_len(sg) which
* is 0.
*/
...
#ifdef CONFIG_NEED_SG_DMA_LENGTH
#define sg_dma_len(sg) ((sg)->dma_length)
#else
#define sg_dma_len(sg) ((sg)->length)
#endif
On the other hand, multi_v7_defconfig has CONFIG_NEED_SG_DMA_LENGTH
enabled, so sg_dma_len(sg) defaults to sg->dma_length and it would need
to be used after calling dma_map_sg() (as indicated in the comment from
include/linux/scatterlist.h).
Ovidiu
> drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
> index 4caf17310e90..ddec1b08d4f6 100644
> --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
> +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
> @@ -141,7 +141,7 @@ static int sun8i_ss_setup_ivs(struct skcipher_request *areq)
>
> /* we need to copy all IVs from source in case DMA is bi-directionnal */
> while (sg && len) {
> - if (sg_dma_len(sg) == 0) {
> + if (sg->length == 0) {
> sg = sg_next(sg);
> continue;
> }
next prev parent reply other threads:[~2025-04-27 18:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-27 11:12 [PATCH RESEND] crypto: sun8i-ss: do not use sg_dma_len before calling DMA functions Corentin Labbe
2025-04-27 18:23 ` Ovidiu Panait [this message]
2025-04-28 3:08 ` Herbert Xu
2025-04-28 11:54 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e147c220-92e1-40cb-920b-916cf6703b40@gmail.com \
--to=ovidiu.panait.oss@gmail.com \
--cc=clabbe.montjoie@gmail.com \
--cc=herbert@gondor.apana.org.au \
--cc=jernej.skrabec@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=samuel@sholland.org \
--cc=wens@csie.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox