Skip to content

xtest: RISC-V vector context switching (regression 1046) - #827

Merged
jenswikl merged 4 commits into
OP-TEE:masterfrom
DavePatel-dev:rp022-m7-vec
Nov 27, 2026
Merged

jenswikl merged 4 commits into
OP-TEE:masterfrom
DavePatel-dev:rp022-m7-vec

Conversation

@DavePatel-dev

@DavePatel-dev DavePatel-dev commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Add xtest regression 1046, the RISC-V vector counterpart of the FP test
(regression 1045). Companion to OP-TEE/optee_os#7961.

Three commits: a shared helper header to observe the vector registers across
a call, the os_test TA support (TA_OS_TEST_CMD_RISCV_VEC_CONTEXT and its
sub-tests), and the regression 1046 host test.

Coverage

1046 has six subcases mirroring 1045: TA context across a syscall, a vector
CSR read, that a TA does not inherit another TA's registers, the normal-world
registers surviving a call using vector and one not using it, and the TA case
run concurrently from several threads.

The two normal-world subcases run only when the host xtest is built with the
vector extension; on a host toolchain without it they report themselves
skipped, exactly as 1045's normal-world subcases depend on host FP support.
The TA sub-tests, which exercise the OP-TEE vector context switch, run
whenever the TA is built with the vector extension.

Testing

Built and booted on QEMU virt (-cpu rv64,v=true,vlen=128, 2 harts, OpenSBI
with domain context switching) against OP-TEE/optee_os#7961: xtest 1046
passes (vlenb 16), the four TA/concurrent subcases run and the two
normal-world subcases skip because this host xtest is built without vector.

@DavePatel-dev

Copy link
Copy Markdown
Contributor Author

D/TA: TA_CreateEntryPoint:20 TA_CreateEntryPoint
D/TA: TA_OpenSessionEntryPoint:38 TA_OpenSessionEntryPoint
F/TC:? 0 trace_syscall:147 syscall #10 (syscall_unmask_cancellation)
I/TA: TA: Initialising Vector registers with test pattern...
I/TA: Dave TA: Before Context Switch
I/TA: Dave TA: GetSystemTime force a context switch...
F/TC:? 0 trace_syscall:147 syscall #13 (syscall_get_time)
I/TA: Dave TA: First Resumed. Verifying Vector register integrity...
I/TA: Dave TA: After First Context Switch
I/TA: Dave TA: Sleeping for 50ms to force a context switch...
F/TC:? 0 trace_syscall:147 syscall #13 (syscall_get_time)
I/TA: Dave TA: Second Resumed. Verifying Vector register integrity...
I/TA: Dave TA: After Second Context Switch
I/TA: Dave TA: SUCCESS! Vector context switch verified perfectly.

xtest output

@DavePatel-dev DavePatel-dev changed the title Adding Vector Context xtest xtest: RISC-V vector context switching (regression 1046) Sep 20, 2026
@jenswikl

Copy link
Copy Markdown
Contributor

Please rebase to resolve the conflicts.

@DavePatel-dev

Copy link
Copy Markdown
Contributor Author

Please rebase to resolve the conflicts.

ok will resolve it, thanks.

@DavePatel-dev

Copy link
Copy Markdown
Contributor Author

Rebased onto current master. The conflicts were the new ASAN test (regression 1042) landing next to the vector helpers and an os_test command-number clash: 1042 is kept as-is and TA_OS_TEST_CMD_RISCV_VEC_CONTEXT moved to 43 (ASAN took 38-42). The three vector commits are otherwise unchanged. Thanks!

Comment thread ta/os_test/include/riscv_vector_ctx.h Resolved
Comment thread ta/os_test/riscv_vector_ctx.S Resolved
Comment thread ta/os_test/riscv_vector_ctx.S Resolved
Comment thread ta/os_test/riscv_vector_ctx.S Resolved
Comment thread ta/os_test/riscv_vector_ctx_rv64.S Resolved
Comment thread ta/os_test/include/riscv_vector_ctx.h Resolved
Comment thread ta/os_test/include/riscv_vector_ctx.h Resolved
Comment thread ta/os_test/include/riscv_vector_ctx.h Resolved
Comment thread ta/os_test/include/riscv_vector_ctx.h Resolved
Comment thread ta/os_test/os_test.c Resolved
Comment thread host/xtest/regression_1000.c Resolved
Comment thread host/xtest/regression_1000.c Resolved
Comment thread ta/os_test/include/riscv_vector_ctx.h Resolved
Comment thread ta/os_test/riscv_vector_ctx_rv64.S Resolved
Comment thread host/xtest/regression_1000.c Resolved
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

This pull request has been marked as a stale pull request because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment, otherwise this pull request will automatically be closed in 5 days. Note that you can always re-open a closed pull request at any time.

@github-actions github-actions Bot added the Stale label Nov 9, 2026
@jenswikl

jenswikl commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Please rebase. Is this PR otherwise ready to be merged (once it's reviewed)?

@github-actions github-actions Bot removed the Stale label Nov 10, 2026
@DavePatel-dev

DavePatel-dev commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Please rebase. Is this PR otherwise ready to be merged (once it's reviewed)?

Hi @jenswikl thanks for heads up, this xtest is dependent on #7961 and hence we need to wait for the optee_os feature to be merged upstream.

@DavePatel-dev
DavePatel-dev force-pushed the rp022-m7-vec branch 2 times, most recently from 9c54195 to b63f036 Compare November 23, 2026 22:52
@DavePatel-dev

Copy link
Copy Markdown
Contributor Author

@jenswikl please can you trigger CI re-run looks like qemu crashed. Thanks

@jenswikl

Copy link
Copy Markdown
Contributor

Restarting the job.

@DavePatel-dev

DavePatel-dev commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @jenswikl please can this PR be reviewed and confirmed?

@jenswikl

Copy link
Copy Markdown
Contributor

I'd appreciate it if someone who knows riscv better than I would review this.
However, I don't see anything scary, so:
Acked-by: Jens Wiklander <jens.wiklander@oss.qualcomm.com>

@DavePatel-dev

Copy link
Copy Markdown
Contributor Author

@jenswikl, QEMU is failing, I have opened a PR to fix this issue and is at
#863.

This PR depend on the fix being upstream, so the CI run is successful.

Add riscv_vector_ctx.h, shared by the os_test TA and the xtest host, to
lay a known pattern into the vector registers, read it back, and diff it,
so a test can check the register file survives an excursion. The register
moves use the whole-register vs8r.v/vl8r.v forms with the vector ISA
enabled per block by .option arch, and the header compiles to nothing when
the build has no vector extension.

Signed-off-by: Dave Patel <dave.patel@riscstar.com>
Acked-by: Jens Wiklander <jens.wiklander@oss.qualcomm.com>
Add TA_OS_TEST_CMD_RISCV_VEC_CONTEXT and its sub-tests, handled by
ta_entry_riscv_vec_context(): install a vector pattern, cross a syscall, an
RPC or a crypto operation, and verify the registers came back, plus a
taint/check-taint pair to confirm a fresh TA does not inherit another's
registers. Returns TEE_ERROR_NOT_SUPPORTED when the TA was built without
the vector extension.

Signed-off-by: Dave Patel <dave.patel@riscstar.com>
Acked-by: Jens Wiklander <jens.wiklander@oss.qualcomm.com>
Add regression 1046, the vector counterpart of 1045. It drives the TA
sub-tests (context across a syscall, a vector CSR read, and that a TA does
not inherit another's registers), checks the normal-world registers survive
a call into the TEE when the host is built with the vector extension, and
runs the TA case from several threads at once. Sub-tests that need a
capability the build lacks report themselves skipped.

Signed-off-by: Dave Patel <dave.patel@riscstar.com>
Acked-by: Jens Wiklander <jens.wiklander@oss.qualcomm.com>
The regression 1046 vector helpers are guarded by __riscv_v, which the
compiler defines only when the TA is built with a V-enabled -march. The
OP-TEE core dev-kit used to force V onto every rv64 TA; it no longer
does, so without this the vector test code is compiled out and 1046 has
nothing to exercise on the TA side.

Opt the os_test TA in to V when the core supports vector context
switching (CFG_RISCV_ISA_V, exported by the dev-kit). The vector asm is
enabled per block with '.option arch', so the -march only serves to
define __riscv_v.

Signed-off-by: Dave Patel <dave.patel@riscstar.com>
Acked-by: Jens Wiklander <jens.wiklander@oss.qualcomm.com>
@DavePatel-dev

Copy link
Copy Markdown
Contributor Author

@jenswikl this PR is ready to merge.

@jenswikl
jenswikl merged commit 4f788e7 into OP-TEE:master Nov 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants