All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jan Maslak" <jan.maslak@intel.com>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v3 4/4] drm/xe/tests: Add xe_migrate_access_memory subtest
Date: Wed, 09 Sep 2026 06:28:43 +0000	[thread overview]
Message-ID: <20260909062844.4010C1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260909061845.4048047-5-jan.maslak@intel.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [Medium] The byte-wise verification logic in `verify_access_memory_read` assumes a little-endian memory layout, causing the test to fail on big-endian architectures.
- [Low] The fallback condition `if (!unaligned_offset)` is dead code and will never evaluate to true.

Pre-existing issues:
- [High] Infinite recursion in `xe_migrate_access_memory` when the allocated bounce buffer is not cacheline aligned.
--

commit bc41ecbf5d587d033724f3736f3ff4ebc8156d3a
Author: Jan Maslak <jan.maslak@intel.com>
Subject: drm/xe/tests: Add xe_migrate_access_memory subtest

This commit adds a new subtest to xe_migrate to verify vram to sram migration.
It specifically tests scenarios where the destination address, migration size,
or source BO offset are not 4-byte aligned.

> diff --git a/drivers/gpu/drm/xe/tests/xe_migrate.c b/drivers/gpu/drm/xe/tests/xe_migrate.c
> index f10d9513747b4..9e18fcd51e26c 100644
> --- a/drivers/gpu/drm/xe/tests/xe_migrate.c
> +++ b/drivers/gpu/drm/xe/tests/xe_migrate.c
[ ... ]
> +static bool verify_access_memory_read(struct kunit *test, u8 *buf,
> +				      u32 buf_start, u32 bo_start,
> +				      u32 size, const char *scenario)
> +{
> +	u32 j;
> +
> +	for (j = 0; j < size; j++) {
> +		u32 bo_byte_offset = bo_start + j;
> +		u32 byte_in_cell = bo_byte_offset % sizeof(u32);
> +		u32 cell_idx = bo_byte_offset / sizeof(u32);
> +		u32 cell_value = cell_idx;
> +		u8 expected_byte = (cell_value >> (byte_in_cell * 8)) & 0xFF;

[Severity: Medium]
Will this test fail spuriously on big-endian architectures? 

The bit-shift logic here in verify_access_memory_read() explicitly expects 
bytes to be laid out in little-endian order, but the array is primed in the
host's native byte order later in access_memory_test_run_tile().

[ ... ]
> +static void access_memory_test_unaligned_bo_offset(struct kunit *test,
> +						    struct xe_migrate *m,
> +						    struct xe_bo *bo, u8 *buf,
> +						    u32 unaligned_offset)
> +{
> +	u32 partial_size = ACCESS_MEM_BO_SIZE - unaligned_offset;
> +	int ret;
> +
> +	memset(buf, 0, ACCESS_MEM_BO_SIZE);
> +
> +	kunit_info(test, "Partial read: bo_offset=0x%x bytes=0x%x\n",
> +		   unaligned_offset, partial_size);
> +
> +	ret = xe_migrate_access_memory(m, bo, unaligned_offset, buf,
> +				       partial_size, false);

[Severity: High]
This is a pre-existing issue, but could these unaligned tests trigger an
infinite recursion loop in xe_migrate_access_memory()? 

When handling an unaligned vram access on a platform without
has_mem_copy_instr, xe_migrate_access_memory() allocates a bounce buffer:

    bounce = kmalloc(XE_CACHELINE_BYTES, GFP_KERNEL);

If debugging options like Kasan or Slub redzoning are enabled, kmalloc is not
guaranteed to return a cacheline-aligned pointer. The unaligned bounce buffer
pointer is then passed to the recursive call where it fails the alignment
check again, leading to another allocation and recursing infinitely.

[ ... ]
> +static void access_memory_test_run_tile(struct xe_device *xe,
> +					struct xe_tile *tile,
> +					struct kunit *test,
> +					bool use_random_offset)
> +{
> +	unsigned int bo_flags = XE_BO_FLAG_VRAM_IF_DGFX(tile);
> +	struct xe_migrate *m = tile->migrate;
> +	u32 j, unaligned_offset;
> +	struct xe_bo *bo;
> +	u8 *buf;
> +	int ret;
> +
> +	if (use_random_offset) {
> +		unaligned_offset = get_random_u32() % (ACCESS_MEM_BO_SIZE / 2);
> +		/* Ensure the offset is not 4-byte aligned */
> +		if (IS_ALIGNED(unaligned_offset, 4))
> +			unaligned_offset |= 2;
> +		if (!unaligned_offset)

[Severity: Low]
Is this fallback condition dead code? 

The value of unaligned_offset can never be 0 at this point. Since 0 is 4-byte
aligned, the preceding bitwise OR is guaranteed to execute and change the
value to 2, rendering this subsequent check permanently false.

> +			unaligned_offset = 3;
> +	} else {
> +		unaligned_offset = ACCESS_MEM_UNALIGNED_OFFSET;
> +	}
[ ... ]
> +	/* Prime the BO */
> +	for (j = 0; j < ACCESS_MEM_NUM_CELLS; j++)
> +		((u32 *)buf)[j] = j;

[Severity: Medium]
Does this code create a mismatch on big-endian architectures? 

The array is primed in the host's native byte order here in
access_memory_test_run_tile(), creating a mismatch when verified against the
little-endian assumption in verify_access_memory_read().

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909061845.4048047-1-jan.maslak@intel.com?part=4

  reply	other threads:[~2026-09-09  6:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09  6:18 [PATCH v3 0/4] drm/xe/xe_migrate: Fix memory corruption with unaligned dst in MEM_COPY Jan Maslak
2026-09-09  6:18 ` [PATCH v3 1/4] drm/xe/xe_migrate: Align MEM_COPY pitch with destination address Jan Maslak
2026-09-09  6:32   ` sashiko-bot
2026-09-09  6:18 ` [PATCH v3 2/4] drm/xe/xe_migrate: Fix page tracking in access_memory Jan Maslak
2026-09-09  6:30   ` sashiko-bot
2026-09-09  6:18 ` [PATCH v3 3/4] drm/xe/xe_migrate: Optimize unaligned access_memory copies Jan Maslak
2026-09-09  6:31   ` sashiko-bot
2026-09-09  6:18 ` [PATCH v3 4/4] drm/xe/tests: Add xe_migrate_access_memory subtest Jan Maslak
2026-09-09  6:28   ` sashiko-bot [this message]
2026-09-09  6:25 ` ✗ CI.checkpatch: warning for drm/xe/xe_migrate: Fix memory corruption with unaligned dst in MEM_COPY (rev3) Patchwork
2026-09-09  6:27 ` ✓ CI.KUnit: success " Patchwork
2026-09-09  7:04 ` ✗ Xe.CI.BAT: failure " Patchwork
2026-09-09 11:36 ` ✗ 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=20260909062844.4010C1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jan.maslak@intel.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.