Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp542236lqt; Mon, 18 Mar 2024 16:08:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU+Fqe0MqtUQS7FoFOIYeWDujDWa8ciuT1nfyU/sUBFhReA8uliV/KrXPXi1mI/mk+xGz0HPlAr/l/7qsjTVSsD7HdewmHSSs/O1JrWAw== X-Google-Smtp-Source: AGHT+IGUM1cxEw5vFKDidrl8m90PbnyNay94vp+G62bWhv3/McCU+9jE+dJQnDB4foqhNE/EiDAl X-Received: by 2002:a05:620a:852:b0:789:fdf5:b4a5 with SMTP id u18-20020a05620a085200b00789fdf5b4a5mr1167616qku.38.1710803296764; Mon, 18 Mar 2024 16:08:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710803296; cv=pass; d=google.com; s=arc-20160816; b=DZzQi90zWVHvpFoQi0UxuNncV/19YR9w5hdQOXNQYJKdVtOVpQ7UL2OtjWwLaR1W6E 2CIFBdlxsLESBlSf/Upu8xc8gy47yJ4GytN7a4ypuPmZMdIZAg2mKnls7juKLgKo6YyM 8d0T90MYOxjSH7GpWlAH0m6/CkIvumukJU2wGTlKL6OIZ+rZPJnwL2rxH/ExxTl5ih9d GC1B7YUUu3Mp3KPNrKlmnfatlQqBVLwqRR1M1y6/0T8O3QnQ3Pz17vTCKqxbPLZ4+bq3 +faeCdTI1ZPRl4IAubgresI0cxdrMO5+O9I6cghYFy1UXVdRr5iekCloX41FpMK447E7 AVEw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Vp2fj/MYBMilLP96pR6H+pUtcsbo8Mpt1Aj+O+LLw6E=; fh=ELhIoUAH1JBQCb7cAB6OS4iXraHmE7PZJmXqxRxHgYo=; b=wuBnpli0RERx8le4yOy/fG8ECMAX9HOyPLNey6cY0PwiQ+7v1iTL+Pd4HwdpuRFedF uIKbVw/67oF9OuvKwi3vQ7/8dTAMqZUzNLsTpeQXa8v1xouSBUEXnTLKkJnWZIdt2ALs u4lfvw+UK0unG0L5o0k1L6QK7jVYqYSzaJRdQGFCb6wGaYpx+6JU5KyNgba7voD6TAwI 0OuQ6H2+NhLd61jwfRSutWfG1AlG2JD7g6e1voM7R9Lhg5IDRwwNIvGAUfhwePE8ulmj nQNEfT3noyiGpsVOIaDJFuigumTrrpRDre1sLWPfLuK+12SiFHtfFtwi9RCpuoYKszEg B8rQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UStO95yQ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-106791-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106791-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id vy26-20020a05620a491a00b00788785480cbsi3825093qkn.784.2024.03.18.16.08.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 16:08:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-106791-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UStO95yQ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-106791-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106791-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2EC901C21705 for ; Mon, 18 Mar 2024 23:08:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 479F35CDEC; Mon, 18 Mar 2024 23:07:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UStO95yQ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6E9F55CDD2 for ; Mon, 18 Mar 2024 23:07:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710803263; cv=none; b=WkD7fq7GF4FcELvu2FVF7koEUIy2kjSE/cerutWb3FomsuRLaUXXd7P/5zKM90wG9IOFjMMoHv8oTEsIMeWrnXQ7IDBbBqXdk5+S5K8zffMZAflVaNNI0N6vwI7YFMbaKOCZOh2SocGE1cJ6Y4HHIMNfigbu3m73nVhGC38E82o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710803263; c=relaxed/simple; bh=UlqDvrWu4RSFciz62KAMjWvFnMF0iPska1bZHtuPE10=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ESpDYitjnCRp0RD5RhY8b1iF55RHJEemBy9OVz46eCMq4EkYXs3rEVt+34ISvtwvbdU6Tw/dvx0qZnL+Bvfi5lF9uR9hzldSUrgRJ3r9MHO0z4iOM4p1sy5x8NVDwe2z4g7ufjl4ejQPapAV47BORyoIKuWIDF6qM3d17Lg/A2Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UStO95yQ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDD4FC433C7; Mon, 18 Mar 2024 23:07:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710803263; bh=UlqDvrWu4RSFciz62KAMjWvFnMF0iPska1bZHtuPE10=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UStO95yQxncL8EQxEj7jQjHfGnqXUvWj55VuGwalJc+F0rneHurLlSBTCvD66afYi v8r/8mHh7OeeoTHx676FxJGR+B5H5u1GhlvaW5IH5WDSUcCXeWwZf218jWBpbaHLcF Czb1/2QPLbGr8dbjNAXt63d2FMWIjewO9PeBHQLn+uDflcK4hMubaiGOUSI3oWB0Br 0cu7DhlFlm3ZIl6rpOcJ3OU5Y3qwpYo4qu7yUJCh8iURaB1Bxt83bz72vHxeu0ZP46 FOABFoRdoTxeAjge/Tqkd9Czl3GnYeMjcvQen5j5DwQTGiOPVGkN1q+xol24T6M3KT f+LBjyQtMXokg== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , "Paul E . McKenney" , Ingo Molnar , Anna-Maria Behnsen Subject: [PATCH 2/2] timers: Fix removed self-IPI on global timer's enqueue in nohz_full Date: Tue, 19 Mar 2024 00:07:29 +0100 Message-ID: <20240318230729.15497-3-frederic@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240318230729.15497-1-frederic@kernel.org> References: <20240318230729.15497-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit While running in nohz_full mode, a task may enqueue a timer while the tick is stopped. However the only places where the timer wheel, alongside the timer migration machinery's decision, may reprogram the next event accordingly with that new timer's expiry are the idle loop or any IRQ tail. However neither the idle task nor an interrupt may run on the CPU if it resumes busy work in userspace for a long while in full dynticks mode. To solve this, the timer enqueue path raises a self-IPI that will re-evaluate the timer wheel on its IRQ tail. This asynchronous solution avoids potential locking inversion. This is supposed to happen both for local and global timers but commit: b2cf7507e186 ("timers: Always queue timers on the local CPU") broke the global timers case with removing the ->is_idle field handling for the global base. As a result, global timers enqueue may go unnoticed in nohz_full. Fix this with restoring the idle tracking of the global timer's base, allowing self-IPIs again on enqueue time. Reported-by: Paul E. McKenney Fixes: b2cf7507e186 ("timers: Always queue timers on the local CPU") Signed-off-by: Frederic Weisbecker --- kernel/time/timer.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index e69e75d3858c..dee29f1f5b75 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -642,7 +642,8 @@ trigger_dyntick_cpu(struct timer_base *base, struct timer_list *timer) * the base lock: */ if (base->is_idle) { - WARN_ON_ONCE(!(timer->flags & TIMER_PINNED)); + WARN_ON_ONCE(!(timer->flags & TIMER_PINNED || + tick_nohz_full_cpu(base->cpu))); wake_up_nohz_cpu(base->cpu); } } @@ -2292,6 +2293,13 @@ static inline u64 __get_next_timer_interrupt(unsigned long basej, u64 basem, */ if (!base_local->is_idle && time_after(nextevt, basej + 1)) { base_local->is_idle = true; + /* + * Global timers queued locally while running in a task + * in nohz_full mode need a self-IPI to kick reprogramming + * in IRQ tail. + */ + if (tick_nohz_full_cpu(base_local->cpu)) + base_global->is_idle = true; trace_timer_base_idle(true, base_local->cpu); } *idle = base_local->is_idle; @@ -2364,6 +2372,8 @@ void timer_clear_idle(void) * path. Required for BASE_LOCAL only. */ __this_cpu_write(timer_bases[BASE_LOCAL].is_idle, false); + if (tick_nohz_full_cpu(smp_processor_id())) + __this_cpu_write(timer_bases[BASE_GLOBAL].is_idle, false); trace_timer_base_idle(false, smp_processor_id()); /* Activate without holding the timer_base->lock */ -- 2.44.0