1bbe16872SChaitanya S Prakash#!/bin/bash 2bbe16872SChaitanya S Prakash# SPDX-License-Identifier: GPL-2.0 3bbe16872SChaitanya S Prakash# 4bbe16872SChaitanya S Prakash# Copyright (C) 2022 Adam Sindelar (Meta) <adam@wowsignal.io> 5bbe16872SChaitanya S Prakash# 6bbe16872SChaitanya S Prakash# This is a test for mmap behavior with 5-level paging. This script wraps the 7bbe16872SChaitanya S Prakash# real test to check that the kernel is configured to support at least 5 8bbe16872SChaitanya S Prakash# pagetable levels. 9bbe16872SChaitanya S Prakash 10bbe16872SChaitanya S Prakash# 1 means the test failed 11bbe16872SChaitanya S Prakashexitcode=1 12bbe16872SChaitanya S Prakash 13bbe16872SChaitanya S Prakash# Kselftest framework requirement - SKIP code is 4. 14bbe16872SChaitanya S Prakashksft_skip=4 15bbe16872SChaitanya S Prakash 16bbe16872SChaitanya S Prakashfail() 17bbe16872SChaitanya S Prakash{ 18bbe16872SChaitanya S Prakash echo "$1" 19bbe16872SChaitanya S Prakash exit $exitcode 20bbe16872SChaitanya S Prakash} 21bbe16872SChaitanya S Prakash 22bbe16872SChaitanya S Prakashcheck_supported_x86_64() 23bbe16872SChaitanya S Prakash{ 24bbe16872SChaitanya S Prakash local config="/proc/config.gz" 25bbe16872SChaitanya S Prakash [[ -f "${config}" ]] || config="/boot/config-$(uname -r)" 26bbe16872SChaitanya S Prakash [[ -f "${config}" ]] || fail "Cannot find kernel config in /proc or /boot" 27bbe16872SChaitanya S Prakash 28bbe16872SChaitanya S Prakash # gzip -dcfq automatically handles both compressed and plaintext input. 29bbe16872SChaitanya S Prakash # See man 1 gzip under '-f'. 30bbe16872SChaitanya S Prakash local pg_table_levels=$(gzip -dcfq "${config}" | grep PGTABLE_LEVELS | cut -d'=' -f 2) 31bbe16872SChaitanya S Prakash 32*8f02931eSAudra Mitchell local cpu_supports_pl5=$(awk '/^flags/ {if (/la57/) {print 0;} 33*8f02931eSAudra Mitchell else {print 1}; exit}' /proc/cpuinfo 2>/dev/null) 34*8f02931eSAudra Mitchell 35bbe16872SChaitanya S Prakash if [[ "${pg_table_levels}" -lt 5 ]]; then 36bbe16872SChaitanya S Prakash echo "$0: PGTABLE_LEVELS=${pg_table_levels}, must be >= 5 to run this test" 37bbe16872SChaitanya S Prakash exit $ksft_skip 38*8f02931eSAudra Mitchell elif [[ "${cpu_supports_pl5}" -ne 0 ]]; then 39*8f02931eSAudra Mitchell echo "$0: CPU does not have the necessary la57 flag to support page table level 5" 40*8f02931eSAudra Mitchell exit $ksft_skip 41bbe16872SChaitanya S Prakash fi 42bbe16872SChaitanya S Prakash} 43bbe16872SChaitanya S Prakash 44bbe16872SChaitanya S Prakashcheck_test_requirements() 45bbe16872SChaitanya S Prakash{ 46bbe16872SChaitanya S Prakash # The test supports x86_64 and powerpc64. We currently have no useful 47bbe16872SChaitanya S Prakash # eligibility check for powerpc64, and the test itself will reject other 48bbe16872SChaitanya S Prakash # architectures. 49bbe16872SChaitanya S Prakash case `uname -m` in 50bbe16872SChaitanya S Prakash "x86_64") 51bbe16872SChaitanya S Prakash check_supported_x86_64 52bbe16872SChaitanya S Prakash ;; 53bbe16872SChaitanya S Prakash *) 54bbe16872SChaitanya S Prakash return 0 55bbe16872SChaitanya S Prakash ;; 56bbe16872SChaitanya S Prakash esac 57bbe16872SChaitanya S Prakash} 58bbe16872SChaitanya S Prakash 59bbe16872SChaitanya S Prakashcheck_test_requirements 60bbe16872SChaitanya S Prakash./va_high_addr_switch 61c025da0fSChaitanya S Prakash 62c025da0fSChaitanya S Prakash# In order to run hugetlb testcases, "--run-hugetlb" must be appended 63c025da0fSChaitanya S Prakash# to the binary. 64c025da0fSChaitanya S Prakash./va_high_addr_switch --run-hugetlb 65