Repository navigation
Closed
Description
Describe the bug
The latest version of 5.10 kernel crashing when using OMX JPEG encoding and TC358743 with 720p video source resolution.
To reproduce
Take TC358743 and ustreamer.
git clone https://github.com/pikvm/ustreamer
cd ustreamer
make WITH_OMX=1
Add cma=128M to cmdline.txt and gpu_mem=256 to config.txt and try this command:
ustreamer --encoder=omx --dv-timings --persistent -m uyvy
You will see the crash.
System
Raspberry Pi 4 B+ 4G- Arch Linux ARM / PiKVM OS
vcgencmd version:Nov 2 2021 13:22:15 Copyright (c) 2012 Broadcom version e50fe24ee2b6974f3ba6615ba0f1d8f45c485f69 (clean) (release) (start)Linux pikvm 5.10.76-4-raspberrypi4-ARCH #1 SMP Fri Nov 5 08:11:58 MSK 2021 armv7l GNU/Linux
Logs
OOPS 1
[ 853.623484] ------------[ cut here ]------------
[ 853.628118] kernel BUG at kernel/dma/mapping.c:208!
[ 853.633006] Internal error: Oops - BUG: 0 [#1] SMP ARM
Entering kdb (current=0xc3823c00, pid 1113) on processor 0 Oops: (null)
due to oops @ 0xc02a4f2c
CPU: 0 PID: 1113 Comm: ILCS_HOST Tainted: G C 5.10.76-4-raspberrypi4-ARCH #1
Hardware name: BCM2711
PC is at dma_unmap_sg_attrs+0x40/0x44
LR is at 0x0
pc : [<c02a4f2c>] lr : [<00000000>] psr: 20080013
sp : c48c9d64 ip : 00000080 fp : 00000000
r10: 000000fc r9 : 00000000 r8 : 00000000
r7 : 00000000 r6 : 00000006 r5 : c1a530f4 r4 : f0e2d0c8
r3 : 10801080 r2 : 10801080 r1 : 10801080 r0 : c1e69a10
Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
Control: 30c5383d Table: 04139c00 DAC: fffffffd
CPU: 0 PID: 1113 Comm: ILCS_HOST Tainted: G C 5.10.76-4-raspberrypi4-ARCH #1
Hardware name: BCM2711
[<c020f0d8>] (unwind_backtrace) from [<c020ae58>] (show_stack+0x10/0x14)
[<c020ae58>] (show_stack) from [<c0e08748>] (dump_stack+0xa4/0xc4)
[<c0e08748>] (dump_stack) from [<c0301eec>] (kdb_main_loop+0x4bc/0x9a0)
[<c0301eec>] (kdb_main_loop) from [<c0304fa0>] (kdb_stub+0x258/0x458)
[<c0304fa0>] (kdb_stub) from [<c02f9ff4>] (kgdb_cpu_enter+0x3e0/0x6fc)
more> ^M[<c02f9ff4>] (kgdb_cpu_enter) from [<c02fa9b4>] (kgdb_handle_exception+0xe0/0x13c)
more> ^M[<c02fa9b4>] (kgdb_handle_exception) from [<c020e794>] (kgdb_notify+0x28/0x48)
more> ^M[<c020e794>] (kgdb_notify) from [<c02503bc>] (notify_die+0x90/0xd0)
more> ^M[<c02503bc>] (notify_die) from [<c020af8c>] (die+0x130/0x34c)
more> ^M[<c020af8c>] (die) from [<c0200b94>] (__und_svc_finish+0x0/0x2c)
more> ^MException stack(0xc48c9cd0 to 0xc48c9d18)
more> ^M9cc0: c1e69a10 10801080 10801080 10801080
more> ^M9ce0: f0e2d0c8 c1a530f4 00000006 00000000 00000000 00000000 000000fc 00000000
more> ^M9d00: 00000080 c48c9d64 00000000 c02a4f2c 20080013 ffffffff
more> ^M[<c0200b94>] (__und_svc_finish) from [<c02a4f2c>] (dma_unmap_sg_attrs+0x40/0x44)
more> ^M[<c02a4f2c>] (dma_unmap_sg_attrs) from [<c0c6509c>] (cleanup_pagelistinfo+0x98/0xb4)
more> ^M[<c0c6509c>] (cleanup_pagelistinfo) from [<c0c656c0>] (vchiq_prepare_bulk_data+0x190/0x6dc)
more> ^M[<c0c656c0>] (vchiq_prepare_bulk_data) from [<c0c5f0e4>] (vchiq_bulk_transfer+0x258/0x3e4)
more> ^M[<c0c5f0e4>] (vchiq_bulk_transfer) from [<c0c63530>] (vchiq_ioctl+0x724/0x17fc)
more> ^M[<c0c63530>] (vchiq_ioctl) from [<c044b198>] (sys_ioctl+0x34c/0x904)
more> ^M[<c044b198>] (sys_ioctl) from [<c0200040>] (ret_fast_syscall+0x0/0x4c)
more> ^MException stack(0xc48c9fa8 to 0xc48c9ff0)
more> ^M9fa0: b6b4b538 afefab1c 00000009 c014c406 afefab1c 000b900e
more> ^M9fc0: b6b4b538 afefab1c ac4ba020 00000036 00000000 3f155c40 ae504ce0 00000000
more> ^M9fe0: b6b4b240 afefab0c b6b38f44 b6c609fc
more> ^M
more> ^M[0]kdb>
OOPS 2
[ 145.337313] ------------[ cut here ]------------
[ 145.341993] kernel BUG at include/linux/scatterlist.h:95!
[ 145.347427] Internal error: Oops - BUG: 0 [#1] SMP ARM
Entering kdb (current=0xc3c1da00, pid 755) on processor 0 Oops: (null)
due to oops @ 0xc0c65774
CPU: 0 PID: 755 Comm: ILCS_HOST Tainted: G C 5.10.76-4-raspberrypi4-ARCH #1
Hardware name: BCM2711
PC is at vchiq_prepare_bulk_data+0x244/0x6dc
LR is at 0x0
pc : [<c0c65774>] lr : [<00000000>] psr: 00080013
sp : c4699d90 ip : 00000001 fp : c1934378
r10: 000006dc r9 : 00000003 r8 : 00033700
r7 : f0e570e0 r6 : 00000035 r5 : f0e571b0 r4 : 00000035
r3 : 00001000 r2 : f0e571c8 r1 : 00000000 r0 : 3b713b9f
Flags: nzcv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
Control: 30c5383d Table: 03bb43c0 DAC: fffffffd
CPU: 0 PID: 755 Comm: ILCS_HOST Tainted: G C 5.10.76-4-raspberrypi4-ARCH #1
Hardware name: BCM2711
[<c020f0d8>] (unwind_backtrace) from [<c020ae58>] (show_stack+0x10/0x14)
[<c020ae58>] (show_stack) from [<c0e08748>] (dump_stack+0xa4/0xc4)
[<c0e08748>] (dump_stack) from [<c0301eec>] (kdb_main_loop+0x4bc/0x9a0)
[<c0301eec>] (kdb_main_loop) from [<c0304fa0>] (kdb_stub+0x258/0x458)
[<c0304fa0>] (kdb_stub) from [<c02f9ff4>] (kgdb_cpu_enter+0x3e0/0x6fc)
more> ^M[<c02f9ff4>] (kgdb_cpu_enter) from [<c02fa9b4>] (kgdb_handle_exception+0xe0/0x13c)
more> ^M[<c02fa9b4>] (kgdb_handle_exception) from [<c020e794>] (kgdb_notify+0x28/0x48)
more> ^M[<c020e794>] (kgdb_notify) from [<c02503bc>] (notify_die+0x90/0xd0)
more> ^M[<c02503bc>] (notify_die) from [<c020af8c>] (die+0x130/0x34c)
more> ^M[<c020af8c>] (die) from [<c0200b94>] (__und_svc_finish+0x0/0x2c)
more> ^MException stack(0xc4699d00 to 0xc4699d48)
more> ^M9d00: 3b713b9f 00000000 f0e571c8 00001000 00000035 f0e571b0 00000035 f0e570e0
more> ^M9d20: 00033700 00000003 000006dc c1934378 00000001 c4699d90 00000000 c0c65774
more> ^M9d40: 00080013 ffffffff
more> ^M[<c0200b94>] (__und_svc_finish) from [<c0c65774>] (vchiq_prepare_bulk_data+0x244/0x6dc)
more> ^M[<c0c65774>] (vchiq_prepare_bulk_data) from [<c0c5f0e4>] (vchiq_bulk_transfer+0x258/0x3e4)
more> ^M[<c0c5f0e4>] (vchiq_bulk_transfer) from [<c0c63530>] (vchiq_ioctl+0x724/0x17fc)
more> ^M[<c0c63530>] (vchiq_ioctl) from [<c044b198>] (sys_ioctl+0x34c/0x904)
more> ^M[<c044b198>] (sys_ioctl) from [<c0200040>] (ret_fast_syscall+0x0/0x4c)
more> ^MException stack(0xc4699fa8 to 0xc4699ff0)
more> ^M9fa0: b6b4c538 afefab1c 00000009 c014c406 afefab1c 0002a00e
more> ^M9fc0: b6b4c538 afefab1c ad2ff020 00000036 00000000 3f155be0 ae504c70 00000000
more> ^M9fe0: b6b4c240 afefab0c b6b39f44 b6c619fc
more> ^M
more> ^M[0]kdb>
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]Oops with vchiq_prepare_bulk_data / DMA[/-][+]Oops with vchiq_prepare_bulk_data (tc358743 + OMX JPEG encoder)[/+]mdevaev commentedon Nov 5, 2021
I have updated the description and localized the problem. It occurs when we try to use OMX JPEG encoding when capturing video from TC358743.
pelwell commentedon Nov 5, 2021
The crash logs suggest the failures are the consequences of memory corruption.
mdevaev commentedon Nov 5, 2021
It doesn't show up on 5.10.52, maybe it's some new bug? On the new kernel, failure occurs 100% of the time when using OMX.
6by9 commentedon Nov 5, 2021
Tripped when encoding JPEG with ustreamer
vcdbg log assert shows:
Kernel oops
Edit: Firmware looks to have died, but hasn't flushed the cache so
vcdbg log msgtail end is corrupted.pelwell commentedon Nov 5, 2021
Yep - that looks like (black) pixel data in a place where no pixel data should be.
6by9 commentedon Nov 5, 2021
Rebuilt my kernel at 2a29770 (5.10.77) and top of tree firmware (with a few local mods). Crashed.
Reset my firmware back ("17 and 10 different commits each, respectively", top commit from origin is bcdfe55d5). I'll bisect it.
6by9 commentedon Nov 5, 2021
Working at 1920x1080 seems to trigger things more frequently. (I was using 1280x720 before).
I've just had a
logged as well, which has also killed everything.
What I thought was working with 5.10.77 and my old firmware does fail at 1080p.
I'm reverting back to the firmware from 5.10.52, but one thought I do have is that the buffers allocated by bcm2835-unicam and consumed by the H264 encoder do NOT have to be aligned to a multiple of 16 lines, whilst the IL JPEG DOES need 16 line alignment. It's not that you're asking it to copy more data than is allocated?
Firmware from 5.10.52 has just crashed with the kernel logging
swiotlb buffer is fullagain.pelwell commentedon Nov 5, 2021
sz: -1249856128is more evidence of corruption (0xb580b580), as I suspect is any mention of swiotlb.6by9 commentedon Nov 5, 2021
raspberrypi/rpi-firmware@c59a637 seems to be the first to really trip this, so it would imply something changed with #4641. Slightly odd as that didn't touch memory allocation of buffer usage, but there you go.
mdevaev commentedon Nov 6, 2021
@6by9 I have already encountered alignment problems and spied code in yavta and gstreamer. At least it worked before the update.
mdevaev commentedon Nov 9, 2021
Please let me know if I can help with testing or anything else.
mdevaev commentedon Nov 17, 2021
By the way, how would you like the new V4L2 M2M interface to support JPEG encoding? Since you're throwing away proprietary libraries, it would be great to have a replacement for this feature. My idea was to make /dev/video21 for ril.image_encode. I will be happy to make draft implementation and patch if you are interested in taking this upstream.
I saw that libcamera uses libjpeg to encode images and on the RPi forum I was offered to use encoding on cores, but as you saw, 1080p encoding consumes a huge amount of CPU resources and takes more time, which is a disaster for PiKVM, we really need hardware encoding to keep zero latency.
PS: I'm sorry to ask this here. It's just that if M2M works and is accepted into the RPi upstream, I can forget about the problems of OMX :) Unless the crash described is related to something lower-level and will still require a fix.
6by9 commentedon Nov 17, 2021
The encoder role in bcm2835-codec already supports MJPEG via video_encode.
image_encode messes around with EXIF headers and similar, which are all irrelevant under V4L2 as there are no controls to pass them in. All V4L2 is really after is the basic encoded image, which MJPEG gives you. It also does rate control rather than manually messing with quantisation parameters.
I realise that you were running multiple image_encode components in parallel as feeding in YUYV (or similar) requires a format conversion first, so effectively you were queuing those up. The structure of the MJPEG codec may not give the required performance there, but I couldn't without trying it. There is an optimisation that could be made for MJPEG if it was close.
V4L2 does avoid VCHIQ bulk transfers, so should avoid this issue.
mdevaev commentedon Nov 17, 2021
Thanks for the explanation.
I couldn't get MJPEG from encoder in version 5.10.52, did it appear later? Whatever encoding parameters I used, it still turned out to be H264. v4l2-ctl --list-formats also showed that /dev/video11 supports only H264.
As for the speed - in any case, I'll try and compare. Even if V4L2 is a bit slower, I expect a speed boost (or compensation) due to the possibility of using DMA, since with OMX I couldn't make it work.
50 remaining items
kernel: Bump to 5.10.95
kernel: Bump to 5.10.95
popcornmix commentedon Feb 2, 2022
It's pushed to rpi-update (but that doesn't affect kernel tree).
6by9 commentedon Feb 2, 2022
Added to userland - raspberrypi/userland@8fa944c
Until it's used in the kernel there is little point in adding it there.
mdevaev commentedon Feb 2, 2022
Got it
mdevaev commentedon Feb 3, 2022
@6by9 Something doesn't seem to be working. I fixed my patch to the latest kernel version and installed a new firmware. The return value of changing the IJG param is -3:
MMAL_PARAMETER_JPEG_IJG_SCALING is 0x10061, same as userspace header (checked).
Also tried
&ctx->component->controlwithout any luck.Am I doing something wrong?
verup and ...
mdevaev commentedon Feb 14, 2022
Sup?
6by9 commentedon Feb 18, 2022
I had got the mapping wrong and hadn't passed the port parameter through. Firmware patch being reviewed now.
I've confirmed that the diff to Raspistill
sets the right flag in the firmware, and it is then passed into the encoder.
mdevaev commentedon Feb 18, 2022
Thank you! I will be waiting for the firmware update.
mdevaev commentedon Feb 28, 2022
Any news about it? When will this fix be released?
pelwell commentedon Mar 1, 2022
I'm not sure what the holdup with the firmware is, but there should be a new release today or tomorrow.
pelwell commentedon Mar 1, 2022
rpi-firmware has been bumped -
sudo rpi-updatewill get you a build with 6by9's patch.mdevaev commentedon Mar 1, 2022
It seems it's working now, thank you.
The next question: could you enable image encoder without
start_x=1? You did this for H264, and it is necessary for the image encoder to work out of the box.