[PATCH] drm/xe: Assume large page size if VMA not yet bound

Matthew Brost matthew.brost at intel.com
Mon Feb 5 23:48:43 UTC 2024


On Mon, Feb 05, 2024 at 06:23:14PM -0500, Rodrigo Vivi wrote:
> On Mon, Feb 05, 2024 at 03:17:14PM -0800, Matthew Brost wrote:
> > The calculation to determine max page size of a VMA during a REMAP
> > operations assumes the VMA has been bound. This assumption is not true
> > if the VMA is from an eariler operation in an array of binds. If a VMA
> > has not been bound use the maximum page size which will ensure the
> > previous / next REMAP operations are not incorrectly skipped.
> > 
> > Fixes: 8f33b4f054fc ("drm/xe: Avoid doing rebinds")
> > Signed-off-by: Matthew Brost <matthew.brost at intel.com>
> > ---
> >  drivers/gpu/drm/xe/xe_vm.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> > index 7e29b816c4d4..ed594fa2f8da 100644
> > --- a/drivers/gpu/drm/xe/xe_vm.c
> > +++ b/drivers/gpu/drm/xe/xe_vm.c
> > @@ -2200,8 +2200,10 @@ static u64 xe_vma_max_pte_size(struct xe_vma *vma)
> >  		return SZ_1G;
> >  	else if (vma->gpuva.flags & XE_VMA_PTE_2M)
> >  		return SZ_2M;
> > +	else if (vma->gpuva.flags & XE_VMA_PTE_4K)
> > +		return SZ_4K;
> 
> I wonder if we should also have something like:
> else if (vma->gpuva.flags & XE_VMA_PTE_1G)
>      return SZ_1G;
> 

This is the first if statement in xe_vma_max_pte_size.

> drm_err("Something wrong with gpuva flags, using max known page anyway\n");

This is not an error the user doing very odd. Let me give an example.

In an array of binds:

1. MAP 0-4MB
2. UNMAP 1MB-3MB

#2 directly modifies #1, the vma->gpuva.flags gets set in the page
walking step of IOCTL which has yet been executed when
xe_vma_max_pte_size() is called. If a page size of #1 returns 4k
(incorrect as the page will be 2MB) #2 will just do partial UNMAP rather
than a full UNMAP + 2 REMAPs.

Agin very silly user but the user should be able to break the kernel or
trigger an error message.

Matt

> return SZ_1G;
> 
> but up to you...
> 
> Reviewed-by: Rodrigo Vivi <rodrigo.vivi at intel.com>
> 
> >  
> > -	return SZ_4K;
> > +	return SZ_1G;	/* Uninitialized, used max size */
> >  }
> >  
> >  static u64 xe_vma_set_pte_size(struct xe_vma *vma, u64 size)
> > -- 
> > 2.34.1
> > 


More information about the Intel-xe mailing list