kpatch: upgrade to 0.9.9

Signed-off-by: hubin <hubin73@huawei.com>
This commit is contained in:
hubin 2024-03-02 00:18:20 +08:00
parent f1c9c54564
commit a652ed44c2
55 changed files with 312 additions and 1094 deletions

View File

@ -1,7 +1,7 @@
From af8c2cebd046dd3833cba8daac26e4d8109f7ff3 Mon Sep 17 00:00:00 2001
From 85c1123ab81c2b753c5fa8a854e51724f98b5e91 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Thu, 20 Dec 2018 04:55:38 +0000
Subject: [PATCH 01/37] kpatch: add aarch64 support
Subject: [PATCH 01/38] kpatch: add aarch64 support
1.use R_AARCH64_ABS64 for aarch64
2.add find_special_section_data_arm64 for arm64:
@ -31,10 +31,10 @@ index bebf3cd..5037677 100644
endif
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 3604411..0b0b06b 100644
index 25710e9..e4c25a6 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -175,6 +175,8 @@ static bool is_gcc6_localentry_bundled_sym(struct kpatch_elf *kelf,
@@ -180,6 +180,8 @@ static bool is_gcc6_localentry_bundled_sym(struct kpatch_elf *kelf,
return false;
case S390:
return false;
@ -43,7 +43,7 @@ index 3604411..0b0b06b 100644
default:
ERROR("unsupported arch");
}
@@ -2186,57 +2188,57 @@ static int fixup_group_size(struct kpatch_elf *kelf, int offset)
@@ -2415,48 +2417,48 @@ static bool static_call_sites_group_filter(struct lookup_table *lookup,
static struct special_section special_sections[] = {
{
.name = "__bug_table",
@ -68,6 +68,7 @@ index 3604411..0b0b06b 100644
- .arch = X86_64 | PPC64 | S390,
+ .arch = X86_64 | PPC64 | S390 | ARM64,
.group_size = jump_table_group_size,
.group_filter = jump_table_group_filter,
},
{
.name = ".printk_index",
@ -98,6 +99,9 @@ index 3604411..0b0b06b 100644
- .arch = X86_64,
+ .arch = X86_64 | ARM64,
.group_size = static_call_sites_group_size,
.group_filter = static_call_sites_group_filter,
},
@@ -2467,12 +2469,12 @@ static struct special_section special_sections[] = {
},
{
.name = ".retpoline_sites",
@ -112,7 +116,7 @@ index 3604411..0b0b06b 100644
.group_size = return_sites_group_size,
},
{
@@ -3097,7 +3099,9 @@ static int function_ptr_rela(const struct rela *rela)
@@ -3241,7 +3243,9 @@ static int function_ptr_rela(const struct rela *rela)
rela_toc->addend == (int)rela_toc->sym->sym.st_value &&
(rela->type == R_X86_64_32S ||
rela->type == R_PPC64_TOC16_HA ||
@ -122,8 +126,8 @@ index 3604411..0b0b06b 100644
+ rela->type == R_AARCH64_ADD_ABS_LO12_NC));
}
static bool need_dynrela(struct kpatch_elf *kelf, struct lookup_table *table,
@@ -3570,7 +3574,8 @@ static void kpatch_create_mcount_sections(struct kpatch_elf *kelf)
static bool need_klp_reloc(struct kpatch_elf *kelf, struct lookup_table *table,
@@ -3715,7 +3719,8 @@ static void kpatch_create_mcount_sections(struct kpatch_elf *kelf)
}
switch(kelf->arch) {
@ -133,7 +137,7 @@ index 3604411..0b0b06b 100644
bool found = false;
list_for_each_entry(rela, &sym->sec->rela->relas, list)
@@ -3806,6 +3811,7 @@ static void kpatch_find_func_profiling_calls(struct kpatch_elf *kelf)
@@ -3958,6 +3963,7 @@ static void kpatch_find_func_profiling_calls(struct kpatch_elf *kelf)
switch(kelf->arch) {
case PPC64:
@ -142,10 +146,10 @@ index 3604411..0b0b06b 100644
if (!strcmp(rela->sym->name, "_mcount")) {
sym->has_func_profiling = 1;
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index 296fa48..73f8976 100755
index d01a8d9..80d7209 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -354,6 +354,9 @@ find_special_section_data() {
@@ -350,6 +350,9 @@ find_special_section_data() {
"s390x")
check[a]=true # alt_instr
;;
@ -155,9 +159,9 @@ index 296fa48..73f8976 100755
esac
# Kernel CONFIG_ features
@@ -362,6 +365,8 @@ find_special_section_data() {
@@ -357,6 +360,8 @@ find_special_section_data() {
[[ -n "$CONFIG_JUMP_LABEL" ]] && check[j]=true # jump_entry
[[ -n "$CONFIG_UNWINDER_ORC" ]] && check[o]=true # orc_entry
[[ -n "$CONFIG_PARAVIRT" ]] && check[p]=true # paravirt_patch_site
+ [[ "$ARCH" == "aarch64" ]] && unset check[p]
+
@ -165,7 +169,7 @@ index 296fa48..73f8976 100755
for c in "${!check[@]}"; do
AWK_OPTIONS+=" -vcheck_${c}=1"
diff --git a/kpatch-build/kpatch-elf.c b/kpatch-build/kpatch-elf.c
index 58dbe1a..069e102 100644
index 374d424..d4aee86 100644
--- a/kpatch-build/kpatch-elf.c
+++ b/kpatch-build/kpatch-elf.c
@@ -142,6 +142,8 @@ unsigned int absolute_rela_type(struct kpatch_elf *kelf)
@ -193,7 +197,7 @@ index 58dbe1a..069e102 100644
return 4;
case S390:
@@ -501,6 +505,9 @@ struct kpatch_elf *kpatch_elf_open(const char *name)
@@ -593,6 +597,9 @@ struct kpatch_elf *kpatch_elf_open(const char *name)
case EM_S390:
kelf->arch = S390;
break;
@ -204,10 +208,10 @@ index 58dbe1a..069e102 100644
ERROR("Unsupported target architecture");
}
diff --git a/kpatch-build/kpatch-elf.h b/kpatch-build/kpatch-elf.h
index 3bc6e76..d887812 100644
index e32209b..47e3117 100644
--- a/kpatch-build/kpatch-elf.h
+++ b/kpatch-build/kpatch-elf.h
@@ -113,6 +113,7 @@ enum architecture {
@@ -115,6 +115,7 @@ enum architecture {
PPC64 = 0x1 << 0,
X86_64 = 0x1 << 1,
S390 = 0x1 << 2,

View File

@ -1,7 +1,7 @@
From cc0e2fd24f623c617ae2c171105ae2924c818007 Mon Sep 17 00:00:00 2001
From d7847561b04a5859f3a013ea28765f965bb540de Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Sun, 14 Nov 2021 15:57:55 +0800
Subject: [PATCH 02/37] create-diff-object: fix symbol changed sections error
Subject: [PATCH 02/38] create-diff-object: fix symbol changed sections error
on aarch64
$d is reserved symbols in aarch64, we met following error when
@ -14,10 +14,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
1 file changed, 2 insertions(+)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 0b0b06b..3b677d3 100644
index e4c25a6..4a5a180 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -892,6 +892,8 @@ static void kpatch_compare_correlated_symbol(struct symbol *sym)
@@ -936,6 +936,8 @@ static void kpatch_compare_correlated_symbol(struct symbol *sym)
if ((sym2->sec->twin && sym2->sec->twin->ignore) ||
kpatch_subsection_changed(sym1->sec, sym2->sec))
sym->status = CHANGED;

View File

@ -1,7 +1,7 @@
From adafc04638712b7227328e44c0e023b5d3c46f53 Mon Sep 17 00:00:00 2001
From c04bfe41ccf06cafac28f4037380131441044556 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Sun, 14 Nov 2021 17:26:59 +0800
Subject: [PATCH 03/37] create-diff-object:support
Subject: [PATCH 03/38] create-diff-object:support
kpatch_line_macro_change_only on aarch64
implement kpatch_line_macro_change_only on aarch64
@ -12,10 +12,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
1 file changed, 16 insertions(+)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 3b677d3..2ad0791 100644
index 4a5a180..f854eca 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -647,6 +647,17 @@ static bool insn_is_load_immediate(struct kpatch_elf *kelf, void *addr)
@@ -691,6 +691,17 @@ static bool insn_is_load_immediate(struct kpatch_elf *kelf, void *addr)
break;
@ -33,7 +33,7 @@ index 3b677d3..2ad0791 100644
case S390:
/* arg2: lghi %r3, imm */
if (insn[0] == 0xa7 && insn[1] == 0x39)
@@ -698,6 +709,7 @@ static bool kpatch_line_macro_change_only(struct kpatch_elf *kelf,
@@ -742,6 +753,7 @@ static bool kpatch_line_macro_change_only(struct kpatch_elf *kelf,
void *data1, *data2, *insn1, *insn2;
struct rela *r, *rela;
bool found, found_any = false;
@ -41,7 +41,7 @@ index 3b677d3..2ad0791 100644
if (sec->status != CHANGED ||
is_rela_section(sec) ||
@@ -743,6 +755,10 @@ static bool kpatch_line_macro_change_only(struct kpatch_elf *kelf,
@@ -787,6 +799,10 @@ static bool kpatch_line_macro_change_only(struct kpatch_elf *kelf,
!insn_is_load_immediate(kelf, insn2))
return false;

View File

@ -1,7 +1,7 @@
From d4c1e4f3b5cb162bff499c1f28d11cbea626f787 Mon Sep 17 00:00:00 2001
From afe37ab3fd229b93319553637e4a12a4c6d6703a Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Sun, 14 Nov 2021 19:53:22 +0800
Subject: [PATCH 04/37] create-diff-object:support skip check func profiling
Subject: [PATCH 04/38] create-diff-object:support skip check func profiling
calls
when kernel support livepatch without ftrace, we can skip check
@ -13,10 +13,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 2ad0791..02a722d 100644
index f854eca..f7b59f0 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -3917,6 +3917,7 @@ int main(int argc, char *argv[])
@@ -4069,6 +4069,7 @@ int main(int argc, char *argv[])
struct section *relasec, *symtab;
char *orig_obj, *patched_obj, *parent_name;
char *parent_symtab, *mod_symvers, *patch_name, *output_obj;
@ -24,7 +24,7 @@ index 2ad0791..02a722d 100644
memset(&arguments, 0, sizeof(arguments));
argp_parse (&argp, argc, argv, 0, NULL, &arguments);
@@ -3970,7 +3971,12 @@ int main(int argc, char *argv[])
@@ -4122,7 +4123,12 @@ int main(int argc, char *argv[])
kpatch_compare_correlated_elements(kelf_patched);
kpatch_mark_ignored_functions_same(kelf_patched);
kpatch_mark_ignored_sections_same(kelf_patched);

View File

@ -1,7 +1,7 @@
From dbecda6959a2e0468aa75dbf647efa396a0359f7 Mon Sep 17 00:00:00 2001
From d95dfac91b76cb524e0382132ce2f0ac3a288a5a Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Tue, 25 Feb 2020 22:44:50 -0500
Subject: [PATCH 05/37] create-diff-object: new static var should be included
Subject: [PATCH 05/38] create-diff-object: new static var should be included
Before this patch, only global variables(no referenced) will be
included by kpatch-build. But some macros put some static varibles
@ -18,10 +18,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
1 file changed, 16 insertions(+)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 02a722d..c9ebb05 100644
index f7b59f0..20d9d8f 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -1870,6 +1870,21 @@ static void kpatch_include_force_elements(struct kpatch_elf *kelf)
@@ -1928,6 +1928,21 @@ static void kpatch_include_force_elements(struct kpatch_elf *kelf)
sym->include = 0;
}
@ -43,7 +43,7 @@ index 02a722d..c9ebb05 100644
static int kpatch_include_new_globals(struct kpatch_elf *kelf)
{
struct symbol *sym;
@@ -3985,6 +4000,7 @@ int main(int argc, char *argv[])
@@ -4137,6 +4152,7 @@ int main(int argc, char *argv[])
callbacks_exist = kpatch_include_callback_elements(kelf_patched);
kpatch_include_force_elements(kelf_patched);
new_globals_exist = kpatch_include_new_globals(kelf_patched);

View File

@ -1,7 +1,7 @@
From 17cb3696430d9d73c94174006ec9922b2285390b Mon Sep 17 00:00:00 2001
From 7874fb22ff9d32a92541c5e304094e813281ec2f Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Fri, 2 Nov 2018 17:24:51 +0000
Subject: [PATCH 06/37] create-diff-object: fix correlate static local
Subject: [PATCH 06/38] create-diff-object: fix correlate static local
variables for __param section
kpatch-build correlate fail when no sections reference
@ -31,10 +31,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
1 file changed, 4 insertions(+)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index c9ebb05..64b63e3 100644
index 20d9d8f..3cbfaee 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -1250,6 +1250,10 @@ static bool kpatch_is_normal_static_local(struct symbol *sym)
@@ -1300,6 +1300,10 @@ static bool kpatch_is_normal_static_local(struct symbol *sym)
if (is_special_static(sym))
return false;

View File

@ -1,7 +1,7 @@
From 9746f100debb0c17397c47f5d3abbe7ca4bde221 Mon Sep 17 00:00:00 2001
From bc9f5d244d3a4527c6390c9c0812b2d34b4655e5 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Tue, 25 Feb 2020 23:40:37 -0500
Subject: [PATCH 07/37] livepatch-patch-hook: support no active after load
Subject: [PATCH 07/38] livepatch-patch-hook: support no active after load
suppport Don't active patch after loading the patch when
DISABLE_AFTER_LOAD is set.
@ -33,10 +33,10 @@ index 3d13ab9..b578ef3 100644
return 0;
out:
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index 73f8976..00ba9ac 100755
index 80d7209..7f3bbce 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -1160,6 +1160,11 @@ export KCFLAGS="-I$DATADIR/patch $ARCH_KCFLAGS"
@@ -1384,6 +1384,11 @@ export KCFLAGS="-I$DATADIR/patch $ARCH_KCFLAGS"
if [[ "$USE_KLP" -eq 0 ]]; then
export KCPPFLAGS="-D__KPATCH_MODULE__"
fi

View File

@ -1,69 +1,47 @@
From f98adab4e8ad3333a4870aca50f9051d3fdf20c9 Mon Sep 17 00:00:00 2001
From 5f97ec32a8a98810811949ea9feeefe583a0fbd3 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Wed, 26 Feb 2020 06:44:06 -0500
Subject: [PATCH 08/37] kpatch-build: enhance for out of tree module
Subject: [PATCH 08/38] kpatch-build: enhance for out of tree module
support set USERMODBUILDDIR to build patch for out
of tree module.
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
---
kpatch-build/kpatch-build | 71 ++++++++++++++++++++++++++++++---------
kpatch-build/kpatch-build | 56 +++++++++++++++++++++++++++++++--------
kpatch-build/kpatch-cc | 4 ++-
2 files changed, 58 insertions(+), 17 deletions(-)
2 files changed, 48 insertions(+), 12 deletions(-)
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index 00ba9ac..139ebb1 100755
index 7f3bbce..8bd721b 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -444,7 +444,11 @@ filter_parent_obj()
local dir="${1}"
local file="${2}"
@@ -571,6 +571,12 @@ find_parent_obj() {
[[ -n "$PARENT" ]] && return
fi
- grep -v "\.mod\.cmd$" | grep -Fv "${dir}/.${file}.cmd"
+ grep -v "\.mod\.cmd$" | grep -Fv "${dir}/.${file}.cmd" | while read input; do
+ if [ "$(readlink -f $input)" != "$(readlink -f ${dir}/.${file}.cmd)" ];then
+ echo $input;
+ fi
+ done
}
find_parent_obj() {
@@ -466,6 +470,11 @@ find_parent_obj() {
num="$(find . -name ".*.cmd" -print0 | xargs -0 grep -lw "$grepname" | filter_parent_obj "${pdir}" "${file}" | wc -l)"
[[ "$num" -eq 1 ]] && last_deep_find="$(dirname "$parent")"
fi
+ if [[ "$num" -eq 0 ]]; then
+ parent="$(find $USERMODBUILDDIR -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | grep -Fv "$pdir/.${file}.cmd" | head -n1)"
+ num="$(find $USERMODBUILDDIR -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | grep -Fvc "$pdir/.${file}.cmd")"
+ [[ "$num" -eq 1 ]] && last_deep_find="$(dirname "$parent")"
+ fi
else
parent="$(grep -lw "$grepname" "$dir"/.*.cmd | filter_parent_obj "${dir}" "${file}" | head -n1)"
num="$(grep -lw "$grepname" "$dir"/.*.cmd | filter_parent_obj "${dir}" "${file}" | wc -l)"
@@ -655,7 +664,11 @@ if [[ -n "$SRCRPM" ]]; then
+ # try to find parent in OOT Module directory
+ if [[ -n "$USERMODBUILDDIR" ]]; then
+ find_parent_obj_in_dir "$file" "$USERMODBUILDDIR"
+ [[ -n "$PARENT" ]] && return
+ fi
+
# prevent known deep finds
if [[ $file = drivers/gpu/drm/amd/* ]]; then
find_parent_obj_in_dir "$file" "drivers/gpu/drm/amd/amdgpu"
@@ -789,6 +795,11 @@ if [[ -n "$SRCRPM" ]]; then
ARCHVERSION="${ARCHVERSION#alt-}"
fi
-if [[ -n "$OOT_MODULE" ]] && [[ -z "$OOT_MODULE_SRCDIR" ]]; then
+if [[ -n "$USERMODBUILDDIR" ]]; then
+ OOT_MODULE="yes"
+ OOT_MODULE_SRCDIR=$USERMODBUILDDIR
+fi
+
+if [[ -n "$OOT_MODULE" ]] && [[ "$OOT_MODULE" != "yes" ]] && [[ -z "$OOT_MODULE_SRCDIR" ]]; then
if [[ -n "$OOT_MODULE" ]] && [[ -z "$OOT_MODULE_SRCDIR" ]]; then
warn "--oot-module requires --oot-module-src"
exit 1
fi
@@ -665,7 +678,7 @@ mkdir -p "$TEMPDIR" || die "Couldn't create $TEMPDIR"
rm -rf "${TEMPDIR:?}"/*
rm -f "$LOGFILE"
-if [[ -n "$USERSRCDIR" ]]; then
+if [[ -n "$USERSRCDIR" ]] && [[ "$OOT_MODULE" != "yes" ]]; then
KERNEL_SRCDIR="$USERSRCDIR"
[[ -z "$VMLINUX" ]] && VMLINUX="$KERNEL_SRCDIR"/vmlinux
@@ -685,17 +698,21 @@ if [[ -n "$USERSRCDIR" ]]; then
@@ -819,7 +830,7 @@ if [[ -n "$USERSRCDIR" ]]; then
fi
fi
@ -72,41 +50,16 @@ index 00ba9ac..139ebb1 100755
ARCHVERSION="$(modinfo -F vermagic "$OOT_MODULE" | awk '{print $1}')"
fi
[[ -z "$ARCHVERSION" ]] && ARCHVERSION="$(uname -r)"
@@ -868,7 +879,7 @@ fi
if [[ -n "$OOT_MODULE" ]]; then
- if [[ -z "$USERSRCDIR" ]]; then
+ if [[ -z "$USERSRCDIR" ]] || [[ "$OOT_MODULE" == "yes" ]]; then
KERNEL_SRCDIR="/lib/modules/$ARCHVERSION/build/"
fi
- BUILDDIR="$OOT_MODULE_SRCDIR"
+ if [[ "$OOT_MODULE" == "yes" ]]; then
+ BUILDDIR="$USERSRCDIR"
+ else
+ BUILDDIR="$OOT_MODULE_SRCDIR"
+ fi
else
BUILDDIR="$KERNEL_SRCDIR"
fi
@@ -709,7 +726,7 @@ if [[ "$ARCHVERSION" =~ - ]]; then
fi
[[ "$ARCHVERSION" =~ .el7a. ]] && ALT="-alt"
-[[ -z "$TARGETS" ]] && TARGETS="vmlinux modules"
+[[ -z "$OOT_MODULE" ]] && [[ -z "$TARGETS" ]] && TARGETS="vmlinux modules"
+[[ -z "$TARGETS" ]] && [[ -z "$OOT_MODULE" ]] && TARGETS="vmlinux modules"
# Don't check external file.
# shellcheck disable=SC1090
@@ -851,7 +868,7 @@ fi
[[ -z "$CONFIGFILE" ]] && CONFIGFILE="$KERNEL_SRCDIR"/.config
[[ ! -e "$CONFIGFILE" ]] && die "can't find config file"
-if [[ -z "$OOT_MODULE" && ! "$CONFIGFILE" -ef "$KERNEL_SRCDIR"/.config ]] ; then
+if [[ ! "$CONFIGFILE" -ef "$KERNEL_SRCDIR"/.config ]] ; then
cp -f "$CONFIGFILE" "$KERNEL_SRCDIR/.config" || die
fi
@@ -925,7 +942,7 @@ if [[ -n "$CONFIG_CC_IS_CLANG" ]]; then
if [[ "$DISTRO" = fedora ]] || [[ "$DISTRO" = rhel ]] || [[ "$DISTRO" = ol ]] ||
[[ "$DISTRO" = centos ]] || [[ "$DISTRO" = openEuler ]] ||
@@ -1150,7 +1161,7 @@ if [[ -n "$CONFIG_CC_IS_CLANG" ]]; then
fi
if [[ "$SKIPCOMPILERCHECK" -eq 0 ]]; then
@ -115,7 +68,7 @@ index 00ba9ac..139ebb1 100755
target="$OOT_MODULE"
else
target="$VMLINUX"
@@ -987,10 +1004,16 @@ fi
@@ -1211,10 +1222,16 @@ fi
# $TARGETS used as list, no quotes.
# shellcheck disable=SC2086
@ -134,7 +87,7 @@ index 00ba9ac..139ebb1 100755
echo "Building patched source"
apply_patches
@@ -1000,7 +1023,12 @@ export KPATCH_GCC_SRCDIR="$BUILDDIR"
@@ -1224,7 +1241,12 @@ export KPATCH_GCC_SRCDIR="$BUILDDIR"
save_env
# $TARGETS used as list, no quotes.
# shellcheck disable=SC2086
@ -148,7 +101,7 @@ index 00ba9ac..139ebb1 100755
# source.c:(.section+0xFF): undefined reference to `symbol'
grep "undefined reference" "$LOGFILE" | sed -r "s/^.*\`(.*)'$/\\1/" \
@@ -1015,7 +1043,7 @@ fi
@@ -1239,7 +1261,7 @@ fi
grep -q vmlinux "$KERNEL_SRCDIR/Module.symvers" || die "truncated $KERNEL_SRCDIR/Module.symvers file"
@ -157,7 +110,7 @@ index 00ba9ac..139ebb1 100755
trace_off "reading Module.symvers"
while read -ra sym_line; do
if [[ ${#sym_line[@]} -lt 4 ]]; then
@@ -1045,7 +1073,11 @@ fi
@@ -1269,7 +1291,11 @@ fi
for i in $(cat "$TEMPDIR/changed_objs")
do
mkdir -p "$TEMPDIR/patched/$(dirname "$i")" || die
@ -170,7 +123,7 @@ index 00ba9ac..139ebb1 100755
done
echo "Extracting new and modified ELF sections"
@@ -1079,7 +1111,7 @@ CHANGED=0
@@ -1303,7 +1329,7 @@ CHANGED=0
ERROR=0
# Prepare OOT module symvers file
@ -179,21 +132,31 @@ index 00ba9ac..139ebb1 100755
cp -f "$OOT_MODULE_SRCDIR/Module.symvers" "$TEMPDIR/Module.symvers" || die
awk '{ print $1 "\t" $2 "\t" $3 "\t" $4}' "${KERNEL_SRCDIR}/Module.symvers" >> "$TEMPDIR/Module.symvers"
fi
@@ -1115,6 +1147,13 @@ for i in $FILES; do
@@ -1322,7 +1348,7 @@ for i in $FILES; do
find_kobj "$i"
cd "$TEMPDIR" || die
if [[ -e "orig/$i" ]]; then
- if [[ -n $OOT_MODULE ]]; then
+ if [[ -n $OOT_MODULE ]] && [[ "$OOT_MODULE" != "yes" ]]; then
KOBJFILE_NAME="$(basename --suffix=.ko "$OOT_MODULE")"
KOBJFILE_NAME="${KOBJFILE_NAME//-/_}"
KOBJFILE_PATH="$OOT_MODULE"
@@ -1339,6 +1365,14 @@ for i in $FILES; do
KOBJFILE_PATH="${TEMPDIR}/module/$KOBJFILE"
SYMTAB="${KOBJFILE_PATH}.symtab"
SYMVERS_FILE="$BUILDDIR/Module.symvers"
+
+ if [ "$OOT_MODULE" == "yes" ];then
+ MODBUILDDIR="/lib/modules/$ARCHVERSION/build/"
+ SYMVERS_FILE="$TEMPDIR/Module.symvers"
+ [[ -e $BUILDDIR/Module.symvers ]] && cp "$BUILDDIR/Module.symvers" "$SYMVERS_FILE"
+ [[ -e $USERMODBUILDDIR/Module.symvers ]] && cp "$USERMODBUILDDIR/Module.symvers" $SYMVERS_FILE
+ awk '{ print $1 "\t" $2 "\t" $3 "\t" $4}' "${KERNEL_SRCDIR}/Module.symvers" >> "$SYMVERS_FILE"
+ awk '{ print $1 "\t" $2 "\t" $3 "\t" $4}' "${MODBUILDDIR}/Module.symvers" >> "$SYMVERS_FILE"
+ fi
fi
"$READELF" -s --wide "$KOBJFILE_PATH" > "$SYMTAB"
@@ -1263,7 +1302,7 @@ fi
@@ -1487,7 +1521,7 @@ fi
# column containing lines unique to first file.
UNDEFINED=$(comm -23 <(sort -u "${TEMPDIR}"/undefined_references) \
<(sort -u "${TEMPDIR}"/new_symbols) | tr '\n' ' ')
@ -203,16 +166,16 @@ index 00ba9ac..139ebb1 100755
cp -f "$TEMPDIR/patch/$MODNAME.ko" "$BASE" || die
diff --git a/kpatch-build/kpatch-cc b/kpatch-build/kpatch-cc
index 6f0063e..991bcad 100755
index 17aae25..ce72e55 100755
--- a/kpatch-build/kpatch-cc
+++ b/kpatch-build/kpatch-cc
@@ -24,7 +24,9 @@ if [[ "$TOOLCHAINCMD" =~ ^(.*-)?gcc$ || "$TOOLCHAINCMD" =~ ^(.*-)?clang$ ]] ; th
[[ "$obj" = */.tmp_*.o ]] && obj="${obj/.tmp_/}"
relobj=${obj##$KPATCH_GCC_SRCDIR/}
relobj=${obj##"$KPATCH_GCC_SRCDIR"/}
- case "$relobj" in
+ tmpobj=$(readlink -f $obj)
+ relobj2=${tmpobj//$KPATCH_GCC_SRCDIR\//}
+ relobj2=${tmpobj##"$KPATCH_GCC_SRCDIR"/}
+ case "$relobj2" in
*.mod.o|\
*built-in.o|\

View File

@ -1,7 +1,7 @@
From 413d7e988102a6cd085650909c98d54656295de9 Mon Sep 17 00:00:00 2001
From df00eb365c9011e32d3c191d6c908a8e745100b2 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Wed, 26 Feb 2020 07:36:59 -0500
Subject: [PATCH 09/37] support c++ kernel module
Subject: [PATCH 09/38] support c++ kernel module
support GNU_UNIQUE type symbols.
support .group section corelation.
@ -16,10 +16,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
4 files changed, 45 insertions(+), 20 deletions(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 64b63e3..7e415dd 100644
index 3cbfaee..d3088b1 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -554,7 +554,7 @@ static void kpatch_compare_correlated_nonrela_section(struct section *sec)
@@ -598,7 +598,7 @@ static void kpatch_compare_correlated_nonrela_section(struct section *sec)
{
struct section *sec1 = sec, *sec2 = sec->twin;
@ -28,7 +28,7 @@ index 64b63e3..7e415dd 100644
memcmp(sec1->data->d_buf, sec2->data->d_buf, sec1->data->d_size))
sec->status = CHANGED;
else
@@ -570,7 +570,7 @@ static void kpatch_compare_correlated_section(struct section *sec)
@@ -614,7 +614,7 @@ static void kpatch_compare_correlated_section(struct section *sec)
sec1->sh.sh_flags != sec2->sh.sh_flags ||
sec1->sh.sh_entsize != sec2->sh.sh_entsize ||
(sec1->sh.sh_addralign != sec2->sh.sh_addralign &&
@ -37,7 +37,7 @@ index 64b63e3..7e415dd 100644
DIFF_FATAL("%s section header details differ from %s", sec1->name, sec2->name);
/* Short circuit for mcount sections, we rebuild regardless */
@@ -1006,6 +1006,34 @@ static void kpatch_correlate_section(struct section *sec_orig,
@@ -1050,6 +1050,34 @@ static void kpatch_correlate_section(struct section *sec_orig,
kpatch_correlate_symbol(sec_orig->sym, sec_patched->sym);
}
@ -72,7 +72,7 @@ index 64b63e3..7e415dd 100644
static void kpatch_correlate_sections(struct list_head *seclist_orig,
struct list_head *seclist_patched)
{
@@ -1029,10 +1057,7 @@ static void kpatch_correlate_sections(struct list_head *seclist_orig,
@@ -1076,10 +1104,7 @@ static void kpatch_correlate_sections(struct list_head *seclist_orig,
* Changed group sections are currently not supported.
*/
if (sec_orig->sh.sh_type == SHT_GROUP) {
@ -84,7 +84,7 @@ index 64b63e3..7e415dd 100644
continue;
}
@@ -1682,17 +1707,6 @@ static void kpatch_verify_patchability(struct kpatch_elf *kelf)
@@ -1740,17 +1765,6 @@ static void kpatch_verify_patchability(struct kpatch_elf *kelf)
errs++;
}
@ -103,7 +103,7 @@ index 64b63e3..7e415dd 100644
* ensure we aren't including .data.* or .bss.*
* (.data.unlikely and .data.once is ok b/c it only has __warned vars)
diff --git a/kpatch-build/kpatch-cc b/kpatch-build/kpatch-cc
index 991bcad..5e241dd 100755
index ce72e55..8f22978 100755
--- a/kpatch-build/kpatch-cc
+++ b/kpatch-build/kpatch-cc
@@ -13,7 +13,9 @@ fi
@ -118,10 +118,10 @@ index 991bcad..5e241dd 100755
if [ "$1" = "-o" ]; then
obj="$2"
diff --git a/kpatch-build/kpatch-elf.c b/kpatch-build/kpatch-elf.c
index 069e102..877deac 100644
index d4aee86..b639bc2 100644
--- a/kpatch-build/kpatch-elf.c
+++ b/kpatch-build/kpatch-elf.c
@@ -851,8 +851,14 @@ void kpatch_reindex_elements(struct kpatch_elf *kelf)
@@ -978,8 +978,14 @@ void kpatch_reindex_elements(struct kpatch_elf *kelf)
unsigned int index;
index = 1; /* elf write function handles NULL section 0 */
@ -138,10 +138,10 @@ index 069e102..877deac 100644
index = 0;
list_for_each_entry(sym, &kelf->symbols, list) {
diff --git a/kpatch-build/lookup.c b/kpatch-build/lookup.c
index f2596b1..829250f 100644
index bd2b732..8905a1d 100644
--- a/kpatch-build/lookup.c
+++ b/kpatch-build/lookup.c
@@ -306,6 +306,8 @@ static void symtab_read(struct lookup_table *table, char *path)
@@ -334,6 +334,8 @@ static void symtab_read(struct lookup_table *table, char *path)
table->obj_syms[i].bind = STB_GLOBAL;
} else if (!strcmp(bind, "WEAK")) {
table->obj_syms[i].bind = STB_WEAK;
@ -150,7 +150,7 @@ index f2596b1..829250f 100644
} else {
ERROR("unknown symbol bind %s", bind);
}
@@ -530,7 +532,8 @@ static bool lookup_global_symbol(struct lookup_table *table, char *name,
@@ -558,7 +560,8 @@ static bool lookup_global_symbol(struct lookup_table *table, char *name,
memset(result, 0, sizeof(*result));
for_each_obj_symbol(i, sym, table) {

View File

@ -1,7 +1,7 @@
From 4821b72a908ed4ded1f0a37afa238af62d0f778a Mon Sep 17 00:00:00 2001
From 44139a57987e0d47fc7e1a39ca1e4ee37eb93a87 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Wed, 26 Feb 2020 22:03:55 -0500
Subject: [PATCH 10/37] symbol lookup enhancement
Subject: [PATCH 10/38] symbol lookup enhancement
For symbols which have same name in one module or have
length longger than KSYM_NAME_LEN(128 bytes). we add
@ -44,10 +44,10 @@ index da4f6a0..9df7818 100644
struct kpatch_pre_patch_callback {
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 7e415dd..e11a900 100644
index d3088b1..ee06ad1 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -3087,6 +3087,14 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
@@ -3231,6 +3231,14 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
funcs[index].old_size = symbol.size;
funcs[index].new_size = sym->sym.st_size;
funcs[index].sympos = symbol.sympos;
@ -62,7 +62,7 @@ index 7e415dd..e11a900 100644
/*
* Add a relocation that will populate the
@@ -3105,7 +3113,8 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
@@ -3249,7 +3257,8 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
ALLOC_LINK(rela, &relasec->relas);
rela->sym = strsym;
rela->type = absolute_rela_type(kelf);
@ -72,7 +72,7 @@ index 7e415dd..e11a900 100644
rela->offset = (unsigned int)(index * sizeof(*funcs) +
offsetof(struct kpatch_patch_func, name));
@@ -3345,6 +3354,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
@@ -3490,6 +3499,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
bool special;
bool vmlinux = !strcmp(objname, "vmlinux");
struct special_section *s;
@ -80,7 +80,7 @@ index 7e415dd..e11a900 100644
/* count rela entries that need to be dynamic */
nr = 0;
@@ -3445,12 +3455,34 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
@@ -3590,12 +3600,34 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
rela->sym->name, symbol.objname,
symbol.sympos);
@ -116,7 +116,7 @@ index 7e415dd..e11a900 100644
ksyms[index].sympos = symbol.sympos;
ksyms[index].type = rela->sym->type;
ksyms[index].bind = rela->sym->bind;
@@ -3459,7 +3491,8 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
@@ -3604,7 +3636,8 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
ALLOC_LINK(rela2, &ksym_sec->rela->relas);
rela2->sym = strsym;
rela2->type = absolute_rela_type(kelf);
@ -126,7 +126,7 @@ index 7e415dd..e11a900 100644
rela2->offset = (unsigned int)(index * sizeof(*ksyms) + \
offsetof(struct kpatch_symbol, name));
@@ -3478,6 +3511,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
@@ -3623,6 +3656,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
krelas[index].addend = rela->addend;
krelas[index].type = rela->type;
krelas[index].external = !vmlinux && symbol.exported;
@ -135,7 +135,7 @@ index 7e415dd..e11a900 100644
/* add rela to fill in krelas[index].dest field */
ALLOC_LINK(rela2, &krela_sec->rela->relas);
diff --git a/kpatch-build/create-klp-module.c b/kpatch-build/create-klp-module.c
index e942b9e..b77028f 100644
index c50f0dd..89d37c8 100644
--- a/kpatch-build/create-klp-module.c
+++ b/kpatch-build/create-klp-module.c
@@ -38,7 +38,9 @@ enum loglevel loglevel = NORMAL;
@ -200,10 +200,10 @@ index e942b9e..b77028f 100644
ERROR("error finding or adding ksym to symtab");
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index 139ebb1..f6855ed 100755
index 8bd721b..0567523 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -1148,6 +1148,18 @@ for i in $FILES; do
@@ -1366,6 +1366,18 @@ for i in $FILES; do
SYMTAB="${KOBJFILE_PATH}.symtab"
SYMVERS_FILE="$BUILDDIR/Module.symvers"
@ -220,8 +220,8 @@ index 139ebb1..f6855ed 100755
+ cd "$TEMPDIR" || die
+
if [ "$OOT_MODULE" == "yes" ];then
MODBUILDDIR="/lib/modules/$ARCHVERSION/build/"
SYMVERS_FILE="$TEMPDIR/Module.symvers"
[[ -e $BUILDDIR/Module.symvers ]] && cp "$BUILDDIR/Module.symvers" "$SYMVERS_FILE"
diff --git a/kpatch-build/kpatch-intermediate.h b/kpatch-build/kpatch-intermediate.h
index 2036cb3..2589959 100644
--- a/kpatch-build/kpatch-intermediate.h
@ -236,7 +236,7 @@ index 2036cb3..2589959 100644
struct kpatch_arch {
diff --git a/kpatch-build/lookup.c b/kpatch-build/lookup.c
index 829250f..71ede78 100644
index 8905a1d..9eb3e73 100644
--- a/kpatch-build/lookup.c
+++ b/kpatch-build/lookup.c
@@ -45,6 +45,7 @@ struct object_symbol {
@ -247,7 +247,7 @@ index 829250f..71ede78 100644
};
struct export_symbol {
@@ -299,6 +300,7 @@ static void symtab_read(struct lookup_table *table, char *path)
@@ -327,6 +328,7 @@ static void symtab_read(struct lookup_table *table, char *path)
table->obj_syms[i].addr = addr;
table->obj_syms[i].size = strtoul(size, NULL, 0);
@ -255,7 +255,7 @@ index 829250f..71ede78 100644
if (!strcmp(bind, "LOCAL")) {
table->obj_syms[i].bind = STB_LOCAL;
@@ -459,6 +461,17 @@ static bool lookup_local_symbol(struct lookup_table *table,
@@ -487,6 +489,17 @@ static bool lookup_local_symbol(struct lookup_table *table,
if (sym->bind == STB_LOCAL && !strcmp(sym->name,
lookup_sym->name))
sympos++;
@ -273,7 +273,7 @@ index 829250f..71ede78 100644
if (lookup_sym->lookup_table_file_sym == sym) {
in_file = 1;
@@ -529,11 +542,22 @@ static bool lookup_global_symbol(struct lookup_table *table, char *name,
@@ -557,11 +570,22 @@ static bool lookup_global_symbol(struct lookup_table *table, char *name,
{
struct object_symbol *sym;
int i;
@ -298,7 +298,7 @@ index 829250f..71ede78 100644
!strcmp(sym->name, name)) {
if (result->objname)
@@ -542,7 +566,7 @@ static bool lookup_global_symbol(struct lookup_table *table, char *name,
@@ -570,7 +594,7 @@ static bool lookup_global_symbol(struct lookup_table *table, char *name,
result->objname = table->objname;
result->addr = sym->addr;
result->size = sym->size;
@ -307,7 +307,7 @@ index 829250f..71ede78 100644
result->global = true;
result->exported = is_exported(table, name);
}
@@ -562,3 +586,132 @@ bool lookup_symbol(struct lookup_table *table, struct symbol *sym,
@@ -590,3 +614,132 @@ bool lookup_symbol(struct lookup_table *table, struct symbol *sym,
return lookup_exported_symbol(table, sym->name, result);
}

View File

@ -1,7 +1,7 @@
From 1a7e97179174f64a99e27649c1e5ff2c322bfa26 Mon Sep 17 00:00:00 2001
From 62125c1bf327ba04df7a3cafb22c92df935fb0f3 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Wed, 26 Feb 2020 20:28:13 -0500
Subject: [PATCH 11/37] Add running kernel symbol table to help symbol lookup
Subject: [PATCH 11/38] Add running kernel symbol table to help symbol lookup
For some duplicate symbols whose section have no other
symbols, we need running kernel symbol table to help
@ -13,7 +13,7 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
1 file changed, 73 insertions(+)
diff --git a/kpatch-build/lookup.c b/kpatch-build/lookup.c
index 71ede78..d3b6ae9 100644
index 9eb3e73..87f315a 100644
--- a/kpatch-build/lookup.c
+++ b/kpatch-build/lookup.c
@@ -46,6 +46,7 @@ struct object_symbol {
@ -24,7 +24,7 @@ index 71ede78..d3b6ae9 100644
};
struct export_symbol {
@@ -411,10 +412,62 @@ static void symvers_read(struct lookup_table *table, char *path)
@@ -439,10 +440,62 @@ static void symvers_read(struct lookup_table *table, char *path)
fclose(file);
}
@ -87,7 +87,7 @@ index 71ede78..d3b6ae9 100644
table = malloc(sizeof(*table));
if (!table)
@@ -424,6 +477,9 @@ struct lookup_table *lookup_open(char *symtab_path, char *objname,
@@ -452,6 +505,9 @@ struct lookup_table *lookup_open(char *symtab_path, char *objname,
table->objname = objname;
symtab_read(table, symtab_path);
symvers_read(table, symvers_path);
@ -97,7 +97,7 @@ index 71ede78..d3b6ae9 100644
find_local_syms_multiple(table, kelf);
@@ -689,6 +745,23 @@ int lookup_ref_symbol_offset(struct lookup_table *table,
@@ -717,6 +773,23 @@ int lookup_ref_symbol_offset(struct lookup_table *table,
}
}

View File

@ -1,7 +1,7 @@
From 66c81cb4c67b21dea3be2d93edf4273346c880e0 Mon Sep 17 00:00:00 2001
From 082ad81ab0b269841c4d4a094d9692a9e681d38f Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Wed, 26 Feb 2020 20:43:34 -0500
Subject: [PATCH 12/37] livepatch-patch-hook: support force enable/disable
Subject: [PATCH 12/38] livepatch-patch-hook: support force enable/disable
we use force to indicate function which bypass stack check
@ -58,10 +58,10 @@ index b578ef3..71439d9 100644
lfunc->old_sympos = func->kfunc->sympos;
#else
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index f6855ed..a5324db 100755
index 0567523..39f8050 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -377,7 +377,7 @@ find_special_section_data() {
@@ -372,7 +372,7 @@ find_special_section_data() {
# shellcheck disable=SC2086
SPECIAL_VARS="$("$READELF" -wi "$VMLINUX" |
gawk --non-decimal-data $AWK_OPTIONS '
@ -70,7 +70,7 @@ index f6855ed..a5324db 100755
# Set state if name matches
check_a && a == 0 && /DW_AT_name.* alt_instr[[:space:]]*$/ {a = 1; next}
@@ -389,6 +389,7 @@ find_special_section_data() {
@@ -384,6 +384,7 @@ find_special_section_data() {
check_o && o == 0 && /DW_AT_name.* orc_entry[[:space:]]*$/ {o = 1; next}
check_p && p == 0 && /DW_AT_name.* paravirt_patch_site[[:space:]]*$/ {p = 1; next}
check_s && s == 0 && /DW_AT_name.* static_call_site[[:space:]]*$/ {s = 1; next}
@ -78,7 +78,7 @@ index f6855ed..a5324db 100755
# Reset state unless this abbrev describes the struct size
a == 1 && !/DW_AT_byte_size/ { a = 0; next }
@@ -400,6 +401,8 @@ find_special_section_data() {
@@ -395,6 +396,8 @@ find_special_section_data() {
o == 1 && !/DW_AT_byte_size/ { o = 0; next }
p == 1 && !/DW_AT_byte_size/ { p = 0; next }
s == 1 && !/DW_AT_byte_size/ { s = 0; next }
@ -87,7 +87,7 @@ index f6855ed..a5324db 100755
# Now that we know the size, stop parsing for it
a == 1 {printf("export ALT_STRUCT_SIZE=%d\n", $4); a = 2}
@@ -411,6 +414,7 @@ find_special_section_data() {
@@ -406,6 +409,7 @@ find_special_section_data() {
o == 1 {printf("export ORC_STRUCT_SIZE=%d\n", $4); o = 2}
p == 1 {printf("export PARA_STRUCT_SIZE=%d\n", $4); p = 2}
s == 1 {printf("export STATIC_CALL_STRUCT_SIZE=%d\n", $4); s = 2}
@ -95,7 +95,7 @@ index f6855ed..a5324db 100755
# Bail out once we have everything
(!check_a || a == 2) &&
@@ -421,7 +425,8 @@ find_special_section_data() {
@@ -416,7 +420,8 @@ find_special_section_data() {
(!check_j || j == 2) &&
(!check_o || o == 2) &&
(!check_p || p == 2) &&
@ -105,7 +105,7 @@ index f6855ed..a5324db 100755
[[ -n "$SPECIAL_VARS" ]] && eval "$SPECIAL_VARS"
@@ -1216,6 +1221,14 @@ if [[ -n "$DISABLE_AFTER_LOAD" ]];then
@@ -1435,6 +1440,14 @@ if [[ -n "$DISABLE_AFTER_LOAD" ]];then
export KCPPFLAGS="-DDISABLE_AFTER_LOAD $KCPPFLAGS"
fi

View File

@ -1,7 +1,7 @@
From 5e9f742fae2faef7ce30acd3bcf0f3085f55a0f6 Mon Sep 17 00:00:00 2001
From 41cb82ddd28ce6abd70686839f871d44f670b5dd Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Wed, 26 Feb 2020 21:01:02 -0500
Subject: [PATCH 13/37] kpatch-build: ignore debuginfo in patch
Subject: [PATCH 13/38] kpatch-build: ignore debuginfo in patch
Just ignore all .debug_* sections
@ -12,10 +12,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
2 files changed, 19 insertions(+)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index e11a900..9b966e8 100644
index ee06ad1..2d28aa0 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -2763,6 +2763,23 @@ static void kpatch_include_debug_sections(struct kpatch_elf *kelf)
@@ -2899,6 +2899,23 @@ static void kpatch_include_debug_sections(struct kpatch_elf *kelf)
}
}
@ -39,7 +39,7 @@ index e11a900..9b966e8 100644
static void kpatch_mark_ignored_sections(struct kpatch_elf *kelf)
{
struct section *sec, *strsec, *ignoresec;
@@ -4054,6 +4071,7 @@ int main(int argc, char *argv[])
@@ -4206,6 +4223,7 @@ int main(int argc, char *argv[])
new_globals_exist = kpatch_include_new_globals(kelf_patched);
kpatch_include_new_static_var(kelf_patched);
kpatch_include_debug_sections(kelf_patched);
@ -48,10 +48,10 @@ index e11a900..9b966e8 100644
kpatch_process_special_sections(kelf_patched, lookup);
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index a5324db..84d8592 100755
index 39f8050..9f14bb2 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -1273,6 +1273,7 @@ CROSS_COMPILE="$CROSS_COMPILE"
@@ -1492,6 +1492,7 @@ CROSS_COMPILE="$CROSS_COMPILE"
save_env
make "${MAKEVARS[@]}" 2>&1 | logger || die

View File

@ -1,7 +1,7 @@
From 9e83f203c363d6cb88853daa0f5751501baa1d70 Mon Sep 17 00:00:00 2001
From 99de1c4a9cf1776b028149575377d7b61faecdbe Mon Sep 17 00:00:00 2001
From: Bin Yang <robin.yb@huawei.com>
Date: Tue, 16 Jul 2019 14:39:27 +0800
Subject: [PATCH 14/37] add object in kpatch
Subject: [PATCH 14/38] add object in kpatch
it is required by make_hotpatch users
@ -11,10 +11,10 @@ Signed-off-by: Bin Yang <robin.yb@huawei.com>
1 file changed, 3 insertions(+)
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index 84d8592..a5168f5 100755
index 9f14bb2..67e56e1 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -1209,6 +1209,8 @@ echo -n "Patched objects:"
@@ -1428,6 +1428,8 @@ echo -n "Patched objects:"
for i in $(echo "${objnames[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')
do
echo -n " $i"
@ -23,7 +23,7 @@ index 84d8592..a5168f5 100755
done
echo
@@ -1331,6 +1333,7 @@ UNDEFINED=$(comm -23 <(sort -u "${TEMPDIR}"/undefined_references) \
@@ -1550,6 +1552,7 @@ UNDEFINED=$(comm -23 <(sort -u "${TEMPDIR}"/undefined_references) \
[[ -z "$USERMODBUILDDIR" ]] && [[ -n "$UNDEFINED" ]] && die "Undefined symbols: $UNDEFINED"
cp -f "$TEMPDIR/patch/$MODNAME.ko" "$BASE" || die

View File

@ -1,7 +1,7 @@
From 98823cdec5eeafae9b7ed17be4e909314e924111 Mon Sep 17 00:00:00 2001
From cd4c9a46e2499ed56950d324b3d95c580e0ab03a Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Thu, 27 Feb 2020 15:36:55 -0500
Subject: [PATCH 15/37] create-diff-object: fix .orc_unwind_ip error
Subject: [PATCH 15/38] create-diff-object: fix .orc_unwind_ip error
error: .orc_unwind_ip section header details
differ from .orc_unwind_ip
@ -14,10 +14,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
1 file changed, 6 insertions(+)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 9b966e8..9c70fee 100644
index 2d28aa0..41a9c0f 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -1061,6 +1061,9 @@ static void kpatch_correlate_sections(struct list_head *seclist_orig,
@@ -1108,6 +1108,9 @@ static void kpatch_correlate_sections(struct list_head *seclist_orig,
continue;
}
@ -27,7 +27,7 @@ index 9b966e8..9c70fee 100644
kpatch_correlate_section(sec_orig, sec_patched);
break;
}
@@ -1098,6 +1101,9 @@ static void kpatch_correlate_symbols(struct list_head *symlist_orig,
@@ -1148,6 +1151,9 @@ static void kpatch_correlate_symbols(struct list_head *symlist_orig,
sym_orig->sec->twin != sym_patched->sec)
continue;

View File

@ -1,7 +1,7 @@
From 7d73bf5fe9d4c551424eb4868cd7081cbf0334d1 Mon Sep 17 00:00:00 2001
From f2b8a790b653d2eab5d48cbb725ec94b1655b0f2 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Mon, 2 Mar 2020 04:35:07 -0500
Subject: [PATCH 16/37] create-diff-object: add jump label support
Subject: [PATCH 16/38] create-diff-object: add jump label support
This patch processes the __jump_table special section, and
only the jump_lable used by the changed functions will be
@ -15,7 +15,7 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 9c70fee..9334cf9 100644
index 41a9c0f..e24482e 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -70,6 +70,7 @@ enum subsection {
@ -24,9 +24,9 @@ index 9c70fee..9334cf9 100644
bool KLP_ARCH;
+char *KEEP_JUMP_LABEL = NULL;
/*******************
* Data structures
@@ -2399,6 +2400,8 @@ static bool should_keep_jump_label(struct lookup_table *lookup,
int jump_label_errors, static_call_errors;
@@ -2355,6 +2356,8 @@ static bool jump_table_group_filter(struct lookup_table *lookup,
if (tracepoint || dynamic_debug)
return false;
@ -35,16 +35,16 @@ index 9c70fee..9334cf9 100644
/*
* This will be upgraded to an error after all jump labels have
* been reported.
@@ -2429,6 +2432,8 @@ static bool should_keep_jump_label(struct lookup_table *lookup,
@@ -2385,6 +2388,8 @@ static bool jump_table_group_filter(struct lookup_table *lookup,
if (tracepoint || dynamic_debug)
return false;
+ if (KEEP_JUMP_LABEL)
+ return true;
/*
* This will be upgraded to an error after all jump labels have
* been reported.
@@ -3027,8 +3032,7 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf,
* This will be upgraded to an error after all jump label
* errors have been reported.
@@ -3171,8 +3176,7 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf,
* labels and enable tracepoints in a patched function.
*/
list_for_each_entry(sec, &kelf->sections, list) {
@ -54,7 +54,7 @@ index 9c70fee..9334cf9 100644
strcmp(sec->name, "__tracepoints_ptrs") &&
strcmp(sec->name, "__tracepoints_strings"))
continue;
@@ -4009,6 +4013,7 @@ int main(int argc, char *argv[])
@@ -4161,6 +4165,7 @@ int main(int argc, char *argv[])
char *parent_symtab, *mod_symvers, *patch_name, *output_obj;
char *no_profiling_calls = NULL;

View File

@ -1,7 +1,7 @@
From 74f78de8bd7f97f4129320f944024ffaa4317c9e Mon Sep 17 00:00:00 2001
From 2573039f44d58727421c235dca385589f9246d83 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Thu, 12 Mar 2020 06:56:21 -0400
Subject: [PATCH 17/37] kpatch-build: add compile flag -fno-reorder-functions
Subject: [PATCH 17/38] kpatch-build: add compile flag -fno-reorder-functions
Sometimes function foo with static variables can be put in
.text.foo section in original binary and be put in
@ -23,10 +23,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index a5168f5..a73bd1b 100755
index 67e56e1..0431e0b 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -975,7 +975,7 @@ if [[ "$ARCH" = "s390x" ]]; then
@@ -1194,7 +1194,7 @@ if [[ "$ARCH" = "s390x" ]]; then
ARCH_KCFLAGS="-mno-pic-data-is-text-relative -fno-section-anchors"
fi

View File

@ -1,7 +1,7 @@
From 240690fed2b440ec5e1a69e5c1d69cbbd064757f Mon Sep 17 00:00:00 2001
From 7d4ffe84f38a79b4de2be6e254d356b0a9936ce7 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Sun, 22 Nov 2020 21:40:39 +0800
Subject: [PATCH 18/37] Fix relocation not resolved when new functions exported
Subject: [PATCH 18/38] Fix relocation not resolved when new functions exported
only
When no functions changed and new functions exported, kobject is not
@ -84,10 +84,10 @@ index 71439d9..9e56fe3 100644
ret = -ENOMEM;
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 9334cf9..2510620 100644
index e24482e..8c1b8ad 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -2968,6 +2968,27 @@ static void kpatch_create_kpatch_arch_section(struct kpatch_elf *kelf, char *obj
@@ -3112,6 +3112,27 @@ static void kpatch_create_kpatch_arch_section(struct kpatch_elf *kelf, char *obj
karch_sec->sh.sh_size = karch_sec->data->d_size;
}
@ -115,7 +115,7 @@ index 9334cf9..2510620 100644
static void kpatch_process_special_sections(struct kpatch_elf *kelf,
struct lookup_table *lookup)
{
@@ -4119,6 +4140,11 @@ int main(int argc, char *argv[])
@@ -4271,6 +4292,11 @@ int main(int argc, char *argv[])
kpatch_create_intermediate_sections(kelf_out, lookup, parent_name, patch_name);
kpatch_create_kpatch_arch_section(kelf_out, parent_name);
kpatch_create_callbacks_objname_rela(kelf_out, parent_name);

View File

@ -1,7 +1,7 @@
From fbf50da80b82c2749a76181f6bd76c9ee8d2539c Mon Sep 17 00:00:00 2001
From bd30bf1f72ec04f272554b3a7074506c6f3af637 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Wed, 30 Dec 2020 21:13:10 -0500
Subject: [PATCH 19/37] support remove static variables using
Subject: [PATCH 19/38] support remove static variables using
KPATCH_IGNORE_STATIC
Static variables will be removed due to compiler optimization.
@ -16,7 +16,7 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/kmod/patch/kpatch-macros.h b/kmod/patch/kpatch-macros.h
index 8e09702..02d548e 100644
index b797838..69fdbbb 100644
--- a/kmod/patch/kpatch-macros.h
+++ b/kmod/patch/kpatch-macros.h
@@ -13,6 +13,10 @@
@ -31,10 +31,10 @@ index 8e09702..02d548e 100644
* KPATCH_IGNORE_SECTION macro
*
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 2510620..c90b30a 100644
index 8c1b8ad..83836f6 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -1319,6 +1319,40 @@ static struct rela *kpatch_find_static_twin_ref(struct section *relasec,
@@ -1369,6 +1369,40 @@ static struct rela *kpatch_find_static_twin_ref(struct section *relasec,
return NULL;
}
@ -75,7 +75,7 @@ index 2510620..c90b30a 100644
/*
* gcc renames static local variables by appending a period and a number. For
* example, __foo could be renamed to __foo.31452. Unfortunately this number
@@ -1399,6 +1433,11 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *orig,
@@ -1449,6 +1483,11 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *orig,
if (sym->twin)
continue;
@ -87,7 +87,7 @@ index 2510620..c90b30a 100644
bundled = sym == sym->sec->sym;
if (bundled && sym->sec == relasec->base) {
/*
@@ -1456,6 +1495,11 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *orig,
@@ -1506,6 +1545,11 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *orig,
if (!kpatch_is_normal_static_local(sym))
continue;
@ -99,7 +99,7 @@ index 2510620..c90b30a 100644
if (!relasec->twin && relasec->base->sym) {
struct symbol *parent = NULL;
@@ -1499,7 +1543,6 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *orig,
@@ -1549,7 +1593,6 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *orig,
log_normal("WARNING: unable to correlate static local variable %s used by %s, assuming variable is new\n",
sym->name,
kpatch_section_function_name(relasec));

View File

@ -1,7 +1,7 @@
From d122635200d5c9d7e6efa59745efe2e796a7f9ff Mon Sep 17 00:00:00 2001
From 2cf99367ed7cdf4f0b2a929f6bddd7ef8c8a6441 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Thu, 12 Mar 2020 05:10:55 -0400
Subject: [PATCH 20/37] use original reloc for symbols exported from modules
Subject: [PATCH 20/38] use original reloc for symbols exported from modules
symbols exported in a patch will generate a symbol version with
object module name in Module.symvers, but the symbol is actually
@ -9,22 +9,23 @@ in patch module which cause livepatch symbol lookup failed.
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
---
kpatch-build/create-diff-object.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
kpatch-build/create-diff-object.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index c90b30a..deddde9 100644
index 83836f6..2a3a5de 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -3388,13 +3388,7 @@ static bool need_dynrela(struct kpatch_elf *kelf, struct lookup_table *table,
@@ -3533,14 +3533,7 @@ static bool need_klp_reloc(struct kpatch_elf *kelf, struct lookup_table *table,
return false;
}
- /*
- * The symbol is exported by the to-be-patched module, or by
- * another module which the patched module depends on. Use a
- * dynrela because of late module loading: the patch module may
- * be loaded before the to-be-patched (or other) module.
- * klp relocation because of late module loading: the patch
- * module may be loaded before the to-be-patched (or other)
- * module.
- */
- return true;
+ return false;

View File

@ -1,7 +1,7 @@
From 2de1633802ae3bc2c4f91e536dbba830da6ad932 Mon Sep 17 00:00:00 2001
From 01214c9675eba980b44886e22478b7daff88c875 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Fri, 2 Nov 2018 17:25:38 +0000
Subject: [PATCH 21/37] create-diff-object: create dynamic relocs for changed
Subject: [PATCH 21/38] create-diff-object: create dynamic relocs for changed
functions in this object
Currently, we only create dynamic relocs for changed functions of
@ -26,10 +26,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
1 file changed, 6 insertions(+)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index deddde9..5e216d1 100644
index 2a3a5de..5bed3e2 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -3309,6 +3309,12 @@ static bool need_dynrela(struct kpatch_elf *kelf, struct lookup_table *table,
@@ -3453,6 +3453,12 @@ static bool need_klp_reloc(struct kpatch_elf *kelf, struct lookup_table *table,
return false;
if (rela->sym->sec) {
@ -40,8 +40,8 @@ index deddde9..5e216d1 100644
+ relasec->base->sym->type == STT_FUNC)
+ return true;
/*
* Internal symbols usually don't need dynrelas, because they
* live in the patch module and can be relocated normally.
* Internal symbols usually don't need klp relocations, because
* they live in the patch module and can be relocated normally.
--
2.33.0

View File

@ -1,7 +1,7 @@
From 9b611ad453be06cfb48d9352ef65166a432a8edd Mon Sep 17 00:00:00 2001
From 54c891e55c80588ec8a18c7ef926e63aff69478c Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Tue, 16 Nov 2021 20:21:31 +0800
Subject: [PATCH 22/37] kpatch-build: support CROSS_COMPILE
Subject: [PATCH 22/38] kpatch-build: support CROSS_COMPILE
some Makefile use $(CROSS_COMPILE)gcc to compile .o
file, append CROSS_COMPILE to MAKEVARS to make it
@ -13,10 +13,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
1 file changed, 1 insertion(+)
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index a73bd1b..daa9a81 100755
index 0431e0b..a5e3688 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -997,6 +997,7 @@ if [[ -n "$CONFIG_CC_IS_CLANG" ]]; then
@@ -1215,6 +1215,7 @@ if [[ -n "$CONFIG_CC_IS_CLANG" ]]; then
MAKEVARS+=("HOSTCC=clang")
else
MAKEVARS+=("CC=${KPATCH_CC_PREFIX}${GCC}")

View File

@ -1,7 +1,7 @@
From 906b218903a32134dcc1a1fdda606e7b41aad616 Mon Sep 17 00:00:00 2001
From 4bef2105aea35f04e62a6a10de75f238917add63 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:26:25 +0800
Subject: [PATCH 23/37] livepatch-patch-hook: disable HAVE_SIMPLE_ENABLE to
Subject: [PATCH 23/38] livepatch-patch-hook: disable HAVE_SIMPLE_ENABLE to
keep register and unregister step of hotpatch
Signed-off-by: Bin Hu <hubin73@huawei.com>

View File

@ -1,7 +1,7 @@
From 4a0580c4179a3455dd3442a0de0ee9e3f4ce6896 Mon Sep 17 00:00:00 2001
From eb743123b846ab0749a2d7ce8e3de3ffff49d957 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:27:28 +0800
Subject: [PATCH 24/37] kpatch-build: add KBUILD_MODPOST_WARN=1 to avoid
Subject: [PATCH 24/38] kpatch-build: add KBUILD_MODPOST_WARN=1 to avoid
modpost undefined error
Signed-off-by: hubin <hubin73@huawei.com>
@ -10,10 +10,10 @@ Signed-off-by: hubin <hubin73@huawei.com>
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index daa9a81..a822708 100755
index a5e3688..19f8d3e 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -1011,9 +1011,9 @@ fi
@@ -1229,9 +1229,9 @@ fi
# $TARGETS used as list, no quotes.
# shellcheck disable=SC2086
if [[ -z "$USERMODBUILDDIR" ]]; then
@ -25,7 +25,7 @@ index daa9a81..a822708 100755
fi
# Save original module symvers
@@ -1158,9 +1158,9 @@ for i in $FILES; do
@@ -1376,9 +1376,9 @@ for i in $FILES; do
remove_patches
cd "$BUILDDIR" || die
if [ -z "$USERMODBUILDDIR" ];then
@ -37,7 +37,7 @@ index daa9a81..a822708 100755
fi
cp ${KOBJFILE} ${KOBJFILE_PATH}
apply_patches
@@ -1275,7 +1275,7 @@ KPATCH_LDFLAGS="$KPATCH_LDFLAGS" \
@@ -1494,7 +1494,7 @@ KPATCH_LDFLAGS="$KPATCH_LDFLAGS" \
CROSS_COMPILE="$CROSS_COMPILE"
save_env

View File

@ -1,7 +1,7 @@
From 85881a54bcb1bbc726d968de708f598c5e2b62c6 Mon Sep 17 00:00:00 2001
From b39116104f1148d2a806e8499e3f9bb6705f003c Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:28:00 +0800
Subject: [PATCH 26/37] create-diff-object: fix segment fault when using
Subject: [PATCH 25/38] create-diff-object: fix segment fault when using
KPATCH_FORCE_UNSAFE
Signed-off-by: hubin <hubin73@huawei.com>
@ -10,10 +10,10 @@ Signed-off-by: hubin <hubin73@huawei.com>
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 5e216d1..b27edd8 100644
index 5bed3e2..0597d14 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -1925,9 +1925,14 @@ static void kpatch_include_force_elements(struct kpatch_elf *kelf)
@@ -1983,9 +1983,14 @@ static void kpatch_include_force_elements(struct kpatch_elf *kelf)
continue;
}
/* .rela.kpatch.force */

View File

@ -1,29 +0,0 @@
From d59f96e9287c3af1090f8f19fdd0f76b2eeedeec Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:27:52 +0800
Subject: [PATCH 25/37] kpatch-build: update find_parent_obj to avoid error
that two parent match same object
Signed-off-by: hubin <hubin73@huawei.com>
---
kpatch-build/kpatch-build | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index a822708..5063dd7 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -476,8 +476,8 @@ find_parent_obj() {
[[ "$num" -eq 1 ]] && last_deep_find="$(dirname "$parent")"
fi
if [[ "$num" -eq 0 ]]; then
- parent="$(find $USERMODBUILDDIR -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | grep -Fv "$pdir/.${file}.cmd" | head -n1)"
- num="$(find $USERMODBUILDDIR -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | grep -Fvc "$pdir/.${file}.cmd")"
+ parent="$(find $USERMODBUILDDIR -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | filter_parent_obj "$pdir" "${file}" | head -n1)"
+ num="$(find $USERMODBUILDDIR -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | filter_parent_obj "$pdir" "${file}" | wc -l)"
[[ "$num" -eq 1 ]] && last_deep_find="$(dirname "$parent")"
fi
else
--
2.33.0

View File

@ -1,7 +1,7 @@
From 7be77c200280aaf4e788dfa9b24194e847ea46fc Mon Sep 17 00:00:00 2001
From 65855a7c36473a1191418fedbbb5aaa2da033494 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:28:17 +0800
Subject: [PATCH 27/37] kpatch-macros: replace __section with __kpatch_section
Subject: [PATCH 26/38] kpatch-macros: replace __section with __kpatch_section
in kpatch macro definition
Signed-off-by: hubin <hubin73@huawei.com>
@ -10,7 +10,7 @@ Signed-off-by: hubin <hubin73@huawei.com>
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kmod/patch/kpatch-macros.h b/kmod/patch/kpatch-macros.h
index 02d548e..f546822 100644
index 69fdbbb..49cb759 100644
--- a/kmod/patch/kpatch-macros.h
+++ b/kmod/patch/kpatch-macros.h
@@ -14,7 +14,7 @@

View File

@ -1,7 +1,7 @@
From 66681deab6874218eedc244138dbc464daf13011 Mon Sep 17 00:00:00 2001
From 6a078af6a032a7580de81da90303427969166525 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:28:26 +0800
Subject: [PATCH 28/37] create-diff-object: ignore changed of section
Subject: [PATCH 27/38] create-diff-object: ignore changed of section
__patchable_function_entries
Linux 5.10 aarch64 uses -fpatchable-function-entry=N to generate N NOPs at the
@ -17,10 +17,10 @@ Signed-off-by: hubin <hubin73@huawei.com>
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index b27edd8..666e44c 100644
index 0597d14..35c13b2 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -3103,7 +3103,8 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf,
@@ -3247,7 +3247,8 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf,
list_for_each_entry(sec, &kelf->sections, list) {
if (strcmp(sec->name, "__tracepoints") &&
strcmp(sec->name, "__tracepoints_ptrs") &&

View File

@ -1,7 +1,7 @@
From d0c418f1e53cbdd6e1672060cef5dccb253cf231 Mon Sep 17 00:00:00 2001
From d5a08f643e91d12b5cf10fba5568a79d77c1085f Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:28:34 +0800
Subject: [PATCH 29/37] create-diff-object: fix null pointer dereference in
Subject: [PATCH 28/38] create-diff-object: fix null pointer dereference in
kpatch_ignore_debug_section
Signed-off-by: hubin <hubin73@huawei.com>
@ -10,10 +10,10 @@ Signed-off-by: hubin <hubin73@huawei.com>
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 666e44c..0b8c46e 100644
index 35c13b2..17875a5 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -2831,7 +2831,7 @@ static void kpatch_ignore_debug_sections(struct kpatch_elf *kelf)
@@ -2967,7 +2967,7 @@ static void kpatch_ignore_debug_sections(struct kpatch_elf *kelf)
if (is_debug_section(sec)) {
sec->include = 0;
sec->status = SAME;

View File

@ -1,7 +1,7 @@
From f9413f0a3dbe3ae506c49d528d8cc5f23dc58a68 Mon Sep 17 00:00:00 2001
From b74c7da334d7cb0538c2287639c0f31a5e9279d5 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:28:46 +0800
Subject: [PATCH 30/37] create-diff-object: ignore .note.gnu.property section
Subject: [PATCH 29/38] create-diff-object: ignore .note.gnu.property section
Linux GABI introduced new .note.gnu.property section which contains a program
property note which describes special handling requirements for linker and run-time loader.
@ -18,10 +18,10 @@ Signed-off-by: hubin <hubin73@huawei.com>
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 0b8c46e..1abf3b8 100644
index 17875a5..24d89ac 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -3104,7 +3104,8 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf,
@@ -3248,7 +3248,8 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf,
if (strcmp(sec->name, "__tracepoints") &&
strcmp(sec->name, "__tracepoints_ptrs") &&
strcmp(sec->name, "__tracepoints_strings") &&

View File

@ -1,7 +1,7 @@
From 9126e10f4998e84f9056b83419f56689c5bcf879 Mon Sep 17 00:00:00 2001
From f548634879ad627346bf2005a983db81985cb599 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:28:55 +0800
Subject: [PATCH 31/37] create-diff-object: skip creating .kpatch.arch section
Subject: [PATCH 30/38] create-diff-object: skip creating .kpatch.arch section
for sections with empty secsym
Signed-off-by: hubin <hubin73@huawei.com>
@ -10,10 +10,10 @@ Signed-off-by: hubin <hubin73@huawei.com>
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 1abf3b8..ecc08e9 100644
index 24d89ac..ea287d8 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -2990,7 +2990,7 @@ static void kpatch_create_kpatch_arch_section(struct kpatch_elf *kelf, char *obj
@@ -3134,7 +3134,7 @@ static void kpatch_create_kpatch_arch_section(struct kpatch_elf *kelf, char *obj
continue;
sec = find_section_by_name(&kelf->sections, special->name);

View File

@ -1,7 +1,7 @@
From 3112275d447899a7063f5753d2cfed4003eecf9d Mon Sep 17 00:00:00 2001
From 54e45c6320d70149db6f026d14c0cc434bbdc4b7 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 16:12:29 +0800
Subject: [PATCH 32/37] kpatch-build: do not copy linux scripts when building
Subject: [PATCH 31/38] kpatch-build: do not copy linux scripts when building
OOT module hotpatch
Signed-off-by: hubin <hubin73@huawei.com>
@ -10,10 +10,10 @@ Signed-off-by: hubin <hubin73@huawei.com>
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index 5063dd7..827207f 100755
index 19f8d3e..5817023 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -932,7 +932,7 @@ fi
@@ -1151,7 +1151,7 @@ fi
# support extended ELF sections. Disable the BTF typeinfo generation in
# link-vmlinux.sh and Makefile.modfinal since kpatch doesn't care about
# that anyway.

View File

@ -1,7 +1,7 @@
From c7a3d873d6f0655765aee36c76b41c5e54286388 Mon Sep 17 00:00:00 2001
From 82bac1154777a909ac1a0ac4ee0f6cad4393def8 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Mon, 23 May 2022 17:00:37 +0800
Subject: [PATCH 33/37] create-diff-object: ignore change of certain special
Subject: [PATCH 32/38] create-diff-object: ignore change of certain special
sections
Signed-off-by: hubin <hubin73@huawei.com>
@ -10,10 +10,10 @@ Signed-off-by: hubin <hubin73@huawei.com>
1 file changed, 13 insertions(+)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index ecc08e9..8e73584 100644
index ea287d8..fe3f2c1 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -3117,6 +3117,19 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf,
@@ -3261,6 +3261,19 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf,
}
}

View File

@ -1,7 +1,7 @@
From e7781ead26083eebec1203ac81a797fd07c077c3 Mon Sep 17 00:00:00 2001
From 0ffe259e6d5782ffea27155cecdd10a9694fd534 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Mon, 23 May 2022 17:08:50 +0800
Subject: [PATCH 34/37] create-diff-object: allow __jump_table section change
Subject: [PATCH 33/38] create-diff-object: allow __jump_table section change
for module hotpatch
Signed-off-by: hubin <hubin73@huawei.com>
@ -10,16 +10,16 @@ Signed-off-by: hubin <hubin73@huawei.com>
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 8e73584..b0975f7 100644
index fe3f2c1..abea045 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -3554,7 +3554,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
@@ -3698,7 +3698,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
* special section init code (e.g., apply_paravirt)
* runs due to late module patching.
*/
- if (!KLP_ARCH && !vmlinux && special)
+ if (!KLP_ARCH && !vmlinux && special && strcmp(relasec->base->name, "__jump_table"))
ERROR("unsupported dynrela reference to symbol '%s' in module-specific special section '%s'",
ERROR("unsupported klp relocation reference to symbol '%s' in module-specific special section '%s'",
rela->sym->name, relasec->base->name);
--

View File

@ -1,7 +1,7 @@
From f4b25dccaac3540f8826ea637549349c0a156a40 Mon Sep 17 00:00:00 2001
From a6963e4745ccb8c3f00fb382f0f069839774c632 Mon Sep 17 00:00:00 2001
From: tangbin <tangbin@cmss.chinamobile.com>
Date: Mon, 5 Sep 2022 12:09:06 -0400
Subject: [PATCH 35/37] livepatch-patch-hook: fix kpatch-build error which do
Subject: [PATCH 34/38] livepatch-patch-hook: fix kpatch-build error which do
not support ftrace
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8

View File

@ -1,7 +1,7 @@
From cb75d02d8b8a773386ef3867457d600752a9ec4b Mon Sep 17 00:00:00 2001
From 62a94545d2cc442f431eb9e49dc8ca674ffa0e23 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Sun, 9 Oct 2022 10:34:52 +0800
Subject: [PATCH 36/37] lookup: skip finding local symbols for object with no
Subject: [PATCH 35/38] lookup: skip finding local symbols for object with no
local symbols
Signed-off-by: hubin <hubin73@huawei.com>
@ -10,11 +10,11 @@ Signed-off-by: hubin <hubin73@huawei.com>
1 file changed, 19 insertions(+)
diff --git a/kpatch-build/lookup.c b/kpatch-build/lookup.c
index d3b6ae9..4b1717a 100644
index 87f315a..34b3602 100644
--- a/kpatch-build/lookup.c
+++ b/kpatch-build/lookup.c
@@ -166,6 +166,22 @@ static bool locals_match(struct lookup_table *table, int idx,
return true;
@@ -186,6 +186,22 @@ static bool file_has_locals(struct symbol *file_sym, struct list_head *sym_list)
return false;
}
+static int count_local_symbol(struct list_head *sym_list)
@ -36,7 +36,7 @@ index d3b6ae9..4b1717a 100644
static void find_local_syms(struct lookup_table *table, struct symbol *file_sym,
struct list_head *sym_list)
{
@@ -173,6 +189,9 @@ static void find_local_syms(struct lookup_table *table, struct symbol *file_sym,
@@ -193,6 +209,9 @@ static void find_local_syms(struct lookup_table *table, struct symbol *file_sym,
struct object_symbol *lookup_table_file_sym = NULL;
int i;

View File

@ -1,7 +1,7 @@
From 4386311b1342c89a999ec2eb6828c9983ffacb65 Mon Sep 17 00:00:00 2001
From 43475f052a4b625f9527e05a6a1537c67e37d6b5 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Sun, 9 Oct 2022 14:33:13 +0800
Subject: [PATCH 37/37] create-diff-object: ignore entsize change of
Subject: [PATCH 36/38] create-diff-object: ignore entsize change of
.return_sites section
If a patch contains newly exported function, kernel Makefile.build
@ -17,10 +17,10 @@ Signed-off-by: hubin <hubin73@huawei.com>
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index b0975f7..49ada5f 100644
index abea045..0df6cd2 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -569,7 +569,8 @@ static void kpatch_compare_correlated_section(struct section *sec)
@@ -613,7 +613,8 @@ static void kpatch_compare_correlated_section(struct section *sec)
/* Compare section headers (must match or fatal) */
if (sec1->sh.sh_type != sec2->sh.sh_type ||
sec1->sh.sh_flags != sec2->sh.sh_flags ||

View File

@ -1,7 +1,7 @@
From c6b399359956bf798f685f5b3aaf47fcf02de523 Mon Sep 17 00:00:00 2001
From 154b990912bed67bbaeedec1d53fd0881900da85 Mon Sep 17 00:00:00 2001
From: laokz <zhangkai@iscas.ac.cn>
Date: Fri, 20 Oct 2023 20:53:32 +0800
Subject: [PATCH] add initial riscv64 support
Subject: [PATCH 37/38] add initial riscv64 support
Per the RISC-V psABI, PCREL_HI20 and PCREL_LO12 must
sit in the same section. PCREL_HI20 may be a global
@ -36,10 +36,10 @@ index 5037677..f24165b 100644
endif
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 0e91513..cca2781 100644
index 0df6cd2..0d1efcf 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -177,6 +177,7 @@ static bool is_gcc6_localentry_bundled_sym(struct kpatch_elf *kelf,
@@ -182,6 +182,7 @@ static bool is_gcc6_localentry_bundled_sym(struct kpatch_elf *kelf,
case S390:
return false;
case ARM64:
@ -47,7 +47,7 @@ index 0e91513..cca2781 100644
return false;
default:
ERROR("unsupported arch");
@@ -444,6 +445,18 @@ static int kpatch_mangled_strcmp(char *s1, char *s2)
@@ -456,6 +457,18 @@ static int kpatch_mangled_strcmp(char *s1, char *s2)
if (!strncmp(s1, "__UNIQUE_ID_", 12))
return __kpatch_unique_id_strcmp(s1, s2);
@ -66,7 +66,7 @@ index 0e91513..cca2781 100644
while (*s1 == *s2) {
if (!*s1)
return 0;
@@ -703,6 +716,10 @@ static bool insn_is_load_immediate(struct kpatch_elf *kelf, void *addr)
@@ -715,6 +728,10 @@ static bool insn_is_load_immediate(struct kpatch_elf *kelf, void *addr)
break;
@ -77,7 +77,7 @@ index 0e91513..cca2781 100644
default:
ERROR("unsupported arch");
}
@@ -970,6 +987,10 @@ static void kpatch_compare_symbols(struct list_head *symlist)
@@ -982,6 +999,10 @@ static void kpatch_compare_symbols(struct list_head *symlist)
if (sym->twin)
kpatch_compare_correlated_symbol(sym);
else
@ -88,7 +88,7 @@ index 0e91513..cca2781 100644
sym->status = NEW;
log_debug("symbol %s is %s\n", sym->name, status_str(sym->status));
@@ -1112,6 +1133,11 @@ static void kpatch_correlate_symbols(struct list_head *symlist_orig,
@@ -1127,6 +1148,11 @@ static void kpatch_correlate_symbols(struct list_head *symlist_orig,
list_for_each_entry(sym_orig, symlist_orig, list) {
if (sym_orig->twin)
continue;
@ -100,7 +100,7 @@ index 0e91513..cca2781 100644
list_for_each_entry(sym_patched, symlist_patched, list) {
if (kpatch_mangled_strcmp(sym_orig->name, sym_patched->name) ||
sym_orig->type != sym_patched->type || sym_patched->twin)
@@ -2327,7 +2353,7 @@ static int fixup_group_size(struct kpatch_elf *kelf, int offset)
@@ -2528,7 +2554,7 @@ static bool static_call_sites_group_filter(struct lookup_table *lookup,
static struct special_section special_sections[] = {
{
.name = "__bug_table",
@ -109,7 +109,7 @@ index 0e91513..cca2781 100644
.group_size = bug_table_group_size,
},
{
@@ -2337,17 +2363,17 @@ static struct special_section special_sections[] = {
@@ -2538,18 +2564,18 @@ static struct special_section special_sections[] = {
},
{
.name = "__ex_table", /* must come after .fixup */
@ -122,6 +122,7 @@ index 0e91513..cca2781 100644
- .arch = X86_64 | PPC64 | S390 | ARM64,
+ .arch = X86_64 | PPC64 | S390 | ARM64 | RISCV64,
.group_size = jump_table_group_size,
.group_filter = jump_table_group_filter,
},
{
.name = ".printk_index",
@ -130,7 +131,7 @@ index 0e91513..cca2781 100644
.group_size = printk_index_group_size,
},
{
@@ -2916,6 +2942,10 @@ static void kpatch_mark_ignored_sections(struct kpatch_elf *kelf)
@@ -3020,6 +3046,10 @@ static void kpatch_mark_ignored_sections(struct kpatch_elf *kelf)
strsec->secsym->include = 1;
name = strsec->data->d_buf + rela->addend;
@ -141,7 +142,7 @@ index 0e91513..cca2781 100644
ignoresec = find_section_by_name(&kelf->sections, name);
if (!ignoresec)
ERROR("KPATCH_IGNORE_SECTION: can't find %s", name);
@@ -3812,6 +3842,7 @@ static void kpatch_create_mcount_sections(struct kpatch_elf *kelf)
@@ -3916,6 +3946,7 @@ static void kpatch_create_mcount_sections(struct kpatch_elf *kelf)
switch(kelf->arch) {
case PPC64:
@ -149,7 +150,7 @@ index 0e91513..cca2781 100644
case ARM64: {
bool found = false;
@@ -4048,6 +4079,7 @@ static void kpatch_find_func_profiling_calls(struct kpatch_elf *kelf)
@@ -4159,6 +4190,7 @@ static void kpatch_find_func_profiling_calls(struct kpatch_elf *kelf)
switch(kelf->arch) {
case PPC64:
@ -158,7 +159,7 @@ index 0e91513..cca2781 100644
list_for_each_entry(rela, &sym->sec->rela->relas, list) {
if (!strcmp(rela->sym->name, "_mcount")) {
diff --git a/kpatch-build/create-klp-module.c b/kpatch-build/create-klp-module.c
index b77028f..dbf4ad4 100644
index 89d37c8..2f41690 100644
--- a/kpatch-build/create-klp-module.c
+++ b/kpatch-build/create-klp-module.c
@@ -162,6 +162,43 @@ static struct section *find_or_add_klp_relasec(struct kpatch_elf *kelf,
@ -217,7 +218,7 @@ index b77028f..dbf4ad4 100644
}
diff --git a/kpatch-build/kpatch-elf.c b/kpatch-build/kpatch-elf.c
index 572f272..40ea6a8 100644
index b639bc2..d6398b3 100644
--- a/kpatch-build/kpatch-elf.c
+++ b/kpatch-build/kpatch-elf.c
@@ -144,6 +144,8 @@ unsigned int absolute_rela_type(struct kpatch_elf *kelf)
@ -249,7 +250,7 @@ index 572f272..40ea6a8 100644
default:
ERROR("unsupported arch");
}
@@ -508,6 +516,9 @@ struct kpatch_elf *kpatch_elf_open(const char *name)
@@ -600,6 +608,9 @@ struct kpatch_elf *kpatch_elf_open(const char *name)
case EM_AARCH64:
kelf->arch = ARM64;
break;
@ -259,7 +260,7 @@ index 572f272..40ea6a8 100644
default:
ERROR("Unsupported target architecture");
}
@@ -902,6 +913,17 @@ void kpatch_rebuild_rela_section_data(struct section *sec)
@@ -1006,6 +1017,17 @@ void kpatch_rebuild_rela_section_data(struct section *sec)
size_t size;
list_for_each_entry(rela, &sec->relas, list)
@ -277,7 +278,7 @@ index 572f272..40ea6a8 100644
nr++;
size = nr * sizeof(*relas);
@@ -916,6 +938,10 @@ void kpatch_rebuild_rela_section_data(struct section *sec)
@@ -1020,6 +1042,10 @@ void kpatch_rebuild_rela_section_data(struct section *sec)
sec->sh.sh_size = size;
list_for_each_entry(rela, &sec->relas, list) {
@ -289,10 +290,10 @@ index 572f272..40ea6a8 100644
relas[index].r_addend = rela->addend;
relas[index].r_info = GELF_R_INFO(rela->sym->index, rela->type);
diff --git a/kpatch-build/kpatch-elf.h b/kpatch-build/kpatch-elf.h
index d887812..6624b2d 100644
index 47e3117..f2cf60a 100644
--- a/kpatch-build/kpatch-elf.h
+++ b/kpatch-build/kpatch-elf.h
@@ -114,6 +114,7 @@ enum architecture {
@@ -116,6 +116,7 @@ enum architecture {
X86_64 = 0x1 << 1,
S390 = 0x1 << 2,
ARM64 = 0x1 << 3,
@ -301,5 +302,5 @@ index d887812..6624b2d 100644
struct kpatch_elf {
--
2.42.0
2.33.0

View File

@ -1,7 +1,8 @@
From fb22714ae934a6a9b8ab0cc635519fb3a24c2052 Mon Sep 17 00:00:00 2001
From 2173df77292171f45a6c314af4c7bb73587cad4c Mon Sep 17 00:00:00 2001
From: Weinan Liu <wnliu@google.com>
Date: Wed, 9 Aug 2023 22:31:21 +0000
Subject: [PATCH] Fix undefined behavior problem when using list_foreach_entry
Subject: [PATCH 38/38] Fix undefined behavior problem when using
list_foreach_entry
This upstream list.h offsetof implementation rely on undefined behavior implementation. Using __builtin_offsetof to fix this problem.
---
@ -22,5 +23,5 @@ index e95593c..ad4643c 100644
/**
* Casts a member of a structure out to the containing structure
--
2.27.0
2.33.0

View File

@ -1,99 +0,0 @@
From 5f6c5965f117cb9b2b21749da49b22b23305d114 Mon Sep 17 00:00:00 2001
From: Pete Swain <swine@google.com>
Date: Tue, 27 Sep 2022 15:56:06 -0400
Subject: [PATCH 1/3] kpatch-build: for clang, use .strtab if no .shstrtab
While gcc puts strings in .strtab and .shstrtab sections,
llvm toolchain just uses .strtab.
Adapt kpatch to handle both styles.
Signed-off-by: Pete Swain <swine@google.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> [small changes]
---
kpatch-build/kpatch-elf.c | 33 +++++++++++++++++++++++++++++----
1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/kpatch-build/kpatch-elf.c b/kpatch-build/kpatch-elf.c
index 58dbe1a..c7d12ec 100644
--- a/kpatch-build/kpatch-elf.c
+++ b/kpatch-build/kpatch-elf.c
@@ -607,7 +607,7 @@ void kpatch_create_shstrtab(struct kpatch_elf *kelf)
shstrtab = find_section_by_name(&kelf->sections, ".shstrtab");
if (!shstrtab)
- ERROR("find_section_by_name");
+ return;
/* determine size of string table */
size = 1; /* for initial NULL terminator */
@@ -648,7 +648,7 @@ void kpatch_create_shstrtab(struct kpatch_elf *kelf)
void kpatch_create_strtab(struct kpatch_elf *kelf)
{
- struct section *strtab;
+ struct section *strtab, *shstrtab;
struct symbol *sym;
size_t size = 0, offset = 0, len;
char *buf;
@@ -657,6 +657,8 @@ void kpatch_create_strtab(struct kpatch_elf *kelf)
if (!strtab)
ERROR("find_section_by_name");
+ shstrtab = find_section_by_name(&kelf->sections, ".shstrtab");
+
/* determine size of string table */
list_for_each_entry(sym, &kelf->symbols, list) {
if (sym->type == STT_SECTION)
@@ -664,6 +666,15 @@ void kpatch_create_strtab(struct kpatch_elf *kelf)
size += strlen(sym->name) + 1; /* include NULL terminator */
}
+ /* and when covering for missing .shstrtab ... */
+ if (!shstrtab) {
+ /* factor out into common (sh)strtab feeder */
+ struct section *sec;
+
+ list_for_each_entry(sec, &kelf->sections, list)
+ size += strlen(sec->name) + 1; /* include NULL terminator */
+ }
+
/* allocate data buffer */
buf = malloc(size);
if (!buf)
@@ -682,8 +693,20 @@ void kpatch_create_strtab(struct kpatch_elf *kelf)
offset += len;
}
+ if (!shstrtab) {
+ struct section *sec;
+
+ /* populate string table and link with section header */
+ list_for_each_entry(sec, &kelf->sections, list) {
+ len = strlen(sec->name) + 1;
+ sec->sh.sh_name = (unsigned int)offset;
+ memcpy(buf + offset, sec->name, len);
+ offset += len;
+ }
+ }
+
if (offset != size)
- ERROR("shstrtab size mismatch");
+ ERROR("strtab size mismatch");
strtab->data->d_buf = buf;
strtab->data->d_size = size;
@@ -928,7 +951,9 @@ void kpatch_write_output_elf(struct kpatch_elf *kelf, Elf *elf, char *outfile,
shstrtab = find_section_by_name(&kelf->sections, ".shstrtab");
if (!shstrtab)
- ERROR("missing .shstrtab section");
+ shstrtab = find_section_by_name(&kelf->sections, ".strtab");
+ if (!shstrtab)
+ ERROR("missing .shstrtab, .strtab sections");
ehout.e_shstrndx = (unsigned short)shstrtab->index;
--
2.27.0

View File

@ -1,28 +0,0 @@
From 37040572440efb95db9a3193d3b51d7597e1badd Mon Sep 17 00:00:00 2001
From: Pete Swain <swine@google.com>
Date: Tue, 27 Sep 2022 15:56:06 -0400
Subject: [PATCH 2/3] create-diff-object: ignore clang's .llvm_addrsig sections
Signed-off-by: Pete Swain <swine@google.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> [subject line]
---
kpatch-build/create-diff-object.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 918d21c..fa7e07f 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -2717,7 +2717,8 @@ static void kpatch_mark_ignored_sections(struct kpatch_elf *kelf)
/* Ignore any discarded sections */
list_for_each_entry(sec, &kelf->sections, list) {
if (!strncmp(sec->name, ".discard", 8) ||
- !strncmp(sec->name, ".rela.discard", 13))
+ !strncmp(sec->name, ".rela.discard", 13) ||
+ !strncmp(sec->name, ".llvm_addrsig", 13))
sec->ignore = 1;
}
--
2.27.0

View File

@ -1,32 +0,0 @@
From 85781b7ea79fb4122efbb51f0bf573ed5fab03e1 Mon Sep 17 00:00:00 2001
From: Pete Swain <swine@google.com>
Date: Tue, 27 Sep 2022 15:56:06 -0400
Subject: [PATCH 3/3] create-diff-object: ignore .llvm.* sections
Clang FDO adds a new, ignorable ELF section, .llvm.call-graph-profile
Generalize to ignore all .llvm.*
Signed-off-by: Pete Swain <swine@google.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> [subject line]
---
kpatch-build/create-diff-object.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index fa7e07f..cdcc13b 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -2718,7 +2718,8 @@ static void kpatch_mark_ignored_sections(struct kpatch_elf *kelf)
list_for_each_entry(sec, &kelf->sections, list) {
if (!strncmp(sec->name, ".discard", 8) ||
!strncmp(sec->name, ".rela.discard", 13) ||
- !strncmp(sec->name, ".llvm_addrsig", 13))
+ !strncmp(sec->name, ".llvm_addrsig", 13) ||
+ !strncmp(sec->name, ".llvm.", 6))
sec->ignore = 1;
}
--
2.27.0

View File

@ -1,51 +0,0 @@
From 846ea81bd9fd673ccbcb64c9e2732422fbd02798 Mon Sep 17 00:00:00 2001
From: Josh Poimboeuf <jpoimboe@redhat.com>
Date: Wed, 17 Aug 2022 12:10:39 -0700
Subject: [PATCH 1/3] kpatch-cc: Add more file ignores
These files aren't in the kernel proper, and can be ignored.
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
kpatch-build/kpatch-cc | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/kpatch-build/kpatch-cc b/kpatch-build/kpatch-cc
index 5e241dd..b9c511a 100755
--- a/kpatch-build/kpatch-cc
+++ b/kpatch-build/kpatch-cc
@@ -35,22 +35,22 @@ if [[ "$TOOLCHAINCMD" =~ ^(.*-)?gcc$ ||
vmlinux.o|\
.tmp_kallsyms1.o|\
.tmp_kallsyms2.o|\
- init/version.o|\
- arch/x86/boot/version.o|\
- arch/x86/boot/compressed/eboot.o|\
- arch/x86/boot/header.o|\
- arch/x86/boot/compressed/efi_stub_64.o|\
- arch/x86/boot/compressed/piggy.o|\
- kernel/system_certificates.o|\
- arch/x86/vdso/*|\
+ arch/x86/boot/*|\
arch/x86/entry/vdso/*|\
- drivers/firmware/efi/libstub/*|\
+ arch/x86/purgatory/*|\
+ arch/x86/realmode/*|\
+ arch/x86/tools/*|\
+ arch/x86/vdso/*|\
arch/powerpc/kernel/prom_init.o|\
arch/powerpc/kernel/vdso64/*|\
arch/s390/boot/*|\
arch/s390/purgatory/*|\
arch/s390/kernel/vdso64/*|\
+ drivers/firmware/efi/libstub/*|\
+ init/version.o|\
+ kernel/system_certificates.o|\
lib/*|\
+ tools/*|\
.*.o|\
*/.lib_exports.o)
break
--
2.27.0

View File

@ -1,69 +0,0 @@
From 000f03dbeefddbf6c9f9336d4e043809eae6a7a2 Mon Sep 17 00:00:00 2001
From: Josh Poimboeuf <jpoimboe@redhat.com>
Date: Mon, 21 Nov 2022 19:32:18 -0800
Subject: [PATCH 2/3] create-diff-object: fix __UNIQUE_ID() variable
correlation
kpatch_mangled_strcmp() only ignores the digits after the period, but in
the case of __UNIQUE_ID(), the symbol names have random digits before
the period due to the use of `__COUNTER__`. Make sure such symbols are
properly correlated.
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
kpatch-build/create-diff-object.c | 32 +++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 5d34717..8a671bd 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -399,6 +399,35 @@ static bool has_digit_tail(char *tail)
return false;
}
+/*
+ * Hack for __UNIQUE_ID(). The following should match:
+ *
+ * __UNIQUE_ID_ddebug1131.186
+ * __UNIQUE_ID_ddebug1132.187
+ */
+static int __kpatch_unique_id_strcmp(char *s1, char *s2)
+{
+ /* match '__UNIQUE_ID_ddebug' */
+ while (*s1 == *s2) {
+ if (!*s1)
+ return 0;
+ s1++;
+ s2++;
+ }
+
+ /* skip digits before '.' or EOL */
+ while (isdigit(*s1))
+ s1++;
+ while (isdigit(*s2))
+ s2++;
+
+ if ((!*s1 || has_digit_tail(s1)) &&
+ (!*s2 || has_digit_tail(s2)))
+ return 0;
+
+ return 1;
+}
+
/*
* This is like strcmp, but for gcc-mangled symbols. It skips the comparison
* of any substring which consists of '.' followed by any number of digits.
@@ -412,6 +441,9 @@ static int kpatch_mangled_strcmp(char *s1, char *s2)
if (strstr(s1, ".str1."))
return strcmp(s1, s2);
+ if (!strncmp(s1, "__UNIQUE_ID_", 12))
+ return __kpatch_unique_id_strcmp(s1, s2);
+
while (*s1 == *s2) {
if (!*s1)
return 0;
--
2.27.0

View File

@ -1,40 +0,0 @@
From b232188e0c220f779ce54955876b56a4161c258a Mon Sep 17 00:00:00 2001
From: Joe Lawrence <joe.lawrence@redhat.com>
Date: Fri, 10 Feb 2023 13:38:05 -0500
Subject: [PATCH 3/3] create-diff-object: ignore __patchable_function_entries
Kernel v6.2+ commit bea75b33895f ("x86/Kconfig: Introduce function
padding") introduces the -fpatchable-function-entry=16,16 build flag on
x86. This leverages compiler support for generating a
__patchable_function_entries section similar to __mcount_loc.
That said, x86 still utilizes __mcount_loc even when
__patchable_function_entries exists. The latter point to the __pfx
symbols, but the section is discarded in the vmlinux link and isn't used
regardless, for ftrace or for any other purpose.
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
---
kpatch-build/create-diff-object.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 8a671bd..0e91513 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -2885,6 +2885,12 @@ static void kpatch_mark_ignored_sections(struct kpatch_elf *kelf)
!strncmp(sec->name, ".llvm_addrsig", 13) ||
!strncmp(sec->name, ".llvm.", 6))
sec->ignore = 1;
+
+ if (kelf->arch == X86_64) {
+ if (!strcmp(sec->name, ".rela__patchable_function_entries") ||
+ !strcmp(sec->name, "__patchable_function_entries"))
+ sec->ignore = 1;
+ }
}
sec = find_section_by_name(&kelf->sections, ".kpatch.ignore.sections");
--
2.27.0

View File

@ -1,49 +0,0 @@
From 13182e50b027c70bd63f53ca43598557d6b41e2e Mon Sep 17 00:00:00 2001
From: Joe Lawrence <joe.lawrence@redhat.com>
Date: Tue, 27 Sep 2022 16:41:48 -0400
Subject: [PATCH] gcc-plugin: update headers for gcc-12
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Fix build error seen on gcc (GCC) 12.1.1 20220507 (Red Hat 12.1.1-1):
g++ -MMD -MP -I../kmod/patch -Iinsn -Wall -Wsign-compare -Wno-sign-conversion -g -Werror -shared -I/usr/lib/gcc/ppc64le-redhat-linux/12/plugin/include -Igcc-plugins -fPIC -fno-rtti -O2 -Wall gcc-plugins/ppc64le-plugin.c -o gcc-plugins/ppc64le-plugin.so
In file included from /usr/include/features.h:490,
from /usr/include/bits/libc-header-start.h:33,
from /usr/include/stdio.h:27,
from /usr/lib/gcc/ppc64le-redhat-linux/12/plugin/include/system.h:46,
from /usr/lib/gcc/ppc64le-redhat-linux/12/plugin/include/gcc-plugin.h:28,
from gcc-plugins/gcc-common.h:6,
from gcc-plugins/ppc64le-plugin.c:1:
/usr/include/bits/error-ldbl.h:23:1: error: type of error is unknown
23 | __LDBL_REDIR_DECL (error)
| ^~~~~~~~~~~~~~~~~
/usr/include/bits/error-ldbl.h:23:1: error: int error redeclared as different kind of entity
23 | __LDBL_REDIR_DECL (error)
| ^~~~~~~~~~~~~~~~~
In file included from gcc-plugins/ppc64le-plugin.c:2:
/usr/include/error.h:31:13: note: previous declaration void error(int, int, const char*, ...)
31 | extern void error (int __status, int __errnum, const char *__format, ...)
| ^~~~~
make[1]: *** [Makefile:39: gcc-plugins/ppc64le-plugin.so] Error 1
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
---
kpatch-build/gcc-plugins/ppc64le-plugin.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kpatch-build/gcc-plugins/ppc64le-plugin.c b/kpatch-build/gcc-plugins/ppc64le-plugin.c
index e3ec20f..ba4a01e 100644
--- a/kpatch-build/gcc-plugins/ppc64le-plugin.c
+++ b/kpatch-build/gcc-plugins/ppc64le-plugin.c
@@ -1,5 +1,5 @@
-#include "gcc-common.h"
#include <error.h>
+#include "gcc-common.h"
#define PLUGIN_NAME "ppc64le-plugin"
--
2.27.0

View File

@ -1,59 +0,0 @@
From 7861240f482aa41bfad41fbb57ac1990cd6b6960 Mon Sep 17 00:00:00 2001
From: Josh Poimboeuf <jpoimboe@redhat.com>
Date: Wed, 17 Aug 2022 12:17:19 -0700
Subject: [PATCH] kpatch-build: Add find_kobj() short-circuit for OOT modules
When patching an OOT module, the parent object is always the OOT module.
Hard-code that to prevent the need for any further special casing in
find_kobj() (e.g., commit 9143e88f16a1 ("kpatch-build: fix
find_parent_obj")).
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
kpatch-build/kpatch-build | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index 296fa48..5435a19 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -479,6 +479,12 @@ find_parent_obj() {
find_kobj() {
arg="$1"
+
+ if [[ -n $OOT_MODULE ]]; then
+ KOBJFILE="$OOT_MODULE"
+ return
+ fi
+
KOBJFILE="$arg"
DEEP_FIND=0
ERROR_IF_DIFF=
@@ -1093,17 +1099,17 @@ for i in $FILES; do
find_kobj "$i"
cd "$TEMPDIR" || die
if [[ -e "orig/$i" ]]; then
- if [[ "$(basename "$KOBJFILE")" = vmlinux ]]; then
- KOBJFILE_NAME=vmlinux
- KOBJFILE_PATH="$VMLINUX"
- SYMTAB="${TEMPDIR}/${KOBJFILE_NAME}.symtab"
- SYMVERS_FILE="$BUILDDIR/Module.symvers"
- elif [[ "$(basename "$KOBJFILE")" = "$(basename "$OOT_MODULE")" ]]; then
+ if [[ -n $OOT_MODULE ]]; then
KOBJFILE_NAME="$(basename --suffix=.ko "$OOT_MODULE")"
KOBJFILE_NAME="${KOBJFILE_NAME//-/_}"
KOBJFILE_PATH="$OOT_MODULE"
SYMTAB="${TEMPDIR}/module/${KOBJFILE_NAME}.symtab"
SYMVERS_FILE="$TEMPDIR/Module.symvers"
+ elif [[ "$(basename "$KOBJFILE")" = vmlinux ]]; then
+ KOBJFILE_NAME=vmlinux
+ KOBJFILE_PATH="$VMLINUX"
+ SYMTAB="${TEMPDIR}/${KOBJFILE_NAME}.symtab"
+ SYMVERS_FILE="$BUILDDIR/Module.symvers"
else
KOBJFILE_NAME=$(basename "${KOBJFILE%.ko}")
KOBJFILE_NAME="${KOBJFILE_NAME//-/_}"
--
2.27.0

View File

@ -1,53 +0,0 @@
From 2feeb0f462875906ee2e754bb1526511393faee2 Mon Sep 17 00:00:00 2001
From: Joe Lawrence <joe.lawrence@redhat.com>
Date: Mon, 7 Nov 2022 11:02:00 -0500
Subject: [PATCH] examples: add /proc/version kpatch sample
Create a simple kpatch test that should apply across a wide range of
kernels. The version_proc_show() is a good candidate as it's easy to
verify and hasn't been touched upstream since 2008.
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
---
examples/proc-version.patch | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
create mode 100644 examples/proc-version.patch
diff --git a/examples/proc-version.patch b/examples/proc-version.patch
new file mode 100644
index 0000000..cb43236
--- /dev/null
+++ b/examples/proc-version.patch
@@ -0,0 +1,29 @@
+From 64aff1ab8f9a9f5df06c998be73d4981b77e480d Mon Sep 17 00:00:00 2001
+From: Joe Lawrence <joe.lawrence@redhat.com>
+Date: Mon, 7 Nov 2022 08:21:58 -0500
+Subject: [PATCH] kpatch: modify /proc/version output
+Content-type: text/plain
+
+This is a simple kpatch example that modifies version_proc_show() so
+that the output of /proc/version will be prefixed by "kpatch ".
+
+Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
+---
+ fs/proc/version.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/fs/proc/version.c b/fs/proc/version.c
+index 02e3c3cd4a9a..957faeea8f5c 100644
+--- a/fs/proc/version.c
++++ b/fs/proc/version.c
+@@ -9,6 +9,7 @@
+
+ static int version_proc_show(struct seq_file *m, void *v)
+ {
++ seq_printf(m, "kpatch ");
+ seq_printf(m, linux_proc_banner,
+ utsname()->sysname,
+ utsname()->release,
+--
+2.26.3
+
--
2.27.0

View File

@ -1,33 +0,0 @@
From ab2397c03e31f0f697aa8bf943d70b4e5a7def54 Mon Sep 17 00:00:00 2001
From: Josh Poimboeuf <jpoimboe@redhat.com>
Date: Mon, 21 Nov 2022 19:41:30 -0800
Subject: [PATCH] kpatch-macros: add KPATCH_STATIC_CALL()
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
kmod/patch/kpatch-macros.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/kmod/patch/kpatch-macros.h b/kmod/patch/kpatch-macros.h
index 8e09702..b797838 100644
--- a/kmod/patch/kpatch-macros.h
+++ b/kmod/patch/kpatch-macros.h
@@ -141,4 +141,15 @@ struct kpatch_post_unpatch_callback {
printk(_fmt, ## __VA_ARGS__); \
})
+/*
+ * KPATCH_STATIC_CALL macro
+ *
+ * Replace usages of static_call() with this macro, when create-diff-object
+ * recommends it due to the original static call key living in a module.
+ *
+ * This converts the static call to a regular indirect call.
+ */
+#define KPATCH_STATIC_CALL(name) \
+ ((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func))
+
#endif /* __KPATCH_MACROS_H_ */
--
2.27.0

View File

@ -1,140 +0,0 @@
From 41128c0987ea569dd623d2de70391c5be739d38e Mon Sep 17 00:00:00 2001
From: Josh Poimboeuf <jpoimboe@redhat.com>
Date: Wed, 30 Nov 2022 18:48:34 -0800
Subject: [PATCH] patch-author-guide: update jump label / static call
descriptions
Now that we have KPATCH_STATIC_CALL(), document its usage. While at it,
give a more thorough description for why jump labels and static calls
aren't supported in some scenarios.
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
doc/patch-author-guide.md | 96 +++++++++++++++++++++++++++------------
1 file changed, 68 insertions(+), 28 deletions(-)
diff --git a/doc/patch-author-guide.md b/doc/patch-author-guide.md
index 0133cec..26daee3 100644
--- a/doc/patch-author-guide.md
+++ b/doc/patch-author-guide.md
@@ -24,7 +24,7 @@ Table of contents
- [Code removal](#code-removal)
- [Once macros](#once-macros)
- [inline implies notrace](#inline-implies-notrace)
-- [Jump labels](#jump-labels)
+- [Jump labels and static calls](#jump-labels-and-static-calls)
- [Sibling calls](#sibling-calls)
- [Exported symbol versioning](#exported-symbol-versioning)
- [System calls](#system-calls)
@@ -747,41 +747,81 @@ changes to all of `__tcp_mtu_to_mss()` callers (ie, it was inlined as
requested). In this case, a simple workaround is to specify
`__tcp_mtu_to_mss()` as `__always_inline` to force the compiler to do so.
-Jump labels
------------
+Jump labels and static calls
+----------------------------
+
+### Late module patching vs special section relocations
+
+Jump labels and static calls can be problematic due to "late module patching",
+which is a feature (design flaw?) in upstream livepatch. When a livepatch
+module patches another module, unfortunately the livepatch module doesn't have
+an official module dependency on the patched module. That means the patched
+module doesn't even have to be loaded when the livepatch module gets loaded.
+In that case the patched module gets patched on demand whenever it might get
+loaded in the future. It also gets unpatched on demand whenever it gets
+unloaded.
+
+Loading (and patching) the module at some point after loading the livepatch
+module is called "late module patching". In order to support this
+(mis?)feature, all relocations in the livepatch module which reference module
+symbols must be converted to "klp relocations", which get resolved at patching
+time.
+
+In all modules (livepatch and otherwise), jump labels and static calls rely on
+special sections which trigger jump-label/static-call code patching when a
+module gets loaded. But unfortunately those special sections have relocations
+which need to get resolved, so there's an ordering issue.
+
+When a (livepatch) module gets loaded, first its relocations are resolved, then
+its special section handling (and code patching) is done. The problem is, for
+klp relocations, if they reference another module's symbols, and that module
+isn't loaded, they're not yet defined. So if a `.static_call_sites` entry
+tries to reference its corresponding `struct static_call_key`, but that key
+lives in another module which is not yet loaded, the key reference won't be
+resolved, and so `mod->static_call_sites` will be corrupted when
+`static_call_module_notify()` runs when the livepatch module first loads.
+
+### Jump labels
+
+With pre-5.8 kernels, kpatch-build will error out if it encounters any jump
+labels:
+```
+oom_kill.o: Found a jump label at out_of_memory()+0x10a, using key cpusets_enabled_key. Jump labels aren't supported with this kernel. Use static_key_enabled() instead.
+```
-When modifying a function that contains a jump label, kpatch-build may
-return an error like: `ERROR: oom_kill.o: kpatch_regenerate_special_section: 2109: Found a jump label at out_of_memory()+0x10a, using key cpusets_enabled_key. Jump labels aren't currently supported. Use static_key_enabled() instead.`
+With Linux 5.8+, klp relocation handling is integrated with the module relocation
+code, so jump labels in patched functions are supported when the static key was
+originally defined in the kernel proper (vmlinux).
-This is due to a limitation in the kernel to process static key
-livepatch relocations (resolved by late-module patching). Older
-versions of kpatch-build may have reported successfully building
-kpatch module, but issue
-[#931](https://github.com/dynup/kpatch/issues/931) revealed potentially
-dangerous behavior if the static key value had been modified from its
-compiled default.
+However, if the static key lives in a module, jump labels are _not_ supported
+in patched code, due to the ordering issue described above. If the jump label
+is a tracepoint, kpatch-build will silently remove the tracepoint. Otherwise,
+there will be an error:
+```
+vmx.o: Found a jump label at vmx_hardware_enable.cold()+0x23, using key enable_evmcs, which is defined in a module. Use static_key_enabled() instead.
+```
-The current workaround is to remove the jump label by explictly checking
-the static key:
+When you get one of the above errors, the fix is to remove the jump label usage
+in the patched function, replacing it with a regular C conditional.
-```c
-DEFINE_STATIC_KEY_TRUE(true_key);
-DEFINE_STATIC_KEY_FALSE(false_key);
+This can be done by replacing any usages of `static_branch_likely()`,
+`static_branch_unlikely()`, `static_key_true()`, and `static_key_false()` with
+`static_key_enabled()` in the patch file.
-/* unsupported */
-if (static_key_true(&true_key))
-if (static_key_false(&false_key))
-if (static_branch_likely(&key))
+### Static calls
-/* supported */
-if (static_key_enabled(&true_key))
-if (static_key_enabled(&false_key))
-if (likely(static_key_enabled(&key)))
+Similarly, static calls are not supported when the corresponding static call
+key was originally defined in a module. If such a static call is part of a
+tracepoint, kpatch-build will silently remove it. Otherwise, there will be an
+error:
+```
+cpuid.o: Found a static call at kvm_set_cpuid.cold()+0x32c, using key __SCK__kvm_x86_vcpu_after_set_cpuid, which is defined in a module. Use KPATCH_STATIC_CALL() instead.
```
-Note that with Linux 5.8+, jump labels in patched functions are now supported
-when the static key was originally defined in the kernel proper (vmlinux). The
-above error will not be seen unless the static key lives in a module.
+To fix this error, simply replace such static calls with regular indirect
+branches (or retpolines, if applicable) by adding `#include "kpatch-macros.h"`
+to the patch source and replacing usages of `static_call()` with
+`KPATCH_STATIC_CALL()`.
Sibling calls
-------------
--
2.27.0

View File

@ -1,32 +0,0 @@
From 934b3b3c0c12be2435f8edbe484c2696dda93864 Mon Sep 17 00:00:00 2001
From: Joe Lawrence <joe.lawrence@redhat.com>
Date: Mon, 16 Jan 2023 09:33:55 -0500
Subject: [PATCH] kpatch-build: ignore init/version-timestamp.o
Kernel v6.1+ commit 2df8220cc511 ("kbuild: build init/built-in.a just
once") split init_uts_ns and linux_banner out to
init/version-timestamp.c from init/version.c
Add init/version-timestamp.o to the list of object files that kpatch-cc
won't add to its changed_objs list.
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
---
kpatch-build/kpatch-cc | 1 +
1 file changed, 1 insertion(+)
diff --git a/kpatch-build/kpatch-cc b/kpatch-build/kpatch-cc
index 2a3d264..17aae25 100755
--- a/kpatch-build/kpatch-cc
+++ b/kpatch-build/kpatch-cc
@@ -44,6 +44,7 @@ if [[ "$TOOLCHAINCMD" =~ ^(.*-)?gcc$ || "$TOOLCHAINCMD" =~ ^(.*-)?clang$ ]] ; th
arch/s390/kernel/vdso64/*|\
drivers/firmware/efi/libstub/*|\
init/version.o|\
+ init/version-timestamp.o|\
kernel/system_certificates.o|\
lib/*|\
tools/*|\
--
2.27.0

View File

@ -1,30 +0,0 @@
From 27d0a22c8abbba12e6146f3f389dd28b0fa862dd Mon Sep 17 00:00:00 2001
From: Ryan Sullivan <rysulliv@redhat.com>
Date: Wed, 26 Apr 2023 10:44:04 -0400
Subject: [PATCH] INSTALL.md: update OpenEuler prereqs formatting
Shrink the size of the sub-section header below the OpenEuler section,
reducing confusion as to what section that is a part of, as it is only
necessary for OpenEuler machines.
Signed-off-by: Ryan Sullivan <rysulliv@redhat.com>
---
doc/INSTALL.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/doc/INSTALL.md b/doc/INSTALL.md
index 3b2fdb7..b67a586 100644
--- a/doc/INSTALL.md
+++ b/doc/INSTALL.md
@@ -203,7 +203,7 @@ Install the dependencies for compiling kpatch and running kpatch-build:
make dependencies
```
-Before running kpatch-build, two more things need to be checked:
+#### Before running kpatch-build, two more things need to be checked:
-------
1. Ensure current kernel compiled with *CONFIG_LIVEPATCH_PER_TASK_CONSISTENCY* set
--
2.27.0

Binary file not shown.

BIN
kpatch-0.9.9.tar.gz Normal file

Binary file not shown.

View File

@ -1,7 +1,7 @@
Name: kpatch
Epoch: 1
Version: 0.9.7
Release: 7
Version: 0.9.9
Release: 1
Summary: A Linux dynamic kernel patching infrastructure
License: GPLv2
@ -37,34 +37,20 @@ Patch0021:0021-create-diff-object-create-dynamic-relocs-for-changed.patch
Patch0022:0022-kpatch-build-support-CROSS_COMPILE.patch
Patch0023:0023-livepatch-patch-hook-disable-HAVE_SIMPLE_ENABLE-to-k.patch
Patch0024:0024-kpatch-build-add-KBUILD_MODPOST_WARN-1-to-avoid-modp.patch
Patch0025:0025-kpatch-build-update-find_parent_obj-to-avoid-error-t.patch
Patch0026:0026-create-diff-object-fix-segment-fault-when-using-KPAT.patch
Patch0027:0027-kpatch-macros-replace-__section-with-__kpatch_sectio.patch
Patch0028:0028-create-diff-object-ignore-changed-of-section-__patch.patch
Patch0029:0029-create-diff-object-fix-null-pointer-dereference-in-k.patch
Patch0030:0030-create-diff-object-ignore-.note.gnu.property-section.patch
Patch0031:0031-create-diff-object-skip-creating-.kpatch.arch-sectio.patch
Patch0032:0032-kpatch-build-do-not-copy-linux-scripts-when-building.patch
Patch0033:0033-create-diff-object-ignore-change-of-certain-special-.patch
Patch0034:0034-create-diff-object-allow-__jump_table-section-change.patch
Patch0035:0035-livepatch-patch-hook-fix-kpatch-build-error-which-do.patch
Patch0036:0036-lookup-skip-finding-local-symbols-for-object-with-no.patch
Patch0037:0037-create-diff-object-ignore-entsize-change-of-.return_.patch
Patch0038:0038-kpatch-build-for-clang-use-.strtab-if-no-.shstrtab.patch
Patch0039:0039-create-diff-object-ignore-clang-s-.llvm_addrsig-sect.patch
Patch0040:0040-create-diff-object-ignore-.llvm.-sections.patch
Patch0041:0041-kpatch-cc-Add-more-file-ignores.patch
Patch0042:0042-create-diff-object-fix-__UNIQUE_ID-variable-correlat.patch
Patch0043:0043-create-diff-object-ignore-__patchable_function_entri.patch
Patch0044:0044-gcc-plugin-update-headers-for-gcc-12.patch
Patch0045:0045-kpatch-build-Add-find_kobj-short-circuit-for-OOT-mod.patch
Patch0046:0048-examples-add-proc-version-kpatch-sample.patch
Patch0047:0050-kpatch-macros-add-KPATCH_STATIC_CALL.patch
Patch0048:0052-patch-author-guide-update-jump-label-static-call-des.patch
Patch0049:0056-kpatch-build-ignore-init-version-timestamp.o.patch
Patch0050:0066-INSTALL.md-update-OpenEuler-prereqs-formatting.patch
Patch0051:0070-Fix-undefined-behavior-problem-when-using-list_forea.patch
Patch0052:0049-add-initial-riscv64-support.patch
Patch0025:0025-create-diff-object-fix-segment-fault-when-using-KPAT.patch
Patch0026:0026-kpatch-macros-replace-__section-with-__kpatch_sectio.patch
Patch0027:0027-create-diff-object-ignore-changed-of-section-__patch.patch
Patch0028:0028-create-diff-object-fix-null-pointer-dereference-in-k.patch
Patch0029:0029-create-diff-object-ignore-.note.gnu.property-section.patch
Patch0030:0030-create-diff-object-skip-creating-.kpatch.arch-sectio.patch
Patch0031:0031-kpatch-build-do-not-copy-linux-scripts-when-building.patch
Patch0032:0032-create-diff-object-ignore-change-of-certain-special-.patch
Patch0033:0033-create-diff-object-allow-__jump_table-section-change.patch
Patch0034:0034-livepatch-patch-hook-fix-kpatch-build-error-which-do.patch
Patch0035:0035-lookup-skip-finding-local-symbols-for-object-with-no.patch
Patch0036:0036-create-diff-object-ignore-entsize-change-of-.return_.patch
Patch0037:0037-add-initial-riscv64-support.patch
Patch0038:0038-Fix-undefined-behavior-problem-when-using-list_forea.patch
BuildRequires: gcc elfutils-libelf-devel kernel-devel git
Requires: bc make gcc patch bison flex openssl-devel
@ -125,6 +111,12 @@ popd
%{_mandir}/man1/*.1.gz
%changelog
* Fri Mar 1 2024 Bin Hu <hubin73@huawei.com> -1:0.9.9-1
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:upgrade to 0.9.9
* Fri Dec 1 2023 laokz <zhangkai@iscas.ac.cn> -1:0.9.7-7
- Type:enhancement
- ID:NA