[PATCH i-g-t v2] tests/intel/xm_vm: add coverage for userptr transparent huge pages

Kamil Konieczny kamil.konieczny at linux.intel.com
Fri Apr 18 14:30:21 UTC 2025


Hi Matthew,
On 2025-03-28 at 18:19:37 +0000, Matthew Auld wrote:

small nit in subjetc:

[PATCH i-g-t v2] tests/intel/xm_vm: add coverage for userptr transparent huge pages

s/xm_vm:/xe_vm:/

so it will read:

[PATCH i-g-t v2] tests/intel/xe_vm: add coverage for userptr transparent huge pages

> In particular we are missing something to test partially mapping a
> huge-page, including being misaligned, such that the mm start and end
> address don't sit on the huge-page boundary.
> 
> v2:
>   - Fully expand thp term (Kamil)
> 
> Signed-off-by: Matthew Auld <matthew.auld at intel.com>
> Cc: Kamil Konieczny <kamil.konieczny at linux.intel.com>
> Cc: Thomas Hellström <thomas.hellstrom at linux.intel.com>
> Cc: Matthew Brost <matthew.brost at intel.com>
> ---
>  tests/intel/xe_vm.c | 55 +++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 51 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/intel/xe_vm.c b/tests/intel/xe_vm.c
> index fdf74c114..af4013f5e 100644
> --- a/tests/intel/xe_vm.c
> +++ b/tests/intel/xe_vm.c
> @@ -1281,6 +1281,7 @@ test_bind_array_conflict(int fd, struct drm_xe_engine_class_instance *eci,
>  #define LARGE_BIND_FLAG_MISALIGNED	(0x1 << 0)
>  #define LARGE_BIND_FLAG_SPLIT		(0x1 << 1)
>  #define LARGE_BIND_FLAG_USERPTR		(0x1 << 2)
> +#define LARGE_BIND_FLAG_USERPTR_THP	(0x1 << 3)
>  
>  /**
>   * SUBTEST: %s-%ld
> @@ -1312,6 +1313,9 @@ test_bind_array_conflict(int fd, struct drm_xe_engine_class_instance *eci,
>   * @large-userptr-split-binds: large-userptr-split-binds
>   * @large-userptr-misaligned-binds: large-userptr-misaligned-binds
>   * @large-userptr-split-misaligned-binds: large-userptr-split-misaligned-binds
> + * @large-userptr-thp-split-binds: large-userptr-split-binds with transparent-huge-page
> + * @large-userptr-thp-misaligned-binds: large-userptr-misaligned-binds with transparent-huge-page
> + * @large-userptr-thp-split-misaligned-binds: large-userptr-split-misaligned-binds with transparent-huge-page
>   *
>   * arg[2].values: 2097152, 4194304, 8388608, 16777216, 33554432
>   * arg[2].values: 67108864, 134217728, 268435456, 536870912, 1073741824
> @@ -1363,7 +1367,7 @@ test_large_binds(int fd, struct drm_xe_engine_class_instance *eci,
>  		.num_syncs = 2,
>  		.syncs = to_user_pointer(sync),
>  	};
> -	size_t bo_size_prefetch, padding;
> +	size_t bo_size_prefetch, padding, map_padding = 0;
>  	uint64_t addr = 0x1ull << 30, base_addr = 0x1ull << 30;
>  	uint32_t vm;
>  	uint32_t exec_queues[MAX_N_EXEC_QUEUES];
> @@ -1387,8 +1391,23 @@ test_large_binds(int fd, struct drm_xe_engine_class_instance *eci,
>  
>  	if (flags & LARGE_BIND_FLAG_USERPTR) {
>  		bo_size_prefetch = xe_bb_size(fd, bo_size);
> -		map = aligned_alloc(xe_get_default_alignment(fd), bo_size_prefetch);
> -		igt_assert(map);
> +
> +		if (flags & LARGE_BIND_FLAG_USERPTR_THP) {
> +			/* Ensure we try to partially map a transparent-huge-page */
> +			if (flags & LARGE_BIND_FLAG_MISALIGNED)
> +				map_padding = xe_get_default_alignment(fd);
> +
> +			map = aligned_alloc(xe_get_default_alignment(fd),
> +					    bo_size_prefetch + map_padding * 2);

Please calculate this for debug printing like:

	size_t align_size = xe_get_default_alignment(fd);
	size_t mem_wanted;
	size_t alloc_size;

	if (flags & LARGE_BIND_FLAG_MISALIGNED)
		map_padding = align_size;

	mem_wanted = bo_size_prefetch + map_padding * 2;
	alloc_size = DIV_ROUND_UP(mem_wanted, align_size) * align_size;
	igt_debug("Transparent huge pages for mem size %dKB padding %dKB\n", alloc_size / 1024, map_padding / 1024);
	map = aligned_alloc(align_size, alloc_size);

Btw in this test you assume that alloc_size should be big, like 2MB?
Or at least larger then PAGE_SIZE (4KB) ?


> +			igt_assert(map);
> +			madvise(map, bo_size_prefetch + map_padding * 2,
> +				MADV_HUGEPAGE);

			ret = madvise(map, alloc_size, MADV_HUGEPAGE);
			igt_assert_eq(ret, 0);


> +			map += map_padding;
> +		} else {
> +			map = aligned_alloc(xe_get_default_alignment(fd),
> +					    bo_size_prefetch);
> +			igt_assert(map);
> +		}
>  	} else {
>  		igt_skip_on(xe_visible_vram_size(fd, 0) && bo_size >
>  			    xe_visible_vram_size(fd, 0));
> @@ -1500,7 +1519,7 @@ test_large_binds(int fd, struct drm_xe_engine_class_instance *eci,
>  		munmap(map, bo_size);
>  		gem_close(fd, bo);
>  	} else {
> -		free(map);
> +		free(map - map_padding);
>  	}
>  	xe_vm_destroy(fd, vm);
>  }
> @@ -2620,6 +2639,34 @@ igt_main
>  						 LARGE_BIND_FLAG_USERPTR);
>  				break;
>  			}
> +		igt_subtest_f("large-userptr-thp-split-binds-%lld",
> +			      (long long)bind_size)
> +			xe_for_each_engine(fd, hwe) {

imho check before starting each test if madvise will return error and
in that case test should skip with message, here and below at other
tests.

void require_madvise_hugepage(void) {
	int ret;

	ret = madvise(0, 0, MADV_HUGEPAGE);
	igt_require(ret == 0, "Madvise hugepage not supported, errno=%d\n", ret);
}

so in each subtest make it like:
		igt_subtest_f("large-userptr-thp-split-binds-%lld",
			      (long long)bind_size)
			{
			require_madvise_hugepage();
			xe_for_each_engine(fd, hwe) {
...

Regards,
Kamil


> +				test_large_binds(fd, hwe, 4, 16, bind_size,
> +						 LARGE_BIND_FLAG_SPLIT |
> +						 LARGE_BIND_FLAG_USERPTR |
> +						 LARGE_BIND_FLAG_USERPTR_THP);
> +				break;
> +			}
> +		igt_subtest_f("large-userptr-thp-misaligned-binds-%lld",
> +			      (long long)bind_size)
> +			xe_for_each_engine(fd, hwe) {
> +				test_large_binds(fd, hwe, 4, 16, bind_size,
> +						 LARGE_BIND_FLAG_MISALIGNED |
> +						 LARGE_BIND_FLAG_USERPTR |
> +						 LARGE_BIND_FLAG_USERPTR_THP);
> +				break;
> +			}
> +		igt_subtest_f("large-userptr-thp-split-misaligned-binds-%lld",
> +			      (long long)bind_size)
> +			xe_for_each_engine(fd, hwe) {
> +				test_large_binds(fd, hwe, 4, 16, bind_size,
> +						 LARGE_BIND_FLAG_SPLIT |
> +						 LARGE_BIND_FLAG_MISALIGNED |
> +						 LARGE_BIND_FLAG_USERPTR |
> +						 LARGE_BIND_FLAG_USERPTR_THP);
> +				break;
> +			}
>  	}
>  
>  	bind_size = (0x1ull << 21) + (0x1ull << 20);
> -- 
> 2.48.1
> 


More information about the igt-dev mailing list