Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2893112yba; Mon, 22 Apr 2019 15:09:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5ZJe5qpiIA8TX4T8OgdwpnULNGj4OCWegdmJiIQ/bKg2MXjlmIntBXbLmkJ9Bt6ef6tp4 X-Received: by 2002:a17:902:7e05:: with SMTP id b5mr23163234plm.127.1555970961501; Mon, 22 Apr 2019 15:09:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555970961; cv=none; d=google.com; s=arc-20160816; b=C9veF+LAZVxHuDgMUvtgnlA83HJi2ajUsIx49kguHp2Y6u+5nn4Fgfi5TFOMLIwaT/ i3eNrN7coYvWCZqz4k1VJl3t1VRgt4wjrh9zceiNAx7HWxYmGfI10vuZYp9E0Shfi/bD Db7bwVIJUeYiL+/XbxPnFfIaxsZkgN0TkbKrrw/sVQ1475uXFsmIvBtCbJw21kj/Xbau m8Oxb9OSDNV4GM0ncNzvVwSocIqxMRyxuLZy5AeV7I55JW6puHFRSQF1izQRjh4o+dQx P21hB4/cXx4CrZ/EiYTf/4YxCxEjOpTmgoanmgUvhXlsvRw4Y7cgywpUC3pV4n//kQIb fZCw== 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=uLDPK2B770PCipCxJX48Ng/P7sNRT7AX39y3de3gxq0=; b=Oy3+HKE+rWJbKeiWXWipwyO0scns4+jHe7n/VjubmLjOEcIQcEmHUD156vd+0wSTE9 1zyHWhjyl4ie2Hxym+Ao69Cj5WqP2eaoix06CuD90vVhKKt6JhFSBAFex423dZNhnmrG nklKw/G+QWHiCWdlPlKtDGOFK3ex4v2rkCB0oFJfHNywA/okk4Z/wym/ssFcpwWD1D4p JCtud6Bab7VRmU/ayd/3f+Y2lMLAxEu6ofeyf7n8tC5aGcljDFqcEI76jgD3u9Zk4Lmj 9L3BZ/bv0fvZH6LkVc7Sl/9ctNXG3s9NlhjiL6F5UbTi2WUtPbB1L56gZNhImu3xtbWM +RFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=czY76zCX; 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 y16si14006866plr.431.2019.04.22.15.08.58; Mon, 22 Apr 2019 15:09:21 -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=czY76zCX; 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 S1729313AbfDVTn5 (ORCPT + 99 others); Mon, 22 Apr 2019 15:43:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:44650 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729300AbfDVTnz (ORCPT ); Mon, 22 Apr 2019 15:43:55 -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 8672A218E0; Mon, 22 Apr 2019 19:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962234; bh=B9hfitLqx3c6/Qrr9wS8Ka+HLiv37qnrs9TxLrLSLG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=czY76zCXwD/JCM5SBg9kJmsNjY5Dr5CKRxj7Vr4WIT3h7PVihZHk6KTL/zJXnE4No QAJwpLX2oShi+OlhXaIZHrlvndd8BRaL5PsZGKwTiaTwHqH/Kz8kBwXZ/MEehIEKgv jt3dGU6ZRY7cRKZ8/heWZAjRV6xcYjsN+l/TYjUo= 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 5.0 54/98] drm: Fix drm_release() and device unplug Date: Mon, 22 Apr 2019 15:41:21 -0400 Message-Id: <20190422194205.10404-54-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194205.10404-1-sashal@kernel.org> References: <20190422194205.10404-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 12e5e2be7890..7a59b8b3ed5a 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 46f48f245eb5..3f20f598cd7c 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