public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/i915: Avoid uninterruptible spinning in debugfs
Date: Fri, 1 Feb 2019 17:29:45 +0000	[thread overview]
Message-ID: <fd2ef1f1-3076-4e68-fa1c-26f2b7d2294f@linux.intel.com> (raw)
In-Reply-To: <20190201105237.12663-1-chris@chris-wilson.co.uk>


On 01/02/2019 10:52, Chris Wilson wrote:
> If we get caught in a kernel bug, we may never idle. Let the user regain
> control of their system^Wterminal by responding to SIGINT!
> 
> v2: Push the signal checking into the loop around flush_work.
> 
> Reported-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> ---
>   drivers/gpu/drm/i915/i915_debugfs.c            | 14 ++++++++------
>   drivers/gpu/drm/i915/i915_gem.c                | 10 +++++++---
>   drivers/gpu/drm/i915/i915_utils.h              | 18 +++++++++++++++---
>   .../gpu/drm/i915/selftests/i915_gem_context.c  |  5 ++++-
>   4 files changed, 34 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> index f3fa31d840f5..44fa34f4ebbc 100644
> --- a/drivers/gpu/drm/i915/i915_debugfs.c
> +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> @@ -3945,12 +3945,14 @@ i915_drop_caches_set(void *data, u64 val)
>   		i915_gem_shrink_all(i915);
>   	fs_reclaim_release(GFP_KERNEL);
>   
> -	if (val & DROP_IDLE) {
> -		do {
> -			if (READ_ONCE(i915->gt.active_requests))
> -				flush_delayed_work(&i915->gt.retire_work);
> -			drain_delayed_work(&i915->gt.idle_work);
> -		} while (READ_ONCE(i915->gt.awake));
> +	if (val & DROP_IDLE && READ_ONCE(i915->gt.awake)) {
> +		if (drain_delayed_work_state(&i915->gt.retire_work,
> +					     TASK_INTERRUPTIBLE) ||
> +		    drain_delayed_work_state(&i915->gt.idle_work,
> +					     TASK_INTERRUPTIBLE)) {
> +			ret = -EINTR;
> +			goto out;
> +		}

Shrinker remains only killable so still not Ctrl-C in all cases here. 
Don't know, not hot not cold. Will re-think it next week.

>   	}
>   
>   	if (val & DROP_FREED)
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index 4067eeaee78a..e47d53e9b634 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -4499,13 +4499,17 @@ int i915_gem_suspend(struct drm_i915_private *i915)
>   	mutex_unlock(&i915->drm.struct_mutex);
>   	i915_reset_flush(i915);
>   
> -	drain_delayed_work(&i915->gt.retire_work);
> -
>   	/*
>   	 * As the idle_work is rearming if it detects a race, play safe and
>   	 * repeat the flush until it is definitely idle.
>   	 */
> -	drain_delayed_work(&i915->gt.idle_work);
> +	if (drain_delayed_work_state(&i915->gt.retire_work,
> +				     TASK_INTERRUPTIBLE) ||
> +	    drain_delayed_work_state(&i915->gt.idle_work,
> +				     TASK_INTERRUPTIBLE)) {
> +		ret = -EINTR;
> +		goto err_unlock;
> +	}

I'm no suspend expert but it sounds unexpected there would be signals 
involved in the process. Does it have an userspace component? We don't 
bother with interruptible mutex on this path either.

>   
>   	/*
>   	 * Assert that we successfully flushed all the work and
> diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
> index fcc751aa1ea8..6866b85e4239 100644
> --- a/drivers/gpu/drm/i915/i915_utils.h
> +++ b/drivers/gpu/drm/i915/i915_utils.h
> @@ -25,6 +25,8 @@
>   #ifndef __I915_UTILS_H
>   #define __I915_UTILS_H
>   
> +#include <linux/sched/signal.h>
> +
>   #undef WARN_ON
>   /* Many gcc seem to no see through this and fall over :( */
>   #if 0
> @@ -148,12 +150,22 @@ static inline void __list_del_many(struct list_head *head,
>    * by requeueing itself. Note, that if the worker never cancels itself,
>    * we will spin forever.
>    */
> -static inline void drain_delayed_work(struct delayed_work *dw)
> +
> +static inline int drain_delayed_work_state(struct delayed_work *dw, int state)
>   {
>   	do {
> -		while (flush_delayed_work(dw))
> -			;
> +		do {
> +			if (signal_pending_state(state, current))
> +				return -EINTR;
> +		} while (flush_delayed_work(dw));
>   	} while (delayed_work_pending(dw));
> +
> +	return 0;
> +}
> +
> +static inline void drain_delayed_work(struct delayed_work *dw)
> +{
> +	drain_delayed_work_state(dw, 0);

0 would be TASK_RUNNING. signal_pending_state bails out in this case so 
that's good.

>   }
>   
>   static inline const char *yesno(bool v)
> diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_context.c b/drivers/gpu/drm/i915/selftests/i915_gem_context.c
> index 2b423128002c..a87998b90bf6 100644
> --- a/drivers/gpu/drm/i915/selftests/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/selftests/i915_gem_context.c
> @@ -1686,8 +1686,11 @@ static int __igt_switch_to_kernel_context(struct drm_i915_private *i915,
>   		/* XXX Bonus points for proving we are the kernel context! */
>   
>   		mutex_unlock(&i915->drm.struct_mutex);
> -		drain_delayed_work(&i915->gt.idle_work);
> +		err = drain_delayed_work_state(&i915->gt.idle_work,
> +					       TASK_KILLABLE);
>   		mutex_lock(&i915->drm.struct_mutex);
> +		if (err)
> +			return -EINTR;
>   	}
>   
>   	if (igt_flush_test(i915, I915_WAIT_LOCKED))
> 

Regards,

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

  reply	other threads:[~2019-02-01 17:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-01 10:22 [PATCH] drm/i915: Avoid uninterruptible spinning in debugfs Chris Wilson
2019-02-01 10:28 ` Chris Wilson
2019-02-01 10:52 ` Chris Wilson
2019-02-01 17:29   ` Tvrtko Ursulin [this message]
2019-02-01 17:32     ` Chris Wilson
2019-02-01 10:58 ` ✗ Fi.CI.BAT: failure for drm/i915: Avoid uninterruptible spinning in debugfs (rev2) Patchwork
2019-02-01 11:01 ` ✓ Fi.CI.BAT: success for drm/i915: Avoid uninterruptible spinning in debugfs Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fd2ef1f1-3076-4e68-fa1c-26f2b7d2294f@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox