From: Benjamin Gaignard <benjamin.gaignard@collabora.com>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com,
ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar,
p.zabel@pengutronix.de, gregkh@linuxfoundation.org,
nicolas.dufresne@collabora.com
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
linux-arm-msm@vger.kernel.org,
linux-rockchip@lists.infradead.org,
linux-staging@lists.linux.dev, kernel@collabora.com
Subject: Re: [PATCH v7 45/49] media: core: Add bitmap manage bufs array entries
Date: Thu, 21 Sep 2023 15:07:05 +0200 [thread overview]
Message-ID: <bf659f27-1669-86b8-df30-f1e7f9ecf371@collabora.com> (raw)
In-Reply-To: <c8b7db47-3875-a10b-8d81-a0b3dcbc564a@collabora.com>
Le 21/09/2023 à 14:46, Benjamin Gaignard a écrit :
>
> Le 21/09/2023 à 14:13, Hans Verkuil a écrit :
>> On 21/09/2023 14:05, Benjamin Gaignard wrote:
>>> Le 21/09/2023 à 12:24, Hans Verkuil a écrit :
>>>> On 21/09/2023 11:28, Benjamin Gaignard wrote:
>>>>> Le 20/09/2023 à 16:56, Hans Verkuil a écrit :
>>>>>> On 20/09/2023 16:30, Benjamin Gaignard wrote:
>>>>>> <snip>
>>>>>>
>>>>>>>>> num_buffers = min_t(unsigned int, num_buffers,
>>>>>>>>> q->max_allowed_buffers -
>>>>>>>>> vb2_get_num_buffers(q));
>>>>>>>>> - first_index = vb2_get_num_buffers(q);
>>>>>>>>> + first_index = bitmap_find_next_zero_area(q->bufs_map,
>>>>>>>>> q->max_allowed_buffers,
>>>>>>>>> + 0, num_buffers, 0);
>>>>>>>>> if (first_index >= q->max_allowed_buffers)
>>>>>>>>> return 0;
>>>>>>>>> @@ -675,7 +678,13 @@ static void __vb2_queue_free(struct
>>>>>>>>> vb2_queue *q, unsigned int buffers)
>>>>>>>>> struct vb2_buffer *vb2_get_buffer(struct vb2_queue *q,
>>>>>>>>> unsigned int index)
>>>>>>>>> {
>>>>>>>>> - if (index < q->num_buffers)
>>>>>>>>> + if (!q->bufs_map || !q->bufs)
>>>>>>>>> + return NULL;
>>>>>>>> I don't think this can ever happen.
>>>>>>> I got kernel crash without them.
>>>>>>> I will keep them.
>>>>>> What is the backtrace? How can this happen? It feels wrong that
>>>>>> this can be
>>>>>> called with a vb2_queue that apparently is not properly initialized.
>>>>> I have this log when adding dump_stack() in vb2_get_buffer() if
>>>>> !q->bufs_bitmap:
>>>>>
>>>>> [ 18.924627] Call trace:
>>>>> [ 18.927090] dump_backtrace+0x94/0xec
>>>>> [ 18.930787] show_stack+0x18/0x24
>>>>> [ 18.934137] dump_stack_lvl+0x48/0x60
>>>>> [ 18.937833] dump_stack+0x18/0x24
>>>>> [ 18.941166] __vb2_queue_cancel+0x23c/0x2f0
>>>>> [ 18.945365] vb2_core_queue_release+0x24/0x6c
>>>>> [ 18.949740] vb2_queue_release+0x10/0x1c
>>>>> [ 18.953677] v4l2_m2m_ctx_release+0x20/0x40
>>>>> [ 18.957892] hantro_release+0x20/0x54
>>>>> [ 18.961584] v4l2_release+0x74/0xec
>>>>> [ 18.965110] __fput+0xb4/0x274
>>>>> [ 18.968205] __fput_sync+0x50/0x5c
>>>>> [ 18.971626] __arm64_sys_close+0x38/0x7c
>>>>> [ 18.975562] invoke_syscall+0x48/0x114
>>>>> [ 18.979329] el0_svc_common.constprop.0+0xc0/0xe0
>>>>> [ 18.984068] do_el0_svc+0x1c/0x28
>>>>> [ 18.987402] el0_svc+0x40/0xe8
>>>>> [ 18.990470] el0t_64_sync_handler+0x100/0x12c
>>>>> [ 18.994842] el0t_64_sync+0x190/0x194
>>>>>
>>>>> This happen at boot time when hantro driver is open and close
>>>>> without other actions.
>>>> Ah, now I see the problem. q->bufs and q->bufs_map are allocated in
>>>> vb2_core_create_bufs and vb2_core_reqbufs, but they should be
>>>> allocated
>>>> in vb2_queue_init: that's the counterpart of vb2_core_queue_release.
Hans,
I think we are doing loops in your comment :-)
https://patchwork.kernel.org/comment/25496456/
Regards,
Benjamin
>>>>
>>>> With that change you shouldn't have to check for q->bufs/bufs_map
>>>> anymore.
>>> It is a better solution but even like this vb2_core_queue_release()
>>> is called
>>> at least 2 times on the same vivid queue and without testing
>>> q->bufs_bitmap
>>> makes kernel crash.
>> Do you have a stacktrace for that? Perhaps vb2_core_queue_release
>> should check
>> for q->bufs/q->bufs_map and return if those are NULL. But it could
>> also be a
>> bug that it is called twice, it just was never noticed because it was
>> harmless
>> before.
>
> I have added some printk to log that when running test-media on vivid:
>
> [ 130.497426] vb2_core_queue_init queue cap-0000000050d195ab allocate
> q->bufs 00000000dc2c15ed and q->bufs_bitmap 000000008173fc5a
> ...
> [ 130.733967] vb2_core_queue_release queue cap-0000000050d195ab
> release q->bufs and q->bufs_bitmap
> [ 133.866345] vb2_get_buffer queue cap-0000000050d195ab
> q->bufs_bitmap is NULL
> [ 133.873454] CPU: 1 PID: 321 Comm: v4l2-ctl Not tainted 6.6.0-rc1+ #542
> [ 133.879997] Hardware name: NXP i.MX8MQ EVK (DT)
> [ 133.884536] Call trace:
> [ 133.886988] dump_backtrace+0x94/0xec
> [ 133.890673] show_stack+0x18/0x24
> [ 133.894002] dump_stack_lvl+0x48/0x60
> [ 133.897681] dump_stack+0x18/0x24
> [ 133.901009] __vb2_queue_cancel+0x250/0x31c
> [ 133.905209] vb2_core_queue_release+0x24/0x88
> [ 133.909580] _vb2_fop_release+0xb0/0xbc
> [ 133.913428] vb2_fop_release+0x2c/0x58
> [ 133.917187] vivid_fop_release+0x80/0x388 [vivid]
> [ 133.921948] v4l2_release+0x74/0xec
> [ 133.925452] __fput+0xb4/0x274
> [ 133.928520] __fput_sync+0x50/0x5c
> [ 133.931934] __arm64_sys_close+0x38/0x7c
> [ 133.935868] invoke_syscall+0x48/0x114
> [ 133.939630] el0_svc_common.constprop.0+0x40/0xe0
> [ 133.944349] do_el0_svc+0x1c/0x28
> [ 133.947677] el0_svc+0x40/0xe8
> [ 133.950741] el0t_64_sync_handler+0x100/0x12c
> [ 133.955109] el0t_64_sync+0x190/0x194
>
> and later I have a call to reqbufs on the same queue without call to
> vb2_core_queue_init before
>
> [ 58.696812] __vb2_queue_alloc queue cap-
> 0000000050d195abq->bufs_bitmap is NULL
> [ 58.704148] CPU: 1 PID: 319 Comm: v4l2-compliance Not tainted
> 6.6.0-rc1+ #544
> [ 58.711291] Hardware name: NXP i.MX8MQ EVK (DT)
> [ 58.715826] Call trace:
> [ 58.718274] dump_backtrace+0x94/0xec
> [ 58.721951] show_stack+0x18/0x24
> [ 58.725274] dump_stack_lvl+0x48/0x60
> [ 58.728946] dump_stack+0x18/0x24
> [ 58.732268] __vb2_queue_alloc+0x4a8/0x50c
> [ 58.736374] vb2_core_reqbufs+0x274/0x46c
> [ 58.740391] vb2_ioctl_reqbufs+0xb0/0xe8
> [ 58.744320] vidioc_reqbufs+0x50/0x64 [vivid]
> [ 58.748717] v4l_reqbufs+0x50/0x64
> [ 58.752125] __video_do_ioctl+0x164/0x3c8
> [ 58.756140] video_usercopy+0x200/0x668
> [ 58.759982] video_ioctl2+0x18/0x28
> [ 58.763475] v4l2_ioctl+0x40/0x60
> [ 58.766798] __arm64_sys_ioctl+0xac/0xf0
> [ 58.770730] invoke_syscall+0x48/0x114
> [ 58.774487] el0_svc_common.constprop.0+0x40/0xe0
> [ 58.779199] do_el0_svc+0x1c/0x28
> [ 58.782520] el0_svc+0x40/0xe8
> [ 58.785580] el0t_64_sync_handler+0x100/0x12c
> [ 58.789942] el0t_64_sync+0x190/0x194
>
>>
>> Regards,
>>
>> Hans
>>
>>>> Regards,
>>>>
>>>> Hans
>>>>
>>>>>>>>> +
>>>>>>>>> + return (bitmap_weight(q->bufs_map,
>>>>>>>>> q->max_allowed_buffers) > 0);
>>>>>>>> How about:
>>>>>>>>
>>>>>>>> return vb2_get_num_buffers(q) > 0;
>>>>>>> vb2_get_num_buffers is defined in videobuf2-core.c, I'm not sure
>>>>>>> that
>>>>>>> an inline function could depend of a module function.
>>>>>> Not a problem. E.g. v4l2-ctrls.h is full of such static inlines.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Hans
>>>>>>
>>
next prev parent reply other threads:[~2023-09-21 13:07 UTC|newest]
Thread overview: 98+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-14 13:32 [PATCH v7 00/49] Add DELETE_BUF ioctl Benjamin Gaignard
2023-09-14 13:32 ` [PATCH v7 01/49] media: videobuf2: Rework offset 'cookie' encoding pattern Benjamin Gaignard
2023-09-19 9:15 ` Hans Verkuil
2023-09-14 13:32 ` [PATCH v7 02/49] media: videobuf2: Stop spamming kernel log with all queue counter Benjamin Gaignard
2023-09-19 9:22 ` Hans Verkuil
2023-09-14 13:32 ` [PATCH v7 03/49] media: videobuf2: Use vb2_buffer instead of index Benjamin Gaignard
2023-09-14 13:32 ` [PATCH v7 04/49] media: amphion: Use vb2_get_buffer() instead of directly access to buffers array Benjamin Gaignard
2023-09-14 13:32 ` [PATCH v7 05/49] media: mediatek: jpeg: " Benjamin Gaignard
2023-09-14 13:32 ` [PATCH v7 06/49] media: mediatek: vdec: " Benjamin Gaignard
2023-09-19 9:37 ` Hans Verkuil
2023-09-14 13:32 ` [PATCH v7 07/49] media: sti: hva: " Benjamin Gaignard
2023-09-19 9:31 ` Hans Verkuil
2023-09-19 10:26 ` Benjamin Gaignard
2023-09-19 11:20 ` Hans Verkuil
2023-09-14 13:32 ` [PATCH v7 08/49] media: visl: " Benjamin Gaignard
2023-09-14 13:32 ` [PATCH v7 09/49] media: atomisp: " Benjamin Gaignard
2023-09-19 9:41 ` Hans Verkuil
2023-09-14 13:32 ` [PATCH v7 10/49] media: dvb-core: " Benjamin Gaignard
2023-09-14 13:32 ` [PATCH v7 11/49] media: videobuf2: Access vb2_queue bufs array through helper functions Benjamin Gaignard
2023-09-19 10:33 ` Hans Verkuil
2023-09-14 13:32 ` [PATCH v7 12/49] media: videobuf2: Be more flexible on the number of queue stored buffers Benjamin Gaignard
2023-09-19 10:55 ` Hans Verkuil
2023-09-19 12:42 ` Hans Verkuil
2023-09-20 8:56 ` Hans Verkuil
2023-09-14 13:32 ` [PATCH v7 13/49] media: verisilicon: Refactor postprocessor to store more buffers Benjamin Gaignard
2023-09-19 10:57 ` Hans Verkuil
2023-09-14 13:32 ` [PATCH v7 14/49] media: verisilicon: Store chroma and motion vectors offset Benjamin Gaignard
2023-09-14 13:32 ` [PATCH v7 15/49] media: verisilicon: g2: Use common helpers to compute chroma and mv offsets Benjamin Gaignard
2023-09-14 13:32 ` [PATCH v7 16/49] media: verisilicon: postproc: Fix down scale test Benjamin Gaignard
2023-09-19 11:16 ` Hans Verkuil
2023-09-20 7:44 ` Benjamin Gaignard
2023-09-14 13:32 ` [PATCH v7 17/49] media: verisilicon: vp9: Allow to change resolution while streaming Benjamin Gaignard
2023-09-14 13:32 ` [PATCH v7 18/49] media: Remove duplicated index vs q->num_buffers check Benjamin Gaignard
2023-09-19 12:21 ` Hans Verkuil
2023-09-14 13:32 ` [PATCH v7 19/49] media: core: Add helper to get queue number of buffers Benjamin Gaignard
2023-09-14 13:32 ` [PATCH v7 20/49] media: core: Rework how create_buf index returned value is computed Benjamin Gaignard
2023-09-19 12:34 ` Hans Verkuil
2023-09-19 14:50 ` Hans Verkuil
2023-09-14 13:32 ` [PATCH v7 21/49] media: dvb: Stop direct calls to queue num_buffers field Benjamin Gaignard
2023-09-19 13:40 ` Hans Verkuil
2023-09-14 13:32 ` [PATCH v7 22/49] media: i2c: " Benjamin Gaignard
2023-09-19 9:27 ` Hans Verkuil
2023-09-19 13:42 ` Hans Verkuil
2023-09-14 13:32 ` [PATCH v7 23/49] media: pci: cx18: " Benjamin Gaignard
2023-09-19 13:42 ` Hans Verkuil
2023-09-14 13:32 ` [PATCH v7 24/49] media: pci: dt3155: " Benjamin Gaignard
2023-09-19 13:43 ` Hans Verkuil
2023-09-14 13:32 ` [PATCH v7 25/49] media: pci: netup_unidvb: " Benjamin Gaignard
2023-09-19 13:52 ` Hans Verkuil
2023-09-14 13:33 ` [PATCH v7 26/49] media: pci: tw68: " Benjamin Gaignard
2023-09-19 13:56 ` Hans Verkuil
2023-09-14 13:33 ` [PATCH v7 27/49] media: pci: tw686x: " Benjamin Gaignard
2023-09-19 13:57 ` Hans Verkuil
2023-09-14 13:33 ` [PATCH v7 28/49] media: amphion: " Benjamin Gaignard
2023-09-14 13:33 ` [PATCH v7 29/49] media: coda: " Benjamin Gaignard
2023-09-14 13:33 ` [PATCH v7 30/49] media: mediatek: vcodec: " Benjamin Gaignard
2023-09-14 13:33 ` [PATCH v7 31/49] media: nxp: " Benjamin Gaignard
2023-09-14 13:33 ` [PATCH v7 32/49] media: renesas: " Benjamin Gaignard
2023-09-19 14:05 ` Hans Verkuil
2023-09-14 13:33 ` [PATCH v7 33/49] media: sti: hva: " Benjamin Gaignard
2023-09-14 13:33 ` [PATCH v7 34/49] media: ti: " Benjamin Gaignard
2023-09-19 14:10 ` Hans Verkuil
2023-09-14 13:33 ` [PATCH v7 35/49] media: verisilicon: " Benjamin Gaignard
2023-09-14 13:33 ` [PATCH v7 36/49] media: test-drivers: " Benjamin Gaignard
2023-09-19 14:15 ` Hans Verkuil
2023-09-14 13:33 ` [PATCH v7 37/49] media: usb: airspy: " Benjamin Gaignard
2023-09-19 14:16 ` Hans Verkuil
2023-09-14 13:33 ` [PATCH v7 38/49] media: usb: cx231xx: " Benjamin Gaignard
2023-09-19 14:19 ` Hans Verkuil
2023-09-14 13:33 ` [PATCH v7 39/49] media: usb: hackrf: " Benjamin Gaignard
2023-09-19 14:20 ` Hans Verkuil
2023-09-14 13:33 ` [PATCH v7 40/49] media: usb: usbtv: " Benjamin Gaignard
2023-09-19 14:21 ` Hans Verkuil
2023-09-14 13:33 ` [PATCH v7 41/49] media: atomisp: " Benjamin Gaignard
2023-09-14 13:33 ` [PATCH v7 42/49] media: imx: " Benjamin Gaignard
2023-09-14 13:33 ` [PATCH v7 43/49] media: meson: vdec: " Benjamin Gaignard
2023-09-14 13:33 ` [PATCH v7 44/49] media: cedrus: " Benjamin Gaignard
2023-09-19 14:26 ` Hans Verkuil
2023-09-14 13:33 ` [PATCH v7 45/49] media: core: Add bitmap manage bufs array entries Benjamin Gaignard
2023-09-15 0:47 ` kernel test robot
2023-09-15 13:02 ` Benjamin Gaignard
2023-09-19 15:00 ` Hans Verkuil
2023-09-20 14:30 ` Benjamin Gaignard
2023-09-20 14:56 ` Hans Verkuil
2023-09-20 15:17 ` Benjamin Gaignard
2023-09-21 9:28 ` Benjamin Gaignard
2023-09-21 10:24 ` Hans Verkuil
2023-09-21 12:05 ` Benjamin Gaignard
2023-09-21 12:13 ` Hans Verkuil
2023-09-21 12:46 ` Benjamin Gaignard
2023-09-21 13:07 ` Benjamin Gaignard [this message]
2023-09-21 13:48 ` Hans Verkuil
2023-09-14 13:33 ` [PATCH v7 46/49] media: core: Free range of buffers Benjamin Gaignard
2023-09-19 15:09 ` Hans Verkuil
2023-09-14 13:33 ` [PATCH v7 47/49] media: v4l2: Add DELETE_BUFS ioctl Benjamin Gaignard
2023-09-19 15:14 ` Hans Verkuil
2023-09-14 13:33 ` [PATCH v7 48/49] media: v4l2: Add mem2mem helpers for " Benjamin Gaignard
2023-09-14 13:33 ` [PATCH v7 49/49] media: test-drivers: Use helper " Benjamin Gaignard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bf659f27-1669-86b8-df30-f1e7f9ecf371@collabora.com \
--to=benjamin.gaignard@collabora.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=gregkh@linuxfoundation.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=kernel@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-staging@lists.linux.dev \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=ming.qian@nxp.com \
--cc=nicolas.dufresne@collabora.com \
--cc=p.zabel@pengutronix.de \
--cc=tfiga@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox