Skip to content

Commit ae358da

Browse files
committed
drm/udl: Get rid of dev->struct_mutex usage
It's only used to protect our page list, and only when we know we have a full reference. This means none of these code paths can ever race with the final unref, and hence we do not need dev->struct_mutex serialization and can simply switch to our own locking. For more context the only magic the locked gem_free_object provides is that it prevents concurrent final unref (and destruction) of gem objects while anyone is holding dev->struct_mutex. This was used by i915 (and other drivers) to implement eviction handling with less headaches. Signed-off-by: Daniel Vetter <daniel.vetter@intel.com> Cc: Dave Airlie <airlied@redhat.com> Reviewed-by: Sean Paul <seanpaul@chromium.org> Link: https://patchwork.freedesktop.org/patch/msgid/20180327082356.24516-3-daniel.vetter@ffwll.ch
1 parent fcb1e57 commit ae358da

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

drivers/gpu/drm/udl/udl_dmabuf.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ static struct sg_table *udl_map_dma_buf(struct dma_buf_attachment *attach,
7676
struct udl_drm_dmabuf_attachment *udl_attach = attach->priv;
7777
struct udl_gem_object *obj = to_udl_bo(attach->dmabuf->priv);
7878
struct drm_device *dev = obj->base.dev;
79+
struct udl_device *udl = dev->dev_private;
7980
struct scatterlist *rd, *wr;
8081
struct sg_table *sgt = NULL;
8182
unsigned int i;
@@ -112,7 +113,7 @@ static struct sg_table *udl_map_dma_buf(struct dma_buf_attachment *attach,
112113
return ERR_PTR(-ENOMEM);
113114
}
114115

115-
mutex_lock(&dev->struct_mutex);
116+
mutex_lock(&udl->gem_lock);
116117

117118
rd = obj->sg->sgl;
118119
wr = sgt->sgl;
@@ -137,7 +138,7 @@ static struct sg_table *udl_map_dma_buf(struct dma_buf_attachment *attach,
137138
attach->priv = udl_attach;
138139

139140
err_unlock:
140-
mutex_unlock(&dev->struct_mutex);
141+
mutex_unlock(&udl->gem_lock);
141142
return sgt;
142143
}
143144

drivers/gpu/drm/udl/udl_drv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static struct drm_driver driver = {
5353
.unload = udl_driver_unload,
5454

5555
/* gem hooks */
56-
.gem_free_object = udl_gem_free_object,
56+
.gem_free_object_unlocked = udl_gem_free_object,
5757
.gem_vm_ops = &udl_gem_vm_ops,
5858

5959
.dumb_create = udl_dumb_create,

drivers/gpu/drm/udl/udl_drv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ struct udl_device {
5454
struct usb_device *udev;
5555
struct drm_crtc *crtc;
5656

57+
struct mutex gem_lock;
58+
5759
int sku_pixel_limit;
5860

5961
struct urb_list urbs;

drivers/gpu/drm/udl/udl_gem.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,10 @@ int udl_gem_mmap(struct drm_file *file, struct drm_device *dev,
214214
{
215215
struct udl_gem_object *gobj;
216216
struct drm_gem_object *obj;
217+
struct udl_device *udl = dev->dev_private;
217218
int ret = 0;
218219

219-
mutex_lock(&dev->struct_mutex);
220+
mutex_lock(&udl->gem_lock);
220221
obj = drm_gem_object_lookup(file, handle);
221222
if (obj == NULL) {
222223
ret = -ENOENT;
@@ -236,6 +237,6 @@ int udl_gem_mmap(struct drm_file *file, struct drm_device *dev,
236237
out:
237238
drm_gem_object_put(&gobj->base);
238239
unlock:
239-
mutex_unlock(&dev->struct_mutex);
240+
mutex_unlock(&udl->gem_lock);
240241
return ret;
241242
}

drivers/gpu/drm/udl/udl_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ int udl_driver_load(struct drm_device *dev, unsigned long flags)
324324
udl->ddev = dev;
325325
dev->dev_private = udl;
326326

327+
mutex_init(&udl->gem_lock);
328+
327329
if (!udl_parse_vendor_descriptor(dev, udl->udev)) {
328330
ret = -ENODEV;
329331
DRM_ERROR("firmware not recognized. Assume incompatible device\n");

0 commit comments

Comments
 (0)