1#!/bin/sh 2 3# 4# Copyright (c) 2015 EMC Corp. 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26# SUCH DAMAGE. 27# 28 29# Regression test for r287591: 30 31# From the commit log: 32# Remove a check which caused spurious SIGSEGV on usermode access to the 33# mapped address without valid pte installed, when parallel wiring of 34# the entry happen. The entry must be copy on write. If entry is COW 35# but was already copied, and parallel wiring set 36# MAP_ENTRY_IN_TRANSITION, vm_fault() would sleep waiting for the 37# MAP_ENTRY_IN_TRANSITION flag to clear. After that, the fault handler 38# is restarted and vm_map_lookup() or vm_map_lookup_locked() trip over 39# the check. Note that this is race, if the address is accessed after 40# the wiring is done, the entry does not fault at all. 41 42# Test scenario by kib@. 43 44. ../default.cfg 45 46[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 47 48dir=/tmp 49odir=`pwd` 50cd $dir 51sed '1,/^EOF/d' < $odir/$0 > $dir/mlockall5.c 52mycc -o mlockall5 -Wall -Wextra -O0 -g mlockall5.c -lpthread || exit 1 53rm -f mlockall5.c 54cd $odir 55 56mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint 57[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart 58mdconfig -a -t swap -s 512m -u $mdstart || exit 1 59newfs $newfs_flags -n md$mdstart > /dev/null 60mount /dev/md$mdstart $mntpoint || exit 1 61 62(cd $mntpoint; /tmp/mlockall5 || echo FAIL) 63 64n=0 65while mount | grep "on $mntpoint " | grep -q /dev/md; do 66 umount $mntpoint || sleep 1 67 n=$((n + 1)) 68 [ $n -gt 10 ] && { echo FAIL; exit 1; } 69done 70mdconfig -d -u $mdstart 71rm -rf /tmp/mlockall5 72exit 73 74EOF 75#include <sys/param.h> 76#include <sys/mman.h> 77#include <sys/stat.h> 78#include <sys/wait.h> 79 80#include <err.h> 81#include <errno.h> 82#include <fcntl.h> 83#include <pthread.h> 84#include <stdio.h> 85#include <stdlib.h> 86#include <unistd.h> 87 88size_t clen; 89volatile u_int share; 90int ps; 91char *c; 92 93void * 94touch(void *arg __unused) 95{ 96 97 int i; 98 99 while (share == 0) 100 ; 101 for (i = 0; i < (int)clen; i += ps) 102 c[i] = 1; 103 104 return (NULL); 105} 106 107void * 108ml(void *arg __unused) 109{ 110 while (share == 0) 111 ; 112 if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) 113 err(1, "mlock"); 114 115 return (NULL); 116} 117 118int 119test(void) 120{ 121 pthread_t tid[2]; 122 int i, rc, status; 123 124 if (fork() == 0) { 125 alarm(60); 126 rc = pthread_create(&tid[0], NULL, touch, NULL); 127 if (rc != 0) 128 errc(1, rc, "pthread_create()"); 129 rc = pthread_create(&tid[1], NULL, ml, NULL); 130 if (rc != 0) 131 errc(1, rc, "pthread_create()"); 132 share = 1; 133 for (i = 0; i < (int)nitems(tid); i++) { 134 rc = pthread_join(tid[i], NULL); 135 if (rc != 0) 136 errc(1, rc, "pthread_join(%d)", i); 137 } 138 _exit(0); 139 } 140 141 if (wait(&status) == -1) 142 err(1, "wait"); 143 144 return (WTERMSIG(status)); 145} 146 147int 148main(void) 149{ 150 int s; 151 152 ps = getpagesize(); 153 clen = 32 * 1024; 154 if ((c = mmap(NULL, clen, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, 155 -1, 0)) == MAP_FAILED) 156 err(1, "mmap"); 157 158 s = test(); 159 160 return (s); 161} 162