drm: Add mode resource leasing
Subsystems (10)
cover drm: Add mode resource leasing
Here's a first cut of the proposed mode resource leasing code. What this does is allow an application to create a new drm_master which "leases" resources from an existing drm_master. This new drm_master can do whatever it likes with the resources it was granted, including setting modes, performing page_flip operations etc.
This can be used to run multiple compositors on the same GPU, each driving its own set of outputs. Examples of this include multi-user setups and virtual reality environments.
Because setting modes can consume 'hidden' resources within the GPU, it isn't entirely clear that letting multiple processes perform mode setting is a good idea or not. A process doing the usual test/render/commit sequence may find that the commit fails because some other process consumed necessary resources after the test was invoked. Daniel Vetter suggested that perhaps some kind of locking mechanism across this sequence might help, but that can lead to problems when a process fails to unlock. If someone wants to come up with a reasonable scheme here, that'd be great.
For now, I'll be working on the assumption that the lease holder will not set any modes, which will avoid the problematic case described above.
The series is broken into four patches in an attempt to make review a bit easier.
The trickiest bit of the code was in creating the new drm_master, which involved allocating a new file and fd and getting those initialized with the right reference counts on all of the related data structures. It "seems" to work, but it would be nice if someone with more experience in that part of the kernel could take a look at it. That's in the fourth patch.
The third patch hooks the lease checks into the other ioctls; that could use some review to make sure I didn't miss any needed checks.
-keith
PATCH 1/4 drm: Add new LEASE debug level
Separate out lease debugging from the core.
--- drivers/gpu/drm/drm_drv.c | 3 ++- include/drm/drmP.h | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_drv.c +2 -1
@@ -57,7 +57,8 @@ MODULE_PARM_DESC(debug, "Enable debug output, where each bit enables a debug cat"\t\tBit 2 (0x04) will enable KMS messages (modesetting code)\n" "\t\tBit 3 (0x08) will enable PRIME messages (prime code)\n" "\t\tBit 4 (0x10) will enable ATOMIC messages (atomic code)\n" -"\t\tBit 5 (0x20) will enable VBL messages (vblank code)"); +"\t\tBit 5 (0x20) will enable VBL messages (vblank code)\n" +"\t\tBit 7 (0x80) will enable LEASE messages (leasing code)");module_param_named (debug, drm_debug, int,0600 );static DEFINE_SPINLOCK (drm_minor_lock);
include/drm/drmP.h +4 -0
@@ -137,6 +137,7 @@ struct dma_buf_attachment;#define DRM_UT_ATOMIC 0x10#define DRM_UT_VBL 0x20#define DRM_UT_STATE 0x40 +#define DRM_UT_LEASE 0x80/***********************************************************************/ /** \name DRM template customization defaults */
@@ -251,6 +252,9 @@ struct dma_buf_attachment;#define DRM_DEBUG_VBL (fmt, ...) \ drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__) +#define DRM_DEBUG_LEASE (fmt, ...) \ + drm_printk(KERN_DEBUG, DRM_UT_LEASE, fmt, ##__VA_ARGS__) + #define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...) \ ({ \ static DEFINE_RATELIMIT_STATE(_rs, \
Signature · 1 line
2.11.0
PATCH 2/4 drm: Add drm_object lease infrastructure
In reply to Keith PackardThis provides new data structures to hold "lease" information about drm mode setting objects, and provides for creating new drm_masters which have access to a subset of the available drm resources.
An 'owner' is a drm_master which is not leasing the objects from another drm_master, and hence 'owns' them. This sits at the top of a tree of drm_masters.
A 'lessee' is a drm_master which is leasing objects from some other drm_master. Each lessee holds the set of objects which it is leasing from the lessor.
A 'lessor' is a drm_master which is leasing objects to another drm_master.
The set of objects any drm_master 'controls' is limited to the set of objects it leases (for lessees) or all objects (for owners), optionally minus the set of objects it has leased to other drm_masters.
Objects not controlled by a drm_master cannot be modified through the various state manipulating ioctls, and any state reported back to user space will be edited to make them appear idle and/or unusable. For instance, connectors always report 'disconnected', while encoders report no possible crtcs or clones.
The full list of lessees leasing objects from an owner (either directly, or indirectly through another lessee), can be searched from an idr in the drm_master of the owner.
--- drivers/gpu/drm/Makefile | 3 +- drivers/gpu/drm/drm_auth.c | 22 +- drivers/gpu/drm/drm_lease.c | 485 ++++++++++++++++++++++++++++++++++++++++++++ include/drm/drmP.h | 1 + include/drm/drm_auth.h | 28 +++ include/drm/drm_lease.h | 51 +++++ 6 files changed, 588 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/drm_lease.c create mode 100644 include/drm/drm_lease.h
drivers/gpu/drm/Makefile +2 -1
@@ -16,7 +16,8 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \ drm_framebuffer.o drm_connector.o drm_blend.o \ drm_encoder.o drm_mode_object.o drm_property.o \ drm_plane.o drm_color_mgmt.o drm_print.o \ - drm_dumb_buffers.o drm_mode_config.o + drm_dumb_buffers.o drm_mode_config.o \ + drm_lease.o drm-$(CONFIG_COMPAT) += drm_ioc32.o drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
drivers/gpu/drm/drm_auth.c +21 -1
@@ -31,6 +31,7 @@#include <drm/drmP.h> #include "drm_internal.h" #include "drm_legacy.h" +#include <drm/drm_lease.h> /** * DOC: master and authentication
@@ -93,7 +94,7 @@ int drm_authmagic(struct drm_device *dev, void *data,return file ?0 : -EINVAL ; } -static struct drm_master *drm_master_create (struct drm_device *dev) +struct drm_master *drm_master_create (struct drm_device *dev) {struct drm_master *master;
@@ -107,6 +108,14 @@ static struct drm_master *drm_master_create(struct drm_device *dev)idr_init (&master->magic_map); master->dev = dev; +/* initialize the tree of output resource lessees */ + master->lessor =NULL ; + master->lessee_id =0 ; +INIT_LIST_HEAD (&master->lessees); +INIT_LIST_HEAD (&master->lessee_list); +idr_init (&master->leases); +idr_init (&master->lessee_idr); +return master; }
@@ -189,6 +198,12 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data, goto out_unlock; } +if (file_priv->master->lessor !=NULL ) { +DRM_DEBUG_LEASE ("Attempt to set lessee %d as master\n" , file_priv->master->lessee_id); + ret = -EINVAL ; + goto out_unlock; + } + ret =drm_set_master (dev, file_priv, false); out_unlock:mutex_unlock (&dev->master_mutex);
@@ -310,12 +325,17 @@ static void drm_master_destroy(struct kref *kref) struct drm_master *master = container_of(kref, struct drm_master, refcount);struct drm_device *dev = master->dev; +drm_lease_destroy (master); +if (dev->driver->master_destroy) dev->driver->master_destroy (dev, master);drm_legacy_master_rmmaps (dev, master);idr_destroy (&master->magic_map); + +idr_destroy (&master->lessee_idr); +kfree (master->unique);kfree (master); }
drivers/gpu/drm/drm_lease.c new file +485 -0
485 lines not on this page · raw message
include/drm/drmP.h +1 -0
@@ -340,6 +340,7 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,#define DRM_CONTROL_ALLOW 0x8#define DRM_UNLOCKED 0x10#define DRM_RENDER_ALLOW 0x20 +#define DRM_ANY_MASTER 0x40struct drm_ioctl_desc {unsigned int cmd;
include/drm/drm_auth.h +28 -0
@@ -50,10 +50,38 @@ struct drm_master {struct idr magic_map;struct drm_lock_data lock;void *driver_priv; + +/* Tree of display resource leases, each of which is a drm_master struct +* All of these get activated simultaneously, so drm_device master points +* at the top of the tree (for which lessor is NULL) +*/ + +/** Lease holder */ +struct drm_master *lessor; + +/** id for lessees. Owners always have id 0 */ +int lessee_id; + +/** other lessees of the same master */ +struct list_head lessee_list; + +/** drm_masters leasing from this one */ +struct list_head lessees; + +/** Objects leased to this drm_master. */ +struct idr leases; + +/** All lessees under this owner (only used where lessor == NULL) */ +struct idr lessee_idr; + +/** Indicates that the leased objects should be hidden from the lessor */ + bool mask_lease; };struct drm_master *drm_master_get (struct drm_master *master);void drm_master_put (struct drm_master **master);bool drm_is_current_master (struct drm_file *fpriv); +struct drm_master *drm_master_create (struct drm_device *dev); +#endif
include/drm/drm_lease.h new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [PATCH 2/4] drm: Add drm_object lease infrastructure
Quoted 12 lines · Keith Packard
This provides new data structures to hold "lease" information about drm mode setting objects, and provides for creating new
drm_masterswhich have access to a subset of the available drm resources.An 'owner' is a
drm_masterwhich is not leasing the objects from anotherdrm_master, and hence 'owns' them. This sits at the top of a tree ofdrm_masters.A 'lessee' is a
drm_masterwhich is leasing objects from some otherdrm_master. Each lessee holds the set of objects which it is leasing from the lessor.
Quoted 7 lines
A 'lessor' is a
drm_masterwhich is leasing objects to anotherdrm_master.The set of objects any
drm_master'controls' is limited to the set of objects it leases (for lessees) or all objects (for owners), optionally minus the set of objects it has leased to otherdrm_masters.
Still not sure we want to restrict objects on the lessor side. Feels like unecessary complexity (i.e. more bugs in kernel, that's never good), and at best only needed for lessors who can't keep track of stuff. I'm also not sure whether we really want sub-leases in v1, that's easy to add later on, but for now just complicates stuff. Main compositor should be a full master, VR can be the first lease level, we don't need more I think for now?
Quoted 11 lines
Objects not controlled by a
drm_mastercannot be modified through the various state manipulating ioctls, and any state reported back to user space will be edited to make them appear idle and/or unusable. For instance, connectors always report 'disconnected', while encoders report no possible crtcs or clones.The full list of lessees leasing objects from an owner (either directly, or indirectly through another lessee), can be searched from an idr in the
drm_masterof the owner.Signed-off-by Keith Packard <[email protected]>
[snip]
include/drm/drm_auth.h struct drm_master { · line 55
Quoted 11 lines
include/drm/drm_auth.h +3
-0@@ -50,10 +50,38 @@ struct drm_master {struct idr magic_map;struct drm_lock_data lock;void *driver_priv; + +/* Tree of display resource leases, each of which is a drm_master struct +* All of these get activated simultaneously, so drm_device master points
&drm_device.master to do a reference in kernel-doc. Please feed this to kernel-doc in general and make sure the links all point at the right stuff, and it's all parsed.
Cheers, Daniel
include/drm/drm_auth.h struct drm_master { · line 59
Quoted 4 lines
include/drm/drm_auth.h +4
-0+* at the top of the tree (for which lessor is NULL) +*/ + +/** Lease holder */
/** @lessor: Lease holder. */
Quoted 92 lines
include/drm/drm_auth.h +21
-0+struct drm_master *lessor; + +/** id for lessees. Owners always have id 0 */ +int lessee_id; + +/** other lessees of the same master */ +struct list_head lessee_list; + +/** drm_masters leasing from this one */ +struct list_head lessees; + +/** Objects leased to this drm_master. */ +struct idr leases; + +/** All lessees under this owner (only used where lessor == NULL) */ +struct idr lessee_idr; + +/** Indicates that the leased objects should be hidden from the lessor */ + bool mask_lease; };struct drm_master *drm_master_get (struct drm_master *master);void drm_master_put (struct drm_master **master);bool drm_is_current_master (struct drm_file *fpriv); +struct drm_master *drm_master_create (struct drm_device *dev); +#endif include/drm/drm_lease.h new file +51
-0@@ -0,0 +1,51 @@ +/* +* Copyright © 2017 Keith Packard <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +*/ + +#ifndef _DRM_LEASE_H_ +#define _DRM_LEASE_H_ + +struct drm_file ; +struct drm_device ; + +struct drm_master *drm_lease_owner (struct drm_master *master); + +struct drm_master *drm_lessee_find (struct drm_master *top,int lessee_id); + +void drm_lease_destroy (struct drm_master *lessee); + +struct drm_mode_object *drm_lease_find (struct drm_master *master,int id); + +/** +* drm_lease_check - check drm_mode_object lease status +* @master: the drm_master +* @id: the object id +* +* Checks if the specified master holds a lease on the object +* and also whether it has been leased to some lessee of the +* specified master. Return value: +* +* 0 'master' holds a lease (or owns) and has not leased +* -EACCESS Some other master holds the lease +* -ENOENT 'id' is not a valid DRM object for this device +* -EBUSY 'master' holds lease, but has sub-leased +*/ + +static inline int drm_lease_check (struct drm_master *master,int id) { +struct drm_mode_object *object =drm_lease_find (master, id); +if (IS_ERR (object)) +return PTR_ERR (object); +return 0 ; +} + +#endif /* _DRM_LEASE_H_ */ Signature · 6 lines
2.11.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/4] drm: Add drm_object lease infrastructure
Quoted 3 lines · Daniel Vetter
Still not sure we want to restrict objects on the lessor side. Feels like unecessary complexity (i.e. more bugs in kernel, that's never good), and at best only needed for lessors who can't keep track of stuff.
It's been useful when hacking existing code, and will help catch application bugs. Limiting access to what you actually need always seems like good practice to me.
Quoted 4 lines
I'm also not sure whether we really want sub-leases in v1, that's easy to add later on, but for now just complicates stuff. Main compositor should be a full master, VR can be the first lease level, we don't need more I think for now?
We've discussed how leases might be used to implement multi-user support, so offering sub-leases means that environment could also support leasing resources out from the users session.
We also just don't know how useful it might be until we explore the space a bit more. Given that it takes years to get new features into distributions, I tend to error on the side of generality.
I think a key requirement for acceptance would be a set of robust tests, something I haven't started writing yet.
Quoted 6 lines
include/drm/drm_auth.h struct drm_master { · line 55
Quoted 2 lines
include/drm/drm_auth.h +2
-0+/* Tree of display resource leases, each of which is a drm_master struct +* All of these get activated simultaneously, so drm_device master points &drm_device.master to do a reference in kernel-doc. Please feed this to kernel-doc in general and make sure the links all point at the right stuff, and it's all parsed.
Thanks, will do.
Signature · 1 line
-keith
Re: [PATCH 2/4] drm: Add drm_object lease infrastructure
Quoted 7 lines · Keith Packard
Quoted 4 lines · Daniel Vetter
I'm also not sure whether we really want sub-leases in v1, that's easy to add later on, but for now just complicates stuff. Main compositor should be a full master, VR can be the first lease level, we don't need more I think for now?
Quoted 6 lines
We've discussed how leases might be used to implement multi-user support, so offering sub-leases means that environment could also support leasing resources out from the users session.
We also just don't know how useful it might be until we explore the space a bit more.
It should only be added upstream once it's clear that it's useful.
Quoted 2 lines
Given that it takes years to get new features into distributions, I tend to error on the side of generality.
Why would it take years? Distros seem to generally use the latest upstream kernel release available at release/freeze.
Signature · 2 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/4] drm: Add drm_object lease infrastructure
In reply to Keith Packarddrivers/gpu/drm/drm_lease.c line 61
Quoted 1 line · Keith Packard
drivers/gpu/drm/drm_lease.c new file +1
-0+BUG_ON (__mutex_owner (&master->dev->mode_config.idr_mutex) != current);
Forgot to reply on this:
lockdep_assert_held + enable lockdep.
Cheers, Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/4] drm: Add drm_object lease infrastructure
Quoted 6 lines · Daniel Vetter
drivers/gpu/drm/drm_lease.c line 61
Quoted 1 line · Keith Packard
drivers/gpu/drm/drm_lease.c new file +1
-0+BUG_ON (__mutex_owner (&master->dev->mode_config.idr_mutex) != current);Forgot to reply on this:
lockdep_assert_held+ enable lockdep.
Thanks. Will fix.
Signature · 1 line
-keith
PATCH 3/4 drm: Check mode object lease status in all master ioctl paths
In reply to Keith PackardAttempts to modify un-leased objects are rejected with an error. Information returned about unleased objects is modified to make them appear unusable and/or disconnected.
--- drivers/gpu/drm/drm_atomic.c | 3 +++ drivers/gpu/drm/drm_auth.c | 2 +- drivers/gpu/drm/drm_color_mgmt.c | 3 +++ drivers/gpu/drm/drm_connector.c | 52 ++++++++++++++++++++++++++------------- drivers/gpu/drm/drm_crtc.c | 15 ++++++++--- drivers/gpu/drm/drm_encoder.c | 18 +++++++++++--- drivers/gpu/drm/drm_mode_object.c | 3 +++ drivers/gpu/drm/drm_plane.c | 36 +++++++++++++++++++++++---- include/drm/drm_lease.h | 4 +++ include/drm/drm_mode_object.h | 1 + 10 files changed, 108 insertions(+), 29 deletions(-)
drivers/gpu/drm/drm_atomic.c +3 -0
@@ -2134,6 +2134,9 @@ int drm_mode_atomic_ioctl(struct drm_device *dev, goto out; } +if ((ret =drm_lease_check (file_priv->master, obj->id)) <0 ) + goto out; +if (!obj->properties) {drm_mode_object_unreference (obj); ret = -ENOENT ;
drivers/gpu/drm/drm_auth.c +1 -1
@@ -303,7 +303,7 @@ void drm_master_release(struct drm_file *file_priv)*/ bool drm_is_current_master (struct drm_file *fpriv) { -return fpriv->is_master && fpriv->master == fpriv->minor->dev->master; +return fpriv->is_master &&drm_lease_owner (fpriv->master) == fpriv->minor->dev->master; }EXPORT_SYMBOL (drm_is_current_master);
drivers/gpu/drm/drm_color_mgmt.c +3 -0
@@ -206,6 +206,9 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev, goto out; } +if ((ret =drm_lease_check (file_priv->master, crtc->base.id)) <0 ) + goto out; +if (crtc->funcs->gamma_set ==NULL ) { ret = -ENOSYS ; goto out;
drivers/gpu/drm/drm_connector.c +35 -17
83 lines not on this page · raw message
drivers/gpu/drm/drm_crtc.c +12 -3
@@ -347,6 +347,7 @@ int drm_mode_getcrtc(struct drm_device *dev, {struct drm_mode_crtc *crtc_resp = data;struct drm_crtc *crtc; +bool leased;if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EINVAL ;
@@ -355,9 +356,13 @@ int drm_mode_getcrtc(struct drm_device *dev,if (!crtc)return -ENOENT ; + leased =drm_lease_check (file_priv->master, crtc->base.id) ==0 ; + +DRM_DEBUG_LEASE ("crtc %d leased %s\n" , crtc->base.id, leased ?"true" :"false" ); +drm_modeset_lock_crtc (crtc, crtc->primary); crtc_resp->gamma_size = crtc->gamma_size; -if (crtc->primary->fb) +if (crtc->primary->fb && leased) crtc_resp->fb_id = crtc->primary->fb->base.id;else crtc_resp->fb_id =0 ;
@@ -365,7 +370,7 @@ int drm_mode_getcrtc(struct drm_device *dev,if (crtc->state) { crtc_resp->x = crtc->primary->state->src_x >>16 ; crtc_resp->y = crtc->primary->state->src_y >>16 ; -if (crtc->state->enable) { +if (crtc->state->enable && leased) {drm_mode_convert_to_umode (&crtc_resp->mode, &crtc->state->mode); crtc_resp->mode_valid =1 ;
@@ -375,7 +380,7 @@ int drm_mode_getcrtc(struct drm_device *dev, }else { crtc_resp->x = crtc->x; crtc_resp->y = crtc->y; -if (crtc->enabled) { +if (crtc->enabled && leased) {drm_mode_convert_to_umode (&crtc_resp->mode, &crtc->mode); crtc_resp->mode_valid =1 ;
@@ -529,6 +534,10 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, }DRM_DEBUG_KMS ("[CRTC:%d:%s]\n" , crtc->base.id, crtc->name); +if ((ret =drm_lease_check (file_priv->master, crtc->base.id)) <0 ) { +DRM_DEBUG_KMS ("CRTC lease not held\n" ); + goto out; + }if (crtc_req->mode_valid) {/* If we have a mode we need a framebuffer. */ /* If we pass -1, set the mode with the currently bound fb */
drivers/gpu/drm/drm_encoder.c +15 -3
@@ -201,6 +201,7 @@ int drm_mode_getencoder(struct drm_device *dev, void *data,struct drm_mode_get_encoder *enc_resp = data;struct drm_encoder *encoder;struct drm_crtc *crtc; +bool leased;if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EINVAL ;
@@ -209,9 +210,13 @@ int drm_mode_getencoder(struct drm_device *dev, void *data,if (!encoder)return -ENOENT ; + leased =drm_lease_check (file_priv->master, encoder->base.id) ==0 ; + +DRM_DEBUG_LEASE ("encoder %d leased %s\n" , encoder->base.id, leased ?"true" :"false" ); +drm_modeset_lock (&dev->mode_config.connection_mutex,NULL ); crtc =drm_encoder_get_crtc (encoder); -if (crtc) +if (crtc && leased) enc_resp->crtc_id = crtc->base.id;else enc_resp->crtc_id =0 ;
@@ -219,8 +224,15 @@ int drm_mode_getencoder(struct drm_device *dev, void *data, enc_resp->encoder_type = encoder->encoder_type; enc_resp->encoder_id = encoder->base.id; - enc_resp->possible_crtcs = encoder->possible_crtcs; - enc_resp->possible_clones = encoder->possible_clones; +if (leased) { + enc_resp->possible_crtcs =drm_lease_filter_crtcs (file_priv->master, + encoder->possible_crtcs); + enc_resp->possible_clones =drm_lease_filter_encoders (file_priv->master, + encoder->possible_clones); + }else { + enc_resp->possible_crtcs =0 ; + enc_resp->possible_clones =0 ; + }return 0 ; }
drivers/gpu/drm/drm_mode_object.c +3 -0
@@ -404,6 +404,9 @@ int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, goto out; } +if ((ret =drm_lease_check (file_priv->master, arg->obj_id)) !=0 ) + goto out; +if (!arg_obj->properties) goto out_unref;
drivers/gpu/drm/drm_plane.c +31 -5
@@ -383,6 +383,7 @@ int drm_mode_getplane(struct drm_device *dev, void *data,struct drm_mode_get_plane *plane_resp = data;struct drm_plane *plane;uint32_t __user *format_ptr; +bool leased;if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EINVAL ;
@@ -391,27 +392,34 @@ int drm_mode_getplane(struct drm_device *dev, void *data,if (!plane)return -ENOENT ; + leased =drm_lease_check (file_priv->master, plane->base.id) ==0 ; +drm_modeset_lock (&plane->mutex,NULL ); -if (plane->crtc) +if (plane->crtc && leased) plane_resp->crtc_id = plane->crtc->base.id;else plane_resp->crtc_id =0 ; -if (plane->fb) +if (plane->fb && leased) plane_resp->fb_id = plane->fb->base.id;else plane_resp->fb_id =0 ;drm_modeset_unlock (&plane->mutex); plane_resp->plane_id = plane->base.id; - plane_resp->possible_crtcs = plane->possible_crtcs; +if (leased) + plane_resp->possible_crtcs =drm_lease_filter_crtcs (file_priv->master, + plane->possible_crtcs); +else + plane_resp->possible_crtcs =0 ; + plane_resp->gamma_size =0 ;/* * This ioctl is called twice, once to determine how much space is * needed, and the 2nd time to fill it. */ -if (plane->format_count && +if (plane->format_count && leased && (plane_resp->count_format_types >= plane->format_count)) { format_ptr = (uint32_t __user *)(unsigned long )plane_resp->format_type_ptr; if (copy_to_user(format_ptr,
@@ -420,7 +428,10 @@ int drm_mode_getplane(struct drm_device *dev, void *data,return -EFAULT ; } } - plane_resp->count_format_types = plane->format_count; +if (leased) + plane_resp->count_format_types = plane->format_count; +else + plane_resp->count_format_types =0 ;return 0 ; }
@@ -551,6 +562,7 @@ int drm_mode_setplane(struct drm_device *dev, void *data,struct drm_plane *plane;struct drm_crtc *crtc =NULL ;struct drm_framebuffer *fb =NULL ; +int ret;if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EINVAL ;
@@ -566,6 +578,12 @@ int drm_mode_setplane(struct drm_device *dev, void *data,return -ENOENT ; } +if ((ret =drm_lease_check (file_priv->master, plane->base.id)) <0 ) { +DRM_DEBUG_KMS ("Plane lease not held: %d error %d\n" , + plane->base.id, ret); +return ret; + } +if (plane_req->fb_id) { fb =drm_framebuffer_lookup (dev, plane_req->fb_id);if (!fb) {
@@ -687,6 +705,11 @@ static int drm_mode_cursor_common(struct drm_device *dev,DRM_DEBUG_KMS ("Unknown CRTC ID %d\n" , req->crtc_id);return -ENOENT ; } +if ((ret =drm_lease_check (file_priv->master, crtc->base.id)) <0 ) { +DRM_DEBUG_KMS ("CRTC lease not held %d error %d\n" , + crtc->base.id, ret); + goto out; + }/* * If this crtc has a universal cursor plane, call that plane's update
@@ -785,6 +808,9 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,if (!crtc)return -ENOENT ; +if ((ret =drm_lease_check (file_priv->master, crtc->base.id)) <0 ) +return ret; +if (crtc->funcs->page_flip_target) {u32 current_vblank;int r;
include/drm/drm_lease.h +4 -0
@@ -48,4 +48,8 @@ static inline int drm_lease_check(struct drm_master *master, int id) { return 0; } +uint32_t drm_lease_filter_crtcs (struct drm_master *master,uint32_t crtcs); + +uint32_t drm_lease_filter_encoders (struct drm_master *master,uint32_t encoders); +#endif /* _DRM_LEASE_H_ */
include/drm/drm_mode_object.h +1 -0
@@ -24,6 +24,7 @@#define __DRM_MODESET_H__#include <linux/kref.h> +#include <drm/drm_lease.h> struct drm_object_properties ;struct drm_property ;struct drm_device ;
Signature · 1 line
2.11.0
Re: [PATCH 3/4] drm: Check mode object lease status in all master ioctl paths
Quoted 5 lines · Keith Packard
Attempts to modify un-leased objects are rejected with an error. Information returned about unleased objects is modified to make them appear unusable and/or disconnected.
Signed-off-by Keith Packard <[email protected]>
Just a merge-technical idea to make this easier to change and less painful to rebase until we've locked down the semantics properly. And also because I expect we'll need v2 of this uapi soon or later anyway:
I think it'd be good if we could consolidate all the lease checking into drm_mode_object_find (respectively __drm_mode_object_find). We'd need to wire up the fpriv to be able to do that, but we could upstream that patch right away before anything else. That should take care of most of the checks in this patch here.
There's a few things on top:
- filtering the various bitmasks. I think you have most, but we could perhaps upstream the helpers for these.
- filtering object lists (essentially getresources and getplanes ioctls).
- filtering implicit objects in the legacy ioctl. E.g. page_flip done through atomic doesn't just need the CRTC id, but also the id of the primary plane plus of the FB_ID atomic property. Similarly for all the other legacy ioctls. I think we want to make sure there's no difference here in behaviour.
Especially for the last one it might be simplest to outright disallow all legacy ioctl and require that sub-drm_master nodes only get access to the read-only GET* ioctl (they get that anyway, even when they're not the current master), plus atomic. Makes it a _lot_ easier to implement. Downside is that amdgpu _really_ needs to land atomic asap :-)
Quoted 32 lines
--- drivers/gpu/drm/drm_atomic.c | 3 +++ drivers/gpu/drm/drm_auth.c | 2 +- drivers/gpu/drm/drm_color_mgmt.c | 3 +++ drivers/gpu/drm/drm_connector.c | 52 ++++++++++++++++++++++++++------------- drivers/gpu/drm/drm_crtc.c | 15 ++++++++--- drivers/gpu/drm/drm_encoder.c | 18 +++++++++++--- drivers/gpu/drm/drm_mode_object.c | 3 +++ drivers/gpu/drm/drm_plane.c | 36 +++++++++++++++++++++++---- include/drm/drm_lease.h | 4 +++ include/drm/drm_mode_object.h | 1 + 10 files changed, 108 insertions(+), 29 deletions(-)drivers/gpu/drm/drm_atomic.c +3
-0@@ -2134,6 +2134,9 @@ int drm_mode_atomic_ioctl(struct drm_device *dev, goto out; } +if ((ret =drm_lease_check (file_priv->master, obj->id)) <0 ) + goto out; +if (!obj->properties) {drm_mode_object_unreference (obj); ret = -ENOENT ;drivers/gpu/drm/drm_auth.c +0
-0
drivers/gpu/drm/drm_auth.c void drm_master_release(struct drm_file *file_priv) · line 306
Quoted 5 lines
drivers/gpu/drm/drm_auth.c +1
-1@@ -303,7 +303,7 @@ void drm_master_release(struct drm_file *file_priv)*/ bool drm_is_current_master (struct drm_file *fpriv) { -return fpriv->is_master && fpriv->master == fpriv->minor->dev->master; +return fpriv->is_master &&drm_lease_owner (fpriv->master) == fpriv->minor->dev->master;
This feels like it should be part of the earlier patch to make sub-drm_master objects for leasing. In that patch we should also make sure that all the current docs about drm_master are updated correctly (but maybe only later on, when we get towards merging this). This change here is pretty important wrt set/drop_master ioctl behaviour and leases.
Cheers, Daniel
Quoted 361 lines
drivers/gpu/drm/drm_auth.c +0
-0}EXPORT_SYMBOL (drm_is_current_master);drivers/gpu/drm/drm_color_mgmt.c +3
-0@@ -206,6 +206,9 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev, goto out; } +if ((ret =drm_lease_check (file_priv->master, crtc->base.id)) <0 ) + goto out; +if (crtc->funcs->gamma_set ==NULL ) { ret = -ENOSYS ; goto out;drivers/gpu/drm/drm_connector.c +35
-17@@ -1079,6 +1079,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,struct drm_mode_modeinfo u_mode;struct drm_mode_modeinfo __user *mode_ptr;uint32_t __user *encoder_ptr; +bool leased;if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EINVAL ;@@ -1093,9 +1094,16 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, goto out_unlock; } -for (i =0 ; i <DRM_CONNECTOR_MAX_ENCODER ; i++) -if (connector->encoder_ids[i] !=0 ) - encoders_count++; + leased =drm_lease_check (file_priv->master, connector->base.id) ==0 ; + +DRM_DEBUG_LEASE ("connector %d leased %s\n" , connector->base.id, leased ?"true" :"false" ); + +if (leased) { +for (i =0 ; i <DRM_CONNECTOR_MAX_ENCODER ; i++) +if (connector->encoder_ids[i] !=0 && +drm_lease_check (file_priv->master, connector->encoder_ids[i]) ==0 ) + encoders_count++; + }if (out_resp->count_modes ==0 ) { connector->funcs->fill_modes(connector,@@ -1104,21 +1112,29 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, }/* delayed so we get modes regardless of pre-fill_modes state */ -list_for_each_entry (mode, &connector->modes, head) -if (drm_mode_expose_to_userspace (mode, file_priv)) - mode_count++; +if (leased) +list_for_each_entry (mode, &connector->modes, head) +if (drm_mode_expose_to_userspace (mode, file_priv)) + mode_count++; out_resp->connector_id = connector->base.id; out_resp->connector_type = connector->connector_type; out_resp->connector_type_id = connector->connector_type_id; - out_resp->mm_width = connector->display_info.width_mm; - out_resp->mm_height = connector->display_info.height_mm; - out_resp->subpixel = connector->display_info.subpixel_order; - out_resp->connection = connector->status; +if (leased) { + out_resp->mm_width = connector->display_info.width_mm; + out_resp->mm_height = connector->display_info.height_mm; + out_resp->subpixel = connector->display_info.subpixel_order; + out_resp->connection = connector->status; + }else { + out_resp->mm_width =0 ; + out_resp->mm_height =0 ; + out_resp->subpixel =0 ; + out_resp->connection = connector_status_disconnected; + }drm_modeset_lock (&dev->mode_config.connection_mutex,NULL ); encoder =drm_connector_get_encoder (connector); -if (encoder) +if (encoder && leased) out_resp->encoder_id = encoder->base.id;else out_resp->encoder_id =0 ;@@ -1145,12 +1161,14 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, } out_resp->count_modes = mode_count; - ret =drm_mode_object_get_properties (&connector->base, file_priv->atomic, - (uint32_t __user *)(unsigned long )(out_resp->props_ptr), - (uint64_t __user *)(unsigned long )(out_resp->prop_values_ptr), - &out_resp->count_props); -if (ret) - goto out; +if (leased) { + ret =drm_mode_object_get_properties (&connector->base, file_priv->atomic, + (uint32_t __user *)(unsigned long )(out_resp->props_ptr), + (uint64_t __user *)(unsigned long )(out_resp->prop_values_ptr), + &out_resp->count_props); +if (ret) + goto out; + }if ((out_resp->count_encoders >= encoders_count) && encoders_count) { copied =0 ;drivers/gpu/drm/drm_crtc.c +12
-3@@ -347,6 +347,7 @@ int drm_mode_getcrtc(struct drm_device *dev, {struct drm_mode_crtc *crtc_resp = data;struct drm_crtc *crtc; +bool leased;if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EINVAL ;@@ -355,9 +356,13 @@ int drm_mode_getcrtc(struct drm_device *dev,if (!crtc)return -ENOENT ; + leased =drm_lease_check (file_priv->master, crtc->base.id) ==0 ; + +DRM_DEBUG_LEASE ("crtc %d leased %s\n" , crtc->base.id, leased ?"true" :"false" ); +drm_modeset_lock_crtc (crtc, crtc->primary); crtc_resp->gamma_size = crtc->gamma_size; -if (crtc->primary->fb) +if (crtc->primary->fb && leased) crtc_resp->fb_id = crtc->primary->fb->base.id;else crtc_resp->fb_id =0 ;@@ -365,7 +370,7 @@ int drm_mode_getcrtc(struct drm_device *dev,if (crtc->state) { crtc_resp->x = crtc->primary->state->src_x >>16 ; crtc_resp->y = crtc->primary->state->src_y >>16 ; -if (crtc->state->enable) { +if (crtc->state->enable && leased) {drm_mode_convert_to_umode (&crtc_resp->mode, &crtc->state->mode); crtc_resp->mode_valid =1 ;@@ -375,7 +380,7 @@ int drm_mode_getcrtc(struct drm_device *dev, }else { crtc_resp->x = crtc->x; crtc_resp->y = crtc->y; -if (crtc->enabled) { +if (crtc->enabled && leased) {drm_mode_convert_to_umode (&crtc_resp->mode, &crtc->mode); crtc_resp->mode_valid =1 ;@@ -529,6 +534,10 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, }DRM_DEBUG_KMS ("[CRTC:%d:%s]\n" , crtc->base.id, crtc->name); +if ((ret =drm_lease_check (file_priv->master, crtc->base.id)) <0 ) { +DRM_DEBUG_KMS ("CRTC lease not held\n" ); + goto out; + }if (crtc_req->mode_valid) {/* If we have a mode we need a framebuffer. */ /* If we pass -1, set the mode with the currently bound fb */ drivers/gpu/drm/drm_encoder.c +15
-3@@ -201,6 +201,7 @@ int drm_mode_getencoder(struct drm_device *dev, void *data,struct drm_mode_get_encoder *enc_resp = data;struct drm_encoder *encoder;struct drm_crtc *crtc; +bool leased;if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EINVAL ;@@ -209,9 +210,13 @@ int drm_mode_getencoder(struct drm_device *dev, void *data,if (!encoder)return -ENOENT ; + leased =drm_lease_check (file_priv->master, encoder->base.id) ==0 ; + +DRM_DEBUG_LEASE ("encoder %d leased %s\n" , encoder->base.id, leased ?"true" :"false" ); +drm_modeset_lock (&dev->mode_config.connection_mutex,NULL ); crtc =drm_encoder_get_crtc (encoder); -if (crtc) +if (crtc && leased) enc_resp->crtc_id = crtc->base.id;else enc_resp->crtc_id =0 ;@@ -219,8 +224,15 @@ int drm_mode_getencoder(struct drm_device *dev, void *data, enc_resp->encoder_type = encoder->encoder_type; enc_resp->encoder_id = encoder->base.id; - enc_resp->possible_crtcs = encoder->possible_crtcs; - enc_resp->possible_clones = encoder->possible_clones; +if (leased) { + enc_resp->possible_crtcs =drm_lease_filter_crtcs (file_priv->master, + encoder->possible_crtcs); + enc_resp->possible_clones =drm_lease_filter_encoders (file_priv->master, + encoder->possible_clones); + }else { + enc_resp->possible_crtcs =0 ; + enc_resp->possible_clones =0 ; + }return 0 ; }drivers/gpu/drm/drm_mode_object.c +3
-0@@ -404,6 +404,9 @@ int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, goto out; } +if ((ret =drm_lease_check (file_priv->master, arg->obj_id)) !=0 ) + goto out; +if (!arg_obj->properties) goto out_unref;drivers/gpu/drm/drm_plane.c +31
-5@@ -383,6 +383,7 @@ int drm_mode_getplane(struct drm_device *dev, void *data,struct drm_mode_get_plane *plane_resp = data;struct drm_plane *plane;uint32_t __user *format_ptr; +bool leased;if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EINVAL ;@@ -391,27 +392,34 @@ int drm_mode_getplane(struct drm_device *dev, void *data,if (!plane)return -ENOENT ; + leased =drm_lease_check (file_priv->master, plane->base.id) ==0 ; +drm_modeset_lock (&plane->mutex,NULL ); -if (plane->crtc) +if (plane->crtc && leased) plane_resp->crtc_id = plane->crtc->base.id;else plane_resp->crtc_id =0 ; -if (plane->fb) +if (plane->fb && leased) plane_resp->fb_id = plane->fb->base.id;else plane_resp->fb_id =0 ;drm_modeset_unlock (&plane->mutex); plane_resp->plane_id = plane->base.id; - plane_resp->possible_crtcs = plane->possible_crtcs; +if (leased) + plane_resp->possible_crtcs =drm_lease_filter_crtcs (file_priv->master, + plane->possible_crtcs); +else + plane_resp->possible_crtcs =0 ; + plane_resp->gamma_size =0 ;/* * This ioctl is called twice, once to determine how much space is * needed, and the 2nd time to fill it. */ -if (plane->format_count && +if (plane->format_count && leased && (plane_resp->count_format_types >= plane->format_count)) { format_ptr = (uint32_t __user *)(unsigned long )plane_resp->format_type_ptr; if (copy_to_user(format_ptr,@@ -420,7 +428,10 @@ int drm_mode_getplane(struct drm_device *dev, void *data,return -EFAULT ; } } - plane_resp->count_format_types = plane->format_count; +if (leased) + plane_resp->count_format_types = plane->format_count; +else + plane_resp->count_format_types =0 ;return 0 ; }@@ -551,6 +562,7 @@ int drm_mode_setplane(struct drm_device *dev, void *data,struct drm_plane *plane;struct drm_crtc *crtc =NULL ;struct drm_framebuffer *fb =NULL ; +int ret;if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EINVAL ;@@ -566,6 +578,12 @@ int drm_mode_setplane(struct drm_device *dev, void *data,return -ENOENT ; } +if ((ret =drm_lease_check (file_priv->master, plane->base.id)) <0 ) { +DRM_DEBUG_KMS ("Plane lease not held: %d error %d\n" , + plane->base.id, ret); +return ret; + } +if (plane_req->fb_id) { fb =drm_framebuffer_lookup (dev, plane_req->fb_id);if (!fb) {@@ -687,6 +705,11 @@ static int drm_mode_cursor_common(struct drm_device *dev,DRM_DEBUG_KMS ("Unknown CRTC ID %d\n" , req->crtc_id);return -ENOENT ; } +if ((ret =drm_lease_check (file_priv->master, crtc->base.id)) <0 ) { +DRM_DEBUG_KMS ("CRTC lease not held %d error %d\n" , + crtc->base.id, ret); + goto out; + }/* * If this crtc has a universal cursor plane, call that plane's update @@ -785,6 +808,9 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,if (!crtc)return -ENOENT ; +if ((ret =drm_lease_check (file_priv->master, crtc->base.id)) <0 ) +return ret; +if (crtc->funcs->page_flip_target) {u32 current_vblank;int r;include/drm/drm_lease.h +4
-0@@ -48,4 +48,8 @@ static inline int drm_lease_check(struct drm_master *master, int id) { return 0; } +uint32_t drm_lease_filter_crtcs (struct drm_master *master,uint32_t crtcs); + +uint32_t drm_lease_filter_encoders (struct drm_master *master,uint32_t encoders); +#endif /* _DRM_LEASE_H_ */ include/drm/drm_mode_object.h +1
-0@@ -24,6 +24,7 @@#define __DRM_MODESET_H__#include <linux/kref.h> +#include <drm/drm_lease.h> struct drm_object_properties ;struct drm_property ;struct drm_device ;Signature · 6 lines
2.11.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 3/4] drm: Check mode object lease status in all master ioctl paths
Quoted 5 lines · Daniel Vetter
I think it'd be good if we could consolidate all the lease checking into
drm_mode_object_find(respectively__drm_mode_object_find). We'd need to wire up the fpriv to be able to do that, but we could upstream that patch right away before anything else. That should take care of most of the checks in this patch here.
That's a good idea.
Quoted 3 lines
There's a few things on top:
- filtering the various bitmasks. I think you have most, but we could perhaps upstream the helpers for these.
Yeah, would be nice to get hooks in place soon to avoid rebase adventures later. I guess that would involve shipping a stub drm_lease.h for now?
Quoted 6 lines
- filtering object lists (essentially getresources and getplanes ioctls).
- filtering implicit objects in the legacy ioctl. E.g.page_flipdone through atomic doesn't just need the CRTC id, but also the id of the primary plane plus of theFB_IDatomic property. Similarly for all the other legacy ioctls. I think we want to make sure there's no difference here in behaviour.
Oh, all of the implicit resource access from the legacy ioctls. Yeah, that will take a bit of research to identify all of them.
Quoted 5 lines
Especially for the last one it might be simplest to outright disallow all legacy ioctl and require that sub-drm_master nodes only get access to the read-only GET* ioctl (they get that anyway, even when they're not the current master), plus atomic. Makes it a _lot_ easier to implement. Downside is that amdgpu _really_ needs to land atomic asap :-)
I'd like to avoid that particular dependency as amdgpu is something of a requirement for this particular project...
I'll get started fixing the lease checking stuff to try and centralize it.
Signature · 1 line
-keith
Re: [PATCH 3/4] drm: Check mode object lease status in all master ioctl paths
Quoted 10 lines · Keith Packard
Quoted 5 lines · Daniel Vetter
I think it'd be good if we could consolidate all the lease checking into
drm_mode_object_find(respectively__drm_mode_object_find). We'd need to wire up the fpriv to be able to do that, but we could upstream that patch right away before anything else. That should take care of most of the checks in this patch here.That's a good idea.
Quoted 7 lines
Quoted 3 lines
There's a few things on top:
- filtering the various bitmasks. I think you have most, but we could perhaps upstream the helpers for these.Yeah, would be nice to get hooks in place soon to avoid rebase adventures later. I guess that would involve shipping a stub
drm_lease.hfor now?
I think we should see how far wiring drm_file *fpriv through the lookup functions gets us, but yeah we probably need a stub drm_lease.h for filtering. For the interface maybe pass a drm_file *fpriv for all the filtering functions, and deref into fpriv->master or whatever on the implementation. That gives us all the freedom to filter however we want really.
Quoted 10 lines
Quoted 6 lines
- filtering object lists (essentially getresources and getplanes ioctls).
- filtering implicit objects in the legacy ioctl. E.g.page_flipdone through atomic doesn't just need the CRTC id, but also the id of the primary plane plus of theFB_IDatomic property. Similarly for all the other legacy ioctls. I think we want to make sure there's no difference here in behaviour.Oh, all of the implicit resource access from the legacy ioctls. Yeah, that will take a bit of research to identify all of them.
Quoted 8 lines
Quoted 5 lines
Especially for the last one it might be simplest to outright disallow all legacy ioctl and require that sub-drm_master nodes only get access to the read-only GET* ioctl (they get that anyway, even when they're not the current master), plus atomic. Makes it a _lot_ easier to implement. Downside is that amdgpu _really_ needs to land atomic asap :-)
I'd like to avoid that particular dependency as amdgpu is something of a requirement for this particular project...
Figured so :-) Otoh I've heard that atomic for amdgpu is happening for real now. Although Harry told me I need to wait a few more weeks before they're ready to present the rewritten stuff and get my feedback ... -Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 3/4] drm: Check mode object lease status in all master ioctl paths
In reply to Daniel VetterQuoted 5 lines · Daniel Vetter
I think it'd be good if we could consolidate all the lease checking into
drm_mode_object_find(respectively__drm_mode_object_find). We'd need to wire up the fpriv to be able to do that, but we could upstream that patch right away before anything else. That should take care of most of the checks in this patch here.
Hrm. Without some major changes, the effect of this will be to have the lessee see only the objects which it holds a lease on. I think that's OK as the lessor will be doing object filtering for its clients, however it's not what Dave and I discussed, so I just want to make him aware that the kernel is going to be simpler than originally planned. We had originally discussed having the lessee see the un-leased objects, but to have them reported with different status.
Signature · 1 line
-keith
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 4/4 drm: Add four ioctls for managing drm mode object leases
In reply to Keith Packarddrm_mode_create_lease
Creates a lease for a list of drm mode objects, returning an fd for the new drm_master and a 64-bit identifier for the lessee
drm_mode_list_lesees
List the identifiers of the lessees from a particular lessor
drm_mode_get_lease
List the leased objects for a particular lessee
drm_mode_change_lease
Adjust the terms of a lease, adding or removing resources or switching from masking to non-masking.
This should suffice to at least create, query and manage available leases.
--- drivers/gpu/drm/drm_ioctl.c | 4 + drivers/gpu/drm/drm_lease.c | 309 ++++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_lease.h | 12 ++ include/uapi/drm/drm.h | 4 + include/uapi/drm/drm_mode.h | 78 +++++++++++ 5 files changed, 407 insertions(+)
drivers/gpu/drm/drm_ioctl.c +4 -0
@@ -636,6 +636,10 @@ static const struct drm_ioctl_desc drm_ioctls[] = {DRM_IOCTL_DEF (DRM_IOCTL_MODE_ATOMIC , drm_mode_atomic_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_CREATEPROPBLOB , drm_mode_createblob_ioctl,DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_DESTROYPROPBLOB , drm_mode_destroyblob_ioctl,DRM_CONTROL_ALLOW |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_CREATE_LEASE , drm_mode_create_lease_ioctl,DRM_ANY_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_LIST_LESSEES , drm_mode_list_lessees_ioctl,DRM_ANY_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_GET_LEASE , drm_mode_get_lease_ioctl,DRM_ANY_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), + DRM_IOCTL_DEF(DRM_IOCTL_MODE_CHANGE_LEASE, drm_mode_change_lease_ioctl, DRM_ANY_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), };#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
drivers/gpu/drm/drm_lease.c +309 -0
312 lines not on this page · raw message
include/drm/drm_lease.h +12 -0
@@ -52,4 +52,16 @@ uint32_t drm_lease_filter_crtcs(struct drm_master *master, uint32_t crtcs);uint32_t drm_lease_filter_encoders (struct drm_master *master,uint32_t encoders); +int drm_mode_create_lease_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv); + +int drm_mode_list_lessees_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv); + +int drm_mode_get_lease_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv); + +int drm_mode_change_lease_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv); +#endif /* _DRM_LEASE_H_ */
include/uapi/drm/drm.h +4 -0
@@ -813,6 +813,10 @@ extern "C" {#define DRM_IOCTL_MODE_ATOMIC DRM_IOWR(0xBC, struct drm_mode_atomic)#define DRM_IOCTL_MODE_CREATEPROPBLOB DRM_IOWR(0xBD, struct drm_mode_create_blob)#define DRM_IOCTL_MODE_DESTROYPROPBLOB DRM_IOWR(0xBE, struct drm_mode_destroy_blob) +#define DRM_IOCTL_MODE_CREATE_LEASE DRM_IOWR(0xBF, struct drm_mode_create_lease) +#define DRM_IOCTL_MODE_LIST_LESSEES DRM_IOWR(0xC0, struct drm_mode_list_lessees) +#define DRM_IOCTL_MODE_GET_LEASE DRM_IOWR(0xC1, struct drm_mode_get_lease) +#define DRM_IOCTL_MODE_CHANGE_LEASE DRM_IOWR(0xC2, struct drm_mode_change_lease)/** * Device specific ioctls should only be in their respective headers
include/uapi/drm/drm_mode.h +78 -0
84 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [PATCH 4/4] drm: Add four ioctls for managing drm mode object leases
Quoted 5 lines · Keith Packard
drm_mode_create_leaseCreates a lease for a list of drm mode objects, returning an fd for the new
drm_masterand a 64-bit identifier for the lessee
Quoted 7 lines
drm_mode_list_leseesList the identifiers of the lessees from a particular lessor
drm_mode_get_leaseList the leased objects for a particular lessee
Should we just use fd for this? Essentially lessors would be required to keep track of all their pending leases, and just dup() them over to the client. Would reduce the uapi scope a bit, and if a lessor can't keep track of it's leases there's a problem.
Quoted 4 lines
drm_mode_change_leaseAdjust the terms of a lease, adding or removing resources or switching from masking to non-masking.
For this one here we could pass the fd of the lease as the argument. I also still think that for v1 we just want revoke and otherwise invariant leases. Makes things simpler.
Quoted 354 lines
This should suffice to at least create, query and manage available leases.
Signed-off-by Keith Packard <[email protected]>--- drivers/gpu/drm/drm_ioctl.c | 4 + drivers/gpu/drm/drm_lease.c | 309 ++++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_lease.h | 12 ++ include/uapi/drm/drm.h | 4 + include/uapi/drm/drm_mode.h | 78 +++++++++++ 5 files changed, 407 insertions(+)drivers/gpu/drm/drm_ioctl.c +4
-0@@ -636,6 +636,10 @@ static const struct drm_ioctl_desc drm_ioctls[] = {DRM_IOCTL_DEF (DRM_IOCTL_MODE_ATOMIC , drm_mode_atomic_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_CREATEPROPBLOB , drm_mode_createblob_ioctl,DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_DESTROYPROPBLOB , drm_mode_destroyblob_ioctl,DRM_CONTROL_ALLOW |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_CREATE_LEASE , drm_mode_create_lease_ioctl,DRM_ANY_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_LIST_LESSEES , drm_mode_list_lessees_ioctl,DRM_ANY_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_GET_LEASE , drm_mode_get_lease_ioctl,DRM_ANY_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), + DRM_IOCTL_DEF(DRM_IOCTL_MODE_CHANGE_LEASE, drm_mode_change_lease_ioctl, DRM_ANY_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), };#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )drivers/gpu/drm/drm_lease.c +309
-0@@ -483,3 +483,312 @@ void drm_lease_destroy(struct drm_master *master)DRM_DEBUG_LEASE ("drm_lease_destroy done %d\n" , master->lessee_id); } + +/** +* drm_mode_create_lease_ioctl - create a new lease +* @dev: the drm device +* @data: pointer to struct drm_mode_create_lease +* @file_priv: the file being manipulated +* +* The master associated with the specified file will have a lease +* created containing the objects specified in the ioctl structure. +* A file descriptor will be allocated for that and returned to the +* application. +*/ +int drm_mode_create_lease_ioctl (struct drm_device *dev, +void *data,struct drm_file *lessor_priv) +{ +struct drm_mode_create_lease *cl = data; +size_t object_count; +size_t o; +int ret =0 ; +struct idr leases; +struct drm_master *lessor = lessor_priv->master; +struct drm_master *lessee =NULL ; +struct file *lessee_file =NULL ; +struct file *lessor_file = lessor_priv->filp; +struct drm_file *lessee_priv; +int fd =-1 ; + + object_count = cl->object_count; +idr_init (&leases); + + fd =get_unused_fd_flags (cl->flags & (O_CLOEXEC |O_NONBLOCK )); + +DRM_DEBUG_LEASE ("Creating new lease\n" ); + +/* Lookup the mode objects and add their IDs to the lease request */ +for (o =0 ; o < object_count; o++) { +__u32 object_id; + +if (copy_from_user (&object_id, +u64_to_user_ptr (cl->object_ids) + o *sizeof (__u32), +sizeof (__u32))) { + ret = -EFAULT ; + goto bail; + } +DRM_DEBUG_LEASE ("Adding object %d to lease\n" , object_id); + + ret =idr_alloc (&leases, (void *)1 , object_id, object_id +1 ,GFP_KERNEL ); +if (ret <0 ) { +DRM_DEBUG_LEASE ("Object %d cannot be inserted into leases (%d)\n" , + object_id, ret); + goto bail; + } + } + +mutex_lock (&dev->master_mutex); + +DRM_DEBUG_LEASE ("Creating lease\n" ); + lessee =drm_lease_create (lessor, cl->mask_lease !=0 , &leases); + +if (IS_ERR (lessee)) { + ret =PTR_ERR (lessee); + lessee =NULL ; +mutex_unlock (&dev->master_mutex); + goto bail; + } + +/* Clone the lessor file to create a new file for us */ +DRM_DEBUG_LEASE ("Allocating lease file\n" ); +path_get (&lessor_file->f_path); + lessee_file =alloc_file (&lessor_file->f_path, + lessor_file->f_mode, +fops_get (lessor_file->f_inode->i_fop)); + +if (IS_ERR (lessee_file)) { + ret =PTR_ERR (lessee_file); + lessee_file =NULL ; +mutex_unlock (&dev->master_mutex); + goto bail; + } + +mutex_unlock (&dev->master_mutex); + +/* Initialize the new file for DRM */ +DRM_DEBUG_LEASE ("Initializing the file with %p\n" , lessee_file->f_op->open); + ret = lessee_file->f_op->open (lessee_file->f_inode, lessee_file); +if (ret) + goto bail; + + lessee_priv = lessee_file->private_data; + +/* Change the file to a master one */ +drm_master_put (&lessee_priv->master); + lessee_priv->master = lessee; + lessee_priv->is_master =1 ; + lessee_priv->authenticated =1 ; + +/* Hook up the fd */ +fd_install (fd, lessee_file); + +/* Pass fd back to userspace */ +DRM_DEBUG_LEASE ("Returning fd %d id %d\n" , fd, lessee->lessee_id); + cl->fd = fd; + cl->lessee_id = lessee->lessee_id; + +/* and don't destroy our resources */ + fd =-1 ; + lessee =NULL ; + lessee_file =NULL ; + + ret =0 ; + +bail: + +if (lessee_file) { +DRM_DEBUG_LEASE ("Freeing lessee file\n" ); +fput (lessee_file); + } + +if (lessee) { +DRM_DEBUG_LEASE ("Freeing lessee drm_master\n" ); +drm_master_put (&lessee); + } + +idr_destroy (&leases); + +if (fd !=-1 ) { +DRM_DEBUG_LEASE ("Freeing unused fd\n" ); +put_unused_fd (fd); + } + +DRM_DEBUG_LEASE ("Return %d from drm_mode_create_lease_ioctl\n" , ret); +return ret; +} + +/** +* drm_mode_list_lessees_ioctl - list lessee ids +* @dev: the drm device +* @data: pointer to struct drm_mode_create_lease +* @file_priv: the file being manipulated +* +* Starting from the master associated with the specified file, +* the master with the provided lessee_id is found, and then +* an array of lessee ids associated with leases from that master +* are returned. +*/ + +int drm_mode_list_lessees_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv) +{ +struct drm_mode_list_lessees *arg = data; +__u32 __user *lessee_ids = (__u32 __user *) (uintptr_t ) (arg->lessees_ptr); +__u32 count_lessees = arg->count_lessees; +struct drm_master *lessor, *lessee; +int count; +int ret =0 ; + +DRM_DEBUG_LEASE ("List lessees for %d\n" , arg->lessor_id); + +mutex_lock (&dev->master_mutex); + +/* Search the tree for the requested drm_master */ + lessor =drm_lessee_get (file_priv->master, arg->lessor_id); +if (!lessor) { +DRM_DEBUG_LEASE ("No such lessor %d\n" , arg->lessor_id); +mutex_unlock (&dev->master_mutex); +return -ENOENT ; + } + + count =0 ; +drm_for_each_lessee (lessee, lessor) { +if (count_lessees > count) { +DRM_DEBUG_LEASE ("Add lessee %d\n" , lessee->lessee_id); + ret =put_user (lessee->lessee_id, lessee_ids + count); +if (ret) +break ; + } + count++; + } + +DRM_DEBUG_LEASE ("Lessor leases to %d\n" , count); +if (ret ==0 ) + arg->count_lessees = count; + +drm_master_put (&lessor); + +mutex_unlock (&dev->master_mutex); + +return ret; +} + +/** +* drm_mode_get_lease_ioctl - list leased objects +* @dev: the drm device +* @data: pointer to struct drm_mode_create_lease +* @file_priv: the file being manipulated +* +* Return the list of leased objects for the specified lessee +*/ + +int drm_mode_get_lease_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv) +{ +struct drm_mode_get_lease *arg = data; +__u32 __user *object_ids = (__u32 __user *) (uintptr_t ) (arg->objects_ptr); +__u32 count_objects = arg->count_objects; +struct drm_master *lessee; +struct idr *object_idr; +int count; +void *entry; +int object; +int ret =0 ; + +DRM_DEBUG_LEASE ("get lease for %d\n" , arg->lessee_id); + +mutex_lock (&dev->master_mutex); + +/* Search the tree for the requested drm_master */ + lessee =drm_lessee_get (file_priv->master, arg->lessee_id); +if (!lessee) { +mutex_unlock (&dev->master_mutex); +DRM_DEBUG_LEASE ("No such lessee %d\n" , arg->lessee_id); +return -ENOENT ; + } + +if (lessee->lessor ==NULL ) + object_idr = &lessee->dev->mode_config.crtc_idr; +else + object_idr = &lessee->leases; + + count =0 ; +idr_for_each_entry (object_idr, entry, object) { +if (count_objects > count) { +DRM_DEBUG_LEASE ("adding object %d\n" , object); + ret =put_user (object, object_ids + count); +if (ret) +break ; + } + count++; + } + +DRM_DEBUG ("lease holds %d objects\n" , count); +if (ret ==0 ) + arg->count_objects = count; + +drm_master_put (&lessee); + +mutex_unlock (&dev->master_mutex); + +return ret; +} + +/** +* drm_mode_change_lease_ioctl - change the objects in a lease +* @dev: the drm device +* @data: pointer to struct drm_mode_create_lease +* @file_priv: the file being manipulated +* +* The master associated with the specified file will have a lease +* created containing the objects specified in the ioctl structure. +* A file descriptor will be allocated for that and returned to the +* application. +*/ +int drm_mode_change_lease_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv) +{ +struct drm_mode_create_lease *cl = data; +size_t object_count; +size_t o; +int ret =0 ; +struct idr leases; +struct drm_master *lessor = file_priv->master; + + object_count = cl->object_count; +idr_init (&leases); + +DRM_DEBUG_LEASE ("Changing existing lease\n" ); + +/* Lookup the mode objects and add their IDs to the lease request */ +for (o =0 ; o < object_count; o++) { +__u32 object_id; + +if (copy_from_user (&object_id, +u64_to_user_ptr (cl->object_ids) + o *sizeof (__u32), +sizeof (__u32))) { +return -EFAULT ; + } +DRM_DEBUG_LEASE ("Adding object %d to lease\n" , object_id); + + ret =idr_alloc (&leases, (void *)1 , object_id, object_id +1 ,GFP_KERNEL ); +if (ret <0 ) { +DRM_DEBUG_LEASE ("Object %d cannot be inserted into leases (%d)\n" , + object_id, ret); +return ret; + } + } + +mutex_lock (&dev->master_mutex); + +DRM_DEBUG_LEASE ("Change lease\n" ); + + ret =drm_lease_change (lessor, cl->lessee_id, cl->mask_lease !=0 , &leases); + +mutex_unlock (&dev->master_mutex); + +idr_destroy (&leases); + +DRM_DEBUG_LEASE ("Return %d from drm_mode_change_lease_ioctl\n" , ret); +return ret; +}include/drm/drm_lease.h +1
-0@@ -52,4 +52,16 @@ uint32_t drm_lease_filter_crtcs(struct drm_master *master, uint32_t crtcs);uint32_t drm_lease_filter_encoders (struct drm_master *master,uint32_t encoders); +int drm_mode_create_lease_ioctl(struct drm_device *dev,
include/drm/drm_lease.h uint32_t drm_lease_filter_crtcs(struct drm_master *master, uint32_t crtcs); · line 65
Quoted 10 lines
include/drm/drm_lease.h +10
-0+ void *data, struct drm_file *file_priv); + +int drm_mode_list_lessees_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv); + +int drm_mode_get_lease_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv); + +int drm_mode_change_lease_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv);
Non-driver functions please into drm-internal.h, we don't want to let drivers even see this :-)
Cheers, Daniel
Quoted 113 lines
include/drm/drm_lease.h +1
-0+#endif /* _DRM_LEASE_H_ */ include/uapi/drm/drm.h +4
-0@@ -813,6 +813,10 @@ extern "C" {#define DRM_IOCTL_MODE_ATOMIC DRM_IOWR(0xBC, struct drm_mode_atomic)#define DRM_IOCTL_MODE_CREATEPROPBLOB DRM_IOWR(0xBD, struct drm_mode_create_blob)#define DRM_IOCTL_MODE_DESTROYPROPBLOB DRM_IOWR(0xBE, struct drm_mode_destroy_blob) +#define DRM_IOCTL_MODE_CREATE_LEASE DRM_IOWR(0xBF, struct drm_mode_create_lease) +#define DRM_IOCTL_MODE_LIST_LESSEES DRM_IOWR(0xC0, struct drm_mode_list_lessees) +#define DRM_IOCTL_MODE_GET_LEASE DRM_IOWR(0xC1, struct drm_mode_get_lease) +#define DRM_IOCTL_MODE_CHANGE_LEASE DRM_IOWR(0xC2, struct drm_mode_change_lease)/** * Device specific ioctls should only be in their respective headers include/uapi/drm/drm_mode.h +78
-0@@ -681,6 +681,84 @@ struct drm_mode_destroy_blob {__u32 blob_id; }; +/** +* Lease mode resources, creating another drm_master. +*/ +struct drm_mode_create_lease { +/** Pointer to array of object ids (__u32) */ +__u64 object_ids; +/** Number of object ids */ +__u32 object_count; +/** flags for new FD (O_CLOEXEC, etc) */ +__u32 flags; +/** whether to hide the leased objects from the lessor */ +__u32 mask_lease; + +/** Return: unique identifier for lessee. */ +__u32 lessee_id; +/** Return: file descriptor to new drm_master file */ +__u32 fd; +}; + +/** +* List lesses from a drm_master +*/ +struct drm_mode_list_lessees { + +/** Identifier of the lessor's lessee_id (0 for owner) */ +__u32 lessor_id; + +/** Number of lessees. +* On input, provides length of the array. +* On output, provides total number. No +* more than the input number will be written +* back, so two calls can be used to get +* the size and then the data. +*/ +__u32 count_lessees; + +/** Pointer to lessees. +* pointer to __u64 array of lessee ids +*/ +__u64 lessees_ptr; +}; + +/** +* Get leased objects for a lessee +*/ +struct drm_mode_get_lease { +/** Identifier of the lessee (0 for owner) */ +__u32 lessee_id; + +/** Number of leased objects. +* On input, provides length of the array. +* On output, provides total number. No +* more than the input number will be written +* back, so two calls can be used to get +* the size and then the data. +*/ +__u32 count_objects; + +/** Pointer to objects. +* pointer to __u32 array of object ids +*/ +__u64 objects_ptr; +}; + +/** +* Change resources leased to another drm_master +*/ +struct drm_mode_change_lease { +/** Pointer to array of object ids (__u32) */ +__u64 object_ids; +/** Number of object ids */ +__u32 object_count; +/** unique identifier for lessee. */ +__u32 lessee_id; +/** whether to hide the leased objects from the lessor */ +__u32 mask_lease; +}; +#if defined(__cplusplus) }#endif Signature · 6 lines
2.11.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 4/4] drm: Add four ioctls for managing drm mode object leases
Quoted 4 lines · Daniel Vetter
Should we just use fd for this? Essentially lessors would be required to keep track of all their pending leases, and just
dup()them over to the client. Would reduce the uapi scope a bit, and if a lessor can't keep track of it's leases there's a problem.
Right now, the lease terminates when the fd closes. If the lessor is holding the fd open, it would have to have some out-of-band indication that the lessee was done so that it could close its copy of the fd.
However, it's not clear what value these query APIs have for the lessor in any case; surely it can remember what resources are in each lease without needing a kernel API. For the lessee, this API provides a way of learning about changes to the lease. That would mean getting rid of the lessee id in the requests, which seems good.
I added them mostly to make checking the code easier during development; it caught a nasty bug where I was smashing the lessor file_priv with the lessee due to poor choice of variable names in the kernel code.
I was thinking this morning that the lessee would like to know not only the ID but also the type of each resources so that it could figure out how to use the lease.
I'll rewrite these to only return the resources for the fd provided, but to return both id and type.
For listing lessees, I don't see value in allowing the lessor to look at sub-leases made by the lessee, so I'll remove the lessor id from that request and have it just return the list of lessees for the current lessor.
Quoted 3 lines
For this one here we could pass the fd of the lease as the argument. I also still think that for v1 we just want revoke and otherwise invariant leases. Makes things simpler.
Again, that means that lessor would need to hold the lease fd open, which makes it hard to know when the lessee is done. However, there's no reason the lessor should be in control of the lessee's sub-leases, so again, I propose to restrict the scope of lessees to those directly under the lessor.
Quoted 2 lines
Non-driver functions please into
drm-internal.h, we don't want to let drivers even see this :-)
Thanks!
Signature · 1 line
-keith
cover drm: Add mode resource leasing [v2]
In reply to Keith PackardHere's a second try at mode resource leasing. The differences from v1 are mostly deleting functionality that isn't currently useful.
There are no more sub-leases; there's the owner, the owner is the only lessor and so the only one who can create leases and hand those out.
The lessor can now manipulate all of the resources without restriction. It's up to user space to enforce whatever access control it wants.
The lessee can no longer see any resources other than those in the lease. This was a bit tricky as there are various indices into the reported arrays of objects in the form of masks.
The query ioctls no longer take lessor or lessee ids; you can query the leases you have granted or query the list of resources in your own lease. The X server uses the former to figure out when lessees close their DRM file and terminate a lease. As I write this, I'm wondering if that latter operation is actually useful though. If not, we can rip that ioctl out easily enough.
As suggested by Daniel Vetter, the first patch changes the API to __drm_mode_object_find to include a relevant struct drm_file * pointer so that function can perform any necessary per-file access control. When there isn't a suitable pointer, NULL is passed instead, which is a proxy for the origin DRM master. For leases, this means that no lease permissions checking is done. This is why there are now 5 patches instead of the original 4.
Thanks again to everyone who commented on the mailing list or on IRC; I'm pretty happy with the current functionality; I've got kmscube leasing resources from the X server this evening.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/5 drm: Pass struct drm_file * to __drm_mode_object_find
This will allow __drm_mode_object_file to be extended to perform access control checks based on the file in use.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 16 ++++++++-------- drivers/gpu/drm/amd/amdgpu/dce_virtual.c | 4 ++-- drivers/gpu/drm/ast/ast_mode.c | 2 +- drivers/gpu/drm/bochs/bochs_kms.c | 2 +- drivers/gpu/drm/cirrus/cirrus_mode.c | 2 +- drivers/gpu/drm/drm_atomic.c | 8 ++++---- drivers/gpu/drm/drm_atomic_helper.c | 2 +- drivers/gpu/drm/drm_color_mgmt.c | 4 ++-- drivers/gpu/drm/drm_connector.c | 2 +- drivers/gpu/drm/drm_crtc.c | 8 ++++---- drivers/gpu/drm/drm_crtc_internal.h | 1 + drivers/gpu/drm/drm_encoder.c | 2 +- drivers/gpu/drm/drm_framebuffer.c | 9 +++++---- drivers/gpu/drm/drm_mode_object.c | 10 ++++++---- drivers/gpu/drm/drm_plane.c | 14 +++++++------- drivers/gpu/drm/drm_property.c | 6 +++--- drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c | 2 +- drivers/gpu/drm/i915/intel_display.c | 2 +- drivers/gpu/drm/i915/intel_overlay.c | 2 +- drivers/gpu/drm/i915/intel_sprite.c | 2 +- drivers/gpu/drm/mgag200/mgag200_mode.c | 2 +- drivers/gpu/drm/nouveau/nouveau_connector.c | 4 ++-- drivers/gpu/drm/radeon/r100.c | 2 +- drivers/gpu/drm/radeon/r600_cs.c | 2 +- drivers/gpu/drm/radeon/radeon_connectors.c | 16 ++++++++-------- drivers/gpu/drm/udl/udl_connector.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c | 4 ++-- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 2 +- include/drm/drm_connector.h | 3 ++- include/drm/drm_crtc.h | 5 +++-- include/drm/drm_encoder.h | 3 ++- include/drm/drm_framebuffer.h | 1 + include/drm/drm_mode_object.h | 2 ++ include/drm/drm_plane.h | 3 ++- include/drm/drm_property.h | 3 ++- 35 files changed, 83 insertions(+), 71 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c +8 -8
@@ -231,7 +231,7 @@ amdgpu_connector_update_scratch_regs(struct drm_connector *connector,if (connector->encoder_ids[i] ==0 )break ; - encoder =drm_encoder_find (connector->dev, + encoder =drm_encoder_find (connector->dev,NULL , connector->encoder_ids[i]);if (!encoder)continue ;
@@ -256,7 +256,7 @@ amdgpu_connector_find_encoder(struct drm_connector *connector,for (i =0 ; i <DRM_CONNECTOR_MAX_ENCODER ; i++) {if (connector->encoder_ids[i] ==0 )break ; - encoder =drm_encoder_find (connector->dev, + encoder =drm_encoder_find (connector->dev,NULL , connector->encoder_ids[i]);if (!encoder)continue ;
@@ -374,7 +374,7 @@ amdgpu_connector_best_single_encoder(struct drm_connector *connector)/* pick the encoder ids */ if (enc_id) -return drm_encoder_find (connector->dev, enc_id); +return drm_encoder_find (connector->dev,NULL , enc_id);return NULL ; }
@@ -1079,7 +1079,7 @@ amdgpu_connector_dvi_detect(struct drm_connector *connector, bool force)if (connector->encoder_ids[i] ==0 )break ; - encoder =drm_encoder_find (connector->dev, connector->encoder_ids[i]); + encoder =drm_encoder_find (connector->dev,NULL , connector->encoder_ids[i]);if (!encoder)continue ;
@@ -1136,7 +1136,7 @@ amdgpu_connector_dvi_encoder(struct drm_connector *connector)if (connector->encoder_ids[i] ==0 )break ; - encoder =drm_encoder_find (connector->dev, connector->encoder_ids[i]); + encoder =drm_encoder_find (connector->dev,NULL , connector->encoder_ids[i]);if (!encoder)continue ;
@@ -1155,7 +1155,7 @@ amdgpu_connector_dvi_encoder(struct drm_connector *connector)/* then check use digitial */ /* pick the first one */ if (enc_id) -return drm_encoder_find (connector->dev, enc_id); +return drm_encoder_find (connector->dev,NULL , enc_id);return NULL ; }
@@ -1296,7 +1296,7 @@ u16 amdgpu_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connif (connector->encoder_ids[i] ==0 )break ; - encoder =drm_encoder_find (connector->dev, + encoder =drm_encoder_find (connector->dev,NULL , connector->encoder_ids[i]);if (!encoder)continue ;
@@ -1325,7 +1325,7 @@ static bool amdgpu_connector_encoder_is_hbr2(struct drm_connector *connector)for (i =0 ; i <DRM_CONNECTOR_MAX_ENCODER ; i++) {if (connector->encoder_ids[i] ==0 )break ; - encoder =drm_encoder_find (connector->dev, + encoder =drm_encoder_find (connector->dev,NULL , connector->encoder_ids[i]);if (!encoder)continue ;
drivers/gpu/drm/amd/amdgpu/dce_virtual.c +2 -2
@@ -362,7 +362,7 @@ dce_virtual_encoder(struct drm_connector *connector)if (connector->encoder_ids[i] ==0 )break ; - encoder =drm_encoder_find (connector->dev, connector->encoder_ids[i]); + encoder =drm_encoder_find (connector->dev,NULL , connector->encoder_ids[i]);if (!encoder)continue ;
@@ -372,7 +372,7 @@ dce_virtual_encoder(struct drm_connector *connector)/* pick the first one */ if (enc_id) -return drm_encoder_find (connector->dev, enc_id); +return drm_encoder_find (connector->dev,NULL , enc_id);return NULL ; }
drivers/gpu/drm/ast/ast_mode.c +1 -1
@@ -690,7 +690,7 @@ static struct drm_encoder *ast_best_single_encoder(struct drm_connector *connectint enc_id = connector->encoder_ids[0 ];/* pick the encoder ids */ if (enc_id) -return drm_encoder_find (connector->dev, enc_id); +return drm_encoder_find (connector->dev,NULL , enc_id);return NULL ; }
drivers/gpu/drm/bochs/bochs_kms.c +1 -1
@@ -212,7 +212,7 @@ bochs_connector_best_encoder(struct drm_connector *connector)int enc_id = connector->encoder_ids[0 ];/* pick the encoder ids */ if (enc_id) -return drm_encoder_find (connector->dev, enc_id); +return drm_encoder_find (connector->dev,NULL , enc_id);return NULL ; }
drivers/gpu/drm/cirrus/cirrus_mode.c +1 -1
@@ -494,7 +494,7 @@ static struct drm_encoder *cirrus_connector_best_encoder(struct drm_connectorint enc_id = connector->encoder_ids[0 ];/* pick the encoder ids */ if (enc_id) -return drm_encoder_find (connector->dev, enc_id); +return drm_encoder_find (connector->dev,NULL , enc_id);return NULL ; }
drivers/gpu/drm/drm_atomic.c +4 -4
@@ -738,7 +738,7 @@ int drm_atomic_plane_set_property(struct drm_plane *plane,struct drm_mode_config *config = &dev->mode_config;if (property == config->prop_fb_id) { -struct drm_framebuffer *fb =drm_framebuffer_lookup (dev, val); +struct drm_framebuffer *fb =drm_framebuffer_lookup (dev,NULL , val);drm_atomic_set_fb_for_plane (state, fb);if (fb)drm_framebuffer_unreference (fb);
@@ -754,7 +754,7 @@ int drm_atomic_plane_set_property(struct drm_plane *plane,return -EINVAL ; }else if (property == config->prop_crtc_id) { -struct drm_crtc *crtc =drm_crtc_find (dev, val); +struct drm_crtc *crtc =drm_crtc_find (dev,NULL , val);return drm_atomic_set_crtc_for_plane (state, crtc); }else if (property == config->prop_crtc_x) { state->crtc_x =U642I64 (val);
@@ -1079,7 +1079,7 @@ int drm_atomic_connector_set_property(struct drm_connector *connector,struct drm_mode_config *config = &dev->mode_config;if (property == config->prop_crtc_id) { -struct drm_crtc *crtc =drm_crtc_find (dev, val); +struct drm_crtc *crtc =drm_crtc_find (dev,NULL , val);return drm_atomic_set_crtc_for_connector (state, crtc); }else if (property == config->dpms_property) {/* setting DPMS property requires special handling, which
@@ -2128,7 +2128,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev, goto out; } - obj =drm_mode_object_find (dev, obj_id,DRM_MODE_OBJECT_ANY ); + obj =drm_mode_object_find (dev, file_priv, obj_id,DRM_MODE_OBJECT_ANY );if (!obj) { ret = -ENOENT ; goto out;
drivers/gpu/drm/drm_atomic_helper.c +1 -1
@@ -2901,7 +2901,7 @@ struct drm_encoder * drm_atomic_helper_best_encoder(struct drm_connector *connector) {WARN_ON (connector->encoder_ids[1 ]); -return drm_encoder_find (connector->dev, connector->encoder_ids[0 ]); +return drm_encoder_find (connector->dev,NULL , connector->encoder_ids[0 ]); }EXPORT_SYMBOL (drm_atomic_helper_best_encoder);
drivers/gpu/drm/drm_color_mgmt.c +2 -2
@@ -200,7 +200,7 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev,return -EINVAL ;drm_modeset_lock_all (dev); - crtc =drm_crtc_find (dev, crtc_lut->crtc_id); + crtc =drm_crtc_find (dev, file_priv, crtc_lut->crtc_id);if (!crtc) { ret = -ENOENT ; goto out;
@@ -272,7 +272,7 @@ int drm_mode_gamma_get_ioctl(struct drm_device *dev,return -EINVAL ;drm_modeset_lock_all (dev); - crtc =drm_crtc_find (dev, crtc_lut->crtc_id); + crtc =drm_crtc_find (dev, file_priv, crtc_lut->crtc_id);if (!crtc) { ret = -ENOENT ; goto out;
drivers/gpu/drm/drm_connector.c +1 -1
@@ -1087,7 +1087,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,mutex_lock (&dev->mode_config.mutex); - connector =drm_connector_lookup (dev, out_resp->connector_id); + connector =drm_connector_lookup (dev, file_priv, out_resp->connector_id);if (!connector) { ret = -ENOENT ; goto out_unlock;
drivers/gpu/drm/drm_crtc.c +4 -4
@@ -351,7 +351,7 @@ int drm_mode_getcrtc(struct drm_device *dev,if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EINVAL ; - crtc =drm_crtc_find (dev, crtc_resp->crtc_id); + crtc =drm_crtc_find (dev, file_priv, crtc_resp->crtc_id);if (!crtc)return -ENOENT ;
@@ -521,7 +521,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,return -ERANGE ;drm_modeset_lock_all (dev); - crtc =drm_crtc_find (dev, crtc_req->crtc_id); + crtc =drm_crtc_find (dev, file_priv, crtc_req->crtc_id);if (!crtc) {DRM_DEBUG_KMS ("Unknown CRTC ID %d\n" , crtc_req->crtc_id); ret = -ENOENT ;
@@ -542,7 +542,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,/* Make refcounting symmetric with the lookup path. */ drm_framebuffer_reference (fb); }else { - fb =drm_framebuffer_lookup (dev, crtc_req->fb_id); + fb =drm_framebuffer_lookup (dev, file_priv, crtc_req->fb_id);if (!fb) {DRM_DEBUG_KMS ("Unknown FB ID%d\n" , crtc_req->fb_id);
@@ -627,7 +627,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, goto out; } - connector =drm_connector_lookup (dev, out_id); + connector =drm_connector_lookup (dev, file_priv, out_id);if (!connector) {DRM_DEBUG_KMS ("Connector id %d unknown\n" , out_id);
drivers/gpu/drm/drm_crtc_internal.h +1 -0
@@ -108,6 +108,7 @@ void drm_mode_object_register(struct drm_device *dev,int drm_mode_object_get (struct drm_device *dev,struct drm_mode_object *obj,uint32_t obj_type);struct drm_mode_object *__drm_mode_object_find (struct drm_device *dev, +struct drm_file *file_priv,uint32_t id,uint32_t type);void drm_mode_object_unregister (struct drm_device *dev,struct drm_mode_object *object);
drivers/gpu/drm/drm_encoder.c +1 -1
@@ -205,7 +205,7 @@ int drm_mode_getencoder(struct drm_device *dev, void *data,if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EINVAL ; - encoder =drm_encoder_find (dev, enc_resp->encoder_id); + encoder =drm_encoder_find (dev, file_priv, enc_resp->encoder_id);if (!encoder)return -ENOENT ;
drivers/gpu/drm/drm_framebuffer.c +5 -4
@@ -357,7 +357,7 @@ int drm_mode_rmfb(struct drm_device *dev,if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EINVAL ; - fb =drm_framebuffer_lookup (dev, *id); + fb =drm_framebuffer_lookup (dev, file_priv, *id);if (!fb)return -ENOENT ;
@@ -426,7 +426,7 @@ int drm_mode_getfb(struct drm_device *dev,if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EINVAL ; - fb =drm_framebuffer_lookup (dev, r->fb_id); + fb =drm_framebuffer_lookup (dev, file_priv, r->fb_id);if (!fb)return -ENOENT ;
@@ -491,7 +491,7 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EINVAL ; - fb =drm_framebuffer_lookup (dev, r->fb_id); + fb =drm_framebuffer_lookup (dev, file_priv, r->fb_id);if (!fb)return -ENOENT ;
@@ -661,12 +661,13 @@ EXPORT_SYMBOL(drm_framebuffer_init);* again, using @drm_framebuffer_unreference. */ struct drm_framebuffer *drm_framebuffer_lookup (struct drm_device *dev, +struct drm_file *file_priv,uint32_t id) {struct drm_mode_object *obj;struct drm_framebuffer *fb =NULL ; - obj =__drm_mode_object_find (dev, id,DRM_MODE_OBJECT_FB ); + obj =__drm_mode_object_find (dev, file_priv, id,DRM_MODE_OBJECT_FB );if (obj) fb =obj_to_fb (obj);return fb;
drivers/gpu/drm/drm_mode_object.c +6 -4
@@ -108,6 +108,7 @@ void drm_mode_object_unregister(struct drm_device *dev, }struct drm_mode_object *__drm_mode_object_find (struct drm_device *dev, +struct drm_file *file_priv,uint32_t id,uint32_t type) {struct drm_mode_object *obj =NULL ;
@@ -130,7 +131,7 @@ struct drm_mode_object *__drm_mode_object_find(struct drm_device *dev,/** * drm_mode_object_find - look up a drm object with static lifetime -* @dev: drm device +* @file_priv: drm file * @id: id of the mode object * @type: type of the mode object *
@@ -139,11 +140,12 @@ struct drm_mode_object *__drm_mode_object_find(struct drm_device *dev,* by callind drm_mode_object_unreference(). */ struct drm_mode_object *drm_mode_object_find (struct drm_device *dev, +struct drm_file *file_priv,uint32_t id,uint32_t type) {struct drm_mode_object *obj =NULL ; - obj =__drm_mode_object_find (dev, id, type); + obj =__drm_mode_object_find (dev, file_priv, id, type);return obj; }EXPORT_SYMBOL (drm_mode_object_find);
@@ -350,7 +352,7 @@ int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,drm_modeset_lock_all (dev); - obj =drm_mode_object_find (dev, arg->obj_id, arg->obj_type); + obj =drm_mode_object_find (dev, file_priv, arg->obj_id, arg->obj_type);if (!obj) { ret = -ENOENT ; goto out;
@@ -398,7 +400,7 @@ int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,drm_modeset_lock_all (dev); - arg_obj =drm_mode_object_find (dev, arg->obj_id, arg->obj_type); + arg_obj =drm_mode_object_find (dev, file_priv, arg->obj_id, arg->obj_type);if (!arg_obj) { ret = -ENOENT ; goto out;
drivers/gpu/drm/drm_plane.c +7 -7
@@ -387,7 +387,7 @@ int drm_mode_getplane(struct drm_device *dev, void *data,if (!drm_core_check_feature (dev,DRIVER_MODESET ))return -EINVAL ; - plane =drm_plane_find (dev, plane_resp->plane_id); + plane =drm_plane_find (dev, file_priv, plane_resp->plane_id);if (!plane)return -ENOENT ;
@@ -559,7 +559,7 @@ int drm_mode_setplane(struct drm_device *dev, void *data,* First, find the plane, crtc, and fb objects. If not available, * we don't bother to call the driver. */ - plane =drm_plane_find (dev, plane_req->plane_id); + plane =drm_plane_find (dev, file_priv, plane_req->plane_id);if (!plane) {DRM_DEBUG_KMS ("Unknown plane ID %d\n" , plane_req->plane_id);
@@ -567,14 +567,14 @@ int drm_mode_setplane(struct drm_device *dev, void *data, }if (plane_req->fb_id) { - fb =drm_framebuffer_lookup (dev, plane_req->fb_id); + fb =drm_framebuffer_lookup (dev, file_priv, plane_req->fb_id);if (!fb) {DRM_DEBUG_KMS ("Unknown framebuffer ID %d\n" , plane_req->fb_id);return -ENOENT ; } - crtc =drm_crtc_find (dev, plane_req->crtc_id); + crtc =drm_crtc_find (dev, file_priv, plane_req->crtc_id);if (!crtc) {DRM_DEBUG_KMS ("Unknown crtc ID %d\n" , plane_req->crtc_id);
@@ -682,7 +682,7 @@ static int drm_mode_cursor_common(struct drm_device *dev,if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags))return -EINVAL ; - crtc =drm_crtc_find (dev, req->crtc_id); + crtc =drm_crtc_find (dev, file_priv, req->crtc_id);if (!crtc) {DRM_DEBUG_KMS ("Unknown CRTC ID %d\n" , req->crtc_id);return -ENOENT ;
@@ -781,7 +781,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,if ((page_flip->flags &DRM_MODE_PAGE_FLIP_ASYNC ) && !dev->mode_config.async_page_flip)return -EINVAL ; - crtc =drm_crtc_find (dev, page_flip->crtc_id); + crtc =drm_crtc_find (dev, file_priv, page_flip->crtc_id);if (!crtc)return -ENOENT ;
@@ -834,7 +834,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, goto out; } - fb =drm_framebuffer_lookup (dev, page_flip->fb_id); + fb =drm_framebuffer_lookup (dev, file_priv, page_flip->fb_id);if (!fb) { ret = -ENOENT ; goto out;
drivers/gpu/drm/drm_property.c +3 -3
@@ -452,7 +452,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,return -EINVAL ;drm_modeset_lock_all (dev); - property =drm_property_find (dev, out_resp->prop_id); + property =drm_property_find (dev, file_priv, out_resp->prop_id);if (!property) { ret = -ENOENT ; goto done;
@@ -648,7 +648,7 @@ struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,struct drm_mode_object *obj;struct drm_property_blob *blob =NULL ; - obj =__drm_mode_object_find (dev, id,DRM_MODE_OBJECT_BLOB ); + obj =__drm_mode_object_find (dev,NULL , id,DRM_MODE_OBJECT_BLOB );if (obj) blob =obj_to_blob (obj);return blob;
@@ -888,7 +888,7 @@ bool drm_property_change_valid_get(struct drm_property *property,if (value ==0 )return true; - *ref =__drm_mode_object_find (property->dev, value, + *ref =__drm_mode_object_find (property->dev,NULL , value, property->values[0 ]);return *ref !=NULL ; }
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c +1 -1
@@ -36,7 +36,7 @@ static int hibmc_connector_mode_valid(struct drm_connector *connector,static struct drm_encoder *hibmc_connector_best_encoder (struct drm_connector *connector) { -return drm_encoder_find (connector->dev, connector->encoder_ids[0 ]); +return drm_encoder_find (connector->dev,NULL , connector->encoder_ids[0 ]); } static const struct drm_connector_helper_funcs
drivers/gpu/drm/i915/intel_display.c +1 -1
@@ -15352,7 +15352,7 @@ int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,struct drm_crtc *drmmode_crtc;struct intel_crtc *crtc; - drmmode_crtc =drm_crtc_find (dev, pipe_from_crtc_id->crtc_id); + drmmode_crtc =drm_crtc_find (dev, file, pipe_from_crtc_id->crtc_id);if (!drmmode_crtc)return -ENOENT ;
drivers/gpu/drm/i915/intel_overlay.c +1 -1
@@ -1119,7 +1119,7 @@ int intel_overlay_put_image_ioctl(struct drm_device *dev, void *data,if (!params)return -ENOMEM ; - drmmode_crtc =drm_crtc_find (dev, put_image_rec->crtc_id); + drmmode_crtc =drm_crtc_find (dev, file_priv, put_image_rec->crtc_id);if (!drmmode_crtc) { ret = -ENOENT ; goto out_free;
drivers/gpu/drm/i915/intel_sprite.c +1 -1
@@ -946,7 +946,7 @@ int intel_sprite_set_colorkey(struct drm_device *dev, void *data, set->flags & I915_SET_COLORKEY_DESTINATION)return -EINVAL ; - plane =drm_plane_find (dev, set->plane_id); + plane =drm_plane_find (dev, file_priv, set->plane_id);if (!plane || plane->type !=DRM_PLANE_TYPE_OVERLAY )return -ENOENT ;
drivers/gpu/drm/mgag200/mgag200_mode.c +1 -1
@@ -1654,7 +1654,7 @@ static struct drm_encoder *mga_connector_best_encoder(struct drm_connectorint enc_id = connector->encoder_ids[0 ];/* pick the encoder ids */ if (enc_id) -return drm_encoder_find (connector->dev, enc_id); +return drm_encoder_find (connector->dev,NULL , enc_id);return NULL ; }
drivers/gpu/drm/nouveau/nouveau_connector.c +2 -2
@@ -372,7 +372,7 @@ find_encoder(struct drm_connector *connector, int type)if (!id)break ; - enc =drm_encoder_find (dev, id); + enc =drm_encoder_find (dev,NULL , id);if (!enc)continue ; nv_encoder =nouveau_encoder (enc);
@@ -440,7 +440,7 @@ nouveau_connector_ddc_detect(struct drm_connector *connector)if (id ==0 )break ; - encoder =drm_encoder_find (dev, id); + encoder =drm_encoder_find (dev,NULL , id);if (!encoder)continue ; nv_encoder =nouveau_encoder (encoder);
drivers/gpu/drm/radeon/r100.c +1 -1
@@ -1460,7 +1460,7 @@ int r100_cs_packet_parse_vline(struct radeon_cs_parser *p) header =radeon_get_ib_value (p, h_idx); crtc_id =radeon_get_ib_value (p, h_idx +5 ); reg =R100_CP_PACKET0_GET_REG (header); - crtc =drm_crtc_find (p->rdev->ddev, crtc_id); + crtc =drm_crtc_find (p->rdev->ddev, p->filp, crtc_id);if (!crtc) {DRM_ERROR ("cannot find crtc %d\n" , crtc_id);return -ENOENT ;
drivers/gpu/drm/radeon/r600_cs.c +1 -1
@@ -887,7 +887,7 @@ int r600_cs_common_vline_parse(struct radeon_cs_parser *p, crtc_id =radeon_get_ib_value (p, h_idx +2 +7 +1 ); reg =R600_CP_PACKET0_GET_REG (header); - crtc =drm_crtc_find (p->rdev->ddev, crtc_id); + crtc =drm_crtc_find (p->rdev->ddev, p->filp, crtc_id);if (!crtc) {DRM_ERROR ("cannot find crtc %d\n" , crtc_id);return -ENOENT ;
drivers/gpu/drm/radeon/radeon_connectors.c +8 -8
@@ -263,7 +263,7 @@ radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_cif (connector->encoder_ids[i] ==0 )break ; - encoder =drm_encoder_find (connector->dev, + encoder =drm_encoder_find (connector->dev,NULL , connector->encoder_ids[i]);if (!encoder)continue ;
@@ -290,7 +290,7 @@ static struct drm_encoder *radeon_find_encoder(struct drm_connector *connector,if (connector->encoder_ids[i] ==0 )break ; - encoder =drm_encoder_find (connector->dev, connector->encoder_ids[i]); + encoder =drm_encoder_find (connector->dev,NULL , connector->encoder_ids[i]);if (!encoder)continue ;
@@ -404,7 +404,7 @@ static struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connint enc_id = connector->encoder_ids[0 ];/* pick the encoder ids */ if (enc_id) -return drm_encoder_find (connector->dev, enc_id); +return drm_encoder_find (connector->dev,NULL , enc_id);return NULL ; }
@@ -1365,7 +1365,7 @@ radeon_dvi_detect(struct drm_connector *connector, bool force)if (connector->encoder_ids[i] ==0 )break ; - encoder =drm_encoder_find (connector->dev, + encoder =drm_encoder_find (connector->dev,NULL , connector->encoder_ids[i]);if (!encoder)continue ;
@@ -1451,7 +1451,7 @@ static struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)if (connector->encoder_ids[i] ==0 )break ; - encoder =drm_encoder_find (connector->dev, connector->encoder_ids[i]); + encoder =drm_encoder_find (connector->dev,NULL , connector->encoder_ids[i]);if (!encoder)continue ;
@@ -1470,7 +1470,7 @@ static struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)/* then check use digitial */ /* pick the first one */ if (enc_id) -return drm_encoder_find (connector->dev, enc_id); +return drm_encoder_find (connector->dev,NULL , enc_id);return NULL ; }
@@ -1617,7 +1617,7 @@ u16 radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connif (connector->encoder_ids[i] ==0 )break ; - encoder =drm_encoder_find (connector->dev, connector->encoder_ids[i]); + encoder =drm_encoder_find (connector->dev,NULL , connector->encoder_ids[i]);if (!encoder)continue ;
@@ -1646,7 +1646,7 @@ static bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector)if (connector->encoder_ids[i] ==0 )break ; - encoder =drm_encoder_find (connector->dev, connector->encoder_ids[i]); + encoder =drm_encoder_find (connector->dev,NULL , connector->encoder_ids[i]);if (!encoder)continue ;
drivers/gpu/drm/udl/udl_connector.c +1 -1
@@ -105,7 +105,7 @@ static struct drm_encoder* udl_best_single_encoder(struct drm_connector *connector) {int enc_id = connector->encoder_ids[0 ]; -return drm_encoder_find (connector->dev, enc_id); +return drm_encoder_find (connector->dev,NULL , enc_id); } static int udl_connector_set_property(struct drm_connector *connector,
drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c +2 -2
@@ -288,7 +288,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,drm_modeset_lock_all (dev); - fb =drm_framebuffer_lookup (dev, arg->fb_id); + fb =drm_framebuffer_lookup (dev, file_priv, arg->fb_id);if (!fb) {DRM_ERROR ("Invalid framebuffer id.\n" ); ret = -ENOENT ;
@@ -371,7 +371,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,drm_modeset_lock_all (dev); - fb =drm_framebuffer_lookup (dev, arg->fb_id); + fb =drm_framebuffer_lookup (dev, file_priv, arg->fb_id);if (!fb) {DRM_ERROR ("Invalid framebuffer id.\n" ); ret = -ENOENT ;
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +1 -1
@@ -1168,7 +1168,7 @@ int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,return 0 ; } - crtc =drm_crtc_find (dev, arg->crtc_id); + crtc =drm_crtc_find (dev, file_priv, arg->crtc_id);if (!crtc) { ret = -ENOENT ; goto out;
include/drm/drm_connector.h +2 -1
@@ -772,10 +772,11 @@ static inline unsigned drm_connector_index(struct drm_connector *connector)* add takes a reference to it. */ static inline struct drm_connector *drm_connector_lookup (struct drm_device *dev, +struct drm_file *file_priv,uint32_t id) {struct drm_mode_object *mo; - mo =drm_mode_object_find (dev, id,DRM_MODE_OBJECT_CONNECTOR ); + mo =drm_mode_object_find (dev, file_priv, id,DRM_MODE_OBJECT_CONNECTOR );return mo ?obj_to_connector (mo) :NULL ; }
include/drm/drm_crtc.h +3 -2
@@ -833,10 +833,11 @@ int drm_mode_set_config_internal(struct drm_mode_set *set);/* Helpers */ static inline struct drm_crtc *drm_crtc_find (struct drm_device *dev, -uint32_t id) +struct drm_file *file_priv, +uint32_t id) {struct drm_mode_object *mo; - mo =drm_mode_object_find (dev, id,DRM_MODE_OBJECT_CRTC ); + mo =drm_mode_object_find (dev, file_priv, id,DRM_MODE_OBJECT_CRTC );return mo ?obj_to_crtc (mo) :NULL ; }
include/drm/drm_encoder.h +2 -1
@@ -213,11 +213,12 @@ static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,* drm_mode_object_find(). */ static inline struct drm_encoder *drm_encoder_find (struct drm_device *dev, +struct drm_file *file_priv,uint32_t id) {struct drm_mode_object *mo; - mo =drm_mode_object_find (dev, id,DRM_MODE_OBJECT_ENCODER ); + mo =drm_mode_object_find (dev, file_priv, id,DRM_MODE_OBJECT_ENCODER );return mo ?obj_to_encoder (mo) :NULL ; }
include/drm/drm_framebuffer.h +1 -0
@@ -212,6 +212,7 @@ int drm_framebuffer_init(struct drm_device *dev,struct drm_framebuffer *fb, const struct drm_framebuffer_funcs *funcs);struct drm_framebuffer *drm_framebuffer_lookup (struct drm_device *dev, +struct drm_file *file_priv,uint32_t id);void drm_framebuffer_remove (struct drm_framebuffer *fb);void drm_framebuffer_cleanup (struct drm_framebuffer *fb);
include/drm/drm_mode_object.h +2 -0
@@ -27,6 +27,7 @@struct drm_object_properties ;struct drm_property ;struct drm_device ; +struct drm_file ;/** * struct drm_mode_object - base structure for modeset objects
@@ -108,6 +109,7 @@ struct drm_object_properties { }struct drm_mode_object *drm_mode_object_find (struct drm_device *dev, +struct drm_file *file_priv,uint32_t id,uint32_t type);void drm_mode_object_reference (struct drm_mode_object *obj);void drm_mode_object_unreference (struct drm_mode_object *obj);
include/drm/drm_plane.h +2 -1
@@ -554,10 +554,11 @@ int drm_mode_plane_set_obj_prop(struct drm_plane *plane,* drm_mode_object_find(). */ static inline struct drm_plane *drm_plane_find (struct drm_device *dev, +struct drm_file *file_priv,uint32_t id) {struct drm_mode_object *mo; - mo =drm_mode_object_find (dev, id,DRM_MODE_OBJECT_PLANE ); + mo =drm_mode_object_find (dev, file_priv, id,DRM_MODE_OBJECT_PLANE );return mo ?obj_to_plane (mo) :NULL ; }
include/drm/drm_property.h +2 -1
@@ -285,10 +285,11 @@ void drm_property_unreference_blob(struct drm_property_blob *blob);* This function looks up the property object specified by id and returns it. */ static inline struct drm_property *drm_property_find (struct drm_device *dev, +struct drm_file *file_priv,uint32_t id) {struct drm_mode_object *mo; - mo =drm_mode_object_find (dev, id,DRM_MODE_OBJECT_PROPERTY ); + mo =drm_mode_object_find (dev, file_priv, id,DRM_MODE_OBJECT_PROPERTY );return mo ?obj_to_property (mo) :NULL ; }
Signature · 6 lines
2.11.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/5 drm: Add new LEASE debug level
In reply to Keith PackardSeparate out lease debugging from the core.
--- drivers/gpu/drm/drm_drv.c | 3 ++- include/drm/drmP.h | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_drv.c +2 -1
@@ -57,7 +57,8 @@ MODULE_PARM_DESC(debug, "Enable debug output, where each bit enables a debug cat"\t\tBit 2 (0x04) will enable KMS messages (modesetting code)\n" "\t\tBit 3 (0x08) will enable PRIME messages (prime code)\n" "\t\tBit 4 (0x10) will enable ATOMIC messages (atomic code)\n" -"\t\tBit 5 (0x20) will enable VBL messages (vblank code)"); +"\t\tBit 5 (0x20) will enable VBL messages (vblank code)\n" +"\t\tBit 7 (0x80) will enable LEASE messages (leasing code)");module_param_named (debug, drm_debug, int,0600 );static DEFINE_SPINLOCK (drm_minor_lock);
include/drm/drmP.h +4 -0
@@ -137,6 +137,7 @@ struct dma_buf_attachment;#define DRM_UT_ATOMIC 0x10#define DRM_UT_VBL 0x20#define DRM_UT_STATE 0x40 +#define DRM_UT_LEASE 0x80/***********************************************************************/ /** \name DRM template customization defaults */
@@ -251,6 +252,9 @@ struct dma_buf_attachment;#define DRM_DEBUG_VBL (fmt, ...) \ drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__) +#define DRM_DEBUG_LEASE (fmt, ...) \ + drm_printk(KERN_DEBUG, DRM_UT_LEASE, fmt, ##__VA_ARGS__) + #define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...) \ ({ \ static DEFINE_RATELIMIT_STATE(_rs, \
Signature · 6 lines
2.11.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/5 drm: Add drm_object lease infrastructure [v2]
In reply to Keith PackardThis provides new data structures to hold "lease" information about drm mode setting objects, and provides for creating new drm_masters which have access to a subset of the available drm resources.
An 'owner' is a drm_master which is not leasing the objects from another drm_master, and hence 'owns' them.
A 'lessee' is a drm_master which is leasing objects from some other drm_master. Each lessee holds the set of objects which it is leasing from the lessor.
A 'lessor' is a drm_master which is leasing objects to another drm_master. This is the same as the owner in the current code.
The set of objects any drm_master 'controls' is limited to the set of objects it leases (for lessees) or all objects (for owners).
Objects not controlled by a drm_master cannot be modified through the various state manipulating ioctls, and any state reported back to user space will be edited to make them appear idle and/or unusable. For instance, connectors always report 'disconnected', while encoders report no possible crtcs or clones.
The full list of lessees leasing objects from an owner (either directly, or indirectly through another lessee), can be searched from an idr in the drm_master of the owner.
Changes for v2 as suggested by Daniel Vetter <[email protected]>:
* Sub-leasing has been disabled.
* BUG_ON for lock checking replaced with lockdep_assert_held
* 'change' ioctl has been removed.
* Leased objects can always be controlled by the lessor; the 'mask_lease' flag has been removed
* Checking for leased status has been simplified, replacing the drm_lease_check function with drm_lease_held.
--- drivers/gpu/drm/Makefile | 3 +- drivers/gpu/drm/drm_auth.c | 22 ++- drivers/gpu/drm/drm_lease.c | 313 ++++++++++++++++++++++++++++++++++++++++++ include/drm/drmP.h | 1 + include/drm/drm_auth.h | 20 +++ include/drm/drm_lease.h | 34 +++++ include/drm/drm_mode_object.h | 1 + 7 files changed, 392 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/drm_lease.c create mode 100644 include/drm/drm_lease.h
drivers/gpu/drm/Makefile +2 -1
@@ -16,7 +16,8 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \ drm_framebuffer.o drm_connector.o drm_blend.o \ drm_encoder.o drm_mode_object.o drm_property.o \ drm_plane.o drm_color_mgmt.o drm_print.o \ - drm_dumb_buffers.o drm_mode_config.o + drm_dumb_buffers.o drm_mode_config.o \ + drm_lease.o drm-$(CONFIG_COMPAT) += drm_ioc32.o drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
drivers/gpu/drm/drm_auth.c +21 -1
@@ -31,6 +31,7 @@#include <drm/drmP.h> #include "drm_internal.h" #include "drm_legacy.h" +#include <drm/drm_lease.h> /** * DOC: master and authentication
@@ -93,7 +94,7 @@ int drm_authmagic(struct drm_device *dev, void *data,return file ?0 : -EINVAL ; } -static struct drm_master *drm_master_create (struct drm_device *dev) +struct drm_master *drm_master_create (struct drm_device *dev) {struct drm_master *master;
@@ -107,6 +108,14 @@ static struct drm_master *drm_master_create(struct drm_device *dev)idr_init (&master->magic_map); master->dev = dev; +/* initialize the tree of output resource lessees */ + master->lessor =NULL ; + master->lessee_id =0 ; +INIT_LIST_HEAD (&master->lessees); +INIT_LIST_HEAD (&master->lessee_list); +idr_init (&master->leases); +idr_init (&master->lessee_idr); +return master; }
@@ -189,6 +198,12 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data, goto out_unlock; } +if (file_priv->master->lessor !=NULL ) { +DRM_DEBUG_LEASE ("Attempt to set lessee %d as master\n" , file_priv->master->lessee_id); + ret = -EINVAL ; + goto out_unlock; + } + ret =drm_set_master (dev, file_priv, false); out_unlock:mutex_unlock (&dev->master_mutex);
@@ -310,12 +325,17 @@ static void drm_master_destroy(struct kref *kref) struct drm_master *master = container_of(kref, struct drm_master, refcount);struct drm_device *dev = master->dev; +drm_lease_destroy (master); +if (dev->driver->master_destroy) dev->driver->master_destroy (dev, master);drm_legacy_master_rmmaps (dev, master);idr_destroy (&master->magic_map); + +idr_destroy (&master->lessee_idr); +kfree (master->unique);kfree (master); }
drivers/gpu/drm/drm_lease.c new file +313 -0
313 lines not on this page · raw message
include/drm/drmP.h +1 -0
@@ -340,6 +340,7 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,#define DRM_CONTROL_ALLOW 0x8#define DRM_UNLOCKED 0x10#define DRM_RENDER_ALLOW 0x20 +#define DRM_ANY_MASTER 0x40struct drm_ioctl_desc {unsigned int cmd;
include/drm/drm_auth.h +20 -0
@@ -38,6 +38,12 @@* @magic_map: Map of used authentication tokens. Protected by struct_mutex. * @lock: DRI lock information. * @driver_priv: Pointer to driver-private information. +* @lessor: Lease holder +* @lessee_id: id for lessees. Owners always have id 0 +* @lessee_list: other lessees of the same master +* @lessees: drm_masters leasing from this one +* @leases: Objects leased to this drm_master. +* @lessee_idr: All lessees under this owner (only used where lessor == NULL) * * Note that master structures are only relevant for the legacy/primary device * nodes, hence there can only be one per device, not one per drm_minor.
@@ -50,10 +56,24 @@ struct drm_master {struct idr magic_map;struct drm_lock_data lock;void *driver_priv; + +/* Tree of display resource leases, each of which is a drm_master struct +* All of these get activated simultaneously, so drm_device master points +* at the top of the tree (for which lessor is NULL) +*/ + +struct drm_master *lessor; +int lessee_id; +struct list_head lessee_list; +struct list_head lessees; +struct idr leases; + struct idr lessee_idr; };struct drm_master *drm_master_get (struct drm_master *master);void drm_master_put (struct drm_master **master);bool drm_is_current_master (struct drm_file *fpriv); +struct drm_master *drm_master_create (struct drm_device *dev); +#endif
include/drm/drm_lease.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright © 2017 Keith Packard <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +*/ + +#ifndef _DRM_LEASE_H_ +#define _DRM_LEASE_H_ + +struct drm_file ; +struct drm_device ; +struct drm_master ; + +struct drm_master *drm_lease_owner (struct drm_master *master); + +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); + +uint32_t drm_lease_filter_crtcs (struct drm_file *file_priv,uint32_t crtcs); + +uint32_t drm_lease_filter_encoders (struct drm_file *file_priv,uint32_t encoders); + +#endif /* _DRM_LEASE_H_ */
include/drm/drm_mode_object.h +1 -0
@@ -24,6 +24,7 @@#define __DRM_MODESET_H__#include <linux/kref.h> +#include <drm/drm_lease.h> struct drm_object_properties ;struct drm_property ;struct drm_device ;
Signature · 6 lines
2.11.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 4/5 drm: Check mode object lease status in all master ioctl paths [v2]
In reply to Keith PackardAttempts to modify un-leased objects are rejected with an error. Information returned about unleased objects is modified to make them appear unusable and/or disconnected.
Changes for v2 as suggested by Daniel Vetter <[email protected]>:
With the change in the __drm_mode_object_find API to pass the file_priv along, we can now centralize most of the lease-based access checks in that function.
A few places skip that API and require in-line checks.
--- drivers/gpu/drm/drm_auth.c | 2 +- drivers/gpu/drm/drm_connector.c | 8 +++--- drivers/gpu/drm/drm_encoder.c | 8 +++--- drivers/gpu/drm/drm_mode_config.c | 52 ++++++++++++++++++++++++--------------- drivers/gpu/drm/drm_mode_object.c | 22 +++++++++++++++++ drivers/gpu/drm/drm_plane.c | 6 +++-- 6 files changed, 69 insertions(+), 29 deletions(-)
drivers/gpu/drm/drm_auth.c +1 -1
@@ -303,7 +303,7 @@ void drm_master_release(struct drm_file *file_priv)*/ bool drm_is_current_master (struct drm_file *fpriv) { -return fpriv->is_master && fpriv->master == fpriv->minor->dev->master; +return fpriv->is_master &&drm_lease_owner (fpriv->master) == fpriv->minor->dev->master; }EXPORT_SYMBOL (drm_is_current_master);
drivers/gpu/drm/drm_connector.c +5 -3
@@ -1094,7 +1094,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, }for (i =0 ; i <DRM_CONNECTOR_MAX_ENCODER ; i++) -if (connector->encoder_ids[i] !=0 ) +if (connector->encoder_ids[i] !=0 && +drm_lease_held (file_priv, connector->encoder_ids[i])) encoders_count++;if (out_resp->count_modes ==0 ) {
@@ -1118,7 +1119,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,drm_modeset_lock (&dev->mode_config.connection_mutex,NULL ); encoder =drm_connector_get_encoder (connector); -if (encoder) +if (encoder &&drm_lease_held (file_priv, encoder->base.id)) out_resp->encoder_id = encoder->base.id;else out_resp->encoder_id =0 ;
@@ -1156,7 +1157,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, copied =0 ; encoder_ptr = (uint32_t __user *)(unsigned long )(out_resp->encoders_ptr);for (i =0 ; i <DRM_CONNECTOR_MAX_ENCODER ; i++) { -if (connector->encoder_ids[i] !=0 ) { +if (connector->encoder_ids[i] !=0 && +drm_lease_held (file_priv, connector->encoder_ids[i])) {if (put_user (connector->encoder_ids[i], encoder_ptr + copied)) { ret = -EFAULT ;
drivers/gpu/drm/drm_encoder.c +5 -3
@@ -211,7 +211,7 @@ int drm_mode_getencoder(struct drm_device *dev, void *data,drm_modeset_lock (&dev->mode_config.connection_mutex,NULL ); crtc =drm_encoder_get_crtc (encoder); -if (crtc) +if (crtc &&drm_lease_held (file_priv, crtc->base.id)) enc_resp->crtc_id = crtc->base.id;else enc_resp->crtc_id =0 ;
@@ -219,8 +219,10 @@ int drm_mode_getencoder(struct drm_device *dev, void *data, enc_resp->encoder_type = encoder->encoder_type; enc_resp->encoder_id = encoder->base.id; - enc_resp->possible_crtcs = encoder->possible_crtcs; - enc_resp->possible_clones = encoder->possible_clones; + enc_resp->possible_crtcs =drm_lease_filter_crtcs (file_priv, + encoder->possible_crtcs); + enc_resp->possible_clones =drm_lease_filter_encoders (file_priv, + encoder->possible_clones);return 0 ; }
drivers/gpu/drm/drm_mode_config.c +32 -20
81 lines not on this page · raw message
drivers/gpu/drm/drm_mode_object.c +22 -0
@@ -107,6 +107,25 @@ void drm_mode_object_unregister(struct drm_device *dev,mutex_unlock (&dev->mode_config.idr_mutex); } +/** +* drm_lease_required - check types which must be leased to be used +* @type: type of object +* +* Returns whether the provided type of drm_mode_object must +* be owned or leased to be used by a process. +*/ +static bool drm_lease_required (uint32_t type) +{ +switch (type) { +case DRM_MODE_OBJECT_CRTC : +case DRM_MODE_OBJECT_CONNECTOR : +case DRM_MODE_OBJECT_ENCODER : +return true; +default : +return false; + } +} +struct drm_mode_object *__drm_mode_object_find (struct drm_device *dev,struct drm_file *file_priv,uint32_t id,uint32_t type)
@@ -120,6 +139,9 @@ struct drm_mode_object *__drm_mode_object_find(struct drm_device *dev,if (obj && obj->id != id) obj =NULL ; +if (obj &&drm_lease_required (obj->type) && !_drm_lease_held (file_priv, obj->id)) + obj =NULL ; +if (obj && obj->free_cb) {if (!kref_get_unless_zero (&obj->refcount)) obj =NULL ;
drivers/gpu/drm/drm_plane.c +4 -2
@@ -392,7 +392,7 @@ int drm_mode_getplane(struct drm_device *dev, void *data,return -ENOENT ;drm_modeset_lock (&plane->mutex,NULL ); -if (plane->crtc) +if (plane->crtc &&drm_lease_held (file_priv, plane->crtc->base.id)) plane_resp->crtc_id = plane->crtc->base.id;else plane_resp->crtc_id =0 ;
@@ -404,7 +404,9 @@ int drm_mode_getplane(struct drm_device *dev, void *data,drm_modeset_unlock (&plane->mutex); plane_resp->plane_id = plane->base.id; - plane_resp->possible_crtcs = plane->possible_crtcs; + plane_resp->possible_crtcs =drm_lease_filter_crtcs (file_priv, + plane->possible_crtcs); + plane_resp->gamma_size =0 ;/*
Signature · 6 lines
2.11.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 5/5 drm: Add three ioctls for managing drm mode object leases [v2]
In reply to Keith Packarddrm_mode_create_lease
Creates a lease for a list of drm mode objects, returning an fd for the new drm_master and a 64-bit identifier for the lessee
drm_mode_list_lesees
List the identifiers of the lessees for a master file
drm_mode_get_lease
List the leased objects for a master file
This should suffice to at least create and query leases.
Changes for v2 as suggested by Daniel Vetter <[email protected]>:
* query ioctls only query the master associated with the provided file.
* 'mask_lease' value has been removed
* change ioctl has been removed.
--- drivers/gpu/drm/drm_ioctl.c | 3 + drivers/gpu/drm/drm_lease.c | 220 ++++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_lease.h | 9 ++ include/uapi/drm/drm.h | 3 + include/uapi/drm/drm_mode.h | 55 +++++++++++ 5 files changed, 290 insertions(+)
drivers/gpu/drm/drm_ioctl.c +3 -0
@@ -636,6 +636,9 @@ static const struct drm_ioctl_desc drm_ioctls[] = {DRM_IOCTL_DEF (DRM_IOCTL_MODE_ATOMIC , drm_mode_atomic_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_CREATEPROPBLOB , drm_mode_createblob_ioctl,DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_DESTROYPROPBLOB , drm_mode_destroyblob_ioctl,DRM_CONTROL_ALLOW |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_CREATE_LEASE , drm_mode_create_lease_ioctl,DRM_ANY_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_LIST_LESSEES , drm_mode_list_lessees_ioctl,DRM_ANY_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), + DRM_IOCTL_DEF(DRM_IOCTL_MODE_GET_LEASE, drm_mode_get_lease_ioctl, DRM_ANY_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), };#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
drivers/gpu/drm/drm_lease.c +220 -0
223 lines not on this page · raw message
include/drm/drm_lease.h +9 -0
@@ -31,4 +31,13 @@ uint32_t drm_lease_filter_crtcs(struct drm_file *file_priv, uint32_t crtcs);uint32_t drm_lease_filter_encoders (struct drm_file *file_priv,uint32_t encoders); +int drm_mode_create_lease_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv); + +int drm_mode_list_lessees_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv); + +int drm_mode_get_lease_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv); +#endif /* _DRM_LEASE_H_ */
include/uapi/drm/drm.h +3 -0
@@ -813,6 +813,9 @@ extern "C" {#define DRM_IOCTL_MODE_ATOMIC DRM_IOWR(0xBC, struct drm_mode_atomic)#define DRM_IOCTL_MODE_CREATEPROPBLOB DRM_IOWR(0xBD, struct drm_mode_create_blob)#define DRM_IOCTL_MODE_DESTROYPROPBLOB DRM_IOWR(0xBE, struct drm_mode_destroy_blob) +#define DRM_IOCTL_MODE_CREATE_LEASE DRM_IOWR(0xBF, struct drm_mode_create_lease) +#define DRM_IOCTL_MODE_LIST_LESSEES DRM_IOWR(0xC0, struct drm_mode_list_lessees) +#define DRM_IOCTL_MODE_GET_LEASE DRM_IOWR(0xC1, struct drm_mode_get_lease)/** * Device specific ioctls should only be in their respective headers
include/uapi/drm/drm_mode.h +55 -0
61 lines not on this page · raw message
Signature · 6 lines
2.11.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel