History

drm/i915: fix reference counting in i915_gem_create

This function is called without the dev->struct_mutex held, hence we need to use the _unlocked unreference variants. As soon as the object is registered userspace can sneak in here with a gem_close ioctl call, so the object can (and with my new evil tests actually does) get the final unreference in this place. The lack of locking then results in hilarity and some good leakage. To fix this we simply need to revert Chris Wilson <chris@chris-wilson.co.uk> v2: We need to make the trace call _before_ we drop our ref - the object might very well be gone by then already. v3: Just revert the original patch as suggested by Chris Wilson.

Daniel Vetter committed 13 years ago

Commit d861e331 parent 17fec8a1 file · +5 −9Browse files

Unified · Split

drivers/gpu/drm/i915/i915_gem.c+5−9
@@ -219,16 +219,10 @@ i915_gem_create(struct drm_file *file, · 218 unmodified lines
219 return -ENOMEM;219 return -ENOMEM;
220 220
221 ret = drm_gem_handle_create(file, &obj->base, &handle);221 ret = drm_gem_handle_create(file, &obj->base, &handle);
222 if (ret) {
223 drm_gem_object_release(&obj->base);
224 i915_gem_info_remove_obj(dev->dev_private, obj->base.size);
225 i915_gem_object_free(obj);
226 return ret;
227 }
228
229 /* drop reference from allocate - handle holds it now */222 /* drop reference from allocate - handle holds it now */
230 drm_gem_object_unreference(&obj->base);223 drm_gem_object_unreference_unlocked(&obj->base);
231 trace_i915_gem_object_create(obj);224 if (ret)
225 return ret;
232 226
233 *handle_p = handle;227 *handle_p = handle;
234 return 0;228 return 0;
@@ -3956,6 +3950,8 @@ struct drm_i915_gem_object *i915_gem_alloc_object(struct drm_device *dev, · 3721 unmodified lines
3956 } else3950 } else
3957 obj->cache_level = I915_CACHE_NONE;3951 obj->cache_level = I915_CACHE_NONE;
3958 3952
3953 trace_i915_gem_object_create(obj);
3954
3959 return obj;3955 return obj;
3960}3956}
3961 3957

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t