From patchwork Sat May 24 18:30:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 4237961 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D213FBF90B for ; Sat, 24 May 2014 18:31:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 01C082022D for ; Sat, 24 May 2014 18:31:22 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id DA75120225 for ; Sat, 24 May 2014 18:31:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EE2D36E483; Sat, 24 May 2014 11:31:19 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qc0-f174.google.com (mail-qc0-f174.google.com [209.85.216.174]) by gabe.freedesktop.org (Postfix) with ESMTP id A04EF6E32E for ; Sat, 24 May 2014 11:31:18 -0700 (PDT) Received: by mail-qc0-f174.google.com with SMTP id c9so1961104qcz.5 for ; Sat, 24 May 2014 11:31:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=75C1xPGzwlaCZIoHWToXBfhm/lxC9taKnNPll7DMZlM=; b=kydqQML6v4ruPjhpUyHMDGH0RoTVHVhdDk0yA/st2NO3JXPddub+nLpDq+foYh8XLN f/iUZkkgspJeq/TzTwLmv0rmXbV9Rp101y9vNOLYm2RCwDg/NIE9xNMtlwkRkQx6jHNs f7rntVNmt9XVXOCn5SK6aN/Rdk+nEvKL48fc8vKn0NDAJEBigNMLf9v3JO4Xq1nULYy4 XJadwSNZz2ex6cAJ8iSaevu3WB+4RcmZ3lp5KFc1VXJCcyx/ZGv7GCmAN/LjKBK5itlv /XPMOSmtkz0v/yQmbHBSx/C4wbPPrbEEGy6gWQjRpnrWtbS1t6fZeXZUkbwdvc/kVTgu r7OA== X-Received: by 10.140.19.76 with SMTP id 70mr17296639qgg.82.1400956278238; Sat, 24 May 2014 11:31:18 -0700 (PDT) Received: from localhost (pool-108-20-252-175.bstnma.east.verizon.net. [108.20.252.175]) by mx.google.com with ESMTPSA id y3sm11117945qaj.49.2014.05.24.11.31.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 May 2014 11:31:17 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH 16/17] drm: more conservative locking Date: Sat, 24 May 2014 14:30:25 -0400 Message-Id: <1400956226-28053-17-git-send-email-robdclark@gmail.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1400956226-28053-1-git-send-email-robdclark@gmail.com> References: <1400956226-28053-1-git-send-email-robdclark@gmail.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 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.7 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 TODO possibly just squash this back into "convert crtc/plane to atomic".. This reintroduces drm_modeset_lock_all() in a places that had not been converted to more fine grained locking (setcrtc, setplane, etc). This makes the locking equivalent to before. Note that since mode_config.mutex is a drm_modeset_lock, the lock is automatically dropped at the end of the atomic update. Signed-off-by: Rob Clark --- drivers/gpu/drm/drm_crtc.c | 21 +++++++++++++++++++++ drivers/gpu/drm/drm_fb_helper.c | 18 +++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 972af76..4e3b527 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -709,14 +709,22 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb) * in this manner. */ if (atomic_read(&fb->refcount.refcount) > 1) { + struct drm_mode_config *config = &dev->mode_config; struct drm_atomic_state *state; + int ret; +retry: state = dev->driver->atomic_begin(dev, 0); if (IS_ERR(state)) { DRM_ERROR("failed to disable crtc and/or plane when fb was deleted\n"); return; } + ret = drm_modeset_lock(&config->mutex, &state->acquire_ctx) || + drm_modeset_lock_all_crtcs(dev, &state->acquire_ctx); + if (ret) + goto out; + /* remove from any plane */ list_for_each_entry(plane, &dev->mode_config.plane_list, head) { if (plane->fb == fb) @@ -729,7 +737,10 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb) else dev->driver->atomic_commit(dev, state); +out: dev->driver->atomic_end(dev, state); + if (ret == -EDEADLK) + goto retry; } drm_framebuffer_unreference(fb); @@ -2595,6 +2606,11 @@ retry: if (IS_ERR(state)) return PTR_ERR(state); + ret = drm_modeset_lock(&config->mutex, &state->acquire_ctx) || + drm_modeset_lock_all_crtcs(dev, &state->acquire_ctx); + if (ret) + goto out; + plane = drm_plane_find(dev, plane_req->plane_id); if (!plane) { DRM_DEBUG_KMS("Unknown plane ID %d\n", @@ -2810,6 +2826,11 @@ retry: if (IS_ERR(state)) return PTR_ERR(state); + ret = drm_modeset_lock(&config->mutex, &state->acquire_ctx) || + drm_modeset_lock_all_crtcs(dev, &state->acquire_ctx); + if (ret) + goto out; + /* If connectors change, we need to check if we need to steal one * from another CRTC.. setcrtc makes this implicit, but atomic * treats it as an error so we need to handle here: diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 3815e1a..4dc22cf 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -287,11 +288,13 @@ bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper *fb_helper, bool lockless) { struct drm_device *dev = fb_helper->dev; + struct drm_mode_config *config = &dev->mode_config; struct drm_plane *plane; bool error = false; struct drm_atomic_state *state; - int i; + int ret, i; +retry: state = dev->driver->atomic_begin(dev, lockless ? DRM_MODE_ATOMIC_NOLOCK : 0); if (IS_ERR(state)) { @@ -299,6 +302,11 @@ bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper *fb_helper, return true; } + ret = drm_modeset_lock(&config->mutex, &state->acquire_ctx) || + drm_modeset_lock_all_crtcs(dev, &state->acquire_ctx); + if (ret) + goto out; + list_for_each_entry(plane, &dev->mode_config.plane_list, head) if (plane->type != DRM_PLANE_TYPE_PRIMARY) drm_plane_force_disable(plane, state); @@ -309,7 +317,12 @@ bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper *fb_helper, else dev->driver->atomic_commit(dev, state); +out: dev->driver->atomic_end(dev, state); + if (ret == -EDEADLK) + goto retry; + + drm_modeset_lock_all(dev); for (i = 0; i < fb_helper->crtc_count; i++) { struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set; @@ -326,6 +339,9 @@ bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper *fb_helper, if (ret) error = true; } + + drm_modeset_unlock_all(dev); + return error; } EXPORT_SYMBOL(drm_fb_helper_restore_fbdev_mode);