crypto: sun8i-ss: do not use sg_dma_len before calling DMA functions
Corentin Labbe
maintainerPATCH RESEND 1/1 crypto: sun8i-ss: do not use sg_dma_len before calling DMA functions
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.
---
If someone know why sunxi_defconfig have sg_dma_len() which always works even with any DMA call not done.
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c +1 -1
@@ -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 ; }
Signature · 1 line
2.49.0
Hi,
Quoted 6 lines · Corentin Labbe
When testing sun8i-ss with
multi_v7_defconfig, all CBC algorithm fail crypto selftests.
This is strange since onsunxi_defconfig, everything was ok.
The problem was in the IV setup loop which never run becausesg_dma_lenwas 0.
Quoted 7 lines
Fixes 359e893e8af4 ("crypto: sun8i-ss - rework handling of IV")Signed-off-by Corentin Labbe <[email protected]>---
If someone know why
sunxi_defconfighavesg_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
Quoted 16 lines
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c +1
-1@@ -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 ; }
Herbert Xu
maintainerQuoted 5 lines · Ovidiu Panait
On the other hand,
multi_v7_defconfighasCONFIG_NEED_SG_DMA_LENGTHenabled, sosg_dma_len(sg)defaults tosg->dma_lengthand it would need to be used after callingdma_map_sg()(as indicated in the comment frominclude/linux/scatterlist.h).
In general, only use sg_dma_len if you are mapping an entire SG list with dma_map_sg.
If you're using dma_map_single, do not use sg_dma_len.
This is because dma_map_sg will try to merge entries together, thus creating an sg_dma_len that is bigger than the original (and reducing the SG list length accordingly).
OTOH dma_map_single can't possibly do that.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Herbert Xu
maintainerQuoted 8 lines · Corentin Labbe
When testing sun8i-ss with
multi_v7_defconfig, all CBC algorithm fail crypto selftests.
This is strange since onsunxi_defconfig, everything was ok.
The problem was in the IV setup loop which never run becausesg_dma_lenwas 0.Fixes 359e893e8af4 ("crypto: sun8i-ss - rework handling of IV")Signed-off-by Corentin Labbe <[email protected]>
Quoted 7 lines
---
If someone know why
sunxi_defconfighavesg_dma_len()which always works even with any DMA call not done.drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt