Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: "Upadhyay, Tejas" <tejas.upadhyay@intel.com>
Cc: "intel-xe@lists.freedesktop.org" <intel-xe@lists.freedesktop.org>,
	"Zanoni, Paulo R" <paulo.r.zanoni@intel.com>,
	"maarten.lankhorst@linux.intel.com"
	<maarten.lankhorst@linux.intel.com>
Subject: Re: [PATCH] drm/xe: Take ref to VM in delayed snapshot
Date: Fri, 26 Jul 2024 12:13:12 +0000	[thread overview]
Message-ID: <ZqOS2JknVn+/Ui/4@DUT025-TGLU.fm.intel.com> (raw)
In-Reply-To: <SJ1PR11MB6204C26850EE7C5D5D115F7D81B42@SJ1PR11MB6204.namprd11.prod.outlook.com>

On Fri, Jul 26, 2024 at 02:17:04AM -0600, Upadhyay, Tejas wrote:
> 
> 
> > -----Original Message-----
> > From: Intel-xe <intel-xe-bounces@lists.freedesktop.org> On Behalf Of
> > Matthew Brost
> > Sent: Friday, July 26, 2024 4:54 AM
> > To: intel-xe@lists.freedesktop.org
> > Cc: Zanoni, Paulo R <paulo.r.zanoni@intel.com>;
> > maarten.lankhorst@linux.intel.com
> > Subject: [PATCH] drm/xe: Take ref to VM in delayed snapshot
> > 
> > Kernel BO's don't take a ref to the VM, we need to the VM for the delayed
> > snapshot, so take a ref to the VM in delayed snapshot.
> 
> Can you please give some details why VM needed now!
> 

If the BO has a VM it shares a dma-resv lock with the VM, thus if the VM
is freed before the TTM object individualized step of a BO we get a UAF.

Ideally we want kernel BOs with a VM to take ref to the VM in a BO layer
(see __xe_bo_create_locked) but there is circular dependency for kernel
BO and VMs which need to get worked out. I'll look into fix that when I
have sometime.

But in meantime this will fix a UAF so it would be good to get in.

Matt

> Tejas
> > 
> > 47058633d9c5 ("drm/xe: Move lrc snapshot capturing to xe_lrc.c")
> > Cc: Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> > Signed-off-by: Matthew Brost <matthew.brost@intel.com>
> > ---
> >  drivers/gpu/drm/xe/xe_lrc.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/xe/xe_lrc.c b/drivers/gpu/drm/xe/xe_lrc.c index
> > 94ff62e1d95e..9ef9b45a3596 100644
> > --- a/drivers/gpu/drm/xe/xe_lrc.c
> > +++ b/drivers/gpu/drm/xe/xe_lrc.c
> > @@ -1634,6 +1634,8 @@ struct xe_lrc_snapshot
> > *xe_lrc_snapshot_capture(struct xe_lrc *lrc)
> >  	if (!snapshot)
> >  		return NULL;
> > 
> > +	xe_vm_get(lrc->bo->vm);
> > +
> >  	snapshot->context_desc = xe_lrc_ggtt_addr(lrc);
> >  	snapshot->indirect_context_desc =
> > xe_lrc_indirect_ring_ggtt_addr(lrc);
> >  	snapshot->head = xe_lrc_ring_head(lrc); @@ -1653,12 +1655,14 @@
> > struct xe_lrc_snapshot *xe_lrc_snapshot_capture(struct xe_lrc *lrc)  void
> > xe_lrc_snapshot_capture_delayed(struct xe_lrc_snapshot *snapshot)  {
> >  	struct xe_bo *bo;
> > +	struct xe_vm *vm;
> >  	struct iosys_map src;
> > 
> >  	if (!snapshot)
> >  		return;
> > 
> >  	bo = snapshot->lrc_bo;
> > +	vm = bo->vm;
> >  	snapshot->lrc_bo = NULL;
> > 
> >  	snapshot->lrc_snapshot = kvmalloc(snapshot->lrc_size, GFP_KERNEL);
> > @@ -1678,6 +1682,7 @@ void xe_lrc_snapshot_capture_delayed(struct
> > xe_lrc_snapshot *snapshot)
> >  	xe_bo_unlock(bo);
> >  put_bo:
> >  	xe_bo_put(bo);
> > +	xe_vm_put(vm);
> >  }
> > 
> >  void xe_lrc_snapshot_print(struct xe_lrc_snapshot *snapshot, struct
> > drm_printer *p)
> > --
> > 2.34.1
> 

  reply	other threads:[~2024-07-26 12:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-25 23:24 [PATCH] drm/xe: Take ref to VM in delayed snapshot Matthew Brost
2024-07-26  0:09 ` ✓ CI.Patch_applied: success for " Patchwork
2024-07-26  0:10 ` ✗ CI.checkpatch: warning " Patchwork
2024-07-26  0:11 ` ✓ CI.KUnit: success " Patchwork
2024-07-26  0:23 ` ✓ CI.Build: " Patchwork
2024-07-26  0:26 ` ✓ CI.Hooks: " Patchwork
2024-07-26  0:28 ` ✓ CI.checksparse: " Patchwork
2024-07-26  0:51 ` ✗ CI.BAT: failure " Patchwork
2024-07-26 12:36   ` Matthew Brost
2024-07-26  8:17 ` [PATCH] " Upadhyay, Tejas
2024-07-26 12:13   ` Matthew Brost [this message]
2024-07-26  9:27 ` ✗ CI.FULL: failure for " 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=ZqOS2JknVn+/Ui/4@DUT025-TGLU.fm.intel.com \
    --to=matthew.brost@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=paulo.r.zanoni@intel.com \
    --cc=tejas.upadhyay@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox