mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Barnabás Pőcze" <barnabas.pocze@ideasonboard.com>
To: Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
	Daniel Scally <dan.scally@ideasonboard.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil+cisco@kernel.org>
Cc: linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH 6/7] media: rzv2h-ivc: Avoid double job scheduling
Date: Wed, 18 Mar 2026 09:18:05 +0100	[thread overview]
Message-ID: <659d6c70-41d7-4dcf-867f-183d85118c4c@ideasonboard.com> (raw)
In-Reply-To: <20260313-mali-ivc-fixes-v7-0-v1-6-cb0714cd1279@ideasonboard.com>

2026. 03. 13. 12:14 keltezéssel, Jacopo Mondi írta:
> From: Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com>
> 
> The scheduling of a new buffer transfer in the IVC driver is triggered
> by two occurrences of the "frame completed" interrupt.
> 
> The first interrupt occurrence identifies when all image data have been
> transferred to the ISP, the second occurrence identifies when the
> post-transfer VBLANK has completed and a new buffer can be transferred.
> 
> Under heavy system load conditions the actual execution of the workqueue
> item might be delayed and two items might happen to run concurrently,
> leading to a new frame transfer being triggered while the previous one
> has not yet finished.
> 
> This error condition is only visible because the driver maintains a
> status variable that counts the number of interrupts since the last
> transfer, and warns in case an IRQ happens before the counter has been
> reset.
> 
> To ensure sequential execution of the worqueue items and avoid a double
> buffer transfer to run concurrently, protect the whole function body
> with the spinlock that so far was solely used to reset the counter and
> inspect the interrupt counter variable at the beginning of the buffer
> transfer function.
> and return
> 
> As soon as the ongoing transfer completes, the workqueue item will be
> re-scheduled and will consume the pending buffer.
> 
> Cc: stable@vger.kernel.org
> Fixes: f0b3984d821b ("media: platform: Add Renesas Input Video Control block driver")
> Signed-off-by: Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com>
> ---

Looks ok to me.

Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>


>   drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-video.c | 11 +++++++----
>   1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-video.c b/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-video.c
> index a22aee0fe1cf..3580a57738a6 100644
> --- a/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-video.c
> +++ b/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-video.c
> @@ -149,6 +149,11 @@ static void rzv2h_ivc_transfer_buffer(struct work_struct *work)
>   					     buffers.work);
>   	struct rzv2h_ivc_buf *buf;
>   
> +	guard(spinlock_irqsave)(&ivc->spinlock);
> +
> +	if (ivc->vvalid_ifp)
> +		return;
> +
>   	/* Setup buffers */
>   	scoped_guard(spinlock_irqsave, &ivc->buffers.lock) {
>   		buf = list_first_entry_or_null(&ivc->buffers.queue,
> @@ -163,9 +168,7 @@ static void rzv2h_ivc_transfer_buffer(struct work_struct *work)
>   	buf->addr = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
>   	rzv2h_ivc_write(ivc, RZV2H_IVC_REG_AXIRX_SADDL_P0, buf->addr);
>   
> -	scoped_guard(spinlock_irqsave, &ivc->spinlock) {
> -		ivc->vvalid_ifp = 2;
> -	}
> +	ivc->vvalid_ifp = 2;
>   	rzv2h_ivc_write(ivc, RZV2H_IVC_REG_FM_FRCON, 0x1);
>   }
>   
> @@ -200,7 +203,7 @@ static void rzv2h_ivc_buf_queue(struct vb2_buffer *vb)
>   	}
>   
>   	scoped_guard(spinlock_irq, &ivc->spinlock) {
> -		if (vb2_is_streaming(vb->vb2_queue) && !ivc->vvalid_ifp)
> +		if (vb2_is_streaming(vb->vb2_queue))
>   			queue_work(ivc->buffers.async_wq, &ivc->buffers.work);
>   	}
>   }
> 


  parent reply	other threads:[~2026-03-18  8:18 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-13 11:13 [PATCH 0/7] media: renesas: rzv2h-ivc: Fix concurrent " Jacopo Mondi
2026-03-13 11:13 ` [PATCH 1/7] media: rzv2h-ivc: Revise default VBLANK formula Jacopo Mondi
2026-03-13 11:13 ` [PATCH 2/7] media: rzv2h-ivc: Fix AXIRX_VBLANK register write Jacopo Mondi
2026-03-13 16:15   ` Dan Scally
2026-03-18  8:24   ` Barnabás Pőcze
2026-03-13 11:13 ` [PATCH 3/7] media: rzv2h-ivc: Write AXIRX_PIXFMT once Jacopo Mondi
2026-03-13 16:07   ` Dan Scally
2026-03-13 16:12     ` Jacopo Mondi
2026-03-13 16:14       ` Dan Scally
2026-03-13 11:14 ` [PATCH 4/7] media: rzv2h-ivc: Fix FM_STOP register write Jacopo Mondi
2026-03-13 20:39   ` Dan Scally
2026-03-13 11:14 ` [PATCH 5/7] media: rzv2h-ivc: Fix concurrent buffer list access Jacopo Mondi
2026-03-13 22:11   ` Dan Scally
2026-03-13 11:14 ` [PATCH 6/7] media: rzv2h-ivc: Avoid double job scheduling Jacopo Mondi
2026-03-18  8:00   ` Dan Scally
2026-03-18  8:18   ` Barnabás Pőcze [this message]
2026-03-13 11:14 ` [PATCH 7/7] media: rzv2h-ivc: Replace workqueue with direct function call Jacopo Mondi
2026-03-13 22:42   ` Dan Scally
2026-03-20 17:16 ` [PATCH 0/7] media: renesas: rzv2h-ivc: Fix concurrent job scheduling Lad, Prabhakar

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=659d6c70-41d7-4dcf-867f-183d85118c4c@ideasonboard.com \
    --to=barnabas.pocze@ideasonboard.com \
    --cc=dan.scally@ideasonboard.com \
    --cc=hverkuil+cisco@kernel.org \
    --cc=jacopo.mondi+renesas@ideasonboard.com \
    --cc=jacopo.mondi@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=stable@vger.kernel.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

all inboxes | Powered by JetHome®