From: Christoph Manszewski <christoph.manszewski@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>,
"Kamil Konieczny" <kamil.konieczny@linux.intel.com>,
"Dominik Grzegorzek" <dominik.grzegorzek@intel.com>,
"Maciej Patelczyk" <maciej.patelczyk@intel.com>,
"Dominik Karol Piątkowski" <dominik.karol.piatkowski@intel.com>,
"Pawel Sikora" <pawel.sikora@intel.com>,
"Andrzej Hajda" <andrzej.hajda@intel.com>,
"Kolanupaka Naveena" <kolanupaka.naveena@intel.com>,
"Mika Kuoppala" <mika.kuoppala@intel.com>,
"Gwan-gyeong Mun" <gwan-gyeong.mun@intel.com>,
"Jan Sokolowski" <jan.sokolowski@intel.com>,
"Christoph Manszewski" <christoph.manszewski@intel.com>
Subject: [PATCH i-g-t v7 08/16] tests/xe_exec_sip: Introduce invalid instruction tests
Date: Wed, 18 Sep 2024 13:30:09 +0200 [thread overview]
Message-ID: <20240918113017.144687-9-christoph.manszewski@intel.com> (raw)
In-Reply-To: <20240918113017.144687-1-christoph.manszewski@intel.com>
From: Andrzej Hajda <andrzej.hajda@intel.com>
Xe2 and earlier gens are able to handle very limited set of invalid
instructions - only illegal and undefined opcodes, other errors in
instruction can cause undefined behavior.
Illegal/undefined opcode results in:
- setting illegal opcode status bit - cr0.1[28],
- calling SIP if illegal opcode bit is enabled - cr0.1[12].
cr0.1[12] can be enabled directly from the thread or by thread dispatcher
from Interface Descriptor Data provided to COMPUTE_WALKER instruction.
Implemented cases:
- check if SIP is not called when exception is not enabled,
- check if SIP is called when exception is enabled from EU thread,
- check if SIP is called when exception is enabled from COMPUTE_WALKER
Signed-off-by: Andrzej Hajda <andrzej.hajda@intel.com>
Cc: Mika Kuoppala <mika.kuoppala@intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek@intel.com>
Signed-off-by: Christoph Manszewski <christoph.manszewski@intel.com>
Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
---
tests/intel/xe_exec_sip.c | 124 ++++++++++++++++++++++++++++++++++----
1 file changed, 113 insertions(+), 11 deletions(-)
diff --git a/tests/intel/xe_exec_sip.c b/tests/intel/xe_exec_sip.c
index 564c899f8..ee4787d61 100644
--- a/tests/intel/xe_exec_sip.c
+++ b/tests/intel/xe_exec_sip.c
@@ -30,12 +30,25 @@
#define COLOR_C4 0xc4
#define SHADER_CANARY 0x01010101
+#define SIP_CANARY 0x02020202
enum shader_type {
SHADER_HANG,
+ SHADER_INV_INSTR_DISABLED,
+ SHADER_INV_INSTR_THREAD_ENABLED,
+ SHADER_INV_INSTR_WALKER_ENABLED,
SHADER_WRITE,
};
+enum sip_type {
+ SIP_INV_INSTR,
+ SIP_NULL,
+};
+
+/* Control Register cr0.1 bits for exception handling */
+#define ILLEGAL_OPCODE_ENABLE BIT(12)
+#define ILLEGAL_OPCODE_STATUS BIT(28)
+
static struct intel_buf *
create_fill_buf(int fd, int width, int height, uint8_t color)
{
@@ -58,8 +71,12 @@ create_fill_buf(int fd, int width, int height, uint8_t color)
static struct gpgpu_shader *get_shader(int fd, enum shader_type shader_type)
{
static struct gpgpu_shader *shader;
+ uint32_t bad;
shader = gpgpu_shader_create(fd);
+ if (shader_type == SHADER_INV_INSTR_WALKER_ENABLED)
+ shader->illegal_opcode_exception_enable = true;
+
gpgpu_shader__write_dword(shader, SHADER_CANARY, 0);
switch (shader_type) {
@@ -70,19 +87,63 @@ static struct gpgpu_shader *get_shader(int fd, enum shader_type shader_type)
break;
case SHADER_WRITE:
break;
+ case SHADER_INV_INSTR_THREAD_ENABLED:
+ gpgpu_shader__set_exception(shader, ILLEGAL_OPCODE_ENABLE);
+ __attribute__ ((fallthrough));
+ case SHADER_INV_INSTR_DISABLED:
+ case SHADER_INV_INSTR_WALKER_ENABLED:
+ bad = (shader_type == SHADER_INV_INSTR_DISABLED) ? ILLEGAL_OPCODE_ENABLE : 0;
+ gpgpu_shader__write_on_exception(shader, 1, 0, ILLEGAL_OPCODE_ENABLE, bad);
+ gpgpu_shader__nop(shader);
+ gpgpu_shader__nop(shader);
+ /* modify second nop, set only opcode bits[6:0] */
+ shader->instr[gpgpu_shader_last_instr(shader)][0] = 0x7f;
+ /* SIP should clear exception bit */
+ bad = ILLEGAL_OPCODE_STATUS;
+ gpgpu_shader__write_on_exception(shader, 2, 0, ILLEGAL_OPCODE_STATUS, bad);
+ break;
}
gpgpu_shader__eot(shader);
return shader;
}
+static struct gpgpu_shader *get_sip(int fd, enum sip_type sip_type, unsigned int y_offset)
+{
+ static struct gpgpu_shader *sip;
+
+ if (sip_type == SIP_NULL)
+ return NULL;
+
+ sip = gpgpu_shader_create(fd);
+ gpgpu_shader__write_dword(sip, SIP_CANARY, y_offset);
+
+ switch (sip_type) {
+ case SIP_INV_INSTR:
+ gpgpu_shader__write_on_exception(sip, 1, y_offset, ILLEGAL_OPCODE_STATUS, 0);
+ break;
+ default:
+ break;
+ }
+
+ gpgpu_shader__end_system_routine(sip, false);
+
+ return sip;
+}
+
static uint32_t gpgpu_shader(int fd, struct intel_bb *ibb, enum shader_type shader_type,
- unsigned int threads, unsigned int width, unsigned int height)
+ enum sip_type sip_type, unsigned int threads, unsigned int width,
+ unsigned int height)
{
struct intel_buf *buf = create_fill_buf(fd, width, height, COLOR_C4);
+ struct gpgpu_shader *sip = get_sip(fd, sip_type, height / 2);
struct gpgpu_shader *shader = get_shader(fd, shader_type);
- gpgpu_shader_exec(ibb, buf, 1, threads, shader, NULL, 0, 0);
+ gpgpu_shader_exec(ibb, buf, 1, threads, shader, sip, 0, 0);
+
+ if (sip)
+ gpgpu_shader_destroy(sip);
+
gpgpu_shader_destroy(shader);
return buf->handle;
}
@@ -98,10 +159,10 @@ static void check_fill_buf(uint8_t *ptr, const int width, const int x,
}
static void check_buf(int fd, uint32_t handle, int width, int height,
- uint8_t poison_c)
+ enum shader_type shader_type, enum sip_type sip_type, uint8_t poison_c)
{
unsigned int sz = ALIGN(width * height, 4096);
- int thread_count = 0;
+ int thread_count = 0, sip_count = 0;
uint32_t *ptr;
int i, j;
@@ -119,7 +180,27 @@ static void check_buf(int fd, uint32_t handle, int width, int height,
i = 0;
}
+ for (i = 0, j = height / 2; j < height; ++j) {
+ if (ptr[j * width / 4] == SIP_CANARY) {
+ ++sip_count;
+ i = 4;
+ }
+
+ for (; i < width; i++)
+ check_fill_buf((uint8_t *)ptr, width, i, j, poison_c);
+
+ i = 0;
+ }
+
igt_assert(thread_count);
+ if (shader_type == SHADER_INV_INSTR_DISABLED)
+ igt_assert(!sip_count);
+ else if (sip_type == SIP_INV_INSTR && shader_type != SHADER_INV_INSTR_DISABLED)
+ igt_assert_f(thread_count == sip_count,
+ "Thread and SIP count mismatch, %d != %d\n",
+ thread_count, sip_count);
+ else
+ igt_assert(sip_count == 0);
munmap(ptr, sz);
}
@@ -143,9 +224,21 @@ xe_sysfs_get_job_timeout_ms(int fd, struct drm_xe_engine_class_instance *eci)
*
* SUBTEST: sanity-after-timeout
* Description: check basic shader execution after job timeout
+ *
+ * SUBTEST: invalidinstr-disabled
+ * Description: Verify that we don't enter SIP after running into an invalid
+ * instruction when exception is not enabled.
+ *
+ * SUBTEST: invalidinstr-thread-enabled
+ * Description: Verify that we enter SIP after running into an invalid instruction
+ * when exception is enabled from thread.
+ *
+ * SUBTEST: invalidinstr-walker-enabled
+ * Description: Verify that we enter SIP after running into an invalid instruction
+ * when exception is enabled from COMPUTE_WALKER.
*/
-static void test_sip(enum shader_type shader_type, struct drm_xe_engine_class_instance *eci,
- uint32_t flags)
+static void test_sip(enum shader_type shader_type, enum sip_type sip_type,
+ struct drm_xe_engine_class_instance *eci, uint32_t flags)
{
unsigned int threads = 512;
unsigned int height = max_t(threads, HEIGHT, threads * 2);
@@ -172,12 +265,12 @@ static void test_sip(enum shader_type shader_type, struct drm_xe_engine_class_in
ibb = intel_bb_create_with_context(fd, exec_queue_id, vm_id, NULL, 4096);
igt_nsec_elapsed(&ts);
- handle = gpgpu_shader(fd, ibb, shader_type, threads, width, height);
+ handle = gpgpu_shader(fd, ibb, shader_type, sip_type, threads, width, height);
intel_bb_sync(ibb);
igt_assert_lt_u64(igt_nsec_elapsed(&ts), timeout);
- check_buf(fd, handle, width, height, COLOR_C4);
+ check_buf(fd, handle, width, height, shader_type, sip_type, COLOR_C4);
gem_close(fd, handle);
intel_bb_destroy(ibb);
@@ -205,17 +298,26 @@ igt_main
fd = drm_open_driver(DRIVER_XE);
test_render_and_compute("sanity", fd, eci)
- test_sip(SHADER_WRITE, eci, 0);
+ test_sip(SHADER_WRITE, SIP_NULL, eci, 0);
test_render_and_compute("sanity-after-timeout", fd, eci) {
- test_sip(SHADER_HANG, eci, 0);
+ test_sip(SHADER_HANG, SIP_NULL, eci, 0);
xe_for_each_engine(fd, eci)
if (eci->engine_class == DRM_XE_ENGINE_CLASS_RENDER ||
eci->engine_class == DRM_XE_ENGINE_CLASS_COMPUTE)
- test_sip(SHADER_WRITE, eci, 0);
+ test_sip(SHADER_WRITE, SIP_NULL, eci, 0);
}
+ test_render_and_compute("invalidinstr-disabled", fd, eci)
+ test_sip(SHADER_INV_INSTR_DISABLED, SIP_INV_INSTR, eci, 0);
+
+ test_render_and_compute("invalidinstr-thread-enabled", fd, eci)
+ test_sip(SHADER_INV_INSTR_THREAD_ENABLED, SIP_INV_INSTR, eci, 0);
+
+ test_render_and_compute("invalidinstr-walker-enabled", fd, eci)
+ test_sip(SHADER_INV_INSTR_WALKER_ENABLED, SIP_INV_INSTR, eci, 0);
+
igt_fixture
drm_close_driver(fd);
}
--
2.34.1
next prev parent reply other threads:[~2024-09-18 11:31 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-18 11:30 [PATCH i-g-t v7 00/16] Test coverage for GPU debug support Christoph Manszewski
2024-09-18 11:30 ` [PATCH i-g-t v7 01/16] lib/xe_ioctl: Add wrapper with vm_bind_op extension parameter Christoph Manszewski
2024-09-18 11:30 ` [PATCH i-g-t v7 02/16] lib/gpgpu_shader: Extend shader building library Christoph Manszewski
2024-09-18 11:30 ` [PATCH i-g-t v7 03/16] lib/gpgpu_shader: Add write_on_exception template Christoph Manszewski
2024-09-18 11:30 ` [PATCH i-g-t v7 04/16] lib/gpgpu_shader: Add set/clear exception register (cr0.1) helpers Christoph Manszewski
2024-09-18 11:30 ` [PATCH i-g-t v7 05/16] lib/intel_batchbuffer: Add helper to get pointer at specified offset Christoph Manszewski
2024-09-18 11:30 ` [PATCH i-g-t v7 06/16] lib/gpgpu_shader: Allow enabling illegal opcode exceptions in shader Christoph Manszewski
2024-09-18 11:30 ` [PATCH i-g-t v7 07/16] tests/xe_exec_sip: Add sanity-after-timeout test Christoph Manszewski
2024-09-18 11:30 ` Christoph Manszewski [this message]
2024-09-18 11:30 ` [PATCH i-g-t v7 09/16] drm-uapi/xe: Sync with eudebug uapi Christoph Manszewski
2024-09-25 19:23 ` Ville Syrjälä
2024-09-26 9:01 ` Manszewski, Christoph
2024-09-26 9:46 ` Ville Syrjälä
2024-09-26 10:28 ` Manszewski, Christoph
2024-09-18 11:30 ` [PATCH i-g-t v7 10/16] lib/xe_eudebug: Introduce eu debug testing framework Christoph Manszewski
2024-09-19 5:47 ` Zbigniew Kempczyński
2024-09-18 11:30 ` [PATCH i-g-t v7 11/16] scripts/test_list: Relax treatment of non-compiled tests Christoph Manszewski
2024-09-19 6:17 ` Zbigniew Kempczyński
2024-09-18 11:30 ` [PATCH i-g-t v7 12/16] tests/xe_eudebug: Test eudebug resource tracking and manipulation Christoph Manszewski
2024-09-19 6:37 ` Zbigniew Kempczyński
2024-09-18 11:30 ` [PATCH i-g-t v7 13/16] lib/intel_batchbuffer: Add support for long-running mode execution Christoph Manszewski
2024-09-18 11:30 ` [PATCH i-g-t v7 14/16] tests/xe_exec_sip_eudebug: Port tests for shaders and sip Christoph Manszewski
2024-09-18 11:30 ` [PATCH i-g-t v7 15/16] tests/xe_eudebug_online: Debug client which runs workloads on EU Christoph Manszewski
2024-09-19 6:52 ` Zbigniew Kempczyński
2024-09-18 11:30 ` [PATCH i-g-t v7 16/16] tests/xe_live_ktest: Add xe_eudebug live test Christoph Manszewski
2024-09-18 12:59 ` ✓ Fi.CI.BAT: success for Test coverage for GPU debug support (rev7) Patchwork
2024-09-18 13:31 ` ✓ CI.xeBAT: " Patchwork
2024-09-18 18:25 ` ✗ CI.xeFULL: failure " Patchwork
2024-09-19 3:24 ` ✗ Fi.CI.IGT: " Patchwork
2024-09-19 18:02 ` [PATCH i-g-t v7 00/16] Test coverage for GPU debug support Dixit, Ashutosh
2024-09-20 12:57 ` Manszewski, Christoph
2024-09-20 16:08 ` Dixit, Ashutosh
2024-09-23 7:57 ` Zbigniew Kempczyński
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=20240918113017.144687-9-christoph.manszewski@intel.com \
--to=christoph.manszewski@intel.com \
--cc=andrzej.hajda@intel.com \
--cc=dominik.grzegorzek@intel.com \
--cc=dominik.karol.piatkowski@intel.com \
--cc=gwan-gyeong.mun@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=jan.sokolowski@intel.com \
--cc=kamil.konieczny@linux.intel.com \
--cc=kolanupaka.naveena@intel.com \
--cc=maciej.patelczyk@intel.com \
--cc=mika.kuoppala@intel.com \
--cc=pawel.sikora@intel.com \
--cc=zbigniew.kempczynski@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