From nobody Thu Feb 12 09:15:49 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E3F0C6FD18 for ; Tue, 25 Apr 2023 18:50:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234389AbjDYSup (ORCPT ); Tue, 25 Apr 2023 14:50:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235011AbjDYSuR (ORCPT ); Tue, 25 Apr 2023 14:50:17 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8981A17A2D for ; Tue, 25 Apr 2023 11:49:36 -0700 (PDT) Message-ID: <20230425183313.777610259@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1682448564; 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=m5Kqsh4JR/w9Cu3b9AUJc4exPQX4NUZsivF0HR7AMXM=; b=nAg/4Ne7AAYygDtnN76h5AZTiIrRn1KYQJcIFl60cNjp7Nn84QDIb1484q8RIgrPnVfXUg N6Ch8MHxSc7DfalJ6QxhZ5meKiAxJj+qaDk2h/4WaGRnMCHDcWFrmnbBqWntU7lEV9uxM4 tP3/mtPlxFeNTeKJ1sd4iJ5QmTt8Dy9IXyx/1XNa3sldpmvKXvCzEAoEJFI/BQy7P/Ew5X Ta73GtL39nmAEp6KJMLYi9G39SUhPVGBN+748tjWi3sP0OK4pEVbJtldPtsZPAg2ttNg+e O2xxliMK+FMdZQhrEhqlnCPE4kLHFkFT5B3ZpgzEv3P78fULEjFMyxEXA7cfuQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1682448564; 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=m5Kqsh4JR/w9Cu3b9AUJc4exPQX4NUZsivF0HR7AMXM=; b=WANxwChzr3gqBMt08n80lCIQi1jCqz/dv9R0coX4NSzLNjRtVZEg2HjqnujVL/DvGGjv9O RgAUfC2+M6KH0WDw== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , Peter Zijlstra , Sebastian Siewior , syzbot+5c54bd3eb218bb595aa9@syzkaller.appspotmail.com, Dmitry Vyukov , Michael Kerrisk Subject: [patch 18/20] posix-timers: Clarify posix_timer_fn() comments References: <20230425181827.219128101@linutronix.de> MIME-Version: 1.0 Date: Tue, 25 Apr 2023 20:49:24 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make the issues vs. SIG_IGN understandable and remove the 15 years old promise that a proper solution is already on the horizon. Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker --- kernel/time/posix-timers.c | 56 +++++++++++++++++++++-------------------= ----- 1 file changed, 27 insertions(+), 29 deletions(-) --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -325,11 +325,11 @@ int posix_timer_event(struct k_itimer *t } =20 /* - * This function gets called when a POSIX.1b interval timer expires. It - * is used as a callback from the kernel internal timer. The - * run_timer_list code ALWAYS calls with interrupts on. - - * This code is for CLOCK_REALTIME* and CLOCK_MONOTONIC* timers. + * This function gets called when a POSIX.1b interval timer expires from + * the HRTIMER soft interrupt with interrupts enabled. + * + * Handles CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_BOOTTIME and CLOCK_TAI + * based timers. */ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer) { @@ -347,9 +347,10 @@ static enum hrtimer_restart posix_timer_ =20 if (posix_timer_event(timr, si_private)) { /* - * signal was not sent because of sig_ignor - * we will not get a call back to restart it AND - * it should be restarted. + * 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 !=3D 0) { ktime_t now =3D hrtimer_cb_get_time(timer); @@ -358,34 +359,31 @@ static enum hrtimer_restart posix_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 which involves sighand locking - * (sigh !), which we don't want to do late in - * the release cycle. + * change to the signal handling code. + * + * For now let timers with an interval less than a + * jiffie expire every jiffie to avoid softirq + * starvation in case of SIG_IGN and a very small + * interval, which would put the timer right back + * on the softirq pending list. Moving now ahead of + * time tricks hrtimer_forward() to expire the + * timer later, while it still maintains the + * overrun accuracy for the price of a slightly + * inconsistency in the timer_gettime() case. This + * is at least better than a starved softirq. * - * For now we just let timers with an interval - * less than a jiffie expire every jiffie to - * avoid softirq starvation in case of SIG_IGN - * and a very small interval, which would put - * the timer right back on the softirq pending - * list. By moving now ahead of time we trick - * hrtimer_forward() to expire the timer - * later, while we still maintain the overrun - * accuracy, but have some inconsistency in - * the timer_gettime() case. This is at least - * better than a starved softirq. A more - * complex fix which solves also another related - * inconsistency is already in the pipeline. + * Only required when high resolution timers are + * enabled as the periodic tick based timers are + * automatically aligned to the next tick. */ -#ifdef CONFIG_HIGH_RES_TIMERS - { + if (IS_ENABLED(CONFIG_HIGHRES_TIMERS)) { ktime_t kj =3D NSEC_PER_SEC / HZ; =20 if (timr->it_interval < kj) now =3D ktime_add(now, kj); } -#endif - timr->it_overrun +=3D hrtimer_forward(timer, now, - timr->it_interval); + + timr->it_overrun +=3D hrtimer_forward(timer, now, timr->it_interval); ret =3D HRTIMER_RESTART; ++timr->it_requeue_pending; timr->it_active =3D 1;