The branch main has been updated by andrew:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=b5876847acfeae2dd3a655cde8cdf6145aed16d8

commit b5876847acfeae2dd3a655cde8cdf6145aed16d8
Author:     Andrew Turner <[email protected]>
AuthorDate: 2021-12-22 17:26:33 +0000
Commit:     Andrew Turner <[email protected]>
CommitDate: 2022-01-19 12:07:35 +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
---
 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;
        /*

Reply via email to