From patchwork Tue Jun 6 14:37:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103872 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3444047vqr; Tue, 6 Jun 2023 07:39:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4vnAgGhSLUsXHjlffRixvQT8ip+0ftqjTukv3G3xWB7vbKAbY9biXZmfe9yEqPWoKtWv9L X-Received: by 2002:a05:620a:488e:b0:75d:54fc:47b1 with SMTP id ea14-20020a05620a488e00b0075d54fc47b1mr2335118qkb.54.1686062363894; Tue, 06 Jun 2023 07:39:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686062363; cv=none; d=google.com; s=arc-20160816; b=mXyjkjA9ISmY/H4CNW4ZqepBmLuEIKluR42rbpPfipDhs1Vr9mWBxiIKa4AyPdYaCe I4iVmWoBLL0aJExLQmVFGt3r975lJWn+JrhwqQpTcWeYSFvty/dVRpM+amYedVsJdGuV +guT3Ilu4U0syaQDSSxWQ8mHCxGT+fzwmVyQDCgAkrXdcn/B02l7aZBAGQzEspfnp4EM exr/7TZScizsLPxDsO+DzmNVd/L3ZTwH1/zYXu5nUgZBqJVQDk4I+UETWNZFmcqbw1uw dDrTSix6Apa4J5QrYS1vGRPwTMesY2kGrma0d+s6HDT67shLygnTFuukMax3tSv8JDKi 6qCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=iBZbrM8aXg0lrMpkqk/B9ueGbYMxSh3wWbEDiu0Wh1o=; b=t+MpGpzvTekigeEouMsgJF38C9rm1rsJQo5b2gcXuzodl80ofaYIbMMa5B5eOP66Mf nrkO1a/Xfrx1Bx91FKVSLcZ2Jf2vu7GsrlSX1vO1fei1m0Ixn435tGTlJaT2apA1Ymw+ jYL9rykmB1WJua+u22XEYLrfaBj/V/uZWynNwMWMpjpetBlz8u0xfXF08YuEIFq2wjMF RAccEB0txmyRkFBmZSoTA4oM5AnwHkQdMXDo50tqjCu9vrV7S4i+Kc8hFCx9Tq+3jpa7 TspTmuJAOcCf4LTsT4TErGbB/xbS8Dtm3bLPpeSGKGWgePT463kXd/lzXkwhGj9QMZ7l IsAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zAvCHooV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=9VqH++YV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g24-20020a37e218000000b007577edeeefcsi6113960qki.576.2023.06.06.07.39.09; Tue, 06 Jun 2023 07:39:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zAvCHooV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=9VqH++YV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237982AbjFFOhf (ORCPT + 99 others); Tue, 6 Jun 2023 10:37:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236520AbjFFOh0 (ORCPT ); Tue, 6 Jun 2023 10:37:26 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDB7010C3 for ; Tue, 6 Jun 2023 07:37:21 -0700 (PDT) Message-ID: <20230606142031.071059989@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062240; 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=iBZbrM8aXg0lrMpkqk/B9ueGbYMxSh3wWbEDiu0Wh1o=; b=zAvCHooVXCehbvvBRL4bEjYh9UjlT1Dg5/wlaOn2FjT9/Q6BaQ0j7jdRCyE+KtygLsHVZx olQCqmJVAu4L20tAv2dh63LCsSboF8YM+3vOsTbdbS+KvI7ZXf83UVCgJuum6THOr4jdjm NHbW8bWPt8dzatd4cDAUNw0RYnKZeNEXal/Zmoz0h1fuVzFFiHeaBO6XD/QCIKBI5VrrQl 0DipQL9zXTv/BCAKUZnQVWrWXJFtGfOWBMqWeR8zSgnF6jQfjTDuyHY+1cGAcJE62SUrj0 JHE6gdfaFFsLE5cjvBxFkPT7lK1xbaE9MxUp8l5Xqtyp3GzHC3xKpO64kBb10g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062240; 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=iBZbrM8aXg0lrMpkqk/B9ueGbYMxSh3wWbEDiu0Wh1o=; b=9VqH++YV0s3KDheDw0FwKjW9k1vXOoHmjwK4BwJVHg7Foj9ibE8CzUrGhhrJerU4EL5OZ3 NqBkukSrCqmHTQBw== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 01/45] selftests/timers/posix_timers: Make signal distribution test less fragile References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:19 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767964529225873870?= X-GMAIL-MSGID: =?utf-8?q?1767964529225873870?= The signal distribution test has a tendency to hang for a long time as the signal delivery is not really evenly distributed. Increasing the timer interval to 10ms makes this less likely. Add a timeout to catch the case where it hangs and terminate the test gracefully. While at it get rid of the pointless atomic operation on a the thread local variable in the signal handler. Signed-off-by: Thomas Gleixner --- tools/testing/selftests/timers/posix_timers.c | 42 ++++++++++++++++---------- 1 file changed, 27 insertions(+), 15 deletions(-) --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -188,18 +188,19 @@ static int check_timer_create(int which) return 0; } -int remain; -__thread int got_signal; +static int remain; +static __thread int got_signal; static void *distribution_thread(void *arg) { - while (__atomic_load_n(&remain, __ATOMIC_RELAXED)); + while (__atomic_load_n(&remain, __ATOMIC_RELAXED) && !done); + return NULL; } static void distribution_handler(int nr) { - if (!__atomic_exchange_n(&got_signal, 1, __ATOMIC_RELAXED)) + if (++got_signal == 1) __atomic_fetch_sub(&remain, 1, __ATOMIC_RELAXED); } @@ -209,20 +210,22 @@ static void distribution_handler(int nr) */ static int check_timer_distribution(void) { - int err, i; - timer_t id; const int nthreads = 10; pthread_t threads[nthreads]; struct itimerspec val = { .it_value.tv_sec = 0, - .it_value.tv_nsec = 1000 * 1000, + .it_value.tv_nsec = 20 * 1000 * 1000, .it_interval.tv_sec = 0, - .it_interval.tv_nsec = 1000 * 1000, + .it_interval.tv_nsec = 20 * 1000 * 1000, }; + time_t start, now; + int err, i; + timer_t id; printf("Check timer_create() per process signal distribution... "); fflush(stdout); + done = 0; remain = nthreads + 1; /* worker threads + this thread */ signal(SIGALRM, distribution_handler); err = timer_create(CLOCK_PROCESS_CPUTIME_ID, NULL, &id); @@ -244,7 +247,18 @@ static int check_timer_distribution(void } /* Wait for all threads to receive the signal. */ - while (__atomic_load_n(&remain, __ATOMIC_RELAXED)); + now = start = time(NULL); + while (__atomic_load_n(&remain, __ATOMIC_RELAXED)) { + now = time(NULL); + if (now - start > 5) + break; + } + done = 1; + + if (timer_delete(id)) { + perror("Can't delete timer\n"); + return -1; + } for (i = 0; i < nthreads; i++) { if (pthread_join(threads[i], NULL)) { @@ -253,12 +267,10 @@ static int check_timer_distribution(void } } - if (timer_delete(id)) { - perror("Can't delete timer\n"); - return -1; - } - - printf("[OK]\n"); + if (now - start <= 5) + printf("[OK]\n"); + else + printf("%d [FAIL]\n", got_signal); return 0; } From patchwork Tue Jun 6 14:37:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103906 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3457882vqr; Tue, 6 Jun 2023 08:01:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4w+HWOkaVyyjeWwq4bCcBK27aMisrJXcydeex736GTsQtCNgoBLFPmeY0oSwaTv/rxnKdK X-Received: by 2002:a05:6214:c6e:b0:628:42e1:f373 with SMTP id t14-20020a0562140c6e00b0062842e1f373mr1858038qvj.59.1686063715902; Tue, 06 Jun 2023 08:01:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063715; cv=none; d=google.com; s=arc-20160816; b=XKoMTSDfflevr2y7Afp2O/ZNi3dCJhfdcqVpU6rLYIVAALTSDuIWv7GKMwU073NCvQ Z+WUNFjMjzq+kaGLvyq1RUhCR9J4hY7jbm1FRPM1bJYxlSkeuPH0j1izovHjE/HGj8f/ gYXXguGCexNgso1b5LLnqYNGVc5Wx2YaYbOId/mIYiQWOp13gsR/YR3xTmG3FAfTA1J3 G2EbREupsMMlrXtkE21sdk/m+B71qJHFZ1uUDPS34FvDCqKOpSgMp5bOVjamn27vTB8C GT6KU5hCCQ2e8E0whMHXfM56TqE//i7kRFsBbpCCAyXTql8r8XNnQBozxnPPs5zYoIk6 4Grw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=MIIp9euOFQMWAHPLIaiH4BFUPFpK2SH94uXT++JmpqU=; b=LnVqaNohKKNyPqMX4t8d/sz4XpO3hHN8fwTWUcDebwb5mgEUPhssWIhn5YyUvj4a/p CMJODuxITPKYt3lwslm85KQCuJN6j08APmVTGUMndPZatqajq1DOjgl5Ba0AjJiV12B6 IDu1ocP6iTlfl/ERzzPr+k64ATE0fpGtKvkYXr1blFBGCcuYmk6jg+DWU4oc/YbkMVHM 1QFInEjoir/Qx35fUg8aObkzoHQIZA8n3/Hg283qXxlu8Mxugf/fEujgXXuR+qGWvwuC CZxZxCkBUf0WWiVIqad+khKZPpI5o/Ba/5i6DtVj3pIhZlNBbQTYR8DC2vX5oNCwFfrh NbPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OhJCSbA7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=VhykV8UV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r8-20020ad45768000000b0062394d4ddabsi6496672qvx.97.2023.06.06.08.01.40; Tue, 06 Jun 2023 08:01:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OhJCSbA7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=VhykV8UV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237989AbjFFOhj (ORCPT + 99 others); Tue, 6 Jun 2023 10:37:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237716AbjFFOh1 (ORCPT ); Tue, 6 Jun 2023 10:37:27 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3ACB210D9 for ; Tue, 6 Jun 2023 07:37:23 -0700 (PDT) Message-ID: <20230606142031.130432648@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062241; 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=MIIp9euOFQMWAHPLIaiH4BFUPFpK2SH94uXT++JmpqU=; b=OhJCSbA791K9lpNAXmM+45wOMTWX9MdTdYKmX1TmFSBi9VUGrV9iTeqZ2IdzbFlKCJ1x1X O6dxV1AF4Pw/BS8wgB9/C30jgSrae/3Lf535gEqFmy3PEdUQO7ETmQ5TV/P+mEvTTaFHMe vWOb8VDiJjEvZIyNSNIehpnd4xDxsoNvM5fvujIIsEvR8+uZ6r2/OP6Ggyv9JGnXDBHVY1 rhDlJs8Jsmfmdb627MbKyFqyVhpoZNdI5UAYv6CGEZ1gnt7OOcQppYKOFQ/MfiWK0kX4AV Fi5jlCmSTdZLsoVsAuZ3m/eoixDXpJXyxR+aql2CA/QqzB9T7O8343Q95Npl2A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062241; 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=MIIp9euOFQMWAHPLIaiH4BFUPFpK2SH94uXT++JmpqU=; b=VhykV8UV6fU3kmkb4uU6Ex5lS64pWPlCpFWkDAaJWZ/CmJYkJVKdWONv1VtKZME8w+rNcu uervyfdtn2KW4DAQ== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 02/45] selftests/timers/posix_timers: Use TAP reporting format References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:21 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965946960336528?= X-GMAIL-MSGID: =?utf-8?q?1767965946960336528?= No functional change. Signed-off-by: Thomas Gleixner --- tools/testing/selftests/timers/posix_timers.c | 173 +++++++++----------------- 1 file changed, 65 insertions(+), 108 deletions(-) --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -19,6 +20,20 @@ #define DELAY 2 #define USECS_PER_SEC 1000000 +static void __fatal_error(const char *test, const char *name, const char *what) +{ + char buf[64]; + + strerror_r(errno, buf, sizeof(buf)); + + if (name && strlen(name)) + ksft_exit_fail_msg("%s %s %s %s\n", test, name, what, buf); + else + ksft_exit_fail_msg("%s %s %s\n", test, what, buf); +} + +#define fatal_error(name, what) __fatal_error(__func__, name, what) + static volatile int done; /* Busy loop in userspace to elapse ITIMER_VIRTUAL */ @@ -66,15 +81,13 @@ static int check_diff(struct timeval sta diff = end.tv_usec - start.tv_usec; diff += (end.tv_sec - start.tv_sec) * USECS_PER_SEC; - if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) { - printf("Diff too high: %lld..", diff); + if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) return -1; - } return 0; } -static int check_itimer(int which) +static void check_itimer(int which, const char *name) { int err; struct timeval start, end; @@ -82,17 +95,6 @@ static int check_itimer(int which) .it_value.tv_sec = DELAY, }; - printf("Check itimer "); - - if (which == ITIMER_VIRTUAL) - printf("virtual... "); - else if (which == ITIMER_PROF) - printf("prof... "); - else if (which == ITIMER_REAL) - printf("real... "); - - fflush(stdout); - done = 0; if (which == ITIMER_VIRTUAL) @@ -103,16 +105,12 @@ static int check_itimer(int which) signal(SIGALRM, sig_handler); err = gettimeofday(&start, NULL); - if (err < 0) { - perror("Can't call gettimeofday()\n"); - return -1; - } + if (err < 0) + fatal_error(name, "gettimeofday()"); err = setitimer(which, &val, NULL); - if (err < 0) { - perror("Can't set timer\n"); - return -1; - } + if (err < 0) + fatal_error(name, "setitimer()"); if (which == ITIMER_VIRTUAL) user_loop(); @@ -122,20 +120,16 @@ static int check_itimer(int which) idle_loop(); err = gettimeofday(&end, NULL); - if (err < 0) { - perror("Can't call gettimeofday()\n"); - return -1; - } + if (err < 0) + fatal_error(name, "gettimeofday()"); if (!check_diff(start, end)) - printf("[OK]\n"); + ksft_test_result_pass("check_itimer %s\n", name); else - printf("[FAIL]\n"); - - return 0; + ksft_test_result_fail("check_itimer %s\n", name); } -static int check_timer_create(int which) +static void check_timer_create(int which, const char *name) { int err; timer_t id; @@ -144,48 +138,32 @@ static int check_timer_create(int which) .it_value.tv_sec = DELAY, }; - printf("Check timer_create() "); - if (which == CLOCK_THREAD_CPUTIME_ID) { - printf("per thread... "); - } else if (which == CLOCK_PROCESS_CPUTIME_ID) { - printf("per process... "); - } - fflush(stdout); - done = 0; err = timer_create(which, NULL, &id); - if (err < 0) { - perror("Can't create timer\n"); - return -1; - } - signal(SIGALRM, sig_handler); + if (err < 0) + fatal_error(name, "timer_create()"); + + if (signal(SIGALRM, sig_handler) == SIG_ERR) + fatal_error(name, "signal()"); err = gettimeofday(&start, NULL); - if (err < 0) { - perror("Can't call gettimeofday()\n"); - return -1; - } + if (err < 0) + fatal_error(name, "gettimeofday()"); err = timer_settime(id, 0, &val, NULL); - if (err < 0) { - perror("Can't set timer\n"); - return -1; - } + if (err < 0) + fatal_error(name, "timer_settime()"); user_loop(); err = gettimeofday(&end, NULL); - if (err < 0) { - perror("Can't call gettimeofday()\n"); - return -1; - } + if (err < 0) + fatal_error(name, "gettimeofday()"); if (!check_diff(start, end)) - printf("[OK]\n"); + ksft_test_result_pass("check_timer_create %s\n", name); else - printf("[FAIL]\n"); - - return 0; + ksft_test_result_fail("check_timer_create %s\n", name); } static int remain; @@ -208,7 +186,7 @@ static void distribution_handler(int nr) * Test that all running threads _eventually_ receive CLOCK_PROCESS_CPUTIME_ID * timer signals. This primarily tests that the kernel does not favour any one. */ -static int check_timer_distribution(void) +static void check_timer_distribution(void) { const int nthreads = 10; pthread_t threads[nthreads]; @@ -222,28 +200,22 @@ static int check_timer_distribution(void int err, i; timer_t id; - printf("Check timer_create() per process signal distribution... "); - fflush(stdout); - done = 0; remain = nthreads + 1; /* worker threads + this thread */ - signal(SIGALRM, distribution_handler); + if (signal(SIGALRM, distribution_handler) == SIG_ERR) + fatal_error(NULL, "signal()"); + err = timer_create(CLOCK_PROCESS_CPUTIME_ID, NULL, &id); - if (err < 0) { - perror("Can't create timer\n"); - return -1; - } + if (err < 0) + fatal_error(NULL, "timer_create()"); + err = timer_settime(id, 0, &val, NULL); - if (err < 0) { - perror("Can't set timer\n"); - return -1; - } + if (err < 0) + fatal_error(NULL, "timer_settime()"); for (i = 0; i < nthreads; i++) { - if (pthread_create(&threads[i], NULL, distribution_thread, NULL)) { - perror("Can't create thread\n"); - return -1; - } + if (pthread_create(&threads[i], NULL, distribution_thread, NULL)) + fatal_error(NULL, "pthread_create()"); } /* Wait for all threads to receive the signal. */ @@ -255,41 +227,29 @@ static int check_timer_distribution(void } done = 1; - if (timer_delete(id)) { - perror("Can't delete timer\n"); - return -1; - } + if (timer_delete(id)) + fatal_error(NULL, "timer_delete()"); for (i = 0; i < nthreads; i++) { - if (pthread_join(threads[i], NULL)) { - perror("Can't join thread\n"); - return -1; - } + if (pthread_join(threads[i], NULL)) + fatal_error(NULL, "pthread_join()"); } if (now - start <= 5) - printf("[OK]\n"); + ksft_test_result_pass("check_signal_distribution\n"); else - printf("%d [FAIL]\n", got_signal); - return 0; + ksft_test_result_fail("check_signal_distribution\n"); } int main(int argc, char **argv) { - printf("Testing posix timers. False negative may happen on CPU execution \n"); - printf("based timers if other threads run on the CPU...\n"); - - if (check_itimer(ITIMER_VIRTUAL) < 0) - return ksft_exit_fail(); + ksft_print_header(); + ksft_set_plan(6); - if (check_itimer(ITIMER_PROF) < 0) - return ksft_exit_fail(); - - if (check_itimer(ITIMER_REAL) < 0) - return ksft_exit_fail(); - - if (check_timer_create(CLOCK_THREAD_CPUTIME_ID) < 0) - return ksft_exit_fail(); + check_itimer(ITIMER_VIRTUAL, "ITIMER_VIRTUAL"); + check_itimer(ITIMER_PROF, "ITIMER_PROF"); + check_itimer(ITIMER_REAL, "ITIMER_REAL"); + check_timer_create(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID"); /* * It's unfortunately hard to reliably test a timer expiration @@ -300,11 +260,8 @@ int main(int argc, char **argv) * to ensure true parallelism. So test only one thread until we * find a better solution. */ - if (check_timer_create(CLOCK_PROCESS_CPUTIME_ID) < 0) - return ksft_exit_fail(); - - if (check_timer_distribution() < 0) - return ksft_exit_fail(); + check_timer_create(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID"); + check_timer_distribution(); - return ksft_exit_pass(); + ksft_finished(); } From patchwork Tue Jun 6 14:37:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103879 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3449152vqr; Tue, 6 Jun 2023 07:47:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ivhfX8qbbbvESbtfvfZxBxRX7X//rkmxxIg13quPxygmqDg/46Ex0KBSl/xRIHPmd0XOg X-Received: by 2002:a05:6a20:549e:b0:104:d028:ffe8 with SMTP id i30-20020a056a20549e00b00104d028ffe8mr1868027pzk.45.1686062865246; Tue, 06 Jun 2023 07:47:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686062865; cv=none; d=google.com; s=arc-20160816; b=lNGydzo3SU8Gs/l90Mh0JbJQ3mhoLJvhqpP00vaN/cgBOvy5oSAUMfb2Kt4etw4Wxt g+aSH178u3cpWHhgEtlDhn2igTVm/95fUqgDhFLzliIqYPBDQ5QGPcqrkmn2nduG23q4 FkSYFRdY0Fu0LY5wxxLeivbN2+/CbyZ1zvAkF/zSvx1jAnbgGTE57QXjM+l0oOQKmDzE +8DicxD4subq4bXwoHUqnL+jmpTsrkiuMQ870OSmco20wwair53VsSEFVCHp7RSiiiDc MvnMuENPBF/YQHEr8tiGZbXXr0qL3rWpH/nOoiJUWZFMDE8qU3wVLjAwu/+VF5T6G0e7 xsyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=yYUjgtlS1VYYLW2ktjjDityNYKx8aW+Dqr0QO8tGRWs=; b=Jsf20TSDKo39LQ2EFQaC2Bdq158hCfmWqrkUl7UtWXtlhogbqRp1EMFWuC1mC3btbO 7KfWBcCC5FaSJRCoicQ0fGJGTwhqC9OZrfeF72IQDMbQOSZHDnrDhcsExqLdrz3tBMj5 xF9GkVNzK6+SlfvDtdjbqLq+SPU8SCURfkf2chh/v0ixeSmWiEGLmyCGVKzpN/bjAOC4 qfzx5vdIRJJWxCbAUl0R4UvCsrN0p6SbrPlJn/EMtMBPDn3C5ljLKhZ/fG2iOzu06Dl0 P7dvi+k/7iv2JeOynKSQNMRuXOMOJn1fHAkAUU6O12OmLDLQ9h1iQU5awpZEjpbM/eA/ PwCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dqlh7RYz; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=lREuHplG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s6-20020aa78bc6000000b0065290aa261dsi7304892pfd.22.2023.06.06.07.47.32; Tue, 06 Jun 2023 07:47:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dqlh7RYz; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=lREuHplG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238015AbjFFOhm (ORCPT + 99 others); Tue, 6 Jun 2023 10:37:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237902AbjFFOh2 (ORCPT ); Tue, 6 Jun 2023 10:37:28 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9039E42 for ; Tue, 6 Jun 2023 07:37:24 -0700 (PDT) Message-ID: <20230606142031.189748136@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062243; 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=yYUjgtlS1VYYLW2ktjjDityNYKx8aW+Dqr0QO8tGRWs=; b=dqlh7RYzlcA2jThLOloAPoArtDoxWdPYT7GQmlD3Zr7Iqj9FgxzLWj7BQt+DdU4HZmnHEV aeFB9SOdnYOPJm5JyY6uKvthAqUS/aZUNI6bQNbF27xSO4SpFBd/MSvN/EWF4Yx2XIiPTN uMMqDJa4CMmySUsPpx9UP/kyHYAsAkYWfME+fkM36x4s336v5ZQZonXRVPjgnNhBq05Vd7 SngygYdiDVOBhMJC/Q144+gbjs8FsXRDh7DlqhgeCEjbMI5B3EGo2V6MNdSNffMGmbcZgh 9MvSp7VXqBU76uQtWAteqRi/xhehkMsF2yzwLpHnTbfG/waGatznAK2N5KHGXA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062243; 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=yYUjgtlS1VYYLW2ktjjDityNYKx8aW+Dqr0QO8tGRWs=; b=lREuHplGAsm0oXNanGsGUW9sxxtwmwYdDXj/iv6dfw8WFGJ+gjV/scneX3N4i4Vy4HFCCI mbr1yfTldUxzHHBQ== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 03/45] selftests/timers/posix_timers: Add SIG_IGN test References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:22 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965054833591212?= X-GMAIL-MSGID: =?utf-8?q?1767965054833591212?= Add a test case to validate correct behaviour vs. SIG_IGN. The posix specification states: "Setting a signal action to SIG_IGN for a signal that is pending shall cause the pending signal to be discarded, whether or not it is blocked." The kernel implements this in the signal handling code, but due to the way how posix timers are handling SIG_IGN for periodic timers, the behaviour after installing a real handler again is inconsistent and suprising. The following sequence is expected to deliver a signal: install_handler(SIG); block_signal(SIG); timer_create(...); <- Should send SIG timer_settime(value=100ms, interval=100ms); sleep(1); <- Timer expires and queues signal, timer is not rearmed as that should happen in the signal delivery path ignore_signal(SIG); <- Discards queued signal install_handler(SIG); <- Restore handler, should rearm but does not sleep(1); unblock_signal(SIG); <- Should deliver one signal with overrun count set in siginfo This fails because nothing rearms the timer when the signal handler is restored. Add a test for this case which fails until the signal and posix timer code is fixed. Signed-off-by: Thomas Gleixner --- tools/testing/selftests/timers/posix_timers.c | 128 +++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 2 deletions(-) --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -6,8 +6,9 @@ * * Kernel loop code stolen from Steven Rostedt */ - +#define _GNU_SOURCE #include +#include #include #include #include @@ -241,10 +242,131 @@ static void check_timer_distribution(voi ksft_test_result_fail("check_signal_distribution\n"); } +struct tmrsig { + int signals; + int overruns; +}; + +static void siginfo_handler(int sig, siginfo_t *si, void *uc) +{ + struct tmrsig *tsig = si ? si->si_ptr : NULL; + + if (tsig) { + tsig->signals++; + tsig->overruns += si->si_overrun; + } +} + +static void *ignore_thread(void *arg) +{ + unsigned int *tid = arg; + sigset_t set; + + sigemptyset(&set); + sigaddset(&set, SIGUSR1); + if (sigprocmask(SIG_BLOCK, &set, NULL)) + fatal_error(NULL, "sigprocmask(SIG_BLOCK)"); + + *tid = gettid(); + sleep(100); + + if (sigprocmask(SIG_UNBLOCK, &set, NULL)) + fatal_error(NULL, "sigprocmask(SIG_UNBLOCK)"); + return NULL; +} + +static void check_sig_ign(int thread) +{ + struct tmrsig tsig = { }; + struct itimerspec its; + unsigned int tid = 0; + struct sigaction sa; + struct sigevent sev; + pthread_t pthread; + timer_t timerid; + sigset_t set; + + if (thread) { + if (pthread_create(&pthread, NULL, ignore_thread, &tid)) + fatal_error(NULL, "pthread_create()"); + sleep(1); + } + + 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 (thread) { + sev.sigev_notify = SIGEV_THREAD_ID; + sev._sigev_un._tid = tid; + } + + 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; + timer_settime(timerid, 0, &its, NULL); + + sleep(1); + + /* Set the signal to be ignored */ + if (signal(SIGUSR1, SIG_IGN) == SIG_ERR) + fatal_error(NULL, "signal(SIG_IGN)"); + + sleep(1); + + if (thread) { + /* Stop the thread first. No signal should be delivered to it */ + pthread_cancel(pthread); + pthread_join(pthread, NULL); + } + + /* Restore the handler */ + if (sigaction(SIGUSR1, &sa, NULL)) + fatal_error(NULL, "sigaction()"); + + sleep(1); + + /* Unblock it, which should deliver the signal in the ! thread case*/ + if (sigprocmask(SIG_UNBLOCK, &set, NULL)) + fatal_error(NULL, "sigprocmask(SIG_UNBLOCK)"); + + if (timer_delete(timerid)) + fatal_error(NULL, "timer_delete()"); + + if (!thread) { + if (tsig.signals == 1 && tsig.overruns == 29) + ksft_test_result_pass("check_sig_ign SIGEV_SIGNAL\n"); + else + ksft_test_result_fail("check_sig_ign SIGEV_SIGNAL\n"); + } else { + if (tsig.signals == 0 && tsig.overruns == 0) + ksft_test_result_pass("check_sig_ign SIGEV_THREAD_ID\n"); + else + ksft_test_result_fail("check_sig_ign SIGEV_THREAD_ID\n"); + } +} + int main(int argc, char **argv) { ksft_print_header(); - ksft_set_plan(6); + ksft_set_plan(8); check_itimer(ITIMER_VIRTUAL, "ITIMER_VIRTUAL"); check_itimer(ITIMER_PROF, "ITIMER_PROF"); @@ -262,6 +384,8 @@ int main(int argc, char **argv) */ check_timer_create(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID"); check_timer_distribution(); + check_sig_ign(0); + check_sig_ign(1); ksft_finished(); } From patchwork Tue Jun 6 14:37:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103873 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3448250vqr; Tue, 6 Jun 2023 07:46:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VArkzNqqz/r2NiP7UGkrVw4s1ez/wD/ZU9tHeJuvA/zFJGTHB4BKKH2/TV5TYRM45P//i X-Received: by 2002:a17:90b:4d83:b0:258:7fae:dce with SMTP id oj3-20020a17090b4d8300b002587fae0dcemr2022057pjb.24.1686062781106; Tue, 06 Jun 2023 07:46:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686062781; cv=none; d=google.com; s=arc-20160816; b=bLVbwBqgKiTLU3lu4XLdD1OmCuarvhQNV9I81fIfWfpJk5JfhZwBBJrkaZPeJicRT6 bJPBJ+A/6wBXzF4jj5677teIg18IFcdTpH2zciuqQxqU3xGTqtRSPvB1F3sTaSokPwtF SJ5Rvqbn2+ZYlECJ4xoZy6BbDBNUyMbB/rtgKaJeytD3hGGvJ+9f5UaJLz/yIx960/UY YlAGGnAR4NNKQk/PEeuOT5qiiIzoCVABdT6jWhbfLFLGxD/p2leOS3VpicM89/rtTwhj 8kj745czC3wcA+ha4Ura4Qk22+M7WBCndQ7glEbv5vSN5kNYQ3l3JVDEd2KN3jPxs0/+ Dadg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=dCkKva35ZSsZYYHSJnYJ6h+ag01NecWv1M8cjMvd9xA=; b=u9Toi+dQQE1WkQXWPaFDzlezQTDTjsQLQRJhPVg88WReVvAu+HdDY9GTGpnyS8Cj2S qwd7Z6istZ2IzAu1VEpJWpmkD9rXJycxXbWyWsDyiMR6+YcU7R3Ld0F3Pl/ENiX+Vm3J aTua+1NHLlvfgAwm3/fqQQhiCaZCO1uVSM11znRlosyDuk2i67nzSDpL0JoCfEnYLeWI EsEID5w6F+rXUGGHGY7tloQ+/ASIs/GMDicGVIrUAhAWD85he158bZuhj+9agP4fsn23 6hXMHpxZ/bKoRUr2QJgsy67I+xAw9WZkFBTunEXmNVZvkPKVD0FahGvBxl8FRO8JNrlW Lq4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="QU/albRf"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h23-20020a17090acf1700b0025620801ed4si7460194pju.1.2023.06.06.07.46.08; Tue, 06 Jun 2023 07:46:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="QU/albRf"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238019AbjFFOhp (ORCPT + 99 others); Tue, 6 Jun 2023 10:37:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237497AbjFFOhb (ORCPT ); Tue, 6 Jun 2023 10:37:31 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D465710E0 for ; Tue, 6 Jun 2023 07:37:26 -0700 (PDT) Message-ID: <20230606142031.246358079@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062245; 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=dCkKva35ZSsZYYHSJnYJ6h+ag01NecWv1M8cjMvd9xA=; b=QU/albRfnjNxtVaW4ks6OeYpS1Ry45BwaI5jS+HjFYb2u9gZDXAtypmNiWbcV65qkRyqjL HkO3FnDqbvQNrM2SS2t0J90ZBR0/kwI5aVuDtjPm0vp5kifLJwelmPtGbeekDoXQdVQVNg 6gzmA7A68rL0e05W+bxbYJexIfYLw7n+FqSlykA/BLTUIxqYLyKs9izoFlPR/TiP21srSF oOIObNNB7TCW8ZY2MfwOO7aNETXuW6va+/WD30jSYAPTqvxjxkGIFlXmdYNV3FpLVsUSlV pukYPDRopj0hHXsVKgTk1qbdJsRoXds9OHOlfTT5kO+QzmetKchG3vX569dxGQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062245; 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=dCkKva35ZSsZYYHSJnYJ6h+ag01NecWv1M8cjMvd9xA=; b=sBlw+8T1RUYJw2yek8bJMo4AxLnoh2lL8sCOe8xz95+a/RPwM6Jv3KHDRF4SYEMEOouBcZ Z5jUQsDF7OSaohBg== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 04/45] selftests/timers/posix_timers: Validate signal rules References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:25 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767964966835137306?= X-GMAIL-MSGID: =?utf-8?q?1767964966835137306?= 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 | 113 +++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 1 deletion(-) --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -363,10 +363,119 @@ 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; + timer_settime(timerid, 0, &its, NULL); + + sleep(1); + + /* Reprogram the timer to single shot */ + its.it_value.tv_sec = 1; + its.it_value.tv_nsec = 0; + its.it_interval.tv_sec = 0; + its.it_interval.tv_nsec = 0; + timer_settime(timerid, 0, &its, NULL); + + /* 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()"); + + if (!tsig.signals) + ksft_test_result_pass("check_rearm\n"); + else + ksft_test_result_fail("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; + timer_settime(timerid, 0, &its, NULL); + + 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)"); + + if (!tsig.signals) + ksft_test_result_pass("check_delete\n"); + else + ksft_test_result_fail("check_delete\n"); +} + int main(int argc, char **argv) { ksft_print_header(); - ksft_set_plan(8); + ksft_set_plan(10); check_itimer(ITIMER_VIRTUAL, "ITIMER_VIRTUAL"); check_itimer(ITIMER_PROF, "ITIMER_PROF"); @@ -386,6 +495,8 @@ int main(int argc, char **argv) check_timer_distribution(); check_sig_ign(0); check_sig_ign(1); + check_rearm(); + check_delete(); ksft_finished(); } From patchwork Tue Jun 6 14:37:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103884 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3450713vqr; Tue, 6 Jun 2023 07:50:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6eXVqsPp7jSGF8Sq9Q7+OsNXcRT5Y6Wcvv4/pGSffMz5GvO1F6o5cCd9/eTeRXnZyyrRCZ X-Received: by 2002:a92:d44d:0:b0:330:f7b3:ead with SMTP id r13-20020a92d44d000000b00330f7b30eadmr3772586ilm.12.1686063036533; Tue, 06 Jun 2023 07:50:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063036; cv=none; d=google.com; s=arc-20160816; b=X504Mqwvsiel02c1sCeP5dJXakTHiFdn1RoD2W7IsZO+X0Xm3ws+fU9qAErYzSYpbi 8PrdDx9EZvnLO/NcVk6nMeSW/QarJrlsSVfLq5nXuwV/ejVvrm19ZYPGRkazuLp3yv0G TPVpUPciMQ5pJ89k1PXi1pvRe19ssBozUiVkMWDIrEQMiowSiVtx1w3x7RZo/DjJ9E1I e8TEOB/K5VEHQmgE0fPh3ivtguAHbxME5zjGkFqo4nV2UnqcpTP+0kfn+4XnmQSvbrdB zZmAONXsyIDsQa+kY64z/kXC8ISGwydb1iHCMYQKYYEEs+WHsumth+/KVmEbM085rQiA /5/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=kUcWS9fKA9MhrLnlJFYDQVKQCJlVl0X8B00s0xylFSg=; b=Soayt5Du3Ez/QRw+iDRyPmH/jVa82gUONgdlvmoe7hushrNoIclqb+RfTbMQS4PWlk h+BK/kWFr4MdrB5C9CLPiY6GZfjjbgM2FjQHeZf3KK3ExXLTzr8nfUXDChsjwb8BE6b2 j3dFZxe8lep6DNeglVBifzt4bXKJQ+oKgQdAyM+AUs9Ja/YieBaAvwaEBkAQ2yUg9y/Q eGJmihsnzu9A5kwX1a8Mlr8uzMLFIbJE22tUxtdVCCaY1JG9Z2mEkzVL4uafA5P9sGo+ bJ5TVfyyme+61UBR5a0HyfI1LAIjnakSJe+qK7TApPnjFdNKkD+hnzgZciZQMokn9OrW ZhuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mFOehDrp; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv3-20020a632e03000000b0053f7fcd4705si7316644pgb.541.2023.06.06.07.50.24; Tue, 06 Jun 2023 07:50:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mFOehDrp; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238039AbjFFOhs (ORCPT + 99 others); Tue, 6 Jun 2023 10:37:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237960AbjFFOhc (ORCPT ); Tue, 6 Jun 2023 10:37:32 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8630E10D9 for ; Tue, 6 Jun 2023 07:37:28 -0700 (PDT) Message-ID: <20230606142031.303328672@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062247; 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=kUcWS9fKA9MhrLnlJFYDQVKQCJlVl0X8B00s0xylFSg=; b=mFOehDrpWendqw/cAVSYhGChRkb3iYtPm4Xp7CX2H+d1SxJ9qVRb1vkP+aBwyehWPL44Nc 4pGtpZuU7woPf1OS7IEHZDzox0gOr3B8BcPEzx5AaJixiefUMsREZviaiDzO1L9TlNYfTm 3DuOAjwU+CIn9UAno4nNi+5UEgaCZ2lb8c3Axqwe0CGBq5MiR+quuTs7EpBw/JfGcRpLtA VYi3dlDyqaK1ouZzY5414NW/cuT9Oz0FZ0smuICrFzunBUPIy7Zr/IfXPu2IIu7Shp9RTK 23O5GioCN4650KgduvEkZinYfWMfTSjDOf9OFC7wb4tSy5IvlriSp8DzYIjvFA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062247; 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=kUcWS9fKA9MhrLnlJFYDQVKQCJlVl0X8B00s0xylFSg=; b=gjFNHKwfsFOq8w0NS15qbmk1cLOOF5v0OtUF2zBdEg7PyKe02PSpVNHQzFxGWp798k9GVC A/7Gz6v1UK1CDcDA== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 05/45] selftests/timers/posix-timers: Validate SIGEV_NONE References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:26 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965234779964848?= X-GMAIL-MSGID: =?utf-8?q?1767965234779964848?= Posix timers with a delivery mode of SIGEV_NONE deliver no signals but the remaining expiry time must be readable via timer_gettime() for both one shot and interval timers. That's implemented correctly for regular posix timers but broken for posix CPU timers. Add a self test so the fixes can be verified. Signed-off-by: Thomas Gleixner --- tools/testing/selftests/timers/posix_timers.c | 55 +++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +21,7 @@ #define DELAY 2 #define USECS_PER_SEC 1000000 +#define NSECS_PER_SEC 1000000000 static void __fatal_error(const char *test, const char *name, const char *what) { @@ -472,10 +474,59 @@ static void check_delete(void) ksft_test_result_fail("check_delete\n"); } +static inline int64_t calcdiff_ns(struct timespec t1, struct timespec t2) +{ + int64_t diff; + + diff = NSECS_PER_SEC * (int64_t)((int) t1.tv_sec - (int) t2.tv_sec); + diff += ((int) t1.tv_nsec - (int) t2.tv_nsec); + return diff; +} + +static void check_sigev_none(int which, const char *name) +{ + struct timespec start, now; + struct itimerspec its; + struct sigevent sev; + timer_t timerid; + + memset(&sev, 0, sizeof(sev)); + sev.sigev_notify = SIGEV_NONE; + + if (timer_create(which, &sev, &timerid)) + fatal_error(name, "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; + timer_settime(timerid, 0, &its, NULL); + + if (clock_gettime(which, &start)) + fatal_error(name, "clock_gettime()"); + + do { + if (clock_gettime(which, &now)) + fatal_error(name, "clock_gettime()"); + } while (calcdiff_ns(now, start) < NSECS_PER_SEC); + + if (timer_gettime(timerid, &its)) + fatal_error(name, "timer_gettime()"); + + if (timer_delete(timerid)) + fatal_error(name, "timer_delete()"); + + if (its.it_value.tv_sec || its.it_value.tv_nsec) + ksft_test_result_pass("check_sigev_none %s\n", name); + else + ksft_test_result_fail("check_sigev_none %s\n", name); +} + int main(int argc, char **argv) { ksft_print_header(); - ksft_set_plan(10); + ksft_set_plan(12); check_itimer(ITIMER_VIRTUAL, "ITIMER_VIRTUAL"); check_itimer(ITIMER_PROF, "ITIMER_PROF"); @@ -497,6 +548,8 @@ int main(int argc, char **argv) check_sig_ign(1); check_rearm(); check_delete(); + check_sigev_none(CLOCK_MONOTONIC, "CLOCK_MONOTONIC"); + check_sigev_none(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID"); ksft_finished(); } From patchwork Tue Jun 6 14:37:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103891 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3452319vqr; Tue, 6 Jun 2023 07:53:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4mahdc2d7HlfLwAdNUTa3xDMAGtAzXOjHPWXOw3N6abb+xn6EPv9DMoF5dsJvbS2QLGbO8 X-Received: by 2002:a05:620a:4116:b0:75e:8f18:6fe4 with SMTP id j22-20020a05620a411600b0075e8f186fe4mr2585024qko.44.1686063208072; Tue, 06 Jun 2023 07:53:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063208; cv=none; d=google.com; s=arc-20160816; b=EyNILNl+aCPh9d7RYk4Ypseo1ce9XYOpduQv56koydKzlbfpRHLodP36N7rs/Ib4EZ rBAtNDSUbAZDT6AlspeKIeq4BXX0PoMPZU0fucoQeqtYIa+1D3TJI66+4CMkqFbkW9Z2 34jFxqDc7QYMTwVFLbjhiEf3e0u7iazbmAydhmFsxFb4/Jm6RjokAqime3NHHhAJYOFP UHimNfWzuxG+wAvJ47ea4jiV4qoGR+GjCFfzZUkwNedc/ftM2F67y9GlysuMwgUFUzPL OaU4/1OVjLev9nIh1m3QRrP42unzKGyX/mpPyPR8D8brtbdhBvRq/JK/rAont6Mc0vyn zNHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=vEpeXsIrZe+OvjERrC+2BpJZspHhIovUmZBUn14588o=; b=qBsynkwrFgfQN6RrrHLbR0NTVKUvsND0Rn9jiqSrKyKaIH2TmnkAzf9HZEYt7B8r3Y ZrW1lsyxqnFc3sSysY0M3atCuJ/iaRzlrIWy3Jl2HLHQrK6sjXm0NaqAmE51hs+4tXJR p5boADaD1gbJcK7tEjZVwYzYpkCc/UGYavKllRF8gOBIxtamjn0oChyjnNu71pXEKRZw 67VNTdzvPmTeRYbYBzZU53OW7soclcX0guUEyPAgO2lMC75BdZ+wDiqIaFecIXKlLu6h 0BWPx/tMm1uS9SCrdzAzpmxn6VZIJGEbcCP/EYkgu3ZJTk/ORZOpwVYSb8wXYZg3nBkn Y6Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MFxYngCM; dkim=neutral (no key) header.i=@linutronix.de header.b=0KZ505Aw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f6-20020a05620a12e600b0075cbf587db1si5773718qkl.79.2023.06.06.07.53.13; Tue, 06 Jun 2023 07:53:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MFxYngCM; dkim=neutral (no key) header.i=@linutronix.de header.b=0KZ505Aw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232951AbjFFOhv (ORCPT + 99 others); Tue, 6 Jun 2023 10:37:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237969AbjFFOhe (ORCPT ); Tue, 6 Jun 2023 10:37:34 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 113FCE6E for ; Tue, 6 Jun 2023 07:37:30 -0700 (PDT) Message-ID: <20230606142031.361364275@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062248; 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=vEpeXsIrZe+OvjERrC+2BpJZspHhIovUmZBUn14588o=; b=MFxYngCMvgFGbZ+qeTOM2WVe2omVI9vCB0KU5kPN8qjGKnGt0ttOHj9DjYtH8UPEe6vSe/ SgYgJrhjyWbHDxrwa8vngQ7l/MqwIYGAHyHvS4w1wS4W8A8QYC4L9MlPRHVypqGCfwjp7s FAT7Wy+ZQghzVPaNqnZMN43gDUXrDxKtjPbFcebAmmad7ohKC4Jgqo6UV6bmcoAwyHL0AX 7ExdTVqndCXYfLUHSJlpQ+uHfZY/s9cNtDHkU/mhxpgPzzABT1ACoAdHzWdG7Kzgo5pzvd 0pPI5wJ01zomBYaoD3u4BxHpsBQAA0CHWvLRb9FmcIKTGWgS6u44Fup8Tcqb4A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062248; 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=vEpeXsIrZe+OvjERrC+2BpJZspHhIovUmZBUn14588o=; b=0KZ505Aw8WKTp7bXANs+TTFcUIQxHVvXogT58oey98b195Yyc7+kJIcfaqn6Aw3wycatnY /Df4udSlqHwuMeDw== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 06/45] selftests/timers/posix-timers: Validate timer_gettime() References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:28 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965414392337970?= X-GMAIL-MSGID: =?utf-8?q?1767965414392337970?= timer_gettime() must return the correct expiry time for interval timers even when the timer is not armed, which is the case when a signal is pending but blocked. Works correctly for regular posix timers, but not for posix CPU timers. Add a selftest to validate the fixes. Signed-off-by: Thomas Gleixner --- tools/testing/selftests/timers/posix_timers.c | 60 +++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -523,10 +523,65 @@ static void check_sigev_none(int which, ksft_test_result_fail("check_sigev_none %s\n", name); } +static void check_gettime(int which, const char *name) +{ + struct itimerspec its, prev; + struct timespec start, now; + struct sigevent sev; + timer_t timerid; + int wraps = 0; + sigset_t set; + + /* Block the signal */ + sigemptyset(&set); + sigaddset(&set, SIGUSR1); + if (sigprocmask(SIG_BLOCK, &set, NULL)) + fatal_error(name, "sigprocmask(SIG_BLOCK)"); + + memset(&sev, 0, sizeof(sev)); + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIGUSR1; + + if (timer_create(which, &sev, &timerid)) + fatal_error(name, "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; + timer_settime(timerid, 0, &its, NULL); + + if (timer_gettime(timerid, &prev)) + fatal_error(name, "timer_gettime()"); + + if (clock_gettime(which, &start)) + fatal_error(name, "clock_gettime()"); + + do { + if (clock_gettime(which, &now)) + fatal_error(name, "clock_gettime()"); + if (timer_gettime(timerid, &its)) + fatal_error(name, "timer_gettime()"); + if (its.it_value.tv_nsec > prev.it_value.tv_nsec) + wraps++; + prev = its; + + } while (calcdiff_ns(now, start) < NSECS_PER_SEC); + + if (timer_delete(timerid)) + fatal_error(name, "timer_delete()"); + + if (wraps > 1) + ksft_test_result_pass("check_gettime %s\n", name); + else + ksft_test_result_fail("check_gettime %s\n", name); +} + int main(int argc, char **argv) { ksft_print_header(); - ksft_set_plan(12); + ksft_set_plan(15); check_itimer(ITIMER_VIRTUAL, "ITIMER_VIRTUAL"); check_itimer(ITIMER_PROF, "ITIMER_PROF"); @@ -550,6 +605,9 @@ int main(int argc, char **argv) check_delete(); check_sigev_none(CLOCK_MONOTONIC, "CLOCK_MONOTONIC"); check_sigev_none(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID"); + check_gettime(CLOCK_MONOTONIC, "CLOCK_MONOTONIC"); + check_gettime(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID"); + check_gettime(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID"); ksft_finished(); } From patchwork Tue Jun 6 14:37:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103885 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3450877vqr; Tue, 6 Jun 2023 07:50:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7vpE2e656pg4Vn+YyNDsSEOu4l5EHEIXNRULo4TN7cdgk/62VZJNCv2uMJkOGp55n8NYXm X-Received: by 2002:a05:6a20:7492:b0:10f:32ec:aa20 with SMTP id p18-20020a056a20749200b0010f32ecaa20mr1328566pzd.32.1686063053651; Tue, 06 Jun 2023 07:50:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063053; cv=none; d=google.com; s=arc-20160816; b=AJg2Mb/S2u8YW1BQom9HSugMUsXpe7NH8TZxk1RohaLql8ZSxn02AFav9rMKZHzr2t H9F5p5H3D2feVVuZiGVl3XSHqd4muo8CvLqB5KcHH8CX/RcFwxH7rve+U5LkZ8KXSdr2 qk9CAg4d47FDlQzIfUCAPZxk+o4GoCXGBetgBoA0F+WLCWAbeK/S1KUpheT7WMm7OZTz fmBZbjlBwS6c+scx+4VwO5Ct3z3i0rtNRFUIiZ95ooaCewrn94JraUkAaVypPtC8Hqn4 cKvn7OqbybSWNK3bYcEfIlYUWqR/r63vg3Ts/AnP0MMF5GVF5U+uWebDwnAA3Jfkq1pu 4a4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=BSLAZiaPu4OlRt7MJLr8iteahUnDIy2W/NiT+df9pkg=; b=kmzHsGT/RybFURDYp9zV3rqzSc6TSbZep1KXTbiV0dOR5qaPeknCZBp/uzwnV9KrK6 83DTo9psHJWZiVQCutRgj9L0WJJjc1GZH6dFqHvmWZN93IewJIy8IOFuIEin0tTOFlie CELtDcLUdT4Jx3rRIir8qZTGroaaAJX/jjBk8WpbWLfHlNJzW/IEdRjesD0ImSaO60dx 7CXIZRDaFGXdN0vYhT0ch8PRM1svLgejB0O2Zilx8IKsS5DCAah5ylrawUPwCuhV7J8L 3FaeiHhbceTXUE9GzlCGV0dNhrXwBARU46I16nj58GVx1MKLB6VhI+lNeq88vbN/VABO bX9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=NGSYWuzH; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e1-20020a170902d38100b001a6f91439d8si7319599pld.393.2023.06.06.07.50.30; Tue, 06 Jun 2023 07:50:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=NGSYWuzH; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238010AbjFFOhz (ORCPT + 99 others); Tue, 6 Jun 2023 10:37:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238012AbjFFOhl (ORCPT ); Tue, 6 Jun 2023 10:37:41 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B29010F0 for ; Tue, 6 Jun 2023 07:37:31 -0700 (PDT) Message-ID: <20230606142031.418148389@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062250; 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=BSLAZiaPu4OlRt7MJLr8iteahUnDIy2W/NiT+df9pkg=; b=NGSYWuzHITJVHI6VTsAf1RP0yNKLn79a3HYPloWgCUX5l4IL/Y3fEGAy5jJdnxpqLdeDOu BJEU49bHoqnbPP7zSmGBLf2qDwc7R8IkUMt++9Nm10DLjKwhwEGOL1s2w62k/FYrneQ8hq GLGJH5NU02wxZ5XXnXWHnfIk9i8+nCDuMdTgZ8UbZSmviMi+9BrdNVWYMr1GDvX2oTCiWe XiMRa9wCPZg4gkYCfXjL3GGSbpfnIkymBPHGLs01wQLKlnV62KgQk4u62mxfS2WEOSaRvh jZaEA4GGm40/gTq3MCj1QDqIHJpmUPBZon847bpwaRNcZwShycOsh8rfoDRhfQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062250; 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=BSLAZiaPu4OlRt7MJLr8iteahUnDIy2W/NiT+df9pkg=; b=SZ+WwAc0hpLj84ylncyoVTYGGxBxKyzgeyk1hVyKYq34jKgtd5/JJtvSKU/azX3SrSJ+3V bPmlI+45gUg4iQCg== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 07/45] selftests/timers/posix-timers: Validate overrun after unblock References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:29 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965252264231189?= X-GMAIL-MSGID: =?utf-8?q?1767965252264231189?= When a timer signal is blocked and later unblocked then one signal should be delivered with the correct number of overruns since the timer was queued. Validate that behaviour. Signed-off-by: Thomas Gleixner --- tools/testing/selftests/timers/posix_timers.c | 63 +++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -578,10 +578,68 @@ static void check_gettime(int which, con ksft_test_result_fail("check_gettime %s\n", name); } +static void check_overrun(int which, const char *name) +{ + struct timespec start, now; + 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(name, "sigaction()"); + + /* Block the signal */ + sigemptyset(&set); + sigaddset(&set, SIGUSR1); + if (sigprocmask(SIG_BLOCK, &set, NULL)) + fatal_error(name, "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(which, &sev, &timerid)) + fatal_error(name, "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; + timer_settime(timerid, 0, &its, NULL); + + if (clock_gettime(which, &start)) + fatal_error(name, "clock_gettime()"); + + do { + if (clock_gettime(which, &now)) + fatal_error(name, "clock_gettime()"); + } while (calcdiff_ns(now, start) < NSECS_PER_SEC); + + /* Unblock it, which should deliver a signal */ + if (sigprocmask(SIG_UNBLOCK, &set, NULL)) + fatal_error(name, "sigprocmask(SIG_UNBLOCK)"); + + if (timer_delete(timerid)) + fatal_error(name, "timer_delete()"); + + if (tsig.signals == 1 && tsig.overruns == 9) + ksft_test_result_pass("check_overrun %s\n", name); + else + ksft_test_result_fail("check_overrun %s\n", name); +} + int main(int argc, char **argv) { ksft_print_header(); - ksft_set_plan(15); + ksft_set_plan(18); check_itimer(ITIMER_VIRTUAL, "ITIMER_VIRTUAL"); check_itimer(ITIMER_PROF, "ITIMER_PROF"); @@ -608,6 +666,9 @@ int main(int argc, char **argv) check_gettime(CLOCK_MONOTONIC, "CLOCK_MONOTONIC"); check_gettime(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID"); check_gettime(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID"); + check_overrun(CLOCK_MONOTONIC, "CLOCK_MONOTONIC"); + check_overrun(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID"); + check_overrun(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID"); ksft_finished(); } From patchwork Tue Jun 6 14:37:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103887 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3451481vqr; Tue, 6 Jun 2023 07:51:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4VP85Z8LcdX8yceKrGetQN6Bb/u1KD1+9M4UR4qLGniliKonHdp9cXnnhSiMUq8+uZ4G0e X-Received: by 2002:ac8:5ac3:0:b0:3f9:b870:ba13 with SMTP id d3-20020ac85ac3000000b003f9b870ba13mr302131qtd.24.1686063110719; Tue, 06 Jun 2023 07:51:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063110; cv=none; d=google.com; s=arc-20160816; b=VdlWood2pUqOHS8eKxD68c7+dt+dtNb7PFi5/Cgkx1S+l3RtkPbKWkjM6yZ8qblpM6 93SmyGCDubEcnW5rrEaU+Bh8RQ4Qee+EtERGWDcOc/0NooiuhU5d+Sp0jc863IJN0C5B IRrpoQ8gd+1Rhe1y7dGPAte2CbMuCiUDFOYSoxG3ddaQGrjQrRFjPgPztWI1mc/DP5lF VapJF77TwsIzHOrzgKku3Lt1pFLpQWRVRm34kF8klOqp+cpmEOC851RVXuMQHk+HEGoT C8XwZJCbKW6Iz7XPVX05Iwbo++LtqEUQ69P1VEoferPxE3KMBLwKBTTUcpspCA8G390p H1CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=feQqbMJR8LNStx4hiDUEIHYcUpveV5I+mK7qWj22Q+I=; b=h4sJR3ziBZsOVsfKVxqJ4pb8SGNWvsVs7vSwbSx+UdVUqUZJppBILfC6tcKZQ0tlEd keqjC4qn89dep2f+iVwNXIgrTWaK7/a1LUgZn3SjhXZqdv7U1ZxL9PRTaFWI4754GIWt OXpbsgJEkDpxgNJAwgIIx04oxAbRyw87JdqsiPrmlf5KzPd2OoE/oyaZxm3NOEMTHVDV dsyX+RzgyDT4xP8aPQ8BJPHtK0L2pFIvM8xazanZEpniWttv9+vvvG/GZ/sEm0oY57QL LaGLJec9r4QDjvR0ljI9c3jtaNRU92p1Bv4AOytR7nRBRnFnCMQlzNnX2Ie2uExrlX+d ECHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=K+0PvOJH; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b4-20020ac85bc4000000b003d53cbf0ecbsi4101820qtb.413.2023.06.06.07.51.35; Tue, 06 Jun 2023 07:51:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=K+0PvOJH; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238058AbjFFOh7 (ORCPT + 99 others); Tue, 6 Jun 2023 10:37:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238014AbjFFOhl (ORCPT ); Tue, 6 Jun 2023 10:37:41 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DB3710FB for ; Tue, 6 Jun 2023 07:37:33 -0700 (PDT) Message-ID: <20230606142031.475141256@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062251; 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=feQqbMJR8LNStx4hiDUEIHYcUpveV5I+mK7qWj22Q+I=; b=K+0PvOJHghqEuSL/XjZ+ievKQ/BpS5nPc98SPu4u7Piv031DQHuSw9oGajptxP1/O3ogEw Fl8h62mYfWJzhBl5vt1SfnvfDv6IZsSKv2SkCdnWniZbRcMcW24rreNAvg5IFmYuJPH25V 8/A8aPCo2v2h6c+XDhMrLrBrRY9PaCT0+uUpc4KREfVFN7t97aDXY5hWuqtYp6/LUg/gdU FD5gLMYyWUjwLccJ3W1YoL64EQ0KSi+4O9ewaCKY/+VUesGZWbzBVVhb0bN/KHpZ17NiK1 19EOg+RuOZcA4sR2BL32JucxrtRvxhIoNTYZ2saEXqn0+S6yjn3mqpv1K1J98w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062251; 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=feQqbMJR8LNStx4hiDUEIHYcUpveV5I+mK7qWj22Q+I=; b=t67079sbUXtqL232iy/n95/NpVWYpidkqzaBa5qDnHjwomga0pshXT7Z0jzaT88DiOzQz+ gBhkOKIZPUOtoeAw== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 08/45] posix-timers: Convert timer list to hlist References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:31 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965312434158290?= X-GMAIL-MSGID: =?utf-8?q?1767965312434158290?= No requirement for a real list. Spare a few bytes. Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker --- fs/proc/base.c | 6 +++--- include/linux/posix-timers.h | 2 +- include/linux/sched/signal.h | 2 +- init/init_task.c | 2 +- kernel/fork.c | 2 +- kernel/time/posix-timers.c | 16 ++++++++-------- 6 files changed, 15 insertions(+), 15 deletions(-) --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2461,13 +2461,13 @@ static void *timers_start(struct seq_fil if (!tp->sighand) return ERR_PTR(-ESRCH); - return seq_list_start(&tp->task->signal->posix_timers, *pos); + return seq_hlist_start(&tp->task->signal->posix_timers, *pos); } static void *timers_next(struct seq_file *m, void *v, loff_t *pos) { struct timers_private *tp = m->private; - return seq_list_next(v, &tp->task->signal->posix_timers, pos); + return seq_hlist_next(v, &tp->task->signal->posix_timers, pos); } static void timers_stop(struct seq_file *m, void *v) @@ -2496,7 +2496,7 @@ static int show_timer(struct seq_file *m [SIGEV_THREAD] = "thread", }; - timer = list_entry((struct list_head *)v, struct k_itimer, list); + timer = hlist_entry((struct hlist_node *)v, struct k_itimer, list); notify = timer->it_sigev_notify; seq_printf(m, "ID: %d\n", timer->it_id); --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -221,7 +221,7 @@ static inline void posix_cputimers_init_ * @rcu: RCU head for freeing the timer. */ struct k_itimer { - struct list_head list; + struct hlist_node list; struct hlist_node t_hash; spinlock_t it_lock; const struct k_clock *kclock; --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -136,7 +136,7 @@ struct signal_struct { /* POSIX.1b Interval Timers */ unsigned int next_posix_timer_id; - struct list_head posix_timers; + struct hlist_head posix_timers; /* ITIMER_REAL timer for the process */ struct hrtimer real_timer; --- a/init/init_task.c +++ b/init/init_task.c @@ -28,7 +28,7 @@ static struct signal_struct init_signals .cred_guard_mutex = __MUTEX_INITIALIZER(init_signals.cred_guard_mutex), .exec_update_lock = __RWSEM_INITIALIZER(init_signals.exec_update_lock), #ifdef CONFIG_POSIX_TIMERS - .posix_timers = LIST_HEAD_INIT(init_signals.posix_timers), + .posix_timers = HLIST_HEAD_INIT, .cputimer = { .cputime_atomic = INIT_CPUTIME_ATOMIC, }, --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1880,7 +1880,7 @@ static int copy_signal(unsigned long clo prev_cputime_init(&sig->prev_cputime); #ifdef CONFIG_POSIX_TIMERS - INIT_LIST_HEAD(&sig->posix_timers); + INIT_HLIST_HEAD(&sig->posix_timers); hrtimer_init(&sig->real_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); sig->real_timer.function = it_real_fn; #endif --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -515,7 +515,7 @@ static int do_timer_create(clockid_t whi spin_lock_irq(¤t->sighand->siglock); /* This makes the timer valid in the hash table */ WRITE_ONCE(new_timer->it_signal, current->signal); - list_add(&new_timer->list, ¤t->signal->posix_timers); + hlist_add_head(&new_timer->list, ¤t->signal->posix_timers); spin_unlock_irq(¤t->sighand->siglock); /* * After unlocking sighand::siglock @new_timer is subject to @@ -1021,7 +1021,7 @@ SYSCALL_DEFINE1(timer_delete, timer_t, t } spin_lock(¤t->sighand->siglock); - list_del(&timer->list); + hlist_del(&timer->list); spin_unlock(¤t->sighand->siglock); /* * A concurrent lookup could check timer::it_signal lockless. It @@ -1071,7 +1071,7 @@ static void itimer_delete(struct k_itime goto retry_delete; } - list_del(&timer->list); + hlist_del(&timer->list); /* * Setting timer::it_signal to NULL is technically not required @@ -1092,20 +1092,20 @@ static void itimer_delete(struct k_itime */ void exit_itimers(struct task_struct *tsk) { - struct list_head timers; + struct hlist_head timers; struct k_itimer *tmr; - if (list_empty(&tsk->signal->posix_timers)) + if (hlist_empty(&tsk->signal->posix_timers)) return; /* Protect against concurrent read via /proc/$PID/timers */ spin_lock_irq(&tsk->sighand->siglock); - list_replace_init(&tsk->signal->posix_timers, &timers); + hlist_move_list(&tsk->signal->posix_timers, &timers); spin_unlock_irq(&tsk->sighand->siglock); /* The timers are not longer accessible via tsk::signal */ - while (!list_empty(&timers)) { - tmr = list_first_entry(&timers, struct k_itimer, list); + while (!hlist_empty(&timers)) { + tmr = hlist_entry(timers.first, struct k_itimer, list); itimer_delete(tmr); } } From patchwork Tue Jun 6 14:37:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103916 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3467566vqr; Tue, 6 Jun 2023 08:12:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4/0t9o1RefDXgz4WGH8pr+VvH2RNm46tgS0CliC6XGSd13KXFDCUBZDHgsCEUOPUq/qpw7 X-Received: by 2002:a9d:67c5:0:b0:6ab:3367:795b with SMTP id c5-20020a9d67c5000000b006ab3367795bmr2397969otn.12.1686064357863; Tue, 06 Jun 2023 08:12:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686064357; cv=none; d=google.com; s=arc-20160816; b=kKq6lp+Bp1LvbCxVZVBg9lT2CaGQF3BWca+0gcz4s6HPhAT8VwHpsvDIB9pejCQsjx voFeFPcuFp9rXC30M3qXW3P9nphPoTgqDPS+D0XRPdtsa80B6NyIluExyBdWJVIanFhf DcjyzZgKke5vLNFO5cItPQq5YuGL3a5TkAWQIqJobXpaG/jDKBYm5qfJvUx3nPVfg6v3 QDk816FlnOaK/B0q5nnmtQ+yTHiY3XPxnXsod1maA6YWMyQEAlSvFc+mgYtc7ZZrC2ab //1ADC7QtAIsmR9NSUq4QjjLHCR2U5ORoDoBhKS9rpGcV4NK/WPoMTFseUNNMUVR7wll ox9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=2mlrLNBzpK9wpMz36KzO779P+Hz9+q0V8boLAVqB0tk=; b=o7ao089938tgLwz94m9NT8Q3AsjE6epqIuXuyIdVZZgJsomDAdsDXmSsu9wpZBWHa1 m93wrt1DBbxfaM2yGW7ERnTcFHBlJ+N93sil0pXcUNu6b8svZblNvPxiN0YgSuQ6ZAht IPVC+DVVf9tpvue8Aytr0YcGcjgLhYdAm3D/ts0K9FvrJc7r3XPiF2PxTFnZtrXr+rEO bjT3umii1X92QoIXYW1/t4TTjVzapVpwODG+/QXvl2JAO7C0c2BUHVB3m/3JJ3ZnMs4R 3lzirU5PHN91MWeTAZI82klXci6y9MvPDBHFHCso5LfeRdMhArvuX8llz9ZnDy56jPFO J8Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CJ8WvJz9; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=+c+DRtc+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l69-20020a638848000000b0054288b91d66si7315184pgd.635.2023.06.06.08.12.25; Tue, 06 Jun 2023 08:12:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CJ8WvJz9; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=+c+DRtc+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238064AbjFFOiE (ORCPT + 99 others); Tue, 6 Jun 2023 10:38:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238034AbjFFOhp (ORCPT ); Tue, 6 Jun 2023 10:37:45 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E11861706 for ; Tue, 6 Jun 2023 07:37:34 -0700 (PDT) Message-ID: <20230606142031.532247561@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062253; 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=2mlrLNBzpK9wpMz36KzO779P+Hz9+q0V8boLAVqB0tk=; b=CJ8WvJz92LOksqzWChyCdQgegHuA0iI3APF+UbZhF4QTEWI16R6Zi1n2EtGAEhAxFgoWpJ 2IhuE+b5XAhpZg7ZVSz8T8FGoUAYr4iIoPtW3zaHAWtOc6KHuETgfoIDai0N8rWfxqjbhU OFL1WyXZZuX0SiBvAy/0daSoqx7caiDZLTGQOwhOJebvQkfHQDkpukEZnHVAo+QfJCof8f lDnuydDPUcN+YHK6UNRLZ3zf4iff7iraJyNVf+Jhnj4mJWYCNaE1lCBjn+SqVpZFrdRodF 5ewoilq02tbaXMHgi/2snlkBwR6zKEHT1chfANfqXoGu3PI1R2Z77g2CXBMK2Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062253; 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=2mlrLNBzpK9wpMz36KzO779P+Hz9+q0V8boLAVqB0tk=; b=+c+DRtc+oNbJkpTeMlItVZc5M7N1nViAElD/CWYyRFb4rkkQD6yPHkUaB2xaaSn3fF6hR6 Rm3g9gbP3GROP+Bg== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 09/45] posix-cpu-timers: Fix posix_cpu_timer_get() behaviour References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:33 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767966619745932932?= X-GMAIL-MSGID: =?utf-8?q?1767966619745932932?= timer_gettime() must return the remaining time to the next expiry of a timer or 0 if the timer is not armed and no signal pending. This has to be correct also for interval timers even if the signal is pending or the timer has been created with SIGEV_NONE. The posix CPU timer implementation fails for both cases as it does not forward the timer in posix_cpu_timer_get() before calculating the expiry time. It neither clears the expiry value when a oneshot SIGEV_NONE timer expired and returns 1nsec instead, which is only correct for timers with signals when the signal delivery did not happen yet. Aside of that posix_cpu_timer_set() pointlessly arms SIGEV_NONE timers which are later disarmed when the initial expiry happens. That's bogus and just keeping the process wide timer active for nothing. Cure this by: 1) Avoiding to arm SIGEV_NONE timers 2) Forwarding interval timers in posix_cpu_timer_get() 3) Taking SIGEV_NONE into account when a oneshot timer has expired Make the update logic a separate function so it can be reused to simplify posix_cpu_timer_set(). Fixes: ae1a78eecc45 ("cpu-timers: Return correct previous timer reload value") Signed-off-by: Thomas Gleixner --- kernel/time/posix-cpu-timers.c | 96 +++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 42 deletions(-) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -584,12 +584,7 @@ static void cpu_timer_fire(struct k_itim { struct cpu_timer *ctmr = &timer->it.cpu; - if ((timer->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE) { - /* - * User don't want any signal. - */ - cpu_timer_setexpires(ctmr, 0); - } else if (unlikely(timer->sigq == NULL)) { + if (unlikely(timer->sigq == NULL)) { /* * This a special case for clock_nanosleep, * not a normal timer from sys_timer_create. @@ -623,6 +618,7 @@ static void cpu_timer_fire(struct k_itim static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags, struct itimerspec64 *new, struct itimerspec64 *old) { + bool sigev_none = timer->it_sigev_notify == SIGEV_NONE; clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); u64 old_expires, new_expires, old_incr, val; struct cpu_timer *ctmr = &timer->it.cpu; @@ -686,7 +682,7 @@ static int posix_cpu_timer_set(struct k_ if (CPUCLOCK_PERTHREAD(timer->it_clock)) val = cpu_clock_sample(clkid, p); else - val = cpu_clock_sample_group(clkid, p, true); + val = cpu_clock_sample_group(clkid, p, !sigev_none); if (old) { if (old_expires == 0) { @@ -723,19 +719,20 @@ static int posix_cpu_timer_set(struct k_ goto out; } - if (new_expires != 0 && !(timer_flags & TIMER_ABSTIME)) { + /* Convert relative expiry time to absolute */ + if (new_expires && !(timer_flags & TIMER_ABSTIME)) new_expires += val; - } + + /* Set the new expiry time (might be 0) */ + cpu_timer_setexpires(ctmr, new_expires); /* - * Install the new expiry time (or zero). - * For a timer with no notification action, we don't actually - * arm the timer (we'll just fake it for timer_gettime). + * Arm the timer if it is not disabled, the new expiry value has + * not yet expired and the timer requires signal delivery. + * SIGEV_NONE timers are never armed. */ - cpu_timer_setexpires(ctmr, new_expires); - if (new_expires != 0 && val < new_expires) { + if (!sigev_none && new_expires && val < new_expires) arm_timer(timer, p); - } unlock_task_sighand(p, &flags); /* @@ -754,7 +751,7 @@ static int posix_cpu_timer_set(struct k_ timer->it_overrun_last = 0; timer->it_overrun = -1; - if (val >= new_expires) { + if (!sigev_none && val >= new_expires) { if (new_expires != 0) { /* * The designated time already passed, so we notify @@ -785,45 +782,60 @@ static int posix_cpu_timer_set(struct k_ return ret; } -static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp) +static void __posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp, u64 now) { - clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); - struct cpu_timer *ctmr = &timer->it.cpu; - u64 now, expires = cpu_timer_getexpires(ctmr); - struct task_struct *p; - - rcu_read_lock(); - p = cpu_timer_task_rcu(timer); - if (!p) - goto out; + bool sigev_none = timer->it_sigev_notify == SIGEV_NONE; + u64 expires; /* - * Easy part: convert the reload time. + * Make sure that interval timers are moved forward for the + * following cases: + * - SIGEV_NONE timers which are never armed + * - Timers which expired, but the signal has not yet been + * delivered */ - itp->it_interval = ktime_to_timespec64(timer->it_interval); - - if (!expires) - goto out; + expires = bump_cpu_timer(timer, now); /* - * Sample the clock to take the difference with the expiry time. + * Interval timers cannot have a remaining time <= 0 because the + * forwarding guarantees to move them forward so that the next + * timer expiry is > @now. */ - if (CPUCLOCK_PERTHREAD(timer->it_clock)) - now = cpu_clock_sample(clkid, p); - else - now = cpu_clock_sample_group(clkid, p, false); - if (now < expires) { itp->it_value = ns_to_timespec64(expires - now); } else { /* - * The timer should have expired already, but the firing - * hasn't taken place yet. Say it's just about to expire. + * A single shot SIGEV_NONE timer must return 0, when it is + * expired! Timers which have a real signal delivery mode + * must return a remaining time greater than 0 because the + * signal has not yet been delivered. */ - itp->it_value.tv_nsec = 1; - itp->it_value.tv_sec = 0; + if (!sigev_none) + itp->it_value.tv_nsec = 1; + } +} + +static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp) +{ + clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); + struct cpu_timer *ctmr = &timer->it.cpu; + struct task_struct *p; + u64 now; + + rcu_read_lock(); + p = cpu_timer_task_rcu(timer); + if (p) { + itp->it_interval = ktime_to_timespec64(timer->it_interval); + + if (cpu_timer_getexpires(ctmr)) { + if (CPUCLOCK_PERTHREAD(timer->it_clock)) + now = cpu_clock_sample(clkid, p); + else + now = cpu_clock_sample_group(clkid, p, false); + + __posix_cpu_timer_get(timer, itp, now); + } } -out: rcu_read_unlock(); } From patchwork Tue Jun 6 14:37:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103909 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3464567vqr; Tue, 6 Jun 2023 08:08:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5C1oIsJ3Q2Wau2v4eI6f2smLK5frCEXxTXcZn3N0Nd8zkYTihuPgcMtao3a+eRD77e3Lu2 X-Received: by 2002:a17:90b:4f8a:b0:258:ebb3:932 with SMTP id qe10-20020a17090b4f8a00b00258ebb30932mr1113645pjb.3.1686064135555; Tue, 06 Jun 2023 08:08:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686064135; cv=none; d=google.com; s=arc-20160816; b=ILC716FdJikFfZwaF/jOV5eJ4osroUPWH1MY/s01K/aF7o0vIqRHkXLXUfrjTTPNSJ gq+jJhh79MMKeOoSRIzcLSABEqHzSJdJiNGTfHg2yy2+c0ou1IsVaPh1skQwrCczVxqJ 14NeBgC07zFSgyzmUSXo+Cc6W/S48irXH497sVRGvKjUA9k4cUPxDDqGz21QRJJBKaqn IlJCaHHvGS5z74/cSO7JSas7kK0Ns3JiG6PJxOH7Aqdcd4jzST4XVD/evSG1QofKVftV eZ8Ph9ODPbDLkDjmJv53fQNhDu0pyteOhW/2hhTw6SBKgCrmBjrO9Qaj3hwBt8AxH/0o AMRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=HZelD7evOzJCYoBqQ1DtkrmmziVEl2j+krjTDCi41Fw=; b=TssqaOYm+Kis4d28pGADg9as6gXXZFmafZm296vtv2tRHpoNyazC85/p41IPx08CQu Xi+4fKAd5gBx5tB6uXu3EyfA+gZ7JjeTwpn5b7arIZ7jlctMELLTrsRwsY5KJqeLjcT9 KSKbWbP3CD1PVmyv00XIKnKX+pDYUXI3QGmQmOtkv5ZIRuCFfjkje7I1GgGDrOuBCkNx 3YqsK3dcUXsi5Qg4tihLYpi8YAM9v8rN2x3km3pkHqwa9rIZilEOpIFr6CYZM28/aRHl RUYovkDqztgx19dn1iqgqdNLlCXSgDFIQr4w//YNN0D4YCDkP+ZF/nJQflw3RAamjB+Q MRtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=eKWFjcJL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=DZ+CbV6p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l69-20020a638848000000b0054288b91d66si7315184pgd.635.2023.06.06.08.08.42; Tue, 06 Jun 2023 08:08:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=eKWFjcJL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=DZ+CbV6p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238146AbjFFOiI (ORCPT + 99 others); Tue, 6 Jun 2023 10:38:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238053AbjFFOhw (ORCPT ); Tue, 6 Jun 2023 10:37:52 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 815E7170B for ; Tue, 6 Jun 2023 07:37:36 -0700 (PDT) Message-ID: <20230606142031.591764431@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062255; 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=HZelD7evOzJCYoBqQ1DtkrmmziVEl2j+krjTDCi41Fw=; b=eKWFjcJLrzMr3pZrkCaPux8kc0/F5ATRMLRIkAmIXE6vAW2dLhmRu1FlnipAK8ZqAY87yN OKdVizAKcJwW+gDt6j3meD7VOb5suNceXo19xEpUev4iofYTJRl26w0Xy4alTZM/CxVXfe u5Jn1bIM2B7BbNYM9CmWdtcD7q+H7+Eh+kVl3u+Rl0NR55gR6TKNZ+Wfa38jIBGrSAX+qT SUFbn8l+kwkxvZMmCk1gb4P/lmmbv8D/ltbIfN/lrH0YwzcTdZsbdw/QYws73GyNWn9gJ0 2jXicaTUDGO28/nNj+QYy82r/Znje7VcTuELo1Q0ucGg/iEcnlgY+4yPrAurdw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062255; 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=HZelD7evOzJCYoBqQ1DtkrmmziVEl2j+krjTDCi41Fw=; b=DZ+CbV6pqD6kTZqg47gK9orPuBvbFpmsqiJfvD93glKabXigqESgkTneY7J5E6nbMULLEW 9J1HkuJTyR6CM1BQ== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 10/45] posix-cpu-timers: Use @now instead of @val for clarity References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:34 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767966387048154007?= X-GMAIL-MSGID: =?utf-8?q?1767966387048154007?= posix_cpu_timer_set() uses @val as variable for the current time. That's confusing at best. Use @now as anywhere else and rewrite the confusing comment about clock sampling. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker --- kernel/time/posix-cpu-timers.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -620,7 +620,7 @@ static int posix_cpu_timer_set(struct k_ { bool sigev_none = timer->it_sigev_notify == SIGEV_NONE; clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); - u64 old_expires, new_expires, old_incr, val; + u64 old_expires, new_expires, old_incr, now; struct cpu_timer *ctmr = &timer->it.cpu; struct sighand_struct *sighand; struct task_struct *p; @@ -672,17 +672,13 @@ static int posix_cpu_timer_set(struct k_ } /* - * We need to sample the current value to convert the new - * value from to relative and absolute, and to convert the - * old value from absolute to relative. To set a process - * timer, we need a sample to balance the thread expiry - * times (in arm_timer). With an absolute time, we must - * check if it's already passed. In short, we need a sample. + * Sample the current clock for saving the previous setting + * and for rearming the timer. */ if (CPUCLOCK_PERTHREAD(timer->it_clock)) - val = cpu_clock_sample(clkid, p); + now = cpu_clock_sample(clkid, p); else - val = cpu_clock_sample_group(clkid, p, !sigev_none); + now = cpu_clock_sample_group(clkid, p, !sigev_none); if (old) { if (old_expires == 0) { @@ -696,10 +692,10 @@ static int posix_cpu_timer_set(struct k_ * though we are swallowing that pending * notification here to install the new setting. */ - u64 exp = bump_cpu_timer(timer, val); + u64 exp = bump_cpu_timer(timer, now); - if (val < exp) { - old_expires = exp - val; + if (now < exp) { + old_expires = exp - now; old->it_value = ns_to_timespec64(old_expires); } else { old->it_value.tv_nsec = 1; @@ -721,7 +717,7 @@ static int posix_cpu_timer_set(struct k_ /* Convert relative expiry time to absolute */ if (new_expires && !(timer_flags & TIMER_ABSTIME)) - new_expires += val; + new_expires += now; /* Set the new expiry time (might be 0) */ cpu_timer_setexpires(ctmr, new_expires); @@ -731,7 +727,7 @@ static int posix_cpu_timer_set(struct k_ * not yet expired and the timer requires signal delivery. * SIGEV_NONE timers are never armed. */ - if (!sigev_none && new_expires && val < new_expires) + if (!sigev_none && new_expires && now < new_expires) arm_timer(timer, p); unlock_task_sighand(p, &flags); @@ -751,7 +747,7 @@ static int posix_cpu_timer_set(struct k_ timer->it_overrun_last = 0; timer->it_overrun = -1; - if (!sigev_none && val >= new_expires) { + if (!sigev_none && now >= new_expires) { if (new_expires != 0) { /* * The designated time already passed, so we notify From patchwork Tue Jun 6 14:37:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103883 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3450368vqr; Tue, 6 Jun 2023 07:49:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4BUK6clWnoVSCrhSxAHetxGIy+f1ZfeIE8DLOjIIH+GCdBkXT6R6HZjxnm97UDZ5SFqwj6 X-Received: by 2002:a05:6a20:a5a2:b0:10e:f1e3:8217 with SMTP id bc34-20020a056a20a5a200b0010ef1e38217mr1035232pzb.17.1686062996385; Tue, 06 Jun 2023 07:49:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686062996; cv=none; d=google.com; s=arc-20160816; b=ykBHrrSmQB8zD2Xwd/mQ552OR/cx9srJQ1XU0ajsv97+T8TEe3FigPwRRJPPTP9nWU NkmHjBgozanRJZCnE8MDQAEaRz5t/y+8OGEZiQCFma9WBEZqQ8D7ZGn7ph10+ynZ7CSG GCBQA3KbsDds95Nzt8TDZcRzuvUZqquQAQ+WJpQMfG1Tdr0B2YYJWoBATK/v/a95BpyK C/73IbDckxSLHHVOKFa9cAUNdIW8qUnH3+KOCXBKZd6w5b08umC3dqnQt7P1knHRpx6P m81wqQIoAafJ8FYfiHmCGSMFM61rHO5qxbSRP2Cuj85CGR1NVdXKIVjuYpRIcIZDYvo/ M5vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=8wmGhqPNf6kLMrAqxn6joNLQMcupbwgXa/J0H7C+wQY=; b=diiQW54aH2Yxx1r+fJvG8OeoiQbvAUho7n5u6OebN4B4JkfI2OJN0Afpeof1qOBH2n 9y2Azp81lE/JRCnuM9Rdmr6VUds6JkBid3AR/wzxsnNYY2d/WRcGj+0OoYCeghkjBp3k sexfyZviIG+pdUfR6sYyvTYU7asbIkTIFVcJYXegEwdpeCuVCQCQlqbOEyQv0LNn15Dx JRkY+hyoc7E1awAvU77oDw8imqGct9XfF9JIQpuP//U4XnynFOGGtWtzE6x1UDmAcHJ5 PHr0zXnN/9THcYKjskW0MgM+Xd+lvpUCosUWjNJxLOGqgulAoOVefDx5A0MDwO1NzYCd Evog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GwMdq1Jo; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=AFQgyOFQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t7-20020a1709028c8700b001b20bf44a42si3473589plo.251.2023.06.06.07.49.43; Tue, 06 Jun 2023 07:49:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GwMdq1Jo; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=AFQgyOFQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238154AbjFFOiL (ORCPT + 99 others); Tue, 6 Jun 2023 10:38:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238061AbjFFOhx (ORCPT ); Tue, 6 Jun 2023 10:37:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8952A171A for ; Tue, 6 Jun 2023 07:37:38 -0700 (PDT) Message-ID: <20230606142031.648340279@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062256; 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=8wmGhqPNf6kLMrAqxn6joNLQMcupbwgXa/J0H7C+wQY=; b=GwMdq1JohYipn8STMGUW7ZcBa0yY0aE3Ne8q2Y9kWG6zabuktu+VI67AjX4eDD+0a+nfDQ Y5y91IEr8HN2mxJVrGL5+RPQvuivR8M9KTlm9W21IBPkuEff8Ga4g1o5Bt0mYvUcmII07A 3rahALeLN57kl6Xfo9m1eVR3o9mND58LTV+fiR/lwgnq89D337yFIktgK83Wh/Lq++f+bW k6SXurPQDJPLB+GXX4Zi7UhydCCH35CP3tSuwcEOZTrkHs4vKmHbI2hPwi6bsbaWpNZy4W y+NZUY2n1XOUpcTQ2vxyZGs5aEkTjT2CiCdAR1FOy2Syh6s9Z464xbdAXQiUaw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062256; 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=8wmGhqPNf6kLMrAqxn6joNLQMcupbwgXa/J0H7C+wQY=; b=AFQgyOFQtWxkhRmhQZ8dSxldXlmaT+Lhpj3c5Vt0pTIv0bC1H3JDQa2jlaj3E8vb34iPS+ p88qJF0IKGlbLFBg== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 11/45] posix-cpu-timers: Remove incorrect comment in posix_cpu_timer_set() References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:36 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965192290563376?= X-GMAIL-MSGID: =?utf-8?q?1767965192290563376?= A leftover from historical code which describes fiction. Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker --- kernel/time/posix-cpu-timers.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -704,13 +704,8 @@ static int posix_cpu_timer_set(struct k_ } } + /* Retry if the timer expiry is running concurrently */ if (unlikely(ret)) { - /* - * We are colliding with the timer actually firing. - * Punt after filling in the timer's old value, and - * disable this firing since we are already reporting - * it as an overrun (thanks to bump_cpu_timer above). - */ unlock_task_sighand(p, &flags); goto out; } From patchwork Tue Jun 6 14:37:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103897 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3454865vqr; Tue, 6 Jun 2023 07:57:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5/ZmyZTYq/iOZPCbj5ZhUCxxVI2kwuwVTynjMHJkoBHDm78ALAv+zYOGohVB6md9Ig/XKn X-Received: by 2002:ac8:5dd4:0:b0:3f8:67d7:e99c with SMTP id e20-20020ac85dd4000000b003f867d7e99cmr2034863qtx.39.1686063475447; Tue, 06 Jun 2023 07:57:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063475; cv=none; d=google.com; s=arc-20160816; b=Bw8GhlTRb6p+vqt9CNEVtOE7YWurd8iTohqKtc1QkBMqC5l/uFiKZ/BrgrtHGwXili adnNZn7axtgmx+fqTOUNPrO5obRIFZ5WV92EVWkbYBkF0DeRMWJ5/Ip9cRA9+yy4Rprv eBtSjyLZebKFeI0rxAEw6l02xYpYbCtwJIKtdjg8yfOz3M7UdiBZw06z1/HLtOQ9Yd17 xmczat0FNz8AA0Pvxd42ITd3GSfxTYcWVMfRRbZquTsO6ncm3fhiqFXJEQodTWto5IZB 7vEA1DnNMGAALAzvFwrTO6Pqe/tRrdEa6lb6RYCCvqQACusRMu6hJLI49l1J0+CAXjra sk3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=dI0D1Wo/Od6DcD7Ru+BANLzwyGF+XR8DfEoK3hFuF2Q=; b=En0g3S2mdH5Y+1gKwxBVxaz71NG18GrGAMqRAsxOgS3FrjHkzYLDQR461BahdX3sfO MGjNbJeHLZzJ+SoqCOeAEgywsacgilg7FF20LsN1jHvAjAi2REeklGI6GLdhOLfaYRGM 2c9teAQHgt86bK8bsINDI1/kasnqeYbKjr9jd8Ft6IEbpUHZOO76U22VQtz4y9A57hny xfBalzPAzkjmWNf8n+s2f/B2fHqFv49Usp+ZKSeTmDi7Mn9wAvNDpqEhyGoSRAYSdIkm AX01OgDvxh2Z+ciYDpl9P/my5gLgYx5ZKDqjE9oaj+2tKHU5jp6AyhrRbvp7/H3i4kkU F38Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Yk/DXFdl"; dkim=neutral (no key) header.i=@linutronix.de header.b="SNm/mWkM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f21-20020a05622a105500b003f4e3171deasi6328978qte.76.2023.06.06.07.57.11; Tue, 06 Jun 2023 07:57:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Yk/DXFdl"; dkim=neutral (no key) header.i=@linutronix.de header.b="SNm/mWkM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238032AbjFFOiV (ORCPT + 99 others); Tue, 6 Jun 2023 10:38:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237955AbjFFOh6 (ORCPT ); Tue, 6 Jun 2023 10:37:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3070172E for ; Tue, 6 Jun 2023 07:37:39 -0700 (PDT) Message-ID: <20230606142031.705286109@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062258; 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=dI0D1Wo/Od6DcD7Ru+BANLzwyGF+XR8DfEoK3hFuF2Q=; b=Yk/DXFdlqLfDQyfx0BKzMlN/bE3cA9fTYL2SSewfi6g0ICus4972urAWOD18WUFrh8QElC J2cZ+8OHKTjsths3W8x50BG9w+ENc2CAv0z9OyxhrYV9U2Khyusw5ZL++NT1iWc3Iw/NoW U7GHdOSNqa54uenn6q2mW4QdYxaUIH3QWvztjseXzYm93xO3le3AajEnSDX02FtCwZzB5H 7ta7T0VkQEUzZ4AVGTQ5cTQG5WGT2B3OV/cOVbp7uyRGicCMiZfpp+wBEnp2KxryAAA8if PJvMUwjuhbMdyuEf4D+zN9MMG1vngzz37BKBmzPQrDgwUdGEgP7QnKYvj/Z12w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062258; 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=dI0D1Wo/Od6DcD7Ru+BANLzwyGF+XR8DfEoK3hFuF2Q=; b=SNm/mWkMVZs8Rfv0eVLM0rOkYdYVZZ281k1zAaoHe4TG53Ioth7F4d1QqGFxgdGx53QrZA udmiyD8CV7sID9CQ== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 12/45] posix-cpu-timers: Simplify posix_cpu_timer_set() References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:37 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965694638878079?= X-GMAIL-MSGID: =?utf-8?q?1767965694638878079?= Avoid the late sighand lock/unlock dance when a timer is not armed to enforce reevaluation of the timer base so that the process wide CPU timer sampling can be disabled. Do it right at the point where the arming decision is made which already has sighand locked. Signed-off-by: Thomas Gleixner --- kernel/time/posix-cpu-timers.c | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -720,10 +720,14 @@ static int posix_cpu_timer_set(struct k_ /* * Arm the timer if it is not disabled, the new expiry value has * not yet expired and the timer requires signal delivery. - * SIGEV_NONE timers are never armed. + * SIGEV_NONE timers are never armed. In case the timer is not + * armed, enforce the reevaluation of the timer base so that the + * process wide cputime counter can be disabled eventually. */ if (!sigev_none && new_expires && now < new_expires) arm_timer(timer, p); + else + trigger_base_recalc_expires(timer, p); unlock_task_sighand(p, &flags); /* @@ -742,30 +746,14 @@ static int posix_cpu_timer_set(struct k_ timer->it_overrun_last = 0; timer->it_overrun = -1; - if (!sigev_none && now >= new_expires) { - if (new_expires != 0) { - /* - * The designated time already passed, so we notify - * immediately, even if the thread never runs to - * accumulate more time on this clock. - */ - cpu_timer_fire(timer); - } - - /* - * Make sure we don't keep around the process wide cputime - * counter or the tick dependency if they are not necessary. - */ - sighand = lock_task_sighand(p, &flags); - if (!sighand) - goto out; - - if (!cpu_timer_queued(ctmr)) - trigger_base_recalc_expires(timer, p); - - unlock_task_sighand(p, &flags); - } - out: + /* + * If the new expiry time was already in the past the timer was not + * queued. Fire it immediately even if the thread never runs to + * accumulate more time on this clock. + */ + if (!sigev_none && new_expires && now >= new_expires) + cpu_timer_fire(timer); +out: rcu_read_unlock(); if (old) old->it_interval = ns_to_timespec64(old_incr); From patchwork Tue Jun 6 14:37:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103910 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3464999vqr; Tue, 6 Jun 2023 08:09:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5J0JhPvfzwJWDuS6L9pYyogpJmFVW0JlBQf9HwDF2YV6eZUMyQDf7EWEjoRGYHqhW8JN1i X-Received: by 2002:a05:620a:4592:b0:75d:520b:cdb8 with SMTP id bp18-20020a05620a459200b0075d520bcdb8mr3247120qkb.35.1686064162258; Tue, 06 Jun 2023 08:09:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686064162; cv=none; d=google.com; s=arc-20160816; b=v0WudlKL3x61LuWi0MMZ8sepwRt5GWL4byo+tdV0uQb/8O39icb/EyLW0mhpR3MJAb X1tOk4I3JplTPDpo6oRZRTczZb+7c2TYtXQDETMhcTuFEnylB7SBFzGqD1GHr8fWHMyN gzHIcGMewA2iliadsKUYa/RF9JFfQwVQHTqSeLUW8qRxnwWHUPe8VMQydsV2WBxp9dGw TLMTDbcdoXXr1/Fop8RRIGKokEJV7t0Ad/qNXX3NHl+XSrxFnxu868rYZTNrlu0VU2+M o2riUmzsqoIB2Y7UMlQJ52Y2qdDaqEkwpMTCvpVM9aOOJxIaG6/OXArCtMS6N6mco7SC Z/9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=ob/W6MhzxScgyFPIMc+gvNg8o5xjqBQZWBN/IorB7bE=; b=wTIBC2PweFbkAxkVPqQ9Qdu4wuFIAgwhnJ8hXLTUM3ELl9EoEES75idJHtYF2WnzMk 3zPnXtkHcwLpmpy+gSdu+n405cXv4XPa76eB8qrX3pWJFVjsm5AM/9FQ7nfVv50pCOra 43d774ktP/RsWZ6NPH8q2Tf75mDSBqWY9eLsD5DPDogJVKcgNrdJ69YY37PInal1CG/a VDGNX/5++QF8gxBV4u/lbKE3BUr9lC3OetG0l3qrEUYrKkwKhgtxllNz3gZoka002zB9 HuNbkQXU074ku458gK1RpGF7ohaWDtCPxGeuQcAeiZrKrS43AUf/kjYYUutwiHK3huUr sOWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SCvoCkSp; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x20-20020ae9e914000000b0075b05e65a32si4030539qkf.528.2023.06.06.08.09.08; Tue, 06 Jun 2023 08:09:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SCvoCkSp; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238196AbjFFOiT (ORCPT + 99 others); Tue, 6 Jun 2023 10:38:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238012AbjFFOh6 (ORCPT ); Tue, 6 Jun 2023 10:37:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EE6F10E0 for ; Tue, 6 Jun 2023 07:37:41 -0700 (PDT) Message-ID: <20230606142031.761271959@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062259; 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=ob/W6MhzxScgyFPIMc+gvNg8o5xjqBQZWBN/IorB7bE=; b=SCvoCkSp2EBNPlg9q940g+JrZP6pzFOgz7FFTWpU46jD5cHmKxKnhMZjnbZ9xoPZCpn3ae FVI578SMgJamC3rLpuuE0d9oufWTkLhmu/h29m2mbczYj9XIo0jczpnqU4XebflDkC2Fdl xI7TfXR/VSOru+FfjXi95UcYj6t8ucuEJeBkHeGzzET9MmOCCDx9JdYA7BDNvIE1ufK3gL hZU043m7L2kxkfuozb1a5r3cYXeS0+IorFh837i9kxsGH85T+cx/k6J/lQxkF5kkaE8McZ T36BXvfzeE6X7FZpYYioGrJE1f7S/Ffhxf5c98hWVriw05GhCegVxf2GeNks9w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062259; 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=ob/W6MhzxScgyFPIMc+gvNg8o5xjqBQZWBN/IorB7bE=; b=nQFBQ5ePLWCt0uAyyP09UUBBGlfIp/c+ObKLOPQeUWXRW/gOnELQ77dt6uEmoAQmjmauIu NfATje6SDz2RZGDQ== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 13/45] posix-cpu-timers: Replace old expiry retrieval in posix_cpu_timer_set() References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:39 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767966414945009492?= X-GMAIL-MSGID: =?utf-8?q?1767966414945009492?= Reuse the split out __posix_cpu_timer_get() function which does already the right thing. Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker --- kernel/time/posix-cpu-timers.c | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -609,6 +609,8 @@ static void cpu_timer_fire(struct k_itim } } +static void __posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp, u64 now); + /* * Guts of sys_timer_settime for CPU timers. * This is called with the timer locked and interrupts disabled. @@ -680,29 +682,9 @@ static int posix_cpu_timer_set(struct k_ else now = cpu_clock_sample_group(clkid, p, !sigev_none); - if (old) { - if (old_expires == 0) { - old->it_value.tv_sec = 0; - old->it_value.tv_nsec = 0; - } else { - /* - * Update the timer in case it has overrun already. - * If it has, we'll report it as having overrun and - * with the next reloaded timer already ticking, - * though we are swallowing that pending - * notification here to install the new setting. - */ - u64 exp = bump_cpu_timer(timer, now); - - if (now < exp) { - old_expires = exp - now; - old->it_value = ns_to_timespec64(old_expires); - } else { - old->it_value.tv_nsec = 1; - old->it_value.tv_sec = 0; - } - } - } + /* Retrieve the previous expiry value if requested. */ + if (old && old_expires) + __posix_cpu_timer_get(timer, old, now); /* Retry if the timer expiry is running concurrently */ if (unlikely(ret)) { From patchwork Tue Jun 6 14:37:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103911 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3465394vqr; Tue, 6 Jun 2023 08:09:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5F8+Ae5nOCKMVbTAQh0QmxhEpdUJdl/EG8X56aByuX+yNl2abRz1uwKKa0Mi87RF+jmRgn X-Received: by 2002:a17:902:ceca:b0:19c:dbce:dce8 with SMTP id d10-20020a170902ceca00b0019cdbcedce8mr2545033plg.15.1686064194035; Tue, 06 Jun 2023 08:09:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686064194; cv=none; d=google.com; s=arc-20160816; b=w9ztvF7b7QkTvf1NipbzT7tL0mncsJ/w9VipNDc1NQTTufsAtQTqXpTDyy0QsFlzgR RRHmHXCkoFuICvu7AE0z0BpTVsMv0CCuVLjXBjmcIqqzZcKOYl73S3N8ZoumkWR8buau m9l+YHku7lfAo0pbq1WxPFFsvMk/Eo657uWeKchYDp2quo/UCoEsRqSlW3gjoGa95bxV YrG0d5TRaol2ZtkzMv2maoiMpoXIBmvzii7btwD99EEOeP3kT1dHiDt5FtqFl/OiPMzy 47uJriJZ9n9zgiiHx56te0ut+mQDmWWFE/dGJcqELRA6h0QEiFfKNXPLMGA9ThRzygcH nD3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=BUuJOcWJlcdLruwzTzGc8KK7BJlrslnwV3YCPjzAVYM=; b=NSjpMEERE8KuOeOmIf6Yi0n+48RxX8NIlyrE1kIR+ne8t1P1yMJIYi0oTFfbbZWoxT PNfyQ9ZX15rA/gx91vNw3Eh6YSrXwp7062n4o7LWVSW0TB0fYiMTHev8ho9ygEbg2qmz bCeRvJwGUzThhZDCGhlYnmgyyy5MwEhyX+fw5PCOkJmw+eUEF2M750mtsbYjOV3tg0M3 XirWHf8zW4LSeZXTIzVdkP3Kqe1odBlto7A1gynMXDXOeVRMcZsL8c+5cKxk+re9/N3E ybfifUbnNBFpL1qxZyQ+a2jFFpFBjr7xPstFYs3VJ7mhNACQt9SUhLVC5/ASlQgpl3xj iBaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=I5569+xR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iw13-20020a170903044d00b001ac91ece0dasi7072377plb.7.2023.06.06.08.09.40; Tue, 06 Jun 2023 08:09:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=I5569+xR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237283AbjFFOiX (ORCPT + 99 others); Tue, 6 Jun 2023 10:38:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238117AbjFFOh7 (ORCPT ); Tue, 6 Jun 2023 10:37:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDD981980 for ; Tue, 6 Jun 2023 07:37:42 -0700 (PDT) Message-ID: <20230606142031.816970056@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062261; 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=BUuJOcWJlcdLruwzTzGc8KK7BJlrslnwV3YCPjzAVYM=; b=I5569+xRiO8L9SxBdKWLlInNoyMp15B5f1fsUhs1CMRrvo5cp44kG2L/Vcn4zOOOwD3ItK P0YOx8Jr1BJcWmL6/6Bre25ByppqEqyTZGXau7n2XKgzVwo1iKT+NygySaNgaVIaZgKgDm FBGuAblTC/3KUREjAh0G5g+N332bg8jawAaS4FdNzKcaqvn4/9dys+TWVzQH1Dig/P+eJ3 M6jDAzJ009c4ETi/evZbe7DzEEPSKUMTFfWtKzSjHvkYNnRQWMpIVDTaNx7mek0YPtQwZu IWNGPjoYqTN6VZJWe/scJykc/7NCj9CRvp36kpt0gfRsLPx5zwOwoBsmbMnUhw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062261; 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=BUuJOcWJlcdLruwzTzGc8KK7BJlrslnwV3YCPjzAVYM=; b=/2HWb7Dxf5+XWRHkdmmsirK76BRh2t1DBD0zPzjUamOK6oidZTOXdFM19EyVGUwK69a7Pm sCh2xituWWCaJOBA== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 14/45] posix-timers: Consolidate interval retrieval References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:40 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767966448106476070?= X-GMAIL-MSGID: =?utf-8?q?1767966448106476070?= There is no point to collect the current interval in the posix clock specific settime() and gettime() callbacks. Just do it right in the common code. Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker --- kernel/time/posix-cpu-timers.c | 26 ++++++++------------------ kernel/time/posix-timers.c | 18 +++++++++--------- 2 files changed, 17 insertions(+), 27 deletions(-) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -622,8 +622,8 @@ static int posix_cpu_timer_set(struct k_ { bool sigev_none = timer->it_sigev_notify == SIGEV_NONE; clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); - u64 old_expires, new_expires, old_incr, now; struct cpu_timer *ctmr = &timer->it.cpu; + u64 old_expires, new_expires, now; struct sighand_struct *sighand; struct task_struct *p; unsigned long flags; @@ -660,10 +660,7 @@ static int posix_cpu_timer_set(struct k_ return -ESRCH; } - /* - * Disarm any old timer after extracting its expiry time. - */ - old_incr = timer->it_interval; + /* Retrieve the current expiry time before disarming the timer */ old_expires = cpu_timer_getexpires(ctmr); if (unlikely(timer->it.cpu.firing)) { @@ -737,9 +734,6 @@ static int posix_cpu_timer_set(struct k_ cpu_timer_fire(timer); out: rcu_read_unlock(); - if (old) - old->it_interval = ns_to_timespec64(old_incr); - return ret; } @@ -785,17 +779,13 @@ static void posix_cpu_timer_get(struct k rcu_read_lock(); p = cpu_timer_task_rcu(timer); - if (p) { - itp->it_interval = ktime_to_timespec64(timer->it_interval); - - if (cpu_timer_getexpires(ctmr)) { - if (CPUCLOCK_PERTHREAD(timer->it_clock)) - now = cpu_clock_sample(clkid, p); - else - now = cpu_clock_sample_group(clkid, p, false); + if (p && cpu_timer_getexpires(ctmr)) { + if (CPUCLOCK_PERTHREAD(timer->it_clock)) + now = cpu_clock_sample(clkid, p); + else + now = cpu_clock_sample_group(clkid, p, false); - __posix_cpu_timer_get(timer, itp, now); - } + __posix_cpu_timer_get(timer, itp, now); } rcu_read_unlock(); } --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -636,17 +636,12 @@ static s64 common_hrtimer_forward(struct */ void common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting) { + bool sig_none = timr->it_sigev_notify == SIGEV_NONE; const struct k_clock *kc = timr->kclock; - ktime_t now, remaining, iv; - bool sig_none; + bool iv = !!timr->it_interval; + ktime_t now, remaining; - sig_none = timr->it_sigev_notify == SIGEV_NONE; - iv = timr->it_interval; - - /* interval timer ? */ - if (iv) { - cur_setting->it_interval = ktime_to_timespec64(iv); - } else if (!timr->it_active) { + if (!iv && !timr->it_active) { /* * SIGEV_NONE oneshot timers are never queued and therefore * timr->it_active is always false. The check below @@ -705,6 +700,8 @@ static int do_timer_gettime(timer_t time return -EINVAL; memset(setting, 0, sizeof(*setting)); + setting->it_interval = ktime_to_timespec64(timr->it_interval); + kc = timr->kclock; if (WARN_ON_ONCE(!kc || !kc->timer_get)) ret = -EINVAL; @@ -918,6 +915,9 @@ static int do_timer_settime(timer_t time if (!timr) return -EINVAL; + if (old_spec64) + old_spec64->it_interval = ktime_to_timespec64(timr->it_interval); + kc = timr->kclock; if (WARN_ON_ONCE(!kc || !kc->timer_set)) error = -EINVAL; From patchwork Tue Jun 6 14:37:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103892 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3452586vqr; Tue, 6 Jun 2023 07:53:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6vnHdAz6isSpP3enVL8Fusj8JVHP4winzJQgYrtWBC9lqguUYHFPe+5wILTq/mVnx6QYrF X-Received: by 2002:a05:6214:403:b0:628:8012:bedd with SMTP id z3-20020a056214040300b006288012beddmr3329754qvx.23.1686063236741; Tue, 06 Jun 2023 07:53:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063236; cv=none; d=google.com; s=arc-20160816; b=XAhj05hqu818ZVYwmR1vtOx9DW8Fv1UX/PhzFoWee1mTQ4KY4axym4yPtaStQ1G2Ra Y1WbEK+CDdDiX3fYZgTPIjD5g2yRYYjqvueKRZZiX89NoIGBM3JmvcYq2TWyjazu2CXF aOv95QoaEK6qeEHPlPN+YHoIBHJVdrJ+nWGFEFnxIGz+RnMu+GXTeFje1d5rdfb+usV6 eFZBOSlWemEsD0u7yfWaJYXTHuilJc9EPJpNzDsSiu4AGEuMgCZ88QFzvLvclc0+5CXp ESTH8AoJkdBbWMcqRpW3NCv7poA0outbObjkps+P2+C2lvuHXVEHfK5VlDAXzibQfl/7 Yuew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=rQhQI9gfYBa5P/AVMCL9wQCPxah+3H97GdCXzoiFlTY=; b=A1pjIGyTMTk14cLIHowua0itInMGxkYKxRgJHXwpTQfGdXLD6fySBq6frelDhRfLa9 WMnRS7Fpa0oDJZqqs0Yz+zgyybNeQz0NOSVaRjNLqvtOeFHPZ0CM0kzbjdoyiB1X+V/k h/c6EFI+bzrlbtNUHNS6GUcQvhbehzx374UO/YnbgK0+XUHX0T9ykpyIYCyOJl26LXRk X1XEnVkNcG9yMFPI+4+KpqQWwSVExZOjFRtIMtohUg7aMbxxi4YEMC+m65Ksunxcy/d6 GuFYsTSC3MN0UY+IdvFbGZtfCOkuOFCCba8oMYv6AeOnx3B2pygVRhmwAAvqtuaoMtBH r4bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xj06h7G2; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=H6NJu23p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g8-20020ac85808000000b003f9a7bba2casi2264858qtg.406.2023.06.06.07.53.42; Tue, 06 Jun 2023 07:53:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xj06h7G2; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=H6NJu23p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236737AbjFFOic (ORCPT + 99 others); Tue, 6 Jun 2023 10:38:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238139AbjFFOiA (ORCPT ); Tue, 6 Jun 2023 10:38:00 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAEB9198C for ; Tue, 6 Jun 2023 07:37:44 -0700 (PDT) Message-ID: <20230606142031.872478114@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062263; 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=rQhQI9gfYBa5P/AVMCL9wQCPxah+3H97GdCXzoiFlTY=; b=xj06h7G2AYuL8XA++I9UO3Tv1HthEl4dLE7oPU7JbFZ/+TZxwMAc8uTehkZNcyX/ZP4rer o1y5qyIdGw2Mu7QAHEEWRZ2lBuZZWBDOEuXPAnIwOVcgYNi801OeIE/mW5WpQmU1vFhAf/ B+Xa9iasYCAVeffcCeSe+dzyLc4tRHmCFup6o5W6Bl8OHAD/F0cKE7m9SVXE8bvCwWKgOl zOII3BcKHF0ZP0frhI4/nZIRHH21D0ArWVsUAQbHTZHYzCihbcxJThjmTUsmFx05htv7U7 cZo6rr+MrdUFepmjJMXA4nVC5KAPPzUitd0dpuAF2eozJdC8PXOPBC2iU3MQuQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062263; 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=rQhQI9gfYBa5P/AVMCL9wQCPxah+3H97GdCXzoiFlTY=; b=H6NJu23pM67W+4Wwdro+qTF2fnserfMFQXQZIBAcn6l/+MFh0aGf5bjOGA8hsJVHoR2MQd gLnBPwseG2ePG/DA== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 15/45] posix-timers: Clear overrun in common_timer_set() References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:42 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965444464633217?= X-GMAIL-MSGID: =?utf-8?q?1767965444464633217?= Keeping the overrun count of the previous setup around is just wrong. The new setting has nothing to do with the previous one and has to start from a clean slate. Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker --- kernel/time/posix-timers.c | 1 + 1 file changed, 1 insertion(+) --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -867,6 +867,7 @@ int common_timer_set(struct k_itimer *ti timr->it_requeue_pending = (timr->it_requeue_pending + 2) & ~REQUEUE_PENDING; timr->it_overrun_last = 0; + timr->it_overrun = -1LL; /* Switch off the timer when it_value is zero */ if (!new_setting->it_value.tv_sec && !new_setting->it_value.tv_nsec) From patchwork Tue Jun 6 14:37:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103881 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3450012vqr; Tue, 6 Jun 2023 07:49:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5+UdBk8dZQXeZtYEbKJQ+IPcMMyKSUasLdB0GV+8+v3WFY+lZO8zCX3n/Ie4LyfSk5neQj X-Received: by 2002:a05:6358:4e11:b0:129:c1c1:c897 with SMTP id cf17-20020a0563584e1100b00129c1c1c897mr1991390rwb.24.1686062958322; Tue, 06 Jun 2023 07:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686062958; cv=none; d=google.com; s=arc-20160816; b=cVEk+I0Iqedqmw+yRM48zcfLY+a3JZRhVwRroGPEQIR2lGj3ZhO0r3dKL7cpNUZZ8Q 7alE0oLurw1ZmCzG1MlpobpOHw789GderEBPH26wQlmd3WTpDyJpZYjTvzSLUbrGBUHA aG3J0pIB/fvVwn9uI6utKj3bdSoEdUPouCCDVIztqAigoyBuQJhLHJHYUR/LQ1roHZD1 +OFsjy421ksdNgCWTBamjofuMaWDMkG/2D3WVAki0iq4F9yhpN1XCWZAn54Ud9GIxadE pXG53R9KgUPWFliY+4Y9PUgX7kZLvTzBCWwgTQPlI3tdEwoFJep8mcvNGAC5cRBfueVG P9iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=BVz57Fiq4y3HANqcZc1xKtZ2T7kpNoRDOZcZ2I4Dywg=; b=kShIoirfEV/k1qoj/6OpmqcCQwGCPZtptqvD/Rz2yqWDXA6JQFAyujAdH9zkCtUVDJ F1iCpdsI8rTRhV0WC249y0epe25ZQyjHdVvjIx45d8S6UisWpIUsZ7JXGdR761vW1Eg7 42GyHSd/FdxWvYxz8RumzkmbSBJ0aedqwUImAS/hSPCw/e8xUTAyWtQ/dng9hUhGPy6p jeCsjKbfzR00S4ucjH8hFBsA2tqszcuGHz7D2+5mFdcbiSE1NKpnWNzkrqqL1H3R0zjd oe+3qNLDMy0saslk9UKlzhmAwWI0aL8aLnAqidwIdJYjh5xtvgwu2a3JcdZeaJL+/OvY XkLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OXNv1Aoe; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z132-20020a63338a000000b00517a4a75528si6975143pgz.162.2023.06.06.07.49.04; Tue, 06 Jun 2023 07:49:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OXNv1Aoe; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238172AbjFFOie (ORCPT + 99 others); Tue, 6 Jun 2023 10:38:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238155AbjFFOiL (ORCPT ); Tue, 6 Jun 2023 10:38:11 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EC29E42 for ; Tue, 6 Jun 2023 07:37:46 -0700 (PDT) Message-ID: <20230606142031.928021762@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062264; 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=BVz57Fiq4y3HANqcZc1xKtZ2T7kpNoRDOZcZ2I4Dywg=; b=OXNv1AoeCwdVG8cgbF4uXunKSC+maSLNg/mynVZgvO9IFMNYyEspVWkSY9eokdBKGA2yGz 5umVpPLu1o8Bq9v0QJkLGjLcjDDCKdvEmgZ/XMNLUzFrv8jzQIDpRaHwvDZMhqsBnmk2bZ zHTmOjzDpL0RvXHDykanfAW2dB2WxRuLnuwMDtItFPiSEjSA9AmrupfA5qHyeYnRo4BwjL hzDqIwZBcItlKFxAG4iTMSdyG4REMta+QimfGeEU44roRuzuZPotlRCGHwlOZnJ31m1VEP y1L+mopDD8Ye3mrWDMgrd0UyfYYipTqW73ZQVDRVQJQtZocHnSt4Qp0wdrghpA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062264; 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=BVz57Fiq4y3HANqcZc1xKtZ2T7kpNoRDOZcZ2I4Dywg=; b=0S4FTbLs/WLg9eK1op5nChLJ5PMVrhUanQz0OQODSwoxoI2fZjXNqo94T/KbL+0WAIn+TM N8pa5f1PXIjBtGDA== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 16/45] posix-timers: Consolidate timer setup References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:44 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965152610311704?= X-GMAIL-MSGID: =?utf-8?q?1767965152610311704?= hrtimer based and CPU timers have their own way to install the new interval and to reset overrun and signal handling related data. Create a helper function and do the same operation for all variants. Signed-off-by: Thomas Gleixner --- kernel/time/posix-cpu-timers.c | 15 +-------------- kernel/time/posix-timers.c | 23 +++++++++++++++++------ kernel/time/posix-timers.h | 1 + 3 files changed, 19 insertions(+), 20 deletions(-) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -709,21 +709,8 @@ static int posix_cpu_timer_set(struct k_ trigger_base_recalc_expires(timer, p); unlock_task_sighand(p, &flags); - /* - * Install the new reload setting, and - * set up the signal and overrun bookkeeping. - */ - timer->it_interval = timespec64_to_ktime(new->it_interval); - /* - * This acts as a modification timestamp for the timer, - * so any automatic reload attempt will punt on seeing - * that we have reset the timer manually. - */ - timer->it_requeue_pending = (timer->it_requeue_pending + 2) & - ~REQUEUE_PENDING; - timer->it_overrun_last = 0; - timer->it_overrun = -1; + posix_timer_set_common(timer, new); /* * If the new expiry time was already in the past the timer was not --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -853,6 +853,21 @@ static struct k_itimer *timer_wait_runni return lock_timer(timer_id, flags); } +/* + * Set up the new interval and reset the signal delivery data + */ +void posix_timer_set_common(struct k_itimer *timer, struct itimerspec64 *new_setting) +{ + if (new_setting->it_value.tv_sec || new_setting->it_value.tv_nsec) + timer->it_interval = timespec64_to_ktime(new_setting->it_interval); + + /* Prevent reloading in case there is a signal pending */ + timer->it_requeue_pending = (timer->it_requeue_pending + 2) & ~REQUEUE_PENDING; + /* Reset overrun accounting */ + timer->it_overrun_last = 0; + timer->it_overrun = -1LL; +} + /* Set a POSIX.1b interval timer. */ int common_timer_set(struct k_itimer *timr, int flags, struct itimerspec64 *new_setting, @@ -875,16 +890,12 @@ int common_timer_set(struct k_itimer *ti return TIMER_RETRY; timr->it_active = 0; - timr->it_requeue_pending = (timr->it_requeue_pending + 2) & - ~REQUEUE_PENDING; - timr->it_overrun_last = 0; - timr->it_overrun = -1LL; + posix_timer_set_common(timr, new_setting); - /* Switch off the timer when it_value is zero */ + /* Keep timer disarmed when it_value is zero */ if (!new_setting->it_value.tv_sec && !new_setting->it_value.tv_nsec) return 0; - timr->it_interval = timespec64_to_ktime(new_setting->it_interval); expires = timespec64_to_ktime(new_setting->it_value); if (flags & TIMER_ABSTIME) expires = timens_ktime_to_host(timr->it_clock, expires); --- a/kernel/time/posix-timers.h +++ b/kernel/time/posix-timers.h @@ -42,4 +42,5 @@ void common_timer_get(struct k_itimer *t int common_timer_set(struct k_itimer *timr, int flags, struct itimerspec64 *new_setting, struct itimerspec64 *old_setting); +void posix_timer_set_common(struct k_itimer *timer, struct itimerspec64 *new_setting); int common_timer_del(struct k_itimer *timer); From patchwork Tue Jun 6 14:37:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103918 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3468293vqr; Tue, 6 Jun 2023 08:13:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ72vS/Sl0aXH2zs4mnNa17vfFjWFnY2Fd3qx6XCctN5/ADVmC6OKMaPP3OJIaw86Uvk4bQB X-Received: by 2002:a17:90a:fa3:b0:258:fe26:9721 with SMTP id 32-20020a17090a0fa300b00258fe269721mr1170105pjz.17.1686064410036; Tue, 06 Jun 2023 08:13:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686064410; cv=none; d=google.com; s=arc-20160816; b=XHvKcVVi2lzMhbwVjg3EdWAvg/GdOObO3aYj/KztIVVG7aYWeFpMB/Jm+ieyobxvw4 DfZGEnhPa5b2+5lNy0nUcw3DuNww5D8yQXEzDfi5QgDI6KPtKhBR4P2aBDP9dGN7nqaH cbpxvrpMgI6IZ0F+a74AhEUp977B+IL+z3QkiN01SwrzyjmCTnv7HRVmESSRCi4e81V/ 5hfh8IqTG11+XI5p01CCm8tECCpw4kibgQk/NH52uvwTNNoMU+rVtG7lyzwzDamLfL+5 pEL0N8sCmKMxvNDY/BS4rulDSLMTURgN0VWvoMJ9QX7T624jeDELX7D0GWb9cjPaosu/ lDXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=lbMmZ14JuZ/krQR6RrGQ1HvOBRw0gNG6TW4Rb4ueY4Q=; b=Wod9JDY6Fu6m1aNtmkVyyWbsKuXN0mUpR19Z1x7wuCR8ElCNWqE12rWxEumb3M0/M+ CNPIblYybv9Q530u2m0RtkRSWgrluefJ9VoXFvAmXB5233owoFWQtk4KvUuO/t2NUY4T 1BpYGOIuZuxRoQAMbB4WM+cjIcLcXCfSMI0D8FZdnx6fW+YpUDXarW5KW30LTApLzKw6 Y8hAQWu0ezOzNEH7l6yqmim4+j2AP/ipD3oI9qu7pCw6Q9plwHu2WYUPvU2tGiLU/VhE bkeyMNtpOnQNc1mwO7EylzhDawDHWhi8M3kyED2H3++EiN2v6ksVE79WaBpZhE0DYDwQ H/2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fr07iI8e; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id np6-20020a17090b4c4600b00256cf521fd0si5462824pjb.147.2023.06.06.08.13.17; Tue, 06 Jun 2023 08:13:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fr07iI8e; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238176AbjFFOig (ORCPT + 99 others); Tue, 6 Jun 2023 10:38:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238164AbjFFOiM (ORCPT ); Tue, 6 Jun 2023 10:38:12 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC9421993 for ; Tue, 6 Jun 2023 07:37:47 -0700 (PDT) Message-ID: <20230606142031.983662966@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062266; 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=lbMmZ14JuZ/krQR6RrGQ1HvOBRw0gNG6TW4Rb4ueY4Q=; b=fr07iI8eiGqzm9c4spmDHsJoDzM4I3AshKTKn0B4qfJFd1pupaIcWrQv+EkERqd+s1WZXs wiyFUStOfDusf4fsevgOi6yqYiPcD5rIPfMqwufQ+O7nln7PpgKlnpIsyYAcPND2lKlfxA nqTeBws/rzNYwbtQMmrjRpBIwSy9mfkZP3jls4azpkFz+v692Oj9/0ucQAW5A1hsEuN5EF 77uSwrbqgHYNvjBVYwOLZiuiSyeD2bDxvYe2gtARLMvpw5pOtrBLYk66YAeNkHilPxXN4m wMa16b0ivC9t/ywD/tYI0O1OYDxFMyZvUBXy4WPxPwgFAiCo2OzMTsscmUMgsg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062266; 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=lbMmZ14JuZ/krQR6RrGQ1HvOBRw0gNG6TW4Rb4ueY4Q=; b=C/BEPwo7ibfW/Qaq98/UdgpbTp1XbZou+bEA3mK0iDko1X3WaoZgGPVPm/FyOape4HgzCU wfAtQ770fIo9KsDg== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 17/45] posix-cpu-timers: Make k_itimer::it_active consistent References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:45 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767966674565048655?= X-GMAIL-MSGID: =?utf-8?q?1767966674565048655?= Posix CPU timers are not updating k_itimer::it_active which makes it impossible to base decisions in the common posix timer code on it. Update it when queueing or dequeueing posix CPU timers. Signed-off-by: Thomas Gleixner --- kernel/time/posix-cpu-timers.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -453,6 +453,7 @@ static void disarm_timer(struct k_itimer struct cpu_timer *ctmr = &timer->it.cpu; struct posix_cputimer_base *base; + timer->it_active = 0; if (!cpu_timer_dequeue(ctmr)) return; @@ -559,6 +560,7 @@ static void arm_timer(struct k_itimer *t struct cpu_timer *ctmr = &timer->it.cpu; u64 newexp = cpu_timer_getexpires(ctmr); + timer->it_active = 1; if (!cpu_timer_enqueue(&base->tqhead, ctmr)) return; @@ -668,6 +670,7 @@ static int posix_cpu_timer_set(struct k_ ret = TIMER_RETRY; } else { cpu_timer_dequeue(ctmr); + timer->it_active = 0; } /* @@ -787,6 +790,7 @@ static u64 collect_timerqueue(struct tim while ((next = timerqueue_getnext(head))) { struct cpu_timer *ctmr; + struct k_itimer *ktmr; u64 expires; ctmr = container_of(next, struct cpu_timer, node); @@ -799,6 +803,8 @@ static u64 collect_timerqueue(struct tim /* See posix_cpu_timer_wait_running() */ rcu_assign_pointer(ctmr->handling, current); cpu_timer_dequeue(ctmr); + ktmr = container_of(ctmr, struct k_itimer, it.cpu); + ktmr->it_active = 0; list_add_tail(&ctmr->elist, firing); } From patchwork Tue Jun 6 14:37:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103876 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3449028vqr; Tue, 6 Jun 2023 07:47:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5/IUj0brwTiKqxtfIUfdapRPvywERJ0hx/z2KJG66V4OEkP9QHNae4EEM6Uq/4l88F+5HH X-Received: by 2002:a17:903:27c3:b0:1ad:d95d:ca9c with SMTP id km3-20020a17090327c300b001add95dca9cmr2433427plb.15.1686062852318; Tue, 06 Jun 2023 07:47:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686062852; cv=none; d=google.com; s=arc-20160816; b=yDXQvepfRRQLiJckcNB7fZ3vESEYVRq7WtgiFbKrjvdFMUTeny6yhrpahg9jh+059O AliKO1SkZ7dEC+1E6r5J4XEAHRPQ4OwpQIx0FtmmJ5YUgvahqqbMJohr4oAcPs6HPull d/jrfAM3LrS8w/8Ss4MZl5xI3D8trXyM94tAW5l/XG5+/qulNhISOIVDaom6b+kBpedk tRegQke4zLIHeVgLYMbfLcsTFvPsmC0DaUJuIhzU4cvRKZzobojq5s6mg5nZ0uBurz6m gto2RhO1R91NmfPb86ShJ8QVZPk5x9Nhs+Y0DndYXmZAcNnGBn+0QKaPmH0Nf/i4/Qjb 6NoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=psF57WLKdFqu9d22GEwITnNmBUegjhn1nfEG4ZPBrXA=; b=vAolK/7Gl6sew2e8FnthdMrL7R/aR734LbXiP6pKDMCjbBcrVBf4LhRDo3wkdkCuzR QbjGXxT+4zUdJz+AugMXbulzvxyz0/buvFcCencsgC3Iz4p/bynYllclBZNvNqSpgEFc MytYuwenQJAo8UDXVebODf03VB00SerFRR/cLnWphxi058FxCdAS0lkM2anv7W/T23LY ah7Mw1DvNITp+ichy6RUX8FUndITdC0iJSFlym8ewaq9Mti5rRGKLNfBRoVRqnkCsds6 Ap6HdIWH6T1wOYKIVZ8dszhZpJZlKkxFVTXpZrbMs+FQt3TUN6yb77YZ3WnJNYe1dbIB TxSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mSPDSqrv; dkim=neutral (no key) header.i=@linutronix.de header.b=yoLu84z6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c4-20020a170902d48400b001b04a379cd2si7471108plg.348.2023.06.06.07.47.19; Tue, 06 Jun 2023 07:47:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mSPDSqrv; dkim=neutral (no key) header.i=@linutronix.de header.b=yoLu84z6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238243AbjFFOii (ORCPT + 99 others); Tue, 6 Jun 2023 10:38:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237908AbjFFOiN (ORCPT ); Tue, 6 Jun 2023 10:38:13 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 160EA19A3 for ; Tue, 6 Jun 2023 07:37:50 -0700 (PDT) Message-ID: <20230606142032.040938859@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062267; 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=psF57WLKdFqu9d22GEwITnNmBUegjhn1nfEG4ZPBrXA=; b=mSPDSqrv1NDyZxfVdpBVPROOQPPJPJbiZLlJlHdy2N3yQzUi5VtXwvWZ0d2alC7elOSJ4Y fbMuF1NEfVrLI2MYC4WrsVzJNyBgERX+kUQItZu0/8d6GlKbYIde4rA7J60J+3PskfQUFI UxPW6Ba+qLTR3IzvxNe8tjVVE+AYd6fUTT5gGATzpVuB1BTCJVCXszMJWWsLfoK7b4dcMU H4tDOXT2dBL7K1Mn0IpeOGSCvmZpTQnhuB9EDdbNA04jbipBuRDAZZYg4otlrEwamP/GHX d2+7Fd3tr81dkp37P3b0pWv5y6cW3USN6pXGwQIoixH17ZtuV6DkURXv46IQWA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062267; 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=psF57WLKdFqu9d22GEwITnNmBUegjhn1nfEG4ZPBrXA=; b=yoLu84z6rrJTIWXMD3aLk4dbgwAS/EFLZIa05jJ8SYQPQhUanOTFGf6+DF2mdXsdkWozuA SEmVuUjkwhLu4bAA== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 18/45] posix-timers: Consolidate signal queueing References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:47 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965041392270255?= X-GMAIL-MSGID: =?utf-8?q?1767965041392270255?= Rename posix_timer_event() to posix_timer_queue_signal() as this is what the function is about. Consolidate the requeue pending and deactivation updates into that function as there is no point in doing this in all incarnations of posix timers. Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker --- kernel/time/alarmtimer.c | 7 +------ kernel/time/posix-cpu-timers.c | 4 ++-- kernel/time/posix-timers.c | 21 +++++++++++---------- kernel/time/posix-timers.h | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -563,15 +563,10 @@ static enum alarmtimer_restart alarm_han it.alarm.alarmtimer); enum alarmtimer_restart result = ALARMTIMER_NORESTART; unsigned long flags; - int si_private = 0; spin_lock_irqsave(&ptr->it_lock, flags); - ptr->it_active = 0; - if (ptr->it_interval) - si_private = ++ptr->it_requeue_pending; - - if (posix_timer_event(ptr, si_private) && ptr->it_interval) { + if (posix_timer_queue_signal(ptr) && ptr->it_interval) { /* * Handle ignored signals and rearm the timer. This will go * away once we handle ignored signals proper. Ensure that --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -597,9 +597,9 @@ static void cpu_timer_fire(struct k_itim /* * One-shot timer. Clear it as soon as it's fired. */ - posix_timer_event(timer, 0); + posix_timer_queue_signal(timer); cpu_timer_setexpires(ctmr, 0); - } else if (posix_timer_event(timer, ++timer->it_requeue_pending)) { + } else if (posix_timer_queue_signal(timer)) { /* * The signal did not get queued because the signal * was ignored, so we won't get any callback to --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -277,10 +277,17 @@ void posixtimer_rearm(struct kernel_sigi unlock_timer(timr, flags); } -int posix_timer_event(struct k_itimer *timr, int si_private) +int posix_timer_queue_signal(struct k_itimer *timr) { + int ret, si_private = 0; enum pid_type type; - int ret; + + lockdep_assert_held(&timr->it_lock); + + timr->it_active = 0; + if (timr->it_interval) + si_private = ++timr->it_requeue_pending; + /* * FIXME: if ->sigq is queued we can race with * dequeue_signal()->posixtimer_rearm(). @@ -309,19 +316,13 @@ int posix_timer_event(struct k_itimer *t */ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer) { + struct k_itimer *timr = container_of(timer, struct k_itimer, it.real.timer); enum hrtimer_restart ret = HRTIMER_NORESTART; - struct k_itimer *timr; unsigned long flags; - int si_private = 0; - timr = container_of(timer, struct k_itimer, it.real.timer); spin_lock_irqsave(&timr->it_lock, flags); - timr->it_active = 0; - if (timr->it_interval != 0) - si_private = ++timr->it_requeue_pending; - - if (posix_timer_event(timr, si_private)) { + if (posix_timer_queue_signal(timr)) { /* * The signal was not queued due to SIG_IGN. As a * consequence the timer is not going to be rearmed from --- a/kernel/time/posix-timers.h +++ b/kernel/time/posix-timers.h @@ -36,7 +36,7 @@ extern const struct k_clock clock_proces extern const struct k_clock clock_thread; extern const struct k_clock alarm_clock; -int posix_timer_event(struct k_itimer *timr, int si_private); +int posix_timer_queue_signal(struct k_itimer *timr); void common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting); int common_timer_set(struct k_itimer *timr, int flags, From patchwork Tue Jun 6 14:37:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103880 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3449329vqr; Tue, 6 Jun 2023 07:48:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Q3A8HNNvRgS2rLv7GRHXyCFA6wnMciE1Hyw0n3ocqh3QTO8xkbRkRon6zcrVVIZ5lAd7T X-Received: by 2002:a05:6a21:99a7:b0:116:df6e:c857 with SMTP id ve39-20020a056a2199a700b00116df6ec857mr3553660pzb.16.1686062882834; Tue, 06 Jun 2023 07:48:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686062882; cv=none; d=google.com; s=arc-20160816; b=eFuQyoB5gFMzGa5rE1AEdwykdRrnuosKjrYOQAybOBv0iWRc4gki8NpMhwdRVPfwWb WEjUSP9nI+3vbMMj9xFlJY2evNvCXt9bKa6F2xYV4zpvmuuVD9dhdxMUuR3vntlfLyvp kYW1TlRf2od/YHteM5H3O/ABjGVNt8Z5RLBoDs9ymyJTcIEr7tWqaPCApt67XSyO8SRm COUykqzvF/81ieVZOw2y/Y2N8NGjL75GezNgMWEHQuCp8LsUU61dnNN5iX0pWvCJ1Y8W KMAro9ewvm6iNEbCpwdres5ZCyXpRnWZm1Hzg3JKb35TfHDUKXilqNXs9KZ82mXTCs6r ta2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=NkUrDTbG2kUXm4FwAX4frsR2bQohb+OmRpFyHE6t2mA=; b=W+NFP7bqX9U1FfRXR1srTUvUpPdNoqN7eU5S65TUaJI12fihYEkLAzzzInDjwFiNdQ /ZlNxHkLh9P0caQZ/iMU9hLfskGr7FnfLPNJ3WK9K85/9bjRsl/ZkHlib6iDhV6L0E8T U2gIMSvUnVX21j93XrureFFhY1zYeWzxHeM2AccCewnl+OR9WY2qi2S8zHiUqFvlVPq9 8X4zMrtKjLpbuyexTjtZwVp6bd6YyJTYTEA2GZaahZbQj8I6rsQeeJ4S4LBhWuEbOext MA3F0aO1ruCzUr3YIdU0D6yV2Sq/osIe4CwAuDfU7DvDlOmTO+hD1dM9rMiwicXPfPOi wdmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3vJpsNCd; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 73-20020a63004c000000b00542c0357ee7si6419896pga.57.2023.06.06.07.47.50; Tue, 06 Jun 2023 07:48:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3vJpsNCd; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238248AbjFFOim (ORCPT + 99 others); Tue, 6 Jun 2023 10:38:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238096AbjFFOiS (ORCPT ); Tue, 6 Jun 2023 10:38:18 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B284F19AD for ; Tue, 6 Jun 2023 07:37:50 -0700 (PDT) Message-ID: <20230606142032.095893220@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062269; 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=NkUrDTbG2kUXm4FwAX4frsR2bQohb+OmRpFyHE6t2mA=; b=3vJpsNCd5Cty9AxlHVIAAC4r6I8hNXiaYpKzMmQUemVg9DoLwOy5WiGazhw+1WqznMIonr cgmpaFC/pWVkbwMhxfiKohvbxtNUHKzO8h9Ykar5+D3cVgyPtCtkrq2xfVG5WrnGwVnrXg z4aULVl0zsL31Js+l0Rx+1lquD6nsZ7aSazjFG+8bHwI/WXTAs+6P89jKbOiNyvxhkGRYU 2gE4nWX0rTtcvxsbJQryz6Tkmw2zobEwcocwp17CV8kVkhJjZ0HF2gj6FP1kVArZhWIilO N8HJjFNqli/nezp9omLTO59XWsqIRqeMfIIheNVfJFz846u2MYZZ4azVZ0FxEg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062269; 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=NkUrDTbG2kUXm4FwAX4frsR2bQohb+OmRpFyHE6t2mA=; b=FOhRJm+RNuhNW+Fzm6R39QCjgVamcm3e4KM3EJudB2HxdLzadgjA+Nkpt2PHOYjQ6frDo5 U1fiiTT0AP6Pu+Cw== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 19/45] signal: Remove task argument from dequeue_signal() References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:48 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965072961608840?= X-GMAIL-MSGID: =?utf-8?q?1767965072961608840?= The task pointer which is handed to dequeue_signal() is always current. The argument along with the first comment about signalfd in that function is confusing at best. Remove it and use current internally. Update the stale comment for dequeue_signal() while at it. Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker --- fs/signalfd.c | 4 ++-- include/linux/sched/signal.h | 5 ++--- kernel/signal.c | 23 ++++++++++------------- 3 files changed, 14 insertions(+), 18 deletions(-) --- a/fs/signalfd.c +++ b/fs/signalfd.c @@ -160,7 +160,7 @@ static ssize_t signalfd_dequeue(struct s DECLARE_WAITQUEUE(wait, current); spin_lock_irq(¤t->sighand->siglock); - ret = dequeue_signal(current, &ctx->sigmask, info, &type); + ret = dequeue_signal(&ctx->sigmask, info, &type); switch (ret) { case 0: if (!nonblock) @@ -175,7 +175,7 @@ static ssize_t signalfd_dequeue(struct s add_wait_queue(¤t->sighand->signalfd_wqh, &wait); for (;;) { set_current_state(TASK_INTERRUPTIBLE); - ret = dequeue_signal(current, &ctx->sigmask, info, &type); + ret = dequeue_signal(&ctx->sigmask, info, &type); if (ret != 0) break; if (signal_pending(current)) { --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -275,8 +275,7 @@ static inline void signal_set_stop_flags extern void flush_signals(struct task_struct *); extern void ignore_signals(struct task_struct *); extern void flush_signal_handlers(struct task_struct *, int force_default); -extern int dequeue_signal(struct task_struct *task, sigset_t *mask, - kernel_siginfo_t *info, enum pid_type *type); +extern int dequeue_signal(sigset_t *mask, kernel_siginfo_t *info, enum pid_type *type); static inline int kernel_dequeue_signal(void) { @@ -286,7 +285,7 @@ static inline int kernel_dequeue_signal( int ret; spin_lock_irq(&task->sighand->siglock); - ret = dequeue_signal(task, &task->blocked, &__info, &__type); + ret = dequeue_signal(&task->blocked, &__info, &__type); spin_unlock_irq(&task->sighand->siglock); return ret; --- a/kernel/signal.c +++ b/kernel/signal.c @@ -621,20 +621,18 @@ static int __dequeue_signal(struct sigpe } /* - * Dequeue a signal and return the element to the caller, which is - * expected to free it. - * - * All callers have to hold the siglock. + * Try to dequeue a signal. If a deliverable signal is found fill in the + * caller provided siginfo and return the signal number. Otherwise return + * 0. */ -int dequeue_signal(struct task_struct *tsk, sigset_t *mask, - kernel_siginfo_t *info, enum pid_type *type) +int dequeue_signal(sigset_t *mask, kernel_siginfo_t *info, enum pid_type *type) { + struct task_struct *tsk = current; bool resched_timer = false; int signr; - /* We only dequeue private signals from ourselves, we don't let - * signalfd steal them - */ + lockdep_assert_held(&tsk->sighand->siglock); + *type = PIDTYPE_PID; signr = __dequeue_signal(&tsk->pending, mask, info, &resched_timer); if (!signr) { @@ -2751,8 +2749,7 @@ bool get_signal(struct ksignal *ksig) type = PIDTYPE_PID; signr = dequeue_synchronous_signal(&ksig->info); if (!signr) - signr = dequeue_signal(current, ¤t->blocked, - &ksig->info, &type); + signr = dequeue_signal(¤t->blocked, &ksig->info, &type); if (!signr) break; /* will return 0 */ @@ -3606,7 +3603,7 @@ static int do_sigtimedwait(const sigset_ signotset(&mask); spin_lock_irq(&tsk->sighand->siglock); - sig = dequeue_signal(tsk, &mask, info, &type); + sig = dequeue_signal(&mask, info, &type); if (!sig && timeout) { /* * None ready, temporarily unblock those we're interested @@ -3625,7 +3622,7 @@ static int do_sigtimedwait(const sigset_ spin_lock_irq(&tsk->sighand->siglock); __set_task_blocked(tsk, &tsk->real_blocked); sigemptyset(&tsk->real_blocked); - sig = dequeue_signal(tsk, &mask, info, &type); + sig = dequeue_signal(&mask, info, &type); } spin_unlock_irq(&tsk->sighand->siglock); From patchwork Tue Jun 6 14:37:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103904 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3457157vqr; Tue, 6 Jun 2023 08:01:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5vs432Iq4/iFeUeYBnV4eikpXbJu/9XjlFVvHGLFkYZ9JR95MTWFaLmUvBEGL+P7I9VzRr X-Received: by 2002:a05:620a:8b03:b0:75b:23a0:e7d8 with SMTP id qw3-20020a05620a8b0300b0075b23a0e7d8mr2019355qkn.57.1686063671932; Tue, 06 Jun 2023 08:01:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063671; cv=none; d=google.com; s=arc-20160816; b=gH8vB+zuiQ5xQzVjv/ElEdXZmJJN/xUP7gS/u+57dyN3ZLxENlgDkBqTVrWg+NqRyt Af79+jvvtHEoBJTRJHdr5t69JuzU79f4bLHHUlQLrPr3SeGQtscL8vrZd9UJhmF2Jv91 NDW2T2vDs+JQ2JvUD6+/4SSG9hPBdGBntidtdgTa7H9fHnbi3hHtBrDZ4qdiP3Q6ve1Y lyGdO+SQsz1Ndxzyb7n2x0W34X6kpcLqXPWhyQnbS5x36xkivJb+VdWkEk7o4ToHvCHm 3JE9Y3WBE1vyrp6K1B2QuyJD9WFsH8CpU4+kSMGmjMM+yggU6iVvnT3JdnsiyxUVkR7w XHbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=Oszm2ZXBXWLXUTPr0v8LyoBnFHycifs2Z0aI1dsyju0=; b=SD74GNt4YMKrhR97mox8LPEY/0zPPQJ0JDHbGwN7Y9wXvfKvcn3X1scMtTBYvy2lJB bVbpR9LF0eBZpwPKZlYnm4bdS0x6BGc/iPJkCIbqfpbEQ4VwsKUK4JhFapl5OIh0ii1Z P+aPl6p0rBMNODi/WDWyxTDakdim5hstIYkcS+MAbwwVA5ZvS6nNgWTXpHTkbCCnrKJn bEzgKWYwiF4VvYGXY+XkcFxplh5tIj8Xpx98ttS/tPrW1wXONaamb5YhpWbL7S+eW3Cc Mm3WXBOwpFB4a0TEC4WCUx+LGwZLc0JbE8EFIEJqsiG+gygXnFfAvRkaJY7Bm5rEc60m qwBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=D0ntuw5C; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o14-20020a05620a130e00b0075ce3d37b63si5850683qkj.554.2023.06.06.08.00.56; Tue, 06 Jun 2023 08:01:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=D0ntuw5C; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238256AbjFFOjE (ORCPT + 99 others); Tue, 6 Jun 2023 10:39:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238195AbjFFOiT (ORCPT ); Tue, 6 Jun 2023 10:38:19 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61A2919BA for ; Tue, 6 Jun 2023 07:37:52 -0700 (PDT) Message-ID: <20230606142032.151323086@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062270; 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=Oszm2ZXBXWLXUTPr0v8LyoBnFHycifs2Z0aI1dsyju0=; b=D0ntuw5CvYsxl7SSpv78NSEO1OXove23skoVb9/culdydz2S3W/9AodOxMk18vwf/Sda8X PLJ+JN27N/9vZ/ZbfB4sfPzgijMO/Czl53luFkcn4sIF4hJJcmNPGHjzTsXxzCTuQXM/8N dVHffqboWgZ/JDXz5LZmHKgSfX30JvUl6sWrLznm6Gq8WUW9vvZvUIF7Ubzq7vYct7mHgY +oow8XxaFw958QPoqnCvgEGlpcHVj22vj1yHcS7Yg4+2vkOHWiq3s4w8X+RGdZSVeFy45v 5lYPgme3D0nI8L6FjetOVpodb/vsthI08TeP63e4ezMc159nfQ853OizEUzDEw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062270; 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=Oszm2ZXBXWLXUTPr0v8LyoBnFHycifs2Z0aI1dsyju0=; b=5htpoKmcrRXlS0Nl4wNjcwhNX8aRSMwzaKf44yg10U6SoWgH0XxX8TaMn1da7IsgGlX4ih 8rmcZVlqOixyvoDQ== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 20/45] signal: Replace BUG_ON()s References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:50 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965901135180744?= X-GMAIL-MSGID: =?utf-8?q?1767965901135180744?= These really can be handled gracefully without killing the machine. Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker --- kernel/signal.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1932,10 +1932,11 @@ struct sigqueue *sigqueue_alloc(void) void sigqueue_free(struct sigqueue *q) { - unsigned long flags; spinlock_t *lock = ¤t->sighand->siglock; + unsigned long flags; - BUG_ON(!(q->flags & SIGQUEUE_PREALLOC)); + if (WARN_ON_ONCE(!(q->flags & SIGQUEUE_PREALLOC))) + return; /* * We must hold ->siglock while testing q->list * to serialize with collect_signal() or with @@ -1963,7 +1964,10 @@ int send_sigqueue(struct sigqueue *q, st unsigned long flags; int ret, result; - BUG_ON(!(q->flags & SIGQUEUE_PREALLOC)); + if (WARN_ON_ONCE(!(q->flags & SIGQUEUE_PREALLOC))) + return 0; + if (WARN_ON_ONCE(q->info.si_code != SI_TIMER)) + return 0; ret = -1; rcu_read_lock(); @@ -1998,7 +2002,6 @@ int send_sigqueue(struct sigqueue *q, st * If an SI_TIMER entry is already queue just increment * the overrun count. */ - BUG_ON(q->info.si_code != SI_TIMER); q->info.si_overrun++; result = TRACE_SIGNAL_ALREADY_PENDING; goto out; From patchwork Tue Jun 6 14:37:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103907 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3461874vqr; Tue, 6 Jun 2023 08:05:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4A+sZfRDU7T9l4jsG20f8ls9UnL9HbY1L1Z43j9gdhnlkv00a7+rO7fMnu4nWS2iAwTTKb X-Received: by 2002:a05:6214:27e2:b0:626:fb4:cced with SMTP id jt2-20020a05621427e200b006260fb4ccedmr2564533qvb.20.1686063947119; Tue, 06 Jun 2023 08:05:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063947; cv=none; d=google.com; s=arc-20160816; b=PXyhG8BEYWGWJm4QLgVWb9XHAtYCy5dT7/AMOzoAf5S6GBP84j3D9F6MWongjpLWCT 2rjB0E4eBaInRy+bS+gFnIcrcKwfyvq+U4HAs/03TEBNVnivaJEOpiS9bNaHku1mINe6 ktjOpdFgVKDxRSCcpL7JdIH0ZO4rCLH6zsr+CzZBAtfpsWd2pjW94MtzrYiZutZvznQh Beqj036m1AMO3r0CGYwQBGQOc9j4R0nffPwXrQ9W/50zKup9pz+yfDxKHoum2aLwn0gm vXXMbKPKHjrkJKh0xS80GQrx1dW9LcgHZnFYFOk8AxbApeOLoGqmtdM2FtLKfBp1dM65 4ZMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=y+RhxJJzE8uzstkBWfAPFhTwZDjjv6jfhmmgOqvJSb0=; b=mi8vtP3OeO7SDH1LSLygS+gMWei/JCvAh8dE6PfFNKsjRKd1h2/CkSmZWa8unAfT+d e/K4ClXQtETkeyLyXBO3gTQ+ouaQJ4R0BO6C9HaHONiVoj9uGNJWezGlPf9kkzksk68I ZXYPFwYZZd+qe44WBPQ0HPusEwdNTSJmxItHKLgloqTuNDSh3yVrhLViovGMQyILQ+os VCKiJP2n2zgttRQ/5BQv0SIk5AOQl+RExa2NX22gG055uwKOnnBRg2CqyN5NZ25FQByi JkTgnwsO6vU3M5U33ypI5HgubqeCH0sW5UL/OiXbqGdr/IpsuoCg4JQTqUvK/s6eQ1/F DmBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=gwgYgVQA; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x20-20020ae9e914000000b0075b05e65a32si4030539qkf.528.2023.06.06.08.05.32; Tue, 06 Jun 2023 08:05:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=gwgYgVQA; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238059AbjFFOjI (ORCPT + 99 others); Tue, 6 Jun 2023 10:39:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238012AbjFFOiU (ORCPT ); Tue, 6 Jun 2023 10:38:20 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D64A110F0 for ; Tue, 6 Jun 2023 07:37:53 -0700 (PDT) Message-ID: <20230606142032.209201867@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062272; 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=y+RhxJJzE8uzstkBWfAPFhTwZDjjv6jfhmmgOqvJSb0=; b=gwgYgVQAUT+3KKpdi3wnvtWIKTUWUU1RrFh4glOGKxb8ztFzovqeMm1EggBrlL8G8jRujj 9sWrK/aqDnCG2lntLhiY9APg0B8wQBz0O6Id7xuWxfQGFCWHFvpUtMlNP1mF1qNlhpFp8s EWGimSiG+2yY5aeJbSqv5ewDg3tDYOxfCKTNH+Z1pGC4juRBP5mFPGdBWqsSgilptkrNwW H7bsyawQ20vNZRJNJy0x3MoAIArY6AbBVsv8M/P4/YjCXLOt/C0PW9PwHVca16uYqq9iW3 8A9sHCbP4Uhv85Gp68cCl25nO1tduw2Kq47p5cekTq//wf24iFKkeDeSDixRWA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062272; 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=y+RhxJJzE8uzstkBWfAPFhTwZDjjv6jfhmmgOqvJSb0=; b=ljl4qT+fsd3lzxkk2vZtMdZ2om0ov9TE6cQQfxnx07U26+XlAHdYyV98BPjTx6oEslQGJS VdQh1J6J657GerBw== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 21/45] signal: Confine POSIX_TIMERS properly References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:52 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767966189310460847?= X-GMAIL-MSGID: =?utf-8?q?1767966189310460847?= Move the itimer rearming out of the signal code and consolidate all posix timer related functions in the signal code under one ifdef. Signed-off-by: Thomas Gleixner --- include/linux/posix-timers.h | 5 + kernel/signal.c | 125 +++++++++++++++---------------------------- kernel/time/itimer.c | 22 +++++++ kernel/time/posix-timers.c | 15 ++++- 4 files changed, 82 insertions(+), 85 deletions(-) --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -162,6 +162,8 @@ static inline void posix_cputimers_rt_wa { pct->bases[CPUCLOCK_SCHED].nextevt = runtime; } +void posixtimer_rearm_itimer(struct task_struct *p); +void posixtimer_rearm(struct kernel_siginfo *info); /* Init task static initializer */ #define INIT_CPU_TIMERBASE(b) { \ @@ -185,6 +187,8 @@ struct cpu_timer { }; static inline void posix_cputimers_init(struct posix_cputimers *pct) { } static inline void posix_cputimers_group_init(struct posix_cputimers *pct, u64 cpu_limit) { } +static inline void posixtimer_rearm_itimer(struct task_struct *p) { } +static inline void posixtimer_rearm(struct kernel_siginfo *info) { } #endif #ifdef CONFIG_POSIX_CPU_TIMERS_TASK_WORK @@ -259,5 +263,4 @@ void set_process_cpu_timer(struct task_s int update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new); -void posixtimer_rearm(struct kernel_siginfo *info); #endif --- a/kernel/signal.c +++ b/kernel/signal.c @@ -485,42 +485,6 @@ void flush_signals(struct task_struct *t } EXPORT_SYMBOL(flush_signals); -#ifdef CONFIG_POSIX_TIMERS -static void __flush_itimer_signals(struct sigpending *pending) -{ - sigset_t signal, retain; - struct sigqueue *q, *n; - - signal = pending->signal; - sigemptyset(&retain); - - list_for_each_entry_safe(q, n, &pending->list, list) { - int sig = q->info.si_signo; - - if (likely(q->info.si_code != SI_TIMER)) { - sigaddset(&retain, sig); - } else { - sigdelset(&signal, sig); - list_del_init(&q->list); - __sigqueue_free(q); - } - } - - sigorsets(&pending->signal, &signal, &retain); -} - -void flush_itimer_signals(void) -{ - struct task_struct *tsk = current; - unsigned long flags; - - spin_lock_irqsave(&tsk->sighand->siglock, flags); - __flush_itimer_signals(&tsk->pending); - __flush_itimer_signals(&tsk->signal->shared_pending); - spin_unlock_irqrestore(&tsk->sighand->siglock, flags); -} -#endif - void ignore_signals(struct task_struct *t) { int i; @@ -639,31 +603,9 @@ int dequeue_signal(sigset_t *mask, kerne *type = PIDTYPE_TGID; signr = __dequeue_signal(&tsk->signal->shared_pending, mask, info, &resched_timer); -#ifdef CONFIG_POSIX_TIMERS - /* - * itimer signal ? - * - * itimers are process shared and we restart periodic - * itimers in the signal delivery path to prevent DoS - * attacks in the high resolution timer case. This is - * compliant with the old way of self-restarting - * itimers, as the SIGALRM is a legacy signal and only - * queued once. Changing the restart behaviour to - * restart the timer in the signal dequeue path is - * reducing the timer noise on heavy loaded !highres - * systems too. - */ - if (unlikely(signr == SIGALRM)) { - struct hrtimer *tmr = &tsk->signal->real_timer; - if (!hrtimer_is_queued(tmr) && - tsk->signal->it_real_incr != 0) { - hrtimer_forward(tmr, tmr->base->get_time(), - tsk->signal->it_real_incr); - hrtimer_restart(tmr); - } - } -#endif + if (unlikely(signr == SIGALRM)) + posixtimer_rearm_itimer(tsk); } recalc_sigpending(); @@ -685,22 +627,12 @@ int dequeue_signal(sigset_t *mask, kerne */ current->jobctl |= JOBCTL_STOP_DEQUEUED; } -#ifdef CONFIG_POSIX_TIMERS - if (resched_timer) { - /* - * Release the siglock to ensure proper locking order - * of timer locks outside of siglocks. Note, we leave - * irqs disabled here, since the posix-timers code is - * about to disable them again anyway. - */ - spin_unlock(&tsk->sighand->siglock); - posixtimer_rearm(info); - spin_lock(&tsk->sighand->siglock); - /* Don't expose the si_sys_private value to userspace */ - info->si_sys_private = 0; + if (IS_ENABLED(CONFIG_POSIX_TIMERS)) { + if (unlikely(resched_timer)) + posixtimer_rearm(info); } -#endif + return signr; } EXPORT_SYMBOL_GPL(dequeue_signal); @@ -1916,15 +1848,45 @@ int kill_pid(struct pid *pid, int sig, i } EXPORT_SYMBOL(kill_pid); +#ifdef CONFIG_POSIX_TIMERS /* - * These functions support sending signals using preallocated sigqueue - * structures. This is needed "because realtime applications cannot - * afford to lose notifications of asynchronous events, like timer - * expirations or I/O completions". In the case of POSIX Timers - * we allocate the sigqueue structure from the timer_create. If this - * allocation fails we are able to report the failure to the application - * with an EAGAIN error. + * These functions handle POSIX timer signals. POSIX timers use + * preallocated sigqueue structs for sending signals. */ +static void __flush_itimer_signals(struct sigpending *pending) +{ + sigset_t signal, retain; + struct sigqueue *q, *n; + + signal = pending->signal; + sigemptyset(&retain); + + list_for_each_entry_safe(q, n, &pending->list, list) { + int sig = q->info.si_signo; + + if (likely(q->info.si_code != SI_TIMER)) { + sigaddset(&retain, sig); + } else { + sigdelset(&signal, sig); + list_del_init(&q->list); + __sigqueue_free(q); + } + } + + sigorsets(&pending->signal, &signal, &retain); +} + +void flush_itimer_signals(void) +{ + struct task_struct *tsk = current; + unsigned long flags; + + spin_lock_irqsave(&tsk->sighand->siglock, flags); + __flush_itimer_signals(&tsk->pending); + __flush_itimer_signals(&tsk->signal->shared_pending); + spin_unlock_irqrestore(&tsk->sighand->siglock, flags); +} + struct sigqueue *sigqueue_alloc(void) { return __sigqueue_alloc(-1, current, GFP_KERNEL, 0, SIGQUEUE_PREALLOC); @@ -2021,6 +1983,7 @@ int send_sigqueue(struct sigqueue *q, st rcu_read_unlock(); return ret; } +#endif /* CONFIG_POSIX_TIMERS */ static void do_notify_pidfd(struct task_struct *task) { --- a/kernel/time/itimer.c +++ b/kernel/time/itimer.c @@ -151,7 +151,27 @@ COMPAT_SYSCALL_DEFINE2(getitimer, int, w #endif /* - * The timer is automagically restarted, when interval != 0 + * Invoked from dequeue_signal() when SIG_ALRM is delivered. + * + * Restart the ITIMER_REAL timer if it is armed as periodic timer. Doing + * this in the signal delivery path instead of self rearming prevents a DoS + * with small increments in the high reolution timer case and reduces timer + * noise in general. + */ +void posixtimer_rearm_itimer(struct task_struct *tsk) +{ + struct hrtimer *tmr = &tsk->signal->real_timer; + + if (!hrtimer_is_queued(tmr) && tsk->signal->it_real_incr != 0) { + hrtimer_forward(tmr, tmr->base->get_time(), + tsk->signal->it_real_incr); + hrtimer_restart(tmr); + } +} + +/* + * Interval timers are restarted in the signal delivery path. See + * posixtimer_rearm_itimer(). */ enum hrtimer_restart it_real_fn(struct hrtimer *timer) { --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -251,7 +251,7 @@ static void common_hrtimer_rearm(struct /* * This function is called from the signal delivery code if - * info->si_sys_private is not zero, which indicates that the timer has to + * info::si_sys_private is not zero, which indicates that the timer has to * be rearmed. Restart the timer and update info::si_overrun. */ void posixtimer_rearm(struct kernel_siginfo *info) @@ -259,9 +259,15 @@ void posixtimer_rearm(struct kernel_sigi struct k_itimer *timr; unsigned long flags; + /* + * Release siglock to ensure proper locking order versus + * timr::it_lock. Keep interrupts disabled. + */ + spin_unlock(¤t->sighand->siglock); + timr = lock_timer(info->si_tid, &flags); if (!timr) - return; + goto out; if (timr->it_interval && timr->it_requeue_pending == info->si_sys_private) { timr->kclock->timer_rearm(timr); @@ -275,6 +281,11 @@ void posixtimer_rearm(struct kernel_sigi } unlock_timer(timr, flags); +out: + spin_lock(¤t->sighand->siglock); + + /* Don't expose the si_sys_private value to userspace */ + info->si_sys_private = 0; } int posix_timer_queue_signal(struct k_itimer *timr) From patchwork Tue Jun 6 14:37:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103886 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3451451vqr; Tue, 6 Jun 2023 07:51:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7M45JC8unt+C+O88R3ofbvFOKb4ylyoZSUT5+pAppTHgB3ZyhTzqyDQQLpBKxabKA9pxh4 X-Received: by 2002:a05:6214:20ec:b0:624:c497:526a with SMTP id 12-20020a05621420ec00b00624c497526amr2392725qvk.24.1686063108211; Tue, 06 Jun 2023 07:51:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063108; cv=none; d=google.com; s=arc-20160816; b=fsJBD2u4RZfFNMtR+bQVvQSSo6UoS/iFXxrIpgr8e9x1YREa9ZDvZmUI2YvNJFGda4 SduxM/xSRRIQybJiD1v3l7A4LMRngWAKe8iy9eo9ZJTxrj6KB5CQBkoUNDj14RrWqooq pU5HlrPEAtqwUhYxRuA/tyizpK0MuYjkm+PDmv2mmo2S6HRfkuYGOBABbvvhpLJ5lJ36 D9mvym1NAxiMZnYbkETi8Q5EClwfYqeIt+2F6DQCU5bC+Ge/h9VR58Bx78B7bgL0DI0X k+b+MEwe/wyLpN+pMZzqmnNgxHl7CA3M1oiATRa6FSU7m5PDVpXyln5ICoItuY2W+Nra khug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=pTwgQriJEXYz/BGSH2oQaAJz9q8TYA27uj1w2y/zcJc=; b=zQfbMSjUQW9ytrNCsizDs+Nlnn2rL0WVzGN6wT+vyHSvL2lkG2ETA2j/hGJOd0FDxu gvun0s1bKivXFOtkc2+BSD/3lkcH161cEOfklIzo4Jk1R1HmuYdKvOVQuZ/7VePHpAJC N05dSMMmYmViCvAkh1FlQYBDiEKJIG/mapl85s6BKd/2RKv4t5h1Z/JjrcT1zfNvg39d E6clZKgq8hmVa5CmqWf9Gc7S0MQJUgg46td0Vw/O8GzGT9p7lf9FlLEGd5XWGaJfwi+F WnKWju3gumbhaPSMFC898HwIDDbt+o9jAmLsHS8AZVbP4E62VsSndgUmKQ5obcObmaqo vgdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0IRnAHwI; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jo10-20020a056214500a00b0062827f7f1bbsi5006608qvb.245.2023.06.06.07.51.34; Tue, 06 Jun 2023 07:51:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0IRnAHwI; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238223AbjFFOjM (ORCPT + 99 others); Tue, 6 Jun 2023 10:39:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238130AbjFFOi3 (ORCPT ); Tue, 6 Jun 2023 10:38:29 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C07791BCC for ; Tue, 6 Jun 2023 07:37:55 -0700 (PDT) Message-ID: <20230606142032.265274690@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062274; 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=pTwgQriJEXYz/BGSH2oQaAJz9q8TYA27uj1w2y/zcJc=; b=0IRnAHwIhJIqglZvpXDrkZu/M/QwBgEWV0yLKYPAXoPN4kfedaIOLiuO2Z5c5hn3FtPUuu QGE7N7o7rl5iQg6iHrhjKFaYtTqIYjNsJ6DOC5S4bM6SAHBATUCGLkAfbT6FK3BzBe5nFL Toi2QxVGSgU74Ak5v8wR34tC742JhdqyFhqjxrji1CFbDYfrtvN7/O7kEy7xIlJgu+BgAm mXFgL6K7p6gPkpg9uQ87lk9akugxVrSUwIAa8xb2ye54ygC3fodE8dLn+4A76CIHznpTrr sEcWOjihR7swEfGfh9xix9cOzwsBw/E7KojqlxpE3vxK3kVlvU5nDusbj6TCTw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062274; 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=pTwgQriJEXYz/BGSH2oQaAJz9q8TYA27uj1w2y/zcJc=; b=JRFbBcCjP4x4iocN+ozTdkGi1p1nb01JhhQ6f5PJp6rE0q/eY9U36wAeEw+i+XMHN5fnK4 KpBY5EooAmYsNODQ== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 22/45] signal: Get rid of resched_timer logic References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:53 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965309860358250?= X-GMAIL-MSGID: =?utf-8?q?1767965309860358250?= There is no reason for handing the *resched pointer argument through several functions just to check whether the signal is related to a self rearming posix timer. SI_TIMER is only used by the posix timer code and cannot be queued from user space. The only extra check in collect_signal() to verify whether the queued signal is preallocated is not really useful. Some other places already check purely the SI_TIMER type. Signed-off-by: Thomas Gleixner --- kernel/signal.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -529,8 +529,7 @@ bool unhandled_signal(struct task_struct return !tsk->ptrace; } -static void collect_signal(int sig, struct sigpending *list, kernel_siginfo_t *info, - bool *resched_timer) +static void collect_signal(int sig, struct sigpending *list, kernel_siginfo_t *info) { struct sigqueue *q, *first = NULL; @@ -552,12 +551,6 @@ static void collect_signal(int sig, stru still_pending: list_del_init(&first->list); copy_siginfo(info, &first->info); - - *resched_timer = - (first->flags & SIGQUEUE_PREALLOC) && - (info->si_code == SI_TIMER) && - (info->si_sys_private); - __sigqueue_free(first); } else { /* @@ -574,13 +567,12 @@ static void collect_signal(int sig, stru } } -static int __dequeue_signal(struct sigpending *pending, sigset_t *mask, - kernel_siginfo_t *info, bool *resched_timer) +static int __dequeue_signal(struct sigpending *pending, sigset_t *mask, kernel_siginfo_t *info) { int sig = next_signal(pending, mask); if (sig) - collect_signal(sig, pending, info, resched_timer); + collect_signal(sig, pending, info); return sig; } @@ -592,17 +584,15 @@ static int __dequeue_signal(struct sigpe int dequeue_signal(sigset_t *mask, kernel_siginfo_t *info, enum pid_type *type) { struct task_struct *tsk = current; - bool resched_timer = false; int signr; lockdep_assert_held(&tsk->sighand->siglock); *type = PIDTYPE_PID; - signr = __dequeue_signal(&tsk->pending, mask, info, &resched_timer); + signr = __dequeue_signal(&tsk->pending, mask, info); if (!signr) { *type = PIDTYPE_TGID; - signr = __dequeue_signal(&tsk->signal->shared_pending, - mask, info, &resched_timer); + signr = __dequeue_signal(&tsk->signal->shared_pending, mask, info); if (unlikely(signr == SIGALRM)) posixtimer_rearm_itimer(tsk); @@ -629,7 +619,7 @@ int dequeue_signal(sigset_t *mask, kerne } if (IS_ENABLED(CONFIG_POSIX_TIMERS)) { - if (unlikely(resched_timer)) + if (unlikely(info->si_code == SI_TIMER && info->si_sys_private)) posixtimer_rearm(info); } @@ -1015,6 +1005,9 @@ static int __send_signal_locked(int sig, lockdep_assert_held(&t->sighand->siglock); + if (WARN_ON_ONCE(!is_si_special(info) && info->si_code == SI_TIMER)) + return 0; + result = TRACE_SIGNAL_IGNORED; if (!prepare_signal(sig, t, force)) goto ret; From patchwork Tue Jun 6 14:37:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103899 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3454932vqr; Tue, 6 Jun 2023 07:58:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4wx3P4TK5ZZJXgb8Ji8Tf6DuBb3I3C/HMtjCXjmFSMZwlD9BKrjXtQ2Hrr21UxyL+GVJjT X-Received: by 2002:ac8:5f53:0:b0:3f9:b187:9c63 with SMTP id y19-20020ac85f53000000b003f9b1879c63mr2430639qta.12.1686063480247; Tue, 06 Jun 2023 07:58:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063480; cv=none; d=google.com; s=arc-20160816; b=z+kfuTRQ14a4BLR71FJUaylCe30TBoz8kUGXSrbas6cBH2DIVQwo6RCs8ijvXJtLfE 227kwWMNdG/lP4sIHTxmWplrXnFtI+8j1OMet/eX4522nv0E3RNdBDffseAXSDAo0fP+ g/QBicwG/re/nfnEqfQ7qn3U+OE1rD/sUtQC1ip3hkxrlnRWeMKWXr30SySF8hittPCN dPHRVrNhFDlMfyxN1dzrU0UjwXwwFggM8pVpKNJ7jQLr8nKxHccSlvoaHe9C8yJfqUEH UjM2tGSG9mnjPP9fcV7mNcIlZXG5kqcQIZ40bmrHLcTa481/+qdtimVbOea4676leZMO 4+bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=H0SHtIHKvGNjccihe5bl5KJFGvU0rvv1sAUDjIUVmZA=; b=Kb0IxmDKR9ff6C4pr0pieFge1xuKs4hXo8CNIYsIJE13ZG9zyqr54ttDTRMiOJOZN/ r2B3lHDZis8kuGxBGd4KE2I6SM5WDRWpnQVqn6I4wSagz79IPpYQyTQX3c6WB+vvYy2c /uP12WK85MdG67umX2dGbekBV4TLZ6xjb+0SNfPAi7ngkkdpxEjRsoSIUjBHy3f0jwCs aeJKq3kmp8zql2K6xaeVlmgkXFTjIt+yN259jV8ZogJcXd1VeAfmLhuA9wWdRxZ8/Sa9 t4uRSCWIVTYnALM2xK6qVYe1fH+f3GHbJme9JApG6kErJoCicg7E2uVWT0t/mv0zPNV3 ncGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xu+LjC6F; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u6-20020a05622a14c600b003f1a0ec00b1si6347048qtx.220.2023.06.06.07.57.45; Tue, 06 Jun 2023 07:58:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xu+LjC6F; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238080AbjFFOjW (ORCPT + 99 others); Tue, 6 Jun 2023 10:39:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238167AbjFFOic (ORCPT ); Tue, 6 Jun 2023 10:38:32 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 691C61BDC for ; Tue, 6 Jun 2023 07:37:57 -0700 (PDT) Message-ID: <20230606142032.320851262@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062275; 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=H0SHtIHKvGNjccihe5bl5KJFGvU0rvv1sAUDjIUVmZA=; b=xu+LjC6FcJ1D7kEM2up0mLuCoSwJNM/DGQub2BCOd4pms81P6znJhC3mipA9MCHfWSSfQ6 nLLV7s3Qnj6R4CZ3oicRu3KRRzvgAD6Qek4KAp/h9o7GT29H4vlAsUN30CDYNKJjazs146 PSOpfDH9bxwGV/aA+3z8XnuWk9jjeV7bUCvEbjhOvQ3wv/0PCPub4A94lNdvXYMJoD3jD2 qg1OGNKqWrNbCjdZLii6CwZAy0bsShKFN1GAqqZqxhMFZokduyrpGnWFOsHD/voFJ45rxI OL2NZ9Afkyn+6Wpaotd6bYKIUfmrEQoiG0Npd5J0uutFjBvWEUNuXLUyKia6uQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062275; 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=H0SHtIHKvGNjccihe5bl5KJFGvU0rvv1sAUDjIUVmZA=; b=29FxhteEWsRBzyVrLTeHNbrXTrB5L2OGD6EO2aYPwHO8ZDj9MiYQjhFnv9Nf9lkU5MCT3A emcm6vEe2z8gzICg== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 23/45] posix-timers: Cure si_sys_private race References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:55 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965699748101285?= X-GMAIL-MSGID: =?utf-8?q?1767965699748101285?= The si_sys_private member of the siginfo which is embedded in the preallocated sigqueue is used by the posix timer code to decide whether a timer must be reprogrammed on signal delivery. The handling of this is racy as a long standing comment in that code documents. It is modified with the timer lock held, but without sighand lock being held. The actual signal delivery code checks for it under sighand lock without holding the timer lock. Hand the new value to send_sigqueue() as argument and store it with sighand lock held. Signed-off-by: Thomas Gleixner --- include/linux/sched/signal.h | 2 +- kernel/signal.c | 10 +++++++++- kernel/time/posix-timers.c | 15 +-------------- 3 files changed, 11 insertions(+), 16 deletions(-) --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -348,7 +348,7 @@ extern int send_sig(int, struct task_str extern int zap_other_threads(struct task_struct *p); extern struct sigqueue *sigqueue_alloc(void); extern void sigqueue_free(struct sigqueue *); -extern int send_sigqueue(struct sigqueue *, struct pid *, enum pid_type); +extern int send_sigqueue(struct sigqueue *, struct pid *, enum pid_type, int si_private); extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *); static inline void clear_notify_signal(void) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1911,7 +1911,7 @@ void sigqueue_free(struct sigqueue *q) __sigqueue_free(q); } -int send_sigqueue(struct sigqueue *q, struct pid *pid, enum pid_type type) +int send_sigqueue(struct sigqueue *q, struct pid *pid, enum pid_type type, int si_private) { int sig = q->info.si_signo; struct sigpending *pending; @@ -1946,6 +1946,14 @@ int send_sigqueue(struct sigqueue *q, st if (!likely(lock_task_sighand(t, &flags))) goto ret; + /* + * Update @q::info::si_sys_private for posix timer signals with + * sighand locked to prevent a race against dequeue_signal() which + * decides based on si_sys_private whether to invoke + * posixtimer_rearm() or not. + */ + q->info.si_sys_private = si_private; + ret = 1; /* the signal is ignored */ result = TRACE_SIGNAL_IGNORED; if (!prepare_signal(sig, t, false)) --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -299,21 +299,8 @@ int posix_timer_queue_signal(struct k_it if (timr->it_interval) si_private = ++timr->it_requeue_pending; - /* - * FIXME: if ->sigq is queued we can race with - * dequeue_signal()->posixtimer_rearm(). - * - * If dequeue_signal() sees the "right" value of - * si_sys_private it calls posixtimer_rearm(). - * We re-queue ->sigq and drop ->it_lock(). - * posixtimer_rearm() locks the timer - * and re-schedules it while ->sigq is pending. - * Not really bad, but not that we want. - */ - timr->sigq->info.si_sys_private = si_private; - type = !(timr->it_sigev_notify & SIGEV_THREAD_ID) ? PIDTYPE_TGID : PIDTYPE_PID; - ret = send_sigqueue(timr->sigq, timr->it_pid, type); + ret = send_sigqueue(timr->sigq, timr->it_pid, type, si_private); /* If we failed to send the signal the timer stops. */ return ret > 0; } From patchwork Tue Jun 6 14:37:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103894 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3453939vqr; Tue, 6 Jun 2023 07:56:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6r3p3FnwtcYM2F2uEIP+L+RDxOXEubdSn/jfdP38/kTF8y6O6akrKZLdBlVEIKF2Ywovzw X-Received: by 2002:a05:6214:c68:b0:626:ca8:e4f7 with SMTP id t8-20020a0562140c6800b006260ca8e4f7mr2334469qvj.56.1686063372410; Tue, 06 Jun 2023 07:56:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063372; cv=none; d=google.com; s=arc-20160816; b=yJ+TEaEDh6B5hM+znc0b4qcSa3AuPpkrsU4SXxx4MxkxiXHFhqdhjdX+wO9G6YZ6+E NCkFTVLNSBVlECxNu679WRYtiFr/2yEHy8lVYYqVzL06Ial3YVmXEjJP3bQqyEsndIsh cuJN27fX9mtSz1McnjF71jDzsvXXS9K+elcKKe//h1OPc0NGEFpTzw80nClDshVMDWjM cjwbENnmOtVtdj4/wYbUV1skr3DTcaZajFKOLfSEt/d7SVwZ5zR6OGgoBpjDjysLBcQG cMCQWhWh4WSVmMsufXvrORX3yUbni8Bzl2Qy/D1JSL/h6XRytjOLmmi2x47wvyWOWac0 zNIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=FsQ2RLjA0ULPK1LuVh79qQG566mUAal9FpthIwhTUsc=; b=xJsOTdf1ruVfbkD+gQRxH0CT+UU1Gl2tsGtQCJnAshXQUBMIFamdi5AkGN+vn/2bhu GjiHnCgGs2tRS86/pyTEjCIXgX83MhLeH1LqzMTQXoPCDeN2y1FvbdSys6dW1lc1+Gp7 Qiu5Xwh5h/Wtqf+imHIB8E6Yr5VE43a42ZpoddoaCbybiMc/tPwKVq+AixBUYgICaVqo cvEdE2rcEzeMrNZvREbWb3KlYEYtFOz8EVEKojKcfBTMHACeQ3kqgx2O4ZrBxpPivyeb FPkqEdlCMeY4YE4oe5Us7aOi5n0EnixoRF7BfDetIWjfrgGesIunyy/Hrg7/a8/plqmt vdSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Tmh6xJJN; dkim=neutral (no key) header.i=@linutronix.de header.b=PL0Wz+ZP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c4-20020ad45ae4000000b006187c933c7asi6768307qvh.54.2023.06.06.07.55.56; Tue, 06 Jun 2023 07:56:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Tmh6xJJN; dkim=neutral (no key) header.i=@linutronix.de header.b=PL0Wz+ZP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238198AbjFFOj0 (ORCPT + 99 others); Tue, 6 Jun 2023 10:39:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238232AbjFFOie (ORCPT ); Tue, 6 Jun 2023 10:38:34 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AFBF10F2 for ; Tue, 6 Jun 2023 07:37:59 -0700 (PDT) Message-ID: <20230606142032.377649534@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062277; 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=FsQ2RLjA0ULPK1LuVh79qQG566mUAal9FpthIwhTUsc=; b=Tmh6xJJN3AmL9nJl7HXapdxc/ZScy95W8+cLDx1L6xE+OP1B2vQPjMLL+5svUX3zoTFAdT gncpwf7lXSp9Ji272ARmG3jMJ2POAqx47PEe+O6pbC62uP1i8RHhb3YpokscJqRUswAWCc VYBDoVqX94siQQ1l/gGSWYOAfMfaSvlt28l9sS0Tp+127j8OnAPpi7pzMsLuA3dgcz4KU8 EPKlkqh/1D1C8Qw5P8QSTShe/ri42DmDm2gA0TUY1FtM02qrEI5yHNZfL3e623giI1omF6 fpnxrcQ1X3iKH2jsmleBx0ROWU8cnw0c++oOho0RNttnba5Ou8bKsRcoYT61SQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062277; 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=FsQ2RLjA0ULPK1LuVh79qQG566mUAal9FpthIwhTUsc=; b=PL0Wz+ZPwNKudLjbFeGDBMcUIJtGwB9cEhmWlmGb5tmx9eStFY3LSEeHX2P7CH6jsbif4L fG2953MQDdo3QkDg== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 24/45] signal: Allow POSIX timer signals to be dropped References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:56 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965586807004058?= X-GMAIL-MSGID: =?utf-8?q?1767965586807004058?= In case that a timer was reprogrammed or deleted an already pending signal is obsolete. Right now such signals are kept around and eventually delivered. While POSIX is blury about this: - "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." it is reasonable in both cases to expect that pending signals are discarded as they have no meaning anymore. Prepare the signal code to allow dropping posix timer signals. Signed-off-by: Thomas Gleixner --- include/linux/posix-timers.h | 5 +++-- kernel/signal.c | 7 +++++-- kernel/time/posix-timers.c | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -162,8 +162,9 @@ static inline void posix_cputimers_rt_wa { pct->bases[CPUCLOCK_SCHED].nextevt = runtime; } + void posixtimer_rearm_itimer(struct task_struct *p); -void posixtimer_rearm(struct kernel_siginfo *info); +bool posixtimer_deliver_signal(struct kernel_siginfo *info); /* Init task static initializer */ #define INIT_CPU_TIMERBASE(b) { \ @@ -188,7 +189,7 @@ static inline void posix_cputimers_init( static inline void posix_cputimers_group_init(struct posix_cputimers *pct, u64 cpu_limit) { } static inline void posixtimer_rearm_itimer(struct task_struct *p) { } -static inline void posixtimer_rearm(struct kernel_siginfo *info) { } +static inline bool posixtimer_deliver_signal(struct kernel_siginfo *info) { return false; } #endif #ifdef CONFIG_POSIX_CPU_TIMERS_TASK_WORK --- a/kernel/signal.c +++ b/kernel/signal.c @@ -588,6 +588,7 @@ int dequeue_signal(sigset_t *mask, kerne lockdep_assert_held(&tsk->sighand->siglock); +again: *type = PIDTYPE_PID; signr = __dequeue_signal(&tsk->pending, mask, info); if (!signr) { @@ -619,8 +620,10 @@ int dequeue_signal(sigset_t *mask, kerne } if (IS_ENABLED(CONFIG_POSIX_TIMERS)) { - if (unlikely(info->si_code == SI_TIMER && info->si_sys_private)) - posixtimer_rearm(info); + if (unlikely(info->si_code == SI_TIMER && info->si_sys_private)) { + if (!posixtimer_deliver_signal(info)) + goto again; + } } return signr; --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -254,7 +254,7 @@ static void common_hrtimer_rearm(struct * info::si_sys_private is not zero, which indicates that the timer has to * be rearmed. Restart the timer and update info::si_overrun. */ -void posixtimer_rearm(struct kernel_siginfo *info) +bool posixtimer_deliver_signal(struct kernel_siginfo *info) { struct k_itimer *timr; unsigned long flags; @@ -286,6 +286,7 @@ void posixtimer_rearm(struct kernel_sigi /* Don't expose the si_sys_private value to userspace */ info->si_sys_private = 0; + return true; } int posix_timer_queue_signal(struct k_itimer *timr) From patchwork Tue Jun 6 14:37:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103901 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3455381vqr; Tue, 6 Jun 2023 07:58:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ63yl8rY9q/4VhmTkeZEwjOR7ap7ivshdhg+gQF/NC5zQ4Pbcd4CLo2fRyBHEfovBmQ1pQD X-Received: by 2002:a05:6214:5189:b0:62a:9624:89d7 with SMTP id kl9-20020a056214518900b0062a962489d7mr2572549qvb.21.1686063527204; Tue, 06 Jun 2023 07:58:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063527; cv=none; d=google.com; s=arc-20160816; b=e+kZGKuHtMEIL7zJfObiTeurpB0aF+iu7jZUgJb6ZtDBKSlVjxVtESgwRVeerqS5yd is8nruOGe7pERW66TxEYT5q2ZcN+prPqeoM7KHmnnvgRrURVyeVSCtBb5LVrY8M9PttH 0R86c792MI7X4rtYZgoigeCo9A1fT+/m3TRxoDF/HlzlN/6agixFm+tFnfwmT4gxwpSM r9+zdhCN6N2gsLIlGx8QibJiUEVOJZeKOz7szWQ8jZ7AOLfjMzuihEg/M7FhHdXEH7ID +DlJR3Ms0w3wfslGzfmcnEh5AxwWvTLeD9TVYPK5wx9Wc/45mANz9rhDBoumFwGlUHTN 21BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=PVNa4KLijTQ7CcOYu3CDLgD0Q8pt6GmBRvk3JFfaO1Y=; b=Al3ftaQxo9SdDDh6f+pxh0goLYtGsJwSi5tBTCI+mpb5q+1PIttMaqv7gZNLnUluON uKZeVVkuqjEiYRi9Lo8zK1OkIpEeeWKgGAbfVWAMqyJ0shid0WYp9Gr5QWSI6TQGRitL 3Dq2pXhYgIXpiJjhu1yzScirSqd1eUQEY+SZ1tcZyCtI7a2kcEjykIctCSVMOSAZH8CA aQaSkCDCZJ2lmvZMDTmHoxszeUd5are5Pd/7igchKjyRtdkCxJAA0dmUylMae8QysEhB JP0dOyME6HgDfLgTAu6jE2T/K3pnc1J/lBNqbhd4P5UI1nX0fSp/r0Szn5FwU3BP6hnF C/BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3tnlpwZR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=zuo3CLae; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gc11-20020a056214230b00b00620cb906a49si6450541qvb.281.2023.06.06.07.58.32; Tue, 06 Jun 2023 07:58:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3tnlpwZR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=zuo3CLae; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238296AbjFFOj3 (ORCPT + 99 others); Tue, 6 Jun 2023 10:39:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238183AbjFFOit (ORCPT ); Tue, 6 Jun 2023 10:38:49 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58E231BE4 for ; Tue, 6 Jun 2023 07:38:01 -0700 (PDT) Message-ID: <20230606142032.433429880@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062278; 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=PVNa4KLijTQ7CcOYu3CDLgD0Q8pt6GmBRvk3JFfaO1Y=; b=3tnlpwZR7AOO7Yh1fmxAmC8HLkEI6QD76zGVnsBJknf8UMe5AeHLON600517dH6ZfYHN1t EsBV1RT/DYKL87zBhaT5vrA6XEstqCzGt65cKoBch1fUhqGgkU0qJFAAFHmZG+cuw8mxxM vTIynumi25/W/Ey+lLIyrp8rJAj3Otsm1xnxe/uPFsybfThD3/Jl3yakh/8aC+J1+oQ21b sCxb0iDMYure57654loi6WY4SlZSuiJ//iQ7wp0Xz94G/FiHDrYQq8FwolQVk48G2kPCjd JuVT+hfISI+Am4uRRb4esCZptkkEH5WdA2cnn263pWvRwpz9Pkk51VmspWig5w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062278; 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=PVNa4KLijTQ7CcOYu3CDLgD0Q8pt6GmBRvk3JFfaO1Y=; b=zuo3CLae5BOp6gIZnvW7WN6SahTzqoMNx2aNczVT7msm1Y6lFSCoT8iMQb3JZiQXA9Wm/F ZFr6Z0bcwUN/2uBg== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 25/45] posix-timers: Drop signal if timer has been deleted or reprogrammed References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:58 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965748861251767?= X-GMAIL-MSGID: =?utf-8?q?1767965748861251767?= No point in delivering a signal from the past. POSIX does not specify the behaviour here: - "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. Drop the signal as that is conistent and understandable behaviour. Signed-off-by: Thomas Gleixner --- kernel/time/posix-timers.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -250,14 +250,14 @@ static void common_hrtimer_rearm(struct } /* - * This function is called from the signal delivery code if - * info::si_sys_private is not zero, which indicates that the timer has to - * be rearmed. Restart the timer and update info::si_overrun. + * This function is called from the signal delivery code. It decides + * whether the signal should be dropped and rearms interval timers. */ bool posixtimer_deliver_signal(struct kernel_siginfo *info) { struct k_itimer *timr; unsigned long flags; + bool ret = false; /* * Release siglock to ensure proper locking order versus @@ -279,6 +279,7 @@ bool posixtimer_deliver_signal(struct ke info->si_overrun = timer_overrun_to_int(timr, info->si_overrun); } + ret = true; unlock_timer(timr, flags); out: @@ -286,7 +287,7 @@ bool posixtimer_deliver_signal(struct ke /* Don't expose the si_sys_private value to userspace */ info->si_sys_private = 0; - return true; + return ret; } int posix_timer_queue_signal(struct k_itimer *timr) From patchwork Tue Jun 6 14:38:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103878 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3449043vqr; Tue, 6 Jun 2023 07:47:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7QPqdyMndXyBMKlL+z0xC+nflR/JhyrBau4lo8o/O14gZk11zZUQAWktPonYJ7eN3AoBFi X-Received: by 2002:a05:6a21:3803:b0:111:3c41:2068 with SMTP id yi3-20020a056a21380300b001113c412068mr1356519pzb.28.1686062853000; Tue, 06 Jun 2023 07:47:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686062852; cv=none; d=google.com; s=arc-20160816; b=ZszHBuMI0n3kifNzHk5Vuvatv5beIhaLdkfdOfJxlyV5q3xuKxXa3KjlJqa/DcdSyb Lj3H2glIRoS+DT9ZCYbU2czYdR7gInKrUoxw8L2KhQaqZrbZ1v8P+I70M+uekkHS7BpU aRBauOOKIkzpyXSkQLe3bQqVKRwdL+pEL5qKFIuUlWnP3p6JZsnIlbOctRC/jVJITysh vtxisjtotlzPql5n7azBHughINEh6u53A3D9DLeNHYVS1shXNCSDG+9W49FtQwvYhBJv tjJDuCsli0kUBnlr/8lbU2vCkI4HNLcap2CFv5TRKZ80aMin7Y8SXZnHbXFknPH5x4wX RidQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=9SYjUCAe0AgsqCGuTWf7t+WUqVVywcl4/ZGVc9cUSlA=; b=cFktCSkcRoKmHqgsOy9fpmMUTcwFtpDmqy3GFAB4r5/yGfujQCL50j3Ie1mFC9piRL U4Hljz8JMuto0BYmA+vQF8LBU25xyOLCDiRTqMxRmiAwTlES1ZxAqTstCepbSF1O59Zf CGS5bHg0etBlWgMLvX7KlO63K0Jc0EODMiVF17YHuRMR7P3J7jHpjeHEjqO7r3rwQMgS D9QN96d7n9EDitkfwenxC24WrH3sWTpev4LN1waK1ehJXAJEEPf5hi5XuQwjGDCVl3hw mRsVRT+TDguyLXpQCB3Q3ke2aMsvc4ok44sflCx1wjhlMLheS0XJyv1c1YanaFBMyM0t tsVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qxu1lZ93; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="x/Zj3IWC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i73-20020a636d4c000000b0053b9ebed2adsi7317456pgc.190.2023.06.06.07.47.20; Tue, 06 Jun 2023 07:47:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qxu1lZ93; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="x/Zj3IWC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238301AbjFFOje (ORCPT + 99 others); Tue, 6 Jun 2023 10:39:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238107AbjFFOjE (ORCPT ); Tue, 6 Jun 2023 10:39:04 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8DEA1BF2 for ; Tue, 6 Jun 2023 07:38:05 -0700 (PDT) Message-ID: <20230606142032.489307214@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062280; 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=9SYjUCAe0AgsqCGuTWf7t+WUqVVywcl4/ZGVc9cUSlA=; b=qxu1lZ9377m1VdXrFDK7hm0MCDbgZuf1oa7cKHpXv9jMupkRKDli7MoIf4AeWKjuPEuWPd 9HjzVBhABZ+JqAiOrNP7c4ViUqE7MgiHSt4LSAEqRJoyVpyjYcXTiMlqLzYMoxsMl6iVVz WSyKN2iWFFR1oGgYONZoIe1/lzhxvYf5mut4FHNSrJVnq9nzukQjRELWq3P3wXp7rK6fNr 9a+0J0Dkm87qeVVlj2N5iTSDvUKu3SmZ1s+ao3oU3A14aOQ/ZWwHyUa6yNsb3u4kzqHvV7 FrGeZZVjmyaHIGITJnuuI/KCbN/iwsBRzA0NEksuMBlXWXrcwhxvBthG1AERGQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062280; 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=9SYjUCAe0AgsqCGuTWf7t+WUqVVywcl4/ZGVc9cUSlA=; b=x/Zj3IWC//rixGZDrq+hF1gwDYu/SR5Sf3JVr45VCeoe7YU3bpROw7BBg8TGKJa7FweLbz PO9GHG/GXN45WWAQ== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 26/45] posix-timers: Rename k_itimer::it_requeue_pending References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:00 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965041748347070?= X-GMAIL-MSGID: =?utf-8?q?1767965041748347070?= Prepare for using this struct member to do a proper reprogramming and deletion accounting so that stale signals can be dropped. No functional change. Signed-off-by: Thomas Gleixner --- include/linux/posix-timers.h | 5 ++--- kernel/time/alarmtimer.c | 2 +- kernel/time/posix-cpu-timers.c | 2 +- kernel/time/posix-timers.c | 12 ++++++------ 4 files changed, 10 insertions(+), 11 deletions(-) --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -213,8 +213,7 @@ static inline void posix_cputimers_init_ * @it_active: Marker that timer is active * @it_overrun: The overrun counter for pending signals * @it_overrun_last: The overrun at the time of the last delivered signal - * @it_requeue_pending: Indicator that timer waits for being requeued on - * signal delivery + * @it_signal_seq: Sequence count to control signal delivery * @it_sigev_notify: The notify word of sigevent struct for signal delivery * @it_interval: The interval for periodic timers * @it_signal: Pointer to the creators signal struct @@ -235,7 +234,7 @@ struct k_itimer { int it_active; s64 it_overrun; s64 it_overrun_last; - int it_requeue_pending; + unsigned int it_signal_seq; int it_sigev_notify; ktime_t it_interval; struct signal_struct *it_signal; --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -573,7 +573,7 @@ static enum alarmtimer_restart alarm_han * small intervals cannot starve the system. */ ptr->it_overrun += __alarm_forward_now(alarm, ptr->it_interval, true); - ++ptr->it_requeue_pending; + ++ptr->it_signal_seq; ptr->it_active = 1; result = ALARMTIMER_RESTART; } --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -607,7 +607,7 @@ static void cpu_timer_fire(struct k_itim * ticking in case the signal is deliverable next time. */ posix_cpu_timer_rearm(timer); - ++timer->it_requeue_pending; + ++timer->it_signal_seq; } } --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -269,13 +269,13 @@ bool posixtimer_deliver_signal(struct ke if (!timr) goto out; - if (timr->it_interval && timr->it_requeue_pending == info->si_sys_private) { + if (timr->it_interval && timr->it_signal_seq == info->si_sys_private) { timr->kclock->timer_rearm(timr); timr->it_active = 1; timr->it_overrun_last = timr->it_overrun; timr->it_overrun = -1LL; - ++timr->it_requeue_pending; + ++timr->it_signal_seq; info->si_overrun = timer_overrun_to_int(timr, info->si_overrun); } @@ -299,7 +299,7 @@ int posix_timer_queue_signal(struct k_it timr->it_active = 0; if (timr->it_interval) - si_private = ++timr->it_requeue_pending; + si_private = ++timr->it_signal_seq; type = !(timr->it_sigev_notify & SIGEV_THREAD_ID) ? PIDTYPE_TGID : PIDTYPE_PID; ret = send_sigqueue(timr->sigq, timr->it_pid, type, si_private); @@ -366,7 +366,7 @@ static enum hrtimer_restart posix_timer_ timr->it_overrun += hrtimer_forward(timer, now, timr->it_interval); ret = HRTIMER_RESTART; - ++timr->it_requeue_pending; + ++timr->it_signal_seq; timr->it_active = 1; } } @@ -662,7 +662,7 @@ void common_timer_get(struct k_itimer *t * is a SIGEV_NONE timer move the expiry time forward by intervals, * so expiry is > now. */ - if (iv && (timr->it_requeue_pending & REQUEUE_PENDING || sig_none)) + if (iv && (timr->it_signal_seq & REQUEUE_PENDING || sig_none)) timr->it_overrun += kc->timer_forward(timr, now); remaining = kc->timer_remaining(timr, now); @@ -863,7 +863,7 @@ void posix_timer_set_common(struct k_iti timer->it_interval = timespec64_to_ktime(new_setting->it_interval); /* Prevent reloading in case there is a signal pending */ - timer->it_requeue_pending = (timer->it_requeue_pending + 2) & ~REQUEUE_PENDING; + timer->it_signal_seq = (timer->it_signal_seq + 2) & ~REQUEUE_PENDING; /* Reset overrun accounting */ timer->it_overrun_last = 0; timer->it_overrun = -1LL; From patchwork Tue Jun 6 14:38:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103882 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3450008vqr; Tue, 6 Jun 2023 07:49:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ71BsJ0LQevj3sMnWdQBXxC/xa0zkZtbpPctX77edPpVZ1x0WRDk1ynQAFkslYk0xgENwke X-Received: by 2002:a05:6a00:2e1a:b0:650:2660:1bcc with SMTP id fc26-20020a056a002e1a00b0065026601bccmr3182470pfb.8.1686062958109; Tue, 06 Jun 2023 07:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686062958; cv=none; d=google.com; s=arc-20160816; b=CBat8curByiz9c+99AhzpO9twRDgRu973PRtgD+mPTCNU4sEGJ8rIBtVIM4UKq/Dt9 W/G+A6HEkovl8Wqq/Ax+9oMy54qTvHv9sgvV57eYk1zBzjLUzu+NQJXlWDe3kzXFK27E pvtPCxhYMZ089CoGmHrzuE3/ZhzK5lDMn11NDwNghgPO0Tq3RziFEWZRRZMy/vzMtJta smCWFB1w7sC0NpYNWZPGMOk3loe9sAW6jswWV0H6I/72zUhXH0gJ52QnPDVdp4wlNuCJ HO/9Gnt05U51mSxPt6IarWZsIz9CEqs2v2X0CHdACSlByGo3hxSk85C7VEzJQ+y6LXnL qSaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=5ed1VkOh2UBEVrURDClugUqs9wtwWx9MqD/9qEBm3z4=; b=y7J9MAjcTFFvD/4GaPjsbJYcwQLXS2DR6UgU00np98Y22aY0B4G9lCKS9Fv6E3h38H r8JvnarFotGBaZNCP4hz9hQLVki54C4uDVPbMYjddq34zXQDPDCc/1WYhR29YkAuf3NS 5AIpnHbNMeANV6ws9dF/z6mVUSw9eH3XLCEL+zAwUwzuMFUOfTeuQmTg7w0i3dm85i62 6nbuGPKR/88pEr/w9FYoXdheJO1M5huFJgjkKpPebF9TNzV5SeWYwhRfCvC6YbvbPo8C 94hX+hlaJNtjI8sxCS1xAWMPejGkNS2jX3G8B36leZsCmjCrN1HvO4rT3o2Ub/3Joeeq vaIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="SuKcaX/u"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c4-20020a637244000000b005304a8af2adsi7171626pgn.392.2023.06.06.07.49.04; Tue, 06 Jun 2023 07:49:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="SuKcaX/u"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238282AbjFFOk3 (ORCPT + 99 others); Tue, 6 Jun 2023 10:40:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238279AbjFFOjU (ORCPT ); Tue, 6 Jun 2023 10:39:20 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 576E31FCE for ; Tue, 6 Jun 2023 07:38:17 -0700 (PDT) Message-ID: <20230606142032.544511403@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062282; 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=5ed1VkOh2UBEVrURDClugUqs9wtwWx9MqD/9qEBm3z4=; b=SuKcaX/uHCB7zYDh0doxbGCGrsnwgsbNatkptPv4YN63eB3SI+fQBRMq82+9X4EFM3OX+d Q2aLgkzG3HLJ7+D5/bvQlaB3bL11ESuo19w8/hYUiZwt3mSp9TWAVxafl60oWkz7+H91+E srSXZRI5FUVOyQZuK7uC1Dh6dvQv2dVY+hCX4zLHmot+wvuHplX074nrPq1EBsUUzloub4 5EoleiXrscDNFk0Zw5vecrIt8UcSs1Xmb97R/1dbfj7p5XD9tF2Wh+oD0K55ogMLQFKhVX 18GxPs8IylsMWpmnDC16vZ9T6wOB5amVLNUae6Xz3YALjUdzr+pxOezVnRgyFw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062282; 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=5ed1VkOh2UBEVrURDClugUqs9wtwWx9MqD/9qEBm3z4=; b=pva/uGMhqiSbwG4R61C+hTFA66LNiX0FDV8a7t7kF753w3k3Uv6gPo7UxGDBcSDwoBDWN0 SFtTkR5NoQ/IgiCQ== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 27/45] posix-timers: Add proper state tracking References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:01 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965152600032869?= X-GMAIL-MSGID: =?utf-8?q?1767965152600032869?= Right now the state tracking is done by two struct members: - it_active: A boolean which tracks armed/disarmed state - it_signal_seq: A sequence counter which is used to invalidate settings and prevent rearming Replace it_active with it_status and keep properly track about the states in one place. This allows to reuse it_signal_seq to track reprogramming, disarm and delete operations in order to drop signals which are related to the state previous of those operations. Signed-off-by: Thomas Gleixner --- include/linux/posix-timers.h | 4 ++-- kernel/time/alarmtimer.c | 2 +- kernel/time/posix-cpu-timers.c | 14 +++++++------- kernel/time/posix-timers.c | 22 +++++++++++++--------- kernel/time/posix-timers.h | 6 ++++++ 5 files changed, 29 insertions(+), 19 deletions(-) --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -210,7 +210,7 @@ static inline void posix_cputimers_init_ * @kclock: Pointer to the k_clock struct handling this timer * @it_clock: The posix timer clock id * @it_id: The posix timer id for identifying the timer - * @it_active: Marker that timer is active + * @it_status: The status of the timer * @it_overrun: The overrun counter for pending signals * @it_overrun_last: The overrun at the time of the last delivered signal * @it_signal_seq: Sequence count to control signal delivery @@ -231,7 +231,7 @@ struct k_itimer { const struct k_clock *kclock; clockid_t it_clock; timer_t it_id; - int it_active; + int it_status; s64 it_overrun; s64 it_overrun_last; unsigned int it_signal_seq; --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -574,7 +574,7 @@ static enum alarmtimer_restart alarm_han */ ptr->it_overrun += __alarm_forward_now(alarm, ptr->it_interval, true); ++ptr->it_signal_seq; - ptr->it_active = 1; + ptr->it_status = POSIX_TIMER_ARMED; result = ALARMTIMER_RESTART; } spin_unlock_irqrestore(&ptr->it_lock, flags); --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -453,7 +453,6 @@ static void disarm_timer(struct k_itimer struct cpu_timer *ctmr = &timer->it.cpu; struct posix_cputimer_base *base; - timer->it_active = 0; if (!cpu_timer_dequeue(ctmr)) return; @@ -494,11 +493,12 @@ static int posix_cpu_timer_del(struct k_ */ WARN_ON_ONCE(ctmr->head || timerqueue_node_queued(&ctmr->node)); } else { - if (timer->it.cpu.firing) + if (timer->it.cpu.firing) { ret = TIMER_RETRY; - else + } else { disarm_timer(timer, p); - + timer->it_status = POSIX_TIMER_DISARMED; + } unlock_task_sighand(p, &flags); } @@ -560,7 +560,7 @@ static void arm_timer(struct k_itimer *t struct cpu_timer *ctmr = &timer->it.cpu; u64 newexp = cpu_timer_getexpires(ctmr); - timer->it_active = 1; + timer->it_status = POSIX_TIMER_ARMED; if (!cpu_timer_enqueue(&base->tqhead, ctmr)) return; @@ -670,7 +670,7 @@ static int posix_cpu_timer_set(struct k_ ret = TIMER_RETRY; } else { cpu_timer_dequeue(ctmr); - timer->it_active = 0; + timer->it_status = POSIX_TIMER_DISARMED; } /* @@ -804,7 +804,7 @@ static u64 collect_timerqueue(struct tim rcu_assign_pointer(ctmr->handling, current); cpu_timer_dequeue(ctmr); ktmr = container_of(ctmr, struct k_itimer, it.cpu); - ktmr->it_active = 0; + ktmr->it_status = POSIX_TIMER_DISARMED; list_add_tail(&ctmr->elist, firing); } --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -272,7 +272,7 @@ bool posixtimer_deliver_signal(struct ke if (timr->it_interval && timr->it_signal_seq == info->si_sys_private) { timr->kclock->timer_rearm(timr); - timr->it_active = 1; + timr->it_status = POSIX_TIMER_ARMED; timr->it_overrun_last = timr->it_overrun; timr->it_overrun = -1LL; ++timr->it_signal_seq; @@ -292,14 +292,17 @@ bool posixtimer_deliver_signal(struct ke int posix_timer_queue_signal(struct k_itimer *timr) { + enum posix_timer_state state = POSIX_TIMER_DISARMED; int ret, si_private = 0; enum pid_type type; lockdep_assert_held(&timr->it_lock); - timr->it_active = 0; - if (timr->it_interval) + if (timr->it_interval) { + state = POSIX_TIMER_REQUEUE_PENDING; si_private = ++timr->it_signal_seq; + } + timr->it_status = state; type = !(timr->it_sigev_notify & SIGEV_THREAD_ID) ? PIDTYPE_TGID : PIDTYPE_PID; ret = send_sigqueue(timr->sigq, timr->it_pid, type, si_private); @@ -367,7 +370,7 @@ static enum hrtimer_restart posix_timer_ timr->it_overrun += hrtimer_forward(timer, now, timr->it_interval); ret = HRTIMER_RESTART; ++timr->it_signal_seq; - timr->it_active = 1; + timr->it_status = POSIX_TIMER_ARMED; } } @@ -642,10 +645,10 @@ void common_timer_get(struct k_itimer *t bool iv = !!timr->it_interval; ktime_t now, remaining; - if (!iv && !timr->it_active) { + if (!iv && timr->it_status == POSIX_TIMER_DISARMED) { /* * SIGEV_NONE oneshot timers are never queued and therefore - * timr->it_active is always false. The check below + * timr->it_status is always DISARMED. The check below * vs. remaining time will handle this case. * * For all other timers there is nothing to update here, so @@ -890,7 +893,7 @@ int common_timer_set(struct k_itimer *ti if (kc->timer_try_to_cancel(timr) < 0) return TIMER_RETRY; - timr->it_active = 0; + timr->it_status = POSIX_TIMER_DISARMED; posix_timer_set_common(timr, new_setting); /* Keep timer disarmed when it_value is zero */ @@ -903,7 +906,8 @@ int common_timer_set(struct k_itimer *ti sigev_none = timr->it_sigev_notify == SIGEV_NONE; kc->timer_arm(timr, expires, flags & TIMER_ABSTIME, sigev_none); - timr->it_active = !sigev_none; + if (!sigev_none) + timr->it_status = POSIX_TIMER_ARMED; return 0; } @@ -1002,7 +1006,7 @@ int common_timer_del(struct k_itimer *ti timer->it_interval = 0; if (kc->timer_try_to_cancel(timer) < 0) return TIMER_RETRY; - timer->it_active = 0; + timer->it_status = POSIX_TIMER_DISARMED; return 0; } --- a/kernel/time/posix-timers.h +++ b/kernel/time/posix-timers.h @@ -1,6 +1,12 @@ /* SPDX-License-Identifier: GPL-2.0 */ #define TIMER_RETRY 1 +enum posix_timer_state { + POSIX_TIMER_DISARMED, + POSIX_TIMER_ARMED, + POSIX_TIMER_REQUEUE_PENDING, +}; + struct k_clock { int (*clock_getres)(const clockid_t which_clock, struct timespec64 *tp); From patchwork Tue Jun 6 14:38:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103955 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3489688vqr; Tue, 6 Jun 2023 08:44:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5girTGUlTHCW5DHg6vboKbcCNuC50qRPR1r+z+uXMyxENVLQQ0bJA1BtVreXJgPynz85ZD X-Received: by 2002:ac8:5a8c:0:b0:3f6:ac41:9f29 with SMTP id c12-20020ac85a8c000000b003f6ac419f29mr100667qtc.15.1686066263455; Tue, 06 Jun 2023 08:44:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686066263; cv=none; d=google.com; s=arc-20160816; b=eJT8rlEh1/HJHkHyjGR+VI5O7bnbwPJ0d2twJbBwQBrl6pIbKmoGWa7L9w1zVXhljT yFuZpAEzVS+MaU3VqPptPv08V8eD4f2nAkapPrdw4y4l91MVw34zyteL8C5sK4wemnsn 0MTi9/0Mfne4fyLKGXMXFVqLcxLr+py7RJ5HImqiAZ4NrvprKAVM63FNQ0gJeX+fkf4p 3mDwMf1RzGrg3B++aGVE+1oY10KJ3uYUBO/J+hoFgpka1U7yuHC5Lxpf/UCg2lkE1oLe 1W8ZIaxdCbqfFlHHEq2HqqyUvIrV0XVVJPWHljgQkJsYLieqJtl6VVQdLnEZoHvU6VPf mc6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=IE+/o+H4G+/DJ08h5MOIwSs6Di0NMd0uAJ8BN6taE4E=; b=fFNZ9iCmVWq30JzD/ZbqB3gpFgSqUU+9GF77/3AOeKpFifNhDusWmxaUg8Uwpd7Fb/ JTBVxN6EEGS1QyyhwdGI+sqRF4WL3PmttKXPMuAJuXoEmc5f11jsh6oQ/WxO2IY2bmvq YX8Pdxddb/rMy2QoQ/QPBkZB5BKcU3EWnGRSWjIANBzVqZu4y0nWs+uIMjaAqYZptdFr DmCr8pGccrAi3cIpFjqBxtuTEfOIy/HnjjBQwVm/CUoI8GypvTmI16Kbbsl+mApaZRbI I6ielbszAgnAL7KI2dfWGVJKsJ+oHt6yOKksayT29vqQpMj8OndCIScmOvhQzzC07h2Z Flmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zIJxWHdU; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f30-20020a05622a1a1e00b003f6c5812132si3710050qtb.385.2023.06.06.08.44.09; Tue, 06 Jun 2023 08:44:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zIJxWHdU; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238342AbjFFOkm (ORCPT + 99 others); Tue, 6 Jun 2023 10:40:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238281AbjFFOjY (ORCPT ); Tue, 6 Jun 2023 10:39:24 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6CBB173E for ; Tue, 6 Jun 2023 07:38:23 -0700 (PDT) Message-ID: <20230606142032.599847383@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062283; 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=IE+/o+H4G+/DJ08h5MOIwSs6Di0NMd0uAJ8BN6taE4E=; b=zIJxWHdUqM4n7bDb1/OCIIoG2UlagFbiwmxrqg8dvkJ5ygXMH7gVqE4XowoOn9QGXa+/pH /DauAZgropTMZ552OMqoZZGes+EvSCLW65weFBD3kRg/96tWgQIxK3cRedD/qX4FSekFFV GXLj+zaD6CXsijyqayQizYSYclMKkIVfz5MGTKRxjDZj7z7NJ6as/lImmj/7v9VIlNmYOm BPnIGg3bJVs6eC8ImSwVEj3hG1408+yjUAaJXaqVovuOsP1v/zTrWBf4HyywVaqwDd11SJ MqHKGzV/DQaTyjdcAuIpvS2BPUCIXAE+SZ8081xRyuOupldHJUqj+PKXH6t/Wg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062283; 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=IE+/o+H4G+/DJ08h5MOIwSs6Di0NMd0uAJ8BN6taE4E=; b=wKlW6c9/tmJd3EDbm0eBxWX51b7a+W86UZZgl1eeqOI4mOlHm5BIph2/T5pfwQWr0nISIY Kfgex+wV+4YEniCA== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 28/45] posix-timers: Make signal delivery consistent References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:03 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767968618340521147?= X-GMAIL-MSGID: =?utf-8?q?1767968618340521147?= Signals of timers which are reprogammed, disarmed or deleted can deliver signals related to the past. The POSIX spec is blury about this: - "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. This makes the behaviour consistent and understandable. Remove the si_sys_private check from the signal delivery code and invoke posix_timer_deliver_signal() unconditionally. Change that function so it controls the actual signal delivery via the return value. It now instructs the signal code to drop the signal when: 1) The timer does not longer exist in the hash table 2) The timer signal_seq value is not the same as the si_sys_private value which was set when the signal was queued. Signed-off-by: Thomas Gleixner --- include/linux/posix-timers.h | 2 -- kernel/signal.c | 2 +- kernel/time/posix-timers.c | 25 +++++++++++++++---------- 3 files changed, 16 insertions(+), 13 deletions(-) --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -200,8 +200,6 @@ static inline void clear_posix_cputimers static inline void posix_cputimers_init_work(void) { } #endif -#define REQUEUE_PENDING 1 - /** * struct k_itimer - POSIX.1b interval timer structure. * @list: List head for binding the timer to signals->posix_timers --- a/kernel/signal.c +++ b/kernel/signal.c @@ -620,7 +620,7 @@ int dequeue_signal(sigset_t *mask, kerne } if (IS_ENABLED(CONFIG_POSIX_TIMERS)) { - if (unlikely(info->si_code == SI_TIMER && info->si_sys_private)) { + if (unlikely(info->si_code == SI_TIMER)) { if (!posixtimer_deliver_signal(info)) goto again; } --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -269,7 +269,10 @@ bool posixtimer_deliver_signal(struct ke if (!timr) goto out; - if (timr->it_interval && timr->it_signal_seq == info->si_sys_private) { + if (timr->it_signal_seq != info->si_sys_private) + goto out_unlock; + + if (timr->it_interval && timr->it_status == POSIX_TIMER_REQUEUE_PENDING) { timr->kclock->timer_rearm(timr); timr->it_status = POSIX_TIMER_ARMED; @@ -281,6 +284,7 @@ bool posixtimer_deliver_signal(struct ke } ret = true; +out_unlock: unlock_timer(timr, flags); out: spin_lock(¤t->sighand->siglock); @@ -293,19 +297,19 @@ bool posixtimer_deliver_signal(struct ke int posix_timer_queue_signal(struct k_itimer *timr) { enum posix_timer_state state = POSIX_TIMER_DISARMED; - int ret, si_private = 0; enum pid_type type; + int ret; lockdep_assert_held(&timr->it_lock); if (timr->it_interval) { + timr->it_signal_seq++; state = POSIX_TIMER_REQUEUE_PENDING; - si_private = ++timr->it_signal_seq; } timr->it_status = state; type = !(timr->it_sigev_notify & SIGEV_THREAD_ID) ? PIDTYPE_TGID : PIDTYPE_PID; - ret = send_sigqueue(timr->sigq, timr->it_pid, type, si_private); + ret = send_sigqueue(timr->sigq, timr->it_pid, type, timr->it_signal_seq); /* If we failed to send the signal the timer stops. */ return ret > 0; } @@ -665,7 +669,7 @@ void common_timer_get(struct k_itimer *t * is a SIGEV_NONE timer move the expiry time forward by intervals, * so expiry is > now. */ - if (iv && (timr->it_signal_seq & REQUEUE_PENDING || sig_none)) + if (iv && timr->it_status != POSIX_TIMER_ARMED) timr->it_overrun += kc->timer_forward(timr, now); remaining = kc->timer_remaining(timr, now); @@ -865,8 +869,6 @@ void posix_timer_set_common(struct k_iti if (new_setting->it_value.tv_sec || new_setting->it_value.tv_nsec) timer->it_interval = timespec64_to_ktime(new_setting->it_interval); - /* Prevent reloading in case there is a signal pending */ - timer->it_signal_seq = (timer->it_signal_seq + 2) & ~REQUEUE_PENDING; /* Reset overrun accounting */ timer->it_overrun_last = 0; timer->it_overrun = -1LL; @@ -884,8 +886,6 @@ int common_timer_set(struct k_itimer *ti if (old_setting) common_timer_get(timr, old_setting); - /* Prevent rearming by clearing the interval */ - timr->it_interval = 0; /* * Careful here. On SMP systems the timer expiry function could be * active and spinning on timr->it_lock. @@ -935,6 +935,9 @@ static int do_timer_settime(timer_t time if (old_spec64) old_spec64->it_interval = ktime_to_timespec64(timr->it_interval); + /* Prevent signal delivery and rearming. */ + timr->it_signal_seq++; + kc = timr->kclock; if (WARN_ON_ONCE(!kc || !kc->timer_set)) error = -EINVAL; @@ -1003,7 +1006,6 @@ int common_timer_del(struct k_itimer *ti { const struct k_clock *kc = timer->kclock; - timer->it_interval = 0; if (kc->timer_try_to_cancel(timer) < 0) return TIMER_RETRY; timer->it_status = POSIX_TIMER_DISARMED; @@ -1031,6 +1033,9 @@ SYSCALL_DEFINE1(timer_delete, timer_t, t if (!timer) return -EINVAL; + /* Prevent signal delivery and rearming. */ + timer->it_signal_seq++; + if (unlikely(timer_delete_hook(timer) == TIMER_RETRY)) { /* Unlocks and relocks the timer if it still exists */ timer = timer_wait_running(timer, &flags); From patchwork Tue Jun 6 14:38:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103888 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3451612vqr; Tue, 6 Jun 2023 07:52:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ZI0+ZW6xjk7jU4VsQXo2bM9bL+0exgJoL3y07+U1LjMEFQAuLV+LurA5gBA8EvXD+tFWf X-Received: by 2002:a05:6214:629:b0:5c5:1a25:edf0 with SMTP id a9-20020a056214062900b005c51a25edf0mr2397560qvx.26.1686063125300; Tue, 06 Jun 2023 07:52:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063125; cv=none; d=google.com; s=arc-20160816; b=n4Cw+f5zl4HUXIkvy27XbIbAev7UaRS3Cf+kgv1iMyTYMe3AFKDpKaK6emtAXrELwy pr6uyfkvU5QUOyRo1E8fR+60sLq8FlNatDoHvGesA3NmeoUU02fe8EGGsCO17lfM5mQH kVBzmgCAf+kwxHCxI/86DrQv/ly8U9vM8TVUPOx9ujUi/wpWsvYjCDGAV29J/4Y5SJkg +Z2kBFYmxnGnHwCHB3ifypHBl0PfDdA/vmeLuvfDfFEpJ4dqQkOT8+/Yv8T0m3/QRRbi U6Xcpnb/11QwZYsgNkVqp+a1cxVm6Q84YneTMvD2F5sLdmPAq/XzmGDArdxK0ThCKQCo qG+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=CLYMwgJmr5FlvwjCFRZh30bCjVfx+q+Z6l1NHlqA5Kg=; b=ggL6ao8TS2/pvzR40NbGYBAVlQj7jXTroPFO031jd2jDUEuERYsQ/BnfnVmVpU64Oh ad+MkgyMU7LZ8BlU7J82y3Ww6tM8JzuBM1Va0+qYSIHumVqJzc1o5lZImoIpESuyipL9 IDUs4XMvtczs6KnuhpIsEqwrUVoccogsIthY+Zzz3R6ZPr7TZf+gQNh7WqO90u1tOn8a T29Lupt8M91w9O8S86eiK3WLKAUFYjWVMihXrGKPRfGkMOKKYq8l2nD51scalgIsUGsl ZL5NiDcujewS1Y8lfkhaOhSRxMYjf222FnZPPcuzo3gad2WhKgAHnHhlQ+eMNpr3hzdN ZyVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SBEkWjjK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=kCwRxsDU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jp11-20020ad45f8b000000b0062b5c0de74esi1300067qvb.592.2023.06.06.07.51.51; Tue, 06 Jun 2023 07:52:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SBEkWjjK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=kCwRxsDU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238167AbjFFOkW (ORCPT + 99 others); Tue, 6 Jun 2023 10:40:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238266AbjFFOjH (ORCPT ); Tue, 6 Jun 2023 10:39:07 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FCB1171D for ; Tue, 6 Jun 2023 07:38:14 -0700 (PDT) Message-ID: <20230606142032.655376396@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062285; 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=CLYMwgJmr5FlvwjCFRZh30bCjVfx+q+Z6l1NHlqA5Kg=; b=SBEkWjjKOPc5r+5qv1tF0CLdempgLMDgk3cqd3AUuEo9hq8jZKn6O3sLLj0nysbfM68AYn VikIQ8Zln3DJFEQyrO8rAU45wcbGPtUUHnJDPSTrsLR/EHe/Q+FByVe3EfMAO4ntt05wBz IMPaxCElQF7f3rpKXvZLfYJZwvTcIjsl3nIGGxvbPOnexQCQu+XuRrreGtQYgQ8iDSMOFJ XkB4GmB6/R4Qj3LdbTQYkT557pSh2o3wqC1padUFRnRJsbGMdq2ZR7RbVGwWdm0IyyfB0Y SJfuSEVhr7SUTgvVfJbOTwNF8qzx3PDPf6chFeCTao3G1pVQpnn/gVH7QN0jyg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062285; 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=CLYMwgJmr5FlvwjCFRZh30bCjVfx+q+Z6l1NHlqA5Kg=; b=kCwRxsDUwnRH9F3ouDI9aLA4jIZh6Raet5hysFRmvvgVfj9nsm6Vn789ZsSIWMFM5RAHaA P1eLYe5cCVClT/Cg== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 29/45] posix-timers: Make signal overrun accounting sensible References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:04 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965327560542280?= X-GMAIL-MSGID: =?utf-8?q?1767965327560542280?= The handling of the timer overrun in the signal code is inconsistent as it takes previous overruns into account. This is just wrong as after the reprogramming of a timer the overrun count starts over from a clean state, i.e. 0. Make the accounting in send_sigqueue() consistent with that. Signed-off-by: Thomas Gleixner --- kernel/signal.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1957,6 +1957,34 @@ int send_sigqueue(struct sigqueue *q, st */ q->info.si_sys_private = si_private; + /* + * Set the overrun count to zero unconditionally. The posix timer + * code does not self rearm periodic timers. They are rearmed from + * dequeue_signal(). + * + * But there is a situation where @q is already enqueued: + * + * 1) timer_settime() + * arm_timer() + * 2) timer_expires() + * send_sigqueue(@q) + * enqueue(@q) + * 3) timer_settime() + * arm_timer() + * 4) timer_expires() + * send_sigqueue(@q) <- Observes @q already queued + * + * In this case incrementing si_overrun does not make sense because + * there is no relationship between timer_settime() #1 and #2. + * + * The POSIX specification is useful as always: "The effect of + * disarming or resetting a timer with pending expiration + * notifications is unspecified." + * + * Just do the sensible thing and reset the overrun. + */ + q->info.si_overrun = 0; + ret = 1; /* the signal is ignored */ result = TRACE_SIGNAL_IGNORED; if (!prepare_signal(sig, t, false)) @@ -1964,15 +1992,9 @@ int send_sigqueue(struct sigqueue *q, st ret = 0; if (unlikely(!list_empty(&q->list))) { - /* - * If an SI_TIMER entry is already queue just increment - * the overrun count. - */ - q->info.si_overrun++; result = TRACE_SIGNAL_ALREADY_PENDING; goto out; } - q->info.si_overrun = 0; signalfd_notify(t, sig); pending = (type != PIDTYPE_PID) ? &t->signal->shared_pending : &t->pending; From patchwork Tue Jun 6 14:38:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103937 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3483905vqr; Tue, 6 Jun 2023 08:35:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4opEkUSwNf/oDabpAwvyjavzIRtydrLpBupyWp86PNI4yZFpnU+ED/s6PZHzp0Gg0Fmyc/ X-Received: by 2002:a05:622a:3cf:b0:3f9:b88c:1e14 with SMTP id k15-20020a05622a03cf00b003f9b88c1e14mr18996qtx.23.1686065729917; Tue, 06 Jun 2023 08:35:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686065729; cv=none; d=google.com; s=arc-20160816; b=KsyKBaCjcdflBVEGVgDMQLKsoBuXMEsjlo4Ck0gkOslsG8KJUJebMp0C4X9KqBdwLp ELMgkAtZnh/BgAyMlPbDfu65166qB88dXkepGWzbDqlUGvbtXNzzSdRuuyuGrO+sNqtb ALf7+fI2HZEsYsxUjJiRJ40dgiN1hwdJuEm4lU0MyoPa+MroYWpmJP18cDjlmRY9V4vE /muvWe0eTz4tTFX4O1hIZNuKCBcK2QlY9SfpsD77HOX+4iDZjJc8/25tv/NNCVP0lFW9 0ZYG8XX2ajUVpM5W28Pshnpu/hAvW+ImrKAyhHxMw7IWCp2X0hSVdNtu1w5ecH3JQ/fE SY+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=tGjZhkMVQyRr4XnKiVSbNfTqylPySohR9BvGVWy+/yU=; b=QEHA8NwCgh9B0sObDUyEsYM+6K7/FpIG50nSWuvKeSX8FkjA11oP23vY5KNBC8nGdC 9jLO24iuL8bt4kFBuws7v2yMQ5Roo/pmht/oE8K3EuYF17w+y23JsmkC1X2VKhm8dS+e Pva3i1Scev//lJsbvvX3XWRzZzWgpr7gwPMfDfg4A1gzl6vFJMKbijlGw63FYy6PwxNV xvwPI5vBWNcyRIED25CD6hDAbxok2EzdDajsJbSydvNIjgEz7q9CJtNctl+5dbYvNazE g8LSEBPJTl6D/JZDtlLPI1RCHAgUg1Oyq6n8GyIqHfX7wbo+tLVR9TbTUH1M5AbWWa+O 5Hxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Js0F1AHE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f13-20020a05622a104d00b003f719daf2cbsi6515572qte.730.2023.06.06.08.35.15; Tue, 06 Jun 2023 08:35:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Js0F1AHE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238160AbjFFOlN (ORCPT + 99 others); Tue, 6 Jun 2023 10:41:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238384AbjFFOj7 (ORCPT ); Tue, 6 Jun 2023 10:39:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BF811FFC for ; Tue, 6 Jun 2023 07:38:44 -0700 (PDT) Message-ID: <20230606142032.710699683@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062287; 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=tGjZhkMVQyRr4XnKiVSbNfTqylPySohR9BvGVWy+/yU=; b=Js0F1AHEaIizBcWa7NPJK4AlSsrHSTctCJtwd7EXPcaUDu6Iw0MFE4A2cVWrts6eEMwuLg F0D+hYNNMgqX6YW61nxInrcWTjNchojQ0rjcHf/BWCmOdcvOiQv3hN763kS6Win12saETu v4bxvCeUQkEe0talgjedYqgUHMqzQvVorHTMwki7YpcRa2qXLZyI7d/qkfQ89IbnjWs3Og FGXLTAUUbYTYdE42MXg5P0RzT1CekezHUrsHZmXWPgcI6ALGDtnVzhrL9fUMzrjPi+gCcf /slyhGEhuzLxSk33oQ9jbmqf+Kfmfdwv4plghTsCMlyw0VtxgEjEAguNo90zRg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062287; 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=tGjZhkMVQyRr4XnKiVSbNfTqylPySohR9BvGVWy+/yU=; b=4JlCTJy514LpWzmZGXVL9Qe2KOlRSWplLy8k9tNqv1tE/OCU7Bc0O3PvAhCBFshCffOYrT MeXFQfA9/r/LRqBA== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 30/45] posix-cpu-timers: Use dedicated flag for CPU timer nanosleep References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:06 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767968058460277137?= X-GMAIL-MSGID: =?utf-8?q?1767968058460277137?= POSIX CPU timer nanosleep creates a k_itimer on stack and uses the sigq pointer to detect the nanosleep case in the expiry function. Prepare for embedding sigqueue into struct k_itimer by using a dedicated flag for nanosleep. Signed-off-by: Thomas Gleixner --- include/linux/posix-timers.h | 4 +++- kernel/time/posix-cpu-timers.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -66,6 +66,7 @@ static inline int clockid_to_fd(const cl * @pid: Pointer to target task PID * @elist: List head for the expiry list * @firing: Timer is currently firing + * @nanosleep: Timer is used for nanosleep and is not a regular posix-timer * @handling: Pointer to the task which handles expiry */ struct cpu_timer { @@ -73,7 +74,8 @@ struct cpu_timer { struct timerqueue_head *head; struct pid *pid; struct list_head elist; - int firing; + bool firing; + bool nanosleep; struct task_struct __rcu *handling; }; --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -586,7 +586,7 @@ static void cpu_timer_fire(struct k_itim { struct cpu_timer *ctmr = &timer->it.cpu; - if (unlikely(timer->sigq == NULL)) { + if (unlikely(ctmr->nanosleep)) { /* * This a special case for clock_nanosleep, * not a normal timer from sys_timer_create. @@ -1471,6 +1471,7 @@ static int do_cpu_nanosleep(const clocki timer.it_overrun = -1; error = posix_cpu_timer_create(&timer); timer.it_process = current; + timer.it.cpu.nanosleep = true; if (!error) { static struct itimerspec64 zero_it; From patchwork Tue Jun 6 14:38:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103903 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3455553vqr; Tue, 6 Jun 2023 07:59:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5XADq3hiGo8vHlYBZZFz+Oxnm35GGe505no77UdmZf++ZIQHUBfF/IAkofH48gIsIQ/e6v X-Received: by 2002:a05:620a:654a:b0:75b:23a1:8e79 with SMTP id qc10-20020a05620a654a00b0075b23a18e79mr1703010qkn.74.1686063546266; Tue, 06 Jun 2023 07:59:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063546; cv=none; d=google.com; s=arc-20160816; b=Tgq3jnZK+pfRp3tikXMfPKTH4skCGdP5CadNB56pSEd9lbGuZSr9cPha/W9sKkw4Vs /hDmsUtyCD2fsCE7k92LvoeBZgSwfiAh2Ozm72ih35DdUuYRvGqY4WIcw+yNB/1c8Vvj EeeVzqG5uNgT8MfvtRUr8gV1uh9Wgk7JvgUxmqsgm56KQrn87qI8iI7qD2bR5FaSoBQB eAimGS/S72kTStdyDc16HSqtwIUh6BCrrdJEgt/gWU2QWFfeOfbEj61mrRgjB6nHvnnM 3NV/R+EKzzHxlwGpEHQjR3hap640HaVO0XquWrkBDabY430HfUOd/hTYML1TJx1vaJ77 xdsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=WBARrxgJ0Fo3O3pXIjgjYSXb/czDjqPuA7NhGPJIs00=; b=X2/gwoH6F1VTjRI5+s4marRnJKRzdiwKVdjAS1Y2eoR4JoJLDnceje7WKBPuMBbqbd bgWsXOnNjiwTKR7QOezYYBTfZQzNz8KE6qzPy3Htp633k6joYtpiT8OgfcPs7GhnIwGV U9Bt/kUH25rhVed2e9EQVKTPi2F1aafGCjvfEw+XAEt/Io1/REVUmxPiParZXsxN72ca GqLAV/T3w/gXKqHno3Vk8nEbvpjb2p9fUBhWMBQh/hF22vBbX8a63nC7Oufd/endOzBk Bn7gvQqKh1GJoR24IMDLjpjxmnVz2Lm4HDXXI5QP14dbl1iQunD2D+8eJBy6Oi4QVuhG X8Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=oEOxb0sU; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z3-20020ae9c103000000b0075cf5c73f94si5981085qki.772.2023.06.06.07.58.52; Tue, 06 Jun 2023 07:59:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=oEOxb0sU; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238267AbjFFOk0 (ORCPT + 99 others); Tue, 6 Jun 2023 10:40:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238139AbjFFOjV (ORCPT ); Tue, 6 Jun 2023 10:39:21 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC4AA10E0 for ; Tue, 6 Jun 2023 07:38:18 -0700 (PDT) Message-ID: <20230606142032.768353204@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062288; 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=WBARrxgJ0Fo3O3pXIjgjYSXb/czDjqPuA7NhGPJIs00=; b=oEOxb0sUym1Pwy7Z9NDCrzBqaCSSmmAuNYE8cNhD9uSA2Muk9RagSHTmhGzOUEUlWgY6mh Gh6EqnielU4dcz0Ho51Yng5JazPPiIWqHbA/EiQvyPzKjh+c+NaWZjzfA6XffeZwNJZRvn cGsHnK+TGhN1FzHt4cyF62HJCIHlokHGgqa07A8imVK6kY5bdtdEErPjSUxk0lTiyMvZwg kHR1DIJXAabMZVX4mksvN86FGlGiRfQi4f1EqtWH7evD0FwPlOz31EX4syi6IKLj0WUxQ/ +3xkOPBlEEj+bgzm18F0jdJCAMUn+dg+CUL9qpsSbxljvgRr28/ITciir3PY7g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062288; 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=WBARrxgJ0Fo3O3pXIjgjYSXb/czDjqPuA7NhGPJIs00=; b=EiH4wIJOOX9gXUPVuG+4+zy6hy9FQTz/fYU92XeTosFRTHiKSnOBst+MAfEaLsjuTBN8dH sh5zPjLfVn7Wc8CA== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 31/45] posix-timers: Add a refcount to struct k_itimer References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:08 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965768723786673?= X-GMAIL-MSGID: =?utf-8?q?1767965768723786673?= To cure the SIG_IGN handling for posix interval timers, the preallocated sigqueue needs to be embedded into struct k_itimer to prevent life time races of all sorts. To make this work correctly this needs reference counting so that timer deletion does not free the timer prematuraly when there is a signal queued or delivered concurrently. Add a rcuref to the posix timer part. Signed-off-by: Thomas Gleixner --- include/linux/posix-timers.h | 14 ++++++++++++++ kernel/time/posix-timers.c | 7 ++++--- 2 files changed, 18 insertions(+), 3 deletions(-) --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -6,10 +6,12 @@ #include #include #include +#include #include struct kernel_siginfo; struct task_struct; +struct k_itimer; /* * Bit fields within a clockid: @@ -167,6 +169,7 @@ static inline void posix_cputimers_rt_wa void posixtimer_rearm_itimer(struct task_struct *p); bool posixtimer_deliver_signal(struct kernel_siginfo *info); +void posixtimer_free_timer(struct k_itimer *timer); /* Init task static initializer */ #define INIT_CPU_TIMERBASE(b) { \ @@ -192,6 +195,7 @@ static inline void posix_cputimers_group u64 cpu_limit) { } static inline void posixtimer_rearm_itimer(struct task_struct *p) { } static inline bool posixtimer_deliver_signal(struct kernel_siginfo *info) { return false; } +static inline void posixtimer_free_timer(struct k_itimer *timer) { } #endif #ifdef CONFIG_POSIX_CPU_TIMERS_TASK_WORK @@ -219,6 +223,7 @@ static inline void posix_cputimers_init_ * @it_signal: Pointer to the creators signal struct * @it_pid: The pid of the process/task targeted by the signal * @it_process: The task to wakeup on clock_nanosleep (CPU timers) + * @rcuref: Reference count for life time management * @sigq: Pointer to preallocated sigqueue * @it: Union representing the various posix timer type * internals. @@ -243,6 +248,7 @@ struct k_itimer { struct task_struct *it_process; }; struct sigqueue *sigq; + rcuref_t rcuref; union { struct { struct hrtimer timer; @@ -263,4 +269,12 @@ void set_process_cpu_timer(struct task_s int update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new); +#ifdef CONFIG_POSIX_TIMERS +static inline void posixtimer_putref(struct k_itimer *tmr) +{ + if (rcuref_put(&tmr->rcuref)) + posixtimer_free_timer(tmr); +} +#endif /* !CONFIG_POSIX_TIMERS */ + #endif --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -417,6 +417,7 @@ static struct k_itimer * alloc_posix_tim return NULL; } clear_siginfo(&tmr->sigq->info); + rcuref_init(&tmr->rcuref, 1); return tmr; } @@ -427,7 +428,7 @@ static void k_itimer_rcu_free(struct rcu kmem_cache_free(posix_timers_cache, tmr); } -static void posix_timer_free(struct k_itimer *tmr) +void posixtimer_free_timer(struct k_itimer *tmr) { put_pid(tmr->it_pid); sigqueue_free(tmr->sigq); @@ -439,7 +440,7 @@ static void posix_timer_unhash_and_free( spin_lock(&hash_lock); hlist_del_rcu(&tmr->t_hash); spin_unlock(&hash_lock); - posix_timer_free(tmr); + posixtimer_putref(tmr); } static int common_timer_create(struct k_itimer *new_timer) @@ -474,7 +475,7 @@ static int do_timer_create(clockid_t whi */ new_timer_id = posix_timer_add(new_timer); if (new_timer_id < 0) { - posix_timer_free(new_timer); + posixtimer_free_timer(new_timer); return new_timer_id; } From patchwork Tue Jun 6 14:38:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103895 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3453945vqr; Tue, 6 Jun 2023 07:56:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4U0gbTG7Cxq7dU/kHGMPRpA7//iPFEqpJyAiOKqslx0kLbep23FTIYYgyBKnK83cVDm5r0 X-Received: by 2002:a05:622a:387:b0:3ec:490b:ce6e with SMTP id j7-20020a05622a038700b003ec490bce6emr2644784qtx.48.1686063373049; Tue, 06 Jun 2023 07:56:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063373; cv=none; d=google.com; s=arc-20160816; b=opv70FODbS2IuwwzrEs9j4SgvKMiBY1Jx2ZvGAbfpHlTC0KYhzVYwwrk9Moq7yQ+c2 /9C6xVgfkZyZwJO5BiNBBArqKRsNE7fZidgGNONctwiDZRKKwu3+ahxGmnqWXDpS8tL0 G66Sfd6YYI9xFTog9XmcmWAtGkLRMro7OIPMDFk8y5ra9ATEHm2PhTqeIS5CPFfz1q3s EdK01XVePTsGXshCPY2GKrlQIWntor7zpeCAk7ubrSFd1Whw1qFkEh5ph8pelV+sXHZB wA15OVS1vHMXIvrr4zJEKucZhzy0p5rlO4KE+bM9oROLgq4HgRs/Yyn9kmKqokBmvW+Q EgpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=wHuT7Hr0NdOKLI1EunOgn59lsnWIJRlvleS26aoiaoA=; b=xhD74KO1Iu7gwN4f/WnBuAlIGmIhv7a9QzlbuVUqgtV64vfjQmQq5NgTRHGLb6DmFp 1lfMwWJpnzQLygfgnUV40rX71g0I28xlYo5YEAGY/CUt80tvsWm8uhNGtfK7VLV91jWo vJ1TF2WiGbqziwOEpHqlMvMHfCAMUsMNp/+pyaT1w9YtaSEKgWvl4NU+3sEShL+VTjIj puMwwQqLtUma4RL0BFKvncNMLXzBYtaLjzGK5XAC8OHjHBp8OvmfWucXuNsGUYi1JXnH BBCcPBIg5eILEQafv2B4gcvHMZlJl87iaGeA0zw2CBDevBIlZAA2evuIGDVH4Il+tSnS 4uoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tl52fd+o; dkim=neutral (no key) header.i=@linutronix.de header.b=tKLxhZYk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g1-20020ac87f41000000b003f5398419e0si6385414qtk.373.2023.06.06.07.55.57; Tue, 06 Jun 2023 07:56:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tl52fd+o; dkim=neutral (no key) header.i=@linutronix.de header.b=tKLxhZYk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238295AbjFFOlQ (ORCPT + 99 others); Tue, 6 Jun 2023 10:41:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238454AbjFFOkL (ORCPT ); Tue, 6 Jun 2023 10:40:11 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4FBA2127 for ; Tue, 6 Jun 2023 07:38:54 -0700 (PDT) Message-ID: <20230606142032.826604145@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062290; 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=wHuT7Hr0NdOKLI1EunOgn59lsnWIJRlvleS26aoiaoA=; b=tl52fd+obPeHQXAjdOtL/sLgOTRfX+FOkkGpvpvRPKOjZH6KoaVfGmKYfD/ixurZHJq2aO p9b15raE24WnbUgpqOWt49PpPr4S/Xj91olySxUAnLLT19vCBUZTrzFOy1JsVMM3C0gMCV Kj78hiY2NhIhJNP+6kxOiRArkqZt1Q71wFNmm5TmA/vCbaG9vstMsUjbu9/tNxUa1ULaLJ OPHNxDm+w9CZgFwXjrPDFEpzQ4QoqCZIKzYHfQKCwXaQj2mYwbGIZkhKdgyJ95SWWbFxCI 7mSNxPw0qqixkzC26R8FNCjKgDwECT/6KhlSIuXysweXwKUEKeckVCddnfKK7w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062290; 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=wHuT7Hr0NdOKLI1EunOgn59lsnWIJRlvleS26aoiaoA=; b=tKLxhZYkjMhy1U7P7k4zoE3Aq3+VKrKcHWCwEdcwwhgUinWe88yTvqhy/x4nyfdjb1Q9GJ E1Zgn7CDIDpelQCg== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 32/45] signal: Split up __sigqueue_alloc() References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:09 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965587402927717?= X-GMAIL-MSGID: =?utf-8?q?1767965587402927717?= To cure the SIG_IGN handling for posix interval timers, the preallocated sigqueue needs to be embedded into struct k_itimer to prevent life time races of all sorts. Reorganize __sigqueue_alloc() so the ucounts retrieval and the initialization can be used independently. No functional change. Signed-off-by: Thomas Gleixner --- kernel/signal.c | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -403,16 +403,9 @@ void task_join_group_stop(struct task_st task_set_jobctl_pending(task, mask | JOBCTL_STOP_PENDING); } -/* - * allocate a new signal queue record - * - this may be called without locks if and only if t == current, otherwise an - * appropriate lock must be held to stop the target task from exiting - */ -static struct sigqueue * -__sigqueue_alloc(int sig, struct task_struct *t, gfp_t gfp_flags, - int override_rlimit, const unsigned int sigqueue_flags) +static struct ucounts *sig_get_ucounts(struct task_struct *t, int sig, + int override_rlimit) { - struct sigqueue *q = NULL; struct ucounts *ucounts = NULL; long sigpending; @@ -431,19 +424,44 @@ static struct sigqueue * if (!sigpending) return NULL; - if (override_rlimit || likely(sigpending <= task_rlimit(t, RLIMIT_SIGPENDING))) { - q = kmem_cache_alloc(sigqueue_cachep, gfp_flags); - } else { + if (unlikely(!override_rlimit && sigpending > task_rlimit(t, RLIMIT_SIGPENDING))) { + dec_rlimit_put_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING); print_dropped_signal(sig); + return NULL; } - if (unlikely(q == NULL)) { + return ucounts; +} + +static void __sigqueue_init(struct sigqueue *q, struct ucounts *ucounts, + const unsigned int sigqueue_flags) +{ + INIT_LIST_HEAD(&q->list); + q->flags = sigqueue_flags; + q->ucounts = ucounts; +} + +/* + * allocate a new signal queue record + * - this may be called without locks if and only if t == current, otherwise an + * appropriate lock must be held to stop the target task from exiting + */ +static struct sigqueue *__sigqueue_alloc(int sig, struct task_struct *t, gfp_t gfp_flags, + int override_rlimit, const unsigned int sigqueue_flags) +{ + struct ucounts *ucounts = sig_get_ucounts(t, sig, override_rlimit); + struct sigqueue *q; + + if (!ucounts) + return NULL; + + q = kmem_cache_alloc(sigqueue_cachep, gfp_flags); + if (!q) { dec_rlimit_put_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING); - } else { - INIT_LIST_HEAD(&q->list); - q->flags = sigqueue_flags; - q->ucounts = ucounts; + return NULL; } + + __sigqueue_init(q, ucounts, sigqueue_flags); return q; } From patchwork Tue Jun 6 14:38:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103877 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3449042vqr; Tue, 6 Jun 2023 07:47:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7FtDIqXGtQdpu/qy9ZAsy0QF3lJXMkr80G1hRLctlFemnpPzVxQqp2F15RUoiCEhnMeX2K X-Received: by 2002:a05:6a00:1250:b0:659:7d45:a52c with SMTP id u16-20020a056a00125000b006597d45a52cmr2497009pfi.30.1686062853300; Tue, 06 Jun 2023 07:47:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686062853; cv=none; d=google.com; s=arc-20160816; b=wIUFrf/N4Bnt3skclCI3MablynNulQgfzIdzZwIK+rSCRMEHe049tM3vmsAqgmrPck O0JNFXV3Qyt1QuaPmaUqo08R6JzWLzif8qvXK8HBz3WiYgcShgqSivaIRdW89k4XxVW/ Kkd4O7TR0kHxe5PdmfkqGAheQwtUofZ+2rNzNPUmrNq6n1caczWU7xEBl9Otmv2sSOS8 cEsZu4G/1SCUivUs59SM/yDFa5im5O8W5BrBA3FyzHWC3vX0p+3OFki/+HtoUje7Hj/Z CpVeTHlZGg0t5C7ZcjR9hhMmeVEUljfEuE/+ABW8JqI8TKg3a1uk11wxMW3HiUKg5NCl cbgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=F1AIORQBsb8Q0wbN0ersqX3Q8WiAIjYPdK55avtTgbc=; b=Mkocmb3EDE+d0o79NQeI+r6E3L6vEIM1PTaCFzbAb0O/lATXlk+Q3khupy1aHzXUOi Wd1guLCi+VjEHFerK5KxDoLWsW86P05ioSsyxR/IcYLZ3+SnftauK3ZWdcaamrh8N0L6 oePlJnw1NLH4TXCeGDs4eMM5sAxPCuH2/uMmGPOOOmSA4zMvq8Ylo/brkAbT57+TOyr3 WjE/tJcQW0bhNigZEpm8N8reRt5o5ydd8YdinYpDUBgi5SJjPyTkY5K2uQ5V0EzDvGOT tm5uJGIjapJSXxXC8Ev2sEw47PWkM7RFniz+BgAat63PXc97jc/ji93H2jyrHjv8aVOH mN0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zYwP+c1d; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bs8-20020a632808000000b0053f21272753si7334703pgb.9.2023.06.06.07.47.20; Tue, 06 Jun 2023 07:47:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zYwP+c1d; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238291AbjFFOkc (ORCPT + 99 others); Tue, 6 Jun 2023 10:40:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238231AbjFFOjV (ORCPT ); Tue, 6 Jun 2023 10:39:21 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04A421730 for ; Tue, 6 Jun 2023 07:38:22 -0700 (PDT) Message-ID: <20230606142032.881951490@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062291; 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=F1AIORQBsb8Q0wbN0ersqX3Q8WiAIjYPdK55avtTgbc=; b=zYwP+c1d0TKBY7umwUqJyZjwLRc75LhgtytLBn0aq2G7R+AEjzhXBYIIc0fMDCIezfOwju EfDzX3nUqEs7bEu4nFl8TNqFvnUb3gEV9jdmdsOKAiiVVWG+sjpYC0yoI5AT2EpQrAubF4 8U40jBTqyal18gawuojiioVpDPLa7G1irpHhsrUayCyedCUUitLHCjcz8nO1WV+pKkotKP oUbnNHJNKUMgrt16vS9OHNRm5n67pBjDPk1x9q6KEqWwqdCa8jIK7mMjvtPJDVxYygNgTs hVTBSjN1kruivBXxTnTLJTS7oHHj5Dy3Koz/4kh+tjAUjTPsJKTtE+HlZd2GYw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062291; 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=F1AIORQBsb8Q0wbN0ersqX3Q8WiAIjYPdK55avtTgbc=; b=PXGS/1RDSbPqccGdfDQYlb/tXnCiLRy+k6oowj4ENqJgwDUvgVlmb55JC5BmOLQiKgKG7W PU5cWxeT8xHU+vCQ== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 33/45] signal: Provide posixtimer_sigqueue_init() References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:11 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965042463498003?= X-GMAIL-MSGID: =?utf-8?q?1767965042463498003?= To cure the SIG_IGN handling for posix interval timers, the preallocated sigqueue needs to be embedded into struct k_itimer to prevent life time races of all sorts. Provide a new function to initialize the embedded sigqueue to prepare for that. Signed-off-by: Thomas Gleixner --- include/linux/posix-timers.h | 1 + kernel/signal.c | 11 +++++++++++ 2 files changed, 12 insertions(+) --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -168,6 +168,7 @@ static inline void posix_cputimers_rt_wa } void posixtimer_rearm_itimer(struct task_struct *p); +bool posixtimer_init_sigqueue(struct sigqueue *q); bool posixtimer_deliver_signal(struct kernel_siginfo *info); void posixtimer_free_timer(struct k_itimer *timer); --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1901,6 +1901,17 @@ void flush_itimer_signals(void) spin_unlock_irqrestore(&tsk->sighand->siglock, flags); } +bool posixtimer_init_sigqueue(struct sigqueue *q) +{ + struct ucounts *ucounts = sig_get_ucounts(current, -1, 0); + + if (!ucounts) + return false; + clear_siginfo(&q->info); + __sigqueue_init(q, ucounts, SIGQUEUE_PREALLOC); + return true; +} + struct sigqueue *sigqueue_alloc(void) { return __sigqueue_alloc(-1, current, GFP_KERNEL, 0, SIGQUEUE_PREALLOC); From patchwork Tue Jun 6 14:38:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103942 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3484690vqr; Tue, 6 Jun 2023 08:36:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6lQxlo76RPZlS6155fgR6KOZ3IgAJn5giCSt8177Tb2HTVq8rRRDUenP6OWIB2DPfihfhm X-Received: by 2002:a05:622a:1a1d:b0:3f6:af73:3c59 with SMTP id f29-20020a05622a1a1d00b003f6af733c59mr2274837qtb.58.1686065795110; Tue, 06 Jun 2023 08:36:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686065795; cv=none; d=google.com; s=arc-20160816; b=bFcVgMsdC4rdgAxfXhlvfLtPRVdWGGEgjf8d0jZEbTAHce3zPZp+DGgNHkQnaIUQlL 44xUp4qwI1yFRzYCpW7OSany+nRGqZ2/BLxLj6jcAIlfllboOGqKoC/rb8hErdSY0l7r UzSbuXHAp8KvbsB2VvseJMTW+7UfoaPxCPnTDAFaz35Suq2KXZLSW0+Tc/lgRf/55q6W OAvx+CBXQf7a/jF57QARo7aCa1GWT1cf4h+nPK77OaWwOQWEJsVM1w8QSTRNIbM3Aicr XQrfrr0YZoQBfZNPFjE0U6SYHuvjDhbV3xv8GyfNPSxxZUYfPoabZ1a+XZuIvIPzp30i 8emA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=X5/mGdJCXgY2x3hbkFl+DcjtQwggjg9WtZyekAGVZm8=; b=YBNYt6LFRNrHk9bTNWQxiQWMh5rlBKRSa6HEPOtf91r3UG3wYmT0xnEtx5FkzTPUG1 TOtvBXuaxCsUOjPv4Yhh4swFPThi27qQaIqGtNJdyw0k644STAHFAL7MRay7BmP3uf5F Ci1XNltZdgfGQBDUMHPzrBy/hGOHUANAFcfSn/NgfAKNBssbFJQiCSioEfFsrH7ycHHd SNsS1Sasre9TSHTRYPeMKfYRSWt4Pq2LH6kPb7cvqTn8gepxiPPklzl09BQQJmzG3H7H 6RdsMvqEOaVTGazOMFQ2O5L7hCMQ+O7Zzq+BsZ8m86SckQ+kwW5BBi6u/jz1CQSY7mR9 ly7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ccXf2YoX; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 11-20020ac8594b000000b003f507800686si6454465qtz.623.2023.06.06.08.36.20; Tue, 06 Jun 2023 08:36:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ccXf2YoX; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238304AbjFFOkg (ORCPT + 99 others); Tue, 6 Jun 2023 10:40:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238072AbjFFOjX (ORCPT ); Tue, 6 Jun 2023 10:39:23 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22FF91733 for ; Tue, 6 Jun 2023 07:38:22 -0700 (PDT) Message-ID: <20230606142032.937376270@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062293; 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=X5/mGdJCXgY2x3hbkFl+DcjtQwggjg9WtZyekAGVZm8=; b=ccXf2YoXP6bmaxL+24Dyu26Jc5EOOnCAU1rwP+7LXMT7NQbtNp7ZqfMgccuylPEE0zuJQA TNAeh3IEOxnWArQhCcIkCwzOqXAupwepk/pBSqxzynyZnwyXdq8wUOI8dGHcBkmw/WGtaX 31Zjsh/Ky9/zJpIxwq/2+9AxNR0ZhRMgUwrRGNxBzv+3OtPc6q/vooEleyMWh2QzGNhHWo 1ABi8DAkkAwxPqSo8kS8mUWPcoM1BGVzcn2SFn2eyV2YdqZsYdPjjptknUHkSKEXQAsAAc FbO9C2bl+unpCOF5qvDuxGbl3TG0/3Fdd3eqrwkK8/FkbQqJsswN1HyfD8VWFw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062293; 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=X5/mGdJCXgY2x3hbkFl+DcjtQwggjg9WtZyekAGVZm8=; b=X788qT6ZGfh/f6eNpLqqkZA8SRx6637+/DkoOQMnZ6oUQzeYu5Y1kc3+Q2QeVwqyIknaG3 mBo/xp4ickMo10AA== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 34/45] signal: Add sys_private_ptr to siginfo::_sifields::_timer References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:12 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767968127300377790?= X-GMAIL-MSGID: =?utf-8?q?1767968127300377790?= On signal delivery collect_signal() copies the queued siginfo into a caller provided siginfo struct. The posix timer signal delivery code then uses siginfo::si_tid to lookup the timer in the hash table. That's required today as the timer and the sigqueue are separate entities and have different life time rules. The sigqueue will be embedded into struct k_itimer to address a few issues in the posix timer signal handling, which means the life time rules are not longer separate, which can spare the lookup. Due to locking rules posixtimer_deliver_signal() cannot be invoked from collect_signal(). The timer pointer could be handed down from collect_signal() to dequeue_signal(), but that's just overhead for the non-posixtimer case. There is room in the _sifields union for an extra pointer which will be used later for storing the timer pointer. This field is copied with siginfo and cleared before the info is delivered to userspace like the existing si_sys_private field. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/signal_32.c | 2 +- arch/x86/kernel/signal_64.c | 2 +- include/uapi/asm-generic/siginfo.h | 2 ++ kernel/time/posix-timers.c | 4 +++- 4 files changed, 7 insertions(+), 3 deletions(-) --- a/arch/x86/kernel/signal_32.c +++ b/arch/x86/kernel/signal_32.c @@ -456,7 +456,7 @@ CHECK_SI_OFFSET(_timer); /* compat_siginfo_t doesn't have si_sys_private */ CHECK_SI_SIZE (_timer, 3*sizeof(int)); #else -CHECK_SI_SIZE (_timer, 4*sizeof(int)); +CHECK_SI_SIZE (_timer, 5*sizeof(int)); #endif static_assert(offsetof(siginfo32_t, si_tid) == 0x0C); static_assert(offsetof(siginfo32_t, si_overrun) == 0x10); --- a/arch/x86/kernel/signal_64.c +++ b/arch/x86/kernel/signal_64.c @@ -450,7 +450,7 @@ static_assert(offsetof(siginfo_t, si_pid static_assert(offsetof(siginfo_t, si_uid) == 0x14); CHECK_SI_OFFSET(_timer); -CHECK_SI_SIZE (_timer, 6*sizeof(int)); +CHECK_SI_SIZE (_timer, 8*sizeof(int)); static_assert(offsetof(siginfo_t, si_tid) == 0x10); static_assert(offsetof(siginfo_t, si_overrun) == 0x14); static_assert(offsetof(siginfo_t, si_value) == 0x18); --- a/include/uapi/asm-generic/siginfo.h +++ b/include/uapi/asm-generic/siginfo.h @@ -47,6 +47,7 @@ union __sifields { int _overrun; /* overrun count */ sigval_t _sigval; /* same as below */ int _sys_private; /* not to be passed to user */ + void *_sys_privptr; /* not to be passed to user */ } _timer; /* POSIX.1b signals */ @@ -151,6 +152,7 @@ typedef struct siginfo { #define si_tid _sifields._timer._tid #define si_overrun _sifields._timer._overrun #define si_sys_private _sifields._timer._sys_private +#define si_sys_privptr _sifields._timer._sys_privptr #define si_status _sifields._sigchld._status #define si_utime _sifields._sigchld._utime #define si_stime _sifields._sigchld._stime --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -289,8 +289,9 @@ bool posixtimer_deliver_signal(struct ke out: spin_lock(¤t->sighand->siglock); - /* Don't expose the si_sys_private value to userspace */ + /* Don't expose the si_sys_priv* values to userspace */ info->si_sys_private = 0; + info->si_sys_privptr = NULL; return ret; } @@ -505,6 +506,7 @@ static int do_timer_create(clockid_t whi new_timer->sigq->info.si_tid = new_timer->it_id; new_timer->sigq->info.si_code = SI_TIMER; + new_timer->sigq->info.si_sys_privptr = new_timer; if (copy_to_user(created_timer_id, &new_timer_id, sizeof (new_timer_id))) { error = -EFAULT; From patchwork Tue Jun 6 14:38:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103913 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3465671vqr; Tue, 6 Jun 2023 08:10:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5zqnlTFKHxBI7zWsMSwxLtjv48uWYpcCwD27tOdooYOTc4nuoBOnN2Jlpcg1VgiyaWjlbN X-Received: by 2002:ac8:5c12:0:b0:3f0:a16a:64a0 with SMTP id i18-20020ac85c12000000b003f0a16a64a0mr1916954qti.54.1686064216251; Tue, 06 Jun 2023 08:10:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686064216; cv=none; d=google.com; s=arc-20160816; b=zMHPK7DW9REJXt+8HVR+bWvn/8shgJ2di92CM6JnZeZD3Oe616r2RWZmrgA5ayvyot jiQkZVna/rGEYKqk/6aFSyhzU54kCReREz/RyDsLljRljRnWePvnLnFiNFL8Rm/QpeA6 q0pD8ukv3E+ReuBo+NQ4lkctE2aq5Yur93BDMvm8DXbvlplKF5Ypbreo+D3VsUqguUOM foJLs6GdRnkBB6U5RJaDFGN2xtIUk+I/lSXFp9L+Y0f89NiSFJUsMUW1enjACgNC8o5H a2LfBxZpULOTWl83HxHCr4W+ATy7cm2UTgUQt8kc9sQbLgfHxBmLdP0KBJmVUVahf9JO CMQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=g7l/2zlLif3HG/2XRk0djJlztUlSNJVVihTa+AYF0Ng=; b=wAiHtoJNS0T2QzPOdNlu6EJ1Nn/uy9XEMKA3OwP1+s0pofLtupJyi0Wf7Be5lOW3GU WTmqCTpK8qxl+k6TQUoXGCe+aqBiPOMgcfd4I4G4qFP3t8AJFv21IRBcRoHjCH/lSE32 KajFB9ltcg8yNunjcoMSS7wSic7FT+zVPylr5G/CvICPL+OzDVIkTucJclhWUmitp1Xi U4BvsWaaQDUJEnYrcyTMmMidEwGOaG+jKtH5QEhxFD2da8LL7850L3y2kWQNG6y0A2yJ 07MHElojyJIrK3XYK/nvvMWbm78HvJVEUtAbGeAJEP2VTRTMLdKLmRtISGxxFRvY/LWp fjIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=DY64q94G; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w13-20020a05622a190d00b003f1ad06b40fsi6372860qtc.695.2023.06.06.08.10.00; Tue, 06 Jun 2023 08:10:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=DY64q94G; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238307AbjFFOkj (ORCPT + 99 others); Tue, 6 Jun 2023 10:40:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236184AbjFFOjZ (ORCPT ); Tue, 6 Jun 2023 10:39:25 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 582421984 for ; Tue, 6 Jun 2023 07:38:24 -0700 (PDT) Message-ID: <20230606142032.993368223@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062295; 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=g7l/2zlLif3HG/2XRk0djJlztUlSNJVVihTa+AYF0Ng=; b=DY64q94Gr7wrbcshB8A2DNDl4W2LY5jV7sNZq7ieAT3C9PxCNyFWm+ECQQovXgpGL0ZOGN wNL0y4ypWKpchpDU4O2ePECiJuF4LdD2J4K4sez9VlJGS2zf5+6+pttuejY5WMn0wNRpOy UiFsqOR4a7HuThqyK4RtfeBEx2WEefOZrAVJSlpYze2HK1P2e19fp3SIRImFHRA4nklXjk Dy1ppYjZ6z0QuCftVICJiHoPDBfdGJsPxTM9YFIQ9xn8ITHVyKhrOlZ6XPzang/4143qtQ cz9Qc6jsQhzZ0gGfkhvO0ioNRACcoaGXsguk2ArKi3U4Y71s7jCSs38XW+hdNA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062295; 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=g7l/2zlLif3HG/2XRk0djJlztUlSNJVVihTa+AYF0Ng=; b=kMg9UwkfddSxmVr4V0gVW7txrjdRA9kem0+WWFZ5TPnH/Qv3jMUURv5SkYZZ/a0mg6cnA3 vaYPPloZYtgAMgCA== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 35/45] signal: Refactor send_sigqueue() References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:14 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767966471806005568?= X-GMAIL-MSGID: =?utf-8?q?1767966471806005568?= To handle posix timers which have their signal ignored via SIG_IGN properly its required to requeue a ignored signal for delivery when SIG_IGN is lifted so the timer gets rearmed. Split the required code out of send_sigqueue() so it can be reused in context of sigaction(). While at it rename send_sigqueue() to posixtimer_send_sigqueue() so its clear what this is about. Signed-off-by: Thomas Gleixner --- include/linux/posix-timers.h | 4 ++ include/linux/sched/signal.h | 1 kernel/signal.c | 73 ++++++++++++++++++++++++------------------- kernel/time/posix-timers.c | 10 ++++- 4 files changed, 53 insertions(+), 35 deletions(-) --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -6,11 +6,13 @@ #include #include #include +#include #include #include struct kernel_siginfo; struct task_struct; +struct sigqueue; struct k_itimer; /* @@ -169,6 +171,7 @@ static inline void posix_cputimers_rt_wa void posixtimer_rearm_itimer(struct task_struct *p); bool posixtimer_init_sigqueue(struct sigqueue *q); +int posixtimer_send_sigqueue(struct k_itimer *tmr); bool posixtimer_deliver_signal(struct kernel_siginfo *info); void posixtimer_free_timer(struct k_itimer *timer); @@ -242,6 +245,7 @@ struct k_itimer { s64 it_overrun_last; unsigned int it_signal_seq; int it_sigev_notify; + enum pid_type it_pid_type; ktime_t it_interval; struct signal_struct *it_signal; union { --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -348,7 +348,6 @@ extern int send_sig(int, struct task_str extern int zap_other_threads(struct task_struct *p); extern struct sigqueue *sigqueue_alloc(void); extern void sigqueue_free(struct sigqueue *); -extern int send_sigqueue(struct sigqueue *, struct pid *, enum pid_type, int si_private); extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *); static inline void clear_notify_signal(void) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1943,38 +1943,53 @@ void sigqueue_free(struct sigqueue *q) __sigqueue_free(q); } -int send_sigqueue(struct sigqueue *q, struct pid *pid, enum pid_type type, int si_private) +static void posixtimer_queue_sigqueue(struct sigqueue *q, struct task_struct *t, enum pid_type type) { - int sig = q->info.si_signo; struct sigpending *pending; + int sig = q->info.si_signo; + + signalfd_notify(t, sig); + pending = (type != PIDTYPE_PID) ? &t->signal->shared_pending : &t->pending; + list_add_tail(&q->list, &pending->list); + sigaddset(&pending->signal, sig); + complete_signal(sig, t, type); +} + +/* + * This function is used by POSIX timers to deliver a timer signal. + * Where type is PIDTYPE_PID (such as for timers with SIGEV_THREAD_ID + * set), the signal must be delivered to the specific thread (queues + * into t->pending). + * + * Where type is not PIDTYPE_PID, signals must be delivered to the + * process. In this case, prefer to deliver to current if it is in + * the same thread group as the target process, which avoids + * unnecessarily waking up a potentially idle task. + */ +static inline struct task_struct *posixtimer_get_target(struct k_itimer *tmr) +{ + struct task_struct *t = pid_task(tmr->it_pid, tmr->it_pid_type); + + if (t && tmr->it_pid_type != PIDTYPE_PID && same_thread_group(t, current)) + t = current; + return t; +} + +int posixtimer_send_sigqueue(struct k_itimer *tmr) +{ + struct sigqueue *q = tmr->sigq; + int sig = q->info.si_signo; struct task_struct *t; unsigned long flags; int ret, result; - if (WARN_ON_ONCE(!(q->flags & SIGQUEUE_PREALLOC))) - return 0; - if (WARN_ON_ONCE(q->info.si_code != SI_TIMER)) - return 0; - ret = -1; rcu_read_lock(); - /* - * This function is used by POSIX timers to deliver a timer signal. - * Where type is PIDTYPE_PID (such as for timers with SIGEV_THREAD_ID - * set), the signal must be delivered to the specific thread (queues - * into t->pending). - * - * Where type is not PIDTYPE_PID, signals must be delivered to the - * process. In this case, prefer to deliver to current if it is in - * the same thread group as the target process, which avoids - * unnecessarily waking up a potentially idle task. - */ - t = pid_task(pid, type); + t = posixtimer_get_target(tmr); if (!t) goto ret; - if (type != PIDTYPE_PID && same_thread_group(t, current)) - t = current; + if (!likely(lock_task_sighand(t, &flags))) goto ret; @@ -1984,7 +1999,7 @@ int send_sigqueue(struct sigqueue *q, st * decides based on si_sys_private whether to invoke * posixtimer_rearm() or not. */ - q->info.si_sys_private = si_private; + q->info.si_sys_private = tmr->it_signal_seq; /* * Set the overrun count to zero unconditionally. The posix timer @@ -2015,24 +2030,20 @@ int send_sigqueue(struct sigqueue *q, st q->info.si_overrun = 0; ret = 1; /* the signal is ignored */ - result = TRACE_SIGNAL_IGNORED; - if (!prepare_signal(sig, t, false)) + if (!prepare_signal(sig, t, false)) { + result = TRACE_SIGNAL_IGNORED; goto out; + } ret = 0; if (unlikely(!list_empty(&q->list))) { result = TRACE_SIGNAL_ALREADY_PENDING; goto out; } - - signalfd_notify(t, sig); - pending = (type != PIDTYPE_PID) ? &t->signal->shared_pending : &t->pending; - list_add_tail(&q->list, &pending->list); - sigaddset(&pending->signal, sig); - complete_signal(sig, t, type); + posixtimer_queue_sigqueue(q, t, tmr->it_pid_type); result = TRACE_SIGNAL_DELIVERED; out: - trace_signal_generate(sig, &q->info, t, type != PIDTYPE_PID, result); + trace_signal_generate(sig, &q->info, t, tmr->it_pid_type != PIDTYPE_PID, result); unlock_task_sighand(t, &flags); ret: rcu_read_unlock(); --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -298,7 +298,6 @@ bool posixtimer_deliver_signal(struct ke int posix_timer_queue_signal(struct k_itimer *timr) { enum posix_timer_state state = POSIX_TIMER_DISARMED; - enum pid_type type; int ret; lockdep_assert_held(&timr->it_lock); @@ -309,8 +308,7 @@ int posix_timer_queue_signal(struct k_it } timr->it_status = state; - type = !(timr->it_sigev_notify & SIGEV_THREAD_ID) ? PIDTYPE_TGID : PIDTYPE_PID; - ret = send_sigqueue(timr->sigq, timr->it_pid, type, timr->it_signal_seq); + ret = posixtimer_send_sigqueue(timr); /* If we failed to send the signal the timer stops. */ return ret > 0; } @@ -504,8 +502,14 @@ static int do_timer_create(clockid_t whi new_timer->it_pid = get_pid(task_tgid(current)); } + if (new_timer->it_sigev_notify & SIGEV_THREAD_ID) + new_timer->it_pid_type = PIDTYPE_PID; + else + new_timer->it_pid_type = PIDTYPE_TGID; + new_timer->sigq->info.si_tid = new_timer->it_id; new_timer->sigq->info.si_code = SI_TIMER; + new_timer->sigq->info.si_sys_privptr = new_timer; if (copy_to_user(created_timer_id, &new_timer_id, sizeof (new_timer_id))) { From patchwork Tue Jun 6 14:38:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103948 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3486661vqr; Tue, 6 Jun 2023 08:39:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ62Lxyw+SPizKOEpnHGpYCcq63w5/EHRys3QiEQtcBFQOuV07ymi66+r47yUFt7z2KRB0gX X-Received: by 2002:a05:620a:219a:b0:75b:23a1:832f with SMTP id g26-20020a05620a219a00b0075b23a1832fmr45771qka.42.1686065980200; Tue, 06 Jun 2023 08:39:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686065980; cv=none; d=google.com; s=arc-20160816; b=aocYAjl4RU5qvKEHHfnOJmmaPWWnNaeNG8MXUUnj/cGLo4agsBSulGA9bhMutiC4mA i0VN+ZbV6Sq8dqqidv6LRPd5F3mapxpJm44msjozWzr027PJDgWezWURp5qh8J1BaFQ+ I6v3vAx4acaGDDdfHe3yhDJaVNSnWt9YsBmoiVR88ZZIYZ8NCp0xThiVGrh615KTcXuk id4giHkJRxIlfPa1HBlHrB6anZvi0c2FTMJrwmNPwlUQbiStvfERN6tUsxKVWEH+zE48 so4xke38/nR3LKH8NS5LZ3g+V5dBtV/nVMsougdcJOUiLjTerTBs4ToJmVoCQdg7PB58 jEkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=FbfX95bonQ6QuMNiHBaPdEVKsEDfcrvq6gge8bQAWbs=; b=dRyo9JU7r8XRP3Yz9t6+xUgOuRtwt9duQz8pmZ1Oy8unnEiUHyrWGl/SuoWFtMUNG9 5u/IHphNHi85jVLtj7jkj3u46o2ECGM5bFjaMclHRseuUX7WW54QODQyfd0RkGkbgnFL pTV/UkpEMOpyBZfKkym/j9q21Ken5GPgyS8cB64vCR7Vgt0x6LJr4sqKpsAvxF/cxwaU x1IvP772h+lEXUzwcAjNhhoS5amIWfimXKVwL8Y2xNsTREQwoY2cUOMsoizLKds1VYgr LYo7URtNBor/JgBwUc5t+UKL95O/WGE4DCSvP6nSKx+QDN2vKV/dsYBv6bE/iwSx3xS2 /L9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qlPPi2zJ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=DNdn4sdd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020ae9e10e000000b0074dec37ab8dsi6162259qkm.256.2023.06.06.08.39.25; Tue, 06 Jun 2023 08:39:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qlPPi2zJ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=DNdn4sdd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237672AbjFFOqH (ORCPT + 99 others); Tue, 6 Jun 2023 10:46:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238848AbjFFOpk (ORCPT ); Tue, 6 Jun 2023 10:45:40 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2E131995 for ; Tue, 6 Jun 2023 07:44:26 -0700 (PDT) Message-ID: <20230606142033.048775731@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062296; 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=FbfX95bonQ6QuMNiHBaPdEVKsEDfcrvq6gge8bQAWbs=; b=qlPPi2zJ1gOLSHTvVnbN6QCmF6iqPsLJVhZeEwc5YDBdAyQLMp416H3yJCEezDSZnvKfTX hyooItR3CpENkV5UDazbBwUjcGIya+Az8psFl3glrZ1jrtJtIxB9Fu+6syIbjOr7zpA7Cq nCyxdYVLopIwnxhvUDeaj1RDPM2pYklFAo7yIvc99hkCPLsrNhVrSd7NtieS7Ok1u+CjZu CSp7DrEzYcJVUuFnkWoAZI9Y8pUqfa0gBA/eetCjEa1pmGG3BNUTm9+j7bvY1/at6D2P0G 19k7eLR9TDaZUbhlLcr8uldK+n7Orh+g+8UgByCgFkiVpD1viADjgwwReqXltw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062296; 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=FbfX95bonQ6QuMNiHBaPdEVKsEDfcrvq6gge8bQAWbs=; b=DNdn4sddi0bwxcS7c+BucGdlXd/d1WavXafOwXOJF33YNAMK6P0VbLjtzLhCI5le5LfMMs lzNAd6E0WvZ4bEAg== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 36/45] posix-timers: Embed sigqueue in struct k_itimer References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:16 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767968321267763761?= X-GMAIL-MSGID: =?utf-8?q?1767968321267763761?= To cure the SIG_IGN handling for posix interval timers, the preallocated sigqueue needs to be embedded into struct k_itimer to prevent life time races of all sorts. Now that the prerequisites are in place, embed the sigqueue into struct k_itimer and fixup the relevant usage sites. Aside of preparing for proper SIG_IGN handling, this spares an extra allocation. Signed-off-by: Thomas Gleixner --- fs/proc/base.c | 4 +- include/linux/posix-timers.h | 23 +++++++++++++++- kernel/signal.c | 12 +++++++- kernel/time/posix-timers.c | 59 ++++++++++++++++++++++++++----------------- 4 files changed, 69 insertions(+), 29 deletions(-) --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2501,8 +2501,8 @@ static int show_timer(struct seq_file *m seq_printf(m, "ID: %d\n", timer->it_id); seq_printf(m, "signal: %d/%px\n", - timer->sigq->info.si_signo, - timer->sigq->info.si_value.sival_ptr); + timer->sigq.info.si_signo, + timer->sigq.info.si_value.sival_ptr); seq_printf(m, "notify: %s/%s.%d\n", nstr[notify & ~SIGEV_THREAD_ID], (notify & SIGEV_THREAD_ID) ? "tid" : "pid", --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -63,6 +63,8 @@ static inline int clockid_to_fd(const cl #ifdef CONFIG_POSIX_TIMERS +#include + /** * cpu_timer - Posix CPU timer representation for k_itimer * @node: timerqueue node to queue in the task/sig @@ -228,7 +230,7 @@ static inline void posix_cputimers_init_ * @it_pid: The pid of the process/task targeted by the signal * @it_process: The task to wakeup on clock_nanosleep (CPU timers) * @rcuref: Reference count for life time management - * @sigq: Pointer to preallocated sigqueue + * @sigq: Embedded sigqueue * @it: Union representing the various posix timer type * internals. * @rcu: RCU head for freeing the timer. @@ -252,7 +254,7 @@ struct k_itimer { struct pid *it_pid; struct task_struct *it_process; }; - struct sigqueue *sigq; + struct sigqueue sigq; rcuref_t rcuref; union { struct { @@ -280,6 +282,23 @@ static inline void posixtimer_putref(str if (rcuref_put(&tmr->rcuref)) posixtimer_free_timer(tmr); } + +static inline void posixtimer_sigqueue_getref(struct sigqueue *q) +{ + struct k_itimer *tmr = container_of(q, struct k_itimer, sigq); + + WARN_ON_ONCE(!rcuref_get(&tmr->rcuref)); +} + +static inline void posixtimer_sigqueue_putref(struct sigqueue *q) +{ + struct k_itimer *tmr = container_of(q, struct k_itimer, sigq); + + posixtimer_putref(tmr); +} +#else /* CONFIG_POSIX_TIMERS */ +static inline void posixtimer_sigqueue_getref(struct sigqueue *q) { } +static inline void posixtimer_sigqueue_putref(struct sigqueue *q) { } #endif /* !CONFIG_POSIX_TIMERS */ #endif --- a/kernel/signal.c +++ b/kernel/signal.c @@ -569,7 +569,12 @@ static void collect_signal(int sig, stru still_pending: list_del_init(&first->list); copy_siginfo(info, &first->info); - __sigqueue_free(first); + /* + * Do not drop the reference count for posix timer + * signals. That's done in posix_timer_deliver_signal(). + */ + if (info->si_code != SI_TIMER) + __sigqueue_free(first); } else { /* * Ok, it wasn't in the queue. This must be @@ -1977,7 +1982,7 @@ static inline struct task_struct *posixt int posixtimer_send_sigqueue(struct k_itimer *tmr) { - struct sigqueue *q = tmr->sigq; + struct sigqueue *q = &tmr->sigq; int sig = q->info.si_signo; struct task_struct *t; unsigned long flags; @@ -2037,9 +2042,12 @@ int posixtimer_send_sigqueue(struct k_it ret = 0; if (unlikely(!list_empty(&q->list))) { + /* This holds a reference count already */ result = TRACE_SIGNAL_ALREADY_PENDING; goto out; } + + posixtimer_sigqueue_getref(q); posixtimer_queue_sigqueue(q, t, tmr->it_pid_type); result = TRACE_SIGNAL_DELIVERED; out: --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -251,12 +251,13 @@ static void common_hrtimer_rearm(struct /* * This function is called from the signal delivery code. It decides - * whether the signal should be dropped and rearms interval timers. + * whether the signal should be dropped and rearms interval timers. The + * timer can be unconditionally accessed as there is a reference held on + * it. */ bool posixtimer_deliver_signal(struct kernel_siginfo *info) { - struct k_itimer *timr; - unsigned long flags; + struct k_itimer *timr = info->si_sys_privptr; bool ret = false; /* @@ -264,12 +265,14 @@ bool posixtimer_deliver_signal(struct ke * timr::it_lock. Keep interrupts disabled. */ spin_unlock(¤t->sighand->siglock); + spin_lock(&timr->it_lock); - timr = lock_timer(info->si_tid, &flags); - if (!timr) - goto out; - - if (timr->it_signal_seq != info->si_sys_private) + /* + * Check if the timer is still alive or whether it got modified + * since the signal was queued. In either case, don't rearm and + * drop the signal. + */ + if (!timr->it_signal || timr->it_signal_seq != info->si_sys_private) goto out_unlock; if (timr->it_interval && timr->it_status == POSIX_TIMER_REQUEUE_PENDING) { @@ -285,8 +288,10 @@ bool posixtimer_deliver_signal(struct ke ret = true; out_unlock: - unlock_timer(timr, flags); -out: + spin_unlock(&timr->it_lock); + /* Drop the reference which was acquired when the signal was queued */ + posixtimer_putref(timr); + spin_lock(¤t->sighand->siglock); /* Don't expose the si_sys_priv* values to userspace */ @@ -405,17 +410,17 @@ static struct pid *good_sigevent(sigeven } } -static struct k_itimer * alloc_posix_timer(void) +static struct k_itimer *alloc_posix_timer(void) { struct k_itimer *tmr = kmem_cache_zalloc(posix_timers_cache, GFP_KERNEL); if (!tmr) return tmr; - if (unlikely(!(tmr->sigq = sigqueue_alloc()))) { + + if (unlikely(!posixtimer_init_sigqueue(&tmr->sigq))) { kmem_cache_free(posix_timers_cache, tmr); return NULL; } - clear_siginfo(&tmr->sigq->info); rcuref_init(&tmr->rcuref, 1); return tmr; } @@ -430,7 +435,8 @@ static void k_itimer_rcu_free(struct rcu void posixtimer_free_timer(struct k_itimer *tmr) { put_pid(tmr->it_pid); - sigqueue_free(tmr->sigq); + if (tmr->sigq.ucounts) + dec_rlimit_put_ucounts(tmr->sigq.ucounts, UCOUNT_RLIMIT_SIGPENDING); call_rcu(&tmr->rcu, k_itimer_rcu_free); } @@ -492,13 +498,13 @@ static int do_timer_create(clockid_t whi goto out; } new_timer->it_sigev_notify = event->sigev_notify; - new_timer->sigq->info.si_signo = event->sigev_signo; - new_timer->sigq->info.si_value = event->sigev_value; + new_timer->sigq.info.si_signo = event->sigev_signo; + new_timer->sigq.info.si_value = event->sigev_value; } else { new_timer->it_sigev_notify = SIGEV_SIGNAL; - new_timer->sigq->info.si_signo = SIGALRM; - memset(&new_timer->sigq->info.si_value, 0, sizeof(sigval_t)); - new_timer->sigq->info.si_value.sival_int = new_timer->it_id; + new_timer->sigq.info.si_signo = SIGALRM; + memset(&new_timer->sigq.info.si_value, 0, sizeof(sigval_t)); + new_timer->sigq.info.si_value.sival_int = new_timer->it_id; new_timer->it_pid = get_pid(task_tgid(current)); } @@ -507,10 +513,10 @@ static int do_timer_create(clockid_t whi else new_timer->it_pid_type = PIDTYPE_TGID; - new_timer->sigq->info.si_tid = new_timer->it_id; - new_timer->sigq->info.si_code = SI_TIMER; + new_timer->sigq.info.si_tid = new_timer->it_id; + new_timer->sigq.info.si_code = SI_TIMER; - new_timer->sigq->info.si_sys_privptr = new_timer; + new_timer->sigq.info.si_sys_privptr = new_timer; if (copy_to_user(created_timer_id, &new_timer_id, sizeof (new_timer_id))) { error = -EFAULT; @@ -594,7 +600,14 @@ static struct k_itimer *__lock_timer(tim * 1) Set timr::it_signal to NULL with timr::it_lock held * 2) Release timr::it_lock * 3) Remove from the hash under hash_lock - * 4) Call RCU for removal after the grace period + * 4) Put the reference count. + * + * The reference count might not drop to zero if timr::sigq is + * queued. In that case the signal delivery or flush will put the + * last reference count. + * + * When the reference count reaches zero, the timer is scheduled + * for RCU removal after the grace period. * * Holding rcu_read_lock() accross the lookup ensures that * the timer cannot be freed. From patchwork Tue Jun 6 14:38:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103956 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3490048vqr; Tue, 6 Jun 2023 08:44:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7MPpevH9wQXsPHPXunqfvqfQepriAhwBcYasgUgJ9yJd8kO25EcvNgGbYFgqA+887NSkRn X-Received: by 2002:a05:6214:2388:b0:626:2ce:3c44 with SMTP id fw8-20020a056214238800b0062602ce3c44mr2704228qvb.30.1686066297770; Tue, 06 Jun 2023 08:44:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686066297; cv=none; d=google.com; s=arc-20160816; b=w5QgHZ+CnsCyuiEEee8y0wItHeNqCWl44CsE83BHvMY9NGvZVSTSJnUWqltOpkr13t RCt+t6j8CLVCjlV6leUA+tyh/SvTDL6DHIGmBRuVBXFaRH8iVdne1lCleoUCFhFbWU1W xhUnp9hAL4SKLtKRj1wDAp2u/GRuo3RYgDBzdJQqjwrlsZEn5P1KOg9j33/v/gzvWvFG SMRCKfdsc/xS4AtlNNyJYzAXgi63EiG/c1YpLuBSkPOmg5wXjHij8008nN8MlH1jrZRR NsqYBflegOizZlS84G4bEkgWS4FE5w/T4STzkBhGvOOYsUHeMyZM08F6dw4884MX7CNj aYWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=SKWTs7mKb9Ib3ce5RFjSWFvKB4MXfu0NjoxHJuv9oio=; b=e3bgF6U2GqTDFDeqZseRJs+d9b7xchjW26M9Yr7vAJCfagRwuMd4mvXZjAI9pULBbU VpkDzG45ockBBfO+BJvTBlUBRI4H6r6qMcddkEBvFOgbcyVGEvgH+UIMVxapfanQWKyD xgu+MImSydKwxsFZc6BOy1FgTAkjqzgILfjY10pNUz30+i7IzDb4Xhzl2GuF3f1Wp7hY LfBcNRYRA0uwQZsgp1KuF6R8F6cFrHU5dped3MmZV6zISS+i7Psh2tT2I5zKPJxgMvHR yZCijx9o2u+ltHSFr3gJ6mj+5GBBUpSfKynOrwti4kHj7X8+eAjeIvhcTRlf93vyuH/w rBOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IATYFsnS; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p19-20020a05622a13d300b003f8704f386esi3726756qtk.652.2023.06.06.08.44.42; Tue, 06 Jun 2023 08:44:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IATYFsnS; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238404AbjFFOli (ORCPT + 99 others); Tue, 6 Jun 2023 10:41:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238348AbjFFOkq (ORCPT ); Tue, 6 Jun 2023 10:40:46 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C27301BCB for ; Tue, 6 Jun 2023 07:39:10 -0700 (PDT) Message-ID: <20230606142033.104268005@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062298; 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=SKWTs7mKb9Ib3ce5RFjSWFvKB4MXfu0NjoxHJuv9oio=; b=IATYFsnS0gO/sbdPVKjHqcBUnjyvM8CNZDC17HGay7W1U6Amt/e/X2eEeS/IpQqcqi5FQd fSTsFDp3mMmGe2BSfdTfWrotDoOZrOFzIwWh49VAPLpdJcJnHnYqoWwURvhBVa8hMDCCyu nTaKbRO5vGAX9SwyZRvJSL6UrcJuc5lJCd4jpUspxAqrm9oIxPjsoNUIZd0Lo6cCyT8Cfl 1Ydw0gw83gEeb/zO0h2Vr400N8OpOd01pjzlFLLEcHqZmJauCOddS6Im/3192QkO6N/FYW ngi/62P2zi6/091XQa5xV94bhrG4Dtap26uQmuixdKwlUfh85CpHdiz2lDaMzA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062298; 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=SKWTs7mKb9Ib3ce5RFjSWFvKB4MXfu0NjoxHJuv9oio=; b=mu8ZLkR72aeYjlFHJHr7VBzPy3g6BhNtw2qEPd8eUo696YIlNoe6HtSw1TOW4NS10lyqg9 s1Sc1HgVcuCPAOBg== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 37/45] signal: Cleanup unused posix-timer leftovers References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:17 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767968654297905082?= X-GMAIL-MSGID: =?utf-8?q?1767968654297905082?= Remove the leftovers of sigqueue preallocation as it's not longer used. Signed-off-by: Thomas Gleixner --- include/linux/sched/signal.h | 2 -- kernel/signal.c | 43 +++++++------------------------------------ 2 files changed, 7 insertions(+), 38 deletions(-) --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -346,8 +346,6 @@ extern void force_fatal_sig(int); extern void force_exit_sig(int); extern int send_sig(int, struct task_struct *, int); extern int zap_other_threads(struct task_struct *p); -extern struct sigqueue *sigqueue_alloc(void); -extern void sigqueue_free(struct sigqueue *); extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *); static inline void clear_notify_signal(void) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -446,8 +446,8 @@ static void __sigqueue_init(struct sigqu * - this may be called without locks if and only if t == current, otherwise an * appropriate lock must be held to stop the target task from exiting */ -static struct sigqueue *__sigqueue_alloc(int sig, struct task_struct *t, gfp_t gfp_flags, - int override_rlimit, const unsigned int sigqueue_flags) +static struct sigqueue *sigqueue_alloc(int sig, struct task_struct *t, gfp_t gfp_flags, + int override_rlimit) { struct ucounts *ucounts = sig_get_ucounts(t, sig, override_rlimit); struct sigqueue *q; @@ -461,14 +461,16 @@ static struct sigqueue *__sigqueue_alloc return NULL; } - __sigqueue_init(q, ucounts, sigqueue_flags); + __sigqueue_init(q, ucounts, 0); return q; } static void __sigqueue_free(struct sigqueue *q) { - if (q->flags & SIGQUEUE_PREALLOC) + if (q->flags & SIGQUEUE_PREALLOC) { + posixtimer_sigqueue_putref(q); return; + } if (q->ucounts) { dec_rlimit_put_ucounts(q->ucounts, UCOUNT_RLIMIT_SIGPENDING); q->ucounts = NULL; @@ -1069,7 +1071,7 @@ static int __send_signal_locked(int sig, else override_rlimit = 0; - q = __sigqueue_alloc(sig, t, GFP_ATOMIC, override_rlimit, 0); + q = sigqueue_alloc(sig, t, GFP_ATOMIC, override_rlimit); if (q) { list_add_tail(&q->list, &pending->list); @@ -1917,37 +1919,6 @@ bool posixtimer_init_sigqueue(struct sig return true; } -struct sigqueue *sigqueue_alloc(void) -{ - return __sigqueue_alloc(-1, current, GFP_KERNEL, 0, SIGQUEUE_PREALLOC); -} - -void sigqueue_free(struct sigqueue *q) -{ - spinlock_t *lock = ¤t->sighand->siglock; - unsigned long flags; - - if (WARN_ON_ONCE(!(q->flags & SIGQUEUE_PREALLOC))) - return; - /* - * We must hold ->siglock while testing q->list - * to serialize with collect_signal() or with - * __exit_signal()->flush_sigqueue(). - */ - spin_lock_irqsave(lock, flags); - q->flags &= ~SIGQUEUE_PREALLOC; - /* - * If it is queued it will be freed when dequeued, - * like the "regular" sigqueue. - */ - if (!list_empty(&q->list)) - q = NULL; - spin_unlock_irqrestore(lock, flags); - - if (q) - __sigqueue_free(q); -} - static void posixtimer_queue_sigqueue(struct sigqueue *q, struct task_struct *t, enum pid_type type) { struct sigpending *pending; From patchwork Tue Jun 6 14:38:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103950 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3487885vqr; Tue, 6 Jun 2023 08:41:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ADmMfeWxo/Adz7SqT6pI7vFoPmqmHvr5xKWI9GDRCDktv2Mpy849NHzf1BtHO3VEwJZPu X-Received: by 2002:ac8:5901:0:b0:3f5:279f:c4dd with SMTP id 1-20020ac85901000000b003f5279fc4ddmr2754990qty.64.1686066097447; Tue, 06 Jun 2023 08:41:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686066097; cv=none; d=google.com; s=arc-20160816; b=aHr+X08RQL3ouch/dEJcyKDZwOxESRpztdzec/HajseQi0AJi9Hp9XWWkLM3rNbqw6 NLK2YEVAUe3gN84qNBQLgb/CLYwnG5rq6KUXTicgZjOOd8ItNWjsOuB+eR4jYyrMea7u Wrqo5dZA38JNP8OABlByXVgWC7b+p4T3uo6PNjk3OKYM0bViMRmlp9gJgEMlrA57VPKt J88LQu8n8fVWFS0UIKgp7EsVEnx7Hz+IQNMYHcZvT4Z+Oh/wGA4RM/3w/6f1jApKGGn1 LJ5oGKSM4bE+aZ2MNjd5jTFDv2rkL1YIiPn8jwWjSav1wpYyNynz8yljs8j+nduLpjDQ JqnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=jyhJ/3GMU7sDY6xXeRfAzgG/VNBQy0NUgflCvHfEUKI=; b=VMV7D7a+BAiy8y3bACL5GTBCvyGvaPyCvS3qBZbIDmEn56BEdfY0h+VV+GZ8CjLqPN jLyB3ZD3EhmsSYYC93rnagiuoBHjUOVZQ97uJddKLnS4WFDtbgT9HMRp9N4K/8kruUS1 Sr1PLnTbXqGVnQZ0262b0yGJFJx9was/oQeDmEGQsnSjyYgV/ERLLrR8FWSGMdTK+CL+ xRtsh3ms+o/XctA4j46K8xOo3cXVFi8F2eNfO6SAT5BM9O6pUOdQVRNJ0Xr/b7Ad4fzz ULXh30co7uLK6/LfFMNfe0/17uBfF8/wrNnDS++lW/mYrwc0zCEsXC0K6drUaXueJyjm ZuBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XJilMgHM; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f30-20020a05622a1a1e00b003f6c5812132si3710050qtb.385.2023.06.06.08.41.22; Tue, 06 Jun 2023 08:41:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XJilMgHM; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238410AbjFFOlk (ORCPT + 99 others); Tue, 6 Jun 2023 10:41:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238354AbjFFOk4 (ORCPT ); Tue, 6 Jun 2023 10:40:56 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A80911BD5 for ; Tue, 6 Jun 2023 07:39:11 -0700 (PDT) Message-ID: <20230606142033.172901153@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062299; 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=jyhJ/3GMU7sDY6xXeRfAzgG/VNBQy0NUgflCvHfEUKI=; b=XJilMgHM4dy9cG9v0F6jyIRHdq6ACnil9FvydviHNHu7inyWZ/fx45hSDqAuNz94cKj0vE enpsGWuvD3DGfZjgYaBI9R5lV3TBjwSQBJSg3GiXnc0Vx2kerYmC2qYG9PtBsJpcYQr6Fk Cps1voMigj6U4UKBV49hXW8apAh3Rif3C51aPFhWeWN3QL6VHUFsRqJSDO35WHmrAs/T1B NHOAQPuPSYEhLjGCN5STeqRPp/dMAVHUq4nIFZstODIQzMNo1Tk1UE/XThfM1krMGuMf4h VNCJcelb2WbxdzWdxlwPI0NN+W0g/+bmtFU2GoqPO17U5T50yBUNo+xNRCN58g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062299; 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=jyhJ/3GMU7sDY6xXeRfAzgG/VNBQy0NUgflCvHfEUKI=; b=RLxZMsOTpnVTE7P8NlmT+H5U2JMs2DASwAD18xvfifkr75/k6ysGl+21VdvBYKC+2+U4/e 8OuAtFyJ3UcNJkCw== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 38/45] signal: Add task argument to flush_sigqueue_mask() References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:19 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767968444189104863?= X-GMAIL-MSGID: =?utf-8?q?1767968444189104863?= To prepare for handling posix timer signals on sigaction(SIG_IGN) properly, add a task argument to flush_sigqueue_mask() and fixup all call sites. This argument will be used in a later step to enqueue posix timers on an ignored list, so their signal can be requeued when SIG_IGN is lifted later on. Signed-off-by: Thomas Gleixner --- kernel/signal.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -727,11 +727,10 @@ void signal_wake_up_state(struct task_st /* * Remove signals in mask from the pending set and queue. - * Returns 1 if any signals were found. * * All callers must be holding the siglock. */ -static void flush_sigqueue_mask(sigset_t *mask, struct sigpending *s) +static void flush_sigqueue_mask(sigset_t *mask, struct sigpending *s, struct task_struct *ptmr_tsk) { struct sigqueue *q, *n; sigset_t m; @@ -869,18 +868,18 @@ static bool prepare_signal(int sig, stru * This is a stop signal. Remove SIGCONT from all queues. */ siginitset(&flush, sigmask(SIGCONT)); - flush_sigqueue_mask(&flush, &signal->shared_pending); + flush_sigqueue_mask(&flush, &signal->shared_pending, NULL); for_each_thread(p, t) - flush_sigqueue_mask(&flush, &t->pending); + flush_sigqueue_mask(&flush, &t->pending, NULL); } else if (sig == SIGCONT) { unsigned int why; /* * Remove all stop signals from all queues, wake all threads. */ siginitset(&flush, SIG_KERNEL_STOP_MASK); - flush_sigqueue_mask(&flush, &signal->shared_pending); + flush_sigqueue_mask(&flush, &signal->shared_pending, NULL); for_each_thread(p, t) { - flush_sigqueue_mask(&flush, &t->pending); + flush_sigqueue_mask(&flush, &t->pending, NULL); task_clear_jobctl_pending(t, JOBCTL_STOP_PENDING); if (likely(!(t->ptrace & PT_SEIZED))) { t->jobctl &= ~JOBCTL_STOPPED; @@ -4097,8 +4096,8 @@ void kernel_sigaction(int sig, __sighand sigemptyset(&mask); sigaddset(&mask, sig); - flush_sigqueue_mask(&mask, ¤t->signal->shared_pending); - flush_sigqueue_mask(&mask, ¤t->pending); + flush_sigqueue_mask(&mask, ¤t->signal->shared_pending, NULL); + flush_sigqueue_mask(&mask, ¤t->pending, NULL); recalc_sigpending(); } spin_unlock_irq(¤t->sighand->siglock); @@ -4165,9 +4164,9 @@ int do_sigaction(int sig, struct k_sigac if (sig_handler_ignored(sig_handler(p, sig), sig)) { sigemptyset(&mask); sigaddset(&mask, sig); - flush_sigqueue_mask(&mask, &p->signal->shared_pending); + flush_sigqueue_mask(&mask, &p->signal->shared_pending, NULL); for_each_thread(p, t) - flush_sigqueue_mask(&mask, &t->pending); + flush_sigqueue_mask(&mask, &t->pending, NULL); } } From patchwork Tue Jun 6 14:38:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103893 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3453784vqr; Tue, 6 Jun 2023 07:55:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ72fsia+WQnw5zrrMhqvM0tM/HFXHW5e6ckugIC+USDBChhuMda0jO3yWbt4ANftzML2M36 X-Received: by 2002:a05:620a:268b:b0:75e:d64d:7011 with SMTP id c11-20020a05620a268b00b0075ed64d7011mr1866272qkp.66.1686063354381; Tue, 06 Jun 2023 07:55:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063354; cv=none; d=google.com; s=arc-20160816; b=IPJcIoF6FP3r8thvO7qqdyVneSY585ES/Gnw6cSLppAcW01hn3FKDG2AfLU51uEnx5 QpekawsdX8S25eoyZ12SNTTrWP1MoMFf2A2nB0rvDGo2lEbTeGicOqrpVT1Ve0YSO4yM 7PX5/oAbNdGvAKJacnSMn4O32G0UTj+vB8bOmOkyvvNCxeakSbcX2e69jAqWvB+YIBUZ wCg4giSgq5sl5r27zhrdzWPnVwqpZKIcJleUutvkTqBIayVjGngbYSgjc5gf9rCZFxaP LYbGVEEZ2pjoG3RMMSrYb/i2UaVKRXsES9aBCWq1GwyQVCWGWut2tWAo0LEP1GKsNRpI DchA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=FIVxxbxY5nm7gn9Zivm/IXjYdCBMNgvVCHW/aP5AbxI=; b=iPe9U/ZckVSDYulUrm45G7a4lnC+4Q3m1RxFH1zQ54PeAxc6RDh8m14YHYIM7xKjpF BZYxPq0qyBdVApp6NuvNGopnksWbSodAx9jE0taiA0nKhWRYjU64OwUNzKAkFrWEmWu5 q+R35RjJKvC0NS5R1cdshjyzb5EhiSJOK9psxM5sfQ+4jPuto2H0Blp3YI1Dem2qxNOa 31icFwg0Hx8IqtdaN8q9lM3RJCgDQFqYJ3Lp9nZh83TLJFBlZbSHYoczGtUXLsdZOSId kiGWQ5PUUeUrR2ME23xepzzeGo6z2AGBT4cDcAO0loY42SKAwejx1vip0fMLQHVY6fR1 Qnng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="G6i/iDvA"; dkim=neutral (no key) header.i=@linutronix.de header.b=Vge8TkXG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h1-20020a37c441000000b0075ec568570dsi1843957qkm.136.2023.06.06.07.55.39; Tue, 06 Jun 2023 07:55:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="G6i/iDvA"; dkim=neutral (no key) header.i=@linutronix.de header.b=Vge8TkXG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238315AbjFFOkp (ORCPT + 99 others); Tue, 6 Jun 2023 10:40:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238254AbjFFOj0 (ORCPT ); Tue, 6 Jun 2023 10:39:26 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D35C91FD8 for ; Tue, 6 Jun 2023 07:38:27 -0700 (PDT) Message-ID: <20230606142033.225765113@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062301; 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=FIVxxbxY5nm7gn9Zivm/IXjYdCBMNgvVCHW/aP5AbxI=; b=G6i/iDvAKRjpnjskrO4KtqHQuYJKJRrXwL2YweYtiuegs0NCLAy6Pb25JWXlFoQwMKyfpR 1nRwTmeynWyQ4FMaNIv5tDh+79wZYFWD31QE57op231XuvU37+E/JZs8aMd/eV4nTWMtrC cSoO1FqNmROB5HyQI6MP98mhXwmjO8W4CM+1W6BrKA3UYPJMrtLf98GHN9i/CxU9IxWhq7 NpTmwR769D1GgHACm2qoDWQrWjBQsOmN7RyHGBe1iTcHqS6nDcVrMAE/mTD+KJ0aspBt5Y 2XRZAzo/z2Wx6OIMcm/j+qk/PEFXZLct23pJPTZac0jmRFxVqXZrd2IHQX5hqA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062301; 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=FIVxxbxY5nm7gn9Zivm/IXjYdCBMNgvVCHW/aP5AbxI=; b=Vge8TkXGkw3jGg0X9UkQfMUAPmd57LOptsE0K6Wi3GYHsXdCwD/sfyqwSZmzU1CooGTGkg R6GpuyzvnFWsO8CA== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 39/45] signal: Provide ignored_posix_timers list References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:20 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965567789071893?= X-GMAIL-MSGID: =?utf-8?q?1767965567789071893?= To prepare for handling posix timer signals on sigaction(SIG_IGN) properly, add a list to task::signal. This list will be used to queue posix timers so their signal can be requeued when SIG_IGN is lifted later. Signed-off-by: Thomas Gleixner --- include/linux/sched/signal.h | 1 + init/init_task.c | 5 +++-- kernel/fork.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -137,6 +137,7 @@ struct signal_struct { /* POSIX.1b Interval Timers */ unsigned int next_posix_timer_id; struct hlist_head posix_timers; + struct hlist_head ignored_posix_timers; /* ITIMER_REAL timer for the process */ struct hrtimer real_timer; --- a/init/init_task.c +++ b/init/init_task.c @@ -28,8 +28,9 @@ static struct signal_struct init_signals .cred_guard_mutex = __MUTEX_INITIALIZER(init_signals.cred_guard_mutex), .exec_update_lock = __RWSEM_INITIALIZER(init_signals.exec_update_lock), #ifdef CONFIG_POSIX_TIMERS - .posix_timers = HLIST_HEAD_INIT, - .cputimer = { + .posix_timers = HLIST_HEAD_INIT, + .ignored_posix_timers = HLIST_HEAD_INIT, + .cputimer = { .cputime_atomic = INIT_CPUTIME_ATOMIC, }, #endif --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1881,6 +1881,7 @@ static int copy_signal(unsigned long clo #ifdef CONFIG_POSIX_TIMERS INIT_HLIST_HEAD(&sig->posix_timers); + INIT_HLIST_HEAD(&sig->ignored_posix_timers); hrtimer_init(&sig->real_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); sig->real_timer.function = it_real_fn; #endif From patchwork Tue Jun 6 14:38:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103875 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3448720vqr; Tue, 6 Jun 2023 07:47:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7mFrFmULDWFsITqkA/RVatCgOYgG1/036WMA0OaFYMAJP6FBKpOjXUET3iPRggXnENMTr1 X-Received: by 2002:a05:6358:c530:b0:123:961:4635 with SMTP id fb48-20020a056358c53000b0012309614635mr3299604rwb.6.1686062823892; Tue, 06 Jun 2023 07:47:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686062823; cv=none; d=google.com; s=arc-20160816; b=TVTzv/WZXcRQyRG6Ugq+c8U3p+EvGcKB2TKYERFKnWcGJcDNkBwL+Egvwq/DscpnDv cMUZaKaUTXXfNtZD9RBnqbtKqqpcsTJW5BAOtnCmg7hUPhS5OzpH3fMf7Ar+TQ3YCjMj LE8JjVLPVFU9ZHv5DQdVXqTw4fbNqH0q0/Gki0tuflWTECCLg0bI0sBd+jCT72GR9KTX vJFj0dkCLz/dUknaXNCYGqnPaW7cVgkt5zkLDM2khGwq84wrQG3J9qro/WfQTCRCZudQ qp7qJugPfl1FTPP6X/bcUK8cwG0xplQf2fwGrPZB1LYUbyfw9sSSUstvYnksjT+u6MAF HOLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=Uv3+NRg/Kf1yCAL/nMP1t/I/1XH205FZqRDMC4g6F7E=; b=FSrz4n0eUt+0ohsv1/a08broQrqJEIw6afnVmg6Zi/OyMRM7Z3YwKDrHctQSajAfxA wN2JOpcnYZP1Aaqqr1gAZg2axRH3B41uL+WJcc3eXlidVVsKp0dmNrwNuE65I1Uqq2Gu ENnKzZqTSsiScw7BzkLcLgOnLxz92Zmm5nthXtjXEByNa/HFhe51gXym+zELTtMiH9aq sG6j2tM33m9oSIFLY3u8XZzq20sP5pvkl/U0iibkx+UFfJW4gDA6PCeHphQIVhEO/hdg SSSmjZJKs0MNd8bdaUOTRGs9fbVUHJ+T217xfo10p/4/n8SgBnoFr0+2EHxGZbDrruVv I8qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Nt7Cp8ck; dkim=neutral (no key) header.i=@linutronix.de header.b=rSKcKGs6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c4-20020a637244000000b005304a8af2adsi7171626pgn.392.2023.06.06.07.46.51; Tue, 06 Jun 2023 07:47:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Nt7Cp8ck; dkim=neutral (no key) header.i=@linutronix.de header.b=rSKcKGs6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238349AbjFFOks (ORCPT + 99 others); Tue, 6 Jun 2023 10:40:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238096AbjFFOj2 (ORCPT ); Tue, 6 Jun 2023 10:39:28 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5535B1FDE for ; Tue, 6 Jun 2023 07:38:29 -0700 (PDT) Message-ID: <20230606142033.278111872@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062302; 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=Uv3+NRg/Kf1yCAL/nMP1t/I/1XH205FZqRDMC4g6F7E=; b=Nt7Cp8cks3GA6mTuqXJmwXQsjXCEORcSPqUYS7EZkdTdEUAPwg6tMSXVbab6r4bownb+1I xOvqJUeBBA+eRMtdMWauNtYTmPrcXPFSOBSD5WCeWES6yZyG6gS8CyGS6zISG0nZaKPl5a VboyMwT5HJHmvVIJQ0FvVydOxhLx1akpwG+Vt0RHyFl3TrI/N4AJx1nsu+jNQ+wYXHhKwd TYlqOpe4ijaMUFlgM3oY+xOBcFX0slYk5iwAT/G7o68wiD4/QS2M7qv+VQ9roAvlx06a5H oe34ahABp5FcXz76n8VG0Ba2Z2F4Bc94vfi4351U9FyyuGPO1FcjxOno9r+XOw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062302; 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=Uv3+NRg/Kf1yCAL/nMP1t/I/1XH205FZqRDMC4g6F7E=; b=rSKcKGs6zOPvDRlV0uIw8qAWPWHuL2cEJvKN1zMRHu51x0sQPhlDha8JpkYs/qCMdMAoLs PjOUop+JBZVpT+DQ== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 40/45] posix-timers: Handle ignored list on delete and exit References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:22 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965011317647976?= X-GMAIL-MSGID: =?utf-8?q?1767965011317647976?= To handle posix timer signals on sigaction(SIG_IGN) properly, the timers will be queued on a separate ignored list. Add the necessary cleanup code for timer_delete() and exit_itimers(). Signed-off-by: Thomas Gleixner --- include/linux/posix-timers.h | 4 +++- kernel/time/posix-timers.c | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -214,7 +214,8 @@ static inline void posix_cputimers_init_ /** * struct k_itimer - POSIX.1b interval timer structure. - * @list: List head for binding the timer to signals->posix_timers + * @list: List node for binding the timer to tsk::signal::posix_timers + * @ignored_list: List node for tracking ignored timers in tsk::signal::ignored_posix_timers * @t_hash: Entry in the posix timer hash table * @it_lock: Lock protecting the timer * @kclock: Pointer to the k_clock struct handling this timer @@ -237,6 +238,7 @@ static inline void posix_cputimers_init_ */ struct k_itimer { struct hlist_node list; + struct hlist_node ignored_list; struct hlist_node t_hash; spinlock_t it_lock; const struct k_clock *kclock; --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -1032,6 +1032,18 @@ int common_timer_del(struct k_itimer *ti return 0; } +/* + * If the deleted timer is on the ignored list, remove it and + * drop the associated reference. + */ +static inline void posix_timer_cleanup_ignored(struct k_itimer *tmr) +{ + if (!hlist_unhashed(&tmr->ignored_list)) { + hlist_del_init(&tmr->ignored_list); + posixtimer_putref(tmr); + } +} + static inline int timer_delete_hook(struct k_itimer *timer) { const struct k_clock *kc = timer->kclock; @@ -1064,6 +1076,7 @@ SYSCALL_DEFINE1(timer_delete, timer_t, t spin_lock(¤t->sighand->siglock); hlist_del(&timer->list); + posix_timer_cleanup_ignored(timer); spin_unlock(¤t->sighand->siglock); /* * A concurrent lookup could check timer::it_signal lockless. It @@ -1115,6 +1128,8 @@ static void itimer_delete(struct k_itime } hlist_del(&timer->list); + posix_timer_cleanup_ignored(timer); + /* * Setting timer::it_signal to NULL is technically not required * here as nothing can access the timer anymore legitimately via @@ -1150,6 +1165,13 @@ void exit_itimers(struct task_struct *ts tmr = hlist_entry(timers.first, struct k_itimer, list); itimer_delete(tmr); } + + /* Mop up timers which are on the ignored list */ + hlist_move_list(&tsk->signal->ignored_posix_timers, &timers); + while (!hlist_empty(&timers)) { + tmr = hlist_entry(timers.first, struct k_itimer, list); + posix_timer_cleanup_ignored(tmr); + } } SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock, From patchwork Tue Jun 6 14:38:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103912 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3465477vqr; Tue, 6 Jun 2023 08:10:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4KHpSZ8lQmBb1HbXt7akG5NeNlOPRAX7YV60NiJCRanbHbQEqjePHeScXXpOVPQuPjjWC8 X-Received: by 2002:a05:620a:6183:b0:75d:8731:4e9f with SMTP id or3-20020a05620a618300b0075d87314e9fmr2259219qkn.69.1686064201953; Tue, 06 Jun 2023 08:10:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686064201; cv=none; d=google.com; s=arc-20160816; b=asR0k5WNMPSL/PZKvGGOkKHE5to1mWCurls8Qk+cfPEjsKRyabMtLRqCZyBmSzWN29 BYr+S+ZREHz/LS6dH1EZdARWp26GEKU8X9l8pcbQYj8FhLWPdwjGyiGLGSQjI27KBgSl k2hf1z521O3V4KNGPBgUAy8wOgKdhZHx7NpThleCmxxRJbB36XDW2ypsZy6+gZdDbB+x Y0EHpPABuA4X8rtBAecsxp0ptdf31DUuCg7wqE4F9tcqH1vyn4Gicz4SkJhfb+rbsOk5 ZN0yY6sECe2voiGmdkI5rftVNvZSLQeQccskhWXp0LmBGoRfkbTZV+IDZ4fXDwH9LGc+ v43A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=fTIz5o5hBoARANmS3u0/FKhZKFc8aKqTiazS/c29bx4=; b=w7aAPE0ZXyWzm8B/l+xkFl/7RRz3IKbUnxci7zQ5j0l0FQDpWz3w3qlMQc8vR7NqH7 sVBaaEKKhIpBx32k8jegFLBAyujx1nrzoILzy/WGFx8NHnbZ5C8T46zHSCe8IUvINSVZ g16F9L2zW4In4TstiajtTO/uaGwIgyK560J2akwA8FA1k7Hehcrn9s4NHUNKkd9Gs8Y+ D2Tu+HPiBtoPcLKZGyb0MCnC4mx2ETyzQfGm2iyyuzC96Rl+Tv9uK33/vthoDMVDIky7 Xkwf5fJnEesbwPjghx2yUTW8U8ZiFRZGm0LLo6Jk7NSnazY37IC5TtIsjX0NDUTscc39 2+eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="OdcnS/g7"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x20-20020ae9e914000000b0075b05e65a32si4030539qkf.528.2023.06.06.08.09.47; Tue, 06 Jun 2023 08:10:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="OdcnS/g7"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238239AbjFFOkx (ORCPT + 99 others); Tue, 6 Jun 2023 10:40:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238295AbjFFOj2 (ORCPT ); Tue, 6 Jun 2023 10:39:28 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 289E9173C for ; Tue, 6 Jun 2023 07:38:30 -0700 (PDT) Message-ID: <20230606142033.330496913@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062304; 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=fTIz5o5hBoARANmS3u0/FKhZKFc8aKqTiazS/c29bx4=; b=OdcnS/g7TLtMK5Roc3vTrxXoq8H3HZqVOPPQe3bOqccGbVUkYJB42PX7X5hlIf783ui1oO JccgdrWqou7YIRWHS6jaj+Soza9KAIEKCVOXbv5iPcjjXuLMrv5RRkFtA6BdCQZWp/WOEE BN0qyQ9T8rtFc/IqQLe/bYDDZA+L5F0HlKgkHnbdhWYKaptYIV8YPYZ7CkfN+GHHhldxhX a3fyCXaTjGPKB/9bX1Dm+Qu1FmJrWuWWyyXMq1lWtM8NtCSvqAaLwv7ZXhwiADF4SMJHEY LKk0XUphu1XFKyePl6h4gqQTocvR8kxW7WRvEgbkAKEbEz2kcwcHW/eL4jVS1A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062304; 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=fTIz5o5hBoARANmS3u0/FKhZKFc8aKqTiazS/c29bx4=; b=s07WC/Jk01SKH8mTDohiDizZp7YjucvjsApqlFfGCLQVuTivaxZ/DQYPyoZW6cg7EVClwN pjnYijYFiVYxaGBQ== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 41/45] signal: Handle ignored signals in do_sigaction(action != SIG_IGN) References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:23 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767966456839667571?= X-GMAIL-MSGID: =?utf-8?q?1767966456839667571?= When a real handler (including SIG_DFL) is installed for a signal, which had previously SIG_IGN set, then the list of ignored posix timers has to be checked for timers which are affected by this change. Add a list walk function which checks for the matching signal number and if found requeues the timers signal, so the timer is rearmed on signal delivery. Rearming the timer right away is not possible because that requires to drop sighand lock. No functional change as the counter part which queues the timers on the ignored list is still missing. Signed-off-by: Thomas Gleixner --- kernel/signal.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2027,7 +2027,55 @@ int posixtimer_send_sigqueue(struct k_it rcu_read_unlock(); return ret; } -#endif /* CONFIG_POSIX_TIMERS */ + +static void posixtimer_sig_unignore(struct task_struct *tsk, int sig) +{ + struct hlist_head *head = &tsk->signal->ignored_posix_timers; + struct hlist_node *tmp; + struct k_itimer *tmr; + + if (likely(hlist_empty(head))) + return; + + /* + * Rearming a timer with sighand lock held is not possible due to + * lock ordering vs. tmr::it_lock. Just stick the sigqueue back and + * let the signal delivery path deal with it whether it needs to be + * rearmed or not. This cannot be decided here w/o dropping sighand + * lock and creating a loop retry horror show. + */ + hlist_for_each_entry_safe(tmr, tmp , head, ignored_list) { + struct task_struct *target; + + /* + * tmr::sigq.info.si_signo is immutable, so accessing it + * without holding tmr::it_lock is safe. + */ + if (tmr->sigq.info.si_signo != sig) + continue; + + hlist_del_init(&tmr->ignored_list); + + /* This should never happen and leaks a reference count */ + if (WARN_ON_ONCE(!list_empty(&tmr->sigq.list))) + continue; + + /* + * Get the target for the signal. If target is a thread and + * has exited by now, drop the reference count. + */ + rcu_read_lock(); + target = posixtimer_get_target(tmr); + if (target) + posixtimer_queue_sigqueue(&tmr->sigq, target, tmr->it_pid_type); + else + posixtimer_putref(tmr); + rcu_read_unlock(); + } +} +#else /* CONFIG_POSIX_TIMERS */ +static inline void posixtimer_sig_unignore(struct task_struct *tsk, int sig) { } +#endif /* !CONFIG_POSIX_TIMERS */ static void do_notify_pidfd(struct task_struct *task) { @@ -4147,6 +4195,8 @@ int do_sigaction(int sig, struct k_sigac sigaction_compat_abi(act, oact); if (act) { + bool was_ignored = k->sa.sa_handler == SIG_IGN; + sigdelsetmask(&act->sa.sa_mask, sigmask(SIGKILL) | sigmask(SIGSTOP)); *k = *act; @@ -4167,6 +4217,8 @@ int do_sigaction(int sig, struct k_sigac flush_sigqueue_mask(&mask, &p->signal->shared_pending, NULL); for_each_thread(p, t) flush_sigqueue_mask(&mask, &t->pending, NULL); + } else if (was_ignored) { + posixtimer_sig_unignore(p, sig); } } From patchwork Tue Jun 6 14:38:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103952 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3489102vqr; Tue, 6 Jun 2023 08:43:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ47Dd9pG8XPYYDZ8fGhXA8j3rypsnlhzZwI8leYL8BO3h8twa6Tu7Oap0rmV3bDYLZ6/FVW X-Received: by 2002:a05:620a:260c:b0:75b:23a1:3667 with SMTP id z12-20020a05620a260c00b0075b23a13667mr70047qko.40.1686066205808; Tue, 06 Jun 2023 08:43:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686066205; cv=none; d=google.com; s=arc-20160816; b=D2MBBvDZDekrzCkJbFAfR/cMAWDX6wxLfjt02S7XpEY1MPv3PNJq2tNtt4hg+GYMXS DtFjndSN11z1hXRwmStud8UeE+Nt5H/JiYTDq9qhmpMDAnI5gHt1ZDU3IeedMZFkIC9b 7ujGkjSCmrgmlw0ZybGt1JnLQv2U3Q1WoNWw1tjGrr8H95y+UeOdTCXHCbrvevSmDKQs nnXjiVyKYNRcz7wKYMo8ufgiZGjU/Kv74r3Y0RxRUXqyLqO115UlQG0Vn8t66b6AaIZx Z+FUaumlBSy67W3RR3zdXlEGU5/EhoRvGFc7sTMaCc7YDVhQ4Z5pDq04gMrsH7HnP+zF pU+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=LYF80Bk8/VFt3/Zfq3hqFvDVFoPNEcj4ORUMtha4AAY=; b=e7QvgnB8DmeL9q00Hlwi6t2Beh5ewljakXSUAB7NP6gMZglmHRyy/U+J/cu3aSvHmU +ijcH0ReB9wz0Bxj83TvGYZ3chIsy1hx2weYR8h5iUqd82fi8ri6H0JhRGNO9chcZyBj IIePISWSMXR6b8HIy3iaHDhdv9WSo5clGJp4rKUrkLy5XeMFq1/7nDpD1Vyy5Tm7+Lr3 +lRWIzrI58oC9puwcxrXoXvoWhE3KBbSbCcj83rFU5y1l/PSeukKZ4w1v4/goQQO4PN9 4N/5ksLQR02UjBstHxWU8PfDWs6es4mDYtZMkg8IG0tpmHnupCWfCplvxcFEULR5Jdr9 X1rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cZacQ8wY; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w20-20020a05620a129400b0074fc1cfb2c9si6022314qki.685.2023.06.06.08.43.11; Tue, 06 Jun 2023 08:43:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cZacQ8wY; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238324AbjFFOk7 (ORCPT + 99 others); Tue, 6 Jun 2023 10:40:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238049AbjFFOj3 (ORCPT ); Tue, 6 Jun 2023 10:39:29 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63DF2173B for ; Tue, 6 Jun 2023 07:38:31 -0700 (PDT) Message-ID: <20230606142033.384181292@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062306; 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=LYF80Bk8/VFt3/Zfq3hqFvDVFoPNEcj4ORUMtha4AAY=; b=cZacQ8wYAB7Fb9DsCdI9e5upBjaTR3/GonogUx1w32o7gnoJL8+oGIBsGZRjWoLL+9KRvV ZF8AjijMZ6myMI0e5MjuVzggO9U6nzZvgkZ4NM5NmQBDDbozZgEm/bzfeQ9yFWJR7n2kp9 DoYdIPD8R/+9CdHtmfpldGwPzv8AdJudlXDytEpOKs1/HM/QvBGZusnYeGZvZGZ92pYiag IyM7pJ/3zaWS/wNloxDpFu1X3UENzr9+5RgPiZ9iJcC7TN4UgfeNEr+j5xFWK8U9QJbpCF X0TEOM1VbVURlL97TkNbqOjr32eMih58SBLQy7kpnwzA4iNKDLcf01PslOTFwg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062306; 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=LYF80Bk8/VFt3/Zfq3hqFvDVFoPNEcj4ORUMtha4AAY=; b=BqlduYM4tBY34xpYtNtBJa2wlNU+kRrBw7+Hr5IfTnIWZ4dF+Q1zbvXE49vkvTgr9KSJwU m4OySW2lELrVxJCQ== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 42/45] signal: Queue ignored posixtimers on ignore list References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:25 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767968557838924104?= X-GMAIL-MSGID: =?utf-8?q?1767968557838924104?= Queue posixtimers which have their signal ignored on the ignored list: 1) When the timer fires and the signal has SIG_IGN set 2) When SIG_IGN is installed via sigaction() and a timer signal is queued This completes the SIG_IGN handling and such timers are not longer self rearmed which avoids pointless wakeups. Signed-off-by: Thomas Gleixner --- kernel/signal.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -725,6 +725,16 @@ void signal_wake_up_state(struct task_st kick_process(t); } +static inline void posixtimer_sig_ignore(struct task_struct *tsk, struct sigqueue *q); + +static void sigqueue_free_ignored(struct task_struct *ptmr_tsk, struct sigqueue *q) +{ + if (likely(!ptmr_tsk || q->info.si_code != SI_TIMER)) + __sigqueue_free(q); + else + posixtimer_sig_ignore(ptmr_tsk, q); +} + /* * Remove signals in mask from the pending set and queue. * @@ -743,7 +753,7 @@ static void flush_sigqueue_mask(sigset_t list_for_each_entry_safe(q, n, &s->list, list) { if (sigismember(mask, q->info.si_signo)) { list_del_init(&q->list); - __sigqueue_free(q); + sigqueue_free_ignored(ptmr_tsk, q); } } } @@ -1956,9 +1966,8 @@ int posixtimer_send_sigqueue(struct k_it int sig = q->info.si_signo; struct task_struct *t; unsigned long flags; - int ret, result; + int result; - ret = -1; rcu_read_lock(); t = posixtimer_get_target(tmr); @@ -2004,13 +2013,24 @@ int posixtimer_send_sigqueue(struct k_it */ q->info.si_overrun = 0; - ret = 1; /* the signal is ignored */ if (!prepare_signal(sig, t, false)) { result = TRACE_SIGNAL_IGNORED; + + /* Paranoia check. Try to survive. */ + if (WARN_ON_ONCE(!list_empty(&q->list))) + goto out; + + if (hlist_unhashed(&tmr->ignored_list)) { + hlist_add_head(&tmr->ignored_list, &t->signal->ignored_posix_timers); + posixtimer_sigqueue_getref(q); + } goto out; } - ret = 0; + /* This should never happen and leaks a reference count */ + if (WARN_ON_ONCE(!hlist_unhashed(&tmr->ignored_list))) + hlist_del_init(&tmr->ignored_list); + if (unlikely(!list_empty(&q->list))) { /* This holds a reference count already */ result = TRACE_SIGNAL_ALREADY_PENDING; @@ -2025,7 +2045,14 @@ int posixtimer_send_sigqueue(struct k_it unlock_task_sighand(t, &flags); ret: rcu_read_unlock(); - return ret; + return 0; +} + +static inline void posixtimer_sig_ignore(struct task_struct *tsk, struct sigqueue *q) +{ + struct k_itimer *tmr = container_of(q, struct k_itimer, sigq); + + hlist_add_head(&tmr->ignored_list, &tsk->signal->ignored_posix_timers); } static void posixtimer_sig_unignore(struct task_struct *tsk, int sig) @@ -2074,6 +2101,7 @@ static void posixtimer_sig_unignore(stru } } #else /* CONFIG_POSIX_TIMERS */ +static inline void posixtimer_sig_ignore(struct task_struct *tsk, struct sigqueue *q) { } static inline void posixtimer_sig_unignore(struct task_struct *tsk, int sig) { } #endif /* !CONFIG_POSIX_TIMERS */ @@ -4214,9 +4242,9 @@ int do_sigaction(int sig, struct k_sigac if (sig_handler_ignored(sig_handler(p, sig), sig)) { sigemptyset(&mask); sigaddset(&mask, sig); - flush_sigqueue_mask(&mask, &p->signal->shared_pending, NULL); + flush_sigqueue_mask(&mask, &p->signal->shared_pending, p); for_each_thread(p, t) - flush_sigqueue_mask(&mask, &t->pending, NULL); + flush_sigqueue_mask(&mask, &t->pending, p); } else if (was_ignored) { posixtimer_sig_unignore(p, sig); } From patchwork Tue Jun 6 14:38:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103905 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3457504vqr; Tue, 6 Jun 2023 08:01:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5S1CPJxs9cVIVqioodPBQZN4/0AwS/3fiKEJogrOiBzPNU8rdqgA6UInhys8JrloUipE88 X-Received: by 2002:aca:1a0f:0:b0:39a:aca9:a648 with SMTP id a15-20020aca1a0f000000b0039aaca9a648mr1100705oia.32.1686063694371; Tue, 06 Jun 2023 08:01:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063694; cv=none; d=google.com; s=arc-20160816; b=XPkDtBYhdHiCuJJQaRSwIHbGi1M01Bl+hdcDbHZkeW0JIohkhcBIz5bypchKRNeBNw a7E46zcOn7a3S78sSxz53VLjNoNGxpW4PL/P8Y0tbHz5s4xQ17vdGIi+H4IGkOLKleWq NKM2z0kfBvOChzJsHvcsCpuzEBJ87paUECtBvLxO3MGUSP3nRhIdgXu65EbvL0/0OESe f0YJkbvsu/9pd/ESsZvPrNCMuIgrS/Jz5Z2lJ09dsBqEaqadqUDrcbgPtsr4/HqG7Izg cUF9W0qnqgFVflWwJ8OINj20gGKCYtx+2Wl32yu/ef+rEtZvQe+RSTRIl4dQ2p1K2Wpm HU2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=KPCEPHtczWIeEtOKLehO2QvyWfrjwM+++WUquCbpcRw=; b=qTu/1YnowG16jW54q0ZgNhAFgDbLxec8PcfFeGNTaR/jtt8GX922vLa8AYaJnz20bu /LAQz2nCLJC55u71l4WyDoJkiJcsqDHT0XQ+Kclkwp1rYBprg6ZKNBHZygZMP+k1pQX7 Jbn7acpbW32mgflgAS/kxD+4MjWiFzdCCLH/fvmPKISylcOm9QmaLJLpgkHMKjHklxuj MojsIj4uUXTa8iMfDcdsiwEJxbef2Cil7QuPf3HH9uWPKeAy/dmUdX162Eauj96A1etZ 0ANstdXXYneceqlbO8AMVyGHEgEnWEB7jNrmwZjESgUCqeb/CXkC3KSwCk6Wv7Li6ZBv QXTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1zWf1jQq; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 14-20020a05621420ce00b0056eb55b3495si6391071qve.449.2023.06.06.08.01.19; Tue, 06 Jun 2023 08:01:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1zWf1jQq; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238363AbjFFOlF (ORCPT + 99 others); Tue, 6 Jun 2023 10:41:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237988AbjFFOjs (ORCPT ); Tue, 6 Jun 2023 10:39:48 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0158B1989 for ; Tue, 6 Jun 2023 07:38:32 -0700 (PDT) Message-ID: <20230606142033.441203108@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062307; 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=KPCEPHtczWIeEtOKLehO2QvyWfrjwM+++WUquCbpcRw=; b=1zWf1jQqodWBHesc5jNRNFwVphF/JwvuwQna14t8+u4vPvJ3+YuUGqenFpAHOkE110KJZb +c0Jk7dbTnIOEzrtwyWkasQcqR6DhR/TBGvNOZbxKFCr/NVJ9/FPsK9BBXZFIeGY9Vhwou Q9Xfhw+EXIaTMUk+qe0H6JVGBXJN9gA07uPqzWV0Pb59lzilizTGX1eJ7W/XhZ9e3EmqFk +rfDwWAXcw1CeUq17l5hvN6r4kuWk3crCYvLrLHNzuFYfwYTJ9AexjfRmV2oihEGIi9BKr H6xyK3u3D9/YbFLg4ACsEp6DGRR6Dnp8Vrx6q2Kn/4+m13dB9ZITLz4zX5wepw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062307; 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=KPCEPHtczWIeEtOKLehO2QvyWfrjwM+++WUquCbpcRw=; b=O/NQe4Bm1NUZ1jjSQh1sYdCGkranWpGj655TOKUl5yu08KaH+ZGR9ainJvhDQyS9uTH0m0 MHosmz8BK5lJQEAg== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 43/45] posix-timers: Cleanup SIG_IGN workaround leftovers References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:27 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965924028178395?= X-GMAIL-MSGID: =?utf-8?q?1767965924028178395?= Now that ignored posix timer signals are requeued and the timers are rearmed on signal delivery the workaround to keep such timers alive and self rearm them is not longer required. Remove the relevant hacks and the not longer required return values from the related functions. The alarm timer workarounds will be cleaned up in a separate step. Signed-off-by: Thomas Gleixner --- include/linux/posix-timers.h | 2 - kernel/signal.c | 3 - kernel/time/alarmtimer.c | 37 +++--------------------- kernel/time/posix-cpu-timers.c | 18 ++--------- kernel/time/posix-timers.c | 63 +++-------------------------------------- kernel/time/posix-timers.h | 2 - 6 files changed, 18 insertions(+), 107 deletions(-) --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -173,7 +173,7 @@ static inline void posix_cputimers_rt_wa void posixtimer_rearm_itimer(struct task_struct *p); bool posixtimer_init_sigqueue(struct sigqueue *q); -int posixtimer_send_sigqueue(struct k_itimer *tmr); +void posixtimer_send_sigqueue(struct k_itimer *tmr); bool posixtimer_deliver_signal(struct kernel_siginfo *info); void posixtimer_free_timer(struct k_itimer *timer); --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1960,7 +1960,7 @@ static inline struct task_struct *posixt return t; } -int posixtimer_send_sigqueue(struct k_itimer *tmr) +void posixtimer_send_sigqueue(struct k_itimer *tmr) { struct sigqueue *q = &tmr->sigq; int sig = q->info.si_signo; @@ -2045,7 +2045,6 @@ int posixtimer_send_sigqueue(struct k_it unlock_task_sighand(t, &flags); ret: rcu_read_unlock(); - return 0; } static inline void posixtimer_sig_ignore(struct task_struct *tsk, struct sigqueue *q) --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -198,27 +198,16 @@ static enum hrtimer_restart alarmtimer_f struct alarm *alarm = container_of(timer, struct alarm, timer); struct alarm_base *base = &alarm_bases[alarm->type]; unsigned long flags; - int ret = HRTIMER_NORESTART; - int restart = ALARMTIMER_NORESTART; spin_lock_irqsave(&base->lock, flags); alarmtimer_dequeue(base, alarm); spin_unlock_irqrestore(&base->lock, flags); if (alarm->function) - restart = alarm->function(alarm, base->get_ktime()); - - spin_lock_irqsave(&base->lock, flags); - if (restart != ALARMTIMER_NORESTART) { - hrtimer_set_expires(&alarm->timer, alarm->node.expires); - alarmtimer_enqueue(base, alarm); - ret = HRTIMER_RESTART; - } - spin_unlock_irqrestore(&base->lock, flags); + alarm->function(alarm, base->get_ktime()); trace_alarmtimer_fired(alarm, base->get_ktime()); - return ret; - + return HRTIMER_NORESTART; } ktime_t alarm_expires_remaining(const struct alarm *alarm) @@ -556,30 +545,16 @@ static enum alarmtimer_type clock2alarm( * * Return: whether the timer is to be restarted */ -static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm, - ktime_t now) +static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm, ktime_t now) { - struct k_itimer *ptr = container_of(alarm, struct k_itimer, - it.alarm.alarmtimer); - enum alarmtimer_restart result = ALARMTIMER_NORESTART; + struct k_itimer *ptr = container_of(alarm, struct k_itimer, it.alarm.alarmtimer); unsigned long flags; spin_lock_irqsave(&ptr->it_lock, flags); - - if (posix_timer_queue_signal(ptr) && ptr->it_interval) { - /* - * Handle ignored signals and rearm the timer. This will go - * away once we handle ignored signals proper. Ensure that - * small intervals cannot starve the system. - */ - ptr->it_overrun += __alarm_forward_now(alarm, ptr->it_interval, true); - ++ptr->it_signal_seq; - ptr->it_status = POSIX_TIMER_ARMED; - result = ALARMTIMER_RESTART; - } + posix_timer_queue_signal(ptr); spin_unlock_irqrestore(&ptr->it_lock, flags); - return result; + return ALARMTIMER_NORESTART; } /** --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -593,21 +593,11 @@ static void cpu_timer_fire(struct k_itim */ wake_up_process(timer->it_process); cpu_timer_setexpires(ctmr, 0); - } else if (!timer->it_interval) { - /* - * One-shot timer. Clear it as soon as it's fired. - */ + } else { posix_timer_queue_signal(timer); - cpu_timer_setexpires(ctmr, 0); - } else if (posix_timer_queue_signal(timer)) { - /* - * The signal did not get queued because the signal - * was ignored, so we won't get any callback to - * reload the timer. But we need to keep it - * ticking in case the signal is deliverable next time. - */ - posix_cpu_timer_rearm(timer); - ++timer->it_signal_seq; + /* Disable oneshot timers */ + if (!timer->it_interval) + cpu_timer_setexpires(ctmr, 0); } } --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -300,10 +300,9 @@ bool posixtimer_deliver_signal(struct ke return ret; } -int posix_timer_queue_signal(struct k_itimer *timr) +void posix_timer_queue_signal(struct k_itimer *timr) { enum posix_timer_state state = POSIX_TIMER_DISARMED; - int ret; lockdep_assert_held(&timr->it_lock); @@ -313,9 +312,7 @@ int posix_timer_queue_signal(struct k_it } timr->it_status = state; - ret = posixtimer_send_sigqueue(timr); - /* If we failed to send the signal the timer stops. */ - return ret > 0; + posixtimer_send_sigqueue(timr); } /* @@ -328,62 +325,12 @@ int posix_timer_queue_signal(struct k_it static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer) { struct k_itimer *timr = container_of(timer, struct k_itimer, it.real.timer); - enum hrtimer_restart ret = HRTIMER_NORESTART; unsigned long flags; spin_lock_irqsave(&timr->it_lock, flags); - - if (posix_timer_queue_signal(timr)) { - /* - * The signal was not queued due to SIG_IGN. As a - * consequence the timer is not going to be rearmed from - * the signal delivery path. But as a real signal handler - * can be installed later the timer must be rearmed here. - */ - if (timr->it_interval != 0) { - ktime_t now = hrtimer_cb_get_time(timer); - - /* - * FIXME: What we really want, is to stop this - * timer completely and restart it in case the - * SIG_IGN is removed. This is a non trivial - * change to the signal handling code. - * - * For now let timers with an interval less than a - * jiffie expire every jiffie and recheck for a - * valid signal handler. - * - * This avoids interrupt starvation in case of a - * very small interval, which would expire the - * timer immediately again. - * - * Moving now ahead of time by one jiffie tricks - * hrtimer_forward() to expire the timer later, - * while it still maintains the overrun accuracy - * for the price of a slight inconsistency in the - * timer_gettime() case. This is at least better - * than a timer storm. - * - * Only required when high resolution timers are - * enabled as the periodic tick based timers are - * automatically aligned to the next tick. - */ - if (IS_ENABLED(CONFIG_HIGHRES_TIMERS)) { - ktime_t kj = TICK_NSEC; - - if (timr->it_interval < kj) - now = ktime_add(now, kj); - } - - timr->it_overrun += hrtimer_forward(timer, now, timr->it_interval); - ret = HRTIMER_RESTART; - ++timr->it_signal_seq; - timr->it_status = POSIX_TIMER_ARMED; - } - } - - unlock_timer(timr, flags); - return ret; + posix_timer_queue_signal(timr); + spin_unlock_irqrestore(&timr->it_lock, flags); + return HRTIMER_NORESTART; } static struct pid *good_sigevent(sigevent_t * event) --- a/kernel/time/posix-timers.h +++ b/kernel/time/posix-timers.h @@ -42,7 +42,7 @@ extern const struct k_clock clock_proces extern const struct k_clock clock_thread; extern const struct k_clock alarm_clock; -int posix_timer_queue_signal(struct k_itimer *timr); +void posix_timer_queue_signal(struct k_itimer *timr); void common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting); int common_timer_set(struct k_itimer *timr, int flags, From patchwork Tue Jun 6 14:38:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103919 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3468673vqr; Tue, 6 Jun 2023 08:13:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5lyqkEFNlDeqzQGstoTRCYPIzbXTY2cw21Hpot+Qf2I+cRtQTLfyvbbIwxnJe1Mj6lWdED X-Received: by 2002:a05:6214:27e8:b0:623:690c:3ce6 with SMTP id jt8-20020a05621427e800b00623690c3ce6mr2182020qvb.32.1686064439400; Tue, 06 Jun 2023 08:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686064439; cv=none; d=google.com; s=arc-20160816; b=Vlao2cA8iJ6d+ybRiWqeqkQvEV4E9QjDLp5BG5ZU8vFrZkGPbnD7n8lkLyG+wPa415 /1/NyL9yx+tOPBLNowppNoI5MtgRkgkEpMSIJfrDRIfIEWJHn7BvDwM/JzqJNGkF/WD9 gPL7WCEuVds5iVZeaPmCpa5wwZSUygxdkyyiGyJ1Tpmj5eWp9xVx9rSe3yp5MtHTudbq Pv+vs/Dx220AADjH9mUQyL9tDM2osDtxJNzFoeSSh0L+D+iig0DnihTBUlvoXoCQG9EP DRm1ovr+Fr+l5vDqNu8It31V/dflN0XBMf1RMK5kOHgtwnXJYjdpIODYCaY5bQud8/NL qxXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=QX5B1K8+RZfszOFPTG8OurkUDJXHJzL25+Bw2kwFOks=; b=P8tchiaND7kJdH1nYUQbKBftJJCMd5WiadgBNVXUd6uHHmuUxERcf6pd7tD6UH2gnS P1Pr8BoE8E2+5JR3lT/WDCYsfTdTKkKMD4A7qGOu+vw5Q7ZwTDpCXWnZK0+coxu9Jn6P ALxGt0pt0hx7TE2JhA9NhezzeasXXbn1u18xdjMTT2KlrXPknp6f/cgessZ4TK9ohSGZ 3mzQ61DM6QKYJ5V1Rv3lVH1dlwrpv8Scu6xIOIhaRN+0a/TxEdDWg0RWu5QYhA9US7WR vvjz7cmynJ5DpM2l18/XbasaJZLuhQzggscB1JkF0tVFK2MVMX7Eq4dBHMn6+euWuo0p 6A/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=vOQ16cEy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=20weg5fG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d6-20020a05621421c600b006262b0bde0dsi6637654qvh.403.2023.06.06.08.13.44; Tue, 06 Jun 2023 08:13:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=vOQ16cEy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=20weg5fG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238369AbjFFOlH (ORCPT + 99 others); Tue, 6 Jun 2023 10:41:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238322AbjFFOjw (ORCPT ); Tue, 6 Jun 2023 10:39:52 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE90C1996 for ; Tue, 6 Jun 2023 07:38:35 -0700 (PDT) Message-ID: <20230606142033.497103352@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062309; 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=QX5B1K8+RZfszOFPTG8OurkUDJXHJzL25+Bw2kwFOks=; b=vOQ16cEyHNDbLUGFYruJwYjN4q7pIkx1YIMSNjLezUFntAY4NfLKrNSAzGYShK+1bxxWsj JdTJO0LI62p7/tTNapErdK+exa61vb0ceeby4gZNozm6CemlpY0qk0sD2sT7M+FiQU2Mgm NbHtaH8AZaVsAQkk0f2bWrwKKme4v0bmelpc59kik23/kxjpHC1p+NgFHzWTUiH6xCoKRj sTr9suQXRMCs1SfNb1Bc6nL3DFVt2lxu4oA/+8uGYxnOxiSrHpvnGEGVvgEpb/QB8QW0kb fOTF+6Avu2+90TgxQBnR0zlbNgBF2TU00pkceF9D6xOU5bS7og20jyHSdMQKVQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062309; 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=QX5B1K8+RZfszOFPTG8OurkUDJXHJzL25+Bw2kwFOks=; b=20weg5fGBIvVECqLe85GEUt4JCXeb060IkO4yfxADrXdfn7vxTPULxdLKN53UFqd5AC16g BcxX0Gy8w4gmKuCA== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 44/45] alarmtimers: Remove the throttle mechanism from alarm_forward_now() References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:28 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767966705577028620?= X-GMAIL-MSGID: =?utf-8?q?1767966705577028620?= Now that ignored posix timer signals are requeued and the timers are rearmed on signal delivery the workaround to keep such timers alive and self rearm them is not longer required. Remove the unused alarm timer parts. Signed-off-by: Thomas Gleixner --- kernel/time/alarmtimer.c | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -458,35 +458,11 @@ u64 alarm_forward(struct alarm *alarm, k } EXPORT_SYMBOL_GPL(alarm_forward); -static u64 __alarm_forward_now(struct alarm *alarm, ktime_t interval, bool throttle) +u64 alarm_forward_now(struct alarm *alarm, ktime_t interval) { struct alarm_base *base = &alarm_bases[alarm->type]; - ktime_t now = base->get_ktime(); - - if (IS_ENABLED(CONFIG_HIGH_RES_TIMERS) && throttle) { - /* - * Same issue as with posix_timer_fn(). Timers which are - * periodic but the signal is ignored can starve the system - * with a very small interval. The real fix which was - * promised in the context of posix_timer_fn() never - * materialized, but someone should really work on it. - * - * To prevent DOS fake @now to be 1 jiffie out which keeps - * the overrun accounting correct but creates an - * inconsistency vs. timer_gettime(2). - */ - ktime_t kj = NSEC_PER_SEC / HZ; - if (interval < kj) - now = ktime_add(now, kj); - } - - return alarm_forward(alarm, now, interval); -} - -u64 alarm_forward_now(struct alarm *alarm, ktime_t interval) -{ - return __alarm_forward_now(alarm, interval, false); + return alarm_forward(alarm, base->get_ktime(), interval); } EXPORT_SYMBOL_GPL(alarm_forward_now); From patchwork Tue Jun 6 14:38:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103898 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3454904vqr; Tue, 6 Jun 2023 07:58:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4f+2QufhJcFDVGXXfEPn6y9EkUUmFlznnf8H7DTaBVdnB2wal/Paq1NAp0x7GqLXNhN6Ng X-Received: by 2002:ac8:7d0c:0:b0:3f6:a92e:7f5e with SMTP id g12-20020ac87d0c000000b003f6a92e7f5emr2863238qtb.40.1686063480001; Tue, 06 Jun 2023 07:58:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063479; cv=none; d=google.com; s=arc-20160816; b=mIcmCSDqbx1Phefm6OhkiU1YfZeB4wpFAucm6h4S+LEMINJPqrENXQAO8SSL6IlZDk kkDJpRJBKkcJ+CP3deubPDplu6cZ4FUpigNCVmMuwpmmZ4NUWYXTgfulurJYhmwzNngw e9C2XHjFHAaGpMm9SNN3F6ceHmge6JbtMQjjhj+hvhyqt6XIFr6SoKbxgw1q4PuZ3PxZ /5+WOFAcC6Su5d5YrqTiLslRIFmZu1OlsLbWj3cTMpi+WsTwCg/9U8GGql8gyo4FCnVo s1y8WgEZdsv6PGWh0dhjJvOmQ5y9P5F9sqvvYEs4ljxSh9tiAi73hbL2D4qzY7b9iBjV JPuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=nJRKWItHXWzejPb3W+5S3exZgj7E4NSZUyd430XhqCY=; b=CHM9MEtnKJNPoONaLgLsi3gZ1g5tyIpY8T2gOpKRP3pevwDRKFL+vlGWCu3ls+XNLA p3+DQ52FisfqGQwaNW/lmoez42EH8/hBr1V89qNlUnZ9VXxjz2wuWCotWtUZpTET8VKW A4d8ftRDSCRIJQv6YRyxWz/Dqw1cbQ4dgwjkBTR5U7WOVKZnO/abMTk27WsLZGg4/Ys/ bhTg60PCYs3H4nPRoS90h9DSZJHZHsF4XrestVDtT2lKl4k6gZiyKy4GfmUWde6EajrP +XLKbVZn83q59c187CHtX7LO7rnPVnI6Pucit1ZQfKKBR/bpT7zH93On7xy0RcWJvpJM W+7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mrU8sqCr; dkim=neutral (no key) header.i=@linutronix.de header.b=67v7msoL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e15-20020ac8598f000000b003f389d7996esi6473353qte.605.2023.06.06.07.57.45; Tue, 06 Jun 2023 07:57:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mrU8sqCr; dkim=neutral (no key) header.i=@linutronix.de header.b=67v7msoL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238272AbjFFOl7 (ORCPT + 99 others); Tue, 6 Jun 2023 10:41:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238264AbjFFOlb (ORCPT ); Tue, 6 Jun 2023 10:41:31 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82261170F for ; Tue, 6 Jun 2023 07:39:25 -0700 (PDT) Message-ID: <20230606142033.552409135@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062310; 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=nJRKWItHXWzejPb3W+5S3exZgj7E4NSZUyd430XhqCY=; b=mrU8sqCrn+7K5DAa7KyiaclT2cu1WFJxS9ck94DJpJt1eUDVdDcA1fYPWAnyQFamwfS/HC Gpak+zdw939IwtgcWduZb6bqN7FHZhnYejDlNgyWtsFeguHp8ZPl6aaFGD6Y1INMfFRySI ffwbT360ct3HKA2j2EUHzhwadvU1GksVv6JEDhDCN0kcdC4ZhPC63FtKz/R+9sBpwFIv8i hEYOD8SnRFPkDZWM9Yv5WF+SYKbeajRMAVIORQvm13OOe9/qgQN+us2/FhVvNT20N2W8g9 XuMBrwUKbljR5tmWey+T8pNtnzBZg/ythb1eNvAIjc/3gNdjTiahhlt0ll9aHA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062310; 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=nJRKWItHXWzejPb3W+5S3exZgj7E4NSZUyd430XhqCY=; b=67v7msoLNJB90fR2k7RuTb3wOWWZ8Z5Ef9sRYGHJay27sXrmhHV299B+LzdYRMEZ+/2eYW RByXcYSwhRAMa6Aw== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 45/45] alarmtimers: Remove return value from alarm functions References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:38:30 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965699411638656?= X-GMAIL-MSGID: =?utf-8?q?1767965699411638656?= Now that the SIG_IGN problem is solved in the core code, the alarmtimer callbacks do not require a return value anymore. Signed-off-by: Thomas Gleixner --- drivers/power/supply/charger-manager.c | 3 +-- fs/timerfd.c | 4 +--- include/linux/alarmtimer.h | 10 ++-------- kernel/time/alarmtimer.c | 16 +++++----------- net/netfilter/xt_IDLETIMER.c | 4 +--- 5 files changed, 10 insertions(+), 27 deletions(-) --- a/drivers/power/supply/charger-manager.c +++ b/drivers/power/supply/charger-manager.c @@ -1412,10 +1412,9 @@ static inline struct charger_desc *cm_ge return dev_get_platdata(&pdev->dev); } -static enum alarmtimer_restart cm_timer_func(struct alarm *alarm, ktime_t now) +static void cm_timer_func(struct alarm *alarm, ktime_t now) { cm_timer_set = false; - return ALARMTIMER_NORESTART; } static int charger_manager_probe(struct platform_device *pdev) --- a/fs/timerfd.c +++ b/fs/timerfd.c @@ -79,13 +79,11 @@ static enum hrtimer_restart timerfd_tmrp return HRTIMER_NORESTART; } -static enum alarmtimer_restart timerfd_alarmproc(struct alarm *alarm, - ktime_t now) +static void timerfd_alarmproc(struct alarm *alarm, ktime_t now) { struct timerfd_ctx *ctx = container_of(alarm, struct timerfd_ctx, t.alarm); timerfd_triggered(ctx); - return ALARMTIMER_NORESTART; } /* --- a/include/linux/alarmtimer.h +++ b/include/linux/alarmtimer.h @@ -20,12 +20,6 @@ enum alarmtimer_type { ALARM_BOOTTIME_FREEZER, }; -enum alarmtimer_restart { - ALARMTIMER_NORESTART, - ALARMTIMER_RESTART, -}; - - #define ALARMTIMER_STATE_INACTIVE 0x00 #define ALARMTIMER_STATE_ENQUEUED 0x01 @@ -42,14 +36,14 @@ enum alarmtimer_restart { struct alarm { struct timerqueue_node node; struct hrtimer timer; - enum alarmtimer_restart (*function)(struct alarm *, ktime_t now); + void (*function)(struct alarm *, ktime_t now); enum alarmtimer_type type; int state; void *data; }; void alarm_init(struct alarm *alarm, enum alarmtimer_type type, - enum alarmtimer_restart (*function)(struct alarm *, ktime_t)); + void (*function)(struct alarm *, ktime_t)); void alarm_start(struct alarm *alarm, ktime_t start); void alarm_start_relative(struct alarm *alarm, ktime_t start); void alarm_restart(struct alarm *alarm); --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -312,7 +312,7 @@ static int alarmtimer_resume(struct devi static void __alarm_init(struct alarm *alarm, enum alarmtimer_type type, - enum alarmtimer_restart (*function)(struct alarm *, ktime_t)) + void (*function)(struct alarm *, ktime_t)) { timerqueue_init(&alarm->node); alarm->timer.function = alarmtimer_fired; @@ -328,7 +328,7 @@ static void * @function: callback that is run when the alarm fires */ void alarm_init(struct alarm *alarm, enum alarmtimer_type type, - enum alarmtimer_restart (*function)(struct alarm *, ktime_t)) + void (*function)(struct alarm *, ktime_t)) { hrtimer_init(&alarm->timer, alarm_bases[type].base_clockid, HRTIMER_MODE_ABS); @@ -521,7 +521,7 @@ static enum alarmtimer_type clock2alarm( * * Return: whether the timer is to be restarted */ -static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm, ktime_t now) +static void alarm_handle_timer(struct alarm *alarm, ktime_t now) { struct k_itimer *ptr = container_of(alarm, struct k_itimer, it.alarm.alarmtimer); unsigned long flags; @@ -529,8 +529,6 @@ static enum alarmtimer_restart alarm_han spin_lock_irqsave(&ptr->it_lock, flags); posix_timer_queue_signal(ptr); spin_unlock_irqrestore(&ptr->it_lock, flags); - - return ALARMTIMER_NORESTART; } /** @@ -691,18 +689,14 @@ static int alarm_timer_create(struct k_i * @now: time at the timer expiration * * Wakes up the task that set the alarmtimer - * - * Return: ALARMTIMER_NORESTART */ -static enum alarmtimer_restart alarmtimer_nsleep_wakeup(struct alarm *alarm, - ktime_t now) +static void alarmtimer_nsleep_wakeup(struct alarm *alarm, ktime_t now) { struct task_struct *task = (struct task_struct *)alarm->data; alarm->data = NULL; if (task) wake_up_process(task); - return ALARMTIMER_NORESTART; } /** @@ -754,7 +748,7 @@ static int alarmtimer_do_nsleep(struct a static void alarm_init_on_stack(struct alarm *alarm, enum alarmtimer_type type, - enum alarmtimer_restart (*function)(struct alarm *, ktime_t)) + void (*function)(struct alarm *, ktime_t)) { hrtimer_init_on_stack(&alarm->timer, alarm_bases[type].base_clockid, HRTIMER_MODE_ABS); --- a/net/netfilter/xt_IDLETIMER.c +++ b/net/netfilter/xt_IDLETIMER.c @@ -107,14 +107,12 @@ static void idletimer_tg_expired(struct schedule_work(&timer->work); } -static enum alarmtimer_restart idletimer_tg_alarmproc(struct alarm *alarm, - ktime_t now) +static void idletimer_tg_alarmproc(struct alarm *alarm, ktime_t now) { struct idletimer_tg *timer = alarm->data; pr_debug("alarm %s expired\n", timer->attr.attr.name); schedule_work(&timer->work); - return ALARMTIMER_NORESTART; } static int idletimer_check_sysfs_name(const char *name, unsigned int size)