[PATCH i-g-t 3/5] lib/xe: Helper added to get memory attributes

Gurram, Pravalika pravalika.gurram at intel.com
Thu Aug 28 14:56:05 UTC 2025



> -----Original Message-----
> From: igt-dev <igt-dev-bounces at lists.freedesktop.org> On Behalf Of
> nishit.sharma at intel.com
> Sent: Tuesday, August 26, 2025 2:12 PM
> To: igt-dev at lists.freedesktop.org; Ghimiray, Himal Prasad
> <himal.prasad.ghimiray at intel.com>; Brost, Matthew
> <matthew.brost at intel.com>; Sharma, Nishit <nishit.sharma at intel.com>
> Subject: [PATCH i-g-t 3/5] lib/xe: Helper added to get memory attributes
> 
commit title can be " lib/xe/ioctl: Introduce xe_vm_print_mem_attr_values_in_range() helper"
> From: Nishit Sharma <nishit.sharma at intel.com>
> 
> xe_vm_print_mem_attr_values_in_range() function added which calls
> QUERY_MEM_RANGES_ATTRS ioctl to get different memory attributes from
> KMD and then prints memory attributes returned by KMD for different
> access policies like atomic access, preferred loc and pat index.
> 

Same here please use add 

--  Pravalika
> Signed-off-by: Nishit Sharma <nishit.sharma at intel.com>
> ---
>  lib/xe/xe_ioctl.c | 92
> +++++++++++++++++++++++++++++++++++++++++++++++
>  lib/xe/xe_ioctl.h |  4 +++
>  2 files changed, 96 insertions(+)
> 
> diff --git a/lib/xe/xe_ioctl.c b/lib/xe/xe_ioctl.c index 43bad8452..4ab2ef39c
> 100644
> --- a/lib/xe/xe_ioctl.c
> +++ b/lib/xe/xe_ioctl.c
> @@ -57,6 +57,98 @@ uint64_t xe_bb_size(int fd, uint64_t reqsize)
>  	             xe_get_default_alignment(fd));  }
> 
> +int xe_vm_number_vmas_in_range(int fd, struct
> +drm_xe_vm_query_mem_range_attr *vmas_attr) {
> +	if (igt_ioctl(fd, DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS,
> vmas_attr))
> +		return -errno;
> +	return 0;
> +}
> +
> +int xe_vm_vma_attrs(int fd, struct drm_xe_vm_query_mem_range_attr
> *vmas_attr,
> +		    struct drm_xe_mem_range_attr *mem_attr) {
> +	if (!mem_attr)
> +		return -EINVAL;
> +
> +	vmas_attr->vector_of_mem_attr = (uintptr_t)mem_attr;
> +
> +	if (igt_ioctl(fd, DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS,
> vmas_attr))
> +		return -errno;
> +
> +	return 0;
> +}
> +
> +/**
> + * xe_vm_print_mem_attr_values_in_range:
> + * @fd: xe device fd
> + * @vm: vm_id of the virtual range
> + * @start: start of the virtual address range
> + * @range: size of the virtual address range
> + *
> + * Calls QUERY_MEM_RANGES_ATTRS ioctl to get memory attributes for
> +different
> + * memory ranges from KMD. prints memory attributes as returned by KMD
> +for
> + * atomic, prefrred loc and pat index types.
> + *
> + * Returns 0 for success or error for failure  */
> +
> +int xe_vm_print_mem_attr_values_in_range(int fd, uint32_t vm, uint64_t
> +start, uint64_t range) {
> +
> +	void *ptr_start, *ptr;
> +	int err;
> +	struct drm_xe_vm_query_mem_range_attr query = {
> +		.vm_id = vm,
> +		.start = start,
> +		.range = range,
> +		.num_mem_ranges = 0,
> +		.sizeof_mem_range_attr = 0,
> +		.vector_of_mem_attr = (uintptr_t)NULL,
> +	};
> +
> +	igt_debug("mem_attr_values_in_range called start = %"PRIu64"\n
> range = %"PRIu64"\n",
> +		  start, range);
> +
> +	err  = xe_vm_number_vmas_in_range(fd, &query);
> +	if (err || !query.num_mem_ranges ||
> !query.sizeof_mem_range_attr) {
> +		igt_warn("ioctl failed for
> xe_vm_number_vmas_in_range\n");
> +		igt_debug("vmas_in_range err = %d
> query.num_mem_ranges = %u query.sizeof_mem_range_attr=%lld\n",
> +			 err, query.num_mem_ranges,
> query.sizeof_mem_range_attr);
> +		return err;
> +	}
> +
> +	/* Allocate buffer for the memory region attributes */
> +	ptr = malloc(query.num_mem_ranges *
> query.sizeof_mem_range_attr);
> +	ptr_start = ptr;
> +
> +	if (!ptr)
> +		return -ENOMEM;
> +
> +	err = xe_vm_vma_attrs(fd, &query, ptr);
> +	if (err) {
> +		igt_warn("ioctl failed for vma_attrs err = %d\n", err);
> +		return err;
> +	}
> +
> +	/* Iterate over the returned memory region attributes */
> +	for (unsigned int i = 0; i < query.num_mem_ranges; ++i) {
> +		struct drm_xe_mem_range_attr *mem_attrs = (struct
> +drm_xe_mem_range_attr *)ptr;
> +
> +		igt_info("vma_id = %d\nvma_start = 0x%016llx\nvma_end =
> 0x%016llx\n"
> +				"vma:atomic = %d\nvma:pat_index =
> %d\nvma:preferred_loc_region = %d\n"
> +				"vma:preferred_loc_devmem_fd =
> %d\n\n\n", i, mem_attrs->start,
> +				mem_attrs->end,
> +				mem_attrs->atomic.val, mem_attrs-
> >pat_index.val,
> +				mem_attrs-
> >preferred_mem_loc.migration_policy,
> +				mem_attrs-
> >preferred_mem_loc.devmem_fd);
> +
> +		ptr += query.sizeof_mem_range_attr;
> +	}
> +
> +	free(ptr_start);
> +	return 0;
> +}
> +
>  uint32_t xe_vm_create(int fd, uint32_t flags, uint64_t ext)  {
>  	struct drm_xe_vm_create create = {
> diff --git a/lib/xe/xe_ioctl.h b/lib/xe/xe_ioctl.h index a5996cf65..ae16af233
> 100644
> --- a/lib/xe/xe_ioctl.h
> +++ b/lib/xe/xe_ioctl.h
> @@ -103,4 +103,8 @@ int __xe_vm_madvise(int fd, uint32_t vm, uint64_t
> addr, uint64_t range, uint64_t
>  		    uint32_t type, uint32_t op_val, uint16_t policy);  int
> xe_vm_madvise(int fd, uint32_t vm, uint64_t addr, uint64_t range, uint64_t
> ext,
>  		  uint32_t type, uint32_t op_val, uint16_t policy);
> +int xe_vm_number_vmas_in_range(int fd, struct
> +drm_xe_vm_query_mem_range_attr *vmas_attr); int
> xe_vm_vma_attrs(int fd, struct drm_xe_vm_query_mem_range_attr
> *vmas_attr,
> +		    struct drm_xe_mem_range_attr *mem_attr); int
> +xe_vm_print_mem_attr_values_in_range(int fd, uint32_t vm, uint64_t
> +start, uint64_t range);
>  #endif /* XE_IOCTL_H */
> --
> 2.43.0



More information about the igt-dev mailing list