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

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