diff mbox

[2/3] crypto: caam_rng: fix rng_unmap_ctx's DMA_UNMAP size problem

Message ID 1425365453-19358-3-git-send-email-yanjiang.jin@windriver.com (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show

Commit Message

yanjiang.jin@windriver.com March 3, 2015, 6:50 a.m. UTC
From: Yanjiang Jin <yanjiang.jin@windriver.com>

Fix rng_unmap_ctx's DMA_UNMAP size problem for caam_rng, else system would
report the below calltrace during kexec boot:

caam_jr ffe301000.jr: DMA-API: device driver frees DMA memory with different size [device address=0x000000007f080010] [map size=16 bytes] [unmap size=40 bytes]
------------[ cut here ]------------
WARNING: at lib/dma-debug.c:887
Modules linked in:
CPU: 1 PID: 730 Comm: kexec Not tainted 3.10.62-ltsi-WR6.0.0.0_standard #188
task: c0000000f7cdaa80 ti: c0000000e5340000 task.ti: c0000000e5340000
NIP: c0000000004f5bc8 LR: c0000000004f5bc4 CTR: c0000000005f69b0
REGS: c0000000e53433c0 TRAP: 0700   Not tainted  (3.10.62-ltsi-WR6.0.0.0_standard)
MSR: 0000000080029000 <CE,EE,ME>  CR: 24088482  XER: 00000000
SOFTE: 0

GPR00: c0000000004f5bc4 c0000000e5343640 c0000000012af360 000000000000009f
GPR04: 0000000000000000 00000000000000a0 c000000000d02070 c000000015980660
GPR08: c000000000cff360 0000000000000000 0000000000000000 c0000000012da018
GPR12: 00000000000001e3 c000000001fff780 00000000100f0000 0000000000000001
GPR16: 0000000000000002 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000000000000000 0000000000000000 ffffffffffffffff 0000000000000001
GPR24: 0000000000000001 0000000000000001 0000000000000000 0000000000000001
GPR28: c000000001556b90 c000000001565b80 c0000000e5343750 c0000000f9427480
NIP [c0000000004f5bc8] .check_unmap+0x538/0x9c0
LR [c0000000004f5bc4] .check_unmap+0x534/0x9c0
Call Trace:
[c0000000e5343640] [c0000000004f5bc4] .check_unmap+0x534/0x9c0 (unreliable)
[c0000000e53436e0] [c0000000004f60d4] .debug_dma_unmap_page+0x84/0xb0
[c0000000e5343810] [c00000000082f9d4] .caam_cleanup+0x1d4/0x240
[c0000000e53438a0] [c00000000056cc88] .hwrng_unregister+0xd8/0x1c0
[c0000000e5343930] [c00000000082fa74] .caam_rng_shutdown+0x34/0x60
[c0000000e53439a0] [c000000000817354] .caam_remove+0x54/0x420
[c0000000e5343a70] [c0000000005791ac] .platform_drv_shutdown+0x3c/0x60
[c0000000e5343af0] [c000000000573728] .device_shutdown+0x128/0x240
[c0000000e5343b90] [c0000000000880b4] .kernel_restart_prepare+0x54/0x70
[c0000000e5343c10] [c0000000000e5cac] .kernel_kexec+0x9c/0xd0
[c0000000e5343c90] [c000000000088404] .SyS_reboot+0x244/0x2d0
[c0000000e5343e30] [c000000000000718] syscall_exit+0x0/0x8c
Instruction dump:
7c641b78 41de0410 e8a90050 2fa50000 419e0484 e8de0028 e8ff0030 3c62ff90
e91e0030 38638388 48546ed9 60000000 <0fe00000> 3c62ff8f 38637fc8 48546ec5
---[ end trace e43fd1734d6600df ]---

Signed-off-by: Yanjiang Jin <yanjiang.jin@windriver.com>
---

V2: no change.

 drivers/crypto/caam/caamrng.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Kim Phillips March 3, 2015, 7:31 p.m. UTC | #1
On Tue, 3 Mar 2015 14:50:52 +0800
<yanjiang.jin@windriver.com> wrote:

> -		dma_unmap_single(jrdev, ctx->sh_desc_dma, DESC_RNG_LEN,
> -				 DMA_TO_DEVICE);
> +		dma_unmap_single(jrdev, ctx->sh_desc_dma,
> +				desc_bytes(ctx->sh_desc), DMA_TO_DEVICE);

alignment: the 'd' in desc_bytes should fall directly under the 'j'
in jrdev.

Also, DESC_RNG_LEN should be corrected to (4 * CAAM_CMD_SZ).

Kim
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
yanjiang.jin@windriver.com March 4, 2015, 5:33 a.m. UTC | #2
On 2015?03?04? 03:31, Kim Phillips wrote:
> On Tue, 3 Mar 2015 14:50:52 +0800
> <yanjiang.jin@windriver.com> wrote:
>
>> -		dma_unmap_single(jrdev, ctx->sh_desc_dma, DESC_RNG_LEN,
>> -				 DMA_TO_DEVICE);
>> +		dma_unmap_single(jrdev, ctx->sh_desc_dma,
>> +				desc_bytes(ctx->sh_desc), DMA_TO_DEVICE);
> alignment: the 'd' in desc_bytes should fall directly under the 'j'
> in jrdev.
>
> Also, DESC_RNG_LEN should be corrected to (4 * CAAM_CMD_SZ).

Hi Kim,

I can't find the obvious limitation for the RNG descriptor length in 
Freescale documents, could you point out it?

Thanks!
Yanjiang
>
> Kim
>
>

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Kim Phillips March 4, 2015, 6:36 p.m. UTC | #3
On Wed, 4 Mar 2015 13:33:22 +0800
yjin <yanjiang.jin@windriver.com> wrote:

> On 2015?03?04? 03:31, Kim Phillips wrote:
> > On Tue, 3 Mar 2015 14:50:52 +0800
> > <yanjiang.jin@windriver.com> wrote:
> >
> >> -		dma_unmap_single(jrdev, ctx->sh_desc_dma, DESC_RNG_LEN,
> >> -				 DMA_TO_DEVICE);
> >> +		dma_unmap_single(jrdev, ctx->sh_desc_dma,
> >> +				desc_bytes(ctx->sh_desc), DMA_TO_DEVICE);
> > alignment: the 'd' in desc_bytes should fall directly under the 'j'
> > in jrdev.
> >
> > Also, DESC_RNG_LEN should be corrected to (4 * CAAM_CMD_SZ).
> 
> Hi Kim,
> 
> I can't find the obvious limitation for the RNG descriptor length in 
> Freescale documents, could you point out it?

?  rng_create_sh_desc() creates a fixed descriptor of exactly 4
command-lengths.

Kim
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
yanjiang.jin@windriver.com March 5, 2015, 2:52 a.m. UTC | #4
On 2015?03?05? 02:36, Kim Phillips wrote:
> On Wed, 4 Mar 2015 13:33:22 +0800
> yjin <yanjiang.jin@windriver.com> wrote:
>
>> On 2015?03?04? 03:31, Kim Phillips wrote:
>>> On Tue, 3 Mar 2015 14:50:52 +0800
>>> <yanjiang.jin@windriver.com> wrote:
>>>
>>>> -		dma_unmap_single(jrdev, ctx->sh_desc_dma, DESC_RNG_LEN,
>>>> -				 DMA_TO_DEVICE);
>>>> +		dma_unmap_single(jrdev, ctx->sh_desc_dma,
>>>> +				desc_bytes(ctx->sh_desc), DMA_TO_DEVICE);
>>> alignment: the 'd' in desc_bytes should fall directly under the 'j'
>>> in jrdev.
>>>
>>> Also, DESC_RNG_LEN should be corrected to (4 * CAAM_CMD_SZ).
>> Hi Kim,
>>
>> I can't find the obvious limitation for the RNG descriptor length in
>> Freescale documents, could you point out it?
> ?  rng_create_sh_desc() creates a fixed descriptor of exactly 4
> command-lengths.

Hi Kim,

Do you mean that the code itself limits the descriptor length? Not a 
hardware limitation.
If so, I prefer to dma_unmap with desc_bytes(ctx->sh_desc) as my 
previous patch, and correct DESC_RNG_LEN to (4 * CAAM_CMD_SZ).

Thanks!
Yanjiang

>
> Kim

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Kim Phillips March 6, 2015, 12:28 a.m. UTC | #5
On Thu, 5 Mar 2015 10:52:37 +0800
yjin <yanjiang.jin@windriver.com> wrote:

> On 2015?03?05? 02:36, Kim Phillips wrote:
> > On Wed, 4 Mar 2015 13:33:22 +0800
> > yjin <yanjiang.jin@windriver.com> wrote:
> >
> >> On 2015?03?04? 03:31, Kim Phillips wrote:
> >>> On Tue, 3 Mar 2015 14:50:52 +0800
> >>> <yanjiang.jin@windriver.com> wrote:
> >>>
> >>>> -		dma_unmap_single(jrdev, ctx->sh_desc_dma, DESC_RNG_LEN,
> >>>> -				 DMA_TO_DEVICE);
> >>>> +		dma_unmap_single(jrdev, ctx->sh_desc_dma,
> >>>> +				desc_bytes(ctx->sh_desc), DMA_TO_DEVICE);
> >>> alignment: the 'd' in desc_bytes should fall directly under the 'j'
> >>> in jrdev.
> >>>
> >>> Also, DESC_RNG_LEN should be corrected to (4 * CAAM_CMD_SZ).
> >>
> >> I can't find the obvious limitation for the RNG descriptor length in
> >> Freescale documents, could you point out it?
> > ?  rng_create_sh_desc() creates a fixed descriptor of exactly 4
> > command-lengths.
> 
> Do you mean that the code itself limits the descriptor length? Not a 
> hardware limitation.

the code writes descriptors such that they don't reach h/w
limitations.

> If so, I prefer to dma_unmap with desc_bytes(ctx->sh_desc) as my 
> previous patch, and correct DESC_RNG_LEN to (4 * CAAM_CMD_SZ).

please.

Kim
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index ae31e55..314f73d 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -90,8 +90,8 @@  static inline void rng_unmap_ctx(struct caam_rng_ctx *ctx)
 	struct device *jrdev = ctx->jrdev;
 
 	if (ctx->sh_desc_dma)
-		dma_unmap_single(jrdev, ctx->sh_desc_dma, DESC_RNG_LEN,
-				 DMA_TO_DEVICE);
+		dma_unmap_single(jrdev, ctx->sh_desc_dma,
+				desc_bytes(ctx->sh_desc), DMA_TO_DEVICE);
 	rng_unmap_buf(jrdev, &ctx->bufs[0]);
 	rng_unmap_buf(jrdev, &ctx->bufs[1]);
 }