dma_resv: prime lockdep annotations
Am 21.08.2019 20:28 schrieb "Thomas Hellström (VMware)" <[email protected]>:
Quoted 113 lines · Daniel Vetter
Quoted 103 lines · Thomas Hellström (VMware)
Quoted 102 lines · Daniel Vetter
Quoted 86 lines · Thomas Hellström (VMware)
Quoted 85 lines · Daniel Vetter
Full audit of everyone:
- i915, radeon, amdgpu should be clean per their maintainers.
- vram helpers should be fine, they don't do command submission, so really no business holding
struct_mutexwhile doing copy_*_user. But I haven't checked them all.- panfrost seems to
dma_resv_lockonly inpanfrost_job_push, which looks clean.- v3d holds
dma_resvlocks in the tail of itsv3d_submit_cl_ioctl(), copying from/to userspace happens all inv3d_lookup_boswhich is outside of the critical section.- vmwgfx has a bunch of ioctls that do their own copy_*_user:
-vmw_execbuf_process: First this does some copies invmw_execbuf_cmdbuf()and also in thevmw_execbuf_process()itself. Then comes the usual ttm reserve/validate sequence, then actual submission/fencing, then unreserving, and finally some morecopy_to_userinvmw_execbuf_copy_fence_user. Glossing over tons of details, but looks all safe.
-vmw_fence_event_ioctl: No ttm_reserve/dma_resv_lock anywhere to be seen, seems to only create a fence and copy it out.
- a pile of smaller ioctl invmwgfx_ioctl.c, no reservations to be found there.
Summary: vmwgfx seems to be fine too.- virtio: There's
virtio_gpu_execbuffer_ioctl, which does all the copying from userspace before even looking up objects through their handles, so safe. Plus the getparam/getcaps ioctl, also both safe.- qxl only has
qxl_execbuffer_ioctl, which calls intoqxl_process_single_command. There's a lovely comment before the__copy_from_user_inatomicthat the slowpath should be copied from i915, but I guess that never happened. Try not to be unlucky and get your CS data evicted between when it's written and the kernel tries to read it. The only othercopy_from_useris for relocs, but those are done beforeqxl_release_reserve_list(), which seems to be the only thing reserving buffers (in the ttm/dma_resv sense) in that code. So looks safe.- A debugfs file in
nouveau_debugfs_pstate_set()and the usif ioctl inusif_ioctl()look safe.nouveau_gem_ioctl_pushbuf()otoh breaks this everywhere and needs to be fixed up.Cc Alex Deucher <[email protected]>Cc Christian König <[email protected]>Cc Chris Wilson <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc Rob Herring <[email protected]>Cc Tomeu Vizoso <[email protected]>Cc Eric Anholt <[email protected]>Cc Dave Airlie <[email protected]>Cc Gerd Hoffmann <[email protected]>Cc Ben Skeggs <[email protected]>Cc "VMware Graphics" <[email protected]>Cc Thomas Hellstrom <[email protected]>Signed-off-by Daniel Vetter <[email protected]>--- drivers/dma-buf/dma-resv.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/dma-buf/dma-resv.c +9
-0@@ -34,6 +34,7 @@#include <linux/dma-resv.h> #include <linux/export.h> +#include <linux/sched/mm.h> /** * DOC: Reservation Object Overview @@ -107,6 +108,17 @@ void dma_resv_init(struct dma_resv *obj) &reservation_seqcount_class);RCU_INIT_POINTER (obj->fence,NULL );RCU_INIT_POINTER (obj->fence_excl,NULL ); + +if (IS_ENABLED (CONFIG_LOCKDEP )) { +if (current->mm) +down_read (¤t->mm->mmap_sem); +ww_mutex_lock (&obj->lock,NULL ); +fs_reclaim_acquire (GFP_KERNEL ); +fs_reclaim_release (GFP_KERNEL ); +ww_mutex_unlock (&obj->lock);Quoted 8 lines
drivers/dma-buf/dma-resv.c void dma_resv_init(struct dma_resv *obj) · line 123
Quoted 5 lines
drivers/dma-buf/dma-resv.c +3
-0+if (current->mm) +up_read (¤t->mm->mmap_sem); + } }EXPORT_SYMBOL (dma_resv_init);I assume if this would have been easily done and maintainable using only lockdep annotation instead of actually acquiring the locks, that would have been done?
There's
might_lock(), plus a pile of macros, but they don't map obviuosly, so pretty good chances I accidentally end up with the wrong type of annotation. Easier to just take the locks quickly, and stuff that all into a lockdep-only section to avoid overhead.Quoted 2 lines
Otherwise LGTM.
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Reviewed-by Thomas Hellström <[email protected]>Will test this and let you know if it trips on vmwgfx, but it really shouldn't.
Thanks, Daniel
One thing that strikes me is that this puts restrictions on where you can actually initialize a
dma_resv, even if locking orders are otherwise obeyed. But that might not be a big problem.
Quoted 8 lines
Hm yeah ... the trouble is a need a non-kthread thread so that I have a
current->mm. Otherwise I'd have put it into some init section with a tempdma_buf. And I kinda don't want to create a fake ->mm just for lockdep priming. I don't expect this to be a real problem in practice, since before you've calleddma_resv_initthe reservation lock doesn't exist, so you can't hold it. And you've probably just allocated it, sofs_reclaimis going to be fine. And if you allocatedma_resvobjects from your fault handlers I have questions anyway :-)
Coming to think of it, I think vmwgfx sometimes create bos with other bo's reservation lock held. I guess that would trip both the mmap_sem check the ww_mutex check?
Dito inside TTM for ghost objects.
We even used to have an dma_resv_init() in an atomic section, but that should be gone by now.
Anyway, probably have to take my review back since this will certainly go up in flames.
Need a better place for this,
Christian.
/Thomas
/Thomas
Quoted 3 lines
So I think this should be safe.
-Daniel
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx