sync from master

Signed-off-by: Wentao Fan <fanwentao@huawei.com>
This commit is contained in:
Wentao Fan 2021-07-23 23:22:16 -04:00
parent 39eb10d00b
commit 9061add331
4 changed files with 140 additions and 15 deletions

View File

@ -0,0 +1,42 @@
From 55a2778284c088f4c383cf364bef18f1b5b88531 Mon Sep 17 00:00:00 2001
From: Artem Savkov <asavkov@redhat.com>
Date: Thu, 4 Mar 2021 12:47:43 +0100
Subject: [PATCH] create-build-diff: support for .cold functions with no id
suffix
create-build-diff expects .cold functions to be suffixed by an id, which
is not always the case. Drop the trailing '.' when searching for cold
functions.
Fixes: #1160
Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
kpatch-build/create-diff-object.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 6b19e1e..d20f2f1 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -124,7 +124,7 @@ static int is_bundleable(struct symbol *sym)
if (sym->type == STT_FUNC &&
!strncmp(sym->sec->name, ".text.unlikely.",15) &&
(!strcmp(sym->sec->name + 15, sym->name) ||
- (strstr(sym->name, ".cold.") &&
+ (strstr(sym->name, ".cold") &&
!strncmp(sym->sec->name + 15, sym->name, strlen(sym->sec->name) - 15))))
return 1;
@@ -248,7 +248,7 @@ static void kpatch_detect_child_functions(struct kpatch_elf *kelf)
list_for_each_entry(sym, &kelf->symbols, list) {
char *coldstr;
- coldstr = strstr(sym->name, ".cold.");
+ coldstr = strstr(sym->name, ".cold");
if (coldstr != NULL) {
char *pname;
--
2.27.0

View File

@ -0,0 +1,62 @@
From b381a0cc0b900d042ff6a718ef9795101310d702 Mon Sep 17 00:00:00 2001
From: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
Date: Wed, 17 Jun 2020 19:51:56 +0530
Subject: [PATCH] lookup: Add __UNIQUE_ID_ to maybe_discarded_sym list
Linux kernel tristate config options allows selected feature, either to
be built-in to the kernel or to be built as a kernel module. When built
as a kernel module, it's expected that the module, will be built with
module information such as author, license, description and others.
For each of the modinfo, a corresponding __UNIQUE_ID_ symbol is
generated. Their lookup succeeds in the case of module but fails when
selected to built-in to the kernel, the reason being that the kernel
discards these __UNIQUE_ID_ symbols during linking. Add __UNIQUE_ID_
symbols to maybe_discarded_sym list, to avoid failure in case of
table->object is vmlinux.
i.e.:
# cat .config|grep IOSCHED_BFQ (can be compiled as module too)
CONFIG_IOSCHED_BFQ=y
# readelf -sW ./block/bfq-iosched.o|grep UNIQUE
219: 0000000000000000 54 OBJECT LOCAL DEFAULT 267 __UNIQUE_ID_description223
220: 0000000000000036 16 OBJECT LOCAL DEFAULT 267 __UNIQUE_ID_license222
221: 0000000000000046 19 OBJECT LOCAL DEFAULT 267 __UNIQUE_ID_file221
222: 0000000000000059 25 OBJECT LOCAL DEFAULT 267 __UNIQUE_ID_author220
223: 0000000000000072 22 OBJECT LOCAL DEFAULT 267 __UNIQUE_ID_alias219
the line below before the kpatch error, is a debug printf to find the failing lookup symbol:
Failed lookup for __UNIQUE_ID_description223
/root/kpatch/kpatch-build/create-diff-object: ERROR: bfq-iosched.o: find_local_syms: 180: couldn't find matching bfq-iosched.c local symbols in ./vmlinux symbol table
with the patch, it successfully builds with both y/m config options:
...
bfq-iosched.o: changed function: bfq_idle_slice_timer
Patched objects: vmlinux
Building patch module:
livepatch-0001-block-bfq-fix-use-after-free-in-b.ko
SUCCESS
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
---
kpatch-build/lookup.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kpatch-build/lookup.c b/kpatch-build/lookup.c
index 4f8c779..9086c9c 100644
--- a/kpatch-build/lookup.c
+++ b/kpatch-build/lookup.c
@@ -83,7 +83,8 @@ static int maybe_discarded_sym(const char *name)
if (!strncmp(name, "__exitcall_", 11) ||
!strncmp(name, "__brk_reservation_fn_", 21) ||
!strncmp(name, "__func_stack_frame_non_standard_", 32) ||
- !strncmp(name, "__addressable_", 14))
+ !strncmp(name, "__addressable_", 14) ||
+ !strncmp(name, "__UNIQUE_ID_", 12))
return 1;
return 0;
--
2.27.0

View File

@ -1,7 +1,7 @@
Name: kpatch
Epoch: 1
Version: 0.9.1
Release: 12
Release: 15
Summary: A Linux dynamic kernel patching infrastructure
License: GPLv2
@ -38,6 +38,8 @@ Patch0023:0023-create-diff-object-fix-duplicate-symbols-for-vmlinux.patch
Patch0024:0024-optimize-for-out-of-tree-module.patch
Patch0025:0025-Fix-relocation-not-resolved-when-new-functions-expor.patch
Patch0026:0026-support-remove-static-variables-using-KPATCH_IGNORE_.patch
Patch0027:0027-create-build-diff-support-for-.cold-functions-with-n.patch
Patch0028:0028-lookup-Add-__UNIQUE_ID_-to-maybe_discarded_sym-list.patch
BuildRequires: gcc elfutils-libelf-devel uname-build-checks kernel-devel git
Requires: bc make gcc patch bison flex openssl-devel
@ -70,6 +72,7 @@ export CFLAGS="$RPM_OPT_FLAGS" LDFLAGS="$RPM_LD_FLAGS"
%make_install PREFIX=%{_prefix}
install -Dm 0500 -t %{buildroot}/%{_bindir} %{SOURCE1} %{SOURCE2}
mkdir -p %{buildroot}/opt/patch_workspace
install -Dm 0500 -t %{buildroot}/opt/patch_workspace/ %{SOURCE3}
pushd %{buildroot}/opt/patch_workspace
mkdir hotpatch package
@ -97,6 +100,24 @@ popd
%{_mandir}/man1/*.1.gz
%changelog
* Fri Jul 23 2021 Xinpeng Liu<liuxp11@chinatelecom.cn> -1:0.9.1-15
- Type:enhancement
- ID:NA
- SUG:NA
- DESC: lookup: Add __UNIQUE_ID_ to maybe_discarded_sym list
* Mon May 31 2021 Xinpeng Liu<liuxp11@chinatelecom.cn> -1:0.9.1-14
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:modify the code stype in make_hotpatch and fix compile bug
* Sat May 29 2021 Wentao Fan<fanwentao@huawei.com> -1:0.9.1-13
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:support for .cold functions with no id suffix
* Wed Feb 10 2021 Zhipeng Xie<xiezhipeng1@huawei.com> -1:0.9.1-12
- Type:enhancement
- ID:NA

View File

@ -326,20 +326,20 @@ function fn_verify_input()
if [ -z "`echo "$input_param" | grep -w "\-i"`" \
-a -z "`echo $input_param | grep -w "\-\-id"`" \
-a $# -gt 1 ];then
echo "error: missing param -i or --id"
fn_do_clean
fn_usage
exit 1
fi
if [ -z "`echo "$input_param" | grep -w "\-d"`" \
-a -z "`echo $input_param | grep -w "\-\-diffext"`" \
-a -z "`echo $input_param | grep -w "\-p"`" \
-a -z "`echo $input_param | grep -w "\-\-patch"`" \
-a $# -gt 1 ];then
echo "error: missing param -d,--diffext or -p,--patch"
fn_do_clean
fn_usage
exit 1
echo "error: missing param -i or --id"
fn_do_clean
fn_usage
exit 1
fi
if [ -z "`echo "$input_param" | grep -w "\-d"`" \
-a -z "`echo $input_param | grep -w "\-\-diffext"`" \
-a -z "`echo $input_param | grep -w "\-p"`" \
-a -z "`echo $input_param | grep -w "\-\-patch"`" \
-a $# -gt 1 ];then
echo "error: missing param -d,--diffext or -p,--patch"
fn_do_clean
fn_usage
exit 1
fi
while [ $# -ge 1 ]; do