From: Gustavo Sousa <gustavo.sousa@intel.com>
To: Michal Wajdeczko <michal.wajdeczko@intel.com>,
<intel-xe@lists.freedesktop.org>
Cc: Matt Roper <matthew.d.roper@intel.com>
Subject: Re: [PATCH 05/12] drm/xe/kunit: Abort test if MMIO operation is attempted
Date: Tue, 5 May 2026 16:11:30 -0300 [thread overview]
Message-ID: <87lddxy8m5.fsf@intel.com> (raw)
In-Reply-To: <203dac4b-2de5-4eef-8bee-e274701db2f2@intel.com>
Michal Wajdeczko <michal.wajdeczko@intel.com> writes:
> On 1/16/2026 11:12 PM, Gustavo Sousa wrote:
>> Regular Xe KUnit tests (i.e. not the live ones) are usually run in
>> User-Mode Linux and do not have access to the real hardware and, as
>> such, should not attempt to do MMIO operations. If some test ends up
>> exercising a path that contains MMIO operations, the test should be
>> rewritten in a way that the MMIO is skipped or simulated (e.g. via a
>> static stub).
>>
>> Let's make sure to abort the test if MMIO is attempted on non-live
>> tests. Before aborting, use drm_WARN() to cause a stack trace to be
>> logged as a debug aid to the developer.
>
> maybe cleaner solution would be first to add to all xe_mmio functions:
>
> KUNIT_STATIC_STUB_REDIRECT
>
> and then (in separate patch) activate "abort" stubs in xe_pci_fake_device_init,
> similar to what we do with read_gmdid & xe_info_probe_tile_count
>
> if any test would like to intercept some mmio read/writes it will just provide and activate its own stub
> and such usage will be no different than any other use of stubs
>
> this will allow to drop patch 6 which introduces (IMO unnecessary) another layer
> (where test should stub another test function instead of the real function)
Thanks for the feedback!
After seeing Matt's feedback on patch #12, I think we will end up
dropping this MMIO intercepting stuff.
I wonder if there is value in keeping the "abort" part though, to ensure
that we don't accidentally try to read info from non-existing hardware.
If so, I guess I would just keep this patch, but modified so that we
don't need the separate xe_kunit_mmio.c file. Also, that would be a
matter of a separate series as well, since it would be orthogonal to
this series.
Thoughts?
--
Gustavo Sousa
>
>>
>> Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
>> ---
>> drivers/gpu/drm/xe/tests/Makefile | 1 +
>> drivers/gpu/drm/xe/tests/xe_kunit_mmio.c | 35 ++++++++++++++++++++++++++++++++
>> drivers/gpu/drm/xe/tests/xe_kunit_mmio.h | 27 ++++++++++++++++++++++++
>> drivers/gpu/drm/xe/xe_mmio.c | 9 ++++++++
>> 4 files changed, 72 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/xe/tests/Makefile b/drivers/gpu/drm/xe/tests/Makefile
>> index 0e3408f4952c..8f3a594449c8 100644
>> --- a/drivers/gpu/drm/xe/tests/Makefile
>> +++ b/drivers/gpu/drm/xe/tests/Makefile
>> @@ -8,6 +8,7 @@ xe_live_test-y = xe_live_test_mod.o
>> obj-$(CONFIG_DRM_XE_KUNIT_TEST) += xe_test.o
>> xe_test-y = xe_test_mod.o \
>> xe_args_test.o \
>> + xe_kunit_mmio.o \
>> xe_pci_test.o \
>> xe_rtp_test.o \
>> xe_wa_test.o
>> diff --git a/drivers/gpu/drm/xe/tests/xe_kunit_mmio.c b/drivers/gpu/drm/xe/tests/xe_kunit_mmio.c
>> new file mode 100644
>> index 000000000000..debf8bd3f9dd
>> --- /dev/null
>> +++ b/drivers/gpu/drm/xe/tests/xe_kunit_mmio.c
>> @@ -0,0 +1,35 @@
>> +// SPDX-License-Identifier: GPL-2.0 AND MIT
>> +/*
>> + * Copyright © 2026 Intel Corporation
>> + */
>> +
>> +#include <kunit/test.h>
>> +#include <kunit/test-bug.h>
>> +
>> +#include <drm/drm_print.h>
>> +
>> +#include "tests/xe_kunit_helpers.h"
>> +#include "tests/xe_kunit_mmio.h"
>> +#include "xe_device_types.h"
>> +
>> +/**
>> + * xe_kunit_mmio_abort_if_not_live_test - Abort test execution if not in a live test.
>> + * @mmio: MMIO target
>> + * @reg: Register on which an MMIO operation is about to be performed
>> + *
>> + * This function must be called from xe_mmio functions that perform MMIO
>> + * operations on the hardware. If the current process is a kunit test and it is
>> + * not a live test, it will cause a warn and abort the test; otherwise it does
>> + * nothing.
>> + */
>> +void xe_kunit_mmio_abort_if_not_live_test(struct xe_mmio *mmio, struct xe_reg reg)
>> +{
>> + struct xe_device *xe = tile_to_xe(mmio->tile);
>> + struct kunit *test = kunit_get_current_test();
>> +
>> + if (!test || xe_kunit_is_live_test(test))
>> + return;
>> +
>> + drm_WARN(&xe->drm, true, "MMIO function called on reg 0x%x\n", reg.addr);
>> + KUNIT_FAIL_AND_ABORT(test, "MMIO function called on reg 0x%x\n", reg.addr);
>> +}
>> diff --git a/drivers/gpu/drm/xe/tests/xe_kunit_mmio.h b/drivers/gpu/drm/xe/tests/xe_kunit_mmio.h
>> new file mode 100644
>> index 000000000000..d46ac2b82969
>> --- /dev/null
>> +++ b/drivers/gpu/drm/xe/tests/xe_kunit_mmio.h
>> @@ -0,0 +1,27 @@
>> +/* SPDX-License-Identifier: GPL-2.0 AND MIT */
>> +/*
>> + * Copyright © 2026 Intel Corporation
>> + */
>> +
>> +#ifndef _XE_KUNIT_MMIO_H_
>> +#define _XE_KUNIT_MMIO_H_
>> +
>> +#include <linux/types.h>
>> +
>> +#include "regs/xe_reg_defs.h"
>> +
>> +struct xe_mmio;
>> +
>> +#if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST)
>> +
>> +void xe_kunit_mmio_abort_if_not_live_test(struct xe_mmio *mmio, struct xe_reg reg);
>> +
>> +#else
>> +
>> +static void xe_kunit_mmio_abort_if_not_live_test(struct xe_mmio *mmio, struct xe_reg reg)
>> +{
>> +}
>> +
>> +#endif
>> +
>> +#endif
>> diff --git a/drivers/gpu/drm/xe/xe_mmio.c b/drivers/gpu/drm/xe/xe_mmio.c
>> index bcb6674b7dac..0f9a1d5453df 100644
>> --- a/drivers/gpu/drm/xe/xe_mmio.c
>> +++ b/drivers/gpu/drm/xe/xe_mmio.c
>> @@ -14,6 +14,7 @@
>> #include <drm/drm_print.h>
>>
>> #include "regs/xe_bars.h"
>> +#include "tests/xe_kunit_mmio.h"
>> #include "xe_device.h"
>> #include "xe_gt_sriov_vf.h"
>> #include "xe_sriov.h"
>> @@ -146,6 +147,8 @@ u8 xe_mmio_read8(struct xe_mmio *mmio, struct xe_reg reg)
>> u32 addr = xe_mmio_adjusted_addr(mmio, reg.addr);
>> u8 val;
>>
>> + xe_kunit_mmio_abort_if_not_live_test(mmio, reg);
>> +
>> mmio_flush_pending_writes(mmio);
>>
>> val = readb(mmio->regs + addr);
>> @@ -159,6 +162,8 @@ u16 xe_mmio_read16(struct xe_mmio *mmio, struct xe_reg reg)
>> u32 addr = xe_mmio_adjusted_addr(mmio, reg.addr);
>> u16 val;
>>
>> + xe_kunit_mmio_abort_if_not_live_test(mmio, reg);
>> +
>> mmio_flush_pending_writes(mmio);
>>
>> val = readw(mmio->regs + addr);
>> @@ -171,6 +176,8 @@ void xe_mmio_write32(struct xe_mmio *mmio, struct xe_reg reg, u32 val)
>> {
>> u32 addr = xe_mmio_adjusted_addr(mmio, reg.addr);
>>
>> + xe_kunit_mmio_abort_if_not_live_test(mmio, reg);
>> +
>> trace_xe_reg_rw(mmio, true, addr, val, sizeof(val));
>>
>> if (!reg.vf && IS_SRIOV_VF(mmio->tile->xe))
>> @@ -185,6 +192,8 @@ u32 xe_mmio_read32(struct xe_mmio *mmio, struct xe_reg reg)
>> u32 addr = xe_mmio_adjusted_addr(mmio, reg.addr);
>> u32 val;
>>
>> + xe_kunit_mmio_abort_if_not_live_test(mmio, reg);
>> +
>> mmio_flush_pending_writes(mmio);
>>
>> if (!reg.vf && IS_SRIOV_VF(mmio->tile->xe))
>>
next prev parent reply other threads:[~2026-05-05 19:11 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-16 22:12 [PATCH 00/12] Fix MCR inconsistencies in RTP tables Gustavo Sousa
2026-01-16 22:12 ` [PATCH 01/12] drm/xe: Define CACHE_MODE_1 as MCR register Gustavo Sousa
2026-01-21 0:04 ` Matt Roper
2026-01-16 22:12 ` [PATCH 02/12] drm/xe: Define and use MCR version of COMMON_SLICE_CHICKEN1 Gustavo Sousa
2026-01-21 0:06 ` Matt Roper
2026-01-16 22:12 ` [PATCH 03/12] drm/xe: Define and use MCR version of COMMON_SLICE_CHICKEN4 Gustavo Sousa
2026-01-21 0:08 ` Matt Roper
2026-01-16 22:12 ` [PATCH 04/12] drm/xe/kunit: Add xe_kunit_is_live_test() Gustavo Sousa
2026-01-16 22:59 ` Michal Wajdeczko
2026-05-05 18:32 ` Gustavo Sousa
2026-01-16 22:12 ` [PATCH 05/12] drm/xe/kunit: Abort test if MMIO operation is attempted Gustavo Sousa
2026-01-16 23:15 ` Michal Wajdeczko
2026-05-05 19:11 ` Gustavo Sousa [this message]
2026-01-16 22:12 ` [PATCH 06/12] drm/xe/kunit: Allow intercepting MMIO operations Gustavo Sousa
2026-01-16 22:12 ` [PATCH 07/12] drm/xe: Extract xe_hw_engine_setup_reg_lrc() Gustavo Sousa
2026-01-21 0:12 ` Matt Roper
2026-01-16 22:12 ` [PATCH 08/12] drm/xe: Extract xe_hw_engines_setup_runtime_mask() Gustavo Sousa
2026-01-28 18:07 ` Matt Roper
2026-01-16 22:12 ` [PATCH 09/12] drm/xe/kunit: Use KUNIT_EXPECT_EQ() in xe_wa_gt() Gustavo Sousa
2026-01-16 23:29 ` Michal Wajdeczko
2026-01-28 18:09 ` Matt Roper
2026-01-16 22:12 ` [PATCH 10/12] drm/xe/kunit: Include hw_engines in xe_wa test Gustavo Sousa
2026-01-28 21:08 ` Matt Roper
2026-01-16 22:12 ` [PATCH 11/12] drm/xe/mcr: Extract reg_in_steering_type_ranges() Gustavo Sousa
2026-01-28 21:11 ` Matt Roper
2026-01-16 22:12 ` [PATCH 12/12] drm/xe/reg_sr: Do sanity check for MCR vs non-MCR Gustavo Sousa
2026-01-28 23:59 ` Matt Roper
2026-05-05 19:39 ` Gustavo Sousa
2026-01-16 23:15 ` ✗ CI.checkpatch: warning for Fix MCR inconsistencies in RTP tables Patchwork
2026-01-16 23:16 ` ✓ CI.KUnit: success " 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=87lddxy8m5.fsf@intel.com \
--to=gustavo.sousa@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.d.roper@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