From patchwork Wed Dec 13 08:57:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 10109521 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 A4D4A602C2 for ; Wed, 13 Dec 2017 08:58:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9998228BEF for ; Wed, 13 Dec 2017 08:58:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E0CE28BF5; Wed, 13 Dec 2017 08:58:11 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2E74728BEF for ; Wed, 13 Dec 2017 08:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: Message-id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:List-Owner; bh=NOcCaKUB/w4yPPjmEPmhp2H6ZiNX9bqBj1XqIGATDOw=; b=sY bEttZy1YaHSfL1gKNgt2sTndv66nppdCbqZja1M85AHInIsMG8+SpnCzIQqaD39oPZHWZEjRMdu7P KA4jo3Brh38BLrwo+sslawX2RXIrY4Bt7+a7UqdfIkF8j42F555MNEO83J1cnWOUVZSCoAiAZ6slZ YG0knwIGXeGFNpLcR8z506sXydpna1ur2G8rb5RigsU1T6mpRdl59kMNC3EnUpPZc6txUn9SYbVMv pS7XmDXCcrDWHhdK+YgAZIXrpK5CaBG2qHbCph6ge8ptOVNemcJDHnLoPGGr/oP69g4ijWP1wD3N9 7AOp10YfWtFDYk90+l6eLstPkkaP33Eg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eP2ri-00053l-QY; Wed, 13 Dec 2017 08:58:10 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eP2rf-0004r0-B6 for linux-arm-kernel@lists.infradead.org; Wed, 13 Dec 2017 08:58:09 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20171213085738euoutp011b2e15451d8c1a07f6b5a6172a2cb732~-zt9K2D-E1612616126euoutp01B; Wed, 13 Dec 2017 08:57:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20171213085738euoutp011b2e15451d8c1a07f6b5a6172a2cb732~-zt9K2D-E1612616126euoutp01B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1513155458; bh=dQRqWmmdLna+Zr1Y6o+J4dO25KRm52AiCs29QSJJ+IE=; h=From:To:Cc:Subject:Date:References:From; b=gAGEwo2Ucxm7wMlRTAKvlGdjWtlGAUNx5d/6LXqHShizrdkiFDI1ZD/3yJZ73a09T 0Kp3ORfRA+6Pxet4gW9sv6I+bPxo81/AMqi7yJYMQiQmAxStR5eZzg//S9BNlAerGD 8F/eClr1EQ6E605iqTfPvewbe8dDOCdeCJwA88rI= Received: from eusmges3.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20171213085737eucas1p199c40074cd67d656161fed6f0588bd93~-zt8cEjWV0128401284eucas1p1H; Wed, 13 Dec 2017 08:57:37 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3.samsung.com (EUCPMTA) with SMTP id 97.56.12867.18BE03A5; Wed, 13 Dec 2017 08:57:37 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20171213085736eucas1p28d10718330c5c2eac834bd26786c84fc~-zt7wNHxX1622416224eucas1p2T; Wed, 13 Dec 2017 08:57:36 +0000 (GMT) X-AuditID: cbfec7f2-f793b6d000003243-42-5a30eb81e917 Received: from eusync2.samsung.com ( [203.254.199.212]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 80.0F.18832.08BE03A5; Wed, 13 Dec 2017 08:57:36 +0000 (GMT) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P0W00EQ267W1Y60@eusync2.samsung.com>; Wed, 13 Dec 2017 08:57:36 +0000 (GMT) From: Marek Szyprowski To: dri-devel@lists.freedesktop.org, Daniel Vetter , Jani Nikula , Gustavo Padovan , Sean Paul , David Airlie Subject: [PATCH] drm: Fix possible deadlock in drm_mode_config_cleanup() Date: Wed, 13 Dec 2017 09:57:20 +0100 Message-id: <20171213085720.6059-1-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.15.0 X-Brightmail-Tracker: H4sIAAAAAAAAAzWSa0hTYRjHe8/Zzs6Gk+Mm+qKBsawPhanYh5cuZiD59iHoQkkjyVGHZTqT HRWNILs4bVqKYI6krG0qLC+xhjmzVXbRWa4sEbNmq0lpNhUvmUmR7sxvv//z/z/P/8tDk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SyjxdQvH1gsfs34wGjRt/YSm4Owx/sbrewesxsusnjsuLuE 0ePk/GdsHn9ntzJ7LN7zkslj06pONo871/aweWz/9oDVY97JQI/9c9ewe9zvPs7ksXlJvceW /rvsHjsn7WXy6NuyijFAMIrLJiU1J7MstUjfLoEr48aP+awFi6Qrdt7ax9jAeEK8i5GTQ0LA RGL2snZGCFtM4sK99WxdjFwcQgJLGCVuzf0P5TQxSVz6sJEVpIpNwFCi620XWEJE4AWjxNNb B1lAHGaBoywS65uPs4NUCQt4SDw/dRasg0VAVaJr2lpmEJtXwEbi884ZUPvkJRZ/38k2gZF7 ASPDKkaR1NLi3PTcYkO94sTc4tK8dL3k/NxNjMBo2Hbs5+YdjJc2Bh9iFOBgVOLhffBAP0qI NbGsuDL3EKMEB7OSCG9PvEGUEG9KYmVValF+fFFpTmrxIUZpDhYlcd7ePasjhQTSE0tSs1NT C1KLYLJMHJxSDYwJ580nM4iuW3hftHhRdOuNh223RJ9s+pfcq+N0qn39rIfXdBa9PumtK7Sh RP9E057j63cG+HVP3tX270bpI7nGb46tZz0Xm1r+fHhq4x8zpRiN00ZnAlwk+JdobnQodl10 98mn8nz1qV6LPwuqPz5+7NG5+iNf30a/Xr23UExxh1FCyY8/z5W6lViKMxINtZiLihMBY+XG 6IICAAA= X-CMS-MailID: 20171213085736eucas1p28d10718330c5c2eac834bd26786c84fc X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20171213085736eucas1p28d10718330c5c2eac834bd26786c84fc X-RootMTR: 20171213085736eucas1p28d10718330c5c2eac834bd26786c84fc References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171213_005807_575183_8D7AD58D X-CRM114-Status: GOOD ( 14.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-samsung-soc@vger.kernel.org, Tomeu Vizoso , Greg Kroah-Hartman , Guillaume Tucker , Thierry Escande , Shuah Khan , Mark Brown , Matt Hart , Kevin Hilman , Enric Balletbo i Serra , Javier Martinez Canillas , linux-arm-kernel@lists.infradead.org, Marek Szyprowski MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP drm_mode_config_cleanup() might be called from a workqueue context (for example in error path handling of deferred probe), so it must not call flush_scheduled_work(), because it would deadlock in such case. Replace that call with explicit counting of the scheduled connector free works and waiting until it reaches zero. Fixes: a703c55004e1 ("drm: safely free connectors from connector_iter") Signed-off-by: Marek Szyprowski --- This fixes the issue discussed in the following thread: https://www.spinics.net/lists/arm-kernel/msg622332.html --- drivers/gpu/drm/drm_connector.c | 6 +++++- drivers/gpu/drm/drm_mode_config.c | 6 +++++- include/drm/drm_mode_config.h | 13 +++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index 0b7e0974e6da..7620ac1ad1b1 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -161,6 +161,8 @@ static void drm_connector_free_work_fn(struct work_struct *work) drm_mode_object_unregister(dev, &connector->base); connector->funcs->destroy(connector); + atomic_dec(&dev->mode_config.connector_free_works); + wake_up_all(&dev->mode_config.connector_free_queue); } /** @@ -552,8 +554,10 @@ EXPORT_SYMBOL(drm_connector_list_iter_begin); static void drm_connector_put_safe(struct drm_connector *conn) { - if (refcount_dec_and_test(&conn->base.refcount.refcount)) + if (refcount_dec_and_test(&conn->base.refcount.refcount)) { + atomic_inc(&conn->dev->mode_config.connector_free_works); schedule_work(&conn->free_work); + } } /** diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c index 6ffe952142e6..cca443faebd8 100644 --- a/drivers/gpu/drm/drm_mode_config.c +++ b/drivers/gpu/drm/drm_mode_config.c @@ -381,6 +381,7 @@ void drm_mode_config_init(struct drm_device *dev) idr_init(&dev->mode_config.tile_idr); ida_init(&dev->mode_config.connector_ida); spin_lock_init(&dev->mode_config.connector_list_lock); + init_waitqueue_head(&dev->mode_config.connector_free_queue); drm_mode_create_standard_properties(dev); @@ -431,8 +432,11 @@ void drm_mode_config_cleanup(struct drm_device *dev) drm_connector_put(connector); } drm_connector_list_iter_end(&conn_iter); + /* connector_iter drops references in a work item. */ - flush_scheduled_work(); + wait_event(dev->mode_config.connector_free_queue, + !atomic_read(&dev->mode_config.connector_free_works)); + if (WARN_ON(!list_empty(&dev->mode_config.connector_list))) { drm_connector_list_iter_begin(dev, &conn_iter); drm_for_each_connector_iter(connector, &conn_iter) diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h index a0afeb591dcb..83a7db997e83 100644 --- a/include/drm/drm_mode_config.h +++ b/include/drm/drm_mode_config.h @@ -413,6 +413,19 @@ struct drm_mode_config { * &struct drm_connector_list_iter to walk this list. */ struct list_head connector_list; + /** + * @pending_connector_free_works: + * + * Number of scheduled connector->free_work instances, see + * drm_connector_put_safe(). + */ + atomic_t connector_free_works; + /** + * @pending_connector_free_queue: + * + * Wait queue for waiting until connector->free_work is finished. + */ + wait_queue_head_t connector_free_queue; /** * @num_encoder: *