From nobody Mon Apr 6 18:55:58 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 2464537EFFF; Wed, 18 Mar 2026 08:25:24 +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=1773822325; cv=none; b=CQhtZhiR0BxFamGEN4n/vn4ObgUNXYE4EXxC3zlPa0nAKZjwKFSKvqIPW/Xv8s8yxjbHEUdEaXZai6xDWol6CN6JfTaqp5Vq1POOP6Bnc3PZ7ZcoKUpWjQAW/qJXAIWUuBk4p2ihhxPvpG8eEpr7sCiDIjI1EPEik+kJbuektu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773822325; c=relaxed/simple; bh=SZiTNsraHJpYzmORYZtz76ebkptKD6XSitgYTw/ThVE=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=XpBn6vuo1omwfGochvQqDXcOgClHAHYBZMqWEn4t2htGTu88mXVXSuJp36M5Yp8tkRPfCOBXnKncssT1axDnqARnnG8H6SFWYhCwiqHGAtg6QaDztKsHdIq9USy2+tRHhzanA4eddnabD5zwSDgBko9nzMXH395HUlfT3Fz4Bdg= 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=mvgTCSWT; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=sHuDub6U; 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="mvgTCSWT"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sHuDub6U" Date: Wed, 18 Mar 2026 08:25:19 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1773822320; 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: in-reply-to:in-reply-to:references:references; bh=qnL2Je8iZfEbDlXiZTjsNoVcAE54JZQwXxVxkskmEck=; b=mvgTCSWTY1/gqTuz6bGiRhGtNMi0gLsZyjVSj7KcMBDLmKv88hf+QHsYRHn9Qcob5t9bo3 c/ud063kfBoYYteLzuRFpnWKuC6fh3/Nwk/mXq3gSs3urFUl8IiYl1TDNNxWgrehyfSenW ah7XvOzqVAquf4th9sdypKB9VBK/Ce5rb2wZ6dkG9nwQYWkhy9iS//SgJVpswf7OxqfNyV Kb3ani4QLjsTrS+/7b+4ohFi7zy8iplCKu2lhBYWx6GhaLHgRFJ62Ybfpq8m7u23dvFBy3 xNFigfY/hSRV/L+yJlhdIbv8a1SyQL2QnDBcvdn2pfdKW88HKprZcGqPPExzEg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1773822320; 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: in-reply-to:in-reply-to:references:references; bh=qnL2Je8iZfEbDlXiZTjsNoVcAE54JZQwXxVxkskmEck=; b=sHuDub6Up8xB7qNcLGYujEOtTCRoswMnwaR6lx2O73/QCFxmtXuEydodTI5sCMceYl2P4v Xc3GBPgnhXbFbaAg== From: "tip-bot2 for Joe Lawrence" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] livepatch/klp-build: switch to GNU patch and recountdiff Cc: Joe Lawrence , Song Liu , Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260310203751.1479229-5-joe.lawrence@redhat.com> References: <20260310203751.1479229-5-joe.lawrence@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177382231945.1647592.18421110831055199877.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: d36a7343f4bac518b6ef05e2ccc47acd3a2cdab9 Gitweb: https://git.kernel.org/tip/d36a7343f4bac518b6ef05e2ccc47acd3= a2cdab9 Author: Joe Lawrence AuthorDate: Tue, 10 Mar 2026 16:37:43 -04:00 Committer: Josh Poimboeuf CommitterDate: Mon, 16 Mar 2026 12:46:48 -07:00 livepatch/klp-build: switch to GNU patch and recountdiff The klp-build script is currently very strict with input patches, requiring them to apply cleanly via `git apply --recount`. This prevents the use of patches with minor contextual fuzz relative to the target kernel sources. To allow users to reuse a patch across similar kernel streams, switch to using GNU patch and patchutils for intermediate patch manipulation. Update the logic for applying, reverting, and regenerating patches: - Use 'patch -p1' for better handling of context fuzz. - Use 'recountdiff' to update line counts after FIX_PATCH_LINES. - Drop git_refresh() and related git-specific logic. Signed-off-by: Joe Lawrence Acked-by: Song Liu Link: https://patch.msgid.link/20260310203751.1479229-5-joe.lawrence@redhat= .com Signed-off-by: Josh Poimboeuf --- scripts/livepatch/klp-build | 59 +++++++----------------------------- 1 file changed, 13 insertions(+), 46 deletions(-) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index 94ed3b4..564985a 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -95,7 +95,7 @@ restore_files() { =20 cleanup() { set +o nounset - revert_patches "--recount" + revert_patches restore_files [[ "$KEEP_TMP" -eq 0 ]] && rm -rf "$TMP_DIR" return 0 @@ -282,7 +282,7 @@ set_module_name() { } =20 # Hardcode the value printed by the localversion script to prevent patch -# application from appending it with '+' due to a dirty git working tree. +# application from appending it with '+' due to a dirty working tree. set_kernelversion() { local file=3D"$SRC/scripts/setlocalversion" local localversion @@ -300,8 +300,8 @@ get_patch_input_files() { local patch=3D"$1" =20 grep0 -E '^--- ' "$patch" \ + | grep0 -v -e '/dev/null' -e '1969-12-31' -e '1970-01-01' \ | gawk '{print $2}' \ - | grep0 -v '^/dev/null$' \ | sed 's|^[^/]*/||' \ | sort -u } @@ -310,8 +310,8 @@ get_patch_output_files() { local patch=3D"$1" =20 grep0 -E '^\+\+\+ ' "$patch" \ + | grep0 -v -e '/dev/null' -e '1969-12-31' -e '1970-01-01' \ | gawk '{print $2}' \ - | grep0 -v '^/dev/null$' \ | sed 's|^[^/]*/||' \ | sort -u } @@ -323,21 +323,6 @@ get_patch_files() { | sort -u } =20 -# Make sure git re-stats the changed files -git_refresh() { - local patch=3D"$1" - local files=3D() - - [[ ! -e "$SRC/.git" ]] && return - - get_patch_input_files "$patch" | mapfile -t files - - ( - cd "$SRC" - git update-index -q --refresh -- "${files[@]}" - ) -} - check_unsupported_patches() { local patch =20 @@ -358,36 +343,19 @@ check_unsupported_patches() { =20 apply_patch() { local patch=3D"$1" - shift - local extra_args=3D("$@") =20 [[ ! -f "$patch" ]] && die "$patch doesn't exist" - - ( - cd "$SRC" - - # The sed strips the version signature from 'git format-patch', - # otherwise 'git apply --recount' warns. - sed -n '/^-- /q;p' "$patch" | - git apply "${extra_args[@]}" - ) + patch -d "$SRC" -p1 --dry-run --silent --no-backup-if-mismatch -r /dev/nu= ll < "$patch" + patch -d "$SRC" -p1 --silent --no-backup-if-mismatch -r /dev/null < "$pat= ch" =20 APPLIED_PATCHES+=3D("$patch") } =20 revert_patch() { local patch=3D"$1" - shift - local extra_args=3D("$@") local tmp=3D() =20 - ( - cd "$SRC" - - sed -n '/^-- /q;p' "$patch" | - git apply --reverse "${extra_args[@]}" - ) - git_refresh "$patch" + patch -d "$SRC" -p1 -R --silent --no-backup-if-mismatch -r /dev/null < "$= patch" =20 for p in "${APPLIED_PATCHES[@]}"; do [[ "$p" =3D=3D "$patch" ]] && continue @@ -406,11 +374,10 @@ apply_patches() { } =20 revert_patches() { - local extra_args=3D("$@") local patches=3D("${APPLIED_PATCHES[@]}") =20 for (( i=3D${#patches[@]}-1 ; i>=3D0 ; i-- )) ; do - revert_patch "${patches[$i]}" "${extra_args[@]}" + revert_patch "${patches[$i]}" done =20 APPLIED_PATCHES=3D() @@ -434,6 +401,7 @@ do_init() { APPLIED_PATCHES=3D() =20 [[ -x "$FIX_PATCH_LINES" ]] || die "can't find fix-patch-lines" + command -v recountdiff &>/dev/null || die "recountdiff not found (install= patchutils)" =20 validate_config set_module_name @@ -459,12 +427,12 @@ refresh_patch() { ( cd "$SRC" && echo "${input_files[@]}" | xargs cp --parents --target-dir= ectory=3D"$tmpdir/a" ) =20 # Copy patched source files to 'b' - apply_patch "$patch" --recount + apply_patch "$patch" ( cd "$SRC" && echo "${output_files[@]}" | xargs cp --parents --target-di= rectory=3D"$tmpdir/b" ) - revert_patch "$patch" --recount + revert_patch "$patch" =20 # Diff 'a' and 'b' to make a clean patch - ( cd "$tmpdir" && git diff --no-index --no-prefix a b > "$patch" ) || true + ( cd "$tmpdir" && diff -Nupr a b > "$patch" ) || true } =20 # Copy the patches to a temporary directory, fix their lines so as not to @@ -487,8 +455,7 @@ fix_patches() { =20 cp -f "$old_patch" "$tmp_patch" refresh_patch "$tmp_patch" - "$FIX_PATCH_LINES" "$tmp_patch" > "$new_patch" - refresh_patch "$new_patch" + "$FIX_PATCH_LINES" "$tmp_patch" | recountdiff > "$new_patch" =20 PATCHES[i]=3D"$new_patch" =20