Return-Path: Received: from mail-sn1nam01on0132.outbound.protection.outlook.com ([104.47.32.132]:20800 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933677AbeCCWfA (ORCPT ); Sat, 3 Mar 2018 17:35:00 -0500 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Kieran Bingham , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 140/219] [media] v4l: vsp1: Prevent multiple streamon race commencing pipeline early Date: Sat, 3 Mar 2018 22:29:17 +0000 Message-ID: <20180303222716.26640-140-alexander.levin@microsoft.com> References: <20180303222716.26640-1-alexander.levin@microsoft.com> In-Reply-To: <20180303222716.26640-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Kieran Bingham [ Upstream commit 4461c84b52b4a952c657505ef7e4e06b016783df ] With multiple inputs through the BRU it is feasible for the streams to race each other at stream-on. Multiple VIDIOC_STREAMON calls racing each other could have process N-1 skipping over the pipeline setup section and then start the pipeline early, if videobuf2 has already enqueued buffers to the driver for process N but not called the .start_streaming() operation yet In the case of the video pipelines, this can present two serious issues. 1) A null-dereference if the pipe->dl is committed at the same time as the vsp1_video_setup_pipeline() is processing 2) A hardware hang, where a display list is committed without having called vsp1_video_setup_pipeline() first Repair this issue, by ensuring that only the stream which configures the pipeline is able to start it. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/platform/vsp1/vsp1_video.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platf= orm/vsp1/vsp1_video.c index d351b9c768d2..743aa0febc09 100644 --- a/drivers/media/platform/vsp1/vsp1_video.c +++ b/drivers/media/platform/vsp1/vsp1_video.c @@ -792,6 +792,7 @@ static int vsp1_video_start_streaming(struct vb2_queue = *vq, unsigned int count) { struct vsp1_video *video =3D vb2_get_drv_priv(vq); struct vsp1_pipeline *pipe =3D video->rwpf->pipe; + bool start_pipeline =3D false; unsigned long flags; int ret; =20 @@ -802,11 +803,23 @@ static int vsp1_video_start_streaming(struct vb2_queu= e *vq, unsigned int count) mutex_unlock(&pipe->lock); return ret; } + + start_pipeline =3D true; } =20 pipe->stream_count++; mutex_unlock(&pipe->lock); =20 + /* + * vsp1_pipeline_ready() is not sufficient to establish that all streams + * are prepared and the pipeline is configured, as multiple streams + * can race through streamon with buffers already queued; Therefore we + * don't even attempt to start the pipeline until the last stream has + * called through here. + */ + if (!start_pipeline) + return 0; + spin_lock_irqsave(&pipe->irqlock, flags); if (vsp1_pipeline_ready(pipe)) vsp1_video_pipeline_run(pipe); --=20 2.14.1