From patchwork Tue Jan 28 10:46:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11354071 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5BDA138C for ; Tue, 28 Jan 2020 10:46:20 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8482D2467E for ; Tue, 28 Jan 2020 10:46:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="L/4V0tvJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8482D2467E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 127CF6EDA9; Tue, 28 Jan 2020 10:46:14 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by gabe.freedesktop.org (Postfix) with ESMTPS id D93366EDA3 for ; Tue, 28 Jan 2020 10:46:10 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id p17so1983378wma.1 for ; Tue, 28 Jan 2020 02:46:10 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=t0yX9feTYHoQ26kAyvkIM1o6zex2wr+Y4O5/1d+GeeM=; b=L/4V0tvJyYf22EPpI1vdwLRrpTjo7j2ruthpY5rn8Er87MQT8PVQdl5E6MP/nyw07e o15EDP4Jdr+I1pUH822wxxuBtsp4J03y3BVLPniRzZ/rsqiuzal+gCuEjSbtwF7UWhns xqRkN082UiOqD8akoQsRCO9jrg3SF0ZF4yBsI= 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:mime-version:content-transfer-encoding; bh=t0yX9feTYHoQ26kAyvkIM1o6zex2wr+Y4O5/1d+GeeM=; b=MOCarMmRx3XqP8X0YGtTLwyItBYU7ebrTm1ctAQqcOkGWg4q+sl2RAJ6zcb1664xNB isD26ea7lRfeXxdQOcCIsar1aIBbqQAygnCL85+bxDoF51BmXMDGxsHIza61ABKpOQbP 3w6WwVlVL2ZJyZ2wQLWl4AEEH6JO0JUsPY8UzM5rcjUo69tsq14+I+uLTVOdk2NgyPB5 rhOZ1Pvrd6pQdsDhxEL2ycxNxTmrrgyOmUCi6uI3CgybKPWISvnASncz9xn+rOKiCUDt 5w4kGl4S1/+PtBq/7BKGX42Yp+IJhJbD79+BFAKOBUiSbH9183Yi57EDxSFj/8GNNWIf RW4w== X-Gm-Message-State: APjAAAX55IBYQ06zEfuxhNMyCh5Qn8THcTkSjjh+IUZL5+BixvpoHynP 7W2ce354ueDQwn5jL7M7ww8gWkq6cp6CIQ== X-Google-Smtp-Source: APXvYqwvIzJiRBU4E6PVgZmi3lFDEZU6Q+c1e4FDDtyZ414uDK5HkCj8AdBeDNMM/uAB2mt1HW3mog== X-Received: by 2002:a05:600c:108a:: with SMTP id e10mr4158517wmd.38.1580208369470; Tue, 28 Jan 2020 02:46:09 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o1sm24998733wrn.84.2020.01.28.02.46.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2020 02:46:08 -0800 (PST) From: Daniel Vetter To: DRI Development Date: Tue, 28 Jan 2020 11:46:00 +0100 Message-Id: <20200128104602.1459802-3-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200128104602.1459802-1-daniel.vetter@ffwll.ch> References: <20200128104602.1459802-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 3/4] drm: Push drm_global_mutex locking in drm_open X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Vetter , Daniel Vetter , Intel Graphics Development Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" We want to only take the BKL on crap drivers, but to know whether we have a crap driver we first need to look it up. Split this shuffle out from the main BKL-disabling patch, for more clarity. Since the minors are refcounted drm_minor_acquire is purely internal and this does not have a driver visible effect. v2: Push the locking even further into drm_open(), suggested by Chris. This gives us more symmetry with drm_release(), and maybe a futuer avenue where we make drm_globale_mutex locking (partially) opt-in like with drm_release_noglobal(). Cc: Chris Wilson Signed-off-by: Daniel Vetter Reviewed-by: Chris Wilson --- drivers/gpu/drm/drm_drv.c | 14 +++++--------- drivers/gpu/drm/drm_file.c | 6 ++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 8deff75b484c..05bdf0b9d2b3 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -1085,17 +1085,14 @@ static int drm_stub_open(struct inode *inode, struct file *filp) DRM_DEBUG("\n"); - mutex_lock(&drm_global_mutex); minor = drm_minor_acquire(iminor(inode)); - if (IS_ERR(minor)) { - err = PTR_ERR(minor); - goto out_unlock; - } + if (IS_ERR(minor)) + return PTR_ERR(minor); new_fops = fops_get(minor->dev->driver->fops); if (!new_fops) { err = -ENODEV; - goto out_release; + goto out; } replace_fops(filp, new_fops); @@ -1104,10 +1101,9 @@ static int drm_stub_open(struct inode *inode, struct file *filp) else err = 0; -out_release: +out: drm_minor_release(minor); -out_unlock: - mutex_unlock(&drm_global_mutex); + return err; } diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index 1075b3a8b5b1..d36cb74ebe0c 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -378,6 +378,8 @@ int drm_open(struct inode *inode, struct file *filp) if (IS_ERR(minor)) return PTR_ERR(minor); + mutex_unlock(&drm_global_mutex); + dev = minor->dev; if (!atomic_fetch_inc(&dev->open_count)) need_setup = 1; @@ -395,10 +397,14 @@ int drm_open(struct inode *inode, struct file *filp) goto err_undo; } } + + mutex_unlock(&drm_global_mutex); + return 0; err_undo: atomic_dec(&dev->open_count); + mutex_unlock(&drm_global_mutex); drm_minor_release(minor); return retcode; }