All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Bernatowicz, Marcin" <marcin.bernatowicz@linux.intel.com>
To: Lukasz Laguna <lukasz.laguna@intel.com>, igt-dev@lists.freedesktop.org
Cc: michal.wajdeczko@intel.com, michal.winiarski@intel.com,
	satyanarayana.k.v.p@intel.com, adam.miszczak@linux.intel.com,
	jakub1.kolakowski@intel.com
Subject: Re: [PATCH i-g-t 3/4] tests/intel/xe_sriov_flr: Use VRAM access helpers from intel_vram library
Date: Thu, 21 Aug 2025 22:30:24 +0200	[thread overview]
Message-ID: <5b9a0e88-4cb9-4296-9039-c67742438dfb@linux.intel.com> (raw)
In-Reply-To: <20250717090812.28628-4-lukasz.laguna@intel.com>



On 7/17/2025 11:08 AM, Lukasz Laguna wrote:
> Replace local VRAM access helper functions with the helpers provided by
> the intel_vram library.
> 
> Signed-off-by: Lukasz Laguna <lukasz.laguna@intel.com>
> ---
>   tests/intel/xe_sriov_flr.c | 106 +++++++------------------------------
>   1 file changed, 20 insertions(+), 86 deletions(-)
> 
> diff --git a/tests/intel/xe_sriov_flr.c b/tests/intel/xe_sriov_flr.c
> index 0c6a0c97e..3b7001ec7 100644
> --- a/tests/intel/xe_sriov_flr.c
> +++ b/tests/intel/xe_sriov_flr.c
> @@ -11,6 +11,7 @@
>   #include "igt_device.h"
>   #include "igt_sriov_device.h"
>   #include "intel_chipset.h"
> +#include "intel_vram.h"
>   #include "linux_scaffold.h"
>   #include "xe/xe_mmio.h"
>   #include "xe/xe_query.h"
> @@ -676,94 +677,28 @@ struct lmem_data {
>   	size_t *vf_lmem_size;
>   };
>   
> -struct lmem_info {
> -	/* pointer to the mapped area */
> -	char *addr;
> -	/* size of mapped area */
> -	size_t size;
> -};
> -
>   const size_t STEP = SZ_1M;
>   
> -static void *mmap_vf_lmem(int pf_fd, int vf_num, size_t length, int prot, off_t offset)
> -{
> -	int open_flags = ((prot & PROT_WRITE) != 0) ? O_RDWR : O_RDONLY;
> -	struct stat st;
> -	int sysfs, fd;
> -	void *addr;
> -
> -	sysfs = igt_sriov_device_sysfs_open(pf_fd, vf_num);
> -	if (sysfs < 0) {
> -		igt_debug("Failed to open sysfs for VF%d: %s\n", vf_num, strerror(errno));
> -		return NULL;
> -	}
> -
> -	fd = openat(sysfs, "resource2", open_flags | O_SYNC);
> -	close(sysfs);
> -	if (fd < 0) {
> -		igt_debug("Failed to open resource2 for VF%d: %s\n", vf_num, strerror(errno));
> -		return NULL;
> -	}
> -
> -	if (fstat(fd, &st)) {
> -		igt_debug("Failed to stat resource2 for VF%d: %s\n", vf_num, strerror(errno));
> -		close(fd);
> -		return NULL;
> -	}
> -
> -	if (st.st_size < length) {
> -		igt_debug("Mapping length (%zu) exceeds BAR2 size (%" PRIu64 ")\n", length, (uint64_t)st.st_size);
> -		close(fd);
> -		return NULL;
> -	}
> -
> -	addr = mmap(NULL, length, prot, MAP_SHARED, fd, offset);
> -	close(fd);
> -	if (addr == MAP_FAILED) {
> -		igt_debug("Failed mmap resource2 for VF%d: %s\n", vf_num, strerror(errno));
> -		return NULL;
> -	}
> -
> -	return addr;
> -}
> -
> -static void munmap_vf_lmem(struct lmem_info *lmem)
> -{
> -	igt_debug_on_f(munmap(lmem->addr, lmem->size),
> -		       "Failed munmap %p: %s\n", lmem->addr, strerror(errno));
> -}
> -
> -static char lmem_read(const char *addr, size_t idx)
> -{
> -	return READ_ONCE(*(addr + idx));
> -}
> -
> -static char lmem_write_readback(char *addr, size_t idx, char value)
> -{
> -	WRITE_ONCE(*(addr + idx), value);
> -	return lmem_read(addr, idx);
> -}
> -
> -static bool lmem_write_pattern(struct lmem_info *lmem, char value, size_t start, size_t step)
> +static bool lmem_write_pattern(struct vram_mapping *m, uint8_t value, size_t start, size_t step)
>   {
> -	char read;
> +	uint8_t read;
>   
> -	for (; start < lmem->size; start += step) {
> -		read = lmem_write_readback(lmem->addr, start, value);
> +	for (; start < m->size; start += step) {
> +		read = intel_vram_write_readback8(m, start, value);
>   		if (igt_debug_on_f(read != value, "LMEM[%zu]=%u != %u\n", start, read, value))
>   			return false;
>   	}
>   	return true;
>   }
>   
> -static bool lmem_contains_expected_values_(struct lmem_info *lmem,
> -					   char expected, size_t start,
> +static bool lmem_contains_expected_values_(struct vram_mapping *m,
> +					   uint8_t expected, size_t start,
>   					   size_t step)
>   {
> -	char read;
> +	uint8_t read;
>   
> -	for (; start < lmem->size; start += step) {
> -		read = lmem_read(lmem->addr, start);
> +	for (; start < m->size; start += step) {
> +		read = intel_vram_read8(m, start);
>   		if (igt_debug_on_f(read != expected,
>   				   "LMEM[%zu]=%u != %u\n", start, read, expected))
>   			return false;
> @@ -774,30 +709,29 @@ static bool lmem_contains_expected_values_(struct lmem_info *lmem,
>   static bool lmem_contains_expected_values(int pf_fd, int vf_num, size_t length,
>   					  char expected)
>   {
> -	struct lmem_info lmem = { .size = length };
> +	struct vram_mapping vram;
>   	bool result;
>   
> -	lmem.addr = mmap_vf_lmem(pf_fd, vf_num, length, PROT_READ | PROT_WRITE, 0);
> -	if (igt_debug_on(!lmem.addr))
> +	vram = intel_vram_mmap(pf_fd, vf_num, length, PROT_READ | PROT_WRITE, 0);
> +	if (igt_debug_on(!vram.addr))
>   		return false;
>   
> -	result = lmem_contains_expected_values_(&lmem, expected, 0, STEP);
> -	munmap_vf_lmem(&lmem);
> +	result = lmem_contains_expected_values_(&vram, expected, 0, STEP);
> +	intel_vram_munmap(&vram);
>   
>   	return result;
>   }
>   
>   static bool lmem_mmap_write_munmap(int pf_fd, int vf_num, size_t length, char value)
>   {
> -	struct lmem_info lmem;
> +	struct vram_mapping vram;
>   	bool result;
>   
> -	lmem.size = length;
> -	lmem.addr = mmap_vf_lmem(pf_fd, vf_num, length, PROT_READ | PROT_WRITE, 0);
> -	if (igt_debug_on(!lmem.addr))
> +	vram = intel_vram_mmap(pf_fd, vf_num, length, PROT_READ | PROT_WRITE, 0);
> +	if (igt_debug_on(!vram.addr))
>   		return false;
> -	result = lmem_write_pattern(&lmem, value, 0, STEP);
> -	munmap_vf_lmem(&lmem);
> +	result = lmem_write_pattern(&vram, value, 0, STEP);
> +	intel_vram_munmap(&vram);
>   
>   	return result;
>   }

LGTM. If intel_vram lib is going to be modified, we should also apply 
the same adjustments here.

  reply	other threads:[~2025-08-21 20:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-17  9:08 [PATCH i-g-t 0/4] Validate VF accesses to VRAM via BAR Lukasz Laguna
2025-07-17  9:08 ` [PATCH i-g-t 1/4] lib/igt_sriov_device: Add helper to iterate over enabled VFs Lukasz Laguna
2025-07-21 10:05   ` Piotr Piórkowski
2025-07-17  9:08 ` [PATCH i-g-t 2/4] lib/intel_vram: Add library for VRAM accesses Lukasz Laguna
2025-08-21 20:26   ` Bernatowicz, Marcin
2025-07-17  9:08 ` [PATCH i-g-t 3/4] tests/intel/xe_sriov_flr: Use VRAM access helpers from intel_vram library Lukasz Laguna
2025-08-21 20:30   ` Bernatowicz, Marcin [this message]
2025-07-17  9:08 ` [PATCH i-g-t 4/4] tests/intel/xe_sriov_vram: Add test checking VF access to VRAM Lukasz Laguna
2025-07-31  8:29   ` Piotr Piórkowski
2025-08-01 12:43     ` Laguna, Lukasz
2025-08-21 16:53   ` Bernatowicz, Marcin
2025-08-27 13:16     ` Laguna, Lukasz
2025-07-17 12:42 ` ✓ i915.CI.BAT: success for Validate VF accesses to VRAM via BAR Patchwork
2025-07-17 13:56 ` ✓ Xe.CI.BAT: " Patchwork
2025-07-18  1:23 ` ✗ i915.CI.Full: failure " Patchwork
2025-07-18 19:07 ` ✗ 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=5b9a0e88-4cb9-4296-9039-c67742438dfb@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=lukasz.laguna@intel.com \
    --cc=michal.wajdeczko@intel.com \
    --cc=michal.winiarski@intel.com \
    --cc=satyanarayana.k.v.p@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.