Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5840DCA5FA5 for ; Tue, 29 Sep 2026 10:50:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 031F210EE38; Tue, 29 Sep 2026 10:50:13 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="e7z4lNlf"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id E2A4910EE32 for ; Tue, 29 Sep 2026 10:49:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790678968; x=1822214968; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/uryn7tmAGkgpntDD2e0dzRWNm3Du31y8udD01uRwCg=; b=e7z4lNlfeJg/eVDYTa/0KI6oms0pRTJw6Pfjy5uDmLOf3xM8E6RTd0zY BhGe7//hAUaxvmwjYbHi9AkNbRVaBlGAfknWJt+A5hocLm2eGdQ5Ztw/E 91rMYWVDpCzHSi2p8QQDV+H+7zQZ1q6z+zacTCI0/Nn07+prwdM1Oizt9 5hqkEjdryA4m1hsil7B53n3o8ij8ELFeGTisvm4bwxWpIdIUFUe/ZA9ad dSO/StBsFZQ5kLSzu2IkPyVbYQ/UHUcMeHilSpBC4gIMn8K/rGvD0Sq4m cGGkoUUN/Rt81+BnIvtMXsAAjyv2mWL4Bx05cQUmVDNcQ/Xw9UbnCkl8Z Q==; X-CSE-ConnectionGUID: aOZhXaojTCGNE+KXaXjilA== X-CSE-MsgGUID: CP9EZZt8R9CfZQ5Wgf+s6g== X-IronPort-AV: E=McAfee;i="6800,10657,11919"; a="90524024" X-IronPort-AV: E=Sophos;i="6.27,130,1787036400"; d="scan'208";a="90524024" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2026 03:49:28 -0700 X-CSE-ConnectionGUID: nIpBr6MpRtuYG1XrBCwPAA== X-CSE-MsgGUID: J2gYySunQG2n+xNarzGvTw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,130,1787036400"; d="scan'208";a="313286219" Received: from anirban-z690i-a-ultra-plus.iind.intel.com ([10.190.216.83]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2026 03:49:26 -0700 From: Sk Anirban To: igt-dev@lists.freedesktop.org Cc: anshuman.gupta@intel.com, badal.nilawar@intel.com, riana.tauro@intel.com, karthik.poosa@intel.com, raag.jadav@intel.com, soham.purkait@intel.com, mallesh.koujalagi@intel.com, Sk Anirban Subject: [PATCH] tests/intel/xe_configfs: reuse pre-existing configfs group Date: Tue, 29 Sep 2026 16:07:02 +0530 Message-ID: <20260929103701.2050914-2-sk.anirban@intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" Handle a pre-existing configfs group by opening and reusing it, retain it across cleanup, and validate the fd so the test fails early with a clear message on any error. v2: Add a common function (Soham) Signed-off-by: Sk Anirban --- lib/igt_configfs.c | 56 ++++++++++++++++++++++ lib/igt_configfs.h | 6 +++ tests/intel/xe_configfs.c | 85 ++++++++++++++++++++-------------- tests/intel/xe_survivability.c | 23 +++------ 4 files changed, 118 insertions(+), 52 deletions(-) diff --git a/lib/igt_configfs.c b/lib/igt_configfs.c index e0cba92a1..a394cebe5 100644 --- a/lib/igt_configfs.c +++ b/lib/igt_configfs.c @@ -10,9 +10,12 @@ #include #include #include +#include +#include #include "igt_aux.h" #include "igt_configfs.h" +#include "igt_fs.h" /** * SECTION:igt_configfs @@ -84,3 +87,56 @@ int igt_configfs_open(const char *name) return open(path, O_DIRECTORY | O_RDONLY); } + +/** + * igt_configfs_create_device_group: create or reuse a device's configfs group + * @configfs_fd: configfs directory fd + * @name: name of the device group + * @preexisting: set to true when @name already existed + * + * Creates the configfs group @name under @configfs_fd. If the group already + * exists, it is opened and reused instead. + * + * Returns: + * The group directory fd. + */ +int igt_configfs_create_device_group(int configfs_fd, const char *name, + bool *preexisting) +{ + mode_t mode = 0755; + int device_fd; + + device_fd = igt_fs_create_dir(configfs_fd, name, mode); + if (device_fd == -EEXIST) { + if (preexisting) + *preexisting = true; + + device_fd = openat(configfs_fd, name, O_DIRECTORY); + if (device_fd < 0) + device_fd = -errno; + } + igt_assert_f(device_fd >= 0, + "Failed to create/open configfs group for %s: %s\n", + name, strerror(-device_fd)); + + return device_fd; +} + +/** + * igt_configfs_close_device_group: close a device's configfs group + * @configfs_fd: configfs directory fd, as returned by igt_configfs_open() + * @name: name of the device group + * @device_fd: group directory fd + * @preexisting: whether the group already existed before it was created by + * igt_configfs_create_device_group() + * + * Closes @device_fd and removes the @name group, unless it was pre-existing + */ +void igt_configfs_close_device_group(int configfs_fd, const char *name, + int device_fd, bool preexisting) +{ + close(device_fd); + + if (!preexisting) + igt_fs_remove_dir(configfs_fd, name); +} diff --git a/lib/igt_configfs.h b/lib/igt_configfs.h index 91f95659b..0f4cfe5d3 100644 --- a/lib/igt_configfs.h +++ b/lib/igt_configfs.h @@ -9,7 +9,13 @@ #ifndef __IGT_CONFIGFS_H__ #define __IGT_CONFIGFS_H__ +#include + const char *igt_configfs_mount(void); int igt_configfs_open(const char *name); +int igt_configfs_create_device_group(int configfs_fd, const char *name, bool *preexisting); +void igt_configfs_close_device_group(int configfs_fd, const char *name, int device_fd, + bool preexisting); + #endif /* __IGT_CONFIGFS_H__ */ diff --git a/tests/intel/xe_configfs.c b/tests/intel/xe_configfs.c index 450c0a119..68daed690 100644 --- a/tests/intel/xe_configfs.c +++ b/tests/intel/xe_configfs.c @@ -26,6 +26,8 @@ static char bus_addr[NAME_MAX]; static struct pci_device *pci_dev; +static bool configfs_group_preexisting; + static bool check_registers(const uint32_t reg[], const uint32_t val[], size_t max) { @@ -60,7 +62,7 @@ static void restore(int sig) /* Drop all custom configfs settings from subtests */ configfs_fd = igt_configfs_open("xe"); - if (configfs_fd >= 0) + if (configfs_fd >= 0 && !configfs_group_preexisting) igt_fs_remove_dir(configfs_fd, bus_addr); close(configfs_fd); @@ -70,10 +72,19 @@ static void restore(int sig) static void set_survivability_mode(int configfs_device_fd, bool value) { + int ret; + igt_audio_driver_unload(NULL); - igt_kmod_unbind("xe", bus_addr); + + ret = igt_kmod_unbind("xe", bus_addr); + igt_assert_f(!ret, "Failed to unbind xe from %s: %s\n", + bus_addr, strerror(-ret)); + igt_sysfs_set_boolean(configfs_device_fd, "survivability_mode", value); - igt_kmod_bind("xe", bus_addr); + + ret = igt_kmod_bind("xe", bus_addr); + igt_assert_f(!ret, "Failed to bind xe to %s: %s\n", + bus_addr, strerror(-ret)); } /** @@ -93,6 +104,9 @@ static void test_survivability_mode(int configfs_device_fd) fd = open(path, O_RDONLY); igt_assert_f(fd >= 0, "Survivability mode not set\n"); + + set_survivability_mode(configfs_device_fd, false); + close(fd); } @@ -357,23 +371,6 @@ static void set_bus_addr(int fd) pci_dev->domain, pci_dev->bus, pci_dev->dev, pci_dev->func); } -static int create_device_configfs_group(int configfs_fd) -{ - mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; - int configfs_device_fd; - - configfs_device_fd = igt_fs_create_dir(configfs_fd, bus_addr, mode); - igt_assert(configfs_device_fd); - - return configfs_device_fd; -} - -static void close_configfs_group(int configfs_fd, int configfs_device_fd) -{ - close(configfs_device_fd); - igt_fs_remove_dir(configfs_fd, bus_addr); -} - int igt_main() { int fd, configfs_fd, configfs_device_fd; @@ -412,62 +409,78 @@ int igt_main() igt_subtest("survivability-mode") { igt_require(has_survivability); igt_require_f(!is_vf_device, "survivability mode not supported in VF\n"); - configfs_device_fd = create_device_configfs_group(configfs_fd); + configfs_device_fd = igt_configfs_create_device_group(configfs_fd, bus_addr, + &configfs_group_preexisting); test_survivability_mode(configfs_device_fd); - close_configfs_group(configfs_fd, configfs_device_fd); + igt_configfs_close_device_group(configfs_fd, bus_addr, configfs_device_fd, + configfs_group_preexisting); } igt_describe("Validate engines_allowed with invalid options"); igt_subtest("engines-allowed-invalid") { - configfs_device_fd = create_device_configfs_group(configfs_fd); + configfs_device_fd = igt_configfs_create_device_group(configfs_fd, bus_addr, + &configfs_group_preexisting); test_engines_allowed_invalid(configfs_device_fd); - close_configfs_group(configfs_fd, configfs_device_fd); + igt_configfs_close_device_group(configfs_fd, bus_addr, configfs_device_fd, + configfs_group_preexisting); } igt_describe("Validate engines_allowed"); igt_subtest("engines-allowed") { - configfs_device_fd = create_device_configfs_group(configfs_fd); + configfs_device_fd = igt_configfs_create_device_group(configfs_fd, bus_addr, + &configfs_group_preexisting); test_engines_allowed(configfs_device_fd); - close_configfs_group(configfs_fd, configfs_device_fd); + igt_configfs_close_device_group(configfs_fd, bus_addr, configfs_device_fd, + configfs_group_preexisting); } igt_describe("Validate gt_types_allowed"); igt_subtest("gt-types-allowed") { - configfs_device_fd = create_device_configfs_group(configfs_fd); + configfs_device_fd = igt_configfs_create_device_group(configfs_fd, bus_addr, + &configfs_group_preexisting); test_gt_types_allowed(configfs_device_fd); - close_configfs_group(configfs_fd, configfs_device_fd); + igt_configfs_close_device_group(configfs_fd, bus_addr, configfs_device_fd, + configfs_group_preexisting); } igt_describe("Validate ctx_restore_post_bb with invalid options"); igt_subtest("ctx-restore-post-bb-invalid") { igt_skip_on_f(is_vf_device, "MMIO register readback not possible on VF\n"); - configfs_device_fd = create_device_configfs_group(configfs_fd); + configfs_device_fd = igt_configfs_create_device_group(configfs_fd, bus_addr, + &configfs_group_preexisting); test_ctx_restore_invalid(configfs_device_fd, "post"); - close_configfs_group(configfs_fd, configfs_device_fd); + igt_configfs_close_device_group(configfs_fd, bus_addr, configfs_device_fd, + configfs_group_preexisting); } igt_describe("Validate ctx_restore_post_bb"); igt_subtest("ctx-restore-post-bb") { igt_skip_on_f(is_vf_device, "MMIO register readback not possible on VF\n"); - configfs_device_fd = create_device_configfs_group(configfs_fd); + configfs_device_fd = igt_configfs_create_device_group(configfs_fd, bus_addr, + &configfs_group_preexisting); test_ctx_restore(configfs_device_fd, "post", engine); - close_configfs_group(configfs_fd, configfs_device_fd); + igt_configfs_close_device_group(configfs_fd, bus_addr, configfs_device_fd, + configfs_group_preexisting); } igt_describe("Validate ctx_restore_mid_bb with invalid options"); igt_subtest("ctx-restore-mid-bb-invalid") { igt_skip_on_f(is_vf_device, "MMIO register readback not possible on VF\n"); - configfs_device_fd = create_device_configfs_group(configfs_fd); + configfs_device_fd = igt_configfs_create_device_group(configfs_fd, bus_addr, + &configfs_group_preexisting); test_ctx_restore_invalid(configfs_device_fd, "mid"); - close_configfs_group(configfs_fd, configfs_device_fd); + igt_configfs_close_device_group(configfs_fd, bus_addr, configfs_device_fd, + configfs_group_preexisting); } igt_describe("Validate ctx_restore_mid_bb"); igt_subtest("ctx-restore-mid-bb") { igt_skip_on_f(is_vf_device, "MMIO register readback not possible on VF\n"); - configfs_device_fd = create_device_configfs_group(configfs_fd); + configfs_device_fd = igt_configfs_create_device_group(configfs_fd, bus_addr, + &configfs_group_preexisting); test_ctx_restore(configfs_device_fd, "mid", engine); - close_configfs_group(configfs_fd, configfs_device_fd); + igt_configfs_close_device_group(configfs_fd, bus_addr, configfs_device_fd, + configfs_group_preexisting); } igt_fixture() { diff --git a/tests/intel/xe_survivability.c b/tests/intel/xe_survivability.c index b4f1dfb38..c89db43f7 100644 --- a/tests/intel/xe_survivability.c +++ b/tests/intel/xe_survivability.c @@ -40,6 +40,8 @@ static char bus_addr[NAME_MAX]; +static bool configfs_group_preexisting; + static void ignore_wedged_in_dmesg(void) { /* this is needed for igt_runner so it will ignore it */ @@ -155,7 +157,7 @@ static void restore(int sig) igt_kmod_unbind("xe", bus_addr); configfs_fd = igt_configfs_open("xe"); - if (configfs_fd >= 0) + if (configfs_fd >= 0 && !configfs_group_preexisting) igt_fs_remove_dir(configfs_fd, bus_addr); close(configfs_fd); @@ -187,17 +189,6 @@ static void test_i2c_functionality(int configfs_device_fd, struct pci_device *pc } } -static int create_device_configfs_group(int configfs_fd) -{ - mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; - int configfs_device_fd; - - configfs_device_fd = igt_fs_create_dir(configfs_fd, bus_addr, mode); - igt_assert(configfs_device_fd); - - return configfs_device_fd; -} - static void test_spinner_after_recovery(int fd) { uint64_t ahnd; @@ -225,7 +216,8 @@ int igt_main() igt_device_get_pci_slot_name(fd, bus_addr); configfs_fd = igt_configfs_open("xe"); igt_require(configfs_fd != -1); - configfs_device_fd = create_device_configfs_group(configfs_fd); + configfs_device_fd = igt_configfs_create_device_group(configfs_fd, bus_addr, + &configfs_group_preexisting); igt_install_exit_handler(restore); } @@ -262,9 +254,8 @@ int igt_main() } igt_fixture() { - igt_fs_remove_dir(configfs_fd, bus_addr); - close(configfs_device_fd); - close(configfs_fd); + igt_configfs_close_device_group(configfs_fd, bus_addr, configfs_device_fd, + configfs_group_preexisting); drm_close_driver(fd); } } -- 2.43.0