From 4f27b9ae31cd5ab289481ec46bc2b05ad923dece Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Thu, 13 Feb 2014 07:49:02 -0600 Subject: [PATCH] functional reorganization Organize the files functionally: - kmod/core: core kmod source - kmod/patch: patch kmod source - kpatch: kpatch script - kpatch-build: kpatch build script and supporting tools - contrib: distro-related files --- .gitignore | 10 ++---- Makefile | 8 ----- README | 16 +++++----- {scripts => contrib}/kpatch.service | 0 {kpatch-kmod => kmod/core}/Makefile | 4 +-- kpatch-kmod/base.c => kmod/core/core.c | 0 {kpatch-kmod => kmod/core}/kpatch.h | 0 {kpatch-kmod => kmod/core}/trampoline.S | 0 {kpatch-files => kmod/patch}/Makefile | 0 .../patch}/kpatch-patch-hook.c | 0 {kpatch-files => kmod/patch}/kpatch.lds | 0 {tools => kpatch-build}/Makefile | 2 +- {tools => kpatch-build}/add-patches-section.c | 0 {tools => kpatch-build}/create-diff-object.c | 0 {scripts => kpatch-build}/kpatch-build | 32 +++++++++---------- {tools => kpatch-build}/link-vmlinux-syms.c | 0 {scripts => kpatch}/kpatch | 0 17 files changed, 30 insertions(+), 42 deletions(-) delete mode 100644 Makefile rename {scripts => contrib}/kpatch.service (100%) rename {kpatch-kmod => kmod/core}/Makefile (80%) rename kpatch-kmod/base.c => kmod/core/core.c (100%) rename {kpatch-kmod => kmod/core}/kpatch.h (100%) rename {kpatch-kmod => kmod/core}/trampoline.S (100%) rename {kpatch-files => kmod/patch}/Makefile (100%) rename {kpatch-files => kmod/patch}/kpatch-patch-hook.c (100%) rename {kpatch-files => kmod/patch}/kpatch.lds (100%) rename {tools => kpatch-build}/Makefile (93%) rename {tools => kpatch-build}/add-patches-section.c (100%) rename {tools => kpatch-build}/create-diff-object.c (100%) rename {scripts => kpatch-build}/kpatch-build (83%) rename {tools => kpatch-build}/link-vmlinux-syms.c (100%) rename {scripts => kpatch}/kpatch (100%) diff --git a/.gitignore b/.gitignore index dd50ef5..1b5b1e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,9 @@ -kpatch-diff-gen/kpatch-diff-gen *.o *.o.cmd *.ko *.ko.cmd *.mod.c *.swp -kmod/.tmp_versions/ -kmod/Module.symvers -kmod/modules.order -tools/add-patches-section -tools/create-diff-object -tools/link-vmlinux-syms +kpatch-build/add-patches-section +kpatch-build/create-diff-object +kpatch-build/link-vmlinux-syms diff --git a/Makefile b/Makefile deleted file mode 100644 index f248f06..0000000 --- a/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -SUBDIRS = kpatch-kmod tools - -.PHONY: clean -clean: - for dir in $(SUBDIRS); do \ - $(MAKE) -C $$dir $@; \ - done - diff --git a/README b/README index 5ddad10..714738a 100644 --- a/README +++ b/README @@ -18,7 +18,7 @@ This only works on Fedora currently. First make a patch against the kernel tree, e.g. foo.patch. Then: - sudo scripts/kpatch-build ~/foo.patch + sudo kpatch-build/kpatch-build ~/foo.patch insmod kpatch.ko kpatch-foo.ko Voila, your kernel is patched. @@ -51,7 +51,7 @@ patches and environments is conducted. DEPENDENCIES -kpatch tools require libelf library and development headers to be installed. +kpatch-build tools require libelf library and development headers to be installed. See GOTCHAS below. GOTCHAS @@ -67,8 +67,8 @@ git://git.fedorahosted.org/git/elfutils.git HOWTO -An example script for automating the hotfix module generation is in -scripts/kpatch-build. The script is written for Fedora but should +An example script for automating the hotfix module generation is +kpatch-build/kpatch-build. The script is written for Fedora but should be adaptable to other distributions with limited changes. The primary steps in the hotfix module generation process are: @@ -80,16 +80,16 @@ The primary steps in the hotfix module generation process are: resulting in the changed patched objects - Unpatch the source tree - Recompile each changed object with -ffunction-sections -fdata-sections - resulting in the changed base objects -- Use tools/create-diff-object to analyze each base/patched object pair + resulting in the changed original objects +- Use create-diff-object to analyze each original/patched object pair for patchability and generate an output object containing modified sections - Link all the output objects in a into a cumulative object -- Use tools/add-patches-section to add the .patches section that the +- Use add-patches-section to add the .patches section that the core kpatch module uses to determine the list of functions that need to be redirected using ftrace - Generate the hotfix kernel module -- Use tools/link-vmlinux-syms to hardcode non-exported kernel symbols +- Use link-vmlinux-syms to hardcode non-exported kernel symbols into the symbol table of the hotfix kernel module DEMONSTRATION diff --git a/scripts/kpatch.service b/contrib/kpatch.service similarity index 100% rename from scripts/kpatch.service rename to contrib/kpatch.service diff --git a/kpatch-kmod/Makefile b/kmod/core/Makefile similarity index 80% rename from kpatch-kmod/Makefile rename to kmod/core/Makefile index 21d200a..ac83fe4 100644 --- a/kpatch-kmod/Makefile +++ b/kmod/core/Makefile @@ -2,9 +2,9 @@ KPATCH_BUILD ?= /usr/lib/modules/$(shell uname -r)/build KPATCH_MAKE = $(MAKE) -C $(KPATCH_BUILD) M=$(PWD) obj-m := kpatch.o -kpatch-y := base.o trampoline.o +kpatch-y := core.o trampoline.o -kpatch.ko: base.c trampoline.S +kpatch.ko: core.c trampoline.S $(KPATCH_MAKE) kpatch.ko all: kpatch.ko diff --git a/kpatch-kmod/base.c b/kmod/core/core.c similarity index 100% rename from kpatch-kmod/base.c rename to kmod/core/core.c diff --git a/kpatch-kmod/kpatch.h b/kmod/core/kpatch.h similarity index 100% rename from kpatch-kmod/kpatch.h rename to kmod/core/kpatch.h diff --git a/kpatch-kmod/trampoline.S b/kmod/core/trampoline.S similarity index 100% rename from kpatch-kmod/trampoline.S rename to kmod/core/trampoline.S diff --git a/kpatch-files/Makefile b/kmod/patch/Makefile similarity index 100% rename from kpatch-files/Makefile rename to kmod/patch/Makefile diff --git a/kpatch-files/kpatch-patch-hook.c b/kmod/patch/kpatch-patch-hook.c similarity index 100% rename from kpatch-files/kpatch-patch-hook.c rename to kmod/patch/kpatch-patch-hook.c diff --git a/kpatch-files/kpatch.lds b/kmod/patch/kpatch.lds similarity index 100% rename from kpatch-files/kpatch.lds rename to kmod/patch/kpatch.lds diff --git a/tools/Makefile b/kpatch-build/Makefile similarity index 93% rename from tools/Makefile rename to kpatch-build/Makefile index 84b1680..de0f15f 100644 --- a/tools/Makefile +++ b/kpatch-build/Makefile @@ -1,4 +1,4 @@ -CFLAGS=-I../kpatch-kmod +CFLAGS=-I../kmod/core all: create-diff-object add-patches-section link-vmlinux-syms diff --git a/tools/add-patches-section.c b/kpatch-build/add-patches-section.c similarity index 100% rename from tools/add-patches-section.c rename to kpatch-build/add-patches-section.c diff --git a/tools/create-diff-object.c b/kpatch-build/create-diff-object.c similarity index 100% rename from tools/create-diff-object.c rename to kpatch-build/create-diff-object.c diff --git a/scripts/kpatch-build b/kpatch-build/kpatch-build similarity index 83% rename from scripts/kpatch-build rename to kpatch-build/kpatch-build index 8c51c2f..9cd749c 100755 --- a/scripts/kpatch-build +++ b/kpatch-build/kpatch-build @@ -24,7 +24,7 @@ BASE=$PWD LOGFILE=$PWD/kpatch-build.log -TOOLSDIR=$BASE/tools +TOOLSDIR=$BASE/kpatch-build ARCHVERSION=$(uname -r) DISTROVERSION=${ARCHVERSION%*.*} CPUS=$(grep -c ^processor /proc/cpuinfo) @@ -56,10 +56,10 @@ then exit 3 fi -PATCHBASE=`basename $PATCHFILE` -if [[ $PATCHBASE =~ \.patch ]] || [[ $PATCHBASE =~ \.diff ]] +PATCHNAME=`basename $PATCHFILE` +if [[ $PATCHNAME =~ \.patch ]] || [[ $PATCHNAME =~ \.diff ]] then - PATCHBASE=${PATCHBASE%.*} + PATCHNAME=${PATCHNAME%.*} fi cleanup @@ -101,7 +101,7 @@ else cp -a $KSRCDIR $KSRCDIR_CACHE fi -cp -R $BASE/kpatch-files/* $BASE/kpatch-kmod $TEMPDIR || die +cp -R $BASE/kmod/patch/* $BASE/kmod/core $TEMPDIR || die cp vmlinux $TEMPDIR || die echo "Building patched kernel" @@ -127,36 +127,36 @@ do done patch -R -p1 < $PATCHFILE >> $LOGFILE 2>&1 -mkdir $TEMPDIR/base +mkdir $TEMPDIR/orig for i in $(cat $TEMPDIR/changed_objs) do rm -f $i KCFLAGS="-ffunction-sections -fdata-sections" make $i >> $LOGFILE 2>&1 || die strip -d $i - cp -f $i $TEMPDIR/base/ + cp -f $i $TEMPDIR/orig/ done echo "Extracting new and modified ELF sections" cd $TEMPDIR mkdir output -for i in base/* +for i in orig/* do FILE=`basename $i` - $TOOLSDIR/create-diff-object base/$FILE patched/$FILE output/$FILE >> $LOGFILE 2>&1 || die + $TOOLSDIR/create-diff-object orig/$FILE patched/$FILE output/$FILE >> $LOGFILE 2>&1 || die done -echo "Building base module: kpatch.ko" -cd kpatch-kmod +echo "Building core module: kpatch.ko" +cd core KPATCH_BUILD=$KSRCDIR make >> $LOGFILE 2>&1 || die cd .. -echo "Building hotpatch module: kpatch-$PATCHBASE.ko" +echo "Building patch module: kpatch-$PATCHNAME.ko" ld -r -o output.o output/* >> $LOGFILE 2>&1 || die $TOOLSDIR/add-patches-section output.o vmlinux >> $LOGFILE 2>&1 || die -KPATCH_BASEDIR=$TEMPDIR/kpatch-kmod KPATCH_BUILD=$KSRCDIR KPATCH_NAME=$PATCHBASE make >> $LOGFILE 2>&1 || die -strip -d kpatch-$PATCHBASE.ko >> $LOGFILE 2>&1 || die -$TOOLSDIR/link-vmlinux-syms kpatch-$PATCHBASE.ko vmlinux >> $LOGFILE 2>&1 || die +KPATCH_BASEDIR=$TEMPDIR/core KPATCH_BUILD=$KSRCDIR KPATCH_NAME=$PATCHNAME make >> $LOGFILE 2>&1 || die +strip -d kpatch-$PATCHNAME.ko >> $LOGFILE 2>&1 || die +$TOOLSDIR/link-vmlinux-syms kpatch-$PATCHNAME.ko vmlinux >> $LOGFILE 2>&1 || die echo "SUCCESS" -cp -f $TEMPDIR/kpatch-$PATCHBASE.ko $TEMPDIR/kpatch-kmod/kpatch.ko $BASE +cp -f $TEMPDIR/kpatch-$PATCHNAME.ko $TEMPDIR/core/kpatch.ko $BASE cleanup diff --git a/tools/link-vmlinux-syms.c b/kpatch-build/link-vmlinux-syms.c similarity index 100% rename from tools/link-vmlinux-syms.c rename to kpatch-build/link-vmlinux-syms.c diff --git a/scripts/kpatch b/kpatch/kpatch similarity index 100% rename from scripts/kpatch rename to kpatch/kpatch