From patchwork Wed Apr 11 15:22:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru-Cosmin Gheorghe X-Patchwork-Id: 10335685 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D0DC06053B for ; Wed, 11 Apr 2018 15:23:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C4AAA2897C for ; Wed, 11 Apr 2018 15:23:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9AC528980; Wed, 11 Apr 2018 15:23:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 631162897C for ; Wed, 11 Apr 2018 15:23:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4E3EC6E68B; Wed, 11 Apr 2018 15:23:11 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20040.outbound.protection.outlook.com [40.107.2.40]) by gabe.freedesktop.org (Postfix) with ESMTPS id 17E386E68A for ; Wed, 11 Apr 2018 15:23:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=2zJxVSw2MPVM55R/wOX2dAbtYIbtXvmkJ3ixo+Plvz4=; b=FMyeEcR2uNHvWKA79V2hT6Cp82RcDJiy6Scqu6jeLfAymduf7roDRUyFckDe8NBx83sO9CNXTGwBLQ+w955isSwvt57oiTinaeHjOIkjgr0T+FP2qtuh8cybgsKVD0vsOHbDiJ6tMvyKqq5NyhhpDdPvr1OhyAOaEQGeYFrmVvU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Alexandru-Cosmin.Gheorghe@arm.com; Received: from e114479-lin.cambridge.arm.com (217.140.96.140) by AM5PR0801MB1249.eurprd08.prod.outlook.com (2603:10a6:203:1e::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.675.10; Wed, 11 Apr 2018 15:23:06 +0000 From: Alexandru Gheorghe To: dri-devel@lists.freedesktop.org, liviu.dudau@arm.com, brian.starkey@arm.com, ayan.halder@arm.com, seanpaul@chromium.org Subject: [PATCH hwc v2 02/18] drm_hwcomposer: vsyncworker: Fix deadlock on exit path Date: Wed, 11 Apr 2018 16:22:13 +0100 Message-Id: <1523460149-1740-3-git-send-email-alexandru-cosmin.gheorghe@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523460149-1740-1-git-send-email-alexandru-cosmin.gheorghe@arm.com> References: <1523460149-1740-1-git-send-email-alexandru-cosmin.gheorghe@arm.com> MIME-Version: 1.0 X-Originating-IP: [217.140.96.140] X-ClientProxiedBy: VI1PR0701CA0066.eurprd07.prod.outlook.com (2603:10a6:800:5f::28) To AM5PR0801MB1249.eurprd08.prod.outlook.com (2603:10a6:203:1e::8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603328)(7153060)(7193020); SRVR:AM5PR0801MB1249; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1249; 3:5ObXt/yKrwKhAFLZyhH8KpcLSmLDfvjOtv0z9ySKUXwEZpMGo8U2btxHdw60nPUm1rVeAvkZqTI7FAas/+N9IeVVtpzZJ0J5fKPNDUbCh2s1fIezQjhvIBksHO1TtxSBqVUIp+ctvOybFaQIgiOOeBlObzZzFYDvKgeJDzivo7LMKd4ScVACZ+nFdb7t6T5PmpTa3H7AiA73akHtElOw5iqo6igDhJI+lp1GOVzHgav7O6ELJ67AZiGy1cKJlvlc; 25:b2oVc1grlwPCUdCxyAntwcxw6FYECjY/4XX3COXyWENMhjrh63XCf7t2MSyzlWhWT4wvphAL1kEnD+W4MMpG49MOfjV/iGPANQtEn8K5UQKCX9D9uf7XR2l3SggdPva1pJYNQV1Fdom8r6i73lZtJgXYm/SiSaj+6rNDAvNs2JMTBBuhMrjWRiqXlah9YDe0OQMj+73I7wzjZs80TR9dRY80cPqETSzAtrQnNj4KdDEMdVqJ55GI1jrQqQ7CXgx4thfoz9tnLM9yCSARuZKvWSTNaCb2Fyj3AzHD5MBqWydBqpmCtAVr6KeqR5cHIfV8jh2aCgU1y6Va6O92osg0CQ==; 31:PwvlIlsgW/LkKFKrr3aAWUUaSAnZig4Ac+a9ZDl6vRB4pPEczu7AzA3kAFMHMYv4DzcK39kYRimjUJq8Ny3vY0b1BCQeGLTl8ABwZxE5an6wWoOJIhB/2JXwa5NofH6+48d4Qhwok78fwY2WXyqLGWdae6MxpyD+vciydPK+FN6i4knEmFN+7nUUDXt/uCoTWN3m/2vybmXWvndiP50UC9rZNqQRd12Wxrpimw5AMsM= X-MS-TrafficTypeDiagnostic: AM5PR0801MB1249: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1249; 20:gxgEONMyeOPNq94uoenvv0zAO4g18uezJIluNvJt2dLZsaRlCvFPXQiQBTe66LuQIpu8/8J/wxYaSCWNxxMXz9tzgHpR+QzLexKm5PHOcpmuJnKUl6nYBLUfi38XFxbE5WfnhiG7y9BUSLIhKsJePu5d6tXKl7e6zpxh+oMv7gk=; 4:6+NL0Y7aYXcnCtKse149d/ZjVatzcZqtLumAIfpaKg0QjbYRGai49hHxuiW5EVST2LDYOIACir/TeEKXUWagfPqDx89dpAZgByL3/cekQMayidDyXnrKXo5Q6hOHd/LIrpkjSEelecqfd2w+LIdVQ9rqw3PAFc7xsd7gtBp6cfLxL9rQ5qr1MozEVvq9WvNFxYBtjSvD1qM9AuUzWphLiw+fqJ/QG4URUOyqRFGZoQ9w1BYqqltsMyhMkMwHO3DO9IymbDist7P7qfuqMuAzDgLh3ldzTB9fW97QY7qK2G9rjMR1luzIyFTDx2xWXmOo X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231221)(944501327)(52105095)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(6072148)(201708071742011); SRVR:AM5PR0801MB1249; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0801MB1249; X-Forefront-PRVS: 0639027A9E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39380400002)(346002)(396003)(376002)(366004)(39860400002)(189003)(199004)(16526019)(478600001)(305945005)(50226002)(575784001)(16586007)(68736007)(7736002)(86362001)(81156014)(8676002)(316002)(81166006)(4326008)(25786009)(2906002)(50466002)(8936002)(6486002)(105586002)(48376002)(186003)(956004)(5660300001)(6666003)(72206003)(106356001)(476003)(53936002)(3846002)(76176011)(51416003)(52116002)(47776003)(7696005)(36756003)(66066001)(11346002)(446003)(386003)(97736004)(59450400001)(6116002)(2616005)(26005)(486006); DIR:OUT; SFP:1101; SCL:1; SRVR:AM5PR0801MB1249; H:e114479-lin.cambridge.arm.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM5PR0801MB1249; 23:gUT+V8XztMKwlAWl83dc4ojOtiAQRq/PABke8U1?= =?us-ascii?Q?QUywGcQjeH/0Mwy958Onhw4FyMLwHFfya7wRH9ya+q7SE2D3X7YhAKvD+7PX?= =?us-ascii?Q?EVD0RWZ3LEJeV9eIIXxFVTXuzFSC2Nh/XxucgmNzCD2/LCProuTjF+RV8dSf?= =?us-ascii?Q?MvNlD3INKq0sLyW8hoOF07+8psriBdZE5LaHOP+NJcLQyVBcWLjCZCYTl6RP?= =?us-ascii?Q?DIJT9sUhceW5a3NmeuDbci9lFLAM9GYDTOseSlmtujpAVyHUXgIYJa9b4mwz?= =?us-ascii?Q?LLpxH3cD6KwCUp+IRXzoAWttnMJCzkLZDdBRbQM+5b0EGxf3zUMBHm4HUdQR?= =?us-ascii?Q?lPXgnnBwP2vnNL2P9ZwCDSp2v/7brqyKxgjyBksDdWqYPaJ0AFAsdMZrm31n?= =?us-ascii?Q?bwNxbG6qK1/MwPvgG1QzMRebA72QJDDBkgVx61xHSVgHy3ghT/mJ2DuqmL7q?= =?us-ascii?Q?jHZJDa7+b0MjEC7HA7mGlX+i9ZBQm23l4yOby4gqhThR8GLzhlFoYQubX+38?= =?us-ascii?Q?ZcpzCGypfEgJjSi/2oPmp3W5qjvxw+JCO9VX/ZR0QGDVn07MQM+oGeGh/kkf?= =?us-ascii?Q?Vy56aY4o2bVMZnjMr77eAE+GBHvTNV6CWs/UPzickn/6PwLjx6CDzyykEWtK?= =?us-ascii?Q?czbjs5egbY0SAYxrUALCtKd36ZW7oxtBnT24W5TVmXg2tJ01IH3pxg1G2Prv?= =?us-ascii?Q?PB8tYDgfeBxAWzachu8/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ZlS3EqZk76yed44kQStgPrbu6UFES1DdabXpTyovzr7WyyUbm83Tm/cG/jvK7pgOCFAJS3RmcGZ8IAKXljPcJ+R7FvBVYXke5OUZBH91eDF+2WEKkNVIA0Aec6M2tkdIDcP9Gj/ax95yerY5N2I5/QUAQTIiJSMJxtaW152UoPYVqsa02CJ96eTgokGdwHiHdeCLRfrX+xJijC41DHhb1nt9aatGneQbdr9N5P1/s/czGHAu5zaaaD6ThZy9kd4ZmIFA==; 5:8NdEAazEnwmHYkgw5porRy504UC1PTQP1Ph+INQjFnHooymy2AUtEj3XHNrFfgRnjyForse13OIyp6SQaWOPGP2bYQaYWPVKpvejlC9Zgj8qw/T0wtcO87WHXm3rneT9me8BAfruCTQIXAO88BLZmPKpy9+EgDQFkOuiX5IX0N0=; 24:VsC31HSiHhlOK8wB/KQYdLjoFYRx+rxpsHGGn2iB3DqsCvjRg6JJPpqaFKmpJuH6Z9nXcDx769cP3oRORnTS6bD330IcclcoCjTYtuP3pfs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1249; 7:6uez1cE7+veVa8a6Qy4Q4XpIcqKClCWNG10FoyQPoo70MBszG+DjTnv0Dhl5Hz5YGXveCW1370wxd3Y6jFFzjC9XNv5RPfRC/FbnnQytIZXqU7XHL5oRikZYIMSMPxZgeZEROnaWlqtxINccvPnRxozGQmW/w+xSokTK1ocmrBVI7LKAQYpKDSL5OnDQs/Q/Ht/VUjItLomMFy61vhq3+Iz8JsmbrMfUzo9HAI9bObg3ASfyn0W765Ei1kX0iIzB X-MS-Office365-Filtering-Correlation-Id: 9010bc07-c87d-4034-b4a2-08d59fc02039 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2018 15:23:06.1099 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9010bc07-c87d-4034-b4a2-08d59fc02039 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1249 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nd@arm.com, Alexandru Gheorghe Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP vsyncworker::Routine assumes that when -EINTR is returned by WaitForSignalOrExitLocked the lock as been released, which is not true, so it hangs if a vsyncworker is never enabled and Exit is called. There are two code paths in WaitForSignalOrExitLocked that return -EINTR, one releases the lock the other doesn't. Looking at the clients of WaitForSignalOrExitLocked all assume the lock is still held, except vsyncworker::Routine. So, the proper fix needs two changes: - Make WaitForSignalOrExitLocked consistent and always hold the lock when exiting. - Release lock in vsynworker::Routine on all code paths. Signed-off-by: Alexandru Gheorghe Signed-off-by: Robert Foss --- vsyncworker.cpp | 1 + worker.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/vsyncworker.cpp b/vsyncworker.cpp index 3bfe4be..7c0c741 100644 --- a/vsyncworker.cpp +++ b/vsyncworker.cpp @@ -120,6 +120,7 @@ void VSyncWorker::Routine() { if (!enabled_) { ret = WaitForSignalOrExitLocked(); if (ret == -EINTR) { + Unlock(); return; } } diff --git a/worker.cpp b/worker.cpp index da6c580..5b351e0 100644 --- a/worker.cpp +++ b/worker.cpp @@ -66,13 +66,13 @@ int Worker::WaitForSignalOrExitLocked(int64_t max_nanoseconds) { ret = -ETIMEDOUT; } + // release leaves mutex locked when going out of scope + lk.release(); + // exit takes precedence on timeout if (should_exit()) ret = -EINTR; - // release leaves mutex locked when going out of scope - lk.release(); - return ret; }