public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: "Bernatowicz, Marcin" <marcin.bernatowicz@linux.intel.com>
To: "Laguna, Lukasz" <lukasz.laguna@intel.com>,
	igt-dev@lists.freedesktop.org
Cc: adam.miszczak@linux.intel.com, jakub1.kolakowski@intel.com,
	kamil.konieczny@linux.intel.com
Subject: Re: [PATCH i-g-t 3/4] tests/intel/xe_sriov_vfio: Add open-basic subtest
Date: Thu, 26 Mar 2026 12:44:57 +0100	[thread overview]
Message-ID: <5f733529-87fe-4c67-90a0-4f89f1a4af02@linux.intel.com> (raw)
In-Reply-To: <37cf5ef3-6247-4c2a-bb24-25b640a929bf@intel.com>


On 3/24/2026 3:17 PM, Laguna, Lukasz wrote:
>
> On 3/18/2026 17:14, Marcin Bernatowicz wrote:
>> The subtest binds a VF to xe-vfio-pci, opens its VFIO group, and
>> verifies basic VFIO access with a minimal group status query. This
>> provides a simple smoke test for VFIO device setup.
>>
>> 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>
>> ---
>>   tests/intel/xe_sriov_vfio.c | 136 ++++++++++++++++++++++++++++++++++++
>>   1 file changed, 136 insertions(+)
>>
>> diff --git a/tests/intel/xe_sriov_vfio.c b/tests/intel/xe_sriov_vfio.c
>> index a2b2959e2..6a5cc536b 100644
>> --- a/tests/intel/xe_sriov_vfio.c
>> +++ b/tests/intel/xe_sriov_vfio.c
>> @@ -6,6 +6,8 @@
>>   #include <ctype.h>
>>   #include <dirent.h>
>>   #include <fcntl.h>
>> +#include <linux/vfio.h>
>> +#include <sys/ioctl.h>
>>     #include "drmtest.h"
>>   #include "igt_core.h"
>> @@ -29,6 +31,9 @@
>>    *
>>    * SUBTEST: bind-unbind-vfs
>>    * Description: Enable VFs and bind/unbind each one to xe-vfio-pci 
>> via driver_override.
>> + *
>> + * SUBTEST: open-basic
>> + * Description: Bind VF to xe-vfio-pci and perform minimal VFIO 
>> group open and status ioctl.
>>    */
>>     IGT_TEST_DESCRIPTION("Xe SR-IOV VFIO tests (xe-vfio-pci)");
>> @@ -199,6 +204,109 @@ static void restore_xe_vfio_module(void)
>>       restore_xe_vfio_on_exit = false;
>>   }
>>   +static bool vf_iommu_group_id_alloc(const char *pci_slot, char 
>> **out_group_id)
>> +{
>> +    char path[PATH_MAX];
>> +    char link[PATH_MAX];
>> +    ssize_t len;
>> +    const char *base;
>> +
>> +    igt_assert(out_group_id);
>> +    *out_group_id = NULL;
>> +
>> +    snprintf(path, sizeof(path), 
>> "/sys/bus/pci/devices/%s/iommu_group", pci_slot);
>> +    len = readlink(path, link, sizeof(link) - 1);
>> +    if (len < 0)
>> +        return false;
>> +
>> +    link[len] = '\0';
>> +    base = strrchr(link, '/');
>> +    if (!base || !base[1])
>> +        return false;
>> +
>> +    *out_group_id = strdup(base + 1);
>> +    igt_assert(*out_group_id);
>> +
>> +    return true;
>> +}
>> +
>> +struct vfio_dev_fds {
>> +    int container_fd;
>> +    int group_fd;
>> +    int device_fd;
>> +    char *group_id;
>> +};
>> +
>> +static void vfio_open_group(const char *pci_slot, struct 
>> vfio_dev_fds *out,
>> +                struct vfio_group_status *out_group_status)
>> +{
>> +    char group_path[PATH_MAX];
>> +    int ret;
>> +
>> +    igt_assert(out);
>> +    *out = (struct vfio_dev_fds){
>> +        .container_fd = -1,
>> +        .group_fd = -1,
>> +        .device_fd = -1,
>> +        .group_id = NULL,
>> +    };
>> +
>> +    if (out_group_status)
>> +        *out_group_status = (struct vfio_group_status){
>> +                    .argsz = sizeof(*out_group_status)
>> +                    };
>> +
>> +    if (!vf_iommu_group_id_alloc(pci_slot, &out->group_id))
>> +        igt_skip("No IOMMU group (IOMMU disabled or not exposed)\n");
>> +
>> +    out->container_fd = open("/dev/vfio/vfio", O_RDWR | O_CLOEXEC);
>> +    if (out->container_fd < 0)
>> +        igt_skip("/dev/vfio/vfio not available\n");
>> +
>> +    snprintf(group_path, sizeof(group_path), "/dev/vfio/%s", 
>> out->group_id);
>> +    out->group_fd = open(group_path, O_RDWR | O_CLOEXEC);
>> +    igt_require_f(out->group_fd >= 0, "Failed to open %s (%d)\n", 
>> group_path, -errno);
>> +
>> +    if (out_group_status) {
>> +        ret = ioctl(out->group_fd, VFIO_GROUP_GET_STATUS, 
>> out_group_status);
>> +        igt_require_f(ret == 0, "VFIO_GROUP_GET_STATUS failed 
>> (%d)\n", -errno);
>> +    }
>> +}
>> +
>> +static void vfio_close_device(struct vfio_dev_fds *fds)
>> +{
>> +    if (!fds)
>> +        return;
>> +
>> +    if (fds->device_fd >= 0)
>> +        close(fds->device_fd);
>> +
>> +    if (fds->group_fd >= 0 && fds->container_fd >= 0)
>> +        ioctl(fds->group_fd, VFIO_GROUP_UNSET_CONTAINER, 
>> &fds->container_fd);
>> +
>> +    if (fds->group_fd >= 0)
>> +        close(fds->group_fd);
>> +    if (fds->container_fd >= 0)
>> +        close(fds->container_fd);
>> +
>> +    free(fds->group_id);
>> +
>> +    fds->container_fd = -1;
>> +    fds->group_fd = -1;
>> +    fds->device_fd = -1;
>> +    fds->group_id = NULL;
>> +}
>> +
>> +static void vfio_open_basic(const char *pci_slot)
>> +{
>> +    struct vfio_dev_fds fds;
>> +    struct vfio_group_status group_status;
>> +
>> +    vfio_open_group(pci_slot, &fds, &group_status);
>> +    igt_info("VFIO group %s status flags=0x%x\n", fds.group_id, 
>> group_status.flags);
>> +    vfio_close_device(&fds);
>> +}
>> +
>>   int igt_main()
>>   {
>>       igt_fixture() {
>> @@ -250,6 +358,34 @@ int igt_main()
>>           }
>>       }
>>   +    igt_describe("Bind VF to xe-vfio-pci and do minimal VFIO open 
>> and GET_STATUS.");
>> +    igt_subtest("open-basic") {
>> +        char *slot = NULL;
>> +
>> +        igt_skip_on_f(igt_kmod_load(XE_VFIO_PCI_MOD, NULL),
>> +                  "Failed to load %s\n", XE_VFIO_PCI_MOD);
>> +        restore_xe_vfio_on_exit = true;
>> +
>> +        open_pf();
>> +
>> +        igt_sriov_disable_driver_autoprobe(pf_fd);
>> +        igt_sriov_enable_vfs(pf_fd, 1);
>
> Maybe vf_num = 1 and then use variable?
ok
>
>> +
>> +        igt_require_f(!igt_pci_system_reinit(), "Failed to refresh 
>> PCI state\n");
>> +        igt_sriov_enable_driver_autoprobe(pf_fd);
>> +
>> +        slot = vf_pci_slot_alloc(1);
>> +
>> +        vf_unbind_override(1);
>
> The same as in previous patch - is this unbind needed?
can be removed, thanks
>
>> +        vf_bind_override(1, XE_VFIO_PCI_DRV);
>> +
>> +        vfio_open_basic(slot);
>> +
>> +        vf_unbind_override(1);
>> +        free(slot);
>> +        igt_sriov_disable_vfs(pf_fd);
>> +    }
>> +
>>       igt_fixture() {
>>           cleanup_pf();
>>           restore_xe_vfio_module();

  reply	other threads:[~2026-03-26 11:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-18 16:14 [PATCH i-g-t 0/4] tests/intel/xe_sriov_vfio: Add basic VFIO coverage Marcin Bernatowicz
2026-03-18 16:14 ` [PATCH i-g-t 1/4] tests/intel/xe_sriov_vfio: Add module load/unload subtests Marcin Bernatowicz
2026-03-24 13:54   ` Laguna, Lukasz
2026-03-26 11:41     ` Bernatowicz, Marcin
2026-03-18 16:14 ` [PATCH i-g-t 2/4] tests/intel/xe_sriov_vfio: Add dynamic bind-unbind-vfs subtest Marcin Bernatowicz
2026-03-24 14:14   ` Laguna, Lukasz
2026-03-26 11:49     ` Bernatowicz, Marcin
2026-03-18 16:14 ` [PATCH i-g-t 3/4] tests/intel/xe_sriov_vfio: Add open-basic subtest Marcin Bernatowicz
2026-03-24 14:17   ` Laguna, Lukasz
2026-03-26 11:44     ` Bernatowicz, Marcin [this message]
2026-03-18 16:14 ` [PATCH i-g-t 4/4] tests/intel/xe_sriov_vfio: Add region-info subtest Marcin Bernatowicz
2026-03-18 18:00 ` ✓ Xe.CI.BAT: success for tests/intel/xe_sriov_vfio: Add basic VFIO coverage Patchwork
2026-03-18 18:17 ` ✓ i915.CI.BAT: " Patchwork
2026-03-19 23:18 ` ✗ i915.CI.Full: failure " Patchwork
2026-03-20  6:16 ` ✗ Xe.CI.FULL: " 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=5f733529-87fe-4c67-90a0-4f89f1a4af02@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