Re: [PATCH 4/4] crypto: caamhash: replace kmalloc with kzalloc
On 2015年03月02日 19:03, Horia Geantă wrote: On 2/28/2015 8:00 AM, yanjiang@windriver.com wrote: From: Yanjiang Jin This can make sure we get a clean memory, else system would report the below warning: I'd avoid using kzalloc, it's an overhead on the hot path. kmalloc can be used with a bit of attention to detail, i.e. what params to explicitly initialize. Got it. Just zeroing edesc->sec4_sg_bytes in V2. Thanks! Yanjiang I see that the stack trace reports using WR Linux and a modified caam driver - it uses NAPI (net_rx_action) instead of tasklet. Have you actually reproduced the problem on upstream linux? There are some fixes that already address similar (if not exact) problem: 76b99080ccc9 "crypto: caam - fix uninitialized edesc->dst_dma fiel" 45e9af78b1ab "crypto: caam - fix uninitialized S/G table size in ahash_digest" Thanks, Horia caam_jr ffe301000.jr: DMA-API: device driver tries to free DMA memory it has not allocated [device address=0xdeadbeefdeadbeef] [size=18446744073150512879 bytes] [ cut here ] WARNING: at lib/dma-debug.c:877 Modules linked in: CPU: 1 PID: 98 Comm: cryptomgr_test Not tainted 3.10.62-ltsi-WR6.0.0.0_standard #175 task: c000f74bc400 ti: c000fffd task.ti: c000f775c000 NIP: c04f5ed8 LR: c04f5ed4 CTR: c055a160 REGS: c000fffd3650 TRAP: 0700 Not tainted (3.10.62-ltsi-WR6.0.0.0_standard) MSR: 80029000 CR: 24a48e84 XER: SOFTE: 1 004f5ed4 c000fffd38d0 c12af348 00a0 24a48e84 c125f1c8 01eb 0060 0001 10187373 0020 01eb c1fff780 c11ac928 c0007f003028 0097 0098 0098 c000f7758800 f7098c00 0001 0001 003f f7098c00 0014 c0007f003000 c11b0e98 c1565b80 c000fffd39e0 c000f72f2410 NIP [c04f5ed8] .check_unmap+0x848/0x9c0 LR [c04f5ed4] .check_unmap+0x844/0x9c0 Call Trace: [c000fffd38d0] [c04f5ed4] .check_unmap+0x844/0x9c0 (unreliable) [c000fffd3970] [c04f60d4] .debug_dma_unmap_page+0x84/0xb0 [c000fffd3aa0] [c08295cc] .ahash_done+0x1dc/0x360 [c000fffd3ca0] [c081b7ec] .caam_jr_dequeue+0x26c/0x3a0 [c000fffd3da0] [c08be50c] .net_rx_action+0x1cc/0x330 [c000fffd3e80] [c007276c] .__do_softirq+0x19c/0x3d0 [c000fffd3f90] [c0017054] .call_do_softirq+0x14/0x24 [c000f775ef10] [c0005fe8] .do_softirq+0x118/0x150 sda: sda1 sda2 sda3 [c000f775efa0] [c0072c54] .irq_exit+0x124/0x140 [c000f775f020] [c0005ac4] .do_IRQ+0x184/0x370 [c000f775f0d0] [c001b93c] exc_0x500_common+0xfc/0x100 --- Exception: 501 at .rcu_note_context_switch+0x0/0x370 edule+0xbc/0x7f0 [c000f775f3c0] [c0a29944] .__schedule+0xa4/0x7f0 (unreliable) [c000f775f620] [c0a277f4] .schedule_timeout+0x1b4/0x2e0 [c000f775f700] [c0a29428] .wait_for_common+0xf8/0x1d0 [c000f775f7c0] [c0a295ac] .wait_for_completion_interruptible+0x2c/0x50 [c000f775f840] [c0494b64] .do_one_async_hash_op.isra.1.part.2+0x24/0x50 [c000f775f8c0] [c04951a8] .test_hash+0x618/0x7d0 [c000f775fb30] [c0495424] .alg_test_hash+0xc4/0xf0 [c000f775fbc0] [c0494928] .alg_test+0xa8/0x2c0 [c000f775fcb0] [c0491164] .cryptomgr_test+0x64/0x80 [c000f775fd30] [c009a8d0] .kthread+0xf0/0x100 [c000f775fe30] [ca08] .ret_from_kernel_thread+0x5c/0xd4 Instruction dump: 7c641b78 419e0160 e8a90050 2fa5 409e0008 e8a90010 e8de0028 e8fe0030 3c62ff90 38638320 48546b69 6000 <0fe0> 4b34 e87e0010 2fa3 ---[ end trace 52825d316d569f00 ]--- Signed-off-by: Yanjiang Jin --- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 4/4] crypto: caamhash: replace kmalloc with kzalloc
On 2/28/2015 8:00 AM, yanjiang@windriver.com wrote: > From: Yanjiang Jin > > This can make sure we get a clean memory, else system would report > the below warning: I'd avoid using kzalloc, it's an overhead on the hot path. kmalloc can be used with a bit of attention to detail, i.e. what params to explicitly initialize. I see that the stack trace reports using WR Linux and a modified caam driver - it uses NAPI (net_rx_action) instead of tasklet. Have you actually reproduced the problem on upstream linux? There are some fixes that already address similar (if not exact) problem: 76b99080ccc9 "crypto: caam - fix uninitialized edesc->dst_dma fiel" 45e9af78b1ab "crypto: caam - fix uninitialized S/G table size in ahash_digest" Thanks, Horia > > caam_jr ffe301000.jr: DMA-API: device driver tries to free DMA memory it has > not allocated [device address=0xdeadbeefdeadbeef] [size=18446744073150512879 > bytes] > [ cut here ] > WARNING: at lib/dma-debug.c:877 > Modules linked in: > CPU: 1 PID: 98 Comm: cryptomgr_test Not tainted > 3.10.62-ltsi-WR6.0.0.0_standard #175 > task: c000f74bc400 ti: c000fffd task.ti: c000f775c000 > NIP: c04f5ed8 LR: c04f5ed4 CTR: c055a160 > REGS: c000fffd3650 TRAP: 0700 Not tainted > (3.10.62-ltsi-WR6.0.0.0_standard) > MSR: 80029000 CR: 24a48e84 XER: > SOFTE: 1 > > 004f5ed4 c000fffd38d0 c12af348 00a0 > 24a48e84 c125f1c8 01eb > 0060 0001 10187373 0020 > 01eb c1fff780 c11ac928 c0007f003028 > 0097 0098 0098 c000f7758800 > f7098c00 0001 0001 003f > f7098c00 0014 c0007f003000 c11b0e98 > c1565b80 c000fffd39e0 c000f72f2410 > NIP [c04f5ed8] .check_unmap+0x848/0x9c0 > LR [c04f5ed4] .check_unmap+0x844/0x9c0 > Call Trace: > [c000fffd38d0] [c04f5ed4] .check_unmap+0x844/0x9c0 (unreliable) > [c000fffd3970] [c04f60d4] .debug_dma_unmap_page+0x84/0xb0 > [c000fffd3aa0] [c08295cc] .ahash_done+0x1dc/0x360 > [c000fffd3ca0] [c081b7ec] .caam_jr_dequeue+0x26c/0x3a0 > [c000fffd3da0] [c08be50c] .net_rx_action+0x1cc/0x330 > [c000fffd3e80] [c007276c] .__do_softirq+0x19c/0x3d0 > [c000fffd3f90] [c0017054] .call_do_softirq+0x14/0x24 > [c000f775ef10] [c0005fe8] .do_softirq+0x118/0x150 > sda: sda1 sda2 sda3 > [c000f775efa0] [c0072c54] .irq_exit+0x124/0x140 > [c000f775f020] [c0005ac4] .do_IRQ+0x184/0x370 > [c000f775f0d0] [c001b93c] exc_0x500_common+0xfc/0x100 > --- Exception: 501 at .rcu_note_context_switch+0x0/0x370 > edule+0xbc/0x7f0 > [c000f775f3c0] [c0a29944] .__schedule+0xa4/0x7f0 (unreliable) > [c000f775f620] [c0a277f4] .schedule_timeout+0x1b4/0x2e0 > [c000f775f700] [c0a29428] .wait_for_common+0xf8/0x1d0 > [c000f775f7c0] [c0a295ac] > .wait_for_completion_interruptible+0x2c/0x50 > [c000f775f840] [c0494b64] > .do_one_async_hash_op.isra.1.part.2+0x24/0x50 > [c000f775f8c0] [c04951a8] .test_hash+0x618/0x7d0 > [c000f775fb30] [c0495424] .alg_test_hash+0xc4/0xf0 > [c000f775fbc0] [c0494928] .alg_test+0xa8/0x2c0 > [c000f775fcb0] [c0491164] .cryptomgr_test+0x64/0x80 > [c000f775fd30] [c009a8d0] .kthread+0xf0/0x100 > [c000f775fe30] [ca08] .ret_from_kernel_thread+0x5c/0xd4 > Instruction dump: > 7c641b78 419e0160 e8a90050 2fa5 409e0008 e8a90010 e8de0028 e8fe0030 > 3c62ff90 38638320 48546b69 6000 <0fe0> 4b34 e87e0010 2fa3 > ---[ end trace 52825d316d569f00 ]--- > > Signed-off-by: Yanjiang Jin > --- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 4/4] crypto: caamhash: replace kmalloc with kzalloc
On 2015年03月02日 19:03, Horia Geantă wrote: On 2/28/2015 8:00 AM, yanjiang@windriver.com wrote: From: Yanjiang Jin yanjiang@windriver.com This can make sure we get a clean memory, else system would report the below warning: I'd avoid using kzalloc, it's an overhead on the hot path. kmalloc can be used with a bit of attention to detail, i.e. what params to explicitly initialize. Got it. Just zeroing edesc-sec4_sg_bytes in V2. Thanks! Yanjiang I see that the stack trace reports using WR Linux and a modified caam driver - it uses NAPI (net_rx_action) instead of tasklet. Have you actually reproduced the problem on upstream linux? There are some fixes that already address similar (if not exact) problem: 76b99080ccc9 crypto: caam - fix uninitialized edesc-dst_dma fiel 45e9af78b1ab crypto: caam - fix uninitialized S/G table size in ahash_digest Thanks, Horia caam_jr ffe301000.jr: DMA-API: device driver tries to free DMA memory it has not allocated [device address=0xdeadbeefdeadbeef] [size=18446744073150512879 bytes] [ cut here ] WARNING: at lib/dma-debug.c:877 Modules linked in: CPU: 1 PID: 98 Comm: cryptomgr_test Not tainted 3.10.62-ltsi-WR6.0.0.0_standard #175 task: c000f74bc400 ti: c000fffd task.ti: c000f775c000 NIP: c04f5ed8 LR: c04f5ed4 CTR: c055a160 REGS: c000fffd3650 TRAP: 0700 Not tainted (3.10.62-ltsi-WR6.0.0.0_standard) MSR: 80029000 CE,EE,ME CR: 24a48e84 XER: SOFTE: 1 004f5ed4 c000fffd38d0 c12af348 00a0 24a48e84 c125f1c8 01eb 0060 0001 10187373 0020 01eb c1fff780 c11ac928 c0007f003028 0097 0098 0098 c000f7758800 f7098c00 0001 0001 003f f7098c00 0014 c0007f003000 c11b0e98 c1565b80 c000fffd39e0 c000f72f2410 NIP [c04f5ed8] .check_unmap+0x848/0x9c0 LR [c04f5ed4] .check_unmap+0x844/0x9c0 Call Trace: [c000fffd38d0] [c04f5ed4] .check_unmap+0x844/0x9c0 (unreliable) [c000fffd3970] [c04f60d4] .debug_dma_unmap_page+0x84/0xb0 [c000fffd3aa0] [c08295cc] .ahash_done+0x1dc/0x360 [c000fffd3ca0] [c081b7ec] .caam_jr_dequeue+0x26c/0x3a0 [c000fffd3da0] [c08be50c] .net_rx_action+0x1cc/0x330 [c000fffd3e80] [c007276c] .__do_softirq+0x19c/0x3d0 [c000fffd3f90] [c0017054] .call_do_softirq+0x14/0x24 [c000f775ef10] [c0005fe8] .do_softirq+0x118/0x150 sda: sda1 sda2 sda3 [c000f775efa0] [c0072c54] .irq_exit+0x124/0x140 [c000f775f020] [c0005ac4] .do_IRQ+0x184/0x370 [c000f775f0d0] [c001b93c] exc_0x500_common+0xfc/0x100 --- Exception: 501 at .rcu_note_context_switch+0x0/0x370 edule+0xbc/0x7f0 [c000f775f3c0] [c0a29944] .__schedule+0xa4/0x7f0 (unreliable) [c000f775f620] [c0a277f4] .schedule_timeout+0x1b4/0x2e0 [c000f775f700] [c0a29428] .wait_for_common+0xf8/0x1d0 [c000f775f7c0] [c0a295ac] .wait_for_completion_interruptible+0x2c/0x50 [c000f775f840] [c0494b64] .do_one_async_hash_op.isra.1.part.2+0x24/0x50 [c000f775f8c0] [c04951a8] .test_hash+0x618/0x7d0 [c000f775fb30] [c0495424] .alg_test_hash+0xc4/0xf0 [c000f775fbc0] [c0494928] .alg_test+0xa8/0x2c0 [c000f775fcb0] [c0491164] .cryptomgr_test+0x64/0x80 [c000f775fd30] [c009a8d0] .kthread+0xf0/0x100 [c000f775fe30] [ca08] .ret_from_kernel_thread+0x5c/0xd4 Instruction dump: 7c641b78 419e0160 e8a90050 2fa5 409e0008 e8a90010 e8de0028 e8fe0030 3c62ff90 38638320 48546b69 6000 0fe0 4b34 e87e0010 2fa3 ---[ end trace 52825d316d569f00 ]--- Signed-off-by: Yanjiang Jin yanjiang@windriver.com --- -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 4/4] crypto: caamhash: replace kmalloc with kzalloc
On 2/28/2015 8:00 AM, yanjiang@windriver.com wrote: From: Yanjiang Jin yanjiang@windriver.com This can make sure we get a clean memory, else system would report the below warning: I'd avoid using kzalloc, it's an overhead on the hot path. kmalloc can be used with a bit of attention to detail, i.e. what params to explicitly initialize. I see that the stack trace reports using WR Linux and a modified caam driver - it uses NAPI (net_rx_action) instead of tasklet. Have you actually reproduced the problem on upstream linux? There are some fixes that already address similar (if not exact) problem: 76b99080ccc9 crypto: caam - fix uninitialized edesc-dst_dma fiel 45e9af78b1ab crypto: caam - fix uninitialized S/G table size in ahash_digest Thanks, Horia caam_jr ffe301000.jr: DMA-API: device driver tries to free DMA memory it has not allocated [device address=0xdeadbeefdeadbeef] [size=18446744073150512879 bytes] [ cut here ] WARNING: at lib/dma-debug.c:877 Modules linked in: CPU: 1 PID: 98 Comm: cryptomgr_test Not tainted 3.10.62-ltsi-WR6.0.0.0_standard #175 task: c000f74bc400 ti: c000fffd task.ti: c000f775c000 NIP: c04f5ed8 LR: c04f5ed4 CTR: c055a160 REGS: c000fffd3650 TRAP: 0700 Not tainted (3.10.62-ltsi-WR6.0.0.0_standard) MSR: 80029000 CE,EE,ME CR: 24a48e84 XER: SOFTE: 1 004f5ed4 c000fffd38d0 c12af348 00a0 24a48e84 c125f1c8 01eb 0060 0001 10187373 0020 01eb c1fff780 c11ac928 c0007f003028 0097 0098 0098 c000f7758800 f7098c00 0001 0001 003f f7098c00 0014 c0007f003000 c11b0e98 c1565b80 c000fffd39e0 c000f72f2410 NIP [c04f5ed8] .check_unmap+0x848/0x9c0 LR [c04f5ed4] .check_unmap+0x844/0x9c0 Call Trace: [c000fffd38d0] [c04f5ed4] .check_unmap+0x844/0x9c0 (unreliable) [c000fffd3970] [c04f60d4] .debug_dma_unmap_page+0x84/0xb0 [c000fffd3aa0] [c08295cc] .ahash_done+0x1dc/0x360 [c000fffd3ca0] [c081b7ec] .caam_jr_dequeue+0x26c/0x3a0 [c000fffd3da0] [c08be50c] .net_rx_action+0x1cc/0x330 [c000fffd3e80] [c007276c] .__do_softirq+0x19c/0x3d0 [c000fffd3f90] [c0017054] .call_do_softirq+0x14/0x24 [c000f775ef10] [c0005fe8] .do_softirq+0x118/0x150 sda: sda1 sda2 sda3 [c000f775efa0] [c0072c54] .irq_exit+0x124/0x140 [c000f775f020] [c0005ac4] .do_IRQ+0x184/0x370 [c000f775f0d0] [c001b93c] exc_0x500_common+0xfc/0x100 --- Exception: 501 at .rcu_note_context_switch+0x0/0x370 edule+0xbc/0x7f0 [c000f775f3c0] [c0a29944] .__schedule+0xa4/0x7f0 (unreliable) [c000f775f620] [c0a277f4] .schedule_timeout+0x1b4/0x2e0 [c000f775f700] [c0a29428] .wait_for_common+0xf8/0x1d0 [c000f775f7c0] [c0a295ac] .wait_for_completion_interruptible+0x2c/0x50 [c000f775f840] [c0494b64] .do_one_async_hash_op.isra.1.part.2+0x24/0x50 [c000f775f8c0] [c04951a8] .test_hash+0x618/0x7d0 [c000f775fb30] [c0495424] .alg_test_hash+0xc4/0xf0 [c000f775fbc0] [c0494928] .alg_test+0xa8/0x2c0 [c000f775fcb0] [c0491164] .cryptomgr_test+0x64/0x80 [c000f775fd30] [c009a8d0] .kthread+0xf0/0x100 [c000f775fe30] [ca08] .ret_from_kernel_thread+0x5c/0xd4 Instruction dump: 7c641b78 419e0160 e8a90050 2fa5 409e0008 e8a90010 e8de0028 e8fe0030 3c62ff90 38638320 48546b69 6000 0fe0 4b34 e87e0010 2fa3 ---[ end trace 52825d316d569f00 ]--- Signed-off-by: Yanjiang Jin yanjiang@windriver.com --- -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 4/4] crypto: caamhash: replace kmalloc with kzalloc
From: Yanjiang Jin This can make sure we get a clean memory, else system would report the below warning: caam_jr ffe301000.jr: DMA-API: device driver tries to free DMA memory it has not allocated [device address=0xdeadbeefdeadbeef] [size=18446744073150512879 bytes] [ cut here ] WARNING: at lib/dma-debug.c:877 Modules linked in: CPU: 1 PID: 98 Comm: cryptomgr_test Not tainted 3.10.62-ltsi-WR6.0.0.0_standard #175 task: c000f74bc400 ti: c000fffd task.ti: c000f775c000 NIP: c04f5ed8 LR: c04f5ed4 CTR: c055a160 REGS: c000fffd3650 TRAP: 0700 Not tainted (3.10.62-ltsi-WR6.0.0.0_standard) MSR: 80029000 CR: 24a48e84 XER: SOFTE: 1 004f5ed4 c000fffd38d0 c12af348 00a0 24a48e84 c125f1c8 01eb 0060 0001 10187373 0020 01eb c1fff780 c11ac928 c0007f003028 0097 0098 0098 c000f7758800 f7098c00 0001 0001 003f f7098c00 0014 c0007f003000 c11b0e98 c1565b80 c000fffd39e0 c000f72f2410 NIP [c04f5ed8] .check_unmap+0x848/0x9c0 LR [c04f5ed4] .check_unmap+0x844/0x9c0 Call Trace: [c000fffd38d0] [c04f5ed4] .check_unmap+0x844/0x9c0 (unreliable) [c000fffd3970] [c04f60d4] .debug_dma_unmap_page+0x84/0xb0 [c000fffd3aa0] [c08295cc] .ahash_done+0x1dc/0x360 [c000fffd3ca0] [c081b7ec] .caam_jr_dequeue+0x26c/0x3a0 [c000fffd3da0] [c08be50c] .net_rx_action+0x1cc/0x330 [c000fffd3e80] [c007276c] .__do_softirq+0x19c/0x3d0 [c000fffd3f90] [c0017054] .call_do_softirq+0x14/0x24 [c000f775ef10] [c0005fe8] .do_softirq+0x118/0x150 sda: sda1 sda2 sda3 [c000f775efa0] [c0072c54] .irq_exit+0x124/0x140 [c000f775f020] [c0005ac4] .do_IRQ+0x184/0x370 [c000f775f0d0] [c001b93c] exc_0x500_common+0xfc/0x100 --- Exception: 501 at .rcu_note_context_switch+0x0/0x370 edule+0xbc/0x7f0 [c000f775f3c0] [c0a29944] .__schedule+0xa4/0x7f0 (unreliable) [c000f775f620] [c0a277f4] .schedule_timeout+0x1b4/0x2e0 [c000f775f700] [c0a29428] .wait_for_common+0xf8/0x1d0 [c000f775f7c0] [c0a295ac] .wait_for_completion_interruptible+0x2c/0x50 [c000f775f840] [c0494b64] .do_one_async_hash_op.isra.1.part.2+0x24/0x50 [c000f775f8c0] [c04951a8] .test_hash+0x618/0x7d0 [c000f775fb30] [c0495424] .alg_test_hash+0xc4/0xf0 [c000f775fbc0] [c0494928] .alg_test+0xa8/0x2c0 [c000f775fcb0] [c0491164] .cryptomgr_test+0x64/0x80 [c000f775fd30] [c009a8d0] .kthread+0xf0/0x100 [c000f775fe30] [ca08] .ret_from_kernel_thread+0x5c/0xd4 Instruction dump: 7c641b78 419e0160 e8a90050 2fa5 409e0008 e8a90010 e8de0028 e8fe0030 3c62ff90 38638320 48546b69 6000 <0fe0> 4b34 e87e0010 2fa3 ---[ end trace 52825d316d569f00 ]--- Signed-off-by: Yanjiang Jin --- drivers/crypto/caam/caamhash.c | 18 +- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index f6ad322..a6ba9f7 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c @@ -451,7 +451,7 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, const u8 *key_in, dma_addr_t src_dma, dst_dma; int ret = 0; - desc = kmalloc(CAAM_CMD_SZ * 8 + CAAM_PTR_SZ * 2, GFP_KERNEL | GFP_DMA); + desc = kzalloc(CAAM_CMD_SZ * 8 + CAAM_PTR_SZ * 2, GFP_KERNEL | GFP_DMA); if (!desc) { dev_err(jrdev, "unable to allocate key input memory\n"); return -ENOMEM; @@ -815,7 +815,7 @@ static int ahash_update_ctx(struct ahash_request *req) * allocate space for base edesc and hw desc commands, * link tables */ - edesc = kmalloc(sizeof(struct ahash_edesc) + DESC_JOB_IO_LEN + + edesc = kzalloc(sizeof(struct ahash_edesc) + DESC_JOB_IO_LEN + sec4_sg_bytes, GFP_DMA | flags); if (!edesc) { dev_err(jrdev, @@ -926,7 +926,7 @@ static int ahash_final_ctx(struct ahash_request *req) sec4_sg_bytes = (1 + (buflen ? 1 : 0)) * sizeof(struct sec4_sg_entry); /* allocate space for base edesc and hw desc commands, link tables */ - edesc = kmalloc(sizeof(struct ahash_edesc) + DESC_JOB_IO_LEN + + edesc = kzalloc(sizeof(struct ahash_edesc) + DESC_JOB_IO_LEN + sec4_sg_bytes, GFP_DMA | flags); if (!edesc) { dev_err(jrdev, "could not allocate extended descriptor\n"); @@ -1013,7 +1013,7 @@ static int ahash_finup_ctx(struct ahash_request *req) sizeof(struct sec4_sg_entry);
[PATCH 4/4] crypto: caamhash: replace kmalloc with kzalloc
From: Yanjiang Jin yanjiang@windriver.com This can make sure we get a clean memory, else system would report the below warning: caam_jr ffe301000.jr: DMA-API: device driver tries to free DMA memory it has not allocated [device address=0xdeadbeefdeadbeef] [size=18446744073150512879 bytes] [ cut here ] WARNING: at lib/dma-debug.c:877 Modules linked in: CPU: 1 PID: 98 Comm: cryptomgr_test Not tainted 3.10.62-ltsi-WR6.0.0.0_standard #175 task: c000f74bc400 ti: c000fffd task.ti: c000f775c000 NIP: c04f5ed8 LR: c04f5ed4 CTR: c055a160 REGS: c000fffd3650 TRAP: 0700 Not tainted (3.10.62-ltsi-WR6.0.0.0_standard) MSR: 80029000 CE,EE,ME CR: 24a48e84 XER: SOFTE: 1 004f5ed4 c000fffd38d0 c12af348 00a0 24a48e84 c125f1c8 01eb 0060 0001 10187373 0020 01eb c1fff780 c11ac928 c0007f003028 0097 0098 0098 c000f7758800 f7098c00 0001 0001 003f f7098c00 0014 c0007f003000 c11b0e98 c1565b80 c000fffd39e0 c000f72f2410 NIP [c04f5ed8] .check_unmap+0x848/0x9c0 LR [c04f5ed4] .check_unmap+0x844/0x9c0 Call Trace: [c000fffd38d0] [c04f5ed4] .check_unmap+0x844/0x9c0 (unreliable) [c000fffd3970] [c04f60d4] .debug_dma_unmap_page+0x84/0xb0 [c000fffd3aa0] [c08295cc] .ahash_done+0x1dc/0x360 [c000fffd3ca0] [c081b7ec] .caam_jr_dequeue+0x26c/0x3a0 [c000fffd3da0] [c08be50c] .net_rx_action+0x1cc/0x330 [c000fffd3e80] [c007276c] .__do_softirq+0x19c/0x3d0 [c000fffd3f90] [c0017054] .call_do_softirq+0x14/0x24 [c000f775ef10] [c0005fe8] .do_softirq+0x118/0x150 sda: sda1 sda2 sda3 [c000f775efa0] [c0072c54] .irq_exit+0x124/0x140 [c000f775f020] [c0005ac4] .do_IRQ+0x184/0x370 [c000f775f0d0] [c001b93c] exc_0x500_common+0xfc/0x100 --- Exception: 501 at .rcu_note_context_switch+0x0/0x370 edule+0xbc/0x7f0 [c000f775f3c0] [c0a29944] .__schedule+0xa4/0x7f0 (unreliable) [c000f775f620] [c0a277f4] .schedule_timeout+0x1b4/0x2e0 [c000f775f700] [c0a29428] .wait_for_common+0xf8/0x1d0 [c000f775f7c0] [c0a295ac] .wait_for_completion_interruptible+0x2c/0x50 [c000f775f840] [c0494b64] .do_one_async_hash_op.isra.1.part.2+0x24/0x50 [c000f775f8c0] [c04951a8] .test_hash+0x618/0x7d0 [c000f775fb30] [c0495424] .alg_test_hash+0xc4/0xf0 [c000f775fbc0] [c0494928] .alg_test+0xa8/0x2c0 [c000f775fcb0] [c0491164] .cryptomgr_test+0x64/0x80 [c000f775fd30] [c009a8d0] .kthread+0xf0/0x100 [c000f775fe30] [ca08] .ret_from_kernel_thread+0x5c/0xd4 Instruction dump: 7c641b78 419e0160 e8a90050 2fa5 409e0008 e8a90010 e8de0028 e8fe0030 3c62ff90 38638320 48546b69 6000 0fe0 4b34 e87e0010 2fa3 ---[ end trace 52825d316d569f00 ]--- Signed-off-by: Yanjiang Jin yanjiang@windriver.com --- drivers/crypto/caam/caamhash.c | 18 +- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index f6ad322..a6ba9f7 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c @@ -451,7 +451,7 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, const u8 *key_in, dma_addr_t src_dma, dst_dma; int ret = 0; - desc = kmalloc(CAAM_CMD_SZ * 8 + CAAM_PTR_SZ * 2, GFP_KERNEL | GFP_DMA); + desc = kzalloc(CAAM_CMD_SZ * 8 + CAAM_PTR_SZ * 2, GFP_KERNEL | GFP_DMA); if (!desc) { dev_err(jrdev, unable to allocate key input memory\n); return -ENOMEM; @@ -815,7 +815,7 @@ static int ahash_update_ctx(struct ahash_request *req) * allocate space for base edesc and hw desc commands, * link tables */ - edesc = kmalloc(sizeof(struct ahash_edesc) + DESC_JOB_IO_LEN + + edesc = kzalloc(sizeof(struct ahash_edesc) + DESC_JOB_IO_LEN + sec4_sg_bytes, GFP_DMA | flags); if (!edesc) { dev_err(jrdev, @@ -926,7 +926,7 @@ static int ahash_final_ctx(struct ahash_request *req) sec4_sg_bytes = (1 + (buflen ? 1 : 0)) * sizeof(struct sec4_sg_entry); /* allocate space for base edesc and hw desc commands, link tables */ - edesc = kmalloc(sizeof(struct ahash_edesc) + DESC_JOB_IO_LEN + + edesc = kzalloc(sizeof(struct ahash_edesc) + DESC_JOB_IO_LEN + sec4_sg_bytes, GFP_DMA | flags); if (!edesc) { dev_err(jrdev, could not allocate extended descriptor\n); @@ -1013,7 +1013,7 @@ static int ahash_finup_ctx(struct ahash_request *req)