Skip to content

Commit 7506384

Browse files
authored
Merge branch 'dynup:master' into master
2 parents 8cb2848 + 6742763 commit 7506384

27 files changed

Lines changed: 567 additions & 57 deletions

.packit.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ _:
1616
fedora-rawhide-ppc64le:
1717
distros: [Fedora-37-Updated]
1818
skip_build: true
19-
manual_trigger: true
19+
manual_trigger: false
2020
tmt_plan: kpatch-integration-upstream
2121
fmf_url: https://gitlab.com/redhat/centos-stream/tests/kernel/test-plans.git
2222
fmf_ref: main
@@ -32,15 +32,15 @@ _:
3232
epel-8-x86_64:
3333
distros: [RHEL-8.10.0-Nightly, RHEL-8.8.0-Nightly, RHEL-8.6.0-Nightly, RHEL-8.4.0-Nightly]
3434
epel-9-x86_64:
35-
distros: [RHEL-9.6.0-Nightly, RHEL-9.4.0-Nightly, RHEL-9.2.0-Nightly, RHEL-9.0.0-Nightly]
35+
distros: [RHEL-9.7.0-Nightly, RHEL-9.6.0-Nightly, RHEL-9.4.0-Nightly, RHEL-9.2.0-Nightly, RHEL-9.0.0-Nightly]
3636
epel-8-ppc64le:
3737
distros: [RHEL-8.10.0-Nightly, RHEL-8.8.0-Nightly, RHEL-8.6.0-Nightly, RHEL-8.4.0-Nightly]
3838
epel-9-ppc64le:
39-
distros: [RHEL-9.6.0-Nightly, RHEL-9.4.0-Nightly, RHEL-9.2.0-Nightly, RHEL-9.0.0-Nightly]
39+
distros: [RHEL-9.7.0-Nightly, RHEL-9.6.0-Nightly, RHEL-9.4.0-Nightly, RHEL-9.2.0-Nightly, RHEL-9.0.0-Nightly]
4040
# rhel+epel-10-ppc64le:
4141
# distros: [RHEL-10.0-Nightly]
4242
skip_build: true
43-
manual_trigger: true
43+
manual_trigger: false
4444
tmt_plan: kpatch-integration-rhel
4545
fmf_url: https://gitlab.com/redhat/centos-stream/tests/kernel/test-plans.git
4646
fmf_ref: main

contrib/kpatch.spec

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Name: kpatch
88
Summary: Dynamic kernel patching
9-
Version: 0.9.10
9+
Version: 0.9.11
1010
License: GPLv2
1111
Group: System Environment/Kernel
1212
URL: http://github.com/dynup/kpatch
@@ -104,6 +104,15 @@ rm -rf %{buildroot}
104104
%{_mandir}/man1/kpatch-build.1*
105105

106106
%changelog
107+
* Mon Oct 27 2025 Joe Lawrence <joe.lawrence@redhat.com> - 0.9.11
108+
- Initial ARM64 architecture support
109+
- Support for kernel module namepsaces
110+
- Kpatch utility support for 'stack_order' sysfs attribute
111+
- Distro support/fixes for AlmaLinux, Fedora, Photon OS, RHEL-9.6
112+
- Cross compilation with env TARGET_ARCH
113+
- Migrated internal testing to Packit Testing Farm
114+
- Support for gcc-14
115+
107116
* Mon Jan 20 2025 Joe Lawrence <joe.lawrence@redhat.com> - 0.9.10
108117
- Support for Amazon Linux, Anolis OS, and OpenCloudOS distros
109118
- Fix cleanup when kpatch is installed in read-only location

doc/INSTALL.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Table of contents
55
=================
66

77
- [Prerequisites](#prerequisites)
8-
- [Fedora, RHEL, CentOS](#fedora-rhel-centos)
8+
- [Fedora, RHEL, CentOS, Rocky](#fedora-rhel-centos-rocky)
99
- [Oracle Linux 7](#oracle-linux-7)
1010
- [Ubuntu](#ubuntu)
1111
- [Debian 9 (Stretch)](#debian-9-stretch)
@@ -24,7 +24,7 @@ Before starting, see [Supported
2424
Architectures](../README.md#supported-architectures) and check if your device's
2525
architecture is supported.
2626

27-
### Fedora, RHEL, CentOS
27+
### Fedora, RHEL, CentOS, Rocky
2828

2929
*NOTE: You'll need about 15GB of free disk space for the kpatch-build cache in
3030
`~/.kpatch` and for ccache.*
@@ -312,5 +312,3 @@ OPTIONAL: Install kpatch to `/usr/local`:
312312
313313
Alternatively, the kpatch and kpatch-build scripts can be run directly from the
314314
git tree.
315-
316-

doc/patch-author-guide.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Table of contents
2929
- [Exported symbol versioning](#exported-symbol-versioning)
3030
- [System calls](#system-calls)
3131
- [Symbol Namespaces](#symbol-namespaces)
32+
- [Cross Compile](#cross-compile)
33+
3234

3335
Patch analysis
3436
--------------
@@ -964,3 +966,25 @@ ERROR: modpost: module livepatch-test uses symbol dma_buf_export from namespace
964966
```
965967
To manually import the required namespace, add the MODULE_IMPORT_NS() macro to
966968
the patch source. For example: `MODULE_IMPORT_NS("DMA_BUF")`
969+
970+
Cross Compile
971+
-------------
972+
973+
It is recommended to build the livepatch in the same environment (compiler/library/etc.) as
974+
the target kernel. When the target kernel was cross compiled for a different architecture,
975+
it is recommended to cross compile the livepatch.
976+
977+
There are two options to cross compile a livepatch.
978+
979+
To specify a separate set of cross compilers,
980+
we can set the `CROSS_COMPILE` environment variable. For example, to use `aarch64-gcc` and `aarch64-ld`,
981+
we can run kpatch-build as
982+
```
983+
CROSS_COMPILE=aarch64- kpatch-build ...
984+
```
985+
986+
llvm/clang supports cross compile with the same binaries. To specify a cross compile target, we can
987+
use the TARGET_ARCH environment variable, for example:
988+
```
989+
TARGET_ARCH=aarch64 kpatch-build ...
990+
```

kpatch-build/create-diff-object.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static unsigned int function_padding_size(struct kpatch_elf *kelf, struct symbol
284284
size = 8;
285285
else if (i != 0)
286286
log_error("function %s within section %s has invalid padding\n", sym->name, sym->sec->name);
287-
287+
288288
break;
289289
}
290290
default:
@@ -522,6 +522,15 @@ static int kpatch_mangled_strcmp(char *s1, char *s2)
522522
if (!strncmp(s1, "__UNIQUE_ID_", 12))
523523
return __kpatch_unique_id_strcmp(s1, s2);
524524

525+
/*
526+
* With LLVM, dynamic debug unique id looks like
527+
* <func_name>.__UNIQUE_ID_ddebug<number>.
528+
*
529+
* Use __kpatch_unique_id_strcmp to compare them.
530+
*/
531+
if (strstr(s1, "__UNIQUE_ID_ddebug"))
532+
return __kpatch_unique_id_strcmp(s1, s2);
533+
525534
while (*s1 == *s2) {
526535
if (!*s1)
527536
return 0;

kpatch-build/kpatch-build

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@
3333
# - Builds the patched kernel/module and monitors changed objects
3434
# - Builds the patched objects with gcc flags -f[function|data]-sections
3535
# - Runs kpatch tools to create and link the patch kernel module
36-
VERSION=0.9.10
36+
VERSION=0.9.11
3737

3838
set -o pipefail
3939

4040
BASE="$PWD"
4141
SCRIPTDIR="$(readlink -f "$(dirname "$(type -p "$0")")")"
4242
ARCH="$(uname -m)"
43+
TARGET_ARCH="${TARGET_ARCH:-$ARCH}"
4344
CPUS="$(getconf _NPROCESSORS_ONLN)"
4445
CACHEDIR="${CACHEDIR:-$HOME/.kpatch}"
4546
KERNEL_SRCDIR="$CACHEDIR/src"
@@ -82,7 +83,8 @@ declare -rA SUPPORTED_RPM_DISTROS=(
8283
["photon"]="Photon OS"
8384
["rhel"]="RHEL"
8485
["almalinux"]="AlmaLinux"
85-
["amzn"]="Amazon Linux")
86+
["amzn"]="Amazon Linux"
87+
["rocky"]="Rocky")
8688

8789

8890
warn() {
@@ -406,7 +408,7 @@ find_special_section_data() {
406408
check[e]=true # exception_table_entry
407409

408410
# Arch-specific features
409-
case "$ARCH" in
411+
case "$TARGET_ARCH" in
410412
"x86_64")
411413
check[a]=true # alt_instr
412414
kernel_version_gte 5.10.0 && check[s]=true # static_call_site
@@ -741,6 +743,15 @@ print_supported_distro(){
741743
fi
742744
}
743745

746+
# Used in "make ARCH=xxx" when making the kernel.
747+
# Match "aarch64" to "arm64", while keep everything else the same.
748+
kernel_make_arch() {
749+
if [[ "$1" == "aarch64" ]]; then
750+
echo "arm64"
751+
else
752+
echo "$1"
753+
fi
754+
}
744755

745756
usage() {
746757
echo "usage: $(basename "$0") [options] <patch1 ... patchN>" >&2
@@ -874,16 +885,28 @@ if [[ ${#PATCH_LIST[@]} -eq 0 ]]; then
874885
fi
875886

876887
trace_on
888+
# Don't check external file.
889+
# shellcheck disable=SC1090
890+
if [[ -z "$USERSRCDIR" ]] && [[ -f "$RELEASE_FILE" ]]; then
891+
source "$RELEASE_FILE"
892+
DISTRO="$ID"
893+
fi
894+
877895

878896
if [[ -n "$SRCRPM" ]]; then
879897
if [[ -n "$ARCHVERSION" ]]; then
880898
warn "--archversion is incompatible with --sourcerpm"
881899
exit 1
882900
fi
883901
rpmname="$(basename "$SRCRPM")"
884-
ARCHVERSION="${rpmname%.src.rpm}.$(uname -m)"
902+
if [[ "$DISTRO" = photon ]]; then
903+
ARCHVERSION="${rpmname%.src.rpm}"
904+
else
905+
ARCHVERSION="${rpmname%.src.rpm}.$(uname -m)"
906+
fi
885907
ARCHVERSION="${ARCHVERSION#kernel-}"
886908
ARCHVERSION="${ARCHVERSION#alt-}"
909+
ARCHVERSION="${ARCHVERSION#linux-}"
887910
fi
888911

889912
if [[ -n "$OOT_MODULE" ]] && [[ -z "$OOT_MODULE_SRCDIR" ]]; then
@@ -933,13 +956,6 @@ fi
933956

934957
[[ "$SKIPCLEANUP" -eq 0 ]] && trap cleanup EXIT INT TERM HUP
935958

936-
# Don't check external file.
937-
# shellcheck disable=SC1090
938-
if [[ -z "$USERSRCDIR" ]] && [[ -f "$RELEASE_FILE" ]]; then
939-
source "$RELEASE_FILE"
940-
DISTRO="$ID"
941-
fi
942-
943959
KVER="${ARCHVERSION%%-*}"
944960
if [[ "$ARCHVERSION" =~ - ]]; then
945961
# handle flavor extension on Photon ex) -rt, -esx
@@ -951,12 +967,12 @@ if [[ "$ARCHVERSION" =~ - ]]; then
951967
KREL="${KREL%-*}"
952968
KREL="${KREL#*-}"
953969

954-
PH_TAG="${ARCHVERSION##*.}"
955-
PH_FLAVOR="${PH_TAG##*-}"
956-
PH_TAG="${PH_TAG%%-*}"
957-
958-
# if no flavor, these will be the same
959-
[[ "$PH_FLAVOR" = "$PH_TAG" ]] && PH_FLAVOR=""
970+
PH_TAG=$(echo "$ARCHVERSION" | grep -oE 'ph[0-9]+')
971+
if [[ "$ARCHVERSION" =~ (^|[-\.])(rt|esx|aws)($|[-\.]) ]]; then
972+
PH_FLAVOR="${BASH_REMATCH[2]}"
973+
else
974+
PH_FLAVOR=""
975+
fi
960976
else
961977
KREL="${ARCHVERSION##*-}"
962978
fi
@@ -1034,11 +1050,9 @@ else
10341050
if [ -z "$SRCRPM" ]; then
10351051
SRCRPM="$TEMPDIR/kernel$ALT-$KVER-$KREL.src.rpm"
10361052
fi
1037-
10381053
fi
10391054

10401055
echo "Unpacking kernel source"
1041-
10421056
if [[ "$DISTRO" = photon ]]; then
10431057
[[ -n "$PH_FLAVOR" ]] && SPECNAME="linux-$PH_FLAVOR.spec" || SPECNAME="linux.spec"
10441058
else
@@ -1049,7 +1063,7 @@ else
10491063

10501064
# Define dist tag to handle rpmbuild of the linux src rpm in Photon
10511065
if [[ "$DISTRO" = photon ]] && [ "$(rpm -E %dist)" = "%dist" ]; then
1052-
sed -i "1s/^/%define dist .$PH_TAG/" "$RPMTOPDIR"/SPECS/"$SPECNAME"
1066+
sed -i "1s|^|%define dist .$PH_TAG\n\n|" "$RPMTOPDIR"/SPECS/"$SPECNAME"
10531067
fi
10541068

10551069
rpmbuild -D "_topdir $RPMTOPDIR" -bp --nodeps "--target=$(uname -m)" "$RPMTOPDIR"/SPECS/"$SPECNAME" 2>&1 | logger || die "rpmbuild -bp failed. you may need to run 'yum-builddep kernel' first."
@@ -1061,19 +1075,6 @@ else
10611075
elif [[ "$DISTRO" = opencloudos ]]; then
10621076
mv "$RPMTOPDIR"/BUILD/kernel-*/kernel-* "$KERNEL_SRCDIR" 2>&1 | logger || die
10631077
elif [[ "$DISTRO" = photon ]]; then
1064-
# Photon has some files that are copied over during the build section of the spec file (instead of prep)
1065-
# These change occasionally, so check they exist before copying
1066-
ls "$RPMTOPDIR"/BUILD/fips*canister* &> /dev/null && ( cp -rT "$RPMTOPDIR"/BUILD/fips*canister* "$RPMTOPDIR"/BUILD/linux-"$KVER"/crypto | logger || die )
1067-
[[ -f "$RPMTOPDIR"/SOURCES/fips_canister-kallsyms ]] && ( cp "$RPMTOPDIR"/SOURCES/fips_canister-kallsyms rpmbuild/BUILD/linux-"$KVER"/crypto | logger || die )
1068-
1069-
if [[ -z "$CONFIGFILE" ]]; then
1070-
# Photon has multiple config files per src rpm sometimes, and naming is not consistent.
1071-
# So do our best to find the right one by parsing the spec file
1072-
SRC_CFG=$(rpmspec -P -D "_topdir $RPMTOPDIR" "$RPMTOPDIR"/SPECS/"$SPECNAME" | awk '/^cp .*\/SOURCES\/config.* \.config$/{print $2}')
1073-
[[ -z "$SRC_CFG" ]] && die "Failed to locate kernel config file"
1074-
SRC_CFG="${SRC_CFG##*/}"
1075-
cp "$RPMTOPDIR"/SOURCES/"$SRC_CFG" "$RPMTOPDIR"/BUILD/linux-"$KVER" | logger || die
1076-
fi
10771078
mv "$RPMTOPDIR"/BUILD/linux-"$KVER" "$KERNEL_SRCDIR" 2>&1 | logger || die
10781079
else
10791080
mv "$RPMTOPDIR"/BUILD/kernel-*/linux-* "$KERNEL_SRCDIR" 2>&1 | logger || die
@@ -1091,20 +1092,14 @@ else
10911092
if [[ "$DISTRO" = openEuler ]] || [[ "$DISTRO" = opencloudos ]]; then
10921093
[[ -z "$CONFIGFILE" ]] && CONFIGFILE="/boot/config-${ARCHVERSION}"
10931094
elif [[ "$DISTRO" = photon ]]; then
1094-
[[ -z "$CONFIGFILE" ]] && CONFIGFILE="$KERNEL_SRCDIR/$SRC_CFG"
1095-
1096-
# modify config file here to get the right vermagic, as Photon does not always listen to localversion file
1097-
if [[ -z "$PH_FLAVOR" ]]; then
1098-
sed -i s/^CONFIG_LOCALVERSION=\".*\"/CONFIG_LOCALVERSION=\"-"$KREL"."$PH_TAG"\"/g "$CONFIGFILE" || die
1099-
else
1100-
sed -i s/^CONFIG_LOCALVERSION=\".*\"/CONFIG_LOCALVERSION=\"-"$KREL"."$PH_TAG"-"$PH_FLAVOR"\"/g "$CONFIGFILE" || die
1101-
fi
1102-
1095+
[[ -z "$CONFIGFILE" ]] && CONFIGFILE="$KERNEL_SRCDIR"/.config
11031096
else
11041097
[[ -z "$CONFIGFILE" ]] && CONFIGFILE="$KERNEL_SRCDIR/configs/kernel$ALT-$KVER-$ARCH.config"
11051098
fi
1099+
if [[ ! "$DISTRO" = photon ]]; then
1100+
(cd "$KERNEL_SRCDIR" && make mrproper 2>&1 | logger) || die
1101+
fi
11061102

1107-
(cd "$KERNEL_SRCDIR" && make mrproper 2>&1 | logger) || die
11081103

11091104
elif is_supported_deb_distro "$DISTRO"; then
11101105

@@ -1330,6 +1325,11 @@ else
13301325
MAKEVARS+=("LD=${KPATCH_CC_PREFIX}${LD}")
13311326
fi
13321327

1328+
if [[ "$ARCH" != "$TARGET_ARCH" ]]; then
1329+
KARCH=$(kernel_make_arch "$TARGET_ARCH")
1330+
MAKEVARS+=("ARCH=$KARCH")
1331+
fi
1332+
13331333

13341334
# $TARGETS used as list, no quotes.
13351335
# shellcheck disable=SC2086
@@ -1520,7 +1520,12 @@ fi
15201520
cd "$TEMPDIR/output" || die
15211521
# $KPATCH_LDFLAGS and result of find used as list, no quotes.
15221522
# shellcheck disable=SC2086,SC2046
1523-
"$LD" -r $KPATCH_LDFLAGS -o ../patch/tmp_output.o $(find . -name "*.o") 2>&1 | logger || die
1523+
if [[ "$ARCH" != "$TARGET_ARCH" ]]; then
1524+
# if cross compiling, use LLD to link
1525+
"$LLD" -r $KPATCH_LDFLAGS -o ../patch/tmp_output.o $(find . -name "*.o") 2>&1 | logger || die
1526+
else
1527+
"$LD" -r $KPATCH_LDFLAGS -o ../patch/tmp_output.o $(find . -name "*.o") 2>&1 | logger || die
1528+
fi
15241529

15251530
if [[ "$USE_KLP" -eq 1 ]]; then
15261531
cp -f "$TEMPDIR"/patch/tmp_output.o "$TEMPDIR"/patch/output.o || die

kpatch/kpatch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
INSTALLDIR=/var/lib/kpatch
2727
SCRIPTDIR="$(readlink -f "$(dirname "$(type -p "$0")")")"
28-
VERSION="0.9.10"
28+
VERSION="0.9.11"
2929
POST_ENABLE_WAIT=15 # seconds
3030
POST_SIGNAL_WAIT=60 # seconds
3131
MODULE_REF_WAIT=15 # seconds

test/integration/lib.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ kpatch_fedora_dependencies()
9494
kpatch_rhel_dependencies
9595
}
9696

97+
kpatch_rocky_dependencies()
98+
{
99+
kpatch_rhel_dependencies
100+
}
101+
97102
kpatch_openEuler_dependencies()
98103
{
99104
local kernel_version

test/integration/rebase-patches

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@
1818
# ID=rhel VERSION_ID=7.8 ./rebase-patches rhel-7.7/*{.patch,.disabled}
1919
# % cp rhel-7.7/*.test rhel-7.8/
2020

21-
OUTDIR=$(pwd)/${ID}-${VERSION_ID}
22-
mkdir -p "$OUTDIR"
21+
if [ -z "$SRCDIR" ] || [ -z "$ID" ] || [ -z "$VERSION_ID" ]; then
22+
echo "ERROR: SRCDIR, ID, and VERSION_ID environment variables must be set"
23+
exit 1
24+
fi
25+
26+
SRCDIR="$(realpath "$SRCDIR")"
27+
OUTDIR="$(realpath "${ID}"-"${VERSION_ID}")"
2328

29+
mkdir -p "$OUTDIR"
2430
echo "* Making backup copy of kernel sources"
2531
rm -rf "${SRCDIR}.orig"
2632
cp -r "$SRCDIR" "${SRCDIR}.orig"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
grep "kpatch: 5" /proc/meminfo

0 commit comments

Comments
 (0)