Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Laguna, Lukasz" <lukasz.laguna@intel.com>
To: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>,
	<igt-dev@lists.freedesktop.org>
Cc: <michal.wajdeczko@intel.com>, <kamil.konieczny@linux.intel.com>
Subject: Re: [PATCH i-g-t] lib/igt_sriov_device: Replace libpciaccess with direct sysfs interaction
Date: Tue, 2 Jul 2024 10:31:25 +0200	[thread overview]
Message-ID: <14e6bc1c-cbc1-4679-a1dc-06722df5a4a6@intel.com> (raw)
In-Reply-To: <20240627145118.719988-1-marcin.bernatowicz@linux.intel.com>

[-- Attachment #1: Type: text/plain, Size: 3477 bytes --]


On 6/27/2024 16:51, Marcin Bernatowicz wrote:
> Previously, libpciaccess was used to fetch PCI device information for
> VFs in SR-IOV, which does not refresh the PCI bus state after the initial
> scan. This can lead to outdated PCI information in dynamic SR-IOV
> environments where VFs are dynamically managed.
>
> The new implementation directly interacts with sysfs to resolve the PCI
> slot address of a VF, ensuring access to the most current state of the
> PCI bus. This change removes the dependency on libpciaccess and uses
> __igt_sriov_get_vf_pci_slot_alloc to fetch the PCI slot addresses
> directly from sysfs based on VF numbers.
>
> Reported-by: Michal Wajdeczko<michal.wajdeczko@intel.com>
> Closes:https://intel-gfx-ci.01.org/tree/intel-xe/xe-pw-135423v1/shard-adlp-9/igt@sriov_basic@bind-unbind-vf@vf-2.html
> Cc: Michal Wajdeczko<michal.wajdeczko@intel.com>
> Cc: Lukasz Laguna<lukasz.laguna@intel.com>
> Cc: Kamil Konieczny<kamil.konieczny@linux.intel.com>
> Signed-off-by: Marcin Bernatowicz<marcin.bernatowicz@linux.intel.com>
> ---
>   lib/igt_sriov_device.c | 46 +++++++++++++++++++++++++++++++++++-------
>   1 file changed, 39 insertions(+), 7 deletions(-)
>
> diff --git a/lib/igt_sriov_device.c b/lib/igt_sriov_device.c
> index a0ef05d5c..416d8f4aa 100644
> --- a/lib/igt_sriov_device.c
> +++ b/lib/igt_sriov_device.c
> @@ -297,26 +297,58 @@ bool igt_sriov_is_vf_drm_driver_probed(int pf, unsigned int vf_num)
>   	return ret;
>   }
>   
> +/*
> + * __igt_sriov_get_vf_pci_slot_alloc:
> + * @pf_sysfs: sysfs directory file descriptor
> + * @vf_num: VF number (1-based)
> + *
> + * Resolve symbolic link from virtfnX to obtain the PCI slot address.
> + * Returns a dynamically allocated string containing the PCI slot address,
> + * or NULL if the link cannot be resolved.
> + * The caller is responsible for freeing the returned memory.
> + */
> +static char *__igt_sriov_get_vf_pci_slot_alloc(int pf_sysfs, unsigned int vf_num)
> +{
> +	char dir_path[PATH_MAX];
> +	char path[PATH_MAX];
> +	char *pci_slot_addr;
> +	int len;
> +
> +	/* Adjust for 0-based index as vf_num is 1-based */
> +	if (vf_num)
> +		snprintf(dir_path, sizeof(dir_path), "device/virtfn%u",
> +			 vf_num - 1);
> +	else
> +		snprintf(dir_path, sizeof(dir_path), "device");
> +
> +	len = readlinkat(pf_sysfs, dir_path, path, sizeof(path));
> +	if (len <= 0)
> +		return NULL;
> +
> +	path[len] = '\0';
> +	pci_slot_addr = strrchr(path, '/') + 1;
> +
> +	return pci_slot_addr ? strdup(pci_slot_addr) : NULL;
> +}
> +
>   static bool __igt_sriov_bind_vf_drm_driver(int pf, unsigned int vf_num, bool bind)
>   {
> -	struct pci_device *pci_dev;
> -	char pci_slot[14];
> +	char *pci_slot;
>   	int sysfs;
>   	bool ret;
>   
>   	igt_assert(vf_num > 0);
>   
> -	pci_dev = __igt_device_get_pci_device(pf, vf_num);
> -	igt_assert_f(pci_dev, "No PCI device for given VF number: %d\n", vf_num);
> -	sprintf(pci_slot, "%04x:%02x:%02x.%x",
> -		pci_dev->domain_16, pci_dev->bus, pci_dev->dev, pci_dev->func);
> -
>   	sysfs = igt_sysfs_open(pf);
>   	igt_assert_fd(sysfs);
>   
> +	pci_slot = __igt_sriov_get_vf_pci_slot_alloc(sysfs, vf_num);
> +	igt_assert(pci_slot);
> +
>   	igt_debug("vf_num: %u, pci_slot: %s\n", vf_num, pci_slot);
>   	ret = igt_sysfs_set(sysfs, bind ? "device/driver/bind" : "device/driver/unbind", pci_slot);
>   
> +	free(pci_slot);
>   	close(sysfs);
>   
>   	return ret;

Reviewed-by: Lukasz Laguna <lukasz.laguna@intel.com 
<mailto:lukasz.laguna@intel.com>>

[-- Attachment #2: Type: text/html, Size: 4630 bytes --]

      parent reply	other threads:[~2024-07-02  8:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-27 14:51 [PATCH i-g-t] lib/igt_sriov_device: Replace libpciaccess with direct sysfs interaction Marcin Bernatowicz
2024-06-28 12:41 ` ✗ Fi.CI.BAT: failure for " Patchwork
2024-06-28 13:17   ` Bernatowicz, Marcin
2024-06-28 12:44 ` ✓ CI.xeBAT: success " Patchwork
2024-07-02  8:31 ` Laguna, Lukasz [this message]

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=14e6bc1c-cbc1-4679-a1dc-06722df5a4a6@intel.com \
    --to=lukasz.laguna@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=marcin.bernatowicz@linux.intel.com \
    --cc=michal.wajdeczko@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