Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2844358yba; Mon, 22 Apr 2019 14:07:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqw7rgnEMgLvSow/heBk+EFe7DLC/78OS5QyBGpgmdW93GNv/gBpwo+FUVneuogmxmQvWdKF X-Received: by 2002:a63:165f:: with SMTP id 31mr21147667pgw.321.1555967270079; Mon, 22 Apr 2019 14:07:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555967270; cv=none; d=google.com; s=arc-20160816; b=I5AR/w4yD07mjjL3M8h5riJFAXXZMhsLKGASILV7DYOXCILHv7iOArVJfwQvvH4Hos 52kkNQzpt70CQkR4b/PJnZEPzrJXXL9e3Zm1EaP7neANWCUQG53wRrMMkVNXa+VzTZMC F9d0Oz4aqMfKXFl5f0uiCLW+r795BwL3YSqyGswYaIDNxsCQgCLfrlMuAkxZSKEt9Qc2 ji7S3Fd3ZhMlxyGPgzek4JXewu6lMpemrASGz7ilM+ANvSDpxGPnBlcPm05Md/ooblyv s0WCK3SJFUQlPDrT8XE6p0NkHbUZ7ifGouXy9ZCE/BBU1iS5luB/82Rj6lGnSl9Li6MW fiGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PtKeu2tKh51aqWFiK04m5TK3o0v15lxRtWmVMQPy/uE=; b=Mg675PcAzOP7gCM4Hk98CVPPnJ8+zDekOdJ/sZRyUXSeh5vSeKHZWpmIx+V6B6jkko Ri4L8dKvBfb3/KCMdSb+V1jTcck7PESC6mCyQhuPX1JZng/EXzMyYbE1fKCzh/cHtbLi qhQBWZ178u8Rj/lRdQ0q87f/kJoL7mqhRj+YnoTMBwAJCNyTiSk2lJ2I7vRy4bPFZFAT yLr8uZzRvLDCBc7RRH9IOz44fgqjkA0WI9p+4nQWL5y4UZlT3D+LvvPM8M6ryC8hX9ln 56NbNZIaN0rMuSL+jcmfCPP92yv0yU6L+sfqln8XFup5gD311FFWec5bWcmxefjvLCOd Qx8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0Gwq8AKZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z10si12797233pgu.172.2019.04.22.14.07.34; Mon, 22 Apr 2019 14:07:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0Gwq8AKZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730091AbfDVTqt (ORCPT + 99 others); Mon, 22 Apr 2019 15:46:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:49174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730081AbfDVTqr (ORCPT ); Mon, 22 Apr 2019 15:46:47 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4BB48218FD; Mon, 22 Apr 2019 19:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962407; bh=7xf2HOKjieMPIfHgmx1fgDO04wQwRRYzoYkayH4jh80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0Gwq8AKZaNvCjDJcFTf+g+RiAKX+zX/alCPsIbPjgDEJ69Nj9PWGOwXjSQr4spRum rtOcdEW9yxwo1pu6rvOuXmY8z3xA4WGpY7lWvqgdAal/V9Hi5ShWlNGBcGTqH4c2HD 68zTXu+b8b24GqhpXAb8YaKTT79fMJh+BkLaPSe0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= , Dave Airlie , Sasha Levin , dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 4.19 43/68] drm: Fix drm_release() and device unplug Date: Mon, 22 Apr 2019 15:44:51 -0400 Message-Id: <20190422194516.11634-43-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194516.11634-1-sashal@kernel.org> References: <20190422194516.11634-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Noralf Trønnes [ Upstream commit 3f04e0a6cfebf48152ac64502346cdc258811f79 ] If userspace has open fd(s) when drm_dev_unplug() is run, it will result in drm_dev_unregister() being called twice. First in drm_dev_unplug() and then later in drm_release() through the call to drm_put_dev(). Since userspace already holds a ref on drm_device through the drm_minor, it's not necessary to add extra ref counting based on no open file handles. Instead just drm_dev_put() unconditionally in drm_dev_unplug(). We now have this: - Userpace holds a ref on drm_device as long as there's open fd(s) - The driver holds a ref on drm_device as long as it's bound to the struct device When both sides are done with drm_device, it is released. Signed-off-by: Noralf Trønnes Reviewed-by: Oleksandr Andrushchenko Reviewed-by: Daniel Vetter Reviewed-by: Sean Paul Signed-off-by: Dave Airlie Link: https://patchwork.freedesktop.org/patch/msgid/20190208140103.28919-2-noralf@tronnes.org Signed-off-by: Sasha Levin (Microsoft) --- drivers/gpu/drm/drm_drv.c | 6 +----- drivers/gpu/drm/drm_file.c | 6 ++---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index ea4941da9b27..0201ccb22f4c 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -381,11 +381,7 @@ void drm_dev_unplug(struct drm_device *dev) synchronize_srcu(&drm_unplug_srcu); drm_dev_unregister(dev); - - mutex_lock(&drm_global_mutex); - if (dev->open_count == 0) - drm_dev_put(dev); - mutex_unlock(&drm_global_mutex); + drm_dev_put(dev); } EXPORT_SYMBOL(drm_dev_unplug); diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index ffa8dc35515f..e4ccb52c67ea 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -479,11 +479,9 @@ int drm_release(struct inode *inode, struct file *filp) drm_file_free(file_priv); - if (!--dev->open_count) { + if (!--dev->open_count) drm_lastclose(dev); - if (drm_dev_is_unplugged(dev)) - drm_put_dev(dev); - } + mutex_unlock(&drm_global_mutex); drm_minor_release(minor); -- 2.19.1