Skip to content

Commit 40647e4

Browse files
committed
drm: Hide master MAP cleanup in drm_bufs.c
And again make sure it's a no-op for modern drivers. Another case of dev->struct_mutex gone for modern drivers! Note that the entirety of the legacy addmap interface is now protected by DRIVER_MODESET. Note that just auditing kernel code is not enough, since userspace loves to set up legacy maps on it's own for various things - with ums userspace and kernel space share control over resources. v2: Also add a DRIVER_* check like for all other maps functions to really short-circuit the code. And give drm_legacy_rmmap used by the dev unregister code the same treatment. v3: - remove redundant return; (Alex, Chris) - don't special case nouveau with DRIVER_KMS_LEGACY_CONTEXT. v4: Again special case nouveau. The problem is not directly in the ddx, but that it calls dri1 functions from the X server. And those do call drmAddMap. Fixed only in commit b1a630b48210d6a3c44994fce1b73273000ace5c Author: Dave Airlie <[email protected]> Date: Wed Nov 7 14:45:14 2012 +1000 nouveau: drop DRI1 device open interface. Acked-by: Alex Deucher <[email protected]> Reviewed-by: Chris Wilson <[email protected]> Cc: Alex Deucher <[email protected]> Cc: Chris Wilson <[email protected]> Signed-off-by: Daniel Vetter <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent e975eef commit 40647e4

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

drivers/gpu/drm/drm_bufs.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,18 +542,35 @@ int drm_legacy_rmmap_locked(struct drm_device *dev, struct drm_local_map *map)
542542
}
543543
EXPORT_SYMBOL(drm_legacy_rmmap_locked);
544544

545-
int drm_legacy_rmmap(struct drm_device *dev, struct drm_local_map *map)
545+
void drm_legacy_rmmap(struct drm_device *dev, struct drm_local_map *map)
546546
{
547-
int ret;
547+
if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
548+
drm_core_check_feature(dev, DRIVER_MODESET))
549+
return;
548550

549551
mutex_lock(&dev->struct_mutex);
550-
ret = drm_legacy_rmmap_locked(dev, map);
552+
drm_legacy_rmmap_locked(dev, map);
551553
mutex_unlock(&dev->struct_mutex);
552-
553-
return ret;
554554
}
555555
EXPORT_SYMBOL(drm_legacy_rmmap);
556556

557+
void drm_legacy_master_rmmaps(struct drm_device *dev, struct drm_master *master)
558+
{
559+
struct drm_map_list *r_list, *list_temp;
560+
561+
if (drm_core_check_feature(dev, DRIVER_MODESET))
562+
return;
563+
564+
mutex_lock(&dev->struct_mutex);
565+
list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head) {
566+
if (r_list->master == master) {
567+
drm_legacy_rmmap_locked(dev, r_list->map);
568+
r_list = NULL;
569+
}
570+
}
571+
mutex_unlock(&dev->struct_mutex);
572+
}
573+
557574
/* The rmmap ioctl appears to be unnecessary. All mappings are torn down on
558575
* the last close of the device, and this is necessary for cleanup when things
559576
* exit uncleanly. Therefore, having userland manually remove mappings seems

drivers/gpu/drm/drm_drv.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,11 @@ static void drm_master_destroy(struct kref *kref)
121121
{
122122
struct drm_master *master = container_of(kref, struct drm_master, refcount);
123123
struct drm_device *dev = master->minor->dev;
124-
struct drm_map_list *r_list, *list_temp;
125124

126125
if (dev->driver->master_destroy)
127126
dev->driver->master_destroy(dev, master);
128127

129-
mutex_lock(&dev->struct_mutex);
130-
list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head) {
131-
if (r_list->master == master) {
132-
drm_legacy_rmmap_locked(dev, r_list->map);
133-
r_list = NULL;
134-
}
135-
}
136-
mutex_unlock(&dev->struct_mutex);
128+
drm_legacy_master_rmmaps(dev, master);
137129

138130
idr_destroy(&master->magic_map);
139131
kfree(master->unique);

include/drm/drm_legacy.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ struct drm_map_list {
154154
int drm_legacy_addmap(struct drm_device *d, resource_size_t offset,
155155
unsigned int size, enum drm_map_type type,
156156
enum drm_map_flags flags, struct drm_local_map **map_p);
157-
int drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map);
157+
void drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map);
158158
int drm_legacy_rmmap_locked(struct drm_device *d, struct drm_local_map *map);
159+
void drm_legacy_master_rmmaps(struct drm_device *dev,
160+
struct drm_master *master);
159161
struct drm_local_map *drm_legacy_getsarea(struct drm_device *dev);
160162
int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma);
161163

0 commit comments

Comments
 (0)