cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

run_vmtests.sh (4634B)


      1#!/bin/bash
      2# SPDX-License-Identifier: GPL-2.0
      3#please run as root
      4
      5# Kselftest framework requirement - SKIP code is 4.
      6ksft_skip=4
      7
      8mnt=./huge
      9exitcode=0
     10
     11#get huge pagesize and freepages from /proc/meminfo
     12while read -r name size unit; do
     13	if [ "$name" = "HugePages_Free:" ]; then
     14		freepgs="$size"
     15	fi
     16	if [ "$name" = "Hugepagesize:" ]; then
     17		hpgsize_KB="$size"
     18	fi
     19done < /proc/meminfo
     20
     21# Simple hugetlbfs tests have a hardcoded minimum requirement of
     22# huge pages totaling 256MB (262144KB) in size.  The userfaultfd
     23# hugetlb test requires a minimum of 2 * nr_cpus huge pages.  Take
     24# both of these requirements into account and attempt to increase
     25# number of huge pages available.
     26nr_cpus=$(nproc)
     27hpgsize_MB=$((hpgsize_KB / 1024))
     28half_ufd_size_MB=$((((nr_cpus * hpgsize_MB + 127) / 128) * 128))
     29needmem_KB=$((half_ufd_size_MB * 2 * 1024))
     30
     31#set proper nr_hugepages
     32if [ -n "$freepgs" ] && [ -n "$hpgsize_KB" ]; then
     33	nr_hugepgs=$(cat /proc/sys/vm/nr_hugepages)
     34	needpgs=$((needmem_KB / hpgsize_KB))
     35	tries=2
     36	while [ "$tries" -gt 0 ] && [ "$freepgs" -lt "$needpgs" ]; do
     37		lackpgs=$((needpgs - freepgs))
     38		echo 3 > /proc/sys/vm/drop_caches
     39		if ! echo $((lackpgs + nr_hugepgs)) > /proc/sys/vm/nr_hugepages; then
     40			echo "Please run this test as root"
     41			exit $ksft_skip
     42		fi
     43		while read -r name size unit; do
     44			if [ "$name" = "HugePages_Free:" ]; then
     45				freepgs=$size
     46			fi
     47		done < /proc/meminfo
     48		tries=$((tries - 1))
     49	done
     50	if [ "$freepgs" -lt "$needpgs" ]; then
     51		printf "Not enough huge pages available (%d < %d)\n" \
     52		       "$freepgs" "$needpgs"
     53		exit 1
     54	fi
     55else
     56	echo "no hugetlbfs support in kernel?"
     57	exit 1
     58fi
     59
     60#filter 64bit architectures
     61ARCH64STR="arm64 ia64 mips64 parisc64 ppc64 ppc64le riscv64 s390x sh64 sparc64 x86_64"
     62if [ -z "$ARCH" ]; then
     63	ARCH=$(uname -m 2>/dev/null | sed -e 's/aarch64.*/arm64/')
     64fi
     65VADDR64=0
     66echo "$ARCH64STR" | grep "$ARCH" && VADDR64=1
     67
     68# Usage: run_test [test binary] [arbitrary test arguments...]
     69run_test() {
     70	local title="running $*"
     71	local sep=$(echo -n "$title" | tr "[:graph:][:space:]" -)
     72	printf "%s\n%s\n%s\n" "$sep" "$title" "$sep"
     73
     74	"$@"
     75	local ret=$?
     76	if [ $ret -eq 0 ]; then
     77		echo "[PASS]"
     78	elif [ $ret -eq $ksft_skip ]; then
     79		echo "[SKIP]"
     80		exitcode=$ksft_skip
     81	else
     82		echo "[FAIL]"
     83		exitcode=1
     84	fi
     85}
     86
     87mkdir "$mnt"
     88mount -t hugetlbfs none "$mnt"
     89
     90run_test ./hugepage-mmap
     91
     92shmmax=$(cat /proc/sys/kernel/shmmax)
     93shmall=$(cat /proc/sys/kernel/shmall)
     94echo 268435456 > /proc/sys/kernel/shmmax
     95echo 4194304 > /proc/sys/kernel/shmall
     96run_test ./hugepage-shm
     97echo "$shmmax" > /proc/sys/kernel/shmmax
     98echo "$shmall" > /proc/sys/kernel/shmall
     99
    100run_test ./map_hugetlb
    101
    102run_test ./hugepage-mremap "$mnt"/huge_mremap
    103rm -f "$mnt"/huge_mremap
    104
    105run_test ./hugepage-vmemmap
    106
    107run_test ./hugetlb-madvise "$mnt"/madvise-test
    108rm -f "$mnt"/madvise-test
    109
    110echo "NOTE: The above hugetlb tests provide minimal coverage.  Use"
    111echo "      https://github.com/libhugetlbfs/libhugetlbfs.git for"
    112echo "      hugetlb regression testing."
    113
    114run_test ./map_fixed_noreplace
    115
    116# get_user_pages_fast() benchmark
    117run_test ./gup_test -u
    118# pin_user_pages_fast() benchmark
    119run_test ./gup_test -a
    120# Dump pages 0, 19, and 4096, using pin_user_pages:
    121run_test ./gup_test -ct -F 0x1 0 19 0x1000
    122
    123run_test ./userfaultfd anon 20 16
    124# Test requires source and destination huge pages.  Size of source
    125# (half_ufd_size_MB) is passed as argument to test.
    126run_test ./userfaultfd hugetlb "$half_ufd_size_MB" 32
    127run_test ./userfaultfd shmem 20 16
    128
    129#cleanup
    130umount "$mnt"
    131rm -rf "$mnt"
    132echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages
    133
    134run_test ./compaction_test
    135
    136run_test sudo -u nobody ./on-fault-limit
    137
    138run_test ./map_populate
    139
    140run_test ./mlock-random-test
    141
    142run_test ./mlock2-tests
    143
    144run_test ./mrelease_test
    145
    146run_test ./mremap_test
    147
    148run_test ./thuge-gen
    149
    150if [ $VADDR64 -ne 0 ]; then
    151	run_test ./virtual_address_range
    152
    153	# virtual address 128TB switch test
    154	run_test ./va_128TBswitch
    155fi # VADDR64
    156
    157# vmalloc stability smoke test
    158run_test ./test_vmalloc.sh smoke
    159
    160run_test ./mremap_dontunmap
    161
    162run_test ./test_hmm.sh smoke
    163
    164# MADV_POPULATE_READ and MADV_POPULATE_WRITE tests
    165run_test ./madv_populate
    166
    167run_test ./memfd_secret
    168
    169# KSM MADV_MERGEABLE test with 10 identical pages
    170run_test ./ksm_tests -M -p 10
    171# KSM unmerge test
    172run_test ./ksm_tests -U
    173# KSM test with 10 zero pages and use_zero_pages = 0
    174run_test ./ksm_tests -Z -p 10 -z 0
    175# KSM test with 10 zero pages and use_zero_pages = 1
    176run_test ./ksm_tests -Z -p 10 -z 1
    177# KSM test with 2 NUMA nodes and merge_across_nodes = 1
    178run_test ./ksm_tests -N -m 1
    179# KSM test with 2 NUMA nodes and merge_across_nodes = 0
    180run_test ./ksm_tests -N -m 0
    181
    182exit $exitcode