Merge pull request #1046 from julien-thierry/unload-fixes

Unload fixes
This commit is contained in:
Josh Poimboeuf 2019-10-28 14:28:11 -05:00 committed by GitHub
commit eec99f0923
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 135 additions and 430 deletions

View File

@ -339,7 +339,10 @@ disable_patch () {
local modname="$1"
local enabled="$SYSFS/$modname/enabled"
[[ -e "$enabled" ]] || die "patch module $1 is not loaded"
if ! [[ -e "$enabled" ]]; then
warn "patch module $modname is not loaded"
return 1
fi
if [[ "$(cat "$enabled")" -eq 1 ]]; then
echo "disabling patch module: $modname"
@ -349,35 +352,44 @@ disable_patch () {
[[ -z "$out" ]] && break
echo "$out" 1>&2
if [[ ! "$out" =~ "Device or resource busy" ]]; then
die "failed to disable module $modname"
return 1
fi
# "Device or resource busy" means the activeness safety check
# failed. Retry in a few seconds.
i=$((i+1))
if [[ $i -eq $MAX_LOAD_ATTEMPTS ]]; then
die "failed to disable module $modname"
return 1
else
warn "retrying..."
sleep $RETRY_INTERVAL
fi
done
fi
}
disable_patch_strict () {
local modname="$1"
disable_patch "$modname" || die "failed to disable module $modname"
if ! wait_for_patch_transition "$modname" ; then
die "transition stalled for $modname"
fi
}
remove_module () {
echo "unloading patch module: $1"
# ignore any error here because rmmod can fail if the module used
# KPATCH_FORCE_UNSAFE.
rmmod "$1" 2> /dev/null || return 0
}
unload_module () {
PATCH="${1//-/_}"
PATCH="${PATCH%.ko}"
disable_patch "$PATCH"
echo "unloading patch module: $PATCH"
# ignore any error here because rmmod can fail if the module used
# KPATCH_FORCE_UNSAFE.
rmmod "$PATCH" 2> /dev/null || return 0
disable_patch_strict "$PATCH"
remove_module "$PATCH"
}
get_module_version() {
@ -415,10 +427,39 @@ case "$1" in
[[ "$#" -ne 2 ]] && usage
case "$2" in
"--all")
# Versions of linux < 5.1 livepatching require patches to be
# disabled in the inverse order in which they were enabled.
while true; do
nr_disabled=0
for module in "$SYSFS"/*; do
modname="$(basename "$module")"
[[ -e "$module" ]] || continue
unload_module "$(basename "$module")" || die "failed to unload module $module"
disable_patch "$modname" || continue
if ! wait_for_patch_transition "$modname" ; then
warn "transition stalled for $modname"
continue
fi
remove_module "$modname"
nr_disabled=$((nr_disabled + 1))
done
if [ $nr_disabled -eq 0 ]; then
break
fi
done
nr_remaining=0
for module in "$SYSFS"/*; do
modname="$(basename "$module")"
[[ -e "$module" ]] || continue
nr_remaining=$((nr_remaining + 1))
warn "failed to unload module $modname"
done
if [ $nr_remaining -gt 0 ]; then
exit 1
fi
;;
*)
unload_module "$(basename "$2")" || die "failed to unload module $2"

View File

@ -1,65 +1,7 @@
#!/bin/bash
SCRIPTDIR="$(readlink -f $(dirname $(type -p $0)))"
ROOTDIR="$(readlink -f $SCRIPTDIR/../../..)"
KPATCH="sudo $ROOTDIR/kpatch/kpatch"
MODULE_PREFIX="test-"
MODULE_POSTFIX=".ko"
TEST_POSTFIX="-LOADED.test"
set -o errexit
die() {
echo "ERROR: $@" >&2
exit 1
}
ko_to_test() {
tmp=${1%${MODULE_POSTFIX}}${TEST_POSTFIX}
echo ${tmp#${MODULE_PREFIX}}
}
# make sure any modules added here are disjoint
declare -a modules
declare -a blacklist=(data-new-LOADED.test)
for file in "${SCRIPTDIR}"/*"${TEST_POSTFIX}"; do
name=$(basename ${file})
skip=0
for bname in "${blacklist[@]}"; do
if [ "${bname}" == "${name}" ]; then
skip=1
break
fi
done
if [ ${skip} -eq 0 ]; then
modules+=(${MODULE_PREFIX}${name%${TEST_POSTFIX}}${MODULE_POSTFIX})
fi
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded before loading any modules"
done
for mod in "${modules[@]}"; do
$KPATCH load $mod
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog || die "$SCRIPTDIR/$testprog failed after loading modules"
done
for ((idx=${#modules[@]}-1 ; idx>=0 ; idx--)); do
mod=${modules[idx]}
$KPATCH unload $mod
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded after unloading modules"
done
exit 0
source ${SCRIPTDIR}/../common/multiple.template

View File

@ -0,0 +1,74 @@
SCRIPTDIR="$(readlink -f $(dirname $(type -p $0)))"
ROOTDIR="$(readlink -f $SCRIPTDIR/../../..)"
KPATCH="sudo $ROOTDIR/kpatch/kpatch"
MODULE_PREFIX="test-"
MODULE_POSTFIX=".ko"
TEST_POSTFIX="-LOADED.test"
set -o errexit
declare -a loaded_modules
cleanup_modules() {
for ((idx=${#loaded_modules[@]}-1 ; idx>=0 ; idx--)); do
mod=${loaded_modules[idx]}
$KPATCH unload $mod
done
}
die_clean() {
cleanup_modules
exit 1
}
die() {
echo "ERROR: $@" >&2
die_clean
}
ko_to_test() {
tmp=${1%${MODULE_POSTFIX}}${TEST_POSTFIX}
echo ${tmp#${MODULE_PREFIX}}
}
# make sure any modules added here are disjoint
declare -a modules
for file in "${SCRIPTDIR}"/*"${TEST_POSTFIX}"; do
name=$(basename ${file})
skip=0
for bname in "${blacklist[@]}"; do
if [ "${bname}" == "${name}" ]; then
skip=1
break
fi
done
if [ ${skip} -eq 0 ]; then
modules+=(${MODULE_PREFIX}${name%${TEST_POSTFIX}}${MODULE_POSTFIX})
fi
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded before loading any modules"
done
for mod in "${modules[@]}"; do
$KPATCH load $mod || die_clean
loaded_modules+=($mod)
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog || die "$SCRIPTDIR/$testprog failed after loading modules"
done
cleanup_modules
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded after unloading modules"
done
exit 0

View File

@ -1,64 +1,7 @@
#!/bin/bash
SCRIPTDIR="$(readlink -f $(dirname $(type -p $0)))"
ROOTDIR="$(readlink -f $SCRIPTDIR/../../..)"
KPATCH="sudo $ROOTDIR/kpatch/kpatch"
MODULE_PREFIX="test-"
MODULE_POSTFIX=".ko"
TEST_POSTFIX="-LOADED.test"
set -o errexit
die() {
echo "ERROR: $@" >&2
exit 1
}
ko_to_test() {
tmp=${1%${MODULE_POSTFIX}}${TEST_POSTFIX}
echo ${tmp#${MODULE_PREFIX}}
}
# make sure any modules added here are disjoint
declare -a modules
declare -a blacklist=(meminfo-cmdline-rebuild-SLOW-LOADED.test)
for file in "${SCRIPTDIR}"/*"${TEST_POSTFIX}"; do
name=$(basename ${file})
skip=0
for bname in "${blacklist[@]}"; do
if [ "${bname}" == "${name}" ]; then
skip=1
break
fi
done
if [ ${skip} -eq 0 ]; then
modules+=(${MODULE_PREFIX}${name%${TEST_POSTFIX}}${MODULE_POSTFIX})
fi
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded before loading any modules"
done
for mod in "${modules[@]}"; do
$KPATCH load $mod
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog || die "$SCRIPTDIR/$testprog failed after loading modules"
done
for mod in "${modules[@]}"; do
$KPATCH unload $mod
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded after unloading modules"
done
exit 0
source ${SCRIPTDIR}/../common/multiple.template

View File

@ -117,14 +117,7 @@ log() {
}
unload_all() {
for i in `/sbin/lsmod |egrep '^kpatch' |awk '{print $1}'`; do
if [[ $i != kpatch ]]; then
$KPATCH unload $i >> $LOG 2>&1 || error "\"kpatch unload $i\" failed"
fi
done
if /sbin/lsmod |egrep -q '^kpatch'; then
$RMMOD kpatch >> $LOG 2>&1 || error "\"rmmod kpatch\" failed"
fi
$KPATCH unload --all
}
build_module() {

View File

@ -1,64 +1,7 @@
#!/bin/bash
SCRIPTDIR="$(readlink -f $(dirname $(type -p $0)))"
ROOTDIR="$(readlink -f $SCRIPTDIR/../../..)"
KPATCH="sudo $ROOTDIR/kpatch/kpatch"
MODULE_PREFIX="test-"
MODULE_POSTFIX=".ko"
TEST_POSTFIX="-LOADED.test"
set -o errexit
die() {
echo "ERROR: $@" >&2
exit 1
}
ko_to_test() {
tmp=${1%${MODULE_POSTFIX}}${TEST_POSTFIX}
echo ${tmp#${MODULE_PREFIX}}
}
# make sure any modules added here are disjoint
declare -a modules
declare -a blacklist=(meminfo-string-LOADED.test)
for file in "${SCRIPTDIR}"/*"${TEST_POSTFIX}"; do
name=$(basename ${file})
skip=0
for bname in "${blacklist[@]}"; do
if [ "${bname}" == "${name}" ]; then
skip=1
break
fi
done
if [ ${skip} -eq 0 ]; then
modules+=(${MODULE_PREFIX}${name%${TEST_POSTFIX}}${MODULE_POSTFIX})
fi
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded before loading any modules"
done
for mod in "${modules[@]}"; do
$KPATCH load $mod
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog || die "$SCRIPTDIR/$testprog failed after loading modules"
done
for mod in "${modules[@]}"; do
$KPATCH unload $mod
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded after unloading modules"
done
exit 0
source ${SCRIPTDIR}/../common/multiple.template

View File

@ -1,65 +1,7 @@
#!/bin/bash
SCRIPTDIR="$(readlink -f $(dirname $(type -p $0)))"
ROOTDIR="$(readlink -f $SCRIPTDIR/../../..)"
KPATCH="sudo $ROOTDIR/kpatch/kpatch"
MODULE_PREFIX="test-"
MODULE_POSTFIX=".ko"
TEST_POSTFIX="-LOADED.test"
set -o errexit
die() {
echo "ERROR: $@" >&2
exit 1
}
ko_to_test() {
tmp=${1%${MODULE_POSTFIX}}${TEST_POSTFIX}
echo ${tmp#${MODULE_PREFIX}}
}
# make sure any modules added here are disjoint
declare -a modules
declare -a blacklist=(meminfo-string-LOADED.test)
for file in "${SCRIPTDIR}"/*"${TEST_POSTFIX}"; do
name=$(basename ${file})
skip=0
for bname in "${blacklist[@]}"; do
if [ "${bname}" == "${name}" ]; then
skip=1
break
fi
done
if [ ${skip} -eq 0 ]; then
modules+=(${MODULE_PREFIX}${name%${TEST_POSTFIX}}${MODULE_POSTFIX})
fi
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded before loading any modules"
done
for mod in "${modules[@]}"; do
$KPATCH load $mod
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog || die "$SCRIPTDIR/$testprog failed after loading modules"
done
for ((idx=${#modules[@]}-1 ; idx>=0 ; idx--)); do
mod=${modules[idx]}
$KPATCH unload $mod
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded after unloading modules"
done
exit 0
source ${SCRIPTDIR}/../common/multiple.template

View File

@ -1,65 +1,7 @@
#!/bin/bash
SCRIPTDIR="$(readlink -f $(dirname $(type -p $0)))"
ROOTDIR="$(readlink -f $SCRIPTDIR/../../..)"
KPATCH="sudo $ROOTDIR/kpatch/kpatch"
MODULE_PREFIX="test-"
MODULE_POSTFIX=".ko"
TEST_POSTFIX="-LOADED.test"
set -o errexit
die() {
echo "ERROR: $@" >&2
exit 1
}
ko_to_test() {
tmp=${1%${MODULE_POSTFIX}}${TEST_POSTFIX}
echo ${tmp#${MODULE_PREFIX}}
}
# make sure any modules added here are disjoint
declare -a modules
declare -a blacklist=(meminfo-string-LOADED.test)
for file in "${SCRIPTDIR}"/*"${TEST_POSTFIX}"; do
name=$(basename ${file})
skip=0
for bname in "${blacklist[@]}"; do
if [ "${bname}" == "${name}" ]; then
skip=1
break
fi
done
if [ ${skip} -eq 0 ]; then
modules+=(${MODULE_PREFIX}${name%${TEST_POSTFIX}}${MODULE_POSTFIX})
fi
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded before loading any modules"
done
for mod in "${modules[@]}"; do
$KPATCH load $mod
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog || die "$SCRIPTDIR/$testprog failed after loading modules"
done
for ((idx=${#modules[@]}-1 ; idx>=0 ; idx--)); do
mod=${modules[idx]}
$KPATCH unload $mod
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded after unloading modules"
done
exit 0
source ${SCRIPTDIR}/../common/multiple.template

View File

@ -1,65 +1,7 @@
#!/bin/bash
SCRIPTDIR="$(readlink -f $(dirname $(type -p $0)))"
ROOTDIR="$(readlink -f $SCRIPTDIR/../../..)"
KPATCH="sudo $ROOTDIR/kpatch/kpatch"
MODULE_PREFIX="test-"
MODULE_POSTFIX=".ko"
TEST_POSTFIX="-LOADED.test"
set -o errexit
die() {
echo "ERROR: $@" >&2
exit 1
}
ko_to_test() {
tmp=${1%${MODULE_POSTFIX}}${TEST_POSTFIX}
echo ${tmp#${MODULE_PREFIX}}
}
# make sure any modules added here are disjoint
declare -a modules
declare -a blacklist=(meminfo-string-LOADED.test)
for file in "${SCRIPTDIR}"/*"${TEST_POSTFIX}"; do
name=$(basename ${file})
skip=0
for bname in "${blacklist[@]}"; do
if [ "${bname}" == "${name}" ]; then
skip=1
break
fi
done
if [ ${skip} -eq 0 ]; then
modules+=(${MODULE_PREFIX}${name%${TEST_POSTFIX}}${MODULE_POSTFIX})
fi
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded before loading any modules"
done
for mod in "${modules[@]}"; do
$KPATCH load $mod
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog || die "$SCRIPTDIR/$testprog failed after loading modules"
done
for ((idx=${#modules[@]}-1 ; idx>=0 ; idx--)); do
mod=${modules[idx]}
$KPATCH unload $mod
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded after unloading modules"
done
exit 0
source ${SCRIPTDIR}/../common/multiple.template

View File

@ -1,64 +1,7 @@
#!/bin/bash
SCRIPTDIR="$(readlink -f $(dirname $(type -p $0)))"
ROOTDIR="$(readlink -f $SCRIPTDIR/../../..)"
KPATCH="sudo $ROOTDIR/kpatch/kpatch"
MODULE_PREFIX="test-"
MODULE_POSTFIX=".ko"
TEST_POSTFIX="-LOADED.test"
set -o errexit
die() {
echo "ERROR: $@" >&2
exit 1
}
ko_to_test() {
tmp=${1%${MODULE_POSTFIX}}${TEST_POSTFIX}
echo ${tmp#${MODULE_PREFIX}}
}
# make sure any modules added here are disjoint
declare -a modules
declare -a blacklist=(data-new-LOADED.test meminfo-cmdline-rebuild-SLOW-LOADED.test)
for file in "${SCRIPTDIR}"/*"${TEST_POSTFIX}"; do
name=$(basename ${file})
skip=0
for bname in "${blacklist[@]}"; do
if [ "${bname}" == "${name}" ]; then
skip=1
break
fi
done
if [ ${skip} -eq 0 ]; then
modules+=(${MODULE_PREFIX}${name%${TEST_POSTFIX}}${MODULE_POSTFIX})
fi
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded before loading any modules"
done
for mod in "${modules[@]}"; do
$KPATCH load $mod
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog || die "$SCRIPTDIR/$testprog failed after loading modules"
done
for mod in "${modules[@]}"; do
$KPATCH unload $mod
done
for mod in "${modules[@]}"; do
testprog=$(ko_to_test $mod)
$SCRIPTDIR/$testprog && die "$SCRIPTDIR/$testprog succeeded after unloading modules"
done
exit 0
source ${SCRIPTDIR}/../common/multiple.template