The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: xur@google.com
To: Josh Poimboeuf <jpoimboe@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>, Rong Xu <xur@google.com>
Cc: linux-kernel@vger.kernel.org,
	Sriraman Tallam <tmsriram@google.com>,
	 Han Shen <shenhan@google.com>,
	Krzysztof Pszeniczny <kpszeniczny@google.com>
Subject: [PATCH v2 2/2] objtool: dead_end function change for split functions
Date: Mon,  3 Nov 2025 21:52:44 +0000	[thread overview]
Message-ID: <20251103215244.2080638-2-xur@google.com> (raw)
In-Reply-To: <20251103215244.2080638-1-xur@google.com>

From: Rong Xu <xur@google.com>

Function Splitting can potentially move all return instructions
into the cold (infrequently executed) section of the function.
If this happens, the original function might be incorrectly
flagged as a dead-end function.

The consequence is an incomplete ORC table, which leads to an unwind
error, and subsequently, a livepatch failure.

This patch adds the support of the dead_end_function check for
split function.

Signed-off-by: Rong Xu <xur@google.com>
Reviewed-by: Sriraman Tallam <tmsriram@google.com>
Reviewed-by: Han Shen <shenhan@google.com>
Reviewed-by: Krzysztof Pszeniczny <kpszeniczny@google.com>

ChangeLOG:
 v2: Coding style changes suggested by Peter Zijlstra.
---
 tools/objtool/check.c | 91 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 72 insertions(+), 19 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index c2ee3c3a84a62..4864d54cdd79e 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -237,6 +237,76 @@ static bool is_rust_noreturn(const struct symbol *func)
 		str_ends_with(func->name, "_fail"));
 }
 
+static bool __dead_end_function(struct objtool_file *, struct symbol *, int);
+
+/*
+ * Check if the target of a sibling_call instruction is a dead_end function.
+ * Note insn must be a sibling call.
+ */
+static inline bool __dead_end_sibling_call(struct objtool_file *file,
+					   struct instruction *insn,
+					   int recursion) {
+	struct instruction *dest = insn->jump_dest;
+
+	if (!dest) {
+		/* sibling call to another file */
+		return false;
+	}
+
+	/* local sibling call */
+	if (recursion == 5) {
+		/*
+		 * Infinite recursion: two functions have
+		 * sibling calls to each other.  This is a very
+		 * rare case.  It means they aren't dead ends.
+		 */
+		return false;
+	}
+
+	return __dead_end_function(file, insn_func(dest), recursion+1);
+}
+
+/*
+ * Handling split functions. Mimic the workflow in __dead_end_function.
+ */
+static bool __dead_end_split_func(struct objtool_file *file,
+				  struct symbol *func, int recursion)
+{
+	char section_name[256];
+	struct section *sec;
+	struct instruction *insn;
+	int n;
+
+	/*
+	 * Use a fixed-size buffer (max 256) to avoid malloc. If the section
+	 * length exceeds this limit, we return a conservative value. This is
+	 * a safe fallback and does not compromise functional correctness.
+	 */
+	n = sizeof(section_name);
+	if (snprintf(section_name, n, ".text.split.%s", func->name) >= n) {
+		fprintf(stderr, "Error: Function name '%s' too long.\n", func->name);
+		return false;
+	}
+
+	sec = find_section_by_name(file->elf, section_name);
+	if (!sec)
+		return false;
+
+	sec_for_each_insn(file, sec, insn) {
+		if (insn->type == INSN_RETURN)
+			return false;
+	}
+
+	sec_for_each_insn(file, sec, insn) {
+		if (is_sibling_call(insn)) {
+			if (!__dead_end_sibling_call(file, insn, recursion))
+				return false;
+		}
+	}
+
+	return true;
+}
+
 /*
  * This checks to see if the given function is a "noreturn" function.
  *
@@ -298,33 +368,16 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
 	 */
 	func_for_each_insn(file, func, insn) {
 		if (is_sibling_call(insn)) {
-			struct instruction *dest = insn->jump_dest;
-
-			if (!dest)
-				/* sibling call to another file */
-				return false;
-
-			/* local sibling call */
-			if (recursion == 5) {
-				/*
-				 * Infinite recursion: two functions have
-				 * sibling calls to each other.  This is a very
-				 * rare case.  It means they aren't dead ends.
-				 */
-				return false;
-			}
-
 			/*
 			 * A function can have multiple sibling calls. All of
 			 * them need to be dead ends for the function to be a
 			 * dead end too.
 			 */
-			if (!__dead_end_function(file, insn_func(dest), recursion+1))
+			if (!__dead_end_sibling_call(file, insn, recursion))
 				return false;
 		}
 	}
-
-	return true;
+	return __dead_end_split_func(file, func, recursion);
 }
 
 static bool dead_end_function(struct objtool_file *file, struct symbol *func)
-- 
2.51.2.997.g839fc31de9-goog


  reply	other threads:[~2025-11-03 21:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-03 21:52 [PATCH v2 1/2] objtool: fix the check for dead_end function with multiple sibliing calls xur
2025-11-03 21:52 ` xur [this message]
2025-11-17 18:54   ` [PATCH v2 2/2] objtool: dead_end function change for split functions Rong Xu
2025-11-17 21:43   ` Josh Poimboeuf
2025-11-17 21:50     ` Josh Poimboeuf
2025-11-17 22:57       ` Rong Xu
2025-11-17 23:23         ` Josh Poimboeuf
2025-11-18 23:29 ` [PATCH v2 1/2] objtool: fix the check for dead_end function with multiple sibliing calls Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251103215244.2080638-2-xur@google.com \
    --to=xur@google.com \
    --cc=jpoimboe@kernel.org \
    --cc=kpszeniczny@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=shenhan@google.com \
    --cc=tmsriram@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox