Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: "Zeng, Oak" <oak.zeng@intel.com>
Cc: "intel-xe@lists.freedesktop.org" <intel-xe@lists.freedesktop.org>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH] drm/xe: Unmap userptr in MMU invalidation notifier
Date: Tue, 30 Apr 2024 15:42:13 +0000	[thread overview]
Message-ID: <ZjERVdJYRq+Fl4X3@DUT025-TGLU.fm.intel.com> (raw)
In-Reply-To: <SA1PR11MB69916539EB7B6F7DD49E2214921A2@SA1PR11MB6991.namprd11.prod.outlook.com>

On Tue, Apr 30, 2024 at 09:11:42AM -0600, Zeng, Oak wrote:
> 
> 
> > -----Original Message-----
> > From: Brost, Matthew <matthew.brost@intel.com>
> > Sent: Monday, April 29, 2024 1:18 PM
> > To: Zeng, Oak <oak.zeng@intel.com>
> > Cc: intel-xe@lists.freedesktop.org; Thomas Hellström
> > <thomas.hellstrom@linux.intel.com>; stable@vger.kernel.org
> > Subject: Re: [PATCH] drm/xe: Unmap userptr in MMU invalidation notifier
> > 
> > On Mon, Apr 29, 2024 at 07:55:22AM -0600, Zeng, Oak wrote:
> > > Hi Matt
> > >
> > > > -----Original Message-----
> > > > From: Intel-xe <intel-xe-bounces@lists.freedesktop.org> On Behalf Of
> > > > Matthew Brost
> > > > Sent: Friday, April 26, 2024 7:33 PM
> > > > To: intel-xe@lists.freedesktop.org
> > > > Cc: Brost, Matthew <matthew.brost@intel.com>; Thomas Hellström
> > > > <thomas.hellstrom@linux.intel.com>; stable@vger.kernel.org
> > > > Subject: [PATCH] drm/xe: Unmap userptr in MMU invalidation notifier
> > > >
> > > > To be secure, when a userptr is invalidated the pages should be dma
> > > > unmapped ensuring the device can no longer touch the invalidated pages.
> > > >
> > > > Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel
> > GPUs")
> > > > Fixes: 12f4b58a37f4 ("drm/xe: Use hmm_range_fault to populate user
> > > > pages")
> > > > Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> > > > Cc: stable@vger.kernel.org # 6.8
> > > > Signed-off-by: Matthew Brost <matthew.brost@intel.com>
> > > > ---
> > > >  drivers/gpu/drm/xe/xe_vm.c | 3 +++
> > > >  1 file changed, 3 insertions(+)
> > > >
> > > > diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> > > > index dfd31b346021..964a5b4d47d8 100644
> > > > --- a/drivers/gpu/drm/xe/xe_vm.c
> > > > +++ b/drivers/gpu/drm/xe/xe_vm.c
> > > > @@ -637,6 +637,9 @@ static bool vma_userptr_invalidate(struct
> > > > mmu_interval_notifier *mni,
> > > >  		XE_WARN_ON(err);
> > > >  	}
> > > >
> > > > +	if (userptr->sg)
> > > > +		xe_hmm_userptr_free_sg(uvma);
> > >
> > > Just some thoughts here. I think when we introduce system allocator,
> > above should be made conditional. We should dma unmap userptr only for
> > normal userptr but not for userptr created for system allocator (fault usrptr
> > in the system allocator series). Because for system allocator the dma-
> > unmapping would be part of the garbage collector and vma destroy process.
> > Right?
> > >
> > 
> > I don't think it should be conditional. In any case when a CPU address
> > is invalidated we need to ensure the dma mapping (IOMMU mapping) is
> > also invalid to ensure no path to the old (invalidate) pages exists.
> 
> I understand for both normal userptr and fault userptr we need to dma unmap.
> 
> I was saying, for fault userptr, the dma unmap would be done in the garbage collector codes (we destroy fault userptr vma there and dma unmap along with vam destroy), so we don't need dma unmap in your above codes. It would something like this:
> 

I understand what you are suggesting, but no this is always needed.

> If (userptr && not fault userptr)
> 	Dma-unmap sg
> 

With what you suggest, there is a window between the MMU notifier
completing and garbage collector running in which the dma-mapping is
valid. This is not allowed per the security model. Thus we need always
invalidate dma-addresses in the notifier.

Matt

> If (fault userptr)
> 	Trigger garbage collector - this will deal with dma-unmap
> 
> 
> Oak 
> 
> 
> > This is an extra security that must be enforced. With removing the dma
> > mapping, in theory rouge accesses from the GPU could still access the
> > old pages.
> > 
> > Matt
> > 
> > > Oak
> > >
> > > > +
> > > >  	trace_xe_vma_userptr_invalidate_complete(vma);
> > > >
> > > >  	return true;
> > > > --
> > > > 2.34.1
> > >

  reply	other threads:[~2024-04-30 15:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-26 23:32 [PATCH] drm/xe: Unmap userptr in MMU invalidation notifier Matthew Brost
2024-04-26 23:37 ` ✓ CI.Patch_applied: success for " Patchwork
2024-04-26 23:37 ` ✓ CI.checkpatch: " Patchwork
2024-04-26 23:38 ` ✓ CI.KUnit: " Patchwork
2024-04-29  1:11 ` [PATCH] " Matthew Brost
2024-04-29 13:05   ` Thomas Hellström
2024-04-29 13:55 ` Zeng, Oak
2024-04-29 17:18   ` Matthew Brost
2024-04-30 15:11     ` Zeng, Oak
2024-04-30 15:42       ` Matthew Brost [this message]
2024-05-01  0:40         ` Zeng, Oak
  -- strict thread matches above, loose matches on Subject: below --
2024-04-30  3:00 Matthew Brost

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=ZjERVdJYRq+Fl4X3@DUT025-TGLU.fm.intel.com \
    --to=matthew.brost@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=oak.zeng@intel.com \
    --cc=stable@vger.kernel.org \
    --cc=thomas.hellstrom@linux.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