1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (C) 2021-2 ARM Limited.
3 // Original author: Mark Brown <broonie@kernel.org>
5 // Scalable Matrix Extension ZT context switch test
6 // Repeatedly writes unique test patterns into ZT0
7 // and reads them back to verify integrity.
9 #include <asm/unistd.h>
10 #include "assembler.h"
11 #include "asm-offsets.h"
17 #define ZT_B (ZT_SZ / 8)
19 // Declare some storage space to shadow ZT register contents and a
31 // Generate a test pattern for storage in ZT
35 // These values are used to construct a 32-bit pattern that is repeated in the
36 // scratch buffer as many times as will fit:
37 // bits 31:24 generation number (increments once per test_loop)
39 // bits 7: 0 32-bit lane index
43 bfi w3, w0, #8, #16 // PID
44 bfi w3, w1, #24, #8 // Generation
50 add w3, w3, #1 // Lane
57 // Set up test pattern in a ZT horizontal vector
63 bl pattern // Get pattern in scratch buffer
70 _ldr_zt 0 // load zt0 from pointer x0
75 // Trivial memory compare: compare x2 bytes starting at address x0 with
76 // bytes starting at address x1.
77 // Returns only if all bytes match; otherwise, the program is aborted.
82 stp x0, x1, [sp, #-0x20]!
94 1: ldr x2, [sp, #0x10]
95 ldp x0, x1, [sp], #0x20
101 // Verify that a ZT vector matches its shadow in memory, else abort
106 ldr x0, =scratch // Poison scratch
120 // Modify the live SME register state, signal return will undo our changes
121 function irritator_handler
122 // Increment the irritation signal count (x23):
123 ldr x0, [x2, #ucontext_regs + 8 * 23]
125 str x0, [x2, #ucontext_regs + 8 * 23]
127 // This will reset ZT to all bits 0
134 function tickle_handler
135 // Increment the signal count (x23):
136 ldr x0, [x2, #ucontext_regs + 8 * 23]
138 str x0, [x2, #ucontext_regs + 8 * 23]
143 function terminate_handler
147 puts "Terminated by signal "
150 puts ", no error, iterations="
151 ldr x0, [x20, #ucontext_regs + 8 * 22]
154 ldr x0, [x20, #ucontext_regs + 8 * 23]
167 str x30, [sp, #-((sa_sz + 15) / 16 * 16 + 16)]!
179 str w6, [x1, #sa_flags]
180 str x5, [x1, #sa_handler]
183 mov x8, #__NR_rt_sigaction
188 puts "sigaction failure\n"
191 1: ldr x30, [sp], #((sa_sz + 15) / 16 * 16 + 16)
195 // Main program entry point
200 mov x23, #0 // signal count
203 adr x1, terminate_handler
208 adr x1, terminate_handler
213 adr x1, irritator_handler
215 orr w2, w2, #SA_NODEFER
219 adr x1, tickle_handler
221 orr w2, w2, #SA_NODEFER
226 // Obtain our PID, to ensure test pattern uniqueness between processes
235 mov x22, #0 // generation number, increments per iteration
241 mov x8, #__NR_sched_yield // Encourage preemption
244 mrs x0, S3_3_C4_C2_2 // SVCR should have ZA=1,SM=0
251 add x22, x22, #1 // Everything still working
262 // fpsimd.c acitivty log dump hack
263 // ldr w0, =0xdeadc0de
264 // mov w8, #__NR_exit
268 mrs x13, S3_3_C4_C2_2
270 mov x10, x0 // expected data
271 mov x11, x1 // actual data
272 mov x12, x2 // data size
274 puts "Mismatch: PID="
295 // fpsimd.c acitivty log dump hack
296 // ldr w0, =0xdeadc0de
297 // mov w8, #__NR_exit
303 // mov x8, #__NR_exit