Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 59F323939B0 for ; Wed, 20 May 2026 07:49:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779263368; cv=none; b=Vp4WnMBK1dXhCoAv0/RG73dO71c0E6U80ujH0ToOh/wll3bCia/eltpndMsjA6aFFdKIlEBbbehGexxJhvTQ2PQO7Qgy1DUI1arj4o6ixcDvCZNoSdxbXved4ii3/jcJzGG3ph5n2cVDIkFrl/UGwmISeA6SPwy5MasNQYzvBpo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779263368; c=relaxed/simple; bh=R3tEzodXKSrAB+eiYSjQm3IqiVbKxmfbbFpyekfJXFU=; h=Message-ID:Date:MIME-Version:From:Subject:To:References: In-Reply-To:Content-Type; b=bKOX7TZXVFa85rf+lG4y3STyVaOcdzYSxvl8DAJ7poiAbBPpOOG1yY+xncOMS1QIcRndsvbbb1+t1oXB4QZF1caOhEDxN9WfiS9AqvIIX4CAdeMptN3y8bd318kCnSK2Ad0j//89cvxlwUyS5VYJzRau6ZF2pZsOmgzSH8/ypSw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U1LyZ4Ra; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U1LyZ4Ra" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 740B61F000E9; Wed, 20 May 2026 07:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779263367; bh=2likVQFqclSauMfAgaKFfGfD+F4dE7LTH1cJEl8pEAY=; h=Date:From:Subject:To:References:In-Reply-To; b=U1LyZ4RaGvsb82Y2SO0m7QF7uesQoaIIIz+GDzeV2KZgZrWeKU+gfvVodwg2c1vaP d9X+4dUw5xjwOsFOeklLzkOQc1valQFkFhsKJ7IMCRHQnnNO7b7VMgi+LTnPEEva10 fwFX7oBKscHfuJ27Mt1XdUcPvs619GXqdh2nrqOPhFKgSrvuTd9iPWp9LsQRA/vBKF 4HyTdtcDrc95NIuvVM/vxV7vyDisrYpyD0+sqQNhUkvG5CUEX9vEVl7QrZKbu9qOHT WdjWgfIwEWN61wsME1DtTrsS2nrI9btkmCrnxZawIEOl27bgZffuGKnVYulPO2Jh0T oWL1kldxuxHTA== Message-ID: Date: Wed, 20 May 2026 09:49:24 +0200 Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Hans Verkuil Subject: Re: [PATCH] media: vivid: check vb2_is_busy before calling vivid_update_format_cap/out To: Nicolas Dufresne , Linux Media Mailing List References: <3016ee7c-9a4f-4fcf-b17f-0dce5bbc9260@kernel.org> <67cd61cb2dd1988f3ccc93e7eb1eff42014ce830.camel@ndufresne.ca> <655cfcf9-d015-49d3-886b-1c4a38553aab@kernel.org> Content-Language: en-US, nl In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 19/05/2026 21:29, Nicolas Dufresne wrote: > Le mardi 19 mai 2026 à 15:30 +0200, Hans Verkuil a écrit : >> On 13/05/2026 16:59, Nicolas Dufresne wrote: >>> Le mercredi 13 mai 2026 à 10:52 +0200, Hans Verkuil a écrit : >>>> The vivid_update_format_cap/out() functions must only be called if the >>>> capture/output queue are not busy. But for several controls that is not >>>> checked. >>>> >>>> Only when streaming starts will they be set to 'grabbed' and it is >>>> impossible to change the control, but between REQBUFS and STREAMON you >>>> are still allowed to set these controls. Since vivid_update_format_cap/out >>>> will change the format, this can cause unexpected results. >>>> >>>> I suspect that this is the cause of this syzbot bug: >>>> >>>> https://syzkaller.appspot.com/bug?extid=dac8f5eaa46837e97b89 >>>> >>>> But since we never have reproducers, it is hard to be certain. In any case, >>>> these checks are needed regardless. >>>> >>>> Reported-by: syzbot+dac8f5eaa46837e97b89@syzkaller.appspotmail.com >>>> Signed-off-by: Hans Verkuil >>>> --- >>>> diff --git a/drivers/media/test-drivers/vivid/vivid-ctrls.c >>>> b/drivers/media/test-drivers/vivid/vivid-ctrls.c >>>> index f94c15ff84f7..e40ff999cad8 100644 >>>> --- a/drivers/media/test-drivers/vivid/vivid-ctrls.c >>>> +++ b/drivers/media/test-drivers/vivid/vivid-ctrls.c >>>> @@ -608,18 +608,26 @@ static int vivid_vid_cap_s_ctrl(struct v4l2_ctrl *ctrl) >>>>   tpg_s_vflip(&dev->tpg, dev->sensor_vflip ^ dev->vflip); >>>>   break; >>>>   case VIVID_CID_REDUCED_FPS: >>>> + if (vb2_is_busy(&dev->vb_vid_cap_q)) >>>> + return -EBUSY; >>> >>> It is unclear to me why users need to free all the buffers to enable this >>> feature.  Should that one only be limited to not being streaming ? I believe it >>> will only affect the HDMI DV Timings and the frame internal in params right ? >> >> The problem is that vivid_update_format_cap() resets the format, as you expect >> when changing input or standard, or timing. >> >> This control implies a new timing, so that's why vivid_update_format_cap >> is called. And that requires the is_busy check. > > I did check again, and the timing is only changed if !vb2_is_busy(). That > matched my first impression that the vivid_update_format_cap() just copy over > the same information without actually changing it. > >> >> It could be implemented differently, but then this control shouldn't use >> vivid_update_format_cap(). > > It would be much more elegant to separate the changes from each other yes. At > separate between what affects the v4l2_fmt (memory allocation) and what doesn't. > Also because its very error prone to trust vivid_update_format_cap() to not have > any side effects. >> >> It's something for another time, for now I want to be consistent in always >> checking vb2_is_busy before vivid_update_format_cap can be called. > > Please add some sort of comment, so future visitors knows this code is > illogically tied together. I decided to make a v2, changing REDUCED_FPS to not need vivid_update_format_cap anymore. Regards, Hans > > Reviewed-by: Nicolas Dufresne > > Nicolas > >> >> Regards, >> >> Hans >> >>> >>>>   dev->reduced_fps = ctrl->val; >>>>   vivid_update_format_cap(dev, true); >>>>   break; >>>>   case VIVID_CID_HAS_CROP_CAP: >>>> + if (vb2_is_busy(&dev->vb_vid_cap_q)) >>>> + return -EBUSY; >>>>   dev->has_crop_cap = ctrl->val; >>>>   vivid_update_format_cap(dev, true); >>>>   break; >>>>   case VIVID_CID_HAS_COMPOSE_CAP: >>>> + if (vb2_is_busy(&dev->vb_vid_cap_q)) >>>> + return -EBUSY; >>>>   dev->has_compose_cap = ctrl->val; >>>>   vivid_update_format_cap(dev, true); >>>>   break; >>>>   case VIVID_CID_HAS_SCALER_CAP: >>>> + if (vb2_is_busy(&dev->vb_vid_cap_q)) >>>> + return -EBUSY; >>>>   dev->has_scaler_cap = ctrl->val; >>>>   vivid_update_format_cap(dev, true); >>>>   break; >>>> @@ -1116,14 +1124,20 @@ static int vivid_vid_out_s_ctrl(struct v4l2_ctrl >>>> *ctrl) >>>> >>>>   switch (ctrl->id) { >>>>   case VIVID_CID_HAS_CROP_OUT: >>>> + if (vb2_is_busy(&dev->vb_vid_out_q)) >>>> + return -EBUSY; >>>>   dev->has_crop_out = ctrl->val; >>>>   vivid_update_format_out(dev); >>>>   break; >>>>   case VIVID_CID_HAS_COMPOSE_OUT: >>>> + if (vb2_is_busy(&dev->vb_vid_out_q)) >>>> + return -EBUSY; >>>>   dev->has_compose_out = ctrl->val; >>>>   vivid_update_format_out(dev); >>>>   break; >>>>   case VIVID_CID_HAS_SCALER_OUT: >>>> + if (vb2_is_busy(&dev->vb_vid_out_q)) >>>> + return -EBUSY; >>>>   dev->has_scaler_out = ctrl->val; >>>>   vivid_update_format_out(dev); >>>>   break;