Received: by 10.213.65.68 with SMTP id h4csp14009imn; Mon, 19 Mar 2018 17:55:44 -0700 (PDT) X-Google-Smtp-Source: AG47ELtHCZZKih9MVgufgnQMUDStVhnw0w6Y9d35umVbR5H2bY5Ip5UgaDNaZB3aCjmA7eBGumTq X-Received: by 10.101.82.69 with SMTP id q5mr10454005pgp.259.1521507344812; Mon, 19 Mar 2018 17:55:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521507344; cv=none; d=google.com; s=arc-20160816; b=m7n6GEvtvDYqn0QTDHIPYbF/gDS5SXKgJfQ0UVlRu75fz3AwRlENelvUwCjy8uGsdC FBk0GyTB4QQIzJHN160IofgCcEGWU+W38czMq4oimpfArrBmEkL4AEBZYbMsK7cT4R6Q hZHu+WublXmdp9UE9CUfHahQuHr44rJXzynl6y4+LUYEXk1766KIloTbym80LhadIuZZ YzW8bbYnq2eZ9lVLvtn6vfDpOERUuI1vAGXuygyGxJ8FIRJ2v05rfZ6FZU9M2vTFl2Qs B2CPob3jaLeTuatlH1rHp/7Hc2krU5pYoaLyIQ/Z2bsndBeKxlSTM4+j+P0s7/srqwpN AZWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=xKHi4LZWAPYpi0tnVaqCgo55mtRW7IBaleJzm76XlYU=; b=VKPJ6yeht21VpU+lUnE9MNeesvxYzFoaCMV4I2066Vca+EF+JEFyZh3MKbMgNYFjYq 1+nzJ/o429yHXdZFJjK2/I8ADXIRP83BU4Z2vcZE2AuBm8ee6Uul64OgmPJqX04PPaD6 a6KNRNkiPnOnISZCDQsBOOBUQWnWH2Pxn+U4dCzgNhpEu60MCzTm+JybwunBYLHcP5b4 qsg8oZbHbLdXDmIC1LUpGkvkltEHg1q8lQsQaeSBm3aMRQD86J1phDZl1xZOkR4iJWnZ dNUSd0JRCjYfBkQtXBgZ3wR+jnYY6wWNlu5LPM94OwMVOy5r1nDSWDWa+GZVcP3ikWkZ 9SYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c5-v6si475096plo.461.2018.03.19.17.55.29; Mon, 19 Mar 2018 17:55:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S969632AbeCSSYS (ORCPT + 99 others); Mon, 19 Mar 2018 14:24:18 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49686 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031526AbeCSSXz (ORCPT ); Mon, 19 Mar 2018 14:23:55 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id EB081EE7; Mon, 19 Mar 2018 18:23:54 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kieran Bingham , Laurent Pinchart , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.9 133/241] [media] v4l: vsp1: Prevent multiple streamon race commencing pipeline early Date: Mon, 19 Mar 2018 19:06:38 +0100 Message-Id: <20180319180756.700122392@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- drivers/media/platform/vsp1/vsp1_video.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- 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(st { struct vsp1_video *video = vb2_get_drv_priv(vq); struct vsp1_pipeline *pipe = video->rwpf->pipe; + bool start_pipeline = false; unsigned long flags; int ret; @@ -802,11 +803,23 @@ static int vsp1_video_start_streaming(st mutex_unlock(&pipe->lock); return ret; } + + start_pipeline = true; } pipe->stream_count++; mutex_unlock(&pipe->lock); + /* + * 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);