git: 61a7ad35bb20 - stable/13 - Teach DTrace about BTI on arm64
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 22 Feb 2022 16:40:20 UTC
The branch stable/13 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=61a7ad35bb20b00755515e484583b92b07c1923d commit 61a7ad35bb20b00755515e484583b92b07c1923d Author: Andrew Turner <andrew@FreeBSD.org> AuthorDate: 2021-12-22 17:26:33 +0000 Commit: Andrew Turner <andrew@FreeBSD.org> CommitDate: 2022-02-22 16:23:07 +0000 Teach DTrace about BTI on arm64 The Branch Target Identification (BTI) Armv8-A extension adds new instructions that can be placed where we may indirrectly branch to, e.g. at the start of a function called via a function pointer. We can't emulate these in DTrace as the kernel will have raised a different exception before the DTrace handler has run. Skip over the BTI instruction if it's used as the first instruction in a function. Sponsored by: The FreeBSD Foundation (cherry picked from commit b5876847acfeae2dd3a655cde8cdf6145aed16d8) --- sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h | 3 +++ sys/cddl/dev/fbt/aarch64/fbt_isa.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h b/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h index f15a971f12be..c15cc39189b1 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h +++ b/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h @@ -2466,6 +2466,9 @@ extern void dtrace_helpers_destroy(proc_t *); #define B_DATA_MASK 0x00ffffff #define B_INSTR 0x14000000 +#define BTI_MASK 0xffffff3f +#define BTI_INSTR 0xd503241f + #define NOP_INSTR 0xd503201f #define RET_INSTR 0xd65f03c0 diff --git a/sys/cddl/dev/fbt/aarch64/fbt_isa.c b/sys/cddl/dev/fbt/aarch64/fbt_isa.c index d00aabf0cc81..07f02e2edb72 100644 --- a/sys/cddl/dev/fbt/aarch64/fbt_isa.c +++ b/sys/cddl/dev/fbt/aarch64/fbt_isa.c @@ -118,6 +118,14 @@ fbt_provide_module_function(linker_file_t lf, int symindx, instr = (uint32_t *)(symval->value); limit = (uint32_t *)(symval->value + symval->size); + /* + * Ignore any bti instruction at the start of the function + * we need to keep it there for any indirect branches calling + * the function on Armv8.5+ + */ + if ((*instr & BTI_MASK) == BTI_INSTR) + instr++; + /* Look for stp (pre-indexed) operation */ found = false; /*