~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <stdio.h>
  3 #include <sys/mman.h>
  4 #include <unistd.h>
  5 
  6 #include "utils.h"
  7 
  8 /* This must match the huge page & THP size */
  9 #define SIZE    (16 * 1024 * 1024)
 10 
 11 static int test_body(void)
 12 {
 13         void *addr;
 14         char *p;
 15 
 16         addr = (void *)0xa0000000;
 17 
 18         p = mmap(addr, SIZE, PROT_READ | PROT_WRITE,
 19                  MAP_HUGETLB | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
 20         if (p != MAP_FAILED) {
 21                 /*
 22                  * Typically the mmap will fail because no huge pages are
 23                  * allocated on the system. But if there are huge pages
 24                  * allocated the mmap will succeed. That's fine too, we just
 25                  * munmap here before continuing.  munmap() length of
 26                  * MAP_HUGETLB memory must be hugepage aligned.
 27                  */
 28                 if (munmap(addr, SIZE)) {
 29                         perror("munmap");
 30                         return 1;
 31                 }
 32         }
 33 
 34         p = mmap(addr, SIZE, PROT_READ | PROT_WRITE,
 35                  MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
 36         if (p == MAP_FAILED) {
 37                 printf("Mapping failed @ %p\n", addr);
 38                 perror("mmap");
 39                 return 1;
 40         }
 41 
 42         /*
 43          * Either a user or kernel access is sufficient to trigger the bug.
 44          * A kernel access is easier to spot & debug, as it will trigger the
 45          * softlockup or RCU stall detectors, and when the system is kicked
 46          * into xmon we get a backtrace in the kernel.
 47          *
 48          * A good option is:
 49          *  getcwd(p, SIZE);
 50          *
 51          * For the purposes of this testcase it's preferable to spin in
 52          * userspace, so the harness can kill us if we get stuck. That way we
 53          * see a test failure rather than a dead system.
 54          */
 55         *p = 0xf;
 56 
 57         munmap(addr, SIZE);
 58 
 59         return 0;
 60 }
 61 
 62 static int test_main(void)
 63 {
 64         int i;
 65 
 66         /* 10,000 because it's a "bunch", and completes reasonably quickly */
 67         for (i = 0; i < 10000; i++)
 68                 if (test_body())
 69                         return 1;
 70 
 71         return 0;
 72 }
 73 
 74 int main(void)
 75 {
 76         return test_harness(test_main, "hugetlb_vs_thp");
 77 }
 78 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php