git: 2ba605f32ac3 - stable/14 - dtrace: fix fbt regression for aarch64

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 10 Oct 2023 13:42:23 UTC
The branch stable/14 has been updated by markj:

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

commit 2ba605f32ac3c673ef0f0bee810a2696f1887488
Author:     Igor Ostapenko <pm@igoro.pro>
AuthorDate: 2023-10-03 16:48:00 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-10-10 13:41:39 +0000

    dtrace: fix fbt regression for aarch64
    
    fbt computes incorrect instruction position for AArch64 kernel module symbol.
    
    The issue is with the for loop, it does an extra increment of instr pointer
    after the required instruction is found. Hence, a wrong instruction is
    targeted for patching.
    
    Signed-off-by:  Igor Ostapenko <pm@igoro.pro>
    
    Fixes:          980746e5cb26 ("fbt: simplify arm64 function-prologue parsing")
    Reviewed by:    markj
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/855
    MFC after:      1 week
    
    (cherry picked from commit b4db386f9fa7be9668aa09d14b0bbd048a7a7e89)
---
 sys/cddl/dev/fbt/aarch64/fbt_isa.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/sys/cddl/dev/fbt/aarch64/fbt_isa.c b/sys/cddl/dev/fbt/aarch64/fbt_isa.c
index 4094ea43a9fe..44690b97f77a 100644
--- a/sys/cddl/dev/fbt/aarch64/fbt_isa.c
+++ b/sys/cddl/dev/fbt/aarch64/fbt_isa.c
@@ -90,7 +90,6 @@ fbt_provide_module_function(linker_file_t lf, int symindx,
 	uint32_t *instr, *limit;
 	const char *name;
 	char *modname;
-	bool found;
 	int offs;
 
 	modname = opaque;
@@ -119,16 +118,16 @@ fbt_provide_module_function(linker_file_t lf, int symindx,
 	if ((*instr & BTI_MASK) == BTI_INSTR)
 		instr++;
 
-	/* Look for stp (pre-indexed) operation */
-	found = false;
 	/*
 	 * If the first instruction is a nop it's a specially marked
 	 * asm function. We only support a nop first as it's not a normal
 	 * part of the function prologue.
 	 */
 	if (*instr == NOP_INSTR)
-		found = true;
-	for (; !found && instr < limit; instr++) {
+		goto found;
+
+	/* Look for stp (pre-indexed) or sub operation */
+	for (; instr < limit; instr++) {
 		/*
 		 * Functions start with "stp xt1, xt2, [xn, <const>]!" or
 		 * "sub sp, sp, <const>".
@@ -142,14 +141,14 @@ fbt_provide_module_function(linker_file_t lf, int symindx,
 			 * past the function prologue.
 			 */
 			if (((*instr >> ADDR_SHIFT) & ADDR_MASK) == 31)
-				found = true;
+				break;
 		} else if ((*instr & SUB_MASK) == SUB_INSTR &&
 		    ((*instr >> SUB_RD_SHIFT) & SUB_R_MASK) == 31 &&
 		    ((*instr >> SUB_RN_SHIFT) & SUB_R_MASK) == 31)
-			found = true;
+			break;
 	}
-
-	if (!found)
+found:
+	if (instr >= limit)
 		return (0);
 
 	fbt = malloc(sizeof (fbt_probe_t), M_FBT, M_WAITOK | M_ZERO);