* Re: [Intel-gfx] [PATCH 3/3] drm/i915/gem: Serialise debugfs i915_gem_objects with ctx->mutex [not found] ` <20200723172119.17649-3-chris@chris-wilson.co.uk> @ 2020-09-14 16:45 ` Tvrtko Ursulin 2020-09-16 7:42 ` Daniel Vetter 0 siblings, 1 reply; 3+ messages in thread From: Tvrtko Ursulin @ 2020-09-14 16:45 UTC (permalink / raw) To: Chris Wilson, intel-gfx Cc: Daniel Vetter, dri-devel, stable, Nikunj A. Dadhania On 23/07/2020 18:21, Chris Wilson wrote: > Since the debugfs may peek into the GEM contexts as the corresponding > client/fd is being closed, we may try and follow a dangling pointer. > However, the context closure itself is serialised with the ctx->mutex, > so if we hold that mutex as we inspect the state coupled in the context, > we know the pointers within the context are stable and will remain valid > as we inspect their tables. > > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> > Cc: CQ Tang <cq.tang@intel.com> > Cc: Daniel Vetter <daniel.vetter@intel.com> > Cc: stable@vger.kernel.org > --- > drivers/gpu/drm/i915/i915_debugfs.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c > index 784219962193..ea469168cd44 100644 > --- a/drivers/gpu/drm/i915/i915_debugfs.c > +++ b/drivers/gpu/drm/i915/i915_debugfs.c > @@ -326,6 +326,7 @@ static void print_context_stats(struct seq_file *m, > } > i915_gem_context_unlock_engines(ctx); > > + mutex_lock(&ctx->mutex); > if (!IS_ERR_OR_NULL(ctx->file_priv)) { > struct file_stats stats = { > .vm = rcu_access_pointer(ctx->vm), > @@ -346,6 +347,7 @@ static void print_context_stats(struct seq_file *m, > > print_file_stats(m, name, stats); > } > + mutex_unlock(&ctx->mutex); > > spin_lock(&i915->gem.contexts.lock); > list_safe_reset_next(ctx, cn, link); > Hm this apparently never got it's r-b and so got re-discovered in the field. +Nikunj Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Regards, Tvrtko _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Intel-gfx] [PATCH 3/3] drm/i915/gem: Serialise debugfs i915_gem_objects with ctx->mutex 2020-09-14 16:45 ` [Intel-gfx] [PATCH 3/3] drm/i915/gem: Serialise debugfs i915_gem_objects with ctx->mutex Tvrtko Ursulin @ 2020-09-16 7:42 ` Daniel Vetter 2020-09-16 8:27 ` Tvrtko Ursulin 0 siblings, 1 reply; 3+ messages in thread From: Daniel Vetter @ 2020-09-16 7:42 UTC (permalink / raw) To: Tvrtko Ursulin Cc: intel-gfx, stable, Nikunj A. Dadhania, dri-devel, Daniel Vetter, Chris Wilson On Mon, Sep 14, 2020 at 05:45:09PM +0100, Tvrtko Ursulin wrote: > > On 23/07/2020 18:21, Chris Wilson wrote: > > Since the debugfs may peek into the GEM contexts as the corresponding > > client/fd is being closed, we may try and follow a dangling pointer. > > However, the context closure itself is serialised with the ctx->mutex, > > so if we hold that mutex as we inspect the state coupled in the context, > > we know the pointers within the context are stable and will remain valid > > as we inspect their tables. > > > > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> > > Cc: CQ Tang <cq.tang@intel.com> > > Cc: Daniel Vetter <daniel.vetter@intel.com> > > Cc: stable@vger.kernel.org > > --- > > drivers/gpu/drm/i915/i915_debugfs.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c > > index 784219962193..ea469168cd44 100644 > > --- a/drivers/gpu/drm/i915/i915_debugfs.c > > +++ b/drivers/gpu/drm/i915/i915_debugfs.c > > @@ -326,6 +326,7 @@ static void print_context_stats(struct seq_file *m, > > } > > i915_gem_context_unlock_engines(ctx); > > + mutex_lock(&ctx->mutex); > > if (!IS_ERR_OR_NULL(ctx->file_priv)) { > > struct file_stats stats = { > > .vm = rcu_access_pointer(ctx->vm), > > @@ -346,6 +347,7 @@ static void print_context_stats(struct seq_file *m, > > print_file_stats(m, name, stats); > > } > > + mutex_unlock(&ctx->mutex); > > spin_lock(&i915->gem.contexts.lock); > > list_safe_reset_next(ctx, cn, link); > > > > Hm this apparently never got it's r-b and so got re-discovered in the field. > +Nikunj > > Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> I'm not super thrilled about patch 1 in this, for debugfs imo better to wrangle this in the driver. And without patch 1 and 2 this wont fix a whole lot. -Daniel > > Regards, > > Tvrtko > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Intel-gfx] [PATCH 3/3] drm/i915/gem: Serialise debugfs i915_gem_objects with ctx->mutex 2020-09-16 7:42 ` Daniel Vetter @ 2020-09-16 8:27 ` Tvrtko Ursulin 0 siblings, 0 replies; 3+ messages in thread From: Tvrtko Ursulin @ 2020-09-16 8:27 UTC (permalink / raw) To: Daniel Vetter Cc: intel-gfx, stable, Nikunj A. Dadhania, dri-devel, Daniel Vetter, Chris Wilson On 16/09/2020 08:42, Daniel Vetter wrote: > On Mon, Sep 14, 2020 at 05:45:09PM +0100, Tvrtko Ursulin wrote: >> >> On 23/07/2020 18:21, Chris Wilson wrote: >>> Since the debugfs may peek into the GEM contexts as the corresponding >>> client/fd is being closed, we may try and follow a dangling pointer. >>> However, the context closure itself is serialised with the ctx->mutex, >>> so if we hold that mutex as we inspect the state coupled in the context, >>> we know the pointers within the context are stable and will remain valid >>> as we inspect their tables. >>> >>> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> >>> Cc: CQ Tang <cq.tang@intel.com> >>> Cc: Daniel Vetter <daniel.vetter@intel.com> >>> Cc: stable@vger.kernel.org >>> --- >>> drivers/gpu/drm/i915/i915_debugfs.c | 2 ++ >>> 1 file changed, 2 insertions(+) >>> >>> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c >>> index 784219962193..ea469168cd44 100644 >>> --- a/drivers/gpu/drm/i915/i915_debugfs.c >>> +++ b/drivers/gpu/drm/i915/i915_debugfs.c >>> @@ -326,6 +326,7 @@ static void print_context_stats(struct seq_file *m, >>> } >>> i915_gem_context_unlock_engines(ctx); >>> + mutex_lock(&ctx->mutex); >>> if (!IS_ERR_OR_NULL(ctx->file_priv)) { >>> struct file_stats stats = { >>> .vm = rcu_access_pointer(ctx->vm), >>> @@ -346,6 +347,7 @@ static void print_context_stats(struct seq_file *m, >>> print_file_stats(m, name, stats); >>> } >>> + mutex_unlock(&ctx->mutex); >>> spin_lock(&i915->gem.contexts.lock); >>> list_safe_reset_next(ctx, cn, link); >>> >> >> Hm this apparently never got it's r-b and so got re-discovered in the field. >> +Nikunj >> >> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > > I'm not super thrilled about patch 1 in this, for debugfs imo better to > wrangle this in the driver. And without patch 1 and 2 this wont fix a > whole lot. I try to avoid spending too much time coming up with smart solutions for _debugfs_. So I was going by the fact it obviously fixes something so it is an improvement. But your proposal to swith iteration to files->contexts also seems would work. It would be slightly semantically different where it wouldn't show the contexts which are active on the GPU but clients have exited, but its debugfs so no one should care. Regards, Tvrtko _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-09-16 8:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20200723172119.17649-1-chris@chris-wilson.co.uk>
[not found] ` <20200723172119.17649-3-chris@chris-wilson.co.uk>
2020-09-14 16:45 ` [Intel-gfx] [PATCH 3/3] drm/i915/gem: Serialise debugfs i915_gem_objects with ctx->mutex Tvrtko Ursulin
2020-09-16 7:42 ` Daniel Vetter
2020-09-16 8:27 ` Tvrtko Ursulin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox