[RFC 08/12] drm/xe: Rename lookup_vma function to xe_find_vma_by_addr

Matthew Brost matthew.brost at intel.com
Fri Mar 28 02:58:23 UTC 2025


On Mon, Mar 10, 2025 at 06:13:37PM +0530, Himal Prasad Ghimiray wrote:
> This update renames the lookup_vma function to xe_vm_find_vma_by_addr and
> makes it accessible externally. The function, which looks up a VMA by
> its address within a specified VM, will be utilized in upcoming patches.
> 
> Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray at intel.com>
> ---

Reviewed-by: Matthew Brost <matthew.brost at intel.com>

>  drivers/gpu/drm/xe/xe_gt_pagefault.c | 24 +----------------------
>  drivers/gpu/drm/xe/xe_vm.c           | 29 ++++++++++++++++++++++++++++
>  drivers/gpu/drm/xe/xe_vm.h           |  2 ++
>  3 files changed, 32 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_gt_pagefault.c b/drivers/gpu/drm/xe/xe_gt_pagefault.c
> index c5ad9a0a89c2..3aaf4090fcfe 100644
> --- a/drivers/gpu/drm/xe/xe_gt_pagefault.c
> +++ b/drivers/gpu/drm/xe/xe_gt_pagefault.c
> @@ -72,28 +72,6 @@ static bool vma_is_valid(struct xe_tile *tile, struct xe_vma *vma)
>  		!(BIT(tile->id) & vma->tile_invalidated);
>  }
>  
> -static bool vma_matches(struct xe_vma *vma, u64 page_addr)
> -{
> -	if (page_addr > xe_vma_end(vma) - 1 ||
> -	    page_addr + SZ_4K - 1 < xe_vma_start(vma))
> -		return false;
> -
> -	return true;
> -}
> -
> -static struct xe_vma *lookup_vma(struct xe_vm *vm, u64 page_addr)
> -{
> -	struct xe_vma *vma = NULL;
> -
> -	if (vm->usm.last_fault_vma) {   /* Fast lookup */
> -		if (vma_matches(vm->usm.last_fault_vma, page_addr))
> -			vma = vm->usm.last_fault_vma;
> -	}
> -	if (!vma)
> -		vma = xe_vm_find_overlapping_vma(vm, page_addr, SZ_4K);
> -
> -	return vma;
> -}
>  
>  static int xe_pf_begin(struct drm_exec *exec, struct xe_vma *vma,
>  		       bool atomic, unsigned int id)
> @@ -231,7 +209,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
>  		goto unlock_vm;
>  	}
>  
> -	vma = lookup_vma(vm, pf->page_addr);
> +	vma = xe_vm_find_vma_by_addr(vm, pf->page_addr);
>  	if (!vma) {
>  		err = -EINVAL;
>  		goto unlock_vm;
> diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> index 3dd08dd5e6d5..a54e78621074 100644
> --- a/drivers/gpu/drm/xe/xe_vm.c
> +++ b/drivers/gpu/drm/xe/xe_vm.c
> @@ -2138,6 +2138,35 @@ int xe_vm_destroy_ioctl(struct drm_device *dev, void *data,
>  	return err;
>  }
>  
> +static bool vma_matches(struct xe_vma *vma, u64 page_addr)
> +{
> +	if (page_addr > xe_vma_end(vma) - 1 ||
> +	    page_addr + SZ_4K - 1 < xe_vma_start(vma))
> +		return false;
> +
> +	return true;
> +}
> +
> +/**
> + * xe_vm_find_vma_by_addr() - Find a VMA by its address
> + *
> + * @vm: the xe_vm the vma belongs to
> + * @page_address: address to look up
> + */
> +struct xe_vma *xe_vm_find_vma_by_addr(struct xe_vm *vm, u64 page_addr)
> +{
> +	struct xe_vma *vma = NULL;
> +
> +	if (vm->usm.last_fault_vma) {   /* Fast lookup */
> +		if (vma_matches(vm->usm.last_fault_vma, page_addr))
> +			vma = vm->usm.last_fault_vma;
> +	}
> +	if (!vma)
> +		vma = xe_vm_find_overlapping_vma(vm, page_addr, SZ_4K);
> +
> +	return vma;
> +}
> +
>  static const u32 region_to_mem_type[] = {
>  	XE_PL_TT,
>  	XE_PL_VRAM0,
> diff --git a/drivers/gpu/drm/xe/xe_vm.h b/drivers/gpu/drm/xe/xe_vm.h
> index 0ef811fc2bde..99e164852f63 100644
> --- a/drivers/gpu/drm/xe/xe_vm.h
> +++ b/drivers/gpu/drm/xe/xe_vm.h
> @@ -169,6 +169,8 @@ static inline bool xe_vma_is_userptr(struct xe_vma *vma)
>  		!xe_vma_is_cpu_addr_mirror(vma);
>  }
>  
> +struct xe_vma *xe_vm_find_vma_by_addr(struct xe_vm *vm, u64 page_addr);
> +
>  /**
>   * to_userptr_vma() - Return a pointer to an embedding userptr vma
>   * @vma: Pointer to the embedded struct xe_vma
> -- 
> 2.34.1
> 


More information about the Intel-xe mailing list