dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dma-fence: add might_sleep annotation to _wait()
@ 2020-05-19 13:27 Daniel Vetter
  2020-05-19 21:51 ` Chris Wilson
  2020-05-20  6:54 ` Christian König
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Vetter @ 2020-05-19 13:27 UTC (permalink / raw)
  To: DRI Development
  Cc: amd-gfx, linux-rdma, Daniel Vetter, intel-gfx, LKML,
	Chris Wilson, linaro-mm-sig, VMware Graphics, Ben Skeggs,
	Rodrigo Vivi, Alex Deucher, Daniel Vetter, linux-media,
	Christian König

Do it uncontionally, there's a separate peek function with
dma_fence_is_signalled() which can be called from atomic context.

v2: Consensus calls for an unconditional might_sleep (Chris,
Christian)

Full audit:
- dma-fence.h: Uses MAX_SCHEDULE_TIMOUT, good chance this sleeps
- dma-resv.c: Timeout always at least 1
- st-dma-fence.c: Save to sleep in testcases
- amdgpu_cs.c: Both callers are for variants of the wait ioctl
- amdgpu_device.c: Two callers in vram recover code, both right next
  to mutex_lock.
- amdgpu_vm.c: Use in the vm_wait ioctl, next to _reserve/unreserve
- remaining functions in amdgpu: All for test_ib implementations for
  various engines, caller for that looks all safe (debugfs, driver
  load, reset)
- etnaviv: another wait ioctl
- habanalabs: another wait ioctl
- nouveau_fence.c: hardcoded 15*HZ ... glorious
- nouveau_gem.c: hardcoded 2*HZ ... so not even super consistent, but
  this one does have a WARN_ON :-/ At least this one is only a
  fallback path for when kmalloc fails. Maybe this should be put onto
  some worker list instead, instead of a work per unamp ...
- i915/selftests: Hardecoded HZ / 4 or HZ / 8
- i915/gt/selftests: Going up the callchain looks safe looking at
  nearby callers
- i915/gt/intel_gt_requests.c. Wrapped in a mutex_lock
- i915/gem_i915_gem_wait.c: The i915-version which is called instead
  for i915 fences already has a might_sleep() annotation, so all good

Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
Cc: Oded Gabbay <oded.gabbay@gmail.com>
Cc: linux-media@vger.kernel.org
Cc: linaro-mm-sig@lists.linaro.org
Cc: linux-rdma@vger.kernel.org
Cc: amd-gfx@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Christian König <christian.koenig@amd.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 drivers/dma-buf/dma-fence.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index 90edf2b281b0..656e9ac2d028 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -208,6 +208,8 @@ dma_fence_wait_timeout(struct dma_fence *fence, bool intr, signed long timeout)
 	if (WARN_ON(timeout < 0))
 		return -EINVAL;
 
+	might_sleep();
+
 	trace_dma_fence_wait_start(fence);
 	if (fence->ops->wait)
 		ret = fence->ops->wait(fence, intr, timeout);
-- 
2.26.2

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

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

* Re: [PATCH] dma-fence: add might_sleep annotation to _wait()
  2020-05-19 13:27 [PATCH] dma-fence: add might_sleep annotation to _wait() Daniel Vetter
@ 2020-05-19 21:51 ` Chris Wilson
  2020-05-20  6:54 ` Christian König
  1 sibling, 0 replies; 4+ messages in thread
From: Chris Wilson @ 2020-05-19 21:51 UTC (permalink / raw)
  To: DRI Development, Daniel Vetter
  Cc: amd-gfx, linux-rdma, Daniel Vetter, intel-gfx, LKML,
	linaro-mm-sig, VMware Graphics, Ben Skeggs, Rodrigo Vivi,
	Alex Deucher, Daniel Vetter, linux-media, Christian König

Quoting Daniel Vetter (2020-05-19 14:27:56)
> Do it uncontionally, there's a separate peek function with
> dma_fence_is_signalled() which can be called from atomic context.
> 
> v2: Consensus calls for an unconditional might_sleep (Chris,
> Christian)
> 
> Full audit:
> - dma-fence.h: Uses MAX_SCHEDULE_TIMOUT, good chance this sleeps
> - dma-resv.c: Timeout always at least 1
> - st-dma-fence.c: Save to sleep in testcases
> - amdgpu_cs.c: Both callers are for variants of the wait ioctl
> - amdgpu_device.c: Two callers in vram recover code, both right next
>   to mutex_lock.
> - amdgpu_vm.c: Use in the vm_wait ioctl, next to _reserve/unreserve
> - remaining functions in amdgpu: All for test_ib implementations for
>   various engines, caller for that looks all safe (debugfs, driver
>   load, reset)
> - etnaviv: another wait ioctl
> - habanalabs: another wait ioctl
> - nouveau_fence.c: hardcoded 15*HZ ... glorious
> - nouveau_gem.c: hardcoded 2*HZ ... so not even super consistent, but
>   this one does have a WARN_ON :-/ At least this one is only a
>   fallback path for when kmalloc fails. Maybe this should be put onto
>   some worker list instead, instead of a work per unamp ...
> - i915/selftests: Hardecoded HZ / 4 or HZ / 8
> - i915/gt/selftests: Going up the callchain looks safe looking at
>   nearby callers
> - i915/gt/intel_gt_requests.c. Wrapped in a mutex_lock
> - i915/gem_i915_gem_wait.c: The i915-version which is called instead
>   for i915 fences already has a might_sleep() annotation, so all good
> 
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: Lucas Stach <l.stach@pengutronix.de>
> Cc: Jani Nikula <jani.nikula@linux.intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
> Cc: Oded Gabbay <oded.gabbay@gmail.com>
> Cc: linux-media@vger.kernel.org
> Cc: linaro-mm-sig@lists.linaro.org
> Cc: linux-rdma@vger.kernel.org
> Cc: amd-gfx@lists.freedesktop.org
> Cc: intel-gfx@lists.freedesktop.org
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Christian König <christian.koenig@amd.com>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> ---
>  drivers/dma-buf/dma-fence.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
> index 90edf2b281b0..656e9ac2d028 100644
> --- a/drivers/dma-buf/dma-fence.c
> +++ b/drivers/dma-buf/dma-fence.c
> @@ -208,6 +208,8 @@ dma_fence_wait_timeout(struct dma_fence *fence, bool intr, signed long timeout)
>         if (WARN_ON(timeout < 0))
>                 return -EINVAL;
>  
> +       might_sleep();

git grep matches your synopsis.

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

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

* Re: [PATCH] dma-fence: add might_sleep annotation to _wait()
  2020-05-19 13:27 [PATCH] dma-fence: add might_sleep annotation to _wait() Daniel Vetter
  2020-05-19 21:51 ` Chris Wilson
@ 2020-05-20  6:54 ` Christian König
  2020-05-20 11:03   ` Daniel Vetter
  1 sibling, 1 reply; 4+ messages in thread
From: Christian König @ 2020-05-20  6:54 UTC (permalink / raw)
  To: Daniel Vetter, DRI Development
  Cc: amd-gfx, linux-rdma, intel-gfx, LKML, Chris Wilson,
	linaro-mm-sig, VMware Graphics, Ben Skeggs, Rodrigo Vivi,
	Alex Deucher, Daniel Vetter, linux-media

Am 19.05.20 um 15:27 schrieb Daniel Vetter:
> Do it uncontionally, there's a separate peek function with
> dma_fence_is_signalled() which can be called from atomic context.
>
> v2: Consensus calls for an unconditional might_sleep (Chris,
> Christian)
>
> Full audit:
> - dma-fence.h: Uses MAX_SCHEDULE_TIMOUT, good chance this sleeps
> - dma-resv.c: Timeout always at least 1
> - st-dma-fence.c: Save to sleep in testcases
> - amdgpu_cs.c: Both callers are for variants of the wait ioctl
> - amdgpu_device.c: Two callers in vram recover code, both right next
>    to mutex_lock.
> - amdgpu_vm.c: Use in the vm_wait ioctl, next to _reserve/unreserve
> - remaining functions in amdgpu: All for test_ib implementations for
>    various engines, caller for that looks all safe (debugfs, driver
>    load, reset)
> - etnaviv: another wait ioctl
> - habanalabs: another wait ioctl
> - nouveau_fence.c: hardcoded 15*HZ ... glorious
> - nouveau_gem.c: hardcoded 2*HZ ... so not even super consistent, but
>    this one does have a WARN_ON :-/ At least this one is only a
>    fallback path for when kmalloc fails. Maybe this should be put onto
>    some worker list instead, instead of a work per unamp ...
> - i915/selftests: Hardecoded HZ / 4 or HZ / 8
> - i915/gt/selftests: Going up the callchain looks safe looking at
>    nearby callers
> - i915/gt/intel_gt_requests.c. Wrapped in a mutex_lock
> - i915/gem_i915_gem_wait.c: The i915-version which is called instead
>    for i915 fences already has a might_sleep() annotation, so all good
>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: Lucas Stach <l.stach@pengutronix.de>
> Cc: Jani Nikula <jani.nikula@linux.intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
> Cc: Oded Gabbay <oded.gabbay@gmail.com>
> Cc: linux-media@vger.kernel.org
> Cc: linaro-mm-sig@lists.linaro.org
> Cc: linux-rdma@vger.kernel.org
> Cc: amd-gfx@lists.freedesktop.org
> Cc: intel-gfx@lists.freedesktop.org
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Christian König <christian.koenig@amd.com>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>

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

> ---
>   drivers/dma-buf/dma-fence.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
> index 90edf2b281b0..656e9ac2d028 100644
> --- a/drivers/dma-buf/dma-fence.c
> +++ b/drivers/dma-buf/dma-fence.c
> @@ -208,6 +208,8 @@ dma_fence_wait_timeout(struct dma_fence *fence, bool intr, signed long timeout)
>   	if (WARN_ON(timeout < 0))
>   		return -EINVAL;
>   
> +	might_sleep();
> +
>   	trace_dma_fence_wait_start(fence);
>   	if (fence->ops->wait)
>   		ret = fence->ops->wait(fence, intr, timeout);

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

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

* Re: [PATCH] dma-fence: add might_sleep annotation to _wait()
  2020-05-20  6:54 ` Christian König
@ 2020-05-20 11:03   ` Daniel Vetter
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Vetter @ 2020-05-20 11:03 UTC (permalink / raw)
  To: Christian König
  Cc: amd-gfx, linux-rdma, Daniel Vetter, intel-gfx, LKML,
	Chris Wilson, linaro-mm-sig, Ben Skeggs, VMware Graphics,
	DRI Development, Rodrigo Vivi, Alex Deucher, Daniel Vetter,
	linux-media

On Wed, May 20, 2020 at 08:54:36AM +0200, Christian König wrote:
> Am 19.05.20 um 15:27 schrieb Daniel Vetter:
> > Do it uncontionally, there's a separate peek function with
> > dma_fence_is_signalled() which can be called from atomic context.
> > 
> > v2: Consensus calls for an unconditional might_sleep (Chris,
> > Christian)
> > 
> > Full audit:
> > - dma-fence.h: Uses MAX_SCHEDULE_TIMOUT, good chance this sleeps
> > - dma-resv.c: Timeout always at least 1
> > - st-dma-fence.c: Save to sleep in testcases
> > - amdgpu_cs.c: Both callers are for variants of the wait ioctl
> > - amdgpu_device.c: Two callers in vram recover code, both right next
> >    to mutex_lock.
> > - amdgpu_vm.c: Use in the vm_wait ioctl, next to _reserve/unreserve
> > - remaining functions in amdgpu: All for test_ib implementations for
> >    various engines, caller for that looks all safe (debugfs, driver
> >    load, reset)
> > - etnaviv: another wait ioctl
> > - habanalabs: another wait ioctl
> > - nouveau_fence.c: hardcoded 15*HZ ... glorious
> > - nouveau_gem.c: hardcoded 2*HZ ... so not even super consistent, but
> >    this one does have a WARN_ON :-/ At least this one is only a
> >    fallback path for when kmalloc fails. Maybe this should be put onto
> >    some worker list instead, instead of a work per unamp ...
> > - i915/selftests: Hardecoded HZ / 4 or HZ / 8
> > - i915/gt/selftests: Going up the callchain looks safe looking at
> >    nearby callers
> > - i915/gt/intel_gt_requests.c. Wrapped in a mutex_lock
> > - i915/gem_i915_gem_wait.c: The i915-version which is called instead
> >    for i915 fences already has a might_sleep() annotation, so all good
> > 
> > Cc: Alex Deucher <alexander.deucher@amd.com>
> > Cc: Lucas Stach <l.stach@pengutronix.de>
> > Cc: Jani Nikula <jani.nikula@linux.intel.com>
> > Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> > Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> > Cc: Ben Skeggs <bskeggs@redhat.com>
> > Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
> > Cc: Oded Gabbay <oded.gabbay@gmail.com>
> > Cc: linux-media@vger.kernel.org
> > Cc: linaro-mm-sig@lists.linaro.org
> > Cc: linux-rdma@vger.kernel.org
> > Cc: amd-gfx@lists.freedesktop.org
> > Cc: intel-gfx@lists.freedesktop.org
> > Cc: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> > Cc: Christian König <christian.koenig@amd.com>
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> 
> Reviewed-by: Christian König <christian.koenig@amd.com>

intel-gfx-ci approves too, thanks to both of you for reviews, patch merged
to drm-misc-next.
-Daniel

> 
> > ---
> >   drivers/dma-buf/dma-fence.c | 2 ++
> >   1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
> > index 90edf2b281b0..656e9ac2d028 100644
> > --- a/drivers/dma-buf/dma-fence.c
> > +++ b/drivers/dma-buf/dma-fence.c
> > @@ -208,6 +208,8 @@ dma_fence_wait_timeout(struct dma_fence *fence, bool intr, signed long timeout)
> >   	if (WARN_ON(timeout < 0))
> >   		return -EINVAL;
> > +	might_sleep();
> > +
> >   	trace_dma_fence_wait_start(fence);
> >   	if (fence->ops->wait)
> >   		ret = fence->ops->wait(fence, intr, timeout);
> 

-- 
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] 4+ messages in thread

end of thread, other threads:[~2020-05-20 11:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19 13:27 [PATCH] dma-fence: add might_sleep annotation to _wait() Daniel Vetter
2020-05-19 21:51 ` Chris Wilson
2020-05-20  6:54 ` Christian König
2020-05-20 11:03   ` Daniel Vetter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).