Hi all,
Jason wanted to do that as part of the scheduler series, but I object since rcu is very, very hard to review when adding, and much, much harder even to review when removing.
This is because simply looking for __rcu pointer annotations and rcu functions isn't enough, rcu is also relied upon in many datastructures which have internally and rcu_read_lock protection (or at least the required amount of barriers), like xarray.
The other problem is that it inherits when chasing pointers, e.g. i915_gem_engines has an rcu pointer to intel_context, which has a non-rcu pointer to i915_address_space. But since we could look-up the entire chain under rcu i.e. engines->context[i]->vm this means more code to audit.
The audit explodes pretty quickly.
Anyway I'm reasonable confident I got them all in the current code, and slightly less confident that I managed to stitch together the full history.
References to relevant commits throughout the series.
Cheers, Daniel
Daniel Vetter (9): drm/i915: Drop code to handle set-vm races from execbuf drm/i915: Rename i915_gem_context_get_vm_rcu to i915_gem_context_get_eb_vm drm/i915: Use i915_gem_context_get_eb_vm in ctx_getparam drm/i915: Add i915_gem_context_is_full_ppgtt drm/i915: Use i915_gem_context_get_eb_vm in intel_context_set_gem drm/i915: Drop __rcu from gem_context->vm drm/i915: use xa_lock/unlock for fpriv->vm_xa lookups drm/i915: Stop rcu support for i915_address_space drm/i915: Split out intel_context_create_user
drivers/gpu/drm/i915/gem/i915_gem_context.c | 82 ++++--------------- drivers/gpu/drm/i915/gem/i915_gem_context.h | 13 ++- .../gpu/drm/i915/gem/i915_gem_context_types.h | 2 +- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 12 ++- .../gpu/drm/i915/gem/selftests/huge_pages.c | 8 +- .../drm/i915/gem/selftests/i915_gem_context.c | 32 +++----- .../gpu/drm/i915/gem/selftests/mock_context.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.c | 22 ++++- drivers/gpu/drm/i915/gt/intel_context.h | 2 + drivers/gpu/drm/i915/gt/intel_ggtt.c | 1 - drivers/gpu/drm/i915/gt/intel_gtt.c | 6 +- drivers/gpu/drm/i915/gt/intel_gtt.h | 2 +- drivers/gpu/drm/i915/gt/selftest_execlists.c | 2 +- drivers/gpu/drm/i915/gt/selftest_hangcheck.c | 2 +- drivers/gpu/drm/i915/i915_drv.h | 4 +- drivers/gpu/drm/i915/i915_trace.h | 2 +- drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 4 +- drivers/gpu/drm/i915/selftests/i915_vma.c | 4 +- 18 files changed, 79 insertions(+), 123 deletions(-)
Changing the vm from a finalized gem ctx is no longer possible, which means we don't have to check for that anymore.
I was pondering whether to keep the check as a WARN_ON, but things go boom real bad real fast if the vm of a vma is wrong. Plus we'd need to also get the ggtt vm for !full-ppgtt platforms. Ditching it all seemed like a better idea.
References: ccbc1b97948a ("drm/i915/gem: Don't allow changing the VM on running contexts (v4)") Signed-off-by: Daniel Vetter daniel.vetter@intel.com Cc: Jon Bloomfield jon.bloomfield@intel.com Cc: Chris Wilson chris@chris-wilson.co.uk Cc: Maarten Lankhorst maarten.lankhorst@linux.intel.com Cc: Joonas Lahtinen joonas.lahtinen@linux.intel.com Cc: Daniel Vetter daniel.vetter@ffwll.ch Cc: "Thomas Hellström" thomas.hellstrom@linux.intel.com Cc: Matthew Auld matthew.auld@intel.com Cc: Lionel Landwerlin lionel.g.landwerlin@intel.com Cc: Dave Airlie airlied@redhat.com Cc: Jason Ekstrand jason@jlekstrand.net --- drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c index 538d9d2e52b7..69e47b97d786 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c @@ -775,11 +775,7 @@ static int __eb_add_lut(struct i915_execbuffer *eb, /* Check that the context hasn't been closed in the meantime */ err = -EINTR; if (!mutex_lock_interruptible(&ctx->lut_mutex)) { - struct i915_address_space *vm = rcu_access_pointer(ctx->vm); - - if (unlikely(vm && vma->vm != vm)) - err = -EAGAIN; /* user racing with ctx set-vm */ - else if (likely(!i915_gem_context_is_closed(ctx))) + if (likely(!i915_gem_context_is_closed(ctx))) err = radix_tree_insert(&ctx->handles_vma, handle, vma); else err = -ENOENT;
The important part isn't so much that this does an rcu lookup - that's more an implementation detail, which will also be removed.
The thing that makes this different from other functions is that it's gettting you the vm that batchbuffers will run in for that gem context, which is either a full ppgtt stored in gem->ctx, or the ggtt.
We'll make more use of this function later on.
Signed-off-by: Daniel Vetter daniel.vetter@intel.com Cc: Jon Bloomfield jon.bloomfield@intel.com Cc: Chris Wilson chris@chris-wilson.co.uk Cc: Maarten Lankhorst maarten.lankhorst@linux.intel.com Cc: Joonas Lahtinen joonas.lahtinen@linux.intel.com Cc: Daniel Vetter daniel.vetter@ffwll.ch Cc: "Thomas Hellström" thomas.hellstrom@linux.intel.com Cc: Matthew Auld matthew.auld@intel.com Cc: Lionel Landwerlin lionel.g.landwerlin@intel.com Cc: Dave Airlie airlied@redhat.com Cc: Jason Ekstrand jason@jlekstrand.net --- drivers/gpu/drm/i915/gem/i915_gem_context.h | 2 +- drivers/gpu/drm/i915/gem/selftests/huge_pages.c | 4 ++-- drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c | 4 ++-- drivers/gpu/drm/i915/gt/selftest_execlists.c | 2 +- drivers/gpu/drm/i915/gt/selftest_hangcheck.c | 2 +- drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 4 ++-- drivers/gpu/drm/i915/selftests/i915_vma.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.h b/drivers/gpu/drm/i915/gem/i915_gem_context.h index 18060536b0c2..da6e8b506d96 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.h +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.h @@ -155,7 +155,7 @@ i915_gem_context_vm(struct i915_gem_context *ctx) }
static inline struct i915_address_space * -i915_gem_context_get_vm_rcu(struct i915_gem_context *ctx) +i915_gem_context_get_eb_vm(struct i915_gem_context *ctx) { struct i915_address_space *vm;
diff --git a/drivers/gpu/drm/i915/gem/selftests/huge_pages.c b/drivers/gpu/drm/i915/gem/selftests/huge_pages.c index a094f3ce1a90..6c68fe26bb32 100644 --- a/drivers/gpu/drm/i915/gem/selftests/huge_pages.c +++ b/drivers/gpu/drm/i915/gem/selftests/huge_pages.c @@ -1456,7 +1456,7 @@ static int igt_tmpfs_fallback(void *arg) struct i915_gem_context *ctx = arg; struct drm_i915_private *i915 = ctx->i915; struct vfsmount *gemfs = i915->mm.gemfs; - struct i915_address_space *vm = i915_gem_context_get_vm_rcu(ctx); + struct i915_address_space *vm = i915_gem_context_get_eb_vm(ctx); struct drm_i915_gem_object *obj; struct i915_vma *vma; u32 *vaddr; @@ -1512,7 +1512,7 @@ static int igt_shrink_thp(void *arg) { struct i915_gem_context *ctx = arg; struct drm_i915_private *i915 = ctx->i915; - struct i915_address_space *vm = i915_gem_context_get_vm_rcu(ctx); + struct i915_address_space *vm = i915_gem_context_get_eb_vm(ctx); struct drm_i915_gem_object *obj; struct i915_gem_engines_iter it; struct intel_context *ce; diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c index 8eb5050f8cb3..d436ce7fa25c 100644 --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c @@ -1528,7 +1528,7 @@ static int write_to_scratch(struct i915_gem_context *ctx,
intel_gt_chipset_flush(engine->gt);
- vm = i915_gem_context_get_vm_rcu(ctx); + vm = i915_gem_context_get_eb_vm(ctx); vma = i915_vma_instance(obj, vm, NULL); if (IS_ERR(vma)) { err = PTR_ERR(vma); @@ -1607,7 +1607,7 @@ static int read_from_scratch(struct i915_gem_context *ctx, if (GRAPHICS_VER(i915) >= 8) { const u32 GPR0 = engine->mmio_base + 0x600;
- vm = i915_gem_context_get_vm_rcu(ctx); + vm = i915_gem_context_get_eb_vm(ctx); vma = i915_vma_instance(obj, vm, NULL); if (IS_ERR(vma)) { err = PTR_ERR(vma); diff --git a/drivers/gpu/drm/i915/gt/selftest_execlists.c b/drivers/gpu/drm/i915/gt/selftest_execlists.c index f12ffe797639..b3863abc51f5 100644 --- a/drivers/gpu/drm/i915/gt/selftest_execlists.c +++ b/drivers/gpu/drm/i915/gt/selftest_execlists.c @@ -3493,7 +3493,7 @@ static int smoke_submit(struct preempt_smoke *smoke, if (batch) { struct i915_address_space *vm;
- vm = i915_gem_context_get_vm_rcu(ctx); + vm = i915_gem_context_get_eb_vm(ctx); vma = i915_vma_instance(batch, vm, NULL); i915_vm_put(vm); if (IS_ERR(vma)) diff --git a/drivers/gpu/drm/i915/gt/selftest_hangcheck.c b/drivers/gpu/drm/i915/gt/selftest_hangcheck.c index 08f011f893b2..6023c418ee8a 100644 --- a/drivers/gpu/drm/i915/gt/selftest_hangcheck.c +++ b/drivers/gpu/drm/i915/gt/selftest_hangcheck.c @@ -117,7 +117,7 @@ static struct i915_request * hang_create_request(struct hang *h, struct intel_engine_cs *engine) { struct intel_gt *gt = h->gt; - struct i915_address_space *vm = i915_gem_context_get_vm_rcu(h->ctx); + struct i915_address_space *vm = i915_gem_context_get_eb_vm(h->ctx); struct drm_i915_gem_object *obj; struct i915_request *rq = NULL; struct i915_vma *hws, *vma; diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c index f843a5040706..2d60a5a5b065 100644 --- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c @@ -1300,7 +1300,7 @@ static int exercise_mock(struct drm_i915_private *i915, if (!ctx) return -ENOMEM;
- vm = i915_gem_context_get_vm_rcu(ctx); + vm = i915_gem_context_get_eb_vm(ctx); err = func(vm, 0, min(vm->total, limit), end_time); i915_vm_put(vm);
@@ -1848,7 +1848,7 @@ static int igt_cs_tlb(void *arg) goto out_unlock; }
- vm = i915_gem_context_get_vm_rcu(ctx); + vm = i915_gem_context_get_eb_vm(ctx); if (i915_is_ggtt(vm)) goto out_vm;
diff --git a/drivers/gpu/drm/i915/selftests/i915_vma.c b/drivers/gpu/drm/i915/selftests/i915_vma.c index dd0607254a95..79ba72da0813 100644 --- a/drivers/gpu/drm/i915/selftests/i915_vma.c +++ b/drivers/gpu/drm/i915/selftests/i915_vma.c @@ -118,7 +118,7 @@ static int create_vmas(struct drm_i915_private *i915, struct i915_vma *vma; int err;
- vm = i915_gem_context_get_vm_rcu(ctx); + vm = i915_gem_context_get_eb_vm(ctx); vma = checked_vma_instance(obj, vm, NULL); i915_vm_put(vm); if (IS_ERR(vma))
Consolidates the "which is the vm my execbuf runs in" code a bit. We do some get/put which isn't really required, but all the other users want the refcounting, and I figured doing a function just for this getparam to avoid 2 atomis is a bit much.
Signed-off-by: Daniel Vetter daniel.vetter@intel.com Cc: Jon Bloomfield jon.bloomfield@intel.com Cc: Chris Wilson chris@chris-wilson.co.uk Cc: Maarten Lankhorst maarten.lankhorst@linux.intel.com Cc: Joonas Lahtinen joonas.lahtinen@linux.intel.com Cc: Daniel Vetter daniel.vetter@ffwll.ch Cc: "Thomas Hellström" thomas.hellstrom@linux.intel.com Cc: Matthew Auld matthew.auld@intel.com Cc: Lionel Landwerlin lionel.g.landwerlin@intel.com Cc: Dave Airlie airlied@redhat.com Cc: Jason Ekstrand jason@jlekstrand.net --- drivers/gpu/drm/i915/gem/i915_gem_context.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c index cff72679ad7c..6263563e15d6 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -2124,6 +2124,7 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data, struct drm_i915_file_private *file_priv = file->driver_priv; struct drm_i915_gem_context_param *args = data; struct i915_gem_context *ctx; + struct i915_address_space *vm; int ret = 0;
ctx = i915_gem_context_lookup(file_priv, args->ctx_id); @@ -2133,12 +2134,10 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data, switch (args->param) { case I915_CONTEXT_PARAM_GTT_SIZE: args->size = 0; - rcu_read_lock(); - if (rcu_access_pointer(ctx->vm)) - args->value = rcu_dereference(ctx->vm)->total; - else - args->value = to_i915(dev)->ggtt.vm.total; - rcu_read_unlock(); + vm = i915_gem_context_get_eb_vm(ctx); + args->value = vm->total; + i915_vm_put(vm); + break;
case I915_CONTEXT_PARAM_NO_ERROR_CAPTURE:
And use it anywhere we have open-coded checks for ctx->vm that really only check for full ppgtt.
Plus for paranoia add a GEM_BUG_ON that checks it's really only set when we have full ppgtt, just in case. gem_context->vm is different since it's NULL in ggtt mode, unlike intel_context->vm or gt->vm, which is always set.
Signed-off-by: Daniel Vetter daniel.vetter@intel.com Cc: Jon Bloomfield jon.bloomfield@intel.com Cc: Chris Wilson chris@chris-wilson.co.uk Cc: Maarten Lankhorst maarten.lankhorst@linux.intel.com Cc: Joonas Lahtinen joonas.lahtinen@linux.intel.com Cc: Daniel Vetter daniel.vetter@ffwll.ch Cc: "Thomas Hellström" thomas.hellstrom@linux.intel.com Cc: Matthew Auld matthew.auld@intel.com Cc: Lionel Landwerlin lionel.g.landwerlin@intel.com Cc: Dave Airlie airlied@redhat.com Cc: Jason Ekstrand jason@jlekstrand.net --- drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_context.h | 7 +++++++ drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 2 +- drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c | 4 ++-- 4 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c index 6263563e15d6..a80b06c98dba 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -1581,7 +1581,7 @@ static int get_ppgtt(struct drm_i915_file_private *file_priv, int err; u32 id;
- if (!rcu_access_pointer(ctx->vm)) + if (!i915_gem_context_is_full_ppgtt(ctx)) return -ENODEV;
rcu_read_lock(); diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.h b/drivers/gpu/drm/i915/gem/i915_gem_context.h index da6e8b506d96..37536a260e6e 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.h +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.h @@ -154,6 +154,13 @@ i915_gem_context_vm(struct i915_gem_context *ctx) return rcu_dereference_protected(ctx->vm, lockdep_is_held(&ctx->mutex)); }
+static inline bool i915_gem_context_is_full_ppgtt(struct i915_gem_context *ctx) +{ + GEM_BUG_ON(!!rcu_access_pointer(ctx->vm) != HAS_FULL_PPGTT(ctx->i915)); + + return !!rcu_access_pointer(ctx->vm); +} + static inline struct i915_address_space * i915_gem_context_get_eb_vm(struct i915_gem_context *ctx) { diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c index 69e47b97d786..bdf2b5785a81 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c @@ -749,7 +749,7 @@ static int eb_select_context(struct i915_execbuffer *eb) return PTR_ERR(ctx);
eb->gem_context = ctx; - if (rcu_access_pointer(ctx->vm)) + if (i915_gem_context_is_full_ppgtt(ctx)) eb->invalid_flags |= EXEC_OBJECT_NEEDS_GTT;
return 0; diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c index d436ce7fa25c..5442b8e59629 100644 --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c @@ -838,7 +838,7 @@ static int igt_shared_ctx_exec(void *arg) pr_err("Failed to fill dword %lu [%lu/%lu] with gpu (%s) [full-ppgtt? %s], err=%d\n", ndwords, dw, max_dwords(obj), engine->name, - yesno(!!rcu_access_pointer(ctx->vm)), + yesno(i915_gem_context_is_full_ppgtt(ctx)), err); intel_context_put(ce); kernel_context_close(ctx); @@ -1417,7 +1417,7 @@ static int igt_ctx_readonly(void *arg) pr_err("Failed to fill dword %lu [%lu/%lu] with gpu (%s) [full-ppgtt? %s], err=%d\n", ndwords, dw, max_dwords(obj), ce->engine->name, - yesno(!!ctx_vm(ctx)), + yesno(i915_gem_context_is_full_ppgtt(ctx)), err); i915_gem_context_unlock_engines(ctx); goto out_file;
Since
commit ccbc1b97948ab671335e950271e39766729736c3 Author: Jason Ekstrand jason@jlekstrand.net Date: Thu Jul 8 10:48:30 2021 -0500
drm/i915/gem: Don't allow changing the VM on running contexts (v4)
the gem_ctx->vm can't change anymore. Plus we always set the intel_context->vm, so might as well use the helper we have for that.
This makes it very clear that we always overwrite intel_context->vm for userspace contexts, since the default is gt->vm, which is explicitly reserved for kernel context use. It would be good to split things up a bit further and avoid any possibility for an accident where we run kernel stuff in userspace vm or the other way round.
Signed-off-by: Daniel Vetter daniel.vetter@intel.com Cc: Jon Bloomfield jon.bloomfield@intel.com Cc: Chris Wilson chris@chris-wilson.co.uk Cc: Maarten Lankhorst maarten.lankhorst@linux.intel.com Cc: Joonas Lahtinen joonas.lahtinen@linux.intel.com Cc: Daniel Vetter daniel.vetter@ffwll.ch Cc: "Thomas Hellström" thomas.hellstrom@linux.intel.com Cc: Matthew Auld matthew.auld@intel.com Cc: Lionel Landwerlin lionel.g.landwerlin@intel.com Cc: Dave Airlie airlied@redhat.com Cc: Jason Ekstrand jason@jlekstrand.net --- drivers/gpu/drm/i915/gem/i915_gem_context.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c index a80b06c98dba..fd24a1236682 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -784,16 +784,8 @@ static int intel_context_set_gem(struct intel_context *ce,
ce->ring_size = SZ_16K;
- if (rcu_access_pointer(ctx->vm)) { - struct i915_address_space *vm; - - rcu_read_lock(); - vm = context_get_vm_rcu(ctx); /* hmm */ - rcu_read_unlock(); - - i915_vm_put(ce->vm); - ce->vm = vm; - } + i915_vm_put(ce->vm); + ce->vm = i915_gem_context_get_eb_vm(ctx);
if (ctx->sched.priority >= I915_PRIORITY_NORMAL && intel_engine_has_timeslices(ce->engine) &&
It's been invariant since
commit ccbc1b97948ab671335e950271e39766729736c3 Author: Jason Ekstrand jason@jlekstrand.net Date: Thu Jul 8 10:48:30 2021 -0500
drm/i915/gem: Don't allow changing the VM on running contexts (v4)
this just completes the deed. I've tried to split out prep work for more careful review as much as possible, this is what's left:
- get_ppgtt gets simplified since we don't need to grab a temporary reference - we can rely on the temporary reference for the gem_ctx while we inspect the vm. The new vm_id still needs a full i915_vm_open ofc. This also removes the final caller of context_get_vm_rcu
- A pile of selftests can now just look at ctx->vm instead of rcu_dereference_protected( , true) or similar things.
- All callers of i915_gem_context_vm also disappear.
- I've changed the hugepage selftest to set scrub_64K without any locking, because when we inspect that setting we're also not taking any locks either. It works because it's a selftests that's careful (single threaded gives you nice ordering) and not a live driver where races can happen from anywhere.
These can only be split up further if we have some intermediate state with a bunch more rcu_dereference_protected(ctx->vm, true), just to shut up lockdep and sparse.
The conversion to __rcu happened in
commit a4e7ccdac38ec8335d9e4e2656c1a041c77feae1 Author: Chris Wilson chris@chris-wilson.co.uk Date: Fri Oct 4 14:40:09 2019 +0100
drm/i915: Move context management under GEM
Note that we're not breaking the actual bugfix in there: The real bugfix is pushing the i915_vm_relase onto a separate worker, to avoid locking inversion issues. The rcu conversion was just thrown in for entertainment value on top (no vm lookup isn't even close to anything that's a hotpath where removing the single spinlock can be measured).
Signed-off-by: Daniel Vetter daniel.vetter@intel.com Cc: Jon Bloomfield jon.bloomfield@intel.com Cc: Chris Wilson chris@chris-wilson.co.uk Cc: Maarten Lankhorst maarten.lankhorst@linux.intel.com Cc: Joonas Lahtinen joonas.lahtinen@linux.intel.com Cc: Daniel Vetter daniel.vetter@ffwll.ch Cc: "Thomas Hellström" thomas.hellstrom@linux.intel.com Cc: Matthew Auld matthew.auld@intel.com Cc: Lionel Landwerlin lionel.g.landwerlin@intel.com Cc: Dave Airlie airlied@redhat.com Cc: Jason Ekstrand jason@jlekstrand.net --- drivers/gpu/drm/i915/gem/i915_gem_context.c | 53 ++----------------- drivers/gpu/drm/i915/gem/i915_gem_context.h | 14 ++--- .../gpu/drm/i915/gem/i915_gem_context_types.h | 2 +- .../gpu/drm/i915/gem/selftests/huge_pages.c | 4 +- .../drm/i915/gem/selftests/i915_gem_context.c | 24 ++++----- drivers/gpu/drm/i915/i915_trace.h | 2 +- drivers/gpu/drm/i915/selftests/i915_vma.c | 2 +- 7 files changed, 21 insertions(+), 80 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c index fd24a1236682..2f3cc73d4710 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -735,44 +735,6 @@ static int set_proto_ctx_param(struct drm_i915_file_private *fpriv, return ret; }
-static struct i915_address_space * -context_get_vm_rcu(struct i915_gem_context *ctx) -{ - GEM_BUG_ON(!rcu_access_pointer(ctx->vm)); - - do { - struct i915_address_space *vm; - - /* - * We do not allow downgrading from full-ppgtt [to a shared - * global gtt], so ctx->vm cannot become NULL. - */ - vm = rcu_dereference(ctx->vm); - if (!kref_get_unless_zero(&vm->ref)) - continue; - - /* - * This ppgtt may have be reallocated between - * the read and the kref, and reassigned to a third - * context. In order to avoid inadvertent sharing - * of this ppgtt with that third context (and not - * src), we have to confirm that we have the same - * ppgtt after passing through the strong memory - * barrier implied by a successful - * kref_get_unless_zero(). - * - * Once we have acquired the current ppgtt of ctx, - * we no longer care if it is released from ctx, as - * it cannot be reallocated elsewhere. - */ - - if (vm == rcu_access_pointer(ctx->vm)) - return rcu_pointer_handoff(vm); - - i915_vm_put(vm); - } while (1); -} - static int intel_context_set_gem(struct intel_context *ce, struct i915_gem_context *ctx, struct intel_sseu sseu) @@ -1193,7 +1155,7 @@ static void context_close(struct i915_gem_context *ctx)
set_closed_name(ctx);
- vm = i915_gem_context_vm(ctx); + vm = ctx->vm; if (vm) i915_vm_close(vm);
@@ -1350,7 +1312,7 @@ i915_gem_create_context(struct drm_i915_private *i915, vm = &ppgtt->vm; } if (vm) { - RCU_INIT_POINTER(ctx->vm, i915_vm_open(vm)); + ctx->vm = i915_vm_open(vm);
/* i915_vm_open() takes a reference */ i915_vm_put(vm); @@ -1576,15 +1538,12 @@ static int get_ppgtt(struct drm_i915_file_private *file_priv, if (!i915_gem_context_is_full_ppgtt(ctx)) return -ENODEV;
- rcu_read_lock(); - vm = context_get_vm_rcu(ctx); - rcu_read_unlock(); - if (!vm) - return -ENODEV; + vm = ctx->vm; + GEM_BUG_ON(!vm);
err = xa_alloc(&file_priv->vm_xa, &id, vm, xa_limit_32b, GFP_KERNEL); if (err) - goto err_put; + return err;
i915_vm_open(vm);
@@ -1592,8 +1551,6 @@ static int get_ppgtt(struct drm_i915_file_private *file_priv, args->value = id; args->size = 0;
-err_put: - i915_vm_put(vm); return err; }
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.h b/drivers/gpu/drm/i915/gem/i915_gem_context.h index 37536a260e6e..7696bc91647d 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.h +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.h @@ -148,17 +148,11 @@ static inline void i915_gem_context_put(struct i915_gem_context *ctx) kref_put(&ctx->ref, i915_gem_context_release); }
-static inline struct i915_address_space * -i915_gem_context_vm(struct i915_gem_context *ctx) -{ - return rcu_dereference_protected(ctx->vm, lockdep_is_held(&ctx->mutex)); -} - static inline bool i915_gem_context_is_full_ppgtt(struct i915_gem_context *ctx) { - GEM_BUG_ON(!!rcu_access_pointer(ctx->vm) != HAS_FULL_PPGTT(ctx->i915)); + GEM_BUG_ON(!!ctx->vm != HAS_FULL_PPGTT(ctx->i915));
- return !!rcu_access_pointer(ctx->vm); + return !!ctx->vm; }
static inline struct i915_address_space * @@ -166,12 +160,10 @@ i915_gem_context_get_eb_vm(struct i915_gem_context *ctx) { struct i915_address_space *vm;
- rcu_read_lock(); - vm = rcu_dereference(ctx->vm); + vm = ctx->vm; if (!vm) vm = &ctx->i915->ggtt.vm; vm = i915_vm_get(vm); - rcu_read_unlock();
return vm; } diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context_types.h b/drivers/gpu/drm/i915/gem/i915_gem_context_types.h index 94c03a97cb77..540ad16204a9 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context_types.h +++ b/drivers/gpu/drm/i915/gem/i915_gem_context_types.h @@ -262,7 +262,7 @@ struct i915_gem_context { * In other modes, this is a NULL pointer with the expectation that * the caller uses the shared global GTT. */ - struct i915_address_space __rcu *vm; + struct i915_address_space *vm;
/** * @pid: process id of creator diff --git a/drivers/gpu/drm/i915/gem/selftests/huge_pages.c b/drivers/gpu/drm/i915/gem/selftests/huge_pages.c index 6c68fe26bb32..5d71626a1ee5 100644 --- a/drivers/gpu/drm/i915/gem/selftests/huge_pages.c +++ b/drivers/gpu/drm/i915/gem/selftests/huge_pages.c @@ -1688,11 +1688,9 @@ int i915_gem_huge_page_live_selftests(struct drm_i915_private *i915) goto out_file; }
- mutex_lock(&ctx->mutex); - vm = i915_gem_context_vm(ctx); + vm = ctx->vm; if (vm) WRITE_ONCE(vm->scrub_64K, true); - mutex_unlock(&ctx->mutex);
err = i915_subtests(tests, ctx);
diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c index 5442b8e59629..49d17701d8d3 100644 --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c @@ -27,12 +27,6 @@
#define DW_PER_PAGE (PAGE_SIZE / sizeof(u32))
-static inline struct i915_address_space *ctx_vm(struct i915_gem_context *ctx) -{ - /* single threaded, private ctx */ - return rcu_dereference_protected(ctx->vm, true); -} - static int live_nop_switch(void *arg) { const unsigned int nctx = 1024; @@ -813,7 +807,7 @@ static int igt_shared_ctx_exec(void *arg) struct i915_gem_context *ctx; struct intel_context *ce;
- ctx = kernel_context(i915, ctx_vm(parent)); + ctx = kernel_context(i915, parent->vm); if (IS_ERR(ctx)) { err = PTR_ERR(ctx); goto out_test; @@ -823,7 +817,7 @@ static int igt_shared_ctx_exec(void *arg) GEM_BUG_ON(IS_ERR(ce));
if (!obj) { - obj = create_test_object(ctx_vm(parent), + obj = create_test_object(parent->vm, file, &objects); if (IS_ERR(obj)) { err = PTR_ERR(obj); @@ -1380,7 +1374,7 @@ static int igt_ctx_readonly(void *arg) goto out_file; }
- vm = ctx_vm(ctx) ?: &i915->ggtt.alias->vm; + vm = ctx->vm ?: &i915->ggtt.alias->vm; if (!vm || !vm->has_read_only) { err = 0; goto out_file; @@ -1499,7 +1493,7 @@ static int write_to_scratch(struct i915_gem_context *ctx,
GEM_BUG_ON(offset < I915_GTT_PAGE_SIZE);
- err = check_scratch(ctx_vm(ctx), offset); + err = check_scratch(ctx->vm, offset); if (err) return err;
@@ -1596,7 +1590,7 @@ static int read_from_scratch(struct i915_gem_context *ctx,
GEM_BUG_ON(offset < I915_GTT_PAGE_SIZE);
- err = check_scratch(ctx_vm(ctx), offset); + err = check_scratch(ctx->vm, offset); if (err) return err;
@@ -1739,7 +1733,7 @@ static int check_scratch_page(struct i915_gem_context *ctx, u32 *out) u32 *vaddr; int err = 0;
- vm = ctx_vm(ctx); + vm = ctx->vm; if (!vm) return -ENODEV;
@@ -1801,7 +1795,7 @@ static int igt_vm_isolation(void *arg) }
/* We can only test vm isolation, if the vm are distinct */ - if (ctx_vm(ctx_a) == ctx_vm(ctx_b)) + if (ctx_a->vm == ctx_b->vm) goto out_file;
/* Read the initial state of the scratch page */ @@ -1813,8 +1807,8 @@ static int igt_vm_isolation(void *arg) if (err) goto out_file;
- vm_total = ctx_vm(ctx_a)->total; - GEM_BUG_ON(ctx_vm(ctx_b)->total != vm_total); + vm_total = ctx_a->vm->total; + GEM_BUG_ON(ctx_b->vm->total != vm_total);
count = 0; num_engines = 0; diff --git a/drivers/gpu/drm/i915/i915_trace.h b/drivers/gpu/drm/i915/i915_trace.h index 806ad688274b..237e5061381b 100644 --- a/drivers/gpu/drm/i915/i915_trace.h +++ b/drivers/gpu/drm/i915/i915_trace.h @@ -1246,7 +1246,7 @@ DECLARE_EVENT_CLASS(i915_context, TP_fast_assign( __entry->dev = ctx->i915->drm.primary->index; __entry->ctx = ctx; - __entry->vm = rcu_access_pointer(ctx->vm); + __entry->vm = ctx->vm; ),
TP_printk("dev=%u, ctx=%p, ctx_vm=%p", diff --git a/drivers/gpu/drm/i915/selftests/i915_vma.c b/drivers/gpu/drm/i915/selftests/i915_vma.c index 79ba72da0813..1f10fe36619b 100644 --- a/drivers/gpu/drm/i915/selftests/i915_vma.c +++ b/drivers/gpu/drm/i915/selftests/i915_vma.c @@ -39,7 +39,7 @@ static bool assert_vma(struct i915_vma *vma, { bool ok = true;
- if (vma->vm != rcu_access_pointer(ctx->vm)) { + if (vma->vm != ctx->vm) { pr_err("VMA created with wrong VM\n"); ok = false; }
Hi Daniel,
I love your patch! Perhaps something to improve:
[auto build test WARNING on drm-tip/drm-tip] [cannot apply to drm-intel/for-linux-next drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next drm/drm-next v5.14-rc3 next-20210730] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Daniel-Vetter/remove-rcu-support-fr... base: git://anongit.freedesktop.org/drm/drm-tip drm-tip config: i386-randconfig-s002-20210802 (attached as .config) compiler: gcc-10 (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.3-341-g8af24329-dirty # https://github.com/0day-ci/linux/commit/4a70c02a8b49ee9845e8222c55b4bf932e84... git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Daniel-Vetter/remove-rcu-support-from-i915_address_space/20210802-234929 git checkout 4a70c02a8b49ee9845e8222c55b4bf932e843224 # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot lkp@intel.com
sparse warnings: (new ones prefixed by >>) drivers/gpu/drm/i915/gem/i915_gem_context.c: note: in included file (through drivers/gpu/drm/i915/gt/intel_gt_requests.h, drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c): /usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h:406:9: sparse: sparse: preprocessor token offsetof redefined drivers/gpu/drm/i915/gem/i915_gem_context.c: note: in included file (through include/uapi/linux/posix_types.h, include/uapi/linux/types.h, include/linux/types.h, ...): include/linux/stddef.h:17:9: sparse: this was the original definition drivers/gpu/drm/i915/gem/i915_gem_context.c: note: in included file:
drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c:698:33: sparse: sparse: incompatible types in comparison expression (different address spaces): drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c:698:33: sparse: struct i915_address_space [noderef] __rcu * drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c:698:33: sparse: struct i915_address_space *
vim +698 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c
f2085c8e950d53 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 631 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 632 static int igt_ctx_exec(void *arg) 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 633 { 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 634 struct drm_i915_private *i915 = arg; e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 635 struct intel_engine_cs *engine; 6e1281412ab9e6 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-11-14 636 int err = -ENODEV; 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 637 0fdbe58c4a0f8c drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2018-07-06 638 /* 0fdbe58c4a0f8c drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2018-07-06 639 * Create a few different contexts (with different mm) and write 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 640 * through each ctx/mm using the GPU making sure those writes end 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 641 * up in the expected pages of our obj. 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 642 */ 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 643 0fdbe58c4a0f8c drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2018-07-06 644 if (!DRIVER_CAPS(i915)->has_logical_contexts) 0fdbe58c4a0f8c drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2018-07-06 645 return 0; 0fdbe58c4a0f8c drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2018-07-06 646 51757cf4d7e6e1 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Tvrtko Ursulin 2019-10-22 647 for_each_uabi_engine(engine, i915) { e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 648 struct drm_i915_gem_object *obj = NULL; e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 649 unsigned long ncontexts, ndwords, dw; f2085c8e950d53 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 650 struct i915_request *tq[5] = {}; e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 651 struct igt_live_test t; e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 652 IGT_TIMEOUT(end_time); e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 653 LIST_HEAD(objects); a8c9a7f52ec5a4 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-11-07 654 struct file *file; e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 655 e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 656 if (!intel_engine_can_store_dword(engine)) e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 657 continue; e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 658 e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 659 if (!engine->context_size) e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 660 continue; /* No logical context support in HW */ e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 661 ef47a0e0f49d53 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-03-13 662 file = mock_file(i915); ef47a0e0f49d53 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-03-13 663 if (IS_ERR(file)) ef47a0e0f49d53 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-03-13 664 return PTR_ERR(file); ef47a0e0f49d53 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-03-13 665 e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 666 err = igt_live_test_begin(&t, i915, __func__, engine->name); 8dd0f8d37eaec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2018-10-12 667 if (err) a4e7ccdac38ec8 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-10-04 668 goto out_file; 8dd0f8d37eaec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2018-10-12 669 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 670 ncontexts = 0; 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 671 ndwords = 0; 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 672 dw = 0; 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 673 while (!time_after(jiffies, end_time)) { 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 674 struct i915_gem_context *ctx; 75b974a859e5d9 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-24 675 struct intel_context *ce; 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 676 5888d588597408 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Jason Ekstrand 2021-07-08 677 ctx = kernel_context(i915, NULL); 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 678 if (IS_ERR(ctx)) { 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 679 err = PTR_ERR(ctx); a4e7ccdac38ec8 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-10-04 680 goto out_file; 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 681 } 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 682 75b974a859e5d9 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-24 683 ce = i915_gem_context_get_engine(ctx, engine->legacy_idx); 21b0c32bdaba7c drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 684 GEM_BUG_ON(IS_ERR(ce)); 75b974a859e5d9 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-24 685 ca83d5840cb641 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-05-23 686 if (!obj) { 75b974a859e5d9 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-24 687 obj = create_test_object(ce->vm, file, &objects); 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 688 if (IS_ERR(obj)) { 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 689 err = PTR_ERR(obj); 75b974a859e5d9 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-24 690 intel_context_put(ce); c4e6488120e9ef drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 691 kernel_context_close(ctx); a4e7ccdac38ec8 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-10-04 692 goto out_file; 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 693 } 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 694 } 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 695 75b974a859e5d9 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-24 696 err = gpu_fill(ce, obj, dw); 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 697 if (err) { 2935ed5339c495 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-10-04 @698 pr_err("Failed to fill dword %lu [%lu/%lu] with gpu (%s) [full-ppgtt? %s], err=%d\n", 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 699 ndwords, dw, max_dwords(obj), 2935ed5339c495 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-10-04 700 engine->name, a4e7ccdac38ec8 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-10-04 701 yesno(!!rcu_access_pointer(ctx->vm)), a4e7ccdac38ec8 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-10-04 702 err); f2085c8e950d53 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 703 intel_context_put(ce); c4e6488120e9ef drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 704 kernel_context_close(ctx); a4e7ccdac38ec8 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-10-04 705 goto out_file; f2085c8e950d53 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 706 } f2085c8e950d53 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 707 f2085c8e950d53 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 708 err = throttle(ce, tq, ARRAY_SIZE(tq)); f2085c8e950d53 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 709 if (err) { f2085c8e950d53 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 710 intel_context_put(ce); c4e6488120e9ef drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 711 kernel_context_close(ctx); a4e7ccdac38ec8 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-10-04 712 goto out_file; 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 713 } 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 714 ca83d5840cb641 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-05-23 715 if (++dw == max_dwords(obj)) { ca83d5840cb641 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-05-23 716 obj = NULL; 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 717 dw = 0; ca83d5840cb641 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-05-23 718 } e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 719 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 720 ndwords++; 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 721 ncontexts++; f2085c8e950d53 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 722 f2085c8e950d53 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 723 intel_context_put(ce); c4e6488120e9ef drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 724 kernel_context_close(ctx); 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 725 } 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 726 e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 727 pr_info("Submitted %lu contexts to %s, filling %lu dwords\n", e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 728 ncontexts, engine->name, ndwords); e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 729 e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 730 ncontexts = dw = 0; 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 731 list_for_each_entry(obj, &objects, st_link) { 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 732 unsigned int rem = 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 733 min_t(unsigned int, ndwords - dw, max_dwords(obj)); 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 734 e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 735 err = cpu_check(obj, ncontexts++, rem); 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 736 if (err) 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 737 break; 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 738 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 739 dw += rem; 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 740 } 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 741 a4e7ccdac38ec8 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-10-04 742 out_file: f2085c8e950d53 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-08-27 743 throttle_release(tq, ARRAY_SIZE(tq)); e4a8c8130ba3ac drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-01-21 744 if (igt_live_test_end(&t)) 7c2f5bc5f0f41a drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2018-05-05 745 err = -EIO; 791ff39ae32a34 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2017-02-13 746 a8c9a7f52ec5a4 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-11-07 747 fput(file); e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 748 if (err) e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 749 return err; 6582f4f613e352 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-07-04 750 6582f4f613e352 drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c Chris Wilson 2019-07-04 751 i915_gem_drain_freed_objects(i915); e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 752 } e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 753 e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 754 return 0; e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 755 } e0695db7298ec2 drivers/gpu/drm/i915/selftests/i915_gem_context.c Chris Wilson 2019-03-22 756
--- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
We don't need the absolute speed of rcu for this. And i915_address_space in general dont need rcu protection anywhere else, after we've made gem contexts and engines a lot more immutable.
Note that this semantically reverts
commit aabbe344dc3ca5f7d8263a02608ba6179e8a4499 Author: Chris Wilson chris@chris-wilson.co.uk Date: Fri Aug 30 19:03:25 2019 +0100
drm/i915: Use RCU for unlocked vm_idr lookup
except we have the conversion from idr to xarray in between.
Signed-off-by: Daniel Vetter daniel.vetter@intel.com Cc: Jon Bloomfield jon.bloomfield@intel.com Cc: Chris Wilson chris@chris-wilson.co.uk Cc: Maarten Lankhorst maarten.lankhorst@linux.intel.com Cc: Joonas Lahtinen joonas.lahtinen@linux.intel.com Cc: Daniel Vetter daniel.vetter@ffwll.ch Cc: "Thomas Hellström" thomas.hellstrom@linux.intel.com Cc: Matthew Auld matthew.auld@intel.com Cc: Lionel Landwerlin lionel.g.landwerlin@intel.com Cc: Dave Airlie airlied@redhat.com Cc: Jason Ekstrand jason@jlekstrand.net --- drivers/gpu/drm/i915/i915_drv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 1488d166d91c..df2d723c894a 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -1880,11 +1880,11 @@ i915_gem_vm_lookup(struct drm_i915_file_private *file_priv, u32 id) { struct i915_address_space *vm;
- rcu_read_lock(); + xa_lock(&file_priv->vm_xa); vm = xa_load(&file_priv->vm_xa, id); if (vm && !kref_get_unless_zero(&vm->ref)) vm = NULL; - rcu_read_unlock(); + xa_unlock(&file_priv->vm_xa);
return vm; }
The full audit is quite a bit of work:
- i915_dpt has very simple lifetime (somehow we create a display pagetable vm per object, so its _very_ simple, there's only ever a single vma in there), and uses i915_vm_close(), which internally does a i915_vm_put(). No rcu.
Aside: wtf is i915_dpt doing in the intel_display.c garbage collector as a new feature, instead of added as a separate file with some clean-ish interface.
Also, i915_dpt unfortunately re-introduces some coding patterns from pre-dma_resv_lock conversion times.
- i915_gem_proto_ctx is fully refcounted and no rcu, all protected by fpriv->proto_context_lock.
- i915_gem_context is itself rcu protected, and that might leak to anything it points at. Before
commit cf977e18610e66e48c31619e7e0cfa871be9eada Author: Chris Wilson chris@chris-wilson.co.uk Date: Wed Dec 2 11:21:40 2020 +0000
drm/i915/gem: Spring clean debugfs
and
commit db80a1294c231b6ac725085f046bb2931e00c9db Author: Chris Wilson chris@chris-wilson.co.uk Date: Mon Jan 18 11:08:54 2021 +0000
drm/i915/gem: Remove per-client stats from debugfs/i915_gem_objects
we had a bunch of debugfs files that relied on rcu protecting everything, but those are gone now. The main one was removed even earlier with
There doesn't seem to be anything left that's actually protecting stuff now that the ctx->vm itself is invariant. See
commit ccbc1b97948ab671335e950271e39766729736c3 Author: Jason Ekstrand jason@jlekstrand.net Date: Thu Jul 8 10:48:30 2021 -0500
drm/i915/gem: Don't allow changing the VM on running contexts (v4)
Note that we drop the vm refcount before the final release of the gem context refcount, so this is all very dangerous even without rcu. Note that aside from later on creating new engines (a defunct feature) and debug output we're never looked at gem_ctx->vm for anything functional, hence why this is ok. Fingers crossed.
Preceeding patches removed all vestiges of rcu use from gem_ctx->vm derferencing to make it clear it's really not used.
The gem_ctx->rcu protection was introduced in
commit a4e7ccdac38ec8335d9e4e2656c1a041c77feae1 Author: Chris Wilson chris@chris-wilson.co.uk Date: Fri Oct 4 14:40:09 2019 +0100
drm/i915: Move context management under GEM
The commit message is somewhat entertaining because it fails to mention this fact completely, and compensates that by an in-commit changelog entry that claims that ctx->vm is protected by ctx->mutex. Which was the case _before_ this commit, but no longer after it.
- intel_context holds a full reference. Unfortunately intel_context is also rcu protected and the reference to the ->vm is dropped before the rcu barrier - only the kfree is delayed. So again we need to check whether that leaks anywhere on the intel_context->vm. RCU is only used to protect intel_context sitting on the breadcrumb lists, which don't look at the vm anywhere, so we are fine.
Nothing else relies on rcu protection of intel_context and hence is fully protected by the kref refcount alone, which protects intel_context->vm in turn.
The breadcrumbs rcu usage was added in
commit c744d50363b714783bbc88d986cc16def13710f7 Author: Chris Wilson chris@chris-wilson.co.uk Date: Thu Nov 26 14:04:06 2020 +0000
drm/i915/gt: Split the breadcrumb spinlock between global and contexts
its parent commit added the intel_context rcu protection:
commit 14d1eaf08845c534963c83f754afe0cb14cb2512 Author: Chris Wilson chris@chris-wilson.co.uk Date: Thu Nov 26 14:04:05 2020 +0000
drm/i915/gt: Protect context lifetime with RCU
given some credence to my claim that I've actually caught them all.
- drm_i915_gem_object's shares_resv_from pointer has a full refcount to the dma_resv, which is a sub-refcount that's released after the final i915_vm_put() has been called. Safe.
Aside: Maybe we should have a struct dma_resv_shared which is just dma_resv + kref as a stand-alone thing. It's a pretty useful pattern which other drivers might want to copy.
For a bit more context see
commit 4d8151ae5329cf50781a02fd2298a909589a5bab Author: Thomas Hellström thomas.hellstrom@linux.intel.com Date: Tue Jun 1 09:46:41 2021 +0200
drm/i915: Don't free shared locks while shared
- the fpriv->vm_xa was relying on rcu_read_lock for lookup, but that was updated in a prep patch too to just be a spinlock-protected lookup.
- intel_gt->vm is set at driver load in intel_gt_init() and released in intel_gt_driver_release(). There seems to be some issue that in some error paths this is called twice, but otherwise no rcu to be found anywhere. This was added in the below commit, which unfortunately doesn't explain why this complication exists.
commit e6ba76480299a0d77c51d846f7467b1673aad25b Author: Chris Wilson chris@chris-wilson.co.uk Date: Sat Dec 21 16:03:24 2019 +0000
drm/i915: Remove i915->kernel_context
The proper fix most likely for this is to start using drmm_ at large scale, but that's also huge amounts of work.
- i915_vma->vm is some real pain, because rcu is rcu protected, at least in the vma lookup in the context lookup cache in eb_lookup_vma(). This was added in
commit 4ff4b44cbb70c269259958cbcc48d7b8a2cb9ec8 Author: Chris Wilson chris@chris-wilson.co.uk Date: Fri Jun 16 15:05:16 2017 +0100
drm/i915: Store a direct lookup from object handle to vma
This was changed to a radix tree from the hashtable in, but with the locking unchanged, in
commit d1b48c1e7184d9bc4ae6d7f9fe2eed9efed11ffc Author: Chris Wilson chris@chris-wilson.co.uk Date: Wed Aug 16 09:52:08 2017 +0100
drm/i915: Replace execbuf vma ht with an idr
In
commit 93159e12353c2a47e5576d642845a91fa00530bf Author: Chris Wilson chris@chris-wilson.co.uk Date: Mon Mar 23 09:28:41 2020 +0000
drm/i915/gem: Avoid gem_context->mutex for simple vma lookup
the locking was changed from dev->struct_mutex to rcu, which added the requirement to rcu protect i915_vma. Somehow this was missed in review (or I'm completely blind).
Irrespective of all that the vma lookup cache rcu_read_lock grabs a full reference of the vma and the rcu doesn't leak further. So no impact on i915_address_space from that.
I have not found any other rcu use for i915_vma, but given that it seems broken I also didn't bother to do a careful in-depth audit.
Alltogether there's nothing left in-tree anymore which requires that a pointer deref to an i915_address_space is safe undre rcu_read_lock only.
rcu protection of i915_address_space was introduced in
commit b32fa811156328aea5a3c2ff05cc096490382456 Author: Chris Wilson chris@chris-wilson.co.uk Date: Thu Jun 20 19:37:05 2019 +0100
drm/i915/gtt: Defer address space cleanup to an RCU worker
by mixing up a bugfixing (i915_address_space needs to be released from a worker) with enabling rcu support. The commit message also seems somewhat confused, because it talks about cleanup of WC pages requiring sleep, while the code and linked bugzilla are about a requirement to take dev->struct_mutex (which yes sleeps but it's a much more specific problem). Since final kref_put can be called from pretty much anywhere (including hardirq context through the scheduler's i915_active cleanup) we need a worker here. Hence that part must be kept.
Ideally all these reclaim workers should have some kind of integration with our shrinkers, but for some of these it's rather tricky. Anyway, that's a preexisting condition in the codeebase that we wont fix in this patch here.
We also remove the rcu_barrier in ggtt_cleanup_hw added in
commit 60a4233a4952729089e4df152e730f8f4d0e82ce Author: Chris Wilson chris@chris-wilson.co.uk Date: Mon Jul 29 14:24:12 2019 +0100
drm/i915: Flush the i915_vm_release before ggtt shutdown
Signed-off-by: Daniel Vetter daniel.vetter@intel.com Cc: Jon Bloomfield jon.bloomfield@intel.com Cc: Chris Wilson chris@chris-wilson.co.uk Cc: Maarten Lankhorst maarten.lankhorst@linux.intel.com Cc: Joonas Lahtinen joonas.lahtinen@linux.intel.com Cc: Daniel Vetter daniel.vetter@ffwll.ch Cc: "Thomas Hellström" thomas.hellstrom@linux.intel.com Cc: Matthew Auld matthew.auld@intel.com Cc: Lionel Landwerlin lionel.g.landwerlin@intel.com Cc: Dave Airlie airlied@redhat.com Cc: Jason Ekstrand jason@jlekstrand.net --- drivers/gpu/drm/i915/gt/intel_ggtt.c | 1 - drivers/gpu/drm/i915/gt/intel_gtt.c | 6 +++--- drivers/gpu/drm/i915/gt/intel_gtt.h | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/i915/gt/intel_ggtt.c b/drivers/gpu/drm/i915/gt/intel_ggtt.c index de3ac58fceec..8d71f67926f1 100644 --- a/drivers/gpu/drm/i915/gt/intel_ggtt.c +++ b/drivers/gpu/drm/i915/gt/intel_ggtt.c @@ -727,7 +727,6 @@ static void ggtt_cleanup_hw(struct i915_ggtt *ggtt)
atomic_set(&ggtt->vm.open, 0);
- rcu_barrier(); /* flush the RCU'ed__i915_vm_release */ flush_workqueue(ggtt->vm.i915->wq);
mutex_lock(&ggtt->vm.mutex); diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.c b/drivers/gpu/drm/i915/gt/intel_gtt.c index e137dd32b5b8..a0c2b952aa57 100644 --- a/drivers/gpu/drm/i915/gt/intel_gtt.c +++ b/drivers/gpu/drm/i915/gt/intel_gtt.c @@ -155,7 +155,7 @@ void i915_vm_resv_release(struct kref *kref) static void __i915_vm_release(struct work_struct *work) { struct i915_address_space *vm = - container_of(work, struct i915_address_space, rcu.work); + container_of(work, struct i915_address_space, release_work);
vm->cleanup(vm); i915_address_space_fini(vm); @@ -171,7 +171,7 @@ void i915_vm_release(struct kref *kref) GEM_BUG_ON(i915_is_ggtt(vm)); trace_i915_ppgtt_release(vm);
- queue_rcu_work(vm->i915->wq, &vm->rcu); + queue_work(vm->i915->wq, &vm->release_work); }
void i915_address_space_init(struct i915_address_space *vm, int subclass) @@ -185,7 +185,7 @@ void i915_address_space_init(struct i915_address_space *vm, int subclass) if (!kref_read(&vm->resv_ref)) kref_init(&vm->resv_ref);
- INIT_RCU_WORK(&vm->rcu, __i915_vm_release); + INIT_WORK(&vm->release_work, __i915_vm_release); atomic_set(&vm->open, 1);
/* diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.h b/drivers/gpu/drm/i915/gt/intel_gtt.h index bc7153018ebd..5b539bd7645d 100644 --- a/drivers/gpu/drm/i915/gt/intel_gtt.h +++ b/drivers/gpu/drm/i915/gt/intel_gtt.h @@ -213,7 +213,7 @@ struct i915_vma_ops {
struct i915_address_space { struct kref ref; - struct rcu_work rcu; + struct work_struct release_work;
struct drm_mm mm; struct intel_gt *gt;
There's quite a fundamental difference between userspace contexts, and kernel contexts. Latter all share intel_gt->vm, former get their vm from gem_ctx->vm (on full ppgtt at least).
By splitting context creation for userspace from kernel-internal ones we can make this all a bit more strict and WARN_ON if there's a vm already set in intel_context_set_gem().
All this is only possible because gem_ctx cannot chance their VM anymore since
commit ccbc1b97948ab671335e950271e39766729736c3 Author: Jason Ekstrand jason@jlekstrand.net Date: Thu Jul 8 10:48:30 2021 -0500
drm/i915/gem: Don't allow changing the VM on running contexts (v4)
Signed-off-by: Daniel Vetter daniel.vetter@intel.com Cc: Jon Bloomfield jon.bloomfield@intel.com Cc: Chris Wilson chris@chris-wilson.co.uk Cc: Maarten Lankhorst maarten.lankhorst@linux.intel.com Cc: Joonas Lahtinen joonas.lahtinen@linux.intel.com Cc: Daniel Vetter daniel.vetter@ffwll.ch Cc: "Thomas Hellström" thomas.hellstrom@linux.intel.com Cc: Matthew Auld matthew.auld@intel.com Cc: Lionel Landwerlin lionel.g.landwerlin@intel.com Cc: Dave Airlie airlied@redhat.com Cc: Jason Ekstrand jason@jlekstrand.net --- drivers/gpu/drm/i915/gem/i915_gem_context.c | 6 ++--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 4 +++- .../gpu/drm/i915/gem/selftests/mock_context.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.c | 22 +++++++++++++++++-- drivers/gpu/drm/i915/gt/intel_context.h | 2 ++ 5 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c index 2f3cc73d4710..13358e6749d9 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -746,7 +746,7 @@ static int intel_context_set_gem(struct intel_context *ce,
ce->ring_size = SZ_16K;
- i915_vm_put(ce->vm); + WARN_ON(ce->vm); ce->vm = i915_gem_context_get_eb_vm(ctx);
if (ctx->sched.priority >= I915_PRIORITY_NORMAL && @@ -856,7 +856,7 @@ static struct i915_gem_engines *default_engines(struct i915_gem_context *ctx, GEM_BUG_ON(engine->legacy_idx >= I915_NUM_ENGINES); GEM_BUG_ON(e->engines[engine->legacy_idx]);
- ce = intel_context_create(engine); + ce = intel_context_create_user(engine); if (IS_ERR(ce)) { err = ERR_CAST(ce); goto free_engines; @@ -897,7 +897,7 @@ static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx,
switch (pe[n].type) { case I915_GEM_ENGINE_TYPE_PHYSICAL: - ce = intel_context_create(pe[n].engine); + ce = intel_context_create_user(pe[n].engine); break;
case I915_GEM_ENGINE_TYPE_BALANCED: diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c index bdf2b5785a81..54de94433365 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c @@ -30,15 +30,17 @@
struct eb_vma { struct i915_vma *vma; + struct drm_i915_gem_object *obj; unsigned int flags;
+ u32 handle; + /** This vma's place in the execbuf reservation list */ struct drm_i915_gem_exec_object2 *exec; struct list_head bind_link; struct list_head reloc_link;
struct hlist_node node; - u32 handle; };
enum { diff --git a/drivers/gpu/drm/i915/gem/selftests/mock_context.c b/drivers/gpu/drm/i915/gem/selftests/mock_context.c index fee070df1c97..e5efda1058a3 100644 --- a/drivers/gpu/drm/i915/gem/selftests/mock_context.c +++ b/drivers/gpu/drm/i915/gem/selftests/mock_context.c @@ -124,7 +124,7 @@ live_context_for_engine(struct intel_engine_cs *engine, struct file *file) return ctx; }
- ce = intel_context_create(engine); + ce = intel_context_create_user(engine); if (IS_ERR(ce)) { __free_engines(engines, 0); return ERR_CAST(ce); diff --git a/drivers/gpu/drm/i915/gt/intel_context.c b/drivers/gpu/drm/i915/gt/intel_context.c index 745e84c72c90..9e33efb594dd 100644 --- a/drivers/gpu/drm/i915/gt/intel_context.c +++ b/drivers/gpu/drm/i915/gt/intel_context.c @@ -34,6 +34,23 @@ void intel_context_free(struct intel_context *ce) call_rcu(&ce->rcu, rcu_context_free); }
+/* for user contexts, callers must set ce->vm correctly */ +struct intel_context * +intel_context_create_user(struct intel_engine_cs *engine) +{ + struct intel_context *ce; + + ce = intel_context_alloc(); + if (!ce) + return ERR_PTR(-ENOMEM); + + intel_context_init(ce, engine); + + trace_intel_context_create(ce); + return ce; +} + +/* for kernel-internal users only, sets ce->vm to intel_gt.vm */ struct intel_context * intel_context_create(struct intel_engine_cs *engine) { @@ -44,6 +61,8 @@ intel_context_create(struct intel_engine_cs *engine) return ERR_PTR(-ENOMEM);
intel_context_init(ce, engine); + ce->vm = i915_vm_get(engine->gt->vm); + trace_intel_context_create(ce); return ce; } @@ -368,6 +387,7 @@ static int sw_fence_dummy_notify(struct i915_sw_fence *sf, return NOTIFY_DONE; }
+/* callers must set ce->vm for user or kernel vm as needed */ void intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine) { @@ -384,8 +404,6 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)
ewma_runtime_init(&ce->runtime.avg);
- ce->vm = i915_vm_get(engine->gt->vm); - /* NB ce->signal_link/lock is used under RCU */ spin_lock_init(&ce->signal_lock); INIT_LIST_HEAD(&ce->signals); diff --git a/drivers/gpu/drm/i915/gt/intel_context.h b/drivers/gpu/drm/i915/gt/intel_context.h index c41098950746..a80018d53a36 100644 --- a/drivers/gpu/drm/i915/gt/intel_context.h +++ b/drivers/gpu/drm/i915/gt/intel_context.h @@ -34,6 +34,8 @@ void intel_context_fini(struct intel_context *ce); void i915_context_module_exit(void); int i915_context_module_init(void);
+struct intel_context * +intel_context_create_user(struct intel_engine_cs *engine); struct intel_context * intel_context_create(struct intel_engine_cs *engine);
dri-devel@lists.freedesktop.org