From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBD32264A9D for ; Wed, 4 Feb 2026 13:58:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770213505; cv=none; b=Alyuib72vVjvvBqMaFTbGg00Rs5Hcnq9U9+/0K4jrc83fNEWx2QA/IL2NVS+hEsC93AXC6p9tl7id5hZFIJYOS3SL6o/2wujarZiJB/BB3WOYerIJM2CdZAJhVvvyRhtCDc7I23+t+UjG/wL4+By4oXnNG+lToFmSU38/ewkB7E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770213505; c=relaxed/simple; bh=NED6ihkuxt53cHfMVzSl/6INvH6CkyiacPJH3CG6Alw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Qnn0kEIhOkcajPom09uJOyghee7flos5Mj0N/ZhA5t5TfM8eddfQTP5eEJG6DqO9XR2XzGr72CKHjHUfaVZyDo/fZRN1aQngXVAY1iR++w4o5VJHMmtY2tRZzlw2rQNqePIyRqEZOg2oaPxN5QnfGzy2lJQ8HkXbdtrXRFQt3qY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=FUmfDN+b; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="FUmfDN+b" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=LXWtY76br226kde4EqTua5VJJDtCbT34vo7/fcRSe+s=; b=FUmfDN+bopO3zU3dc2gDcbPYwW feZ+u07Xg/ngqkfin5YgQQ9jfmjF5LEU92ILDPqvSuZwTDom/prFBisA4koOLr3t3/J8S/Tw3cKYz 5SeizBYBYcyPRYfJbX1jyaOaoToN0DV8D4fMdN1wluhem97hXPOM8Qhoijscx2o7Y2Pvqbh1pBUaE cOp1SvMZSZGuOJ22cQi+RDaOnhTOEoiRLYZF9qfL/sH+5R9bvSrMI6Topc2FxQS3rBNncRcSszM6x x21k/UJZNYzecVz3dKFzQkI+fSuBTAErHpiYB1wbXdy+1VZQ5r7y1FZlUWXV7yX11k8Ju0xDGCOtl LWHs26KA==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vndOZ-00000000cIG-1BGu; Wed, 04 Feb 2026 13:58:15 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 0143B300E8B; Wed, 04 Feb 2026 14:58:14 +0100 (CET) Date: Wed, 4 Feb 2026 14:58:13 +0100 From: Peter Zijlstra To: Thomas Gleixner Cc: arnd@arndb.de, anna-maria@linutronix.de, frederic@kernel.org, luto@kernel.org, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, linux-kernel@vger.kernel.org, oliver.sang@intel.com Subject: Re: [PATCH v2 5/6] entry,hrtimer: Push reprogramming timers into the interrupt return path Message-ID: <20260204135813.GL2995752@noisy.programming.kicks-ass.net> References: <20260121162010.647043073@infradead.org> <20260121162508.011240183@infradead.org> <878qdbfbza.ffs@tglx> <20260202163355.GI1395266@noisy.programming.kicks-ass.net> <87v7ge4tf6.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87v7ge4tf6.ffs@tglx> On Tue, Feb 03, 2026 at 12:28:13AM +0100, Thomas Gleixner wrote: > But looking at this there is already a problem without interrupt > nesting: > > irq_enter_rcu(); > timer_interrupt() > hrtimer_interrupt() > delay_rearm(); > irq_exit_rcu() > __irq_exit_rcu() > invoke_softirq() <- Here > > Soft interrupts can run for quite some time, which means this already > can cause timers being delayed for way too long. I think in > __irq_exit_rcu() you want to do: > > if (!in_interrupt() && local_softirq_pending()) { > hrtimer_rearm(); > invoke_softirq(); > } Right, and we can do the same on (nested) IRQ entry. Something like so: --- --- a/kernel/entry/common.c +++ b/kernel/entry/common.c @@ -63,6 +63,8 @@ static __always_inline unsigned long __e if (ti_work & (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)) { if (!rseq_grant_slice_extension(ti_work & TIF_SLICE_EXT_DENY)) schedule(); + else + hrtimer_rearm(); } if (ti_work & _TIF_UPROBE) --- a/kernel/softirq.c +++ b/kernel/softirq.c @@ -663,6 +663,13 @@ void irq_enter_rcu(void) { __irq_enter_raw(); + /* + * If this is a nested IRQ that hits the exit_to_user_mode_loop + * where it has enabled IRQs but before it has hit schedule() + * we could have hrtimers in an undefined state. Fix it up here. + */ + hrtimer_rearm(); + if (tick_nohz_full_cpu(smp_processor_id()) || (is_idle_task(current) && (irq_count() == HARDIRQ_OFFSET))) tick_irq_enter(); @@ -719,8 +726,14 @@ static inline void __irq_exit_rcu(void) #endif account_hardirq_exit(current); preempt_count_sub(HARDIRQ_OFFSET); - if (!in_interrupt() && local_softirq_pending()) + if (!in_interrupt() && local_softirq_pending()) { + /* + * If we left hrtimers unarmed, make sure to arm them now, + * before enabling interrupts to run SoftIRQ. + */ + hrtimer_rearm(); invoke_softirq(); + } if (IS_ENABLED(CONFIG_IRQ_FORCED_THREADING) && force_irqthreads() && local_timers_pending_force_th() && !(in_nmi() | in_hardirq())) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1279,8 +1279,8 @@ static int __hrtimer_start_range_ns(stru if (timer->is_fuzzy) { /* - * XXX fuzzy implies pinned! not sure how to deal with - * retrigger_next_event() for the !local case. + * Fuzzy requires pinned as the lazy programming only works + * for CPU local timers. */ WARN_ON_ONCE(!(mode & HRTIMER_MODE_PINNED)); /* @@ -1898,7 +1898,7 @@ static __latent_entropy void hrtimer_run /* * Very similar to hrtimer_force_reprogram(), except it deals with - * in_hrirq and hang_detected. + * in_hrtirq and hang_detected. */ static void __hrtimer_rearm(struct hrtimer_cpu_base *cpu_base, ktime_t now, ktime_t expires_next)