Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Bommu Krishnaiah <krishnaiah.bommu@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Bommu Krishnaiah <krishnaiah.bommu@intel.com>,
	Oak Zeng <oak.zeng@intel.com>,
	Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Subject: [PATCH i-g-t v2 09/10] tests/intel/xe_svm: svm_mprotect
Date: Tue, 14 May 2024 12:40:25 +0530	[thread overview]
Message-ID: <20240514071026.748257-10-krishnaiah.bommu@intel.com> (raw)
In-Reply-To: <20240514071026.748257-1-krishnaiah.bommu@intel.com>

Verify SVM functionality while accessing read only memory

Signed-off-by: Bommu Krishnaiah <krishnaiah.bommu@intel.com>
Cc: Oak Zeng <oak.zeng@intel.com>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
---
 tests/intel/xe_svm.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/tests/intel/xe_svm.c b/tests/intel/xe_svm.c
index 0b573e0c9..e8989afaa 100644
--- a/tests/intel/xe_svm.c
+++ b/tests/intel/xe_svm.c
@@ -34,6 +34,8 @@
  * Description: verify SVM basic functionality by using GPU atomic access any location in malloc'ed memory
  * SUBTEST: svm_invalid_va
  * Description: verify SVM functionality while accessing invalid address
+ * SUBTEST: svm-mprotect
+ * Description: verify SVM functionality while accessing read only memory
  * SUBTEST: svm-benchmark
  * Description: verify SVM performance with simple benchmark test
  */
@@ -256,6 +258,38 @@ static void svm_invalid_va(int fd, uint32_t vm, struct drm_xe_engine_class_insta
 	free(dst);
 }
 
+/**
+ * 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);
+}
+
 /**
  * A simple benchmark test.
  * Use GPU to memset a buffer with specific value and
@@ -338,6 +372,10 @@ igt_main
 		xe_for_each_engine(fd, hwe)
 			svm_invalid_va(fd, vm, hwe);
 
+	igt_subtest_f("svm-mprotect")
+		xe_for_each_engine(fd, hwe)
+			svm_mprotect(fd, vm, hwe);
+
 	igt_subtest_f("svm-benchmark")
 		xe_for_each_engine(fd, hwe)
 			svm_benchmark(fd, vm, hwe);
-- 
2.25.1


  parent reply	other threads:[~2024-05-14  7:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-14  7:10 [PATCH i-g-t v2 00/10] helper function Bommu Krishnaiah
2024-05-14  7:10 ` [PATCH i-g-t v2 01/10] lib/xe/xe_util: Introduce helper functions for buffer creation and command submission etc Bommu Krishnaiah
2024-05-14  7:10 ` [PATCH i-g-t v2 02/10] tests/intel/xe_svm: basic xe_svm test Bommu Krishnaiah
2024-05-14  7:10 ` [PATCH i-g-t v2 03/10] tests/xe_svm: basic svm test Bommu Krishnaiah
2024-05-15 17:38   ` Kamil Konieczny
2024-05-14  7:10 ` [PATCH i-g-t v2 04/10] tests/intel/xe_svm: svm_random_access Bommu Krishnaiah
2024-05-14  7:10 ` [PATCH i-g-t v2 05/10] tests/intel/xe_svm: svm-huge-page Bommu Krishnaiah
2024-05-14  7:10 ` [PATCH i-g-t v2 06/10] tests/intel/xe_svm: svm_atomic_access Bommu Krishnaiah
2024-05-14  8:14   ` Lisovskiy, Stanislav
2024-05-14  7:10 ` [PATCH i-g-t v2 07/10] tests/intel/xe_svm: svm-invalid-va Bommu Krishnaiah
2024-05-14  7:10 ` [PATCH i-g-t v2 08/10] tests/intel/xe_svm: svm_benchmark Bommu Krishnaiah
2024-05-14  7:10 ` Bommu Krishnaiah [this message]
2024-05-14  7:10 ` [PATCH i-g-t v2 10/10] tests/intel/xe_svm: svm-sparse-access Bommu Krishnaiah
2024-05-14  7:52 ` ✗ Fi.CI.BUILD: failure for helper function (rev2) Patchwork
2024-05-14  7:58 ` ✗ GitLab.Pipeline: warning " Patchwork
2024-05-15 17:29 ` [PATCH i-g-t v2 00/10] helper function Kamil Konieczny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240514071026.748257-10-krishnaiah.bommu@intel.com \
    --to=krishnaiah.bommu@intel.com \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=oak.zeng@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox