From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 585EA37AA97; Wed, 18 Mar 2026 08:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773821893; cv=none; b=b+zIk++qIS5MutiOFg2yhuBv2UcCMZs/1/Ad5UwF0zCxEnkN8Ucda6/rLlBOOSDjAh7ETo+V3JxtILVq0V5kUIHwggNuaBtrS0DRoYg12R2FuZai8fUKMkOLE2IHO6RmWG3yrXGnmdyv85GYZK1pFzV0y3lxqc+qYACMjAoVJQk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773821893; c=relaxed/simple; bh=wFbDTEvR7olB1fWLkOBoDY4V+b8vzKWvYlVrfuh1TQE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=iu/cycCYFRwU+xghfcYT6hIm5JEy10fa2lzHFcFR/Zd+V331ol6U5Y0cQgaqzC7oibGjHR+Xes4Yn+FXDPJ2Psx7UXNqKetAqsEFcF7bo9nFMxU0XYE/caiVaSeFnYQhqUBLIYI0D20Vz7bt8X1oKFeQrezywNrcLPPWs7WBpDo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=rY8+Fq+m; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="rY8+Fq+m" Received: from [192.168.33.40] (185.182.214.153.nat.pool.zt.hu [185.182.214.153]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 703B6379; Wed, 18 Mar 2026 09:16:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1773821816; bh=wFbDTEvR7olB1fWLkOBoDY4V+b8vzKWvYlVrfuh1TQE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=rY8+Fq+maQOcG232S0Bm8lqr4HAUCl0I6PXWBHoTnPp9pKuQzrjXiFnDdqA3HqqSZ 0AW3qpYQz3KhnXGH8iRH+gT0jxOlvjUzpWTHNoRi55PWeDrKA6d14wBazLMW3uBXOZ UIJy7sK35CX/WrqOImTajmeghrVn9qcYEWjm6Mzs= Message-ID: <659d6c70-41d7-4dcf-867f-183d85118c4c@ideasonboard.com> Date: Wed, 18 Mar 2026 09:18:05 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 6/7] media: rzv2h-ivc: Avoid double job scheduling To: Jacopo Mondi , Daniel Scally , Mauro Carvalho Chehab , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Jacopo Mondi , stable@vger.kernel.org References: <20260313-mali-ivc-fixes-v7-0-v1-0-cb0714cd1279@ideasonboard.com> <20260313-mali-ivc-fixes-v7-0-v1-6-cb0714cd1279@ideasonboard.com> From: =?UTF-8?Q?Barnab=C3=A1s_P=C5=91cze?= Content-Language: en-US, hu-HU In-Reply-To: <20260313-mali-ivc-fixes-v7-0-v1-6-cb0714cd1279@ideasonboard.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 2026. 03. 13. 12:14 keltezéssel, Jacopo Mondi írta: > From: Jacopo Mondi > > 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 > --- Looks ok to me. Reviewed-by: Barnabás Pőcze > 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); > } > } >