From patchwork Wed Dec 12 13:07:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 1866391 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 3CEE94006E for ; Wed, 12 Dec 2012 13:55:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1D37DE65AE for ; Wed, 12 Dec 2012 05:55:54 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ee0-f49.google.com (mail-ee0-f49.google.com [74.125.83.49]) by gabe.freedesktop.org (Postfix) with ESMTP id 43441E610E for ; Wed, 12 Dec 2012 05:13:07 -0800 (PST) Received: by mail-ee0-f49.google.com with SMTP id c4so428749eek.36 for ; Wed, 12 Dec 2012 05:13:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=hp6M1ZBy4732vjRQZgjGRQ1j+xS8ay3rZ0DiuKNhDwM=; b=bNGtwwfhNRLD4nX5WSklZzhtPXzCmS1pNV9S37sG7nb68M4TgfyWmujHC0GwRue+qA TNPa9x/0HBJEWKgfAirle5gWJNl0rF3WAZJfPd39m1rR6UrQOWcxd6LLIdbQUSYTVhAC 8b7KPi1M0byt9FskJ2vtU8NYjlZ9uiH/plIwU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=hp6M1ZBy4732vjRQZgjGRQ1j+xS8ay3rZ0DiuKNhDwM=; b=epGf0GZDCRd569nK82Kw+haSnCJpiCkzXfZBW1i66fzikawKbDW1KIXRr3C5yFuWEh UsmfvJT4uaQXvIdIjiJv4l3nBCzjyYrVs7vGtY6GYwBp2XzN9PsmqyxLBnL1QwGZnIaT 01oH9LjjhPnEmTx4cKs8RxVqR8hnDS+f6Nfmcr4+BAACk+TBfwwj75PKDFPPXAfq4Ufm cXPhOkB2OHAiWjkvZxfFmtSUc+FGVy8YnaDgwy0F/rudjVZq/sMoQxCDt+Nq88cjAQ2a YriOxJMFVpzFSIQg9x15On8ibro1qwK+PB5dQif6W95324FwVWpihi5mjx6T2VJ2DMae bT8w== Received: by 10.14.214.132 with SMTP id c4mr2704209eep.18.1355317665581; Wed, 12 Dec 2012 05:07:45 -0800 (PST) Received: from biers.ffwll.local (178-83-130-250.dynamic.hispeed.ch. [178.83.130.250]) by mx.google.com with ESMTPS id r1sm55868541eeo.2.2012.12.12.05.07.44 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 12 Dec 2012 05:07:45 -0800 (PST) From: Daniel Vetter To: DRI Development Subject: [PATCH 22/37] drm: nest modeset locks within fpriv->fbs_lock Date: Wed, 12 Dec 2012 14:07:02 +0100 Message-Id: <1355317637-16742-23-git-send-email-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1355317637-16742-1-git-send-email-daniel.vetter@ffwll.ch> References: <1355317637-16742-1-git-send-email-daniel.vetter@ffwll.ch> X-Gm-Message-State: ALoCoQlVFQUEVTv0hwPFIm/+jvETAllxn1mKFrDgIt9tldWLfVQpqSEQmjWi1S3/NcVSZpPshPe0 Cc: Nouveau Dev , Intel Graphics Development , Radeon Dev , Daniel Vetter 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+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Atm we still need to unconditionally take the modeset locks in the rmfb paths. But eventually we only want to take them if there are other users around as a slow-path. This way sane userspace avoids blocking on edid reads and other stuff in rmfb if it ensures that the fb isn't used anywhere by a crtc/plane. We can do a quick check for such other users once framebuffers are properly refcounting by locking at the refcount - if it's more than 1, there are other users left. Again, rmfb racing against other ioctls isn't a real problem, userspace is allowed to shoot its foot. This patch just prepares this by moving the modeset locks to nest within fpriv->fbs_lock. Now the distinction between the fbs_lock and the device-global fb_lock is clear, since we need to hold the fbs_lock outside of any modeset_locks in fb_release. Signed-off-by: Daniel Vetter --- drivers/gpu/drm/drm_crtc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 20ccdc4..33e95bb 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -2266,13 +2266,13 @@ int drm_mode_addfb(struct drm_device *dev, drm_modeset_unlock_all(dev); return PTR_ERR(fb); } + drm_modeset_unlock_all(dev); mutex_lock(&file_priv->fbs_lock); or->fb_id = fb->base.id; list_add(&fb->filp_head, &file_priv->fbs); DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id); mutex_unlock(&file_priv->fbs_lock); - drm_modeset_unlock_all(dev); return ret; } @@ -2449,6 +2449,7 @@ int drm_mode_addfb2(struct drm_device *dev, drm_modeset_unlock_all(dev); return PTR_ERR(fb); } + drm_modeset_unlock_all(dev); mutex_lock(&file_priv->fbs_lock); r->fb_id = fb->base.id; @@ -2456,7 +2457,6 @@ int drm_mode_addfb2(struct drm_device *dev, DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id); mutex_unlock(&file_priv->fbs_lock); - drm_modeset_unlock_all(dev); return ret; } @@ -2651,7 +2651,6 @@ void drm_fb_release(struct drm_file *priv) struct drm_device *dev = priv->minor->dev; struct drm_framebuffer *fb, *tfb; - drm_modeset_lock_all(dev); mutex_lock(&priv->fbs_lock); list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) { @@ -2663,10 +2662,11 @@ void drm_fb_release(struct drm_file *priv) list_del_init(&fb->filp_head); /* This will also drop the fpriv->fbs reference. */ + drm_modeset_lock_all(dev); drm_framebuffer_remove(fb); + drm_modeset_unlock_all(dev); } mutex_unlock(&priv->fbs_lock); - drm_modeset_unlock_all(dev); } /**