From nobody Sat May 07 15:57:10 2022 X-Original-To: dev-commits-src-branches@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 1A5781AC49B6; Sat, 7 May 2022 15:57:11 +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 4KwXBG6rWHz4R5N; Sat, 7 May 2022 15:57:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651939031; 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=Ol6cbc+d3SHbbBLIlE62oYFvHhbA899qgLYVG4rqC0c=; b=dz7A551dmOw8DHO9v6W9bUSHbaWttkHN7qD1wpL7PJ9LI/gjb75Tk0bz5sSSKatsV2lI3W 6uYj75NbMQT21wZ7YEsaHyfZowOEnbWdu2TV84PVFL7x/fcDmO+XLVL1MX5XOicxxPiL79 OhCC/gYdKQKC87DZTLKmwS/4PLJvCY8SIHB0MNhhGJa09dXX6guVUvPGaYy36B3Hr5hFO+ P5nXwqqFYshkp7bbTDOY8w8TCAo+UTXCnOBNuk9Ow5ejE1YR4Q6tvMUcDLzYHidEuqhGiE hKKp6Y8PuuzIIRSZDq7Jg45iuvHnoqateRMALLGeuGK2nB6ghY6ItLphGL2URA== 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 CA92613738; Sat, 7 May 2022 15:57:10 +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 247FvA6e014960; Sat, 7 May 2022 15:57:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 247FvAXb014959; Sat, 7 May 2022 15:57:10 GMT (envelope-from git) Date: Sat, 7 May 2022 15:57:10 GMT Message-Id: <202205071557.247FvAXb014959@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alex Richardson Subject: git: b0188ea20071 - stable/13 - Add a test for https://reviews.freebsd.org/D31858 (PR 258310) List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: arichardson X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b0188ea200713bbdbeef6a810f8c46a4833bf09b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651939031; 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=Ol6cbc+d3SHbbBLIlE62oYFvHhbA899qgLYVG4rqC0c=; b=pEdYvK/x0ppHLsw9OaCNoTWFPfiIHgU26t4/G+Q2VPmnQt6z+KNx7pyo1ct8+pDHL2cac0 i8tEAG9XWyQkrqUq5oqAbP1uCDpYVYRamJkODPE82z7uMshVJU2y8pld9R+RneV5H73xvu SByPvJShh2yjrk9/j9rvJ8bMo7cYidX2gObPwDwPKDHgBp0HFrM2B9EemXd1L24PAuV7d6 fK1KjtT7tJWuk/TpIJPT/4IwPJFO1HcBX+zi2HUi64wEHT8KyhG3eS4q0f1QuVedoqq0Zm 8MGDL77wX0tTg3B4rxtdsMEPmMSWnt0VTxMw7V8cOum8Ke4QpJ0Z476PNpiHWw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651939031; a=rsa-sha256; cv=none; b=XzLYDvpLUy8W10/Qcc7egNuxUlGeeAeX4HjwrQDOSTbshHiQuhQ+I8lxIAAWMr9K16H0rd tqmIffjDkQkNQ//n9ExXqgOBHUpFIaj1R4lRdrGvjXsJWGk7WBzQ2kv1W6f9ezkoQr+Vz7 7kqlxokD+L07RaFIztbSiqE+K7VJwQo5Khc1yR9eGVgP/uB0vZbSe73cyxViIPu6fZlDdR pTy8KG2FXGdVDZv7c9KfnG2nEz2dqbKENpuyebPpxM89/fvUM+/4Gd/LQv+eht2PWSpn5C O7y0rLJasANpdtoHWcu0T+xrM4SbVO7Fpe76Cdt1SMQWe7h+b1KWxag+8W6Tfg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by arichardson: URL: https://cgit.FreeBSD.org/src/commit/?id=b0188ea200713bbdbeef6a810f8c46a4833bf09b commit b0188ea200713bbdbeef6a810f8c46a4833bf09b Author: Alex Richardson AuthorDate: 2021-09-13 09:16:05 +0000 Commit: Alex Richardson CommitDate: 2022-05-07 11:56:58 +0000 Add a test for https://reviews.freebsd.org/D31858 (PR 258310) This test (based on https://github.com/jiixyj/epoll-shim/pull/32#issuecomment-891276654) fails reproducibly on QEMU with KVM and `-smp 2` prior to D31858 (committed as 98168a6e6c12dab8f608f6b5f5b0b175d2b87ef0) and passes with the patch applied. Reviewed By: kib, imp Differential Revision: https://reviews.freebsd.org/D31862 (cherry picked from commit d7d962ead0b6e5e8a39202d0590022082bf5bfb6) --- tests/sys/kqueue/Makefile | 2 + tests/sys/kqueue/kqueue_peek_signal.c | 106 ++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/tests/sys/kqueue/Makefile b/tests/sys/kqueue/Makefile index 40f892d36fbd..1bf13772f0f2 100644 --- a/tests/sys/kqueue/Makefile +++ b/tests/sys/kqueue/Makefile @@ -5,6 +5,8 @@ TESTSRC= ${SRCTOP}/contrib/netbsd-tests/kernel/kqueue TESTSDIR= ${TESTSBASE}/sys/kqueue BINDIR= ${TESTSDIR} +ATF_TESTS_C+= kqueue_peek_signal + NETBSD_ATF_TESTS_C= proc1_test # XXX: fails `ke.fflags & NOTE_TRACKERR` invariant #NETBSD_ATF_TESTS_C+= proc2_test diff --git a/tests/sys/kqueue/kqueue_peek_signal.c b/tests/sys/kqueue/kqueue_peek_signal.c new file mode 100644 index 000000000000..16dbce68a57c --- /dev/null +++ b/tests/sys/kqueue/kqueue_peek_signal.c @@ -0,0 +1,106 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright 2021 Jan Kokemüller + * Copyright 2021 Alex Richardson + * + * This work was supported by Innovate UK project 105694, "Digital Security by + * Design (DSbD) Technology Platform Prototype". + * + * 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. + */ +#include +#include + +#include +#include +#include + +ATF_TC_WITHOUT_HEAD(main); + +ATF_TC_BODY(main, tc) +{ + int rv; + + sigset_t set; + rv = sigemptyset(&set); + ATF_REQUIRE_EQ(0, rv); + rv = sigaddset(&set, SIGUSR1); + ATF_REQUIRE_EQ(0, rv); + rv = sigprocmask(SIG_BLOCK, &set, NULL); + ATF_REQUIRE_EQ(0, rv); + + int skq = kqueue(); + ATF_REQUIRE(skq >= 0); + + struct kevent kev; + EV_SET(&kev, SIGUSR1, EVFILT_SIGNAL, EV_ADD, 0, 0, 0); + rv = kevent(skq, &kev, 1, NULL, 0, NULL); + ATF_REQUIRE_EQ(0, rv); + + int kq = kqueue(); + ATF_REQUIRE(kq >= 0); + + EV_SET(&kev, skq, EVFILT_READ, EV_ADD | EV_CLEAR, 0, 0, 0); + rv = kevent(kq, &kev, 1, NULL, 0, NULL); + ATF_REQUIRE_EQ(0, rv); + + /* + * It was previously not guaranteed that sending a signal to self would + * be immediately visible in the nested kqueue activation with a zero + * timeout. As of https://reviews.freebsd.org/D31858, the kqueue task + * queue will be processed in this case, so we are guaranteed to see the + * SIGUSR1 here even with a zero timeout. We run the code below in a + * loop to make it more likely that older kernels without the fix fail + * this test. + */ + for (int i = 0; i < 100; i++) { + rv = kill(getpid(), SIGUSR1); + ATF_REQUIRE_EQ(0, rv); + + rv = kevent(kq, NULL, 0, &kev, 1, &(struct timespec) { 0, 0 }); + ATF_REQUIRE_EQ_MSG(1, rv, + "Unexpected result %d from kevent() after %d iterations", + rv, i); + rv = kevent(kq, NULL, 0, &kev, 1, &(struct timespec) { 0, 0 }); + ATF_REQUIRE_EQ(0, rv); + + rv = kevent(skq, NULL, 0, &kev, 1, &(struct timespec) { 0, 0 }); + ATF_REQUIRE_EQ(1, rv); + rv = kevent(skq, NULL, 0, &kev, 1, &(struct timespec) { 0, 0 }); + ATF_REQUIRE_EQ(0, rv); + + siginfo_t siginfo; + rv = sigtimedwait(&set, &siginfo, &(struct timespec) { 0, 0 }); + ATF_REQUIRE_EQ(SIGUSR1, rv); + + rv = sigtimedwait(&set, &siginfo, &(struct timespec) { 0, 0 }); + ATF_REQUIRE_ERRNO(EAGAIN, rv < 0); + } +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, main); + + return (atf_no_error()); +}