linux/include/drm
Daniel Vetter 20228c4478 drm/gem: completely close gem_open vs. gem_close races
The gem flink name holds a reference onto the object itself, and this
self-reference would prevent an flink'ed object from every being
freed. To break that loop we remove the flink name when the last
userspace handle disappears, i.e. when obj->handle_count reaches 0.

Now in gem_open we drop the dev->object_name_lock between the flink
name lookup and actually adding the handle. This means a concurrent
gem_close of the last handle could result in the flink name getting
reaped right inbetween, i.e.

Thread 1		Thread 2
gem_open		gem_close

flink -> obj lookup
			handle_count drops to 0
			remove flink name
create_handle
handle_count++

If someone now flinks this object again, we'll get a new flink name.

We can close this race by removing the lock dropping and making the
entire lookup+handle_create sequence atomic. Unfortunately to still be
able to share the handle_create logic this requires a
handle_create_tail function which drops the lock - we can't hold the
object_name_lock while calling into a driver's ->gem_open callback.

Note that for flink fixing this race isn't really important, since
racing gem_open against gem_close is clearly a userspace bug. And no
matter how the race ends, we won't leak any references.

But with dma-buf where the userspace dma-buf fd itself is refcounted
this is a valid sequence and hence we should fix it. Therefore this
patch here is just a warm-up exercise (and for consistency between
flink buffer sharing and dma-buf buffer sharing with self-imports).

Also note that this extension of the critical section in gem_open
protected by dev->object_name_lock only works because it's now a
mutex: A spinlock would conflict with the potential memory allocation
in idr_preload().

This is exercises by igt/gem_flink_race/flink_name.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2013-08-21 12:58:17 +10:00
..
i2c drm/i2c: tda998x: add video and audio input configuration 2013-08-19 09:10:32 +10:00
ttm drm/ttm: convert to unified vma offset manager 2013-07-25 20:47:07 +10:00
drmP.h drm/gem: completely close gem_open vs. gem_close races 2013-08-21 12:58:17 +10:00
drm_agpsupport.h drm: provide agp dummies for CONFIG_AGP=n 2013-08-09 07:22:11 +10:00
drm_buffer.h UAPI: (Scripted) Convert #include "..." to #include <path/...> in kernel system headers 2012-10-02 18:01:25 +01:00
drm_cache.h drm/ttm: consolidate cache flushing code in one place. 2009-08-27 09:53:47 +10:00
drm_core.h drm: Fix support for PCI domains 2010-08-10 08:20:20 +10:00
drm_crtc.h drm: Remove 2 unused defines 2013-08-21 12:47:36 +10:00
drm_crtc_helper.h drm: extract drm_kms_helper_hotplug_event 2012-11-20 15:50:32 +10:00
drm_dp_helper.h drm: Added SDP and VSC structures for handling PSR for eDP 2013-07-18 09:59:21 +02:00
drm_edid.h drm: add drm_edid_to_eld helper extracting SADs from EDID (v2) 2013-04-23 18:03:58 -04:00
drm_encoder_slave.h drm: i2c encoder helper wrappers 2013-02-17 17:55:42 -05:00
drm_fb_cma_helper.h drm: Make drm_fb_cma_describe() static 2013-08-21 12:47:41 +10:00
drm_fb_helper.h drm: Remove pointless '-' characters from drm_fb_helper documentation 2013-05-10 14:46:11 +10:00
drm_fixed.h drm: add some additional fixed point helpers (v3) 2013-06-27 19:16:37 -04:00
drm_flip_work.h drm: add flip-work helper 2013-08-19 10:32:26 +10:00
drm_gem_cma_helper.h drm/gem: create drm_gem_dumb_destroy 2013-08-07 09:59:24 +10:00
drm_global.h drm: move ttm global code to core drm 2010-08-04 09:46:06 +10:00
drm_hashtab.h drm: Add a hash-tab rcu-safe API 2012-11-28 18:36:05 +10:00
drm_mem_util.h introduce SIZE_MAX 2012-05-31 17:49:26 -07:00
drm_memory.h UAPI: (Scripted) Convert #include "..." to #include <path/...> in kernel system headers 2012-10-02 18:01:25 +01:00
drm_mm.h drm/mm: remove unused API 2013-08-07 10:16:50 +10:00
drm_os_linux.h drm: Remove mtrr_add and mtrr_del fallback hack for non-MTRR systems 2013-05-31 13:37:37 +10:00
drm_pciids.h drm: Remove unused PCI ids 2013-08-21 12:47:45 +10:00
drm_rect.h drm: Fix drm_rect documentation 2013-05-23 12:51:32 +02:00
drm_sysfs.h drm: Enable drm drivers to add drm sysfs devices. 2009-08-19 16:08:51 +10:00
drm_usb.h drm: add usb framework 2011-02-07 13:09:42 +10:00
drm_vma_manager.h drm/vma: provide drm_vma_node_unmap() helper 2013-07-25 20:47:08 +10:00
exynos_drm.h drm/exynos: change file license to GPL 2013-01-04 15:54:32 +09:00
gma_drm.h gma500: fix ioctl confict 2012-03-10 13:06:04 +00:00
i915_drm.h UAPI: (Scripted) Disintegrate include/drm 2012-10-04 18:21:50 +01:00
i915_powerwell.h i915/drm: Add private api for power well usage 2013-06-06 17:32:16 +02:00
intel-gtt.h drm/i915: Fix gen2 mappable calculations 2013-02-15 10:30:38 +01:00