From nobody Sun Sep 27 02:14:25 2026 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (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 E071B381B0D for ; Thu, 27 Aug 2026 05:21:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787808077; cv=none; b=M5IXcusUji2Ik6CdLU3meGjqU/Cl6P0bjsMMw6/v0msUx69NnimPp87aiFlmny1EUhU5ponB1yZ/Lj6fMwroZnTOFrzmjRFOdvXO7juzu20ISrPYAcl3+ab16iTYDK/k9IRSc9jhTNlk5pIAqdouFav7zewn7WdWvG7SBTvKn5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787808077; c=relaxed/simple; bh=kjDR/D7LPdvgDM4pefUxqSAvBAfOPT1V659fB5GlNWA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l3JFm+Kfo753CkkLgLRCFZDQjnQPpznx0c6KFnX+WP5zMKerHyBOC2OK8nLb7VTm5aLUU0LgO4uuemv/pqg7hV7GbHvzs8h19Saqdw2TtHJmOqHIXgcqEu7TieMAxTbMKdGtik/84KV5R9nZKViE7p45EnFhYFZt1vT6praZbQM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=J37O9UP7; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=e8tVzCYr; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="J37O9UP7"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="e8tVzCYr" Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67R3J0EX1665967 for ; Thu, 27 Aug 2026 05:21:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= xv3IIYIE+BN+vFwAFrajkJNHRbsBTd+G179aP6n55qw=; b=J37O9UP7S5+to3wP i7J8mEjQXee+CrkqPl5ge+tBTLWRg0Fn5HKVWTUwcGZ2+lUlerIWhAGqqd+sNZ6T yLuydCfTZUR6HR8RJbWz6r6qBBkXw50YwS4V5QIC4zQJIM541GpLn8aVLawKBwNG cuWfEfGjZOvX1p2OIVoMMNot0jh2zr9SAJAaHS8Wc1QvoujiclS2N7sQYHn4l4C5 3L5nIe2+fn4jGR67CoYP5VggqllqQNfLZwhJTNUFe+nTVubC+0oNCNWe83i/khcq Cx/zcLDmbxUx9Uoo42k4NPMKFCg4PGtjTGV3d1RQPxTyn3kmf3DqXVCsQzMzAQW8 QTYB8A== Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4gaa3bgwjn-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 27 Aug 2026 05:21:14 +0000 (GMT) Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-396638f9a18so3365758a91.2 for ; Wed, 26 Aug 2026 22:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787808074; x=1788412874; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xv3IIYIE+BN+vFwAFrajkJNHRbsBTd+G179aP6n55qw=; b=e8tVzCYr+HB9hoe/s77X+yUmJEcRa4xqADESFKjF0bZHUfVCa/0G1sivVs1/dDyntI UDvny4OYcsc6luakEHlrq36v/fTCq65znzRBlTQSH4DE7/nKD4mgiGZQ3tQ65zWI0+oZ pFpi/zSBQiDvzB9Tcme13P1OvSGN8rCabqr7hQyw5nqmKUssrczTLS2Jlp+U/qY3vbRt GDtfm3NO+7S7wx3u7bO6cOq4NaaPZH/Ro113nv/YANUWtBaFtcb4TK4FMPx53Y4vzIZD VgmUS50mNx3VnmpL1Y5E5dzwhFDsX5OI+SzWO/7fw4TE65ukjvwCyk+SuIXMxUzuRVC3 vLIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787808074; x=1788412874; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=xv3IIYIE+BN+vFwAFrajkJNHRbsBTd+G179aP6n55qw=; b=gsuM/kgFjuGDHKsj5ilei4K2hP5PQzQw+HCKuUWHZ4gLLcQkzi1uSGMLcV0nMS676s FINOwGpASHTbim5tgVxpV+HxilwoxXi0Qf5seDQ+WbRKwvuxD4J/WiPfWzN6SfDSXGz6 dX6c46h6ezXmybG7Pb+XCbmcsoo1FNm48gbJwS3cvLSW0/PUPOmqxa/hRUAfrJz2/JeN Mtkz1x9v9qFPxPEkpPnHEfANBTPMkHsxOv6U/Fm28PTTd5Adw2ewB+eaINWROMltwlTY BqRkMjoI94zV6PjQlZq/SsUwSqhdIA4p1t3xTyuS11foNb0Zd7QmWfGMBGHevi69zHH7 mttw== X-Gm-Message-State: AFuF++ky+9Z7667PMombSQvoSlLBhOCuoVgAB69bqBT64R5te5bBTrUY 09TT0GpGhvcmKKrI6Xqv984QUr602PFKkPxEllR31zdm2RWoMLkihIPD2DauvmdAhRO0BwZkJws Ygxjmj05PA7HuH4sDCu7udN03+PpGIk4u/w82GMT/TN+KHB49MICnyHs90iQ2+aJ+B3A= X-Gm-Gg: AR+sD117BQtA5D+i+AbWi33ChFB9gjjfx8xPzpjELgEfejJDYB7afV9e3Qa7/O+3jYa ByDmrqoiQVxti6pS8A8FYGvyGs0hfB0bT/k/reM8hfz9GQS0KsH7v/1VeAohfNVrSvK9FlzQj7E ZLkIX7dKotPAapuaXdOrkRl/1kgdGrQ7dYXktAPnjFo/etiSfjBrocdpwu9+8VNC3w5ke1zqw4B bIlKX22YskvbaXg0joejMb+w5ydYgZVPdPlgSidLjXcdCAky62hytgegdzLAEAVl4CMZ7IrG8Ug 4T1wbOFNRjs544694hMBz662kWbYZaeXCRYxIQdR9UD0KNxGaNnqJeEF8Y50ks8FK4P+4f/c0KU 6rX7yQGRteZaJC1h/A9Hm X-Received: by 2002:a17:90b:3fc4:b0:38f:dec8:f7e9 with SMTP id 98e67ed59e1d1-3966d443146mr26001454a91.12.1787808073576; Wed, 26 Aug 2026 22:21:13 -0700 (PDT) X-Received: by 2002:a17:90b:3fc4:b0:38f:dec8:f7e9 with SMTP id 98e67ed59e1d1-3966d443146mr26001361a91.12.1787808073095; Wed, 26 Aug 2026 22:21:13 -0700 (PDT) Received: from [10.213.104.145] ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3283da25c09sm23734633eec.31.2026.08.26.22.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Aug 2026 22:21:12 -0700 (PDT) From: Aditya Chillara Date: Thu, 27 Aug 2026 10:50:57 +0530 Subject: [PATCH 1/2] stop_machine: Track when a CPU executes a stopper callback 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260827-defer-legacy-console-write-on-multi_cpu_stop-v1-1-3b9f6bb4679f@oss.qualcomm.com> References: <20260827-defer-legacy-console-write-on-multi_cpu_stop-v1-0-3b9f6bb4679f@oss.qualcomm.com> In-Reply-To: <20260827-defer-legacy-console-write-on-multi_cpu_stop-v1-0-3b9f6bb4679f@oss.qualcomm.com> To: Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky Cc: linux-kernel@vger.kernel.org, Aditya Chillara X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1787808067; l=3222; i=aditya.chillara@oss.qualcomm.com; s=20260626; h=from:subject:message-id; bh=kjDR/D7LPdvgDM4pefUxqSAvBAfOPT1V659fB5GlNWA=; b=s5V3la4kCXHfsm6oMmYSaV9k3hJkf+8MYeJIEfxiuhBckq/c5pPTNZ/Ofw+jlz8+jmxlZHy6/ dx+GClhMy9ECxxU3DqSyYTETIHOMECjEN+gwr2pFAa6gFnXaHzrhAhD X-Developer-Key: i=aditya.chillara@oss.qualcomm.com; a=ed25519; pk=3vcOzHlHNCpL/4rvfU3cpTk2xIC7SI+TH0gypa9FdZQ= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI3MDA0MiBTYWx0ZWRfX3KtjTXV1JtMg wR36qK34+u6HpHufMKyhggj0FN6+CBPLBM5pKxt9gsOigafDpEef2vGVqhg/DkL5UPZ83MjDO1U r+sAkDIQoNKMJRYvKxgSKux0jR/18KIB17STji90wb9fls2QnpnVPdaNzj4t8rkPyuBahAzOd3D pWHDQRZO1Eyw6un8fo7d32EZMboTgdKo6+kheCNNqhkgTmePaRpvd/CZB7zcQYLqPJ9MXFl+n8r QEU4UU9XpRa9FeXzppQ7KEAqBr4IWnv+r/Po/40VX6JpsPM8KBi91gDHc4bSJJFUL8rKDeY9oKA cqGy26ueGAip+KPriRs+g8ogy+TC5fJYpVOPoHdr6BsQqxYIEbyilaQD7UJw2csmp2JrWhY0qn9 CxMGLatUA5MqGm9xAfTjpdh7rW+W58Gm33B2YBRjmtEl8riXU2fTM0Uvg28QFl46ZAcmAPVOcWy JVMcahXYjpuQgvPCeHw== X-Proofpoint-Spam-Info: AW1haW4tMjYwODI3MDA0MiBTYWx0ZWRfX0qMl/wp0EBjA y8yvYp9mZNQ1NivpmAwANk7KL/e1XXURTsj6N6JMsJTyxSXNCrr/Ikuhyu+kMXoUYa9v9XXV6WL EuBlr6QPI3wEl6RKsAsBaGZD4mNV8Go= X-Proofpoint-ORIG-GUID: 4o5Q5KStQ3pniRI-0NvPWV0HStBiW6lt X-Proofpoint-GUID: 4o5Q5KStQ3pniRI-0NvPWV0HStBiW6lt X-Authority-Analysis: v=2.4 cv=KbfidwYD c=1 sm=1 tr=0 ts=6a8fc94a cx=c_pps a=UNFcQwm+pnOIJct1K4W+Mw==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=IkcTkHD0fZMA:10 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_glEPmIy2e8OvE2BGh3C:22 a=EUspDBNiAAAA:8 a=ufIu5EhPaA2AthKxfoUA:9 a=QEXdDO2ut3YA:10 a=uKXjsCUrEbL0IQVhDsJ9:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-27_02,2026-08-26_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 bulkscore=0 adultscore=0 malwarescore=0 phishscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608270042 The cpu stopper thread runs in stop_sched_class, above every other scheduling class. While a stopper callback executes, nothing else on that CPU is scheduled, including RT kthreads such as a watchdog pet thread. A callback that performs a long, slow operation can therefore starve those threads, and for multi_cpu_stop() stall the whole state machine. The same is true of an interrupt taken during the callback: multi_cpu_stop() keeps interrupts enabled during MULTI_STOP_PREPARE, and softirqs may run on irq exit. Add a per-CPU flag covering execution of a stopper callback, set in the dispatch path before the callback runs and cleared after it returns, and expose in_cpu_stop() so callers can detect this context and defer operations that could hold the CPU. Assisted-by: LLM Signed-off-by: Aditya Chillara Tested-by: Aditya Chillara --- include/linux/stop_machine.h | 13 +++++++++++++ kernel/stop_machine.c | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/linux/stop_machine.h b/include/linux/stop_machine.h index 84e7fb627ba4..ae71a829f036 100644 --- a/include/linux/stop_machine.h +++ b/include/linux/stop_machine.h @@ -38,6 +38,14 @@ void stop_machine_park(int cpu); void stop_machine_unpark(int cpu); void stop_machine_yield(const struct cpumask *cpumask); =20 +/* + * True while the current CPU is executing a cpu stopper callback. The + * stopper runs above every other scheduling class, so nothing else on the + * CPU is scheduled until the callback returns. Callers use this to defer + * work that could hold the CPU too long (e.g. slow console flushes). + */ +bool in_cpu_stop(void); + extern void print_stop_info(const char *log_lvl, struct task_struct *task); =20 #else /* CONFIG_SMP */ @@ -84,6 +92,11 @@ static inline void stop_one_cpu_nowait(unsigned int cpu, =20 static inline void print_stop_info(const char *log_lvl, struct task_struct= *task) { } =20 +static inline bool in_cpu_stop(void) +{ + return false; +} + #endif /* CONFIG_SMP */ =20 /* diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index d085ba1f4b44..d38fabb0b9f1 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c @@ -48,8 +48,21 @@ struct cpu_stopper { }; =20 static DEFINE_PER_CPU(struct cpu_stopper, cpu_stopper); +static DEFINE_PER_CPU(bool, cpu_stop_active); static bool stop_machine_initialized =3D false; =20 +bool in_cpu_stop(void) +{ + bool ret; + + preempt_disable(); + ret =3D READ_ONCE(*this_cpu_ptr(&cpu_stop_active)); + preempt_enable(); + + return ret; +} +EXPORT_SYMBOL_GPL(in_cpu_stop); + void print_stop_info(const char *log_lvl, struct task_struct *task) { /* @@ -507,7 +520,16 @@ static void cpu_stopper_thread(unsigned int cpu) stopper->caller =3D work->caller; stopper->fn =3D fn; preempt_count_inc(); + + /* + * Set before the callback runs so an interrupt taken during it, + * and any softirq run on irq exit, sees the CPU as inside a + * stopper callback. + */ + this_cpu_write(cpu_stop_active, true); ret =3D fn(arg); + this_cpu_write(cpu_stop_active, false); + if (done) { if (ret) done->ret =3D ret; --=20 2.34.1 From nobody Sun Sep 27 02:14:25 2026 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (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 0F069286881 for ; Thu, 27 Aug 2026 05:21:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787808080; cv=none; b=qdkC0Y+92ZSY/67Y2wFN0gs/m8FLTTv3RmtlvTbPGsENEE2/g2l5NcjyUPLUDLND29iTUJCJmtxiYoM7iseW8NNpGuySpL/T009kyEZR3ct2aSY7WgnQb3V5EFEH5/u9vKN9+rFrYFJFCQew4OnW8hzDTBXsRYjcslNDmlpvVx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787808080; c=relaxed/simple; bh=YTC2a5INYjpakMMBayVLgaN9fcrqTzlfCEFcqNRJA7g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OPYDl7aVjxis/o9/LO6riin7Dj88fqXeHfuXJRKm8F2wC5MBlbOJfDIJiVaRm4dNBU3DPh8dgVmY+d+hQU5E7u8JT/hZYRsjmVghux7Xj/2WPWu2Ew6m9HKBqgpyU8plWd1Wx6+OfW2p9em/FdqZGagfT4DDGYngA6RjEvdFp60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=caQ9FA9H; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=Z+pRAHSb; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="caQ9FA9H"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="Z+pRAHSb" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67R3J18r2861714 for ; Thu, 27 Aug 2026 05:21:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= B9ZrWjcx63Nd0pIr0om8uI+X2l6rfXA78LDeZeZ0iEo=; b=caQ9FA9HRzWPooZV piwKivQRwj7x1oYdmDXJrUR/TIhymw+yjNw0YeJHY7SuBFRmEXe98RKWjxkySK3Z 63GOEWfNujHtqoTIWNNGI+0XL8DR7zGNo18UxwnfqUeBjUo2SaI29Rx2wok5dx01 aaFk7fNQcdQFqWr7t6DymBeBK811zcIO13xVyg4u97niorLWDEm38h59/HKhSPSg XZdxXXWs7WXLhrutnj3LZdCoS4iUIYeoNSlBPJjDpHxlWaOI5u58M3KIl4U25v0R NgaSYheq+XlOvaH48A88ePcX3xVMdmuWZ+JFgo8YzQYbJvO4lcPUakuNTrSxZCFi gaJcmQ== Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4ga075ba3u-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 27 Aug 2026 05:21:17 +0000 (GMT) Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-cb6cf425e86so2323531a12.1 for ; Wed, 26 Aug 2026 22:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787808076; x=1788412876; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=B9ZrWjcx63Nd0pIr0om8uI+X2l6rfXA78LDeZeZ0iEo=; b=Z+pRAHSbUKYwCN8x8/LjlarNcqgQdTL1TG3aPNSvpZVODVZurWNyDcj+Fjh1lxV88d CkeJmQ/WN2Gf9Bpqy9mQVPzhcOGgp0WFZPnQQcenS0Aadlr1oRGSS0aDqVzNgzqsxT3y ND+jUaoEHMzzNfJd5JxYYNeBwqCunGCjlr8xanal+uwB3YcpvBGsSxIdjWLH7y68xmd3 x2Kh7yqBlXCRYMFXMhf6PTHEXTx5CMSe/AcjgVkUx5/xG5I2j2BXKuVeHKCj0KBLykDC gmjHIf3zIdx+Iqxfm6tQskPejaV0N/1KRadiXUIfSqCOWSsBZHrZg8dWo8Upd2vlrl9S oT3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787808076; x=1788412876; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=B9ZrWjcx63Nd0pIr0om8uI+X2l6rfXA78LDeZeZ0iEo=; b=RJwvOXnf668grZTCsZ0Xt1nv2p9RP7jx+LN/4mqbF4J/Hu8mBZtFvsW22HaSZgFhxU QnNgw3QSrTX0qv6BlNE081ss2m5oKi2Otzh9dGlBNbh0a6roFqZ6qXMgP1g89plgYGpL 7jklzvPb/YFqfV8RfhTGD8gm85SE2wYKMw3v90i2e9SXbS4C5MtsXyA5BhDTLDBRXkH0 3rFd6Q8+mDzIO9JfyEGtpSu4nUhKJFbelYJSE9DGMmKv8jODa2ggCpoUw8YzuLyUgmbA Klje5oORyeEmo5n4ikEx7/Gi9CMyyVgUVCcgi4AVUkQx6wFbPKPy2qi9oWpXMKwKakoZ PEWw== X-Gm-Message-State: AFuF++nPiDGteUuMBOLE10YAHYe9uyNSKDUPju1EnCs/cvBEIMBPgLJt Vdb4M6JEJq4yhf+QjB42kVFlN2jYnzDLMgkLwj76ypbdvK5QcX2Uzn53Esr88KHLJ7S7vRWyIDc PIQxOKn5l0uYxQsvGQ9MZ0P9YR2Ocp9igyIcg+so9YZ/1GfbS4AVlzCo6PkBrvU3Wmx4= X-Gm-Gg: AR+sD10WgWMl6kwKv+LfbMbRf+2m98g5U7yLdxxgCAvCS0nRGZIDhRocFBXnItcaEzU 3OdiKBvuX7Ht90CqbszZeLZIxwXd2jJ/x7t81bZB8zlhGRZAZ+ZCIS2dcoQv5sWG843ScjxB/6X RMBQzKrH1WNf/tUIR2KT8Bi/2lTdVF1lAOJJdbd1pbnsi5VF7mj0ELVMmh0Jmm7yZyv5Z0sIivi 7YfgrO3sKVDx7Zj3vtf5LTrxF+A4+uYxjDIdRh5mhJuz+5ubpoVgRt3idrKr0cb6K8DEe2WW5qX RfEpbUr0aMYMRfUHcYkYk/P4TvmO+DFjzGPnkvnVviQN0mrdmXirFviPJ29xZ9ti9aOmBkJbA4B Qo+FxCOfHl4HFg7gaHsLr X-Received: by 2002:a05:6a20:684a:b0:3c4:1c9f:d7e with SMTP id adf61e73a8af0-3cf76084069mr24417459637.6.1787808076405; Wed, 26 Aug 2026 22:21:16 -0700 (PDT) X-Received: by 2002:a05:6a20:684a:b0:3c4:1c9f:d7e with SMTP id adf61e73a8af0-3cf76084069mr24417369637.6.1787808075837; Wed, 26 Aug 2026 22:21:15 -0700 (PDT) Received: from [10.213.104.145] ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3283da25c09sm23734633eec.31.2026.08.26.22.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Aug 2026 22:21:15 -0700 (PDT) From: Aditya Chillara Date: Thu, 27 Aug 2026 10:50:58 +0530 Subject: [PATCH 2/2] printk: Defer legacy console flushes while a CPU runs a stopper callback 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260827-defer-legacy-console-write-on-multi_cpu_stop-v1-2-3b9f6bb4679f@oss.qualcomm.com> References: <20260827-defer-legacy-console-write-on-multi_cpu_stop-v1-0-3b9f6bb4679f@oss.qualcomm.com> In-Reply-To: <20260827-defer-legacy-console-write-on-multi_cpu_stop-v1-0-3b9f6bb4679f@oss.qualcomm.com> To: Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky Cc: linux-kernel@vger.kernel.org, Aditya Chillara X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1787808067; l=5222; i=aditya.chillara@oss.qualcomm.com; s=20260626; h=from:subject:message-id; bh=YTC2a5INYjpakMMBayVLgaN9fcrqTzlfCEFcqNRJA7g=; b=nRORsC8ftY5WQJwBU4AiGoBGndkRa0PXb66VfzAOuAFnAGsYCmupNE7lFnpvSOBQZ847dTymD FSg+02QGAPkA7cDlj2YO8heUsD9uABA9+uhAHWJ077MkPBcF0V/lBcf X-Developer-Key: i=aditya.chillara@oss.qualcomm.com; a=ed25519; pk=3vcOzHlHNCpL/4rvfU3cpTk2xIC7SI+TH0gypa9FdZQ= X-Proofpoint-ORIG-GUID: kzFQyqQtkctf4yu56JiS9DrPxSVdcgjm X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI3MDA0MiBTYWx0ZWRfXx8wGp7AgS1Mk JxegUEco56uGLV7iMq942n6xa+KAGDxpouOY2UNev9MeKW1QB8yZa47YV4IzVG6gcyl6I7+r7q7 3FbqBeghtpzwcGcvXSNBTIfgHVWEDsNVmzPTyhaBy9rHSEKP6ZNMK4qw3PMuGzmkfR6vaXKcu+q l+iNTH7iaomn5Sm9lFgyqxO7jfjcPEhARJHSurmM2aNUxm1T5p5CoR05Qo9uxJmF4mWHYR7qmhb A4FNxfMuYcQ5SAjd57auND05E1ZZhca9X5A2G88WbjfxT+QbHMSqIFqFLXvCvJ4q3KJUk4ZnWBQ +CAmmLZENSfcSdLzC7pJE/s6LJHCy4EjuoD2QbAY+VAqHIKbUM9b6rdzpC4i9BFMQQEiehkBr+f UEFuznPqOOWDgvJoun9i8xVZLyVNjZ/mF8dRCD3A1p34gVAy/uP66A40D1B8LzebRr1lQiIjky9 q7O4VEfNiqGd2kAT9Cg== X-Proofpoint-GUID: kzFQyqQtkctf4yu56JiS9DrPxSVdcgjm X-Proofpoint-Spam-Info: AW1haW4tMjYwODI3MDA0MiBTYWx0ZWRfX5up0OI8bJc5m c03ELNY7P+ZAflLZa+MvfgMJf/lpTEgz+Xv58suWwC3EQraM0jfGCfA4KZcnxvRnV39aAI/0ZzL wVti1wpx4ZVOWMci21WRus6F0+yAfVk= X-Authority-Analysis: v=2.4 cv=RPiD2Yi+ c=1 sm=1 tr=0 ts=6a8fc94d cx=c_pps a=oF/VQ+ItUULfLr/lQ2/icg==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=IkcTkHD0fZMA:10 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=EUspDBNiAAAA:8 a=5A7826UXk9eT2lxxAD4A:9 a=QEXdDO2ut3YA:10 a=3WC7DwWrALyhR5TkjVHa:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-27_02,2026-08-26_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 clxscore=1015 priorityscore=1501 spamscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 suspectscore=0 bulkscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608270042 The cpu stopper thread runs above every other scheduling class, so while a stopper callback executes, nothing else on that CPU is scheduled. If such a callback emits a normal-priority printk(), the legacy console path can synchronously flush the pending console backlog. On systems with a slow UART and a large backlog, this holds the CPU long enough to starve RT kthreads such as the watchdog pet, and for multi_cpu_stop() prevents the CPU from advancing the state machine while the other CPUs wait. The resulting delay can prevent watchdog servicing long enough to trigger a watchdog bark or bite. The same can happen from an interrupt taken during the callback: multi_cpu_stop() keeps interrupts enabled during MULTI_STOP_PREPARE, and a printk() may be emitted from a softirq run on irq exit. Defer normal-priority legacy console output while a CPU is executing a stopper callback (in_cpu_stop()), and reschedule any pending output after the callback exits. Keep emergency and panic console behavior unchanged. Assisted-by: LLM Signed-off-by: Aditya Chillara Tested-by: Aditya Chillara --- include/linux/printk.h | 5 +++++ kernel/printk/internal.h | 9 ++++++++- kernel/printk/printk.c | 23 +++++++++++++++++++++++ kernel/stop_machine.c | 7 +++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/include/linux/printk.h b/include/linux/printk.h index f594c1266bfd..4f3fb4ef5b92 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -166,6 +166,7 @@ __printf(1, 2) __cold int _printk_deferred(const char *= fmt, ...); =20 extern void __printk_deferred_enter(void); extern void __printk_deferred_exit(void); +void printk_defer_console_output(void); =20 extern void printk_force_console_enter(void); extern void printk_force_console_exit(void); @@ -239,6 +240,10 @@ static inline void printk_deferred_exit(void) { } =20 +static inline void printk_defer_console_output(void) +{ +} + static inline void printk_force_console_enter(void) { } diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 85fbf1801cbe..8c02f93e798c 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -3,6 +3,7 @@ * internal.h - printk internal definitions */ #include +#include #include #include =20 @@ -206,7 +207,13 @@ static inline void printk_get_console_flush_type(struc= t console_flush_type *ft) =20 /* Legacy consoles are flushed directly when possible. */ if (have_legacy_console || have_boot_console) { - if (!is_printk_legacy_deferred()) + /* + * Offload while this CPU runs a stopper callback so that a + * slow flush cannot starve RT kthreads (e.g. the watchdog + * pet) or stall the multi_cpu_stop() state machine. + * Flushed once the stopper exits. + */ + if (!is_printk_legacy_deferred() && !in_cpu_stop()) ft->legacy_direct =3D true; else if (!console_irqwork_blocked) ft->legacy_offload =3D true; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 3fcdf4b4e2e5..379fcbe6914c 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -49,6 +49,7 @@ #include #include #include +#include =20 #include #include @@ -4602,6 +4603,16 @@ static void wake_up_klogd_work_func(struct irq_work = *irq_work) { int pending =3D this_cpu_xchg(printk_pending, 0); =20 + /* + * Don't flush the legacy console from irq_work while this CPU runs a + * stopper callback; keep the bit pending and re-run once it exits (see + * cpu_stopper_thread()). + */ + if ((pending & PRINTK_PENDING_OUTPUT) && in_cpu_stop()) { + this_cpu_or(printk_pending, PRINTK_PENDING_OUTPUT); + pending &=3D ~PRINTK_PENDING_OUTPUT; + } + if (pending & PRINTK_PENDING_OUTPUT) { if (force_legacy_kthread()) { if (printk_legacy_kthread) @@ -4687,6 +4698,18 @@ void defer_console_output(void) __wake_up_klogd(PRINTK_PENDING_WAKEUP | PRINTK_PENDING_OUTPUT); } =20 +void printk_defer_console_output(void) +{ + bool pending_output; + + preempt_disable(); + pending_output =3D this_cpu_read(printk_pending) & PRINTK_PENDING_OUTPUT; + preempt_enable(); + + if (pending_output) + defer_console_output(); +} + /** * printk_trigger_flush - Attempt to flush printk buffer to consoles. * diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index d38fabb0b9f1..18ae7ff2d8b8 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c @@ -22,6 +22,7 @@ #include #include #include +#include #include =20 /* @@ -530,6 +531,12 @@ static void cpu_stopper_thread(unsigned int cpu) ret =3D fn(arg); this_cpu_write(cpu_stop_active, false); =20 + /* + * Flush console output that was deferred while the callback ran, + * now that it is safe to do so from this CPU. + */ + printk_defer_console_output(); + if (done) { if (ret) done->ret =3D ret; --=20 2.34.1