diff options
author | Ruslan Bilovol <rbilovol@cisco.com> | 2018-02-01 18:34:18 +0200 |
---|---|---|
committer | Armin Kuster <akuster808@gmail.com> | 2018-02-11 11:52:54 -0800 |
commit | 6cb84a77bbf537651838bef88f84a55e239c2881 (patch) | |
tree | f7400071525ed66e0a33ba0071eb10875a07901f /meta-oe/recipes-kernel | |
parent | f75e11225f5f424abfb672d09728c60c61cd801f (diff) | |
download | meta-openembedded-6cb84a77bbf537651838bef88f84a55e239c2881.tar.gz |
recipes-kernel: add kpatch dynamic kernel patching infrastructure
kpatch is a Linux dynamic kernel patching infrastructure
which allows you to patch a running kernel without
rebooting or restarting any processes
Currently it is enabled and tested on x86-64 systems,
although can be extended to PPC64 as well.
Signed-off-by: Ruslan Bilovol <rbilovol@cisco.com>
Signed-off-by: Armin Kuster <akuster808@gmail.com>
Diffstat (limited to 'meta-oe/recipes-kernel')
4 files changed, 225 insertions, 0 deletions
diff --git a/meta-oe/recipes-kernel/kpatch/kpatch.inc b/meta-oe/recipes-kernel/kpatch/kpatch.inc new file mode 100644 index 000000000..b1e73e954 --- /dev/null +++ b/meta-oe/recipes-kernel/kpatch/kpatch.inc | |||
@@ -0,0 +1,49 @@ | |||
1 | SUMMARY = "Linux dynamic kernel patching infrastructure" | ||
2 | DESCRIPTION = "kpatch is a Linux dynamic kernel patching infrastructure which allows you to patch a running kernel without rebooting or restarting any processes." | ||
3 | LICENSE = "GPLv2 & LGPLv2" | ||
4 | DEPENDS = "elfutils bash" | ||
5 | |||
6 | SRC_URI = "git://github.com/dynup/kpatch.git;protocol=https \ | ||
7 | file://0001-kpatch-build-add-cross-compilation-support.patch \ | ||
8 | file://0002-kpatch-build-allow-overriding-of-distro-name.patch \ | ||
9 | " | ||
10 | |||
11 | EXTRA_OEMAKE = " \ | ||
12 | PREFIX=${prefix} \ | ||
13 | BINDIR=${D}${bindir} \ | ||
14 | SBINDIR=${D}${sbindir} \ | ||
15 | LIBDIR=${D}${libdir} \ | ||
16 | MANDIR=${D}${mandir}/man1 \ | ||
17 | SYSTEMDDIR=${D}${systemd_system_unitdir} \ | ||
18 | DESTDIR=${D} \ | ||
19 | BUILDMOD=no \ | ||
20 | CC='${CC}' \ | ||
21 | " | ||
22 | |||
23 | S = "${WORKDIR}/git" | ||
24 | |||
25 | do_install () { | ||
26 | oe_runmake install | ||
27 | } | ||
28 | |||
29 | PACKAGES =+ "kpatch-build" | ||
30 | PROVIDES += "kpatch-build" | ||
31 | |||
32 | COMPATIBLE_HOST = "(x86_64).*-linux" | ||
33 | |||
34 | RDEPENDS_${PN} = "bash binutils" | ||
35 | RDEPENDS_kpatch-build = "bash glibc-utils" | ||
36 | |||
37 | FILES_${PN} = " \ | ||
38 | ${sbindir}/kpatch \ | ||
39 | ${systemd_system_unitdir}/kpatch.service \ | ||
40 | ${mandir}/man1/kpatch.1.gz \ | ||
41 | " | ||
42 | FILES_kpatch-build = " \ | ||
43 | ${bindir}/kpatch-build \ | ||
44 | ${libexecdir}/* \ | ||
45 | ${datadir}/kpatch \ | ||
46 | ${mandir}/man1/kpatch-build.1.gz \ | ||
47 | " | ||
48 | |||
49 | SYSTEMD_SERVICE_${PN} = "kpatch.service" | ||
diff --git a/meta-oe/recipes-kernel/kpatch/kpatch/0001-kpatch-build-add-cross-compilation-support.patch b/meta-oe/recipes-kernel/kpatch/kpatch/0001-kpatch-build-add-cross-compilation-support.patch new file mode 100644 index 000000000..459fb2197 --- /dev/null +++ b/meta-oe/recipes-kernel/kpatch/kpatch/0001-kpatch-build-add-cross-compilation-support.patch | |||
@@ -0,0 +1,103 @@ | |||
1 | From a9a80a1f4df65892a0269295ce8a64b06f2ff61d Mon Sep 17 00:00:00 2001 | ||
2 | From: Ruslan Bilovol <rbilovol@cisco.com> | ||
3 | Date: Tue, 19 Dec 2017 15:59:04 +0200 | ||
4 | Subject: [PATCH] kpatch-build: add cross-compilation support | ||
5 | |||
6 | This patch introduces new option for kpatch-build | ||
7 | script "--cross-compile" which can be used for | ||
8 | specifying cross-complier prefix. | ||
9 | It allows to build live patches not only on | ||
10 | target system, but also on hosts for a target other | ||
11 | than the one on which the compiler is running | ||
12 | |||
13 | Also removed quotes in exec lines, so it is | ||
14 | possible to pass multy-component strings like | ||
15 | "ccache x86_64-xelinux-linux-" as cross-compiler | ||
16 | |||
17 | Upstream-Status: Pending | ||
18 | |||
19 | Signed-off-by: Ruslan Bilovol <rbilovol@cisco.com> | ||
20 | --- | ||
21 | kpatch-build/kpatch-build | 13 +++++++++++-- | ||
22 | kpatch-build/kpatch-gcc | 4 ++-- | ||
23 | 2 files changed, 13 insertions(+), 4 deletions(-) | ||
24 | |||
25 | diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build | ||
26 | index 166ecbd..af24cc4 100755 | ||
27 | --- a/kpatch-build/kpatch-build | ||
28 | +++ b/kpatch-build/kpatch-build | ||
29 | @@ -195,7 +195,7 @@ gcc_version_check() { | ||
30 | # gcc --version varies between distributions therefore extract version | ||
31 | # by compiling a test file and compare it to vmlinux's version. | ||
32 | echo 'void main(void) {}' > "$c" | ||
33 | - out="$(gcc -c -pg -ffunction-sections -o "$o" "$c" 2>&1)" | ||
34 | + out="$(${KPATCH_CROSS_COMPILE}gcc -c -pg -ffunction-sections -o "$o" "$c" 2>&1)" | ||
35 | gccver="$(gcc_version_from_file "$o")" | ||
36 | kgccver="$(gcc_version_from_file "$VMLINUX")" | ||
37 | rm -f "$c" "$o" | ||
38 | @@ -381,12 +381,14 @@ usage() { | ||
39 | echo " -d, --debug Enable 'xtrace' and keep scratch files" >&2 | ||
40 | echo " in <CACHEDIR>/tmp" >&2 | ||
41 | echo " (can be specified multiple times)" >&2 | ||
42 | + echo " --cross-compile Specify the prefix used for all executables" >&2 | ||
43 | + echo " used during compilation" >&2 | ||
44 | echo " --skip-cleanup Skip post-build cleanup" >&2 | ||
45 | echo " --skip-gcc-check Skip gcc version matching check" >&2 | ||
46 | echo " (not recommended)" >&2 | ||
47 | } | ||
48 | |||
49 | -options="$(getopt -o ha:r:s:c:v:j:t:n:o:d -l "help,archversion:,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,debug,skip-gcc-check,skip-cleanup" -- "$@")" || die "getopt failed" | ||
50 | +options="$(getopt -o ha:r:s:c:v:j:t:n:o:d -l "help,archversion:,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,debug,cross-compile:,skip-gcc-check,skip-cleanup" -- "$@")" || die "getopt failed" | ||
51 | |||
52 | eval set -- "$options" | ||
53 | |||
54 | @@ -444,6 +446,10 @@ while [[ $# -gt 0 ]]; do | ||
55 | echo "DEBUG mode enabled" | ||
56 | fi | ||
57 | ;; | ||
58 | + --cross-compile) | ||
59 | + KPATCH_CROSS_COMPILE="$2" | ||
60 | + shift | ||
61 | + ;; | ||
62 | --skip-cleanup) | ||
63 | echo "Skipping cleanup" | ||
64 | SKIPCLEANUP=1 | ||
65 | @@ -691,6 +697,8 @@ if [[ $DEBUG -ge 4 ]]; then | ||
66 | export KPATCH_GCC_DEBUG=1 | ||
67 | fi | ||
68 | |||
69 | +export KPATCH_CROSS_COMPILE | ||
70 | + | ||
71 | echo "Building original kernel" | ||
72 | ./scripts/setlocalversion --save-scmversion || die | ||
73 | make mrproper 2>&1 | logger || die | ||
74 | @@ -840,6 +848,7 @@ cd "$TEMPDIR/patch" || die | ||
75 | KPATCH_BUILD="$SRCDIR" KPATCH_NAME="$MODNAME" \ | ||
76 | KBUILD_EXTRA_SYMBOLS="$KBUILD_EXTRA_SYMBOLS" \ | ||
77 | KPATCH_LDFLAGS="$KPATCH_LDFLAGS" \ | ||
78 | +CROSS_COMPILE="$KPATCH_CROSS_COMPILE" \ | ||
79 | make 2>&1 | logger || die | ||
80 | |||
81 | if ! "$KPATCH_MODULE"; then | ||
82 | diff --git a/kpatch-build/kpatch-gcc b/kpatch-build/kpatch-gcc | ||
83 | index 6ba133c..3937948 100755 | ||
84 | --- a/kpatch-build/kpatch-gcc | ||
85 | +++ b/kpatch-build/kpatch-gcc | ||
86 | @@ -8,7 +8,7 @@ TOOLCHAINCMD="$1" | ||
87 | shift | ||
88 | |||
89 | if [[ -z "$KPATCH_GCC_TEMPDIR" ]]; then | ||
90 | - exec "$TOOLCHAINCMD" "$@" | ||
91 | + exec ${KPATCH_CROSS_COMPILE}${TOOLCHAINCMD} "$@" | ||
92 | fi | ||
93 | |||
94 | declare -a args=("$@") | ||
95 | @@ -80,4 +80,4 @@ elif [[ "$TOOLCHAINCMD" = "ld" ]] ; then | ||
96 | done | ||
97 | fi | ||
98 | |||
99 | -exec "$TOOLCHAINCMD" "${args[@]}" | ||
100 | +exec ${KPATCH_CROSS_COMPILE}${TOOLCHAINCMD} "${args[@]}" | ||
101 | -- | ||
102 | 1.9.1 | ||
103 | |||
diff --git a/meta-oe/recipes-kernel/kpatch/kpatch/0002-kpatch-build-allow-overriding-of-distro-name.patch b/meta-oe/recipes-kernel/kpatch/kpatch/0002-kpatch-build-allow-overriding-of-distro-name.patch new file mode 100644 index 000000000..a9d8a7f2c --- /dev/null +++ b/meta-oe/recipes-kernel/kpatch/kpatch/0002-kpatch-build-allow-overriding-of-distro-name.patch | |||
@@ -0,0 +1,62 @@ | |||
1 | From d418d716dae1e2a05131dfb42a19a4da2fc8a85d Mon Sep 17 00:00:00 2001 | ||
2 | From: Ruslan Bilovol <rbilovol@cisco.com> | ||
3 | Date: Tue, 2 Jan 2018 14:50:03 +0200 | ||
4 | Subject: [PATCH] kpatch-build: allow overriding of distro name | ||
5 | |||
6 | It is sometimes useful to have ability to override | ||
7 | distro name, for example during cross-compilation | ||
8 | build when livepatch modules will be ran on the | ||
9 | target which differs from host. | ||
10 | |||
11 | This patch adds a new --distro option which | ||
12 | implements all needed functionality | ||
13 | |||
14 | Upstream-Status: Pending | ||
15 | |||
16 | Signed-off-by: Ruslan Bilovol <rbilovol@cisco.com> | ||
17 | --- | ||
18 | kpatch-build/kpatch-build | 9 +++++++-- | ||
19 | 1 file changed, 7 insertions(+), 2 deletions(-) | ||
20 | |||
21 | diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build | ||
22 | index af24cc4..4f9f78d 100755 | ||
23 | --- a/kpatch-build/kpatch-build | ||
24 | +++ b/kpatch-build/kpatch-build | ||
25 | @@ -383,12 +383,13 @@ usage() { | ||
26 | echo " (can be specified multiple times)" >&2 | ||
27 | echo " --cross-compile Specify the prefix used for all executables" >&2 | ||
28 | echo " used during compilation" >&2 | ||
29 | + echo " --distro Override distro name" >&2 | ||
30 | echo " --skip-cleanup Skip post-build cleanup" >&2 | ||
31 | echo " --skip-gcc-check Skip gcc version matching check" >&2 | ||
32 | echo " (not recommended)" >&2 | ||
33 | } | ||
34 | |||
35 | -options="$(getopt -o ha:r:s:c:v:j:t:n:o:d -l "help,archversion:,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,debug,cross-compile:,skip-gcc-check,skip-cleanup" -- "$@")" || die "getopt failed" | ||
36 | +options="$(getopt -o ha:r:s:c:v:j:t:n:o:d -l "help,archversion:,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,debug,cross-compile:,distro:,skip-gcc-check,skip-cleanup" -- "$@")" || die "getopt failed" | ||
37 | |||
38 | eval set -- "$options" | ||
39 | |||
40 | @@ -450,6 +451,10 @@ while [[ $# -gt 0 ]]; do | ||
41 | KPATCH_CROSS_COMPILE="$2" | ||
42 | shift | ||
43 | ;; | ||
44 | + --distro) | ||
45 | + DISTRO="$2" | ||
46 | + shift | ||
47 | + ;; | ||
48 | --skip-cleanup) | ||
49 | echo "Skipping cleanup" | ||
50 | SKIPCLEANUP=1 | ||
51 | @@ -526,7 +531,7 @@ fi | ||
52 | # Don't check external file. | ||
53 | # shellcheck disable=SC1091 | ||
54 | source /etc/os-release | ||
55 | -DISTRO="$ID" | ||
56 | +DISTRO="${DISTRO:-${ID}}" | ||
57 | if [[ "$DISTRO" = fedora ]] || [[ "$DISTRO" = rhel ]] || [[ "$DISTRO" = ol ]] || [[ "$DISTRO" = centos ]]; then | ||
58 | [[ -z "$VMLINUX" ]] && VMLINUX="/usr/lib/debug/lib/modules/$ARCHVERSION/vmlinux" | ||
59 | [[ -e "$VMLINUX" ]] || die "kernel-debuginfo-$ARCHVERSION not installed" | ||
60 | -- | ||
61 | 1.9.1 | ||
62 | |||
diff --git a/meta-oe/recipes-kernel/kpatch/kpatch_git.bb b/meta-oe/recipes-kernel/kpatch/kpatch_git.bb new file mode 100644 index 000000000..e495e2882 --- /dev/null +++ b/meta-oe/recipes-kernel/kpatch/kpatch_git.bb | |||
@@ -0,0 +1,11 @@ | |||
1 | require kpatch.inc | ||
2 | |||
3 | LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263" | ||
4 | |||
5 | SRCREV = "db6efbb8c7e90d2b761272cf563047119072768f" | ||
6 | |||
7 | PV = "0.5.0+git${SRCPV}" | ||
8 | |||
9 | S = "${WORKDIR}/git" | ||
10 | |||
11 | BBCLASSEXTEND = "native nativesdk" | ||