From nobody Sat Jun 13 22:13:44 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 8CEA1426D22; Tue, 5 May 2026 10:56:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777978570; cv=none; b=FfVPi9wGHiGxdUZDfJdMsT8MPmh+BOGIE7zEugMUvqJOIV7BmfAeUO4L7i6IVtNQaT14I0qJyrnMAW6ld8H5J984KqcmUl36kXRWiA63n4fVvPQUD4bMpOZUseyLpW8lZRfSW0x6Nb2BYv+bXoKpKQni9bWSD2otNcYyZD5cuhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777978570; c=relaxed/simple; bh=6n//r6X88bXJ3Zrht+za7X1AHexSsfBdVolkK8iti6E=; h=Date:From:To:Subject:Cc:MIME-Version:Message-ID:Content-Type; b=HEBNSVhhBa1I6/MPNJ4dMYdtuUkYCUneAFb9NRJOpoo3YKsPXs5vRJhlZMZPohRfr0ktBVlnZMCrgb4VeMVnFKkcmcL/whFaI8d9UCiN1hn9iO9plAvy5AjkYM5KBhUz1vwXHeOYgOh5evwtRXmTWcIiTK21luAXXXIj+SUTaCg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=RsfrJ2e8; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=vReJ0LGb; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="RsfrJ2e8"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vReJ0LGb" Date: Tue, 05 May 2026 10:56:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777978566; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=bMUL6eYaX34VvZ8ZQJInEQHyoo2ajKikFPqRjMlqsts=; b=RsfrJ2e8GFKHISJv4NOKyDw21jjRIZKx/aoNdZQFkjvLUvoSnS+Zr55z8CIDn7j6VaeJ6E rh2jTzzPWGXRH6bNgXNVR5ScaaH3l8pYcpzmfyic6SuAE7qnPOVgB1L5PVNNsPebJzF95+ Y0glhGGkdNNuouUeL7XO6e4Mqux52s8gASrqtLq11AoeajC4FUVrZAtPocQm4Etl37OmnO Le9QwqtvgIDuWhhH3UC0zRIDybB0L/XU0ICs503zPZ7+LKwYB6yFfNeM8nZqAaVvLkbK3p xmFCskOGD9Z9bj6zjilAn4FuMyzOYdGTBBdH0DJjw0jZTImJgfmkXyC4Jy3b0Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777978566; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=bMUL6eYaX34VvZ8ZQJInEQHyoo2ajKikFPqRjMlqsts=; b=vReJ0LGbjvQVCjUcUIBshvZpBa4pw2SjcfJq/XW/6De0S4FuSTUKkBfssZFBb+SFy6fox5 QYPVxDpkUFSUS8Dg== From: "tip-bot2 for Josh Poimboeuf" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] klp-build: Use "objtool klp checksum" subcommand Cc: Song Liu , Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177797856451.424702.1369048480044825887.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the objtool/core branch of tip: Commit-ID: d4888d58041d1a61d66f2c81cb398f9685bc7576 Gitweb: https://git.kernel.org/tip/d4888d58041d1a61d66f2c81cb398f968= 5bc7576 Author: Josh Poimboeuf AuthorDate: Fri, 03 Apr 2026 13:09:34 -07:00 Committer: Josh Poimboeuf CommitterDate: Mon, 04 May 2026 21:16:05 -07:00 klp-build: Use "objtool klp checksum" subcommand 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. Acked-by: Song Liu Signed-off-by: Josh Poimboeuf --- scripts/livepatch/klp-build | 95 ++++++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 30 deletions(-) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index 215d230..6103345 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -37,10 +37,12 @@ OBJTOOL=3D"$PWD/tools/objtool/objtool" CONFIG=3D"$PWD/.config" TMP_DIR=3D"$PWD/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" @@ -136,10 +138,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 @@ -203,10 +206,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 @@ -513,11 +517,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 @@ -544,7 +545,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 @@ -574,7 +574,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"$PWD/$rel_file" @@ -630,6 +630,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" + "$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" @@ -639,16 +668,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() @@ -672,8 +701,8 @@ diff_objects() { fi =20 ( - cd "$ORIG_DIR" - [[ -v VERBOSE ]] && echo "cd $ORIG_DIR && ${cmd[*]}" + cd "$ORIG_CSUM_DIR" + [[ -v VERBOSE ]] && echo "cd $ORIG_CSUM_DIR && ${cmd[*]}" "${cmd[@]}" \ 1> >(tee -a "$log") \ 2> >(tee -a "$log" | "${filter[@]}" >&2) || \ @@ -682,9 +711,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" @@ -709,8 +738,7 @@ diff_checksums() { done =20 cmd=3D("$OBJTOOL") - cmd+=3D("--checksum") - cmd+=3D("--link") + cmd+=3D("klp" "checksum") cmd+=3D("--dry-run") =20 for file in "${!funcs[@]}"; do @@ -719,11 +747,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 @@ -861,6 +889,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 @@ -869,7 +904,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