SSPUSH/SSAMOSWAP to non-shadow-stack pages write RW/RWX pages and page-fault on X/RX pages

Problem. "Should a shadow stack instruction access a page that is not designated as a shadow stack page and is not marked as read-only (pte.xwr=0b001), a store/AMO access-fault exception will be invoked." (priv cfi.adoc, norm:ssmp_ss_page_illegal_access; the note that follows names RW, RWX, RX and X pages). In S-mode, QEMU lets sspush and ssamoswap.d write RW (xwr = 011) and RWX (111) pages with no trap, and raises a store/AMO page fault (cause 15) on X (100) and RX (101) pages. QEMU work item #4379 covers SSPOPCHK on an RW page only; this report covers the SSPUSH/SSAMOSWAP cases and the X/RX pages.

Version. QEMU 11.1.1.

Reproduce. 04-qemu-ss-insn-non-ss-page.tar.gz tar xzf 04-qemu-ss-insn-non-ss-page.tar.gz && ./04-qemu-ss-insn-non-ss-page/run.sh Key command: the qemu-rv64-max command line with -d int -bios ss_non_ss_page.elf. The exit status is a mask of the 8 cases that did not raise cause 7 (sspush and ssamoswap.d on each of RW, RWX, X and RX).

Observed vs expected.

QEMU exit status 255   (0 = correct: all 8 cases raise cause 7)
    <<< no trap for the 4 RW/RWX cases (epc 0x800001e4, 0x80000214, 0x80000244, 0x80000274)
cause:000000000000000f, epc:0x800002a4, tval:0x00000001403027f8, desc=store_page_fault   <<< expected 7
cause:000000000000000f, epc:0x800002d4, tval:0x0000000140302800, desc=store_page_fault   <<< expected 7
cause:000000000000000f, epc:0x80000304, tval:0x00000001403037f8, desc=store_page_fault   <<< expected 7
cause:000000000000000f, epc:0x80000334, tval:0x0000000140303800, desc=store_page_fault   <<< expected 7
Sail:  store/amo-access-fault for all 8 cases

Source. target/riscv/tcg/cpu_helper.c, get_physical_address(): the leaf switch (rwx) special-cases only PTE_W (SS page) and PTE_R. Other encodings take the ordinary permission check, and an X/RX failure returns TRANSLATE_FAIL (page fault) because sstack_page is false.