Skip to content

Commit d793b8f

Browse files
desmondcheongzxdanvet
authored andcommitted
drm: clarify usage of drm leases
We make the following changes to the documentation of drm leases to make it easier to reason about their usage. In particular, we clarify the lifetime and locking rules of lease fields in drm_master: 1. Make it clear that &drm_device.mode_config.idr_mutex protects the lease idr and list structures for drm_master. The lessor field itself doesn't need to be protected as it doesn't change after it's set in drm_lease_create. 2. Add descriptions for the lifetime of lessors and leases. 3. Add an overview DOC: section in drm-uapi.rst that defines the terminology for drm leasing, and explains how leases work and why they're used. Signed-off-by: Desmond Cheong Zhi Xi <[email protected]> Reviewed-by: Daniel Vetter <[email protected]> Signed-off-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 7835ed6 commit d793b8f

File tree

3 files changed

+116
-11
lines changed

3 files changed

+116
-11
lines changed

Documentation/gpu/drm-uapi.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ Primary Nodes, DRM Master and Authentication
3737
.. kernel-doc:: include/drm/drm_auth.h
3838
:internal:
3939

40+
41+
.. _drm_leasing:
42+
43+
DRM Display Resource Leasing
44+
============================
45+
46+
.. kernel-doc:: drivers/gpu/drm/drm_lease.c
47+
:doc: drm leasing
48+
4049
Open-Source Userspace Requirements
4150
==================================
4251

drivers/gpu/drm/drm_lease.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,57 @@
1515
#include "drm_crtc_internal.h"
1616
#include "drm_internal.h"
1717

18+
/**
19+
* DOC: drm leasing
20+
*
21+
* DRM leases provide information about whether a DRM master may control a DRM
22+
* mode setting object. This enables the creation of multiple DRM masters that
23+
* manage subsets of display resources.
24+
*
25+
* The original DRM master of a device 'owns' the available drm resources. It
26+
* may create additional DRM masters and 'lease' resources which it controls
27+
* to the new DRM master. This gives the new DRM master control over the
28+
* leased resources until the owner revokes the lease, or the new DRM master
29+
* is closed. Some helpful terminology:
30+
*
31+
* - An 'owner' is a &struct drm_master that is not leasing objects from
32+
* another &struct drm_master, and hence 'owns' the objects. The owner can be
33+
* identified as the &struct drm_master for which &drm_master.lessor is NULL.
34+
*
35+
* - A 'lessor' is a &struct drm_master which is leasing objects to one or more
36+
* other &struct drm_master. Currently, lessees are not allowed to
37+
* create sub-leases, hence the lessor is the same as the owner.
38+
*
39+
* - A 'lessee' is a &struct drm_master which is leasing objects from some
40+
* other &struct drm_master. Each lessee only leases resources from a single
41+
* lessor recorded in &drm_master.lessor, and holds the set of objects that
42+
* it is leasing in &drm_master.leases.
43+
*
44+
* - A 'lease' is a contract between the lessor and lessee that identifies
45+
* which resources may be controlled by the lessee. All of the resources
46+
* that are leased must be owned by or leased to the lessor, and lessors are
47+
* not permitted to lease the same object to multiple lessees.
48+
*
49+
* The set of objects any &struct drm_master 'controls' is limited to the set
50+
* of objects it leases (for lessees) or all objects (for owners).
51+
*
52+
* Objects not controlled by a &struct drm_master cannot be modified through
53+
* the various state manipulating ioctls, and any state reported back to user
54+
* space will be edited to make them appear idle and/or unusable. For
55+
* instance, connectors always report 'disconnected', while encoders
56+
* report no possible crtcs or clones.
57+
*
58+
* Since each lessee may lease objects from a single lessor, display resource
59+
* leases form a tree of &struct drm_master. As lessees are currently not
60+
* allowed to create sub-leases, the tree depth is limited to 1. All of
61+
* these get activated simultaneously when the top level device owner changes
62+
* through the SETMASTER or DROPMASTER IOCTL, so &drm_device.master points to
63+
* the owner at the top of the lease tree (i.e. the &struct drm_master for which
64+
* &drm_master.lessor is NULL). The full list of lessees that are leasing
65+
* objects from the owner can be searched via the owner's
66+
* &drm_master.lessee_idr.
67+
*/
68+
1869
#define drm_for_each_lessee(lessee, lessor) \
1970
list_for_each_entry((lessee), &(lessor)->lessees, lessee_list)
2071

include/drm/drm_auth.h

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ struct drm_lock_data {
5858
* @refcount: Refcount for this master object.
5959
* @dev: Link back to the DRM device
6060
* @driver_priv: Pointer to driver-private information.
61-
* @lessor: Lease holder
62-
* @lessee_id: id for lessees. Owners always have id 0
63-
* @lessee_list: other lessees of the same master
64-
* @lessees: drm_masters leasing from this one
65-
* @leases: Objects leased to this drm_master.
66-
* @lessee_idr: All lessees under this owner (only used where lessor == NULL)
6761
*
6862
* Note that master structures are only relevant for the legacy/primary device
6963
* nodes, hence there can only be one per device, not one per drm_minor.
@@ -88,17 +82,68 @@ struct drm_master {
8882
struct idr magic_map;
8983
void *driver_priv;
9084

91-
/* Tree of display resource leases, each of which is a drm_master struct
92-
* All of these get activated simultaneously, so drm_device master points
93-
* at the top of the tree (for which lessor is NULL). Protected by
94-
* &drm_device.mode_config.idr_mutex.
85+
/**
86+
* @lessor:
87+
*
88+
* Lease grantor, only set if this &struct drm_master represents a
89+
* lessee holding a lease of objects from @lessor. Full owners of the
90+
* device have this set to NULL.
91+
*
92+
* The lessor does not change once it's set in drm_lease_create(), and
93+
* each lessee holds a reference to its lessor that it releases upon
94+
* being destroyed in drm_lease_destroy().
95+
*
96+
* See also the :ref:`section on display resource leasing
97+
* <drm_leasing>`.
9598
*/
96-
9799
struct drm_master *lessor;
100+
101+
/**
102+
* @lessee_id:
103+
*
104+
* ID for lessees. Owners (i.e. @lessor is NULL) always have ID 0.
105+
* Protected by &drm_device.mode_config's &drm_mode_config.idr_mutex.
106+
*/
98107
int lessee_id;
108+
109+
/**
110+
* @lessee_list:
111+
*
112+
* List entry of lessees of @lessor, where they are linked to @lessees.
113+
* Not used for owners. Protected by &drm_device.mode_config's
114+
* &drm_mode_config.idr_mutex.
115+
*/
99116
struct list_head lessee_list;
117+
118+
/**
119+
* @lessees:
120+
*
121+
* List of drm_masters leasing from this one. Protected by
122+
* &drm_device.mode_config's &drm_mode_config.idr_mutex.
123+
*
124+
* This list is empty if no leases have been granted, or if all lessees
125+
* have been destroyed. Since lessors are referenced by all their
126+
* lessees, this master cannot be destroyed unless the list is empty.
127+
*/
100128
struct list_head lessees;
129+
130+
/**
131+
* @leases:
132+
*
133+
* Objects leased to this drm_master. Protected by
134+
* &drm_device.mode_config's &drm_mode_config.idr_mutex.
135+
*
136+
* Objects are leased all together in drm_lease_create(), and are
137+
* removed all together when the lease is revoked.
138+
*/
101139
struct idr leases;
140+
141+
/**
142+
* @lessee_idr:
143+
*
144+
* All lessees under this owner (only used where @lessor is NULL).
145+
* Protected by &drm_device.mode_config's &drm_mode_config.idr_mutex.
146+
*/
102147
struct idr lessee_idr;
103148
/* private: */
104149
#if IS_ENABLED(CONFIG_DRM_LEGACY)

0 commit comments

Comments
 (0)