All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] dma_resv: prime lockdep annotations
@ 2019-08-21 21:50 Daniel Vetter
       [not found] ` <20190821215030.31660-1-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
                   ` (11 more replies)
  0 siblings, 12 replies; 40+ messages in thread
From: Daniel Vetter @ 2019-08-21 21:50 UTC (permalink / raw)
  To: DRI Development
  Cc: Rob Herring, Thomas Hellstrom, Tomeu Vizoso, Daniel Vetter,
	Intel Graphics Development, VMware Graphics, Gerd Hoffmann,
	Thomas Zimmermann, Daniel Vetter, Alex Deucher, Dave Airlie,
	Christian König, Ben Skeggs

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_mutex while doing copy_*_user. But
  I haven't checked them all.

- panfrost seems to dma_resv_lock only in panfrost_job_push, which
  looks clean.

- v3d holds dma_resv locks in the tail of its v3d_submit_cl_ioctl(),
  copying from/to userspace happens all in v3d_lookup_bos which 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 in
    vmw_execbuf_cmdbuf() and also in the vmw_execbuf_process() itself.
    Then comes the usual ttm reserve/validate sequence, then actual
    submission/fencing, then unreserving, and finally some more
    copy_to_user in vmw_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 in vmwgfx_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 into
  qxl_process_single_command. There's a lovely comment before the
  __copy_from_user_inatomic that 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 other copy_from_user is for relocs, but those
  are done before qxl_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 in
  usif_ioctl() look safe. nouveau_gem_ioctl_pushbuf() otoh breaks this
  everywhere and needs to be fixed up.

v2: Thomas pointed at that vmwgfx calls dma_resv_init while it holds a
dma_resv lock of a different object already. Christian mentioned that
ttm core does this too for ghost objects. intel-gfx-ci highlighted
that i915 has similar issues.

Unfortunately we can't do this in the usual module init functions,
because kernel threads don't have an ->mm - we have to wait around for
some user thread to do this.

Solution is to spawn a worker (but only once). It's horrible, but it
works.

Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Cc: Eric Anholt <eric@anholt.net>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 drivers/dma-buf/dma-resv.c | 42 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
index 42a8f3f11681..29988b1564c1 100644
--- a/drivers/dma-buf/dma-resv.c
+++ b/drivers/dma-buf/dma-resv.c
@@ -34,6 +34,7 @@
 
 #include <linux/dma-resv.h>
 #include <linux/export.h>
+#include <linux/sched/mm.h>
 
 /**
  * DOC: Reservation Object Overview
@@ -95,6 +96,28 @@ static void dma_resv_list_free(struct dma_resv_list *list)
 	kfree_rcu(list, rcu);
 }
 
+#if IS_ENABLED(CONFIG_LOCKDEP)
+struct lockdep_work {
+	struct work_struct work;
+	struct dma_resv obj;
+	struct mm_struct *mm;
+} lockdep_work;
+
+void lockdep_work_fn(struct work_struct *work)
+{
+	dma_resv_init(&lockdep_work.obj);
+
+	down_read(&lockdep_work.mm->mmap_sem);
+	ww_mutex_lock(&lockdep_work.obj.lock, NULL);
+	fs_reclaim_acquire(GFP_KERNEL);
+	fs_reclaim_release(GFP_KERNEL);
+	ww_mutex_unlock(&lockdep_work.obj.lock);
+	up_read(&lockdep_work.mm->mmap_sem);
+	
+	mmput(lockdep_work.mm);
+}
+#endif
+
 /**
  * dma_resv_init - initialize a reservation object
  * @obj: the reservation object
@@ -107,6 +130,25 @@ 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) {
+		static atomic_t lockdep_primed;
+
+		/*
+		 * This gets called from all kinds of places, launch a worker.
+		 * Usual init sections don't work for kernel threads lack an
+		 * ->mm.
+		 */
+		if (atomic_cmpxchg(&lockdep_primed, 0, 1) == 0) {
+			INIT_WORK(&lockdep_work.work, lockdep_work_fn);
+			lockdep_work.mm = current->mm;
+			mmget(lockdep_work.mm);
+
+			schedule_work(&lockdep_work.work);
+		}
+	}
+#endif
 }
 EXPORT_SYMBOL(dma_resv_init);
 
-- 
2.23.0.rc1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
       [not found] ` <20190821215030.31660-1-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
@ 2019-08-21 21:50   ` Daniel Vetter
       [not found]     ` <20190821215030.31660-2-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
  0 siblings, 1 reply; 40+ messages in thread
From: Daniel Vetter @ 2019-08-21 21:50 UTC (permalink / raw)
  To: DRI Development
  Cc: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	Intel Graphics Development, Ben Skeggs, Daniel Vetter

We can't copy_*_user while holding reservations, that will (soon even
for nouveau) lead to deadlocks. And it breaks the cross-driver
contract around dma_resv.

Fix this by adding a slowpath for when we need relocations, and by
pushing the writeback of the new presumed offsets to the very end.

Aside from "it compiles" entirely untested unfortunately.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: nouveau@lists.freedesktop.org
---
 drivers/gpu/drm/nouveau/nouveau_gem.c | 57 ++++++++++++++++++---------
 1 file changed, 38 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
index c77302f969e8..60309b997951 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -482,12 +482,9 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
 
 static int
 validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
-	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
-	      uint64_t user_pbbo_ptr)
+	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo)
 {
 	struct nouveau_drm *drm = chan->drm;
-	struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
-				(void __force __user *)(uintptr_t)user_pbbo_ptr;
 	struct nouveau_bo *nvbo;
 	int ret, relocs = 0;
 
@@ -531,10 +528,6 @@ validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
 			b->presumed.offset = nvbo->bo.offset;
 			b->presumed.valid = 0;
 			relocs++;
-
-			if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
-					     &b->presumed, sizeof(b->presumed)))
-				return -EFAULT;
 		}
 	}
 
@@ -545,8 +538,8 @@ static int
 nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
 			     struct drm_file *file_priv,
 			     struct drm_nouveau_gem_pushbuf_bo *pbbo,
-			     uint64_t user_buffers, int nr_buffers,
-			     struct validate_op *op, int *apply_relocs)
+			     int nr_buffers,
+			     struct validate_op *op, bool *apply_relocs)
 {
 	struct nouveau_cli *cli = nouveau_cli(file_priv);
 	int ret;
@@ -563,7 +556,7 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
 		return ret;
 	}
 
-	ret = validate_list(chan, cli, &op->list, pbbo, user_buffers);
+	ret = validate_list(chan, cli, &op->list, pbbo);
 	if (unlikely(ret < 0)) {
 		if (ret != -ERESTARTSYS)
 			NV_PRINTK(err, cli, "validating bo list\n");
@@ -603,16 +596,12 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
 static int
 nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
 				struct drm_nouveau_gem_pushbuf *req,
+				struct drm_nouveau_gem_pushbuf_reloc *reloc,
 				struct drm_nouveau_gem_pushbuf_bo *bo)
 {
-	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
 	int ret = 0;
 	unsigned i;
 
-	reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
-	if (IS_ERR(reloc))
-		return PTR_ERR(reloc);
-
 	for (i = 0; i < req->nr_relocs; i++) {
 		struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
 		struct drm_nouveau_gem_pushbuf_bo *b;
@@ -691,11 +680,13 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct drm_nouveau_gem_pushbuf *req = data;
 	struct drm_nouveau_gem_pushbuf_push *push;
+	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
 	struct drm_nouveau_gem_pushbuf_bo *bo;
 	struct nouveau_channel *chan = NULL;
 	struct validate_op op;
 	struct nouveau_fence *fence = NULL;
-	int i, j, ret = 0, do_reloc = 0;
+	int i, j, ret = 0;
+	bool do_reloc = false;
 
 	if (unlikely(!abi16))
 		return -ENOMEM;
@@ -753,7 +744,8 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 	}
 
 	/* Validate buffer list */
-	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
+revalidate:
+	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo,
 					   req->nr_buffers, &op, &do_reloc);
 	if (ret) {
 		if (ret != -ERESTARTSYS)
@@ -763,7 +755,18 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 
 	/* Apply any relocations that are required */
 	if (do_reloc) {
-		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
+		if (!reloc) {
+			validate_fini(&op, chan, NULL, bo);
+			reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
+			if (IS_ERR(reloc)) {
+				ret = PTR_ERR(reloc);
+				goto out_prevalid;
+			}
+
+			goto revalidate;
+		}
+
+		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, reloc, bo);
 		if (ret) {
 			NV_PRINTK(err, cli, "reloc apply: %d\n", ret);
 			goto out;
@@ -849,6 +852,22 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 	validate_fini(&op, chan, fence, bo);
 	nouveau_fence_unref(&fence);
 
+	if (do_reloc) {
+		struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
+			u64_to_user_ptr(req->buffers);
+
+		for (i = 0; i < req->nr_buffers; i++) {
+			if (bo[i].presumed.valid)
+				continue;
+
+			if (copy_to_user(&upbbo[i].presumed, &bo[i].presumed,
+					 sizeof(bo[i].presumed))) {
+				ret = -EFAULT;
+				break;
+			}
+		}
+		u_free(reloc);
+	}
 out_prevalid:
 	u_free(bo);
 	u_free(push);
-- 
2.23.0.rc1

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH 3/3] drm/ttm: remove ttm_bo_wait_unreserved
  2019-08-21 21:50 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
       [not found] ` <20190821215030.31660-1-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
@ 2019-08-21 21:50 ` Daniel Vetter
  2019-08-21 22:20 ` [PATCH 1/3] dma_resv: prime lockdep annotations Chris Wilson
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 40+ messages in thread
From: Daniel Vetter @ 2019-08-21 21:50 UTC (permalink / raw)
  To: DRI Development
  Cc: Thomas Hellstrom, Daniel Vetter, Intel Graphics Development,
	Huang Rui, VMware Graphics, Gerd Hoffmann, Daniel Vetter,
	Christian König

With nouveau fixed all ttm-using drives have the correct nesting of
mmap_sem vs dma_resv, and we can just lock the buffer.

Assuming I didn't screw up anything with my audit of course.

v2:
- Dont forget wu_mutex (Christian König)
- Keep the mmap_sem-less wait optimization (Thomas)
- Use _lock_interruptible to be good citizens (Thomas)

Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Christian Koenig <christian.koenig@amd.com>
Cc: Huang Rui <ray.huang@amd.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c      | 36 -------------------------------
 drivers/gpu/drm/ttm/ttm_bo_util.c |  1 -
 drivers/gpu/drm/ttm/ttm_bo_vm.c   | 18 +++++-----------
 include/drm/ttm/ttm_bo_api.h      |  4 ----
 4 files changed, 5 insertions(+), 54 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 20ff56f27aa4..d1ce5d315d5b 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -162,7 +162,6 @@ static void ttm_bo_release_list(struct kref *list_kref)
 	dma_fence_put(bo->moving);
 	if (!ttm_bo_uses_embedded_gem_object(bo))
 		dma_resv_fini(&bo->base._resv);
-	mutex_destroy(&bo->wu_mutex);
 	bo->destroy(bo);
 	ttm_mem_global_free(bdev->glob->mem_glob, acc_size);
 }
@@ -1319,7 +1318,6 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
 	INIT_LIST_HEAD(&bo->ddestroy);
 	INIT_LIST_HEAD(&bo->swap);
 	INIT_LIST_HEAD(&bo->io_reserve_lru);
-	mutex_init(&bo->wu_mutex);
 	bo->bdev = bdev;
 	bo->type = type;
 	bo->num_pages = num_pages;
@@ -1954,37 +1952,3 @@ void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
 		;
 }
 EXPORT_SYMBOL(ttm_bo_swapout_all);
-
-/**
- * ttm_bo_wait_unreserved - interruptible wait for a buffer object to become
- * unreserved
- *
- * @bo: Pointer to buffer
- */
-int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo)
-{
-	int ret;
-
-	/*
-	 * In the absense of a wait_unlocked API,
-	 * Use the bo::wu_mutex to avoid triggering livelocks due to
-	 * concurrent use of this function. Note that this use of
-	 * bo::wu_mutex can go away if we change locking order to
-	 * mmap_sem -> bo::reserve.
-	 */
-	ret = mutex_lock_interruptible(&bo->wu_mutex);
-	if (unlikely(ret != 0))
-		return -ERESTARTSYS;
-	if (!dma_resv_is_locked(bo->base.resv))
-		goto out_unlock;
-	ret = dma_resv_lock_interruptible(bo->base.resv, NULL);
-	if (ret == -EINTR)
-		ret = -ERESTARTSYS;
-	if (unlikely(ret != 0))
-		goto out_unlock;
-	dma_resv_unlock(bo->base.resv);
-
-out_unlock:
-	mutex_unlock(&bo->wu_mutex);
-	return ret;
-}
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index fe81c565e7ef..82ea26a49959 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -508,7 +508,6 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
 	INIT_LIST_HEAD(&fbo->base.lru);
 	INIT_LIST_HEAD(&fbo->base.swap);
 	INIT_LIST_HEAD(&fbo->base.io_reserve_lru);
-	mutex_init(&fbo->base.wu_mutex);
 	fbo->base.moving = NULL;
 	drm_vma_node_reset(&fbo->base.base.vma_node);
 	atomic_set(&fbo->base.cpu_writers, 0);
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 76eedb963693..a61a35e57d1c 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -125,30 +125,22 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
 		&bdev->man[bo->mem.mem_type];
 	struct vm_area_struct cvma;
 
-	/*
-	 * Work around locking order reversal in fault / nopfn
-	 * between mmap_sem and bo_reserve: Perform a trylock operation
-	 * for reserve, and if it fails, retry the fault after waiting
-	 * for the buffer to become unreserved.
-	 */
 	if (unlikely(!dma_resv_trylock(bo->base.resv))) {
 		if (vmf->flags & FAULT_FLAG_ALLOW_RETRY) {
 			if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
 				ttm_bo_get(bo);
 				up_read(&vmf->vma->vm_mm->mmap_sem);
-				(void) ttm_bo_wait_unreserved(bo);
+				if (!dma_resv_lock_interruptible(bo->base.resv,
+								 NULL))
+					dma_resv_unlock(bo->base.resv);
 				ttm_bo_put(bo);
 			}
 
 			return VM_FAULT_RETRY;
 		}
 
-		/*
-		 * If we'd want to change locking order to
-		 * mmap_sem -> bo::reserve, we'd use a blocking reserve here
-		 * instead of retrying the fault...
-		 */
-		return VM_FAULT_NOPAGE;
+		if (dma_resv_lock_interruptible(bo->base.resv, NULL))
+			return VM_FAULT_NOPAGE;
 	}
 
 	/*
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 43c4929a2171..21c7d0d28757 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -155,7 +155,6 @@ struct ttm_tt;
  * @offset: The current GPU offset, which can have different meanings
  * depending on the memory type. For SYSTEM type memory, it should be 0.
  * @cur_placement: Hint of current placement.
- * @wu_mutex: Wait unreserved mutex.
  *
  * Base class for TTM buffer object, that deals with data placement and CPU
  * mappings. GPU mappings are really up to the driver, but for simpler GPUs
@@ -229,8 +228,6 @@ struct ttm_buffer_object {
 	uint64_t offset; /* GPU address space is independent of CPU word size */
 
 	struct sg_table *sg;
-
-	struct mutex wu_mutex;
 };
 
 /**
@@ -765,7 +762,6 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
 int ttm_bo_swapout(struct ttm_bo_global *glob,
 			struct ttm_operation_ctx *ctx);
 void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
-int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);
 
 /**
  * ttm_bo_uses_embedded_gem_object - check if the given bo uses the
-- 
2.23.0.rc1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH 1/3] dma_resv: prime lockdep annotations
  2019-08-21 21:50 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
       [not found] ` <20190821215030.31660-1-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
  2019-08-21 21:50 ` [PATCH 3/3] drm/ttm: remove ttm_bo_wait_unreserved Daniel Vetter
@ 2019-08-21 22:20 ` Chris Wilson
  2019-08-21 22:22 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [1/3] " Patchwork
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 40+ messages in thread
From: Chris Wilson @ 2019-08-21 22:20 UTC (permalink / raw)
  To: DRI Development
  Cc: Rob Herring, Thomas Hellstrom, Tomeu Vizoso, Daniel Vetter,
	Intel Graphics Development, VMware Graphics, Gerd Hoffmann,
	Thomas Zimmermann, Daniel Vetter, Alex Deucher, Dave Airlie,
	Christian König, Ben Skeggs

Quoting Daniel Vetter (2019-08-21 22:50:28)
> 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_mutex while doing copy_*_user. But
>   I haven't checked them all.
> 
> - panfrost seems to dma_resv_lock only in panfrost_job_push, which
>   looks clean.
> 
> - v3d holds dma_resv locks in the tail of its v3d_submit_cl_ioctl(),
>   copying from/to userspace happens all in v3d_lookup_bos which 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 in
>     vmw_execbuf_cmdbuf() and also in the vmw_execbuf_process() itself.
>     Then comes the usual ttm reserve/validate sequence, then actual
>     submission/fencing, then unreserving, and finally some more
>     copy_to_user in vmw_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 in vmwgfx_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 into
>   qxl_process_single_command. There's a lovely comment before the
>   __copy_from_user_inatomic that 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 other copy_from_user is for relocs, but those
>   are done before qxl_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 in
>   usif_ioctl() look safe. nouveau_gem_ioctl_pushbuf() otoh breaks this
>   everywhere and needs to be fixed up.
> 
> v2: Thomas pointed at that vmwgfx calls dma_resv_init while it holds a
> dma_resv lock of a different object already. Christian mentioned that
> ttm core does this too for ghost objects. intel-gfx-ci highlighted
> that i915 has similar issues.
> 
> Unfortunately we can't do this in the usual module init functions,
> because kernel threads don't have an ->mm - we have to wait around for
> some user thread to do this.
> 
> Solution is to spawn a worker (but only once). It's horrible, but it
> works.
> 
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: Christian König <christian.koenig@amd.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> Cc: Eric Anholt <eric@anholt.net>
> Cc: Dave Airlie <airlied@redhat.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
> Cc: Thomas Hellstrom <thellstrom@vmware.com>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> ---
>  drivers/dma-buf/dma-resv.c | 42 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 42 insertions(+)
> 
> diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
> index 42a8f3f11681..29988b1564c1 100644
> --- a/drivers/dma-buf/dma-resv.c
> +++ b/drivers/dma-buf/dma-resv.c
> @@ -34,6 +34,7 @@
>  
>  #include <linux/dma-resv.h>
>  #include <linux/export.h>
> +#include <linux/sched/mm.h>
>  
>  /**
>   * DOC: Reservation Object Overview
> @@ -95,6 +96,28 @@ static void dma_resv_list_free(struct dma_resv_list *list)
>         kfree_rcu(list, rcu);
>  }
>  
> +#if IS_ENABLED(CONFIG_LOCKDEP)
> +struct lockdep_work {
> +       struct work_struct work;
> +       struct dma_resv obj;
> +       struct mm_struct *mm;
> +} lockdep_work;
> +
> +void lockdep_work_fn(struct work_struct *work)
> +{
> +       dma_resv_init(&lockdep_work.obj);
> +
> +       down_read(&lockdep_work.mm->mmap_sem);
> +       ww_mutex_lock(&lockdep_work.obj.lock, NULL);
> +       fs_reclaim_acquire(GFP_KERNEL);
> +       fs_reclaim_release(GFP_KERNEL);
> +       ww_mutex_unlock(&lockdep_work.obj.lock);
> +       up_read(&lockdep_work.mm->mmap_sem);
> +       
> +       mmput(lockdep_work.mm);
> +}
> +#endif

#if IS_ENABLED(CONFIG_LOCKDEP)
static void dma_resv_lockmap(void)
{
	struct mm_struct *mm = alloc_mm();
	struct dma_resv obj;

	dma_resv_init(&obj);

	down_read(&mm->mmap_sem);
	ww_mutex_lock(&obj.lock, NULL);
	fs_reclaim_acquire(GFP_KERNEL);
	fs_reclaim_release(GFP_KERNEL);
	ww_mutex_unlock(&obj.lock);
	up_read(&mm->mmap_sem);

	mmput(mm);
}
core_initcall(dma_resv_lockmap);
#endif

as a thought.
-Chris
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* ✗ Fi.CI.CHECKPATCH: warning for series starting with [1/3] dma_resv: prime lockdep annotations
  2019-08-21 21:50 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
                   ` (2 preceding siblings ...)
  2019-08-21 22:20 ` [PATCH 1/3] dma_resv: prime lockdep annotations Chris Wilson
@ 2019-08-21 22:22 ` Patchwork
  2019-08-21 22:46 ` ✓ Fi.CI.BAT: success " Patchwork
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 40+ messages in thread
From: Patchwork @ 2019-08-21 22:22 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: intel-gfx

== Series Details ==

Series: series starting with [1/3] dma_resv: prime lockdep annotations
URL   : https://patchwork.freedesktop.org/series/65575/
State : warning

== Summary ==

$ dim checkpatch origin/drm-tip
27b2890c9980 dma_resv: prime lockdep annotations
-:77: WARNING:BAD_SIGN_OFF: email address '"VMware Graphics" <linux-graphics-maintainer@vmware.com>' might be better as 'VMware Graphics <linux-graphics-maintainer@vmware.com>'
#77: 
Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>

-:114: ERROR:TRAILING_WHITESPACE: trailing whitespace
#114: FILE: drivers/dma-buf/dma-resv.c:116:
+^I$

-:147: WARNING:NO_AUTHOR_SIGN_OFF: Missing Signed-off-by: line by nominal patch author 'Daniel Vetter <daniel.vetter@ffwll.ch>'

total: 1 errors, 2 warnings, 0 checks, 60 lines checked
b036ba3d6038 drm/nouveau: slowpath for pushbuf ioctl
-:153: WARNING:NO_AUTHOR_SIGN_OFF: Missing Signed-off-by: line by nominal patch author 'Daniel Vetter <daniel.vetter@ffwll.ch>'

total: 0 errors, 1 warnings, 0 checks, 122 lines checked
95bae0c804e9 drm/ttm: remove ttm_bo_wait_unreserved
-:24: WARNING:BAD_SIGN_OFF: email address '"VMware Graphics" <linux-graphics-maintainer@vmware.com>' might be better as 'VMware Graphics <linux-graphics-maintainer@vmware.com>'
#24: 
Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>

-:165: WARNING:NO_AUTHOR_SIGN_OFF: Missing Signed-off-by: line by nominal patch author 'Daniel Vetter <daniel.vetter@ffwll.ch>'

total: 0 errors, 2 warnings, 0 checks, 81 lines checked

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* ✓ Fi.CI.BAT: success for series starting with [1/3] dma_resv: prime lockdep annotations
  2019-08-21 21:50 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
                   ` (3 preceding siblings ...)
  2019-08-21 22:22 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [1/3] " Patchwork
@ 2019-08-21 22:46 ` Patchwork
  2019-08-22  6:49 ` [PATCH] drm/ttm: remove ttm_bo_wait_unreserved Daniel Vetter
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 40+ messages in thread
From: Patchwork @ 2019-08-21 22:46 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: intel-gfx

== Series Details ==

Series: series starting with [1/3] dma_resv: prime lockdep annotations
URL   : https://patchwork.freedesktop.org/series/65575/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_6759 -> Patchwork_14132
====================================================

Summary
-------

  **SUCCESS**

  No regressions found.

  External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/

Known issues
------------

  Here are the changes found in Patchwork_14132 that come from known issues:

### IGT changes ###

#### Issues hit ####

  * igt@gem_mmap_gtt@basic-write-read-distinct:
    - fi-icl-u3:          [PASS][1] -> [DMESG-WARN][2] ([fdo#107724])
   [1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/fi-icl-u3/igt@gem_mmap_gtt@basic-write-read-distinct.html
   [2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/fi-icl-u3/igt@gem_mmap_gtt@basic-write-read-distinct.html

  * igt@i915_selftest@live_execlists:
    - fi-skl-gvtdvm:      [PASS][3] -> [DMESG-FAIL][4] ([fdo#111108])
   [3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/fi-skl-gvtdvm/igt@i915_selftest@live_execlists.html
   [4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/fi-skl-gvtdvm/igt@i915_selftest@live_execlists.html

  * igt@kms_chamelium@common-hpd-after-suspend:
    - fi-kbl-7567u:       [PASS][5] -> [DMESG-FAIL][6] ([fdo#102505] / [fdo#105079])
   [5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/fi-kbl-7567u/igt@kms_chamelium@common-hpd-after-suspend.html
   [6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/fi-kbl-7567u/igt@kms_chamelium@common-hpd-after-suspend.html

  * igt@kms_force_connector_basic@force-connector-state:
    - fi-ilk-650:         [PASS][7] -> [DMESG-WARN][8] ([fdo#106387])
   [7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/fi-ilk-650/igt@kms_force_connector_basic@force-connector-state.html
   [8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/fi-ilk-650/igt@kms_force_connector_basic@force-connector-state.html

  * igt@kms_pipe_crc_basic@read-crc-pipe-c:
    - fi-kbl-7567u:       [PASS][9] -> [SKIP][10] ([fdo#109271]) +19 similar issues
   [9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/fi-kbl-7567u/igt@kms_pipe_crc_basic@read-crc-pipe-c.html
   [10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/fi-kbl-7567u/igt@kms_pipe_crc_basic@read-crc-pipe-c.html

  
#### Possible fixes ####

  * igt@debugfs_test@read_all_entries:
    - fi-kbl-7567u:       [DMESG-WARN][11] ([fdo#103558] / [fdo#105602]) -> [PASS][12]
   [11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/fi-kbl-7567u/igt@debugfs_test@read_all_entries.html
   [12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/fi-kbl-7567u/igt@debugfs_test@read_all_entries.html

  * igt@gem_exec_suspend@basic-s3:
    - fi-kbl-7567u:       [DMESG-WARN][13] ([fdo#103558] / [fdo#105079] / [fdo#105602]) -> [PASS][14]
   [13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/fi-kbl-7567u/igt@gem_exec_suspend@basic-s3.html
   [14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/fi-kbl-7567u/igt@gem_exec_suspend@basic-s3.html

  * igt@kms_busy@basic-flip-a:
    - fi-kbl-7567u:       [SKIP][15] ([fdo#109271] / [fdo#109278]) -> [PASS][16] +2 similar issues
   [15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/fi-kbl-7567u/igt@kms_busy@basic-flip-a.html
   [16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/fi-kbl-7567u/igt@kms_busy@basic-flip-a.html

  * igt@kms_chamelium@hdmi-edid-read:
    - fi-kbl-7567u:       [FAIL][17] ([fdo#109569]) -> [PASS][18] +1 similar issue
   [17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/fi-kbl-7567u/igt@kms_chamelium@hdmi-edid-read.html
   [18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/fi-kbl-7567u/igt@kms_chamelium@hdmi-edid-read.html

  
#### Warnings ####

  * igt@kms_chamelium@hdmi-hpd-fast:
    - fi-icl-u2:          [FAIL][19] ([fdo#109483]) -> [FAIL][20] ([fdo#111407])
   [19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/fi-icl-u2/igt@kms_chamelium@hdmi-hpd-fast.html
   [20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/fi-icl-u2/igt@kms_chamelium@hdmi-hpd-fast.html
    - fi-kbl-7567u:       [FAIL][21] ([fdo#109800]) -> [FAIL][22] ([fdo#111407])
   [21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/fi-kbl-7567u/igt@kms_chamelium@hdmi-hpd-fast.html
   [22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/fi-kbl-7567u/igt@kms_chamelium@hdmi-hpd-fast.html

  * igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a:
    - fi-kbl-7567u:       [DMESG-FAIL][23] ([fdo#105079]) -> [SKIP][24] ([fdo#109271])
   [23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/fi-kbl-7567u/igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a.html
   [24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/fi-kbl-7567u/igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a.html

  
  {name}: This element is suppressed. This means it is ignored when computing
          the status of the difference (SUCCESS, WARNING, or FAILURE).

  [fdo#102505]: https://bugs.freedesktop.org/show_bug.cgi?id=102505
  [fdo#103558]: https://bugs.freedesktop.org/show_bug.cgi?id=103558
  [fdo#105079]: https://bugs.freedesktop.org/show_bug.cgi?id=105079
  [fdo#105602]: https://bugs.freedesktop.org/show_bug.cgi?id=105602
  [fdo#106387]: https://bugs.freedesktop.org/show_bug.cgi?id=106387
  [fdo#107724]: https://bugs.freedesktop.org/show_bug.cgi?id=107724
  [fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
  [fdo#109278]: https://bugs.freedesktop.org/show_bug.cgi?id=109278
  [fdo#109483]: https://bugs.freedesktop.org/show_bug.cgi?id=109483
  [fdo#109569]: https://bugs.freedesktop.org/show_bug.cgi?id=109569
  [fdo#109800]: https://bugs.freedesktop.org/show_bug.cgi?id=109800
  [fdo#111045]: https://bugs.freedesktop.org/show_bug.cgi?id=111045
  [fdo#111096]: https://bugs.freedesktop.org/show_bug.cgi?id=111096
  [fdo#111108]: https://bugs.freedesktop.org/show_bug.cgi?id=111108
  [fdo#111407]: https://bugs.freedesktop.org/show_bug.cgi?id=111407


Participating hosts (56 -> 47)
------------------------------

  Missing    (9): fi-kbl-soraka fi-ilk-m540 fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-gdg-551 fi-icl-y fi-byt-clapper fi-bdw-samus 


Build changes
-------------

  * CI: CI-20190529 -> None
  * Linux: CI_DRM_6759 -> Patchwork_14132

  CI-20190529: 20190529
  CI_DRM_6759: ef8503f9bd35e778de52953fe627fd50f316d712 @ git://anongit.freedesktop.org/gfx-ci/linux
  IGT_5146: 357dbe1869d88a2f08bcee4eebceff4ee9014424 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
  Patchwork_14132: 95bae0c804e91ea50401859c0f59635eed746891 @ git://anongit.freedesktop.org/gfx-ci/linux


== Linux commits ==

95bae0c804e9 drm/ttm: remove ttm_bo_wait_unreserved
b036ba3d6038 drm/nouveau: slowpath for pushbuf ioctl
27b2890c9980 dma_resv: prime lockdep annotations

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [PATCH] drm/ttm: remove ttm_bo_wait_unreserved
  2019-08-21 21:50 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
                   ` (4 preceding siblings ...)
  2019-08-21 22:46 ` ✓ Fi.CI.BAT: success " Patchwork
@ 2019-08-22  6:49 ` Daniel Vetter
  2019-08-22  7:56   ` Koenig, Christian
  2019-08-22  6:54 ` [PATCH] dma_resv: prime lockdep annotations Daniel Vetter
                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 40+ messages in thread
From: Daniel Vetter @ 2019-08-22  6:49 UTC (permalink / raw)
  To: DRI Development
  Cc: Thomas Hellstrom, Daniel Vetter, Intel Graphics Development,
	Huang Rui, VMware Graphics, Gerd Hoffmann, Daniel Vetter,
	Christian König

With nouveau fixed all ttm-using drives have the correct nesting of
mmap_sem vs dma_resv, and we can just lock the buffer.

Assuming I didn't screw up anything with my audit of course.

v2:
- Dont forget wu_mutex (Christian König)
- Keep the mmap_sem-less wait optimization (Thomas)
- Use _lock_interruptible to be good citizens (Thomas)

Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Christian Koenig <christian.koenig@amd.com>
Cc: Huang Rui <ray.huang@amd.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c      | 36 -------------------------------
 drivers/gpu/drm/ttm/ttm_bo_util.c |  1 -
 drivers/gpu/drm/ttm/ttm_bo_vm.c   | 18 +++++-----------
 include/drm/ttm/ttm_bo_api.h      |  4 ----
 4 files changed, 5 insertions(+), 54 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 20ff56f27aa4..d1ce5d315d5b 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -162,7 +162,6 @@ static void ttm_bo_release_list(struct kref *list_kref)
 	dma_fence_put(bo->moving);
 	if (!ttm_bo_uses_embedded_gem_object(bo))
 		dma_resv_fini(&bo->base._resv);
-	mutex_destroy(&bo->wu_mutex);
 	bo->destroy(bo);
 	ttm_mem_global_free(bdev->glob->mem_glob, acc_size);
 }
@@ -1319,7 +1318,6 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
 	INIT_LIST_HEAD(&bo->ddestroy);
 	INIT_LIST_HEAD(&bo->swap);
 	INIT_LIST_HEAD(&bo->io_reserve_lru);
-	mutex_init(&bo->wu_mutex);
 	bo->bdev = bdev;
 	bo->type = type;
 	bo->num_pages = num_pages;
@@ -1954,37 +1952,3 @@ void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
 		;
 }
 EXPORT_SYMBOL(ttm_bo_swapout_all);
-
-/**
- * ttm_bo_wait_unreserved - interruptible wait for a buffer object to become
- * unreserved
- *
- * @bo: Pointer to buffer
- */
-int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo)
-{
-	int ret;
-
-	/*
-	 * In the absense of a wait_unlocked API,
-	 * Use the bo::wu_mutex to avoid triggering livelocks due to
-	 * concurrent use of this function. Note that this use of
-	 * bo::wu_mutex can go away if we change locking order to
-	 * mmap_sem -> bo::reserve.
-	 */
-	ret = mutex_lock_interruptible(&bo->wu_mutex);
-	if (unlikely(ret != 0))
-		return -ERESTARTSYS;
-	if (!dma_resv_is_locked(bo->base.resv))
-		goto out_unlock;
-	ret = dma_resv_lock_interruptible(bo->base.resv, NULL);
-	if (ret == -EINTR)
-		ret = -ERESTARTSYS;
-	if (unlikely(ret != 0))
-		goto out_unlock;
-	dma_resv_unlock(bo->base.resv);
-
-out_unlock:
-	mutex_unlock(&bo->wu_mutex);
-	return ret;
-}
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index fe81c565e7ef..82ea26a49959 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -508,7 +508,6 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
 	INIT_LIST_HEAD(&fbo->base.lru);
 	INIT_LIST_HEAD(&fbo->base.swap);
 	INIT_LIST_HEAD(&fbo->base.io_reserve_lru);
-	mutex_init(&fbo->base.wu_mutex);
 	fbo->base.moving = NULL;
 	drm_vma_node_reset(&fbo->base.base.vma_node);
 	atomic_set(&fbo->base.cpu_writers, 0);
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 76eedb963693..a61a35e57d1c 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -125,30 +125,22 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
 		&bdev->man[bo->mem.mem_type];
 	struct vm_area_struct cvma;
 
-	/*
-	 * Work around locking order reversal in fault / nopfn
-	 * between mmap_sem and bo_reserve: Perform a trylock operation
-	 * for reserve, and if it fails, retry the fault after waiting
-	 * for the buffer to become unreserved.
-	 */
 	if (unlikely(!dma_resv_trylock(bo->base.resv))) {
 		if (vmf->flags & FAULT_FLAG_ALLOW_RETRY) {
 			if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
 				ttm_bo_get(bo);
 				up_read(&vmf->vma->vm_mm->mmap_sem);
-				(void) ttm_bo_wait_unreserved(bo);
+				if (!dma_resv_lock_interruptible(bo->base.resv,
+								 NULL))
+					dma_resv_unlock(bo->base.resv);
 				ttm_bo_put(bo);
 			}
 
 			return VM_FAULT_RETRY;
 		}
 
-		/*
-		 * If we'd want to change locking order to
-		 * mmap_sem -> bo::reserve, we'd use a blocking reserve here
-		 * instead of retrying the fault...
-		 */
-		return VM_FAULT_NOPAGE;
+		if (dma_resv_lock_interruptible(bo->base.resv, NULL))
+			return VM_FAULT_NOPAGE;
 	}
 
 	/*
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 43c4929a2171..21c7d0d28757 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -155,7 +155,6 @@ struct ttm_tt;
  * @offset: The current GPU offset, which can have different meanings
  * depending on the memory type. For SYSTEM type memory, it should be 0.
  * @cur_placement: Hint of current placement.
- * @wu_mutex: Wait unreserved mutex.
  *
  * Base class for TTM buffer object, that deals with data placement and CPU
  * mappings. GPU mappings are really up to the driver, but for simpler GPUs
@@ -229,8 +228,6 @@ struct ttm_buffer_object {
 	uint64_t offset; /* GPU address space is independent of CPU word size */
 
 	struct sg_table *sg;
-
-	struct mutex wu_mutex;
 };
 
 /**
@@ -765,7 +762,6 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
 int ttm_bo_swapout(struct ttm_bo_global *glob,
 			struct ttm_operation_ctx *ctx);
 void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
-int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);
 
 /**
  * ttm_bo_uses_embedded_gem_object - check if the given bo uses the
-- 
2.23.0.rc1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH] dma_resv: prime lockdep annotations
  2019-08-21 21:50 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
                   ` (5 preceding siblings ...)
  2019-08-22  6:49 ` [PATCH] drm/ttm: remove ttm_bo_wait_unreserved Daniel Vetter
@ 2019-08-22  6:54 ` Daniel Vetter
  2019-08-22  7:48   ` Chris Wilson
                     ` (2 more replies)
  2019-08-22  8:40 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with dma_resv: prime lockdep annotations (rev3) Patchwork
                   ` (4 subsequent siblings)
  11 siblings, 3 replies; 40+ messages in thread
From: Daniel Vetter @ 2019-08-22  6:54 UTC (permalink / raw)
  To: DRI Development
  Cc: Rob Herring, Thomas Hellstrom, Tomeu Vizoso, Daniel Vetter,
	Intel Graphics Development, VMware Graphics, Gerd Hoffmann,
	Thomas Zimmermann, Daniel Vetter, Alex Deucher, Dave Airlie,
	Christian König, Ben Skeggs

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_mutex while doing copy_*_user. But
  I haven't checked them all.

- panfrost seems to dma_resv_lock only in panfrost_job_push, which
  looks clean.

- v3d holds dma_resv locks in the tail of its v3d_submit_cl_ioctl(),
  copying from/to userspace happens all in v3d_lookup_bos which 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 in
    vmw_execbuf_cmdbuf() and also in the vmw_execbuf_process() itself.
    Then comes the usual ttm reserve/validate sequence, then actual
    submission/fencing, then unreserving, and finally some more
    copy_to_user in vmw_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 in vmwgfx_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 into
  qxl_process_single_command. There's a lovely comment before the
  __copy_from_user_inatomic that 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 other copy_from_user is for relocs, but those
  are done before qxl_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 in
  usif_ioctl() look safe. nouveau_gem_ioctl_pushbuf() otoh breaks this
  everywhere and needs to be fixed up.

v2: Thomas pointed at that vmwgfx calls dma_resv_init while it holds a
dma_resv lock of a different object already. Christian mentioned that
ttm core does this too for ghost objects. intel-gfx-ci highlighted
that i915 has similar issues.

Unfortunately we can't do this in the usual module init functions,
because kernel threads don't have an ->mm - we have to wait around for
some user thread to do this.

Solution is to spawn a worker (but only once). It's horrible, but it
works.

v3: We can allocate mm! (Chris). Horrible worker hack out, clean
initcall solution in.

Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Cc: Eric Anholt <eric@anholt.net>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 drivers/dma-buf/dma-resv.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
index 42a8f3f11681..d233ef4cf0d7 100644
--- a/drivers/dma-buf/dma-resv.c
+++ b/drivers/dma-buf/dma-resv.c
@@ -34,6 +34,7 @@
 
 #include <linux/dma-resv.h>
 #include <linux/export.h>
+#include <linux/sched/mm.h>
 
 /**
  * DOC: Reservation Object Overview
@@ -95,6 +96,29 @@ static void dma_resv_list_free(struct dma_resv_list *list)
 	kfree_rcu(list, rcu);
 }
 
+#if IS_ENABLED(CONFIG_LOCKDEP)
+static void dma_resv_lockdep(void)
+{
+	struct mm_struct *mm = mm_alloc();
+	struct dma_resv obj;
+
+	if (!mm)
+		return;
+
+	dma_resv_init(&obj);
+
+	down_read(&mm->mmap_sem);
+	ww_mutex_lock(&obj.lock, NULL);
+	fs_reclaim_acquire(GFP_KERNEL);
+	fs_reclaim_release(GFP_KERNEL);
+	ww_mutex_unlock(&obj.lock);
+	up_read(&mm->mmap_sem);
+	
+	mmput(mm);
+}
+subsys_initcall(dma_resv_lockdep);
+#endif
+
 /**
  * dma_resv_init - initialize a reservation object
  * @obj: the reservation object
-- 
2.23.0.rc1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH] dma_resv: prime lockdep annotations
  2019-08-22  6:54 ` [PATCH] dma_resv: prime lockdep annotations Daniel Vetter
@ 2019-08-22  7:48   ` Chris Wilson
  2019-08-22  7:53   ` Koenig, Christian
  2019-08-22 12:56   ` Rob Herring
  2 siblings, 0 replies; 40+ messages in thread
From: Chris Wilson @ 2019-08-22  7:48 UTC (permalink / raw)
  To: DRI Development
  Cc: Rob Herring, Thomas Hellstrom, Tomeu Vizoso, Daniel Vetter,
	Intel Graphics Development, VMware Graphics, Gerd Hoffmann,
	Thomas Zimmermann, Daniel Vetter, Alex Deucher, Dave Airlie,
	Christian König, Ben Skeggs

Quoting Daniel Vetter (2019-08-22 07:54:57)
> +#if IS_ENABLED(CONFIG_LOCKDEP)
> +static void dma_resv_lockdep(void)
> +{
> +       struct mm_struct *mm = mm_alloc();
> +       struct dma_resv obj;
> +
> +       if (!mm)
> +               return;
> +
> +       dma_resv_init(&obj);
> +
> +       down_read(&mm->mmap_sem);
> +       ww_mutex_lock(&obj.lock, NULL);
> +       fs_reclaim_acquire(GFP_KERNEL);
> +       fs_reclaim_release(GFP_KERNEL);
> +       ww_mutex_unlock(&obj.lock);
> +       up_read(&mm->mmap_sem);
> +       
> +       mmput(mm);
> +}
> +subsys_initcall(dma_resv_lockdep);
> +#endif

Adding a

	dma_resv_lock();
	might_lock(&i915->drm.struct_mutex);
	dma_resv_unlock();

yielded

[   18.513633] ======================================================
[   18.513636] WARNING: possible circular locking dependency detected
[   18.513639] 5.3.0-rc5+ #76 Not tainted
[   18.513640] ------------------------------------------------------
[   18.513643] insmod/655 is trying to acquire lock:
[   18.513645] 00000000877909e7 (&dev->struct_mutex){+.+.}, at: i915_driver_probe+0x89c/0x1470 [i915]
[   18.513671] 
[   18.513671] but task is already holding lock:
[   18.513673] 00000000a85ba8ec (reservation_ww_class_mutex){+.+.}, at: i915_driver_probe+0x8e1/0x1470 [i915]
[   18.513698] 
[   18.513698] which lock already depends on the new lock.
[   18.513698] 
[   18.513701] 
[   18.513701] the existing dependency chain (in reverse order) is:
[   18.513703] 
[   18.513703] -> #1 (reservation_ww_class_mutex){+.+.}:
[   18.513708]        __ww_mutex_lock.constprop.17+0xbc/0xf90
[   18.513739]        i915_gem_init+0x518/0x750 [i915]
[   18.513762]        i915_driver_probe+0x891/0x1470 [i915]
[   18.513785]        i915_pci_probe+0x2f/0x110 [i915]
[   18.513789]        pci_device_probe+0x99/0x110
[   18.513792]        really_probe+0xd1/0x360
[   18.513794]        driver_probe_device+0xaf/0xf0
[   18.513796]        device_driver_attach+0x4a/0x50
[   18.513799]        __driver_attach+0x80/0x140
[   18.513801]        bus_for_each_dev+0x5e/0x90
[   18.513804]        bus_add_driver+0x148/0x1e0
[   18.513806]        driver_register+0x66/0xb0
[   18.513809]        do_one_initcall+0x45/0x29f
[   18.513812]        do_init_module+0x55/0x200
[   18.513814]        load_module+0x2519/0x2690
[   18.513816]        __do_sys_finit_module+0x8f/0xd0
[   18.513818]        do_syscall_64+0x4f/0x220
[   18.513822]        entry_SYSCALL_64_after_hwframe+0x49/0xbe
[   18.513824] 
[   18.513824] -> #0 (&dev->struct_mutex){+.+.}:
[   18.513828]        __lock_acquire+0xcb9/0x1520
[   18.513831]        lock_acquire+0x90/0x170
[   18.513853]        i915_driver_probe+0x8fd/0x1470 [i915]
[   18.513876]        i915_pci_probe+0x2f/0x110 [i915]
[   18.513879]        pci_device_probe+0x99/0x110
[   18.513881]        really_probe+0xd1/0x360
[   18.513883]        driver_probe_device+0xaf/0xf0
[   18.513886]        device_driver_attach+0x4a/0x50
[   18.513888]        __driver_attach+0x80/0x140
[   18.513891]        bus_for_each_dev+0x5e/0x90
[   18.513893]        bus_add_driver+0x148/0x1e0
[   18.513895]        driver_register+0x66/0xb0
[   18.513897]        do_one_initcall+0x45/0x29f
[   18.513899]        do_init_module+0x55/0x200
[   18.513902]        load_module+0x2519/0x2690
[   18.513904]        __do_sys_finit_module+0x8f/0xd0
[   18.513906]        do_syscall_64+0x4f/0x220
[   18.513909]        entry_SYSCALL_64_after_hwframe+0x49/0xbe
[   18.513911] 
[   18.513911] other info that might help us debug this:
[   18.513911] 
[   18.513914]  Possible unsafe locking scenario:
[   18.513914] 
[   18.513916]        CPU0                    CPU1
[   18.513918]        ----                    ----
[   18.513920]   lock(reservation_ww_class_mutex);
[   18.513922]                                lock(&dev->struct_mutex);
[   18.513924]                                lock(reservation_ww_class_mutex);
[   18.513927]   lock(&dev->struct_mutex);
[   18.513929] 
[   18.513929]  *** DEADLOCK ***
[   18.513929] 
[   18.513932] 3 locks held by insmod/655:
[   18.513933]  #0: 000000004dccb591 (&dev->mutex){....}, at: device_driver_attach+0x18/0x50
[   18.513938]  #1: 000000009118ecae (&mm->mmap_sem#2){++++}, at: i915_driver_probe+0x8c8/0x1470 [i915]
[   18.513962]  #2: 00000000a85ba8ec (reservation_ww_class_mutex){+.+.}, at: i915_driver_probe+0x8e1/0x1470 [i915]

so

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Tested-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH] dma_resv: prime lockdep annotations
  2019-08-22  6:54 ` [PATCH] dma_resv: prime lockdep annotations Daniel Vetter
  2019-08-22  7:48   ` Chris Wilson
@ 2019-08-22  7:53   ` Koenig, Christian
  2019-09-03  8:16     ` Daniel Vetter
  2019-08-22 12:56   ` Rob Herring
  2 siblings, 1 reply; 40+ messages in thread
From: Koenig, Christian @ 2019-08-22  7:53 UTC (permalink / raw)
  To: Daniel Vetter, DRI Development
  Cc: Thomas Hellstrom, Tomeu Vizoso, Intel Graphics Development,
	VMware Graphics, Gerd Hoffmann, Thomas Zimmermann, Daniel Vetter,
	Deucher, Alexander, Dave Airlie, Ben Skeggs

Am 22.08.19 um 08:54 schrieb 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_mutex while doing copy_*_user. But
>    I haven't checked them all.
>
> - panfrost seems to dma_resv_lock only in panfrost_job_push, which
>    looks clean.
>
> - v3d holds dma_resv locks in the tail of its v3d_submit_cl_ioctl(),
>    copying from/to userspace happens all in v3d_lookup_bos which 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 in
>      vmw_execbuf_cmdbuf() and also in the vmw_execbuf_process() itself.
>      Then comes the usual ttm reserve/validate sequence, then actual
>      submission/fencing, then unreserving, and finally some more
>      copy_to_user in vmw_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 in vmwgfx_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 into
>    qxl_process_single_command. There's a lovely comment before the
>    __copy_from_user_inatomic that 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 other copy_from_user is for relocs, but those
>    are done before qxl_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 in
>    usif_ioctl() look safe. nouveau_gem_ioctl_pushbuf() otoh breaks this
>    everywhere and needs to be fixed up.
>
> v2: Thomas pointed at that vmwgfx calls dma_resv_init while it holds a
> dma_resv lock of a different object already. Christian mentioned that
> ttm core does this too for ghost objects. intel-gfx-ci highlighted
> that i915 has similar issues.
>
> Unfortunately we can't do this in the usual module init functions,
> because kernel threads don't have an ->mm - we have to wait around for
> some user thread to do this.
>
> Solution is to spawn a worker (but only once). It's horrible, but it
> works.
>
> v3: We can allocate mm! (Chris). Horrible worker hack out, clean
> initcall solution in.
>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: Christian König <christian.koenig@amd.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> Cc: Eric Anholt <eric@anholt.net>
> Cc: Dave Airlie <airlied@redhat.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
> Cc: Thomas Hellstrom <thellstrom@vmware.com>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/dma-buf/dma-resv.c | 24 ++++++++++++++++++++++++
>   1 file changed, 24 insertions(+)
>
> diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
> index 42a8f3f11681..d233ef4cf0d7 100644
> --- a/drivers/dma-buf/dma-resv.c
> +++ b/drivers/dma-buf/dma-resv.c
> @@ -34,6 +34,7 @@
>   
>   #include <linux/dma-resv.h>
>   #include <linux/export.h>
> +#include <linux/sched/mm.h>
>   
>   /**
>    * DOC: Reservation Object Overview
> @@ -95,6 +96,29 @@ static void dma_resv_list_free(struct dma_resv_list *list)
>   	kfree_rcu(list, rcu);
>   }
>   
> +#if IS_ENABLED(CONFIG_LOCKDEP)
> +static void dma_resv_lockdep(void)
> +{
> +	struct mm_struct *mm = mm_alloc();
> +	struct dma_resv obj;
> +
> +	if (!mm)
> +		return;
> +
> +	dma_resv_init(&obj);
> +
> +	down_read(&mm->mmap_sem);
> +	ww_mutex_lock(&obj.lock, NULL);
> +	fs_reclaim_acquire(GFP_KERNEL);
> +	fs_reclaim_release(GFP_KERNEL);
> +	ww_mutex_unlock(&obj.lock);
> +	up_read(&mm->mmap_sem);
> +	
> +	mmput(mm);
> +}
> +subsys_initcall(dma_resv_lockdep);
> +#endif
> +
>   /**
>    * dma_resv_init - initialize a reservation object
>    * @obj: the reservation object

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH] drm/ttm: remove ttm_bo_wait_unreserved
  2019-08-22  6:49 ` [PATCH] drm/ttm: remove ttm_bo_wait_unreserved Daniel Vetter
@ 2019-08-22  7:56   ` Koenig, Christian
  2019-08-22  8:47     ` Daniel Vetter
  2019-08-22 13:06     ` Daniel Vetter
  0 siblings, 2 replies; 40+ messages in thread
From: Koenig, Christian @ 2019-08-22  7:56 UTC (permalink / raw)
  To: Daniel Vetter, DRI Development
  Cc: Thomas Hellstrom, Intel Graphics Development, Huang, Ray,
	VMware Graphics, Gerd Hoffmann, Daniel Vetter

Am 22.08.19 um 08:49 schrieb Daniel Vetter:
> With nouveau fixed all ttm-using drives have the correct nesting of
> mmap_sem vs dma_resv, and we can just lock the buffer.
>
> Assuming I didn't screw up anything with my audit of course.
>
> v2:
> - Dont forget wu_mutex (Christian König)
> - Keep the mmap_sem-less wait optimization (Thomas)
> - Use _lock_interruptible to be good citizens (Thomas)
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Christian Koenig <christian.koenig@amd.com>
> Cc: Huang Rui <ray.huang@amd.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
> Cc: Thomas Hellstrom <thellstrom@vmware.com>
> ---
>   drivers/gpu/drm/ttm/ttm_bo.c      | 36 -------------------------------
>   drivers/gpu/drm/ttm/ttm_bo_util.c |  1 -
>   drivers/gpu/drm/ttm/ttm_bo_vm.c   | 18 +++++-----------
>   include/drm/ttm/ttm_bo_api.h      |  4 ----
>   4 files changed, 5 insertions(+), 54 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 20ff56f27aa4..d1ce5d315d5b 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -162,7 +162,6 @@ static void ttm_bo_release_list(struct kref *list_kref)
>   	dma_fence_put(bo->moving);
>   	if (!ttm_bo_uses_embedded_gem_object(bo))
>   		dma_resv_fini(&bo->base._resv);
> -	mutex_destroy(&bo->wu_mutex);
>   	bo->destroy(bo);
>   	ttm_mem_global_free(bdev->glob->mem_glob, acc_size);
>   }
> @@ -1319,7 +1318,6 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
>   	INIT_LIST_HEAD(&bo->ddestroy);
>   	INIT_LIST_HEAD(&bo->swap);
>   	INIT_LIST_HEAD(&bo->io_reserve_lru);
> -	mutex_init(&bo->wu_mutex);
>   	bo->bdev = bdev;
>   	bo->type = type;
>   	bo->num_pages = num_pages;
> @@ -1954,37 +1952,3 @@ void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
>   		;
>   }
>   EXPORT_SYMBOL(ttm_bo_swapout_all);
> -
> -/**
> - * ttm_bo_wait_unreserved - interruptible wait for a buffer object to become
> - * unreserved
> - *
> - * @bo: Pointer to buffer
> - */
> -int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo)
> -{
> -	int ret;
> -
> -	/*
> -	 * In the absense of a wait_unlocked API,
> -	 * Use the bo::wu_mutex to avoid triggering livelocks due to
> -	 * concurrent use of this function. Note that this use of
> -	 * bo::wu_mutex can go away if we change locking order to
> -	 * mmap_sem -> bo::reserve.
> -	 */
> -	ret = mutex_lock_interruptible(&bo->wu_mutex);
> -	if (unlikely(ret != 0))
> -		return -ERESTARTSYS;
> -	if (!dma_resv_is_locked(bo->base.resv))
> -		goto out_unlock;
> -	ret = dma_resv_lock_interruptible(bo->base.resv, NULL);
> -	if (ret == -EINTR)
> -		ret = -ERESTARTSYS;
> -	if (unlikely(ret != 0))
> -		goto out_unlock;
> -	dma_resv_unlock(bo->base.resv);
> -
> -out_unlock:
> -	mutex_unlock(&bo->wu_mutex);
> -	return ret;
> -}
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index fe81c565e7ef..82ea26a49959 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -508,7 +508,6 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
>   	INIT_LIST_HEAD(&fbo->base.lru);
>   	INIT_LIST_HEAD(&fbo->base.swap);
>   	INIT_LIST_HEAD(&fbo->base.io_reserve_lru);
> -	mutex_init(&fbo->base.wu_mutex);
>   	fbo->base.moving = NULL;
>   	drm_vma_node_reset(&fbo->base.base.vma_node);
>   	atomic_set(&fbo->base.cpu_writers, 0);
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> index 76eedb963693..a61a35e57d1c 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> @@ -125,30 +125,22 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
>   		&bdev->man[bo->mem.mem_type];
>   	struct vm_area_struct cvma;
>   
> -	/*
> -	 * Work around locking order reversal in fault / nopfn
> -	 * between mmap_sem and bo_reserve: Perform a trylock operation
> -	 * for reserve, and if it fails, retry the fault after waiting
> -	 * for the buffer to become unreserved.
> -	 */
>   	if (unlikely(!dma_resv_trylock(bo->base.resv))) {
>   		if (vmf->flags & FAULT_FLAG_ALLOW_RETRY) {
>   			if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {

Not an expert on fault handling, but shouldn't this now be one if?

E.g. if FAULT_FLAG_RETRY_NOWAIT is set we should return VM_FAULT_NOPAGE 
instead of VM_FAULT_RETRY.

But really take that with a grain of salt,
Christian.

>   				ttm_bo_get(bo);
>   				up_read(&vmf->vma->vm_mm->mmap_sem);
> -				(void) ttm_bo_wait_unreserved(bo);
> +				if (!dma_resv_lock_interruptible(bo->base.resv,
> +								 NULL))
> +					dma_resv_unlock(bo->base.resv);
>   				ttm_bo_put(bo);
>   			}
>   
>   			return VM_FAULT_RETRY;
>   		}
>   
> -		/*
> -		 * If we'd want to change locking order to
> -		 * mmap_sem -> bo::reserve, we'd use a blocking reserve here
> -		 * instead of retrying the fault...
> -		 */
> -		return VM_FAULT_NOPAGE;
> +		if (dma_resv_lock_interruptible(bo->base.resv, NULL))
> +			return VM_FAULT_NOPAGE;
>   	}
>   
>   	/*
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index 43c4929a2171..21c7d0d28757 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -155,7 +155,6 @@ struct ttm_tt;
>    * @offset: The current GPU offset, which can have different meanings
>    * depending on the memory type. For SYSTEM type memory, it should be 0.
>    * @cur_placement: Hint of current placement.
> - * @wu_mutex: Wait unreserved mutex.
>    *
>    * Base class for TTM buffer object, that deals with data placement and CPU
>    * mappings. GPU mappings are really up to the driver, but for simpler GPUs
> @@ -229,8 +228,6 @@ struct ttm_buffer_object {
>   	uint64_t offset; /* GPU address space is independent of CPU word size */
>   
>   	struct sg_table *sg;
> -
> -	struct mutex wu_mutex;
>   };
>   
>   /**
> @@ -765,7 +762,6 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
>   int ttm_bo_swapout(struct ttm_bo_global *glob,
>   			struct ttm_operation_ctx *ctx);
>   void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
> -int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);
>   
>   /**
>    * ttm_bo_uses_embedded_gem_object - check if the given bo uses the

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* ✗ Fi.CI.CHECKPATCH: warning for series starting with dma_resv: prime lockdep annotations (rev3)
  2019-08-21 21:50 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
                   ` (6 preceding siblings ...)
  2019-08-22  6:54 ` [PATCH] dma_resv: prime lockdep annotations Daniel Vetter
@ 2019-08-22  8:40 ` Patchwork
  2019-08-22  9:16 ` ✓ Fi.CI.BAT: success " Patchwork
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 40+ messages in thread
From: Patchwork @ 2019-08-22  8:40 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: intel-gfx

== Series Details ==

Series: series starting with dma_resv: prime lockdep annotations (rev3)
URL   : https://patchwork.freedesktop.org/series/65575/
State : warning

== Summary ==

$ dim checkpatch origin/drm-tip
e2a9273511d1 dma_resv: prime lockdep annotations
-:80: WARNING:BAD_SIGN_OFF: email address '"VMware Graphics" <linux-graphics-maintainer@vmware.com>' might be better as 'VMware Graphics <linux-graphics-maintainer@vmware.com>'
#80: 
Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>

-:120: ERROR:TRAILING_WHITESPACE: trailing whitespace
#120: FILE: drivers/dma-buf/dma-resv.c:116:
+^I$

-:128: WARNING:NO_AUTHOR_SIGN_OFF: Missing Signed-off-by: line by nominal patch author 'Daniel Vetter <daniel.vetter@ffwll.ch>'

total: 1 errors, 2 warnings, 0 checks, 36 lines checked
6a45501169ac drm/nouveau: slowpath for pushbuf ioctl
-:153: WARNING:NO_AUTHOR_SIGN_OFF: Missing Signed-off-by: line by nominal patch author 'Daniel Vetter <daniel.vetter@ffwll.ch>'

total: 0 errors, 1 warnings, 0 checks, 122 lines checked
dd4da03d3f1f drm/ttm: remove ttm_bo_wait_unreserved
-:24: WARNING:BAD_SIGN_OFF: email address '"VMware Graphics" <linux-graphics-maintainer@vmware.com>' might be better as 'VMware Graphics <linux-graphics-maintainer@vmware.com>'
#24: 
Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>

-:165: WARNING:NO_AUTHOR_SIGN_OFF: Missing Signed-off-by: line by nominal patch author 'Daniel Vetter <daniel.vetter@ffwll.ch>'

total: 0 errors, 2 warnings, 0 checks, 81 lines checked

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH] drm/ttm: remove ttm_bo_wait_unreserved
  2019-08-22  7:56   ` Koenig, Christian
@ 2019-08-22  8:47     ` Daniel Vetter
  2019-08-22  9:53       ` Thomas Hellström (VMware)
  2019-08-22 13:06     ` Daniel Vetter
  1 sibling, 1 reply; 40+ messages in thread
From: Daniel Vetter @ 2019-08-22  8:47 UTC (permalink / raw)
  To: Koenig, Christian
  Cc: Thomas Hellstrom, Intel Graphics Development, DRI Development,
	Huang, Ray, VMware Graphics, Gerd Hoffmann, Daniel Vetter

On Thu, Aug 22, 2019 at 9:56 AM Koenig, Christian
<Christian.Koenig@amd.com> wrote:
> Am 22.08.19 um 08:49 schrieb Daniel Vetter:
> > With nouveau fixed all ttm-using drives have the correct nesting of
> > mmap_sem vs dma_resv, and we can just lock the buffer.
> >
> > Assuming I didn't screw up anything with my audit of course.
> >
> > v2:
> > - Dont forget wu_mutex (Christian König)
> > - Keep the mmap_sem-less wait optimization (Thomas)
> > - Use _lock_interruptible to be good citizens (Thomas)
> >
> > Reviewed-by: Christian König <christian.koenig@amd.com>
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > Cc: Christian Koenig <christian.koenig@amd.com>
> > Cc: Huang Rui <ray.huang@amd.com>
> > Cc: Gerd Hoffmann <kraxel@redhat.com>
> > Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
> > Cc: Thomas Hellstrom <thellstrom@vmware.com>
> > ---
> >   drivers/gpu/drm/ttm/ttm_bo.c      | 36 -------------------------------
> >   drivers/gpu/drm/ttm/ttm_bo_util.c |  1 -
> >   drivers/gpu/drm/ttm/ttm_bo_vm.c   | 18 +++++-----------
> >   include/drm/ttm/ttm_bo_api.h      |  4 ----
> >   4 files changed, 5 insertions(+), 54 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> > index 20ff56f27aa4..d1ce5d315d5b 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> > @@ -162,7 +162,6 @@ static void ttm_bo_release_list(struct kref *list_kref)
> >       dma_fence_put(bo->moving);
> >       if (!ttm_bo_uses_embedded_gem_object(bo))
> >               dma_resv_fini(&bo->base._resv);
> > -     mutex_destroy(&bo->wu_mutex);
> >       bo->destroy(bo);
> >       ttm_mem_global_free(bdev->glob->mem_glob, acc_size);
> >   }
> > @@ -1319,7 +1318,6 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
> >       INIT_LIST_HEAD(&bo->ddestroy);
> >       INIT_LIST_HEAD(&bo->swap);
> >       INIT_LIST_HEAD(&bo->io_reserve_lru);
> > -     mutex_init(&bo->wu_mutex);
> >       bo->bdev = bdev;
> >       bo->type = type;
> >       bo->num_pages = num_pages;
> > @@ -1954,37 +1952,3 @@ void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
> >               ;
> >   }
> >   EXPORT_SYMBOL(ttm_bo_swapout_all);
> > -
> > -/**
> > - * ttm_bo_wait_unreserved - interruptible wait for a buffer object to become
> > - * unreserved
> > - *
> > - * @bo: Pointer to buffer
> > - */
> > -int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo)
> > -{
> > -     int ret;
> > -
> > -     /*
> > -      * In the absense of a wait_unlocked API,
> > -      * Use the bo::wu_mutex to avoid triggering livelocks due to
> > -      * concurrent use of this function. Note that this use of
> > -      * bo::wu_mutex can go away if we change locking order to
> > -      * mmap_sem -> bo::reserve.
> > -      */
> > -     ret = mutex_lock_interruptible(&bo->wu_mutex);
> > -     if (unlikely(ret != 0))
> > -             return -ERESTARTSYS;
> > -     if (!dma_resv_is_locked(bo->base.resv))
> > -             goto out_unlock;
> > -     ret = dma_resv_lock_interruptible(bo->base.resv, NULL);
> > -     if (ret == -EINTR)
> > -             ret = -ERESTARTSYS;
> > -     if (unlikely(ret != 0))
> > -             goto out_unlock;
> > -     dma_resv_unlock(bo->base.resv);
> > -
> > -out_unlock:
> > -     mutex_unlock(&bo->wu_mutex);
> > -     return ret;
> > -}
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> > index fe81c565e7ef..82ea26a49959 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> > @@ -508,7 +508,6 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
> >       INIT_LIST_HEAD(&fbo->base.lru);
> >       INIT_LIST_HEAD(&fbo->base.swap);
> >       INIT_LIST_HEAD(&fbo->base.io_reserve_lru);
> > -     mutex_init(&fbo->base.wu_mutex);
> >       fbo->base.moving = NULL;
> >       drm_vma_node_reset(&fbo->base.base.vma_node);
> >       atomic_set(&fbo->base.cpu_writers, 0);
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > index 76eedb963693..a61a35e57d1c 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > @@ -125,30 +125,22 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
> >               &bdev->man[bo->mem.mem_type];
> >       struct vm_area_struct cvma;
> >
> > -     /*
> > -      * Work around locking order reversal in fault / nopfn
> > -      * between mmap_sem and bo_reserve: Perform a trylock operation
> > -      * for reserve, and if it fails, retry the fault after waiting
> > -      * for the buffer to become unreserved.
> > -      */
> >       if (unlikely(!dma_resv_trylock(bo->base.resv))) {
> >               if (vmf->flags & FAULT_FLAG_ALLOW_RETRY) {
> >                       if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
>
> Not an expert on fault handling, but shouldn't this now be one if?
>
> E.g. if FAULT_FLAG_RETRY_NOWAIT is set we should return VM_FAULT_NOPAGE
> instead of VM_FAULT_RETRY.

Honestly I have no idea at all about this stuff. I just learned about
the mmap_sem less retry now that Thomas pointed it out, and I have no
idea how anything else here works. My approach has always been to just
throw ridiculous amounts of really nasty tests at fault handling
(including handling our own gtt mmaps to copy*user in relocs or gup
for userptr and all that), and leave it at that :-)

> But really take that with a grain of salt,

No idea either. It should be functionally equivalent to what was there
before, except we now have the full blocking wait for the mutex
instead of busy-spinning on NO_PAGE (with the wait_unreserved mixed in
every odd fault I guess?). All over my head I'd say ...

Cheers, Daniel

> Christian.
>
> >                               ttm_bo_get(bo);
> >                               up_read(&vmf->vma->vm_mm->mmap_sem);
> > -                             (void) ttm_bo_wait_unreserved(bo);
> > +                             if (!dma_resv_lock_interruptible(bo->base.resv,
> > +                                                              NULL))
> > +                                     dma_resv_unlock(bo->base.resv);
> >                               ttm_bo_put(bo);
> >                       }
> >
> >                       return VM_FAULT_RETRY;
> >               }
> >
> > -             /*
> > -              * If we'd want to change locking order to
> > -              * mmap_sem -> bo::reserve, we'd use a blocking reserve here
> > -              * instead of retrying the fault...
> > -              */
> > -             return VM_FAULT_NOPAGE;
> > +             if (dma_resv_lock_interruptible(bo->base.resv, NULL))
> > +                     return VM_FAULT_NOPAGE;
> >       }
> >
> >       /*
> > diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> > index 43c4929a2171..21c7d0d28757 100644
> > --- a/include/drm/ttm/ttm_bo_api.h
> > +++ b/include/drm/ttm/ttm_bo_api.h
> > @@ -155,7 +155,6 @@ struct ttm_tt;
> >    * @offset: The current GPU offset, which can have different meanings
> >    * depending on the memory type. For SYSTEM type memory, it should be 0.
> >    * @cur_placement: Hint of current placement.
> > - * @wu_mutex: Wait unreserved mutex.
> >    *
> >    * Base class for TTM buffer object, that deals with data placement and CPU
> >    * mappings. GPU mappings are really up to the driver, but for simpler GPUs
> > @@ -229,8 +228,6 @@ struct ttm_buffer_object {
> >       uint64_t offset; /* GPU address space is independent of CPU word size */
> >
> >       struct sg_table *sg;
> > -
> > -     struct mutex wu_mutex;
> >   };
> >
> >   /**
> > @@ -765,7 +762,6 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
> >   int ttm_bo_swapout(struct ttm_bo_global *glob,
> >                       struct ttm_operation_ctx *ctx);
> >   void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
> > -int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);
> >
> >   /**
> >    * ttm_bo_uses_embedded_gem_object - check if the given bo uses the
>


-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* ✓ Fi.CI.BAT: success for series starting with dma_resv: prime lockdep annotations (rev3)
  2019-08-21 21:50 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
                   ` (7 preceding siblings ...)
  2019-08-22  8:40 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with dma_resv: prime lockdep annotations (rev3) Patchwork
@ 2019-08-22  9:16 ` Patchwork
  2019-08-22 13:07 ` [PATCH] dma_resv: prime lockdep annotations Daniel Vetter
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 40+ messages in thread
From: Patchwork @ 2019-08-22  9:16 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: intel-gfx

== Series Details ==

Series: series starting with dma_resv: prime lockdep annotations (rev3)
URL   : https://patchwork.freedesktop.org/series/65575/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_6763 -> Patchwork_14136
====================================================

Summary
-------

  **SUCCESS**

  No regressions found.

  External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/

Known issues
------------

  Here are the changes found in Patchwork_14136 that come from known issues:

### IGT changes ###

#### Possible fixes ####

  * igt@gem_exec_suspend@basic-s3:
    - fi-blb-e6850:       [INCOMPLETE][1] ([fdo#107718]) -> [PASS][2]
   [1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/fi-blb-e6850/igt@gem_exec_suspend@basic-s3.html
   [2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/fi-blb-e6850/igt@gem_exec_suspend@basic-s3.html

  * igt@gem_mmap_gtt@basic-small-bo-tiledx:
    - fi-icl-u3:          [DMESG-WARN][3] ([fdo#107724]) -> [PASS][4]
   [3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/fi-icl-u3/igt@gem_mmap_gtt@basic-small-bo-tiledx.html
   [4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/fi-icl-u3/igt@gem_mmap_gtt@basic-small-bo-tiledx.html

  
#### Warnings ####

  * igt@i915_pm_rpm@basic-pci-d3-state:
    - fi-kbl-guc:         [SKIP][5] ([fdo#109271]) -> [FAIL][6] ([fdo#107707])
   [5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/fi-kbl-guc/igt@i915_pm_rpm@basic-pci-d3-state.html
   [6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/fi-kbl-guc/igt@i915_pm_rpm@basic-pci-d3-state.html

  * igt@kms_chamelium@hdmi-hpd-fast:
    - fi-kbl-7500u:       [FAIL][7] ([fdo#111096]) -> [FAIL][8] ([fdo#111407])
   [7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/fi-kbl-7500u/igt@kms_chamelium@hdmi-hpd-fast.html
   [8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/fi-kbl-7500u/igt@kms_chamelium@hdmi-hpd-fast.html

  
  {name}: This element is suppressed. This means it is ignored when computing
          the status of the difference (SUCCESS, WARNING, or FAILURE).

  [fdo#103167]: https://bugs.freedesktop.org/show_bug.cgi?id=103167
  [fdo#107707]: https://bugs.freedesktop.org/show_bug.cgi?id=107707
  [fdo#107718]: https://bugs.freedesktop.org/show_bug.cgi?id=107718
  [fdo#107724]: https://bugs.freedesktop.org/show_bug.cgi?id=107724
  [fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
  [fdo#111096]: https://bugs.freedesktop.org/show_bug.cgi?id=111096
  [fdo#111407]: https://bugs.freedesktop.org/show_bug.cgi?id=111407


Participating hosts (56 -> 45)
------------------------------

  Missing    (11): fi-kbl-soraka fi-ilk-m540 fi-bsw-n3050 fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-gdg-551 fi-pnv-d510 fi-icl-y fi-byt-clapper fi-bdw-samus 


Build changes
-------------

  * CI: CI-20190529 -> None
  * Linux: CI_DRM_6763 -> Patchwork_14136

  CI-20190529: 20190529
  CI_DRM_6763: a9a5855cece4d78bc2dfd4c719191a9ccabab4fb @ git://anongit.freedesktop.org/gfx-ci/linux
  IGT_5147: 289dcb935ee195352f987c0ae7dd31693bf7de0f @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
  Patchwork_14136: dd4da03d3f1fffd050c83bbd0458d4b566483e86 @ git://anongit.freedesktop.org/gfx-ci/linux


== Linux commits ==

dd4da03d3f1f drm/ttm: remove ttm_bo_wait_unreserved
6a45501169ac drm/nouveau: slowpath for pushbuf ioctl
e2a9273511d1 dma_resv: prime lockdep annotations

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH] drm/ttm: remove ttm_bo_wait_unreserved
  2019-08-22  8:47     ` Daniel Vetter
@ 2019-08-22  9:53       ` Thomas Hellström (VMware)
  0 siblings, 0 replies; 40+ messages in thread
From: Thomas Hellström (VMware) @ 2019-08-22  9:53 UTC (permalink / raw)
  To: Daniel Vetter, Koenig, Christian
  Cc: Thomas Hellstrom, Intel Graphics Development, DRI Development,
	Huang, Ray, VMware Graphics, Gerd Hoffmann, Daniel Vetter

On 8/22/19 10:47 AM, Daniel Vetter wrote:
> On Thu, Aug 22, 2019 at 9:56 AM Koenig, Christian
> <Christian.Koenig@amd.com> wrote:
>> Am 22.08.19 um 08:49 schrieb Daniel Vetter:
>>> With nouveau fixed all ttm-using drives have the correct nesting of
>>> mmap_sem vs dma_resv, and we can just lock the buffer.
>>>
>>> Assuming I didn't screw up anything with my audit of course.
>>>
>>> v2:
>>> - Dont forget wu_mutex (Christian König)
>>> - Keep the mmap_sem-less wait optimization (Thomas)
>>> - Use _lock_interruptible to be good citizens (Thomas)
>>>
>>> Reviewed-by: Christian König <christian.koenig@amd.com>
>>> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
>>> Cc: Christian Koenig <christian.koenig@amd.com>
>>> Cc: Huang Rui <ray.huang@amd.com>
>>> Cc: Gerd Hoffmann <kraxel@redhat.com>
>>> Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
>>> Cc: Thomas Hellstrom <thellstrom@vmware.com>
>>> ---
>>>    drivers/gpu/drm/ttm/ttm_bo.c      | 36 -------------------------------
>>>    drivers/gpu/drm/ttm/ttm_bo_util.c |  1 -
>>>    drivers/gpu/drm/ttm/ttm_bo_vm.c   | 18 +++++-----------
>>>    include/drm/ttm/ttm_bo_api.h      |  4 ----
>>>    4 files changed, 5 insertions(+), 54 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
>>> index 20ff56f27aa4..d1ce5d315d5b 100644
>>> --- a/drivers/gpu/drm/ttm/ttm_bo.c
>>> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
>>> @@ -162,7 +162,6 @@ static void ttm_bo_release_list(struct kref *list_kref)
>>>        dma_fence_put(bo->moving);
>>>        if (!ttm_bo_uses_embedded_gem_object(bo))
>>>                dma_resv_fini(&bo->base._resv);
>>> -     mutex_destroy(&bo->wu_mutex);
>>>        bo->destroy(bo);
>>>        ttm_mem_global_free(bdev->glob->mem_glob, acc_size);
>>>    }
>>> @@ -1319,7 +1318,6 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
>>>        INIT_LIST_HEAD(&bo->ddestroy);
>>>        INIT_LIST_HEAD(&bo->swap);
>>>        INIT_LIST_HEAD(&bo->io_reserve_lru);
>>> -     mutex_init(&bo->wu_mutex);
>>>        bo->bdev = bdev;
>>>        bo->type = type;
>>>        bo->num_pages = num_pages;
>>> @@ -1954,37 +1952,3 @@ void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
>>>                ;
>>>    }
>>>    EXPORT_SYMBOL(ttm_bo_swapout_all);
>>> -
>>> -/**
>>> - * ttm_bo_wait_unreserved - interruptible wait for a buffer object to become
>>> - * unreserved
>>> - *
>>> - * @bo: Pointer to buffer
>>> - */
>>> -int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo)
>>> -{
>>> -     int ret;
>>> -
>>> -     /*
>>> -      * In the absense of a wait_unlocked API,
>>> -      * Use the bo::wu_mutex to avoid triggering livelocks due to
>>> -      * concurrent use of this function. Note that this use of
>>> -      * bo::wu_mutex can go away if we change locking order to
>>> -      * mmap_sem -> bo::reserve.
>>> -      */
>>> -     ret = mutex_lock_interruptible(&bo->wu_mutex);
>>> -     if (unlikely(ret != 0))
>>> -             return -ERESTARTSYS;
>>> -     if (!dma_resv_is_locked(bo->base.resv))
>>> -             goto out_unlock;
>>> -     ret = dma_resv_lock_interruptible(bo->base.resv, NULL);
>>> -     if (ret == -EINTR)
>>> -             ret = -ERESTARTSYS;
>>> -     if (unlikely(ret != 0))
>>> -             goto out_unlock;
>>> -     dma_resv_unlock(bo->base.resv);
>>> -
>>> -out_unlock:
>>> -     mutex_unlock(&bo->wu_mutex);
>>> -     return ret;
>>> -}
>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
>>> index fe81c565e7ef..82ea26a49959 100644
>>> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
>>> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
>>> @@ -508,7 +508,6 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
>>>        INIT_LIST_HEAD(&fbo->base.lru);
>>>        INIT_LIST_HEAD(&fbo->base.swap);
>>>        INIT_LIST_HEAD(&fbo->base.io_reserve_lru);
>>> -     mutex_init(&fbo->base.wu_mutex);
>>>        fbo->base.moving = NULL;
>>>        drm_vma_node_reset(&fbo->base.base.vma_node);
>>>        atomic_set(&fbo->base.cpu_writers, 0);
>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>> index 76eedb963693..a61a35e57d1c 100644
>>> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>> @@ -125,30 +125,22 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
>>>                &bdev->man[bo->mem.mem_type];
>>>        struct vm_area_struct cvma;
>>>
>>> -     /*
>>> -      * Work around locking order reversal in fault / nopfn
>>> -      * between mmap_sem and bo_reserve: Perform a trylock operation
>>> -      * for reserve, and if it fails, retry the fault after waiting
>>> -      * for the buffer to become unreserved.
>>> -      */
>>>        if (unlikely(!dma_resv_trylock(bo->base.resv))) {
>>>                if (vmf->flags & FAULT_FLAG_ALLOW_RETRY) {
>>>                        if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
>> Not an expert on fault handling, but shouldn't this now be one if?
>>
>> E.g. if FAULT_FLAG_RETRY_NOWAIT is set we should return VM_FAULT_NOPAGE
>> instead of VM_FAULT_RETRY.
> Honestly I have no idea at all about this stuff. I just learned about
> the mmap_sem less retry now that Thomas pointed it out, and I have no
> idea how anything else here works. My approach has always been to just
> throw ridiculous amounts of really nasty tests at fault handling
> (including handling our own gtt mmaps to copy*user in relocs or gup
> for userptr and all that), and leave it at that :-)
>
>> But really take that with a grain of salt,
> No idea either. It should be functionally equivalent to what was there
> before, except we now have the full blocking wait for the mutex
> instead of busy-spinning on NO_PAGE (with the wait_unreserved mixed in
> every odd fault I guess?). All over my head I'd say ...

To be honest I don't remember the difference about VM_FAULT_RETRY with 
!FAULT_FLAG_RETRY_NOWAIT and just returning VM_FAULT_NOPAGE. It appears 
most users and TTM use the former, while shmem uses the latter.

The detailed FAULT_RETRY semantics are pretty undocumented and requires 
diving into the mm system to get the full picture.

BTW it looks to me like vgem and vmks has got VM_FAULT_RETRY wrong, 
since they might return it
without ALLOW_RETRY, and if FAULT_FLAG_RETRY_NOWAIT is true they, should 
drop the mmap_sem,
otherwise things will go really bad.

/Thomas


>
> Cheers, Daniel
>
>> Christian.
>>
>>>                                ttm_bo_get(bo);
>>>                                up_read(&vmf->vma->vm_mm->mmap_sem);
>>> -                             (void) ttm_bo_wait_unreserved(bo);
>>> +                             if (!dma_resv_lock_interruptible(bo->base.resv,
>>> +                                                              NULL))
>>> +                                     dma_resv_unlock(bo->base.resv);
>>>                                ttm_bo_put(bo);
>>>                        }
>>>
>>>                        return VM_FAULT_RETRY;
>>>                }
>>>
>>> -             /*
>>> -              * If we'd want to change locking order to
>>> -              * mmap_sem -> bo::reserve, we'd use a blocking reserve here
>>> -              * instead of retrying the fault...
>>> -              */
>>> -             return VM_FAULT_NOPAGE;
>>> +             if (dma_resv_lock_interruptible(bo->base.resv, NULL))
>>> +                     return VM_FAULT_NOPAGE;
>>>        }
>>>
>>>        /*
>>> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
>>> index 43c4929a2171..21c7d0d28757 100644
>>> --- a/include/drm/ttm/ttm_bo_api.h
>>> +++ b/include/drm/ttm/ttm_bo_api.h
>>> @@ -155,7 +155,6 @@ struct ttm_tt;
>>>     * @offset: The current GPU offset, which can have different meanings
>>>     * depending on the memory type. For SYSTEM type memory, it should be 0.
>>>     * @cur_placement: Hint of current placement.
>>> - * @wu_mutex: Wait unreserved mutex.
>>>     *
>>>     * Base class for TTM buffer object, that deals with data placement and CPU
>>>     * mappings. GPU mappings are really up to the driver, but for simpler GPUs
>>> @@ -229,8 +228,6 @@ struct ttm_buffer_object {
>>>        uint64_t offset; /* GPU address space is independent of CPU word size */
>>>
>>>        struct sg_table *sg;
>>> -
>>> -     struct mutex wu_mutex;
>>>    };
>>>
>>>    /**
>>> @@ -765,7 +762,6 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
>>>    int ttm_bo_swapout(struct ttm_bo_global *glob,
>>>                        struct ttm_operation_ctx *ctx);
>>>    void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
>>> -int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);
>>>
>>>    /**
>>>     * ttm_bo_uses_embedded_gem_object - check if the given bo uses the
>

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH] dma_resv: prime lockdep annotations
  2019-08-22  6:54 ` [PATCH] dma_resv: prime lockdep annotations Daniel Vetter
  2019-08-22  7:48   ` Chris Wilson
  2019-08-22  7:53   ` Koenig, Christian
@ 2019-08-22 12:56   ` Rob Herring
  2 siblings, 0 replies; 40+ messages in thread
From: Rob Herring @ 2019-08-22 12:56 UTC (permalink / raw)
  To: Daniel Vetter
  Cc: Thomas Hellstrom, Tomeu Vizoso, Intel Graphics Development,
	DRI Development, VMware Graphics, Gerd Hoffmann,
	Thomas Zimmermann, Daniel Vetter, Alex Deucher, Dave Airlie,
	Christian König, Ben Skeggs

On Thu, Aug 22, 2019 at 1:55 AM Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
>
> 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_mutex while doing copy_*_user. But
>   I haven't checked them all.
>
> - panfrost seems to dma_resv_lock only in panfrost_job_push, which
>   looks clean.
>
> - v3d holds dma_resv locks in the tail of its v3d_submit_cl_ioctl(),
>   copying from/to userspace happens all in v3d_lookup_bos which 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 in
>     vmw_execbuf_cmdbuf() and also in the vmw_execbuf_process() itself.
>     Then comes the usual ttm reserve/validate sequence, then actual
>     submission/fencing, then unreserving, and finally some more
>     copy_to_user in vmw_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 in vmwgfx_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 into
>   qxl_process_single_command. There's a lovely comment before the
>   __copy_from_user_inatomic that 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 other copy_from_user is for relocs, but those
>   are done before qxl_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 in
>   usif_ioctl() look safe. nouveau_gem_ioctl_pushbuf() otoh breaks this
>   everywhere and needs to be fixed up.
>
> v2: Thomas pointed at that vmwgfx calls dma_resv_init while it holds a
> dma_resv lock of a different object already. Christian mentioned that
> ttm core does this too for ghost objects. intel-gfx-ci highlighted
> that i915 has similar issues.
>
> Unfortunately we can't do this in the usual module init functions,
> because kernel threads don't have an ->mm - we have to wait around for
> some user thread to do this.
>
> Solution is to spawn a worker (but only once). It's horrible, but it
> works.
>
> v3: We can allocate mm! (Chris). Horrible worker hack out, clean
> initcall solution in.
>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: Christian König <christian.koenig@amd.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> Cc: Eric Anholt <eric@anholt.net>
> Cc: Dave Airlie <airlied@redhat.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
> Cc: Thomas Hellstrom <thellstrom@vmware.com>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> ---
>  drivers/dma-buf/dma-resv.c | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
>
> diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
> index 42a8f3f11681..d233ef4cf0d7 100644
> --- a/drivers/dma-buf/dma-resv.c
> +++ b/drivers/dma-buf/dma-resv.c
> @@ -34,6 +34,7 @@
>
>  #include <linux/dma-resv.h>
>  #include <linux/export.h>
> +#include <linux/sched/mm.h>
>
>  /**
>   * DOC: Reservation Object Overview
> @@ -95,6 +96,29 @@ static void dma_resv_list_free(struct dma_resv_list *list)
>         kfree_rcu(list, rcu);
>  }
>
> +#if IS_ENABLED(CONFIG_LOCKDEP)
> +static void dma_resv_lockdep(void)

__init

> +{
> +       struct mm_struct *mm = mm_alloc();
> +       struct dma_resv obj;
> +
> +       if (!mm)
> +               return;
> +
> +       dma_resv_init(&obj);
> +
> +       down_read(&mm->mmap_sem);
> +       ww_mutex_lock(&obj.lock, NULL);
> +       fs_reclaim_acquire(GFP_KERNEL);
> +       fs_reclaim_release(GFP_KERNEL);
> +       ww_mutex_unlock(&obj.lock);
> +       up_read(&mm->mmap_sem);
> +
> +       mmput(mm);
> +}
> +subsys_initcall(dma_resv_lockdep);
> +#endif
> +
>  /**
>   * dma_resv_init - initialize a reservation object
>   * @obj: the reservation object
> --
> 2.23.0.rc1
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH] drm/ttm: remove ttm_bo_wait_unreserved
  2019-08-22  7:56   ` Koenig, Christian
  2019-08-22  8:47     ` Daniel Vetter
@ 2019-08-22 13:06     ` Daniel Vetter
  2019-08-22 14:02       ` Koenig, Christian
  1 sibling, 1 reply; 40+ messages in thread
From: Daniel Vetter @ 2019-08-22 13:06 UTC (permalink / raw)
  To: Koenig, Christian
  Cc: Thomas Hellstrom, Daniel Vetter, Intel Graphics Development,
	DRI Development, Huang, Ray, VMware Graphics, Gerd Hoffmann,
	Daniel Vetter

On Thu, Aug 22, 2019 at 07:56:56AM +0000, Koenig, Christian wrote:
> Am 22.08.19 um 08:49 schrieb Daniel Vetter:
> > With nouveau fixed all ttm-using drives have the correct nesting of
> > mmap_sem vs dma_resv, and we can just lock the buffer.
> >
> > Assuming I didn't screw up anything with my audit of course.
> >
> > v2:
> > - Dont forget wu_mutex (Christian König)
> > - Keep the mmap_sem-less wait optimization (Thomas)
> > - Use _lock_interruptible to be good citizens (Thomas)
> >
> > Reviewed-by: Christian König <christian.koenig@amd.com>

btw I realized I didn't remove your r-b, since v1 was broken.

For formality, can you pls reaffirm, or still something broken?

Also from the other thread: Reviewed-by: Thomas Hellström <thellstrom@vmware.com>

Thanks, Daniel

> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > Cc: Christian Koenig <christian.koenig@amd.com>
> > Cc: Huang Rui <ray.huang@amd.com>
> > Cc: Gerd Hoffmann <kraxel@redhat.com>
> > Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
> > Cc: Thomas Hellstrom <thellstrom@vmware.com>
> > ---
> >   drivers/gpu/drm/ttm/ttm_bo.c      | 36 -------------------------------
> >   drivers/gpu/drm/ttm/ttm_bo_util.c |  1 -
> >   drivers/gpu/drm/ttm/ttm_bo_vm.c   | 18 +++++-----------
> >   include/drm/ttm/ttm_bo_api.h      |  4 ----
> >   4 files changed, 5 insertions(+), 54 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> > index 20ff56f27aa4..d1ce5d315d5b 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> > @@ -162,7 +162,6 @@ static void ttm_bo_release_list(struct kref *list_kref)
> >   	dma_fence_put(bo->moving);
> >   	if (!ttm_bo_uses_embedded_gem_object(bo))
> >   		dma_resv_fini(&bo->base._resv);
> > -	mutex_destroy(&bo->wu_mutex);
> >   	bo->destroy(bo);
> >   	ttm_mem_global_free(bdev->glob->mem_glob, acc_size);
> >   }
> > @@ -1319,7 +1318,6 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
> >   	INIT_LIST_HEAD(&bo->ddestroy);
> >   	INIT_LIST_HEAD(&bo->swap);
> >   	INIT_LIST_HEAD(&bo->io_reserve_lru);
> > -	mutex_init(&bo->wu_mutex);
> >   	bo->bdev = bdev;
> >   	bo->type = type;
> >   	bo->num_pages = num_pages;
> > @@ -1954,37 +1952,3 @@ void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
> >   		;
> >   }
> >   EXPORT_SYMBOL(ttm_bo_swapout_all);
> > -
> > -/**
> > - * ttm_bo_wait_unreserved - interruptible wait for a buffer object to become
> > - * unreserved
> > - *
> > - * @bo: Pointer to buffer
> > - */
> > -int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo)
> > -{
> > -	int ret;
> > -
> > -	/*
> > -	 * In the absense of a wait_unlocked API,
> > -	 * Use the bo::wu_mutex to avoid triggering livelocks due to
> > -	 * concurrent use of this function. Note that this use of
> > -	 * bo::wu_mutex can go away if we change locking order to
> > -	 * mmap_sem -> bo::reserve.
> > -	 */
> > -	ret = mutex_lock_interruptible(&bo->wu_mutex);
> > -	if (unlikely(ret != 0))
> > -		return -ERESTARTSYS;
> > -	if (!dma_resv_is_locked(bo->base.resv))
> > -		goto out_unlock;
> > -	ret = dma_resv_lock_interruptible(bo->base.resv, NULL);
> > -	if (ret == -EINTR)
> > -		ret = -ERESTARTSYS;
> > -	if (unlikely(ret != 0))
> > -		goto out_unlock;
> > -	dma_resv_unlock(bo->base.resv);
> > -
> > -out_unlock:
> > -	mutex_unlock(&bo->wu_mutex);
> > -	return ret;
> > -}
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> > index fe81c565e7ef..82ea26a49959 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> > @@ -508,7 +508,6 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
> >   	INIT_LIST_HEAD(&fbo->base.lru);
> >   	INIT_LIST_HEAD(&fbo->base.swap);
> >   	INIT_LIST_HEAD(&fbo->base.io_reserve_lru);
> > -	mutex_init(&fbo->base.wu_mutex);
> >   	fbo->base.moving = NULL;
> >   	drm_vma_node_reset(&fbo->base.base.vma_node);
> >   	atomic_set(&fbo->base.cpu_writers, 0);
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > index 76eedb963693..a61a35e57d1c 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > @@ -125,30 +125,22 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
> >   		&bdev->man[bo->mem.mem_type];
> >   	struct vm_area_struct cvma;
> >   
> > -	/*
> > -	 * Work around locking order reversal in fault / nopfn
> > -	 * between mmap_sem and bo_reserve: Perform a trylock operation
> > -	 * for reserve, and if it fails, retry the fault after waiting
> > -	 * for the buffer to become unreserved.
> > -	 */
> >   	if (unlikely(!dma_resv_trylock(bo->base.resv))) {
> >   		if (vmf->flags & FAULT_FLAG_ALLOW_RETRY) {
> >   			if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
> 
> Not an expert on fault handling, but shouldn't this now be one if?
> 
> E.g. if FAULT_FLAG_RETRY_NOWAIT is set we should return VM_FAULT_NOPAGE 
> instead of VM_FAULT_RETRY.
> 
> But really take that with a grain of salt,
> Christian.
> 
> >   				ttm_bo_get(bo);
> >   				up_read(&vmf->vma->vm_mm->mmap_sem);
> > -				(void) ttm_bo_wait_unreserved(bo);
> > +				if (!dma_resv_lock_interruptible(bo->base.resv,
> > +								 NULL))
> > +					dma_resv_unlock(bo->base.resv);
> >   				ttm_bo_put(bo);
> >   			}
> >   
> >   			return VM_FAULT_RETRY;
> >   		}
> >   
> > -		/*
> > -		 * If we'd want to change locking order to
> > -		 * mmap_sem -> bo::reserve, we'd use a blocking reserve here
> > -		 * instead of retrying the fault...
> > -		 */
> > -		return VM_FAULT_NOPAGE;
> > +		if (dma_resv_lock_interruptible(bo->base.resv, NULL))
> > +			return VM_FAULT_NOPAGE;
> >   	}
> >   
> >   	/*
> > diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> > index 43c4929a2171..21c7d0d28757 100644
> > --- a/include/drm/ttm/ttm_bo_api.h
> > +++ b/include/drm/ttm/ttm_bo_api.h
> > @@ -155,7 +155,6 @@ struct ttm_tt;
> >    * @offset: The current GPU offset, which can have different meanings
> >    * depending on the memory type. For SYSTEM type memory, it should be 0.
> >    * @cur_placement: Hint of current placement.
> > - * @wu_mutex: Wait unreserved mutex.
> >    *
> >    * Base class for TTM buffer object, that deals with data placement and CPU
> >    * mappings. GPU mappings are really up to the driver, but for simpler GPUs
> > @@ -229,8 +228,6 @@ struct ttm_buffer_object {
> >   	uint64_t offset; /* GPU address space is independent of CPU word size */
> >   
> >   	struct sg_table *sg;
> > -
> > -	struct mutex wu_mutex;
> >   };
> >   
> >   /**
> > @@ -765,7 +762,6 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
> >   int ttm_bo_swapout(struct ttm_bo_global *glob,
> >   			struct ttm_operation_ctx *ctx);
> >   void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
> > -int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);
> >   
> >   /**
> >    * ttm_bo_uses_embedded_gem_object - check if the given bo uses the
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [PATCH] dma_resv: prime lockdep annotations
  2019-08-21 21:50 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
                   ` (8 preceding siblings ...)
  2019-08-22  9:16 ` ✓ Fi.CI.BAT: success " Patchwork
@ 2019-08-22 13:07 ` Daniel Vetter
  2019-08-22 13:30   ` Thomas Hellström (VMware)
  2019-08-22 14:46 ` ✓ Fi.CI.IGT: success for series starting with [1/3] " Patchwork
  2019-08-23  1:43 ` ✓ Fi.CI.IGT: success for series starting with dma_resv: prime lockdep annotations (rev3) Patchwork
  11 siblings, 1 reply; 40+ messages in thread
From: Daniel Vetter @ 2019-08-22 13:07 UTC (permalink / raw)
  To: DRI Development
  Cc: Thomas Hellstrom, Tomeu Vizoso, Daniel Vetter, VMware Graphics,
	Gerd Hoffmann, Thomas Zimmermann, Daniel Vetter, Alex Deucher,
	Dave Airlie, Christian König, Ben Skeggs

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_mutex while doing copy_*_user. But
  I haven't checked them all.

- panfrost seems to dma_resv_lock only in panfrost_job_push, which
  looks clean.

- v3d holds dma_resv locks in the tail of its v3d_submit_cl_ioctl(),
  copying from/to userspace happens all in v3d_lookup_bos which 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 in
    vmw_execbuf_cmdbuf() and also in the vmw_execbuf_process() itself.
    Then comes the usual ttm reserve/validate sequence, then actual
    submission/fencing, then unreserving, and finally some more
    copy_to_user in vmw_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 in vmwgfx_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 into
  qxl_process_single_command. There's a lovely comment before the
  __copy_from_user_inatomic that 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 other copy_from_user is for relocs, but those
  are done before qxl_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 in
  usif_ioctl() look safe. nouveau_gem_ioctl_pushbuf() otoh breaks this
  everywhere and needs to be fixed up.

v2: Thomas pointed at that vmwgfx calls dma_resv_init while it holds a
dma_resv lock of a different object already. Christian mentioned that
ttm core does this too for ghost objects. intel-gfx-ci highlighted
that i915 has similar issues.

Unfortunately we can't do this in the usual module init functions,
because kernel threads don't have an ->mm - we have to wait around for
some user thread to do this.

Solution is to spawn a worker (but only once). It's horrible, but it
works.

v3: We can allocate mm! (Chris). Horrible worker hack out, clean
initcall solution in.

v4: Annotate with __init (Rob Herring)

Cc: Rob Herring <robh@kernel.org>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Cc: Eric Anholt <eric@anholt.net>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Tested-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 drivers/dma-buf/dma-resv.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
index 42a8f3f11681..97c4c4812d08 100644
--- a/drivers/dma-buf/dma-resv.c
+++ b/drivers/dma-buf/dma-resv.c
@@ -34,6 +34,7 @@
 
 #include <linux/dma-resv.h>
 #include <linux/export.h>
+#include <linux/sched/mm.h>
 
 /**
  * DOC: Reservation Object Overview
@@ -95,6 +96,29 @@ static void dma_resv_list_free(struct dma_resv_list *list)
 	kfree_rcu(list, rcu);
 }
 
+#if IS_ENABLED(CONFIG_LOCKDEP)
+static void __init dma_resv_lockdep(void)
+{
+	struct mm_struct *mm = mm_alloc();
+	struct dma_resv obj;
+
+	if (!mm)
+		return;
+
+	dma_resv_init(&obj);
+
+	down_read(&mm->mmap_sem);
+	ww_mutex_lock(&obj.lock, NULL);
+	fs_reclaim_acquire(GFP_KERNEL);
+	fs_reclaim_release(GFP_KERNEL);
+	ww_mutex_unlock(&obj.lock);
+	up_read(&mm->mmap_sem);
+	
+	mmput(mm);
+}
+subsys_initcall(dma_resv_lockdep);
+#endif
+
 /**
  * dma_resv_init - initialize a reservation object
  * @obj: the reservation object
-- 
2.23.0.rc1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH] dma_resv: prime lockdep annotations
  2019-08-22 13:07 ` [PATCH] dma_resv: prime lockdep annotations Daniel Vetter
@ 2019-08-22 13:30   ` Thomas Hellström (VMware)
  2019-08-22 13:36     ` Daniel Vetter
  0 siblings, 1 reply; 40+ messages in thread
From: Thomas Hellström (VMware) @ 2019-08-22 13:30 UTC (permalink / raw)
  To: Daniel Vetter, DRI Development
  Cc: Thomas Hellstrom, Tomeu Vizoso, VMware Graphics, Gerd Hoffmann,
	Thomas Zimmermann, Dave Airlie, Alex Deucher, Daniel Vetter,
	Christian König, Ben Skeggs

On 8/22/19 3:07 PM, Daniel Vetter wrote:
> 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_mutex while doing copy_*_user. But
>    I haven't checked them all.
>
> - panfrost seems to dma_resv_lock only in panfrost_job_push, which
>    looks clean.
>
> - v3d holds dma_resv locks in the tail of its v3d_submit_cl_ioctl(),
>    copying from/to userspace happens all in v3d_lookup_bos which 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 in
>      vmw_execbuf_cmdbuf() and also in the vmw_execbuf_process() itself.
>      Then comes the usual ttm reserve/validate sequence, then actual
>      submission/fencing, then unreserving, and finally some more
>      copy_to_user in vmw_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 in vmwgfx_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 into
>    qxl_process_single_command. There's a lovely comment before the
>    __copy_from_user_inatomic that 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 other copy_from_user is for relocs, but those
>    are done before qxl_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 in
>    usif_ioctl() look safe. nouveau_gem_ioctl_pushbuf() otoh breaks this
>    everywhere and needs to be fixed up.
>
> v2: Thomas pointed at that vmwgfx calls dma_resv_init while it holds a
> dma_resv lock of a different object already. Christian mentioned that
> ttm core does this too for ghost objects. intel-gfx-ci highlighted
> that i915 has similar issues.
>
> Unfortunately we can't do this in the usual module init functions,
> because kernel threads don't have an ->mm - we have to wait around for
> some user thread to do this.
>
> Solution is to spawn a worker (but only once). It's horrible, but it
> works.
>
> v3: We can allocate mm! (Chris). Horrible worker hack out, clean
> initcall solution in.
>
> v4: Annotate with __init (Rob Herring)
>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: Christian König <christian.koenig@amd.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> Cc: Eric Anholt <eric@anholt.net>
> Cc: Dave Airlie <airlied@redhat.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
> Cc: Thomas Hellstrom <thellstrom@vmware.com>
> Reviewed-by: Christian König <christian.koenig@amd.com>
> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
> Tested-by: Chris Wilson <chris@chris-wilson.co.uk>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> ---
>   drivers/dma-buf/dma-resv.c | 24 ++++++++++++++++++++++++
>   1 file changed, 24 insertions(+)
>
> diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
> index 42a8f3f11681..97c4c4812d08 100644
> --- a/drivers/dma-buf/dma-resv.c
> +++ b/drivers/dma-buf/dma-resv.c
> @@ -34,6 +34,7 @@
>   
>   #include <linux/dma-resv.h>
>   #include <linux/export.h>
> +#include <linux/sched/mm.h>
>   
>   /**
>    * DOC: Reservation Object Overview
> @@ -95,6 +96,29 @@ static void dma_resv_list_free(struct dma_resv_list *list)
>   	kfree_rcu(list, rcu);
>   }
>   
> +#if IS_ENABLED(CONFIG_LOCKDEP)
> +static void __init dma_resv_lockdep(void)
> +{
> +	struct mm_struct *mm = mm_alloc();
> +	struct dma_resv obj;
> +
> +	if (!mm)
> +		return;
> +
> +	dma_resv_init(&obj);
> +
> +	down_read(&mm->mmap_sem);


I took a quick look into using lockdep macros replacing the actual 
locks: Something along the lines of

lock_acquire(mm->mmap_sem.dep_map, 0, 0, 1, 1, NULL, _THIS_IP_);
> +	ww_mutex_lock(&obj.lock, NULL);
lock_acquire(obj.lock.dep_map, 0, 0, 0, 1, NULL, _THIS_IP_);
> +	fs_reclaim_acquire(GFP_KERNEL);
> +	fs_reclaim_release(GFP_KERNEL);
> +	ww_mutex_unlock(&obj.lock);

lock_release(obj.lock.dep_map, 0, _THIS_IP_);

> +	up_read(&mm->mmap_sem);

lock_release(obj.lock.dep_map, 0, _THIS_IP_);

Either way is fine with me, though.

Reviewed-by: Thomas Hellström <thellstrom@vmware.com>


> +	
> +	mmput(mm);
> +}
> +subsys_initcall(dma_resv_lockdep);
> +#endif
> +
>   /**
>    * dma_resv_init - initialize a reservation object
>    * @obj: the reservation object


_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH] dma_resv: prime lockdep annotations
  2019-08-22 13:30   ` Thomas Hellström (VMware)
@ 2019-08-22 13:36     ` Daniel Vetter
  2019-08-22 14:56       ` Thomas Hellström (VMware)
  0 siblings, 1 reply; 40+ messages in thread
From: Daniel Vetter @ 2019-08-22 13:36 UTC (permalink / raw)
  To: Thomas Hellström (VMware)
  Cc: Thomas Hellstrom, Tomeu Vizoso, DRI Development, VMware Graphics,
	Gerd Hoffmann, Thomas Zimmermann, Daniel Vetter, Alex Deucher,
	Dave Airlie, Christian König, Ben Skeggs

On Thu, Aug 22, 2019 at 3:30 PM Thomas Hellström (VMware)
<thomas_os@shipmail.org> wrote:
>
> On 8/22/19 3:07 PM, Daniel Vetter wrote:
> > 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_mutex while doing copy_*_user. But
> >    I haven't checked them all.
> >
> > - panfrost seems to dma_resv_lock only in panfrost_job_push, which
> >    looks clean.
> >
> > - v3d holds dma_resv locks in the tail of its v3d_submit_cl_ioctl(),
> >    copying from/to userspace happens all in v3d_lookup_bos which 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 in
> >      vmw_execbuf_cmdbuf() and also in the vmw_execbuf_process() itself.
> >      Then comes the usual ttm reserve/validate sequence, then actual
> >      submission/fencing, then unreserving, and finally some more
> >      copy_to_user in vmw_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 in vmwgfx_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 into
> >    qxl_process_single_command. There's a lovely comment before the
> >    __copy_from_user_inatomic that 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 other copy_from_user is for relocs, but those
> >    are done before qxl_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 in
> >    usif_ioctl() look safe. nouveau_gem_ioctl_pushbuf() otoh breaks this
> >    everywhere and needs to be fixed up.
> >
> > v2: Thomas pointed at that vmwgfx calls dma_resv_init while it holds a
> > dma_resv lock of a different object already. Christian mentioned that
> > ttm core does this too for ghost objects. intel-gfx-ci highlighted
> > that i915 has similar issues.
> >
> > Unfortunately we can't do this in the usual module init functions,
> > because kernel threads don't have an ->mm - we have to wait around for
> > some user thread to do this.
> >
> > Solution is to spawn a worker (but only once). It's horrible, but it
> > works.
> >
> > v3: We can allocate mm! (Chris). Horrible worker hack out, clean
> > initcall solution in.
> >
> > v4: Annotate with __init (Rob Herring)
> >
> > Cc: Rob Herring <robh@kernel.org>
> > Cc: Alex Deucher <alexander.deucher@amd.com>
> > Cc: Christian König <christian.koenig@amd.com>
> > Cc: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: Thomas Zimmermann <tzimmermann@suse.de>
> > Cc: Rob Herring <robh@kernel.org>
> > Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> > Cc: Eric Anholt <eric@anholt.net>
> > Cc: Dave Airlie <airlied@redhat.com>
> > Cc: Gerd Hoffmann <kraxel@redhat.com>
> > Cc: Ben Skeggs <bskeggs@redhat.com>
> > Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
> > Cc: Thomas Hellstrom <thellstrom@vmware.com>
> > Reviewed-by: Christian König <christian.koenig@amd.com>
> > Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
> > Tested-by: Chris Wilson <chris@chris-wilson.co.uk>
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > ---
> >   drivers/dma-buf/dma-resv.c | 24 ++++++++++++++++++++++++
> >   1 file changed, 24 insertions(+)
> >
> > diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
> > index 42a8f3f11681..97c4c4812d08 100644
> > --- a/drivers/dma-buf/dma-resv.c
> > +++ b/drivers/dma-buf/dma-resv.c
> > @@ -34,6 +34,7 @@
> >
> >   #include <linux/dma-resv.h>
> >   #include <linux/export.h>
> > +#include <linux/sched/mm.h>
> >
> >   /**
> >    * DOC: Reservation Object Overview
> > @@ -95,6 +96,29 @@ static void dma_resv_list_free(struct dma_resv_list *list)
> >       kfree_rcu(list, rcu);
> >   }
> >
> > +#if IS_ENABLED(CONFIG_LOCKDEP)
> > +static void __init dma_resv_lockdep(void)
> > +{
> > +     struct mm_struct *mm = mm_alloc();
> > +     struct dma_resv obj;
> > +
> > +     if (!mm)
> > +             return;
> > +
> > +     dma_resv_init(&obj);
> > +
> > +     down_read(&mm->mmap_sem);
>
>
> I took a quick look into using lockdep macros replacing the actual
> locks: Something along the lines of
>
> lock_acquire(mm->mmap_sem.dep_map, 0, 0, 1, 1, NULL, _THIS_IP_);

Yeah I'm not a fan of the magic numbers this nees :-/ And now this is
run once at startup, so the taking the fake locks for real, once,
shouldn't hurt. Lockdep updating it's data structures is going to be
100x more cpu cycles anyway :-)

> > +     ww_mutex_lock(&obj.lock, NULL);
> lock_acquire(obj.lock.dep_map, 0, 0, 0, 1, NULL, _THIS_IP_);
> > +     fs_reclaim_acquire(GFP_KERNEL);
> > +     fs_reclaim_release(GFP_KERNEL);
> > +     ww_mutex_unlock(&obj.lock);
>
> lock_release(obj.lock.dep_map, 0, _THIS_IP_);
>
> > +     up_read(&mm->mmap_sem);
>
> lock_release(obj.lock.dep_map, 0, _THIS_IP_);
>
> Either way is fine with me, though.
>
> Reviewed-by: Thomas Hellström <thellstrom@vmware.com>

Thanks for your review comments.

Can you pls also run this in some test cycles, if that's easily
possible? I'd like to have a tested-by from at least the big drivers -
i915, amd, nouveau, vmwgfx and is definitely using ttm to its fullest
too, so best chances for hitting an oversight.

Cheers, Daniel

>
>
> > +
> > +     mmput(mm);
> > +}
> > +subsys_initcall(dma_resv_lockdep);
> > +#endif
> > +
> >   /**
> >    * dma_resv_init - initialize a reservation object
> >    * @obj: the reservation object
>
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel



-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH] drm/ttm: remove ttm_bo_wait_unreserved
  2019-08-22 13:06     ` Daniel Vetter
@ 2019-08-22 14:02       ` Koenig, Christian
  2019-08-22 14:24         ` Thomas Hellström (VMware)
  0 siblings, 1 reply; 40+ messages in thread
From: Koenig, Christian @ 2019-08-22 14:02 UTC (permalink / raw)
  To: Daniel Vetter
  Cc: Thomas Hellstrom, Daniel Vetter, Intel Graphics Development,
	DRI Development, Huang, Ray, VMware Graphics, Gerd Hoffmann,
	Daniel Vetter

Am 22.08.19 um 15:06 schrieb Daniel Vetter:
> On Thu, Aug 22, 2019 at 07:56:56AM +0000, Koenig, Christian wrote:
>> Am 22.08.19 um 08:49 schrieb Daniel Vetter:
>>> With nouveau fixed all ttm-using drives have the correct nesting of
>>> mmap_sem vs dma_resv, and we can just lock the buffer.
>>>
>>> Assuming I didn't screw up anything with my audit of course.
>>>
>>> v2:
>>> - Dont forget wu_mutex (Christian König)
>>> - Keep the mmap_sem-less wait optimization (Thomas)
>>> - Use _lock_interruptible to be good citizens (Thomas)
>>>
>>> Reviewed-by: Christian König <christian.koenig@amd.com>
> btw I realized I didn't remove your r-b, since v1 was broken.
>
> For formality, can you pls reaffirm, or still something broken?

My r-b is still valid.

Only problem I see is that neither of us seems to have a good idea about 
the different VM_FAULT_* replies.

But that worked before so it should still work now,
Christian.

>
> Also from the other thread: Reviewed-by: Thomas Hellström <thellstrom@vmware.com>
>
> Thanks, Daniel
>
>>> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
>>> Cc: Christian Koenig <christian.koenig@amd.com>
>>> Cc: Huang Rui <ray.huang@amd.com>
>>> Cc: Gerd Hoffmann <kraxel@redhat.com>
>>> Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
>>> Cc: Thomas Hellstrom <thellstrom@vmware.com>
>>> ---
>>>    drivers/gpu/drm/ttm/ttm_bo.c      | 36 -------------------------------
>>>    drivers/gpu/drm/ttm/ttm_bo_util.c |  1 -
>>>    drivers/gpu/drm/ttm/ttm_bo_vm.c   | 18 +++++-----------
>>>    include/drm/ttm/ttm_bo_api.h      |  4 ----
>>>    4 files changed, 5 insertions(+), 54 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
>>> index 20ff56f27aa4..d1ce5d315d5b 100644
>>> --- a/drivers/gpu/drm/ttm/ttm_bo.c
>>> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
>>> @@ -162,7 +162,6 @@ static void ttm_bo_release_list(struct kref *list_kref)
>>>    	dma_fence_put(bo->moving);
>>>    	if (!ttm_bo_uses_embedded_gem_object(bo))
>>>    		dma_resv_fini(&bo->base._resv);
>>> -	mutex_destroy(&bo->wu_mutex);
>>>    	bo->destroy(bo);
>>>    	ttm_mem_global_free(bdev->glob->mem_glob, acc_size);
>>>    }
>>> @@ -1319,7 +1318,6 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
>>>    	INIT_LIST_HEAD(&bo->ddestroy);
>>>    	INIT_LIST_HEAD(&bo->swap);
>>>    	INIT_LIST_HEAD(&bo->io_reserve_lru);
>>> -	mutex_init(&bo->wu_mutex);
>>>    	bo->bdev = bdev;
>>>    	bo->type = type;
>>>    	bo->num_pages = num_pages;
>>> @@ -1954,37 +1952,3 @@ void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
>>>    		;
>>>    }
>>>    EXPORT_SYMBOL(ttm_bo_swapout_all);
>>> -
>>> -/**
>>> - * ttm_bo_wait_unreserved - interruptible wait for a buffer object to become
>>> - * unreserved
>>> - *
>>> - * @bo: Pointer to buffer
>>> - */
>>> -int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo)
>>> -{
>>> -	int ret;
>>> -
>>> -	/*
>>> -	 * In the absense of a wait_unlocked API,
>>> -	 * Use the bo::wu_mutex to avoid triggering livelocks due to
>>> -	 * concurrent use of this function. Note that this use of
>>> -	 * bo::wu_mutex can go away if we change locking order to
>>> -	 * mmap_sem -> bo::reserve.
>>> -	 */
>>> -	ret = mutex_lock_interruptible(&bo->wu_mutex);
>>> -	if (unlikely(ret != 0))
>>> -		return -ERESTARTSYS;
>>> -	if (!dma_resv_is_locked(bo->base.resv))
>>> -		goto out_unlock;
>>> -	ret = dma_resv_lock_interruptible(bo->base.resv, NULL);
>>> -	if (ret == -EINTR)
>>> -		ret = -ERESTARTSYS;
>>> -	if (unlikely(ret != 0))
>>> -		goto out_unlock;
>>> -	dma_resv_unlock(bo->base.resv);
>>> -
>>> -out_unlock:
>>> -	mutex_unlock(&bo->wu_mutex);
>>> -	return ret;
>>> -}
>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
>>> index fe81c565e7ef..82ea26a49959 100644
>>> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
>>> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
>>> @@ -508,7 +508,6 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
>>>    	INIT_LIST_HEAD(&fbo->base.lru);
>>>    	INIT_LIST_HEAD(&fbo->base.swap);
>>>    	INIT_LIST_HEAD(&fbo->base.io_reserve_lru);
>>> -	mutex_init(&fbo->base.wu_mutex);
>>>    	fbo->base.moving = NULL;
>>>    	drm_vma_node_reset(&fbo->base.base.vma_node);
>>>    	atomic_set(&fbo->base.cpu_writers, 0);
>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>> index 76eedb963693..a61a35e57d1c 100644
>>> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>> @@ -125,30 +125,22 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
>>>    		&bdev->man[bo->mem.mem_type];
>>>    	struct vm_area_struct cvma;
>>>    
>>> -	/*
>>> -	 * Work around locking order reversal in fault / nopfn
>>> -	 * between mmap_sem and bo_reserve: Perform a trylock operation
>>> -	 * for reserve, and if it fails, retry the fault after waiting
>>> -	 * for the buffer to become unreserved.
>>> -	 */
>>>    	if (unlikely(!dma_resv_trylock(bo->base.resv))) {
>>>    		if (vmf->flags & FAULT_FLAG_ALLOW_RETRY) {
>>>    			if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
>> Not an expert on fault handling, but shouldn't this now be one if?
>>
>> E.g. if FAULT_FLAG_RETRY_NOWAIT is set we should return VM_FAULT_NOPAGE
>> instead of VM_FAULT_RETRY.
>>
>> But really take that with a grain of salt,
>> Christian.
>>
>>>    				ttm_bo_get(bo);
>>>    				up_read(&vmf->vma->vm_mm->mmap_sem);
>>> -				(void) ttm_bo_wait_unreserved(bo);
>>> +				if (!dma_resv_lock_interruptible(bo->base.resv,
>>> +								 NULL))
>>> +					dma_resv_unlock(bo->base.resv);
>>>    				ttm_bo_put(bo);
>>>    			}
>>>    
>>>    			return VM_FAULT_RETRY;
>>>    		}
>>>    
>>> -		/*
>>> -		 * If we'd want to change locking order to
>>> -		 * mmap_sem -> bo::reserve, we'd use a blocking reserve here
>>> -		 * instead of retrying the fault...
>>> -		 */
>>> -		return VM_FAULT_NOPAGE;
>>> +		if (dma_resv_lock_interruptible(bo->base.resv, NULL))
>>> +			return VM_FAULT_NOPAGE;
>>>    	}
>>>    
>>>    	/*
>>> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
>>> index 43c4929a2171..21c7d0d28757 100644
>>> --- a/include/drm/ttm/ttm_bo_api.h
>>> +++ b/include/drm/ttm/ttm_bo_api.h
>>> @@ -155,7 +155,6 @@ struct ttm_tt;
>>>     * @offset: The current GPU offset, which can have different meanings
>>>     * depending on the memory type. For SYSTEM type memory, it should be 0.
>>>     * @cur_placement: Hint of current placement.
>>> - * @wu_mutex: Wait unreserved mutex.
>>>     *
>>>     * Base class for TTM buffer object, that deals with data placement and CPU
>>>     * mappings. GPU mappings are really up to the driver, but for simpler GPUs
>>> @@ -229,8 +228,6 @@ struct ttm_buffer_object {
>>>    	uint64_t offset; /* GPU address space is independent of CPU word size */
>>>    
>>>    	struct sg_table *sg;
>>> -
>>> -	struct mutex wu_mutex;
>>>    };
>>>    
>>>    /**
>>> @@ -765,7 +762,6 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
>>>    int ttm_bo_swapout(struct ttm_bo_global *glob,
>>>    			struct ttm_operation_ctx *ctx);
>>>    void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
>>> -int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);
>>>    
>>>    /**
>>>     * ttm_bo_uses_embedded_gem_object - check if the given bo uses the

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH] drm/ttm: remove ttm_bo_wait_unreserved
  2019-08-22 14:02       ` Koenig, Christian
@ 2019-08-22 14:24         ` Thomas Hellström (VMware)
  2019-08-22 14:30           ` Thomas Hellström (VMware)
  0 siblings, 1 reply; 40+ messages in thread
From: Thomas Hellström (VMware) @ 2019-08-22 14:24 UTC (permalink / raw)
  To: Koenig, Christian, Daniel Vetter
  Cc: Thomas Hellstrom, Daniel Vetter, Intel Graphics Development,
	DRI Development, Huang, Ray, VMware Graphics, Gerd Hoffmann,
	Daniel Vetter

On 8/22/19 4:02 PM, Koenig, Christian wrote:
> Am 22.08.19 um 15:06 schrieb Daniel Vetter:
>> On Thu, Aug 22, 2019 at 07:56:56AM +0000, Koenig, Christian wrote:
>>> Am 22.08.19 um 08:49 schrieb Daniel Vetter:
>>>> With nouveau fixed all ttm-using drives have the correct nesting of
>>>> mmap_sem vs dma_resv, and we can just lock the buffer.
>>>>
>>>> Assuming I didn't screw up anything with my audit of course.
>>>>
>>>> v2:
>>>> - Dont forget wu_mutex (Christian König)
>>>> - Keep the mmap_sem-less wait optimization (Thomas)
>>>> - Use _lock_interruptible to be good citizens (Thomas)
>>>>
>>>> Reviewed-by: Christian König <christian.koenig@amd.com>
>> btw I realized I didn't remove your r-b, since v1 was broken.
>>
>> For formality, can you pls reaffirm, or still something broken?
> My r-b is still valid.
>
> Only problem I see is that neither of us seems to have a good idea about
> the different VM_FAULT_* replies.

I took a look in mm/gup.c. It seems like when using get_user_pages, 
VM_FAULT_RETRY will retry to a requesting caller telling it that a long 
wait was expected and not performed, whereas VM_FAULT_NOPAGE will just 
keep get_user_pages to spin. So the proposed patch should be correct 
from my understanding.

If the fault originates from user-space, I guess either is fine.

/Thomas


>
> But that worked before so it should still work now,
> Christian.
>
>> Also from the other thread: Reviewed-by: Thomas Hellström <thellstrom@vmware.com>
>>
>> Thanks, Daniel
>>
>>>> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
>>>> Cc: Christian Koenig <christian.koenig@amd.com>
>>>> Cc: Huang Rui <ray.huang@amd.com>
>>>> Cc: Gerd Hoffmann <kraxel@redhat.com>
>>>> Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
>>>> Cc: Thomas Hellstrom <thellstrom@vmware.com>
>>>> ---
>>>>     drivers/gpu/drm/ttm/ttm_bo.c      | 36 -------------------------------
>>>>     drivers/gpu/drm/ttm/ttm_bo_util.c |  1 -
>>>>     drivers/gpu/drm/ttm/ttm_bo_vm.c   | 18 +++++-----------
>>>>     include/drm/ttm/ttm_bo_api.h      |  4 ----
>>>>     4 files changed, 5 insertions(+), 54 deletions(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
>>>> index 20ff56f27aa4..d1ce5d315d5b 100644
>>>> --- a/drivers/gpu/drm/ttm/ttm_bo.c
>>>> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
>>>> @@ -162,7 +162,6 @@ static void ttm_bo_release_list(struct kref *list_kref)
>>>>     	dma_fence_put(bo->moving);
>>>>     	if (!ttm_bo_uses_embedded_gem_object(bo))
>>>>     		dma_resv_fini(&bo->base._resv);
>>>> -	mutex_destroy(&bo->wu_mutex);
>>>>     	bo->destroy(bo);
>>>>     	ttm_mem_global_free(bdev->glob->mem_glob, acc_size);
>>>>     }
>>>> @@ -1319,7 +1318,6 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
>>>>     	INIT_LIST_HEAD(&bo->ddestroy);
>>>>     	INIT_LIST_HEAD(&bo->swap);
>>>>     	INIT_LIST_HEAD(&bo->io_reserve_lru);
>>>> -	mutex_init(&bo->wu_mutex);
>>>>     	bo->bdev = bdev;
>>>>     	bo->type = type;
>>>>     	bo->num_pages = num_pages;
>>>> @@ -1954,37 +1952,3 @@ void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
>>>>     		;
>>>>     }
>>>>     EXPORT_SYMBOL(ttm_bo_swapout_all);
>>>> -
>>>> -/**
>>>> - * ttm_bo_wait_unreserved - interruptible wait for a buffer object to become
>>>> - * unreserved
>>>> - *
>>>> - * @bo: Pointer to buffer
>>>> - */
>>>> -int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo)
>>>> -{
>>>> -	int ret;
>>>> -
>>>> -	/*
>>>> -	 * In the absense of a wait_unlocked API,
>>>> -	 * Use the bo::wu_mutex to avoid triggering livelocks due to
>>>> -	 * concurrent use of this function. Note that this use of
>>>> -	 * bo::wu_mutex can go away if we change locking order to
>>>> -	 * mmap_sem -> bo::reserve.
>>>> -	 */
>>>> -	ret = mutex_lock_interruptible(&bo->wu_mutex);
>>>> -	if (unlikely(ret != 0))
>>>> -		return -ERESTARTSYS;
>>>> -	if (!dma_resv_is_locked(bo->base.resv))
>>>> -		goto out_unlock;
>>>> -	ret = dma_resv_lock_interruptible(bo->base.resv, NULL);
>>>> -	if (ret == -EINTR)
>>>> -		ret = -ERESTARTSYS;
>>>> -	if (unlikely(ret != 0))
>>>> -		goto out_unlock;
>>>> -	dma_resv_unlock(bo->base.resv);
>>>> -
>>>> -out_unlock:
>>>> -	mutex_unlock(&bo->wu_mutex);
>>>> -	return ret;
>>>> -}
>>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
>>>> index fe81c565e7ef..82ea26a49959 100644
>>>> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
>>>> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
>>>> @@ -508,7 +508,6 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
>>>>     	INIT_LIST_HEAD(&fbo->base.lru);
>>>>     	INIT_LIST_HEAD(&fbo->base.swap);
>>>>     	INIT_LIST_HEAD(&fbo->base.io_reserve_lru);
>>>> -	mutex_init(&fbo->base.wu_mutex);
>>>>     	fbo->base.moving = NULL;
>>>>     	drm_vma_node_reset(&fbo->base.base.vma_node);
>>>>     	atomic_set(&fbo->base.cpu_writers, 0);
>>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>>> index 76eedb963693..a61a35e57d1c 100644
>>>> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>>> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>>> @@ -125,30 +125,22 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
>>>>     		&bdev->man[bo->mem.mem_type];
>>>>     	struct vm_area_struct cvma;
>>>>     
>>>> -	/*
>>>> -	 * Work around locking order reversal in fault / nopfn
>>>> -	 * between mmap_sem and bo_reserve: Perform a trylock operation
>>>> -	 * for reserve, and if it fails, retry the fault after waiting
>>>> -	 * for the buffer to become unreserved.
>>>> -	 */
>>>>     	if (unlikely(!dma_resv_trylock(bo->base.resv))) {
>>>>     		if (vmf->flags & FAULT_FLAG_ALLOW_RETRY) {
>>>>     			if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
>>> Not an expert on fault handling, but shouldn't this now be one if?
>>>
>>> E.g. if FAULT_FLAG_RETRY_NOWAIT is set we should return VM_FAULT_NOPAGE
>>> instead of VM_FAULT_RETRY.
>>>
>>> But really take that with a grain of salt,
>>> Christian.
>>>
>>>>     				ttm_bo_get(bo);
>>>>     				up_read(&vmf->vma->vm_mm->mmap_sem);
>>>> -				(void) ttm_bo_wait_unreserved(bo);
>>>> +				if (!dma_resv_lock_interruptible(bo->base.resv,
>>>> +								 NULL))
>>>> +					dma_resv_unlock(bo->base.resv);
>>>>     				ttm_bo_put(bo);
>>>>     			}
>>>>     
>>>>     			return VM_FAULT_RETRY;
>>>>     		}
>>>>     
>>>> -		/*
>>>> -		 * If we'd want to change locking order to
>>>> -		 * mmap_sem -> bo::reserve, we'd use a blocking reserve here
>>>> -		 * instead of retrying the fault...
>>>> -		 */
>>>> -		return VM_FAULT_NOPAGE;
>>>> +		if (dma_resv_lock_interruptible(bo->base.resv, NULL))
>>>> +			return VM_FAULT_NOPAGE;
>>>>     	}
>>>>     
>>>>     	/*
>>>> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
>>>> index 43c4929a2171..21c7d0d28757 100644
>>>> --- a/include/drm/ttm/ttm_bo_api.h
>>>> +++ b/include/drm/ttm/ttm_bo_api.h
>>>> @@ -155,7 +155,6 @@ struct ttm_tt;
>>>>      * @offset: The current GPU offset, which can have different meanings
>>>>      * depending on the memory type. For SYSTEM type memory, it should be 0.
>>>>      * @cur_placement: Hint of current placement.
>>>> - * @wu_mutex: Wait unreserved mutex.
>>>>      *
>>>>      * Base class for TTM buffer object, that deals with data placement and CPU
>>>>      * mappings. GPU mappings are really up to the driver, but for simpler GPUs
>>>> @@ -229,8 +228,6 @@ struct ttm_buffer_object {
>>>>     	uint64_t offset; /* GPU address space is independent of CPU word size */
>>>>     
>>>>     	struct sg_table *sg;
>>>> -
>>>> -	struct mutex wu_mutex;
>>>>     };
>>>>     
>>>>     /**
>>>> @@ -765,7 +762,6 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
>>>>     int ttm_bo_swapout(struct ttm_bo_global *glob,
>>>>     			struct ttm_operation_ctx *ctx);
>>>>     void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
>>>> -int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);
>>>>     
>>>>     /**
>>>>      * ttm_bo_uses_embedded_gem_object - check if the given bo uses the
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH] drm/ttm: remove ttm_bo_wait_unreserved
  2019-08-22 14:24         ` Thomas Hellström (VMware)
@ 2019-08-22 14:30           ` Thomas Hellström (VMware)
  0 siblings, 0 replies; 40+ messages in thread
From: Thomas Hellström (VMware) @ 2019-08-22 14:30 UTC (permalink / raw)
  To: Koenig, Christian, Daniel Vetter
  Cc: Thomas Hellstrom, Daniel Vetter, Intel Graphics Development,
	DRI Development, Huang, Ray, VMware Graphics, Gerd Hoffmann,
	Daniel Vetter

On 8/22/19 4:24 PM, Thomas Hellström (VMware) wrote:
> On 8/22/19 4:02 PM, Koenig, Christian wrote:
>> Am 22.08.19 um 15:06 schrieb Daniel Vetter:
>>> On Thu, Aug 22, 2019 at 07:56:56AM +0000, Koenig, Christian wrote:
>>>> Am 22.08.19 um 08:49 schrieb Daniel Vetter:
>>>>> With nouveau fixed all ttm-using drives have the correct nesting of
>>>>> mmap_sem vs dma_resv, and we can just lock the buffer.
>>>>>
>>>>> Assuming I didn't screw up anything with my audit of course.
>>>>>
>>>>> v2:
>>>>> - Dont forget wu_mutex (Christian König)
>>>>> - Keep the mmap_sem-less wait optimization (Thomas)
>>>>> - Use _lock_interruptible to be good citizens (Thomas)
>>>>>
>>>>> Reviewed-by: Christian König <christian.koenig@amd.com>
>>> btw I realized I didn't remove your r-b, since v1 was broken.
>>>
>>> For formality, can you pls reaffirm, or still something broken?
>> My r-b is still valid.
>>
>> Only problem I see is that neither of us seems to have a good idea about
>> the different VM_FAULT_* replies.
>
> I took a look in mm/gup.c. It seems like when using get_user_pages, 
> VM_FAULT_RETRY will retry 

s/retry/return/


> to a requesting caller telling it that a long wait was expected and 
> not performed, whereas VM_FAULT_NOPAGE will just keep get_user_pages 
> to spin. So the proposed patch should be correct from my understanding.
>
> If the fault originates from user-space, I guess either is fine.
>
> /Thomas

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* ✓ Fi.CI.IGT: success for series starting with [1/3] dma_resv: prime lockdep annotations
  2019-08-21 21:50 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
                   ` (9 preceding siblings ...)
  2019-08-22 13:07 ` [PATCH] dma_resv: prime lockdep annotations Daniel Vetter
@ 2019-08-22 14:46 ` Patchwork
  2019-08-23  1:43 ` ✓ Fi.CI.IGT: success for series starting with dma_resv: prime lockdep annotations (rev3) Patchwork
  11 siblings, 0 replies; 40+ messages in thread
From: Patchwork @ 2019-08-22 14:46 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: intel-gfx

== Series Details ==

Series: series starting with [1/3] dma_resv: prime lockdep annotations
URL   : https://patchwork.freedesktop.org/series/65575/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_6759_full -> Patchwork_14132_full
====================================================

Summary
-------

  **SUCCESS**

  No regressions found.

  

Known issues
------------

  Here are the changes found in Patchwork_14132_full that come from known issues:

### IGT changes ###

#### Issues hit ####

  * igt@debugfs_test@read_all_entries_display_on:
    - shard-skl:          [PASS][1] -> [DMESG-WARN][2] ([fdo#106107])
   [1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-skl1/igt@debugfs_test@read_all_entries_display_on.html
   [2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-skl8/igt@debugfs_test@read_all_entries_display_on.html

  * igt@gem_ctx_isolation@rcs0-s3:
    - shard-apl:          [PASS][3] -> [DMESG-WARN][4] ([fdo#108566]) +3 similar issues
   [3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-apl4/igt@gem_ctx_isolation@rcs0-s3.html
   [4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-apl6/igt@gem_ctx_isolation@rcs0-s3.html

  * igt@gem_exec_schedule@out-order-bsd:
    - shard-iclb:         [PASS][5] -> [SKIP][6] ([fdo#111325])
   [5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-iclb8/igt@gem_exec_schedule@out-order-bsd.html
   [6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-iclb4/igt@gem_exec_schedule@out-order-bsd.html

  * igt@gem_exec_schedule@preempt-queue-bsd1:
    - shard-iclb:         [PASS][7] -> [SKIP][8] ([fdo#109276]) +6 similar issues
   [7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-iclb1/igt@gem_exec_schedule@preempt-queue-bsd1.html
   [8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-iclb6/igt@gem_exec_schedule@preempt-queue-bsd1.html

  * igt@kms_atomic@test_only:
    - shard-snb:          [PASS][9] -> [SKIP][10] ([fdo#109271]) +2 similar issues
   [9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-snb6/igt@kms_atomic@test_only.html
   [10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-snb7/igt@kms_atomic@test_only.html

  * igt@kms_cursor_legacy@2x-long-cursor-vs-flip-legacy:
    - shard-hsw:          [PASS][11] -> [FAIL][12] ([fdo#105767])
   [11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-hsw8/igt@kms_cursor_legacy@2x-long-cursor-vs-flip-legacy.html
   [12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-hsw6/igt@kms_cursor_legacy@2x-long-cursor-vs-flip-legacy.html

  * igt@kms_flip@flip-vs-expired-vblank-interruptible:
    - shard-glk:          [PASS][13] -> [FAIL][14] ([fdo#105363])
   [13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-glk2/igt@kms_flip@flip-vs-expired-vblank-interruptible.html
   [14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-glk3/igt@kms_flip@flip-vs-expired-vblank-interruptible.html

  * igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-cur-indfb-draw-pwrite:
    - shard-iclb:         [PASS][15] -> [FAIL][16] ([fdo#103167]) +4 similar issues
   [15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-iclb3/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-cur-indfb-draw-pwrite.html
   [16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-iclb6/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-cur-indfb-draw-pwrite.html

  * igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-shrfb-draw-mmap-gtt:
    - shard-iclb:         [PASS][17] -> [INCOMPLETE][18] ([fdo#106978] / [fdo#107713])
   [17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-iclb6/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-shrfb-draw-mmap-gtt.html
   [18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-iclb1/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-shrfb-draw-mmap-gtt.html

  * igt@kms_frontbuffer_tracking@psr-1p-offscren-pri-indfb-draw-blt:
    - shard-skl:          [PASS][19] -> [FAIL][20] ([fdo#103167])
   [19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-skl2/igt@kms_frontbuffer_tracking@psr-1p-offscren-pri-indfb-draw-blt.html
   [20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-skl4/igt@kms_frontbuffer_tracking@psr-1p-offscren-pri-indfb-draw-blt.html

  * igt@kms_plane_alpha_blend@pipe-a-constant-alpha-min:
    - shard-skl:          [PASS][21] -> [FAIL][22] ([fdo#108145])
   [21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-skl2/igt@kms_plane_alpha_blend@pipe-a-constant-alpha-min.html
   [22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-skl4/igt@kms_plane_alpha_blend@pipe-a-constant-alpha-min.html

  * igt@kms_psr@psr2_suspend:
    - shard-iclb:         [PASS][23] -> [SKIP][24] ([fdo#109441])
   [23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-iclb2/igt@kms_psr@psr2_suspend.html
   [24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-iclb4/igt@kms_psr@psr2_suspend.html

  * igt@kms_vblank@pipe-a-wait-forked-hang:
    - shard-snb:          [PASS][25] -> [INCOMPLETE][26] ([fdo#105411])
   [25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-snb5/igt@kms_vblank@pipe-a-wait-forked-hang.html
   [26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-snb1/igt@kms_vblank@pipe-a-wait-forked-hang.html

  * igt@perf@blocking:
    - shard-skl:          [PASS][27] -> [FAIL][28] ([fdo#110728])
   [27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-skl10/igt@perf@blocking.html
   [28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-skl9/igt@perf@blocking.html

  
#### Possible fixes ####

  * igt@gem_eio@unwedge-stress:
    - shard-glk:          [FAIL][29] ([fdo#109661]) -> [PASS][30]
   [29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-glk7/igt@gem_eio@unwedge-stress.html
   [30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-glk3/igt@gem_eio@unwedge-stress.html

  * igt@gem_exec_reloc@basic-cpu-active:
    - shard-skl:          [DMESG-WARN][31] ([fdo#106107]) -> [PASS][32]
   [31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-skl7/igt@gem_exec_reloc@basic-cpu-active.html
   [32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-skl2/igt@gem_exec_reloc@basic-cpu-active.html

  * igt@gem_workarounds@suspend-resume-context:
    - shard-apl:          [DMESG-WARN][33] ([fdo#108566]) -> [PASS][34] +7 similar issues
   [33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-apl1/igt@gem_workarounds@suspend-resume-context.html
   [34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-apl2/igt@gem_workarounds@suspend-resume-context.html

  * igt@i915_selftest@live_execlists:
    - shard-skl:          [DMESG-FAIL][35] ([fdo#111422]) -> [PASS][36]
   [35]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-skl8/igt@i915_selftest@live_execlists.html
   [36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-skl1/igt@i915_selftest@live_execlists.html

  * igt@i915_suspend@forcewake:
    - shard-skl:          [INCOMPLETE][37] ([fdo#104108]) -> [PASS][38]
   [37]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-skl3/igt@i915_suspend@forcewake.html
   [38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-skl7/igt@i915_suspend@forcewake.html

  * igt@i915_suspend@sysfs-reader:
    - shard-apl:          [INCOMPLETE][39] ([fdo#103927]) -> [PASS][40]
   [39]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-apl2/igt@i915_suspend@sysfs-reader.html
   [40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-apl3/igt@i915_suspend@sysfs-reader.html

  * igt@kms_frontbuffer_tracking@fbc-1p-offscren-pri-shrfb-draw-pwrite:
    - shard-iclb:         [FAIL][41] ([fdo#103167]) -> [PASS][42] +2 similar issues
   [41]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-iclb1/igt@kms_frontbuffer_tracking@fbc-1p-offscren-pri-shrfb-draw-pwrite.html
   [42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-iclb6/igt@kms_frontbuffer_tracking@fbc-1p-offscren-pri-shrfb-draw-pwrite.html

  * igt@kms_plane_alpha_blend@pipe-b-coverage-7efc:
    - shard-skl:          [FAIL][43] ([fdo#108145] / [fdo#110403]) -> [PASS][44]
   [43]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-skl10/igt@kms_plane_alpha_blend@pipe-b-coverage-7efc.html
   [44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-skl9/igt@kms_plane_alpha_blend@pipe-b-coverage-7efc.html

  * igt@kms_psr@psr2_sprite_plane_onoff:
    - shard-iclb:         [SKIP][45] ([fdo#109441]) -> [PASS][46]
   [45]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-iclb1/igt@kms_psr@psr2_sprite_plane_onoff.html
   [46]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-iclb2/igt@kms_psr@psr2_sprite_plane_onoff.html

  * igt@kms_setmode@basic:
    - shard-apl:          [FAIL][47] ([fdo#99912]) -> [PASS][48]
   [47]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-apl2/igt@kms_setmode@basic.html
   [48]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-apl5/igt@kms_setmode@basic.html

  * igt@kms_vblank@pipe-b-ts-continuation-dpms-suspend:
    - shard-skl:          [INCOMPLETE][49] ([fdo#104108] / [fdo#107773]) -> [PASS][50]
   [49]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-skl2/igt@kms_vblank@pipe-b-ts-continuation-dpms-suspend.html
   [50]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-skl7/igt@kms_vblank@pipe-b-ts-continuation-dpms-suspend.html

  * igt@kms_vblank@pipe-c-ts-continuation-modeset-hang:
    - shard-hsw:          [INCOMPLETE][51] ([fdo#103540]) -> [PASS][52]
   [51]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-hsw4/igt@kms_vblank@pipe-c-ts-continuation-modeset-hang.html
   [52]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-hsw1/igt@kms_vblank@pipe-c-ts-continuation-modeset-hang.html

  * igt@prime_busy@hang-bsd2:
    - shard-iclb:         [SKIP][53] ([fdo#109276]) -> [PASS][54] +9 similar issues
   [53]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-iclb5/igt@prime_busy@hang-bsd2.html
   [54]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-iclb4/igt@prime_busy@hang-bsd2.html

  
#### Warnings ####

  * igt@kms_frontbuffer_tracking@fbc-1p-offscren-pri-indfb-draw-blt:
    - shard-skl:          [FAIL][55] ([fdo#108040]) -> [FAIL][56] ([fdo#103167])
   [55]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6759/shard-skl9/igt@kms_frontbuffer_tracking@fbc-1p-offscren-pri-indfb-draw-blt.html
   [56]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/shard-skl4/igt@kms_frontbuffer_tracking@fbc-1p-offscren-pri-indfb-draw-blt.html

  
  [fdo#103167]: https://bugs.freedesktop.org/show_bug.cgi?id=103167
  [fdo#103540]: https://bugs.freedesktop.org/show_bug.cgi?id=103540
  [fdo#103927]: https://bugs.freedesktop.org/show_bug.cgi?id=103927
  [fdo#104108]: https://bugs.freedesktop.org/show_bug.cgi?id=104108
  [fdo#105363]: https://bugs.freedesktop.org/show_bug.cgi?id=105363
  [fdo#105411]: https://bugs.freedesktop.org/show_bug.cgi?id=105411
  [fdo#105767]: https://bugs.freedesktop.org/show_bug.cgi?id=105767
  [fdo#106107]: https://bugs.freedesktop.org/show_bug.cgi?id=106107
  [fdo#106978]: https://bugs.freedesktop.org/show_bug.cgi?id=106978
  [fdo#107713]: https://bugs.freedesktop.org/show_bug.cgi?id=107713
  [fdo#107773]: https://bugs.freedesktop.org/show_bug.cgi?id=107773
  [fdo#108040]: https://bugs.freedesktop.org/show_bug.cgi?id=108040
  [fdo#108145]: https://bugs.freedesktop.org/show_bug.cgi?id=108145
  [fdo#108566]: https://bugs.freedesktop.org/show_bug.cgi?id=108566
  [fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
  [fdo#109276]: https://bugs.freedesktop.org/show_bug.cgi?id=109276
  [fdo#109441]: https://bugs.freedesktop.org/show_bug.cgi?id=109441
  [fdo#109661]: https://bugs.freedesktop.org/show_bug.cgi?id=109661
  [fdo#110403]: https://bugs.freedesktop.org/show_bug.cgi?id=110403
  [fdo#110728]: https://bugs.freedesktop.org/show_bug.cgi?id=110728
  [fdo#111325]: https://bugs.freedesktop.org/show_bug.cgi?id=111325
  [fdo#111422]: https://bugs.freedesktop.org/show_bug.cgi?id=111422
  [fdo#99912]: https://bugs.freedesktop.org/show_bug.cgi?id=99912


Participating hosts (10 -> 10)
------------------------------

  No changes in participating hosts


Build changes
-------------

  * CI: CI-20190529 -> None
  * Linux: CI_DRM_6759 -> Patchwork_14132

  CI-20190529: 20190529
  CI_DRM_6759: ef8503f9bd35e778de52953fe627fd50f316d712 @ git://anongit.freedesktop.org/gfx-ci/linux
  IGT_5146: 357dbe1869d88a2f08bcee4eebceff4ee9014424 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
  Patchwork_14132: 95bae0c804e91ea50401859c0f59635eed746891 @ git://anongit.freedesktop.org/gfx-ci/linux
  piglit_4509: fdc5a4ca11124ab8413c7988896eec4c97336694 @ git://anongit.freedesktop.org/piglit

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14132/
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH] dma_resv: prime lockdep annotations
  2019-08-22 13:36     ` Daniel Vetter
@ 2019-08-22 14:56       ` Thomas Hellström (VMware)
  0 siblings, 0 replies; 40+ messages in thread
From: Thomas Hellström (VMware) @ 2019-08-22 14:56 UTC (permalink / raw)
  To: Daniel Vetter
  Cc: Thomas Hellstrom, Tomeu Vizoso, DRI Development, VMware Graphics,
	Gerd Hoffmann, Thomas Zimmermann, Daniel Vetter, Alex Deucher,
	Dave Airlie, Christian König, Ben Skeggs

On 8/22/19 3:36 PM, Daniel Vetter wrote:
> On Thu, Aug 22, 2019 at 3:30 PM Thomas Hellström (VMware)
> <thomas_os@shipmail.org> wrote:
>> On 8/22/19 3:07 PM, Daniel Vetter wrote:
>>> 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_mutex while doing copy_*_user. But
>>>     I haven't checked them all.
>>>
>>> - panfrost seems to dma_resv_lock only in panfrost_job_push, which
>>>     looks clean.
>>>
>>> - v3d holds dma_resv locks in the tail of its v3d_submit_cl_ioctl(),
>>>     copying from/to userspace happens all in v3d_lookup_bos which 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 in
>>>       vmw_execbuf_cmdbuf() and also in the vmw_execbuf_process() itself.
>>>       Then comes the usual ttm reserve/validate sequence, then actual
>>>       submission/fencing, then unreserving, and finally some more
>>>       copy_to_user in vmw_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 in vmwgfx_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 into
>>>     qxl_process_single_command. There's a lovely comment before the
>>>     __copy_from_user_inatomic that 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 other copy_from_user is for relocs, but those
>>>     are done before qxl_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 in
>>>     usif_ioctl() look safe. nouveau_gem_ioctl_pushbuf() otoh breaks this
>>>     everywhere and needs to be fixed up.
>>>
>>> v2: Thomas pointed at that vmwgfx calls dma_resv_init while it holds a
>>> dma_resv lock of a different object already. Christian mentioned that
>>> ttm core does this too for ghost objects. intel-gfx-ci highlighted
>>> that i915 has similar issues.
>>>
>>> Unfortunately we can't do this in the usual module init functions,
>>> because kernel threads don't have an ->mm - we have to wait around for
>>> some user thread to do this.
>>>
>>> Solution is to spawn a worker (but only once). It's horrible, but it
>>> works.
>>>
>>> v3: We can allocate mm! (Chris). Horrible worker hack out, clean
>>> initcall solution in.
>>>
>>> v4: Annotate with __init (Rob Herring)
>>>
>>> Cc: Rob Herring <robh@kernel.org>
>>> Cc: Alex Deucher <alexander.deucher@amd.com>
>>> Cc: Christian König <christian.koenig@amd.com>
>>> Cc: Chris Wilson <chris@chris-wilson.co.uk>
>>> Cc: Thomas Zimmermann <tzimmermann@suse.de>
>>> Cc: Rob Herring <robh@kernel.org>
>>> Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
>>> Cc: Eric Anholt <eric@anholt.net>
>>> Cc: Dave Airlie <airlied@redhat.com>
>>> Cc: Gerd Hoffmann <kraxel@redhat.com>
>>> Cc: Ben Skeggs <bskeggs@redhat.com>
>>> Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
>>> Cc: Thomas Hellstrom <thellstrom@vmware.com>
>>> Reviewed-by: Christian König <christian.koenig@amd.com>
>>> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
>>> Tested-by: Chris Wilson <chris@chris-wilson.co.uk>
>>> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
>>> ---
>>>    drivers/dma-buf/dma-resv.c | 24 ++++++++++++++++++++++++
>>>    1 file changed, 24 insertions(+)
>>>
>>> diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
>>> index 42a8f3f11681..97c4c4812d08 100644
>>> --- a/drivers/dma-buf/dma-resv.c
>>> +++ b/drivers/dma-buf/dma-resv.c
>>> @@ -34,6 +34,7 @@
>>>
>>>    #include <linux/dma-resv.h>
>>>    #include <linux/export.h>
>>> +#include <linux/sched/mm.h>
>>>
>>>    /**
>>>     * DOC: Reservation Object Overview
>>> @@ -95,6 +96,29 @@ static void dma_resv_list_free(struct dma_resv_list *list)
>>>        kfree_rcu(list, rcu);
>>>    }
>>>
>>> +#if IS_ENABLED(CONFIG_LOCKDEP)
>>> +static void __init dma_resv_lockdep(void)
>>> +{
>>> +     struct mm_struct *mm = mm_alloc();
>>> +     struct dma_resv obj;
>>> +
>>> +     if (!mm)
>>> +             return;
>>> +
>>> +     dma_resv_init(&obj);
>>> +
>>> +     down_read(&mm->mmap_sem);
>>
>> I took a quick look into using lockdep macros replacing the actual
>> locks: Something along the lines of
>>
>> lock_acquire(mm->mmap_sem.dep_map, 0, 0, 1, 1, NULL, _THIS_IP_);
> Yeah I'm not a fan of the magic numbers this nees :-/ And now this is
> run once at startup, so the taking the fake locks for real, once,
> shouldn't hurt. Lockdep updating it's data structures is going to be
> 100x more cpu cycles anyway :-)
>
>>> +     ww_mutex_lock(&obj.lock, NULL);
>> lock_acquire(obj.lock.dep_map, 0, 0, 0, 1, NULL, _THIS_IP_);
>>> +     fs_reclaim_acquire(GFP_KERNEL);
>>> +     fs_reclaim_release(GFP_KERNEL);
>>> +     ww_mutex_unlock(&obj.lock);
>> lock_release(obj.lock.dep_map, 0, _THIS_IP_);
>>
>>> +     up_read(&mm->mmap_sem);
>> lock_release(obj.lock.dep_map, 0, _THIS_IP_);
>>
>> Either way is fine with me, though.
>>
>> Reviewed-by: Thomas Hellström <thellstrom@vmware.com>
> Thanks for your review comments.
>
> Can you pls also run this in some test cycles, if that's easily
> possible? I'd like to have a tested-by from at least the big drivers -
> i915, amd, nouveau, vmwgfx and is definitely using ttm to its fullest
> too, so best chances for hitting an oversight.
>
> Cheers, Daniel

Tested vmwgfx with a decent OpenGL / rendercheck stress test and no 
lockdep trips.

/Thomas

Tested-by: Thomas Hellström <thellstrom@vmware.com>


_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* ✓ Fi.CI.IGT: success for series starting with dma_resv: prime lockdep annotations (rev3)
  2019-08-21 21:50 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
                   ` (10 preceding siblings ...)
  2019-08-22 14:46 ` ✓ Fi.CI.IGT: success for series starting with [1/3] " Patchwork
@ 2019-08-23  1:43 ` Patchwork
  11 siblings, 0 replies; 40+ messages in thread
From: Patchwork @ 2019-08-23  1:43 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: intel-gfx

== Series Details ==

Series: series starting with dma_resv: prime lockdep annotations (rev3)
URL   : https://patchwork.freedesktop.org/series/65575/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_6763_full -> Patchwork_14136_full
====================================================

Summary
-------

  **SUCCESS**

  No regressions found.

  

Known issues
------------

  Here are the changes found in Patchwork_14136_full that come from known issues:

### IGT changes ###

#### Issues hit ####

  * igt@gem_ctx_isolation@rcs0-s3:
    - shard-apl:          [PASS][1] -> [DMESG-WARN][2] ([fdo#108566]) +3 similar issues
   [1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-apl4/igt@gem_ctx_isolation@rcs0-s3.html
   [2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-apl8/igt@gem_ctx_isolation@rcs0-s3.html

  * igt@gem_exec_balancer@smoke:
    - shard-iclb:         [PASS][3] -> [SKIP][4] ([fdo#110854])
   [3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-iclb4/igt@gem_exec_balancer@smoke.html
   [4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-iclb8/igt@gem_exec_balancer@smoke.html

  * igt@gem_exec_flush@basic-wb-ro-default:
    - shard-iclb:         [PASS][5] -> [INCOMPLETE][6] ([fdo#107713] / [fdo#109100])
   [5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-iclb7/igt@gem_exec_flush@basic-wb-ro-default.html
   [6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-iclb7/igt@gem_exec_flush@basic-wb-ro-default.html

  * igt@gem_exec_schedule@preempt-other-chain-bsd:
    - shard-iclb:         [PASS][7] -> [SKIP][8] ([fdo#111325]) +5 similar issues
   [7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-iclb5/igt@gem_exec_schedule@preempt-other-chain-bsd.html
   [8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-iclb2/igt@gem_exec_schedule@preempt-other-chain-bsd.html

  * igt@kms_cursor_legacy@flip-vs-cursor-atomic-transitions-varying-size:
    - shard-skl:          [PASS][9] -> [FAIL][10] ([fdo#102670])
   [9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-skl9/igt@kms_cursor_legacy@flip-vs-cursor-atomic-transitions-varying-size.html
   [10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-skl4/igt@kms_cursor_legacy@flip-vs-cursor-atomic-transitions-varying-size.html

  * igt@kms_flip@flip-vs-suspend-interruptible:
    - shard-skl:          [PASS][11] -> [INCOMPLETE][12] ([fdo#109507])
   [11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-skl1/igt@kms_flip@flip-vs-suspend-interruptible.html
   [12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-skl8/igt@kms_flip@flip-vs-suspend-interruptible.html

  * igt@kms_frontbuffer_tracking@fbc-2p-primscrn-spr-indfb-fullscreen:
    - shard-hsw:          [PASS][13] -> [SKIP][14] ([fdo#109271])
   [13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-hsw5/igt@kms_frontbuffer_tracking@fbc-2p-primscrn-spr-indfb-fullscreen.html
   [14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-hsw8/igt@kms_frontbuffer_tracking@fbc-2p-primscrn-spr-indfb-fullscreen.html

  * igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-spr-indfb-draw-render:
    - shard-iclb:         [PASS][15] -> [FAIL][16] ([fdo#103167]) +1 similar issue
   [15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-iclb5/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-spr-indfb-draw-render.html
   [16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-iclb2/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-spr-indfb-draw-render.html

  * igt@kms_psr@psr2_basic:
    - shard-iclb:         [PASS][17] -> [SKIP][18] ([fdo#109441]) +3 similar issues
   [17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-iclb2/igt@kms_psr@psr2_basic.html
   [18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-iclb6/igt@kms_psr@psr2_basic.html

  * igt@kms_vblank@pipe-c-ts-continuation-suspend:
    - shard-skl:          [PASS][19] -> [INCOMPLETE][20] ([fdo#104108])
   [19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-skl9/igt@kms_vblank@pipe-c-ts-continuation-suspend.html
   [20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-skl7/igt@kms_vblank@pipe-c-ts-continuation-suspend.html

  * igt@prime_busy@hang-bsd2:
    - shard-iclb:         [PASS][21] -> [SKIP][22] ([fdo#109276]) +12 similar issues
   [21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-iclb4/igt@prime_busy@hang-bsd2.html
   [22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-iclb5/igt@prime_busy@hang-bsd2.html

  
#### Possible fixes ####

  * igt@gem_ctx_shared@exec-single-timeline-bsd:
    - shard-iclb:         [SKIP][23] ([fdo#110841]) -> [PASS][24]
   [23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-iclb4/igt@gem_ctx_shared@exec-single-timeline-bsd.html
   [24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-iclb5/igt@gem_ctx_shared@exec-single-timeline-bsd.html

  * igt@gem_exec_schedule@preempt-queue-bsd1:
    - shard-iclb:         [SKIP][25] ([fdo#109276]) -> [PASS][26] +13 similar issues
   [25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-iclb8/igt@gem_exec_schedule@preempt-queue-bsd1.html
   [26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-iclb4/igt@gem_exec_schedule@preempt-queue-bsd1.html

  * igt@gem_exec_schedule@preemptive-hang-bsd:
    - shard-iclb:         [SKIP][27] ([fdo#111325]) -> [PASS][28] +7 similar issues
   [27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-iclb1/igt@gem_exec_schedule@preemptive-hang-bsd.html
   [28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-iclb7/igt@gem_exec_schedule@preemptive-hang-bsd.html

  * igt@i915_suspend@sysfs-reader:
    - shard-apl:          [DMESG-WARN][29] ([fdo#108566]) -> [PASS][30] +3 similar issues
   [29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-apl4/igt@i915_suspend@sysfs-reader.html
   [30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-apl4/igt@i915_suspend@sysfs-reader.html

  * igt@kms_color@pipe-b-degamma:
    - shard-skl:          [FAIL][31] ([fdo#104782]) -> [PASS][32]
   [31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-skl9/igt@kms_color@pipe-b-degamma.html
   [32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-skl7/igt@kms_color@pipe-b-degamma.html

  * igt@kms_cursor_legacy@2x-long-cursor-vs-flip-atomic:
    - shard-hsw:          [FAIL][33] ([fdo#105767]) -> [PASS][34]
   [33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-hsw4/igt@kms_cursor_legacy@2x-long-cursor-vs-flip-atomic.html
   [34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-hsw1/igt@kms_cursor_legacy@2x-long-cursor-vs-flip-atomic.html

  * igt@kms_cursor_legacy@pipe-a-torture-bo:
    - shard-apl:          [INCOMPLETE][35] ([fdo#103927]) -> [PASS][36] +3 similar issues
   [35]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-apl4/igt@kms_cursor_legacy@pipe-a-torture-bo.html
   [36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-apl2/igt@kms_cursor_legacy@pipe-a-torture-bo.html

  * igt@kms_flip@2x-flip-vs-expired-vblank:
    - shard-hsw:          [FAIL][37] ([fdo#102887]) -> [PASS][38]
   [37]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-hsw2/igt@kms_flip@2x-flip-vs-expired-vblank.html
   [38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-hsw5/igt@kms_flip@2x-flip-vs-expired-vblank.html

  * igt@kms_flip@2x-flip-vs-expired-vblank-interruptible:
    - shard-glk:          [FAIL][39] ([fdo#105363]) -> [PASS][40]
   [39]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-glk1/igt@kms_flip@2x-flip-vs-expired-vblank-interruptible.html
   [40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-glk6/igt@kms_flip@2x-flip-vs-expired-vblank-interruptible.html

  * igt@kms_flip@dpms-vs-vblank-race:
    - shard-glk:          [FAIL][41] ([fdo#103060]) -> [PASS][42]
   [41]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-glk6/igt@kms_flip@dpms-vs-vblank-race.html
   [42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-glk3/igt@kms_flip@dpms-vs-vblank-race.html

  * igt@kms_frontbuffer_tracking@fbc-1p-primscrn-cur-indfb-draw-render:
    - shard-iclb:         [FAIL][43] ([fdo#103167]) -> [PASS][44] +3 similar issues
   [43]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-iclb2/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-cur-indfb-draw-render.html
   [44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-iclb6/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-cur-indfb-draw-render.html

  * igt@kms_plane_alpha_blend@pipe-c-constant-alpha-min:
    - shard-skl:          [FAIL][45] ([fdo#108145]) -> [PASS][46] +1 similar issue
   [45]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-skl9/igt@kms_plane_alpha_blend@pipe-c-constant-alpha-min.html
   [46]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-skl4/igt@kms_plane_alpha_blend@pipe-c-constant-alpha-min.html

  * igt@kms_psr@no_drrs:
    - shard-iclb:         [FAIL][47] ([fdo#108341]) -> [PASS][48]
   [47]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-iclb1/igt@kms_psr@no_drrs.html
   [48]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-iclb4/igt@kms_psr@no_drrs.html

  * igt@kms_psr@psr2_primary_mmap_cpu:
    - shard-iclb:         [SKIP][49] ([fdo#109441]) -> [PASS][50] +2 similar issues
   [49]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-iclb5/igt@kms_psr@psr2_primary_mmap_cpu.html
   [50]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-iclb2/igt@kms_psr@psr2_primary_mmap_cpu.html

  * igt@kms_vblank@pipe-a-wait-busy-hang:
    - shard-iclb:         [INCOMPLETE][51] ([fdo#107713]) -> [PASS][52]
   [51]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-iclb7/igt@kms_vblank@pipe-a-wait-busy-hang.html
   [52]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-iclb4/igt@kms_vblank@pipe-a-wait-busy-hang.html

  * igt@kms_vblank@pipe-b-ts-continuation-suspend:
    - shard-kbl:          [INCOMPLETE][53] ([fdo#103665]) -> [PASS][54]
   [53]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-kbl2/igt@kms_vblank@pipe-b-ts-continuation-suspend.html
   [54]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-kbl6/igt@kms_vblank@pipe-b-ts-continuation-suspend.html

  
#### Warnings ####

  * igt@gem_mocs_settings@mocs-reset-bsd2:
    - shard-iclb:         [FAIL][55] ([fdo#111330]) -> [SKIP][56] ([fdo#109276]) +1 similar issue
   [55]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6763/shard-iclb2/igt@gem_mocs_settings@mocs-reset-bsd2.html
   [56]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/shard-iclb5/igt@gem_mocs_settings@mocs-reset-bsd2.html

  
  [fdo#102670]: https://bugs.freedesktop.org/show_bug.cgi?id=102670
  [fdo#102887]: https://bugs.freedesktop.org/show_bug.cgi?id=102887
  [fdo#103060]: https://bugs.freedesktop.org/show_bug.cgi?id=103060
  [fdo#103167]: https://bugs.freedesktop.org/show_bug.cgi?id=103167
  [fdo#103665]: https://bugs.freedesktop.org/show_bug.cgi?id=103665
  [fdo#103927]: https://bugs.freedesktop.org/show_bug.cgi?id=103927
  [fdo#104108]: https://bugs.freedesktop.org/show_bug.cgi?id=104108
  [fdo#104782]: https://bugs.freedesktop.org/show_bug.cgi?id=104782
  [fdo#105363]: https://bugs.freedesktop.org/show_bug.cgi?id=105363
  [fdo#105767]: https://bugs.freedesktop.org/show_bug.cgi?id=105767
  [fdo#107713]: https://bugs.freedesktop.org/show_bug.cgi?id=107713
  [fdo#108145]: https://bugs.freedesktop.org/show_bug.cgi?id=108145
  [fdo#108341]: https://bugs.freedesktop.org/show_bug.cgi?id=108341
  [fdo#108566]: https://bugs.freedesktop.org/show_bug.cgi?id=108566
  [fdo#109100]: https://bugs.freedesktop.org/show_bug.cgi?id=109100
  [fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
  [fdo#109276]: https://bugs.freedesktop.org/show_bug.cgi?id=109276
  [fdo#109441]: https://bugs.freedesktop.org/show_bug.cgi?id=109441
  [fdo#109507]: https://bugs.freedesktop.org/show_bug.cgi?id=109507
  [fdo#110841]: https://bugs.freedesktop.org/show_bug.cgi?id=110841
  [fdo#110854]: https://bugs.freedesktop.org/show_bug.cgi?id=110854
  [fdo#111325]: https://bugs.freedesktop.org/show_bug.cgi?id=111325
  [fdo#111330]: https://bugs.freedesktop.org/show_bug.cgi?id=111330


Participating hosts (9 -> 9)
------------------------------

  No changes in participating hosts


Build changes
-------------

  * CI: CI-20190529 -> None
  * Linux: CI_DRM_6763 -> Patchwork_14136

  CI-20190529: 20190529
  CI_DRM_6763: a9a5855cece4d78bc2dfd4c719191a9ccabab4fb @ git://anongit.freedesktop.org/gfx-ci/linux
  IGT_5147: 289dcb935ee195352f987c0ae7dd31693bf7de0f @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
  Patchwork_14136: dd4da03d3f1fffd050c83bbd0458d4b566483e86 @ git://anongit.freedesktop.org/gfx-ci/linux
  piglit_4509: fdc5a4ca11124ab8413c7988896eec4c97336694 @ git://anongit.freedesktop.org/piglit

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14136/
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH] dma_resv: prime lockdep annotations
  2019-08-22  7:53   ` Koenig, Christian
@ 2019-09-03  8:16     ` Daniel Vetter
  2019-09-03  9:02       ` Koenig, Christian
  0 siblings, 1 reply; 40+ messages in thread
From: Daniel Vetter @ 2019-09-03  8:16 UTC (permalink / raw)
  To: Koenig, Christian
  Cc: Thomas Hellstrom, Tomeu Vizoso, Daniel Vetter,
	Intel Graphics Development, DRI Development, VMware Graphics,
	Gerd Hoffmann, Thomas Zimmermann, Daniel Vetter, Deucher,
	Alexander, Dave Airlie, Ben Skeggs

On Thu, Aug 22, 2019 at 07:53:53AM +0000, Koenig, Christian wrote:
> Am 22.08.19 um 08:54 schrieb 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_mutex while doing copy_*_user. But
> >    I haven't checked them all.
> >
> > - panfrost seems to dma_resv_lock only in panfrost_job_push, which
> >    looks clean.
> >
> > - v3d holds dma_resv locks in the tail of its v3d_submit_cl_ioctl(),
> >    copying from/to userspace happens all in v3d_lookup_bos which 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 in
> >      vmw_execbuf_cmdbuf() and also in the vmw_execbuf_process() itself.
> >      Then comes the usual ttm reserve/validate sequence, then actual
> >      submission/fencing, then unreserving, and finally some more
> >      copy_to_user in vmw_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 in vmwgfx_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 into
> >    qxl_process_single_command. There's a lovely comment before the
> >    __copy_from_user_inatomic that 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 other copy_from_user is for relocs, but those
> >    are done before qxl_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 in
> >    usif_ioctl() look safe. nouveau_gem_ioctl_pushbuf() otoh breaks this
> >    everywhere and needs to be fixed up.
> >
> > v2: Thomas pointed at that vmwgfx calls dma_resv_init while it holds a
> > dma_resv lock of a different object already. Christian mentioned that
> > ttm core does this too for ghost objects. intel-gfx-ci highlighted
> > that i915 has similar issues.
> >
> > Unfortunately we can't do this in the usual module init functions,
> > because kernel threads don't have an ->mm - we have to wait around for
> > some user thread to do this.
> >
> > Solution is to spawn a worker (but only once). It's horrible, but it
> > works.
> >
> > v3: We can allocate mm! (Chris). Horrible worker hack out, clean
> > initcall solution in.
> >
> > Cc: Alex Deucher <alexander.deucher@amd.com>
> > Cc: Christian König <christian.koenig@amd.com>
> > Cc: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: Thomas Zimmermann <tzimmermann@suse.de>
> > Cc: Rob Herring <robh@kernel.org>
> > Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> > Cc: Eric Anholt <eric@anholt.net>
> > Cc: Dave Airlie <airlied@redhat.com>
> > Cc: Gerd Hoffmann <kraxel@redhat.com>
> > Cc: Ben Skeggs <bskeggs@redhat.com>
> > Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
> > Cc: Thomas Hellstrom <thellstrom@vmware.com>
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> 
> Reviewed-by: Christian König <christian.koenig@amd.com>

Did you get a chance to give this a spin on the amd CI?
-Daniel

> 
> > ---
> >   drivers/dma-buf/dma-resv.c | 24 ++++++++++++++++++++++++
> >   1 file changed, 24 insertions(+)
> >
> > diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
> > index 42a8f3f11681..d233ef4cf0d7 100644
> > --- a/drivers/dma-buf/dma-resv.c
> > +++ b/drivers/dma-buf/dma-resv.c
> > @@ -34,6 +34,7 @@
> >   
> >   #include <linux/dma-resv.h>
> >   #include <linux/export.h>
> > +#include <linux/sched/mm.h>
> >   
> >   /**
> >    * DOC: Reservation Object Overview
> > @@ -95,6 +96,29 @@ static void dma_resv_list_free(struct dma_resv_list *list)
> >   	kfree_rcu(list, rcu);
> >   }
> >   
> > +#if IS_ENABLED(CONFIG_LOCKDEP)
> > +static void dma_resv_lockdep(void)
> > +{
> > +	struct mm_struct *mm = mm_alloc();
> > +	struct dma_resv obj;
> > +
> > +	if (!mm)
> > +		return;
> > +
> > +	dma_resv_init(&obj);
> > +
> > +	down_read(&mm->mmap_sem);
> > +	ww_mutex_lock(&obj.lock, NULL);
> > +	fs_reclaim_acquire(GFP_KERNEL);
> > +	fs_reclaim_release(GFP_KERNEL);
> > +	ww_mutex_unlock(&obj.lock);
> > +	up_read(&mm->mmap_sem);
> > +	
> > +	mmput(mm);
> > +}
> > +subsys_initcall(dma_resv_lockdep);
> > +#endif
> > +
> >   /**
> >    * dma_resv_init - initialize a reservation object
> >    * @obj: the reservation object
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
       [not found]     ` <20190821215030.31660-2-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
@ 2019-09-03  8:17       ` Daniel Vetter
       [not found]         ` <20190903081714.GO2112-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
  0 siblings, 1 reply; 40+ messages in thread
From: Daniel Vetter @ 2019-09-03  8:17 UTC (permalink / raw)
  To: DRI Development
  Cc: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	Intel Graphics Development, Ben Skeggs, Daniel Vetter

On Wed, Aug 21, 2019 at 11:50:29PM +0200, Daniel Vetter wrote:
> We can't copy_*_user while holding reservations, that will (soon even
> for nouveau) lead to deadlocks. And it breaks the cross-driver
> contract around dma_resv.
> 
> Fix this by adding a slowpath for when we need relocations, and by
> pushing the writeback of the new presumed offsets to the very end.
> 
> Aside from "it compiles" entirely untested unfortunately.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: nouveau@lists.freedesktop.org

Ping for some review/testing (apparently needs pre-nv50). I'd really like
to land this series here, it should help a lot in making sure everyone
uses dma_resv in a compatible way across drivers.

Thanks, Daniel

> ---
>  drivers/gpu/drm/nouveau/nouveau_gem.c | 57 ++++++++++++++++++---------
>  1 file changed, 38 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
> index c77302f969e8..60309b997951 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
> @@ -482,12 +482,9 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
>  
>  static int
>  validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
> -	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
> -	      uint64_t user_pbbo_ptr)
> +	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo)
>  {
>  	struct nouveau_drm *drm = chan->drm;
> -	struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
> -				(void __force __user *)(uintptr_t)user_pbbo_ptr;
>  	struct nouveau_bo *nvbo;
>  	int ret, relocs = 0;
>  
> @@ -531,10 +528,6 @@ validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
>  			b->presumed.offset = nvbo->bo.offset;
>  			b->presumed.valid = 0;
>  			relocs++;
> -
> -			if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
> -					     &b->presumed, sizeof(b->presumed)))
> -				return -EFAULT;
>  		}
>  	}
>  
> @@ -545,8 +538,8 @@ static int
>  nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
>  			     struct drm_file *file_priv,
>  			     struct drm_nouveau_gem_pushbuf_bo *pbbo,
> -			     uint64_t user_buffers, int nr_buffers,
> -			     struct validate_op *op, int *apply_relocs)
> +			     int nr_buffers,
> +			     struct validate_op *op, bool *apply_relocs)
>  {
>  	struct nouveau_cli *cli = nouveau_cli(file_priv);
>  	int ret;
> @@ -563,7 +556,7 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
>  		return ret;
>  	}
>  
> -	ret = validate_list(chan, cli, &op->list, pbbo, user_buffers);
> +	ret = validate_list(chan, cli, &op->list, pbbo);
>  	if (unlikely(ret < 0)) {
>  		if (ret != -ERESTARTSYS)
>  			NV_PRINTK(err, cli, "validating bo list\n");
> @@ -603,16 +596,12 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
>  static int
>  nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
>  				struct drm_nouveau_gem_pushbuf *req,
> +				struct drm_nouveau_gem_pushbuf_reloc *reloc,
>  				struct drm_nouveau_gem_pushbuf_bo *bo)
>  {
> -	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
>  	int ret = 0;
>  	unsigned i;
>  
> -	reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
> -	if (IS_ERR(reloc))
> -		return PTR_ERR(reloc);
> -
>  	for (i = 0; i < req->nr_relocs; i++) {
>  		struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
>  		struct drm_nouveau_gem_pushbuf_bo *b;
> @@ -691,11 +680,13 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>  	struct nouveau_drm *drm = nouveau_drm(dev);
>  	struct drm_nouveau_gem_pushbuf *req = data;
>  	struct drm_nouveau_gem_pushbuf_push *push;
> +	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
>  	struct drm_nouveau_gem_pushbuf_bo *bo;
>  	struct nouveau_channel *chan = NULL;
>  	struct validate_op op;
>  	struct nouveau_fence *fence = NULL;
> -	int i, j, ret = 0, do_reloc = 0;
> +	int i, j, ret = 0;
> +	bool do_reloc = false;
>  
>  	if (unlikely(!abi16))
>  		return -ENOMEM;
> @@ -753,7 +744,8 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>  	}
>  
>  	/* Validate buffer list */
> -	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
> +revalidate:
> +	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo,
>  					   req->nr_buffers, &op, &do_reloc);
>  	if (ret) {
>  		if (ret != -ERESTARTSYS)
> @@ -763,7 +755,18 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>  
>  	/* Apply any relocations that are required */
>  	if (do_reloc) {
> -		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
> +		if (!reloc) {
> +			validate_fini(&op, chan, NULL, bo);
> +			reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
> +			if (IS_ERR(reloc)) {
> +				ret = PTR_ERR(reloc);
> +				goto out_prevalid;
> +			}
> +
> +			goto revalidate;
> +		}
> +
> +		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, reloc, bo);
>  		if (ret) {
>  			NV_PRINTK(err, cli, "reloc apply: %d\n", ret);
>  			goto out;
> @@ -849,6 +852,22 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>  	validate_fini(&op, chan, fence, bo);
>  	nouveau_fence_unref(&fence);
>  
> +	if (do_reloc) {
> +		struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
> +			u64_to_user_ptr(req->buffers);
> +
> +		for (i = 0; i < req->nr_buffers; i++) {
> +			if (bo[i].presumed.valid)
> +				continue;
> +
> +			if (copy_to_user(&upbbo[i].presumed, &bo[i].presumed,
> +					 sizeof(bo[i].presumed))) {
> +				ret = -EFAULT;
> +				break;
> +			}
> +		}
> +		u_free(reloc);
> +	}
>  out_prevalid:
>  	u_free(bo);
>  	u_free(push);
> -- 
> 2.23.0.rc1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH] dma_resv: prime lockdep annotations
  2019-09-03  8:16     ` Daniel Vetter
@ 2019-09-03  9:02       ` Koenig, Christian
  0 siblings, 0 replies; 40+ messages in thread
From: Koenig, Christian @ 2019-09-03  9:02 UTC (permalink / raw)
  To: Daniel Vetter
  Cc: Rob Herring, Thomas Hellstrom, Tomeu Vizoso, Daniel Vetter,
	Intel Graphics Development, DRI Development, VMware Graphics,
	Gerd Hoffmann, Thomas Zimmermann, Daniel Vetter, Deucher,
	Alexander, Dave Airlie, Ben Skeggs

Am 03.09.19 um 10:16 schrieb Daniel Vetter:
> On Thu, Aug 22, 2019 at 07:53:53AM +0000, Koenig, Christian wrote:
>> Am 22.08.19 um 08:54 schrieb 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_mutex while doing copy_*_user. But
>>>     I haven't checked them all.
>>>
>>> - panfrost seems to dma_resv_lock only in panfrost_job_push, which
>>>     looks clean.
>>>
>>> - v3d holds dma_resv locks in the tail of its v3d_submit_cl_ioctl(),
>>>     copying from/to userspace happens all in v3d_lookup_bos which 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 in
>>>       vmw_execbuf_cmdbuf() and also in the vmw_execbuf_process() itself.
>>>       Then comes the usual ttm reserve/validate sequence, then actual
>>>       submission/fencing, then unreserving, and finally some more
>>>       copy_to_user in vmw_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 in vmwgfx_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 into
>>>     qxl_process_single_command. There's a lovely comment before the
>>>     __copy_from_user_inatomic that 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 other copy_from_user is for relocs, but those
>>>     are done before qxl_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 in
>>>     usif_ioctl() look safe. nouveau_gem_ioctl_pushbuf() otoh breaks this
>>>     everywhere and needs to be fixed up.
>>>
>>> v2: Thomas pointed at that vmwgfx calls dma_resv_init while it holds a
>>> dma_resv lock of a different object already. Christian mentioned that
>>> ttm core does this too for ghost objects. intel-gfx-ci highlighted
>>> that i915 has similar issues.
>>>
>>> Unfortunately we can't do this in the usual module init functions,
>>> because kernel threads don't have an ->mm - we have to wait around for
>>> some user thread to do this.
>>>
>>> Solution is to spawn a worker (but only once). It's horrible, but it
>>> works.
>>>
>>> v3: We can allocate mm! (Chris). Horrible worker hack out, clean
>>> initcall solution in.
>>>
>>> Cc: Alex Deucher <alexander.deucher@amd.com>
>>> Cc: Christian König <christian.koenig@amd.com>
>>> Cc: Chris Wilson <chris@chris-wilson.co.uk>
>>> Cc: Thomas Zimmermann <tzimmermann@suse.de>
>>> Cc: Rob Herring <robh@kernel.org>
>>> Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
>>> Cc: Eric Anholt <eric@anholt.net>
>>> Cc: Dave Airlie <airlied@redhat.com>
>>> Cc: Gerd Hoffmann <kraxel@redhat.com>
>>> Cc: Ben Skeggs <bskeggs@redhat.com>
>>> Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
>>> Cc: Thomas Hellstrom <thellstrom@vmware.com>
>>> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
>> Reviewed-by: Christian König <christian.koenig@amd.com>
> Did you get a chance to give this a spin on the amd CI?

No and sorry totally forgot to ask about that.

Going to try to bring this up tomorrow once more, but don't expect that 
I can get this tested anytime soon.

Christian.

> -Daniel
>
>>> ---
>>>    drivers/dma-buf/dma-resv.c | 24 ++++++++++++++++++++++++
>>>    1 file changed, 24 insertions(+)
>>>
>>> diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
>>> index 42a8f3f11681..d233ef4cf0d7 100644
>>> --- a/drivers/dma-buf/dma-resv.c
>>> +++ b/drivers/dma-buf/dma-resv.c
>>> @@ -34,6 +34,7 @@
>>>    
>>>    #include <linux/dma-resv.h>
>>>    #include <linux/export.h>
>>> +#include <linux/sched/mm.h>
>>>    
>>>    /**
>>>     * DOC: Reservation Object Overview
>>> @@ -95,6 +96,29 @@ static void dma_resv_list_free(struct dma_resv_list *list)
>>>    	kfree_rcu(list, rcu);
>>>    }
>>>    
>>> +#if IS_ENABLED(CONFIG_LOCKDEP)
>>> +static void dma_resv_lockdep(void)
>>> +{
>>> +	struct mm_struct *mm = mm_alloc();
>>> +	struct dma_resv obj;
>>> +
>>> +	if (!mm)
>>> +		return;
>>> +
>>> +	dma_resv_init(&obj);
>>> +
>>> +	down_read(&mm->mmap_sem);
>>> +	ww_mutex_lock(&obj.lock, NULL);
>>> +	fs_reclaim_acquire(GFP_KERNEL);
>>> +	fs_reclaim_release(GFP_KERNEL);
>>> +	ww_mutex_unlock(&obj.lock);
>>> +	up_read(&mm->mmap_sem);
>>> +	
>>> +	mmput(mm);
>>> +}
>>> +subsys_initcall(dma_resv_lockdep);
>>> +#endif
>>> +
>>>    /**
>>>     * dma_resv_init - initialize a reservation object
>>>     * @obj: the reservation object

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
       [not found]         ` <20190903081714.GO2112-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
@ 2019-09-18  9:29           ` Daniel Vetter
  0 siblings, 0 replies; 40+ messages in thread
From: Daniel Vetter @ 2019-09-18  9:29 UTC (permalink / raw)
  To: DRI Development
  Cc: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	Intel Graphics Development, Ben Skeggs, Daniel Vetter

On Tue, Sep 03, 2019 at 10:17:14AM +0200, Daniel Vetter wrote:
> On Wed, Aug 21, 2019 at 11:50:29PM +0200, Daniel Vetter wrote:
> > We can't copy_*_user while holding reservations, that will (soon even
> > for nouveau) lead to deadlocks. And it breaks the cross-driver
> > contract around dma_resv.
> > 
> > Fix this by adding a slowpath for when we need relocations, and by
> > pushing the writeback of the new presumed offsets to the very end.
> > 
> > Aside from "it compiles" entirely untested unfortunately.
> > 
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > Cc: Ben Skeggs <bskeggs@redhat.com>
> > Cc: nouveau@lists.freedesktop.org
> 
> Ping for some review/testing (apparently needs pre-nv50). I'd really like
> to land this series here, it should help a lot in making sure everyone
> uses dma_resv in a compatible way across drivers.

Now that the gem/ttm fallout is fixed, ping for testing on this one here
... Also need some r-b to get this landed.

Thanks, Daniel

> > ---
> >  drivers/gpu/drm/nouveau/nouveau_gem.c | 57 ++++++++++++++++++---------
> >  1 file changed, 38 insertions(+), 19 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
> > index c77302f969e8..60309b997951 100644
> > --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
> > +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
> > @@ -482,12 +482,9 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
> >  
> >  static int
> >  validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
> > -	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
> > -	      uint64_t user_pbbo_ptr)
> > +	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo)
> >  {
> >  	struct nouveau_drm *drm = chan->drm;
> > -	struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
> > -				(void __force __user *)(uintptr_t)user_pbbo_ptr;
> >  	struct nouveau_bo *nvbo;
> >  	int ret, relocs = 0;
> >  
> > @@ -531,10 +528,6 @@ validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
> >  			b->presumed.offset = nvbo->bo.offset;
> >  			b->presumed.valid = 0;
> >  			relocs++;
> > -
> > -			if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
> > -					     &b->presumed, sizeof(b->presumed)))
> > -				return -EFAULT;
> >  		}
> >  	}
> >  
> > @@ -545,8 +538,8 @@ static int
> >  nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
> >  			     struct drm_file *file_priv,
> >  			     struct drm_nouveau_gem_pushbuf_bo *pbbo,
> > -			     uint64_t user_buffers, int nr_buffers,
> > -			     struct validate_op *op, int *apply_relocs)
> > +			     int nr_buffers,
> > +			     struct validate_op *op, bool *apply_relocs)
> >  {
> >  	struct nouveau_cli *cli = nouveau_cli(file_priv);
> >  	int ret;
> > @@ -563,7 +556,7 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
> >  		return ret;
> >  	}
> >  
> > -	ret = validate_list(chan, cli, &op->list, pbbo, user_buffers);
> > +	ret = validate_list(chan, cli, &op->list, pbbo);
> >  	if (unlikely(ret < 0)) {
> >  		if (ret != -ERESTARTSYS)
> >  			NV_PRINTK(err, cli, "validating bo list\n");
> > @@ -603,16 +596,12 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
> >  static int
> >  nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
> >  				struct drm_nouveau_gem_pushbuf *req,
> > +				struct drm_nouveau_gem_pushbuf_reloc *reloc,
> >  				struct drm_nouveau_gem_pushbuf_bo *bo)
> >  {
> > -	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
> >  	int ret = 0;
> >  	unsigned i;
> >  
> > -	reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
> > -	if (IS_ERR(reloc))
> > -		return PTR_ERR(reloc);
> > -
> >  	for (i = 0; i < req->nr_relocs; i++) {
> >  		struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
> >  		struct drm_nouveau_gem_pushbuf_bo *b;
> > @@ -691,11 +680,13 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
> >  	struct nouveau_drm *drm = nouveau_drm(dev);
> >  	struct drm_nouveau_gem_pushbuf *req = data;
> >  	struct drm_nouveau_gem_pushbuf_push *push;
> > +	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
> >  	struct drm_nouveau_gem_pushbuf_bo *bo;
> >  	struct nouveau_channel *chan = NULL;
> >  	struct validate_op op;
> >  	struct nouveau_fence *fence = NULL;
> > -	int i, j, ret = 0, do_reloc = 0;
> > +	int i, j, ret = 0;
> > +	bool do_reloc = false;
> >  
> >  	if (unlikely(!abi16))
> >  		return -ENOMEM;
> > @@ -753,7 +744,8 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
> >  	}
> >  
> >  	/* Validate buffer list */
> > -	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
> > +revalidate:
> > +	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo,
> >  					   req->nr_buffers, &op, &do_reloc);
> >  	if (ret) {
> >  		if (ret != -ERESTARTSYS)
> > @@ -763,7 +755,18 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
> >  
> >  	/* Apply any relocations that are required */
> >  	if (do_reloc) {
> > -		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
> > +		if (!reloc) {
> > +			validate_fini(&op, chan, NULL, bo);
> > +			reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
> > +			if (IS_ERR(reloc)) {
> > +				ret = PTR_ERR(reloc);
> > +				goto out_prevalid;
> > +			}
> > +
> > +			goto revalidate;
> > +		}
> > +
> > +		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, reloc, bo);
> >  		if (ret) {
> >  			NV_PRINTK(err, cli, "reloc apply: %d\n", ret);
> >  			goto out;
> > @@ -849,6 +852,22 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
> >  	validate_fini(&op, chan, fence, bo);
> >  	nouveau_fence_unref(&fence);
> >  
> > +	if (do_reloc) {
> > +		struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
> > +			u64_to_user_ptr(req->buffers);
> > +
> > +		for (i = 0; i < req->nr_buffers; i++) {
> > +			if (bo[i].presumed.valid)
> > +				continue;
> > +
> > +			if (copy_to_user(&upbbo[i].presumed, &bo[i].presumed,
> > +					 sizeof(bo[i].presumed))) {
> > +				ret = -EFAULT;
> > +				break;
> > +			}
> > +		}
> > +		u_free(reloc);
> > +	}
> >  out_prevalid:
> >  	u_free(bo);
> >  	u_free(push);
> > -- 
> > 2.23.0.rc1
> > 
> 
> -- 
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
@ 2019-11-05 12:30           ` Maarten Lankhorst
  0 siblings, 0 replies; 40+ messages in thread
From: Maarten Lankhorst @ 2019-11-05 12:30 UTC (permalink / raw)
  To: Daniel Vetter, DRI Development
  Cc: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	Intel Graphics Development, Ben Skeggs, Daniel Vetter

Op 05-11-2019 om 12:04 schreef Daniel Vetter:
> On Mon, Nov 04, 2019 at 06:38:00PM +0100, Daniel Vetter wrote:
>> We can't copy_*_user while holding reservations, that will (soon even
>> for nouveau) lead to deadlocks. And it breaks the cross-driver
>> contract around dma_resv.
>>
>> Fix this by adding a slowpath for when we need relocations, and by
>> pushing the writeback of the new presumed offsets to the very end.
>>
>> Aside from "it compiles" entirely untested unfortunately.
>>
>> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
>> Cc: Ilia Mirkin <imirkin@alum.mit.edu>
>> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>> Cc: Ben Skeggs <bskeggs@redhat.com>
>> Cc: nouveau@lists.freedesktop.org
> Ping for ack/review so I can land this entire series. intel-gfx-ci is all
> happy with the rebased version, so nouveau ack is the only hold-up here.

I don't feel confident reviewing this as I lack the hw, so all review caveats reply.

Having said that, this looks sane, and if it blows up we'll found out eventually. :)

Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
@ 2019-11-05 12:30           ` Maarten Lankhorst
  0 siblings, 0 replies; 40+ messages in thread
From: Maarten Lankhorst @ 2019-11-05 12:30 UTC (permalink / raw)
  To: Daniel Vetter, DRI Development
  Cc: nouveau, Intel Graphics Development, Ben Skeggs, Daniel Vetter,
	Daniel Vetter

Op 05-11-2019 om 12:04 schreef Daniel Vetter:
> On Mon, Nov 04, 2019 at 06:38:00PM +0100, Daniel Vetter wrote:
>> We can't copy_*_user while holding reservations, that will (soon even
>> for nouveau) lead to deadlocks. And it breaks the cross-driver
>> contract around dma_resv.
>>
>> Fix this by adding a slowpath for when we need relocations, and by
>> pushing the writeback of the new presumed offsets to the very end.
>>
>> Aside from "it compiles" entirely untested unfortunately.
>>
>> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
>> Cc: Ilia Mirkin <imirkin@alum.mit.edu>
>> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>> Cc: Ben Skeggs <bskeggs@redhat.com>
>> Cc: nouveau@lists.freedesktop.org
> Ping for ack/review so I can land this entire series. intel-gfx-ci is all
> happy with the rebased version, so nouveau ack is the only hold-up here.

I don't feel confident reviewing this as I lack the hw, so all review caveats reply.

Having said that, this looks sane, and if it blows up we'll found out eventually. :)

Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
@ 2019-11-05 11:04       ` Daniel Vetter
  0 siblings, 0 replies; 40+ messages in thread
From: Daniel Vetter @ 2019-11-05 11:04 UTC (permalink / raw)
  To: DRI Development
  Cc: Daniel Vetter, Intel Graphics Development, Ben Skeggs, nouveau,
	Daniel Vetter, Ilia Mirkin

On Mon, Nov 04, 2019 at 06:38:00PM +0100, Daniel Vetter wrote:
> We can't copy_*_user while holding reservations, that will (soon even
> for nouveau) lead to deadlocks. And it breaks the cross-driver
> contract around dma_resv.
> 
> Fix this by adding a slowpath for when we need relocations, and by
> pushing the writeback of the new presumed offsets to the very end.
> 
> Aside from "it compiles" entirely untested unfortunately.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Ilia Mirkin <imirkin@alum.mit.edu>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: nouveau@lists.freedesktop.org

Ping for ack/review so I can land this entire series. intel-gfx-ci is all
happy with the rebased version, so nouveau ack is the only hold-up here.
-Daniel

> ---
>  drivers/gpu/drm/nouveau/nouveau_gem.c | 57 ++++++++++++++++++---------
>  1 file changed, 38 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
> index 1324c19f4e5c..05ec8edd6a8b 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
> @@ -484,12 +484,9 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
>  
>  static int
>  validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
> -	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
> -	      uint64_t user_pbbo_ptr)
> +	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo)
>  {
>  	struct nouveau_drm *drm = chan->drm;
> -	struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
> -				(void __force __user *)(uintptr_t)user_pbbo_ptr;
>  	struct nouveau_bo *nvbo;
>  	int ret, relocs = 0;
>  
> @@ -533,10 +530,6 @@ validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
>  			b->presumed.offset = nvbo->bo.offset;
>  			b->presumed.valid = 0;
>  			relocs++;
> -
> -			if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
> -					     &b->presumed, sizeof(b->presumed)))
> -				return -EFAULT;
>  		}
>  	}
>  
> @@ -547,8 +540,8 @@ static int
>  nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
>  			     struct drm_file *file_priv,
>  			     struct drm_nouveau_gem_pushbuf_bo *pbbo,
> -			     uint64_t user_buffers, int nr_buffers,
> -			     struct validate_op *op, int *apply_relocs)
> +			     int nr_buffers,
> +			     struct validate_op *op, bool *apply_relocs)
>  {
>  	struct nouveau_cli *cli = nouveau_cli(file_priv);
>  	int ret;
> @@ -565,7 +558,7 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
>  		return ret;
>  	}
>  
> -	ret = validate_list(chan, cli, &op->list, pbbo, user_buffers);
> +	ret = validate_list(chan, cli, &op->list, pbbo);
>  	if (unlikely(ret < 0)) {
>  		if (ret != -ERESTARTSYS)
>  			NV_PRINTK(err, cli, "validating bo list\n");
> @@ -605,16 +598,12 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
>  static int
>  nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
>  				struct drm_nouveau_gem_pushbuf *req,
> +				struct drm_nouveau_gem_pushbuf_reloc *reloc,
>  				struct drm_nouveau_gem_pushbuf_bo *bo)
>  {
> -	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
>  	int ret = 0;
>  	unsigned i;
>  
> -	reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
> -	if (IS_ERR(reloc))
> -		return PTR_ERR(reloc);
> -
>  	for (i = 0; i < req->nr_relocs; i++) {
>  		struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
>  		struct drm_nouveau_gem_pushbuf_bo *b;
> @@ -693,11 +682,13 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>  	struct nouveau_drm *drm = nouveau_drm(dev);
>  	struct drm_nouveau_gem_pushbuf *req = data;
>  	struct drm_nouveau_gem_pushbuf_push *push;
> +	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
>  	struct drm_nouveau_gem_pushbuf_bo *bo;
>  	struct nouveau_channel *chan = NULL;
>  	struct validate_op op;
>  	struct nouveau_fence *fence = NULL;
> -	int i, j, ret = 0, do_reloc = 0;
> +	int i, j, ret = 0;
> +	bool do_reloc = false;
>  
>  	if (unlikely(!abi16))
>  		return -ENOMEM;
> @@ -755,7 +746,8 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>  	}
>  
>  	/* Validate buffer list */
> -	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
> +revalidate:
> +	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo,
>  					   req->nr_buffers, &op, &do_reloc);
>  	if (ret) {
>  		if (ret != -ERESTARTSYS)
> @@ -765,7 +757,18 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>  
>  	/* Apply any relocations that are required */
>  	if (do_reloc) {
> -		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
> +		if (!reloc) {
> +			validate_fini(&op, chan, NULL, bo);
> +			reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
> +			if (IS_ERR(reloc)) {
> +				ret = PTR_ERR(reloc);
> +				goto out_prevalid;
> +			}
> +
> +			goto revalidate;
> +		}
> +
> +		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, reloc, bo);
>  		if (ret) {
>  			NV_PRINTK(err, cli, "reloc apply: %d\n", ret);
>  			goto out;
> @@ -851,6 +854,22 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>  	validate_fini(&op, chan, fence, bo);
>  	nouveau_fence_unref(&fence);
>  
> +	if (do_reloc) {
> +		struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
> +			u64_to_user_ptr(req->buffers);
> +
> +		for (i = 0; i < req->nr_buffers; i++) {
> +			if (bo[i].presumed.valid)
> +				continue;
> +
> +			if (copy_to_user(&upbbo[i].presumed, &bo[i].presumed,
> +					 sizeof(bo[i].presumed))) {
> +				ret = -EFAULT;
> +				break;
> +			}
> +		}
> +		u_free(reloc);
> +	}
>  out_prevalid:
>  	u_free(bo);
>  	u_free(push);
> -- 
> 2.24.0.rc2
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
@ 2019-11-05 11:04       ` Daniel Vetter
  0 siblings, 0 replies; 40+ messages in thread
From: Daniel Vetter @ 2019-11-05 11:04 UTC (permalink / raw)
  To: DRI Development
  Cc: Daniel Vetter, Intel Graphics Development, Ben Skeggs, nouveau,
	Daniel Vetter

On Mon, Nov 04, 2019 at 06:38:00PM +0100, Daniel Vetter wrote:
> We can't copy_*_user while holding reservations, that will (soon even
> for nouveau) lead to deadlocks. And it breaks the cross-driver
> contract around dma_resv.
> 
> Fix this by adding a slowpath for when we need relocations, and by
> pushing the writeback of the new presumed offsets to the very end.
> 
> Aside from "it compiles" entirely untested unfortunately.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Ilia Mirkin <imirkin@alum.mit.edu>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: nouveau@lists.freedesktop.org

Ping for ack/review so I can land this entire series. intel-gfx-ci is all
happy with the rebased version, so nouveau ack is the only hold-up here.
-Daniel

> ---
>  drivers/gpu/drm/nouveau/nouveau_gem.c | 57 ++++++++++++++++++---------
>  1 file changed, 38 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
> index 1324c19f4e5c..05ec8edd6a8b 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
> @@ -484,12 +484,9 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
>  
>  static int
>  validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
> -	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
> -	      uint64_t user_pbbo_ptr)
> +	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo)
>  {
>  	struct nouveau_drm *drm = chan->drm;
> -	struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
> -				(void __force __user *)(uintptr_t)user_pbbo_ptr;
>  	struct nouveau_bo *nvbo;
>  	int ret, relocs = 0;
>  
> @@ -533,10 +530,6 @@ validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
>  			b->presumed.offset = nvbo->bo.offset;
>  			b->presumed.valid = 0;
>  			relocs++;
> -
> -			if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
> -					     &b->presumed, sizeof(b->presumed)))
> -				return -EFAULT;
>  		}
>  	}
>  
> @@ -547,8 +540,8 @@ static int
>  nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
>  			     struct drm_file *file_priv,
>  			     struct drm_nouveau_gem_pushbuf_bo *pbbo,
> -			     uint64_t user_buffers, int nr_buffers,
> -			     struct validate_op *op, int *apply_relocs)
> +			     int nr_buffers,
> +			     struct validate_op *op, bool *apply_relocs)
>  {
>  	struct nouveau_cli *cli = nouveau_cli(file_priv);
>  	int ret;
> @@ -565,7 +558,7 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
>  		return ret;
>  	}
>  
> -	ret = validate_list(chan, cli, &op->list, pbbo, user_buffers);
> +	ret = validate_list(chan, cli, &op->list, pbbo);
>  	if (unlikely(ret < 0)) {
>  		if (ret != -ERESTARTSYS)
>  			NV_PRINTK(err, cli, "validating bo list\n");
> @@ -605,16 +598,12 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
>  static int
>  nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
>  				struct drm_nouveau_gem_pushbuf *req,
> +				struct drm_nouveau_gem_pushbuf_reloc *reloc,
>  				struct drm_nouveau_gem_pushbuf_bo *bo)
>  {
> -	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
>  	int ret = 0;
>  	unsigned i;
>  
> -	reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
> -	if (IS_ERR(reloc))
> -		return PTR_ERR(reloc);
> -
>  	for (i = 0; i < req->nr_relocs; i++) {
>  		struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
>  		struct drm_nouveau_gem_pushbuf_bo *b;
> @@ -693,11 +682,13 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>  	struct nouveau_drm *drm = nouveau_drm(dev);
>  	struct drm_nouveau_gem_pushbuf *req = data;
>  	struct drm_nouveau_gem_pushbuf_push *push;
> +	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
>  	struct drm_nouveau_gem_pushbuf_bo *bo;
>  	struct nouveau_channel *chan = NULL;
>  	struct validate_op op;
>  	struct nouveau_fence *fence = NULL;
> -	int i, j, ret = 0, do_reloc = 0;
> +	int i, j, ret = 0;
> +	bool do_reloc = false;
>  
>  	if (unlikely(!abi16))
>  		return -ENOMEM;
> @@ -755,7 +746,8 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>  	}
>  
>  	/* Validate buffer list */
> -	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
> +revalidate:
> +	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo,
>  					   req->nr_buffers, &op, &do_reloc);
>  	if (ret) {
>  		if (ret != -ERESTARTSYS)
> @@ -765,7 +757,18 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>  
>  	/* Apply any relocations that are required */
>  	if (do_reloc) {
> -		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
> +		if (!reloc) {
> +			validate_fini(&op, chan, NULL, bo);
> +			reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
> +			if (IS_ERR(reloc)) {
> +				ret = PTR_ERR(reloc);
> +				goto out_prevalid;
> +			}
> +
> +			goto revalidate;
> +		}
> +
> +		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, reloc, bo);
>  		if (ret) {
>  			NV_PRINTK(err, cli, "reloc apply: %d\n", ret);
>  			goto out;
> @@ -851,6 +854,22 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>  	validate_fini(&op, chan, fence, bo);
>  	nouveau_fence_unref(&fence);
>  
> +	if (do_reloc) {
> +		struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
> +			u64_to_user_ptr(req->buffers);
> +
> +		for (i = 0; i < req->nr_buffers; i++) {
> +			if (bo[i].presumed.valid)
> +				continue;
> +
> +			if (copy_to_user(&upbbo[i].presumed, &bo[i].presumed,
> +					 sizeof(bo[i].presumed))) {
> +				ret = -EFAULT;
> +				break;
> +			}
> +		}
> +		u_free(reloc);
> +	}
>  out_prevalid:
>  	u_free(bo);
>  	u_free(push);
> -- 
> 2.24.0.rc2
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
@ 2019-11-04 17:38     ` Daniel Vetter
  0 siblings, 0 replies; 40+ messages in thread
From: Daniel Vetter @ 2019-11-04 17:38 UTC (permalink / raw)
  To: DRI Development
  Cc: Intel Graphics Development, Maarten Lankhorst, Ben Skeggs,
	nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW, Daniel Vetter

We can't copy_*_user while holding reservations, that will (soon even
for nouveau) lead to deadlocks. And it breaks the cross-driver
contract around dma_resv.

Fix this by adding a slowpath for when we need relocations, and by
pushing the writeback of the new presumed offsets to the very end.

Aside from "it compiles" entirely untested unfortunately.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Ilia Mirkin <imirkin@alum.mit.edu>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: nouveau@lists.freedesktop.org
---
 drivers/gpu/drm/nouveau/nouveau_gem.c | 57 ++++++++++++++++++---------
 1 file changed, 38 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
index 1324c19f4e5c..05ec8edd6a8b 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -484,12 +484,9 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
 
 static int
 validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
-	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
-	      uint64_t user_pbbo_ptr)
+	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo)
 {
 	struct nouveau_drm *drm = chan->drm;
-	struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
-				(void __force __user *)(uintptr_t)user_pbbo_ptr;
 	struct nouveau_bo *nvbo;
 	int ret, relocs = 0;
 
@@ -533,10 +530,6 @@ validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
 			b->presumed.offset = nvbo->bo.offset;
 			b->presumed.valid = 0;
 			relocs++;
-
-			if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
-					     &b->presumed, sizeof(b->presumed)))
-				return -EFAULT;
 		}
 	}
 
@@ -547,8 +540,8 @@ static int
 nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
 			     struct drm_file *file_priv,
 			     struct drm_nouveau_gem_pushbuf_bo *pbbo,
-			     uint64_t user_buffers, int nr_buffers,
-			     struct validate_op *op, int *apply_relocs)
+			     int nr_buffers,
+			     struct validate_op *op, bool *apply_relocs)
 {
 	struct nouveau_cli *cli = nouveau_cli(file_priv);
 	int ret;
@@ -565,7 +558,7 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
 		return ret;
 	}
 
-	ret = validate_list(chan, cli, &op->list, pbbo, user_buffers);
+	ret = validate_list(chan, cli, &op->list, pbbo);
 	if (unlikely(ret < 0)) {
 		if (ret != -ERESTARTSYS)
 			NV_PRINTK(err, cli, "validating bo list\n");
@@ -605,16 +598,12 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
 static int
 nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
 				struct drm_nouveau_gem_pushbuf *req,
+				struct drm_nouveau_gem_pushbuf_reloc *reloc,
 				struct drm_nouveau_gem_pushbuf_bo *bo)
 {
-	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
 	int ret = 0;
 	unsigned i;
 
-	reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
-	if (IS_ERR(reloc))
-		return PTR_ERR(reloc);
-
 	for (i = 0; i < req->nr_relocs; i++) {
 		struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
 		struct drm_nouveau_gem_pushbuf_bo *b;
@@ -693,11 +682,13 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct drm_nouveau_gem_pushbuf *req = data;
 	struct drm_nouveau_gem_pushbuf_push *push;
+	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
 	struct drm_nouveau_gem_pushbuf_bo *bo;
 	struct nouveau_channel *chan = NULL;
 	struct validate_op op;
 	struct nouveau_fence *fence = NULL;
-	int i, j, ret = 0, do_reloc = 0;
+	int i, j, ret = 0;
+	bool do_reloc = false;
 
 	if (unlikely(!abi16))
 		return -ENOMEM;
@@ -755,7 +746,8 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 	}
 
 	/* Validate buffer list */
-	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
+revalidate:
+	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo,
 					   req->nr_buffers, &op, &do_reloc);
 	if (ret) {
 		if (ret != -ERESTARTSYS)
@@ -765,7 +757,18 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 
 	/* Apply any relocations that are required */
 	if (do_reloc) {
-		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
+		if (!reloc) {
+			validate_fini(&op, chan, NULL, bo);
+			reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
+			if (IS_ERR(reloc)) {
+				ret = PTR_ERR(reloc);
+				goto out_prevalid;
+			}
+
+			goto revalidate;
+		}
+
+		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, reloc, bo);
 		if (ret) {
 			NV_PRINTK(err, cli, "reloc apply: %d\n", ret);
 			goto out;
@@ -851,6 +854,22 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 	validate_fini(&op, chan, fence, bo);
 	nouveau_fence_unref(&fence);
 
+	if (do_reloc) {
+		struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
+			u64_to_user_ptr(req->buffers);
+
+		for (i = 0; i < req->nr_buffers; i++) {
+			if (bo[i].presumed.valid)
+				continue;
+
+			if (copy_to_user(&upbbo[i].presumed, &bo[i].presumed,
+					 sizeof(bo[i].presumed))) {
+				ret = -EFAULT;
+				break;
+			}
+		}
+		u_free(reloc);
+	}
 out_prevalid:
 	u_free(bo);
 	u_free(push);
-- 
2.24.0.rc2

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
@ 2019-11-04 17:38     ` Daniel Vetter
  0 siblings, 0 replies; 40+ messages in thread
From: Daniel Vetter @ 2019-11-04 17:38 UTC (permalink / raw)
  To: DRI Development
  Cc: Daniel Vetter, Intel Graphics Development, Ben Skeggs, nouveau,
	Daniel Vetter

We can't copy_*_user while holding reservations, that will (soon even
for nouveau) lead to deadlocks. And it breaks the cross-driver
contract around dma_resv.

Fix this by adding a slowpath for when we need relocations, and by
pushing the writeback of the new presumed offsets to the very end.

Aside from "it compiles" entirely untested unfortunately.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Ilia Mirkin <imirkin@alum.mit.edu>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: nouveau@lists.freedesktop.org
---
 drivers/gpu/drm/nouveau/nouveau_gem.c | 57 ++++++++++++++++++---------
 1 file changed, 38 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
index 1324c19f4e5c..05ec8edd6a8b 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -484,12 +484,9 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
 
 static int
 validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
-	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
-	      uint64_t user_pbbo_ptr)
+	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo)
 {
 	struct nouveau_drm *drm = chan->drm;
-	struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
-				(void __force __user *)(uintptr_t)user_pbbo_ptr;
 	struct nouveau_bo *nvbo;
 	int ret, relocs = 0;
 
@@ -533,10 +530,6 @@ validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
 			b->presumed.offset = nvbo->bo.offset;
 			b->presumed.valid = 0;
 			relocs++;
-
-			if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
-					     &b->presumed, sizeof(b->presumed)))
-				return -EFAULT;
 		}
 	}
 
@@ -547,8 +540,8 @@ static int
 nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
 			     struct drm_file *file_priv,
 			     struct drm_nouveau_gem_pushbuf_bo *pbbo,
-			     uint64_t user_buffers, int nr_buffers,
-			     struct validate_op *op, int *apply_relocs)
+			     int nr_buffers,
+			     struct validate_op *op, bool *apply_relocs)
 {
 	struct nouveau_cli *cli = nouveau_cli(file_priv);
 	int ret;
@@ -565,7 +558,7 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
 		return ret;
 	}
 
-	ret = validate_list(chan, cli, &op->list, pbbo, user_buffers);
+	ret = validate_list(chan, cli, &op->list, pbbo);
 	if (unlikely(ret < 0)) {
 		if (ret != -ERESTARTSYS)
 			NV_PRINTK(err, cli, "validating bo list\n");
@@ -605,16 +598,12 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
 static int
 nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
 				struct drm_nouveau_gem_pushbuf *req,
+				struct drm_nouveau_gem_pushbuf_reloc *reloc,
 				struct drm_nouveau_gem_pushbuf_bo *bo)
 {
-	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
 	int ret = 0;
 	unsigned i;
 
-	reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
-	if (IS_ERR(reloc))
-		return PTR_ERR(reloc);
-
 	for (i = 0; i < req->nr_relocs; i++) {
 		struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
 		struct drm_nouveau_gem_pushbuf_bo *b;
@@ -693,11 +682,13 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct drm_nouveau_gem_pushbuf *req = data;
 	struct drm_nouveau_gem_pushbuf_push *push;
+	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
 	struct drm_nouveau_gem_pushbuf_bo *bo;
 	struct nouveau_channel *chan = NULL;
 	struct validate_op op;
 	struct nouveau_fence *fence = NULL;
-	int i, j, ret = 0, do_reloc = 0;
+	int i, j, ret = 0;
+	bool do_reloc = false;
 
 	if (unlikely(!abi16))
 		return -ENOMEM;
@@ -755,7 +746,8 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 	}
 
 	/* Validate buffer list */
-	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
+revalidate:
+	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo,
 					   req->nr_buffers, &op, &do_reloc);
 	if (ret) {
 		if (ret != -ERESTARTSYS)
@@ -765,7 +757,18 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 
 	/* Apply any relocations that are required */
 	if (do_reloc) {
-		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
+		if (!reloc) {
+			validate_fini(&op, chan, NULL, bo);
+			reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
+			if (IS_ERR(reloc)) {
+				ret = PTR_ERR(reloc);
+				goto out_prevalid;
+			}
+
+			goto revalidate;
+		}
+
+		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, reloc, bo);
 		if (ret) {
 			NV_PRINTK(err, cli, "reloc apply: %d\n", ret);
 			goto out;
@@ -851,6 +854,22 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 	validate_fini(&op, chan, fence, bo);
 	nouveau_fence_unref(&fence);
 
+	if (do_reloc) {
+		struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
+			u64_to_user_ptr(req->buffers);
+
+		for (i = 0; i < req->nr_buffers; i++) {
+			if (bo[i].presumed.valid)
+				continue;
+
+			if (copy_to_user(&upbbo[i].presumed, &bo[i].presumed,
+					 sizeof(bo[i].presumed))) {
+				ret = -EFAULT;
+				break;
+			}
+		}
+		u_free(reloc);
+	}
 out_prevalid:
 	u_free(bo);
 	u_free(push);
-- 
2.24.0.rc2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
@ 2019-10-24  9:04       ` Daniel Vetter
  0 siblings, 0 replies; 40+ messages in thread
From: Daniel Vetter @ 2019-10-24  9:04 UTC (permalink / raw)
  To: DRI Development, airlied
  Cc: Nouveau Dev, Intel Graphics Development, Ben Skeggs,
	Daniel Vetter, Ilia Mirkin

On Mon, Oct 21, 2019 at 4:50 PM Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
>
> We can't copy_*_user while holding reservations, that will (soon even
> for nouveau) lead to deadlocks. And it breaks the cross-driver
> contract around dma_resv.
>
> Fix this by adding a slowpath for when we need relocations, and by
> pushing the writeback of the new presumed offsets to the very end.
>
> Aside from "it compiles" entirely untested unfortunately.
>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Ilia Mirkin <imirkin@alum.mit.edu>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: nouveau@lists.freedesktop.org

Ping for review/testing/ack, I'd really like to get this in.
-Daniel

> ---
>  drivers/gpu/drm/nouveau/nouveau_gem.c | 57 ++++++++++++++++++---------
>  1 file changed, 38 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
> index 1324c19f4e5c..05ec8edd6a8b 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
> @@ -484,12 +484,9 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
>
>  static int
>  validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
> -             struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
> -             uint64_t user_pbbo_ptr)
> +             struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo)
>  {
>         struct nouveau_drm *drm = chan->drm;
> -       struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
> -                               (void __force __user *)(uintptr_t)user_pbbo_ptr;
>         struct nouveau_bo *nvbo;
>         int ret, relocs = 0;
>
> @@ -533,10 +530,6 @@ validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
>                         b->presumed.offset = nvbo->bo.offset;
>                         b->presumed.valid = 0;
>                         relocs++;
> -
> -                       if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
> -                                            &b->presumed, sizeof(b->presumed)))
> -                               return -EFAULT;
>                 }
>         }
>
> @@ -547,8 +540,8 @@ static int
>  nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
>                              struct drm_file *file_priv,
>                              struct drm_nouveau_gem_pushbuf_bo *pbbo,
> -                            uint64_t user_buffers, int nr_buffers,
> -                            struct validate_op *op, int *apply_relocs)
> +                            int nr_buffers,
> +                            struct validate_op *op, bool *apply_relocs)
>  {
>         struct nouveau_cli *cli = nouveau_cli(file_priv);
>         int ret;
> @@ -565,7 +558,7 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
>                 return ret;
>         }
>
> -       ret = validate_list(chan, cli, &op->list, pbbo, user_buffers);
> +       ret = validate_list(chan, cli, &op->list, pbbo);
>         if (unlikely(ret < 0)) {
>                 if (ret != -ERESTARTSYS)
>                         NV_PRINTK(err, cli, "validating bo list\n");
> @@ -605,16 +598,12 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
>  static int
>  nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
>                                 struct drm_nouveau_gem_pushbuf *req,
> +                               struct drm_nouveau_gem_pushbuf_reloc *reloc,
>                                 struct drm_nouveau_gem_pushbuf_bo *bo)
>  {
> -       struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
>         int ret = 0;
>         unsigned i;
>
> -       reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
> -       if (IS_ERR(reloc))
> -               return PTR_ERR(reloc);
> -
>         for (i = 0; i < req->nr_relocs; i++) {
>                 struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
>                 struct drm_nouveau_gem_pushbuf_bo *b;
> @@ -693,11 +682,13 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>         struct nouveau_drm *drm = nouveau_drm(dev);
>         struct drm_nouveau_gem_pushbuf *req = data;
>         struct drm_nouveau_gem_pushbuf_push *push;
> +       struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
>         struct drm_nouveau_gem_pushbuf_bo *bo;
>         struct nouveau_channel *chan = NULL;
>         struct validate_op op;
>         struct nouveau_fence *fence = NULL;
> -       int i, j, ret = 0, do_reloc = 0;
> +       int i, j, ret = 0;
> +       bool do_reloc = false;
>
>         if (unlikely(!abi16))
>                 return -ENOMEM;
> @@ -755,7 +746,8 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>         }
>
>         /* Validate buffer list */
> -       ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
> +revalidate:
> +       ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo,
>                                            req->nr_buffers, &op, &do_reloc);
>         if (ret) {
>                 if (ret != -ERESTARTSYS)
> @@ -765,7 +757,18 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>
>         /* Apply any relocations that are required */
>         if (do_reloc) {
> -               ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
> +               if (!reloc) {
> +                       validate_fini(&op, chan, NULL, bo);
> +                       reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
> +                       if (IS_ERR(reloc)) {
> +                               ret = PTR_ERR(reloc);
> +                               goto out_prevalid;
> +                       }
> +
> +                       goto revalidate;
> +               }
> +
> +               ret = nouveau_gem_pushbuf_reloc_apply(cli, req, reloc, bo);
>                 if (ret) {
>                         NV_PRINTK(err, cli, "reloc apply: %d\n", ret);
>                         goto out;
> @@ -851,6 +854,22 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>         validate_fini(&op, chan, fence, bo);
>         nouveau_fence_unref(&fence);
>
> +       if (do_reloc) {
> +               struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
> +                       u64_to_user_ptr(req->buffers);
> +
> +               for (i = 0; i < req->nr_buffers; i++) {
> +                       if (bo[i].presumed.valid)
> +                               continue;
> +
> +                       if (copy_to_user(&upbbo[i].presumed, &bo[i].presumed,
> +                                        sizeof(bo[i].presumed))) {
> +                               ret = -EFAULT;
> +                               break;
> +                       }
> +               }
> +               u_free(reloc);
> +       }
>  out_prevalid:
>         u_free(bo);
>         u_free(push);
> --
> 2.23.0
>


-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
@ 2019-10-24  9:04       ` Daniel Vetter
  0 siblings, 0 replies; 40+ messages in thread
From: Daniel Vetter @ 2019-10-24  9:04 UTC (permalink / raw)
  To: DRI Development, airlied
  Cc: Nouveau Dev, Intel Graphics Development, Ben Skeggs, Daniel Vetter

On Mon, Oct 21, 2019 at 4:50 PM Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
>
> We can't copy_*_user while holding reservations, that will (soon even
> for nouveau) lead to deadlocks. And it breaks the cross-driver
> contract around dma_resv.
>
> Fix this by adding a slowpath for when we need relocations, and by
> pushing the writeback of the new presumed offsets to the very end.
>
> Aside from "it compiles" entirely untested unfortunately.
>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Ilia Mirkin <imirkin@alum.mit.edu>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: nouveau@lists.freedesktop.org

Ping for review/testing/ack, I'd really like to get this in.
-Daniel

> ---
>  drivers/gpu/drm/nouveau/nouveau_gem.c | 57 ++++++++++++++++++---------
>  1 file changed, 38 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
> index 1324c19f4e5c..05ec8edd6a8b 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
> @@ -484,12 +484,9 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
>
>  static int
>  validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
> -             struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
> -             uint64_t user_pbbo_ptr)
> +             struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo)
>  {
>         struct nouveau_drm *drm = chan->drm;
> -       struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
> -                               (void __force __user *)(uintptr_t)user_pbbo_ptr;
>         struct nouveau_bo *nvbo;
>         int ret, relocs = 0;
>
> @@ -533,10 +530,6 @@ validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
>                         b->presumed.offset = nvbo->bo.offset;
>                         b->presumed.valid = 0;
>                         relocs++;
> -
> -                       if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
> -                                            &b->presumed, sizeof(b->presumed)))
> -                               return -EFAULT;
>                 }
>         }
>
> @@ -547,8 +540,8 @@ static int
>  nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
>                              struct drm_file *file_priv,
>                              struct drm_nouveau_gem_pushbuf_bo *pbbo,
> -                            uint64_t user_buffers, int nr_buffers,
> -                            struct validate_op *op, int *apply_relocs)
> +                            int nr_buffers,
> +                            struct validate_op *op, bool *apply_relocs)
>  {
>         struct nouveau_cli *cli = nouveau_cli(file_priv);
>         int ret;
> @@ -565,7 +558,7 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
>                 return ret;
>         }
>
> -       ret = validate_list(chan, cli, &op->list, pbbo, user_buffers);
> +       ret = validate_list(chan, cli, &op->list, pbbo);
>         if (unlikely(ret < 0)) {
>                 if (ret != -ERESTARTSYS)
>                         NV_PRINTK(err, cli, "validating bo list\n");
> @@ -605,16 +598,12 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
>  static int
>  nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
>                                 struct drm_nouveau_gem_pushbuf *req,
> +                               struct drm_nouveau_gem_pushbuf_reloc *reloc,
>                                 struct drm_nouveau_gem_pushbuf_bo *bo)
>  {
> -       struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
>         int ret = 0;
>         unsigned i;
>
> -       reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
> -       if (IS_ERR(reloc))
> -               return PTR_ERR(reloc);
> -
>         for (i = 0; i < req->nr_relocs; i++) {
>                 struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
>                 struct drm_nouveau_gem_pushbuf_bo *b;
> @@ -693,11 +682,13 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>         struct nouveau_drm *drm = nouveau_drm(dev);
>         struct drm_nouveau_gem_pushbuf *req = data;
>         struct drm_nouveau_gem_pushbuf_push *push;
> +       struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
>         struct drm_nouveau_gem_pushbuf_bo *bo;
>         struct nouveau_channel *chan = NULL;
>         struct validate_op op;
>         struct nouveau_fence *fence = NULL;
> -       int i, j, ret = 0, do_reloc = 0;
> +       int i, j, ret = 0;
> +       bool do_reloc = false;
>
>         if (unlikely(!abi16))
>                 return -ENOMEM;
> @@ -755,7 +746,8 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>         }
>
>         /* Validate buffer list */
> -       ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
> +revalidate:
> +       ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo,
>                                            req->nr_buffers, &op, &do_reloc);
>         if (ret) {
>                 if (ret != -ERESTARTSYS)
> @@ -765,7 +757,18 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>
>         /* Apply any relocations that are required */
>         if (do_reloc) {
> -               ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
> +               if (!reloc) {
> +                       validate_fini(&op, chan, NULL, bo);
> +                       reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
> +                       if (IS_ERR(reloc)) {
> +                               ret = PTR_ERR(reloc);
> +                               goto out_prevalid;
> +                       }
> +
> +                       goto revalidate;
> +               }
> +
> +               ret = nouveau_gem_pushbuf_reloc_apply(cli, req, reloc, bo);
>                 if (ret) {
>                         NV_PRINTK(err, cli, "reloc apply: %d\n", ret);
>                         goto out;
> @@ -851,6 +854,22 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
>         validate_fini(&op, chan, fence, bo);
>         nouveau_fence_unref(&fence);
>
> +       if (do_reloc) {
> +               struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
> +                       u64_to_user_ptr(req->buffers);
> +
> +               for (i = 0; i < req->nr_buffers; i++) {
> +                       if (bo[i].presumed.valid)
> +                               continue;
> +
> +                       if (copy_to_user(&upbbo[i].presumed, &bo[i].presumed,
> +                                        sizeof(bo[i].presumed))) {
> +                               ret = -EFAULT;
> +                               break;
> +                       }
> +               }
> +               u_free(reloc);
> +       }
>  out_prevalid:
>         u_free(bo);
>         u_free(push);
> --
> 2.23.0
>


-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
       [not found] ` <20191021145017.17384-1-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
@ 2019-10-21 14:50   ` Daniel Vetter
  2019-10-24  9:04       ` Daniel Vetter
  0 siblings, 1 reply; 40+ messages in thread
From: Daniel Vetter @ 2019-10-21 14:50 UTC (permalink / raw)
  To: DRI Development
  Cc: Intel Graphics Development, Maarten Lankhorst, Ben Skeggs,
	nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW, Daniel Vetter

We can't copy_*_user while holding reservations, that will (soon even
for nouveau) lead to deadlocks. And it breaks the cross-driver
contract around dma_resv.

Fix this by adding a slowpath for when we need relocations, and by
pushing the writeback of the new presumed offsets to the very end.

Aside from "it compiles" entirely untested unfortunately.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Ilia Mirkin <imirkin@alum.mit.edu>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: nouveau@lists.freedesktop.org
---
 drivers/gpu/drm/nouveau/nouveau_gem.c | 57 ++++++++++++++++++---------
 1 file changed, 38 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
index 1324c19f4e5c..05ec8edd6a8b 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -484,12 +484,9 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
 
 static int
 validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
-	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
-	      uint64_t user_pbbo_ptr)
+	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo)
 {
 	struct nouveau_drm *drm = chan->drm;
-	struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
-				(void __force __user *)(uintptr_t)user_pbbo_ptr;
 	struct nouveau_bo *nvbo;
 	int ret, relocs = 0;
 
@@ -533,10 +530,6 @@ validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
 			b->presumed.offset = nvbo->bo.offset;
 			b->presumed.valid = 0;
 			relocs++;
-
-			if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
-					     &b->presumed, sizeof(b->presumed)))
-				return -EFAULT;
 		}
 	}
 
@@ -547,8 +540,8 @@ static int
 nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
 			     struct drm_file *file_priv,
 			     struct drm_nouveau_gem_pushbuf_bo *pbbo,
-			     uint64_t user_buffers, int nr_buffers,
-			     struct validate_op *op, int *apply_relocs)
+			     int nr_buffers,
+			     struct validate_op *op, bool *apply_relocs)
 {
 	struct nouveau_cli *cli = nouveau_cli(file_priv);
 	int ret;
@@ -565,7 +558,7 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
 		return ret;
 	}
 
-	ret = validate_list(chan, cli, &op->list, pbbo, user_buffers);
+	ret = validate_list(chan, cli, &op->list, pbbo);
 	if (unlikely(ret < 0)) {
 		if (ret != -ERESTARTSYS)
 			NV_PRINTK(err, cli, "validating bo list\n");
@@ -605,16 +598,12 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
 static int
 nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
 				struct drm_nouveau_gem_pushbuf *req,
+				struct drm_nouveau_gem_pushbuf_reloc *reloc,
 				struct drm_nouveau_gem_pushbuf_bo *bo)
 {
-	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
 	int ret = 0;
 	unsigned i;
 
-	reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
-	if (IS_ERR(reloc))
-		return PTR_ERR(reloc);
-
 	for (i = 0; i < req->nr_relocs; i++) {
 		struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
 		struct drm_nouveau_gem_pushbuf_bo *b;
@@ -693,11 +682,13 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct drm_nouveau_gem_pushbuf *req = data;
 	struct drm_nouveau_gem_pushbuf_push *push;
+	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
 	struct drm_nouveau_gem_pushbuf_bo *bo;
 	struct nouveau_channel *chan = NULL;
 	struct validate_op op;
 	struct nouveau_fence *fence = NULL;
-	int i, j, ret = 0, do_reloc = 0;
+	int i, j, ret = 0;
+	bool do_reloc = false;
 
 	if (unlikely(!abi16))
 		return -ENOMEM;
@@ -755,7 +746,8 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 	}
 
 	/* Validate buffer list */
-	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
+revalidate:
+	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo,
 					   req->nr_buffers, &op, &do_reloc);
 	if (ret) {
 		if (ret != -ERESTARTSYS)
@@ -765,7 +757,18 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 
 	/* Apply any relocations that are required */
 	if (do_reloc) {
-		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
+		if (!reloc) {
+			validate_fini(&op, chan, NULL, bo);
+			reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
+			if (IS_ERR(reloc)) {
+				ret = PTR_ERR(reloc);
+				goto out_prevalid;
+			}
+
+			goto revalidate;
+		}
+
+		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, reloc, bo);
 		if (ret) {
 			NV_PRINTK(err, cli, "reloc apply: %d\n", ret);
 			goto out;
@@ -851,6 +854,22 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 	validate_fini(&op, chan, fence, bo);
 	nouveau_fence_unref(&fence);
 
+	if (do_reloc) {
+		struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
+			u64_to_user_ptr(req->buffers);
+
+		for (i = 0; i < req->nr_buffers; i++) {
+			if (bo[i].presumed.valid)
+				continue;
+
+			if (copy_to_user(&upbbo[i].presumed, &bo[i].presumed,
+					 sizeof(bo[i].presumed))) {
+				ret = -EFAULT;
+				break;
+			}
+		}
+		u_free(reloc);
+	}
 out_prevalid:
 	u_free(bo);
 	u_free(push);
-- 
2.23.0

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
  2019-08-20 14:53 [PATCH 0/3] RFC/T: dma_resv vs. mmap_sem Daniel Vetter
@ 2019-08-20 14:53 ` Daniel Vetter
  0 siblings, 0 replies; 40+ messages in thread
From: Daniel Vetter @ 2019-08-20 14:53 UTC (permalink / raw)
  To: DRI Development
  Cc: nouveau, Daniel Vetter, Intel Graphics Development, Ben Skeggs,
	Daniel Vetter

We can't copy_*_user while holding reservations, that will (soon even
for nouveau) lead to deadlocks. And it breaks the cross-driver
contract around dma_resv.

Fix this by adding a slowpath for when we need relocations, and by
pushing the writeback of the new presumed offsets to the very end.

Aside from "it compiles" entirely untested unfortunately.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: nouveau@lists.freedesktop.org
---
 drivers/gpu/drm/nouveau/nouveau_gem.c | 57 ++++++++++++++++++---------
 1 file changed, 38 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
index c77302f969e8..60309b997951 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -482,12 +482,9 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
 
 static int
 validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
-	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
-	      uint64_t user_pbbo_ptr)
+	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo)
 {
 	struct nouveau_drm *drm = chan->drm;
-	struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
-				(void __force __user *)(uintptr_t)user_pbbo_ptr;
 	struct nouveau_bo *nvbo;
 	int ret, relocs = 0;
 
@@ -531,10 +528,6 @@ validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
 			b->presumed.offset = nvbo->bo.offset;
 			b->presumed.valid = 0;
 			relocs++;
-
-			if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
-					     &b->presumed, sizeof(b->presumed)))
-				return -EFAULT;
 		}
 	}
 
@@ -545,8 +538,8 @@ static int
 nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
 			     struct drm_file *file_priv,
 			     struct drm_nouveau_gem_pushbuf_bo *pbbo,
-			     uint64_t user_buffers, int nr_buffers,
-			     struct validate_op *op, int *apply_relocs)
+			     int nr_buffers,
+			     struct validate_op *op, bool *apply_relocs)
 {
 	struct nouveau_cli *cli = nouveau_cli(file_priv);
 	int ret;
@@ -563,7 +556,7 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
 		return ret;
 	}
 
-	ret = validate_list(chan, cli, &op->list, pbbo, user_buffers);
+	ret = validate_list(chan, cli, &op->list, pbbo);
 	if (unlikely(ret < 0)) {
 		if (ret != -ERESTARTSYS)
 			NV_PRINTK(err, cli, "validating bo list\n");
@@ -603,16 +596,12 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
 static int
 nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
 				struct drm_nouveau_gem_pushbuf *req,
+				struct drm_nouveau_gem_pushbuf_reloc *reloc,
 				struct drm_nouveau_gem_pushbuf_bo *bo)
 {
-	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
 	int ret = 0;
 	unsigned i;
 
-	reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
-	if (IS_ERR(reloc))
-		return PTR_ERR(reloc);
-
 	for (i = 0; i < req->nr_relocs; i++) {
 		struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
 		struct drm_nouveau_gem_pushbuf_bo *b;
@@ -691,11 +680,13 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct drm_nouveau_gem_pushbuf *req = data;
 	struct drm_nouveau_gem_pushbuf_push *push;
+	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
 	struct drm_nouveau_gem_pushbuf_bo *bo;
 	struct nouveau_channel *chan = NULL;
 	struct validate_op op;
 	struct nouveau_fence *fence = NULL;
-	int i, j, ret = 0, do_reloc = 0;
+	int i, j, ret = 0;
+	bool do_reloc = false;
 
 	if (unlikely(!abi16))
 		return -ENOMEM;
@@ -753,7 +744,8 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 	}
 
 	/* Validate buffer list */
-	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
+revalidate:
+	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo,
 					   req->nr_buffers, &op, &do_reloc);
 	if (ret) {
 		if (ret != -ERESTARTSYS)
@@ -763,7 +755,18 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 
 	/* Apply any relocations that are required */
 	if (do_reloc) {
-		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
+		if (!reloc) {
+			validate_fini(&op, chan, NULL, bo);
+			reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
+			if (IS_ERR(reloc)) {
+				ret = PTR_ERR(reloc);
+				goto out_prevalid;
+			}
+
+			goto revalidate;
+		}
+
+		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, reloc, bo);
 		if (ret) {
 			NV_PRINTK(err, cli, "reloc apply: %d\n", ret);
 			goto out;
@@ -849,6 +852,22 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
 	validate_fini(&op, chan, fence, bo);
 	nouveau_fence_unref(&fence);
 
+	if (do_reloc) {
+		struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
+			u64_to_user_ptr(req->buffers);
+
+		for (i = 0; i < req->nr_buffers; i++) {
+			if (bo[i].presumed.valid)
+				continue;
+
+			if (copy_to_user(&upbbo[i].presumed, &bo[i].presumed,
+					 sizeof(bo[i].presumed))) {
+				ret = -EFAULT;
+				break;
+			}
+		}
+		u_free(reloc);
+	}
 out_prevalid:
 	u_free(bo);
 	u_free(push);
-- 
2.23.0.rc1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2019-11-05 12:30 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-21 21:50 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
     [not found] ` <20190821215030.31660-1-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
2019-08-21 21:50   ` [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl Daniel Vetter
     [not found]     ` <20190821215030.31660-2-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
2019-09-03  8:17       ` Daniel Vetter
     [not found]         ` <20190903081714.GO2112-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2019-09-18  9:29           ` Daniel Vetter
2019-08-21 21:50 ` [PATCH 3/3] drm/ttm: remove ttm_bo_wait_unreserved Daniel Vetter
2019-08-21 22:20 ` [PATCH 1/3] dma_resv: prime lockdep annotations Chris Wilson
2019-08-21 22:22 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [1/3] " Patchwork
2019-08-21 22:46 ` ✓ Fi.CI.BAT: success " Patchwork
2019-08-22  6:49 ` [PATCH] drm/ttm: remove ttm_bo_wait_unreserved Daniel Vetter
2019-08-22  7:56   ` Koenig, Christian
2019-08-22  8:47     ` Daniel Vetter
2019-08-22  9:53       ` Thomas Hellström (VMware)
2019-08-22 13:06     ` Daniel Vetter
2019-08-22 14:02       ` Koenig, Christian
2019-08-22 14:24         ` Thomas Hellström (VMware)
2019-08-22 14:30           ` Thomas Hellström (VMware)
2019-08-22  6:54 ` [PATCH] dma_resv: prime lockdep annotations Daniel Vetter
2019-08-22  7:48   ` Chris Wilson
2019-08-22  7:53   ` Koenig, Christian
2019-09-03  8:16     ` Daniel Vetter
2019-09-03  9:02       ` Koenig, Christian
2019-08-22 12:56   ` Rob Herring
2019-08-22  8:40 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with dma_resv: prime lockdep annotations (rev3) Patchwork
2019-08-22  9:16 ` ✓ Fi.CI.BAT: success " Patchwork
2019-08-22 13:07 ` [PATCH] dma_resv: prime lockdep annotations Daniel Vetter
2019-08-22 13:30   ` Thomas Hellström (VMware)
2019-08-22 13:36     ` Daniel Vetter
2019-08-22 14:56       ` Thomas Hellström (VMware)
2019-08-22 14:46 ` ✓ Fi.CI.IGT: success for series starting with [1/3] " Patchwork
2019-08-23  1:43 ` ✓ Fi.CI.IGT: success for series starting with dma_resv: prime lockdep annotations (rev3) Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2019-11-04 17:37 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
     [not found] ` <20191104173801.2972-1-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
2019-11-04 17:38   ` [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl Daniel Vetter
2019-11-04 17:38     ` Daniel Vetter
2019-11-05 11:04     ` Daniel Vetter
2019-11-05 11:04       ` Daniel Vetter
     [not found]       ` <20191105110419.GG10326-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2019-11-05 12:30         ` Maarten Lankhorst
2019-11-05 12:30           ` Maarten Lankhorst
2019-10-21 14:50 [PATCH 0/3] dma_resv lockdep annotations/priming Daniel Vetter
     [not found] ` <20191021145017.17384-1-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
2019-10-21 14:50   ` [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl Daniel Vetter
2019-10-24  9:04     ` Daniel Vetter
2019-10-24  9:04       ` Daniel Vetter
2019-08-20 14:53 [PATCH 0/3] RFC/T: dma_resv vs. mmap_sem Daniel Vetter
2019-08-20 14:53 ` [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl Daniel Vetter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.