From: Mika Kuoppala <mika.kuoppala@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/i915: Avoid refcount_inc on known zero count
Date: Wed, 29 May 2019 15:13:25 +0300 [thread overview]
Message-ID: <87imttsbkq.fsf@gaia.fi.intel.com> (raw)
In-Reply-To: <20190528154053.22004-1-chris@chris-wilson.co.uk>
Chris Wilson <chris@chris-wilson.co.uk> writes:
> In intel_wakeref_auto, we use refcount_inc_not_zero to detect the first
> use and initialise the timer. On doing so, we have to avoid using
> refcount_inc on that zero count as the debug code flags that as an
> error:
> refcount_t: increment on 0; use-after-free.
>
Yeah there are reinforced version: refcount_inc_checked, which
I failed to notice.
I guess the good news is that now we have proof that there is
someone watching our six.
> Rearrange the code so that if we know the count is 0 and we are
> initialising, we explicitly set it to 1.
>
> Fixes: b27e35ae5b18 ("drm/i915: Keep user GGTT alive for a minimum of 250ms")
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
> ---
> drivers/gpu/drm/i915/intel_wakeref.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/intel_wakeref.c b/drivers/gpu/drm/i915/intel_wakeref.c
> index c2dda5a375f0..c25ba1b5e8ba 100644
> --- a/drivers/gpu/drm/i915/intel_wakeref.c
> +++ b/drivers/gpu/drm/i915/intel_wakeref.c
> @@ -114,11 +114,11 @@ void intel_wakeref_auto(struct intel_wakeref_auto *wf, unsigned long timeout)
>
> if (!refcount_inc_not_zero(&wf->count)) {
> spin_lock_irqsave(&wf->lock, flags);
> - if (!refcount_read(&wf->count)) {
> + if (!refcount_inc_not_zero(&wf->count)) {
Ok, overflow is checked with this.
Reviewed-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
> GEM_BUG_ON(wf->wakeref);
> wf->wakeref = intel_runtime_pm_get_if_in_use(wf->i915);
> + refcount_set(&wf->count, 1);
> }
> - refcount_inc(&wf->count);
> spin_unlock_irqrestore(&wf->lock, flags);
> }
>
> --
> 2.20.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
prev parent reply other threads:[~2019-05-29 12:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-28 15:40 [PATCH] drm/i915: Avoid refcount_inc on known zero count Chris Wilson
2019-05-28 16:46 ` ✗ Fi.CI.BAT: failure for " Patchwork
2019-05-29 12:13 ` Mika Kuoppala [this message]
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=87imttsbkq.fsf@gaia.fi.intel.com \
--to=mika.kuoppala@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 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.