From: Max Chou <max.chou@sifive.com>
To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org,
richard.henderson@linaro.org
Cc: Palmer Dabbelt <palmer@dabbelt.com>,
Alistair Francis <alistair.francis@wdc.com>,
Weiwei Li <liwei1518@gmail.com>,
Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>,
Liu Zhiwei <zhiwei_liu@linux.alibaba.com>,
Chao Liu <chao.liu@processmission.com>,
Max Chou <max.chou@sifive.com>
Subject: [PATCH 5/6] tests/tcg/riscv64: Add vector fault-only-first page probe test
Date: Wed, 9 Sep 2026 16:41:52 +0800 [thread overview]
Message-ID: <20260909084154.223529-6-max.chou@sifive.com> (raw)
In-Reply-To: <20260909084154.223529-1-max.chou@sifive.com>
Add a bare-metal test for vector fault-only-first loads whose
first-element probe crosses a page boundary. The test covers a body
access that crosses the boundary after the first element, and a first
element that itself straddles the boundary, checking that both cases
report a full vl and vstart of 0 rather than faulting on a mapped page.
Signed-off-by: Max Chou <max.chou@sifive.com>
---
tests/tcg/riscv64/Makefile.softmmu-target | 9 ++-
tests/tcg/riscv64/test-rvv-ldst-ff-page.S | 83 +++++++++++++++++++++++
2 files changed, 90 insertions(+), 2 deletions(-)
create mode 100644 tests/tcg/riscv64/test-rvv-ldst-ff-page.S
diff --git a/tests/tcg/riscv64/Makefile.softmmu-target b/tests/tcg/riscv64/Makefile.softmmu-target
index 9e0e0490753..93c4e58e0c2 100644
--- a/tests/tcg/riscv64/Makefile.softmmu-target
+++ b/tests/tcg/riscv64/Makefile.softmmu-target
@@ -86,14 +86,16 @@ run-test-vle32ff: test-vle32ff
test-vle32ff: CFLAGS += -march=rv64gcv
RVV_LDST_MARCH = -march=rv64gcv
-RVV_LDST_TESTS = test-rvv-ldst-ff-pmp test-rvv-ldst-us-pmp
+RVV_LDST_TESTS = test-rvv-ldst-ff-pmp test-rvv-ldst-us-pmp \
+ test-rvv-ldst-ff-page
CLEANFILES += $(RVV_LDST_TESTS)
$(RVV_LDST_TESTS): %: %.S rvv-ldst.inc $(LINK_SCRIPT)
$(CC) $(CFLAGS) $(RVV_LDST_MARCH) $< -Wa,--noexecstack -c -o $@.o
$(LD) $(LDFLAGS) $@.o -o $@
-EXTRA_RUNS += run-test-rvv-ldst-ff-pmp run-test-rvv-ldst-us-pmp
+EXTRA_RUNS += run-test-rvv-ldst-ff-pmp run-test-rvv-ldst-us-pmp \
+ run-test-rvv-ldst-ff-page
run-test-rvv-ldst-ff-pmp: test-rvv-ldst-ff-pmp
$(call run-test, $<, $(QEMU) -cpu rv64$(comma)v=true$(comma)vlen=128$(comma)elen=64$(comma)vext_spec=v1.0$(comma)rvv_ta_all_1s=true$(comma)rvv_ma_all_1s=true $(QEMU_OPTS)$<)
@@ -101,5 +103,8 @@ run-test-rvv-ldst-ff-pmp: test-rvv-ldst-ff-pmp
run-test-rvv-ldst-us-pmp: test-rvv-ldst-us-pmp
$(call run-test, $<, $(QEMU) -cpu rv64$(comma)v=true$(comma)vlen=128$(comma)elen=64$(comma)vext_spec=v1.0$(comma)rvv_ta_all_1s=true$(comma)rvv_ma_all_1s=true $(QEMU_OPTS)$<)
+run-test-rvv-ldst-ff-page: test-rvv-ldst-ff-page
+ $(call run-test, $<, $(QEMU) -cpu rv64$(comma)v=true$(comma)vlen=128$(comma)elen=64$(comma)vext_spec=v1.0 $(QEMU_OPTS)$<)
+
# We don't currently support the multiarch system tests
undefine MULTIARCH_TESTS
diff --git a/tests/tcg/riscv64/test-rvv-ldst-ff-page.S b/tests/tcg/riscv64/test-rvv-ldst-ff-page.S
new file mode 100644
index 00000000000..63b1e0ac8a8
--- /dev/null
+++ b/tests/tcg/riscv64/test-rvv-ldst-ff-page.S
@@ -0,0 +1,83 @@
+/*
+ * RISC-V vector fault-only-first probe page-crossing tests
+ *
+ * A first-element probe validates the mapping only for the bytes that
+ * the first (fault-only) element itself touches, then lets the
+ * remaining elements of the vector body fault normally. An
+ * implementation that instead probes the whole multi-element access
+ * range as one host operation aborts as soon as that range crosses a
+ * page boundary, even though every page involved is in fact mapped.
+ *
+ * Case 1 crosses the page boundary only in the vector body, after the
+ * first element. Case 2 crosses it inside the first element itself,
+ * so the first-element probe must span both pages it touches.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+ #include "rvv-ldst.inc"
+
+ .text
+ .global _start
+_start:
+ RVV_ENABLE
+ lla t0, trap_handler
+ csrw mtvec, t0
+
+ /*
+ * Case 1: the body crosses the page boundary; the first element does not.
+ */
+ CASE 1
+ li t0, 3
+ vsetvli t1, t0, e8, m1, tu, mu
+ lla a0, cross_segment
+ vlseg2e8ff.v v2, (a0)
+ csrr t0, vl
+ ASSERT_EQ t0, 3
+ csrr t0, vstart
+ ASSERT_EQ t0, 0
+ lla a0, output
+ vsseg2e8.v v2, (a0)
+ lbu t0, 5(a0)
+ ASSERT_EQ t0, 0x66
+
+ /*
+ * Case 2: the first segment element itself straddles the page boundary.
+ */
+ CASE 2
+ li t0, 3
+ vsetvli t1, t0, e8, m1, tu, mu
+ lla a0, straddle_segment
+ vlseg2e8ff.v v2, (a0)
+ csrr t0, vl
+ ASSERT_EQ t0, 3
+ csrr t0, vstart
+ ASSERT_EQ t0, 0
+ lla a0, output
+ vsseg2e8.v v2, (a0)
+ lbu t0, 5(a0)
+ ASSERT_EQ t0, 0xf6
+ li a0, 0
+exit:
+ SEMI_EXIT
+ FAIL
+
+ /*
+ * No trap is expected: a spurious fault from the page-crossing probe
+ * is the very thing under test. Report the case number rather than
+ * vectoring to the reset value of mtvec and hanging until the
+ * harness timeout.
+ */
+ .balign 4
+trap_handler:
+ j fail
+
+ .data
+ .balign 16
+semiargs: .space 16
+ .balign 4096
+ .space 4094
+cross_segment: .byte 0x11, 0x22, 0x33, 0x44, 0x55, 0x66
+output: .space 6
+ .balign 4096
+ .space 4095
+straddle_segment: .byte 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf6
--
2.43.0
next prev parent reply other threads:[~2026-09-09 8:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 8:41 [PATCH 0/6] tests/tcg/riscv64: Add system mode rvv ld/st tests Max Chou
2026-09-09 8:41 ` [PATCH 1/6] target/riscv: Match PMP entries lying inside the checked range Max Chou
2026-09-09 8:41 ` [PATCH 2/6] target/riscv: rvv: Probe unit-stride accesses by the first element Max Chou
2026-09-09 8:41 ` [PATCH 3/6] tests/tcg/riscv64: Add vector masked fault-only-first PMP test Max Chou
2026-09-11 5:49 ` Chao Liu
2026-09-09 8:41 ` [PATCH 4/6] tests/tcg/riscv64: Add vector unit-stride " Max Chou
2026-09-09 8:41 ` Max Chou [this message]
2026-09-09 8:41 ` [PATCH 6/6] tests/tcg/riscv64: Add vector segment PMP region spanning test Max Chou
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=20260909084154.223529-6-max.chou@sifive.com \
--to=max.chou@sifive.com \
--cc=alistair.francis@wdc.com \
--cc=chao.liu@processmission.com \
--cc=daniel.barboza@oss.qualcomm.com \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=zhiwei_liu@linux.alibaba.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.