[PATCH i-g-t v3 3/4] lib/drmtest: invalidate cached fds after unbind

Kamil Konieczny kamil.konieczny at linux.intel.com
Fri Nov 8 20:18:38 UTC 2024


After driver unbind or reload cached drm file descriptors could
become stale, so there is no point in preventing calling
drm_open_driver() again. This should prevent errors like:

(xe_wedged:3680) drmtest-DEBUG: Condition stat(path, &new) != 0 occurred
	in function _is_already_opened, file ../lib/drmtest.c:407
(xe_wedged:3680) drmtest-WARNING: card maching filter 0 is already opened

when test tries to open again driver and make checks if
it is functional.

Cc: Janusz Krzysztofik <janusz.krzysztofik at linux.intel.com>
Signed-off-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
---
 lib/drmtest.c          | 18 ++++++++++++++++++
 lib/drmtest.h          |  2 ++
 lib/igt_sysfs.c        |  1 +
 tests/core_hotunplug.c |  1 +
 4 files changed, 22 insertions(+)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 2dd4540b8..2919a4891 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -726,6 +726,24 @@ static void cancel_work_at_exit_render(int sig)
 	at_exit_drm_render_fd = -1;
 }
 
+/**
+ * __drm_invalidate_opened_fds:
+ *
+ * Invalidate drmtest internal fd caches.
+ */
+void __drm_invalidate_opened_fds(void)
+{
+	_opened_fds_count = 0;
+	if (at_exit_drm_fd >= 0)
+		close(at_exit_drm_fd);
+
+	at_exit_drm_fd = -1;
+	if (at_exit_drm_render_fd >= 0)
+		close(at_exit_drm_render_fd);
+
+	at_exit_drm_render_fd = -1;
+}
+
 static const char *chipset_to_vendor_str(int chipset)
 {
 	return chipset == DRIVER_XE ? chipset_to_str(DRIVER_INTEL) : chipset_to_str(chipset);
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 27e5a18e2..fb37a1070 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -129,6 +129,8 @@ int drm_reopen_driver(int fd);
 int drm_prepare_filtered_multigpu(int chipset);
 int drm_open_filtered_card(int idx);
 
+void __drm_invalidate_opened_fds(void);
+
 void igt_require_amdgpu(int fd);
 void igt_require_intel(int fd);
 void igt_require_i915(int fd);
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 26a3aa31f..356b20f29 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -1377,6 +1377,7 @@ int xe_sysfs_driver_do(int xe_device, char pci_slot[], enum xe_sysfs_driver_acti
 
 	sysfs = open("/sys/bus/pci/drivers/xe", O_DIRECTORY);
 	igt_assert(sysfs);
+	__drm_invalidate_opened_fds();
 
 	switch(action) {
 	case XE_SYSFS_DRIVER_BIND:
diff --git a/tests/core_hotunplug.c b/tests/core_hotunplug.c
index 7f17f4423..39042f200 100644
--- a/tests/core_hotunplug.c
+++ b/tests/core_hotunplug.c
@@ -489,6 +489,7 @@ static bool healthcheck(struct hotunplug *priv, bool recover)
 
 	/* device name may have changed, rebuild IGT device list */
 	igt_devices_scan(true);
+	__drm_invalidate_opened_fds();
 
 	node_healthcheck(priv, recover ? FLAG_RECOVER : 0);
 	if (!priv->failure)
-- 
2.47.0



More information about the igt-dev mailing list