Files
linux/tools/testing/selftests/kvm/x86/nx_huge_pages_test.sh
Sean Christopherson 67730e6c53 KVM: selftests: Use canonical $(ARCH) paths for KVM selftests directories
Use the kernel's canonical $(ARCH) paths instead of the raw target triple
for KVM selftests directories.  KVM selftests are quite nearly the only
place in the entire kernel that using the target triple for directories,
tools/testing/selftests/drivers/s390x being the lone holdout.

Using the kernel's preferred nomenclature eliminates the minor, but
annoying, friction of having to translate to KVM's selftests directories,
e.g. for pattern matching, opening files, running selftests, etc.

Opportunsitically delete file comments that reference the full path of the
file, as they are obviously prone to becoming stale, and serve no known
purpose.

Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Acked-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Acked-by: Andrew Jones <ajones@ventanamicro.com>
Link: https://lore.kernel.org/r/20241128005547.4077116-16-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
2024-12-18 14:15:04 -08:00

70 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-only */
#
# Wrapper script which performs setup and cleanup for nx_huge_pages_test.
# Makes use of root privileges to set up huge pages and KVM module parameters.
#
# Copyright (C) 2022, Google LLC.
set -e
NX_HUGE_PAGES=$(cat /sys/module/kvm/parameters/nx_huge_pages)
NX_HUGE_PAGES_RECOVERY_RATIO=$(cat /sys/module/kvm/parameters/nx_huge_pages_recovery_ratio)
NX_HUGE_PAGES_RECOVERY_PERIOD=$(cat /sys/module/kvm/parameters/nx_huge_pages_recovery_period_ms)
HUGE_PAGES=$(cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages)
# If we're already root, the host might not have sudo.
if [ $(whoami) == "root" ]; then
function do_sudo () {
"$@"
}
else
function do_sudo () {
sudo "$@"
}
fi
set +e
function sudo_echo () {
echo "$1" | do_sudo tee -a "$2" > /dev/null
}
NXECUTABLE="$(dirname $0)/nx_huge_pages_test"
sudo_echo test /dev/null || exit 4 # KSFT_SKIP=4
(
set -e
sudo_echo 1 /sys/module/kvm/parameters/nx_huge_pages
sudo_echo 1 /sys/module/kvm/parameters/nx_huge_pages_recovery_ratio
sudo_echo 100 /sys/module/kvm/parameters/nx_huge_pages_recovery_period_ms
sudo_echo "$(( $HUGE_PAGES + 3 ))" /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
# Test with reboot permissions
if [ $(whoami) == "root" ] || sudo setcap cap_sys_boot+ep $NXECUTABLE 2> /dev/null; then
echo Running test with CAP_SYS_BOOT enabled
$NXECUTABLE -t 887563923 -p 100 -r
test $(whoami) == "root" || sudo setcap cap_sys_boot-ep $NXECUTABLE
else
echo setcap failed, skipping nx_huge_pages_test with CAP_SYS_BOOT enabled
fi
# Test without reboot permissions
if [ $(whoami) != "root" ] ; then
echo Running test with CAP_SYS_BOOT disabled
$NXECUTABLE -t 887563923 -p 100
else
echo Running as root, skipping nx_huge_pages_test with CAP_SYS_BOOT disabled
fi
)
RET=$?
sudo_echo "$NX_HUGE_PAGES" /sys/module/kvm/parameters/nx_huge_pages
sudo_echo "$NX_HUGE_PAGES_RECOVERY_RATIO" /sys/module/kvm/parameters/nx_huge_pages_recovery_ratio
sudo_echo "$NX_HUGE_PAGES_RECOVERY_PERIOD" /sys/module/kvm/parameters/nx_huge_pages_recovery_period_ms
sudo_echo "$HUGE_PAGES" /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
exit $RET