From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Subject: Re: [Intel-gfx] [PATCH 2/7] drm/i915/gt: Protect context lifetime with RCU
Date: Fri, 7 Aug 2020 12:31:39 +0100 [thread overview]
Message-ID: <5bf59216-e857-598d-2f79-a79481b40892@linux.intel.com> (raw)
In-Reply-To: <159679886876.9674.7609264645683877304@build.alporthouse.com>
On 07/08/2020 12:14, Chris Wilson wrote:
> Quoting Tvrtko Ursulin (2020-08-07 11:08:59)
>>
>> On 07/08/2020 09:32, Chris Wilson wrote:
>>> +static void __intel_context_ctor(void *arg)
>>> +{
>>> + struct intel_context *ce = arg;
>>> +
>>> + INIT_LIST_HEAD(&ce->signal_link);
>>> + INIT_LIST_HEAD(&ce->signals);
>>> +
>>> + atomic_set(&ce->pin_count, 0);
>>> + mutex_init(&ce->pin_mutex);
>>> +
>>> + ce->active_count = 0;
>>> + i915_active_init(&ce->active,
>>> + __intel_context_active, __intel_context_retire);
>>> +
>>> + ce->inflight = NULL;
>>> + ce->lrc_reg_state = NULL;
>>> + ce->lrc.desc = 0;
>>> +}
>>> +
>>> +static void
>>> +__intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)
>>> +{
>>> + GEM_BUG_ON(!engine->cops);
>>> + GEM_BUG_ON(!engine->gt->vm);
>>> +
>>> + kref_init(&ce->ref);
>>> + i915_active_reinit(&ce->active);
>>> +
>>> + ce->engine = engine;
>>> + ce->ops = engine->cops;
>>> + ce->sseu = engine->sseu;
>>> +
>>> + ce->wa_bb_page = 0;
>>> + ce->flags = 0;
>>> + ce->tag = 0;
>>> +
>>> + memset(&ce->runtime, 0, sizeof(ce->runtime));
>>> +
>>> + ce->vm = i915_vm_get(engine->gt->vm);
>>> + ce->gem_context = NULL;
>>> +
>>> + ce->ring = __intel_context_ring_size(SZ_4K);
>>> + ce->timeline = NULL;
>>> + ce->state = NULL;
>>> +
>>> + GEM_BUG_ON(atomic_read(&ce->pin_count));
>>> + GEM_BUG_ON(ce->active_count);
>>> + GEM_BUG_ON(ce->inflight);
>>> +}
>>> +
>>> +void
>>> +intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)
>>> +{
>>> + __intel_context_ctor(ce);
>>> + __intel_context_init(ce, engine);
>>
>> Which bits are accessed from outside context free (inside the RCU
>> period) and based on which ones is the decision taken in the caller that
>> the context is free so should be skipped?
>>
>> And arent' both _ctor and _init fields re-initialized in the same go
>> with this approach (no RCU period between them) - that is - object can
>> get recycled instantly so what is the point in this case between the
>> _ctor and _init split?
>
> ctor is once per slab-page allocation, init is once per object
> allocation. Once upon a time it was said that "DESTROY_BY_RCU without ctor is
> inherently wrong" (which was immediately contradicted by others), but
> the point still resonates in that since the object may be reused within
> an rcu grace period, one should consider what access may still be
> inflight at that time. Here, I was just going through the motions of
> minimising the amount we reset during init.
>
> We don't have to use TYPESAFE_BY_RCU, it has some nice properties in
> freelist management (at least without measuring they sound nice on
> paper), we could just use add a manual call_rcu() to defer the
> kmem_cache_free. Or we could just ignore the _ctor since we don't
> yet have a conflicting access pattern.
Ugh sorry then, I was thinking ctor was called on giving out the new object.
TYPESAFE_BY_RCU does have the advantage compared to kfree_rcu/call_rcu,
but just please document in comments how the callers are using this.
Like with requests we have a clear kref_get_unless_zero via
dma_fence_get_rcu, so we need to know what is the "equivalent" for
intel_context. And which stale data can get accessed, by whom, and why
it is safe.
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2020-08-07 11:31 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-07 8:32 [Intel-gfx] [PATCH 1/7] drm/i915/gt: Remove defunct intel_virtual_engine_get_sibling() Chris Wilson
2020-08-07 8:32 ` [Intel-gfx] [PATCH 2/7] drm/i915/gt: Protect context lifetime with RCU Chris Wilson
2020-08-07 10:08 ` Tvrtko Ursulin
2020-08-07 11:14 ` Chris Wilson
2020-08-07 11:31 ` Tvrtko Ursulin [this message]
2020-08-07 11:49 ` Chris Wilson
2020-08-07 8:32 ` [Intel-gfx] [PATCH 3/7] drm/i915/gt: Defer enabling the breadcrumb interrupt to after submission Chris Wilson
2020-08-07 8:37 ` Chris Wilson
2020-08-07 11:21 ` Tvrtko Ursulin
2020-08-07 8:32 ` [Intel-gfx] [PATCH 4/7] drm/i915/gt: Track signaled breadcrumbs outside of the breadcrumb spinlock Chris Wilson
2020-08-07 11:26 ` Tvrtko Ursulin
2020-08-07 11:54 ` Chris Wilson
2020-08-07 11:56 ` Tvrtko Ursulin
2020-08-07 8:32 ` [Intel-gfx] [PATCH 5/7] drm/i915/gt: Don't cancel the interrupt shadow too early Chris Wilson
2020-08-07 11:27 ` Tvrtko Ursulin
2020-08-07 8:32 ` [Intel-gfx] [PATCH 6/7] drm/i915/gt: Split the breadcrumb spinlock between global and contexts Chris Wilson
2020-08-07 8:35 ` Chris Wilson
2020-08-07 11:54 ` Tvrtko Ursulin
2020-08-07 12:27 ` Chris Wilson
2020-08-07 8:32 ` [Intel-gfx] [PATCH 7/7] drm/i915/gt: Free stale request on destroying the virtual engine Chris Wilson
2020-08-07 12:08 ` Tvrtko Ursulin
2020-08-07 12:45 ` Chris Wilson
2020-08-07 9:50 ` [Intel-gfx] [PATCH 1/7] drm/i915/gt: Remove defunct intel_virtual_engine_get_sibling() Tvrtko Ursulin
2020-08-07 11:57 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for series starting with [1/7] " Patchwork
2020-08-07 11:58 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2020-08-07 12:19 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2020-08-07 14:51 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
-- strict thread matches above, loose matches on Subject: below --
2020-08-07 12:54 [Intel-gfx] [PATCH 1/7] " Chris Wilson
2020-08-07 12:54 ` [Intel-gfx] [PATCH 2/7] drm/i915/gt: Protect context lifetime with RCU Chris Wilson
2020-08-07 14:10 ` Tvrtko Ursulin
2020-08-07 14:14 ` Chris Wilson
2020-08-03 14:41 [Intel-gfx] [PATCH 1/7] drm/i915/gem: Reduce context termination list iteration guard to RCU Chris Wilson
2020-08-03 14:41 ` [Intel-gfx] [PATCH 2/7] drm/i915/gt: Protect context lifetime with RCU Chris Wilson
2020-08-03 10:11 [Intel-gfx] [PATCH 1/7] drm/i915/gem: Reduce context termination list iteration guard to RCU Chris Wilson
2020-08-03 10:11 ` [Intel-gfx] [PATCH 2/7] drm/i915/gt: Protect context lifetime with RCU Chris Wilson
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=5bf59216-e857-598d-2f79-a79481b40892@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;
as well as URLs for NNTP newsgroup(s).