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: "Adam Miszczak" <adam.miszczak@linux.intel.com>,
	"Jakub Kolakowski" <jakub1.kolakowski@intel.com>,
	"Michał Wajdeczko" <michal.wajdeczko@intel.com>,
	"Michał Winiarski" <michal.winiarski@intel.com>,
	"Narasimha C V" <narasimha.c.v@intel.com>,
	"Piotr Piórkowski" <piotr.piorkowski@intel.com>,
	"Satyanarayana K V P" <satyanarayana.k.v.p@intel.com>,
	"Tomasz Lis" <tomasz.lis@intel.com>
Subject: Re: [PATCH v2 i-g-t 2/7] lib/xe/xe_sriov_debugfs: Add validation for provisioned ranges
Date: Wed, 15 Jan 2025 16:55:55 +0100	[thread overview]
Message-ID: <90a12c2a-0ee5-4270-aac0-afdae2530f4e@intel.com> (raw)
In-Reply-To: <20250114150848.332708-3-marcin.bernatowicz@linux.intel.com>

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


On 1/14/2025 16:08, Marcin Bernatowicz wrote:
> Introduce `xe_sriov_pf_debugfs_read_check_ranges`, adding a validation
> step on top of `xe_sriov_pf_debugfs_read_provisioned_ranges`.
>
> Enforce checks for:
> - Ranges when no VFs are expected.
> - Duplicate, missing, or out-of-range VF IDs.
>
> The function ensures the returned ranges are sorted by VF ID.
>
> 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: Lukasz Laguna<lukasz.laguna@intel.com>
> Cc: Michał Wajdeczko<michal.wajdeczko@intel.com>
> Cc: Michał Winiarski<michal.winiarski@intel.com>
> Cc: Narasimha C V<narasimha.c.v@intel.com>
> Cc: Piotr Piórkowski<piotr.piorkowski@intel.com>
> Cc: Satyanarayana K V P<satyanarayana.k.v.p@intel.com>
> Cc: Tomasz Lis<tomasz.lis@intel.com>
> ---
>   lib/xe/xe_sriov_debugfs.c | 116 ++++++++++++++++++++++++++++++++++++++
>   lib/xe/xe_sriov_debugfs.h |   4 ++
>   2 files changed, 120 insertions(+)
>
> diff --git a/lib/xe/xe_sriov_debugfs.c b/lib/xe/xe_sriov_debugfs.c
> index 92a477764..abb1bf7d5 100644
> --- a/lib/xe/xe_sriov_debugfs.c
> +++ b/lib/xe/xe_sriov_debugfs.c
> @@ -206,6 +206,122 @@ cleanup:
>   	return ret;
>   }
>   
> +static int compare_ranges_by_vf_id(const void *a, const void *b)
> +{
> +	const struct xe_sriov_provisioned_range *range_a = a;
> +	const struct xe_sriov_provisioned_range *range_b = b;
> +
> +	return (range_a->vf_id - range_b->vf_id);
> +}
> +
> +#define MAX_DEBUG_ENTRIES 70U
> +
> +static int validate_vf_ids(enum xe_sriov_shared_res res,
> +			   struct xe_sriov_provisioned_range *ranges,
> +			   unsigned int nr_ranges, unsigned int expected_num_vfs)
> +{
> +	unsigned int current_vf_id = 0;
> +
> +	/* If no VFs are expected, ensure no ranges are provided */
> +	if (expected_num_vfs == 0) {
> +		if (nr_ranges > 0) {
> +			unsigned int limit = min(nr_ranges, MAX_DEBUG_ENTRIES);
> +
> +			igt_debug("%s: Unexpected %u ranges when expected num_vfs == 0\n",
> +				  xe_sriov_debugfs_provisioned_attr_name(res),
> +				  nr_ranges);
> +			for (unsigned int i = 0; i < limit; i++) {
> +				igt_debug((res == XE_SRIOV_SHARED_RES_GGTT) ?
> +						  "%s:VF%u: %lx-%lx\n" :
> +						  "%s:VF%u: %lu-%lu\n",
> +					  xe_sriov_shared_res_to_string(res),
> +					  ranges[i].vf_id, ranges[i].start, ranges[i].end);
> +			}
> +			igt_debug_on_f(nr_ranges > MAX_DEBUG_ENTRIES,
> +				       "%s: Output truncated to first %u ranges out of %u\n",
> +				       xe_sriov_debugfs_provisioned_attr_name(res),
> +				       MAX_DEBUG_ENTRIES, nr_ranges);
> +
> +			return -ERANGE;
> +		}
> +		return 0; /* Valid case: no VFs, no ranges */
> +	}
> +
> +	if (igt_debug_on_f(nr_ranges == 0,
> +			   "%s: No VF ranges\n",
> +			   xe_sriov_debugfs_provisioned_attr_name(res)))
> +		return -ENOENT;
> +
> +	igt_assert(ranges);
> +	qsort(ranges, nr_ranges, sizeof(ranges[0]), compare_ranges_by_vf_id);
> +
> +	for (unsigned int i = 0; i < nr_ranges; i++) {
> +		unsigned int vf_id = ranges[i].vf_id;
> +
> +		if (igt_debug_on_f(vf_id == current_vf_id,
> +				   "%s: Duplicate VF%u entry found\n",
> +				   xe_sriov_debugfs_provisioned_attr_name(res), vf_id))
> +			return -EEXIST;
> +
> +		if (igt_debug_on_f(vf_id < 1 || vf_id > expected_num_vfs,
> +				   "%s: Out of range VF%u\n",
> +				   xe_sriov_debugfs_provisioned_attr_name(res), vf_id))
> +			return -ERANGE;
> +
> +		if (igt_debug_on_f(vf_id > current_vf_id + 1,
> +				   "%s: Missing VF%u\n",
> +				   xe_sriov_debugfs_provisioned_attr_name(res),
> +				   current_vf_id + 1))
> +			return -ESRCH;
> +
> +		current_vf_id = vf_id;
> +	}
> +
> +	if (igt_debug_on_f(current_vf_id != expected_num_vfs,
> +			   "%s: Missing VF%u\n",
> +			   xe_sriov_debugfs_provisioned_attr_name(res), expected_num_vfs))
> +		return -ESRCH;
> +
> +	return 0;
> +}
> +
> +/**
> + * xe_sriov_pf_debugfs_read_check_ranges:
> + * @pf_fd: PF device file descriptor
> + * @res: resource
> + * @gt_id: GT number
> + * @ranges: pointer to array of provisioned ranges
> + * @expected_num_vfs: expected number of provisioned VFs
> + *
> + * Reads and validates provisioned ranges of shared resources.
> + * If successfully validated, returns num_vfs allocated ranges
> + * sorted by VF id.
> + * The caller should free the allocated space.
> + *
> + * Return: 0 if successful in reading valid ranges, otherwise negative error code.
> + */
> +int xe_sriov_pf_debugfs_read_check_ranges(int pf_fd, enum xe_sriov_shared_res res,
> +					  unsigned int gt_id,
> +					  struct xe_sriov_provisioned_range **ranges,
> +					  unsigned int expected_num_vfs)
> +{
> +	unsigned int nr_ranges;
> +	int ret;
> +
> +	ret = xe_sriov_pf_debugfs_read_provisioned_ranges(pf_fd, res, gt_id,
> +							  ranges, &nr_ranges);
> +	if (ret)
> +		return ret;
> +
> +	ret = validate_vf_ids(res, *ranges, nr_ranges, expected_num_vfs);
> +	if (ret) {
> +		free(*ranges);
> +		*ranges = NULL;
> +	}
> +
> +	return ret;
> +}
> +
>   static int xe_sriov_pf_debugfs_path_open(int pf, unsigned int vf_num,
>   					 unsigned int gt_num)
>   {
> diff --git a/lib/xe/xe_sriov_debugfs.h b/lib/xe/xe_sriov_debugfs.h
> index 2db965f9b..cd5f932be 100644
> --- a/lib/xe/xe_sriov_debugfs.h
> +++ b/lib/xe/xe_sriov_debugfs.h
> @@ -16,6 +16,10 @@ int xe_sriov_pf_debugfs_read_provisioned_ranges(int pf_fd, enum xe_sriov_shared_
>   						unsigned int gt_id,
>   						struct xe_sriov_provisioned_range **ranges,
>   						unsigned int *nr_ranges);
> +int xe_sriov_pf_debugfs_read_check_ranges(int pf_fd, enum xe_sriov_shared_res res,
> +					  unsigned int gt_id,
> +					  struct xe_sriov_provisioned_range **ranges,
> +					  unsigned int expected_num_vfs);
>   int __xe_sriov_pf_debugfs_get_u32(int pf, unsigned int vf_num,
>   				  unsigned int gt_num, const char *attr,
>   				  uint32_t *value);

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

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

  reply	other threads:[~2025-01-15 15:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-14 15:08 [PATCH v2 i-g-t 0/7] Add xe_sriov_auto_provisioning tests Marcin Bernatowicz
2025-01-14 15:08 ` [PATCH v2 i-g-t 1/7] lib/xe/xe_sriov_debugfs: Add debugfs get/set functions for u32, u64, bool Marcin Bernatowicz
2025-01-14 15:08 ` [PATCH v2 i-g-t 2/7] lib/xe/xe_sriov_debugfs: Add validation for provisioned ranges Marcin Bernatowicz
2025-01-15 15:55   ` Laguna, Lukasz [this message]
2025-01-14 15:08 ` [PATCH v2 i-g-t 3/7] lib/xe/xe_sriov_provisioning: Add accessors for quota/spare attributes Marcin Bernatowicz
2025-01-14 15:08 ` [PATCH v2 i-g-t 4/7] lib/xe/xe_sriov_provisioning: Add shared resource provisionability check Marcin Bernatowicz
2025-01-14 15:08 ` [PATCH v2 i-g-t 5/7] lib/igt_sriov_device: Add helper functions for VF range validation Marcin Bernatowicz
2025-01-14 15:08 ` [PATCH v2 i-g-t 6/7] tests/xe_sriov_auto_provisioning: Add tests for SR-IOV auto-provisioning Marcin Bernatowicz
2025-01-15 15:57   ` Laguna, Lukasz
2025-01-14 15:08 ` [PATCH v2 i-g-t 7/7] tests/xe_sriov_auto_provisioning: Add 'extended' command line option Marcin Bernatowicz
2025-01-15 16:06   ` Laguna, Lukasz
2025-01-14 18:17 ` ✓ i915.CI.BAT: success for Add xe_sriov_auto_provisioning tests (rev2) Patchwork
2025-01-14 18:24 ` ✓ Xe.CI.BAT: " Patchwork
2025-01-14 20:53 ` ✗ Xe.CI.Full: failure " Patchwork
2025-01-15 13:04 ` ✗ i915.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=90a12c2a-0ee5-4270-aac0-afdae2530f4e@intel.com \
    --to=lukasz.laguna@intel.com \
    --cc=adam.miszczak@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=jakub1.kolakowski@intel.com \
    --cc=marcin.bernatowicz@linux.intel.com \
    --cc=michal.wajdeczko@intel.com \
    --cc=michal.winiarski@intel.com \
    --cc=narasimha.c.v@intel.com \
    --cc=piotr.piorkowski@intel.com \
    --cc=satyanarayana.k.v.p@intel.com \
    --cc=tomasz.lis@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