From: Maxime Ripard <mripard@kernel.org>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>,
Simona Vetter <simona@ffwll.ch>,
Louis Chauvet <louis.chauvet@bootlin.com>,
Haneen Mohammed <hamohammed.sa@gmail.com>,
Melissa Wen <melissa.srw@gmail.com>
Cc: "Daniel Stone" <daniels@collabora.com>,
"Harry Wentland" <harry.wentland@amd.com>,
"Jocelyn Falempe" <jfalempe@redhat.com>,
"Jonas Ådahl" <jadahl@redhat.com>,
"Michel Dänzer" <mdaenzer@redhat.com>,
"Pekka Paalanen" <pekka.paalanen@collabora.com>,
"Sebastian Wick" <sebastian.wick@redhat.com>,
"Simon Ser" <contact@emersion.fr>,
"Victoria Brekenfeld" <victoria@system76.com>,
"Xaver Hugl" <xaver.hugl@kde.org>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
"Maxime Ripard" <mripard@kernel.org>
Subject: [PATCH v9 03/10] drm/lease: Add a helper to tell whether a lease was revoked
Date: Tue, 10 Nov 2026 17:02:50 +0100 [thread overview]
Message-ID: <20261110-drm-reset-state-flag-v9-3-ddb0e26324a0@kernel.org> (raw)
In-Reply-To: <20261110-drm-reset-state-flag-v9-0-ddb0e26324a0@kernel.org>
drm_lease_held() only answers whether a given object is part of a lease,
and the answer can change from one call to the next. Code that needs to
look at several objects in a row has no way to tell whether the lease it
has been checking against is still around by the time it is done.
Add a helper reporting whether a lease has been revoked, so that such
code can bail out instead of acting on a lease that went away.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/gpu/drm/drm_lease.c | 30 ++++++++++++++++++++++++++++++
include/drm/drm_auth.h | 11 +++++++++++
include/drm/drm_lease.h | 2 ++
3 files changed, 43 insertions(+)
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 5d2cf724cbd7..f2370a9a18fc 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -145,10 +145,38 @@ bool drm_lease_held(struct drm_file *file_priv, int id)
out:
drm_master_put(&master);
return ret;
}
+/*
+ * Checks whether the file is a lessee whose lease has been revoked. A
+ * lease is always revoked as a whole, but empty leases can also be
+ * created on purpose, so the revocation is tracked explicitly in
+ * drm_master rather than inferred from an empty lease.
+ */
+bool drm_lease_revoked(struct drm_file *file_priv)
+{
+ struct drm_master *master;
+ bool ret = false;
+
+ if (!file_priv)
+ return false;
+
+ master = drm_file_get_master(file_priv);
+ if (!master)
+ return false;
+
+ if (master->lessor) {
+ mutex_lock(&master->dev->mode_config.idr_mutex);
+ ret = master->lease_revoked;
+ mutex_unlock(&master->dev->mode_config.idr_mutex);
+ }
+
+ drm_master_put(&master);
+ return ret;
+}
+
/*
* Given a bitmask of crtcs to check, reconstructs a crtc mask based on the
* crtcs which are visible through the specified file.
*/
uint32_t drm_lease_filter_crtcs(struct drm_file *file_priv, uint32_t crtcs_in)
@@ -315,10 +343,12 @@ static void _drm_lease_revoke(struct drm_master *top)
/* Evacuate the lease */
idr_for_each_entry(&master->leases, entry, object)
idr_remove(&master->leases, object);
+ master->lease_revoked = true;
+
/* Depth-first list walk */
/* Down */
if (!list_empty(&master->lessees)) {
master = list_first_entry(&master->lessees, struct drm_master, lessee_list);
diff --git a/include/drm/drm_auth.h b/include/drm/drm_auth.h
index 50131383ed81..b1962f197b05 100644
--- a/include/drm/drm_auth.h
+++ b/include/drm/drm_auth.h
@@ -118,10 +118,21 @@ struct drm_master {
* Objects are leased all together in drm_lease_create(), and are
* removed all together when the lease is revoked.
*/
struct idr leases;
+ /**
+ * @lease_revoked:
+ *
+ * Whether the lease of this drm_master has been revoked. Since empty
+ * leases can be created on purpose, an empty &leases doesn't imply a
+ * revocation, so it has to be tracked explicitly. Never cleared once
+ * set: a revoked master cannot be leased anything again. Protected by
+ * &drm_device.mode_config's &drm_mode_config.idr_mutex.
+ */
+ bool lease_revoked;
+
/**
* @lessee_idr:
*
* All lessees under this owner (only used where @lessor is NULL).
* Protected by &drm_device.mode_config's &drm_mode_config.idr_mutex.
diff --git a/include/drm/drm_lease.h b/include/drm/drm_lease.h
index 53545b4ca9ef..03f7ea36c37c 100644
--- a/include/drm/drm_lease.h
+++ b/include/drm/drm_lease.h
@@ -18,10 +18,12 @@ void drm_lease_destroy(struct drm_master *lessee);
bool drm_lease_held(struct drm_file *file_priv, int id);
bool _drm_lease_held(struct drm_file *file_priv, int id);
+bool drm_lease_revoked(struct drm_file *file_priv);
+
void drm_lease_revoke(struct drm_master *master);
uint32_t drm_lease_filter_crtcs(struct drm_file *file_priv, uint32_t crtcs);
int drm_mode_create_lease_ioctl(struct drm_device *dev,
--
2.56.0
next prev parent reply other threads:[~2026-11-10 16:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 16:02 [PATCH v9 00/10] drm: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
2026-11-10 16:02 ` [PATCH v9 01/10] drm/amd/display: Fix planes atomic_create_state implementation Maxime Ripard
2026-11-10 16:02 ` [PATCH v9 02/10] drm/atomic: Add drm_atomic_implements_create_state() helper Maxime Ripard
2026-11-10 16:02 ` Maxime Ripard [this message]
2026-11-10 16:02 ` [PATCH v9 04/10] drm/atomic: Allow filling a commit with pristine object states Maxime Ripard
2026-11-10 16:02 ` [PATCH v9 05/10] drm/tests: atomic: Add tests for drm_atomic_commit_fill_with_defaults() Maxime Ripard
2026-11-10 16:02 ` [PATCH v9 06/10] drm/amd/display: Take over the current stream and dc_state Maxime Ripard
2026-11-10 16:02 ` [PATCH v9 07/10] drm/vc4: Carry the HVS channel over to created CRTC states Maxime Ripard
2026-11-10 16:02 ` [PATCH v9 08/10] drm/msm/dpu1: Carry the mixers " Maxime Ripard
2026-11-10 16:02 ` [PATCH v9 09/10] drm/atomic-uapi: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
2026-11-10 16:02 ` [PATCH v9 10/10] drm/vkms: Add driver-specific plane property for testing Maxime Ripard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261110-drm-reset-state-flag-v9-3-ddb0e26324a0@kernel.org \
--to=mripard@kernel.org \
--cc=airlied@gmail.com \
--cc=contact@emersion.fr \
--cc=daniels@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hamohammed.sa@gmail.com \
--cc=harry.wentland@amd.com \
--cc=jadahl@redhat.com \
--cc=jfalempe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=louis.chauvet@bootlin.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mdaenzer@redhat.com \
--cc=melissa.srw@gmail.com \
--cc=pekka.paalanen@collabora.com \
--cc=sebastian.wick@redhat.com \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
--cc=victoria@system76.com \
--cc=xaver.hugl@kde.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®