linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] LoongArch: Make bounds-checking instructions useful
@ 2023-04-16 17:33 WANG Xuerui
  2023-04-16 17:33 ` [PATCH 1/2] LoongArch: Add opcodes of bounds-checking instructions WANG Xuerui
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: WANG Xuerui @ 2023-04-16 17:33 UTC (permalink / raw)
  To: loongarch
  Cc: WANG Xuerui, Huacai Chen, Xi Ruoyao, Eric Biederman, Al Viro,
	Arnd Bergmann, linux-api, linux-arch, linux-kernel

From: WANG Xuerui <git@xen0n.name>

Hi,

The LoongArch-64 base architecture is capable of performing
bounds-checking either before memory accesses or alone, with specialized
instructions generating BCEs (bounds-checking error) in case of failed
assertions (ISA manual Volume 1, Sections 2.2.6.1 [1] and 2.2.10.3 [2]).
This could be useful for managed runtimes, but the exception is not
being handled so far, resulting in SIGSYSes in these cases, which is
incorrect and warrants a fix in itself.

During experimentation, it was discovered that there is already UAPI for
expressing such semantics: SIGSEGV with si_code=SEGV_BNDERR. This was
originally added for Intel MPX, and there is currently no user (!) after
the removal of MPX support a few years ago. Although the semantics is
not a 1:1 match to that of LoongArch, still it is better than
alternatives such as SIGTRAP or SIGBUS of BUS_OBJERR kind, due to being
able to convey both the value that failed assertion and the bound value.

This patch series implements just this approach: translating BCEs into
SIGSEGVs with si_code=SEGV_BNDERR, si_value set to the offending value,
and si_lower and si_upper set to resemble a range with both lower and
upper bound while in fact there is only one.

The instructions are not currently used anywhere yet in the fledgling
LoongArch ecosystem, so it's not very urgent and we could take the time
to figure out the best way forward (should SEGV_BNDERR turn out not
suitable).

[1]: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#bound-check-memory-access-instructions
[2]: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#_asrtlegt_d

WANG Xuerui (2):
  LoongArch: Add opcodes of bounds-checking instructions
  LoongArch: Relay BCE exceptions to userland as SIGSEGVs with
    si_code=SEGV_BNDERR

 arch/loongarch/include/asm/inst.h   |  26 +++++++
 arch/loongarch/include/asm/kdebug.h |   1 +
 arch/loongarch/kernel/genex.S       |   1 +
 arch/loongarch/kernel/traps.c       | 107 ++++++++++++++++++++++++++++
 4 files changed, 135 insertions(+)

-- 
2.40.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-04-22  8:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-16 17:33 [PATCH 0/2] LoongArch: Make bounds-checking instructions useful WANG Xuerui
2023-04-16 17:33 ` [PATCH 1/2] LoongArch: Add opcodes of bounds-checking instructions WANG Xuerui
2023-04-16 17:33 ` [PATCH 2/2] LoongArch: Relay BCE exceptions to userland as SIGSEGVs with si_code=SEGV_BNDERR WANG Xuerui
2023-04-16 17:57   ` WANG Xuerui
2023-04-17  6:47 ` [PATCH 0/2] LoongArch: Make bounds-checking instructions useful Xi Ruoyao
2023-04-17  7:54   ` WANG Xuerui
2023-04-17  9:50     ` Xi Ruoyao
2023-04-20  8:36       ` Huacai Chen
2023-04-20  9:38         ` WANG Xuerui
2023-04-22  8:39           ` Huacai Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).