From patchwork Wed Mar 29 14:43:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 9651725 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 E3B55602BE for ; Wed, 29 Mar 2017 14:44:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9A0F284CC for ; Wed, 29 Mar 2017 14:44:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE33B284D1; Wed, 29 Mar 2017 14:44:14 +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 5CB7D284CC for ; Wed, 29 Mar 2017 14:44:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 27CD76E759; 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-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 57AC36E757; Wed, 29 Mar 2017 14:44:10 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id w43so3620697wrb.1; Wed, 29 Mar 2017 07:44:10 -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=bRVAbXb3AVjSFQUsl5s8aJiUpBz1i7waYHaO2T/pkUs=; b=DWnGjM/gEshXsV5nFZCuBFpZUdFCdMGTQ12kXtKLHgcJFqEI7zkSFmth+N8a8rcgL7 rDYg+RUa95zx8YRpTE5KSFVm6H3g5x+DSFl+h7O+YLdoUo6FToyb5B+z7ojRjy/WFApr SZAFJ6nT4z1NVir+ZdbIZIKNk1Z649nuLxec2OTcCsq2BWKi9GMKosqU3+Vjq75U8Y5A lwGOH6TvPGB5vrv8dC66QO058kc4s+XyuTioYBipoNO9fln35Z/vitx6PHxxvJwofEjM u0zMe/sCe0qycu++1FY5Z/58f2kHhzNe0OTcILR1Yonm9nphjyMykkGXbWKDbA1wvq+4 B3PA== 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=bRVAbXb3AVjSFQUsl5s8aJiUpBz1i7waYHaO2T/pkUs=; b=UxB2AUghI9iSdXpPBhf5nCfK2g3O7O0qLiYpTLhCygMWEsI1yYMwM9vKGAu+CZwGcz FOXmxlDBET3ZALMwC1Oh4Kcw9/RCva4/w3lekBR/o3x46YPS7+O8ukGeSFGELDBdE4zj Ff+C3Xnp3UYFEk04HrTVz5ygz+dJMS/n/PSSfE6thDUGhVUvSWepeeayRL/NEWAUL2u1 zOz2isFF8zhhej63ULpgTWblZlZi0PT2YSYb0il+7DiwDpwDAPyLNJD1RSag/YV7Bt/0 m74RlStcMaO7/i3eKEn3l7BuXJtpmZbywkCR5n0SgarIvjw+9QPdTC70m7nKmAhB0oXZ bORA== X-Gm-Message-State: AFeK/H2KZ231HSoX+JnRBOkCrIMZW2FYBlKsp/WQWpGwbeiuYdxbHm4UQs/IYMHYceLE8w== X-Received: by 10.28.181.80 with SMTP id e77mr1726485wmf.57.1490798648769; Wed, 29 Mar 2017 07:44:08 -0700 (PDT) Received: from localhost (port-5852.pppoe.wtnet.de. [84.46.22.242]) by smtp.gmail.com with ESMTPSA id 65sm9709731wri.68.2017.03.29.07.44.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Mar 2017 07:44:08 -0700 (PDT) From: Thierry Reding To: Daniel Vetter Date: Wed, 29 Mar 2017 16:43:55 +0200 Message-Id: <20170329144401.1804-6-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 05/11] drm/fb-helper: Add top-level lock 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 Introduce a new top-level lock for the FB helper code. This will allow better locking granularity and avoid the need to abuse modeset locking for this purpose instead. Tested-by: John Stultz Reviewed-by: Daniel Vetter Signed-off-by: Thierry Reding --- drivers/gpu/drm/drm_fb_helper.c | 26 +++++++++++++++++++++++++- include/drm/drm_fb_helper.h | 12 ++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 18105cbe9810..860be51d92f6 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -119,6 +119,7 @@ static int __drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, if (!drm_fbdev_emulation) return 0; + WARN_ON(!mutex_is_locked(&fb_helper->lock)); WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex)); count = fb_helper->connector_count + 1; @@ -150,11 +151,13 @@ int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, { int err; + mutex_lock(&fb_helper->lock); mutex_lock(&fb_helper->dev->mode_config.mutex); err = __drm_fb_helper_add_one_connector(fb_helper, connector); mutex_unlock(&fb_helper->dev->mode_config.mutex); + mutex_unlock(&fb_helper->lock); return err; } @@ -184,6 +187,7 @@ int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper) if (!drm_fbdev_emulation) return 0; + mutex_lock(&fb_helper->lock); mutex_lock(&dev->mode_config.mutex); drm_connector_list_iter_begin(dev, &conn_iter); drm_for_each_connector_iter(connector, &conn_iter) { @@ -207,6 +211,7 @@ int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper) out: drm_connector_list_iter_end(&conn_iter); mutex_unlock(&dev->mode_config.mutex); + mutex_unlock(&fb_helper->lock); return ret; } @@ -221,6 +226,7 @@ static int __drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper, if (!drm_fbdev_emulation) return 0; + WARN_ON(!mutex_is_locked(&fb_helper->lock)); WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex)); for (i = 0; i < fb_helper->connector_count; i++) { @@ -247,11 +253,13 @@ int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper, { int err; + mutex_lock(&fb_helper->lock); mutex_lock(&fb_helper->dev->mode_config.mutex); err = __drm_fb_helper_remove_one_connector(fb_helper, connector); mutex_unlock(&fb_helper->dev->mode_config.mutex); + mutex_unlock(&fb_helper->lock); return err; } @@ -503,16 +511,21 @@ 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); drm_modeset_lock_all(dev); + ret = restore_fbdev_mode(fb_helper); do_delayed = fb_helper->delayed_hotplug; if (do_delayed) 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); + return ret; } EXPORT_SYMBOL(drm_fb_helper_restore_fbdev_mode_unlocked); @@ -748,6 +761,7 @@ void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper, INIT_WORK(&helper->resume_work, drm_fb_helper_resume_worker); INIT_WORK(&helper->dirty_work, drm_fb_helper_dirty_work); helper->dirty_clip.x1 = helper->dirty_clip.y1 = ~0; + mutex_init(&helper->lock); helper->funcs = funcs; helper->dev = dev; } @@ -913,6 +927,7 @@ void drm_fb_helper_fini(struct drm_fb_helper *fb_helper) } mutex_unlock(&kernel_fb_helper_lock); + mutex_destroy(&fb_helper->lock); drm_fb_helper_crtc_free(fb_helper); } @@ -2422,25 +2437,34 @@ 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; + 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); - return 0; + 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); + mutex_unlock(&fb_helper->lock); drm_fb_helper_set_par(fb_helper->fbdev); return 0; + +unlock: + mutex_unlock(&fb_helper->lock); + return err; } EXPORT_SYMBOL(drm_fb_helper_hotplug_event); diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper.h index 119e5e4609c7..44e2c57a7049 100644 --- a/include/drm/drm_fb_helper.h +++ b/include/drm/drm_fb_helper.h @@ -201,6 +201,18 @@ struct drm_fb_helper { struct work_struct resume_work; /** + * @lock: + * + * Top-level FB helper lock. This protects all internal data structures + * and lists, such as @connector_info and @crtc_info. + * + * FIXME: fbdev emulation locking is a mess and long term we want to + * protect all helper internal state with this lock as well as reduce + * core KMS locking as much as possible. + */ + struct mutex lock; + + /** * @kernel_fb_list: * * Entry on the global kernel_fb_helper_list, used for kgdb entry/exit.