From patchwork Tue Aug 1 08:11:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yao mark X-Patchwork-Id: 9873827 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 BFBC56037D for ; Tue, 1 Aug 2017 08:12:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93DE62863E for ; Tue, 1 Aug 2017 08:12:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88C1828643; Tue, 1 Aug 2017 08:12:45 +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, RCVD_IN_DNSWL_MED 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 792E42863E for ; Tue, 1 Aug 2017 08:12:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F1A316E066; Tue, 1 Aug 2017 08:12:02 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from regular1.263xmail.com (regular1.263xmail.com [211.150.99.139]) by gabe.freedesktop.org (Postfix) with ESMTPS id E1F7C6E066 for ; Tue, 1 Aug 2017 08:12:01 +0000 (UTC) Received: from mark.yao?rock-chips.com (unknown [192.168.167.160]) by regular1.263xmail.com (Postfix) with ESMTP id 448665539; Tue, 1 Aug 2017 16:11:56 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from yaozq-pc.lan (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id 7337D3F3; Tue, 1 Aug 2017 16:11:54 +0800 (CST) X-RL-SENDER: mark.yao@rock-chips.com X-FST-TO: mark.yao@rock-chips.com X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: mark.yao@rock-chips.com X-UNIQUE-TAG: <0eb87748b3676a6feb462030d86e1206> X-ATTACHMENT-NUM: 0 X-SENDER: yzq@rock-chips.com X-DNS-TYPE: 0 Received: from yaozq-pc.lan (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith ESMTP id 18671GEB7GH; Tue, 01 Aug 2017 16:11:56 +0800 (CST) From: Mark Yao To: Mark Yao , David Airlie , Heiko Stuebner Subject: [PATCH v1.1] drm/rockchip: fix race with kms hotplug and fbdev Date: Tue, 1 Aug 2017 16:11:43 +0800 Message-Id: <1501575103-20136-1-git-send-email-mark.yao@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501494601-7140-1-git-send-email-mark.yao@rock-chips.com> References: <1501494601-7140-1-git-send-email-mark.yao@rock-chips.com> Cc: linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP According to the kerneldoc[0], should do fbdev setup before calling drm_kms_helper_poll_init(), otherwise, Kms hotplug event may race into fbdev helper initial, and fb_helper->dev may be NULL pointer, that would cause the bug: [ 0.735411] [00000200] *pgd=00000000f6ffe003, *pud=00000000f6ffe003, *pmd=0000000000000000 [ 0.736156] Internal error: Oops: 96000005 [#1] PREEMPT SMP [ 0.736648] Modules linked in: [ 0.736930] CPU: 2 PID: 20 Comm: kworker/2:0 Not tainted 4.4.41 #20 [ 0.737480] Hardware name: Rockchip RK3399 Board rev2 (BOX) (DT) [ 0.738020] Workqueue: events cdn_dp_pd_event_work [ 0.738447] task: ffffffc0f21f3100 ti: ffffffc0f2218000 task.ti: ffffffc0f2218000 [ 0.739109] PC is at mutex_lock+0x14/0x44 [ 0.739469] LR is at drm_fb_helper_hotplug_event+0x30/0x114 [ 0.756253] [] mutex_lock+0x14/0x44 [ 0.756260] [] drm_fb_helper_hotplug_event+0x30/0x114 [ 0.756271] [] rockchip_drm_output_poll_changed+0x18/0x20 [ 0.756280] [] drm_kms_helper_hotplug_event+0x28/0x34 [ 0.756286] [] cdn_dp_pd_event_work+0x394/0x3c4 [ 0.756295] [] process_one_work+0x218/0x3e0 [ 0.756302] [] worker_thread+0x2e8/0x404 [ 0.756308] [] kthread+0xe8/0xf0 [ 0.756316] [] ret_from_fork+0x10/0x40 [0]: https://01.org/linuxgraphics/gfx-docs/drm/gpu/drm-kms-helpers.html Signed-off-by: Mark Yao Reviewed-by: Sandy huang --- Changes in v1.1: - According to the kerneldoc, fix the race bug in generic way. drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c index 848edcf..c41f48a 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c @@ -161,22 +161,21 @@ static int rockchip_drm_bind(struct device *dev) */ drm_dev->irq_enabled = true; - /* init kms poll for handling hpd */ - drm_kms_helper_poll_init(drm_dev); - ret = rockchip_drm_fbdev_init(drm_dev); if (ret) - goto err_kms_helper_poll_fini; + goto err_unbind_all; + + /* init kms poll for handling hpd */ + drm_kms_helper_poll_init(drm_dev); ret = drm_dev_register(drm_dev, 0); if (ret) - goto err_fbdev_fini; + goto err_kms_helper_poll_fini; return 0; -err_fbdev_fini: - rockchip_drm_fbdev_fini(drm_dev); err_kms_helper_poll_fini: drm_kms_helper_poll_fini(drm_dev); + rockchip_drm_fbdev_fini(drm_dev); err_unbind_all: component_unbind_all(dev, drm_dev); err_mode_config_cleanup: