All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: Mika Kuoppala <mika.kuoppala@linux.intel.com>,
	intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 25/33] drm/i915: Move object close under its own lock
Date: Wed, 22 May 2019 15:52:12 +0100	[thread overview]
Message-ID: <155853673288.28319.12696768527763712185@skylake-alporthouse-com> (raw)
In-Reply-To: <87mujepnjx.fsf@gaia.fi.intel.com>

Quoting Mika Kuoppala (2019-05-22 15:32:34)
> Chris Wilson <chris@chris-wilson.co.uk> writes:
> > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> > index 5016a3e1f863..a9608d9ced6a 100644
> > --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
> > +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> > @@ -95,24 +95,42 @@ void i915_lut_handle_free(struct i915_lut_handle *lut)
> >  
> >  static void lut_close(struct i915_gem_context *ctx)
> >  {
> > -     struct i915_lut_handle *lut, *ln;
> >       struct radix_tree_iter iter;
> >       void __rcu **slot;
> >  
> > -     list_for_each_entry_safe(lut, ln, &ctx->handles_list, ctx_link) {
> > -             list_del(&lut->obj_link);
> > -             i915_lut_handle_free(lut);
> > -     }
> > -     INIT_LIST_HEAD(&ctx->handles_list);
> > +     lockdep_assert_held(&ctx->mutex);
> >  
> >       rcu_read_lock();
> >       radix_tree_for_each_slot(slot, &ctx->handles_vma, &iter, 0) {
> >               struct i915_vma *vma = rcu_dereference_raw(*slot);
> > -
> > -             radix_tree_iter_delete(&ctx->handles_vma, &iter, slot);
> > -
> > -             vma->open_count--;
> > -             i915_vma_put(vma);
> > +             struct drm_i915_gem_object *obj = vma->obj;
> > +             struct i915_lut_handle *lut;
> > +             bool found = false;
> > +
> > +             rcu_read_unlock();
> > +             i915_gem_object_lock(obj);
> > +             list_for_each_entry(lut, &obj->lut_list, obj_link) {
> > +                     if (lut->ctx != ctx)
> > +                             continue;
> > +
> > +                     if (lut->handle != iter.index)
> > +                             continue;
> > +
> > +                     list_del(&lut->obj_link);
> > +                     i915_lut_handle_free(lut);
> 
> You could free this after object_unlock if you want. Shrug.
> 
> > +                     found = true;
> > +                     break;
> > +             }
> > +             i915_gem_object_unlock(obj);
> > +             rcu_read_lock();
> > +
> > +             if (found) {
> > +                     radix_tree_iter_delete(&ctx->handles_vma, &iter, slot);
> > +                     if (atomic_dec_and_test(&vma->open_count) &&
> > +                         !i915_vma_is_ggtt(vma))
> > +                             i915_vma_close(vma);
> > +                     i915_gem_object_put(obj);
> 
> I am strugging to pair this with get.

[snip]

> >  #endif /* __I915_GEM_CONTEXT_TYPES_H__ */
> > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
> > index 13ab2a2e0099..fa0a880ca4de 100644
> > --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
> > +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
> > @@ -801,9 +801,6 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb)
> >       unsigned int i, batch;
> >       int err;
> >  
> > -     if (unlikely(i915_gem_context_is_closed(eb->gem_context)))
> > -             return -ENOENT;
> > -
> >       if (unlikely(i915_gem_context_is_banned(eb->gem_context)))
> >               return -EIO;
> >  
> > @@ -812,6 +809,12 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb)
> >  
> >       batch = eb_batch_index(eb);
> >  
> > +     mutex_lock(&eb->gem_context->mutex);
> > +     if (unlikely(i915_gem_context_is_closed(eb->gem_context))) {
> > +             err = -ENOENT;
> > +             goto err_ctx;
> > +     }
> > +
> >       for (i = 0; i < eb->buffer_count; i++) {
> >               u32 handle = eb->exec[i].handle;
> >               struct i915_lut_handle *lut;
> > @@ -846,12 +849,14 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb)
> >               }
> >  
> >               /* transfer ref to ctx */

It is this reference that we transfer from the object lookup into the
lut, that we must release if we throwaway the lut.

> > -             if (!vma->open_count++)
> > +             if (!atomic_fetch_inc(&vma->open_count))
> >                       i915_vma_reopen(vma);
> > -             list_add(&lut->obj_link, &obj->lut_list);
> > -             list_add(&lut->ctx_link, &eb->gem_context->handles_list);
> > -             lut->ctx = eb->gem_context;
> >               lut->handle = handle;
> > +             lut->ctx = eb->gem_context;
> > +
> > +             i915_gem_object_lock(obj);
> > +             list_add(&lut->obj_link, &obj->lut_list);
> > +             i915_gem_object_unlock(obj);

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

  parent reply	other threads:[~2019-05-22 14:52 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-20  8:00 [PATCH 01/33] drm/i915: Restore control over ppgtt for context creation ABI Chris Wilson
2019-05-20  8:00 ` [PATCH 02/33] drm/i915: Allow a context to define its set of engines Chris Wilson
2019-05-20  8:00 ` [PATCH 03/33] drm/i915: Extend I915_CONTEXT_PARAM_SSEU to support local ctx->engine[] Chris Wilson
2019-05-20  8:00 ` [PATCH 04/33] drm/i915: Re-expose SINGLE_TIMELINE flags for context creation Chris Wilson
2019-05-20  8:00 ` [PATCH 05/33] drm/i915: Allow userspace to clone contexts on creation Chris Wilson
2019-05-20  8:01 ` [PATCH 06/33] drm/i915: Load balancing across a virtual engine Chris Wilson
2019-05-20  8:01 ` [PATCH 07/33] drm/i915: Apply an execution_mask to the virtual_engine Chris Wilson
2019-05-20  8:01 ` [PATCH 08/33] drm/i915: Extend execution fence to support a callback Chris Wilson
2019-05-20  8:01 ` [PATCH 09/33] drm/i915/execlists: Virtual engine bonding Chris Wilson
2019-05-20  8:01 ` [PATCH 10/33] drm/i915: Allow specification of parallel execbuf Chris Wilson
2019-05-20  8:01 ` [PATCH 11/33] drm/i915: Split GEM object type definition to its own header Chris Wilson
2019-05-20  8:01 ` [PATCH 12/33] drm/i915: Pull GEM ioctls interface to its own file Chris Wilson
2019-05-20  8:01 ` [PATCH 13/33] drm/i915: Move object->pages API to i915_gem_object.[ch] Chris Wilson
2019-05-20  8:01 ` [PATCH 14/33] drm/i915: Move shmem object setup to its own file Chris Wilson
2019-05-20  8:01 ` [PATCH 15/33] drm/i915: Move phys objects " Chris Wilson
2019-05-20  8:01 ` [PATCH 16/33] drm/i915: Move mmap and friends " Chris Wilson
2019-05-20  8:01 ` [PATCH 17/33] drm/i915: Move GEM domain management " Chris Wilson
2019-05-20  8:01 ` [PATCH 18/33] drm/i915: Move more GEM objects under gem/ Chris Wilson
2019-05-20 12:58   ` Mika Kuoppala
2019-05-20  8:01 ` [PATCH 19/33] drm/i915: Pull scatterlist utils out of i915_gem.h Chris Wilson
2019-05-20  8:01 ` [PATCH 20/33] drm/i915: Move GEM object domain management from struct_mutex to local Chris Wilson
2019-05-20  8:01 ` [PATCH 21/33] drm/i915: Move GEM object waiting to its own file Chris Wilson
2019-05-20  8:01 ` [PATCH 22/33] drm/i915: Move GEM object busy checking " Chris Wilson
2019-05-20  8:01 ` [PATCH 23/33] drm/i915: Move GEM client throttling " Chris Wilson
2019-05-20  8:01 ` [PATCH 24/33] drm/i915: Drop the deferred active reference Chris Wilson
2019-05-20  8:01 ` [PATCH 25/33] drm/i915: Move object close under its own lock Chris Wilson
2019-05-22 14:32   ` Mika Kuoppala
2019-05-22 14:47     ` Chris Wilson
2019-05-22 14:52     ` Chris Wilson [this message]
2019-05-20  8:01 ` [PATCH 26/33] drm/i915: Rename intel_context.active to .inflight Chris Wilson
2019-05-20  8:01 ` [PATCH 27/33] drm/i915: Keep contexts pinned until after the next kernel context switch Chris Wilson
2019-05-20  8:01 ` [PATCH 28/33] drm/i915: Stop retiring along engine Chris Wilson
2019-05-20  8:01 ` [PATCH 29/33] drm/i915: Replace engine->timeline with a plain list Chris Wilson
2019-05-20  8:01 ` [PATCH 30/33] drm/i915: Flush the execution-callbacks on retiring Chris Wilson
2019-05-20  8:01 ` [PATCH 31/33] drm/i915/execlists: Preempt-to-busy Chris Wilson
2019-05-20  8:01 ` [PATCH 32/33] drm/i915/execlists: Minimalistic timeslicing Chris Wilson
2019-05-20  8:01 ` [PATCH 33/33] drm/i915/execlists: Force preemption Chris Wilson
2019-05-20 13:05 ` ✗ Fi.CI.BAT: failure for series starting with [01/33] drm/i915: Restore control over ppgtt for context creation ABI 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=155853673288.28319.12696768527763712185@skylake-alporthouse-com \
    --to=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=mika.kuoppala@linux.intel.com \
    /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.