From: Niranjan Vishwanathapura <niranjana.vishwanathapura@intel.com> To: Chris Wilson <chris@chris-wilson.co.uk> Cc: intel-gfx@lists.freedesktop.org Subject: Re: [PATCH] drm/i915/gem: Safely acquire the ctx->vm when copying Date: Thu, 7 Nov 2019 11:40:59 -0800 [thread overview] Message-ID: <20191107194059.GI19940@nvishwa1-DESK.sc.intel.com> (raw) In-Reply-To: <157314607464.2228.12518419712996055704@skylake-alporthouse-com> On Thu, Nov 07, 2019 at 05:01:14PM +0000, Chris Wilson wrote: >Quoting Niranjan Vishwanathapura (2019-11-07 16:09:31) >> On Wed, Nov 06, 2019 at 09:13:12AM +0000, Chris Wilson wrote: >> >As we read the ctx->vm unlocked before cloning/exporting, we should >> >validate our reference is correct before returning it. We already do for >> >clone_vm() but were not so strict around get_ppgtt(). >> > >> >Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> >> >--- >> > drivers/gpu/drm/i915/gem/i915_gem_context.c | 80 +++++++++++---------- >> > 1 file changed, 43 insertions(+), 37 deletions(-) >> > >> >diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c >> >index de6e55af82cf..a06cc8e63281 100644 >> >--- a/drivers/gpu/drm/i915/gem/i915_gem_context.c >> >+++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c >> >@@ -995,6 +995,38 @@ static int context_barrier_task(struct i915_gem_context *ctx, >> > return err; >> > } >> > >> >+static struct i915_address_space * >> >+context_get_vm_rcu(struct i915_gem_context *ctx) >> >+{ >> >+ do { >> >+ struct i915_address_space *vm; >> >+ >> >+ vm = rcu_dereference(ctx->vm); >> >+ if (!kref_get_unless_zero(&vm->ref)) >> >+ continue; >> >> But should we check for NULL vm? >> I know the callers are ensuring ctx->vm will not be NULL, but just wondering. > >We don't need to as the rule is that ctx->vm once set can never be >unset; and it can only be set during construction based on the HW >properties. The idea is that !!ctx->vm is an invariant indicating >whether or not we have full-ppgtt enabled. From a security perspective, >allowing a downgrade from full-ppgtt to a shared global gtt is a big no, >so I don't anticipating us allowing setting ctx->vm to NULL anytime in >the near future :) OK, sounds right. > >> >+ >> >+ /* >> >+ * 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 src, >> >+ * we no longer care if it is released from src, as >> >+ * it cannot be reallocated elsewhere. >> >+ */ >> >> Comment should be made generic? It is too specific to cloning case. > >s/src/ctx/ >-Chris _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx
WARNING: multiple messages have this Message-ID (diff)
From: Niranjan Vishwanathapura <niranjana.vishwanathapura@intel.com> To: Chris Wilson <chris@chris-wilson.co.uk> Cc: intel-gfx@lists.freedesktop.org Subject: Re: [Intel-gfx] [PATCH] drm/i915/gem: Safely acquire the ctx->vm when copying Date: Thu, 7 Nov 2019 11:40:59 -0800 [thread overview] Message-ID: <20191107194059.GI19940@nvishwa1-DESK.sc.intel.com> (raw) Message-ID: <20191107194059.lOegiJl5KgS1-y9vxa7JDuWIN14U7QviGp-O_UChOLw@z> (raw) In-Reply-To: <157314607464.2228.12518419712996055704@skylake-alporthouse-com> On Thu, Nov 07, 2019 at 05:01:14PM +0000, Chris Wilson wrote: >Quoting Niranjan Vishwanathapura (2019-11-07 16:09:31) >> On Wed, Nov 06, 2019 at 09:13:12AM +0000, Chris Wilson wrote: >> >As we read the ctx->vm unlocked before cloning/exporting, we should >> >validate our reference is correct before returning it. We already do for >> >clone_vm() but were not so strict around get_ppgtt(). >> > >> >Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> >> >--- >> > drivers/gpu/drm/i915/gem/i915_gem_context.c | 80 +++++++++++---------- >> > 1 file changed, 43 insertions(+), 37 deletions(-) >> > >> >diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c >> >index de6e55af82cf..a06cc8e63281 100644 >> >--- a/drivers/gpu/drm/i915/gem/i915_gem_context.c >> >+++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c >> >@@ -995,6 +995,38 @@ static int context_barrier_task(struct i915_gem_context *ctx, >> > return err; >> > } >> > >> >+static struct i915_address_space * >> >+context_get_vm_rcu(struct i915_gem_context *ctx) >> >+{ >> >+ do { >> >+ struct i915_address_space *vm; >> >+ >> >+ vm = rcu_dereference(ctx->vm); >> >+ if (!kref_get_unless_zero(&vm->ref)) >> >+ continue; >> >> But should we check for NULL vm? >> I know the callers are ensuring ctx->vm will not be NULL, but just wondering. > >We don't need to as the rule is that ctx->vm once set can never be >unset; and it can only be set during construction based on the HW >properties. The idea is that !!ctx->vm is an invariant indicating >whether or not we have full-ppgtt enabled. From a security perspective, >allowing a downgrade from full-ppgtt to a shared global gtt is a big no, >so I don't anticipating us allowing setting ctx->vm to NULL anytime in >the near future :) OK, sounds right. > >> >+ >> >+ /* >> >+ * 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 src, >> >+ * we no longer care if it is released from src, as >> >+ * it cannot be reallocated elsewhere. >> >+ */ >> >> Comment should be made generic? It is too specific to cloning case. > >s/src/ctx/ >-Chris _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2019-11-07 19:52 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-11-06 9:13 [PATCH] drm/i915/gem: Safely acquire the ctx->vm when copying Chris Wilson 2019-11-06 9:13 ` [Intel-gfx] " Chris Wilson 2019-11-06 11:20 ` ✓ Fi.CI.BAT: success for " Patchwork 2019-11-06 11:20 ` [Intel-gfx] " Patchwork 2019-11-07 7:44 ` ✓ Fi.CI.IGT: " Patchwork 2019-11-07 7:44 ` [Intel-gfx] " Patchwork 2019-11-07 16:09 ` [PATCH] " Niranjan Vishwanathapura 2019-11-07 16:09 ` [Intel-gfx] " Niranjan Vishwanathapura 2019-11-07 17:01 ` Chris Wilson 2019-11-07 17:01 ` [Intel-gfx] " Chris Wilson 2019-11-07 19:40 ` Niranjan Vishwanathapura [this message] 2019-11-07 19:40 ` Niranjan Vishwanathapura
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=20191107194059.GI19940@nvishwa1-DESK.sc.intel.com \ --to=niranjana.vishwanathapura@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: linkBe 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.