From: Sultan Alsawaf <sultan@kerneltoast.com>
To: "Du, Bin" <bin.du@amd.com>
Cc: mchehab@kernel.org, hverkuil@xs4all.nl,
laurent.pinchart+renesas@ideasonboard.com,
bryan.odonoghue@linaro.org, sakari.ailus@linux.intel.com,
prabhakar.mahadev-lad.rj@bp.renesas.com,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
pratap.nirujogi@amd.com, benjamin.chan@amd.com, king.li@amd.com,
gjorgji.rosikopulos@amd.com, Phil.Jawich@amd.com,
Dominic.Antony@amd.com, mario.limonciello@amd.com,
richard.gong@amd.com, anson.tsao@amd.com,
Alexey Zagorodnikov <xglooom@gmail.com>
Subject: Re: [PATCH v4 3/7] media: platform: amd: Add isp4 fw and hw interface
Date: Wed, 24 Sep 2025 00:09:39 -0700 [thread overview]
Message-ID: <aNOZM2fj1X9TfZSF@sultan-box> (raw)
In-Reply-To: <df5f52eb-0480-4d59-b930-e8336a993831@amd.com>
On Tue, Sep 23, 2025 at 05:24:11PM +0800, Du, Bin wrote:
> On 9/22/2025 5:55 AM, Sultan Alsawaf wrote:
> > On Thu, Sep 11, 2025 at 06:08:43PM +0800, Bin Du wrote:
> > > + if (!mem_info)
> > > + return NULL;
> > > +
> > > + mem_info->mem_size = mem_size;
> >
> > mem_info->mem_size is not used anywhere, remove it.
> >
>
> Actually, mem_size will be used in following patches in isp4_subdev.c, so,
> i'd like to keep it.
Ah, I didn't notice, my apologies.
> > > + for (i = 0; i < buf_size / sizeof(u32); i++)
> > > + checksum += buffer[i];
> > > +
> > > + surplus_ptr = (u8 *)&buffer[i];
> >
> > Change cast to `(const u32 *)`
> >
>
> Sure, will modify in the next version. I guess you mean `(const u8 *)`
Yes, it should be `(const u8 *)`, apologies for the typo.
> > > +
> > > + guard(mutex)(&ispif->cmdq_mutex);
> > > +
> > > + list_for_each_entry_safe(buf_node, tmp_node, &ispif->cmdq, list) {
> > > + list_del(&buf_node->list);
> > > + kfree(buf_node);
> > > + }
> >
> > Move the whole list to a local LIST_HEAD(free_list) variable and then release
> > the lock. Then you can list_for_each_entry_safe() without needing to do a
> > list_del() every time, and you won't need to hold the lock the whole time.
> >
>
> Thanks for the suggestion, seems that will make code complicated, e.g. this
> is the suggested implementation in my mind if i don't get you wrong,
>
> void isp4if_clear_cmdq(struct isp4_interface *ispif)
> {
> struct isp4if_cmd_element *buf_node;
> struct isp4if_cmd_element *tmp_node;
> LIST_HEAD(free_list);
>
> {
> guard(mutex)(&ispif->cmdq_mutex);
> if (list_empty(&ispif->cmdq))
> return;
> free_list = ispif->cmdq;
> INIT_LIST_HEAD(&ispif->cmdq);
> }
>
> list_for_each_entry_safe(buf_node, tmp_node, &free_list, list) {
> bool quit = false;
>
> if (buf_node->list.next == &ispif->cmdq)
> quit = true;
> kfree(buf_node);
> if (quit)
> return;
> }
> }
> So, I'd like to keep previous implementation by removing list_del and adding
> INIT_LIST_HEAD, so this will be the code after refine,
>
> void isp4if_clear_cmdq(struct isp4_interface *ispif)
> {
> struct isp4if_cmd_element *buf_node;
> struct isp4if_cmd_element *tmp_node;
>
> guard(mutex)(&ispif->cmdq_mutex);
>
> list_for_each_entry_safe(buf_node, tmp_node, &ispif->cmdq, list)
> kfree(buf_node);
> INIT_LIST_HEAD(&ispif->cmdq);
> }
> It's much simpler, and based on our test, for command and buffer queue, the
> elements in the queue won't exceed 5 when run to here, so the lock time will
> be very short. What do you think?
This is what I am thinking (with cmdq_mutex replaced with a spin lock):
void isp4if_clear_cmdq(struct isp4_interface *ispif)
{
struct isp4if_cmd_element *buf_node, *tmp_node;
LIST_HEAD(free_list);
scoped_guard(spinlock, &ispif->cmdq_lock)
list_splice_init(&ispif->cmdq, &free_list);
list_for_each_entry_safe(buf_node, tmp_node, &free_list, list)
kfree(buf_node);
}
> > > + struct isp4if_cmd_element *cmd_ele = NULL;
> > > + struct isp4if_rb_config *rb_config;
> > > + struct device *dev = ispif->dev;
> > > + struct isp4fw_cmd cmd = {};
> >
> > Use memset() to guarantee padding bits of cmd are zeroed, since this may not
> > guarantee it on all compilers.
> >
>
> Sure, will do it in the next version. Just a question, padding bits seem
> never to be used, will it cause any problem if they are not zeroed?
Padding bits, if there are any, are used by isp4if_compute_check_sum() and are
also sent to the firmware.
> > > +
> > > + ret = isp4if_insert_isp_fw_cmd(ispif, stream, &cmd);
> > > + if (ret) {
> > > + dev_err(dev, "fail for insert_isp_fw_cmd camId (0x%08x)\n", cmd_id);
> > > + if (cmd_ele) {
> > > + isp4if_rm_cmd_from_cmdq(ispif, cmd_ele->seq_num, cmd_ele->cmd_id);
> >
> > Using isp4if_rm_cmd_from_cmdq() sort of implies that there is a risk that
> > cmd_ele may have been removed from the list somehow, even though the fw cmd
> > insertion failed? In any case, either make it truly safe by assuming that it's
> > unsafe to dereference cmd_ele right now, or just delete cmd_ele directly from
> > the list under the lock.
> >
>
> Good consideration, so will change it to following in the next version,
> ret = isp4if_insert_isp_fw_cmd(ispif, stream, &cmd);
> if (ret) {
> dev_err(dev, "fail for insert_isp_fw_cmd camId %s(0x%08x)\n",
> isp4dbg_get_cmd_str(cmd_id), cmd_id);
> if (cmd_ele) {
> cmd_ele = isp4if_rm_cmd_from_cmdq(ispif, seq_num, cmd_id);
> kfree(cmd_ele);
> }
> }
> The final cmd_ele to be freed will come from cmdq which will be protected by
> mutex, so it will be safe.
Looks good to me!
> > > +static int isp4if_send_buffer(struct isp4_interface *ispif, struct isp4if_img_buf_info *buf_info)
> > > +{
> > > + struct isp4fw_cmd_send_buffer cmd = {};
> >
> > Use memset() to guarantee padding bits are zeroed, since this may not guarantee
> > it on all compilers.
> >
>
> Sure, will do it in the next version. as mentioned above, padding bits seem
> never to be used, will it cause any problem if they are not zeroed?
Padding bits, if there are any, are used by isp4if_compute_check_sum() and are
also sent to the firmware.
> > > +
> > > + guard(mutex)(&ispif->bufq_mutex);
> > > +
> > > + list_for_each_entry_safe(buf_node, tmp_node, &ispif->bufq, node) {
> > > + list_del(&buf_node->node);
> > > + kfree(buf_node);
> > > + }
> >
> > Move the whole list to a local LIST_HEAD(free_list) variable and then release
> > the lock. Then you can list_for_each_entry_safe() without needing to do a
> > list_del() every time, and you won't need to hold the lock the whole time.
> >
>
> Same comments as above cmdq
This is what I am thinking (with bufq_mutex replaced with a spin lock):
void isp4if_clear_bufq(struct isp4_interface *ispif)
{
struct isp4if_img_buf_node *buf_node, *tmp_node;
LIST_HEAD(free_list);
scoped_guard(spinlock, &ispif->bufq_lock)
list_splice_init(&ispif->bufq, &free_list);
list_for_each_entry_safe(buf_node, tmp_node, &free_list, node)
kfree(buf_node);
}
> > > +struct isp4_interface {
> > > + struct device *dev;
> > > + void __iomem *mmio;
> > > +
> > > + struct mutex cmdq_mutex; /* used for cmdq access */
> > > + struct mutex bufq_mutex; /* used for bufq access */
> >
> > It makes more sense for cmdq_mutex and bufq_mutex to be spin locks since they
> > are only held briefly for list traversal.
> >
>
> I'd like to keep them as mutex, because 1.no sync with hard/soft interrupt
> is needed, 2.Not very time critical 3.Make guard mutex optimization
> possible. What do you think?
For very quick/short critical sections that don't sleep, it makes more sense to
use a spin lock. A mutex lock is heavy when it needs to sleep on contention,
which isn't worth it if the critical section has very few instructions.
Also, guard and scoped_guard are available for spin locks too, as shown in my
replies above.
> > > +
> > > +#endif
> >
> > Add /* _ISP4_INTERFACE_ */
> >
>
> Sure, will add it in the next version and check all header files. BTW, will
> change the macro name to _ISP4_INTERFACE_H_ to align with others
Good catch, sounds good.
Sultan
next prev parent reply other threads:[~2025-09-24 7:09 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-11 10:08 [PATCH v4 0/7] Add AMD ISP4 driver Bin Du
2025-09-11 10:08 ` [PATCH v4 1/7] media: platform: amd: Introduce amd isp4 capture driver Bin Du
2025-09-21 20:23 ` Sultan Alsawaf
2025-09-23 7:56 ` Du, Bin
2025-09-11 10:08 ` [PATCH v4 2/7] media: platform: amd: low level support for isp4 firmware Bin Du
2025-09-21 20:31 ` Sultan Alsawaf
2025-09-23 8:05 ` Du, Bin
2025-09-11 10:08 ` [PATCH v4 3/7] media: platform: amd: Add isp4 fw and hw interface Bin Du
2025-09-21 21:55 ` Sultan Alsawaf
2025-09-23 9:24 ` Du, Bin
2025-09-24 7:09 ` Sultan Alsawaf [this message]
2025-09-25 3:56 ` Du, Bin
2025-09-25 7:20 ` Sultan Alsawaf
2025-09-25 9:42 ` Du, Bin
2025-09-11 10:08 ` [PATCH v4 4/7] media: platform: amd: isp4 subdev and firmware loading handling added Bin Du
2025-09-23 7:23 ` Sultan Alsawaf
2025-09-30 7:30 ` Du, Bin
2025-10-01 7:24 ` Sultan Alsawaf
2025-10-10 10:25 ` Du, Bin
2025-10-11 7:18 ` Sultan Alsawaf
2025-10-11 8:27 ` Du, Bin
2025-09-11 10:08 ` [PATCH v4 5/7] media: platform: amd: isp4 video node and buffers " Bin Du
2025-10-01 6:53 ` Sultan Alsawaf
2025-10-11 9:30 ` Du, Bin
2025-10-12 6:08 ` Sultan Alsawaf
2025-10-13 9:55 ` Du, Bin
2025-10-16 8:13 ` Du, Bin
2025-10-17 8:34 ` Sultan Alsawaf
2025-10-17 9:53 ` Du, Bin
2025-10-19 22:11 ` Sultan Alsawaf
2025-09-11 10:08 ` [PATCH v4 6/7] media: platform: amd: isp4 debug fs logging and more descriptive errors Bin Du
2025-09-11 10:08 ` [PATCH v4 7/7] Documentation: add documentation of AMD isp 4 driver Bin Du
2025-09-19 3:24 ` [PATCH v4 0/7] Add AMD ISP4 driver Du, Bin
2025-09-19 12:23 ` Laurent Pinchart
2025-09-22 2:50 ` Du, Bin
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=aNOZM2fj1X9TfZSF@sultan-box \
--to=sultan@kerneltoast.com \
--cc=Dominic.Antony@amd.com \
--cc=Phil.Jawich@amd.com \
--cc=anson.tsao@amd.com \
--cc=benjamin.chan@amd.com \
--cc=bin.du@amd.com \
--cc=bryan.odonoghue@linaro.org \
--cc=gjorgji.rosikopulos@amd.com \
--cc=hverkuil@xs4all.nl \
--cc=king.li@amd.com \
--cc=laurent.pinchart+renesas@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=mchehab@kernel.org \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=pratap.nirujogi@amd.com \
--cc=richard.gong@amd.com \
--cc=sakari.ailus@linux.intel.com \
--cc=xglooom@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.