From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4394A3563E8; Thu, 23 Apr 2026 04:04:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917064; cv=none; b=tVoPmm8w7gTzhuh5w7nSdjh/2H1N9DTFMsTXnxETM85v1XyvRIiGFGbiMZTAHnk7T3LaeeWI/kPhSkB+49R5f5FN1SipY+gQGQCjB54cLtr5pbrjdNZWk5cVRcUVKcfCwyOH1wIhkr4EgmQ2uEVRmNSK2kastJLxQwUmU7vKBvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917064; c=relaxed/simple; bh=CRPOSrWb90t9017QEk/rI+Ud/vacLDUdl92sc+smDow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VM4TXj2mjRiGTBPdTHxPzYAHr5yod8ORpE6LyrrvCC2DWPoVUYnonPylOq+4dasmM2VwXw1IG/fkgxFZw1XiP8OIhRx883rNhwOgIXaLuKB26aUaKLZgqWZHnBlha/BxVowmCH+ANFAejSC8VZ0IR9gh1zVYNGmfh274o6RDxKk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KOJpFITE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KOJpFITE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7C6DC2BCB6; Thu, 23 Apr 2026 04:04:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917064; bh=CRPOSrWb90t9017QEk/rI+Ud/vacLDUdl92sc+smDow=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KOJpFITEx+22jPK0Q6qFGsyxJks6JqIr7Uw2sL/XzxnakRE05XXt1qWPihgg9miZL LMBXuk2r+EAmYACPa7RfVDYfbAh83CJXc5Zwd7iecbIv2RUVNHzCRu1mh7U/SoOpeo yB7QLMPP8XgvCoMBiNgXxjOhqhY+CakoNIyAa2ZFHNHPAC7MZ2axw0k/xX4XBwLnur WBCm2LnJvSAP5VbNYc687vRD9Necr0Clu9c9RN69U8IH9oWY0Ibxvt6gL8806f6NiP dEOhxemJJywKSCj73EBuWTXd8BFRqR10rlDWLZ3J1pIaKXa3mokb+3FHpaw2kVBh/Q JjgCSx+8sKaaQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 01/48] objtool/klp: Fix is_uncorrelated_static_local() for Clang Date: Wed, 22 Apr 2026 21:03:29 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Joe Lawrence For naming function-local static locals, GCC uses ., e.g. __already_done.15, while Clang uses . with optional ., e.g. create_worker.__already_done.111 The existing is_uncorrelated_static_local() check only matches the GCC convention where the variable name is a prefix. Handle both cases by checking for a prefix match (GCC) and by checking after the first dot separator (Clang). Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffin= g object files") Signed-off-by: Joe Lawrence Signed-off-by: Josh Poimboeuf Acked-by: Song Liu Reviewed-by: Miroslav Benes --- tools/objtool/klp-diff.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 0b0d1503851f..b1b068e9b4c7 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -242,16 +242,17 @@ static struct symbol *next_file_symbol(struct elf *el= f, struct symbol *sym) static bool is_uncorrelated_static_local(struct symbol *sym) { static const char * const vars[] =3D { - "__already_done.", - "__func__.", - "__key.", - "__warned.", - "_entry.", - "_entry_ptr.", - "_rs.", - "descriptor.", - "CSWTCH.", + "__already_done", + "__func__", + "__key", + "__warned", + "_entry", + "_entry_ptr", + "_rs", + "descriptor", + "CSWTCH", }; + const char *dot; =20 if (!is_object_sym(sym) || !is_local_sym(sym)) return false; @@ -259,8 +260,20 @@ static bool is_uncorrelated_static_local(struct symbol= *sym) if (!strcmp(sym->sec->name, ".data.once")) return true; =20 + dot =3D strchr(sym->name, '.'); + if (!dot) + return false; + for (int i =3D 0; i < ARRAY_SIZE(vars); i++) { - if (strstarts(sym->name, vars[i])) + size_t len =3D strlen(vars[i]); + + /* GCC: . */ + if (strstarts(sym->name, vars[i]) && (sym->name[len] =3D=3D '.')) + return true; + + /* Clang: .[.] */ + if (strstarts(dot + 1, vars[i]) && + (dot[1 + len] =3D=3D '.' || dot[1 + len] =3D=3D '\0')) return true; } =20 --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A397932ED24; Thu, 23 Apr 2026 04:04:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917064; cv=none; b=HPgAjMbvJc5twfOZA8nOdJa/AgixcwsKXurltL5Cw3Ri9ez/Om1g+bUNKtUnjwbZgRk7ZIe/MYeiPcUh/FwklLCzxEFCiYZ+VUD3JZvPFa1nxzI3VaRfpZqSqgZGUmmDB0GG8y3+Y83cwZc0ILYgczvDcG/nSHaZ/gXThNkhzMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917064; c=relaxed/simple; bh=m63KetNM8hjihetR3hWKARSwXrlz8FMc6/yAkKODq4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h3iIBQZDgzMCNXGrgHMttWD2rkyvTeHg9dnr0jrbjDmYGdChnP24sov0khbTDv5kFRx9UQvj/C6iUI8Ayz2DwKTmrnFNxTEQyvuz/Mjk5ftpj/bmqaw7LESfSiLdoQXETlouvStyE+PKk/Pz36SE8aOxVIoQq10iiXOCNMWBAgY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cthaEmPR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cthaEmPR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38D2FC2BCB7; Thu, 23 Apr 2026 04:04:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917064; bh=m63KetNM8hjihetR3hWKARSwXrlz8FMc6/yAkKODq4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cthaEmPR59tv0x35YlMswmRUajeUCH/x2qQ9kOU63AJLsjCm5/7kA8rYVCWR8jZiI 3lh9+bEkSzNGAVRHo/ucOfg9Qb7JQY8Y0cn/7vV3fk/jUYm81brakJbHnTHIbP5o9s DAx5mfIA6/3m48Bht9DS9WTIYtzmINDnomcvsZP8KfG8XHdhs0qq0OpFPSur+KnOJP kf1dpZ4g8PKOIcOY07FRXA8BlprdZm7oHdfTTaQ0fcj4qbYzI2G06hFl3ZKtV3m9bH NNp6pfQPYXP2I2v8X0zDELifwKP9pdbIhDgCnpSh03DrC/GwYjLuoZ1FnWSpujMmPM n0DbyUOBxpwag== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 02/48] objtool/klp: Fix .data..once static local non-correlation Date: Wed, 22 Apr 2026 21:03:30 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" While there was once a section named .data.once, it has since been renamed to .data..once with commit dbefa1f31a91 ("Rename .data.once to .data..once to fix resetting WARN*_ONCE"). Fix it. Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffin= g object files") Signed-off-by: Josh Poimboeuf Acked-by: Song Liu Reviewed-by: Miroslav Benes --- tools/objtool/klp-diff.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index b1b068e9b4c7..cb26c1c92a74 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -257,7 +257,8 @@ static bool is_uncorrelated_static_local(struct symbol = *sym) if (!is_object_sym(sym) || !is_local_sym(sym)) return false; =20 - if (!strcmp(sym->sec->name, ".data.once")) + /* WARN_ONCE, etc */ + if (!strcmp(sym->sec->name, ".data..once")) return true; =20 dot =3D strchr(sym->name, '.'); --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55F293CAE88; Thu, 23 Apr 2026 04:04:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917065; cv=none; b=Fl9gsNwbJ0jPS8/vadvD1OI5JbBVtkcUE9Q+Vb3iiSNqmR341QudbTWoeiKCtAYOAm74/nRPDJKZGOk83n6uUFP811KnrA2I/6Ztqy2LD1DULWawtahLvEIdVwlEsA43N/nTlNseMmN8P5bRJUGQwh8fcOa7kAQ+9RIYOfqqZmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917065; c=relaxed/simple; bh=v1/YJzbW78of1CWH8JzZKZQJi1ocZAKbzDcRsWSyYUc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F8+7BIKkkKvxgSefLgwe5W8eZAuaNv0RucPWNKBMxW1FZFl3MghHKezZMsxzYBs0SyQcJuGIzDHLotYXc+HbUP5/ntcxVbysG34/ktbFwfTybfc0Nf6uP1nb/6T1WMWhXv+fRL62UDelVBuJyFOcMsZjcr2zZT4Rf+YXHrx4A+c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bd/UpBJR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bd/UpBJR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB049C2BCB4; Thu, 23 Apr 2026 04:04:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917065; bh=v1/YJzbW78of1CWH8JzZKZQJi1ocZAKbzDcRsWSyYUc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bd/UpBJRcj60h8ndcdZ3gMivL5+djsGqFUhrx2KqjFAaR26m7RCUtBqRAnAYj+piQ 9c6p/EKw/dfEyYvq0IbT88w24h7ZRVt3Sm3pza8+1uTD8u09RM4jrKkhcAKnEmrUlD KS2WTe+jRxN9RjAtIF8V8svK0xTQNqwy/6eN3q+5lWyWYuSm7kKTcuPQfpbeOiZCr0 3zK5CzoXPjMun1eSKB2OKHdgXm02lVyQfwz5FY6Ou7/3WTRlPSG0abqsnjZD9EK3c7 zmFxKiw5WbqFLQyuTTQ4yxtsdWPximFqrpV9hWq8O7vl/l2EIhKelzhXK71DBZv/Ur K3ffavY3K/gPA== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 03/48] objtool/klp: Don't correlate __ADDRESSABLE() symbols Date: Wed, 22 Apr 2026 21:03:31 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Symbols created by __ADDRESSABLE() are only used to convince the toolchain not to optimize out the referenced symbol. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes --- tools/objtool/klp-diff.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index cb26c1c92a74..36753eeba58c 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -352,6 +352,15 @@ static bool is_special_section_aux(struct section *sec) return false; } =20 +/* + * Symbols created by ___ADDRESSABLE() are only used to convince the toolc= hain + * not to optimize out the referenced symbol. + */ +static bool is_addressable_sym(struct symbol *sym) +{ + return !strcmp(sym->sec->name, ".discard.addressable"); +} + /* * These symbols should never be correlated, so their local patched versio= ns * are used instead of linking to the originals. @@ -365,6 +374,7 @@ static bool dont_correlate(struct symbol *sym) is_uncorrelated_static_local(sym) || is_clang_tmp_label(sym) || is_string_sec(sym->sec) || + is_addressable_sym(sym) || is_special_section(sym->sec) || is_special_section_aux(sym->sec) || strstarts(sym->name, "__initcall__"); --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDF5B3CCFC8; Thu, 23 Apr 2026 04:04:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917065; cv=none; b=vBLiZeiYJZAFnIiHpAqulbB+VMUxrKgGVcKsTnKHrQlfVwB1gJNFiz6M1xD1AhB87afdB7Mn/h5Jgq/h3ABai/ZTTCC1GJvOfbpnnH0EkT+jHgEBS40Q5FOS6y3E07gkxEc8au64s80ViPS8kRbqJwF9OV1nZtF7MvZPjS+WD/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917065; c=relaxed/simple; bh=cyERcQW1CXamUSzBO/tZKHzPR2DszRUAPYcixAswNfM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mgZ72xYeloO0EJYSucd4EfA4wiiK30D2C49LpyG6AVKcH29FD35nkZ1TdXqrI1rdnRM6IXJbwELZ1exTg7fEOyKtQE3dOx07u/Alp7F6h29+zdXp3KeCiftMcyx8dQYDtwSVc9z9JptwkQ9E1EaOlnHWSAB7dyYRm43ET9HEwuA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=huIztDtu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="huIztDtu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C354C2BCB6; Thu, 23 Apr 2026 04:04:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917065; bh=cyERcQW1CXamUSzBO/tZKHzPR2DszRUAPYcixAswNfM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=huIztDtuAgkDcSUuO04FF1F0vDM2AEATe9A4j5P9HhRL5Z9FIMQdWcedoudB5hHHE uBMTr0hpINH7OmhdN//sKqABUAiTTa3qZrn2grLsk4Kt0dEIJOr1IKZg1njVpUUhWb CQd/1pYHrGTzorixy4AtcL5uog1ZWfxrtrWZ1rUdMi52zOEw55wFq2aPhhTUuPEIQX FLeYlH67sBpMDMN+qSIiwGKkg8GUPnzIwdog53PRa/i2qHh5kNBQ4NSExuPWWpPvE2 Qes9Y+F39/jkWh7d8X7ZUxMQCDZOV+JqSKdXSQlXhxYTbGXIQvCzsEfuL1TJJGO/zf i6r065urYF1Mg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 04/48] objtool/klp: Ignore __UNIQUE_ID_*() PCI stub functions Date: Wed, 22 Apr 2026 21:03:32 -0700 Message-ID: <93c7c80130375edd22874a57cdea132b0edbb0e4.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With Clang LTO enabled, DECLARE_PCI_FIXUP_SECTION() uses __UNIQUE_ID() to generate uniquely named wrapper functions, which are being reported as new functions and unnecessarily included in the patch module: vmlinux.o: new function: __UNIQUE_ID_quirk_f0_vpd_link_661 These stub functions only exist to make the compiler happy. Just ignore them along with any other dont_correlate() symbols. Note that dont_correlate() already includes prefix functions. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu Reviewed-by: Miroslav Benes --- tools/objtool/klp-diff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 36753eeba58c..ea9ccf8c4ea9 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -786,7 +786,7 @@ static int mark_changed_functions(struct elfs *e) =20 /* Find changed functions */ for_each_sym(e->orig, sym_orig) { - if (!is_func_sym(sym_orig) || is_prefix_func(sym_orig)) + if (!is_func_sym(sym_orig) || dont_correlate(sym_orig)) continue; =20 patched_sym =3D sym_orig->twin; @@ -802,7 +802,7 @@ static int mark_changed_functions(struct elfs *e) =20 /* Find added functions and print them */ for_each_sym(e->patched, patched_sym) { - if (!is_func_sym(patched_sym) || is_prefix_func(patched_sym)) + if (!is_func_sym(patched_sym) || dont_correlate(patched_sym)) continue; =20 if (!patched_sym->twin) { --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6ABF73CE493; Thu, 23 Apr 2026 04:04:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917066; cv=none; b=en13oUU/BGzG8AnVOdes1TPyR9+w+wk4nwSdQOaGo4hJ93R12OLD5ZTXSrt5YV5LayBstGSMUCDRN6rp9dZC2Qgbi8D9VjclAu2+oNxZVA0/2wOXmYrRFN+c0bLOG2tTJEKI49jbno8LY4OugBVzkTWzaD13hobpXhAeHOznhkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917066; c=relaxed/simple; bh=ugHeCutv5a7BLLAyhgSmNXWzhfKrZRVBZiPfR6m9uQg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MVYnv00y/jsZBzRMQyMZGL1aeFP7rwR/40FZoLQYHNkr5Zf9D6HO56s0DWg9AQuq/SRt3Hr5NlMdFw2/Vgf+QRaJA4JToBQ0pDWYTCJnW9km9SsGUlDJtjCE4gD1jxfmHp0zEfC9SMwiFjJzQqUGtegCeUjZXLrqeKmoxM0iYEw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HGGXrATR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HGGXrATR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7948C2BCB5; Thu, 23 Apr 2026 04:04:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917066; bh=ugHeCutv5a7BLLAyhgSmNXWzhfKrZRVBZiPfR6m9uQg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HGGXrATRJK551pU1DVlQhCmfzQEuln84NTfxhxnOl/UvTIjJTTxsvkmBw43oIazrl PDVMEAX9gOk0v/1AVGfvFUkmSgKEo70IVCoRK/60gbOx3vLMrJ93c5myeRWJk3k/u5 xx8WVwlCMN0zkvnBw3xOtbQOwbYaU1x8JioWh0NVRTHl912mGEs6pJpUqodKMEeiHq nyDXprCadM46yb1BIwSmE7Esbi39Q27MPXNfK+rn3ibkOnOHJEL4BpMnoOzIBEluVb gwxFfGuciLL9ig9WO4dJkP6qRdJENKpEKsFrIoU26sC+giePFfW/u375LqfzO3gRz5 uQwieM5bZaeFA== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 05/48] objtool: Move mark_rodata() to elf.c Date: Wed, 22 Apr 2026 21:03:33 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the sec->rodata marking from check.c to elf.c so it's set during ELF reading rather than during the check pipeline. This makes the rodata flag available to all objtool users, including klp-diff which reads ELF files directly without running check(). Add an is_rodata_sec() helper to elf.h for consistency with is_text_sec() and is_string_sec(). Signed-off-by: Josh Poimboeuf Acked-by: Peter Zijlstra (Intel) Acked-by: Song Liu Reviewed-by: Miroslav Benes --- tools/objtool/check.c | 11 +++-------- tools/objtool/elf.c | 13 +++++++++++++ tools/objtool/include/objtool/elf.h | 5 +++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 9b11cf3193b9..5722d4568401 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2566,7 +2566,6 @@ static int classify_symbols(struct objtool_file *file) static void mark_rodata(struct objtool_file *file) { struct section *sec; - bool found =3D false; =20 /* * Search for the following rodata sections, each of which can @@ -2579,15 +2578,11 @@ static void mark_rodata(struct objtool_file *file) * .rodata.str1.* sections are ignored; they don't contain jump tables. */ for_each_sec(file->elf, sec) { - if ((!strncmp(sec->name, ".rodata", 7) && - !strstr(sec->name, ".str1.")) || - !strncmp(sec->name, ".data.rel.ro", 12)) { - sec->rodata =3D true; - found =3D true; + if (is_rodata_sec(sec)) { + file->rodata =3D true; + return; } } - - file->rodata =3D found; } =20 static void mark_holes(struct objtool_file *file) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index f3df2bde119f..ac9da81a7a2f 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -1172,6 +1172,17 @@ static int read_relocs(struct elf *elf) return 0; } =20 +static void mark_rodata(struct elf *elf) +{ + struct section *sec; + + for_each_sec(elf, sec) { + if ((strstarts(sec->name, ".rodata") && !strstr(sec->name, ".str1.")) || + strstarts(sec->name, ".data.rel.ro")) + sec->rodata =3D true; + } +} + struct elf *elf_open_read(const char *name, int flags) { struct elf *elf; @@ -1222,6 +1233,8 @@ struct elf *elf_open_read(const char *name, int flags) if (read_sections(elf)) goto err; =20 + mark_rodata(elf); + if (read_symbols(elf)) goto err; =20 diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 25573e5af76e..c61bd57767f9 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -296,6 +296,11 @@ static inline bool is_text_sec(struct section *sec) return sec->sh.sh_flags & SHF_EXECINSTR; } =20 +static inline bool is_rodata_sec(struct section *sec) +{ + return sec->rodata; +} + static inline bool sec_changed(struct section *sec) { return sec->_changed; --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFB1A3CEBB7; Thu, 23 Apr 2026 04:04:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917066; cv=none; b=BphGAbYzAnCk6bU0llcgXr1hB4+/f0JzSwGgxw7E22M86B7uNvHa+W9QphfuxqIr8QzWYuH6kg6a9zSWlJl6fsZNkdeUABK/bAYQCZKb//P5C7Wffq0NIoYTuBnky+uaxm3GaVnTs92Xfpwc6BoYZAYR+gvZ0n/9ISQK6GusKJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917066; c=relaxed/simple; bh=HnzSw9B7ABZdAUJ8CrWgBNLplWHA42vKKzWDFcZRmYM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jtyh0BRCxaKTM7aRadEzw8GZ0B4GFMIVmnsxYr3iKUrzbZ5eNO275c4LiwMaL66VZt/VKp5rjIrmh3wBVjF/Llvulh445P5TMjK7HPdpPk8+6cEdmXgruILn2PzaTvWq6xT0pROQ/z7LNu7yxazQe66oSjMEBQPdcAp4xfXPEQM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UPM9KZp7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UPM9KZp7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5670BC2BCB2; Thu, 23 Apr 2026 04:04:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917066; bh=HnzSw9B7ABZdAUJ8CrWgBNLplWHA42vKKzWDFcZRmYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UPM9KZp7chTUZFxT/grSTDssHWGe5slGOBvpd86CGtsY/b+qHpfKMxidoTmQ5C4JI AR1CIoOqqc5+A367vVAYOHqaK8XcCv/dMzSnaAZeZmmfVON1jHHN4H6mRU5sz88ZzH pb/tM4myygYmuSr/77fkyjcHlDEO6PQbbqGryvRkpWJEFXN9JFr6uh3JYkA13cgs/I OruSSTv/lkG0O+xkxK8rYZIDKKI7tZOan6qH75qnX1FIShAEN1b6Z1U6cR6jINIY6G ZFeDTrkPXADvCkrIWBXd1epx3QcsqDUA1uFXhRTJECiS/8htVUbUfQJBIBn5xcv+Cn DG+nQwHsOl0Pw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 06/48] objtool/klp: Don't correlate rodata symbols Date: Wed, 22 Apr 2026 21:03:34 -0700 Message-ID: <602e405888ab38cd08de4375060b56db0965651d.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Some crypto assembly codes define the same local rodata labels (e.g., K256) which get duplicated when multiple .S files are linked into the same composite object, triggering "Multiple correlation candidates" errors. Correlating rodata is tricky anyway, and not all rodata is associated with a symbol. So just don't correlate any rodata, so that any referenced data will get duplicated in the livepatch module. Signed-off-by: Josh Poimboeuf --- tools/objtool/klp-diff.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index ea9ccf8c4ea9..f6597015b33b 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -374,6 +374,7 @@ static bool dont_correlate(struct symbol *sym) is_uncorrelated_static_local(sym) || is_clang_tmp_label(sym) || is_string_sec(sym->sec) || + is_rodata_sec(sym->sec) || is_addressable_sym(sym) || is_special_section(sym->sec) || is_special_section_aux(sym->sec) || --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F59733C50D; Thu, 23 Apr 2026 04:04:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917067; cv=none; b=MCGNAra1bq5SPJxzq5HiH4fpda1FUoESePxdFi6CW+QAZKoOUUoaWVe+Sxww53snBT53U8T9yT6CuCsqzKBk/Pl2kuJ1rATrFcS/qSknAZMY4XYbHaR+i6SSfvzguyGywqqDK4JiGFgkg5M0ZSo6HWmejUVaIyaBTy3OWE3MRnI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917067; c=relaxed/simple; bh=gJ1+DoSFGtvcVD+smd+XFxno5et035NmMg4Kg1wvN8w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Mn//oD/dYsj0yKzweZIPtXu5QhU8DbJsACk9tOAaA/bXS9Uhjse23HrbKB9kEyox7M5mxKqwhYxxfM42YckDY8V5VDnpJdtTVPD3C7p0xin2Pun5DSJKKEuqZaybMWBtWa0c6k76K2TpYopgbGZoU9jZNd9Kb35cGh/MxF4wtsc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wabissop; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Wabissop" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C976CC2BCB4; Thu, 23 Apr 2026 04:04:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917067; bh=gJ1+DoSFGtvcVD+smd+XFxno5et035NmMg4Kg1wvN8w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wabissop1FapQwrgMoLvrQdVncN/GeQhBXpsfuatWX/8fDWMosxt/XzL77JCpv8Sm uJ6vG16dCJGUs1kkP8QgIwq/KwpfWr8qBJ+6LVJy+alvucM3X3mRgnrxd4n2jPqPYc Zah/w+FDBNhrKO2lqemQsKkS/UY63Tx1VKGJubPHQt9GxoA4djjoCFiktEnqETmz+H 5nz3QksxdLIXA+oCJ110gY+NG2aIUNLk2+oHGnbXIHoBVRdXrdRBLoEn65/COVxg37 vPvc/kvZDgrb89k7ufzAIe6LJfVkaKLHyVRaADao7sAQPjgJiKT685IYBzufFO5n9Q mbnGf/dK9slRg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 07/48] objtool/klp: Don't correlate absolute symbols Date: Wed, 22 Apr 2026 21:03:35 -0700 Message-ID: <1dc8b127ff0b1252e53bb7e6130ed46c60f57c25.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Some arch/x86/crypto/*.S files define local .set/.equ constants that get duplicated in vmlinux.o. This causes klp-diff to fail with "Multiple correlation candidates" errors since it can't uniquely match these between orig and patched builds. Skip ABS symbols in dont_correlate(). They're purely compile-time assembly constants that are never referenced by relocations, so they don't need correlation. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu Reviewed-by: Miroslav Benes --- tools/objtool/klp-diff.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index f6597015b33b..05071d691b5f 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -361,6 +361,15 @@ static bool is_addressable_sym(struct symbol *sym) return !strcmp(sym->sec->name, ".discard.addressable"); } =20 +/* + * ABS symbols are typically assembly .set/.equ constants which are never + * referenced by relocations. (Exclude FILE symbols which are also SHN_AB= S.) + */ +static bool is_abs_sym(struct symbol *sym) +{ + return sym->sym.st_shndx =3D=3D SHN_ABS && !is_file_sym(sym); +} + /* * These symbols should never be correlated, so their local patched versio= ns * are used instead of linking to the originals. @@ -370,6 +379,7 @@ static bool dont_correlate(struct symbol *sym) return is_file_sym(sym) || is_null_sym(sym) || is_sec_sym(sym) || + is_abs_sym(sym) || is_prefix_func(sym) || is_uncorrelated_static_local(sym) || is_clang_tmp_label(sym) || --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD52B3D0930; Thu, 23 Apr 2026 04:04:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917067; cv=none; b=N5uUAxBeenX7veOeyXnnT8YNtbRjFa6ndFeWS54Pt9Z9l7+uMx4L2gwK0DLHrbyDKe5zIu61RoBPg/Zd/BhHRY/BM4epSPhyhgT9fDRtJNOwn0Zqo0jbN35Yb50W5UiwYz5dOq066sZC8Q8NUQL7MiEgQeGixuwYbyEBD2MrAW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917067; c=relaxed/simple; bh=GWjzH6dcqSwmIWvvOSKlsujsIsapPa8vd+VFv56LUmQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EDi+oBR7KL3yF0k5bMR4U3whsEuXkgDyaxeg9fNL/0AlmhO9eB/Z1llOzqxo2irv4ZU/wyWkwS7kGIIabJEMnzuzc9vdJrIkkdf0U6rhj/JNt46Z3YoZBMPHP5ENV+BnOXGHbRvvb7mfamOqDA0R2It5jbxRfQ1RvdTrQNeeLAo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XBwdmJA3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XBwdmJA3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A7DCC2BCB7; Thu, 23 Apr 2026 04:04:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917067; bh=GWjzH6dcqSwmIWvvOSKlsujsIsapPa8vd+VFv56LUmQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XBwdmJA3wEXVC7/pP1ySoBIClAjgySAOXE6DOLWEFKYl83d9dkBlk3ViRn3HdC5NQ 1EvrQWd7ref03C4Q5v+QgWQnKYL0OtTVB5sIytyRAb9emEUWrYNkw118ZBd3bK1K5a 7zNLeUWvNAHHJYbfXpyAmhaL9tGDeJk3yIUWRAKaoYpp+oR7WJ1uqWlYH5uCwQSECy qB46pUzmVITr7lPApdYXzjwmVRxp9M65dlGUHrZHNjpJJHTdC1LPw33ZEs3ArRUp8V KEPEC8Fqi/IAWSQQvbqRvUAtUYIZbBPhHX0l283xwNqKHC1GDtUweX9vzyn6JQVV1U WcYtkOgs35k8A== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 08/48] objtool/klp: Don't correlate __initstub__ symbols Date: Wed, 22 Apr 2026 21:03:36 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With LTO, the initcall infrastructure generates __initstub__kmod_* wrapper functions in .init.text. These are the LTO equivalent of __initcall__kmod_* data pointers, which are already excluded from correlation. These are __init functions whose memory is freed after boot, so there's no reason to include or reference them in a livepatch module. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu Reviewed-by: Miroslav Benes --- tools/objtool/klp-diff.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 05071d691b5f..022522cd9b6c 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -370,6 +370,12 @@ static bool is_abs_sym(struct symbol *sym) return sym->sym.st_shndx =3D=3D SHN_ABS && !is_file_sym(sym); } =20 +static bool is_initcall_sym(struct symbol *sym) +{ + return strstarts(sym->name, "__initcall__") || + strstarts(sym->name, "__initstub__"); +} + /* * These symbols should never be correlated, so their local patched versio= ns * are used instead of linking to the originals. @@ -385,10 +391,10 @@ static bool dont_correlate(struct symbol *sym) is_clang_tmp_label(sym) || is_string_sec(sym->sec) || is_rodata_sec(sym->sec) || + is_initcall_sym(sym) || is_addressable_sym(sym) || is_special_section(sym->sec) || - is_special_section_aux(sym->sec) || - strstarts(sym->name, "__initcall__"); + is_special_section_aux(sym->sec); } =20 struct process_demangled_name_data { --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83C2935E937; Thu, 23 Apr 2026 04:04:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917068; cv=none; b=AoB358XFiJpQjpfyq/QR9Ib/Y+eeTXJ2p76VqOWqR8o/YEmmD45890QbmufD6koUz/cGfM8TQ/fbsSsljewu87E2llbbgk/iv3sotYfIDnAbYk8M7UDi2GJbrCfNtj4fd4Kww/f6m3zfxlFBxmEzMKm8OPigi1Fp4wrYJI69TLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917068; c=relaxed/simple; bh=IJ9wumKXfu5EvewV2eGErMj5akhjS9yL+uKUgD0DKhQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X+Grybzxj1l1wIct9m3P9iM7JguFm+FDe7ydHMxqCBi2SsyQHIi+mq2eO8m0tY2IPD+urwrrxEXjqWNtFyqNqgT0CPR2C07LYVM1g0jIqwqcsbCtJDXhLu8eHP+h2PikkVL+3DWDH5lvabrnlyacrfcOsS59PeCOfuoKusVYQSw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PZhHZrol; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PZhHZrol" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C289AC2BCB4; Thu, 23 Apr 2026 04:04:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917068; bh=IJ9wumKXfu5EvewV2eGErMj5akhjS9yL+uKUgD0DKhQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PZhHZrolGJo0ZQrnW/m+WlJu5aSIOPOhdKFKrBwsV7HhYqL42UWZfp+V/4r9NE1t4 BVT5Om4jp/Z3tCdX2QeC3N7CVxlHKwI/VhnBwzK7UP2wKERKbwr8fDK/zWNHWKSzyk RD4jSv59JN6CeFR7hP3v215QZYnBGfGZTLzB1QFOTNaAoPADpkCojGD6JG6qKiljqa 2/9Ad51x3d3lu/idNCHDVeWPEQ5FWqnXr//7wj8ClgCzQR4Vo1rLng1jPDzMgwMnJs DCDXDQ3MuXUmJr5aAJQbJkdMV5Y/L4F/0yDjNZPChnSHVi+qVfBTW3Vl0I06jchWzO uezoqqefncqaw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 09/48] objtool/klp: Fix create_fake_symbols() skipping entsize-based sections Date: Wed, 22 Apr 2026 21:03:37 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Joe Lawrence create_fake_symbols() has two phases: creating symbols from ANNOTATE_DATA_SPECIAL entries, and a fallback that uses sh_entsize for special sections like .static_call_sites. When .discard.annotate_data is absent, the function returns early, skipping the entsize fallback and silently allowing unsupported module-local static call keys through. Fix it by jumping to the entsize phase instead of returning early. Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffin= g object files") Assisted-by: Claude:claude-4-opus Signed-off-by: Joe Lawrence Signed-off-by: Josh Poimboeuf Acked-by: Song Liu Reviewed-by: Miroslav Benes --- tools/objtool/klp-diff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 022522cd9b6c..767716766d41 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -1375,7 +1375,7 @@ static int create_fake_symbols(struct elf *elf) =20 sec =3D find_section_by_name(elf, ".discard.annotate_data"); if (!sec || !sec->rsec) - return 0; + goto entsize; =20 for_each_reloc(sec->rsec, reloc) { unsigned long offset, size; @@ -1407,7 +1407,7 @@ static int create_fake_symbols(struct elf *elf) /* * 2) Make symbols for sh_entsize, and simple arrays of pointers: */ - +entsize: for_each_sec(elf, sec) { unsigned int entry_size; unsigned long offset; --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 200DC3D34BD; Thu, 23 Apr 2026 04:04:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917069; cv=none; b=f7fu5d9i49FzAbPn1seqNPMypOt+SCYIZ5l8gP/Q3HzZHEGGzw+D27F0FbfuejuPsC/LlBRRB0rJ7waNkXFsuUJSGruh6V2DJKa5Z1wXWB/VrUGGsjtrZnpSndRXl6FzLowkFi5G45VxN5tFtoNBOHX/o+HvJpeXbFar7VJ5ayU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917069; c=relaxed/simple; bh=rVqo26BEtqzWbHDo8Y040gyqac0pVZ43mNsABwPmsbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rm69iApn6uEeKmT6ApHpkHZ5Gq1RRzFdDOiKVnUWi6S7sdgn8igNK1av6qT1vV+tegbvHv67WqNOX1mJU+96rUqi6D/L/yf+bvZoXyBNr5FiLdATC+jjP86Eh5KItjXDd91Nq5NM72Sh4wTKt5E2I6LQKtpERU3N2G4LWOv8c70= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aH8wP7S9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aH8wP7S9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54727C2BCC4; Thu, 23 Apr 2026 04:04:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917068; bh=rVqo26BEtqzWbHDo8Y040gyqac0pVZ43mNsABwPmsbo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aH8wP7S9CD5PYdEeKRrY6ahQtBMMGjFFTal1JFXBMeH7eteOe08Z26VfR8gcJRU4X kkW2+O2BVuVYGecNMGGlI0wixMeLazkB7nB9XKpjzaw5SqZ8Rwy99SrpmopWhGbshK rZr6M0TvAKQo/yQ9kF3L4TWlFtuupRLxeFwPxPw1+nXRyMmRP+FJRmEyLBtgwvdla7 NeIC4V6FexEKNe2W/fzq1ovv2mhdisznZKCxQeCLzGnnBMt/qTGdfDQ2wFLufRAosE fLXUkAeGyBzhsEU1HSjAK+7ayCakJgqDxs6TciwBhQIGISRDCsvhVvmTDYspVrrpoU mIdXNJBslmflg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 10/48] objtool/klp: Fix --debug-checksum for duplicate symbol names Date: Wed, 22 Apr 2026 21:03:38 -0700 Message-ID: <7fd49264db4f5a9c654ad162cca96ce575e77ae4.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" find_symbol_by_name() only returns the first match, so --debug-checksum=3D silently ignores any subsequent duplicately named functions after the first. Add a new iterate_sym_by_name() to fix that. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu --- tools/objtool/check.c | 19 ++++++++++++++----- tools/objtool/elf.c | 12 ++++++++++++ tools/objtool/include/objtool/elf.h | 3 +++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 5722d4568401..f14212a8c179 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3657,6 +3657,17 @@ static bool skip_alt_group(struct instruction *insn) return alt_insn->type =3D=3D INSN_CLAC || alt_insn->type =3D=3D INSN_STAC; } =20 +static void enable_debug_checksum_cb(struct symbol *sym, void *d) +{ + bool *found =3D d; + + if (!is_func_sym(sym)) + return; + + sym->debug_checksum =3D 1; + *found =3D true; +} + static int checksum_debug_init(struct objtool_file *file) { char *dup, *s; @@ -3672,18 +3683,16 @@ static int checksum_debug_init(struct objtool_file = *file) =20 s =3D dup; while (*s) { - struct symbol *func; + bool found =3D false; char *comma; =20 comma =3D strchr(s, ','); if (comma) *comma =3D '\0'; =20 - func =3D find_symbol_by_name(file->elf, s); - if (!func || !is_func_sym(func)) + iterate_sym_by_name(file->elf, s, enable_debug_checksum_cb, &found); + if (!found) WARN("--debug-checksum: can't find '%s'", s); - else - func->debug_checksum =3D 1; =20 if (!comma) break; diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index ac9da81a7a2f..a5486e172e5c 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -335,6 +335,18 @@ void iterate_global_symbol_by_demangled_name(const str= uct elf *elf, } } =20 +void iterate_sym_by_name(const struct elf *elf, const char *name, + void (*process)(struct symbol *sym, void *data), + void *data) +{ + struct symbol *sym; + + elf_hash_for_each_possible(symbol_name, sym, name_hash, str_hash_demangle= d(name)) { + if (!strcmp(sym->name, name)) + process(sym, data); + } +} + struct reloc *find_reloc_by_dest_range(const struct elf *elf, struct secti= on *sec, unsigned long offset, unsigned int len) { diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index c61bd57767f9..cd5844c7b4e2 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -189,6 +189,9 @@ struct symbol *find_global_symbol_by_name(const struct = elf *elf, const char *nam void iterate_global_symbol_by_demangled_name(const struct elf *elf, const = char *demangled_name, void (*process)(struct symbol *sym, void *data), void *data); +void iterate_sym_by_name(const struct elf *elf, const char *name, + void (*process)(struct symbol *sym, void *data), + void *data); struct symbol *find_symbol_containing(const struct section *sec, unsigned = long offset); int find_symbol_hole_containing(const struct section *sec, unsigned long o= ffset); struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *se= c, unsigned long offset); --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D20D337107; Thu, 23 Apr 2026 04:04:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917069; cv=none; b=sxbP8a3F2jIKT1AYDSIuwU1BWup4pnZmA6ufO8KJv0ScZqqpzr8lVBamC9nQ5ypBm+8HW/AezbzINrKxymigCjW4iEC0rz4BNgsJ6DQ0SVWmFHX/oFsNh9Nur6Q5A/g1ONU72/j5mvoXRlFDIgviHC8Lts7ICTkfTHh05O7Qla4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917069; c=relaxed/simple; bh=vLGLOGLMn3+R/d2XjxqRW6cGvDuWqyjdilzW6mjwMpw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UOc8trYCOyatfWJsXxSHUE+6WJl95N3nT0ui/ygcGRISfphm0yqfViwA9ELpzipPHgpGboOGMJYhzQkTwgUTAz68hrZVGTlk/sjhDZEM7AfAupv0Lt/vVFs42DYwt1AMEUlz+y3f8cB0/thhW7iAfkoWW5gAGMsKhmH0gCtEgbk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TRx94qkc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TRx94qkc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB5D3C2BCB2; Thu, 23 Apr 2026 04:04:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917069; bh=vLGLOGLMn3+R/d2XjxqRW6cGvDuWqyjdilzW6mjwMpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TRx94qkcUM1obFtUfNlL3X8/3lfcwjbvfy0ytGsJKHWKsZd767DsJd6v735nDIRN+ 7shKOEQa5YhtB2FHSRye4Pu15CtVGxwzxBtxzl3CNZgrFOC46BO0KpAZAhkiWyId9I o9ouDVMJEqBdywl+aRssHLG+YZ4Sd8oaO/r2SHzDjjVN7EpXuUcs8z9NhVP/POfy+1 ytyVlj+uwwov1Zjh3m5jN+KiGb31ASh1+IBlYWjyqAqQ02nHPYToR+LbLuUIrf0T5C asU+huj+EFhrP5LH7HOYcLbNLIJ1lBIOB1Pk+KuzDRoIxBA4bG6KB7PPwkB9kyYv+n 72H8qtt2v7jZw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 11/48] objtool/klp: Fix handling of zero-length .altinstr_replacement sections Date: Wed, 22 Apr 2026 21:03:39 -0700 Message-ID: <99099e77dffb352f97c5276298ab344c186a3ee2.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a section is empty (e.g. only zero-length alternative replacements), there are no symbols to convert a section symbol reference to. Skip the reloc instead of erroring out. Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffin= g object files") Signed-off-by: Josh Poimboeuf Acked-by: Song Liu Reviewed-by: Miroslav Benes --- tools/objtool/klp-diff.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 767716766d41..7f6f86117394 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -1020,6 +1020,13 @@ static int convert_reloc_secsym_to_sym(struct elf *e= lf, struct reloc *reloc) /* No dedicated section; find the symbol manually */ sym =3D find_symbol_containing(sec, arch_adjusted_addend(reloc)); if (!sym) { + /* + * This is presumably an .altinstr_replacement section which is + * empty due to it only having zero-length replacement(s). + */ + if (!sec_size(sec)) + return 1; + /* * This can happen for special section references to weak code * whose symbol has been stripped by the linker. @@ -1280,6 +1287,7 @@ static int clone_sym_relocs(struct elfs *e, struct sy= mbol *patched_sym) =20 for_each_reloc(patched_rsec, patched_reloc) { unsigned long offset; + int ret; =20 if (reloc_offset(patched_reloc) < start || reloc_offset(patched_reloc) >=3D end) @@ -1293,12 +1301,15 @@ static int clone_sym_relocs(struct elfs *e, struct = symbol *patched_sym) !strcmp(patched_reloc->sym->sec->name, ".altinstr_aux")) continue; =20 - if (convert_reloc_sym(e->patched, patched_reloc)) { + ret =3D convert_reloc_sym(e->patched, patched_reloc); + if (ret < 0) { ERROR_FUNC(patched_rsec->base, reloc_offset(patched_reloc), "failed to convert reloc sym '%s' to its proper format", patched_reloc->sym->name); return -1; } + if (ret > 0) + continue; =20 offset =3D out_sym->offset + (reloc_offset(patched_reloc) - patched_sym-= >offset); =20 --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFC763D4114; Thu, 23 Apr 2026 04:04:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917069; cv=none; b=uVXgBVkW9rOoPB6HJScdEu94vXZRoCLYrwZaF7Syrc0IYr1Mxs7aBhPWmC2eNSVBQgfPNy/B7oCBNWw/GMULjzafVbBepAPCx3CFusL1/iyadMWGGFx+AmwSYoO9hp+tyt/F4BJIinZoW09J/+z3y3JwcJuTJYhLCLseHb345fc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917069; c=relaxed/simple; bh=bzJBvGoGyO4TnHZ5apFVQzs3GCgFKmm9Wup3gNMX+ec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TlUSHRnL7encXhNXUfxMsGw/VzcHXxu1sI0nxB9ZtrD4JYWbVvPrLgf3V1FeMqH0AafGXruIqsIfKygmWOuHjH6hjh/fankAfIzoo54UHHQu4Ym1yQqT+1tFN9/bntylyOR2RFtrD/89xFt+o9zS5haVSCNbFsEsmG7/YgBCPwo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kBXE0E2c; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kBXE0E2c" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FAC5C2BCB4; Thu, 23 Apr 2026 04:04:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917069; bh=bzJBvGoGyO4TnHZ5apFVQzs3GCgFKmm9Wup3gNMX+ec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kBXE0E2ccU6hLStbQ1hi8YCScxAKPS0AjcS/vST+KZglJdttIsUu34fhYQXX03WKA EL/VWpNFh74xEsFiuZWJWGL1C3E8LK7ULuB3Sdu4gRrmGW3EDSnTKx3oHkFXKyoZd4 IEZ0cIlS1soOGWCXsTVp2ry0wR/2CVZK6qVJruZeQQ4Uz9CU4Prxg8s4xqeDj5SWYA /6R+3Fi3ZP/G8osKzKGWFYxhFR5/qdyqoKIEx0PhuUDjWl9iJvwyevog2jPeGsuJdy uVLFJ8Le/hA57JSTq9xT72RSLIblEuKc+ATLXbe9DooVU/noau+aVILc/GcZELxcuD WqZTsH4n8Dftw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 12/48] objtool/klp: Fix cloning of zero-length section symbols Date: Wed, 22 Apr 2026 21:03:40 -0700 Message-ID: <2a02cb0d5de7a60f5ef135dac071c93f6303bd82.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fix NULL dereference when cloning a symbol from an empty section. sec->data is only populated for sections with non-zero size. Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffin= g object files") Signed-off-by: Josh Poimboeuf Acked-by: Song Liu Reviewed-by: Miroslav Benes --- tools/objtool/klp-diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 7f6f86117394..3303664a39d7 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -696,7 +696,7 @@ static struct symbol *__clone_symbol(struct elf *elf, s= truct symbol *patched_sym size_t size; =20 /* bss doesn't have data */ - if (patched_sym->sec->data->d_buf) + if (patched_sym->sec->data && patched_sym->sec->data->d_buf) data =3D patched_sym->sec->data->d_buf + patched_sym->offset; =20 if (is_sec_sym(patched_sym)) --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A9ED3D47AB; Thu, 23 Apr 2026 04:04:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917070; cv=none; b=BZ1/9zAF+GwErjLF7NoaVoJmRZZZ6XiVvnUkbo0RAw7+yzBF0JeaKf3g7MjGRtFWdIIJMmiqOmF/TZBIrDtsvYvSml++6+eTyijNIyuTfoD9R2oCtIXqa3kABLFVosi/Fi474XXpil0vrCM1tx/9ore5CYkWriNRDCOjQqgLHK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917070; c=relaxed/simple; bh=HBm3BUQmvyMpEmGdKmvIPMG0lJthm5R/bEW+RgXKsQA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Az1x0Bgshl88cjPvqENb0nKkuuzHxSY+m1TqTGBYXoZeNLJS3z3hpTgPB/AGEUbX/2inuw9te+HRCtafLSbouKWAR0FiIvCL4Isd3CNGhEAzaJET/k1+5o9Gt4Off2FOB4AQ4Dp31CosUI5PAthKo19G2cwEQo0Qd9RAEALqAa8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Opm85S3x; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Opm85S3x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6D0FC2BCB9; Thu, 23 Apr 2026 04:04:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917070; bh=HBm3BUQmvyMpEmGdKmvIPMG0lJthm5R/bEW+RgXKsQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Opm85S3xGgAbExPKOaEG7DU0K0CYzHt5DwdMtnKR6AJ6gftBWns6VB1JmPHmbN1AJ cZtUxhmoMk2BUSpt7Bk5yvzHQeveVh2SYYWNOZovfO0Ge2yakp1Om8GsTYh6wzOGLG ZZzx/9nd76v85jxJP7W9sWuCDKI1bsuHfzx3i8F/sxNKxPoFBP4zyuUvyAs9VN6XXN BekyLFlC8A3LnlocPQZwzIwatyX3uJ3DlcEPZil69S5YnW/onDwkluDrP2G9uw9tC0 1Oh7s/uR1p+4s4NK8qJGGgjdDVuuSZ60ct7Avatf0SMAXfn2WwoeDLUoTKJbBCwY90 8jIWaNooQZePA== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 13/48] objtool/klp: Fix XXH3 state memory leak Date: Wed, 22 Apr 2026 21:03:41 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The XXH3 state allocated in checksum_init() is never freed. Free it in checksum_finish(). Signed-off-by: Josh Poimboeuf Acked-by: Song Liu Reviewed-by: Miroslav Benes --- tools/objtool/include/objtool/checksum.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/objtool/include/objtool/checksum.h b/tools/objtool/inclu= de/objtool/checksum.h index 7fe21608722a..0bd16fe9168b 100644 --- a/tools/objtool/include/objtool/checksum.h +++ b/tools/objtool/include/objtool/checksum.h @@ -26,6 +26,7 @@ static inline void checksum_finish(struct symbol *func) { if (func && func->csum.state) { func->csum.checksum =3D XXH3_64bits_digest(func->csum.state); + XXH3_freeState(func->csum.state); func->csum.state =3D NULL; } } --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 053CF3D5221; Thu, 23 Apr 2026 04:04:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917071; cv=none; b=Jbo1+Q2K7fIlcOcainFSuN7g1XbatEYfk05LdY71n3MdPSA0dKfxLMafFH1VGtiPurYkV1StpLpieMYUxVF0zQwcCOocsjhy9mRsZw4XurOjoWizeIbKYbAzDQMS5oN9U9P4WVZeBd4oS//Pjz6itRxHxBQ3miGMbGE716rpKME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917071; c=relaxed/simple; bh=LKvhLrcHURxd3W/qU1rasqzFGdBHUvsFoEIkyy4Mb8Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rtAJ9LRh3LAJjTzXPQYJW+ULS/nHRBZZftlyopLKg964CmYkAk/cmCN7JYFLjgG/IuHiX0mcGoxRj3O/GFKDu7VVEXDuY8ipmb7b5MooqSx/xmy/Oqn1nnQ6Lku8RkNhA+nDnI887u5k4DAhF38ExH3yVnH4CPWpIZoC4c1Xnww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jE1GO0Qx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jE1GO0Qx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64E2FC2BCB5; Thu, 23 Apr 2026 04:04:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917070; bh=LKvhLrcHURxd3W/qU1rasqzFGdBHUvsFoEIkyy4Mb8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jE1GO0Qx29cBxaWwjd1HT8uX0hHmetXbzBybGhea+So6PxHq2TeZBLsB6ehYTa5jC BY+Ye6tf1OorGxQqUNeMGeqvLhkAQd4dvkPunW30ETIMx57s4EyxoMe7WNnvCPUcOx lvT7UC1iMV1aqbMoMdjgy079w9nj+ePnIq2PCnl5uiU2XohBk7wTHzjzidT/fBI2dg RikdFrMicNgcDsY+zF+i/ZN4SOIlx4FkdE8mc4zfUicDjbMAqc8n/OByeIyFN5avfG 39ncUmIy8yHOoFZ59XTQPcfFKn1njxiJXF47WX439KLeLraalFefqhr/JeyphrJFIT mOANcLTZsCAWA== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 14/48] objtool/klp: Fix extraction of text annotations for alternatives Date: Wed, 22 Apr 2026 21:03:42 -0700 Message-ID: <5e67de043745aec66abf963edbd74d13c5ea142a.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Objtool is failing to extract text annotations which reference .altinstr_replacement instructions: 1) Alternative replacement fake symbols are NOTYPE rather than FUNC, and they don't have sym->included set, thus they aren't recognized by should_keep_special_sym(). 2) .discard.annotate_insn gets processed before .altinstr_replacement, so the referenced (fake) symbols don't have clones yet. Fix the first issue by checking for a valid clone instead of sym->included and by accepting NOTYPE symbols when processing .discard.annotate_insn. Fix the second issue by deferring text annotation processing until after the other special sections have been cloned. Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffin= g object files") Signed-off-by: Josh Poimboeuf Acked-by: Song Liu Reviewed-by: Miroslav Benes --- tools/objtool/klp-diff.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 3303664a39d7..22942f394745 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -1452,6 +1452,7 @@ static int create_fake_symbols(struct elf *elf) /* Keep a special section entry if it references an included function */ static bool should_keep_special_sym(struct elf *elf, struct symbol *sym) { + bool annotate_insn =3D !strcmp(sym->sec->name, ".discard.annotate_insn"); struct reloc *reloc; =20 if (is_sec_sym(sym) || !sym->sec->rsec) @@ -1461,7 +1462,16 @@ static bool should_keep_special_sym(struct elf *elf,= struct symbol *sym) if (convert_reloc_sym(elf, reloc)) continue; =20 - if (is_func_sym(reloc->sym) && reloc->sym->included) + if (!reloc->sym->clone || is_undef_sym(reloc->sym->clone)) + continue; + + /* + * Keep special section references to cloned functions. + * In some cases annotate_insn can also reference cloned alt + * replacement fake symbols; keep those references as well. + */ + if (is_func_sym(reloc->sym) || + (annotate_insn && is_notype_sym(reloc->sym))) return true; } =20 @@ -1605,15 +1615,28 @@ static int clone_special_section(struct elfs *e, st= ruct section *patched_sec) /* Extract only the needed bits from special sections */ static int clone_special_sections(struct elfs *e) { - struct section *patched_sec; + struct section *sec, *annotate_insn =3D NULL; =20 - for_each_sec(e->patched, patched_sec) { - if (is_special_section(patched_sec)) { - if (clone_special_section(e, patched_sec)) + for_each_sec(e->patched, sec) { + if (is_special_section(sec)) { + if (!strcmp(sec->name, ".discard.annotate_insn")) { + annotate_insn =3D sec; + continue; + } + if (clone_special_section(e, sec)) return -1; } } =20 + /* + * Do .discard.annotate_insn last, it can reference other special + * sections (alt replacements) so they need to be cloned first. + */ + if (annotate_insn) { + if (clone_special_section(e, annotate_insn)) + return -1; + } + return 0; } =20 --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79D313D5250; Thu, 23 Apr 2026 04:04:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917071; cv=none; b=BQ2C/yMHjnzcMaQsE8+MKip4ZTKSvSyDzxOLHqXG8Jw2HstJrCeZnjqAuRzcsEiTmCzCaZCi2X5R6Kl0fvdZz/QqBmQh150DYtJft3yzkbFHf4oEGzrViAQ8S8cpeUCkY63Iwv9eo6BqPQF893tIExX51UBV3cvXkkBeyTMaxwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917071; c=relaxed/simple; bh=pytJZpJjyK7ja4MgCp5b2WBjImBrrXu1b/o8kx/gZ/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T8ixqL0BJSYNXt8u3qtZ+7wUWef8ruPPXEwi3AfNGygD8iJKOJ1GXGdl8oUZpLATDM6LliN/0R2Be5Xg3ZFBvnrrNp8hVO1vsS/WUCcARNw0wEPY/e1oNz2usGLlIv5ebo5T2DSGHggnSK8D2oI1azE5/0z1YQF4IDvHNbV8Ke4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Lxspzcl4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Lxspzcl4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6CA7C2BCB9; Thu, 23 Apr 2026 04:04:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917071; bh=pytJZpJjyK7ja4MgCp5b2WBjImBrrXu1b/o8kx/gZ/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lxspzcl4uBH0BHsHMPKftU4YmHtENPHM7XiE8eeYp9EiBJrlqUwKa3JnmTkntP+vO ELpR6A6aG5UZlcS9YgPrp5Pf3Z2jvWlQEKCKQwQEPgJXdfPBKhiFyfhp/qQM2SpkLW d0T0RliCgh7p/cKnMmIe2vcMIf8QZfX7G2BjxJ7l7cxmNn6CqZbVapuC4uHrfz00V8 vlTBFpmwaXaTmSPPg1t4ETBbac8ZMn/7a/U9JbwzboGJ8ShSeUqgXFlU0Ab6JhM2UI tDLMV8Ld7rJ1Q8SyWgD4V7vjtNWtkBK5mj2Pf4NrABN5WIPtQ/7OKIOzE23eMVlkO2 MYquJYvETaSmw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 15/48] objtool/klp: Fix kCFI trap handling Date: Wed, 22 Apr 2026 21:03:43 -0700 Message-ID: <2022e064d670290bfc4ce96207c64b2282d39959.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" .kcfi_traps contains references to kCFI trap instruction locations. When a KCFI type check fails at an indirect call, the trap handler looks up the faulting address in this section. Add it to the special sections list so the entries get extracted for the changed functions they reference. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu Reviewed-by: Miroslav Benes --- tools/objtool/klp-diff.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 22942f394745..a8b9a1441e7e 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -296,6 +296,7 @@ static bool is_special_section(struct section *sec) { static const char * const specials[] =3D { ".altinstructions", + ".kcfi_traps", ".smp_locks", "__bug_table", "__ex_table", --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFC423D4125; Thu, 23 Apr 2026 04:04:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917071; cv=none; b=CjGsYeMWmvCbGqjrpL3XRqWuAs4SYetwdMo7L9RfnfpcD53kHnequuO9MwaIO+oj0ntnNB3YPnZ5HLXFU9cUPIicvXWNPgu0V7LB7+AcSznNBVmTh+HLpbWGpV90OyUs9TSmpPjw7fo186FwrmuX8RBfxhid871521TgeGhr7+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917071; c=relaxed/simple; bh=vt25iPC4lRsFBzlUwIK2gTOLg/NqXONtzBsE6CA3csA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oXvXW/3seY8NQ3Dlo8Gm1ikuEmitU/tQV2betkSchAPcjBOtTzNKUarlVFfzIhuiNyrwsUQ4jzWgQva/NiXImmow3K18E2HcfP/+FFpnuD79M6ZbCTg2uC0/jrPBCl5OLcKyr+THeaqQXH3o4y7h5QzeNupwjMNVulROGXVxfAM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=A7YtDtnh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="A7YtDtnh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69CADC2BCB7; Thu, 23 Apr 2026 04:04:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917071; bh=vt25iPC4lRsFBzlUwIK2gTOLg/NqXONtzBsE6CA3csA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A7YtDtnhNFfWXg6YUcDXazyDy9KiR+fXE2zvSw3qwVRT9/u2bjvG3171N/a6x/2c4 3oghwh/CnhTLxWwoCh+pqIYGQPTBtlW2tv/1gtDWe/C1kYRu7B7PEFgSUeUqXA0vCu 4vGR9FB1OAIY/ysST9Cp8LZqjZJjqDNCBCLzN1cba96SnfUo6zYulpm9edm+KXHRXl MjVaVin0jgVXPFovWErTMNbq+4O96HIo92rfbXfbVBYidbTv4jdq8fppOXStehNPKJ RSgsOyDOPeDKOdGrenkvuIFcGMS+686oP0BKfxJPK9X/FYvyTkLgBnQhjeHnfdLJ9S OiUK+b7W7mPoQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 16/48] objtool/klp: Fix relocation conversion failures for R_X86_64_NONE Date: Wed, 22 Apr 2026 21:03:44 -0700 Message-ID: <2779114efd74a9dd9f1e78076e1b9e3a5273de73.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Objtool has some hacks which NOP out certain calls/jumps and replace their relocations with R_X86_64_NONE. The klp-diff relocation extraction code will error out when trying to copy these relocations due to their negative addend, which would only makes sense for a PC-relative branch instruction. Just ignore them. Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffin= g object files") Signed-off-by: Josh Poimboeuf Acked-by: Song Liu Reviewed-by: Miroslav Benes --- tools/objtool/klp-diff.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index a8b9a1441e7e..57d2af98a33c 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -1048,6 +1048,9 @@ static int convert_reloc_secsym_to_sym(struct elf *el= f, struct reloc *reloc) */ static int convert_reloc_sym(struct elf *elf, struct reloc *reloc) { + if (reloc_type(reloc) =3D=3D R_NONE) + return 1; + if (is_reloc_allowed(reloc)) return 0; =20 --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BC213D567C; Thu, 23 Apr 2026 04:04:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917072; cv=none; b=WoGciyaQX6I7M0L3QD8iETHphIUUH9S4pSGJ+aKoNzR7Zm0PaL8R5hJK9txFrdzg3cmqTVPRRQ6DClILl5s5JZoSmOtp6rOmI1izjFi2ck+xdxTZDDF3mCDmTGlvahzpAUf6TZ5+xt9PanBcn7ojOrY+oPhlr8CuTlh9EM/Zvng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917072; c=relaxed/simple; bh=Ty1q/fm/UXH3JfFek3GeE1KHOOhsnkTq3KM1WCeyXt8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vj0KfUJ8qMCHHzJw1rTsak+Qfq7dBiYDyzvsWcYIJLMndFpLeHBT/5jbsIDsAlMeZLBpmNh9tVrxoszXt8fHwcw1V4CSx/khrHDV2cAPIaSSSYplGh0R1evvolLXoNwkq1EorFqGcPkEoZH2DuxvVK05wiANFYZ9JPUSXBuKhgk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BK2XFmxg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BK2XFmxg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D86DFC2BCB6; Thu, 23 Apr 2026 04:04:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917072; bh=Ty1q/fm/UXH3JfFek3GeE1KHOOhsnkTq3KM1WCeyXt8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BK2XFmxgKUC9ZQ3pLPB3IZi/Uezxbk4X5xsY985zXVxWPd/W9cdktW8cCn7NnfZMu xpanm927rX5uoL4SPSme1p/OKf4+doRK/wsa3jrIv7WHOTygPEz/yjYYCWXJQlBtDy y8b/+EjEXqJx7Yg8mfERYeZkkCVTcEoXRCDCiiIEESQuA5wlhz30HW1UPyvdBR1erW vYewGBndqCgytyZp1gz5xFvXT1sSAjXC53aZGdAA7b4KC0u86MMRQwdpG6giL97tTj n1UU0QBvcT9wgiur7IyDtnu7Qg9+OXqc7uMwvt4lCLaFcsOlUsA3OxvoxDHui1resD RiKl5uMlxi2ng== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 17/48] objtool: Fix reloc hash collision in find_reloc_by_dest_range() Date: Wed, 22 Apr 2026 21:03:45 -0700 Message-ID: <09dab1995c4ba6ca29dd70b0a7472f1a2975fefd.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In find_reloc_by_dest_range(), hash collisions can cause a high-offset relocation to appear when probing a low-offset hash bucket. Only return early when the best match found so far genuinely belongs to the current bucket (its offset is within the bucket's stride range). Otherwise, continue scanning later buckets which may contain lower-offset matches. Fixes: 74b873e49d92 ("objtool: Optimize find_rela_by_dest_range()") Signed-off-by: Josh Poimboeuf Acked-by: Peter Zijlstra (Intel) Acked-by: Song Liu Reviewed-by: Miroslav Benes --- tools/objtool/elf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index a5486e172e5c..c4cb371e72b2 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -370,11 +370,11 @@ struct reloc *find_reloc_by_dest_range(const struct e= lf *elf, struct section *se r =3D reloc; } } - if (r) + if (r && (reloc_offset(r) & OFFSET_STRIDE_MASK) =3D=3D o) return r; } =20 - return NULL; + return r; } =20 struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *se= c, unsigned long offset) --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3BB23D6674; Thu, 23 Apr 2026 04:04:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917072; cv=none; b=PjAm0RIZ1dmjATl9ddY2VvenKp3n1xcdRXfA/o6FbfRveVI5+1/ZVXCAyBzNmttCOmAQ2OnQRKmJnwPhQoAh9QaEC1pZ6LjKdL1hgXnH+HP/6c8eNhG+T+uAZOK4dczLAEiMTzqPf4MHguNIXKBrz75BsUbnfdCHt6xF0vk+53I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917072; c=relaxed/simple; bh=ks80gAFM+9j74ozL8rTgGc80chRVvZX5kr5nIZrm2Tw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H/gPp5H9ghfjfj1WwDvRIOYrWfZZr5ZMskNO+mN9eKCNe1OlChgwuJXtxtRaHtMiNuIlvoIl5HwRXIQnEfsCJg8niHfhya1LmXPyZcgaM2fjVrhQqTPWFDnvyBlZtr1be57BH0AsS/rmahUCX39i0B4+EybZkLaoJ9ySAO3Yn2U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EW64AaX2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EW64AaX2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55751C2BCB2; Thu, 23 Apr 2026 04:04:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917072; bh=ks80gAFM+9j74ozL8rTgGc80chRVvZX5kr5nIZrm2Tw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EW64AaX2kYMDykl26Mi439TtATlDMaKbfnk8zNIC1O8Ti91qwrOSoyQ01zf9CNy4R n5wMB7sKnLnAIcz5K49m56MY5e5VFR6uENAe2vafjswJnmHpDshdc/ngckupsUvAvi Dzbmj1E68k1bHsOq3hLJgZZEPflUz+p2l5YCqhx4+LJ+1LQa9ZKCu4YfTo3QU4dHwY FpetTuFJwiz7TglKAcHfGhZ+dLUZlE+ZpRtJG6Sw8un8KPFW8SXaN3il2zBz+3frp+ /77S6ufJ+KFeS/W/09d/oQzB60qdtrZnAi41bO3qq2FbkxbQppuR2sL1FYtzlMYrKS ubHH5Lepex5Ww== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 18/48] klp-build: Fix hang on out-of-date .config Date: Wed, 22 Apr 2026 21:03:46 -0700 Message-ID: <1b3add71a35ff83fc9653c2c872b811cfd5629a3.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If .config is out of date with the kernel source, 'make syncconfig' hangs while waiting for user input on new config options. Detect the mismatch and return an error. Fixes: 6f93f7b06810 ("livepatch/klp-build: Fix inconsistent kernel version") Signed-off-by: Josh Poimboeuf --- scripts/livepatch/klp-build | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index 0ad7e6631314..81b35fc10877 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -306,7 +306,12 @@ set_kernelversion() { =20 stash_file "$file" =20 - kernelrelease=3D"$(cd "$SRC" && make syncconfig &>/dev/null && make -s ke= rnelrelease)" + if [[ -n "$(make -s listnewconfig 2>/dev/null)" ]]; then + die ".config mismatch, check your .config or run 'make olddefconfig'" + fi + make syncconfig &>/dev/null || die "make syncconfig failed" + + kernelrelease=3D"$(cd "$SRC" && make -s kernelrelease)" [[ -z "$kernelrelease" ]] && die "failed to get kernel version" =20 sed -i "2i echo $kernelrelease; exit 0" scripts/setlocalversion --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 830E43D6CC2; Thu, 23 Apr 2026 04:04:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917073; cv=none; b=tshwHzc+C0AAGPod6VNzrLMiIyWXJyj0Y95xmloAHuQexwRI0RzHzjHiYbe1AaFQp6s8HZZE2Ywq6NBIZrRqGAK4V0aqF1tvyAGiOL2c4c7t+9a1gqvrG0ug4j4Jmsekd6vKpAOTkgH5z8ADsCT6qIyLM7xEGwmM+pY0wPVCG1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917073; c=relaxed/simple; bh=0rrESB7Tw2th22oQqKf55qbbRHuSPvTcbVTjD/fC290=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nWCdW9Ga2Goi0huVYxBZLH1bx9D3yH5GcfyBBPosL/zTzRUoNuV1VHSeqZtngW6QZNld9wUomSjm4xc52HJDYr4pNk+bzkCorBwkE20uYEdgWNA+3xSANEM7gGQSGBINtkOg+5JUO5CYMC9gepUrDr6on232ipIXGLOrvwE22OA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NI2csMWY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NI2csMWY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF550C2BCB4; Thu, 23 Apr 2026 04:04:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917073; bh=0rrESB7Tw2th22oQqKf55qbbRHuSPvTcbVTjD/fC290=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NI2csMWY0m2KHlosfoeo9wEfVaEvSTNfoc2yn3xfMJbUSZ69lbPOEwbHyQ8v0PpdB ebv970LuBdJhotr3PvrREVPQ3a0oCfFtrFfn0ZgYMVVctqhNZXoutDAV7vaH5vqQ2Y LDtaVUmuv+RpKxR9ZOYPlQxezRk7H5CIiRJNVrPPl+R/SLjjvO5pMSB4AzhgWV0YlV FmuYOAviDvT8VpfIkEezGJnmFvDOxyl8hTNslbmx7+EMMOdfFAHuTXGKI02rnybugP Qdz6j22eRWmXDS6C3x7KVcFUCd5Qvfd0leZQ+FlZGwsY8KDjV8OsxRshLmrv6OxxoE YrXvPO5tsuiLw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 19/48] klp-build: Fix checksum comparison for changed offsets Date: Wed, 22 Apr 2026 21:03:47 -0700 Message-ID: <128563f2a525de0ab3518f826d4719149e5712cf.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The klp-build -f/--show-first-changed feature uses diff to compare checksum log lines between original and patched objects. However, diff compares entire lines, including the offset field. When a function is at a different section offset, the offset field differs even though the instruction checksum is identical, causing the wrong instruction to be printed. Only compare the checksum field when looking for the first changed instruction. Also print both the original and patched offsets when they differ. Fixes: 78be9facfb5e ("livepatch/klp-build: Add --show-first-changed option = to show function divergence") Signed-off-by: Josh Poimboeuf --- scripts/livepatch/klp-build | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index 81b35fc10877..2b8b3c338a87 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -727,13 +727,29 @@ diff_checksums() { ) =20 for func in ${funcs[$file]}; do - diff <( grep0 -E "^DEBUG: .*checksum: $func " "$orig_log" | sed "s|$= ORIG_DIR/||") \ - <( grep0 -E "^DEBUG: .*checksum: $func " "$patched_log" | sed "s|$= PATCHED_DIR/||") \ - | gawk '/^< DEBUG: / { - gsub(/:/, "") - printf "%s: %s: %s\n", $3, $5, $6 - exit - }' || true + local -a orig patched + paste <(grep0 -E "^DEBUG: .*checksum: $func " "$orig_log") \ + <(grep0 -E "^DEBUG: .*checksum: $func " "$patched_log") | + while IFS=3D$'\t' read -r orig patched; do + read -ra orig <<< "$orig" + read -ra patched <<< "$patched" + + if [[ ${#patched[@]} -eq 0 ]]; then + printf "%s: %s: %s (removed)\n" "${orig[1]%:}" "${orig[3]}" "${orig[-= 2]}" + break + elif [[ ${#orig[@]} -eq 0 ]]; then + printf "%s: %s: %s (added)\n" "${patched[1]%:}" "${patched[3]}" "${pa= tched[-2]}" + break + fi + + [[ "${orig[-1]}" =3D=3D "${patched[-1]}" ]] && continue + + printf "%s: %s: %s" "${orig[1]%:}" "${orig[3]}" "${orig[-2]}" + [[ "${orig[-2]}" !=3D "${patched[-2]}" ]] && \ + printf " (patched: %s)" "${patched[-2]}" + printf "\n" + break + done || true done done } --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C53DD3D75A0; Thu, 23 Apr 2026 04:04:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917073; cv=none; b=h4FMg9sJ+bcHtCKpHjLUWrQEnBavsMxKsUyvgPrEAyK4XSVmFfRrsHYBj5L5M8aqUViPLzJMzDC9ejDydPrEux8KCajDkWYr0Ct+q5k4gL7YJhyi3B9ooNb808bM/gzWO/ai2QO9aDXx1v8+3jEJJq7vP7xzlJLpaUKybd5RgGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917073; c=relaxed/simple; bh=p3tDSzhkhuYxo7Rda0jssYM2X7zLXfdCw/lc/q2MBvI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f+pfvXVGigTID5F4erd77gfH0M75Tx6heuuNoq7oc/kJKK05n9zplpi+kQdHkLTt0HK0AMvDwCPoDUPdXeYhfku0tjYKFrabmOX/P5X6uOTOnaGaynzgLI3fafp1DU8aZTTY56w50+w7UiLJvJgS9jFqh8mKYVM3+y5vP/cOhIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vGgetgGZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="vGgetgGZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 544F1C2BCB2; Thu, 23 Apr 2026 04:04:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917073; bh=p3tDSzhkhuYxo7Rda0jssYM2X7zLXfdCw/lc/q2MBvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vGgetgGZdpahrvq2LAhRk7GcdNa2zsd68FktJYpWHwX6KBFj5nMY/b5ywNXnO4AU0 39mLZ/72IWp5DzKp/1BIdzfJaRsgGVRlTGVjT2lMcNjeUetCQ/0JkZx/DUFwRZxsJz xoPjHY36w3nCsV32x4eA5usbBjDbN7SGYEhbfqxQty5HnQxrROjnU1U2X9TXBVgc3r Xx0wh3cTM6p83fogP6FcQztd7ryn27noYDpkF722Kur9beGC1nSfwXKRhJYwlYfY1U cB1QYa5sPJru38mDNynCpOs21Y1faSpsqjX2tACooYFCGXvPQM5NvaCtQOtYlKDZ9K A6OcSJRqlOqfg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 20/48] klp-build: Don't use errexit Date: Wed, 22 Apr 2026 21:03:48 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The errtrace option (combined with the ERR trap) already serves the same function (and more) as errexit, so errexit is redundant. And it has more pitfalls. Remove it. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu Reviewed-by: Miroslav Benes --- scripts/livepatch/klp-build | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index 2b8b3c338a87..e2f0eb8fdc7f 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -11,7 +11,6 @@ if (( BASH_VERSINFO[0] < 4 || \ exit 1 fi =20 -set -o errexit set -o errtrace set -o pipefail set -o nounset --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 429603D75D0; Thu, 23 Apr 2026 04:04:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917074; cv=none; b=AbR3Q49d82VKJYRwbN/gVxt/am6RV6gHHDDnj53XCtZrDw88+vmo460f3s4X4nyZCZhgZoukAEp9wD5eUoQ1PA7u3NRW+z7dd9e2moiL2ukrlzF1MpKK7Gali1jkALwuejy8wWWsoR/2E0D5bveJ25DNMatgkUXsThbUsB3Z/KI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917074; c=relaxed/simple; bh=572VMYMokd1zIrU682srFN53tjx+p2xgs9meRhcLEfc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q3cs6Ay692S3Xv/ahw2kJHSc5ctdNuG+LGn5EwuVM6IFbrrZRymaNIheygU1DUcSA5CBqkNm1TrkzrBXpa8FToEUK0VBYLLGuTrM+FrH3w7m0LLEFYnx4Z1uCKsQkAFNE9+EcFSEqQZUnnzvEaOE7yGk6j6pb8ZV5ImsM6O0E0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q2vMUoT/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q2vMUoT/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF627C2BCC4; Thu, 23 Apr 2026 04:04:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917074; bh=572VMYMokd1zIrU682srFN53tjx+p2xgs9meRhcLEfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q2vMUoT/ygHTZ1c0ydtEMX99VJrOSpukhi4oZJ/7OQBSTjrkL7VF8maOHCeClCm0r oGM5AxWcakjgFkhNBT4hBjw1cPszcRMppWTbYxYaxggE4TWA1qdV60NnwAXsjDZjn1 kzgFIDCnNnwRGLGTN1gvG1ej/n4dnGMavFIoGXT1cAGOQ9FehJnR69VlK5KeQ8F6yZ rFosBMSfhKtJuBECmU3Hxuha6FYbapf0DhZ7qJhVH5TQbZfCv0U8SXUQj3GUBAbRb1 W1MDkxjjCj4458guDByxMVzUEOiLFhwAycg7fQXYg2Snxm0eItcmCDbeHr/u43Lqav pBzpmHqs9lOPA== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 21/48] klp-build: Validate patch file existence Date: Wed, 22 Apr 2026 21:03:49 -0700 Message-ID: <66e3edb75bf1924c650bce43835acc2053d1cf1a.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make sure all patch files actually exist. Otherwise there can be confusing errors later. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu Reviewed-by: Miroslav Benes --- scripts/livepatch/klp-build | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index e2f0eb8fdc7f..115f68db49c9 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -157,6 +157,7 @@ process_args() { local short local long local args + local patch =20 short=3D"hfj:o:vdS:T" long=3D"help,show-first-changed,jobs:,output:,no-replace,verbose,debug,sh= ort-circuit:,keep-tmp" @@ -235,6 +236,10 @@ process_args() { =20 KEEP_TMP=3D"$keep_tmp" PATCHES=3D("$@") + + for patch in "${PATCHES[@]}"; do + [[ -f "$patch" ]] || die "$patch doesn't exist" + done } =20 # temporarily disable xtrace for especially verbose code --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DAB2E3CC9E4; Thu, 23 Apr 2026 04:04:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917074; cv=none; b=JauWeMce0G7DdBqpfonQkFM25QS7D5CWmubXaOz5ffSC5GnEBhhxoWQ/ofA1c6zN480s2EjxSfPJ9LFfVNsDpyc7J2SHK5+Rs/kS6afG09mhQor2YbSGYFihD3gGeoA9q9grmA4MrA6P+hLqvcRg/FqABbEO+vYTEoo5e9A48V8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917074; c=relaxed/simple; bh=02VvGyXarl2XFlvNz5pnH+G+BL/1jtvXwmkMaOF0LH4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GbX6bi7Q4lmCvSdMthuM02/k1TOCHCquiD/gEYUb4njbNNY8Pxi3Ktjgorhl6RHikKcp0IPs1hKv5o+NiAgdSdT1M+li7L7F+Jy4xWBbcU5IeiAFCMqiuWXg+coJ7dIdVt5Q9NbKn6Uig9LxeCU1HDbv0mATQUPEC89s1+CMDfc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FC31JauQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FC31JauQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F9A4C2BCB2; Thu, 23 Apr 2026 04:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917074; bh=02VvGyXarl2XFlvNz5pnH+G+BL/1jtvXwmkMaOF0LH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FC31JauQdS3femwHcLxBjpzz68ctv4cFhjgWmC/5RCyFjScntWT1a41mjH0OWkSF/ 9/th9W9QuRuLZj/7GxXuLbcXMWNlMDIeCgvzLewXW99g4EBzU3DYX7M582VD8NaiXJ 1EdlmPeG+qVUPjoCPgDEAuwzRWYXCMxOWJq1gg7FKC8C5CX9l9eqRm91gpiD0ZL3n9 +vOsCYMeDIlpUWR/Vz6S8Jje43fe/LqK6yrjXTJAWQG6a7fCb1dGry9ZemZwBFzEc3 uf01VYiOsIFNc+tLEad0/P9xp+nsSVG3AN+PEXih3vyLom41zmqp8LtTRmsUBvb8WF tTQB5fYTYFbww== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 22/48] klp-build: Suppress excessive fuzz output by default Date: Wed, 22 Apr 2026 21:03:50 -0700 Message-ID: <58c5ac9ae38760beb06e5ddddb742ea54f922371.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a patch applies with fuzz, the detailed output from the patch tool can be very noisy, especially for big patches. Suppress the fuzz details by default, while keeping the "applied with fuzz" warning. The noise can be restored with '--verbose'. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu Reviewed-by: Miroslav Benes --- scripts/livepatch/klp-build | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index 115f68db49c9..a7f571df7813 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -19,12 +19,11 @@ set -o nounset # This helps keep execution in pipes so pipefail+errexit can catch errors. shopt -s lastpipe =20 -unset DEBUG_CLONE DIFF_CHECKSUM SKIP_CLEANUP XTRACE +unset DEBUG_CLONE DIFF_CHECKSUM SKIP_CLEANUP VERBOSE XTRACE =20 REPLACE=3D1 SHORT_CIRCUIT=3D0 JOBS=3D"$(getconf _NPROCESSORS_ONLN)" -VERBOSE=3D"-s" shopt -o xtrace | grep -q 'on' && XTRACE=3D1 =20 # Avoid removing the previous $TMP_DIR until args have been fully processe= d. @@ -194,7 +193,7 @@ process_args() { shift ;; -v | --verbose) - VERBOSE=3D"V=3D1" + VERBOSE=3D1 shift ;; -d | --debug) @@ -381,7 +380,7 @@ apply_patch() { echo "$output" >&2 die "$patch did not apply" elif [[ "$output" =3D~ $drift_regex ]]; then - echo "$output" >&2 + [[ -v VERBOSE ]] && echo "$output" >&2 warn "${patch} applied with fuzz" fi =20 @@ -544,7 +543,11 @@ build_kernel() { # cmd+=3D("KBUILD_MODPOST_WARN=3D1") =20 - cmd+=3D("$VERBOSE") + if [[ -v VERBOSE ]]; then + cmd+=3D("V=3D1") + else + cmd+=3D("-s") + fi cmd+=3D("-j$JOBS") cmd+=3D("KCFLAGS=3D-ffunction-sections -fdata-sections") cmd+=3D("OBJTOOL_ARGS=3D${objtool_args[*]}") @@ -805,7 +808,11 @@ build_patch_module() { [[ $REPLACE -eq 0 ]] && cflags+=3D("-DKLP_NO_REPLACE") =20 cmd=3D("make") - cmd+=3D("$VERBOSE") + if [[ -v VERBOSE ]]; then + cmd+=3D("V=3D1") + else + cmd+=3D("-s") + fi cmd+=3D("-j$JOBS") cmd+=3D("--directory=3D.") cmd+=3D("M=3D$KMOD_DIR") --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 327123D8113; Thu, 23 Apr 2026 04:04:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917075; cv=none; b=GBmL2fxrGPJgbhlK2oL5GNq6e53SS4mGL3tQlt2xegwVIKrZL0mngBUZG6tsrG5DW7E2/E1dX9PylUJpHFGUABKY4p/atGA/544uWFN2my4uvlU9/+3hsSvWag9578HIugFTHgi4/IW1U9BLZDDYtBEGP5sVT6f0ow08V0hHNBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917075; c=relaxed/simple; bh=TGQr/sL6V2smG8IwtZoYQMzCjA/Kyq1WZ0Uu4gpZ2LI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M4Zd1s3BPljo0WLnBpkTTnLSNtTVkYJWwiLUnftFN3r7L7HYmZPxzPX+BimlNMc0r03/rgzNlAXRoteIyIPbH9m5qnNKaUpcPqJsKBAzaKoDmbxX8XjKIOTxkLRt4Bo7u9qRK9fLupfXZ5rdGNH1ISCol9OGWHnY+Cvf/Eh7Wbk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZSVM/VpF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZSVM/VpF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE4A9C2BCB5; Thu, 23 Apr 2026 04:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917075; bh=TGQr/sL6V2smG8IwtZoYQMzCjA/Kyq1WZ0Uu4gpZ2LI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZSVM/VpFOYQSTjRv60gqM4wcH0py2/LIg/PfgME1xuxWhZWQBZu/Ke45WLm+npRde euVXo+zZVt6P6yFsFw5DXXimagsZXv22dy4hYcyIT3ysz5YWS6tqYBgzVbItfvkN8X 8l48zJUumLXVyhUjXjgpKXbyb52du4DfRZ0SbaRGRk42ETn4WaJwqKHF3CshWemtSg jgouUq+v0AiiV54kWVMkxC+sCLzo/WsVevWEdVIDyNqzqE0Ko8rBA+4e1VZgGZ+xVO tVyLu0PTL7/OJHT3nD3GD7u1u5OfbHeDNP0PDP4mqtV14LVFLYMjIcMbOLwC2IGGdd wlRitBr2NfzTQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 23/48] klp-build: Fix patch cleanup on interrupt Date: Wed, 22 Apr 2026 21:03:51 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If a build error occurs and the user hits Ctrl-C while a large patch is being reverted during cleanup, the cleanup EXIT trap gets re-triggered and tries to re-revert the already partially-reverted patch. That causes 'patch -R' to repeatedly prompt "Unreversed patch detected! Ignore -R? [n]" for each already-reverted hunk, with no way to break out. Fix it by adding '--force' to the patch revert command in revert_patch(), which causes it to silently ignore already-reverted hunks. And ignore errors, as the cleanup is always best-effort. For similar reasons, add to APPLIED_PATCHES before (rather than after) applying the patch in apply_patch() so an interrupted apply will also get cleaned up. Fixes: d36a7343f4ba ("livepatch/klp-build: switch to GNU patch and recountd= iff") Signed-off-by: Josh Poimboeuf Acked-by: Song Liu --- scripts/livepatch/klp-build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index a7f571df7813..60231cf49e5c 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -384,15 +384,15 @@ apply_patch() { warn "${patch} applied with fuzz" fi =20 - patch -d "$SRC" -p1 --no-backup-if-mismatch -r /dev/null "${extra_args[@]= }" --silent < "$patch" APPLIED_PATCHES+=3D("$patch") + patch -d "$SRC" -p1 --no-backup-if-mismatch -r /dev/null "${extra_args[@]= }" --silent < "$patch" } =20 revert_patch() { local patch=3D"$1" local tmp=3D() =20 - patch -d "$SRC" -p1 -R --silent --no-backup-if-mismatch -r /dev/null < "$= patch" + patch -d "$SRC" -p1 -R --force --no-backup-if-mismatch -r /dev/null &> /d= ev/null < "$patch" || true =20 for p in "${APPLIED_PATCHES[@]}"; do [[ "$p" =3D=3D "$patch" ]] && continue --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1E193D88E7; Thu, 23 Apr 2026 04:04:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917075; cv=none; b=iaqMT1Gr60mmpd/Gah8lGx8JlWfWMgn466+zoDYK447opw7AoxgGpjcEd/Ti4T1ueusjePWoaFwQo1KSLu5mp8qzyMqivIF8DAWebbORlj4HPe/ea9ynk36wP9Z0heyIb5WuuUMBX1twKwCr/kVcJwuT7tz1eZoFhYkP+US6ARE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917075; c=relaxed/simple; bh=LObtQ0w+WobgTBSWD0xjzwXpJVrz7inT8xZhCcIsA/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ULOAyP3cagCyd9byE3QEOIBaoF8kU6DvdNbqqwWseQTGWlsARgiN+Ghm9x4787TiyCbITHy7ipQt1y/XR5HCU5V+avH5o9gUlu0cAcBWPgkccgt++7LiiLWQzqPKcT/VwxHr2rXy0xRProjrayY0b56UKojQhKXaxNxMQFuW1F8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RZFxCeaL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RZFxCeaL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39F0FC2BCB7; Thu, 23 Apr 2026 04:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917075; bh=LObtQ0w+WobgTBSWD0xjzwXpJVrz7inT8xZhCcIsA/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RZFxCeaLvAuLkpJlvYHeVDUwOIVz+z1S7TrVYT40dVm8nmD+EI0LDX0DGEE2uvOKr ywDeAlP3zFtZvM3N82lUsoSE6NAQXU+FwLoq0Y80NLrQeiWtkFJkskCupk6DazNL+L WzokQqjOsfmTfjsOpxObTGi/0rtHsUBfrZDLwYBpdb8aiZxmw4lTXFv8NY8zrzb97Q GaRqynFn05PI5g9IcezDDmsqCz7Z3tkTMIc0dm0YM6GpTPPa4ZUVO29V5McLzj0UVv wDBIjiqEXTaQivfMLi8yAaZDNmCewKXNYnXtcAvPsWNqGMeMUnruUV3Z5QBUG2qszI iTbZRxMhquwMQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 24/48] klp-build: Reject patches to vDSO Date: Wed, 22 Apr 2026 21:03:52 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" vDSO code runs in userspace and can't be livepatched. Such patches also cause spurious "new function" errors due to generated files like vdso*-image.c having unstable line numbers across builds. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu --- scripts/livepatch/klp-build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index 60231cf49e5c..deb1723b70de 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -357,7 +357,7 @@ check_unsupported_patches() { =20 for file in "${files[@]}"; do case "$file" in - lib/*|*.S) + lib/*|*/vdso/*|*.S) die "${patch}: unsupported patch to $file" ;; esac --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42D043D9021; Thu, 23 Apr 2026 04:04:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917076; cv=none; b=HXRrPp5OiCN5yavClUfM2XGDSLUkLZapeo/35nwvsVYbVcei/MMQ0EbPit+kNj4bD99XqgsiyLHEJFFpWMYJ1YxMVp+lypXhix93fVEreHaB9E9+zAORGPP+8Ax3vN0RGg4VWJoeziZ5T3MdQRvPsHwNUhpx3S+xBonz2pGNcaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917076; c=relaxed/simple; bh=WtJVJFghOUklJ4ji8GkVc/S/A2k9LHH39VLyaoUY8Cg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hChmC77/iiNntOGAX2Vl0MH+j6QWrBCdlXYYpoG7lTFSPCUGN2Btvc0E7InwyPaWnr+BLmoCpEcT41GKwqBtsFKirw8AwFl+wxMQy3MrERN0NO1upv6sqLyRS83Ekg5Sjw9lVgTm8TwVjl8ueVizP0YzqPdw8lhB5zqpJOu9rzM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BGJk09rc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BGJk09rc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6E03C2BCB2; Thu, 23 Apr 2026 04:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917076; bh=WtJVJFghOUklJ4ji8GkVc/S/A2k9LHH39VLyaoUY8Cg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BGJk09rcAD05iE6w4mhdyVB5+kWdNPHeXN08L8AjJf0H5NXLanIgRsUyPY0CzBHrh ylKBorVSlDxYlw3aLy76vzlwc7wWT6ZtRrm4/1tGojxCXQ2S3n/nEVoIPzMtaQgMM9 PqDtKejgvpMpEpnZl3awlo9xifzR8yvfSgL+afsI67sorkb3Pc002GCuiwJrfTQhJ7 D8tST1m6BjiPI+Lry9Mwi/jTZz+wkDgUvVDPLuyhvfDfkFFjVRIFYm5MLqoCfyRglT 7Dvoa2JoXqmBxEYuIZQL4yWzwKBzcVBjGvuxTh/QRakCVyvudjbeze7ZHrmqDv3tH7 ZHAcLUP8cXvtw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 25/48] klp-build: Reject patches to realmode Date: Wed, 22 Apr 2026 21:03:53 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Realmode code is compiled as a separate 16-bit binary and embedded into the kernel image via rmpiggy.S. It can't be livepatched. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu --- scripts/livepatch/klp-build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index deb1723b70de..48abbe43f1c9 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -357,7 +357,7 @@ check_unsupported_patches() { =20 for file in "${files[@]}"; do case "$file" in - lib/*|*/vdso/*|*.S) + lib/*|*/vdso/*|*/realmode/rm/*|*.S) die "${patch}: unsupported patch to $file" ;; esac --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A09D3D9DAF; Thu, 23 Apr 2026 04:04:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917077; cv=none; b=joOjGXuapogl5rpfDH7GE763CoOvAgRNEFvnp0LxTY66gyYD1cKKaiP4J+P84JdviBGe6bMDFZkB2uIOSBtaihRB/g/y1BW8brEkKv1eA7/6/eFqk5lbItog+JX/yrlRtFnmRXA3BV4nxXZXREqCuv+1CLMWhtJg6x99YqiE0b4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917077; c=relaxed/simple; bh=wnpusLmivo25BkT7sUHXFVVaM+q/AHUvZQDgUKM6pzM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s5okGyH60jorg/A89TvzISgcl9PCDoc1+M07eCMr9ST3ySjt2hq9rjlnHqlPJ/z953oWpSwiYrCE3LqV30KReHAMJs0FoZ2J4vDaN9GD37v0SF7YFmx4fwClO4Q/Equ1Zz1FFevLYLkrX+v2iHEE5ys1nbsuQvsLruFOO2JenhU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LgRKYwn7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LgRKYwn7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 595DCC2BCB5; Thu, 23 Apr 2026 04:04:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917076; bh=wnpusLmivo25BkT7sUHXFVVaM+q/AHUvZQDgUKM6pzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LgRKYwn7zuHMyDCME2tVM0CJiWFcCyJzmQ1f8KCQj6EXk4/ZH/K9giih0e+aCvZG0 EIteuUCtIoETM1+9Qr67jApBQU/dAtUNmvnD9zPmO534+3g6DcbD/AtdArXIYBaqgo 5dN+VSrU5HN8l/4yAWvxIxnEJaAqTQvMCMYe4M31CNMWoqz376unCK/ifTdeU0iDvQ Kklpl/2CqG9q4YzUm1ZckHFImbtcYR9Lnp5DjFWqsUVTUKH7eeNJ1oZiYimhBDxGoW 9ya7xYNpObRrUKzGWx4eso0S/oE2X+/w5sTQ6eL4c+xHx0BBftsXorKfHSsie09LrY nWkvzyOw+5avw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 26/48] objtool/klp: Don't set sym->file for section symbols Date: Wed, 22 Apr 2026 21:03:54 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Section symbols aren't grouped after their corresponding FILE symbols. Their sym->file should really be NULL rather than whatever random FILE happened to be last. Signed-off-by: Josh Poimboeuf Acked-by: Peter Zijlstra (Intel) Acked-by: Song Liu --- tools/objtool/elf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index c4cb371e72b2..00c2389f345f 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -680,7 +680,7 @@ static int read_symbols(struct elf *elf) =20 if (is_file_sym(sym)) file =3D sym; - else if (sym->bind =3D=3D STB_LOCAL) + else if (sym->bind =3D=3D STB_LOCAL && !is_sec_sym(sym)) sym->file =3D file; } =20 --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FC083D75D0; Thu, 23 Apr 2026 04:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917077; cv=none; b=NG511wpfi+vrpVQzy/yzaJk8eNA62usz2s1QKh2TbWJ6kjVChd97y2perdq4lwyOiSVSoeDRIIlUgnakBQH4ku+3iOPdjNknOnVCxGjguB+T78CAUERLtjGrUwqWipCJ8tsOCBUp4nw5YjKPgikfGzwqx9WNToHuOqbgwRJcbg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917077; c=relaxed/simple; bh=AjMnfHekD59cKjru1WGxZYJOSyqqQxN6zRp36f0FFWY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rXCmlNkf+SjbOt5rrdKC8Xd05tD8HJ+IphCbNTWUHPG1nh4XqbL3QDI2RPqZ34AMvmTsLlpUqQvTjtAb/O2vtpWZFfM42bMA4/0L6ohr1YIliwHsH06Y3iJpm8h7QfD6Sv8VLZA37n3aAcWfaZQMKiumnEfwGSdhHvkCvlIsAc8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qcYCXfLd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qcYCXfLd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0F73C2BCB6; Thu, 23 Apr 2026 04:04:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917077; bh=AjMnfHekD59cKjru1WGxZYJOSyqqQxN6zRp36f0FFWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qcYCXfLdkWyruZRFWevSdvQ2tx72xbTqp7jNIWWHVgZJfaMe5QmMr9HeFRXsrsKYg XpAHjX0WkF9AyO2EDb3KLFDmeFqSs+PvE51733juO0NZ2L23ebqaoyLue53d1mno2Y fJpAn5g+Fh50WdcHhdsp6elQ1XAPlTQtTwtzgezP1FDQr4BIvA+Q7ky2pEO565QUoa II0PBe2W7VcEumDVv9sxw6xSNj9HuVKOrElyX1QxUbL1FKl4tZd5u4NFvzN3/EXOer Y3Ft8wuypjjdq55cNYd5OGVRxgH29x5D7TjVVYiKMSAn0zk2eOjuXKuKUHEjqh4lHb FIHsoDm5PXDfw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 27/48] objtool: Include libsubcmd headers directly from source tree Date: Wed, 22 Apr 2026 21:03:55 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Instead of installing libsubcmd headers to a build output directory and including from there, include directly from tools/lib/ where they already exist. This fixes clangd indexing which otherwise can't find libsubcmd headers. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu --- tools/objtool/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index b71d1886022e..a4484fd22a96 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -58,7 +58,7 @@ INCLUDES :=3D -I$(srctree)/tools/include \ -I$(srctree)/tools/arch/$(SRCARCH)/include \ -I$(srctree)/tools/objtool/include \ -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \ - -I$(LIBSUBCMD_OUTPUT)/include + -I$(srctree)/tools/lib =20 OBJTOOL_CFLAGS :=3D -std=3Dgnu11 -fomit-frame-pointer -O2 -g $(WARNINGS) \ $(INCLUDES) $(LIBELF_FLAGS) $(LIBXXHASH_CFLAGS) $(HOSTCFLAGS) @@ -135,7 +135,7 @@ $(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE $(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=3D$(LIBSUBCMD_OUTPUT) \ DESTDIR=3D$(LIBSUBCMD_OUTPUT) prefix=3D subdir=3D \ $(HOST_OVERRIDES) EXTRA_CFLAGS=3D"$(OBJTOOL_CFLAGS)" \ - $@ install_headers + $@ =20 $(LIBSUBCMD)-clean: $(call QUIET_CLEAN, libsubcmd) --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECF483D8128; Thu, 23 Apr 2026 04:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917078; cv=none; b=fGWQuKDgOk9gFMr63IvNSSkqghNyY98WuHU4yWRjg79IpSvWDa+l8zWQj7JTP1hFRNenSnxN34VPW6/XmVUtgv3ge74DFU+ofPGARpV7KU9q/y35S205NDNmkgQgZZWKwiSPBJHWNSj4a6778XF9ywhsho9UJFczVEtjpF51UFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917078; c=relaxed/simple; bh=1Yg1WyHHwy/0H2Hyiv4fKLbjE8nOHP0jcAPFhtPhwmQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n2ICY44874ELcSpywQ4oOcHc2nqpqauBMjEy3qqJALKS8pILYdjGq8TtaJQd/SpH/rewAhZOi3cR1WWv0McAY4y9uHTmWSS5RchyyKvoC7EdfuWi6nBECUKI3jLMYfgd3tjHIt5ysBvEr2rPnln6XRzsf0k6EG7JivMsTYYzlAM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V+BEhp90; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="V+BEhp90" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64267C2BCB5; Thu, 23 Apr 2026 04:04:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917077; bh=1Yg1WyHHwy/0H2Hyiv4fKLbjE8nOHP0jcAPFhtPhwmQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V+BEhp90S2/pTZYmbAeudjUuutJYGuZirc5cLg+dQE4S4ZuENehhW1QJTpUQNa++m rNkNfdXJsjY8xwq0sbGfEyxRZBkYxKCdgt96zw2Eb7bZQmBzIcQfKK/x0k9WDYgTmy xcJVvAjiOMLPbITUAYdwOcGyaKW8pBG0ERNhwTRjDWt4olhtBp/PQLUxfowV3vvqq5 8qUfqbtLN4bG1CXK8FFml89FMWqG8fIyQhB/zPtteZES5I7H8Hy0XdUuf1MhOLVaWo i2Iwwo0t0xRNFwekJej30uJwjJM2aXOuPW3pbjHWcIceof96Kpf6rDJvQ4lPhiLZcz 8tgJMm8Ld2AXg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 28/48] objtool/klp: Create empty checksum sections for function-less object files Date: Wed, 22 Apr 2026 21:03:56 -0700 Message-ID: <199a3d975e8e562421edd342b9eda242b4f57a71.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If an object file has no functions, objtool has nothing to checksum, so it doesn't create the .discard.sym_checksum symbol. Then when 'objtool klp diff' reads symbol checksums, it errors out due to the missing .discard.sym_checksum section. Instead, just create an empty checksum section to signal to read_sym_checksums() that the file has been processed. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu --- tools/objtool/check.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index f14212a8c179..54ceac857979 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1044,9 +1044,6 @@ static int create_sym_checksum_section(struct objtool= _file *file) if (sym->csum.checksum) idx++; =20 - if (!idx) - return 0; - sec =3D elf_create_section_pair(file->elf, ".discard.sym_checksum", entsi= ze, idx, idx); if (!sec) --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CE7C3DA5C0; Thu, 23 Apr 2026 04:04:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917078; cv=none; b=UpAbLf7HZom8ev4omvjg7b6l8mLnIUGuoZxdkMo4exd1H+ifzypUIpxueq1RxvNIxuS+vpCcujcK6UVPIC7itQO8LoF/06mGIv8X4mai6ywTi8BzaWKSWOSwouIiI2tqNRsgUL2sRkryCXuCgdwMAzXU90hbVgLxzFjX+nVaZgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917078; c=relaxed/simple; bh=7Qo3koABbYsFQ9v2wstd1aYbFGOa31F2LrdyiuE6QIs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dEuSQiTFDI0p4C2pqpMoAan0VmH0zKuECXvXfNxoNFJ/6Ip2P1XxBnzZbkLZ3kmnrw1XXdoShkojb+RFs86/YVO4k7Uv6esbFXEPwd73jZdjYzDnTli1QY2f/gDePbZclt+zeuza/C16nhY+CK1DIrtxjLBC93niJGHLTrK66Ek= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Hr6tNusV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Hr6tNusV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9FFBC2BCB9; Thu, 23 Apr 2026 04:04:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917078; bh=7Qo3koABbYsFQ9v2wstd1aYbFGOa31F2LrdyiuE6QIs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hr6tNusV7nYG66unsYMJlbD/Y06sS36HSpMa1No5ZPd4KySGbUvy6pP9weewce2bi ZEpRg8ozaW69WckfsYSuQ3bXbg9YATZkPcTsPba9Y9WBSyNWSxYJFfsZveOT6H0dmo fWEBxr/kDXXhM1vvbFcv+7dJwaE/u2PsIkwvGaR2soknJv2TbAW2jBc81AqyCcyeJw H61O9+Z018Q0G5dQ7M7KWc/FC0lo/qE75MrhZrE93cbq02DvNGY7ThiEH1Tk4fVffQ Xl6N64L3MSMZiJVT2gessfNTqwiBOWqlg31gyoTf55A/5xybh3OkFHawOmd2y6ljB1 QwYVzfcZAvmtA== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 29/48] klp-build: Print "objtool klp diff" command in verbose mode Date: Wed, 22 Apr 2026 21:03:57 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Print the full objtool command line when '--verbose' is given to help with debugging. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu --- scripts/livepatch/klp-build | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index 48abbe43f1c9..84053e8aadd3 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -681,6 +681,7 @@ diff_objects() { =20 ( cd "$ORIG_DIR" + [[ -v VERBOSE ]] && echo "${cmd[@]}" "${cmd[@]}" \ 1> >(tee -a "$log") \ 2> >(tee -a "$log" | "${filter[@]}" >&2) || \ --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA5233D9054; Thu, 23 Apr 2026 04:04:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917078; cv=none; b=C41vCt4c/ns9BQz6tJ8PFutRAVPLM/+SphJfrjEw3DNe0pzZtUfJMJS+ZSUHo7WZVNYGjO3S1IEPHOoln+9jyhaRZDUrsHqZx6av2KifCXLyR8ybMAuSBNdrLg6oNRbd5Hj0lgK49A6Qr8u6T1t4LJCHtjqYl/dFad+vkuaRgIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917078; c=relaxed/simple; bh=KwniOSZKrmfZmefhKpGgVT9FoHPJ4cAvLoUrNHUDbJk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uO52PT6ER0O2NvemCwnJ5oL/KSSnMIdHUNQwvkuKXi41bvdz+HEFfzSHtKgvGLyCwTIWgu1/CDxjtyCXYVr8wA0mi3DgzIgQ9xd6srVxH5dc1E1MA5Y/EvZt8pxBvrqKaA4kSe4WpW4pVn+SS8Oje9/AAZK9e0d/u24914YBym0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r1CyKk4T; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r1CyKk4T" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61996C2BCB2; Thu, 23 Apr 2026 04:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917078; bh=KwniOSZKrmfZmefhKpGgVT9FoHPJ4cAvLoUrNHUDbJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r1CyKk4THXKlJgNsmI0gbgKN8TZTwhCka7ORFxagTbgY21eNJKGH4Q/2+fWGDTaSs DeTRt3sF7mzTUNZm4/bK4ytEAqtQ7ztlfMNYGr3DcD+/S6zR7h3VAgWqe5Qx18sybC rdEqw0JXaIhlO7Zcnk9WDctDIOnEpVa3mDkW5PdRiuRzrH8/xk6Ifgmnrjfx2TXDEv 1f+3EgMbAjdVKRlUorcCeimSerbNAuo5aRVOuhNzEKAIs43LQPeRlCFfQh3DlOccub JcZ+PtgBF8pUT1w7xk/cRdxjGcAsYVzhUZkB2HQ42bPyNi/9IQZQX3YVOxJxbLF03Z IoXlSwPDCWSfA== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 30/48] objtool/klp: Handle Clang .data..Lanon anonymous data sections Date: Wed, 22 Apr 2026 21:03:58 -0700 Message-ID: <11a0af398f5ebd591e87f3f8627bbf512260549a.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Clang generates anonymous data sections named .data..Lanon.. These need section-symbol references in the same way as .data..Lubsan (GCC) and .data..L__unnamed_ (Clang UBSAN) sections. Without this, convert_reloc_sym() fails when processing relocations that reference these sections. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu --- tools/objtool/klp-diff.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 57d2af98a33c..1951a8b2df44 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -873,9 +873,10 @@ static bool section_reference_needed(struct section *s= ec) if (strstarts(sec->name, ".rodata")) return true; =20 - /* UBSAN anonymous data */ + /* Anonymous data (UBSAN, Clang anonymous constants, etc.) */ if (strstarts(sec->name, ".data..Lubsan") || /* GCC */ - strstarts(sec->name, ".data..L__unnamed_")) /* Clang */ + strstarts(sec->name, ".data..L__unnamed_") || /* Clang */ + strstarts(sec->name, ".data..Lanon.")) /* Clang */ return true; =20 return false; --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AF1E3DA7DA; Thu, 23 Apr 2026 04:04:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917079; cv=none; b=XV1e0UqMpqJX9hOlvbAHdzx5za8gTUNfTS5lRHy7kOUA8yiGSvJl8cAhA7trl2HaDg0ZUAM7n4ug23Nw4ATHTKQphg8552G6BO2uhSHWnash3AwHgzoaLgxxa1rs64EWTlUbfBVy1XaiN05GG9V57DdCaIdJwIXeDN/HmdhvKEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917079; c=relaxed/simple; bh=7tLQh+7OETPl9KIZz6uVG5pJs5EnZZ9Aues+hP46pQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nkOFNjXpIBo3+36knykMKgw2504X+IEleTwsZzppvoMtFq3pEU++9v2bGZMmrg8mtdYjJc6G0Vu/QaT71fjOtxpnWiuGuCc8AnFeiJLuqjdar7CLFlagt7Ng1JHBZ0k1AnJQMFyMHIgNrjdzcJk4MgmntylAFyQZb9GW0AeZaKo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=glGmYpJg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="glGmYpJg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4624C2BCB7; Thu, 23 Apr 2026 04:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917079; bh=7tLQh+7OETPl9KIZz6uVG5pJs5EnZZ9Aues+hP46pQU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=glGmYpJgfLF9atIcpDOB50iD65TuVCr1JiRY4g9B2dV4kXcR2l272p1gs/g4EzLNH tkcYnfQEkvx1jkNzSKN4EJpF5/ERyQV5jdxdRTrzcZYzuCuyDtof4h/BEHOTdWvlDh uZ4c1ZpGakWKGZnf5Jo2yuSptYvV6M9q3hVoKb2L0v/7xon3fE3VJs0f0b1BKaAR+e qj8Nzft92flHFtH1JEaZSEQ3NcGxXnZTKIsPCexND6ImlYlWrA/qjwM4Rnw+iTm9er c1arNO7QWRbZeaZcAuBhXjTYj2s33MtB30t/dZs4TD2G3Idq08ldteTeB61mmwCxiD X23wnWbz4kc4w== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 31/48] objtool: Add is_alias_sym() helper Date: Wed, 22 Apr 2026 21:03:59 -0700 Message-ID: <360097539ed947aea82ce5392548a898a346ffa7.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Improve readability with a new is_alias_sym() helper. No functional changes intended. Signed-off-by: Josh Poimboeuf Acked-by: Peter Zijlstra (Intel) Acked-by: Song Liu --- tools/objtool/check.c | 6 +++--- tools/objtool/include/objtool/elf.h | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 54ceac857979..4c18d6e7f6c3 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -491,7 +491,7 @@ static int decode_instructions(struct objtool_file *fil= e) return -1; } =20 - if (func->embedded_insn || func->alias !=3D func) + if (func->embedded_insn || is_alias_sym(func)) continue; =20 if (!find_insn(file, sec, func->offset)) { @@ -2229,7 +2229,7 @@ static int add_jump_table_alts(struct objtool_file *f= ile) return 0; =20 for_each_sym(file->elf, func) { - if (!is_func_sym(func) || func->alias !=3D func) + if (!is_func_sym(func) || is_alias_sym(func)) continue; =20 mark_func_jump_tables(file, func); @@ -4527,7 +4527,7 @@ static int validate_symbol(struct objtool_file *file,= struct section *sec, return 1; } =20 - if (sym->pfunc !=3D sym || sym->alias !=3D sym) + if (sym->pfunc !=3D sym || is_alias_sym(sym)) return 0; =20 insn =3D find_insn(file, sec, sym->offset); diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index cd5844c7b4e2..3abe4cbc584c 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -279,6 +279,11 @@ static inline bool is_local_sym(struct symbol *sym) return sym->bind =3D=3D STB_LOCAL; } =20 +static inline bool is_alias_sym(struct symbol *sym) +{ + return sym->alias !=3D sym; +} + static inline bool is_prefix_func(struct symbol *sym) { return sym->prefix; --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0E833DA7F5; Thu, 23 Apr 2026 04:04:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917079; cv=none; b=V6/0RA8XeGGDXOjcnnSvXIsCmkvg4wrquSOp4uwWPzv7MxBBxnfFOXVZ6V3tB5rkYBGdTaYzBQxyNLv3QPWa2HMWAPwHVTc7ZowTFcFPn5b0Ax9nGdBCbwi/2JrGdOLbx8ztwV7oWBPcoOqDxCTAmMMtWwUUYH1xi+Lfw/kP1AU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917079; c=relaxed/simple; bh=XbcxHpw4uNE+IqekwDvaZ6DdyZ/BQ3OprymmdKhzlBw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aDpjBxDFqyVcoXWFjWMRuDqbihwYKxffvWaFy+5Pt5scBG0ehUlJJolp/EcwDssZFw8RbQMDxoX89A6OuIkZTPd91kzWAMSyeFpqRlgTtU7M9WKddd6zAOIYqTHLmclmSUx54mzIKyxBWNHvP+UFWNqhBgWukIlSDmjt11ZcOTg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QWEis7Tv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QWEis7Tv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64E9BC2BCB4; Thu, 23 Apr 2026 04:04:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917079; bh=XbcxHpw4uNE+IqekwDvaZ6DdyZ/BQ3OprymmdKhzlBw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QWEis7TvAB7Vg5ENluoGzKpx+kegITEYzcABHxGej7FaLpvFCt1siydDvMEp7Gfns +/f0QeS9B6DoPohejA+6zGD1w+yMkH2EOkNYXbawWVB9dzMCMhYvCM+sr7qcjkNtX5 8TU6sC2JB7do7MBjLrHiFd3Sn3TsnxArwgLYkHlHEM+QLWVAI58Uc2sKT0wwwaAr5w Ab0o4OJB2drn14GmY+JU2DXdR6eUQ/8tCR0q3Ku4gu1nULMySPCv8rvUkXiKsM+JuM 3+okCSdAirBw2meTqas8662CUYeMlNnwKw/suRajq5g+J94dpgsyJy0D1elpHURypR iCmxhj1wB2I9Q== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 32/48] objtool: Add is_cold_func() helper Date: Wed, 22 Apr 2026 21:04:00 -0700 Message-ID: <8eea11ea7d0efc5fcd2e57a10c4285fe998f0cec.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add an is_cold_func() helper. The sym->cold bit is redundant and can be removed. No functional changes intended. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 6 +++--- tools/objtool/elf.c | 9 +++++---- tools/objtool/include/objtool/elf.h | 6 +++++- tools/objtool/klp-diff.c | 3 ++- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 4c18d6e7f6c3..4ed27c53c718 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2614,7 +2614,7 @@ static void mark_holes(struct objtool_file *file) if (insn->jump_dest) { struct symbol *dest_func =3D insn_func(insn->jump_dest); =20 - if (dest_func && dest_func->cold) + if (dest_func && is_cold_func(dest_func)) dest_func->ignore =3D true; } } @@ -4426,8 +4426,8 @@ static int create_prefix_symbol(struct objtool_file *= file, struct symbol *func) char name[SYM_NAME_LEN]; struct cfi_state *cfi; =20 - if (!is_func_sym(func) || is_prefix_func(func) || - func->cold || func->static_call_tramp) + if (!is_func_sym(func) || is_prefix_func(func) || is_cold_func(func) || + func->static_call_tramp) return 0; =20 if ((strlen(func->name) + sizeof("__pfx_") > SYM_NAME_LEN)) { diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 00c2389f345f..8a6e1338af97 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -586,8 +586,11 @@ static int elf_add_symbol(struct elf *elf, struct symb= ol *sym) if (strstarts(sym->name, ".klp.sym")) sym->klp =3D 1; =20 + sym->pfunc =3D sym->cfunc =3D sym; + if (!sym->klp && !is_sec_sym(sym) && strstr(sym->name, ".cold")) { - sym->cold =3D 1; + /* Tell read_symbols() this is a cold subfunction */ + sym->pfunc =3D NULL; =20 /* * Clang doesn't mark cold subfunctions as STT_FUNC, which @@ -596,8 +599,6 @@ static int elf_add_symbol(struct elf *elf, struct symbo= l *sym) sym->type =3D STT_FUNC; } =20 - sym->pfunc =3D sym->cfunc =3D sym; - return 0; } =20 @@ -695,7 +696,7 @@ static int read_symbols(struct elf *elf) char *pname; size_t pnamelen; =20 - if (!sym->cold) + if (sym->pfunc) continue; =20 coldstr =3D strstr(sym->name, ".cold"); diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 3abe4cbc584c..82b9fb05af26 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -83,7 +83,6 @@ struct symbol { u8 frame_pointer : 1; u8 ignore : 1; u8 nocfi : 1; - u8 cold : 1; u8 prefix : 1; u8 debug_checksum : 1; u8 changed : 1; @@ -289,6 +288,11 @@ static inline bool is_prefix_func(struct symbol *sym) return sym->prefix; } =20 +static inline bool is_cold_func(struct symbol *sym) +{ + return sym->pfunc !=3D sym; +} + static inline bool is_reloc_sec(struct section *sec) { return sec->sh.sh_type =3D=3D SHT_RELA || sec->sh.sh_type =3D=3D SHT_REL; diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 1951a8b2df44..266f0d2ba4fe 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -1718,7 +1718,8 @@ static int create_klp_sections(struct elfs *e) unsigned long sympos; void *func_data; =20 - if (!is_func_sym(sym) || sym->cold || !sym->clone || !sym->clone->change= d) + if (!is_func_sym(sym) || is_cold_func(sym) || + !sym->clone || !sym->clone->changed) continue; =20 /* allocate klp_func_ext */ --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5079B3CD8BE; Thu, 23 Apr 2026 04:04:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917080; cv=none; b=r2Axg0Iv3ZUVFj11QXMtTpzbha56OmaaKvMV7FRpvO4V3KzU6n9inbMyuf24q31R62q+T1ue7XhkdV3x9rdmQmKnd3l2emAv+wDy1KzsDatxran0WxizQYXWOwQXHRrmoNETzeWaJQyCbPV/ynpTNd9PHJigr8IW3be7ukisEa4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917080; c=relaxed/simple; bh=QpN3wZEF3XEi04wYPc8WrluAdlGjdrfTiO9Mcvdilu0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gE617/OPrUGnljpvMIm0lE7LjNsfLziq1jn6YzSswDfLXoZfKmXO4S/WkoJ/Rnn+Du7GToVbXd8Apl3vVOJoDaBdv6WkIvEaEbdm5QOziTaFqgBy8wbdc/8GfQlVafgJwItOSPyIozs9ZohEP2y1FHZDNUIs8L/2l3rPcKBg/aE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Yj8xm7qf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Yj8xm7qf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC620C2BCB8; Thu, 23 Apr 2026 04:04:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917080; bh=QpN3wZEF3XEi04wYPc8WrluAdlGjdrfTiO9Mcvdilu0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yj8xm7qf9s682URxqg+h2lbJviHosIXvBNvCFb5joxskXGd5Ym29EobPFazH6PbC/ KsoagM5k1DkT78WWkp6u4siJ/nx3f+LptAMGMwnoNfLnfX0xUiGSIyv6uBD7JW/x4+ DbbRsD4QXAOLcO2Q0EBsbyKSYf6r+ZgrATmmCuVmJ65YU7yNSTHWI9ch2Y4lkPB4PC Ph/rRgsyoFkKf39qw22A+Ib7qFMWTS6ojOj6BkhwMjmzveApZ29YjjnLV+0HY3/1yl YhMF/9F2JOkJ2QYCsa0cYwVLKyyJu7Ys3vKqDEn/zIi3p8NdsVty1QyWnB/c3WzAMc DpJGYVAvEAK6g== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 33/48] objtool/klp: Extricate checksum calculation from validate_branch() Date: Wed, 22 Apr 2026 21:04:01 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation for porting the checksum code to other arches, make its functionality independent from the CFG reverse engineering code. Move it into a standalone calculate_checksums() function which iterates all functions and instructions directly, rather than being called inline from do_validate_branch(). Since checksum_update_insn() is no longer called during CFG traversal, it needs to manually iterate the alternatives. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu --- tools/objtool/check.c | 106 +++++++++++++++++------ tools/objtool/include/objtool/checksum.h | 6 +- 2 files changed, 80 insertions(+), 32 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 4ed27c53c718..c8208caa4b2c 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1350,10 +1350,7 @@ static struct reloc *insn_reloc(struct objtool_file = *file, struct instruction *i { struct reloc *reloc; =20 - if (insn->no_reloc) - return NULL; - - if (!file) + if (!file || insn->no_reloc || insn->fake) return NULL; =20 reloc =3D find_reloc_by_dest_range(file->elf, insn->sec, @@ -2622,9 +2619,17 @@ static void mark_holes(struct objtool_file *file) =20 static bool validate_branch_enabled(void) { - return opts.stackval || - opts.orc || - opts.uaccess || + return opts.stackval || + opts.orc || + opts.uaccess; +} + +static bool alts_needed(void) +{ + return validate_branch_enabled() || + opts.noinstr || + opts.hack_jump_label || + opts.disas || opts.checksum; } =20 @@ -2658,7 +2663,7 @@ static int decode_sections(struct objtool_file *file) * Must be before add_jump_destinations(), which depends on 'func' * being set for alternatives, to enable proper sibling call detection. */ - if (validate_branch_enabled() || opts.noinstr || opts.hack_jump_label || = opts.disas) { + if (alts_needed()) { if (add_special_section_alts(file)) return -1; } @@ -3654,6 +3659,7 @@ static bool skip_alt_group(struct instruction *insn) return alt_insn->type =3D=3D INSN_CLAC || alt_insn->type =3D=3D INSN_STAC; } =20 +#ifdef BUILD_KLP static void enable_debug_checksum_cb(struct symbol *sym, void *d) { bool *found =3D d; @@ -3705,8 +3711,10 @@ static void checksum_update_insn(struct objtool_file= *file, struct symbol *func, struct instruction *insn) { struct reloc *reloc =3D insn_reloc(file, insn); + struct alternative *alt; unsigned long offset; struct symbol *sym; + static bool in_alt; =20 if (insn->fake) return; @@ -3719,7 +3727,7 @@ static void checksum_update_insn(struct objtool_file = *file, struct symbol *func, if (call_dest) checksum_update(func, insn, call_dest->demangled_name, strlen(call_dest->demangled_name)); - return; + goto alts; } =20 sym =3D reloc->sym; @@ -3730,21 +3738,78 @@ static void checksum_update_insn(struct objtool_fil= e *file, struct symbol *func, =20 str =3D sym->sec->data->d_buf + sym->offset + offset; checksum_update(func, insn, str, strlen(str)); - return; + goto alts; } =20 if (is_sec_sym(sym)) { sym =3D find_symbol_containing(reloc->sym->sec, offset); if (!sym) - return; + goto alts; =20 offset -=3D sym->offset; } =20 checksum_update(func, insn, sym->demangled_name, strlen(sym->demangled_na= me)); checksum_update(func, insn, &offset, sizeof(offset)); + +alts: + for (alt =3D insn->alts; alt; alt =3D alt->next) { + struct alt_group *alt_group =3D alt->insn->alt_group; + + /* Prevent __ex_table recursion, e.g. LOAD_SEGMENT() */ + if (in_alt) + break; + in_alt =3D true; + + checksum_update(func, insn, &alt->type, sizeof(alt->type)); + + if (alt_group && alt_group->orig_group) { + struct instruction *alt_insn; + + checksum_update(func, insn, &alt_group->feature, sizeof(alt_group->feat= ure)); + + for (alt_insn =3D alt->insn; alt_insn; alt_insn =3D next_insn_same_sec(= file, alt_insn)) { + checksum_update_insn(file, func, alt_insn); + if (!alt_group->last_insn || alt_insn =3D=3D alt_group->last_insn) + break; + } + } else { + checksum_update_insn(file, func, alt->insn); + } + + in_alt =3D false; + } } =20 +static int calculate_checksums(struct objtool_file *file) +{ + struct instruction *insn; + struct symbol *func; + + if (checksum_debug_init(file)) + return -1; + + for_each_sym(file->elf, func) { + /* + * Skip cold subfunctions and aliases: they share the + * parent's checksum via func_for_each_insn() which + * follows func->cfunc into the cold subfunction. + */ + if (!is_func_sym(func) || is_cold_func(func) || + is_alias_sym(func) || !func->len) + continue; + + checksum_init(func); + + func_for_each_insn(file, func, insn) + checksum_update_insn(file, func, insn); + + checksum_finish(func); + } + return 0; +} +#endif /* BUILD_KLP */ + static int validate_branch(struct objtool_file *file, struct symbol *func, struct instruction *insn, struct insn_state state); static int do_validate_branch(struct objtool_file *file, struct symbol *fu= nc, @@ -4026,9 +4091,6 @@ static int do_validate_branch(struct objtool_file *fi= le, struct symbol *func, insn->trace =3D 0; next_insn =3D next_insn_to_validate(file, insn); =20 - if (opts.checksum && func && insn->sec) - checksum_update_insn(file, func, insn); - if (func && insn_func(insn) && func !=3D insn_func(insn)->pfunc) { /* Ignore KCFI type preambles, which always fall through */ if (is_prefix_func(func)) @@ -4094,9 +4156,6 @@ static int validate_unwind_hint(struct objtool_file *= file, struct symbol *func =3D insn_func(insn); int ret; =20 - if (opts.checksum) - checksum_init(func); - ret =3D validate_branch(file, func, insn, *state); if (ret) BT_INSN(insn, "<=3D=3D=3D (hint)"); @@ -4539,9 +4598,6 @@ static int validate_symbol(struct objtool_file *file,= struct section *sec, =20 func =3D insn_func(insn); =20 - if (opts.checksum) - checksum_init(func); - if (opts.trace && !fnmatch(opts.trace, sym->name, 0)) { trace_enable(); TRACE("%s: validation begin\n", sym->name); @@ -4554,9 +4610,6 @@ static int validate_symbol(struct objtool_file *file,= struct section *sec, TRACE("%s: validation %s\n\n", sym->name, ret ? "failed" : "end"); trace_disable(); =20 - if (opts.checksum) - checksum_finish(func); - return ret; } =20 @@ -5011,10 +5064,6 @@ int check(struct objtool_file *file) cfi_hash_add(&init_cfi); cfi_hash_add(&func_cfi); =20 - ret =3D checksum_debug_init(file); - if (ret) - goto out; - ret =3D decode_sections(file); if (ret) goto out; @@ -5105,6 +5154,9 @@ int check(struct objtool_file *file) warnings +=3D check_abs_references(file); =20 if (opts.checksum) { + ret =3D calculate_checksums(file); + if (ret) + goto out; ret =3D create_sym_checksum_section(file); if (ret) goto out; diff --git a/tools/objtool/include/objtool/checksum.h b/tools/objtool/inclu= de/objtool/checksum.h index 0bd16fe9168b..3f25df90305d 100644 --- a/tools/objtool/include/objtool/checksum.h +++ b/tools/objtool/include/objtool/checksum.h @@ -33,11 +33,7 @@ static inline void checksum_finish(struct symbol *func) =20 #else /* !BUILD_KLP */ =20 -static inline void checksum_init(struct symbol *func) {} -static inline void checksum_update(struct symbol *func, - struct instruction *insn, - const void *data, size_t size) {} -static inline void checksum_finish(struct symbol *func) {} +static inline int calculate_checksums(struct objtool_file *file) { return = -ENOSYS; } =20 #endif /* !BUILD_KLP */ =20 --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21BCD3DB65C; Thu, 23 Apr 2026 04:04:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917081; cv=none; b=Flm6UQHlHNRFQhbpgP+s1jEeACnns0GZNnqWI4M2cDkqs2REDr2bA7AOkci0ai9qNkcrdFUoo8h4Ko1ZlK2uWeFDS+mqychb4L9kuR/Efs2psRhTy5hs3dE5gkROP6BVrjSvnl6Voy/4WrqjVf3ShbLbcbg79n/p61U94ppYkVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917081; c=relaxed/simple; bh=kwelDbqX8+gKK6dbL+lWyI5iAhkQ0lkBTLIv2bxDSQQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S0iAuWiHHCJUndsxQYH9vGBTNRZTDl4nxNXRmP1yvm8edtWaqCVcDAi4xijKkObzyp8rDaj5tiUPkUV3jeK8WuCXjrRRoO27uDv6xpY1VYTwo5R3PTbt97wd5EwzoHufFh8yoUXr5yfgCpDZA5d/Yo/DVAO42v3DqfuZneUhB9o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BwoG2ZMD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BwoG2ZMD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E2CEC2BCB2; Thu, 23 Apr 2026 04:04:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917080; bh=kwelDbqX8+gKK6dbL+lWyI5iAhkQ0lkBTLIv2bxDSQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BwoG2ZMDfvZcKFKOY5T087PGCTED4dTs6Mm1wSEgU0LvfrE6S7K61vokrKzA8C5er A4PKpfWBKcKWOJsspMy/w64JRDSFy/Zormb0tkrDheUP40fy3WFvr+J8fWbNCYaLao ESQCC44PlFGoJCZgeZYYU5ocnB8HTk5idbJ4xdiUfpSwf2c/P69NI9yaNbKRetqsvg IgXuROd6cNej3bDcY9+VJTbtlBZIAr80xb0cxzQtlpd3XabLuMdIWbiQ+0zyl8FRdD ZvINGtcaOTvPQ3RznDIIQWIiBXRlrcwlV1tBDvM+NdGaOMZcd/7izAh2POuahuxSd8 qXsUauhTXlzWw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 34/48] objtool: Consolidate file decoding into decode_file() Date: Wed, 22 Apr 2026 21:04:02 -0700 Message-ID: <1b6557569cbdf893b832c37ba16dafaf69f9c3f6.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" decode_sections() relies on CFI and cfi_hash initialization done separately in check(), making it unusable outside of check(). Consolidate the initialization into decode_sections() and rename it to decode_file(), and make it global along with free_insns() and insn_reloc() for use by other objtool components -- namely, the checksum code which will be moving to another file. Signed-off-by: Josh Poimboeuf Acked-by: Peter Zijlstra (Intel) Acked-by: Song Liu --- tools/objtool/check.c | 36 +++++++++++++-------------- tools/objtool/include/objtool/check.h | 5 ++++ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index c8208caa4b2c..17cb9265973d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1346,7 +1346,7 @@ __weak bool arch_is_embedded_insn(struct symbol *sym) return false; } =20 -static struct reloc *insn_reloc(struct objtool_file *file, struct instruct= ion *insn) +struct reloc *insn_reloc(struct objtool_file *file, struct instruction *in= sn) { struct reloc *reloc; =20 @@ -2633,8 +2633,21 @@ static bool alts_needed(void) opts.checksum; } =20 -static int decode_sections(struct objtool_file *file) +int decode_file(struct objtool_file *file) { + arch_initial_func_cfi_state(&initial_func_cfi); + init_cfi_state(&init_cfi); + init_cfi_state(&func_cfi); + set_func_state(&func_cfi); + init_cfi_state(&force_undefined_cfi); + force_undefined_cfi.force_undefined =3D true; + + if (!cfi_hash_alloc(1UL << (file->elf->symbol_bits - 3))) + return -1; + + cfi_hash_add(&init_cfi); + cfi_hash_add(&func_cfi); + file->klp =3D is_livepatch_module(file); =20 mark_rodata(file); @@ -5002,7 +5015,7 @@ struct insn_chunk { * which can trigger more allocations for .debug_* sections whose data has= n't * been read yet. */ -static void free_insns(struct objtool_file *file) +void free_insns(struct objtool_file *file) { struct instruction *insn; struct insn_chunk *chunks =3D NULL, *chunk; @@ -5049,22 +5062,7 @@ int check(struct objtool_file *file) objtool_disas_ctx =3D disas_ctx; } =20 - arch_initial_func_cfi_state(&initial_func_cfi); - init_cfi_state(&init_cfi); - init_cfi_state(&func_cfi); - set_func_state(&func_cfi); - init_cfi_state(&force_undefined_cfi); - force_undefined_cfi.force_undefined =3D true; - - if (!cfi_hash_alloc(1UL << (file->elf->symbol_bits - 3))) { - ret =3D -1; - goto out; - } - - cfi_hash_add(&init_cfi); - cfi_hash_add(&func_cfi); - - ret =3D decode_sections(file); + ret =3D decode_file(file); if (ret) goto out; =20 diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index 5f2f77bd9b41..6489e52ea2f2 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -155,6 +155,11 @@ struct instruction *next_insn_same_sec(struct objtool_= file *file, struct instruc insn && insn->offset < sym->offset + sym->len; \ insn =3D next_insn_same_sec(file, insn)) =20 +struct reloc *insn_reloc(struct objtool_file *file, struct instruction *in= sn); + +int decode_file(struct objtool_file *file); +void free_insns(struct objtool_file *file); + const char *objtool_disas_insn(struct instruction *insn); =20 extern size_t sym_name_max_len; --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B40093DBD5A; Thu, 23 Apr 2026 04:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917081; cv=none; b=pqHoDT0qFfiFGk2jFkMmtFM50qgSIsfIXPo5t4Wxg420ZMqHhxcT5DI7jPWbESu5opP3k8Bnt4d9HuFyGqjF7NBCVZV1DA60mVdHHnpjuooEPAMfqGLJAgU1Wh58RA2D/DBAe3KNUvYpEUBJHZR7jSAMNJdBi6asIJBIZv/17Xo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917081; c=relaxed/simple; bh=nXjO5KQLtOifVVfeV6Y4aDKneTABOfZLjYSzsIkufG4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lB/5Au6f2MYqkv+msDe3+g0g7JlxzZulCpuQ60ocrh4ONSPpkcXv9ZybwZLsKlCTqowsrh7VoTnJS/iiBH5NBm/GpIbG2PhxTylVLNLGKuEKpZ+Ar1LDoEWRZVRUHIY1VoxiR1UTd5Imu2WzOV5kTV+IF3VcDuD/wEk8j1OPcbg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YQ7kORIx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YQ7kORIx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 080BAC2BCB5; Thu, 23 Apr 2026 04:04:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917081; bh=nXjO5KQLtOifVVfeV6Y4aDKneTABOfZLjYSzsIkufG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YQ7kORIxhrANejo4a9cmGDtLmNSVm5X0uTBTwkPxFqRlCN+rDT9Qv3hsN0LEk99G5 ShULYYqsx5SQPKna+bw0IGPaGLBGosKmgdh1X0TbsyxRqRbMN9ToPwem3/tscHohrR +rcNXwKhput22FoMTrfAhdXTKvWTAPIJT8CeBXNIpShXL0+dPl+99yvucnspmfohBF H9VCck/dFesDnC78IFSYqBGczSEfGgUHMqky3iPVsFjG/BhRkrhmTRG/dEpLmlK6se gsZcKeqHz203CtlzL2Fpb9F1Lq/wsLZlqQTpxOYiN4tdEGEEjlflBQf887py8/hp7P kG6colNIbXyyQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 35/48] objtool/klp: Add "objtool klp checksum" subcommand Date: Wed, 22 Apr 2026 21:04:03 -0700 Message-ID: <29304d60b4b4949720e3e5a5e6f26196bc29fa07.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the checksum functionality out of the main objtool command into a new "objtool klp checksum" subcommand. This has the benefit of making the code (and the patch generation process itself) more modular. For bisectability, both "objtool --checksum" and "objtool klp checksum" work for now. The former will be removed after klp-build has been converted to use the new subcommand. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu --- tools/objtool/Build | 2 +- tools/objtool/builtin-klp.c | 1 + tools/objtool/check.c | 209 +----------------- tools/objtool/include/objtool/check.h | 6 + tools/objtool/include/objtool/checksum.h | 4 + tools/objtool/include/objtool/klp.h | 1 + tools/objtool/klp-checksum.c | 257 +++++++++++++++++++++++ tools/objtool/klp-diff.c | 2 +- 8 files changed, 273 insertions(+), 209 deletions(-) create mode 100644 tools/objtool/klp-checksum.c diff --git a/tools/objtool/Build b/tools/objtool/Build index 600da051af12..93a37b0dfd31 100644 --- a/tools/objtool/Build +++ b/tools/objtool/Build @@ -12,7 +12,7 @@ objtool-$(BUILD_DISAS) +=3D disas.o objtool-$(BUILD_DISAS) +=3D trace.o =20 objtool-$(BUILD_ORC) +=3D orc_gen.o orc_dump.o -objtool-$(BUILD_KLP) +=3D builtin-klp.o klp-diff.o klp-post-link.o +objtool-$(BUILD_KLP) +=3D builtin-klp.o klp-checksum.o klp-diff.o klp-post= -link.o =20 objtool-y +=3D libstring.o objtool-y +=3D libctype.o diff --git a/tools/objtool/builtin-klp.c b/tools/objtool/builtin-klp.c index 56d5a5b92f72..58c3b9bda3eb 100644 --- a/tools/objtool/builtin-klp.c +++ b/tools/objtool/builtin-klp.c @@ -13,6 +13,7 @@ struct subcmd { }; =20 static struct subcmd subcmds[] =3D { + { "checksum", "Generate per-function checksums", cmd_klp_checksum, }, { "diff", "Generate binary diff of two object files", cmd_klp_diff, }, { "post-link", "Finalize klp symbols/relocs after module linking", cmd_k= lp_post_link, }, }; diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 17cb9265973d..3e5d335d0e29 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -64,8 +64,8 @@ struct instruction *next_insn_same_sec(struct objtool_fil= e *file, return insn; } =20 -static struct instruction *next_insn_same_func(struct objtool_file *file, - struct instruction *insn) +struct instruction *next_insn_same_func(struct objtool_file *file, + struct instruction *insn) { struct instruction *next =3D next_insn_same_sec(file, insn); struct symbol *func =3D insn_func(insn); @@ -113,10 +113,6 @@ static struct instruction *prev_insn_same_sym(struct o= bjtool_file *file, for_each_sec(file->elf, __sec) \ sec_for_each_insn(file, __sec, insn) =20 -#define func_for_each_insn(file, func, insn) \ - for (insn =3D find_insn(file, func->sec, func->offset); \ - insn; \ - insn =3D next_insn_same_func(file, insn)) =20 #define sym_for_each_insn(file, sym, insn) \ for (insn =3D find_insn(file, sym->sec, sym->offset); \ @@ -1023,56 +1019,6 @@ static int create_direct_call_sections(struct objtoo= l_file *file) return 0; } =20 -#ifdef BUILD_KLP -static int create_sym_checksum_section(struct objtool_file *file) -{ - struct section *sec; - struct symbol *sym; - unsigned int idx =3D 0; - struct sym_checksum *checksum; - size_t entsize =3D sizeof(struct sym_checksum); - - sec =3D find_section_by_name(file->elf, ".discard.sym_checksum"); - if (sec) { - if (!opts.dryrun) - WARN("file already has .discard.sym_checksum section, skipping"); - - return 0; - } - - for_each_sym(file->elf, sym) - if (sym->csum.checksum) - idx++; - - sec =3D elf_create_section_pair(file->elf, ".discard.sym_checksum", entsi= ze, - idx, idx); - if (!sec) - return -1; - - idx =3D 0; - for_each_sym(file->elf, sym) { - if (!sym->csum.checksum) - continue; - - if (!elf_init_reloc(file->elf, sec->rsec, idx, idx * entsize, - sym, 0, R_TEXT64)) - return -1; - - checksum =3D (struct sym_checksum *)sec->data->d_buf + idx; - checksum->addr =3D 0; /* reloc */ - checksum->checksum =3D sym->csum.checksum; - - mark_sec_changed(file->elf, sec, true); - - idx++; - } - - return 0; -} -#else -static int create_sym_checksum_section(struct objtool_file *file) { return= -EINVAL; } -#endif - /* * Warnings shouldn't be reported for ignored functions. */ @@ -3672,157 +3618,6 @@ static bool skip_alt_group(struct instruction *insn) return alt_insn->type =3D=3D INSN_CLAC || alt_insn->type =3D=3D INSN_STAC; } =20 -#ifdef BUILD_KLP -static void enable_debug_checksum_cb(struct symbol *sym, void *d) -{ - bool *found =3D d; - - if (!is_func_sym(sym)) - return; - - sym->debug_checksum =3D 1; - *found =3D true; -} - -static int checksum_debug_init(struct objtool_file *file) -{ - char *dup, *s; - - if (!opts.debug_checksum) - return 0; - - dup =3D strdup(opts.debug_checksum); - if (!dup) { - ERROR_GLIBC("strdup"); - return -1; - } - - s =3D dup; - while (*s) { - bool found =3D false; - char *comma; - - comma =3D strchr(s, ','); - if (comma) - *comma =3D '\0'; - - iterate_sym_by_name(file->elf, s, enable_debug_checksum_cb, &found); - if (!found) - WARN("--debug-checksum: can't find '%s'", s); - - if (!comma) - break; - - s =3D comma + 1; - } - - free(dup); - return 0; -} - -static void checksum_update_insn(struct objtool_file *file, struct symbol = *func, - struct instruction *insn) -{ - struct reloc *reloc =3D insn_reloc(file, insn); - struct alternative *alt; - unsigned long offset; - struct symbol *sym; - static bool in_alt; - - if (insn->fake) - return; - - checksum_update(func, insn, insn->sec->data->d_buf + insn->offset, insn->= len); - - if (!reloc) { - struct symbol *call_dest =3D insn_call_dest(insn); - - if (call_dest) - checksum_update(func, insn, call_dest->demangled_name, - strlen(call_dest->demangled_name)); - goto alts; - } - - sym =3D reloc->sym; - offset =3D arch_insn_adjusted_addend(insn, reloc); - - if (is_string_sec(sym->sec)) { - char *str; - - str =3D sym->sec->data->d_buf + sym->offset + offset; - checksum_update(func, insn, str, strlen(str)); - goto alts; - } - - if (is_sec_sym(sym)) { - sym =3D find_symbol_containing(reloc->sym->sec, offset); - if (!sym) - goto alts; - - offset -=3D sym->offset; - } - - checksum_update(func, insn, sym->demangled_name, strlen(sym->demangled_na= me)); - checksum_update(func, insn, &offset, sizeof(offset)); - -alts: - for (alt =3D insn->alts; alt; alt =3D alt->next) { - struct alt_group *alt_group =3D alt->insn->alt_group; - - /* Prevent __ex_table recursion, e.g. LOAD_SEGMENT() */ - if (in_alt) - break; - in_alt =3D true; - - checksum_update(func, insn, &alt->type, sizeof(alt->type)); - - if (alt_group && alt_group->orig_group) { - struct instruction *alt_insn; - - checksum_update(func, insn, &alt_group->feature, sizeof(alt_group->feat= ure)); - - for (alt_insn =3D alt->insn; alt_insn; alt_insn =3D next_insn_same_sec(= file, alt_insn)) { - checksum_update_insn(file, func, alt_insn); - if (!alt_group->last_insn || alt_insn =3D=3D alt_group->last_insn) - break; - } - } else { - checksum_update_insn(file, func, alt->insn); - } - - in_alt =3D false; - } -} - -static int calculate_checksums(struct objtool_file *file) -{ - struct instruction *insn; - struct symbol *func; - - if (checksum_debug_init(file)) - return -1; - - for_each_sym(file->elf, func) { - /* - * Skip cold subfunctions and aliases: they share the - * parent's checksum via func_for_each_insn() which - * follows func->cfunc into the cold subfunction. - */ - if (!is_func_sym(func) || is_cold_func(func) || - is_alias_sym(func) || !func->len) - continue; - - checksum_init(func); - - func_for_each_insn(file, func, insn) - checksum_update_insn(file, func, insn); - - checksum_finish(func); - } - return 0; -} -#endif /* BUILD_KLP */ - static int validate_branch(struct objtool_file *file, struct symbol *func, struct instruction *insn, struct insn_state state); static int do_validate_branch(struct objtool_file *file, struct symbol *fu= nc, diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index 6489e52ea2f2..eea64728d39b 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -144,6 +144,12 @@ struct instruction *find_insn(struct objtool_file *fil= e, struct section *sec, unsigned long offset); =20 struct instruction *next_insn_same_sec(struct objtool_file *file, struct i= nstruction *insn); +struct instruction *next_insn_same_func(struct objtool_file *file, struct = instruction *insn); + +#define func_for_each_insn(file, func, insn) \ + for (insn =3D find_insn(file, func->sec, func->offset); \ + insn; \ + insn =3D next_insn_same_func(file, insn)) =20 #define sec_for_each_insn(file, _sec, insn) \ for (insn =3D find_insn(file, _sec, 0); \ diff --git a/tools/objtool/include/objtool/checksum.h b/tools/objtool/inclu= de/objtool/checksum.h index 3f25df90305d..be4eb7dfe6f2 100644 --- a/tools/objtool/include/objtool/checksum.h +++ b/tools/objtool/include/objtool/checksum.h @@ -31,9 +31,13 @@ static inline void checksum_finish(struct symbol *func) } } =20 +int calculate_checksums(struct objtool_file *file); +int create_sym_checksum_section(struct objtool_file *file); + #else /* !BUILD_KLP */ =20 static inline int calculate_checksums(struct objtool_file *file) { return = -ENOSYS; } +static inline int create_sym_checksum_section(struct objtool_file *file) {= return -EINVAL; } =20 #endif /* !BUILD_KLP */ =20 diff --git a/tools/objtool/include/objtool/klp.h b/tools/objtool/include/ob= jtool/klp.h index e32e5e8bc631..6f60cf05db86 100644 --- a/tools/objtool/include/objtool/klp.h +++ b/tools/objtool/include/objtool/klp.h @@ -29,6 +29,7 @@ struct klp_reloc { u32 type; }; =20 +int cmd_klp_checksum(int argc, const char **argv); int cmd_klp_diff(int argc, const char **argv); int cmd_klp_post_link(int argc, const char **argv); =20 diff --git a/tools/objtool/klp-checksum.c b/tools/objtool/klp-checksum.c new file mode 100644 index 000000000000..4edd29028bff --- /dev/null +++ b/tools/objtool/klp-checksum.c @@ -0,0 +1,257 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static void enable_debug_checksum_cb(struct symbol *sym, void *d) +{ + bool *found =3D d; + + if (!is_func_sym(sym)) + return; + + sym->debug_checksum =3D 1; + *found =3D true; +} + +static int checksum_debug_init(struct objtool_file *file) +{ + char *dup, *s; + + if (!opts.debug_checksum) + return 0; + + dup =3D strdup(opts.debug_checksum); + if (!dup) { + ERROR_GLIBC("strdup"); + return -1; + } + + s =3D dup; + while (*s) { + bool found =3D false; + char *comma; + + comma =3D strchr(s, ','); + if (comma) + *comma =3D '\0'; + + iterate_sym_by_name(file->elf, s, enable_debug_checksum_cb, &found); + if (!found) + WARN("--debug-checksum: can't find '%s'", s); + + if (!comma) + break; + + s =3D comma + 1; + } + + free(dup); + return 0; +} + +static void checksum_update_insn(struct objtool_file *file, struct symbol = *func, + struct instruction *insn) +{ + struct reloc *reloc =3D insn_reloc(file, insn); + struct alternative *alt; + unsigned long offset; + struct symbol *sym; + static bool in_alt; + + if (insn->fake) + return; + + checksum_update(func, insn, insn->sec->data->d_buf + insn->offset, insn->= len); + + if (!reloc) { + struct symbol *call_dest =3D insn_call_dest(insn); + + if (call_dest) + checksum_update(func, insn, call_dest->demangled_name, + strlen(call_dest->demangled_name)); + goto alts; + } + + sym =3D reloc->sym; + offset =3D arch_insn_adjusted_addend(insn, reloc); + + if (is_string_sec(sym->sec)) { + char *str; + + str =3D sym->sec->data->d_buf + sym->offset + offset; + checksum_update(func, insn, str, strlen(str)); + goto alts; + } + + if (is_sec_sym(sym)) { + sym =3D find_symbol_containing(reloc->sym->sec, offset); + if (!sym) + goto alts; + + offset -=3D sym->offset; + } + + checksum_update(func, insn, sym->demangled_name, strlen(sym->demangled_na= me)); + checksum_update(func, insn, &offset, sizeof(offset)); + +alts: + for (alt =3D insn->alts; alt; alt =3D alt->next) { + struct alt_group *alt_group =3D alt->insn->alt_group; + + /* Prevent __ex_table recursion, e.g. LOAD_SEGMENT() */ + if (in_alt) + break; + in_alt =3D true; + + checksum_update(func, insn, &alt->type, sizeof(alt->type)); + + if (alt_group && alt_group->orig_group) { + struct instruction *alt_insn; + + checksum_update(func, insn, &alt_group->feature, sizeof(alt_group->feat= ure)); + + for (alt_insn =3D alt->insn; alt_insn; alt_insn =3D next_insn_same_sec(= file, alt_insn)) { + checksum_update_insn(file, func, alt_insn); + if (!alt_group->last_insn || alt_insn =3D=3D alt_group->last_insn) + break; + } + } else { + checksum_update_insn(file, func, alt->insn); + } + + in_alt =3D false; + } +} + +int calculate_checksums(struct objtool_file *file) +{ + struct instruction *insn; + struct symbol *func; + + if (checksum_debug_init(file)) + return -1; + + for_each_sym(file->elf, func) { + /* + * Skip cold subfunctions and aliases: they share the + * parent's checksum via func_for_each_insn() which + * follows func->cfunc into the cold subfunction. + */ + if (!is_func_sym(func) || is_cold_func(func) || + is_alias_sym(func) || !func->len) + continue; + + checksum_init(func); + + func_for_each_insn(file, func, insn) + checksum_update_insn(file, func, insn); + + checksum_finish(func); + } + return 0; +} + +int create_sym_checksum_section(struct objtool_file *file) +{ + struct section *sec; + struct symbol *sym; + unsigned int idx =3D 0; + struct sym_checksum *checksum; + size_t entsize =3D sizeof(struct sym_checksum); + + sec =3D find_section_by_name(file->elf, ".discard.sym_checksum"); + if (sec) { + if (!opts.dryrun) + WARN("file already has .discard.sym_checksum section, skipping"); + + return 0; + } + + for_each_sym(file->elf, sym) + if (sym->csum.checksum) + idx++; + + sec =3D elf_create_section_pair(file->elf, ".discard.sym_checksum", entsi= ze, + idx, idx); + if (!sec) + return -1; + + idx =3D 0; + for_each_sym(file->elf, sym) { + if (!sym->csum.checksum) + continue; + + if (!elf_init_reloc(file->elf, sec->rsec, idx, idx * entsize, + sym, 0, R_TEXT64)) + return -1; + + checksum =3D (struct sym_checksum *)sec->data->d_buf + idx; + checksum->addr =3D 0; /* reloc */ + checksum->checksum =3D sym->csum.checksum; + + mark_sec_changed(file->elf, sec, true); + + idx++; + } + + return 0; +} + +static const char * const klp_checksum_usage[] =3D { + "objtool klp checksum [] file.o", + NULL, +}; + +int cmd_klp_checksum(int argc, const char **argv) +{ + struct objtool_file *file; + int ret; + + const struct option options[] =3D { + OPT_STRING(0, "debug-checksum", &opts.debug_checksum, "funcs", "enable c= hecksum debug output"), + OPT_BOOLEAN(0, "dry-run", &opts.dryrun, "don't write modifications"), + OPT_END(), + }; + + argc =3D parse_options(argc, argv, options, klp_checksum_usage, 0); + if (argc !=3D 1) + usage_with_options(klp_checksum_usage, options); + + opts.checksum =3D true; + + objname =3D argv[0]; + + file =3D objtool_open_read(objname); + if (!file) + return 1; + + ret =3D decode_file(file); + if (ret) + goto out; + + ret =3D calculate_checksums(file); + if (ret) + goto out; + + ret =3D create_sym_checksum_section(file); + +out: + free_insns(file); + + if (ret) + return ret; + + if (!opts.dryrun && file->elf->changed && elf_write(file->elf)) + return 1; + + return elf_close(file->elf); +} diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 266f0d2ba4fe..c903aa65d4b6 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -171,7 +171,7 @@ static int read_sym_checksums(struct elf *elf) =20 sec =3D find_section_by_name(elf, ".discard.sym_checksum"); if (!sec) { - ERROR("'%s' missing .discard.sym_checksum section, file not processed by= 'objtool --checksum'?", + ERROR("'%s' missing .discard.sym_checksum section, file not processed by= 'objtool klp checksum'?", elf->name); return -1; } --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AAB13DBD6F; Thu, 23 Apr 2026 04:04:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917082; cv=none; b=bmqh+KIADlxg2eQ3MPNtULohiN77JfW3AoZCruLi0hOlUhenhWwwpGAJgp7tHOAvxMdJljYV6VfAjOGJhBQExRt4Vrw0WxzKagi3ShzNkUqKDTJ3AESD1rQJvhvbzK0rmhKchp9irx5yfvyU/OtugiM9/XKsOBQajfGqoisUl2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917082; c=relaxed/simple; bh=ljj6t8WcunUTkYwZXIS1IPUO1uAXy2ns4cJ5oZW9oe0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VCrfARWHzk6PUZeyUWsO+vM74G6oR0pzR1VygwBm7wxW8jsoiqMeuVxXpM90bq30TNk8sPHBrQyfPf3T4hf1u3BWQJi9EjSSfxgzYBNSDB2V7kRAVcxEtI8tbtehcv8XS7KcJhwCloPtG21BhdEx+WMplMxkCb1l9r2UwtZHOtU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IDRsGj10; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IDRsGj10" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD8E4C2BCB4; Thu, 23 Apr 2026 04:04:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917082; bh=ljj6t8WcunUTkYwZXIS1IPUO1uAXy2ns4cJ5oZW9oe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IDRsGj10Ic4KlG3tOpGPuT6x1EZkVPHLXS7rq23SvZBFz6h9TQho1mzFoCPhL4yVL ehZc2CJOROcfFaBCfU+lJT9zqrTnFa3D7I+zXX+a38SItxXRAGz5+EuiY96UJ0lWke HwRZdP2Ldx9K/GeLgHsMZQXRc2Hon4HuBpArnKOIg1BmrSsY/GPp/qsYPBMX0TrJlM R4oHNp3MhYe8w+RQJh5fSSTZmGU2oj2EmfmAEbIRnrxeo6svOF17HLRTVFyL4eMrhG FAkv317puxbp1schIU7VadcDIkX+qWbPutNP+dRWVGwj+esGSzqfZVIITbd8g1EnES wTTah4Gu6ymGg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 36/48] klp-build: Use "objtool klp checksum" subcommand Date: Wed, 22 Apr 2026 21:04:04 -0700 Message-ID: <99e40357ee24962b3514d9ce4f6e773eff3a15f3.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the new "objtool klp checksum" subcommand instead of injecting --checksum into every objtool invocation via OBJTOOL_ARGS during the kernel build. This decouples checksum generation from the build, running it in separate post-build passes, making the code (and the patch generation pipeline itself) more modular. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu --- scripts/livepatch/klp-build | 93 +++++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 29 deletions(-) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index 84053e8aadd3..d29ef3022556 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -39,10 +39,12 @@ OBJ=3D"$(pwd)" CONFIG=3D"$OBJ/.config" TMP_DIR=3D"$OBJ/klp-tmp" =20 -ORIG_DIR=3D"$TMP_DIR/orig" -PATCHED_DIR=3D"$TMP_DIR/patched" -DIFF_DIR=3D"$TMP_DIR/diff" -KMOD_DIR=3D"$TMP_DIR/kmod" +ORIG_DIR=3D"$TMP_DIR/1-orig" +PATCHED_DIR=3D"$TMP_DIR/2-patched" +ORIG_CSUM_DIR=3D"$TMP_DIR/3-checksum-orig" +PATCHED_CSUM_DIR=3D"$TMP_DIR/3-checksum-patched" +DIFF_DIR=3D"$TMP_DIR/4-diff" +KMOD_DIR=3D"$TMP_DIR/5-kmod" =20 STASH_DIR=3D"$TMP_DIR/stash" TIMESTAMP=3D"$TMP_DIR/timestamp" @@ -138,10 +140,11 @@ Options: Advanced Options: -d, --debug Show symbol/reloc cloning decisions -S, --short-circuit=3DSTEP Start at build step (requires prior --keep-t= mp) - 1|orig Build original kernel (default) - 2|patched Build patched kernel - 3|diff Diff objects - 4|kmod Build patch module + 1|orig Build original kernel (default) + 2|patched Build patched kernel + 3|checksum Generate checksums + 4|diff Diff objects + 5|kmod Build patch module -T, --keep-tmp Preserve tmp dir on exit =20 EOF @@ -205,10 +208,11 @@ process_args() { [[ ! -d "$TMP_DIR" ]] && die "--short-circuit requires preserved klp-t= mp dir" keep_tmp=3D1 case "$2" in - 1 | orig) SHORT_CIRCUIT=3D1; ;; - 2 | patched) SHORT_CIRCUIT=3D2; ;; - 3 | diff) SHORT_CIRCUIT=3D3; ;; - 4 | mod) SHORT_CIRCUIT=3D4; ;; + 1 | orig) SHORT_CIRCUIT=3D1; ;; + 2 | patched) SHORT_CIRCUIT=3D2; ;; + 3 | checksum) SHORT_CIRCUIT=3D3; ;; + 4 | diff) SHORT_CIRCUIT=3D4; ;; + 5 | kmod) SHORT_CIRCUIT=3D5; ;; *) die "invalid short-circuit step '$2'" ;; esac shift 2 @@ -519,11 +523,8 @@ clean_kernel() { build_kernel() { local build=3D"$1" local log=3D"$TMP_DIR/build.log" - local objtool_args=3D() local cmd=3D() =20 - objtool_args=3D("--checksum") - cmd=3D("make") =20 # When a patch to a kernel module references a newly created unexported @@ -550,7 +551,6 @@ build_kernel() { fi cmd+=3D("-j$JOBS") cmd+=3D("KCFLAGS=3D-ffunction-sections -fdata-sections") - cmd+=3D("OBJTOOL_ARGS=3D${objtool_args[*]}") cmd+=3D("vmlinux") cmd+=3D("modules") =20 @@ -582,7 +582,7 @@ copy_orig_objects() { =20 find_objects | mapfile -t files =20 - xtrace_save "copying orig objects" + xtrace_save "copying original objects" for _file in "${files[@]}"; do local rel_file=3D"${_file/.ko/.o}" local file=3D"$OBJ/$rel_file" @@ -638,6 +638,35 @@ copy_patched_objects() { mv -f "$TMP_DIR/build.log" "$PATCHED_DIR" } =20 +# Copy .o files to a separate directory and run "objtool klp checksum" on = each +# copy. The checksums are written to a .discard.sym_checksum section. +# +# If match_dir is given, only process files which also exist there. +generate_checksums() { + local src_dir=3D"$1" + local dest_dir=3D"$2" + local match_dir=3D"${3:-}" + local files=3D() + local file + + rm -rf "$dest_dir" + mkdir -p "$dest_dir" + + find "$src_dir" -type f -name "*.o" | mapfile -t files + for file in "${files[@]}"; do + local rel=3D"${file#"$src_dir"/}" + local dest=3D"$dest_dir/$rel" + + [[ -n "$match_dir" && ! -f "$match_dir/$rel" ]] && continue + + mkdir -p "$(dirname "$dest")" + cp -f "$file" "$dest" + "$SRC/tools/objtool/objtool" klp checksum "$dest" + done + + touch "$dest_dir/.complete" +} + # Diff changed objects, writing output object to $DIFF_DIR diff_objects() { local log=3D"$KLP_DIFF_LOG" @@ -647,16 +676,16 @@ diff_objects() { rm -rf "$DIFF_DIR" mkdir -p "$DIFF_DIR" =20 - find "$PATCHED_DIR" -type f -name "*.o" | mapfile -t files + find "$PATCHED_CSUM_DIR" -type f -name "*.o" | mapfile -t files [[ ${#files[@]} -eq 0 ]] && die "no changes detected" =20 [[ -v DEBUG_CLONE ]] && opts=3D("--debug") =20 # Diff all changed objects for file in "${files[@]}"; do - local rel_file=3D"${file#"$PATCHED_DIR"/}" + local rel_file=3D"${file#"$PATCHED_CSUM_DIR"/}" local orig_file=3D"$rel_file" - local patched_file=3D"$PATCHED_DIR/$rel_file" + local patched_file=3D"$PATCHED_CSUM_DIR/$rel_file" local out_file=3D"$DIFF_DIR/$rel_file" local filter=3D() local cmd=3D() @@ -680,7 +709,7 @@ diff_objects() { fi =20 ( - cd "$ORIG_DIR" + cd "$ORIG_CSUM_DIR" [[ -v VERBOSE ]] && echo "${cmd[@]}" "${cmd[@]}" \ 1> >(tee -a "$log") \ @@ -690,9 +719,9 @@ diff_objects() { done } =20 -# For each changed object, run objtool with --debug-checksum to get the -# per-instruction checksums, and then diff those to find the first changed -# instruction for each function. +# For each changed object, run "objtool klp checksum" with --debug-checksu= m to +# get the per-instruction checksums, and then diff those to find the first +# changed instruction for each function. diff_checksums() { local orig_log=3D"$ORIG_DIR/checksum.log" local patched_log=3D"$PATCHED_DIR/checksum.log" @@ -717,8 +746,7 @@ diff_checksums() { done =20 cmd=3D("$SRC/tools/objtool/objtool") - cmd+=3D("--checksum") - cmd+=3D("--link") + cmd+=3D("klp" "checksum") cmd+=3D("--dry-run") =20 for file in "${!funcs[@]}"; do @@ -727,11 +755,11 @@ diff_checksums() { ( cd "$ORIG_DIR" "${cmd[@]}" "$opt" "$file" &> "$orig_log" || \ - ( cat "$orig_log" >&2; die "objtool --debug-checksum failed" ) + ( cat "$orig_log" >&2; die "objtool klp checksum failed" ) =20 cd "$PATCHED_DIR" "${cmd[@]}" "$opt" "$file" &> "$patched_log" || \ - ( cat "$patched_log" >&2; die "objtool --debug-checksum failed" ) + ( cat "$patched_log" >&2; die "objtool klp checksum failed" ) ) =20 for func in ${funcs[$file]}; do @@ -872,6 +900,13 @@ if (( SHORT_CIRCUIT <=3D 2 )); then fi =20 if (( SHORT_CIRCUIT <=3D 3 )); then + status "Generating original checksums" + generate_checksums "$ORIG_DIR" "$ORIG_CSUM_DIR" "$PATCHED_DIR" + status "Generating patched checksums" + generate_checksums "$PATCHED_DIR" "$PATCHED_CSUM_DIR" +fi + +if (( SHORT_CIRCUIT <=3D 4 )); then status "Diffing objects" diff_objects if [[ -v DIFF_CHECKSUM ]]; then @@ -880,7 +915,7 @@ if (( SHORT_CIRCUIT <=3D 3 )); then fi fi =20 -if (( SHORT_CIRCUIT <=3D 4 )); then +if (( SHORT_CIRCUIT <=3D 5 )); then status "Building patch module: $OUTFILE" build_patch_module fi --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA1783DC4B2; Thu, 23 Apr 2026 04:04:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917083; cv=none; b=pNLUY16PSJ3sF0VUJ22vfLIGy6JGWLirwfvvfpzLe4DV+fFRY+g5yJP/5onajijuCo5GYu3ybjjwnTvT3oCdpj5qT3ApZqiMFV9am6byBvoNifM+N32j50fYDyhP8WmLY0uoJcWEbvJKHb8CcVh96ApgX46fZQ80uVxEUr7BIKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917083; c=relaxed/simple; bh=Z/dFkGhk1xaKXkKBuoSU1geqYdPfgu4flSFr4FFNNM8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JRws19a3tHLjSu1C/zV3dljxGmstP4UIjVsiRgAbJcctLtqQUgfLuibj9M/4pMS7RKSZe+7w3PBS4gyJp+5Krg+v6hkK4tIwtddcMbtTwkBzO3My1TKYPmEgSi/1SoGZ+UOZ9AGq6x9L126HDXlzMCSWyF5zCJhpwFJlrY3QEnU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YrIxR+og; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YrIxR+og" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80641C2BCB5; Thu, 23 Apr 2026 04:04:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917082; bh=Z/dFkGhk1xaKXkKBuoSU1geqYdPfgu4flSFr4FFNNM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YrIxR+ogEYi571zaFj8Q7Vy4BaDx3CE/g4KPnqr9uzqxmMshzq/XtgrxBxQRuij7b 0tDJVeYe7mianxVcbuI2fyc7cuC71JfD0flaaTha2Hj8kKHOqgt7ANVg/5CK1xqnX2 boZS41iqwqYpY9WF4n96Fx7TT9ZUzUCtlqIZ2xyX0LhMHliWlG/n8UU7a+95DktJBq lMnIUFPxSH5mEVdx8OdSVJ6JjWbFxNgeah1B0J5BH26BCJyHq7fXHlKTgX71zaaOjQ si0Mdq/9OlxqOJj33whH7vDX89M+FfEKd1xLCVSKH7qrJceJ6Ql9mL9SAMQ4tfpOl7 GOZJSV6gKJz3A== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 37/48] objtool/klp: Remove "objtool --checksum" Date: Wed, 22 Apr 2026 21:04:05 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The checksum functionality has been moved to "objtool klp checksum" which is now used by klp-build. Remove the now-dead --checksum and --debug-checksum options from the default objtool command. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu --- scripts/livepatch/klp-build | 3 +++ tools/objtool/builtin-check.c | 17 +---------------- tools/objtool/check.c | 10 ---------- 3 files changed, 4 insertions(+), 26 deletions(-) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index d29ef3022556..eda690b297cc 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -277,6 +277,9 @@ validate_config() { [[ "$CONFIG_AS_VERSION" -lt 200000 ]] && \ die "Clang assembler version < 20 not supported" =20 + "$SRC/tools/objtool/objtool" klp 2>&1 | command grep -q "not implemented"= && \ + die "objtool not built with KLP support; install xxhash-devel/libxxhash-= dev (version >=3D 0.8) and recompile" + return 0 } =20 diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index b780df513715..ec7f10a5ef19 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -73,7 +73,6 @@ static int parse_hacks(const struct option *opt, const ch= ar *str, int unset) =20 static const struct option check_options[] =3D { OPT_GROUP("Actions:"), - OPT_BOOLEAN(0, "checksum", &opts.checksum, "generate per-function check= sums"), OPT_BOOLEAN(0, "cfi", &opts.cfi, "annotate kernel control flow integrit= y (kCFI) function preambles"), OPT_STRING_OPTARG('d', "disas", &opts.disas, "function-pattern", "disass= emble functions", "*"), OPT_CALLBACK_OPTARG('h', "hacks", NULL, NULL, "jump_label,noinstr,skylake= ", "patch toolchain bugs/limitations", parse_hacks), @@ -95,7 +94,6 @@ static const struct option check_options[] =3D { OPT_GROUP("Options:"), OPT_BOOLEAN(0, "backtrace", &opts.backtrace, "unwind on error"), OPT_BOOLEAN(0, "backup", &opts.backup, "create backup (.orig) file on w= arning/error"), - OPT_STRING(0, "debug-checksum", &opts.debug_checksum, "funcs", "enable= checksum debug output"), OPT_BOOLEAN(0, "dry-run", &opts.dryrun, "don't write modifications"), OPT_BOOLEAN(0, "link", &opts.link, "object is a linked object"), OPT_BOOLEAN(0, "module", &opts.module, "object is part of a kernel modu= le"), @@ -165,20 +163,7 @@ static bool opts_valid(void) return false; } =20 -#ifndef BUILD_KLP - if (opts.checksum) { - ERROR("--checksum not supported; install xxhash-devel/libxxhash-dev (ver= sion >=3D 0.8) and recompile"); - return false; - } -#endif - - if (opts.debug_checksum && !opts.checksum) { - ERROR("--debug-checksum requires --checksum"); - return false; - } - - if (opts.checksum || - opts.disas || + if (opts.disas || opts.hack_jump_label || opts.hack_noinstr || opts.ibt || diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 3e5d335d0e29..ae047be919c5 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -18,7 +18,6 @@ #include #include #include -#include #include =20 #include @@ -4946,15 +4945,6 @@ int check(struct objtool_file *file) if (opts.noabs) warnings +=3D check_abs_references(file); =20 - if (opts.checksum) { - ret =3D calculate_checksums(file); - if (ret) - goto out; - ret =3D create_sym_checksum_section(file); - if (ret) - goto out; - } - if (opts.orc && nr_insns) { ret =3D orc_create(file); if (ret) --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C325D3DC4D7; Thu, 23 Apr 2026 04:04:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917083; cv=none; b=AWtmoRulD+5vzlOXSNi6I8WokGnCLB7mhjKD5VxNco4rF+9ptMJxZsE+4VzsEWi25Jlg7ZEVbat6Yk0C/LkT4Z4PU8vDoWY5KAPo7j5XQxIQewCkRURDgZcxRKuhvq+uSdxabf85GYLnFcoVt2uoUctD+RG6vsVVXvc9PyvhEJQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917083; c=relaxed/simple; bh=pu/FDwgsFYcunTKMSHAiFW7k0utTyQ1Y/HhIEU5kLD8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gef7H1srOljz8i3fmApGwDbECKr9tU0ySMfByx5eLkRcAULPkTnlslNyp6tXzovul0ereaC5tR4BZgY4+cwKhN5TlavwQrM24RHbjfnVLtiMMsXtZupWr2I4VpHqArZW8d2V3hDv00+VSI6EwHfmA6Kihp/mraUpBiIUb7IUVXA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nZTuU3K3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nZTuU3K3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05612C2BCC4; Thu, 23 Apr 2026 04:04:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917083; bh=pu/FDwgsFYcunTKMSHAiFW7k0utTyQ1Y/HhIEU5kLD8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nZTuU3K3bwi2vviefcyLAlSKZwJjGC1BUgZiQZpzBgd2gADC11RARsh/t6DS+l0b7 ++rsuh1DBX6lgS5Pq4bCeNmM6wpf67lSdXFLw6G3PgUM5gXp5ts2So20tViXD0P4vr 0rlneApSEpHym3fs4ngPsASGSXVh2Pf1XWe+cAjNOrBsoyvlBAwTSe/0NZ2g2mifzY wzV42QxYXaaboEHPtk8X9D3yJw1bWZR9N0BTNCV0hTRBrxsu2ZhC2UbUp7MwjjDmXZ cw2yT4cmk+1Ss0J9Y+VJ3ZPu+5gFVfel9hdMh9r1g+JiKWVsF/92lJ9rYbwYjoWIBu xI2FFf8G1K6YQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 38/48] klp-build: Validate short-circuit prerequisites Date: Wed, 22 Apr 2026 21:04:06 -0700 Message-ID: <338295e0bf3353dd62536df672a2615f72be013b.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The --short-circuit option implicitly requires that certain directories are already in klp-tmp. Enforce that to prevent confusing errors. Signed-off-by: Josh Poimboeuf --- scripts/livepatch/klp-build | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index eda690b297cc..b44924d097a5 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -440,6 +440,20 @@ do_init() { [[ ! "$SRC" -ef "$SCRIPT_DIR/../.." ]] && die "please run from the kernel= root directory" [[ ! "$OBJ" -ef "$SCRIPT_DIR/../.." ]] && die "please run from the kernel= root directory" =20 + if (( SHORT_CIRCUIT >=3D 2 )); then + [[ -f "$ORIG_DIR/.complete" ]] || die "-S $SHORT_CIRCUIT requires comple= ted $ORIG_DIR" + if (( SHORT_CIRCUIT >=3D 3 )); then + [[ -f "$PATCHED_DIR/.complete" ]] || die "-S $SHORT_CIRCUIT requires co= mpleted $PATCHED_DIR" + if (( SHORT_CIRCUIT >=3D 4 )); then + [[ -f "$ORIG_CSUM_DIR/.complete" ]] || die "-S $SHORT_CIRCUIT requires= completed $ORIG_CSUM_DIR" + [[ -f "$PATCHED_CSUM_DIR/.complete" ]] || die "-S $SHORT_CIRCUIT requi= res completed $PATCHED_CSUM_DIR" + if (( SHORT_CIRCUIT >=3D 5 )); then + [[ -f "$DIFF_DIR/.complete" ]] || die "-S $SHORT_CIRCUIT requires com= pleted $DIFF_DIR" + fi + fi + fi + fi + (( SHORT_CIRCUIT <=3D 1 )) && rm -rf "$TMP_DIR" mkdir -p "$TMP_DIR" =20 @@ -601,6 +615,7 @@ copy_orig_objects() { =20 mv -f "$TMP_DIR/build.log" "$ORIG_DIR" touch "$TIMESTAMP" + touch "$ORIG_DIR/.complete" } =20 # Copy all changed objects to $PATCHED_DIR @@ -639,6 +654,7 @@ copy_patched_objects() { (( found =3D=3D 0 )) && die "no changes detected" =20 mv -f "$TMP_DIR/build.log" "$PATCHED_DIR" + touch "$PATCHED_DIR/.complete" } =20 # Copy .o files to a separate directory and run "objtool klp checksum" on = each @@ -720,6 +736,8 @@ diff_objects() { die "objtool klp diff failed" ) done + + touch "$DIFF_DIR/.complete" } =20 # For each changed object, run "objtool klp checksum" with --debug-checksu= m to --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 381913DCD81; Thu, 23 Apr 2026 04:04:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917084; cv=none; b=jLehWfi/dOu8BylVuBPoe4VYRVsqCvUFSJwui0SPSsFkrs/AOhbnU+B2K+1ttL3ZZvH3wLDt7PYVwcqAeMimxO36iuVXoxHUHncrBE7IPw1zEhMt1aLxIJQpuZY5cRYv6LTXbknQrs8fKKbvtC+Hv88FAvNtqXkuYhJaxHKD+EI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917084; c=relaxed/simple; bh=2w8CeG6pOvd1rlnM0WqP9uenooE/GJd9V/fFSVkUS7E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MS1uolsFztXhFrqc8lTX9HUy3hCnO/noWTUMwO9W5j1Ame4zY2ORs+H8OJXkW/rfNZrMb3ZNaOq2/6ag9ffyEdRepV3m9lzyYqK4fvCfmGgR0mzPtMAntIy3IIfxh/C0CAjuw+YlDgdq1rCR28b/CAC5zl5LKm7N09k2LYtbzk4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dsSoejWm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dsSoejWm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAE38C2BCB2; Thu, 23 Apr 2026 04:04:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917084; bh=2w8CeG6pOvd1rlnM0WqP9uenooE/GJd9V/fFSVkUS7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dsSoejWmlSmCA//um+LUJ88uf9VRQfFOq38cZX3PdaA6PVbi6Wy4kZ8g+fa2xAIHS bNV9uRlcQgYg/CDRdw5KWUXGZGpoIh/wx9fvvsAFFfTKS8xYK3VZ0//x+uqcM3phsh U07HWUzeF/z6HawjOuI+fkng42a4WBNkxq+5yniBdHfl4KB9qBDn61RJL3/7fvdtNY Zn/dWrdyJTPdldNCyV8J1vQ9r4/fObQP/xrOQKleKTt+Bru3OxHXb9mQ0XIKhm1HLW e9DpjdFY/xyEGOygu8Jp/rqtLIbRw87FDWnBLnurQcb1CiA5SCfN4Iv/3EHMfbAfZD Pfw6O4i3sSvuw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 39/48] objtool: Replace iterator callbacks with for_each_sym_by_*() Date: Wed, 22 Apr 2026 21:04:07 -0700 Message-ID: <03f7804ae62c5c4521053afc3f6a1c4a11bc85de.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Convert the callback-based iterate_sym_by_name() and iterate_sym_by_demangled_name() callers to use new for_each_sym_by[_demangled]_name() macros. This eliminates the callback structs and functions and makes the code more compact and readable. Signed-off-by: Josh Poimboeuf --- tools/objtool/elf.c | 80 ++++++----------------------- tools/objtool/include/objtool/elf.h | 40 ++++++++++++--- tools/objtool/klp-checksum.c | 20 +++----- tools/objtool/klp-diff.c | 42 +++++---------- 4 files changed, 73 insertions(+), 109 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 8a6e1338af97..8d823e96b7c9 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -27,27 +27,16 @@ =20 static ssize_t demangled_name_len(const char *name); =20 -static inline u32 str_hash(const char *str) -{ - return jhash(str, strlen(str), 0); -} - -static inline u32 str_hash_demangled(const char *str) +u32 str_hash_demangled(const char *str) { return jhash(str, demangled_name_len(str), 0); } =20 -#define __elf_table(name) (elf->name##_hash) -#define __elf_bits(name) (elf->name##_bits) - -#define __elf_table_entry(name, key) \ - __elf_table(name)[hash_min(key, __elf_bits(name))] - #define elf_hash_add(name, node, key) \ ({ \ struct elf_hash_node *__node =3D node; \ - __node->next =3D __elf_table_entry(name, key); \ - __elf_table_entry(name, key) =3D __node; \ + __node->next =3D __elf_table_entry(elf, name, key); \ + __elf_table_entry(elf, name, key) =3D __node; \ }) =20 static inline void __elf_hash_del(struct elf_hash_node *node, @@ -69,30 +58,20 @@ static inline void __elf_hash_del(struct elf_hash_node = *node, } =20 #define elf_hash_del(name, node, key) \ - __elf_hash_del(node, &__elf_table_entry(name, key)) - -#define elf_list_entry(ptr, type, member) \ -({ \ - typeof(ptr) __ptr =3D (ptr); \ - __ptr ? container_of(__ptr, type, member) : NULL; \ -}) - -#define elf_hash_for_each_possible(name, obj, member, key) \ - for (obj =3D elf_list_entry(__elf_table_entry(name, key), typeof(*obj), m= ember); \ - obj; \ - obj =3D elf_list_entry(obj->member.next, typeof(*(obj)), member)) + __elf_hash_del(node, &__elf_table_entry(elf, name, key)) =20 #define elf_alloc_hash(name, size) \ ({ \ - __elf_bits(name) =3D max(10, ilog2(size)); \ - __elf_table(name) =3D mmap(NULL, sizeof(struct elf_hash_node *) << __elf_= bits(name), \ + __elf_bits(elf, name) =3D max(10, ilog2(size)); \ + __elf_table(elf, name) =3D mmap(NULL, \ + sizeof(struct elf_hash_node *) << __elf_bits(elf, name), \ PROT_READ|PROT_WRITE, \ MAP_PRIVATE|MAP_ANON, -1, 0); \ - if (__elf_table(name) =3D=3D (void *)-1L) { \ + if (__elf_table(elf, name) =3D=3D (void *)-1L) { \ ERROR_GLIBC("mmap fail " #name); \ - __elf_table(name) =3D NULL; \ + __elf_table(elf, name) =3D NULL; \ } \ - __elf_table(name); \ + __elf_table(elf, name); \ }) =20 static inline unsigned long __sym_start(struct symbol *s) @@ -141,7 +120,7 @@ struct section *find_section_by_name(const struct elf *= elf, const char *name) { struct section *sec; =20 - elf_hash_for_each_possible(section_name, sec, name_hash, str_hash(name)) { + elf_hash_for_each_possible(elf, section_name, sec, name_hash, str_hash(na= me)) { if (!strcmp(sec->name, name)) return sec; } @@ -154,7 +133,7 @@ static struct section *find_section_by_index(struct elf= *elf, { struct section *sec; =20 - elf_hash_for_each_possible(section, sec, hash, idx) { + elf_hash_for_each_possible(elf, section, sec, hash, idx) { if (sec->idx =3D=3D idx) return sec; } @@ -166,7 +145,7 @@ static struct symbol *find_symbol_by_index(struct elf *= elf, unsigned int idx) { struct symbol *sym; =20 - elf_hash_for_each_possible(symbol, sym, hash, idx) { + elf_hash_for_each_possible(elf, symbol, sym, hash, idx) { if (sym->idx =3D=3D idx) return sym; } @@ -285,7 +264,7 @@ struct symbol *find_symbol_by_name(const struct elf *el= f, const char *name) { struct symbol *sym; =20 - elf_hash_for_each_possible(symbol_name, sym, name_hash, str_hash(name)) { + elf_hash_for_each_possible(elf, symbol_name, sym, name_hash, str_hash(nam= e)) { if (!strcmp(sym->name, name)) return sym; } @@ -300,7 +279,7 @@ static struct symbol *find_local_symbol_by_file_and_nam= e(const struct elf *elf, { struct symbol *sym; =20 - elf_hash_for_each_possible(symbol_name, sym, name_hash, str_hash_demangle= d(name)) { + elf_hash_for_each_possible(elf, symbol_name, sym, name_hash, str_hash_dem= angled(name)) { if (sym->bind =3D=3D STB_LOCAL && sym->file =3D=3D file && !strcmp(sym->name, name)) { return sym; @@ -314,7 +293,7 @@ struct symbol *find_global_symbol_by_name(const struct = elf *elf, const char *nam { struct symbol *sym; =20 - elf_hash_for_each_possible(symbol_name, sym, name_hash, str_hash_demangle= d(name)) { + elf_hash_for_each_possible(elf, symbol_name, sym, name_hash, str_hash_dem= angled(name)) { if (!strcmp(sym->name, name) && !is_local_sym(sym)) return sym; } @@ -322,31 +301,6 @@ struct symbol *find_global_symbol_by_name(const struct= elf *elf, const char *nam return NULL; } =20 -void iterate_global_symbol_by_demangled_name(const struct elf *elf, - const char *demangled_name, - void (*process)(struct symbol *sym, void *data), - void *data) -{ - struct symbol *sym; - - elf_hash_for_each_possible(symbol_name, sym, name_hash, str_hash(demangle= d_name)) { - if (!strcmp(sym->demangled_name, demangled_name) && !is_local_sym(sym)) - process(sym, data); - } -} - -void iterate_sym_by_name(const struct elf *elf, const char *name, - void (*process)(struct symbol *sym, void *data), - void *data) -{ - struct symbol *sym; - - elf_hash_for_each_possible(symbol_name, sym, name_hash, str_hash_demangle= d(name)) { - if (!strcmp(sym->name, name)) - process(sym, data); - } -} - struct reloc *find_reloc_by_dest_range(const struct elf *elf, struct secti= on *sec, unsigned long offset, unsigned int len) { @@ -359,7 +313,7 @@ struct reloc *find_reloc_by_dest_range(const struct elf= *elf, struct section *se return NULL; =20 for_offset_range(o, offset, offset + len) { - elf_hash_for_each_possible(reloc, reloc, hash, + elf_hash_for_each_possible(elf, reloc, reloc, hash, sec_offset_hash(rsec, o)) { if (reloc->sec !=3D rsec) continue; diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 82b9fb05af26..ba13dd67cf26 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -21,6 +21,13 @@ #define SEC_NAME_LEN 1024 #define SYM_NAME_LEN 512 =20 +static inline u32 str_hash(const char *str) +{ + return jhash(str, strlen(str), 0); +} + +u32 str_hash_demangled(const char *str); + #define bswap_if_needed(elf, val) __bswap_if_needed(&elf->ehdr, val) =20 #ifdef LIBELF_USE_DEPRECATED @@ -129,6 +136,23 @@ struct elf { struct symbol *symbol_data; }; =20 +#define __elf_table(elf, name) ((elf)->name##_hash) +#define __elf_bits(elf, name) ((elf)->name##_bits) + +#define __elf_table_entry(elf, name, key) \ + __elf_table(elf, name)[hash_min(key, __elf_bits(elf, name))] + +#define elf_list_entry(ptr, type, member) \ +({ \ + typeof(ptr) __ptr =3D (ptr); \ + __ptr ? container_of(__ptr, type, member) : NULL; \ +}) + +#define elf_hash_for_each_possible(elf, name, obj, member, key) \ + for (obj =3D elf_list_entry(__elf_table_entry(elf, name, key), typeof(*ob= j), member); \ + obj; \ + obj =3D elf_list_entry(obj->member.next, typeof(*(obj)), member)) + struct elf *elf_open_read(const char *name, int flags); struct elf *elf_create_file(GElf_Ehdr *ehdr, const char *name); =20 @@ -185,12 +209,6 @@ struct symbol *find_func_by_offset(struct section *sec= , unsigned long offset); struct symbol *find_symbol_by_offset(struct section *sec, unsigned long of= fset); struct symbol *find_symbol_by_name(const struct elf *elf, const char *name= ); struct symbol *find_global_symbol_by_name(const struct elf *elf, const cha= r *name); -void iterate_global_symbol_by_demangled_name(const struct elf *elf, const = char *demangled_name, - void (*process)(struct symbol *sym, void *data), - void *data); -void iterate_sym_by_name(const struct elf *elf, const char *name, - void (*process)(struct symbol *sym, void *data), - void *data); struct symbol *find_symbol_containing(const struct section *sec, unsigned = long offset); int find_symbol_hole_containing(const struct section *sec, unsigned long o= ffset); struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *se= c, unsigned long offset); @@ -485,6 +503,16 @@ static inline void set_sym_next_reloc(struct reloc *re= loc, struct reloc *next) #define for_each_sym_continue(elf, sym) \ list_for_each_entry_continue(sym, &elf->symbols, global_list) =20 +#define for_each_sym_by_name(elf, _name, sym) \ + elf_hash_for_each_possible(elf, symbol_name, sym, name_hash, \ + str_hash_demangled(_name)) \ + if (!strcmp(sym->name, _name)) + +#define for_each_sym_by_demangled_name(elf, name, sym) \ + elf_hash_for_each_possible(elf, symbol_name, sym, name_hash, \ + str_hash(name)) \ + if (!strcmp(sym->demangled_name, name)) + #define rsec_next_reloc(rsec, reloc) \ reloc_idx(reloc) < sec_num_entries(rsec) - 1 ? reloc + 1 : NULL =20 diff --git a/tools/objtool/klp-checksum.c b/tools/objtool/klp-checksum.c index 4edd29028bff..e4a910f3211c 100644 --- a/tools/objtool/klp-checksum.c +++ b/tools/objtool/klp-checksum.c @@ -11,17 +11,6 @@ #include #include =20 -static void enable_debug_checksum_cb(struct symbol *sym, void *d) -{ - bool *found =3D d; - - if (!is_func_sym(sym)) - return; - - sym->debug_checksum =3D 1; - *found =3D true; -} - static int checksum_debug_init(struct objtool_file *file) { char *dup, *s; @@ -38,13 +27,20 @@ static int checksum_debug_init(struct objtool_file *fil= e) s =3D dup; while (*s) { bool found =3D false; + struct symbol *sym; char *comma; =20 comma =3D strchr(s, ','); if (comma) *comma =3D '\0'; =20 - iterate_sym_by_name(file->elf, s, enable_debug_checksum_cb, &found); + for_each_sym_by_name(file->elf, s, sym) { + if (!is_func_sym(sym)) + continue; + sym->debug_checksum =3D 1; + found =3D true; + } + if (!found) WARN("--debug-checksum: can't find '%s'", s); =20 diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index c903aa65d4b6..33e401b85001 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -46,11 +46,6 @@ static const struct option klp_diff_options[] =3D { =20 static DEFINE_HASHTABLE(exports, 15); =20 -static inline u32 str_hash(const char *str) -{ - return jhash(str, strlen(str), 0); -} - static char *escape_str(const char *orig) { size_t len =3D 0; @@ -398,22 +393,6 @@ static bool dont_correlate(struct symbol *sym) is_special_section_aux(sym->sec); } =20 -struct process_demangled_name_data { - struct symbol *ret; - int count; -}; - -static void process_demangled_name(struct symbol *sym, void *d) -{ - struct process_demangled_name_data *data =3D d; - - if (sym->twin) - return; - - data->count++; - data->ret =3D sym; -} - /* * When there is no full name match, try match demangled_name. This would * match original foo.llvm.123 to patched foo.llvm.456. @@ -425,16 +404,23 @@ static void process_demangled_name(struct symbol *sym= , void *d) static int find_global_symbol_by_demangled_name(struct elf *elf, struct sy= mbol *sym, struct symbol **out_sym) { - struct process_demangled_name_data data =3D {}; + struct symbol *sym2, *result =3D NULL; + int count =3D 0; =20 - iterate_global_symbol_by_demangled_name(elf, sym->demangled_name, - process_demangled_name, - &data); - if (data.count > 1) { - ERROR("Multiple (%d) correlation candidates for %s", data.count, sym->na= me); + for_each_sym_by_demangled_name(elf, sym->demangled_name, sym2) { + if (is_local_sym(sym2) || sym2->twin) + continue; + + count++; + result =3D sym2; + } + + if (count > 1) { + ERROR("Multiple (%d) correlation candidates for %s", count, sym->name); return -1; } - *out_sym =3D data.ret; + + *out_sym =3D result; return 0; } =20 --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED5753DCDB4; Thu, 23 Apr 2026 04:04:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917085; cv=none; b=kNxIw6AEeWBM6IWZ/n5D75dCbrT7Mz5bqaDeCZEf4kaEjP7IMv4uokX+/I8s/+u1bTvjWHfOPhomZTQO4YLEgcvwqJJAFM9FTtRhjGHCGXtzUoLgX89MuV6Z8cMNUm0I9TQM4MJc/MRitROGOWbYUy9h31vbpWcrZSUAr3cWemg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917085; c=relaxed/simple; bh=R+8ECy7yKq4jzp8RCvv7108cy8ywNl7MbZrfSymzIeo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dIid0AU8L36rh2XWByVPWMk/LBAiGHhaWf3pLwTBRQI7Z0yze9idgdb/iudlHSno452w5a9VwRQ3SLJFY9jql9Ak+eEvfWJXd6wYAtecgvsVvyKnl2jRQgcG2s4/QkwKe6XGw5Bc8YN1J5POgAsZgvYnfetKjk0kLZHeUZb/gVU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ma5VlDf/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ma5VlDf/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 554CFC2BCB4; Thu, 23 Apr 2026 04:04:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917084; bh=R+8ECy7yKq4jzp8RCvv7108cy8ywNl7MbZrfSymzIeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ma5VlDf/0OzzM81D5iviwwY4gJCat5drvAU3olfjhiM4V8xAiK/8W2qkI0e2N6LYq nUVC/7ftMTiJ0BKSsMm/2bioCNMtJtBqP6LjBVpVH99hf9aWltvK5FrHMAd9OOXoTq 6LHYoL6RpuzE/+v1soZ8jP53Oa1GQZGOWSNl+jX4FX9EGaT11IaqBWncnn1kYVoUCu erYT8wBv/dLdXQ5ALi52JVZfB5LDfcXu8J9ANGsG6Z97L4t9QY1aCgviWY1WEGtLzA cNG2YMHKayBPc6QG6rHO/vUQmcMJLnUhP0naBtRE/Ii7aDc4YyEjs6FThrQREFcwP2 5uh8dRjXWjGJw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 40/48] objtool/klp: Calculate object checksums Date: Wed, 22 Apr 2026 21:04:08 -0700 Message-ID: <084424751bed439249657e1aef6a3d5c4e199680.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Start checksumming data objects in preparation for revamping the correlation algorithm. Signed-off-by: Josh Poimboeuf --- tools/objtool/include/objtool/checksum.h | 43 ++++++++---- tools/objtool/include/objtool/warn.h | 29 ++++---- tools/objtool/klp-checksum.c | 88 +++++++++++++++++++----- tools/objtool/klp-diff.c | 2 +- 4 files changed, 115 insertions(+), 47 deletions(-) diff --git a/tools/objtool/include/objtool/checksum.h b/tools/objtool/inclu= de/objtool/checksum.h index be4eb7dfe6f2..ccaf57c7df38 100644 --- a/tools/objtool/include/objtool/checksum.h +++ b/tools/objtool/include/objtool/checksum.h @@ -6,28 +6,43 @@ =20 #ifdef BUILD_KLP =20 -static inline void checksum_init(struct symbol *func) +static inline void checksum_init(struct symbol *sym) { - if (func && !func->csum.state) { - func->csum.state =3D XXH3_createState(); - XXH3_64bits_reset(func->csum.state); + if (sym && !sym->csum.state) { + sym->csum.state =3D XXH3_createState(); + XXH3_64bits_reset(sym->csum.state); } } =20 -static inline void checksum_update(struct symbol *func, - struct instruction *insn, - const void *data, size_t size) +static inline void __checksum_update(struct symbol *sym, const void *data, + size_t size) { - XXH3_64bits_update(func->csum.state, data, size); - dbg_checksum(func, insn, XXH3_64bits_digest(func->csum.state)); + XXH3_64bits_update(sym->csum.state, data, size); } =20 -static inline void checksum_finish(struct symbol *func) +static inline void __checksum_update_insn(struct symbol *sym, + struct instruction *insn, + const void *data, size_t size) { - if (func && func->csum.state) { - func->csum.checksum =3D XXH3_64bits_digest(func->csum.state); - XXH3_freeState(func->csum.state); - func->csum.state =3D NULL; + __checksum_update(sym, data, size); + dbg_checksum_insn(sym, insn, XXH3_64bits_digest(sym->csum.state)); +} + +static inline void __checksum_update_object(struct symbol *sym, + unsigned long offset, + const char *what, const void *data, + size_t size) +{ + __checksum_update(sym, data, size); + dbg_checksum_object(sym, offset, what, XXH3_64bits_digest(sym->csum.state= )); +} + +static inline void checksum_finish(struct symbol *sym) +{ + if (sym && sym->csum.state) { + sym->csum.checksum =3D XXH3_64bits_digest(sym->csum.state); + XXH3_freeState(sym->csum.state); + sym->csum.state =3D NULL; } } =20 diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/o= bjtool/warn.h index fa8b7d292e83..595ee8009667 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -130,10 +130,22 @@ static inline void unindent(int *unused) { indent--; } objname ? ": " : "", \ ##__VA_ARGS__) =20 -#define dbg(args...) \ +#define dbg_checksum_insn(func, insn, checksum) \ ({ \ - if (unlikely(debug)) \ - __dbg(args); \ + if (unlikely(func->debug_checksum)) { \ + char *insn_off =3D offstr(insn->sec, insn->offset); \ + __dbg("checksum: %s(): %s %016llx", \ + func->name, insn_off, (unsigned long long)checksum);\ + free(insn_off); \ + } \ +}) + +#define dbg_checksum_object(sym, offset, what, checksum) \ +({ \ + if (unlikely(sym->debug_checksum)) \ + __dbg("checksum: %s+0x%lx: %s %016llx", \ + sym->name, offset, what, \ + (unsigned long long)checksum); \ }) =20 #define __dbg_indent(format, ...) \ @@ -147,15 +159,4 @@ static inline void unindent(int *unused) { indent--; } __dbg_indent(args); \ indent++ =20 -#define dbg_checksum(func, insn, checksum) \ -({ \ - if (unlikely(insn->sym && insn->sym->pfunc && \ - insn->sym->pfunc->debug_checksum)) { \ - char *insn_off =3D offstr(insn->sec, insn->offset); \ - __dbg("checksum: %s %s %016llx", \ - func->name, insn_off, (unsigned long long)checksum);\ - free(insn_off); \ - } \ -}) - #endif /* _WARN_H */ diff --git a/tools/objtool/klp-checksum.c b/tools/objtool/klp-checksum.c index e4a910f3211c..adfd02447a45 100644 --- a/tools/objtool/klp-checksum.c +++ b/tools/objtool/klp-checksum.c @@ -35,7 +35,7 @@ static int checksum_debug_init(struct objtool_file *file) *comma =3D '\0'; =20 for_each_sym_by_name(file->elf, s, sym) { - if (!is_func_sym(sym)) + if (!is_func_sym(sym) && !is_object_sym(sym)) continue; sym->debug_checksum =3D 1; found =3D true; @@ -66,14 +66,14 @@ static void checksum_update_insn(struct objtool_file *f= ile, struct symbol *func, if (insn->fake) return; =20 - checksum_update(func, insn, insn->sec->data->d_buf + insn->offset, insn->= len); + __checksum_update_insn(func, insn, insn->sec->data->d_buf + insn->offset,= insn->len); =20 if (!reloc) { struct symbol *call_dest =3D insn_call_dest(insn); =20 if (call_dest) - checksum_update(func, insn, call_dest->demangled_name, - strlen(call_dest->demangled_name)); + __checksum_update_insn(func, insn, call_dest->demangled_name, + strlen(call_dest->demangled_name)); goto alts; } =20 @@ -84,7 +84,7 @@ static void checksum_update_insn(struct objtool_file *fil= e, struct symbol *func, char *str; =20 str =3D sym->sec->data->d_buf + sym->offset + offset; - checksum_update(func, insn, str, strlen(str)); + __checksum_update_insn(func, insn, str, strlen(str)); goto alts; } =20 @@ -96,8 +96,9 @@ static void checksum_update_insn(struct objtool_file *fil= e, struct symbol *func, offset -=3D sym->offset; } =20 - checksum_update(func, insn, sym->demangled_name, strlen(sym->demangled_na= me)); - checksum_update(func, insn, &offset, sizeof(offset)); + __checksum_update_insn(func, insn, sym->demangled_name, + strlen(sym->demangled_name)); + __checksum_update_insn(func, insn, &offset, sizeof(offset)); =20 alts: for (alt =3D insn->alts; alt; alt =3D alt->next) { @@ -108,12 +109,13 @@ static void checksum_update_insn(struct objtool_file = *file, struct symbol *func, break; in_alt =3D true; =20 - checksum_update(func, insn, &alt->type, sizeof(alt->type)); + __checksum_update_insn(func, insn, &alt->type, + sizeof(alt->type)); =20 if (alt_group && alt_group->orig_group) { struct instruction *alt_insn; =20 - checksum_update(func, insn, &alt_group->feature, sizeof(alt_group->feat= ure)); + __checksum_update_insn(func, insn, &alt_group->feature,sizeof(alt_group= ->feature)); =20 for (alt_insn =3D alt->insn; alt_insn; alt_insn =3D next_insn_same_sec(= file, alt_insn)) { checksum_update_insn(file, func, alt_insn); @@ -128,31 +130,81 @@ static void checksum_update_insn(struct objtool_file = *file, struct symbol *func, } } =20 +static void checksum_update_object(struct objtool_file *file, struct symbo= l *sym) +{ + struct reloc *reloc; + + __checksum_update_object(sym, 0, "len", &sym->len, sizeof(sym->len)); + + if (sym->sec->data->d_buf) + __checksum_update_object(sym, 0, "data", + sym->sec->data->d_buf + sym->offset, + sym->len); + + sym_for_each_reloc(file->elf, sym, reloc) { + struct symbol *target =3D reloc->sym; + s64 offset; + + offset =3D reloc_addend(reloc); + + if (is_string_sec(target->sec)) { + char *str; + + str =3D target->sec->data->d_buf + target->offset + offset; + __checksum_update_object(sym, reloc_offset(reloc), + "reloc string", str, strlen(str)); + continue; + } + + if (is_sec_sym(target)) { + target =3D find_symbol_containing(reloc->sym->sec, offset); + if (!target) + continue; + + offset -=3D target->offset; + } + + __checksum_update_object(sym, reloc_offset(reloc), "reloc name", + target->demangled_name, + strlen(target->demangled_name)); + __checksum_update_object(sym, reloc_offset(reloc), "reloc addend", + &offset, sizeof(offset)); + } +} + int calculate_checksums(struct objtool_file *file) { struct instruction *insn; - struct symbol *func; + struct symbol *sym; =20 if (checksum_debug_init(file)) return -1; =20 - for_each_sym(file->elf, func) { + for_each_sym(file->elf, sym) { + /* * Skip cold subfunctions and aliases: they share the * parent's checksum via func_for_each_insn() which * follows func->cfunc into the cold subfunction. */ - if (!is_func_sym(func) || is_cold_func(func) || - is_alias_sym(func) || !func->len) + if (is_cold_func(sym) || is_alias_sym(sym) || !sym->len || + !sym->sec || !sym->sec->data) continue; =20 - checksum_init(func); + if (is_func_sym(sym)) { + checksum_init(sym); + func_for_each_insn(file, sym, insn) + checksum_update_insn(file, sym, insn); + checksum_finish(sym); =20 - func_for_each_insn(file, func, insn) - checksum_update_insn(file, func, insn); + } else if (is_object_sym(sym)) { + checksum_init(sym); + checksum_update_object(file, sym); + checksum_finish(sym); + } =20 - checksum_finish(func); } + return 0; } =20 @@ -213,7 +265,7 @@ int cmd_klp_checksum(int argc, const char **argv) int ret; =20 const struct option options[] =3D { - OPT_STRING(0, "debug-checksum", &opts.debug_checksum, "funcs", "enable c= hecksum debug output"), + OPT_STRING(0, "debug-checksum", &opts.debug_checksum, "syms", "enable ch= ecksum debug output"), OPT_BOOLEAN(0, "dry-run", &opts.dryrun, "don't write modifications"), OPT_END(), }; diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 33e401b85001..8d64d4c691cb 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -201,7 +201,7 @@ static int read_sym_checksums(struct elf *elf) return -1; } =20 - if (is_func_sym(sym)) + if (is_func_sym(sym) || is_object_sym(sym)) sym->csum.checksum =3D sym_checksum->checksum; } =20 --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 863DF3DD52F; Thu, 23 Apr 2026 04:04:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917085; cv=none; b=KTBGxmbeOyIiFHfctWJqVbqWKM2g3xoZWW0lM+Oh5Vuqrpvx7mpxfcLusD2Ys4vO09so0JoYd1RSKPtVDzJ9M0ndkoiKvhyQPt+fxPO/m4TmU9Scm5E+4ahKgOcL+ema1pJcEUEVwmKZF8WhSdVwuYc4LDJewk9a4fWipa7GLlM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917085; c=relaxed/simple; bh=v3Bzrs9qCVgv3gQrZ2y2TiXWIceFm8oIUME09GIvrXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=We9t2BRjYsL67bv9VIJ+tZ6k+p3lgoYX8nD2695nj4iRGZOsN5ptvnl3kqn9r/vsrcdfqIZ7jIr28sQh8XWOebMxx2QM/AAv76GBWVTe6a35ml7Q3ig+PKwZfP6yd+VAAJ/drwc7L1wGaVCZKv11f6PkxcZ/R1FV/rPfiDH0PGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=unLZLjaL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="unLZLjaL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02CA7C2BCB5; Thu, 23 Apr 2026 04:04:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917085; bh=v3Bzrs9qCVgv3gQrZ2y2TiXWIceFm8oIUME09GIvrXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=unLZLjaL1v3E2CnB+I5597Ry3C6UXa5pYmOBDX7fVM08xcg+IbYn5SE29giEGe3Nb DkFjjE8onuKJ9eQzfLuOTFTks+932N4bwqDCyiJWNimzpYfRxbeGhK5JuhurpLF9vT e0bd0P1B5/AdJv3G1dEle8MFHr2gFaVwhf5WUzFvEpGKNK0LFDLDq+nPhOzJfi2Msi KahdAGH4a5FaAhvAaZn3dkE+bC/6SP5jJcTMiAwIS0L5rvpD6oDyxlshYOdemzdS/T Gistc5GThLk28R8sldGfEZ+kYqls/xeBOJKwzdkzKCO0q4QJCX+XrEDuLXuKlnTqpH uTXvoW/46Vn3Q== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 41/48] objtool/klp: Rewrite symbol correlation algorithm Date: Wed, 22 Apr 2026 21:04:09 -0700 Message-ID: <284944d45120ff69959c4d9cde90db13e493d223.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rewrite the symbol correlation code, using a tiered list of deterministic strategies in a loop. For duplicately named symbols, each tier applies a filter with the goal of finding a 1:1 deterministic correlation between the original and patched version of the symbol. Overall this works much better than the existing algorithm, particularly with LTO kernels. Signed-off-by: Josh Poimboeuf --- tools/objtool/klp-diff.c | 482 ++++++++++++++++++++++++++++----------- 1 file changed, 346 insertions(+), 136 deletions(-) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 8d64d4c691cb..6d7fbb16e59c 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -393,78 +393,319 @@ static bool dont_correlate(struct symbol *sym) is_special_section_aux(sym->sec); } =20 -/* - * When there is no full name match, try match demangled_name. This would - * match original foo.llvm.123 to patched foo.llvm.456. - * - * Note that, in very rare cases, it is possible to have multiple - * foo.llvm. in the same kernel. When this happens, report error and - * fail the diff. - */ -static int find_global_symbol_by_demangled_name(struct elf *elf, struct sy= mbol *sym, - struct symbol **out_sym) +static const char *llvm_suffix(const char *name) { - struct symbol *sym2, *result =3D NULL; - int count =3D 0; + return strstr(name, ".llvm."); +} =20 - for_each_sym_by_demangled_name(elf, sym->demangled_name, sym2) { - if (is_local_sym(sym2) || sym2->twin) +static bool is_llvm_sym(struct symbol *sym) +{ + return llvm_suffix(sym->name); +} + +/* + * Determine if two symbols have compatible source file origins: + * + * - If both symbols are local, only return true if they belong to the s= ame + * ELF file symbol. + * + * - If both symbols are global, always return true, as globals don't ha= ve + * file associations. + * + * - If they have different scopes, also return true, as the patch might= have + * changed the symbol's scope. + * + * Works for both same-ELF (direct pointer compare) and cross-ELF + * (compare via file->twin) cases. + */ +static bool maybe_same_file(struct symbol *sym1, struct symbol *sym2) +{ + if (!sym1->file || !sym2->file) + return true; + if (sym1->file =3D=3D sym2->file) + return true; + return sym1->file->twin =3D=3D sym2->file; +} + +/* + * Similar to maybe_same_file(), but strict: no scope changes allowed. + * + * Works for both same-ELF (direct pointer compare) and cross-ELF + * (compare via file->twin) cases. + */ +static bool same_file(struct symbol *sym1, struct symbol *sym2) +{ + if (llvm_suffix(sym1->name) && llvm_suffix(sym2->name)) + return true; + if (!sym1->file && !sym2->file) + return true; + if (!sym1->file || !sym2->file) + return false; + if (sym1->file =3D=3D sym2->file) + return true; + return sym1->file->twin =3D=3D sym2->file; +} + +/* + * Is it a local symbol, or at least was it local in the translation unit + * before LLVM promoted it? + */ +static bool is_tu_local_sym(struct symbol *sym) +{ + return is_local_sym(sym) || is_llvm_sym(sym); +} + +/* + * Try to find sym1's twin in patched using deterministic matching. + * + * Multiple symbols can share a demangled name (e.g., static functions in + * different TUs). This function counts same-named candidates through a + * funnel of progressively tighter filters. Each level is a strict subset + * of the previous one. + * + * The widest level that yields a 1:1 match wins. Narrower levels are only + * needed when the wider level is ambiguous (count > 1). + */ +static struct symbol *find_twin(struct elfs *e, struct symbol *sym1) +{ + struct symbol *name_last =3D NULL, *scope_last =3D NULL, + *file_last =3D NULL, *csum_last =3D NULL; + unsigned int name_orig =3D 0, name_patched =3D 0; + unsigned int scope_orig =3D 0, scope_patched =3D 0; + unsigned int file_orig =3D 0, file_patched =3D 0; + unsigned int csum_orig =3D 0, csum_patched =3D 0; + struct symbol *sym2, *match =3D NULL; + + /* Count orig candidates */ + for_each_sym_by_demangled_name(e->orig, sym1->demangled_name, sym2) { + if (sym2->twin || sym1->type !=3D sym2->type || dont_correlate(sym2) || + (!maybe_same_file(sym1, sym2))) continue; =20 - count++; - result =3D sym2; + /* Level 1: name match (widest filter) */ + name_orig++; + + /* Level 2: scope (scope changes allowed) */ + if (is_tu_local_sym(sym1) !=3D is_tu_local_sym(sym2)) + continue; + scope_orig++; + + /* Level 3: file (scope changes disallowed) */ + if (!same_file(sym1, sym2)) + continue; + file_orig++; + + /* Level 4: checksum (unchanged symbols) */ + if (sym1->len !=3D sym2->len || !sym1->csum.checksum || + sym1->csum.checksum !=3D sym2->csum.checksum) + continue; + csum_orig++; } =20 - if (count > 1) { - ERROR("Multiple (%d) correlation candidates for %s", count, sym->name); - return -1; + /* Count patched candidates */ + for_each_sym_by_demangled_name(e->patched, sym1->demangled_name, sym2) { + if (sym2->twin || sym1->type !=3D sym2->type || dont_correlate(sym2)) + continue; + + /* Level 1 */ + if (!maybe_same_file(sym1, sym2)) + continue; + name_patched++; + name_last =3D sym2; + + /* Level 2 */ + if (is_tu_local_sym(sym1) !=3D is_tu_local_sym(sym2)) + continue; + scope_patched++; + scope_last =3D sym2; + + /* Level 3 */ + if (!same_file(sym1, sym2)) + continue; + file_patched++; + file_last =3D sym2; + + /* Level 4 */ + if (sym1->len !=3D sym2->len || !sym1->csum.checksum || + sym1->csum.checksum !=3D sym2->csum.checksum) + continue; + csum_patched++; + csum_last =3D sym2; + } + + /* Return the widest level that yields a unique (1:1) match */ + if (name_orig =3D=3D 1 && name_patched =3D=3D 1) + match =3D name_last; + else if (scope_orig =3D=3D 1 && scope_patched =3D=3D 1) + match =3D scope_last; + else if (file_orig =3D=3D 1 && file_patched =3D=3D 1) + match =3D file_last; + else if (csum_orig =3D=3D 1 && csum_patched =3D=3D 1) + match =3D csum_last; + + return match; +} + +struct llvm_suffix_pair { + struct hlist_node hash; + const char *orig; + const char *patched; +}; + +static DECLARE_HASHTABLE(suffix_map, 7); + +/* + * Build a mapping of known orig-to-patched LLVM suffixes based on + * already-correlated symbol pairs. All promoted symbols from the same TU + * share the same .llvm. suffix, so one correlated pair seeds the map + * for the entire TU. + */ +static int update_suffix_map(struct elf *elf) +{ + struct llvm_suffix_pair *entry; + struct symbol *sym; + + for_each_sym(elf, sym) { + const char *s1, *s2; + bool found; + + if (!sym->twin) + continue; + + s1 =3D llvm_suffix(sym->name); + s2 =3D llvm_suffix(sym->twin->name); + + if (!s1 || !s2) + continue; + + found =3D false; + hash_for_each_possible(suffix_map, entry, hash, str_hash(s1)) { + if (!strcmp(entry->orig, s1)) { + found =3D true; + break; + } + } + if (found) + continue; + + entry =3D calloc(1, sizeof(*entry)); + if (!entry) { + ERROR_GLIBC("calloc"); + return -1; + } + + entry->orig =3D s1; + entry->patched =3D s2; + hash_add(suffix_map, &entry->hash, str_hash(s1)); } =20 - *out_sym =3D result; return 0; } =20 /* - * For each symbol in the original kernel, find its corresponding "twin" i= n the - * patched kernel. + * Match by translating the symbol's .llvm. suffix through the suffix + * map to find the corresponding hash suffix for the patched object. + */ +static struct symbol *find_twin_suffixed(struct elf *elf, struct symbol *s= ym1) +{ + const char *suffix, *patched_suffix =3D NULL; + struct symbol *sym2, *match =3D NULL; + char name[SYM_NAME_LEN]; + struct llvm_suffix_pair *entry; + int count =3D 0; + + suffix =3D llvm_suffix(sym1->name); + if (!suffix) + return NULL; + + hash_for_each_possible(suffix_map, entry, hash, str_hash(suffix)) { + if (!strcmp(entry->orig, suffix)) { + patched_suffix =3D entry->patched; + break; + } + } + if (!patched_suffix) + return NULL; + + if (snprintf_check(name, SYM_NAME_LEN, "%s%s", + sym1->demangled_name, patched_suffix)) + return NULL; + + for_each_sym_by_name(elf, name, sym2) { + if (sym2->twin || sym1->type !=3D sym2->type || dont_correlate(sym2)) + continue; + count++; + match =3D sym2; + } + + if (count =3D=3D 1) + return match; + + return NULL; +} + +/* + * Last-resort positional matching. + * + * Finds a symbol with the same position in the symbol table among + * same-demangled-name candidates, similar to livepatch sympos. Note that + * LLVM-promoted symbols are globals, which come after locals in the symbol + * table, so we have to be careful not to compare different scopes. + * + * This is a bit less deterministic than the other matching strategies, so= it + * should be done last. + */ +static struct symbol *find_twin_positional(struct elfs *e, struct symbol *= sym1) +{ + unsigned int idx_orig =3D 0, idx_patched =3D 0; + unsigned int sym1_pos =3D 0; + struct symbol *sym2, *match =3D NULL; + + for_each_sym_by_demangled_name(e->orig, sym1->demangled_name, sym2) { + if (sym2->twin || sym1->type !=3D sym2->type || dont_correlate(sym2) || + !maybe_same_file(sym1, sym2)) + continue; + if (is_tu_local_sym(sym1) !=3D is_tu_local_sym(sym2) || + is_llvm_sym(sym1) !=3D is_llvm_sym(sym2)) + continue; + if (sym1 =3D=3D sym2) + sym1_pos =3D idx_orig; + idx_orig++; + } + + for_each_sym_by_demangled_name(e->patched, sym1->demangled_name, sym2) { + if (sym2->twin || sym1->type !=3D sym2->type || dont_correlate(sym2) || + !maybe_same_file(sym1, sym2)) + continue; + if (is_tu_local_sym(sym1) !=3D is_tu_local_sym(sym2) || + is_llvm_sym(sym1) !=3D is_llvm_sym(sym2)) + continue; + if (idx_patched =3D=3D sym1_pos) + match =3D sym2; + idx_patched++; + } + + if (idx_orig !=3D idx_patched) + return NULL; + + return match; +} + +/* + * Correlate symbols between the orig and patched objects. This is a + * prerequisite for detecting changed functions, as well as for properly + * translating relocations so they point to the correct symbol. */ static int correlate_symbols(struct elfs *e) { struct symbol *file1_sym, *file2_sym; struct symbol *sym1, *sym2; + bool progress; =20 + /* Correlate FILE symbols */ file1_sym =3D first_file_symbol(e->orig); file2_sym =3D first_file_symbol(e->patched); =20 - /* - * Correlate any locals before the first FILE symbol. This has been - * seen when LTO inexplicably strips the initramfs_data.o FILE symbol - * due to the file only containing data and no code. - */ - for_each_sym(e->orig, sym1) { - if (sym1 =3D=3D file1_sym || !is_local_sym(sym1)) - break; - - if (dont_correlate(sym1)) - continue; - - for_each_sym(e->patched, sym2) { - if (sym2 =3D=3D file2_sym || !is_local_sym(sym2)) - break; - - if (sym2->twin || dont_correlate(sym2)) - continue; - - if (strcmp(sym1->demangled_name, sym2->demangled_name)) - continue; - - sym1->twin =3D sym2; - sym2->twin =3D sym1; - break; - } - } - - /* Correlate locals after the first FILE symbol */ for (; ; file1_sym =3D next_file_symbol(e->orig, file1_sym), file2_sym =3D next_file_symbol(e->patched, file2_sym)) { =20 @@ -488,92 +729,52 @@ static int correlate_symbols(struct elfs *e) =20 file1_sym->twin =3D file2_sym; file2_sym->twin =3D file1_sym; - - sym1 =3D file1_sym; - - for_each_sym_continue(e->orig, sym1) { - if (is_file_sym(sym1) || !is_local_sym(sym1)) - break; - - if (dont_correlate(sym1)) - continue; - - sym2 =3D file2_sym; - for_each_sym_continue(e->patched, sym2) { - if (is_file_sym(sym2) || !is_local_sym(sym2)) - break; - - if (sym2->twin || dont_correlate(sym2)) - continue; - - if (strcmp(sym1->demangled_name, sym2->demangled_name)) - continue; - - sym1->twin =3D sym2; - sym2->twin =3D sym1; - break; - } - } } =20 - /* Correlate globals */ - for_each_sym(e->orig, sym1) { - if (sym1->bind =3D=3D STB_LOCAL) - continue; - - sym2 =3D find_global_symbol_by_name(e->patched, sym1->name); - if (sym2 && !sym2->twin) { - sym1->twin =3D sym2; - sym2->twin =3D sym1; - } - } =20 /* - * Correlate globals with demangled_name. - * A separate loop is needed because we want to finish all the - * full name correlations first. + * Correlate in two phases: loop deterministic levels until no more + * progress, then use positional fallback for the rest. This prevents + * the nondeterministic positional matching from stealing symbols that + * have deterministic matches. */ + hash_init(suffix_map); + do { + progress =3D false; + for_each_sym(e->orig, sym1) { + if (sym1->twin || dont_correlate(sym1)) + continue; + sym2 =3D find_twin(e, sym1); + if (!sym2) + continue; + sym1->twin =3D sym2; + sym2->twin =3D sym1; + progress =3D true; + } + + if (update_suffix_map(e->orig)) + return -1; + + for_each_sym(e->orig, sym1) { + if (sym1->twin || dont_correlate(sym1)) + continue; + sym2 =3D find_twin_suffixed(e->patched, sym1); + if (!sym2) + continue; + sym1->twin =3D sym2; + sym2->twin =3D sym1; + progress =3D true; + } + } while (progress); + for_each_sym(e->orig, sym1) { - if (sym1->bind =3D=3D STB_LOCAL || sym1->twin) + if (sym1->twin || dont_correlate(sym1)) continue; - - if (find_global_symbol_by_demangled_name(e->patched, sym1, &sym2)) - return -1; - - if (sym2 && !sym2->twin) { - sym1->twin =3D sym2; - sym2->twin =3D sym1; - } - } - - /* Correlate original locals with patched globals */ - for_each_sym(e->orig, sym1) { - if (sym1->twin || dont_correlate(sym1) || !is_local_sym(sym1)) + sym2 =3D find_twin_positional(e, sym1); + if (!sym2) continue; - - sym2 =3D find_global_symbol_by_name(e->patched, sym1->name); - if (!sym2 && find_global_symbol_by_demangled_name(e->patched, sym1, &sym= 2)) - return -1; - - if (sym2 && !sym2->twin) { - sym1->twin =3D sym2; - sym2->twin =3D sym1; - } - } - - /* Correlate original globals with patched locals */ - for_each_sym(e->patched, sym2) { - if (sym2->twin || dont_correlate(sym2) || !is_local_sym(sym2)) - continue; - - sym1 =3D find_global_symbol_by_name(e->orig, sym2->name); - if (!sym1 && find_global_symbol_by_demangled_name(e->orig, sym2, &sym1)) - return -1; - - if (sym1 && !sym1->twin) { - sym2->twin =3D sym1; - sym1->twin =3D sym2; - } + sym1->twin =3D sym2; + sym2->twin =3D sym1; } =20 for_each_sym(e->orig, sym1) { @@ -785,19 +986,24 @@ static void mark_included_function(struct symbol *fun= c) */ static int mark_changed_functions(struct elfs *e) { - struct symbol *sym_orig, *patched_sym; + struct symbol *orig_sym, *patched_sym; bool changed =3D false; =20 /* Find changed functions */ - for_each_sym(e->orig, sym_orig) { - if (!is_func_sym(sym_orig) || dont_correlate(sym_orig)) + for_each_sym(e->orig, orig_sym) { + if (dont_correlate(orig_sym)) continue; =20 - patched_sym =3D sym_orig->twin; + patched_sym =3D orig_sym->twin; if (!patched_sym) continue; =20 - if (sym_orig->csum.checksum !=3D patched_sym->csum.checksum) { + if (orig_sym->csum.checksum !=3D patched_sym->csum.checksum) { + if (!is_func_sym(orig_sym)) { + ERROR("changed data: %s", orig_sym->name); + return -1; + } + patched_sym->changed =3D 1; mark_included_function(patched_sym); changed =3D true; @@ -822,7 +1028,7 @@ static int mark_changed_functions(struct elfs *e) printf("%s: changed function: %s\n", objname, patched_sym->name); } =20 - return !changed ? -1 : 0; + return !changed ? 1 : 0; } =20 static int clone_included_functions(struct elfs *e) @@ -1865,6 +2071,7 @@ static int copy_import_ns(struct elfs *e) int cmd_klp_diff(int argc, const char **argv) { struct elfs e =3D {0}; + int ret; =20 argc =3D parse_options(argc, argv, klp_diff_options, klp_diff_usage, 0); if (argc !=3D 3) @@ -1891,7 +2098,10 @@ int cmd_klp_diff(int argc, const char **argv) if (correlate_symbols(&e)) return -1; =20 - if (mark_changed_functions(&e)) + ret =3D mark_changed_functions(&e); + if (ret < 0) + return -1; + if (ret > 0) return 0; =20 e.out =3D elf_create_file(&e.orig->ehdr, argv[2]); --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B3B33DD514; Thu, 23 Apr 2026 04:04:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917086; cv=none; b=EFgMU8Obci7pq3+MmuuyvUM9mudQ0cEqf9nA9PrMBqEXxtm96Zg6SJGN4Gp39E/BjI+U2cTK/NJK79iKcUr74RsuxfHQd5nqQoPzMCoBm7eHR3ig2n8yXk8ixRJCHCF4W7M8Plk6LLBKglYb+qRB2DUs9a7pr4Ltz9fl9FAZRZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917086; c=relaxed/simple; bh=7M7eH1eisSgyr1bdBueJqCoMzPzFDdbSQZ9d31WFrcc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kTxq/eqHzHaTPQv6cP3GWMr0NxNt27DvPGu2hyDidVY/16usVvsomAyoQaGI3aZhB2vOvdzKhP/w/EQwlVi9AOxKdYK3BZ64XrlkxSjW8mhGWWmVbozBoMHR6nCUJXKJlJyZWx3x03Nu0U1jrGxNYt05T8RaoScx9DwhXsluB3I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kvRe+Iz9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kvRe+Iz9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D7BFC2BCB6; Thu, 23 Apr 2026 04:04:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917086; bh=7M7eH1eisSgyr1bdBueJqCoMzPzFDdbSQZ9d31WFrcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kvRe+Iz9Lj0dZn6eucl1aO9jT7WYsMSt8UxH+Ra9bwTzUzHQX30biVETvxZcM13yq GTZvhYsqENeQnlIfuYIYNzHWj4lQnU8Eegwa+IrabDcd2OvcLNiAao+6HupS4K8OoA eZhdLuLVOYuINoSChDOF3Xs1kePBzDSe36ofDuo0cFKquzPC4BVQ0A6Jto00YWqkGr vnUa6MQgHli1HYMFLPIXsEm7q4ZYrE06GaO4WlO7KvlM5FGC7AlqsNyxjMfzUSrM1r 3/yHCm2QpCD+Amd7MfVSE+zz2TJhquW1wVM5rBwR70CdzeG0ixEBMsu/A3Ce0r1bA4 /WXVaxczQgkAg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 42/48] objtool/klp: Add correlation debugging output Date: Wed, 22 Apr 2026 21:04:10 -0700 Message-ID: <44757e0c259e4651275e24b49dc9f7220ecfe16b.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add debugging messages to show how duplicate symbols get correlated, and split the --debug feature into --debug-correlate and --debug-clone. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu --- tools/objtool/include/objtool/warn.h | 16 +++++++---- tools/objtool/klp-diff.c | 42 ++++++++++++++++++++++------ tools/objtool/objtool.c | 3 -- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/o= bjtool/warn.h index 595ee8009667..a9936d60980c 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -109,7 +109,7 @@ static inline char *offstr(struct section *sec, unsigne= d long offset) #define ERROR_FUNC(sec, offset, format, ...) __WARN_FUNC(ERROR_STR, sec, o= ffset, format, ##__VA_ARGS__) #define ERROR_INSN(insn, format, ...) ERROR_FUNC(insn->sec, insn->offset, = format, ##__VA_ARGS__) =20 -extern bool debug; +extern bool debug, debug_correlate, debug_clone; extern int indent; =20 static inline void unindent(int *unused) { indent--; } @@ -148,15 +148,21 @@ static inline void unindent(int *unused) { indent--; } (unsigned long long)checksum); \ }) =20 -#define __dbg_indent(format, ...) \ +#define dbg_correlate(args...) \ ({ \ - if (unlikely(debug)) \ + if (unlikely(debug_correlate)) \ + __dbg(args); \ +}) + +#define __dbg_clone(format, ...) \ +({ \ + if (unlikely(debug_clone)) \ __dbg("%*s" format, indent * 8, "", ##__VA_ARGS__); \ }) =20 -#define dbg_indent(args...) \ +#define dbg_clone(args...) \ int __cleanup(unindent) __dummy_##__COUNTER__; \ - __dbg_indent(args); \ + __dbg_clone(args); \ indent++ =20 #endif /* _WARN_H */ diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 6d7fbb16e59c..acb76aefd04f 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -33,6 +33,9 @@ struct export { char *mod, *sym; }; =20 +bool debug, debug_correlate, debug_clone; +int indent; + static const char * const klp_diff_usage[] =3D { "objtool klp diff [] ", NULL, @@ -40,7 +43,9 @@ static const char * const klp_diff_usage[] =3D { =20 static const struct option klp_diff_options[] =3D { OPT_GROUP("Options:"), - OPT_BOOLEAN('d', "debug", &debug, "enable debug output"), + OPT_BOOLEAN('d', "debug", &debug, "enable all debug output"), + OPT_BOOLEAN(0, "debug-correlate", &debug_correlate, "enable correlation d= ebug output"), + OPT_BOOLEAN(0, "debug-clone", &debug_clone, "enable cloning debug output"= ), OPT_END(), }; =20 @@ -543,6 +548,14 @@ static struct symbol *find_twin(struct elfs *e, struct= symbol *sym1) else if (csum_orig =3D=3D 1 && csum_patched =3D=3D 1) match =3D csum_last; =20 + if (!match) + return NULL; + + if (name_orig !=3D 1 || name_patched !=3D 1) + dbg_correlate("find_twin(): %s%s -> %s%s", + sym1->name, is_func_sym(sym1) ? "()" : "", + match->name, is_func_sym(match) ? "()" : ""); + return match; } =20 @@ -638,10 +651,14 @@ static struct symbol *find_twin_suffixed(struct elf *= elf, struct symbol *sym1) match =3D sym2; } =20 - if (count =3D=3D 1) - return match; + if (count !=3D 1) + return NULL; =20 - return NULL; + dbg_correlate("find_suffixed_twin(): %s%s -> %s%s", + sym1->name, is_func_sym(sym1) ? "()" : "", + match->name, is_func_sym(match) ? "()" : ""); + + return match; } =20 /* @@ -688,6 +705,10 @@ static struct symbol *find_twin_positional(struct elfs= *e, struct symbol *sym1) if (idx_orig !=3D idx_patched) return NULL; =20 + dbg_correlate("find_twin_positional(): %s%s -> %s%s", + sym1->name, is_func_sym(sym1) ? "()" : "", + match->name, is_func_sym(match) ? "()" : ""); + return match; } =20 @@ -944,7 +965,7 @@ static struct symbol *clone_symbol(struct elfs *e, stru= ct symbol *patched_sym, if (patched_sym->clone) return patched_sym->clone; =20 - dbg_indent("%s%s", patched_sym->name, data_too ? " [+DATA]" : ""); + dbg_clone("%s%s", patched_sym->name, data_too ? " [+DATA]" : ""); =20 /* Make sure the prefix gets cloned first */ if (is_func_sym(patched_sym) && data_too) { @@ -1324,7 +1345,7 @@ static int clone_reloc_klp(struct elfs *e, struct rel= oc *patched_reloc, =20 klp_sym =3D find_symbol_by_name(e->out, sym_name); if (!klp_sym) { - __dbg_indent("%s", sym_name); + __dbg_clone("%s", sym_name); =20 /* STB_WEAK: avoid modpost undefined symbol warnings */ klp_sym =3D elf_create_symbol(e->out, sym_name, NULL, @@ -1375,7 +1396,7 @@ static int clone_reloc_klp(struct elfs *e, struct rel= oc *patched_reloc, } =20 #define dbg_clone_reloc(sec, offset, patched_sym, addend, export, klp) \ - dbg_indent("%s+0x%lx: %s%s0x%lx [%s%s%s%s%s%s]", \ + dbg_clone("%s+0x%lx: %s%s0x%lx [%s%s%s%s%s%s]", \ sec->name, offset, patched_sym->name, \ addend >=3D 0 ? "+" : "-", labs(addend), \ sym_type(patched_sym), \ @@ -1437,7 +1458,7 @@ static int clone_reloc(struct elfs *e, struct reloc *= patched_reloc, if (is_string_sec(patched_sym->sec)) { const char *str =3D patched_sym->sec->data->d_buf + addend; =20 - __dbg_indent("\"%s\"", escape_str(str)); + __dbg_clone("\"%s\"", escape_str(str)); =20 addend =3D elf_add_string(e->out, out_sym->sec, str); if (addend =3D=3D -1) @@ -2077,6 +2098,11 @@ int cmd_klp_diff(int argc, const char **argv) if (argc !=3D 3) usage_with_options(klp_diff_usage, klp_diff_options); =20 + if (debug) { + debug_correlate =3D true; + debug_clone =3D true; + } + objname =3D argv[0]; =20 e.orig =3D elf_open_read(argv[0], O_RDONLY); diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c index 1c3622117c33..a4e139dee7e9 100644 --- a/tools/objtool/objtool.c +++ b/tools/objtool/objtool.c @@ -16,9 +16,6 @@ #include #include =20 -bool debug; -int indent; - static struct objtool_file file; =20 struct objtool_file *objtool_open_read(const char *filename) --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C0273DE428; Thu, 23 Apr 2026 04:04:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917087; cv=none; b=KM4NXCDLPouUr/Pn3Eu2VU3rViaz65yPqxsZeRXfWwpbaKcwLnMHkPQ0Z1mxVePhO5afEnswejPiF6hUpVABS0L6S69C4F/jfyby8yrqpjF67+qpTbNnwdnReWSS/6AmdspbMZcbQ0POBUSbWbKzIO7CfAoFp+35wEnhYHhEPb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917087; c=relaxed/simple; bh=FJ/Y9BWcbaZl6ejRAnlM4cC3j3Cvsf19SCh9hgYDiiI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d3gSka1GX+drE4yXUeLsx8F/b67dJPX8WzyBUAb0jJAJtumnvsmXid5P0761KAizSYNKLjfklqksyY5RNQjAZutGzi3iue8GlEVoUB0taphfc1ca0MuEfk2GAkq3la8UCGpd5cZ2JJAFuzVweQKLOhgL5QlDvJxEj/VKUCNdTsU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bkMTFV16; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bkMTFV16" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4148AC2BCB2; Thu, 23 Apr 2026 04:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917086; bh=FJ/Y9BWcbaZl6ejRAnlM4cC3j3Cvsf19SCh9hgYDiiI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bkMTFV16QJTyQc0xqGZ8tAuDM1Cl1iGhjYdGZ3wPy4O8WS0EB+BHciYfS6Tv29S1r m2TYvX1U7BNpwtpiaWlwmtbUCL4zzqKfPfMREgUSXECsh+FTVpsN9PG7O0bOIV8ipk 2CcskBd5K02K06RIIyQLFTEBo4lkvkJ803N3s7+6peYHOABFWAGPgEeV700M7Z5Fau pPftebxpVjhJ99P6gS5Qek1Iw6dfm+LIMyEmj0b7HqcG5H6CL1JluAqIwgPXGdz2HU gHEvnkdd/VrgWhBRZVwYC25mwc2z/5ufqle3F3kM3fTmqWo2JgslcrfHtzCJclkdc0 IAmG6Zvwoegew== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 43/48] objtool: Add insn_sym() helper Date: Wed, 22 Apr 2026 21:04:11 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Alternative replacement instructions awkwardly have insn->sym set to the function they get patched to rather than the symbol (or rather lack thereof) they belong to in the file. This makes it difficult to know where a given instruction actually lives. Add a new insn_sym() helper which preserves the existing semantic of insn->sym. Rename insn->sym to insn->_sym, which contains the actual ELF binary symbol (or NULL, for alternative replacements) an instruction lives in. The private insn->_sym value will be needed for a subsequent patch. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 31 ++++++++++++--------------- tools/objtool/disas.c | 22 +++++++++---------- tools/objtool/include/objtool/check.h | 19 ++++++++++++++-- tools/objtool/include/objtool/warn.h | 6 +++--- tools/objtool/trace.c | 8 +++---- 5 files changed, 48 insertions(+), 38 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index ae047be919c5..410061aeed26 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -495,7 +495,7 @@ static int decode_instructions(struct objtool_file *fil= e) } =20 sym_for_each_insn(file, func, insn) { - insn->sym =3D func; + insn->_sym =3D func; if (is_func_sym(func) && insn->type =3D=3D INSN_ENDBR && list_empty(&insn->call_node)) { @@ -859,15 +859,14 @@ static int create_ibt_endbr_seal_sections(struct objt= ool_file *file) list_for_each_entry(insn, &file->endbr_list, call_node) { =20 int *site =3D (int *)sec->data->d_buf + idx; - struct symbol *sym =3D insn->sym; + struct symbol *func =3D insn_func(insn); *site =3D 0; =20 - if (opts.module && sym && is_func_sym(sym) && - insn->offset =3D=3D sym->offset && - (!strcmp(sym->name, "init_module") || - !strcmp(sym->name, "cleanup_module"))) { + if (opts.module && func && insn->offset =3D=3D func->offset && + (!strcmp(func->name, "init_module") || + !strcmp(func->name, "cleanup_module"))) { ERROR("%s(): Magic init_module() function name is deprecated, use modul= e_init(fn) instead", - sym->name); + func->name); return -1; } =20 @@ -1581,7 +1580,7 @@ static int add_jump_destinations(struct objtool_file = *file) } =20 if (!dest_sym || is_sec_sym(dest_sym)) { - dest_sym =3D dest_insn->sym; + dest_sym =3D insn_sym(dest_insn); if (!dest_sym) goto set_jump_dest; } @@ -1597,7 +1596,7 @@ static int add_jump_destinations(struct objtool_file = *file) continue; } =20 - if (!insn->sym || insn->sym->pfunc =3D=3D dest_sym->pfunc) + if (!insn_sym(insn) || insn_sym(insn)->pfunc =3D=3D dest_sym->pfunc) goto set_jump_dest; =20 /* @@ -1770,7 +1769,6 @@ static int handle_group_alt(struct objtool_file *file, nop->offset =3D special_alt->new_off + special_alt->new_len; nop->len =3D special_alt->orig_len - special_alt->new_len; nop->type =3D INSN_NOP; - nop->sym =3D orig_insn->sym; nop->alt_group =3D new_alt_group; nop->fake =3D 1; } @@ -1789,7 +1787,6 @@ static int handle_group_alt(struct objtool_file *file, =20 last_new_insn =3D insn; =20 - insn->sym =3D orig_insn->sym; insn->alt_group =3D new_alt_group; =20 /* @@ -2432,12 +2429,12 @@ static int __annotate_late(struct objtool_file *fil= e, int type, struct instructi break; =20 case ANNOTYPE_NOCFI: - sym =3D insn->sym; + sym =3D insn_sym(insn); if (!sym) { ERROR_INSN(insn, "dodgy NOCFI annotation"); return -1; } - insn->sym->nocfi =3D 1; + insn_sym(insn)->nocfi =3D 1; break; =20 default: @@ -2538,7 +2535,7 @@ static void mark_holes(struct objtool_file *file) * favour of a regular symbol, but leaves the code in place. */ for_each_insn(file, insn) { - if (insn->sym || !find_symbol_hole_containing(insn->sec, insn->offset)) { + if (insn_sym(insn) || !find_symbol_hole_containing(insn->sec, insn->offs= et)) { in_hole =3D false; continue; } @@ -2982,7 +2979,7 @@ static int update_cfi_state(struct instruction *insn, } =20 if (op->dest.reg =3D=3D CFI_BP && op->src.reg =3D=3D CFI_SP && - insn->sym->frame_pointer) { + insn_sym(insn)->frame_pointer) { /* addi.d fp,sp,imm on LoongArch */ if (cfa->base =3D=3D CFI_SP && cfa->offset =3D=3D op->src.offset) { cfa->base =3D CFI_BP; @@ -2994,7 +2991,7 @@ static int update_cfi_state(struct instruction *insn, if (op->dest.reg =3D=3D CFI_SP && op->src.reg =3D=3D CFI_BP) { /* addi.d sp,fp,imm on LoongArch */ if (cfa->base =3D=3D CFI_BP && cfa->offset =3D=3D 0) { - if (insn->sym->frame_pointer) { + if (insn_sym(insn)->frame_pointer) { cfa->base =3D CFI_SP; cfa->offset =3D -op->src.offset; } @@ -4171,7 +4168,7 @@ static int validate_retpoline(struct objtool_file *fi= le) * broken. */ list_for_each_entry(insn, &file->retpoline_call_list, call_node) { - struct symbol *sym =3D insn->sym; + struct symbol *sym =3D insn_sym(insn); =20 if (sym && (is_notype_sym(sym) || is_func_sym(sym)) && !sym->nocfi) { diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 59090234af19..e6a54a83605c 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -210,7 +210,7 @@ static bool disas_print_addr_alt(bfd_vma addr, struct d= isassemble_info *dinfo) offset =3D addr - alt_group->first_insn->offset; =20 addr =3D orig_first_insn->offset + offset; - sym =3D orig_first_insn->sym; + sym =3D insn_sym(orig_first_insn); =20 disas_print_addr_sym(orig_first_insn->sec, sym, addr, dinfo); =20 @@ -222,15 +222,13 @@ static void disas_print_addr_noreloc(bfd_vma addr, { struct disas_context *dctx =3D dinfo->application_data; struct instruction *insn =3D dctx->insn; - struct symbol *sym =3D NULL; + struct symbol *sym =3D insn_sym(insn); =20 if (disas_print_addr_alt(addr, dinfo)) return; =20 - if (insn->sym && addr >=3D insn->sym->offset && - addr < insn->sym->offset + insn->sym->len) { - sym =3D insn->sym; - } + if (sym && (addr < sym->offset || addr >=3D sym->offset + sym->len)) + sym =3D NULL; =20 disas_print_addr_sym(insn->sec, sym, addr, dinfo); } @@ -291,9 +289,9 @@ static void disas_print_address(bfd_vma addr, struct di= sassemble_info *dinfo) * up. So check it first. */ jump_dest =3D insn->jump_dest; - if (jump_dest && jump_dest->sym && jump_dest->offset =3D=3D addr) { + if (jump_dest && insn_sym(jump_dest) && jump_dest->offset =3D=3D addr) { if (!disas_print_addr_alt(addr, dinfo)) - disas_print_addr_sym(jump_dest->sec, jump_dest->sym, + disas_print_addr_sym(jump_dest->sec, insn_sym(jump_dest), addr, dinfo); return; } @@ -768,8 +766,8 @@ static int disas_alt_jump(struct disas_alt *dalt) if (orig_insn->len =3D=3D 5) suffix[0] =3D 'q'; str =3D strfmt("jmp%-3s %lx <%s+0x%lx>", suffix, - dest_insn->offset, dest_insn->sym->name, - dest_insn->offset - dest_insn->sym->offset); + dest_insn->offset, insn_sym(dest_insn)->name, + dest_insn->offset - insn_sym(dest_insn)->offset); nops =3D 0; } else { str =3D strfmt("nop%d", orig_insn->len); @@ -794,8 +792,8 @@ static int disas_alt_extable(struct disas_alt *dalt) =20 alt_insn =3D dalt->alt->insn; str =3D strfmt("resume at 0x%lx <%s+0x%lx>", - alt_insn->offset, alt_insn->sym->name, - alt_insn->offset - alt_insn->sym->offset); + alt_insn->offset, insn_sym(alt_insn)->name, + alt_insn->offset - insn_sym(alt_insn)->offset); if (!str) return -1; =20 diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index eea64728d39b..0c53476528a8 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -94,14 +94,29 @@ struct instruction { }; }; struct alternative *alts; - struct symbol *sym; + struct symbol *_sym; struct stack_op *stack_ops; struct cfi_state *cfi; }; =20 +/* + * Return the symbol associated with an instruction. For alternative + * replacements, return the symbol of the original code being replaced rat= her + * than NULL. insn->_sym reflects the actual location in the ELF file. + */ +static inline struct symbol *insn_sym(struct instruction *insn) +{ + struct symbol *sym =3D insn->_sym; + + if (!sym && insn->alt_group && insn->alt_group->orig_group) + sym =3D insn->alt_group->orig_group->first_insn->_sym; + + return sym; +} + static inline struct symbol *insn_func(struct instruction *insn) { - struct symbol *sym =3D insn->sym; + struct symbol *sym =3D insn_sym(insn); =20 if (sym && sym->type !=3D STT_FUNC) sym =3D NULL; diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/o= bjtool/warn.h index a9936d60980c..870e147f3a56 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -77,13 +77,13 @@ static inline char *offstr(struct section *sec, unsigne= d long offset) #define WARN_INSN(insn, format, ...) \ ({ \ struct instruction *_insn =3D (insn); \ - if (!_insn->sym || !_insn->sym->warned) { \ + if (!insn_sym(_insn) || !insn_sym(_insn)->warned) { \ WARN_FUNC(_insn->sec, _insn->offset, format, \ ##__VA_ARGS__); \ BT_INSN(_insn, ""); \ } \ - if (_insn->sym) \ - _insn->sym->warned =3D 1; \ + if (insn_sym(_insn)) \ + insn_sym(_insn)->warned =3D 1; \ }) =20 #define BT_INSN(insn, format, ...) \ diff --git a/tools/objtool/trace.c b/tools/objtool/trace.c index 5dec44dab781..61c6aa302bc3 100644 --- a/tools/objtool/trace.c +++ b/tools/objtool/trace.c @@ -169,8 +169,8 @@ void trace_alt_begin(struct instruction *orig_insn, str= uct alternative *alt, */ TRACE_ALT_INFO_NOADDR(orig_insn, "/ ", "%s for instruction at 0x%lx <%s+= 0x%lx>", alt_name, - orig_insn->offset, orig_insn->sym->name, - orig_insn->offset - orig_insn->sym->offset); + orig_insn->offset, insn_sym(orig_insn)->name, + orig_insn->offset - insn_sym(orig_insn)->offset); } else { TRACE_ALT_INFO_NOADDR(orig_insn, "/ ", "%s", alt_name); } @@ -185,8 +185,8 @@ void trace_alt_begin(struct instruction *orig_insn, str= uct alternative *alt, if (orig_insn->type =3D=3D INSN_NOP) { suffix[0] =3D (orig_insn->len =3D=3D 5) ? 'q' : '\0'; TRACE_ADDR(orig_insn, "jmp%-3s %lx <%s+0x%lx>", suffix, - alt_insn->offset, alt_insn->sym->name, - alt_insn->offset - alt_insn->sym->offset); + alt_insn->offset, insn_sym(alt_insn)->name, + alt_insn->offset - insn_sym(alt_insn)->offset); } else { TRACE_ADDR(orig_insn, "nop%d", orig_insn->len); trace_depth--; --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F02E3DE43B; Thu, 23 Apr 2026 04:04:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917087; cv=none; b=mj4jC1Yjl2X6sufs6NnY5c73RWmv78Tw8xepVlzWq+9cjEdKjkGKnwggzNeadTTVZ4fEokWnBSOmh2fqXHLccYTtjp5ySOtq+JY8oQdviR3A40Zyrne1ZCSqw1gmCAXk2DvA78TS/g8JAVTWconKtKfjdDi6LtsOjDIqSJNuaCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917087; c=relaxed/simple; bh=k0wkC3ZtERLufbrxciB55SYGNx4LscQb4oK+lu00MeQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n2SvA4z8GAXJP0fpBZDaKZY4TQ20sr9kOZ4/TjFgB3kvBlianS/Po90dTzE0cvyANXvIlrCFvR7E9rNxEko0hUgVJbk0DNFBYge0Xm8qNdpDhb+93MUD1iFwVsLomI2ka0X2GR/amgXLPz2aXNbrqyf+mR5rqNQOGnxDjlQh560= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HUGNA1vS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HUGNA1vS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2117C2BCB5; Thu, 23 Apr 2026 04:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917087; bh=k0wkC3ZtERLufbrxciB55SYGNx4LscQb4oK+lu00MeQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HUGNA1vSr+2XrVwdGReq9tkvDWmxVLnO6PNpjLATZrLlH8WAFhsPyx7lVi1MZPdvm L06g0DJD80u82J4ErJ2770XDxXWla6lQ3ml0URKm3XefjjscPRrqDO+4/HcwMr6vtg ev0YteGnzasN78tvibh7xcoba0I0M36AbVEO/JILtQgeEZ0Zwv8lE+VSO2jvdeuBxF ZgFT/PK1oCNlteW3FBKyC9Nb0vUdtnojlT38sBktsFQREmW8931NdPx1PPJPddPF9z YVgnxf0qEXIuWmV0nD1Z1SUZNR/ZK0hu7FkIi86Z3QbshPSPcJ1AVaIdXNagdltSZ0 wJkKhw3pvrZ9A== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 44/48] objtool/klp: Fix position-dependent checksums for non-relocated jumps/calls Date: Wed, 22 Apr 2026 21:04:12 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When computing klp checksums, instructions with non-relocated jump/call destination offsets are problematic because the offset values can change when surrounding code has moved, causing the function to be incorrectly marked as changed. Specifically, that includes jumps from alternatives to the end of the alternative, which from objtool's perspective are jumps to the end of the alternative instruction block in the original function. Note that 'jump_dest' jumps don't include sibling calls (those use call_dest), nor do they include jumps to/from .cold sub functions (those are cross-section and need a reloc). Fix it by hashing the opcode bytes (excluding the immediate operand) along with a position-independent representation of the destination. For calls, use the function name, and for jumps, use the destination's offset within its function. [Note the "9 bit hole" comment was wrong: it has been 8 bits since commit 70589843b36f ("objtool: Add option to trace function validation") added the 'trace' field. Adding the 4-bit 'immediate_len' field now leaves a 4-bit hole.] Fixes: 0d83da43b1e1 ("objtool/klp: Add --checksum option to generate per-fu= nction checksums") Signed-off-by: Josh Poimboeuf --- tools/objtool/arch/x86/decode.c | 17 ++++++++- tools/objtool/include/objtool/arch.h | 3 ++ tools/objtool/include/objtool/check.h | 3 +- tools/objtool/klp-checksum.c | 53 ++++++++++++++++++++++++--- 4 files changed, 67 insertions(+), 9 deletions(-) diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index 350b8ee6e776..1b387d5a195b 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -805,14 +805,27 @@ int arch_decode_instruction(struct objtool_file *file= , const struct section *sec break; } =20 - if (ins.immediate.nbytes) + if (ins.immediate.nbytes) { insn->immediate =3D ins.immediate.value; - else if (ins.displacement.nbytes) + insn->immediate_len =3D ins.immediate.nbytes; + } else if (ins.displacement.nbytes) { insn->immediate =3D ins.displacement.value; + insn->immediate_len =3D ins.displacement.nbytes; + } =20 return 0; } =20 +size_t arch_jump_opcode_bytes(struct objtool_file *file, struct instructio= n *insn, + unsigned char *buf) +{ + size_t len; + + len =3D insn->len - insn->immediate_len; + memcpy(buf, insn->sec->data->d_buf + insn->offset, len); + return len; +} + void arch_initial_func_cfi_state(struct cfi_init_state *state) { int i; diff --git a/tools/objtool/include/objtool/arch.h b/tools/objtool/include/o= bjtool/arch.h index 8866158975fc..96d828a8401f 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -79,6 +79,9 @@ int arch_decode_instruction(struct objtool_file *file, co= nst struct section *sec unsigned long offset, unsigned int maxlen, struct instruction *insn); =20 +size_t arch_jump_opcode_bytes(struct objtool_file *file, struct instructio= n *insn, + unsigned char *buf); + bool arch_callee_saved_reg(unsigned char reg); =20 unsigned long arch_jump_destination(struct instruction *insn); diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index 0c53476528a8..bc99355e66e9 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -68,6 +68,7 @@ struct instruction { s8 instr; =20 u32 idx : INSN_CHUNK_BITS, + immediate_len : 4, dead_end : 1, ignore_alts : 1, hint : 1, @@ -81,7 +82,7 @@ struct instruction { hole : 1, fake : 1, trace : 1; - /* 9 bit hole */ + /* 4 bit hole */ =20 struct alt_group *alt_group; struct instruction *jump_dest; diff --git a/tools/objtool/klp-checksum.c b/tools/objtool/klp-checksum.c index adfd02447a45..4100b4dfba86 100644 --- a/tools/objtool/klp-checksum.c +++ b/tools/objtool/klp-checksum.c @@ -66,17 +66,58 @@ static void checksum_update_insn(struct objtool_file *f= ile, struct symbol *func, if (insn->fake) return; =20 - __checksum_update_insn(func, insn, insn->sec->data->d_buf + insn->offset,= insn->len); - if (!reloc) { struct symbol *call_dest =3D insn_call_dest(insn); + struct instruction *jump_dest =3D insn->jump_dest; =20 - if (call_dest) - __checksum_update_insn(func, insn, call_dest->demangled_name, - strlen(call_dest->demangled_name)); - goto alts; + /* + * For a jump/call non-relocated dest offset embedded in the + * instruction, the offset may vary due to changes in + * surrounding code. Just hash the opcode and a + * position-independent representation of the destination. + */ + + if (call_dest || jump_dest) { + unsigned char buf[16]; + size_t len; + + len =3D arch_jump_opcode_bytes(file, insn, buf); + __checksum_update_insn(func, insn, buf, len); + + if (call_dest) { + __checksum_update_insn(func, insn, call_dest->demangled_name, + strlen(call_dest->demangled_name)); + + } else if (jump_dest) { + struct symbol *dest_sym; + unsigned long offset; + + /* + * use insn->_sym instead of insn_sym() here. + * For alternative replacements, the latter + * would give the function of the code being + * replaced. + */ + dest_sym =3D jump_dest->_sym; + if (!dest_sym) + goto alts; + + __checksum_update_insn(func, insn, dest_sym->demangled_name, + strlen(dest_sym->demangled_name)); + + offset =3D jump_dest->offset - dest_sym->offset; + __checksum_update_insn(func, insn, &offset, sizeof(offset)); + } + + goto alts; + } } =20 + __checksum_update_insn(func, insn, insn->sec->data->d_buf + insn->offset,= insn->len); + + if (!reloc) + goto alts; + sym =3D reloc->sym; offset =3D arch_insn_adjusted_addend(insn, reloc); =20 --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFEE33D9054; Thu, 23 Apr 2026 04:04:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917087; cv=none; b=UjzqRi7TPOkRchuXlI/V9NXY2wcfAUWEOCH/ynA+45b/meOW+QqiCyv0cEH41quqNTjarbfovS8FoA1nL4RlWfwVFiw8OzwdTPAabQBz+L3kbXy5Zprh7RztxxX/I17G46bK7IFouVNXZagyoGSIn06tMChd+SRR0Bvz4KlXiG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917087; c=relaxed/simple; bh=jmH/VKCty/iodGaVUHV5BrqXJdFzVyb8Cmk8zWijg8w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AEecHfP9qTKvKJDiSMRkhLYlYbYMuzxBXRMBu7RzW/XH8Vcdpg9GtAAOmn8GkhXL03s1hPBOq8+yebk3aF/UahcjQ/kepf/29p4fV9TnIs+2B1M/lUu6Ex5jWmwQFOtPojVhillHQq0Yu6NU1GX98f6A1JgX+mCt/MZnjctpgYo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YsFbKer+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YsFbKer+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3EE20C2BCB2; Thu, 23 Apr 2026 04:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917087; bh=jmH/VKCty/iodGaVUHV5BrqXJdFzVyb8Cmk8zWijg8w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YsFbKer+mw5YiGBPTDk47cFunDmnrwF8xmy4Yevn6it73xihNSdI7/IRoHFPjFpbc iU9MieBK5xCg0G9phrOvyVmdgQP9UflP45Z/wVXoYMBuEeD44t+opS/pIcS67X6OZT Z1kW/IIyJVGQSfIrA9oUIgVfi9XXzuCEmIHtBTgOJ84ojq/nb46OxR7ZKK6EK2G4+b TMkdqE0W0H6jcC0/mbQ1lFQpt8kDwEuLnHf0qJ92fXWERviawR9hY/YPURl6KDTQrN GCI9zzplzQh023ILGrg1uXzt8e3VcptGI41bRYQz2OIXYWNngqRGVBXUwNfmxBQUKW k8GqZ0jvPDd4g== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 45/48] x86/Kconfig: Enable CONFIG_PREFIX_SYMBOLS for FineIBT Date: Wed, 22 Apr 2026 21:04:13 -0700 Message-ID: <70107aab81b01f8a2360f052ff550a9e97c30f79.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" PREFIX_SYMBOLS has a !CFI dependency because the compiler already generates __cfi_ prefix symbols for kCFI builds, so objtool-generated __pfx_ symbols were considered redundant. However, the __cfi_ symbols only cover the 5-byte kCFI type hash. With FUNCTION_CALL_PADDING, there are also 11 bytes of NOP padding between the hash and the function entry which have no symbol to claim them. The NOPs can be rewritten with call depth tracking thunks at runtime. Without a symbol, unwinders and other tools that symbolize code locations misattribute those bytes. Remove the !CFI guard so objtool creates __pfx_ symbols for all CALL_PADDING configs, covering the full padding area regardless of whether there's also a __cfi_ symbol. Signed-off-by: Josh Poimboeuf --- arch/x86/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index f3f7cb01d69d..493b0038ac8d 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -2439,7 +2439,7 @@ config CALL_THUNKS =20 config PREFIX_SYMBOLS def_bool y - depends on CALL_PADDING && !CFI + depends on CALL_PADDING =20 menuconfig CPU_MITIGATIONS bool "Mitigations for CPU vulnerabilities" --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41FC43DEAD6; Thu, 23 Apr 2026 04:04:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917088; cv=none; b=lgyzIMFkij+QfKbJN3SGuoh+8OtCDSc1G+GlJT2qX/fpTkTOYnEu4ajHETd9fWTrOF0L4cTUKbFUvHzyQS5Lope5xOnlXkM8Ss25NPwEQHWKOsH2sTgjlNINkzbuVGKiySYA4qz5sJTljOub/xRX13r78jDhD8iQwlneaPRElmM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917088; c=relaxed/simple; bh=h6zRAY4MZHAqnNqN11j07fqZ4dA1MwgNBlIVRviGFls=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g2yIzVyBd+kkP6luyczZ8VILPOoq0gTSlgZnGd7s6GAIKhnJEbr7jmnQRmsIxBSi2BhGcvuLM3g4iR5hKGJliUu+6BeJEUSofvkHE7iwYqHKPUODg85wGsoh6Aq+gw1jnr77yDNsoVH1O1ssvrfMU0yOUtdO212eE42/hKj8LKE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pD5Pn2A0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pD5Pn2A0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2EB4C2BCB5; Thu, 23 Apr 2026 04:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917088; bh=h6zRAY4MZHAqnNqN11j07fqZ4dA1MwgNBlIVRviGFls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pD5Pn2A05HKIyzHzGgjocnBkW9h13tTbHMpYaSB+LoQuxa02+rNQvVYntBZHrn8Us SmN0uIgy1/44Qnsf7nru9XlUPR2z99xTMShg9NsU4VxdwVSj+F8Y5FEKAMp2ujAZii /TymBO3EuwGfPCzUoh/6m9o716vGUai8ufEtV6nyl+GGiTd5Qg+NIZLppALTyFaUIR VKioCiwCNODctswhYKpPbTILHpGjmlmgHZtcK0zWqra/1nlzCKsqgwCc8hw9otbvsH lOETFFVYH7n8iTamlU+RAj2zoNHhTZF/wq9qiWIcUhXgbOb9QyJT4CL0Pp+NLxiQt1 grigtftmUAzqA== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 46/48] objtool/klp: Make function prefix handling more generic Date: Wed, 22 Apr 2026 21:04:14 -0700 Message-ID: <666c12d66a3bc3c628a265da67801090132956ca.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The way x86 klp-diff handles function prefix symbols is a bit awkward, Also, x86 is the only arch which needs the __pfx_/cfi_ prefix symbols, so this approach isn't extensible to other arches. And while other arches *do* use __patchable_function_entries (PFEs), they use them in completely different ways. In preparation for supporting other arches, use a more generic approach that will work for all arches with prefixed areas and/or PFE sections. Signed-off-by: Josh Poimboeuf --- tools/objtool/include/objtool/elf.h | 15 +-- tools/objtool/klp-diff.c | 187 ++++++++++++++++++++++++---- 2 files changed, 161 insertions(+), 41 deletions(-) diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index ba13dd67cf26..21441bd72971 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -119,6 +119,7 @@ struct elf { struct list_head sections; struct list_head symbols; unsigned long num_relocs; + int pfe_offset; =20 int symbol_bits; int symbol_name_bits; @@ -532,20 +533,6 @@ static inline void set_sym_next_reloc(struct reloc *re= loc, struct reloc *next) reloc && reloc_offset(reloc) < sym->offset + sym->len; \ reloc =3D rsec_next_reloc(sym->sec->rsec, reloc)) =20 -static inline struct symbol *get_func_prefix(struct symbol *func) -{ - struct symbol *prev; - - if (!is_func_sym(func)) - return NULL; - - prev =3D sec_prev_sym(func); - if (prev && is_prefix_func(prev)) - return prev; - - return NULL; -} - #define OFFSET_STRIDE_BITS 4 #define OFFSET_STRIDE (1UL << OFFSET_STRIDE_BITS) #define OFFSET_STRIDE_MASK (~(OFFSET_STRIDE - 1)) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index acb76aefd04f..420d05633aba 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -213,6 +213,88 @@ static int read_sym_checksums(struct elf *elf) return 0; } =20 +/* + * Detect the offset from the function entry point to its + * __patchable_function_entries (PFE) relocation target. + * + * offset < 0 (before function entry): + * + * CONFIG_FINEIBT (x86) + * CONFIG_MITIGATION_CALL_DEPTH_TRACKING (x86) + */ +static int read_pfe_offset(struct elf *elf) +{ + bool has_pfe =3D false; + struct section *sec; + + for_each_sec(elf, sec) { + struct reloc *reloc; + + if (strcmp(sec->name, "__patchable_function_entries")) + continue; + if (!sec->rsec) + continue; + + has_pfe =3D true; + + for_each_reloc(sec->rsec, reloc) { + unsigned long target =3D reloc->sym->offset + reloc_addend(reloc); + struct symbol *func; + + func =3D find_func_containing(reloc->sym->sec, target); + if (func) { + if (is_prefix_func(func)) + elf->pfe_offset =3D target - (func->offset + func->len); + else + elf->pfe_offset =3D target - func->offset; + return 0; + } + } + } + + if (has_pfe) { + ERROR("can't find __patchable_function_entries offset"); + return -1; + } + + return 0; +} + +/* + * Detect the size of the area before a function's entry point. This pref= ix + * area is used for CFI type hashes, call thunks, or ftrace call ops. + * + * __pfx_ prefix function (x86): + * + * CONFIG_MITIGATION_CALL_DEPTH_TRACKING + * + * __cfi_ prefix function (x86): + * + * CONFIG_CFI + */ +static unsigned long func_pfx_size(struct elf *elf, struct symbol *func) +{ + struct symbol *pfx; + + /* x86 __pfx_ and/or __cfi_ */ + if (func->offset) { + pfx =3D find_func_containing(func->sec, func->offset - 1); + if (pfx && pfx->prefix) { + struct symbol *pfx2; + + /* FineIBT has both */ + if (pfx->offset) { + pfx2 =3D find_func_containing(func->sec, pfx->offset - 1); + if (pfx2 && pfx2->prefix) + pfx =3D pfx2; + } + + return func->offset - pfx->offset; + } + } + return 0; +} + static struct symbol *first_file_symbol(struct elf *elf) { struct symbol *sym; @@ -302,6 +384,7 @@ static bool is_special_section(struct section *sec) "__ex_table", "__jump_table", "__mcount_loc", + "__patchable_function_entries", =20 /* * Extract .static_call_sites here to inherit non-module @@ -872,7 +955,7 @@ static struct symbol *__clone_symbol(struct elf *elf, s= truct symbol *patched_sym bool data_too) { struct section *out_sec =3D NULL; - unsigned long offset =3D 0; + unsigned long offset =3D 0, pfx_size =3D 0; struct symbol *out_sym; =20 if (data_too && !is_undef_sym(patched_sym)) { @@ -901,20 +984,26 @@ static struct symbol *__clone_symbol(struct elf *elf,= struct symbol *patched_sym offset =3D ALIGN(sec_size(out_sec), out_sec->sh.sh_addralign); =20 if (patched_sym->len || is_sec_sym(patched_sym)) { - void *data =3D NULL; size_t size; + void *data =3D NULL; + + /* Clone function prefix area */ + if (is_func_sym(patched_sym)) + pfx_size =3D func_pfx_size(elf, patched_sym); =20 /* bss doesn't have data */ if (patched_sym->sec->data && patched_sym->sec->data->d_buf) - data =3D patched_sym->sec->data->d_buf + patched_sym->offset; + data =3D patched_sym->sec->data->d_buf + patched_sym->offset - pfx_siz= e; =20 if (is_sec_sym(patched_sym)) size =3D sec_size(patched_sym->sec); else - size =3D patched_sym->len; + size =3D patched_sym->len + pfx_size; =20 if (!elf_add_data(elf, out_sec, data, size)) return NULL; + + offset +=3D pfx_size; } } =20 @@ -924,6 +1013,23 @@ static struct symbol *__clone_symbol(struct elf *elf,= struct symbol *patched_sym if (!out_sym) return NULL; =20 + /* + * The copied prefixed area may have had a __cfi_ symbol which needs to + * be copied. During the module link, objtool collates these in a + * .cfi_sites section for FineIBT. + */ + if (pfx_size && is_func_sym(patched_sym)) { + struct symbol *cfi_sym; + + cfi_sym =3D find_func_containing(patched_sym->sec, patched_sym->offset -= pfx_size); + if (cfi_sym && strstarts(cfi_sym->name, "__cfi_")) { + if (!elf_create_symbol(elf, cfi_sym->name, out_sec, + cfi_sym->bind, cfi_sym->type, + offset - pfx_size, cfi_sym->len)) + return NULL; + } + } + sym_created: patched_sym->clone =3D out_sym; out_sym->clone =3D patched_sym; @@ -960,20 +1066,11 @@ static const char *sym_bind(struct symbol *sym) static struct symbol *clone_symbol(struct elfs *e, struct symbol *patched_= sym, bool data_too) { - struct symbol *pfx; - if (patched_sym->clone) return patched_sym->clone; =20 dbg_clone("%s%s", patched_sym->name, data_too ? " [+DATA]" : ""); =20 - /* Make sure the prefix gets cloned first */ - if (is_func_sym(patched_sym) && data_too) { - pfx =3D get_func_prefix(patched_sym); - if (pfx) - clone_symbol(e, pfx, true); - } - if (!__clone_symbol(e->out, patched_sym, data_too)) return NULL; =20 @@ -985,15 +1082,8 @@ static struct symbol *clone_symbol(struct elfs *e, st= ruct symbol *patched_sym, =20 static void mark_included_function(struct symbol *func) { - struct symbol *pfx; - func->included =3D 1; =20 - /* Include prefix function */ - pfx =3D get_func_prefix(func); - if (pfx) - pfx->included =3D 1; - /* Make sure .cold parent+child always stay together */ if (func->cfunc && func->cfunc !=3D func) func->cfunc->included =3D 1; @@ -1222,17 +1312,37 @@ static int convert_reloc_sym_to_secsym(struct elf *= elf, struct reloc *reloc) return 0; } =20 +/* + * __patchable_function_entries relocs point to the patchable entry NOPs, + * which are at 'pfe_offset' bytes from the function symbol. + * + * Some entries (e.g., removed weak functions, syscall -ENOSYS stubs) don't + * have a corresponding function symbol. Skip those with a return value o= f 1. + */ +static int convert_pfe_reloc(struct elf *elf, struct reloc *reloc) +{ + struct symbol *func; + + func =3D find_func_by_offset(reloc->sym->sec, + reloc->sym->offset + + reloc_addend(reloc) - elf->pfe_offset); + if (!func) + return 1; + + reloc->sym =3D func; + set_reloc_sym(elf, reloc, func->idx); + set_reloc_addend(elf, reloc, elf->pfe_offset); + return 0; +} + static int convert_reloc_secsym_to_sym(struct elf *elf, struct reloc *relo= c) { struct symbol *sym =3D reloc->sym; struct section *sec =3D sym->sec; =20 - /* If the symbol has a dedicated section, it's easy to find */ - sym =3D find_symbol_by_offset(sec, 0); - if (sym && sym->len =3D=3D sec_size(sec)) - goto found_sym; + if (!strcmp(reloc->sec->name, ".rela__patchable_function_entries")) + return convert_pfe_reloc(elf, reloc); =20 - /* No dedicated section; find the symbol manually */ sym =3D find_symbol_containing(sec, arch_adjusted_addend(reloc)); if (!sym) { /* @@ -1249,7 +1359,6 @@ static int convert_reloc_secsym_to_sym(struct elf *el= f, struct reloc *reloc) return -1; } =20 -found_sym: reloc->sym =3D sym; set_reloc_sym(elf, reloc, sym->idx); set_reloc_addend(elf, reloc, reloc_addend(reloc) - sym->offset); @@ -1802,6 +1911,9 @@ static int validate_special_section_klp_reloc(struct = elfs *e, struct symbol *sym =20 static int clone_special_section(struct elfs *e, struct section *patched_s= ec) { + bool is_pfe =3D !strcmp(patched_sec->name, "__patchable_function_entries"= ); + struct section *out_sec =3D NULL; + struct reloc *patched_reloc; struct symbol *patched_sym; =20 /* @@ -1809,6 +1921,7 @@ static int clone_special_section(struct elfs *e, stru= ct section *patched_sec) * reference included functions. */ sec_for_each_sym(patched_sec, patched_sym) { + struct symbol *out_sym; int ret; =20 if (!is_object_sym(patched_sym)) @@ -1823,8 +1936,23 @@ static int clone_special_section(struct elfs *e, str= uct section *patched_sec) if (ret > 0) continue; =20 - if (!clone_symbol(e, patched_sym, true)) + out_sym =3D clone_symbol(e, patched_sym, true); + if (!out_sym) return -1; + + if (!is_pfe || (out_sec && out_sec->sh.sh_link)) + continue; + + /* + * For reasons, the patched object has multiple PFE sections, + * but we only need to create one combined section for the + * output. Link the single PFE ouput section to a random text + * section to satisfy the linker for SHF_LINK_ORDER. + */ + out_sec =3D out_sym->sec; + patched_reloc =3D find_reloc_by_dest(e->patched, patched_sec, + patched_sym->offset); + out_sec->sh.sh_link =3D patched_reloc->sym->clone->sec->idx; } =20 return 0; @@ -2121,6 +2249,9 @@ int cmd_klp_diff(int argc, const char **argv) if (read_sym_checksums(e.patched)) return -1; =20 + if (read_pfe_offset(e.patched)) + return -1; + if (correlate_symbols(&e)) return -1; =20 @@ -2134,6 +2265,8 @@ int cmd_klp_diff(int argc, const char **argv) if (!e.out) return -1; =20 + e.out->pfe_offset =3D e.patched->pfe_offset; + /* * Special section fake symbols are needed so that individual special * section entries can be extracted by clone_special_sections(). --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DD753DEAEC; Thu, 23 Apr 2026 04:04:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917088; cv=none; b=A7bDgVt6yA6VF4kawgccNNmWaRKVtm3Sz8SxsgnCzcPjOPfPRBpj7SjW2VsIQVE47gshm+OQ8id5CdLs3PIJSEzXiLPUJ0oMESMq/MX63iKpAh1q12ZqmVI/UpfWU+BSfHspA86WaJqbvkFt/uPPQLw+Un5pF6ZCuVulC37Xep0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917088; c=relaxed/simple; bh=wIc5nXX6Jz223dE6PJMDQQKraiu/sKQQ6i4/IJEIOzk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N6BGV8Oy1BkbfyBJYcfP3YKPgJ6HPtrREYPP2SuAUoro0rJ+usTYuTpDyMWL9Ap8KUQbELZ11fM0RlTUx8vRei6WKHInkoa65uwA7s+625Tr5D13jBJr5pHrp3rXcrp9Jf+qwT2IUJwyWMMvM2GlnMHJ1HrM470kLZSIQ96VN/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DPDOBKmO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DPDOBKmO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30829C2BCB4; Thu, 23 Apr 2026 04:04:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917088; bh=wIc5nXX6Jz223dE6PJMDQQKraiu/sKQQ6i4/IJEIOzk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DPDOBKmO2SCP1Q0QS2lpJONcdtDtFgooduX4v8wrwmnWZAkDcYnI8dCoR6pYLHnc6 d9a+6uv6A9LTydM49dUzS+D0R4DPGS+eLrtiHwKbjrwQ1u6V+wzIalmtAoO70h8ngb GkPpFpQAaqmhSrPuEnLhHOQSXqEppNmxP9oqteHR9f3DwdMmv1E0+yVwEObw5LZWxu 7lfWWtRoenRte2w/IzVsDGqtRNk6H1EySJLSex3UwVvzSG7xb5wZAECZjeOcAX2Ehh 7iNDXJaP1nvPbZWmzqxPE4fG3EIlClAcioE1LITQmw39FbQTi07n7Gave4z+9UPMhK arwVO6tyrOgDQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 47/48] objtool: Improve and simplify prefix symbol detection Date: Wed, 22 Apr 2026 21:04:15 -0700 Message-ID: <45d385f7112ccb71f991a8524e3f9f48b37c1fd9.1776916871.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Only create prefix symbols for functions that have __patchable_function_entries entries, since those are the only functions where prefix NOPs are intentional. This both simplifies the detection and makes it more accurate. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 90 ++++++++++--------------------------------- 1 file changed, 21 insertions(+), 69 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 410061aeed26..d438c5a4444b 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4271,17 +4271,6 @@ static bool ignore_unreachable_insn(struct objtool_f= ile *file, struct instructio * For FineIBT or kCFI, a certain number of bytes preceding the function m= ay be * NOPs. Those NOPs may be rewritten at runtime and executed, so give the= m a * proper function name: __pfx_. - * - * The NOPs may not exist for the following cases: - * - * - compiler cloned functions (*.cold, *.part0, etc) - * - asm functions created with inline asm or without SYM_FUNC_START() - * - * Also, the function may already have a prefix from a previous objtool run - * (livepatch extracted functions, or manually running objtool multiple ti= mes). - * - * So return 0 if the NOPs are missing or the function already has a prefix - * symbol. */ static int create_prefix_symbol(struct objtool_file *file, struct symbol *= func) { @@ -4289,10 +4278,6 @@ static int create_prefix_symbol(struct objtool_file = *file, struct symbol *func) char name[SYM_NAME_LEN]; struct cfi_state *cfi; =20 - if (!is_func_sym(func) || is_prefix_func(func) || is_cold_func(func) || - func->static_call_tramp) - return 0; - if ((strlen(func->name) + sizeof("__pfx_") > SYM_NAME_LEN)) { WARN("%s: symbol name too long, can't create __pfx_ symbol", func->name); @@ -4302,59 +4287,21 @@ static int create_prefix_symbol(struct objtool_file= *file, struct symbol *func) if (snprintf_check(name, SYM_NAME_LEN, "__pfx_%s", func->name)) return -1; =20 - if (file->klp) { - struct symbol *pfx; - - pfx =3D find_symbol_by_offset(func->sec, func->offset - opts.prefix); - if (pfx && is_prefix_func(pfx) && !strcmp(pfx->name, name)) - return 0; - } - - insn =3D find_insn(file, func->sec, func->offset); - if (!insn) { - WARN("%s: can't find starting instruction", func->name); + if (!elf_create_symbol(file->elf, name, func->sec, + GELF_ST_BIND(func->sym.st_info), + GELF_ST_TYPE(func->sym.st_info), + func->offset - opts.prefix, opts.prefix)) return -1; - } - - for (prev =3D prev_insn_same_sec(file, insn); - prev; - prev =3D prev_insn_same_sec(file, prev)) { - u64 offset; - - if (prev->type !=3D INSN_NOP) - return 0; - - offset =3D func->offset - prev->offset; - - if (offset > opts.prefix) - return 0; - - if (offset < opts.prefix) - continue; - - if (!elf_create_symbol(file->elf, name, func->sec, - GELF_ST_BIND(func->sym.st_info), - GELF_ST_TYPE(func->sym.st_info), - prev->offset, opts.prefix)) - return -1; - - break; - } - - if (!prev) - return 0; - - if (!insn->cfi) { - /* - * This can happen if stack validation isn't enabled or the - * function is annotated with STACK_FRAME_NON_STANDARD. - */ - return 0; - } =20 /* Propagate insn->cfi to the prefix code */ + insn =3D find_insn(file, func->sec, func->offset); + if (!insn || !insn->cfi) + return 0; + cfi =3D cfi_hash_find_or_add(insn->cfi); - for (; prev !=3D insn; prev =3D next_insn_same_sec(file, prev)) + for (prev =3D find_insn(file, func->sec, func->offset - opts.prefix); + prev && prev !=3D insn; + prev =3D next_insn_same_sec(file, prev)) prev->cfi =3D cfi; =20 return 0; @@ -4362,15 +4309,20 @@ static int create_prefix_symbol(struct objtool_file= *file, struct symbol *func) =20 static int create_prefix_symbols(struct objtool_file *file) { - struct section *sec; + struct section *pfe_sec; struct symbol *func; + struct reloc *reloc; =20 - for_each_sec(file->elf, sec) { - if (!is_text_sec(sec)) + for_each_sec(file->elf, pfe_sec) { + if (strcmp(pfe_sec->name, "__patchable_function_entries")) + continue; + if (!pfe_sec->rsec) continue; =20 - sec_for_each_sym(sec, func) { - if (create_prefix_symbol(file, func)) + for_each_reloc(pfe_sec->rsec, reloc) { + func =3D find_func_by_offset(reloc->sym->sec, + reloc->sym->offset + reloc_addend(reloc) + opts.prefix); + if (func && create_prefix_symbol(file, func)) return -1; } } --=20 2.53.0 From nobody Wed Jun 17 05:10:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6052B3DC4D8; Thu, 23 Apr 2026 04:04:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917089; cv=none; b=kT7h3+pXztRoDRtjbA1pH8+tlFRgwBVIAWhNq1kYghX1uMoN5t6M5lk+x+iLhpLd40eqFAriTA1nFinbZBrFCMdvSWMiddk/9fDlg7Jd9gCq64YeeDqVBVjK3mMIwL+3m+oTmOPqRe+BHS49/fCamgEX8rRu30hIpMk4nrMWdLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917089; c=relaxed/simple; bh=X4dg66aAqYt7wEo6E6eFhwh+BC1shUoGhNLsTu5F2rE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MB/0ntorqAUMa97QXH/ucF6V1jZpcNVEimXQjw2HtB15viuSb/OZfFNn5PMfB++3nfAjTeVXjBztNOrV51YQg3upxi5fII9U73hTXqAPNaP8+M7ugkPn79ubk/4B2EGvvr90htpxjQVJU7f6mMsP1LCW1QZ0UbnLE+uciILximY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YsM4P7Am; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YsM4P7Am" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2D82C2BCC4; Thu, 23 Apr 2026 04:04:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776917089; bh=X4dg66aAqYt7wEo6E6eFhwh+BC1shUoGhNLsTu5F2rE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YsM4P7AmPt9KiGADmJ6hySaQDs+6gyWzU/RrRKxa4nUy1uDiVl98dKnH4voyGKd+S tIm6twNhHkFtSiGWTy1NhctxW+l4TKfgyaUKUx3GWLxcNw/gKCSS0662y2tdVCfJIk Nh4oBi7bSTBt9xtuqwjSHyrItzz4ID3c/LXQZKI8J8hX1+mlCmMwOAfMzNLC6FsZKq fe5Qggou7fVP+ARzyKufEeeRBDnEjizkEdryGZc6ZlIpq+gIOi8WmZP9DIJ/tTQ6Xk 1eCGs1G1cP+V57kV3VISVQT/NkBuCe2ShozP3VMKPqvbfCwu/Adro+MdcCyUOPxxaf jr2Pu5Rcjbczg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Joe Lawrence , Song Liu , Miroslav Benes , Petr Mladek Subject: [PATCH 48/48] objtool/klp: Cache dont_correlate() result Date: Wed, 22 Apr 2026 21:04:16 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Cache the dont_correlate() result once per symbol at the start of correlate_symbols(). This reduces klp diff time on an arm64 LTO vmlinux.o from 2m51s to 35s. Signed-off-by: Josh Poimboeuf Acked-by: Song Liu --- tools/objtool/include/objtool/elf.h | 1 + tools/objtool/klp-diff.c | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 21441bd72971..fb4fec7d8a6e 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -95,6 +95,7 @@ struct symbol { u8 changed : 1; u8 included : 1; u8 klp : 1; + u8 dont_correlate : 1; struct list_head pv_target; struct reloc *relocs; struct section *group_sec; diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 420d05633aba..a848015b477c 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -566,7 +566,7 @@ static struct symbol *find_twin(struct elfs *e, struct = symbol *sym1) =20 /* Count orig candidates */ for_each_sym_by_demangled_name(e->orig, sym1->demangled_name, sym2) { - if (sym2->twin || sym1->type !=3D sym2->type || dont_correlate(sym2) || + if (sym2->twin || sym1->type !=3D sym2->type || sym2->dont_correlate || (!maybe_same_file(sym1, sym2))) continue; =20 @@ -592,7 +592,7 @@ static struct symbol *find_twin(struct elfs *e, struct = symbol *sym1) =20 /* Count patched candidates */ for_each_sym_by_demangled_name(e->patched, sym1->demangled_name, sym2) { - if (sym2->twin || sym1->type !=3D sym2->type || dont_correlate(sym2)) + if (sym2->twin || sym1->type !=3D sym2->type || sym2->dont_correlate) continue; =20 /* Level 1 */ @@ -728,7 +728,7 @@ static struct symbol *find_twin_suffixed(struct elf *el= f, struct symbol *sym1) return NULL; =20 for_each_sym_by_name(elf, name, sym2) { - if (sym2->twin || sym1->type !=3D sym2->type || dont_correlate(sym2)) + if (sym2->twin || sym1->type !=3D sym2->type || sym2->dont_correlate) continue; count++; match =3D sym2; @@ -762,7 +762,7 @@ static struct symbol *find_twin_positional(struct elfs = *e, struct symbol *sym1) struct symbol *sym2, *match =3D NULL; =20 for_each_sym_by_demangled_name(e->orig, sym1->demangled_name, sym2) { - if (sym2->twin || sym1->type !=3D sym2->type || dont_correlate(sym2) || + if (sym2->twin || sym1->type !=3D sym2->type || sym2->dont_correlate || !maybe_same_file(sym1, sym2)) continue; if (is_tu_local_sym(sym1) !=3D is_tu_local_sym(sym2) || @@ -774,7 +774,7 @@ static struct symbol *find_twin_positional(struct elfs = *e, struct symbol *sym1) } =20 for_each_sym_by_demangled_name(e->patched, sym1->demangled_name, sym2) { - if (sym2->twin || sym1->type !=3D sym2->type || dont_correlate(sym2) || + if (sym2->twin || sym1->type !=3D sym2->type || sym2->dont_correlate || !maybe_same_file(sym1, sym2)) continue; if (is_tu_local_sym(sym1) !=3D is_tu_local_sym(sym2) || @@ -806,6 +806,11 @@ static int correlate_symbols(struct elfs *e) struct symbol *sym1, *sym2; bool progress; =20 + for_each_sym(e->orig, sym1) + sym1->dont_correlate =3D dont_correlate(sym1); + for_each_sym(e->patched, sym2) + sym2->dont_correlate =3D dont_correlate(sym2); + /* Correlate FILE symbols */ file1_sym =3D first_file_symbol(e->orig); file2_sym =3D first_file_symbol(e->patched); @@ -846,7 +851,7 @@ static int correlate_symbols(struct elfs *e) do { progress =3D false; for_each_sym(e->orig, sym1) { - if (sym1->twin || dont_correlate(sym1)) + if (sym1->twin || sym1->dont_correlate) continue; sym2 =3D find_twin(e, sym1); if (!sym2) @@ -860,7 +865,7 @@ static int correlate_symbols(struct elfs *e) return -1; =20 for_each_sym(e->orig, sym1) { - if (sym1->twin || dont_correlate(sym1)) + if (sym1->twin || sym1->dont_correlate) continue; sym2 =3D find_twin_suffixed(e->patched, sym1); if (!sym2) @@ -872,7 +877,7 @@ static int correlate_symbols(struct elfs *e) } while (progress); =20 for_each_sym(e->orig, sym1) { - if (sym1->twin || dont_correlate(sym1)) + if (sym1->twin || sym1->dont_correlate) continue; sym2 =3D find_twin_positional(e, sym1); if (!sym2) @@ -882,7 +887,7 @@ static int correlate_symbols(struct elfs *e) } =20 for_each_sym(e->orig, sym1) { - if (sym1->twin || dont_correlate(sym1)) + if (sym1->twin || sym1->dont_correlate) continue; WARN("no correlation: %s", sym1->name); } @@ -1102,7 +1107,7 @@ static int mark_changed_functions(struct elfs *e) =20 /* Find changed functions */ for_each_sym(e->orig, orig_sym) { - if (dont_correlate(orig_sym)) + if (orig_sym->dont_correlate) continue; =20 patched_sym =3D orig_sym->twin; @@ -1123,7 +1128,7 @@ static int mark_changed_functions(struct elfs *e) =20 /* Find added functions and print them */ for_each_sym(e->patched, patched_sym) { - if (!is_func_sym(patched_sym) || dont_correlate(patched_sym)) + if (!is_func_sym(patched_sym) || patched_sym->dont_correlate) continue; =20 if (!patched_sym->twin) { @@ -1263,7 +1268,7 @@ static bool klp_reloc_needed(struct reloc *patched_re= loc) struct export *export; =20 /* no external symbol to reference */ - if (dont_correlate(patched_sym)) + if (patched_sym->dont_correlate) return false; =20 /* For included functions, a regular reloc will do. */ --=20 2.53.0