From patchwork Wed Nov 20 20:48:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 3215401 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 25A50C045B for ; Wed, 20 Nov 2013 20:48:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CCC232076B for ; Wed, 20 Nov 2013 20:48:38 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 4927B20752 for ; Wed, 20 Nov 2013 20:48:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AE799FD52E; Wed, 20 Nov 2013 12:48:33 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qe0-f50.google.com (mail-qe0-f50.google.com [209.85.128.50]) by gabe.freedesktop.org (Postfix) with ESMTP id B62A5FD428 for ; Wed, 20 Nov 2013 12:48:29 -0800 (PST) Received: by mail-qe0-f50.google.com with SMTP id 1so6706072qee.9 for ; Wed, 20 Nov 2013 12:48:29 -0800 (PST) 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=ygBcuYB83V+C3fgkkJCBliQEbwTI8IE5+SO9gQ86R8Y=; b=UVhusBvaYtOOwDojMmZyrLbUvTxl11qeq7JV02w/qG+FXb4EAy1vBSiP5QixtEuGUT waQWRJJ8D1dg/mD6FeJI0/tejldvgpRdIuYXCU2w9y5Rofh/Xqh/ouyeRiSOAC5OOLsz nJYtXqaKEaCpAtnoiZwXO3OVYxBoFL8pADK+1HUWYmhQ3PdBIzjJY5CN02U9kiW7586G dt++RGbL9qPyuiZxUt9NQZvP9HwZmSMEw7nShyU5QAZ+LHpz/YkarM2fROlQ/4tBBTTJ 1U1y5EaqIQOoajhMEanHXM+1V0AhtiMLMDbqr8g6iJuN5pisfM0PrnS3+7h6PUBdVxbQ k9BA== X-Received: by 10.224.67.200 with SMTP id s8mr5005529qai.75.1384980509174; Wed, 20 Nov 2013 12:48:29 -0800 (PST) Received: from localhost (pool-108-20-250-166.bstnma.east.verizon.net. [108.20.250.166]) by mx.google.com with ESMTPSA id p17sm258029qak.4.2013.11.20.12.48.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Nov 2013 12:48:28 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [RFCv3 02/14] drm: convert crtc to ww_mutex Date: Wed, 20 Nov 2013 15:48:01 -0500 Message-Id: <1384980493-25499-3-git-send-email-robdclark@gmail.com> X-Mailer: git-send-email 1.8.4.2 In-Reply-To: <1384980493-25499-1-git-send-email-robdclark@gmail.com> References: <1384980493-25499-1-git-send-email-robdclark@gmail.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.6 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 At the moment, this doesn't do anything. But for atomic we will have an ww_acquire_ctx associated with the state, to simplify the locking and avoid potential deadlock when we cannot control the locking order. --- drivers/gpu/drm/drm_crtc.c | 20 +++++++++++--------- drivers/gpu/drm/i915/intel_display.c | 16 ++++++++-------- drivers/gpu/drm/omapdrm/omap_crtc.c | 10 +++++----- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 12 ++++++++---- include/drm/drm_crtc.h | 3 ++- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 81ac351..55f37db 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -52,7 +52,7 @@ void drm_modeset_lock_all(struct drm_device *dev) mutex_lock(&dev->mode_config.mutex); list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) - mutex_lock_nest_lock(&crtc->mutex, &dev->mode_config.mutex); + mutex_lock_nest_lock(&crtc->mutex.base, &dev->mode_config.mutex); } EXPORT_SYMBOL(drm_modeset_lock_all); @@ -65,7 +65,7 @@ void drm_modeset_unlock_all(struct drm_device *dev) struct drm_crtc *crtc; list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) - mutex_unlock(&crtc->mutex); + ww_mutex_unlock(&crtc->mutex); mutex_unlock(&dev->mode_config.mutex); } @@ -84,7 +84,7 @@ void drm_warn_on_modeset_not_all_locked(struct drm_device *dev) return; list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) - WARN_ON(!mutex_is_locked(&crtc->mutex)); + WARN_ON(!ww_mutex_is_locked(&crtc->mutex)); WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); } @@ -613,6 +613,8 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb) } EXPORT_SYMBOL(drm_framebuffer_remove); +static DEFINE_WW_CLASS(crtc_ww_class); + /** * drm_crtc_init - Initialise a new CRTC object * @dev: DRM device @@ -634,8 +636,8 @@ int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, crtc->invert_dimensions = false; drm_modeset_lock_all(dev); - mutex_init(&crtc->mutex); - mutex_lock_nest_lock(&crtc->mutex, &dev->mode_config.mutex); + ww_mutex_init(&crtc->mutex, &crtc_ww_class); + mutex_lock_nest_lock(&crtc->mutex.base, &dev->mode_config.mutex); ret = drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC); if (ret) @@ -2284,7 +2286,7 @@ static int drm_mode_cursor_common(struct drm_device *dev, } crtc = obj_to_crtc(obj); - mutex_lock(&crtc->mutex); + ww_mutex_lock(&crtc->mutex, NULL); if (req->flags & DRM_MODE_CURSOR_BO) { if (!crtc->funcs->cursor_set && !crtc->funcs->cursor_set2) { ret = -ENXIO; @@ -2308,7 +2310,7 @@ static int drm_mode_cursor_common(struct drm_device *dev, } } out: - mutex_unlock(&crtc->mutex); + ww_mutex_unlock(&crtc->mutex); return ret; @@ -3657,7 +3659,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, return -ENOENT; crtc = obj_to_crtc(obj); - mutex_lock(&crtc->mutex); + ww_mutex_lock(&crtc->mutex, NULL); if (crtc->fb == NULL) { /* The framebuffer is currently unbound, presumably * due to a hotplug event, that userspace has not @@ -3741,7 +3743,7 @@ out: drm_framebuffer_unreference(fb); if (old_fb) drm_framebuffer_unreference(old_fb); - mutex_unlock(&crtc->mutex); + ww_mutex_unlock(&crtc->mutex); return ret; } diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index 3cddd50..741188f 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -2232,11 +2232,11 @@ void intel_display_handle_reset(struct drm_device *dev) list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { struct intel_crtc *intel_crtc = to_intel_crtc(crtc); - mutex_lock(&crtc->mutex); + ww_mutex_lock(&crtc->mutex, NULL); if (intel_crtc->active) dev_priv->display.update_plane(crtc, crtc->fb, crtc->x, crtc->y); - mutex_unlock(&crtc->mutex); + ww_mutex_unlock(&crtc->mutex); } } @@ -7550,7 +7550,7 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector, if (encoder->crtc) { crtc = encoder->crtc; - mutex_lock(&crtc->mutex); + ww_mutex_lock(&crtc->mutex, NULL); old->dpms_mode = connector->dpms; old->load_detect_temp = false; @@ -7581,7 +7581,7 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector, return false; } - mutex_lock(&crtc->mutex); + ww_mutex_lock(&crtc->mutex, NULL); intel_encoder->new_crtc = to_intel_crtc(crtc); to_intel_connector(connector)->new_encoder = intel_encoder; @@ -7609,7 +7609,7 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector, DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); if (IS_ERR(fb)) { DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); - mutex_unlock(&crtc->mutex); + ww_mutex_unlock(&crtc->mutex); return false; } @@ -7617,7 +7617,7 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector, DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); if (old->release_fb) old->release_fb->funcs->destroy(old->release_fb); - mutex_unlock(&crtc->mutex); + ww_mutex_unlock(&crtc->mutex); return false; } @@ -7648,7 +7648,7 @@ void intel_release_load_detect_pipe(struct drm_connector *connector, drm_framebuffer_unreference(old->release_fb); } - mutex_unlock(&crtc->mutex); + ww_mutex_unlock(&crtc->mutex); return; } @@ -7656,7 +7656,7 @@ void intel_release_load_detect_pipe(struct drm_connector *connector, if (old->dpms_mode != DRM_MODE_DPMS_ON) connector->funcs->dpms(connector, old->dpms_mode); - mutex_unlock(&crtc->mutex); + ww_mutex_unlock(&crtc->mutex); } static int i9xx_pll_refclk(struct drm_device *dev, diff --git a/drivers/gpu/drm/omapdrm/omap_crtc.c b/drivers/gpu/drm/omapdrm/omap_crtc.c index 5dd22ab..c09d29f 100644 --- a/drivers/gpu/drm/omapdrm/omap_crtc.c +++ b/drivers/gpu/drm/omapdrm/omap_crtc.c @@ -307,13 +307,13 @@ static void page_flip_worker(struct work_struct *work) struct drm_display_mode *mode = &crtc->mode; struct drm_gem_object *bo; - mutex_lock(&crtc->mutex); + ww_mutex_lock(&crtc->mutex, NULL); omap_plane_mode_set(omap_crtc->plane, crtc, crtc->fb, 0, 0, mode->hdisplay, mode->vdisplay, crtc->x << 16, crtc->y << 16, mode->hdisplay << 16, mode->vdisplay << 16, vblank_cb, crtc); - mutex_unlock(&crtc->mutex); + ww_mutex_unlock(&crtc->mutex); bo = omap_framebuffer_bo(crtc->fb, 0); drm_gem_object_unreference_unlocked(bo); @@ -447,7 +447,7 @@ static void apply_worker(struct work_struct *work) * the callbacks and list modification all serialized * with respect to modesetting ioctls from userspace. */ - mutex_lock(&crtc->mutex); + ww_mutex_lock(&crtc->mutex, NULL); dispc_runtime_get(); /* @@ -492,7 +492,7 @@ static void apply_worker(struct work_struct *work) out: dispc_runtime_put(); - mutex_unlock(&crtc->mutex); + ww_mutex_unlock(&crtc->mutex); } int omap_crtc_apply(struct drm_crtc *crtc, @@ -500,7 +500,7 @@ int omap_crtc_apply(struct drm_crtc *crtc, { struct omap_crtc *omap_crtc = to_omap_crtc(crtc); - WARN_ON(!mutex_is_locked(&crtc->mutex)); + WARN_ON(!ww_mutex_is_locked(&crtc->mutex)); /* no need to queue it again if it is already queued: */ if (apply->queued) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c index f91447c..7b3bf18 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c @@ -186,7 +186,7 @@ int vmw_du_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv, * can do this since the caller in the drm core doesn't check anything * which is protected by any looks. */ - mutex_unlock(&crtc->mutex); + ww_mutex_unlock(&crtc->mutex); drm_modeset_lock_all(dev_priv->dev); /* A lot of the code assumes this */ @@ -251,7 +251,9 @@ int vmw_du_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv, ret = 0; out: drm_modeset_unlock_all(dev_priv->dev); - mutex_lock(&crtc->mutex); +// XXX umm, we probably need the state object here to properly +// re-aquire the lock.. + ww_mutex_lock(&crtc->mutex, NULL); return ret; } @@ -272,7 +274,7 @@ int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) * can do this since the caller in the drm core doesn't check anything * which is protected by any looks. */ - mutex_unlock(&crtc->mutex); + ww_mutex_unlock(&crtc->mutex); drm_modeset_lock_all(dev_priv->dev); vmw_cursor_update_position(dev_priv, shown, @@ -280,7 +282,9 @@ int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) du->cursor_y + du->hotspot_y); drm_modeset_unlock_all(dev_priv->dev); - mutex_lock(&crtc->mutex); +// XXX umm, we probably need the state object here to properly +// re-aquire the lock.. + ww_mutex_lock(&crtc->mutex, NULL); return 0; } diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 0ca684a..3650254 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -417,7 +418,7 @@ struct drm_crtc { * state, ...) and a write lock for everything which can be update * without a full modeset (fb, cursor data, ...) */ - struct mutex mutex; + struct ww_mutex mutex; struct drm_mode_object base;