From: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: kamil.konieczny@linux.intel.com, adam.miszczak@linux.intel.com,
jakub1.kolakowski@intel.com, lukasz.laguna@intel.com,
Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
Subject: [PATCH v2 i-g-t 2/4] tests/intel/xe_sriov_vfio: Add dynamic bind-unbind-vfs subtest
Date: Fri, 27 Mar 2026 15:06:25 +0100 [thread overview]
Message-ID: <20260327140627.64574-3-marcin.bernatowicz@linux.intel.com> (raw)
In-Reply-To: <20260327140627.64574-1-marcin.bernatowicz@linux.intel.com>
For each supported numvfs-N configuration, enable N VFs and
bind/unbind each VF to xe-vfio-pci through driver_override.
Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
Cc: Adam Miszczak <adam.miszczak@linux.intel.com>
Cc: Jakub Kolakowski <jakub1.kolakowski@intel.com>
Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Cc: Lukasz Laguna <lukasz.laguna@intel.com>
---
v2:
- Split assert_bound_driver_is into two helpers (Lukasz)
- Remove unnecessary unbind before bind (Lukasz)
---
tests/intel/xe_sriov_vfio.c | 139 ++++++++++++++++++++++++++++++++++++
1 file changed, 139 insertions(+)
diff --git a/tests/intel/xe_sriov_vfio.c b/tests/intel/xe_sriov_vfio.c
index ef92fb233..fa9026741 100644
--- a/tests/intel/xe_sriov_vfio.c
+++ b/tests/intel/xe_sriov_vfio.c
@@ -3,8 +3,11 @@
* Copyright(c) 2026 Intel Corporation. All rights reserved.
*/
+#include "drmtest.h"
#include "igt_core.h"
#include "igt_kmod.h"
+#include "igt_pci.h"
+#include "igt_sriov_device.h"
/**
* TEST: xe_sriov_vfio
@@ -16,14 +19,135 @@
*
* SUBTEST: load-unload-xe-vfio-pci
* Description: Attempt to load xe_vfio_pci module and then unload it.
+ *
+ * SUBTEST: bind-unbind-vfs
+ * Description: Enable VFs and bind/unbind each one to xe-vfio-pci via driver_override.
*/
IGT_TEST_DESCRIPTION("Xe SR-IOV VFIO tests (xe-vfio-pci)");
+#define DRIVER_OVERRIDE_TIMEOUT_MS 200
+
static const char *XE_VFIO_PCI_MOD = "xe_vfio_pci";
+static const char *XE_VFIO_PCI_DRV = "xe-vfio-pci";
+static int pf_fd = -1;
+static bool autoprobe;
static bool xe_vfio_loaded_initially;
+static void assert_xe_vfio_pci_is_bound(const char *pci_slot)
+{
+ char bound[64];
+ int ret;
+
+ ret = igt_pci_get_bound_driver_name(pci_slot, bound, sizeof(bound));
+ igt_assert_f(ret >= 0, "Failed to read bound driver for %s (%d)\n", pci_slot, ret);
+ igt_assert_f(ret > 0, "Expected %s to be bound to %s, but it is unbound\n",
+ pci_slot, XE_VFIO_PCI_DRV);
+ igt_assert_f(!strcmp(bound, XE_VFIO_PCI_DRV),
+ "Expected %s to be bound to %s, got %s\n",
+ pci_slot, XE_VFIO_PCI_DRV, bound);
+}
+
+static void assert_driver_unbound(const char *pci_slot)
+{
+ char bound[64];
+ int ret;
+
+ ret = igt_pci_get_bound_driver_name(pci_slot, bound, sizeof(bound));
+ igt_assert_f(ret >= 0, "Failed to read bound driver for %s (%d)\n", pci_slot, ret);
+ igt_assert_f(ret == 0, "Expected %s to be unbound, but is bound to %s\n",
+ pci_slot, bound);
+}
+
+static char *vf_pci_slot_alloc(unsigned int vf_id)
+{
+ char *slot = igt_sriov_get_vf_pci_slot_alloc(pf_fd, vf_id);
+
+ igt_assert_f(slot, "Failed to get VF%u PCI slot\n", vf_id);
+ return slot;
+}
+
+static void vf_bind_override(unsigned int vf_id, const char *driver)
+{
+ char *slot = vf_pci_slot_alloc(vf_id);
+ int ret;
+
+ ret = igt_pci_bind_driver_override(slot, driver, DRIVER_OVERRIDE_TIMEOUT_MS);
+ igt_assert_f(ret == 0, "bind %s (VF%u) to %s failed (%d)\n", slot, vf_id, driver, ret);
+ assert_xe_vfio_pci_is_bound(slot);
+
+ free(slot);
+}
+
+static void vf_unbind_override(unsigned int vf_id)
+{
+ char *slot = vf_pci_slot_alloc(vf_id);
+ int ret;
+
+ ret = igt_pci_unbind_driver_override(slot, DRIVER_OVERRIDE_TIMEOUT_MS);
+ igt_assert_f(ret == 0, "unbind %s (VF%u) failed (%d)\n", slot, vf_id, ret);
+ assert_driver_unbound(slot);
+
+ free(slot);
+}
+
+static void bind_unbind_vfs(unsigned int num_vfs)
+{
+ igt_sriov_disable_driver_autoprobe(pf_fd);
+ igt_sriov_enable_vfs(pf_fd, num_vfs);
+
+ igt_require_f(!igt_pci_system_reinit(), "Failed to refresh PCI state\n");
+
+ igt_sriov_enable_driver_autoprobe(pf_fd);
+
+ for (unsigned int vf_id = 1; vf_id <= num_vfs; vf_id++) {
+ vf_bind_override(vf_id, XE_VFIO_PCI_DRV);
+ vf_unbind_override(vf_id);
+ }
+
+ igt_sriov_disable_vfs(pf_fd);
+}
+
+static void open_pf(void)
+{
+ int fd;
+
+ if (pf_fd >= 0)
+ return;
+
+ fd = drm_open_driver(DRIVER_XE);
+ igt_assert_fd(fd);
+
+ if (!igt_sriov_is_pf(fd)) {
+ drm_close_driver(fd);
+ igt_skip("Xe device is not an SR-IOV PF\n");
+ }
+
+ if (igt_sriov_get_enabled_vfs(fd) != 0) {
+ drm_close_driver(fd);
+ igt_skip("VFs must be disabled before running this test\n");
+ }
+
+ autoprobe = igt_sriov_is_driver_autoprobe_enabled(fd);
+ pf_fd = fd;
+}
+
+static void cleanup_pf(void)
+{
+ if (pf_fd < 0)
+ return;
+
+ igt_sriov_disable_vfs(pf_fd);
+ igt_abort_on_f(igt_sriov_get_enabled_vfs(pf_fd) > 0, "Failed to disable VF(s)\n");
+ autoprobe ? igt_sriov_enable_driver_autoprobe(pf_fd) :
+ igt_sriov_disable_driver_autoprobe(pf_fd);
+ igt_abort_on_f(autoprobe != igt_sriov_is_driver_autoprobe_enabled(pf_fd),
+ "Failed to restore sriov_drivers_autoprobe value\n");
+ drm_close_driver(pf_fd);
+ pf_fd = -1;
+}
+
static void restore_xe_vfio_module(void)
{
bool loaded;
@@ -69,7 +193,22 @@ int igt_main()
igt_assert(igt_kmod_is_loaded(XE_VFIO_PCI_MOD) == false);
}
+ igt_describe("Enable VFs and bind/unbind each one to xe-vfio-pci via driver_override.");
+ igt_subtest_with_dynamic("bind-unbind-vfs") {
+ igt_skip_on_f(igt_kmod_load(XE_VFIO_PCI_MOD, NULL),
+ "Failed to load %s\n", XE_VFIO_PCI_MOD);
+
+ open_pf();
+
+ for_each_sriov_num_vfs(pf_fd, num_vfs) {
+ igt_dynamic_f("numvfs-%u", num_vfs) {
+ bind_unbind_vfs(num_vfs);
+ }
+ }
+ }
+
igt_fixture() {
+ cleanup_pf();
restore_xe_vfio_module();
}
}
--
2.43.0
next prev parent reply other threads:[~2026-03-27 14:07 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-27 14:06 [PATCH v2 i-g-t 0/4] tests/intel/xe_sriov_vfio: Add basic VFIO coverage Marcin Bernatowicz
2026-03-27 14:06 ` [PATCH v2 i-g-t 1/4] tests/intel/xe_sriov_vfio: Add VFIO module load/unload subtest Marcin Bernatowicz
2026-03-30 8:18 ` Laguna, Lukasz
2026-03-27 14:06 ` Marcin Bernatowicz [this message]
2026-03-30 8:18 ` [PATCH v2 i-g-t 2/4] tests/intel/xe_sriov_vfio: Add dynamic bind-unbind-vfs subtest Laguna, Lukasz
2026-03-27 14:06 ` [PATCH v2 i-g-t 3/4] tests/intel/xe_sriov_vfio: Add open-basic subtest Marcin Bernatowicz
2026-03-30 8:19 ` Laguna, Lukasz
2026-03-27 14:06 ` [PATCH v2 i-g-t 4/4] tests/intel/xe_sriov_vfio: Add region-info subtest Marcin Bernatowicz
2026-03-30 8:19 ` Laguna, Lukasz
2026-03-27 22:25 ` ✓ Xe.CI.BAT: success for tests/intel/xe_sriov_vfio: Add basic VFIO coverage (rev2) Patchwork
2026-03-27 22:57 ` ✓ i915.CI.BAT: " Patchwork
2026-03-28 15:53 ` ✓ Xe.CI.FULL: " Patchwork
2026-03-29 3:48 ` ✗ i915.CI.Full: failure " 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=20260327140627.64574-3-marcin.bernatowicz@linux.intel.com \
--to=marcin.bernatowicz@linux.intel.com \
--cc=adam.miszczak@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=jakub1.kolakowski@intel.com \
--cc=kamil.konieczny@linux.intel.com \
--cc=lukasz.laguna@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