All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mika Kuoppala <mika.kuoppala@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 2/2] drm/i915: Avoid unguarded reads from the request pointer
Date: Mon, 06 Feb 2017 17:04:01 +0200	[thread overview]
Message-ID: <87r33bs6n2.fsf@gaia.fi.intel.com> (raw)
In-Reply-To: <20170206141609.GM12434@nuc-i3427.alporthouse.com>

Chris Wilson <chris@chris-wilson.co.uk> writes:

> On Mon, Feb 06, 2017 at 03:57:47PM +0200, Mika Kuoppala wrote:
>> Chris Wilson <chris@chris-wilson.co.uk> writes:
>> 
>> > In commit 86aa7e760a67 ("drm/i915: Assert that the context-switch
>> > completion matches our context") I added a read to the irq tasklet
>> > handler that compared the on-chip status with that of our sw tracking,
>> > using an unguarded read of the request pointer to get the context and
>> > beyond. Whilst we hold a reference to the request, we do not hold
>> > anything on the context and if we are unlucky it may be reaped from a
>> > second thread retiring the request (since it may retire the request as
>> > soon as the breadcrumb is complete, even before we finish processing the
>> > context switch) as we try to read from the context pointer.
>> >
>> 
>> Please add warning of the possibility of context vanishing beneath
>> our feet. Perhaps a good spot is when we store a bug on variable
>> context_id.
>
> diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
> index c6c5050c79c0..937e2af2da64 100644
> --- a/drivers/gpu/drm/i915/intel_lrc.c
> +++ b/drivers/gpu/drm/i915/intel_lrc.c
> @@ -564,6 +564,22 @@ static void intel_lrc_irq_handler(unsigned long data)
>                         unsigned int idx = ++head % GEN8_CSB_ENTRIES;
>                         unsigned int status = readl(buf + 2 * idx);
>  
> +                       /* We are flying near dragons again.
> +                        *
> +                        * We hold a reference to the request in execlist_port[]
> +                        * but no more than that. We are operating in softirq
> +                        * context and so cannot hold any mutex or sleep. That
> +                        * prevents us stopping the requests we are processing
> +                        * in port[] from being retired simultaneously (the
> +                        * breadcrumb will be complete before we see the
> +                        * context-switch). As we only hold the reference to
> +                        * request, any pointer chasing underneath the request
> +                        * is subject to a potential use-after-free. Thus we
> +                        * store all of the bookkeeping within port[], if
> +                        * required, and avoid using request itself. The
> +                        * same applies to the atomic status notifier.
> +                        */
> +

Agreed that it is better in this spot and that any pointer chasing
will lead to trouble.

-Mika

>                         if (!(status & GEN8_CTX_STATUS_COMPLETED_MASK))
>                                 continue;
>
> -- 
> Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2017-02-06 15:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-06 13:25 [PATCH 1/2] drm/i915: Mark the end of intel_ring_begin() and check in intel_ring_advance() Chris Wilson
2017-02-06 13:25 ` [PATCH 2/2] drm/i915: Avoid unguarded reads from the request pointer Chris Wilson
2017-02-06 13:57   ` Mika Kuoppala
2017-02-06 14:06     ` Chris Wilson
2017-02-06 14:16     ` Chris Wilson
2017-02-06 15:04       ` Mika Kuoppala [this message]
2017-02-06 14:01   ` Mika Kuoppala
2017-02-06 13:53 ` [PATCH 1/2] drm/i915: Mark the end of intel_ring_begin() and check in intel_ring_advance() Mika Kuoppala
2017-02-06 18:54 ` ✗ Fi.CI.BAT: failure for series starting with [1/2] " 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=87r33bs6n2.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.