Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp7355981yba; Thu, 2 May 2019 08:31:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkCFSG1NZvx0RVeFJCgVCClIr2q9Z1tctYHz8hJvp2Vi3AWuydQZ2tDb3jusmgfSLcBWZ5 X-Received: by 2002:aa7:8b83:: with SMTP id r3mr4847475pfd.248.1556811102338; Thu, 02 May 2019 08:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556811102; cv=none; d=google.com; s=arc-20160816; b=i4raX/fC+EJ6CSU5CQ5HgqF1K7p4q1/7gN690MjMK5wggb211TT0/C+57GEJKO7vd2 C6wCR8lXrlFaGqERqGOx+g0R8LMaDJYi9oCsFG4wFIi05GoWVIIJmOutYAg0yJO5/T44 qRHmK6alMrqCVdNqtPjHMZX0dlOmEFa718y3/JU+a+uIKta9POZCsCG/PiHX8WkLJpJt fbNlxnPTx14Zjihri6hwxAyd2HBSHTDuBhvulW6HEfBRE7YSBIWgybA8N1m0Uj30VLWn gYhvjfjhnrfSP8c4ErNgd4VfK7JeUynZG3K/w0UkHI2AYEalnR+jPfm4MaGvLiVjzngd FwAg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IqcFLklnfwKRW1W3zEfqQi9zB7XV+MiQzUfMe1/HK6k=; b=q626vpVfQBINKMYFuwjLSGI8JYQbxNYdFHpp2p51aOPnxVK4dwsPZnp7rSrQj35+PV NRMQujQZIiRc+Malvje/EzJWIqgldOKOkV7v4lvY7yAB4Dv7iU87S+HJblIAX4NO26rh LVyOipht3S5ziv6Xfh1Z6mJZ6AMwZ0Nnk+ZEX4+DHWLSJ6sX31JrLDeOclVIWLITB+pV GkdjrkdPX1L+qEPB/bauP7+qhugCsNmDeNO+etETJ7zc7A5OfdNbU95/ef9Xg8NYqbjZ BE1TJpx9jB24iRBM4IHRlmEP9uMpegw3nVaRwmo7304ee6zHX88aed0M2q0ugtz/wrqR b32Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DEy6oo8G; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9si907746pgh.206.2019.05.02.08.31.25; Thu, 02 May 2019 08:31:42 -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=DEy6oo8G; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728284AbfEBP2o (ORCPT + 99 others); Thu, 2 May 2019 11:28:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:46038 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727481AbfEBP2m (ORCPT ); Thu, 2 May 2019 11:28:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4936020B7C; Thu, 2 May 2019 15:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556810921; bh=PoPu/I84kFCzCWxj8UouCBzrxnj1cCJbzkgCqkMbJBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DEy6oo8Gra7qvffo7x4UPegKVfiemGDOBhTOjitD3gkwnrLab7ldckvPriyRD8A/W vEYDtQBntIqF+L/CXTEI61ay0v9ZUUsItCsIw2EQtlkSeBSGtEugcx1FZPSRfXpkkq sfxRdsV++/1WWmFMnDB2D1RDB+of92+KMbiP9apA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= , Oleksandr Andrushchenko , Daniel Vetter , Sean Paul , Dave Airlie , "Sasha Levin (Microsoft)" Subject: [PATCH 4.19 49/72] drm: Fix drm_release() and device unplug Date: Thu, 2 May 2019 17:21:11 +0200 Message-Id: <20190502143337.314286147@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190502143333.437607839@linuxfoundation.org> References: <20190502143333.437607839@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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