Skip to content

Commit 0e97598

Browse files
Peter Antoinedanvet
authored andcommitted
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 nouvea driver that may require them with an old version of libdrm. The previous attempt was commit 7c51013 Author: Daniel Vetter <daniel.vetter@ffwll.ch> Date: Thu Aug 8 15:41:21 2013 +0200 drm: mark context support as a legacy subsystem but this had to be reverted commit c21eb21 Author: Dave Airlie <airlied@redhat.com> Date: Fri Sep 20 08:32:59 2013 +1000 Revert "drm: mark context support as a legacy subsystem" v2: remove returns from void function, and formatting (Daniel Vetter) v3: - s/Nova/nouveau/ in the commit message, and add references to the previous attempts - drop the part touching the drm hw lock, that should be a separate patch. Signed-off-by: Peter Antoine <peter.antoine@intel.com> (v2) Cc: Peter Antoine <peter.antoine@intel.com> (v2) Reviewed-by: Peter Antoine <peter.antoine@intel.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent 8b72ce1 commit 0e97598

File tree

4 files changed

+70
-17
lines changed

4 files changed

+70
-17
lines changed

drivers/gpu/drm/drm_context.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ struct drm_ctx_list {
5353
*/
5454
void drm_legacy_ctxbitmap_free(struct drm_device * dev, int ctx_handle)
5555
{
56+
if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
57+
drm_core_check_feature(dev, DRIVER_MODESET))
58+
return;
59+
5660
mutex_lock(&dev->struct_mutex);
5761
idr_remove(&dev->ctx_idr, ctx_handle);
5862
mutex_unlock(&dev->struct_mutex);
@@ -87,6 +91,10 @@ static int drm_legacy_ctxbitmap_next(struct drm_device * dev)
8791
*/
8892
int drm_legacy_ctxbitmap_init(struct drm_device * dev)
8993
{
94+
if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
95+
drm_core_check_feature(dev, DRIVER_MODESET))
96+
return -EINVAL;
97+
9098
idr_init(&dev->ctx_idr);
9199
return 0;
92100
}
@@ -101,6 +109,10 @@ int drm_legacy_ctxbitmap_init(struct drm_device * dev)
101109
*/
102110
void drm_legacy_ctxbitmap_cleanup(struct drm_device * dev)
103111
{
112+
if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
113+
drm_core_check_feature(dev, DRIVER_MODESET))
114+
return;
115+
104116
mutex_lock(&dev->struct_mutex);
105117
idr_destroy(&dev->ctx_idr);
106118
mutex_unlock(&dev->struct_mutex);
@@ -119,6 +131,10 @@ void drm_legacy_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file)
119131
{
120132
struct drm_ctx_list *pos, *tmp;
121133

134+
if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
135+
drm_core_check_feature(dev, DRIVER_MODESET))
136+
return;
137+
122138
mutex_lock(&dev->ctxlist_mutex);
123139

124140
list_for_each_entry_safe(pos, tmp, &dev->ctxlist, head) {
@@ -161,6 +177,10 @@ int drm_legacy_getsareactx(struct drm_device *dev, void *data,
161177
struct drm_local_map *map;
162178
struct drm_map_list *_entry;
163179

180+
if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
181+
drm_core_check_feature(dev, DRIVER_MODESET))
182+
return -EINVAL;
183+
164184
mutex_lock(&dev->struct_mutex);
165185

166186
map = idr_find(&dev->ctx_idr, request->ctx_id);
@@ -205,6 +225,10 @@ int drm_legacy_setsareactx(struct drm_device *dev, void *data,
205225
struct drm_local_map *map = NULL;
206226
struct drm_map_list *r_list = NULL;
207227

228+
if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
229+
drm_core_check_feature(dev, DRIVER_MODESET))
230+
return -EINVAL;
231+
208232
mutex_lock(&dev->struct_mutex);
209233
list_for_each_entry(r_list, &dev->maplist, head) {
210234
if (r_list->map
@@ -305,6 +329,10 @@ int drm_legacy_resctx(struct drm_device *dev, void *data,
305329
struct drm_ctx ctx;
306330
int i;
307331

332+
if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
333+
drm_core_check_feature(dev, DRIVER_MODESET))
334+
return -EINVAL;
335+
308336
if (res->count >= DRM_RESERVED_CONTEXTS) {
309337
memset(&ctx, 0, sizeof(ctx));
310338
for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
@@ -335,6 +363,10 @@ int drm_legacy_addctx(struct drm_device *dev, void *data,
335363
struct drm_ctx_list *ctx_entry;
336364
struct drm_ctx *ctx = data;
337365

366+
if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
367+
drm_core_check_feature(dev, DRIVER_MODESET))
368+
return -EINVAL;
369+
338370
ctx->handle = drm_legacy_ctxbitmap_next(dev);
339371
if (ctx->handle == DRM_KERNEL_CONTEXT) {
340372
/* Skip kernel's context and get a new one. */
@@ -378,6 +410,10 @@ int drm_legacy_getctx(struct drm_device *dev, void *data,
378410
{
379411
struct drm_ctx *ctx = data;
380412

413+
if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
414+
drm_core_check_feature(dev, DRIVER_MODESET))
415+
return -EINVAL;
416+
381417
/* This is 0, because we don't handle any context flags */
382418
ctx->flags = 0;
383419

@@ -400,6 +436,10 @@ int drm_legacy_switchctx(struct drm_device *dev, void *data,
400436
{
401437
struct drm_ctx *ctx = data;
402438

439+
if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
440+
drm_core_check_feature(dev, DRIVER_MODESET))
441+
return -EINVAL;
442+
403443
DRM_DEBUG("%d\n", ctx->handle);
404444
return drm_context_switch(dev, dev->last_context, ctx->handle);
405445
}
@@ -420,6 +460,10 @@ int drm_legacy_newctx(struct drm_device *dev, void *data,
420460
{
421461
struct drm_ctx *ctx = data;
422462

463+
if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
464+
drm_core_check_feature(dev, DRIVER_MODESET))
465+
return -EINVAL;
466+
423467
DRM_DEBUG("%d\n", ctx->handle);
424468
drm_context_switch_complete(dev, file_priv, ctx->handle);
425469

@@ -442,6 +486,10 @@ int drm_legacy_rmctx(struct drm_device *dev, void *data,
442486
{
443487
struct drm_ctx *ctx = data;
444488

489+
if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
490+
drm_core_check_feature(dev, DRIVER_MODESET))
491+
return -EINVAL;
492+
445493
DRM_DEBUG("%d\n", ctx->handle);
446494
if (ctx->handle != DRM_KERNEL_CONTEXT) {
447495
if (dev->driver->context_dtor)

drivers/gpu/drm/drm_drv.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,14 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,
582582
if (drm_ht_create(&dev->map_hash, 12))
583583
goto err_minors;
584584

585-
ret = drm_legacy_ctxbitmap_init(dev);
586-
if (ret) {
587-
DRM_ERROR("Cannot allocate memory for context bitmap.\n");
588-
goto err_ht;
589-
}
585+
if (drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) ||
586+
!drm_core_check_feature(dev, DRIVER_MODESET))
587+
ret = drm_legacy_ctxbitmap_init(dev);
588+
if (ret) {
589+
DRM_ERROR(
590+
"Cannot allocate memory for context bitmap.\n");
591+
goto err_ht;
592+
}
590593

591594
if (drm_core_check_feature(dev, DRIVER_GEM)) {
592595
ret = drm_gem_init(dev);

drivers/gpu/drm/nouveau/nouveau_drm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,8 @@ static struct drm_driver
941941
driver_stub = {
942942
.driver_features =
943943
DRIVER_USE_AGP |
944-
DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | DRIVER_RENDER,
944+
DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | DRIVER_RENDER |
945+
DRIVER_KMS_LEGACY_CONTEXT,
945946

946947
.load = nouveau_drm_load,
947948
.unload = nouveau_drm_unload,

include/drm/drmP.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,18 @@ void drm_err(const char *format, ...);
137137
/*@{*/
138138

139139
/* driver capabilities and requirements mask */
140-
#define DRIVER_USE_AGP 0x1
141-
#define DRIVER_PCI_DMA 0x8
142-
#define DRIVER_SG 0x10
143-
#define DRIVER_HAVE_DMA 0x20
144-
#define DRIVER_HAVE_IRQ 0x40
145-
#define DRIVER_IRQ_SHARED 0x80
146-
#define DRIVER_GEM 0x1000
147-
#define DRIVER_MODESET 0x2000
148-
#define DRIVER_PRIME 0x4000
149-
#define DRIVER_RENDER 0x8000
150-
#define DRIVER_ATOMIC 0x10000
140+
#define DRIVER_USE_AGP 0x1
141+
#define DRIVER_PCI_DMA 0x8
142+
#define DRIVER_SG 0x10
143+
#define DRIVER_HAVE_DMA 0x20
144+
#define DRIVER_HAVE_IRQ 0x40
145+
#define DRIVER_IRQ_SHARED 0x80
146+
#define DRIVER_GEM 0x1000
147+
#define DRIVER_MODESET 0x2000
148+
#define DRIVER_PRIME 0x4000
149+
#define DRIVER_RENDER 0x8000
150+
#define DRIVER_ATOMIC 0x10000
151+
#define DRIVER_KMS_LEGACY_CONTEXT 0x20000
151152

152153
/***********************************************************************/
153154
/** \name Macros to make printk easier */

0 commit comments

Comments
 (0)