From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796306852; b=Z3mmBeaJFlREs7YkOxUGAlnAyGPQ3TArf47MtH+oAno/t/xnR/h04Kg8JpqnXA/gMu/Q IL+ZpzYslhs0swwJq2Mqyv7hcalTkeRol2R8E/nCZ9+w5dX9AfjMXOMra+M9FhfrE4yFP o9eFFnckpSC3i87hVQMhV0Jwr4WFgBxS3dxxOpTiWFpky7MKC1A3XINlb8xwSYBu/LZVr cKoo3dn77vamV4cDkkHexJzM0FAe4N9z19qM/zvA2QqoNWrwc6ZsWTEHtvsEcSyI3X49J qJUjBIxlu9v0y1vJYHL88TizFN4AZXW0RVwRMikZOVt12b5MHjzKsWvmaXmO9mtAbaA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796306852; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=1O/iWcpaDLDABo8zbg4rWRqu0twKXVtaRhQrbkT1TJY=; b=0YGy7+Xif02pPb2RlRfbFsxV3R6EISXojhGSBp3M5PScCP2FVya6/Cf7pUclvLr3mqzK Jwm7XUfIoe7gwfzEIgoIAY7/ul5LnPZYl45ijGTwsd5IvmLHGsDoba7LlfSjWK4NyWdWZ bjHmX6q/219r7CuekeHBiFGohn+wDFa1EokCt+UtdMMlYvOHyOnmIIZv1WQ+WmZWTynQX i8OlODH95HRAmMGH0HgoBJcAtxtd26NALW7nYRh72g2SEE1IRAxZ2aTFvaWP8ZRX6u8hQ YwY8eiSzCN1+MSncd49fmdGBQ5aw5+7Daa8vEu77mtzYMvnJ+6I9vV5yHVnZPxmCUyg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IUoBQ0FW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18AAA606A32C for ; Thu, 3 Dec 2026 14:07:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IUoBQ0FW Received: by smtp.kernel.org (Postfix) with ESMTPSA id 293561F00893; Thu, 3 Dec 2026 14:07:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796306851; bh=1O/iWcpaDLDABo8zbg4rWRqu0twKXVtaRhQrbkT1TJY=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=IUoBQ0FWB0DyZV+XoWfJ/ZU4/V8HW3VcFqdHKPDXp0gR3iMY457OVNmUVPTOXGUFp C04yqMPgUg4jS1W5WdhK+2vhoYkLuKq1iZBa+4t+Oex2wjDJta0R5ITY8T9Cu+hQ8u QgjXf57nObOhZ2GvvV/mEfSIMWPFwqAJGEDRjiXJAHlgIQanJWlW2JWBv7gWdVtka6 lIxbOPsssaY886lWi5ILl464CPfl2AxDEF+ADqnNJAb8VIO6lfJuFZl/An0eze1S3j hu0IaeEKwNGwU8PWycykTFH5/36PZZPsxgixw3Wpc5OnHHzecX1TX08B2X1arcSdTC w2iwdpHmcb6AQ== From: Maxime Ripard Date: Thu, 03 Dec 2026 15:07:19 +0100 Subject: [PATCH v13 1/9] drm/lease: Add a helper to tell whether a lease was revoked X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261203-drm-reset-state-flag-v13-1-b09f19f64e64@kernel.org> References: <20261203-drm-reset-state-flag-v13-0-b09f19f64e64@kernel.org> In-Reply-To: <20261203-drm-reset-state-flag-v13-0-b09f19f64e64@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Louis Chauvet , Haneen Mohammed , Melissa Wen Cc: Daniel Stone , Harry Wentland , Jocelyn Falempe , =?utf-8?q?Jonas_=C3=85dahl?= , =?utf-8?q?Michel_D=C3=A4nzer?= , Pekka Paalanen , Sebastian Wick , Simon Ser , Victoria Brekenfeld , Xaver Hugl , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Maxime Ripard X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3971; i=mripard@kernel.org; h=from:subject:message-id; bh=wRnV+wy9xwdTC2qKWH1mLvRkgp+R/JzXKyINvFvYY98=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDNmC5TNdd0auflnO6XvvXsHiGtkE1c6iraE88Xp802ILn b4dff2sYyoLgzAng6yYIssTmbDTy9sXVznYr/wBM4eVCWQIAxenAExklyVjfchCha+NyQu3Tnzw NXPzBXbdoHQhpdkXGDTfSIWEyrlNmLNtaZ1W5K9rG6vNJ0baGTiuZKz3+yJ9nIuRIdpnxc8FbtE LBF66imn+YTI01hDXseZNU7edun5SyrtKlf2H16Q9aa1I0gMA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D 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. Reviewed-by: Thomas Zimmermann Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_lease.c | 29 +++++++++++++++++++++++++++++ include/drm/drm_auth.h | 11 +++++++++++ include/drm/drm_lease.h | 2 ++ 3 files changed, 42 insertions(+) diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c index 5d2cf724cbd7..c3047934b81e 100644 --- a/drivers/gpu/drm/drm_lease.c +++ b/drivers/gpu/drm/drm_lease.c @@ -145,10 +145,37 @@ 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) { + scoped_guard(mutex, &master->dev->mode_config.idr_mutex) + ret = master->lease_revoked; + } + + 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 +342,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.1