RFR: 8310656: RISC-V: __builtin___clear_cache can fail silently.

Thomas Stuefe stuefe at openjdk.org
Wed Jun 28 05:36:03 UTC 2023


On Tue, 27 Jun 2023 08:19:47 GMT, Robbin Ehn <rehn at openjdk.org> wrote:

> Hi, please consider.
> 
> We recently had a bug where user were missing permissions to use this syscall.
> Which caused crashing on, according to hs_err on things like "addi x11, x24, 0" with SIGILL.
> If it fails it is even possible to execute valid but 'old' instruction which may not lead to a crash, instead the program misbehaves.
> 
> To avoid this mess I suggest that we first test the syscall during vm init and we use it directly.
> This way we can make sure it never fails.
> 
> Tested failing syscall with qemu, tested t1 in qemu, t1 on jh7110 in-progress.

Got curious. Looks good.

I was not even aware that __builtin___clear_cache had an errno. Is this documented somewhere? We should probably check arm64 too.

Question, would cacheflush(2) have worked too? Instead of the syscall?

src/hotspot/os_cpu/linux_riscv/riscv_flush_icache.cpp line 44:

> 42: 
> 43: #define assert_with_errno(cond, msg)    check_with_errno(assert, cond, msg)
> 44: #define guarantee_with_errno(cond, msg) check_with_errno(guarantee, cond, msg)

useful; potentially in debug.hpp?

-------------

Marked as reviewed by stuefe (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/14670#pullrequestreview-1502301176
PR Review Comment: https://git.openjdk.org/jdk/pull/14670#discussion_r1244698313


More information about the hotspot-dev mailing list