Received: by 10.223.185.116 with SMTP id b49csp1104823wrg; Sat, 3 Mar 2018 15:42:02 -0800 (PST) X-Google-Smtp-Source: AG47ELu4OcfIHetWnCY/hEcb5y26sj7+euYOlgDb99OhnVcXaAaMUJnnsoKxFvWeE5HuyamjQHCE X-Received: by 2002:a17:902:57c6:: with SMTP id g6-v6mr8884574plj.358.1520120522616; Sat, 03 Mar 2018 15:42:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520120522; cv=none; d=google.com; s=arc-20160816; b=o4q77tvSGyWfk+YYB4g53XOf4bUUmZTVGZMG0XX7JcJ2jtR7xTaP1VOKk4CRofssUZ xBtW9e30FGSp5GrzslX1XzBgyiJqaOomhkqWgNL/W8L+zSTiItTri2rgdSbp6B6mB0gP yF/+ceFuBpDSw/rCggbVW+As81NuIGyppfIs1U+OuZNBE4U1BOs8R4kaGSrYZqOVn243 Q/Ki929VbpCinClG3nkmEStf9ay88cYaW1XRXeobbZL/p6YXsd4JkUdUAWaZHDqff5UL yB3S2WfjY7o0JYebuAAk4lFp7OJhi3uQdMmQ8HBCN8g18lRSixQZmfBc4N29JV+8xvU8 MiMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Ur6i+HZQyI4I/Um0jfqCnKfsg6KcGiehYsSmY8lXabw=; b=rK1Kxua3+w91gRfcPcKLZkXcNBPUsaCi3C+KOhFgbkIpIoyiKS9z6Ff53H/JUqw21y xQaPaOFBotAji5cYxPjdVhqjQ5tOYLh/Eh4pAyA+2TbHtVib4gsnfomZTTeKSoAKP7R1 QJQE3MLbLdBfugJOG8+Da/Znikm4YK8+sKr1v3Gsx1Tc5IFcGli8mNeUx6BJ1elP6V2o f93u2FyL8uoSp0z7AAik6XdLNn/Tgd6Lx4kspgvEnopLqAjVR6rmGkx+jn9FdBqU5eNT /NbPu2CnxROZcVGhRqB1BqwHfOeLiS4JTq+b5jLxOvYWWOasDFCz9PG/AHMNrsGfndYx PPGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=HqfFs3Iv; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x13si6117195pgc.75.2018.03.03.15.41.48; Sat, 03 Mar 2018 15:42:02 -0800 (PST) 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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=HqfFs3Iv; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934318AbeCCWfF (ORCPT + 99 others); Sat, 3 Mar 2018 17:35:05 -0500 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Ur6i+HZQyI4I/Um0jfqCnKfsg6KcGiehYsSmY8lXabw=; b=HqfFs3IvaJUq9eWhVvqgKYVo83I5B2nYxmxXSl+iTGq+1io5jJ+lXlaWsCszm7wrOODrnziuJ42luTbcPBIcD6+8CE0d7CjNCkD2UE/hB0vrg2U8D3KyuIwsFiIaJgmfLo0CAwy1qMeDA7wV2b2PJ0KyGpzapx9sTBIv3aAKupk= Received: from MW2PR2101MB1034.namprd21.prod.outlook.com (52.132.149.10) by MW2PR2101MB0924.namprd21.prod.outlook.com (52.132.152.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.588.3; Sat, 3 Mar 2018 22:34:56 +0000 Received: from MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0]) by MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0%3]) with mapi id 15.20.0567.006; Sat, 3 Mar 2018 22:34:56 +0000 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 Thread-Topic: [PATCH AUTOSEL for 4.9 140/219] [media] v4l: vsp1: Prevent multiple streamon race commencing pipeline early Thread-Index: AQHTsz8RoU7X7hjY4kOELp8+LHy1zg== 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> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MW2PR2101MB0924;6:jVsqxPzDyV7rDX5olPh5SEGZHY8CdhbK9NLrRxCZnIy3mcgvcbzBqUvlYxpdzkfMMi8DH/2oZMvZO/fXqB2diav3XBCkggCqlkt/PNDPf4zdE9oLT9SSBmTQiBOD5SkhiUt3KQSi7BgM4yfhdyI0/bZCCfPDu8z2/1gLxhucXPMvQbDGcCMk6+snjAvKgSbVf1TtkLAGtZ4UjbMlGjb6wa7Bx56t65WXnN2XyZUgB4mkzf9Q/4rKMg6+IuFt+KMfkuvyEcBuSiKOK+i3HwSxH1G+gxUhcTO7U0qhzIqsmburmtGRg3LueyZPLAHUOmqJ+WCSDmkLCZVg87mvPg76Kj/bC123CEf2eYld6fEgKI0=;5:mUbw7+YY3X8lT1NVMlEf/ez3APolVuFJtXknsB0XaWC9clAx8h4VNlZd+xMuyVaUkPHyVZBB3DUCvMNVBllkHTfmGFK8S1uIzwH73JifhK2/JVMa4RnOB9NEzmG67GchTwCydjeqSI1igC87sSOuz7gNGAe/V6/hC4tyUzlN69Q=;24:AmU977Qp45yGMqj6xFK0kbjJapW6PgTOWYot+dL1OZCD5GNKz1Y1rKHohm70L2Hr0VACV3wllBakszO82GNp+vL6veamofBNZESkhi+lR5c=;7:jb9F5CtnM0kD8T/smwXFO+an/ThVfSII+j15pf5scpGzj67E0UN5pjZsV7Ucic18F6oRa6CHQlY6BLk2xzclHU3BPLbPhxWFfb0FMmNIZ/tlBcD9no9nRAmMn3m3v3UwiGMgKqkOdwOv1aMryGvgjQyC9cMoxVIdTrnbLi8DrcVY4Xum6NjFVhD9tYrcN/7EEb4psEYQRMBKsKDFyRCqvH3D/E8dzYPu1pY+ZmVw1W4y3jp7mZRLZRqdRsnzfyyX x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 4c2e1d2c-b625-4a16-32e4-08d58156fd95 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603307)(7193020);SRVR:MW2PR2101MB0924; x-ms-traffictypediagnostic: MW2PR2101MB0924: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231220)(944501244)(52105095)(3002001)(6055026)(61426038)(61427038)(6041288)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:MW2PR2101MB0924;BCL:0;PCL:0;RULEID:;SRVR:MW2PR2101MB0924; x-forefront-prvs: 0600F93FE1 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(376002)(39860400002)(396003)(366004)(39380400002)(189003)(199004)(102836004)(2950100002)(10090500001)(6666003)(316002)(26005)(186003)(25786009)(2900100001)(2906002)(54906003)(22452003)(110136005)(97736004)(6506007)(59450400001)(7736002)(4326008)(305945005)(5250100002)(86362001)(575784001)(2501003)(99286004)(68736007)(72206003)(53936002)(6436002)(6116002)(3846002)(5660300001)(66066001)(1076002)(76176011)(14454004)(36756003)(3660700001)(6486002)(86612001)(81156014)(8676002)(81166006)(10290500003)(6512007)(8936002)(3280700002)(478600001)(107886003)(106356001)(105586002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:MW2PR2101MB0924;H:MW2PR2101MB1034.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4c2e1d2c-b625-4a16-32e4-08d58156fd95 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2018 22:29:17.9163 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR2101MB0924 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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