On Sat, Oct 25, 2025 at 02:04:08PM +0200, Thomas Hellström wrote:
> Simplify madvise_preferred_mem_loc by removing repetitive patterns
> in favour of local variables.
> 
> Signed-off-by: Thomas Hellström <[email protected]>

Reviewed-by: Matthew Brost <[email protected]>

Feel free to send a version of patch out on drm-tip, keep the RB, and
merge it as this change can go in ahead of the entire series.

Matt

> ---
>  drivers/gpu/drm/xe/xe_vm_madvise.c | 21 +++++++++++----------
>  drivers/gpu/drm/xe/xe_vm_types.h   |  2 +-
>  2 files changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_vm_madvise.c 
> b/drivers/gpu/drm/xe/xe_vm_madvise.c
> index 9553008409d1..d6f47c8e146d 100644
> --- a/drivers/gpu/drm/xe/xe_vm_madvise.c
> +++ b/drivers/gpu/drm/xe/xe_vm_madvise.c
> @@ -81,21 +81,22 @@ static void madvise_preferred_mem_loc(struct xe_device 
> *xe, struct xe_vm *vm,
>       xe_assert(vm->xe, op->type == DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC);
>  
>       for (i = 0; i < num_vmas; i++) {
> +             struct xe_vma *vma = vmas[i];
> +             struct xe_vma_preferred_loc *loc = &vma->attr.preferred_loc;
> +
>               /*TODO: Extend attributes to bo based vmas */
> -             if ((vmas[i]->attr.preferred_loc.devmem_fd == 
> op->preferred_mem_loc.devmem_fd &&
> -                  vmas[i]->attr.preferred_loc.migration_policy ==
> -                  op->preferred_mem_loc.migration_policy) ||
> -                 !xe_vma_is_cpu_addr_mirror(vmas[i])) {
> -                     vmas[i]->skip_invalidation = true;
> +             if ((loc->devmem_fd == op->preferred_mem_loc.devmem_fd &&
> +                  loc->migration_policy == 
> op->preferred_mem_loc.migration_policy) ||
> +                 !xe_vma_is_cpu_addr_mirror(vma)) {
> +                     vma->skip_invalidation = true;
>               } else {
> -                     vmas[i]->skip_invalidation = false;
> -                     vmas[i]->attr.preferred_loc.devmem_fd = 
> op->preferred_mem_loc.devmem_fd;
> +                     vma->skip_invalidation = false;
> +                     loc->devmem_fd = op->preferred_mem_loc.devmem_fd;
>                       /* Till multi-device support is not added 
> migration_policy
>                        * is of no use and can be ignored.
>                        */
> -                     vmas[i]->attr.preferred_loc.migration_policy =
> -                                             
> op->preferred_mem_loc.migration_policy;
> -                     vmas[i]->attr.preferred_loc.dpagemap = NULL;
> +                     loc->migration_policy = 
> op->preferred_mem_loc.migration_policy;
> +                     loc->dpagemap = NULL;
>               }
>       }
>  }
> diff --git a/drivers/gpu/drm/xe/xe_vm_types.h 
> b/drivers/gpu/drm/xe/xe_vm_types.h
> index 5313bf2afa54..a83a0bda6861 100644
> --- a/drivers/gpu/drm/xe/xe_vm_types.h
> +++ b/drivers/gpu/drm/xe/xe_vm_types.h
> @@ -56,7 +56,7 @@ struct xe_vm_pgtable_update_op;
>   */
>  struct xe_vma_mem_attr {
>       /** @preferred_loc: perferred memory_location */
> -     struct {
> +     struct xe_vma_preferred_loc {
>               /** @preferred_loc.migration_policy: Pages migration policy */
>               u32 migration_policy;
>  
> -- 
> 2.51.0
> 

Reply via email to