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: 1867461 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id 7DE68DF215 for ; Wed, 12 Dec 2012 14:42:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5331EE661E for ; Wed, 12 Dec 2012 06:42:05 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-ea0-f177.google.com (mail-ea0-f177.google.com [209.85.215.177]) by gabe.freedesktop.org (Postfix) with ESMTP id 8A7F1E613D for ; Wed, 12 Dec 2012 05:15:49 -0800 (PST) Received: by mail-ea0-f177.google.com with SMTP id c10so222309eaa.36 for ; Wed, 12 Dec 2012 05:15:48 -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=H3QhzUjC1+wAu2PntEFozCPE/f+F4oiSxSPzGXdFUtVcHXXJMoLLqCGoJOGNrg2rd9 NRv21/3Bv5dBo1xuPv5/KO1Cm+wClCovW/wsFLjDLPC9YpsN1rR/FSMbEebXVHCQwiUk TC5q1Y/hZTqWF9+cpdDjtqICtENut9/vp6Cbzv24GguzovwPQzZtZTeFWlL16EdOZ5Jh YkqFGnRS1/DIdf1wx+To7rJGag6x3/mDHJwcGuFWGiXU/qMEhCBfMDvWGD5l0ajdAuWV VJNVx1H6dH1/kXdvbZe98S2ebrRVxPonYhsKM0lwhtLrJXKbQHJ8vh+lFbVozI93SpE4 lR1w== 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 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: ALoCoQnNOlhNGVqKgwuNAoYmK+z/o7D0rFwZnGWXWIvNNHUYo8CydfsYKsDijfIVRJY0g851fvF/ Cc: Nouveau Dev , Intel Graphics Development , Radeon Dev , Daniel Vetter Subject: [Intel-gfx] [PATCH 22/37] drm: nest modeset locks within fpriv->fbs_lock X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=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); } /**