drm: Turn off Legacy Context Functions
Subsystems (3)
PATCH v2 1/1 drm: Turn off Legacy Context Functions
The context functions are not used by the i915 driver and should not be used by modeset drivers. These driver functions contain several bugs and security holes. This change makes these functions optional can be turned on by a setting, they are turned off by default for modeset driver with the exception of the Nova driver that may require them with an old version of libdrm.
v2: remove returns from void function, and formatting (Daniel Vetter)
--- drivers/gpu/drm/drm_context.c | 48 +++++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_drv.c | 13 ++++++---- drivers/gpu/drm/drm_lock.c | 8 ++++++ drivers/gpu/drm/nouveau/nouveau_drm.c | 3 ++- include/drm/drmP.h | 23 +++++++++-------- 5 files changed, 78 insertions(+), 17 deletions(-)
drivers/gpu/drm/drm_context.c +48 -0
@@ -53,6 +53,10 @@ struct drm_ctx_list {*/ void drm_legacy_ctxbitmap_free (struct drm_device * dev,int ctx_handle) { +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return ; +mutex_lock (&dev->struct_mutex);idr_remove (&dev->ctx_idr, ctx_handle);mutex_unlock (&dev->struct_mutex);
@@ -87,6 +91,10 @@ static int drm_legacy_ctxbitmap_next(struct drm_device * dev)*/ int drm_legacy_ctxbitmap_init (struct drm_device * dev) { +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +idr_init (&dev->ctx_idr);return 0 ; }
@@ -101,6 +109,10 @@ int drm_legacy_ctxbitmap_init(struct drm_device * dev)*/ void drm_legacy_ctxbitmap_cleanup (struct drm_device * dev) { +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return ; +mutex_lock (&dev->struct_mutex);idr_destroy (&dev->ctx_idr);mutex_unlock (&dev->struct_mutex);
@@ -119,6 +131,10 @@ void drm_legacy_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file) {struct drm_ctx_list *pos, *tmp; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return ; +mutex_lock (&dev->ctxlist_mutex);list_for_each_entry_safe (pos, tmp, &dev->ctxlist, head) {
@@ -161,6 +177,10 @@ int drm_legacy_getsareactx(struct drm_device *dev, void *data,struct drm_local_map *map;struct drm_map_list *_entry; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +mutex_lock (&dev->struct_mutex); map =idr_find (&dev->ctx_idr, request->ctx_id);
@@ -205,6 +225,10 @@ int drm_legacy_setsareactx(struct drm_device *dev, void *data,struct drm_local_map *map =NULL ;struct drm_map_list *r_list =NULL ; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +mutex_lock (&dev->struct_mutex);list_for_each_entry (r_list, &dev->maplist, head) { if (r_list->map
@@ -305,6 +329,10 @@ int drm_legacy_resctx(struct drm_device *dev, void *data,struct drm_ctx ctx;int i; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +if (res->count >=DRM_RESERVED_CONTEXTS ) {memset (&ctx,0 ,sizeof (ctx));for (i =0 ; i <DRM_RESERVED_CONTEXTS ; i++) {
@@ -335,6 +363,10 @@ int drm_legacy_addctx(struct drm_device *dev, void *data,struct drm_ctx_list *ctx_entry;struct drm_ctx *ctx = data; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; + ctx->handle =drm_legacy_ctxbitmap_next (dev);if (ctx->handle ==DRM_KERNEL_CONTEXT ) {/* Skip kernel's context and get a new one. */
@@ -378,6 +410,10 @@ int drm_legacy_getctx(struct drm_device *dev, void *data, {struct drm_ctx *ctx = data; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +/* This is 0, because we don't handle any context flags */ ctx->flags =0 ;
@@ -400,6 +436,10 @@ int drm_legacy_switchctx(struct drm_device *dev, void *data, {struct drm_ctx *ctx = data; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +DRM_DEBUG ("%d\n" , ctx->handle);return drm_context_switch (dev, dev->last_context, ctx->handle); }
@@ -420,6 +460,10 @@ int drm_legacy_newctx(struct drm_device *dev, void *data, {struct drm_ctx *ctx = data; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +DRM_DEBUG ("%d\n" , ctx->handle);drm_context_switch_complete (dev, file_priv, ctx->handle);
@@ -442,6 +486,10 @@ int drm_legacy_rmctx(struct drm_device *dev, void *data, {struct drm_ctx *ctx = data; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +DRM_DEBUG ("%d\n" , ctx->handle);if (ctx->handle !=DRM_KERNEL_CONTEXT ) {if (dev->driver->context_dtor)
drivers/gpu/drm/drm_drv.c +8 -5
@@ -584,11 +584,14 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,if (drm_ht_create (&dev->map_hash,12 )) goto err_minors; - ret =drm_legacy_ctxbitmap_init (dev); -if (ret) { -DRM_ERROR ("Cannot allocate memory for context bitmap.\n" ); - goto err_ht; - } +if (drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) || + !drm_core_check_feature (dev,DRIVER_MODESET )) + ret =drm_legacy_ctxbitmap_init (dev); +if (ret) { +DRM_ERROR ( +"Cannot allocate memory for context bitmap.\n" ); + goto err_ht; + }if (drm_core_check_feature (dev,DRIVER_GEM )) { ret =drm_gem_init (dev);
drivers/gpu/drm/drm_lock.c +8 -0
@@ -61,6 +61,10 @@ int drm_legacy_lock(struct drm_device *dev, void *data,struct drm_master *master = file_priv->master;int ret =0 ; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; + ++file_priv->lock_count;if (lock->context ==DRM_KERNEL_CONTEXT ) {
@@ -153,6 +157,10 @@ int drm_legacy_unlock(struct drm_device *dev, void *data, struct drm_file *file_struct drm_lock *lock = data;struct drm_master *master = file_priv->master; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +if (lock->context ==DRM_KERNEL_CONTEXT ) {DRM_ERROR ("Process %d using kernel context %d\n" ,task_pid_nr (current), lock->context);
drivers/gpu/drm/nouveau/nouveau_drm.c +2 -1
@@ -941,7 +941,8 @@ static struct drm_driver driver_stub = { .driver_features =DRIVER_USE_AGP | - DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | DRIVER_RENDER, +DRIVER_GEM |DRIVER_MODESET |DRIVER_PRIME |DRIVER_RENDER | + DRIVER_KMS_LEGACY_CONTEXT, .load = nouveau_drm_load, .unload = nouveau_drm_unload,
include/drm/drmP.h +12 -11
@@ -137,17 +137,18 @@ void drm_err(const char *format, ...);/*@{*/ /* driver capabilities and requirements mask */ -#define DRIVER_USE_AGP 0x1 -#define DRIVER_PCI_DMA 0x8 -#define DRIVER_SG 0x10 -#define DRIVER_HAVE_DMA 0x20 -#define DRIVER_HAVE_IRQ 0x40 -#define DRIVER_IRQ_SHARED 0x80 -#define DRIVER_GEM 0x1000 -#define DRIVER_MODESET 0x2000 -#define DRIVER_PRIME 0x4000 -#define DRIVER_RENDER 0x8000 -#define DRIVER_ATOMIC 0x10000 +#define DRIVER_USE_AGP 0x1 +#define DRIVER_PCI_DMA 0x8 +#define DRIVER_SG 0x10 +#define DRIVER_HAVE_DMA 0x20 +#define DRIVER_HAVE_IRQ 0x40 +#define DRIVER_IRQ_SHARED 0x80 +#define DRIVER_GEM 0x1000 +#define DRIVER_MODESET 0x2000 +#define DRIVER_PRIME 0x4000 +#define DRIVER_RENDER 0x8000 +#define DRIVER_ATOMIC 0x10000 +#define DRIVER_KMS_LEGACY_CONTEXT 0x20000/***********************************************************************/ /** \name Macros to make printk easier */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 10 lines · Peter Antoine
The context functions are not used by the i915 driver and should not be used by modeset drivers. These driver functions contain several bugs and security holes. This change makes these functions optional can be turned on by a setting, they are turned off by default for modeset driver with the exception of the Nova driver that may require them with an old version of libdrm.
v2: remove returns from void function, and formatting (Daniel Vetter)
Signed-off-by Peter Antoine <[email protected]>
dri-devel wasn't cc'd on this version. And I also spotted a few other things to improve/polish, most of which was mentioned in earlier revision. I amended your patch with 2 more of mine and resubmitted them. Can you pls take a quick look and r-b stampe the entire pile?
Thanks, Daniel
Quoted 245 lines
--- drivers/gpu/drm/drm_context.c | 48 +++++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_drv.c | 13 ++++++---- drivers/gpu/drm/drm_lock.c | 8 ++++++ drivers/gpu/drm/nouveau/nouveau_drm.c | 3 ++- include/drm/drmP.h | 23 +++++++++-------- 5 files changed, 78 insertions(+), 17 deletions(-)drivers/gpu/drm/drm_context.c +48
-0@@ -53,6 +53,10 @@ struct drm_ctx_list {*/ void drm_legacy_ctxbitmap_free (struct drm_device * dev,int ctx_handle) { +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return ; +mutex_lock (&dev->struct_mutex);idr_remove (&dev->ctx_idr, ctx_handle);mutex_unlock (&dev->struct_mutex);@@ -87,6 +91,10 @@ static int drm_legacy_ctxbitmap_next(struct drm_device * dev)*/ int drm_legacy_ctxbitmap_init (struct drm_device * dev) { +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +idr_init (&dev->ctx_idr);return 0 ; }@@ -101,6 +109,10 @@ int drm_legacy_ctxbitmap_init(struct drm_device * dev)*/ void drm_legacy_ctxbitmap_cleanup (struct drm_device * dev) { +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return ; +mutex_lock (&dev->struct_mutex);idr_destroy (&dev->ctx_idr);mutex_unlock (&dev->struct_mutex);@@ -119,6 +131,10 @@ void drm_legacy_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file) {struct drm_ctx_list *pos, *tmp; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return ; +mutex_lock (&dev->ctxlist_mutex);list_for_each_entry_safe (pos, tmp, &dev->ctxlist, head) {@@ -161,6 +177,10 @@ int drm_legacy_getsareactx(struct drm_device *dev, void *data,struct drm_local_map *map;struct drm_map_list *_entry; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +mutex_lock (&dev->struct_mutex); map =idr_find (&dev->ctx_idr, request->ctx_id);@@ -205,6 +225,10 @@ int drm_legacy_setsareactx(struct drm_device *dev, void *data,struct drm_local_map *map =NULL ;struct drm_map_list *r_list =NULL ; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +mutex_lock (&dev->struct_mutex);list_for_each_entry (r_list, &dev->maplist, head) { if (r_list->map@@ -305,6 +329,10 @@ int drm_legacy_resctx(struct drm_device *dev, void *data,struct drm_ctx ctx;int i; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +if (res->count >=DRM_RESERVED_CONTEXTS ) {memset (&ctx,0 ,sizeof (ctx));for (i =0 ; i <DRM_RESERVED_CONTEXTS ; i++) {@@ -335,6 +363,10 @@ int drm_legacy_addctx(struct drm_device *dev, void *data,struct drm_ctx_list *ctx_entry;struct drm_ctx *ctx = data; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; + ctx->handle =drm_legacy_ctxbitmap_next (dev);if (ctx->handle ==DRM_KERNEL_CONTEXT ) {/* Skip kernel's context and get a new one. */ @@ -378,6 +410,10 @@ int drm_legacy_getctx(struct drm_device *dev, void *data, {struct drm_ctx *ctx = data; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +/* This is 0, because we don't handle any context flags */ ctx->flags =0 ;@@ -400,6 +436,10 @@ int drm_legacy_switchctx(struct drm_device *dev, void *data, {struct drm_ctx *ctx = data; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +DRM_DEBUG ("%d\n" , ctx->handle);return drm_context_switch (dev, dev->last_context, ctx->handle); }@@ -420,6 +460,10 @@ int drm_legacy_newctx(struct drm_device *dev, void *data, {struct drm_ctx *ctx = data; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +DRM_DEBUG ("%d\n" , ctx->handle);drm_context_switch_complete (dev, file_priv, ctx->handle);@@ -442,6 +486,10 @@ int drm_legacy_rmctx(struct drm_device *dev, void *data, {struct drm_ctx *ctx = data; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +DRM_DEBUG ("%d\n" , ctx->handle);if (ctx->handle !=DRM_KERNEL_CONTEXT ) {if (dev->driver->context_dtor)drivers/gpu/drm/drm_drv.c +8
-5@@ -584,11 +584,14 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,if (drm_ht_create (&dev->map_hash,12 )) goto err_minors; - ret =drm_legacy_ctxbitmap_init (dev); -if (ret) { -DRM_ERROR ("Cannot allocate memory for context bitmap.\n" ); - goto err_ht; - } +if (drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) || + !drm_core_check_feature (dev,DRIVER_MODESET )) + ret =drm_legacy_ctxbitmap_init (dev); +if (ret) { +DRM_ERROR ( +"Cannot allocate memory for context bitmap.\n" ); + goto err_ht; + }if (drm_core_check_feature (dev,DRIVER_GEM )) { ret =drm_gem_init (dev);drivers/gpu/drm/drm_lock.c +8
-0@@ -61,6 +61,10 @@ int drm_legacy_lock(struct drm_device *dev, void *data,struct drm_master *master = file_priv->master;int ret =0 ; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; + ++file_priv->lock_count;if (lock->context ==DRM_KERNEL_CONTEXT ) {@@ -153,6 +157,10 @@ int drm_legacy_unlock(struct drm_device *dev, void *data, struct drm_file *file_struct drm_lock *lock = data;struct drm_master *master = file_priv->master; +if (!drm_core_check_feature (dev,DRIVER_KMS_LEGACY_CONTEXT ) && +drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; +if (lock->context ==DRM_KERNEL_CONTEXT ) {DRM_ERROR ("Process %d using kernel context %d\n" ,task_pid_nr (current), lock->context);drivers/gpu/drm/nouveau/nouveau_drm.c +2
-1@@ -941,7 +941,8 @@ static struct drm_driver driver_stub = { .driver_features =DRIVER_USE_AGP | - DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | DRIVER_RENDER, +DRIVER_GEM |DRIVER_MODESET |DRIVER_PRIME |DRIVER_RENDER | + DRIVER_KMS_LEGACY_CONTEXT, .load = nouveau_drm_load, .unload = nouveau_drm_unload,include/drm/drmP.h +12
-11@@ -137,17 +137,18 @@ void drm_err(const char *format, ...);/*@{*/ /* driver capabilities and requirements mask */ -#define DRIVER_USE_AGP 0x1 -#define DRIVER_PCI_DMA 0x8 -#define DRIVER_SG 0x10 -#define DRIVER_HAVE_DMA 0x20 -#define DRIVER_HAVE_IRQ 0x40 -#define DRIVER_IRQ_SHARED 0x80 -#define DRIVER_GEM 0x1000 -#define DRIVER_MODESET 0x2000 -#define DRIVER_PRIME 0x4000 -#define DRIVER_RENDER 0x8000 -#define DRIVER_ATOMIC 0x10000 +#define DRIVER_USE_AGP 0x1 +#define DRIVER_PCI_DMA 0x8 +#define DRIVER_SG 0x10 +#define DRIVER_HAVE_DMA 0x20 +#define DRIVER_HAVE_IRQ 0x40 +#define DRIVER_IRQ_SHARED 0x80 +#define DRIVER_GEM 0x1000 +#define DRIVER_MODESET 0x2000 +#define DRIVER_PRIME 0x4000 +#define DRIVER_RENDER 0x8000 +#define DRIVER_ATOMIC 0x10000 +#define DRIVER_KMS_LEGACY_CONTEXT 0x20000/***********************************************************************/ /** \name Macros to make printk easier */ Signature · 1 line
1.9.1
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx