drm/vma: add access management helpers
authorDavid Herrmann <dh.herrmann@gmail.com>
Sun, 25 Aug 2013 16:28:57 +0000 (18:28 +0200)
committerDave Airlie <airlied@redhat.com>
Tue, 27 Aug 2013 01:54:54 +0000 (11:54 +1000)
commit88d7ebe59341dc3b82e662b80809694e3c6b3766
treec9b89ab9ba6b2310e270b67600ca790cc85e24c3
parent291d284c6004e3a63d0c2f6c31570ab2126843a8
drm/vma: add access management helpers

The VMA offset manager uses a device-global address-space. Hence, any
user can currently map any offset-node they want. They only need to guess
the right offset. If we wanted per open-file offset spaces, we'd either
need VM_NONLINEAR mappings or multiple "struct address_space" trees. As
both doesn't really scale, we implement access management in the VMA
manager itself.

We use an rb-tree to store open-files for each VMA node. On each mmap
call, GEM, TTM or the drivers must check whether the current user is
allowed to map this file.

We add a separate lock for each node as there is no generic lock available
for the caller to protect the node easily.

As we currently don't know whether an object may be used for mmap(), we
have to do access management for all objects. If it turns out to slow down
handle creation/deletion significantly, we can optimize it in several
ways:
 - Most times only a single filp is added per bo so we could use a static
   "struct file *main_filp" which is checked/added/removed first before we
   fall back to the rbtree+drm_vma_offset_file.
   This could be even done lockless with rcu.
 - Let user-space pass a hint whether mmap() should be supported on the
   bo and avoid access-management if not.
 - .. there are probably more ideas once we have benchmarks ..

v2: add drm_vma_node_verify_access() helper

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/drm_gem.c
drivers/gpu/drm/drm_vma_manager.c
include/drm/drm_vma_manager.h