Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp165434rdh; Mon, 18 Dec 2023 15:19:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZoXcZwXYk9HfwmSwN2jVmBVhryz4Wnpht1VQiU/5q7ZtSamw02b3RXvbNmyv8gThVX5hK X-Received: by 2002:a05:622a:1895:b0:425:8ee2:506a with SMTP id v21-20020a05622a189500b004258ee2506amr26631532qtc.15.1702941589333; Mon, 18 Dec 2023 15:19:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702941589; cv=none; d=google.com; s=arc-20160816; b=tnLFn+k/dzJ1HEwnIPLD8KcEFIjoDQ8OY85Y/i+Xgdr86fnp6azNvcUAE2+idqgk9y Y/cZmxDr2UcY5u2DUrh5ITDk2rK2s+TcKDXAjtKdQwAml0lzruA8J/5lYlyoljM4oFOP cVeeKsS+X30wTa9ahN0UFKGxnvLWKzu3sU5vmTT9N1nVK6r16sqtr8X+weiH5kevr40A YEU54B6VnZbj0mlKtJX0UYw4sqIG/GNLYK+vmKLArK0eTkAWnUpOC9KMiCgv8ovdRqUD ArEuUP8mDDK5gqxN7cBgyVhj2v8kGlmGFUg0JlFJ94h/7BGTjdthNhNXSfRD5TsJ1xdS 0ACg== ARC-Message-Signature: i=1; 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=Asl6aLsRmwP2sFFs9YzqrnABpsTWBrhHNnBKAX0bLZk=; fh=xvjKaM6hmtHqnOhs670mkmt5SmfrGcW6BwluoXDWXqs=; b=a4WTVskS0Mk77Hv67uCfxmtIfpbc8zqu3wxKwEqfwI43U/VU3QHKaJmXbJNTWl7kQL cF9kny2EWJfYRWW3y/zIonprZGZlzUYmY+wwWril35SFTUb8jAv2NbGPZvfSSzY+ZxYR 69WcHWISrMlJSNq3inTk3yTOE/4LIEJVe/Jv/y6UItpxPFpTk0mwZiup1oKSdDqWa46c j1B8kJ0xQuiz+AcNBrIzmxoHYrtnaPAadl8ORbxZ7udVIsORNVMS9F/xqjPb3LlqjZO4 cxvElgwX7L4CauufPzZjNomMUX6aavhLMDsgj3tDgRMPRGuWiuewCQVNvZ7cQ3wLu6s6 ExIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i0OedXEp; spf=pass (google.com: domain of linux-kernel+bounces-4476-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4476-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. [147.75.199.223]) by mx.google.com with ESMTPS id z19-20020ac87f93000000b004236fb00c24si26227625qtj.674.2023.12.18.15.19.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 15:19:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4476-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i0OedXEp; spf=pass (google.com: domain of linux-kernel+bounces-4476-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4476-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 A41451C21D35 for ; Mon, 18 Dec 2023 23:19:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2CB2E79941; Mon, 18 Dec 2023 23:19:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i0OedXEp" X-Original-To: linux-kernel@vger.kernel.org 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 1BBC87690D; Mon, 18 Dec 2023 23:19:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DF7EC433C9; Mon, 18 Dec 2023 23:19:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702941566; bh=Jj6CqcZq/pZ6jGPq5AqwOGCyrcsDTwMv9Bv+MG30lpE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i0OedXEpe7TdHAuEUjoZS031nMA8vIi+C1jB4UJK9EyzWV5mDKvo9vEQwWlnsKFlb VJyx6izFRylZqstyJNMQCUmi5pTjUFVDkRvtyVjkH0r2hVK4KzeVOs/u608jbuGsDY ZMGe1pG4kzPypddBqkW9FweztB4mfeP+m9NrGwisBFfWW/gMoSYDcxRTsNGT7+Bqh8 HmLmbVGdpKOmgzg9+5t2CtLlOwuSksH/9RsknFHUtkyHfOhtM2YK0iWwXLx61Cb/s7 bl5hxyARrPV0l9Dtw7ji0RAJN7ewXdITIXOR5JHYAcS7gEdmSWKCRra67QeVO1NyV3 vEUJp6Ll1YXXw== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Boqun Feng , Joel Fernandes , Neeraj Upadhyay , Uladzislau Rezki , Zqiang , rcu , "Paul E . McKenney" , Thomas Gleixner , Peter Zijlstra Subject: [PATCH 1/3] hrtimer: Report offline hrtimer enqueue Date: Tue, 19 Dec 2023 00:19:14 +0100 Message-ID: <20231218231916.11719-2-frederic@kernel.org> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20231218231916.11719-1-frederic@kernel.org> References: <20231218231916.11719-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 The hrtimers migration on CPU-down hotplug process has been moved earlier, before the CPU actually goes to die. This leaves a small window of opportunity to queue an hrtimer in a blind spot, leaving it ignored. For example a practical case has been reported with RCU waking up a SCHED_FIFO task right before the CPUHP_AP_IDLE_DEAD stage, queuing that way a sched/rt timer to the local offline CPU. Make sure such situations never go unnoticed and warn when that happens. Reported-by: Paul E. McKenney Fixes: 5c0930ccaad5 ("hrtimers: Push pending hrtimers away from outgoing CPU earlier") Signed-off-by: Frederic Weisbecker --- include/linux/hrtimer.h | 3 ++- kernel/time/hrtimer.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h index f2044d5a652b..f0204630a443 100644 --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h @@ -219,7 +219,8 @@ struct hrtimer_cpu_base { unsigned int hres_active : 1, in_hrtirq : 1, hang_detected : 1, - softirq_activated : 1; + softirq_activated : 1, + online : 1; #ifdef CONFIG_HIGH_RES_TIMERS unsigned int nr_events; unsigned short nr_retries; diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index 760793998cdd..edb0f821dcea 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1085,6 +1085,7 @@ static int enqueue_hrtimer(struct hrtimer *timer, enum hrtimer_mode mode) { debug_activate(timer, mode); + WARN_ON_ONCE(!base->cpu_base->online); base->cpu_base->active_bases |= 1 << base->index; @@ -2183,6 +2184,7 @@ int hrtimers_prepare_cpu(unsigned int cpu) cpu_base->softirq_next_timer = NULL; cpu_base->expires_next = KTIME_MAX; cpu_base->softirq_expires_next = KTIME_MAX; + cpu_base->online = 1; hrtimer_cpu_base_init_expiry_lock(cpu_base); return 0; } @@ -2250,6 +2252,7 @@ int hrtimers_cpu_dying(unsigned int dying_cpu) smp_call_function_single(ncpu, retrigger_next_event, NULL, 0); raw_spin_unlock(&new_base->lock); + old_base->online = 0; raw_spin_unlock(&old_base->lock); return 0; -- 2.42.1