From patchwork Tue Feb 6 10:10:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 197299 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1437652dyb; Tue, 6 Feb 2024 02:11:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IEY1TIDmgbKc4FO7RfQTNTlm1eSpdqNie6GWs58K+g3XGbbjYJZmpqMmlzxWq60tXUoTCP1 X-Received: by 2002:ae9:f001:0:b0:785:38e3:ae78 with SMTP id l1-20020ae9f001000000b0078538e3ae78mr1509909qkg.58.1707214266367; Tue, 06 Feb 2024 02:11:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707214266; cv=pass; d=google.com; s=arc-20160816; b=rtJXhNGQy7+y1JtiLMoEydDvzi2fzlBunabLj0EjEeHUE14XvDY6gwkUpfVdFID2sY Jb/aOc+jFJoHR2OdmpbO1MOJjJYmnyf+teqqOLjPYM93tNWli62pJtrg297ScTb46lPC khr5OP9KGP40VQ/7x+1zhNzghHEGRDbk0E1t5zd1gRlp3UyZ0V1pRcjfXM9GKlF/wqNG eVpTKy1WAZh4uArdSq73S28Wd0fI13hJJBlrPcuSE9xKBjw1AnVE8r8+1TYwk5p0FTHG Bn4HB9y9Jh2PMHEaDWONswbG+MwLfywwdM4zJvLwVbZJWa7+11TLRVzRAVa1cZVhxOjK 0CPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=85JFYrajsZCSPLaR70HH1roOmEwxVGyELjZIaTlWZzE=; fh=14G0Ahbzw9VsjDbuXPQkX2K6sQb5Kh1Yh74uQ9ZA52w=; b=wJBLOoPhJrVAh2saVKRWIHdkgmbYUTcPQ49IBtSW7MvyJqLb2HwAnpy/6CXojNkW5A g6RdWn3rH2rPE6dezyaRmpxMH9q0ig8ZHPcg93Z8H3acIof7ToYOQAg7I3DbWFxHZimo 2pKWlmioJFBg4p8M7AOi064B8YkINXsb8bjHCfhOTJNFCy3BNflkgN3QoUwLnIepHwbl vJtBbFCMNiqIL6bK/HsdczSlX4C9rZwSYKokltg/bnwnyAxon7OVwsUwo2DvEJAUfxyU iOsc6vQFpZ9t3lImQ5z1/MgP4JaIj0JMub43cBgHvyuhggl6XYztHKO2/sK0XSGfO8je BeKQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HtH0ojja; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-54656-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54656-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=1; AJvYcCX21oIFjRcnvk4awe8S7OxYk495ErL2J7XvgnvAJkVg6LKc1kqEUKfL5yJzR8jBEKQuZF2IjLofQPtuw+ZB+FofIc+LlQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z34-20020a05620a262200b007855387679bsi2201404qko.122.2024.02.06.02.11.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 02:11:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54656-ouuuleilei=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=@linutronix.de header.s=2020 header.b=HtH0ojja; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-54656-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54656-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 270251C23459 for ; Tue, 6 Feb 2024 10:11:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2EB6812EBE9; Tue, 6 Feb 2024 10:10:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HtH0ojja"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GKEfr1is" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 8B8D912E1C5; Tue, 6 Feb 2024 10:10:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707214227; cv=none; b=KmpWSpMknIMFCpGxLHiy3RtcHBBAx6Ej1Z9ZyQh6ZW02v2XGJYO9nq/YwwsJWWkgnrYUg5JnFZTTNlebuSEyjL7iGmLFY+dO2rkFsq0WUeu5fO6zmuA5qsK2A5t5ra6UxjBXnWuLRuSecEVPid6BY+DjgwXLi+sQc8GI1QdPdbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707214227; c=relaxed/simple; bh=/WH4wHExctajLCka8lPaJbDC+CM3T/biAoLKRWKeI9c=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=clp8MQpCZuBQ9ddiI4PJAWLd62eQjcPsDD41c8/roYSP7TfVgLMWu3CLbqSrnytWAa2mce5+iy3oMC71Fz8pQ//HWJ8qPA3uNr/Rcoh6JhuSQ0ASLg4+VGkiSMgEBcmAom0aDrLyOITj/LPqkfzukyd30CKYgJPxsXa/i6d47Og= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=HtH0ojja; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=GKEfr1is; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Tue, 06 Feb 2024 10:10:22 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707214223; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=85JFYrajsZCSPLaR70HH1roOmEwxVGyELjZIaTlWZzE=; b=HtH0ojjaPgsOapXdl4MFrGz9hNSpBrMRiKHQtUGzcWToQMezt/SjXJXx/xejOMN6Cdoy1A Sasr0nlsy5PhgFy/kjoIE3pfddjwaKVAgmAHu9u2wyB7ycRpI+NM6KAfkUaoojhbxIHo4L btuYjdjyfYCJxkI9CefuVvv8u2lOklMH1qozC/L/HlJZIsZq7wPVsHzLQbzJV4yYOZ2SZl eT7WoaXtkK68hnARc9WV1oB9qYYdpz+MeZ5ar5BQh776Wp0eNuLZ2ag42E+B8K2SqUbqqF +lagKbyd8ehAxAzJlLcrWPJkEaOqVBNyEjN3QkBi9JWgxZdslUmMHHPUMovznQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707214223; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=85JFYrajsZCSPLaR70HH1roOmEwxVGyELjZIaTlWZzE=; b=GKEfr1isn26zmy7+wqvheQ9ouEgknT3tUwr6cr0khC1Ajczz7oTYFj34vX3KkMKv5nv3iR mUL8jG+vFYB0RKDw== From: "tip-bot2 for Frederic Weisbecker" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/urgent] hrtimer: Report offline hrtimer enqueue Cc: "Paul E. McKenney" , Frederic Weisbecker , Thomas Gleixner , stable@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240129235646.3171983-4-boqun.feng@gmail.com> References: <20240129235646.3171983-4-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170721422238.398.262942897891124372.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789471226220379920 X-GMAIL-MSGID: 1790143906197625746 The following commit has been merged into the timers/urgent branch of tip: Commit-ID: dad6a09f3148257ac1773cd90934d721d68ab595 Gitweb: https://git.kernel.org/tip/dad6a09f3148257ac1773cd90934d721d68ab595 Author: Frederic Weisbecker AuthorDate: Mon, 29 Jan 2024 15:56:36 -08:00 Committer: Thomas Gleixner CommitterDate: Tue, 06 Feb 2024 10:56:35 +01:00 hrtimer: Report offline hrtimer enqueue 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. Fixes: 5c0930ccaad5 ("hrtimers: Push pending hrtimers away from outgoing CPU earlier") Reported-by: Paul E. McKenney Signed-off-by: Frederic Weisbecker Signed-off-by: Paul E. McKenney Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20240129235646.3171983-4-boqun.feng@gmail.com --- include/linux/hrtimer.h | 4 +++- kernel/time/hrtimer.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h index 87e3bed..641c456 100644 --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h @@ -157,6 +157,7 @@ enum hrtimer_base_type { * @max_hang_time: Maximum time spent in hrtimer_interrupt * @softirq_expiry_lock: Lock which is taken while softirq based hrtimer are * expired + * @online: CPU is online from an hrtimers point of view * @timer_waiters: A hrtimer_cancel() invocation waits for the timer * callback to finish. * @expires_next: absolute time of the next event, is required for remote @@ -179,7 +180,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 7607939..edb0f82 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;