Compare commits

...

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
b7bbdc89e4
!145 ignore sssnic module when building hotpatch to fix sssnic wrongly dependency of sssnic
From: @pshysimon 
Reviewed-by: @hubin95 
Signed-off-by: @hubin95
2024-07-16 12:25:24 +00:00
PhsySimon
34a316af77 ignore sssnic module when building hotpatch to fix sssnic wrongly dependency of sssnic 2024-07-16 20:16:44 +08:00
openeuler-ci-bot
f265fa18f2
!133 add gcc-plugin-devel to BuildRequires for ppc64le
From: @hugel 
Reviewed-by: @hubin95 
Signed-off-by: @hubin95
2024-06-12 03:39:23 +00:00
gengqihu
0e5df930a8 add gcc-plugin-devel to BuildRequires for ppc64le 2024-06-12 11:12:00 +08:00
openeuler-ci-bot
32496a8b9c
!81 kpatch-build: fix gcc version check when using OOT_MODULE
From: @hubin95 
Reviewed-by: @xiezhipeng1 
Signed-off-by: @xiezhipeng1
2022-10-26 09:45:41 +00:00
Bin Hu
3a394e7d04 kpatch-build: fix gcc version check when using OOT_MODULE
Signed-off-by: Bin Hu <hubin73@huawei.com>
2022-10-26 17:19:37 +08:00
openeuler-ci-bot
741c231290 !49 sync from master
From: @henry-fan
Reviewed-by: @xiezhipeng1
Signed-off-by: @xiezhipeng1
2021-10-26 12:03:33 +00:00
Wentao Fan
1473b90fdc sync from master
Signed-off-by: Wentao Fan <fanwentao@huawei.com>
2021-10-26 19:55:01 +08:00
openeuler-ci-bot
75ef2b1f26 !46 update README and fix two issues
From: @henry-fan
Reviewed-by: @xiezhipeng1
Signed-off-by: @xiezhipeng1
2021-09-28 09:35:49 +00:00
Wentao Fan
e1e031ef84 update README and fix two issues
Signed-off-by: Wentao Fan <fanwentao@huawei.com>
2021-09-28 05:28:33 -04:00
10 changed files with 378 additions and 3 deletions

View File

@ -0,0 +1,104 @@
From 8f5c1ff32fcc519bf061f68a481116f622b9cef8 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Fri, 10 Sep 2021 04:34:40 -0400
Subject: [PATCH] kpatch: update sympos for duplicate symbols in vmlinux
kallsyms in vmlinux is sorted by address, so symbol order
in vmlinux is different from /proc/kallsyms, update sympos
when patching duplicate symbol function.
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
Signed-off-by: hubin57 <hubin57@huawei.com>
---
kpatch-build/create-diff-object.c | 26 ++++++--------------------
kpatch-build/lookup.c | 24 ++++++++++++++++++++++++
kpatch-build/lookup.h | 2 ++
3 files changed, 32 insertions(+), 20 deletions(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index afd5e3b..ff2b0e4 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -2813,26 +2813,12 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
funcs[index].new_size = sym->sym.st_size;
funcs[index].sympos = result.pos;
if (lookup_is_duplicate_symbol(table, sym->name, objname, result.pos)) {
- struct lookup_refsym refsym;
- long offset;
-
- if (lookup_ref_symbol_offset(table, sym->name, &refsym,
- objname, &offset))
- ERROR("unresolvable ambiguity on symbol %s\n", sym->name);
-
- funcs[index].ref_offset = offset;
-
- /*
- * Add a relocation that will populate
- * the funcs[index].ref_name field.
- */
- ALLOC_LINK(rela, &relasec->relas);
- rela->sym = strsym;
- rela->type = absolute_rela_type;
- rela->addend = offset_of_string(&kelf->strings, refsym.name);
- rela->offset = (unsigned int)(index * sizeof(*funcs) +
- offsetof(struct kpatch_patch_func, ref_name));
-
+ if (!strcmp(objname, "vmlinux")) {
+ result.pos = get_vmlinux_duplicate_symbol_pos(table, sym->name, result.value);
+ log_debug("update %s sympos from %ld to %ld\n",
+ sym->name, funcs[index].sympos, result.pos);
+ funcs[index].sympos = result.pos;
+ }
}
diff --git a/kpatch-build/lookup.c b/kpatch-build/lookup.c
index 888bcc9..aa8527d 100644
--- a/kpatch-build/lookup.c
+++ b/kpatch-build/lookup.c
@@ -526,6 +526,30 @@ int lookup_global_symbol(struct lookup_table *table, char *name,
return 1;
}
+/*
+ * In case sometimes the sympos of duplicate symbols are different in vmlinux and
+ * /proc/kallsyms, and causes lookup_local_symbol to save wrong sympos in result,
+ * this function returns correct sympos of the symbol, by comparing
+ * address value with the symbol in vmlinux symbol table.
+ */
+unsigned long get_vmlinux_duplicate_symbol_pos(struct lookup_table *table,
+ char *name, unsigned long value)
+{
+ struct object_symbol *sym;
+ unsigned long pos = 1;
+ int i;
+
+ for_each_obj_symbol(i, sym, table) {
+ if (strcmp(sym->name, name))
+ continue;
+
+ if (sym->value < value)
+ pos++;
+ }
+
+ return pos;
+}
+
int lookup_is_exported_symbol(struct lookup_table *table, char *name)
{
struct export_symbol *sym, *match = NULL;
diff --git a/kpatch-build/lookup.h b/kpatch-build/lookup.h
index daeea73..c745366 100644
--- a/kpatch-build/lookup.h
+++ b/kpatch-build/lookup.h
@@ -37,5 +37,7 @@ int lookup_is_duplicate_symbol(struct lookup_table *table, char *name,
int lookup_ref_symbol_offset(struct lookup_table *table, char *name,
struct lookup_refsym *refsym, char *objname,
long *offset);
+unsigned long get_vmlinux_duplicate_symbol_pos(struct lookup_table *table, char *name,
+ unsigned long value);
#endif /* _LOOKUP_H_ */
--
2.27.0

View File

@ -0,0 +1,30 @@
From 8d1e6f4cfe3fc7007f17e0f01e7ec8aa71e18cae Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Fri, 17 Sep 2021 10:22:24 +0800
Subject: [PATCH] create-diff-object: fix segment fault when sec2->rela is NULL
when patched section has no rela section, we meet segment fault in
__kpatch_correlate_section. add sec2->rela check to fix it.
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
Signed-off-by: hubin57 <hubin57@huawei.com>
---
kpatch-build/create-diff-object.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index ff2b0e4..2159cf0 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -916,7 +916,7 @@ static void kpatch_correlate_section(struct section *sec1, struct section *sec2)
__kpatch_correlate_section(sec1->base, sec2->base);
sec1 = sec1->base;
sec2 = sec2->base;
- } else if (sec1->rela) {
+ } else if (sec1->rela && sec2->rela) {
__kpatch_correlate_section(sec1->rela, sec2->rela);
}
--
2.27.0

View File

@ -0,0 +1,36 @@
From fa5a95cafdb034b825242a93ef1b4ce57985a93d Mon Sep 17 00:00:00 2001
From: Josh Poimboeuf <jpoimboe@redhat.com>
Date: Tue, 13 Apr 2021 13:58:59 -0500
Subject: [PATCH] create-diff-object: Fix out-of-range relocation error message
Showing sec+addend isn't valid, show sym+addend instead.
Before:
create-diff-object: ERROR: sys.o: kpatch_check_relocations: 2550: out-of-range relocation .rodata.__kpatch_do_sys_uname.str1.1+139 in .rela.text.__kpatch_do_sys_uname
After:
create-diff-object: ERROR: sys.o: kpatch_check_relocations: 2550: out-of-range relocation .LC7+139 in .rela.text.__kpatch_do_sys_uname
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
kpatch-build/create-diff-object.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 82e486f..d427beb 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -2547,7 +2547,7 @@ static void kpatch_check_relocations(struct kpatch_elf *kelf)
if (rela->sym->sec) {
sdata = rela->sym->sec->data;
if (rela->addend > (long)sdata->d_size) {
- ERROR("out-of-range relocation %s+%lx in %s", rela->sym->sec->name,
+ ERROR("out-of-range relocation %s+%lx in %s", rela->sym->name,
rela->addend, sec->name);
}
}
--
2.23.0

View File

@ -0,0 +1,32 @@
From 81f9ca4833bf9c5867858d633c340cedca554ca6 Mon Sep 17 00:00:00 2001
From: Josh Poimboeuf <jpoimboe@redhat.com>
Date: Tue, 13 Apr 2021 14:00:41 -0500
Subject: [PATCH] create-diff-object: Fix out-of-range relocation check
Improve the relocation check for the case where the referenced symbol
isn't at the beginning of the section.
Note that the check still isn't perfect, as many relocations have a
negative addend. But it's still a lot better than nothing.
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
kpatch-build/create-diff-object.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index d427beb..14eb1f5 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -2546,7 +2546,7 @@ static void kpatch_check_relocations(struct kpatch_elf *kelf)
list_for_each_entry(rela, &sec->relas, list) {
if (rela->sym->sec) {
sdata = rela->sym->sec->data;
- if (rela->addend > (long)sdata->d_size) {
+ if ((long)rela->sym->sym.st_value + rela->addend > (long)sdata->d_size) {
ERROR("out-of-range relocation %s+%lx in %s", rela->sym->name,
rela->addend, sec->name);
}
--
2.23.0

View File

@ -0,0 +1,25 @@
From eaaced1912c43103749366927daff5794ea4f404 Mon Sep 17 00:00:00 2001
From: gouhao <gouhao@uniontech.com>
Date: Wed, 8 Sep 2021 09:37:08 +0800
Subject: [PATCH] add openEuler build support
---
kpatch-build/kpatch-build | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index 495ca3d..49c0045 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -696,7 +696,7 @@ fi
# shellcheck disable=SC1090
[[ -f "$RELEASE_FILE" ]] && source "$RELEASE_FILE"
DISTRO="$ID"
-if [[ "$DISTRO" = fedora ]] || [[ "$DISTRO" = rhel ]] || [[ "$DISTRO" = ol ]] || [[ "$DISTRO" = centos ]]; then
+if [[ "$DISTRO" = fedora ]] || [[ "$DISTRO" = rhel ]] || [[ "$DISTRO" = ol ]] || [[ "$DISTRO" = centos ]] || [[ "$DISTRO" = openEuler ]]; then
[[ -z "$VMLINUX" ]] && VMLINUX="/usr/lib/debug/lib/modules/$ARCHVERSION/vmlinux"
[[ -e "$VMLINUX" ]] || die "kernel-debuginfo-$ARCHVERSION not installed"
--
2.23.0

View File

@ -0,0 +1,26 @@
From 3911cf1b0631185f5aafca06610f98bd92f4a9db Mon Sep 17 00:00:00 2001
From: Bin Hu <hubin73@huawei.com>
Date: Wed, 26 Oct 2022 17:14:50 +0800
Subject: [PATCH] kpatch-build: fix gcc version check when using OOT_MODULE
Signed-off-by: Bin Hu <hubin73@huawei.com>
---
kpatch-build/kpatch-build | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index 19002a2..c110556 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -229,7 +229,7 @@ gcc_version_check() {
echo 'void main(void) {}' > "$c"
out="$(gcc -c -pg -ffunction-sections -o "$o" "$c" 2>&1)"
gccver="$(gcc_version_from_file "$o")"
- if [[ -n "$OOT_MODULE" ]]; then
+ if [[ -n "$OOT_MODULE" && "$OOT_MODULE" != "yes" ]]; then
kgccver="$(gcc_version_from_file "$OOT_MODULE")"
else
kgccver="$(gcc_version_from_file "$VMLINUX")"
--
2.27.0

View File

@ -0,0 +1,26 @@
From 44026d09697e612c2bc6f08b1a219f09c40a1e11 Mon Sep 17 00:00:00 2001
From: Cai Xiaomeng <caixiaomeng2@huawei.com>
Date: Sat, 13 Jul 2024 14:53:06 +0800
Subject: [PATCH] fix sssnic module always changes, kpatch relying on sssnic
problem
---
kpatch-build/kpatch-gcc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kpatch-build/kpatch-gcc b/kpatch-build/kpatch-gcc
index 80d310c..688d92b 100755
--- a/kpatch-build/kpatch-gcc
+++ b/kpatch-build/kpatch-gcc
@@ -49,7 +49,8 @@ if [[ "$TOOLCHAINCMD" =~ ^(.*-)?gcc$ ||
arch/powerpc/kernel/prom_init.o|\
lib/*|\
.*.o|\
- */.lib_exports.o)
+ */.lib_exports.o|\
+ drivers/net/ethernet/3snic/sssnic/*)
break
;;
*.o)
--
2.33.0

View File

@ -163,10 +163,11 @@ livepatch -r cmdline
## 编译更新补丁工具
```bash
yum install -y git rpm-build elfutils-libelf-devel uname-build-checks gdb-headless
yum install -y git rpm-build elfutils-libelf-devel gdb-headless
git clone https://gitee.com/src-openeuler/kpatch.git
mkdir -p ~/rpmbuild/SOURCES/
/bin/cp kpatch/* ~/rpmbuild/SOURCES/
rpmbuild -ba kpatch/kpatch.spec
rpm -Uvh ~/rpmbuild/RPMS/`arch`/kpatch*.rpm
rpm -Uvh ~/rpmbuild/RPMS/noarch/kpatch*.rpm
```

View File

@ -1,7 +1,7 @@
Name: kpatch
Epoch: 1
Version: 0.9.1
Release: 16
Release: 23
Summary: A Linux dynamic kernel patching infrastructure
License: GPLv2
@ -41,8 +41,18 @@ 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
Patch0029:0029-create-diff-object-error-on-detect-new-changed-ALTIN.patch
Patch0030:0030-kpatch-update-sympos-for-duplicate-symbols-in-vmlinu.patch
Patch0031:0031-create-diff-object-fix-segment-fault-when-sec2-rela-.patch
Patch0032:0032-create-diff-object-Fix-out-of-range-relocation-error.patch
Patch0033:0033-create-diff-object-Fix-out-of-range-relocation-check.patch
Patch0034:0034-add-openEuler-build-support.patch
Patch0035:0035-kpatch-build-fix-gcc-version-check-when-using-OOT_MO.patch
Patch0036:0036-fix-sssnic-module-always-changes-kpatch-relying-on-s.patch
BuildRequires: gcc elfutils-libelf-devel uname-build-checks kernel-devel git
BuildRequires: gcc elfutils-libelf-devel kernel-devel git
%ifarch ppc64le
BuildRequires: gcc-plugin-devel
%endif
Requires: bc make gcc patch bison flex openssl-devel
Recommends: %{name}-help = %{version}-%{release}
@ -101,6 +111,49 @@ popd
%{_mandir}/man1/*.1.gz
%changelog
* Tue Jul 16 2024 caixiaomeng<caixiaomeng2@huawei.com> -1:0.9.1-23
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:ignore sssnic module when building hotpatch to fix sssnic wrongly dependency of sssnic
* Wed Jun 12 2024 gengqihu<gengqihu2@h-partners.com> -1:0.9.1-22
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:add gcc-plugin-devel to BuildRequires for ppc64le
* Wed Oct 26 2022 Bin Hu<hubin73@huawei.com> -1:0.9.1-21
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:kpatch-build: fix gcc version check when using OOT_MODULE
* Tue Oct 26 2021 Zhipeng Xie<xiezhipeng1@huawei.com> -1:0.9.1-20
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:backport upstream patches
* Tue Oct 26 2021 Zhipeng Xie<xiezhipeng1@huawei.com> -1:0.9.1-19
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:support make compile environment
* Tue Sep 28 2021 Zhipeng Xie<xiezhipeng1@huawei.com> -1:0.9.1-18
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:kpatch: update sympos for duplicate symbols in vmlinux
create-diff-object: fix segment fault when sec2->rela is NULL
* Tue Sep 28 2021 Bin Hu<hubin57@huawei.com> -1:0.9.1-17
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:remove uname-build-check from build dependency
* Sat Aug 21 2021 Zhipeng Xie<xiezhipeng1@huawei.com> -1:0.9.1-16
- Type:enhancement
- ID:NA

42
make_compile_env.sh Normal file
View File

@ -0,0 +1,42 @@
#!/bin/bash
rm -rf kpatch_compile_env
yum install -y strace vim git rpm-build bc elfutils-libelf-devel gdb-headless make gcc patch bison flex openssl-devel kernel-source-`uname -r` kernel-debuginfo-`uname -r` kernel-devel-`uname -r` --installroot=`pwd`/kpatch_compile_env/
mkdir -p kpatch_compile_env/kpatch
/bin/cp * kpatch_compile_env/kpatch/
cat > kpatch_compile_env/installkpatch.sh <<EOF
#!/bin/bash
mkdir -p ~/rpmbuild/SOURCES/
/bin/cp kpatch/* ~/rpmbuild/SOURCES/
rpmbuild -ba kpatch/kpatch.spec
rpm -Uvh ~/rpmbuild/RPMS/`arch`/kpatch*.rpm
cd /opt/patch_workspace
rm -rf kernel-source .config
ln -s /usr/src/linux-`uname -r`/ kernel-source
ln -s /usr/src/linux-`uname -r`/.config .config
ln -s /usr/lib/debug/lib/modules/`uname -r`/vmlinux vmlinux
rm -rf /dev/null
mknod /dev/null c 1 3
rm -rf /dev/zero
mknod /dev/zero c 1 5
rm -rf /dev/random
mknod /dev/random c 1 8
rm -rf /dev/tty
mknod /dev/tty c 5 0
EOF
chmod a+x kpatch_compile_env/installkpatch.sh
chroot kpatch_compile_env /installkpatch.sh
cat > kpatch_compile_env/chroot.sh <<EOF
mount -t proc proc \$(dirname \$0)/proc
chroot \$(dirname \$0)
EOF
cat > kpatch_compile_env/unchroot.sh <<EOF
umount \$(dirname \$0)/proc
EOF
cat > kpatch_compile_env/usr/bin/openEuler_history<<EOF
#!/bin/bash
EOF
chmod a+x kpatch_compile_env/chroot.sh
chmod a+x kpatch_compile_env/unchroot.sh
chmod a+x kpatch_compile_env/usr/bin/openEuler_history
tar -czf kpatch_compile_env.tar.gz kpatch_compile_env
rm -rf kpatch_compile_env