[i-g-t v6 4/4] tests/intel/xe_exec_fault_mode: Test scratch page under fault mode

Matthew Brost matthew.brost at intel.com
Mon Mar 17 19:07:47 UTC 2025


On Mon, Feb 24, 2025 at 12:40:10PM -0500, Oak Zeng wrote:
> On certain HW (such as lunarlake and battlemage), driver now allows
> scratch page be enabled under fault mode. Test this functionality
> 
> v1: Move the test to separate function.
>     Write to scratch page before rebind (Matt)
> 
> Signed-off-by: Oak Zeng <oak.zeng at intel.com>

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

> ---
>  tests/intel/xe_exec_fault_mode.c | 68 ++++++++++++++++++++++++++++++++
>  1 file changed, 68 insertions(+)
> 
> diff --git a/tests/intel/xe_exec_fault_mode.c b/tests/intel/xe_exec_fault_mode.c
> index ae40e099b..6cc27102a 100644
> --- a/tests/intel/xe_exec_fault_mode.c
> +++ b/tests/intel/xe_exec_fault_mode.c
> @@ -17,6 +17,7 @@
>  #include "igt.h"
>  #include "lib/igt_syncobj.h"
>  #include "lib/intel_reg.h"
> +#include "lib/xe/xe_util.h"
>  #include "xe_drm.h"
>  
>  #include "xe/xe_ioctl.h"
> @@ -36,6 +37,64 @@
>  #define INVALID_VA	(0x1 << 8)
>  #define ENABLE_SCRATCH  (0x1 << 9)
>  
> +
> +/**
> + * SUBTEST: scratch-fault
> + * Description: Test scratch page functionality
> + * Test category: functionality test
> + */
> +static void test_scratch(int fd, struct drm_xe_engine_class_instance *eci)
> +{
> +	size_t bb_size = xe_bb_size(fd, PAGE_ALIGN_UFENCE);
> +	uint32_t vm;
> +
> +	struct xe_buffer dst_buf = {
> +		.fd = fd,
> +		.size = bb_size,
> +		.gpu_addr = 0x1a0000,
> +		.placement = vram_if_possible(fd, eci->gt_id),
> +		.flag = DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM,
> +	};
> +
> +	struct xe_cmdbuf cmdbuf = {
> +		.buf = {
> +			.fd = fd,
> +			.gpu_addr = 0x10a0000,
> +			.placement = vram_if_possible(fd, eci->gt_id),
> +			.flag = DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM,
> +		},
> +		.cmd_size = bb_size,
> +	};
> +
> +	vm = xe_vm_create(fd, DRM_XE_VM_CREATE_FLAG_LR_MODE |
> +			  DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE |
> +			  DRM_XE_VM_CREATE_FLAG_FAULT_MODE, 0);
> +
> +	dst_buf.vm = vm;
> +	cmdbuf.buf.vm = vm;
> +	/* Submit a command to write 0x1a0000
> +	 * Since 0x1a0000 is mapped scratch page, cmd execution should still
> +	 * be successful. Write is either be dropped by HW (NULL PTE case) or
> +	 * written to scratch page.
> +	 */
> +	xe_cmdbuf_create(&cmdbuf, eci);
> +	xe_cmdbuf_insert_store(&cmdbuf, dst_buf.gpu_addr, 0xc0ffee);
> +	xe_cmdbuf_insert_bbe(&cmdbuf);
> +	xe_cmdbuf_submit(&cmdbuf);
> +
> +	/* Create a buffer object, vm_bind it to 0x1a0000, then re-submit
> +	 * the command buffer. This should write to the buffer object.
> +	 * Check the buffer object to see if the write was successful.
> +	 */
> +	xe_buffer_create(&dst_buf);
> +	xe_cmdbuf_submit(&cmdbuf);
> +	igt_assert_eq(*(uint64_t *)dst_buf.cpu_addr, 0xc0ffee);
> +
> +	xe_cmdbuf_destroy(&cmdbuf);
> +	xe_buffer_destroy(&dst_buf);
> +	xe_vm_destroy(fd, vm);
> +}
> +
>  /**
>   * SUBTEST: invalid-va
>   * Description: Access invalid va and check for EIO through user fence.
> @@ -458,6 +517,7 @@ igt_main
>  		{ NULL },
>  	};
>  	int fd;
> +	uint32_t dev_id;
>  
>  	igt_fixture {
>  		struct timespec tv = {};
> @@ -466,6 +526,7 @@ igt_main
>  		int timeout = igt_run_in_simulation() ? 20 : 2;
>  
>  		fd = drm_open_driver(DRIVER_XE);
> +		dev_id = intel_get_drm_devid(fd);
>  		do {
>  			if (ret)
>  				usleep(5000);
> @@ -508,6 +569,13 @@ igt_main
>  		xe_for_each_engine(fd, hwe)
>  			test_exec(fd, hwe, 1, 1, ENABLE_SCRATCH | INVALID_VA);
>  
> +	igt_describe("Check if scratch page works under fault mode");
> +	igt_subtest("scratch-fault") {
> +		igt_skip_on(!IS_LUNARLAKE(dev_id) && !IS_BATTLEMAGE(dev_id));
> +		xe_for_each_engine(fd, hwe)
> +			test_scratch(fd, hwe);
> +	}
> +
>  	igt_fixture {
>  		drm_close_driver(fd);
>  	}
> -- 
> 2.26.3
> 


More information about the igt-dev mailing list