mirror of
https://github.com/torvalds/linux.git
synced 2026-04-19 15:24:02 -04:00
Patch series "liveupdate: Rework KHO for in-kernel users", v9. This series refactors the KHO framework to better support in-kernel users like the upcoming LUO. The current design, which relies on a notifier chain and debugfs for control, is too restrictive for direct programmatic use. The core of this rework is the removal of the notifier chain in favor of a direct registration API. This decouples clients from the shutdown-time finalization sequence, allowing them to manage their preserved state more flexibly and at any time. In support of this new model, this series also: - Makes the debugfs interface optional. - Introduces APIs to unpreserve memory and fixes a bug in the abort path where client state was being incorrectly discarded. Note that this is an interim step, as a more comprehensive fix is planned as part of the stateless KHO work [1]. - Moves all KHO code into a new kernel/liveupdate/ directory to consolidate live update components. This patch (of 9): Currently, KHO is controlled via debugfs interface, but once LUO is introduced, it can control KHO, and the debug interface becomes optional. Add a separate config CONFIG_KEXEC_HANDOVER_DEBUGFS that enables the debugfs interface, and allows to inspect the tree. Move all debugfs related code to a new file to keep the .c files clear of ifdefs. Link: https://lkml.kernel.org/r/20251101142325.1326536-1-pasha.tatashin@soleen.com Link: https://lkml.kernel.org/r/20251101142325.1326536-2-pasha.tatashin@soleen.com Link: https://lore.kernel.org/all/20251020100306.2709352-1-jasonmiu@google.com [1] Co-developed-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com> Reviewed-by: Pratyush Yadav <pratyush@kernel.org> Cc: Alexander Graf <graf@amazon.com> Cc: Christian Brauner <brauner@kernel.org> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Masahiro Yamada <masahiroy@kernel.org> Cc: Miguel Ojeda <ojeda@kernel.org> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: Tejun Heo <tj@kernel.org> Cc: Changyuan Lyu <changyuanl@google.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Simon Horman <horms@kernel.org> Cc: Zhu Yanjun <yanjun.zhu@linux.dev> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
187 lines
3.9 KiB
Bash
Executable File
187 lines
3.9 KiB
Bash
Executable File
#!/bin/bash
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
set -ue
|
|
|
|
CROSS_COMPILE="${CROSS_COMPILE:-""}"
|
|
|
|
test_dir=$(realpath "$(dirname "$0")")
|
|
kernel_dir=$(realpath "$test_dir/../../../..")
|
|
|
|
tmp_dir=$(mktemp -d /tmp/kho-test.XXXXXXXX)
|
|
headers_dir="$tmp_dir/usr"
|
|
initrd="$tmp_dir/initrd.cpio"
|
|
|
|
source "$test_dir/../kselftest/ktap_helpers.sh"
|
|
|
|
function usage() {
|
|
cat <<EOF
|
|
$0 [-d build_dir] [-j jobs] [-t target_arch] [-h]
|
|
Options:
|
|
-d) path to the kernel build directory
|
|
-j) number of jobs for compilation, similar to -j in make
|
|
-t) run test for target_arch, requires CROSS_COMPILE set
|
|
supported targets: aarch64, x86_64
|
|
-h) display this help
|
|
EOF
|
|
}
|
|
|
|
function cleanup() {
|
|
rm -fr "$tmp_dir"
|
|
ktap_finished
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
function skip() {
|
|
local msg=${1:-""}
|
|
|
|
ktap_test_skip "$msg"
|
|
exit "$KSFT_SKIP"
|
|
}
|
|
|
|
function fail() {
|
|
local msg=${1:-""}
|
|
|
|
ktap_test_fail "$msg"
|
|
exit "$KSFT_FAIL"
|
|
}
|
|
|
|
function build_kernel() {
|
|
local build_dir=$1
|
|
local make_cmd=$2
|
|
local arch_kconfig=$3
|
|
local kimage=$4
|
|
|
|
local kho_config="$tmp_dir/kho.config"
|
|
local kconfig="$build_dir/.config"
|
|
|
|
# enable initrd, KHO and KHO test in kernel configuration
|
|
tee "$kconfig" > "$kho_config" <<EOF
|
|
CONFIG_BLK_DEV_INITRD=y
|
|
CONFIG_KEXEC_HANDOVER=y
|
|
CONFIG_KEXEC_HANDOVER_DEBUGFS=y
|
|
CONFIG_TEST_KEXEC_HANDOVER=y
|
|
CONFIG_DEBUG_KERNEL=y
|
|
CONFIG_DEBUG_VM=y
|
|
$arch_kconfig
|
|
EOF
|
|
|
|
make_cmd="$make_cmd -C $kernel_dir O=$build_dir"
|
|
$make_cmd olddefconfig
|
|
|
|
# verify that kernel confiration has all necessary options
|
|
while read -r opt ; do
|
|
grep "$opt" "$kconfig" &>/dev/null || skip "$opt is missing"
|
|
done < "$kho_config"
|
|
|
|
$make_cmd "$kimage"
|
|
$make_cmd headers_install INSTALL_HDR_PATH="$headers_dir"
|
|
}
|
|
|
|
function mkinitrd() {
|
|
local kernel=$1
|
|
|
|
"$CROSS_COMPILE"gcc -s -static -Os -nostdinc -nostdlib \
|
|
-fno-asynchronous-unwind-tables -fno-ident \
|
|
-I "$headers_dir/include" \
|
|
-I "$kernel_dir/tools/include/nolibc" \
|
|
-o "$tmp_dir/init" "$test_dir/init.c"
|
|
|
|
cat > "$tmp_dir/cpio_list" <<EOF
|
|
dir /dev 0755 0 0
|
|
dir /proc 0755 0 0
|
|
dir /debugfs 0755 0 0
|
|
nod /dev/console 0600 0 0 c 5 1
|
|
file /init $tmp_dir/init 0755 0 0
|
|
file /kernel $kernel 0644 0 0
|
|
EOF
|
|
|
|
"$build_dir/usr/gen_init_cpio" "$tmp_dir/cpio_list" > "$initrd"
|
|
}
|
|
|
|
function run_qemu() {
|
|
local qemu_cmd=$1
|
|
local cmdline=$2
|
|
local kernel=$3
|
|
local serial="$tmp_dir/qemu.serial"
|
|
|
|
cmdline="$cmdline kho=on panic=-1"
|
|
|
|
$qemu_cmd -m 1G -smp 2 -no-reboot -nographic -nodefaults \
|
|
-accel kvm -accel hvf -accel tcg \
|
|
-serial file:"$serial" \
|
|
-append "$cmdline" \
|
|
-kernel "$kernel" \
|
|
-initrd "$initrd"
|
|
|
|
grep "KHO restore succeeded" "$serial" &> /dev/null || fail "KHO failed"
|
|
}
|
|
|
|
function target_to_arch() {
|
|
local target=$1
|
|
|
|
case $target in
|
|
aarch64) echo "arm64" ;;
|
|
x86_64) echo "x86" ;;
|
|
*) skip "architecture $target is not supported"
|
|
esac
|
|
}
|
|
|
|
function main() {
|
|
local build_dir="$kernel_dir/.kho"
|
|
local jobs=$(($(nproc) * 2))
|
|
local target="$(uname -m)"
|
|
|
|
# skip the test if any of the preparation steps fails
|
|
set -o errtrace
|
|
trap skip ERR
|
|
|
|
while getopts 'hd:j:t:' opt; do
|
|
case $opt in
|
|
d)
|
|
build_dir="$OPTARG"
|
|
;;
|
|
j)
|
|
jobs="$OPTARG"
|
|
;;
|
|
t)
|
|
target="$OPTARG"
|
|
;;
|
|
h)
|
|
usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo Unknown argument "$opt"
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
ktap_print_header
|
|
ktap_set_plan 1
|
|
|
|
if [[ "$target" != "$(uname -m)" ]] && [[ -z "$CROSS_COMPILE" ]]; then
|
|
skip "Cross-platform testing needs to specify CROSS_COMPILE"
|
|
fi
|
|
|
|
mkdir -p "$build_dir"
|
|
local arch=$(target_to_arch "$target")
|
|
source "$test_dir/$arch.conf"
|
|
|
|
# build the kernel and create initrd
|
|
# initrd includes the kernel image that will be kexec'ed
|
|
local make_cmd="make ARCH=$arch CROSS_COMPILE=$CROSS_COMPILE -j$jobs"
|
|
build_kernel "$build_dir" "$make_cmd" "$QEMU_KCONFIG" "$KERNEL_IMAGE"
|
|
|
|
local kernel="$build_dir/arch/$arch/boot/$KERNEL_IMAGE"
|
|
mkinitrd "$kernel"
|
|
|
|
run_qemu "$QEMU_CMD" "$KERNEL_CMDLINE" "$kernel"
|
|
|
|
ktap_test_pass "KHO succeeded"
|
|
}
|
|
|
|
main "$@"
|