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: 121724 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp5206498qgn; Wed, 13 Dec 2017 00:57:46 -0800 (PST) X-Google-Smtp-Source: ACJfBouKTQuY5YOu5Wd+2EANAFI475Ptcg8412G2xbXze2VfgRj5BFl+U0jfBjNiZtchsbDnxx08 X-Received: by 10.99.3.146 with SMTP id 140mr4576191pgd.273.1513155466778; Wed, 13 Dec 2017 00:57:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513155466; cv=none; d=google.com; s=arc-20160816; b=OT1KiDVnZNPfU6IvRJqKULMw/yEFOWyeNeRkE6+UXg5bu4J6OUVNeI3/69ZabYFW3/ +oX4azfFUzzVWKaca9xcpY/r67UyK55fL/dfQSm3LF5yB8632UBqkC12gWwCBSKr+fCo ZL4XLIQvELZ7nb51dg2dGcu8u/XGZiyABI3WThRXZyyA8yz18bjR8bxYGJzO+cbUBix/ D1oYlLuFCnfM9953cIvVZb4R9BeVaiXk2laMLCeQ42KC/WFHW8fyHwFX0GmHARNyjpn6 ZoyCr2O0glVD5Z/kTjnt2z4SbabcUgXaru42jliPXBYWheussj8Lyu/7ooj9ywGVIThp kVcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=6YIe2hhKElz78eEIqet0KTeTBCK9LFhl73GeDlVJgHk=; b=jMaRyTyDtawO9+gyPgtDkfc5KfAZJkZDZkMvw/eZX7d1NLBpMhA8fJkNopB9yCEvry WMat2Jh1IheRlMoFf7f60TTBPjB5qQ5iSksSooV50XdjMBAowzlRpmP2OUYv+sPcJC+c jh1nzZ8cwmmhP8RiNZ8uO7zRwX0JigbrGyzFp/nF2vMsf3yQE/zSQgWfCSAKYmGHmhrM cdSWDZ/w8KTXqGdYdTWxMirv/ubqTZ1VB3h9wgHbgk/mBSY/wk3+UwE8WgK1gmCs+kYV akjG1Ody9/FCZzb5l/R+eCiuBII1d17lAgh/ifcgjLckz+FC2keS/KZ+zc6N59kD5+zf NGzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=gAGEwo2U; spf=pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p26si1050237pfh.220.2017.12.13.00.57.46; Wed, 13 Dec 2017 00:57:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=gAGEwo2U; spf=pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751861AbdLMI5p (ORCPT + 3 others); Wed, 13 Dec 2017 03:57:45 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:59955 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752021AbdLMI5l (ORCPT ); Wed, 13 Dec 2017 03:57:41 -0500 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 Cc: Marek Szyprowski , Javier Martinez Canillas , Shuah Khan , Guillaume Tucker , Mark Brown , Kevin Hilman , Matt Hart , Thierry Escande , Tomeu Vizoso , Enric Balletbo i Serra , Greg Kroah-Hartman , linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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/8tDkzKz MILOyM5ltdmqLAUlEbS9XHTFXJiIU8ZVtEvQVZeTQNVfRinU+LqFRAPzUxRq+tgF0CVTK4V+ zphIZPd0iFDj+1aABpcMFFossRHI6h0UIsMbB4Gan7tFyDmsB8h9rw+g6rlpAfpjmAboWvM7 KkmOp4aKRbi2qF+A291mgJ113yj8t7aYxKbOcQJbLVco/Gmwk8IPfnmE+JbzAH58s0mEP5d1 E/i++Ty2VbhF2F71iMDXbBawP0Qp2XGSzcrIZ7WxiemSU0O/64Q5xsgC+7ADFIGecD0Q05DZ CqdH9YDnMPh2pJXSAwktY+oBdBqMAl7MAtj49S5Y3ahtKAG80QBgzbAlkCoioHfMQq2kKCYe 6n16/61QZgxAa5POL0jmqQAOlFcSKyk5g+H33j7hCguYDVB/vZlcYSmzA87aDYG+KGhasPuX IWMUwbEBXcBIhhPGMoJnOfzRbRPxvBZeKX0amFcAeLF4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YLJMHJxSDYwJ580nM4iuW3hftHhRdOuNh223RJ9s+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: Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org 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(-) -- 2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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: *