Skip to content

Commit

Permalink
LF-6212: mxc: vpu_malone: avoid kernel panic in alloc_dma_buffer
Browse files Browse the repository at this point in the history
The call trace show the kernel panic occurs
in memset_io.
Seems dma_alloc_coherent() return an error code on fail instead of NULL.

So we use the IS_ERR_OR_NULL to check the return value.

But it's strangely as the document has described
the function dma_alloc_coherent returns a pointer to
the allocated region (in the processor's virtual address space)
or NULL if the allocation failed.

2022-05-24T04:06:15 [  745.193344] Unable to handle kernel paging request at virtual address ffffffffffffffe8
2022-05-24T04:06:15 [  745.201296] Mem abort info:
2022-05-24T04:06:15 [  745.204101]   ESR = 0x86000004
2022-05-24T04:06:15 [  745.207161]   EC = 0x21: IABT (current EL), IL = 32 bits
2022-05-24T04:06:15 [  745.212503]   SET = 0, FnV = 0
2022-05-24T04:06:15 [  745.215596]   EA = 0, S1PTW = 0
2022-05-24T04:06:15 [  745.218740]   FSC = 0x04: level 0 translation fault
2022-05-24T04:06:15 [  745.224070] swapper pgtable: 4k pages, 48-bit VAs, pgdp=0000000081b03000
2022-05-24T04:06:15 [  745.231018] [ffffffffffffffe8] pgd=0000000000000000, p4d=0000000000000000
2022-05-24T04:06:15 [  745.237851] Internal error: Oops: 86000004 [#1] PREEMPT SMP
2022-05-24T04:06:16 [  745.287814] Hardware name: Freescale i.MX8QM MEK (DT)
2022-05-24T04:06:16 [  745.292862] pstate: 80000005 (Nzcv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
2022-05-24T04:06:16 [  745.299819] pc : 0xffffffffffffffe8
2022-05-24T04:06:16 [  745.303303] lr : alloc_dma_buffer+0x5c/0xdc
2022-05-24T04:06:16 [  745.307499] sp : ffff80001686ba50
2022-05-24T04:06:16 [  745.310809] x29: ffff80001686ba50 x28: ffff00081e934008 x27: 0000000000000000
2022-05-24T04:06:16 [  745.317950] x26: ffff00081e934680 x25: ffff00081e934900 x24: ffff00081e935000
2022-05-24T04:06:16 [  745.325091] x23: ffff800009d3b5b0 x22: ffff0008197d9800 x21: fffffffffffff9b0
2022-05-24T04:06:16 [  745.332233] x20: ffff00081e934000 x19: ffff00081e935db0 x18: 0000000000000000
2022-05-24T04:06:16 [  745.339374] x17: 0000000000002000 x16: fffffc00010fffc8 x15: 0000000000000001
2022-05-24T04:06:16 [  745.346515] x14: 0000000000000002 x13: 00000000000c5a87 x12: ffff0008ff4458c0
2022-05-24T04:06:16 [  745.353656] x11: ffff0008f95f9668 x10: fffffc0020453a08 x9 : 0000000000000000
2022-05-24T04:06:16 [  745.360797] x8 : ffff80001c8be000 x7 : 0000000000000000 x6 : 000000000000003f
2022-05-24T04:06:16 [  745.367938] x5 : 0000000000000040 x4 : 0000000000000000 x3 : ffff80001c8be000
2022-05-24T04:06:16 [  745.375079] x2 : 0000000000c00000 x1 : 0000000000000000 x0 : ffff80001c5ef198
2022-05-24T04:06:16 [  745.382221] Call trace:
2022-05-24T04:06:16 [  745.384662]  0xffffffffffffffe8
2022-05-24T04:06:16 [  745.387798]  vpu_buf_queue+0x314/0x580
2022-05-24T04:06:16 [  745.391551]  __enqueue_in_driver+0x3c/0x6c
2022-05-24T04:06:16 [  745.395651]  vb2_core_qbuf+0x44c/0x5a0
2022-05-24T04:06:16 [  745.399396]  vb2_qbuf+0x94/0xf0
2022-05-24T04:06:16 [  745.402532]  v4l2_ioctl_qbuf+0x1a4/0x29c
2022-05-24T04:06:16 [  745.406450]  v4l_qbuf+0x48/0x60
2022-05-24T04:06:16 [  745.409586]  __video_do_ioctl+0x178/0x3dc
2022-05-24T04:06:16 [  745.413591]  video_usercopy+0x374/0x6a0
2022-05-24T04:06:16 [  745.417422]  video_ioctl2+0x18/0x24
2022-05-24T04:06:16 [  745.420906]  v4l2_ioctl+0x44/0x64
2022-05-24T04:06:16 [  745.424216]  __arm64_sys_ioctl+0xa8/0xf0
2022-05-24T04:06:16 [  745.428142]  invoke_syscall+0x48/0x114
2022-05-24T04:06:16 [  745.431895]  el0_svc_common.constprop.0+0xd4/0xfc
2022-05-24T04:06:16 [  745.436595]  do_el0_svc+0x28/0x90
2022-05-24T04:06:16 [  745.439905]  el0_svc+0x34/0xb0
2022-05-24T04:06:16 [  745.442955]  el0t_64_sync_handler+0xa4/0x130
2022-05-24T04:06:16 [  745.447220]  el0t_64_sync+0x18c/0x190
2022-05-24T04:06:16 [  745.450884] Code: bad PC value
2022-05-24T04:06:16 [  745.453940] ---[ end trace 0000000000000000 ]---
2022-05-24T04:06:16 [  745.458550] Kernel panic - not syncing: Oops: Fatal exception
2022-05-24T04:06:16 [  745.464292] SMP: stopping secondary CPUs

Signed-off-by: Ming Qian <[email protected]>
Reviewed-by: Zhou Peng <[email protected]>
  • Loading branch information
mingqian-0 committed Jul 12, 2022
1 parent baec80b commit 1ce081b
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions drivers/mxc/vpu_malone/vpu_b0.c
Original file line number Diff line number Diff line change
Expand Up @@ -1452,14 +1452,13 @@ static int alloc_dma_buffer(struct vpu_ctx *ctx, struct dma_buffer *buffer)
(dma_addr_t *)&buffer->dma_phy,
GFP_KERNEL | GFP_DMA32 | __GFP_NOWARN);

if (!buffer->dma_virt) {
if (IS_ERR_OR_NULL(buffer->dma_virt)) {
vpu_err("error: %s() dma buffer alloc size(%x) fail!\n",
__func__, buffer->dma_size);
vpu_dec_event_decode_error(ctx);
return -ENOMEM;
}

memset_io(buffer->dma_virt, 0, buffer->dma_size);
atomic64_add(buffer->dma_size, &ctx->statistic.total_dma_size);
return 0;
}
Expand Down

0 comments on commit 1ce081b

Please sign in to comment.