From owner-dev-commits-src-main@freebsd.org Fri Jul 2 05:25:45 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EE80D65F360; Fri, 2 Jul 2021 05:25:45 +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 4GGNpK3mwbz4ggM; Fri, 2 Jul 2021 05:25:45 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 5F02666FD; Fri, 2 Jul 2021 05:25:45 +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 1625PjTu078399; Fri, 2 Jul 2021 05:25:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1625Pjkk078398; Fri, 2 Jul 2021 05:25:45 GMT (envelope-from git) Date: Fri, 2 Jul 2021 05:25:45 GMT Message-Id: <202107020525.1625Pjkk078398@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: fe5d22f8f487 - main - stress2: Added a test scenario from Bug 227041 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: fe5d22f8f487f31fd6c5e5017e7d9dd59b5e072e Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Jul 2021 05:25:46 -0000 The branch main has been updated by pho: URL: https://cgit.FreeBSD.org/src/commit/?id=fe5d22f8f487f31fd6c5e5017e7d9dd59b5e072e commit fe5d22f8f487f31fd6c5e5017e7d9dd59b5e072e Author: Peter Holm AuthorDate: 2021-07-02 05:24:38 +0000 Commit: Peter Holm CommitDate: 2021-07-02 05:24:38 +0000 stress2: Added a test scenario from Bug 227041 --- tools/test/stress2/misc/pmc8.sh | 116 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/tools/test/stress2/misc/pmc8.sh b/tools/test/stress2/misc/pmc8.sh new file mode 100755 index 000000000000..6695b0b52f2a --- /dev/null +++ b/tools/test/stress2/misc/pmc8.sh @@ -0,0 +1,116 @@ +#!/bin/sh + +# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=227041 + +# panic: [pmc,2749] (ri21, rc1) waiting too long for pmc to be free +# cpuid = 23 +# time = 1624293771 +# KDB: stack backtrace: +# db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe01ab083850 +# vpanic() at vpanic+0x181/frame 0xfffffe01ab0838a0 +# panic() at panic+0x43/frame 0xfffffe01ab083900 +# pmc_wait_for_pmc_idle() at pmc_wait_for_pmc_idle+0xa2/frame 0xfffffe01ab083930 +# pmc_release_pmc_descriptor() at pmc_release_pmc_descriptor+0x20b/frame 0xfffffe01ab083980 +# pmc_syscall_handler() at pmc_syscall_handler+0x4bd/frame 0xfffffe01ab083ac0 +# amd64_syscall() at amd64_syscall+0x762/frame 0xfffffe01ab083bf0 +# fast_syscall_common() at fast_syscall_common+0xf8/frame 0xfffffe01ab083bf0 +# --- syscall (0, FreeBSD ELF64, nosys), rip = 0x8009c154a, rsp = 0x7fffffffe4d8, rbp = 0x7fffffffe500 --- +# KDB: enter: panic +# [ thread pid 3123 tid 100454 ] +# Stopped at kdb_enter+0x37: movq $0,0x1285d1e(%rip) +# db> x/s version +# version: FreeBSD 14.0-CURRENT #1 ufs-n247476-f77f86ecfea: Mon Jun 21 08:40:40 CEST 2021 +# pho@t2.osted.lan:/var/tmp/deviant3/sys/amd64/compile/PHO +# db> + +. ../default.cfg +cat > /tmp/pmc-crash.c < + All rights reserved. + + 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. + + clang -lpmc pmc-crash.c -o pmc-crash +*/ + +#include +#include +#include +#include +#include +#include +#include + +int main(void) +{ + if (pmc_init() != 0) + { + printf("pmc_init %s", strerror(errno)); + exit(-1); + } + + pmc_id_t pmc_id = 0; + if (pmc_allocate("inst_retired.any", PMC_MODE_TC, 0, PMC_CPU_ANY, + &pmc_id, 1024) != 0) + { + printf("pmc_allocate %s", strerror(errno)); + exit(-1); + } + + printf("attaching to self\n"); + if (pmc_attach(pmc_id, 0) != 0) + { + printf("pmc_attach %s", strerror(errno)); + exit(-1); + } + + if (pmc_start(pmc_id) != 0) + { + printf("pmc_start %s", strerror(errno)); + exit(-1); + } + + pmc_value_t v = 0; + for (int i = 0; i < 100; i++) + { + pmc_read(pmc_id, &v); + } + pmc_stop(pmc_id); + + printf("success, detaching...\n"); + pmc_detach(pmc_id, 0); + pmc_release(pmc_id); + + printf("ok?"); +} +EOF +mycc -o /tmp/pmc-crash -Wall -Wextra -O0 /tmp/pmc-crash.c -lpmc || exit +kldstat -v | grep -q hwpmc || { kldload hwpmc; loaded=1; } +here=`pwd` +cd /tmp +./pmc-crash; s=$? +cd $here +rm -f /tmp/pmc-crash /tmp/pmc-crash.core /tmp/pmc-crash.c +[ $loaded ] && kldunload hwpmc +exit $s