Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp65527lqg; Wed, 10 Apr 2024 15:50:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVGaa0qiWbKY5VlROW01s26+n+huYCKK87zEUL4fPi7tzyw0vf+62pUPT63J3/0O/TZsMl1LHQk3XEhGKKIyzhtnz6XDGTBzeDxmcQ3ag== X-Google-Smtp-Source: AGHT+IGysQNVE8sxM+ikkaOCN/9Kvy1FXftqP+Oe0u0NvaaxtAi3vX8VbDWWUO2yZ+JVstY+5mCX X-Received: by 2002:a05:6871:6a91:b0:22e:7e8c:1f8f with SMTP id zf17-20020a0568716a9100b0022e7e8c1f8fmr3362632oab.51.1712789400771; Wed, 10 Apr 2024 15:50:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712789400; cv=pass; d=google.com; s=arc-20160816; b=f6R2kqrPW1mJbq2udmG7H0L15rxPagOyyvwja1BHdg+Ec/tDKffWFOQwhwyrlU6zoB eriAFP5m7cdotXQPZzGp0sP5mXpdxyQ+IX4LVwtHMyguYCZ6nyQ6VswRxzax6dl0V4rH Q1gQEiI1j8ntfe3sEgPLjTouAyK4DlDUR8z9IHKTFY+fy2rIlI4N8z3CtF0hC7Talj8C OJaHBghTQrgihi4K4yGYqksmygUX0n+qhFfBWmMjNpLEYKB4Z5N2PNXEI51ULiYNVGud sMSS4XyG60uR/z5E3YDuh+4L0qwVmW67dEC5VbCOhNUTouLPgRp0RTihtYHqHydFAbXn j16Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=53aZ8Z0KAYc29a8/TyvmKDTswskAp7PFmRVpcJga0I0=; fh=joBs/8L+orz77ylyCy6wqNwwi35f7sYhLR+/TQjQjhI=; b=h+bMCMtr3vwQEdHiMtGFvAGIZFL1YmMQQ/Dgj2Cqq72bABuMziW5AZZnNbBDJolJGc BF7J/J6sRCcM0kBKx4320haclvoBUI/ty5VVe5ND46DXKfyC7OkZk8am2q1L79oyhq7w nQRen4cxmSvMk1dS9BYZezm2pTFDAyyJ+orQ+pwFKKxZ7HRP+Jw36vgS92NDci4W2hTP G0V6O93oB+J0ob5k1StBs6I+1LebIryyKBd0FTMUxjtOQQL9ks+sZ+5jgcAg52+R44F+ x2mbpiY4wgOK88b1PBYbbBqcndl9RU/hI6BXwl0xVMH5lN+qiUTauOnQ4U8nVwgbVLi6 aKww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0iUKFiyd; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-139455-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139455-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id ff22-20020a056a002f5600b006ed14fed3d6si231008pfb.79.2024.04.10.15.50.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 15:50:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139455-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0iUKFiyd; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-139455-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139455-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 26D4EB22DD2 for ; Wed, 10 Apr 2024 22:46:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4BA6D10971; Wed, 10 Apr 2024 22:46:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0iUKFiyd"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="caTf1ZIl" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA0A92EB0B for ; Wed, 10 Apr 2024 22:46:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712789181; cv=none; b=DnqDcs2yHbqXy7/acHXjop1UZ69UgRozWfJCxHq66WJ0kcXazAYDgpPmLk2PnlhAd/hTlMGz5QE9RFJQO2xhqVgkIqsciDfWzsoFDQ2k4o+QbDlZb9/S8HRruNDQR+9eWntbw6NPdHNtUs0k31Xb0NHIXbSp62n5+7v6ylCHzig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712789181; c=relaxed/simple; bh=0dOor7S/Yn3rDNsac02RvT1qNgsnOubhGwF303qU4IE=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=VZW3tpm7Qsx+IUESWWyWpBrUsfigEOoQc8/67iWZAcQpP08rtNLaNXBrDjycELPcX2fzaaafsBz9bWrKDI2z7Lkot+meaJMsvkf2uLcJ7KufdsIbDUBX10g0iKIHe1p/GUveDcP+JtNi/YMiUadWeenXuomCHhfsc4pG9XJkOxA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0iUKFiyd; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=caTf1ZIl; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: <20240410165551.126670434@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712789177; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=53aZ8Z0KAYc29a8/TyvmKDTswskAp7PFmRVpcJga0I0=; b=0iUKFiydvpLT6lDDnkTvpYZ1jRsvCtCCN6Oj9PD15+qkwNlGXlnmI2O2JVyJQ6zvBE66Lp 6Pa2eYkcVYTUwlNQ55J6TeXreWxxUFBsxetPJc3UccyQ4Yct4EDeaZo8vtsk2i+SleQQOV z/byf4uzVi9vJ+XteToDqjpMObS83/+tofht2VKAk6/J52nj3qQaXmdusdw0dbJBSp/BoE /s1i54fbWDoqxOeKTFzjgQ6urmDtkLaYPp8A7tBUtuGe0z7bKIp7InDALjY/t7M8iBHOqy Q/4/DufK2umItwcOTL4sK3YlgNV+M/3lLWHghjBjEZEdxDrxDywezgdFXwe4cg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712789177; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=53aZ8Z0KAYc29a8/TyvmKDTswskAp7PFmRVpcJga0I0=; b=caTf1ZIlVoP0PVlm5Onw13uKDfieYjX3oY13CdhGRrZfWZW+jIxWwL/dUSsc7JC/4e1Gn5 CEvBmI8uW7wGOlBw== From: Thomas Gleixner To: LKML Cc: Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch V2 03/50] selftests/timers/posix_timers: Validate signal rules References: <20240410164558.316665885@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Thu, 11 Apr 2024 00:46:17 +0200 (CEST) Add a test case to validate correct behaviour vs. timer reprogramming and deletion. The handling of queued signals in case of timer reprogramming or deletion is inconsistent at best. POSIX does not really specify the behaviour for that: - "The effect of disarming or resetting a timer with pending expiration notifications is unspecified." - "The disposition of pending signals for the deleted timer is unspecified." In both cases it is reasonable to expect that pending signals are discarded. Especially in the reprogramming case it does not make sense to account for previous overruns or to deliver a signal for a timer which has been disarmed. Add tests to validate that no unexpected signals are delivered. They fail for now until the signal and posix timer code is updated. Signed-off-by: Thomas Gleixner --- tools/testing/selftests/timers/posix_timers.c | 108 +++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -334,10 +334,114 @@ static void check_sig_ign(int thread) } } +static void check_rearm(void) +{ + struct tmrsig tsig = { }; + struct itimerspec its; + struct sigaction sa; + struct sigevent sev; + timer_t timerid; + sigset_t set; + + sa.sa_flags = SA_SIGINFO; + sa.sa_sigaction = siginfo_handler; + sigemptyset(&sa.sa_mask); + if (sigaction(SIGUSR1, &sa, NULL)) + fatal_error(NULL, "sigaction()"); + + /* Block the signal */ + sigemptyset(&set); + sigaddset(&set, SIGUSR1); + if (sigprocmask(SIG_BLOCK, &set, NULL)) + fatal_error(NULL, "sigprocmask(SIG_BLOCK)"); + + memset(&sev, 0, sizeof(sev)); + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIGUSR1; + sev.sigev_value.sival_ptr = &tsig; + if (timer_create(CLOCK_MONOTONIC, &sev, &timerid)) + fatal_error(NULL, "timer_create()"); + + /* Start the timer to expire in 100ms and 100ms intervals */ + its.it_value.tv_sec = 0; + its.it_value.tv_nsec = 100000000; + its.it_interval.tv_sec = 0; + its.it_interval.tv_nsec = 100000000; + if (timer_settime(timerid, 0, &its, NULL)) + fatal_error(NULL, "timer_settime()"); + + sleep(1); + + /* Reprogram the timer to single shot */ + its.it_value.tv_sec = 10; + its.it_value.tv_nsec = 0; + its.it_interval.tv_sec = 0; + its.it_interval.tv_nsec = 0; + if (timer_settime(timerid, 0, &its, NULL)) + fatal_error(NULL, "timer_settime()"); + + /* Unblock it, which should not deliver a signal */ + if (sigprocmask(SIG_UNBLOCK, &set, NULL)) + fatal_error(NULL, "sigprocmask(SIG_UNBLOCK)"); + + if (timer_delete(timerid)) + fatal_error(NULL, "timer_delete()"); + + ksft_test_result(!tsig.signals, "check_rearm\n"); +} + +static void check_delete(void) +{ + struct tmrsig tsig = { }; + struct itimerspec its; + struct sigaction sa; + struct sigevent sev; + timer_t timerid; + sigset_t set; + + sa.sa_flags = SA_SIGINFO; + sa.sa_sigaction = siginfo_handler; + sigemptyset(&sa.sa_mask); + if (sigaction(SIGUSR1, &sa, NULL)) + fatal_error(NULL, "sigaction()"); + + /* Block the signal */ + sigemptyset(&set); + sigaddset(&set, SIGUSR1); + if (sigprocmask(SIG_BLOCK, &set, NULL)) + fatal_error(NULL, "sigprocmask(SIG_BLOCK)"); + + memset(&sev, 0, sizeof(sev)); + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIGUSR1; + sev.sigev_value.sival_ptr = &tsig; + if (timer_create(CLOCK_MONOTONIC, &sev, &timerid)) + fatal_error(NULL, "timer_create()"); + + /* Start the timer to expire in 100ms and 100ms intervals */ + its.it_value.tv_sec = 0; + its.it_value.tv_nsec = 100000000; + its.it_interval.tv_sec = 0; + its.it_interval.tv_nsec = 100000000; + if (timer_settime(timerid, 0, &its, NULL)) + fatal_error(NULL, "timer_settime()"); + + sleep(1); + + if (timer_delete(timerid)) + fatal_error(NULL, "timer_delete()"); + + /* Unblock it, which should not deliver a signal */ + if (sigprocmask(SIG_UNBLOCK, &set, NULL)) + fatal_error(NULL, "sigprocmask(SIG_UNBLOCK)"); + + ksft_test_result(!tsig.signals, "check_delete\n"); +} + int main(int argc, char **argv) { ksft_print_header(); - ksft_set_plan(8); + ksft_set_plan(10); ksft_print_msg("Testing posix timers. False negative may happen on CPU execution \n"); ksft_print_msg("based timers if other threads run on the CPU...\n"); @@ -361,6 +465,8 @@ int main(int argc, char **argv) check_sig_ign(0); check_sig_ign(1); + check_rearm(); + check_delete(); ksft_finished(); }