[PATCH i-g-t v3 09/10] tests/intel/xe_svm: Add svm-mprotect test to verify SVM functionality with read-only memory access
Bommu Krishnaiah
krishnaiah.bommu at intel.com
Fri May 17 11:46:57 UTC 2024
svm-mprotect test ensures that the driver correctly handles invalid
GPU write attempts to read-only memory regions in the context of SVM scenarios.
Signed-off-by: Bommu Krishnaiah <krishnaiah.bommu at intel.com>
Cc: Oak Zeng <oak.zeng at intel.com>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray at intel.com>
---
tests/intel/xe_svm.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/tests/intel/xe_svm.c b/tests/intel/xe_svm.c
index 072a602b1..86c9e86b8 100644
--- a/tests/intel/xe_svm.c
+++ b/tests/intel/xe_svm.c
@@ -42,6 +42,9 @@
*
* SUBTEST: svm-benchmark
* Description: Verify SVM performance with a simple benchmark test.
+ *
+ * SUBTEST: svm-mprotect
+ * Description: verify SVM functionality while accessing read only memory
*/
#include <fcntl.h>
@@ -345,6 +348,38 @@ static void svm_benchmark(int fd, uint32_t vm, struct drm_xe_engine_class_instan
igt_info("engine class %d, engine id %d memset E2E bandwidth(include sync overhead) %.3f MiB/s\n", eci->engine_class, eci->engine_instance, bandwidth);
}
+/**
+ * Use mprotect to mark a chunk of memory to be read only and submit
+ * GPU command to write to this read only memory. GPU write should
+ * fail and driver should detect an invalid access error.
+ */
+static void svm_mprotect(int fd, uint32_t vm, struct drm_xe_engine_class_instance *eci)
+{
+ uint64_t gpu_va = 0x1a0000;
+ size_t bo_size = xe_bb_size(fd, PAGE_ALIGN_UFENCE);
+ uint32_t *dst;
+ uint32_t size = 65536;
+
+ struct xe_buffer cmd_buf = {
+ .fd = fd,
+ .gpu_addr = (void *)(uintptr_t)gpu_va,
+ .vm = vm,
+ .size = bo_size,
+ .placement = vram_if_possible(fd, eci->gt_id),
+ .flag = DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM,
+ };
+
+ dst = aligned_alloc(size, size);
+ mprotect(dst, size, PROT_READ);
+
+ xe_create_cmdbuf(&cmd_buf, insert_store, (uint64_t)dst, 0xc0ffee, eci);
+
+ igt_assert_eq(__xe_submit_cmd(&cmd_buf), -EIO);
+
+ xe_destroy_cmdbuf(&cmd_buf);
+ free(dst);
+}
+
igt_main
{
int fd;
@@ -389,6 +424,10 @@ igt_main
xe_for_each_engine(fd, hwe)
svm_benchmark(fd, vm, hwe);
+ igt_subtest_f("svm-mprotect")
+ xe_for_each_engine(fd, hwe)
+ svm_mprotect(fd, vm, hwe);
+
igt_fixture {
xe_vm_destroy(fd, vm);
drm_close_driver(fd);
--
2.25.1
More information about the igt-dev
mailing list