Blame SOURCES/0001-kpatch-add-ABI-backwards-compatibility.patch

7a9d72
From 9eed5d4bac0b43372d98572d923ca84e091c8982 Mon Sep 17 00:00:00 2001
7a9d72
Message-Id: <9eed5d4bac0b43372d98572d923ca84e091c8982.1508328327.git.jpoimboe@redhat.com>
7a9d72
From: Josh Poimboeuf <jpoimboe@redhat.com>
7a9d72
Date: Mon, 9 Oct 2017 09:04:46 -0500
7a9d72
Subject: [PATCH] kpatch: add ABI backwards compatibility
7a9d72
7a9d72
When running a kernel for a long period of time without rebooting, it's
7a9d72
possible that newer versions of the kpatch script may get installed.  So
7a9d72
new versions of the kpatch script need to support old versions of
7a9d72
kpatch.ko.
7a9d72
7a9d72
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
7a9d72
---
7a9d72
 kpatch/kpatch | 35 +++++++++++++++++++++++++++--------
7a9d72
 1 file changed, 27 insertions(+), 8 deletions(-)
7a9d72
7a9d72
diff --git a/kpatch/kpatch b/kpatch/kpatch
7a9d72
index ef36087..5998fbc 100755
7a9d72
--- a/kpatch/kpatch
7a9d72
+++ b/kpatch/kpatch
7a9d72
@@ -27,14 +27,6 @@ INSTALLDIR=/var/lib/kpatch
7a9d72
 SCRIPTDIR="$(readlink -f $(dirname $(type -p $0)))"
7a9d72
 VERSION="0.4.0"
7a9d72
 
7a9d72
-# Livepatch is built into the kernel, if it's not present
7a9d72
-# we must use kpatch core module.
7a9d72
-if [[ -e /sys/kernel/livepatch ]] ; then
7a9d72
-	SYSFS="/sys/kernel/livepatch"
7a9d72
-else
7a9d72
-	SYSFS="/sys/kernel/kpatch"
7a9d72
-fi
7a9d72
-
7a9d72
 usage_cmd() {
7a9d72
 	printf '   %-20s\n      %s\n' "$1" "$2" >&2
7a9d72
 }
7a9d72
@@ -132,6 +124,23 @@ get_module_name () {
7a9d72
 	echo $(readelf -p .gnu.linkonce.this_module $1 | grep '\[.*\]' | awk '{print $3}')
7a9d72
 }
7a9d72
 
7a9d72
+init_sysfs_var() {
7a9d72
+	# If the kernel is configured with CONFIG_LIVEPATCH, use that.
7a9d72
+	# Otherwise, use the kpatch core module (kpatch.ko).
7a9d72
+	if [[ -e /sys/kernel/livepatch ]] ; then
7a9d72
+		# livepatch ABI
7a9d72
+		SYSFS="/sys/kernel/livepatch"
7a9d72
+
7a9d72
+	elif [[ -e /sys/kernel/kpatch/patches ]] ; then
7a9d72
+		# kpatch pre-0.4 ABI
7a9d72
+		SYSFS="/sys/kernel/kpatch/patches"
7a9d72
+
7a9d72
+	else
7a9d72
+		# kpatch 0.4 ABI
7a9d72
+		SYSFS="/sys/kernel/kpatch"
7a9d72
+	fi
7a9d72
+}
7a9d72
+
7a9d72
 verify_module_checksum () {
7a9d72
 	modname=$(get_module_name $1)
7a9d72
 	[[ -z $modname ]] && return 1
7a9d72
@@ -158,6 +167,10 @@ load_module () {
7a9d72
 			echo "loading core module: $COREMOD"
7a9d72
 			insmod "$COREMOD" || die "failed to load core module"
7a9d72
 		fi
7a9d72
+
7a9d72
+		# Now that the core module has been loaded, set $SYSFS to the
7a9d72
+		# correct value based on the loaded core module's ABI.
7a9d72
+		init_sysfs_var
7a9d72
 	fi
7a9d72
 
7a9d72
 	local modname=$(get_module_name $module)
7a9d72
@@ -222,6 +235,12 @@ get_module_version() {
7a9d72
 }
7a9d72
 
7a9d72
 unset MODULE
7a9d72
+
7a9d72
+# Initialize the $SYSFS var.  This only works if the core module has been
7a9d72
+# loaded.  Otherwise, the value of $SYSFS doesn't matter at this point anyway,
7a9d72
+# and we'll have to call this function again after loading it.
7a9d72
+init_sysfs_var
7a9d72
+
7a9d72
 [[ "$#" -lt 1 ]] && usage
7a9d72
 case "$1" in
7a9d72
 "load")
7a9d72
-- 
7a9d72
2.13.6
7a9d72