From patchwork Wed Mar 29 14:43:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 9651731 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 DBDFC602BE for ; Wed, 29 Mar 2017 14:44:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D15E5284CC for ; Wed, 29 Mar 2017 14:44:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C62F8284D1; Wed, 29 Mar 2017 14:44:21 +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.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 51B87284CC for ; Wed, 29 Mar 2017 14:44:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D92066E75D; Wed, 29 Mar 2017 14:44:13 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id BE22A6E757; Wed, 29 Mar 2017 14:44:11 +0000 (UTC) Received: by mail-wr0-x242.google.com with SMTP id u18so3624908wrc.0; Wed, 29 Mar 2017 07:44:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wFsi9Z+qwY7vD9/gv8U+HDdz+N8sI3deYsdtuuNOcYY=; b=Sw7kAa4fe6TVY03QZaFNeJo/Zo/nBReCmOirXcjjvjtN7KYleOefQulFbgeK8BYXEj vYjFl341AfKMF+/p2l2vhtQSWa9TAydv/ceUbKZCcadv7UsoSneBWg5/F62sOw4Uicdz ZW8vMvLNwpxhZxoGHL9TPnXDVB6ZNR5PTzP16VXqqgzTqGrM7vZM7alSRviqGQtqIDRV 6tRqOVDo8qrToEbz+mP+dhyTDNj8SAHMKFjXgyDHlYfvwsuwoiuvY/bCKaZP92tTS43B YYmLFV2eUf1pzMYtrnAR4wOic24grPfDssJ5NqglgadkaSoyiVxG9DR5CdLqDYYU59I5 WtGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wFsi9Z+qwY7vD9/gv8U+HDdz+N8sI3deYsdtuuNOcYY=; b=pcXdMQMiN3F+6lccFf75HVGTldPGp1/QIn+XtBzXY+AvF6WKyz97xATwjgmBRP7+GD VQIkSwZf6p4Kfaz+sRg8fuFzJo5vZRa5wLq0B7Miyuc7NI1/6MZE6+AAtwuLzeBDY4h7 ek5fiYTayzWku8bqHihLH3+Oef7Wi57xaFPxLWVJDJbPk2MTv14Ye/5hwa1STr61pDNd cjvVmYKZPA61Nl9jgpyuaXBdRhNDrcyebtWo2CVjmf+W0dW0ARpsJf/XqjMG4UyGHfgN Suqeb4/2fmJpYgRJqkrKAf+85/o5knBNi94owkbjhcA1XvLSWSgxinqjd9ExRhVfLbtE Mtpw== X-Gm-Message-State: AFeK/H3cyZ279zLDnNwkxF333HJUKxqojA6sVmcZYfGThgFDZh4t8+CIAth9tQV+y5m83w== X-Received: by 10.28.152.11 with SMTP id a11mr1758948wme.64.1490798650072; Wed, 29 Mar 2017 07:44:10 -0700 (PDT) Received: from localhost (port-5852.pppoe.wtnet.de. [84.46.22.242]) by smtp.gmail.com with ESMTPSA id k32sm9657418wre.18.2017.03.29.07.44.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Mar 2017 07:44:09 -0700 (PDT) From: Thierry Reding To: Daniel Vetter Date: Wed, 29 Mar 2017 16:43:56 +0200 Message-Id: <20170329144401.1804-7-thierry.reding@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170329144401.1804-1-thierry.reding@gmail.com> References: <20170329144401.1804-1-thierry.reding@gmail.com> Cc: John Stultz , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [Intel-gfx] [PATCH v4 06/11] drm/fb-helper: Make top-level lock more robust X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Thierry Reding The existing drm_fb_helper_hotplug_event() function needs to take the top-level fb-helper lock. However, the function can also be called from code that has already taken this lock. Introduce an unlocked variant of this function that can be used in the latter case. This function calls drm_fb_helper_restore_fbdev_mode_unlocked(), via drm_fb_helper_set_par(), so we also need to introduce an unlocked copy of that to avoid recursive locking issues. Similarly, the drm_fb_helper_initial_config() function ends up calling drm_fb_helper_set_par(), via register_framebuffer(), and needs an unlocked variant to avoid recursive locking. Signed-off-by: Thierry Reding --- drivers/gpu/drm/drm_fb_helper.c | 167 +++++++++++++++++++++++++--------------- 1 file changed, 104 insertions(+), 63 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 860be51d92f6..21a90322531c 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -491,18 +491,10 @@ static int restore_fbdev_mode(struct drm_fb_helper *fb_helper) return 0; } -/** - * drm_fb_helper_restore_fbdev_mode_unlocked - restore fbdev configuration - * @fb_helper: fbcon to restore - * - * This should be called from driver's drm &drm_driver.lastclose callback - * when implementing an fbcon on top of kms using this helper. This ensures that - * the user isn't greeted with a black screen when e.g. X dies. - * - * RETURNS: - * Zero if everything went ok, negative error code otherwise. - */ -int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper) +static int __drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper); + +static int +__drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper) { struct drm_device *dev = fb_helper->dev; bool do_delayed; @@ -511,7 +503,8 @@ int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper) if (!drm_fbdev_emulation) return -ENODEV; - mutex_lock(&fb_helper->lock); + WARN_ON(!mutex_is_locked(&fb_helper->lock)); + drm_modeset_lock_all(dev); ret = restore_fbdev_mode(fb_helper); @@ -521,10 +514,31 @@ int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper) fb_helper->delayed_hotplug = false; drm_modeset_unlock_all(dev); - mutex_unlock(&fb_helper->lock); if (do_delayed) - drm_fb_helper_hotplug_event(fb_helper); + __drm_fb_helper_hotplug_event(fb_helper); + + return ret; +} + +/** + * drm_fb_helper_restore_fbdev_mode_unlocked - restore fbdev configuration + * @fb_helper: fbcon to restore + * + * This should be called from driver's drm &drm_driver.lastclose callback + * when implementing an fbcon on top of kms using this helper. This ensures that + * the user isn't greeted with a black screen when e.g. X dies. + * + * RETURNS: + * Zero if everything went ok, negative error code otherwise. + */ +int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper) +{ + int ret; + + mutex_lock(&fb_helper->lock); + ret = __drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper); + mutex_unlock(&fb_helper->lock); return ret; } @@ -1486,7 +1500,7 @@ int drm_fb_helper_set_par(struct fb_info *info) return -EINVAL; } - drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper); + __drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper); return 0; } @@ -2333,6 +2347,46 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, kfree(enabled); } +static int __drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, + int bpp_sel) +{ + struct drm_device *dev = fb_helper->dev; + struct fb_info *info; + int ret; + + if (!drm_fbdev_emulation) + return 0; + + WARN_ON(!mutex_is_locked(&fb_helper->lock)); + + mutex_lock(&dev->mode_config.mutex); + drm_setup_crtcs(fb_helper, + dev->mode_config.max_width, + dev->mode_config.max_height); + ret = drm_fb_helper_single_fb_probe(fb_helper, bpp_sel); + mutex_unlock(&dev->mode_config.mutex); + if (ret) + return ret; + + info = fb_helper->fbdev; + info->var.pixclock = 0; + ret = register_framebuffer(info); + if (ret < 0) + return ret; + + dev_info(dev->dev, "fb%d: %s frame buffer device\n", + info->node, info->fix.id); + + mutex_lock(&kernel_fb_helper_lock); + if (list_empty(&kernel_fb_helper_list)) + register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op); + + list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list); + mutex_unlock(&kernel_fb_helper_lock); + + return 0; +} + /** * drm_fb_helper_initial_config - setup a sane initial connector configuration * @fb_helper: fb_helper device struct @@ -2377,41 +2431,50 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, */ int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel) { - struct drm_device *dev = fb_helper->dev; - struct fb_info *info; int ret; + mutex_lock(&fb_helper->lock); + ret = __drm_fb_helper_initial_config(fb_helper, bpp_sel); + mutex_unlock(&fb_helper->lock); + + return ret; +} +EXPORT_SYMBOL(drm_fb_helper_initial_config); + +static int __drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper) +{ + struct drm_device *dev = fb_helper->dev; + unsigned int width, height; + if (!drm_fbdev_emulation) return 0; + WARN_ON(!mutex_is_locked(&fb_helper->lock)); + mutex_lock(&dev->mode_config.mutex); - drm_setup_crtcs(fb_helper, - dev->mode_config.max_width, - dev->mode_config.max_height); - ret = drm_fb_helper_single_fb_probe(fb_helper, bpp_sel); - mutex_unlock(&dev->mode_config.mutex); - if (ret) - return ret; - info = fb_helper->fbdev; - info->var.pixclock = 0; - ret = register_framebuffer(info); - if (ret < 0) - return ret; + if (!fb_helper->fb || !drm_fb_helper_is_bound(fb_helper)) { + fb_helper->delayed_hotplug = true; + mutex_unlock(&dev->mode_config.mutex); + return 0; + } - dev_info(dev->dev, "fb%d: %s frame buffer device\n", - info->node, info->fix.id); + DRM_DEBUG_KMS("\n"); - mutex_lock(&kernel_fb_helper_lock); - if (list_empty(&kernel_fb_helper_list)) - register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op); + width = dev->mode_config.max_width; + height = dev->mode_config.max_height; - list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list); - mutex_unlock(&kernel_fb_helper_lock); + if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 0) + DRM_DEBUG_KMS("No connectors reported connected with modes\n"); + + drm_setup_crtcs(fb_helper, fb_helper->fb->width, fb_helper->fb->height); + + mutex_unlock(&dev->mode_config.mutex); + + drm_fb_helper_set_par(fb_helper->fbdev); return 0; } -EXPORT_SYMBOL(drm_fb_helper_initial_config); /** * drm_fb_helper_hotplug_event - respond to a hotplug notification by @@ -2436,35 +2499,13 @@ EXPORT_SYMBOL(drm_fb_helper_initial_config); */ int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper) { - struct drm_device *dev = fb_helper->dev; - int err = 0; - - if (!drm_fbdev_emulation) - return 0; + int ret; mutex_lock(&fb_helper->lock); - mutex_lock(&dev->mode_config.mutex); - - if (!fb_helper->fb || !drm_fb_helper_is_bound(fb_helper)) { - fb_helper->delayed_hotplug = true; - mutex_unlock(&dev->mode_config.mutex); - goto unlock; - } - - DRM_DEBUG_KMS("\n"); - - drm_setup_crtcs(fb_helper, fb_helper->fb->width, fb_helper->fb->height); - - mutex_unlock(&dev->mode_config.mutex); + ret = __drm_fb_helper_hotplug_event(fb_helper); mutex_unlock(&fb_helper->lock); - drm_fb_helper_set_par(fb_helper->fbdev); - - return 0; - -unlock: - mutex_unlock(&fb_helper->lock); - return err; + return ret; } EXPORT_SYMBOL(drm_fb_helper_hotplug_event);