From nobody Thu Aug 11 07:43:06 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4M3Jgt3TH2z4YBSX; Thu, 11 Aug 2022 07:43:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4M3Jgt308yz3SmQ; Thu, 11 Aug 2022 07:43:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660203786; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jHw6dab4Km+NRytga7kwSFnfAsfWFyMwgye5LXqtg6s=; b=kOaYF85upeZgTT3bnpILXJ0srmDiJsb5fZdkRTn3vw+7+simhaNsqrNdoaD5hS2MBo8WOV 4eYZJ1VMYuNei3nDD+tfb9ZbIiisrTasH4p69Xn7HQeQER1Gudj5Neqy8a1uxdW7kRag8W zWdbVYbJovAugrK17e3zXO2EzqM+zZYRFyZCHvP6vKUGnckzT45QCNSiXMjXrkNML6x5Rc zGLZ2avF/SNATf7kfH7VQ+mpGu8LfIBurLXqgXHqFewJLiMi8gJPeT/kjBjdy8huquJTOW sI4reCuatJOoVRTMeplQsD4v2vuu5A9zvwqmJQx5WOvhF+JGqTcRl9ZCycGyiA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4M3Jgt23skzjxW; Thu, 11 Aug 2022 07:43:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 27B7h6Wx048701; Thu, 11 Aug 2022 07:43:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27B7h6Kp048700; Thu, 11 Aug 2022 07:43:06 GMT (envelope-from git) Date: Thu, 11 Aug 2022 07:43:06 GMT Message-Id: <202208110743.27B7h6Kp048700@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Peter Holm Subject: git: 64f923959a8a - main - stress2: Added a regression test List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pho X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 64f923959a8abd963954ff67f3fc159b2d4826c8 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660203786; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jHw6dab4Km+NRytga7kwSFnfAsfWFyMwgye5LXqtg6s=; b=Ji+r96TPNfuAjsXgWeWAgRU41kgRKspnYdV6XYkfz0sXKa9Avjran0kgU7uf23vt4t8IV/ /UbAOIzuommol2vSKTMCSCY58Xb9etoCZhLZQ1LQrKxs2/uTFFoc35C0T8PqEVva54gBvx aY/v8xX8rvoh0U3EW9kShELtPm8RuYc3i73uLSovQjMz3KQHl1DULQxnFyUHNHNcPmqtoy wYnKGcAEep+ExEAUR8vyCzZ5bYFS/5F2krt1CI/r5VsjZaUGFVY/cIzGZgAqYAiv41ZdiF 98WbgmGR6zGI9Q8WpoOyh68v0WEPdtiflu24mRVJr1fj09bPqnycrSiNlSFiUQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660203786; a=rsa-sha256; cv=none; b=AdPzm94xElNHTvN9UJgodZ7xVGQtNLo1qs3CO0ifz7jRDi/AzWQ5Ahlq3ul/ZcNRBAv6sP txI2n2inodlgeNEBvvyGfu5dtuSjjlNn2vr3addIIlFVoyXZ0ddM6hLWg7xDE4ZAACZjGF mGeKJrG79fgNtPVwIHyJntNR3IspeCcODpNbLixKZBm9qHMMzeTUFzxF9KTS9f1DMHl5MN xXQDi17j1cPKGsI5d7Ut6F6GuYcynk0yzxj3q/iaqGMX3k4UD7ho4gT2GSuTAZG1v014lt LhCX0SLtlPrsrUkTa7SX903nD0I8MyToF7exhXHhUTlPQ08w1rwD1ie0UAvZ0A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by pho: URL: https://cgit.FreeBSD.org/src/commit/?id=64f923959a8abd963954ff67f3fc159b2d4826c8 commit 64f923959a8abd963954ff67f3fc159b2d4826c8 Author: Peter Holm AuthorDate: 2022-08-11 07:42:02 +0000 Commit: Peter Holm CommitDate: 2022-08-11 07:42:02 +0000 stress2: Added a regression test --- tools/test/stress2/misc/fork2.sh | 135 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/tools/test/stress2/misc/fork2.sh b/tools/test/stress2/misc/fork2.sh new file mode 100755 index 000000000000..894f44556a01 --- /dev/null +++ b/tools/test/stress2/misc/fork2.sh @@ -0,0 +1,135 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2022 Peter Holm +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +# Regression test for D36069 +# thread_create(): call cpu_copy_thread() after td_pflags is zeroed + +# Seen before fix: +# cc: error: unable to execute command: Segmentation fault (core dumped) +# cc: error: linker command failed due to signal (use -v to see invocation) +# Aug 9 18:27:47 freebsd-vm kernel: pid 32094 (ld.lld), jid 0, uid 0: exited on signal 11 (core dumped) + +. ../default.cfg +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/fork2.c +mycc -o fork2 -Wall -Wextra -O0 -g fork2.c || exit 1 +cd $odir + +set -e +mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint +[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +set +e + +cd $mntpoint +$dir/fork2 +s=$? +pkill fork2 +[ -f fork2.core -a $s -eq 0 ] && + { ls -l fork2.core; mv fork2.core $dir; s=1; } +cd $odir + +for i in `jot 6`; do + mount | grep -q "on $mntpoint " || break + umount $mntpoint && break || sleep 10 + [ $i -eq 6 ] && + { echo FATAL; fstat -mf $mntpoint; exit 1; } +done +mdconfig -d -u $mdstart +cd $dir +mycc -o $dir/fork2 -Wall -Wextra -O0 -g $dir/fork2.c; s=$? +rm -rf $dir/fork2 $dir/fork2.c +exit $s + +EOF +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile u_int *share; + +#define MX 5000 +#define RUNTIME (1 * 60) +#define SYNC 0 + +int +main(void) +{ + pid_t pid; + size_t len; + time_t start; + int n; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + n = 0; + signal(SIGCHLD, SIG_IGN); + start = time(NULL); + while ((time(NULL) - start) < RUNTIME) { + while ((atomic_load_int(&share[SYNC])) > MX) + usleep(100); + n++; + pid = fork(); + if (pid == -1) + err(1, "fork)"); + if (pid == 0) { + atomic_add_int(&share[SYNC], 1); + while (atomic_load_int(&share[SYNC]) <= MX) + usleep(10000); + usleep(arc4random() % 1000); + atomic_add_int(&share[SYNC], -1); + raise(SIGHUP); + _exit(0); + } + } + atomic_add_int(&share[SYNC], MX * 2); + fprintf(stderr, "%d fork() calls\n", n); +}