From: sashiko-bot@kernel.org
To: "Jan Maslak" <jan.maslak@intel.com>, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v4 4/4] drm/xe/tests: Add xe_migrate_access_memory subtest
Date: Wed, 14 Oct 2026 13:58:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-171392@kernel.org> (raw)
In-Reply-To: <20261014134634.582314-5-jan.maslak@intel.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] xe: infinite recursion in xe_migrate_access_memory() due to unaligned kmalloc
- [Medium] drm/xe: test failure on big-endian architectures due to little-endian assumption
- [Low] drm/xe/tests: dead code in random offset generation
--
commit 123f5e095a34197f112fb5cb560c6b8a8cf51802
Author: Jan Maslak <jan.maslak@intel.com>
drm/xe/tests: Add xe_migrate_access_memory subtest
This commit adds a new xe_migrate subtest to verify VRAM to SRAM migration.
It explicitly tests migration when the destination address, migration size,
or source BO offset is not 4-byte aligned.
> diff --git a/drivers/gpu/drm/xe/tests/xe_migrate.c b/drivers/gpu/drm/xe/tests/xe_migrate.c
> --- 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 falsely fail on big-endian architectures?
Buffer generation in access_memory_test_run_tile() primes the test buffer
using native host endianness:
((u32 *)buf)[j] = j;
However, the bit shift here fundamentally assumes a little-endian memory
layout where the least significant byte is stored at the lowest address. On
a big-endian CPU, the most significant byte sits at the lowest address,
resulting in a mismatch. Should the code use explicit cpu_to_le32 and
le32_to_cpu macros to remain architecture-agnostic?
[ ... ]
> +static void access_memory_test_run_tile(struct xe_device *xe,
> + struct xe_tile *tile,
> + struct kunit *test,
> + bool use_random_offset)
> +{
> + struct drm_exec *exec = XE_VALIDATION_OPT_OUT;
> + 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;
> + long timeout;
> + 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)
> + unaligned_offset = 3;
[Severity: Low]
Is the zero-check fallback logic unreachable?
Any initial zero value from get_random_u32() is transformed to 2 by the
preceding alignment enforcement, so unaligned_offset cannot be 0 at this
point. This appears to be unnecessary dead code.
[ ... ]
> + access_memory_test_unaligned_bo_offset(test, m, bo, buf, unaligned_offset);
[Severity: High]
Could this unaligned testing trigger an infinite recursion and stack overflow
in xe_migrate_access_memory() when memory debugging is enabled?
When xe->info.has_mem_copy_instr is false, xe_migrate_access_memory()
handles unaligned offsets by allocating a bounce buffer and then recursively
calling itself:
drivers/gpu/drm/xe/xe_migrate.c:xe_migrate_access_memory() {
...
bounce = kmalloc(XE_CACHELINE_BYTES, GFP_KERNEL);
...
err = xe_migrate_access_memory(m, bo,
offset & ~XE_CACHELINE_MASK,
bounce,
XE_CACHELINE_BYTES, 0);
...
}
Under configurations like CONFIG_SLUB_DEBUG or CONFIG_KASAN, kmalloc()
for 64 bytes does not guarantee 64-byte alignment due to redzoning and
padding. If the returned bounce buffer is not cacheline aligned, the
recursive call's page_offset will be unaligned, causing the alignment check
to evaluate to true again and leading to unbounded recursion.
> + access_memory_test_unaligned_dst(test, m, bo, buf, unaligned_offset);
> + access_memory_test_unaligned_dst_aligned_size(test, m, bo, buf, unaligned_offset);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261014134634.582314-1-jan.maslak@intel.com?part=4
prev parent reply other threads:[~2026-10-14 13:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 13:46 [PATCH v4 0/4] drm/xe/xe_migrate: Fix memory corruption with unaligned dst in MEM_COPY Jan Maslak
2026-10-14 13:46 ` [PATCH v4 1/4] drm/xe/xe_migrate: Fix page tracking in access_memory Jan Maslak
2026-10-14 13:46 ` [PATCH v4 2/4] drm/xe/xe_migrate: Align MEM_COPY pitch with destination address Jan Maslak
2026-10-14 13:58 ` sashiko-bot
2026-10-14 13:46 ` [PATCH v4 3/4] drm/xe/xe_migrate: Optimize unaligned access_memory copies Jan Maslak
2026-10-14 13:57 ` sashiko-bot
2026-10-14 13:46 ` [PATCH v4 4/4] drm/xe/tests: Add xe_migrate_access_memory subtest Jan Maslak
2026-10-14 13:58 ` sashiko-bot [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=sashiko-outbox-171392@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox