xref: /linux/tools/testing/selftests/mm/va_high_addr_switch.sh (revision 23ca32e4ead48f68e37000f2552b973ef1439acb)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Copyright (C) 2022 Adam Sindelar (Meta) <adam@wowsignal.io>
5#
6# This is a test for mmap behavior with 5-level paging. This script wraps the
7# real test to check that the kernel is configured to support at least 5
8# pagetable levels.
9
10# Kselftest framework requirement - SKIP code is 4.
11ksft_skip=4
12
13skip()
14{
15	echo "$1"
16	exit $ksft_skip
17}
18
19check_supported_x86_64()
20{
21	local config="/proc/config.gz"
22	[[ -f "${config}" ]] || config="/boot/config-$(uname -r)"
23	[[ -f "${config}" ]] || skip "Cannot find kernel config in /proc or /boot"
24
25	# gzip -dcfq automatically handles both compressed and plaintext input.
26	# See man 1 gzip under '-f'.
27	local pg_table_levels=$(gzip -dcfq "${config}" | grep PGTABLE_LEVELS | cut -d'=' -f 2)
28
29	local cpu_supports_pl5=$(awk '/^flags/ {if (/la57/) {print 0;}
30		else {print 1}; exit}' /proc/cpuinfo 2>/dev/null)
31
32	if [[ "${pg_table_levels}" -lt 5 ]]; then
33		skip "$0: PGTABLE_LEVELS=${pg_table_levels}, must be >= 5 to run this test"
34	elif [[ "${cpu_supports_pl5}" -ne 0 ]]; then
35		skip "$0: CPU does not have the necessary la57 flag to support page table level 5"
36	fi
37}
38
39check_supported_ppc64()
40{
41	local config="/proc/config.gz"
42	[[ -f "${config}" ]] || config="/boot/config-$(uname -r)"
43	[[ -f "${config}" ]] || skip "Cannot find kernel config in /proc or /boot"
44
45	local pg_table_levels=$(gzip -dcfq "${config}" | grep PGTABLE_LEVELS | cut -d'=' -f 2)
46	if [[ "${pg_table_levels}" -lt 5 ]]; then
47		skip "$0: PGTABLE_LEVELS=${pg_table_levels}, must be >= 5 to run this test"
48	fi
49
50	local mmu_support=$(grep -m1 "mmu" /proc/cpuinfo | awk '{print $3}')
51	if [[ "$mmu_support" != "radix" ]]; then
52		skip "$0: System does not use Radix MMU, required for 5-level paging"
53	fi
54
55	local hugepages_total=$(awk '/HugePages_Total/ {print $2}' /proc/meminfo)
56	if [[ "${hugepages_total}" -eq 0 ]]; then
57		skip "$0: HugePages are not enabled, required for some tests"
58	fi
59}
60
61check_test_requirements()
62{
63	# The test supports x86_64 and powerpc64. We currently have no useful
64	# eligibility check for powerpc64, and the test itself will reject other
65	# architectures.
66	case `uname -m` in
67		"x86_64")
68			check_supported_x86_64
69		;;
70		"ppc64le"|"ppc64")
71			check_supported_ppc64
72		;;
73		*)
74			return 0
75		;;
76	esac
77}
78
79check_test_requirements
80./va_high_addr_switch --run-hugetlb
81