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

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

Version: ~ [ linux-5.13-rc5 ] ~ [ linux-5.12.9 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.42 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.124 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.193 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.235 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.271 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.271 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ 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.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0+
  2 //
  3 // Copyright 2019, Michael Ellerman, IBM Corp.
  4 //
  5 // Test that allocating memory beyond the memory limit and then forking is
  6 // handled correctly, ie. the child is able to access the mappings beyond the
  7 // memory limit and the child's writes are not visible to the parent.
  8 
  9 #include <stdio.h>
 10 #include <stdlib.h>
 11 #include <sys/mman.h>
 12 #include <sys/types.h>
 13 #include <sys/wait.h>
 14 #include <unistd.h>
 15 
 16 #include "utils.h"
 17 
 18 
 19 #ifndef MAP_FIXED_NOREPLACE
 20 #define MAP_FIXED_NOREPLACE     MAP_FIXED       // "Should be safe" above 512TB
 21 #endif
 22 
 23 
 24 static int test(void)
 25 {
 26         int p2c[2], c2p[2], rc, status, c, *p;
 27         unsigned long page_size;
 28         pid_t pid;
 29 
 30         page_size = sysconf(_SC_PAGESIZE);
 31         SKIP_IF(page_size != 65536);
 32 
 33         // Create a mapping at 512TB to allocate an extended_id
 34         p = mmap((void *)(512ul << 40), page_size, PROT_READ | PROT_WRITE,
 35                 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE, -1, 0);
 36         if (p == MAP_FAILED) {
 37                 perror("mmap");
 38                 printf("Error: couldn't mmap(), confirm kernel has 4TB support?\n");
 39                 return 1;
 40         }
 41 
 42         printf("parent writing %p = 1\n", p);
 43         *p = 1;
 44 
 45         FAIL_IF(pipe(p2c) == -1 || pipe(c2p) == -1);
 46 
 47         pid = fork();
 48         if (pid == 0) {
 49                 FAIL_IF(read(p2c[0], &c, 1) != 1);
 50 
 51                 pid = getpid();
 52                 printf("child writing  %p = %d\n", p, pid);
 53                 *p = pid;
 54 
 55                 FAIL_IF(write(c2p[1], &c, 1) != 1);
 56                 FAIL_IF(read(p2c[0], &c, 1) != 1);
 57                 exit(0);
 58         }
 59 
 60         c = 0;
 61         FAIL_IF(write(p2c[1], &c, 1) != 1);
 62         FAIL_IF(read(c2p[0], &c, 1) != 1);
 63 
 64         // Prevent compiler optimisation
 65         barrier();
 66 
 67         rc = 0;
 68         printf("parent reading %p = %d\n", p, *p);
 69         if (*p != 1) {
 70                 printf("Error: BUG! parent saw child's write! *p = %d\n", *p);
 71                 rc = 1;
 72         }
 73 
 74         FAIL_IF(write(p2c[1], &c, 1) != 1);
 75         FAIL_IF(waitpid(pid, &status, 0) == -1);
 76         FAIL_IF(!WIFEXITED(status) || WEXITSTATUS(status));
 77 
 78         if (rc == 0)
 79                 printf("success: test completed OK\n");
 80 
 81         return rc;
 82 }
 83 
 84 int main(void)
 85 {
 86         return test_harness(test, "large_vm_fork_separation");
 87 }
 88 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp