Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>,
	"Matthew Brost" <matthew.brost@intel.com>,
	"Kamil Konieczny" <kamil.konieczny@linux.intel.com>
Subject: [PATCH i-g-t v2] tests/xe_evict|exec_threads: Use fd reopen to avoid corrupting global data
Date: Mon, 22 Apr 2024 16:47:13 +0200	[thread overview]
Message-ID: <20240422144713.76025-1-zbigniew.kempczynski@intel.com> (raw)

Device scanning and filtering was designed to work in multi-process
environment. Due to that opening the device with drm_open_driver()
in multiple threads lead to global device data corruption.

At the moment there's no easy way to redesign this so simplest thing
we may do is to just acquire device fd in main process and reopen it
(this doesn't involve any device scanning) in spawned threads.

Lets use drm_reopen_driver() to stop calling not thread-safe code.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>

---
v2: Add reopen in test_evict_cm() (Kamil)
---
 tests/intel/xe_evict.c        | 10 +++++-----
 tests/intel/xe_exec_threads.c | 22 ++++++++--------------
 2 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/tests/intel/xe_evict.c b/tests/intel/xe_evict.c
index 8ef55211f7..5994ebb142 100644
--- a/tests/intel/xe_evict.c
+++ b/tests/intel/xe_evict.c
@@ -61,7 +61,7 @@ test_evict(int fd, struct drm_xe_engine_class_instance *eci,
 	bo = calloc(n_execs / 2, sizeof(*bo));
 	igt_assert(bo);
 
-	fd = drm_open_driver(DRIVER_XE);
+	fd = drm_reopen_driver(fd);
 
 	vm = xe_vm_create(fd, 0, 0);
 	if (flags & BIND_EXEC_QUEUE)
@@ -241,7 +241,7 @@ test_evict_cm(int fd, struct drm_xe_engine_class_instance *eci,
 	bo = calloc(n_execs / 2, sizeof(*bo));
 	igt_assert(bo);
 
-	fd = drm_open_driver(DRIVER_XE);
+	fd = drm_reopen_driver(fd);
 
 	vm = xe_vm_create(fd, DRM_XE_VM_CREATE_FLAG_LR_MODE, 0);
 	if (flags & BIND_EXEC_QUEUE)
@@ -769,21 +769,21 @@ igt_main
 
 	for (const struct section *s = sections; s->name; s++) {
 		igt_subtest_f("evict-%s", s->name)
-			test_evict(-1, hwe, s->n_exec_queues, s->n_execs,
+			test_evict(fd, hwe, s->n_exec_queues, s->n_execs,
 				   calc_bo_size(vram_size, s->mul, s->div),
 				   s->flags, NULL);
 	}
 
 	for (const struct section_cm *s = sections_cm; s->name; s++) {
 		igt_subtest_f("evict-%s", s->name)
-			test_evict_cm(-1, hwe, s->n_exec_queues, s->n_execs,
+			test_evict_cm(fd, hwe, s->n_exec_queues, s->n_execs,
 				      calc_bo_size(vram_size, s->mul, s->div),
 				      s->flags, NULL);
 	}
 
 	for (const struct section_threads *s = sections_threads; s->name; s++) {
 		igt_subtest_f("evict-%s", s->name)
-			threads(-1, hwe, s->n_threads, s->n_exec_queues,
+			threads(fd, hwe, s->n_threads, s->n_exec_queues,
 				 s->n_execs,
 				 calc_bo_size(vram_size, s->mul, s->div),
 				 s->flags);
diff --git a/tests/intel/xe_exec_threads.c b/tests/intel/xe_exec_threads.c
index 8083980f90..1e80842b98 100644
--- a/tests/intel/xe_exec_threads.c
+++ b/tests/intel/xe_exec_threads.c
@@ -71,8 +71,8 @@ test_balancer(int fd, int gt, uint32_t vm, uint64_t addr, uint64_t userptr,
 
 	igt_assert(n_exec_queues <= MAX_N_EXEC_QUEUES);
 
-	if (!fd) {
-		fd = drm_open_driver(DRIVER_XE);
+	if (flags & FD) {
+		fd = drm_reopen_driver(fd);
 		owns_fd = true;
 	}
 
@@ -273,8 +273,8 @@ test_compute_mode(int fd, uint32_t vm, uint64_t addr, uint64_t userptr,
 
 	igt_assert(n_exec_queues <= MAX_N_EXEC_QUEUES);
 
-	if (!fd) {
-		fd = drm_open_driver(DRIVER_XE);
+	if (flags & FD) {
+		fd = drm_reopen_driver(fd);
 		owns_fd = true;
 	}
 
@@ -477,8 +477,8 @@ test_legacy_mode(int fd, uint32_t vm, uint64_t addr, uint64_t userptr,
 
 	igt_assert(n_exec_queues <= MAX_N_EXEC_QUEUES);
 
-	if (!fd) {
-		fd = drm_open_driver(DRIVER_XE);
+	if (flags & FD) {
+		fd = drm_reopen_driver(fd);
 		owns_fd = true;
 	}
 
@@ -995,10 +995,7 @@ static void threads(int fd, int flags)
 #define ADDRESS_SHIFT	39
 		threads_data[i].addr = addr | (i << ADDRESS_SHIFT);
 		threads_data[i].userptr = userptr | (i << ADDRESS_SHIFT);
-		if (flags & FD)
-			threads_data[i].fd = 0;
-		else
-			threads_data[i].fd = fd;
+		threads_data[i].fd = fd;
 		threads_data[i].vm_legacy_mode = vm_legacy_mode;
 		threads_data[i].vm_compute_mode = vm_compute_mode;
 		threads_data[i].eci = hwe;
@@ -1046,10 +1043,7 @@ static void threads(int fd, int flags)
 						threads_data[i].addr = addr;
 					threads_data[i].userptr = userptr |
 						(i << ADDRESS_SHIFT);
-					if (flags & FD)
-						threads_data[i].fd = 0;
-					else
-						threads_data[i].fd = fd;
+					threads_data[i].fd = fd;
 					threads_data[i].gt = gt;
 					threads_data[i].vm_legacy_mode =
 						vm_legacy_mode;
-- 
2.34.1


             reply	other threads:[~2024-04-22 14:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-22 14:47 Zbigniew Kempczyński [this message]
2024-04-22 17:01 ` ✓ Fi.CI.BAT: success for tests/xe_evict|exec_threads: Use fd reopen to avoid corrupting global data (rev3) Patchwork
2024-04-22 17:21 ` ✓ CI.xeBAT: " Patchwork
2024-04-23  0:12 ` ✗ CI.xeFULL: failure " Patchwork
2024-04-23  6:12   ` Zbigniew Kempczyński
2024-04-23  8:11 ` [PATCH i-g-t v2] tests/xe_evict|exec_threads: Use fd reopen to avoid corrupting global data Kamil Konieczny
2024-04-23  8:57 ` ✗ Fi.CI.IGT: failure for tests/xe_evict|exec_threads: Use fd reopen to avoid corrupting global data (rev3) Patchwork
2024-04-23 19:51   ` Kamil Konieczny
2024-04-25 15:06 ` ✓ Fi.CI.IGT: success " Patchwork

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=20240422144713.76025-1-zbigniew.kempczynski@intel.com \
    --to=zbigniew.kempczynski@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=matthew.brost@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