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 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 echo $(( $lackpgs + $nr_hugepgs )) > /proc/sys/vm/nr_hugepages 40 if [ $? -ne 0 ]; then 41 echo "Please run this test as root" 42 exit $ksft_skip 43 fi 44 while read name size unit; do 45 if [ "$name" = "HugePages_Free:" ]; then 46 freepgs=$size 47 fi 48 done < /proc/meminfo 49 tries=$((tries - 1)) 50 done 51 if [ $freepgs -lt $needpgs ]; then 52 printf "Not enough huge pages available (%d < %d)\n" \ 53 $freepgs $needpgs 54 exit 1 55 fi 56else 57 echo "no hugetlbfs support in kernel?" 58 exit 1 59fi 60 61#filter 64bit architectures 62ARCH64STR="arm64 ia64 mips64 parisc64 ppc64 ppc64le riscv64 s390x sh64 sparc64 x86_64" 63if [ -z $ARCH ]; then 64 ARCH=`uname -m 2>/dev/null | sed -e 's/aarch64.*/arm64/'` 65fi 66VADDR64=0 67echo "$ARCH64STR" | grep $ARCH && VADDR64=1 68 69mkdir $mnt 70mount -t hugetlbfs none $mnt 71 72echo "---------------------" 73echo "running hugepage-mmap" 74echo "---------------------" 75./hugepage-mmap 76if [ $? -ne 0 ]; then 77 echo "[FAIL]" 78 exitcode=1 79else 80 echo "[PASS]" 81fi 82 83shmmax=`cat /proc/sys/kernel/shmmax` 84shmall=`cat /proc/sys/kernel/shmall` 85echo 268435456 > /proc/sys/kernel/shmmax 86echo 4194304 > /proc/sys/kernel/shmall 87echo "--------------------" 88echo "running hugepage-shm" 89echo "--------------------" 90./hugepage-shm 91if [ $? -ne 0 ]; then 92 echo "[FAIL]" 93 exitcode=1 94else 95 echo "[PASS]" 96fi 97echo $shmmax > /proc/sys/kernel/shmmax 98echo $shmall > /proc/sys/kernel/shmall 99 100echo "-------------------" 101echo "running map_hugetlb" 102echo "-------------------" 103./map_hugetlb 104if [ $? -ne 0 ]; then 105 echo "[FAIL]" 106 exitcode=1 107else 108 echo "[PASS]" 109fi 110 111echo "NOTE: The above hugetlb tests provide minimal coverage. Use" 112echo " https://github.com/libhugetlbfs/libhugetlbfs.git for" 113echo " hugetlb regression testing." 114 115echo "---------------------------" 116echo "running map_fixed_noreplace" 117echo "---------------------------" 118./map_fixed_noreplace 119if [ $? -ne 0 ]; then 120 echo "[FAIL]" 121 exitcode=1 122else 123 echo "[PASS]" 124fi 125 126echo "--------------------------------------------" 127echo "running 'gup_benchmark -U' (normal/slow gup)" 128echo "--------------------------------------------" 129./gup_benchmark -U 130if [ $? -ne 0 ]; then 131 echo "[FAIL]" 132 exitcode=1 133else 134 echo "[PASS]" 135fi 136 137echo "------------------------------------------" 138echo "running gup_benchmark -b (pin_user_pages)" 139echo "------------------------------------------" 140./gup_benchmark -b 141if [ $? -ne 0 ]; then 142 echo "[FAIL]" 143 exitcode=1 144else 145 echo "[PASS]" 146fi 147 148echo "-------------------" 149echo "running userfaultfd" 150echo "-------------------" 151./userfaultfd anon 128 32 152if [ $? -ne 0 ]; then 153 echo "[FAIL]" 154 exitcode=1 155else 156 echo "[PASS]" 157fi 158 159echo "---------------------------" 160echo "running userfaultfd_hugetlb" 161echo "---------------------------" 162# Test requires source and destination huge pages. Size of source 163# (half_ufd_size_MB) is passed as argument to test. 164./userfaultfd hugetlb $half_ufd_size_MB 32 $mnt/ufd_test_file 165if [ $? -ne 0 ]; then 166 echo "[FAIL]" 167 exitcode=1 168else 169 echo "[PASS]" 170fi 171rm -f $mnt/ufd_test_file 172 173echo "-------------------------" 174echo "running userfaultfd_shmem" 175echo "-------------------------" 176./userfaultfd shmem 128 32 177if [ $? -ne 0 ]; then 178 echo "[FAIL]" 179 exitcode=1 180else 181 echo "[PASS]" 182fi 183 184#cleanup 185umount $mnt 186rm -rf $mnt 187echo $nr_hugepgs > /proc/sys/vm/nr_hugepages 188 189echo "-----------------------" 190echo "running compaction_test" 191echo "-----------------------" 192./compaction_test 193if [ $? -ne 0 ]; then 194 echo "[FAIL]" 195 exitcode=1 196else 197 echo "[PASS]" 198fi 199 200echo "----------------------" 201echo "running on-fault-limit" 202echo "----------------------" 203sudo -u nobody ./on-fault-limit 204if [ $? -ne 0 ]; then 205 echo "[FAIL]" 206 exitcode=1 207else 208 echo "[PASS]" 209fi 210 211echo "--------------------" 212echo "running map_populate" 213echo "--------------------" 214./map_populate 215if [ $? -ne 0 ]; then 216 echo "[FAIL]" 217 exitcode=1 218else 219 echo "[PASS]" 220fi 221 222echo "-------------------------" 223echo "running mlock-random-test" 224echo "-------------------------" 225./mlock-random-test 226if [ $? -ne 0 ]; then 227 echo "[FAIL]" 228 exitcode=1 229else 230 echo "[PASS]" 231fi 232 233echo "--------------------" 234echo "running mlock2-tests" 235echo "--------------------" 236./mlock2-tests 237if [ $? -ne 0 ]; then 238 echo "[FAIL]" 239 exitcode=1 240else 241 echo "[PASS]" 242fi 243 244echo "-----------------" 245echo "running thuge-gen" 246echo "-----------------" 247./thuge-gen 248if [ $? -ne 0 ]; then 249 echo "[FAIL]" 250 exitcode=1 251else 252 echo "[PASS]" 253fi 254 255if [ $VADDR64 -ne 0 ]; then 256echo "-----------------------------" 257echo "running virtual_address_range" 258echo "-----------------------------" 259./virtual_address_range 260if [ $? -ne 0 ]; then 261 echo "[FAIL]" 262 exitcode=1 263else 264 echo "[PASS]" 265fi 266 267echo "-----------------------------" 268echo "running virtual address 128TB switch test" 269echo "-----------------------------" 270./va_128TBswitch 271if [ $? -ne 0 ]; then 272 echo "[FAIL]" 273 exitcode=1 274else 275 echo "[PASS]" 276fi 277fi # VADDR64 278 279echo "------------------------------------" 280echo "running vmalloc stability smoke test" 281echo "------------------------------------" 282./test_vmalloc.sh smoke 283ret_val=$? 284 285if [ $ret_val -eq 0 ]; then 286 echo "[PASS]" 287elif [ $ret_val -eq $ksft_skip ]; then 288 echo "[SKIP]" 289 exitcode=$ksft_skip 290else 291 echo "[FAIL]" 292 exitcode=1 293fi 294 295echo "------------------------------------" 296echo "running MREMAP_DONTUNMAP smoke test" 297echo "------------------------------------" 298./mremap_dontunmap 299ret_val=$? 300 301if [ $ret_val -eq 0 ]; then 302 echo "[PASS]" 303elif [ $ret_val -eq $ksft_skip ]; then 304 echo "[SKIP]" 305 exitcode=$ksft_skip 306else 307 echo "[FAIL]" 308 exitcode=1 309fi 310 311echo "running HMM smoke test" 312echo "------------------------------------" 313./test_hmm.sh smoke 314ret_val=$? 315 316if [ $ret_val -eq 0 ]; then 317 echo "[PASS]" 318elif [ $ret_val -eq $ksft_skip ]; then 319 echo "[SKIP]" 320 exitcode=$ksft_skip 321else 322 echo "[FAIL]" 323 exitcode=1 324fi 325 326exit $exitcode 327