2021-02-09 07:05:21

by chenxiang (M)

[permalink] [raw]
Subject: [PATCH 0/4] Fix the parameter of dma_map_sg()

From: Xiang Chen <[email protected]>

According to Documentation/core-api/dma-api-howto.rst, the parameters
of dma_unmap_sg() must be the same as those which are passed in to the
scatter/gather mapping API.
But for some drivers under crypto, the <nents> parameter of dma_unmap_sg()
is number of elements after mapping. So fix them.

Part of the document is as follows:

To unmap a scatterlist, just call::

dma_unmap_sg(dev, sglist, nents, direction);

Again, make sure DMA activity has already finished.

.. note::

The 'nents' argument to the dma_unmap_sg call must be
the _same_ one you passed into the dma_map_sg call,
it should _NOT_ be the 'count' value _returned_ from the
dma_map_sg call.

chenxiang (4):
crypto: amlogic - Fix the parameter of dma_unmap_sg()
crypto: cavium - Fix the parameter of dma_unmap_sg()
crypto: ux500 - Fix the parameter of dma_unmap_sg()
crypto: allwinner - Fix the parameter of dma_unmap_sg()

drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 9 ++++++---
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 3 ++-
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 9 ++++++---
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 3 ++-
drivers/crypto/amlogic/amlogic-gxl-cipher.c | 6 +++---
drivers/crypto/cavium/nitrox/nitrox_reqmgr.c | 8 ++++----
drivers/crypto/ux500/cryp/cryp_core.c | 4 ++--
drivers/crypto/ux500/hash/hash_core.c | 2 +-
8 files changed, 26 insertions(+), 18 deletions(-)

--
2.8.1


2021-02-09 07:05:46

by chenxiang (M)

[permalink] [raw]
Subject: [PATCH 1/4] crypto: amlogic - Fix the parameter of dma_unmap_sg()

From: Xiang Chen <[email protected]>

For function dma_unmap_sg(), the <nents> parameter should be number of
elements in the scatterlist prior to the mapping, not after the mapping.
So fix this usage.

Signed-off-by: Xiang Chen <[email protected]>
---
drivers/crypto/amlogic/amlogic-gxl-cipher.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
index 8b5e073..c6865cbd 100644
--- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c
+++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
@@ -236,10 +236,10 @@ static int meson_cipher(struct skcipher_request *areq)
dma_unmap_single(mc->dev, phykeyiv, keyivlen, DMA_TO_DEVICE);

if (areq->src == areq->dst) {
- dma_unmap_sg(mc->dev, areq->src, nr_sgs, DMA_BIDIRECTIONAL);
+ dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_BIDIRECTIONAL);
} else {
- dma_unmap_sg(mc->dev, areq->src, nr_sgs, DMA_TO_DEVICE);
- dma_unmap_sg(mc->dev, areq->dst, nr_sgd, DMA_FROM_DEVICE);
+ dma_unmap_sg(mc->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE);
+ dma_unmap_sg(mc->dev, areq->dst, sg_nents(areq->dst), DMA_FROM_DEVICE);
}

if (areq->iv && ivsize > 0) {
--
2.8.1

2021-02-09 07:06:16

by chenxiang (M)

[permalink] [raw]
Subject: [PATCH 2/4] crypto: cavium - Fix the parameter of dma_unmap_sg()

From: Xiang Chen <[email protected]>

For function dma_unmap_sg(), the <nents> parameter should be number of
elements in the scatterlist prior to the mapping, not after the mapping.
So fix this usage.

Signed-off-by: Xiang Chen <[email protected]>
---
drivers/crypto/cavium/nitrox/nitrox_reqmgr.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/cavium/nitrox/nitrox_reqmgr.c b/drivers/crypto/cavium/nitrox/nitrox_reqmgr.c
index 53ef067..1263194 100644
--- a/drivers/crypto/cavium/nitrox/nitrox_reqmgr.c
+++ b/drivers/crypto/cavium/nitrox/nitrox_reqmgr.c
@@ -170,7 +170,7 @@ static int dma_map_inbufs(struct nitrox_softreq *sr,
sr->in.total_bytes += sg_dma_len(sg);

sr->in.sg = req->src;
- sr->in.sgmap_cnt = nents;
+ sr->in.sgmap_cnt = sg_nents(req->src);
ret = create_sg_component(sr, &sr->in, sr->in.sgmap_cnt);
if (ret)
goto incomp_err;
@@ -178,7 +178,7 @@ static int dma_map_inbufs(struct nitrox_softreq *sr,
return 0;

incomp_err:
- dma_unmap_sg(dev, req->src, nents, DMA_BIDIRECTIONAL);
+ dma_unmap_sg(dev, req->src, sg_nents(req->src), DMA_BIDIRECTIONAL);
sr->in.sgmap_cnt = 0;
return ret;
}
@@ -195,7 +195,7 @@ static int dma_map_outbufs(struct nitrox_softreq *sr,
return -EINVAL;

sr->out.sg = req->dst;
- sr->out.sgmap_cnt = nents;
+ sr->out.sgmap_cnt = sg_nents(req->dst);
ret = create_sg_component(sr, &sr->out, sr->out.sgmap_cnt);
if (ret)
goto outcomp_map_err;
@@ -203,7 +203,7 @@ static int dma_map_outbufs(struct nitrox_softreq *sr,
return 0;

outcomp_map_err:
- dma_unmap_sg(dev, req->dst, nents, DMA_BIDIRECTIONAL);
+ dma_unmap_sg(dev, req->dst, sg_nents(req->dst), DMA_BIDIRECTIONAL);
sr->out.sgmap_cnt = 0;
sr->out.sg = NULL;
return ret;
--
2.8.1

2021-02-09 07:06:28

by chenxiang (M)

[permalink] [raw]
Subject: [PATCH 4/4] crypto: allwinner - Fix the parameter of dma_unmap_sg()

From: Xiang Chen <[email protected]>

For function dma_unmap_sg(), the <nents> parameter should be number of
elements in the scatterlist prior to the mapping, not after the mapping.
So fix this usage.

Signed-off-by: Xiang Chen <[email protected]>
---
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 9 ++++++---
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 3 ++-
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 9 ++++++---
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 3 ++-
4 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
index 33707a2..54ae8d1 100644
--- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
+++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
@@ -240,11 +240,14 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req

theend_sgs:
if (areq->src == areq->dst) {
- dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_BIDIRECTIONAL);
+ dma_unmap_sg(ce->dev, areq->src, sg_nents(areq->src),
+ DMA_BIDIRECTIONAL);
} else {
if (nr_sgs > 0)
- dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_TO_DEVICE);
- dma_unmap_sg(ce->dev, areq->dst, nr_sgd, DMA_FROM_DEVICE);
+ dma_unmap_sg(ce->dev, areq->src, sg_nents(areq->src),
+ DMA_TO_DEVICE);
+ dma_unmap_sg(ce->dev, areq->dst, sg_nents(areq->dst),
+ DMA_FROM_DEVICE);
}

theend_iv:
diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
index 2f09a37..8819471 100644
--- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
+++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
@@ -405,7 +405,8 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
err = sun8i_ce_run_task(ce, flow, crypto_tfm_alg_name(areq->base.tfm));

dma_unmap_single(ce->dev, addr_pad, j * 4, DMA_TO_DEVICE);
- dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_TO_DEVICE);
+ dma_unmap_sg(ce->dev, areq->src, sg_nents(areq->src),
+ DMA_TO_DEVICE);
dma_unmap_single(ce->dev, addr_res, digestsize, DMA_FROM_DEVICE);


diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
index ed2a69f..f945750 100644
--- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
@@ -232,10 +232,13 @@ static int sun8i_ss_cipher(struct skcipher_request *areq)

theend_sgs:
if (areq->src == areq->dst) {
- dma_unmap_sg(ss->dev, areq->src, nr_sgs, DMA_BIDIRECTIONAL);
+ dma_unmap_sg(ss->dev, areq->src, sg_nents(areq->src),
+ DMA_BIDIRECTIONAL);
} else {
- dma_unmap_sg(ss->dev, areq->src, nr_sgs, DMA_TO_DEVICE);
- dma_unmap_sg(ss->dev, areq->dst, nr_sgd, DMA_FROM_DEVICE);
+ dma_unmap_sg(ss->dev, areq->src, sg_nents(areq->src),
+ DMA_TO_DEVICE);
+ dma_unmap_sg(ss->dev, areq->dst, sg_nents(areq->dst),
+ DMA_FROM_DEVICE);
}

theend_iv:
diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
index 11cbcbc..55c06c3a 100644
--- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
+++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
@@ -432,7 +432,8 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq)
err = sun8i_ss_run_hash_task(ss, rctx, crypto_tfm_alg_name(areq->base.tfm));

dma_unmap_single(ss->dev, addr_pad, j * 4, DMA_TO_DEVICE);
- dma_unmap_sg(ss->dev, areq->src, nr_sgs, DMA_TO_DEVICE);
+ dma_unmap_sg(ss->dev, areq->src, sg_nents(areq->src),
+ DMA_TO_DEVICE);
dma_unmap_single(ss->dev, addr_res, digestsize, DMA_FROM_DEVICE);

kfree(pad);
--
2.8.1

2021-02-09 07:07:07

by chenxiang (M)

[permalink] [raw]
Subject: [PATCH 3/4] crypto: ux500 - Fix the parameter of dma_unmap_sg()

From: Xiang Chen <[email protected]>

For function dma_unmap_sg(), the <nents> parameter should be number of
elements in the scatterlist prior to the mapping, not after the mapping.
So fix this usage.

Signed-off-by: Xiang Chen <[email protected]>
---
drivers/crypto/ux500/cryp/cryp_core.c | 4 ++--
drivers/crypto/ux500/hash/hash_core.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/ux500/cryp/cryp_core.c b/drivers/crypto/ux500/cryp/cryp_core.c
index c3adeb2..9abf00e 100644
--- a/drivers/crypto/ux500/cryp/cryp_core.c
+++ b/drivers/crypto/ux500/cryp/cryp_core.c
@@ -608,12 +608,12 @@ static void cryp_dma_done(struct cryp_ctx *ctx)
chan = ctx->device->dma.chan_mem2cryp;
dmaengine_terminate_all(chan);
dma_unmap_sg(chan->device->dev, ctx->device->dma.sg_src,
- ctx->device->dma.sg_src_len, DMA_TO_DEVICE);
+ ctx->device->dma.nents_src, DMA_TO_DEVICE);

chan = ctx->device->dma.chan_cryp2mem;
dmaengine_terminate_all(chan);
dma_unmap_sg(chan->device->dev, ctx->device->dma.sg_dst,
- ctx->device->dma.sg_dst_len, DMA_FROM_DEVICE);
+ ctx->device->dma.nents_dst, DMA_FROM_DEVICE);
}

static int cryp_dma_write(struct cryp_ctx *ctx, struct scatterlist *sg,
diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c
index da284b0..67b1237 100644
--- a/drivers/crypto/ux500/hash/hash_core.c
+++ b/drivers/crypto/ux500/hash/hash_core.c
@@ -190,7 +190,7 @@ static void hash_dma_done(struct hash_ctx *ctx)
chan = ctx->device->dma.chan_mem2hash;
dmaengine_terminate_all(chan);
dma_unmap_sg(chan->device->dev, ctx->device->dma.sg,
- ctx->device->dma.sg_len, DMA_TO_DEVICE);
+ ctx->device->dma.nents, DMA_TO_DEVICE);
}

static int hash_dma_write(struct hash_ctx *ctx,
--
2.8.1

2021-02-10 14:30:10

by Corentin Labbe

[permalink] [raw]
Subject: Re: [PATCH 4/4] crypto: allwinner - Fix the parameter of dma_unmap_sg()

Le Tue, Feb 09, 2021 at 02:59:25PM +0800, chenxiang a ?crit :
> From: Xiang Chen <[email protected]>
>
> For function dma_unmap_sg(), the <nents> parameter should be number of
> elements in the scatterlist prior to the mapping, not after the mapping.
> So fix this usage.
>
> Signed-off-by: Xiang Chen <[email protected]>
> ---
> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 9 ++++++---
> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 3 ++-
> drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 9 ++++++---
> drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 3 ++-
> 4 files changed, 16 insertions(+), 8 deletions(-)
>

Hello

Acked-by: Corentin LABBE <[email protected]>
Tested-by: Corentin LABBE <[email protected]>
Tested-on: sun8i-a83t-bananapi-m3
Tested-on: sun50i-h6-pine-h64
Tested-on: sun50i-h6-orangepi-one-plus

Thanks

2021-02-20 01:55:09

by chenxiang (M)

[permalink] [raw]
Subject: Re: [PATCH 0/4] Fix the parameter of dma_map_sg()

Ping...

?? 2021/2/9 14:59, chenxiang ะด??:
> From: Xiang Chen <chenxiang6[email protected]>
>
> According to Documentation/core-api/dma-api-howto.rst, the parameters
> of dma_unmap_sg() must be the same as those which are passed in to the
> scatter/gather mapping API.
> But for some drivers under crypto, the <nents> parameter of dma_unmap_sg()
> is number of elements after mapping. So fix them.
>
> Part of the document is as follows:
>
> To unmap a scatterlist, just call::
>
> dma_unmap_sg(dev, sglist, nents, direction);
>
> Again, make sure DMA activity has already finished.
>
> .. note::
>
> The 'nents' argument to the dma_unmap_sg call must be
> the _same_ one you passed into the dma_map_sg call,
> it should _NOT_ be the 'count' value _returned_ from the
> dma_map_sg call.
>
> chenxiang (4):
> crypto: amlogic - Fix the parameter of dma_unmap_sg()
> crypto: cavium - Fix the parameter of dma_unmap_sg()
> crypto: ux500 - Fix the parameter of dma_unmap_sg()
> crypto: allwinner - Fix the parameter of dma_unmap_sg()
>
> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 9 ++++++---
> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 3 ++-
> drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 9 ++++++---
> drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 3 ++-
> drivers/crypto/amlogic/amlogic-gxl-cipher.c | 6 +++---
> drivers/crypto/cavium/nitrox/nitrox_reqmgr.c | 8 ++++----
> drivers/crypto/ux500/cryp/cryp_core.c | 4 ++--
> drivers/crypto/ux500/hash/hash_core.c | 2 +-
> 8 files changed, 26 insertions(+), 18 deletions(-)
>


2021-02-20 02:19:43

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH 0/4] Fix the parameter of dma_map_sg()

On Sat, Feb 20, 2021 at 09:51:17AM +0800, chenxiang (M) wrote:
> Ping...

Please be patient.
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt