From patchwork Thu Nov 20 23:42:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 5351361 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DBC7C9F4E3 for ; Thu, 20 Nov 2014 23:43:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BF9EA20221 for ; Thu, 20 Nov 2014 23:43:14 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 9B146201EF for ; Thu, 20 Nov 2014 23:43:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E85156FCDB; Thu, 20 Nov 2014 15:43:12 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qa0-f45.google.com (mail-qa0-f45.google.com [209.85.216.45]) by gabe.freedesktop.org (Postfix) with ESMTP id 6518C6FCDB for ; Thu, 20 Nov 2014 15:43:11 -0800 (PST) Received: by mail-qa0-f45.google.com with SMTP id x12so2688104qac.4 for ; Thu, 20 Nov 2014 15:43:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1Qs4Gu4Pyh+7Z57YjkKAzQZn9a1rbnaXR/EekNdISC0=; b=GVMQr+5ShAEedrURpblL2514T5UaQaWxpn/vEYyGDyurfsPyhWRHmMQSwITxfhryIx umYHY6W3GLvd4ovGn+qkC30PuGjnGDQU0BEXvx1PG+9rFE39AMtdvrlX4f77e8SF/KaG L1u7AVlLii5EKlJenwvtjEvn7T5FVPvLPgDNJHfHD8+Y7syn58LhC5U6RJESC8HSZI4K deufMYDUX9EMzNrkNBOhGI/RzUj0GMT43L4e1F9pkxFPAS1angvf+ZN9tKC+8gh4KaF6 TkxUvTFDmgzmmOrLSGt41d7hrqIJc/UZNktbG0TzZ6p+2BPT68ejoeUFVv2VzFPCF77c wJWg== X-Received: by 10.224.46.66 with SMTP id i2mr1659372qaf.72.1416526990892; Thu, 20 Nov 2014 15:43:10 -0800 (PST) Received: from localhost.localdomain ([187.34.44.229]) by mx.google.com with ESMTPSA id o30sm961607qge.33.2014.11.20.15.43.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Nov 2014 15:43:09 -0800 (PST) From: Gustavo Padovan To: linux-samsung-soc@vger.kernel.org Subject: [PATCH 3/3] drm/exynos: move Exynos platform drivers registration to init Date: Thu, 20 Nov 2014 21:42:56 -0200 Message-Id: <1416526976-9467-4-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1416526976-9467-1-git-send-email-gustavo@padovan.org> References: <1416526976-9467-1-git-send-email-gustavo@padovan.org> Cc: Gustavo Padovan , dri-devel@lists.freedesktop.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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Gustavo Padovan Registering the Exynos DRM subdevices platform drivers in the probe function is causing an infinite loop. Fix this by moving it to the exynos_drm_init() function to register the drivers on module init. Registering drivers in the probe functions causes a deadlock in the parent device lock. See Grant Likely explanation on the topic: "I think the problem is that exynos_drm_init() is registering a normal (non-OF) platform device, so the parent will be /sys/devices/platform. It immediately gets bound against exynos_drm_platform_driver which calls the exynos drm_platform_probe() hook. The driver core obtains device_lock() on the device *and on the device parent*. Inside the probe hook, additional platform_drivers get registered. Each time one does, it tries to bind against every platform device in the system, which includes the ones created by OF. When it attempts to bind, it obtains device_lock() on the device *and on the device parent*. Before the change to move of-generated platform devices into /sys/devices/platform, the devices had different parents. Now both devices have /sys/devices/platform as the parent, so yes they are going to deadlock. The real problem is registering drivers from within a probe hook. That is completely wrong for the above deadlock reason. __driver_attach() will deadlock. Those registrations must be pulled out of .probe(). Registering devices in .probe() is okay because __device_attach() doesn't try to obtain device_lock() on the parent." INFO: task swapper/0:1 blocked for more than 120 seconds. Not tainted 3.18.0-rc3-next-20141105 #794 "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. swapper/0 D c052534c 0 1 0 0x00000000 [] (__schedule) from [] (schedule_preempt_disabled+0x14/0x20) [] (schedule_preempt_disabled) from [] (mutex_lock_nested+0x1c4/0x464 [] (mutex_lock_nested) from [] (__driver_attach+0x48/0x98) [] (__driver_attach) from [] (bus_for_each_dev+0x54/0x88) [] (bus_for_each_dev) from [] (bus_add_driver+0xe4/0x200) [] (bus_add_driver) from [] (driver_register+0x78/0xf4) [] (driver_register) from [] (exynos_drm_platform_probe+0x34/0x234) [] (exynos_drm_platform_probe) from [] (platform_drv_probe+0x48/0xa4) [] (platform_drv_probe) from [] (driver_probe_device+0x13c/0x37c) [] (driver_probe_device) from [] (__driver_attach+0x94/0x98) [] (__driver_attach) from [] (bus_for_each_dev+0x54/0x88) [] (bus_for_each_dev) from [] (bus_add_driver+0xe4/0x200) [] (bus_add_driver) from [] (driver_register+0x78/0xf4) [] (driver_register) from [] (exynos_drm_init+0x70/0xa0) [] (exynos_drm_init) from [] (do_one_initcall+0xac/0x1f0) [] (do_one_initcall) from [] (kernel_init_freeable+0x10c/0x1d8) [] (kernel_init_freeable) from [] (kernel_init+0x8/0xec) [] (kernel_init) from [] (ret_from_fork+0x14/0x2c) 3 locks held by swapper/0/1: #0: (&dev->mutex){......}, at: [] __driver_attach+0x48/0x98 #1: (&dev->mutex){......}, at: [] __driver_attach+0x58/0x98 #2: (&dev->mutex){......}, at: [] __driver_attach+0x48/0x98 Signed-off-by: Javier Martinez Canillas Signed-off-by: Gustavo Padovan --- drivers/gpu/drm/exynos/exynos_drm_drv.c | 124 +++++++++++++++----------------- 1 file changed, 59 insertions(+), 65 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c index 91891cf..cb3ed9b 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_drv.c +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c @@ -548,6 +548,38 @@ static const struct component_master_ops exynos_drm_ops = { .unbind = exynos_drm_unbind, }; +static int exynos_drm_platform_probe(struct platform_device *pdev) +{ + struct component_match *match; + + pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); + exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls); + + match = exynos_drm_match_add(&pdev->dev); + if (IS_ERR(match)) { + return PTR_ERR(match); + } + + return component_master_add_with_match(&pdev->dev, &exynos_drm_ops, + match); +} + +static int exynos_drm_platform_remove(struct platform_device *pdev) +{ + component_master_del(&pdev->dev, &exynos_drm_ops); + return 0; +} + +static struct platform_driver exynos_drm_platform_driver = { + .probe = exynos_drm_platform_probe, + .remove = exynos_drm_platform_remove, + .driver = { + .owner = THIS_MODULE, + .name = "exynos-drm", + .pm = &exynos_drm_pm_ops, + }, +}; + static struct platform_driver *const exynos_drm_kms_drivers[] = { #ifdef CONFIG_DRM_EXYNOS_FIMD &fimd_driver, @@ -582,13 +614,24 @@ static struct platform_driver *const exynos_drm_non_kms_drivers[] = { #endif }; -static int exynos_drm_platform_probe(struct platform_device *pdev) +static int exynos_drm_init(void) { - struct component_match *match; int ret, i, j; - pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); - exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls); + exynos_drm_pdev = platform_device_register_simple("exynos-drm", -1, + NULL, 0); + if (IS_ERR(exynos_drm_pdev)) + return PTR_ERR(exynos_drm_pdev); + +#ifdef CONFIG_DRM_EXYNOS_VIDI + ret = exynos_drm_probe_vidi(); + if (ret < 0) + goto err_unregister_pd; +#endif + + ret = platform_driver_register(&exynos_drm_platform_driver); + if (ret) + goto err_remove_vidi; for (i = 0; i < ARRAY_SIZE(exynos_drm_kms_drivers); ++i) { ret = platform_driver_register(exynos_drm_kms_drivers[i]); @@ -596,26 +639,17 @@ static int exynos_drm_platform_probe(struct platform_device *pdev) goto err_unregister_kms_drivers; } - match = exynos_drm_match_add(&pdev->dev); - if (IS_ERR(match)) { - ret = PTR_ERR(match); - goto err_unregister_kms_drivers; - } - - ret = component_master_add_with_match(&pdev->dev, &exynos_drm_ops, - match); - if (ret < 0) - goto err_unregister_kms_drivers; - for (j = 0; j < ARRAY_SIZE(exynos_drm_non_kms_drivers); ++j) { ret = platform_driver_register(exynos_drm_non_kms_drivers[j]); if (ret < 0) - goto err_del_component_master; + goto err_unregister_non_kms_drivers; } +#ifdef CONFIG_DRM_EXYNOS_IPP ret = exynos_platform_device_ipp_register(); if (ret < 0) goto err_unregister_non_kms_drivers; +#endif return ret; @@ -626,17 +660,22 @@ err_unregister_non_kms_drivers: while (--j >= 0) platform_driver_unregister(exynos_drm_non_kms_drivers[j]); -err_del_component_master: - component_master_del(&pdev->dev, &exynos_drm_ops); - err_unregister_kms_drivers: while (--i >= 0) platform_driver_unregister(exynos_drm_kms_drivers[i]); +err_remove_vidi: +#ifdef CONFIG_DRM_EXYNOS_VIDI + exynos_drm_remove_vidi(); + +err_unregister_pd: +#endif + platform_device_unregister(exynos_drm_pdev); + return ret; } -static int exynos_drm_platform_remove(struct platform_device *pdev) +static void exynos_drm_exit(void) { int i; @@ -647,54 +686,9 @@ static int exynos_drm_platform_remove(struct platform_device *pdev) for (i = ARRAY_SIZE(exynos_drm_non_kms_drivers) - 1; i >= 0; --i) platform_driver_unregister(exynos_drm_non_kms_drivers[i]); - component_master_del(&pdev->dev, &exynos_drm_ops); - for (i = ARRAY_SIZE(exynos_drm_kms_drivers) - 1; i >= 0; --i) platform_driver_unregister(exynos_drm_kms_drivers[i]); - return 0; -} - -static struct platform_driver exynos_drm_platform_driver = { - .probe = exynos_drm_platform_probe, - .remove = exynos_drm_platform_remove, - .driver = { - .owner = THIS_MODULE, - .name = "exynos-drm", - .pm = &exynos_drm_pm_ops, - }, -}; - -static int exynos_drm_init(void) -{ - int ret; - - exynos_drm_pdev = platform_device_register_simple("exynos-drm", -1, - NULL, 0); - if (IS_ERR(exynos_drm_pdev)) - return PTR_ERR(exynos_drm_pdev); - - ret = exynos_drm_probe_vidi(); - if (ret < 0) - goto err_unregister_pd; - - ret = platform_driver_register(&exynos_drm_platform_driver); - if (ret) - goto err_remove_vidi; - - return 0; - -err_remove_vidi: - exynos_drm_remove_vidi(); - -err_unregister_pd: - platform_device_unregister(exynos_drm_pdev); - - return ret; -} - -static void exynos_drm_exit(void) -{ platform_driver_unregister(&exynos_drm_platform_driver); exynos_drm_remove_vidi();