From mboxrd@z Thu Jan 1 00:00:00 1970 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 1F06023392B for ; Thu, 27 Aug 2026 19:05:29 +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=1787857531; cv=none; b=oCDWulf4S2zbM/HPTGYnBi8f4zIuMJ+ptX91w/LHd3rEKLziO+vYZ7HqOqXGhGPlILGTYBc7sH5LlfqLYGet4EjgnkUyzgYXh/RTIRQBKcoWUYLge8nqQevDHCnsWLVp1DB4dNWdOa89j6WZczC4TFlmCqcOyvX/ryBzM/EjGO4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787857531; c=relaxed/simple; bh=AImPO2yc3vyRcHbRtS9kErL7C+vs8y+5bovw/Pauct4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=gHYxt4qseW/Nq/B7GVws46THKffUJcpmiif7oPMG38yjRzr+ySnCVanb8ZU/GXloTxc/C/cC0sttTKB+QEnZLOJZB5h3GTaEpVrxioWnQszUqNqogf/SZl3jDAYlnDO4MGosgel4LIy1yqYVk6NfEaKDWVA9moI6O+GtCF5jJBw= 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=JfLIGPWP; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=j6SZCrKo; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JfLIGPWP"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="j6SZCrKo" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1787857528; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1t06oSpIK8dv7dZg9J3ZYOM/SDrR5ugFNYHdBQaPLvc=; b=JfLIGPWPaTY4pzuuiyA0KfmW8WLto7GPBL/8JQWIdwK3Zg9BH8L9Zpn6nmMQ6hE++vCtbG hvqUjNaR10w58aYgMlByQ/SUiy0DZVVbo8+9oYXHkNf1xrw8/W6Ud/Y9HDIK3bMslealcg 2trLeAjQi7PHtK6zFZ9L/w8AlhFT5995EyqJgeAkIjsYMWH0/zflGs39yN7OEErnYA+Zsf dllEmt0lW7yso3IclIkSFF/9ce1rg7aqthHWODtawBbACQh45yxL+m215008dxZhFknWHN L0DR+53KTvxrPySSMaZySEQvuVVJYtTo+jgxuVcKFxOOoIVp9d7sA9CvhaJ4Qw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1787857528; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1t06oSpIK8dv7dZg9J3ZYOM/SDrR5ugFNYHdBQaPLvc=; b=j6SZCrKop2FK6ohkxXhy0BJWduFkU1ugPJkzLguyo+2s8/mnk97iiSmW1zVCR/5+8z0WGP SDyaqmHBgFw2QxCQ== To: Aditya Chillara , Petr Mladek , Steven Rostedt , Sergey Senozhatsky Cc: linux-kernel@vger.kernel.org, Aditya Chillara Subject: Re: [PATCH 0/2] printk/stop_machine: Defer legacy console flushes while a CPU runs a stopper callback In-Reply-To: <20260827-defer-legacy-console-write-on-multi_cpu_stop-v1-0-3b9f6bb4679f@oss.qualcomm.com> References: <20260827-defer-legacy-console-write-on-multi_cpu_stop-v1-0-3b9f6bb4679f@oss.qualcomm.com> Date: Thu, 27 Aug 2026 21:11:27 +0206 Message-ID: <87pkz3o03s.fsf@jogness.linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On 2026-08-27, Aditya Chillara wrote: > A device using a legacy UART console (console=ttyMSM0,115200n8) hit a > watchdog bark/bite about 40 seconds after boot. > > stop_machine() (used here for kprobe text patching) stops every CPU by > running multi_cpu_stop() on each of them, through the per-CPU > "migration/%u" threads. These threads run at a higher priority than the > msm_watchdog thread. At bite time, all eight CPUs were still spinning in > multi_cpu_stop()'s MULTI_STOP_PREPARE state, where interrupts are left > enabled. > > Heavy SELinux denial logging had built up a large backlog on the > console. One CPU took an interrupt while spinning in MULTI_STOP_PREPARE. > Handling it eventually led to a printk(), and because the console was a > legacy console, that printk() synchronously drained the whole backlog > over the slow UART. While the drain was still running, the watchdog bark > interrupt hit the same CPU, found no recent pet, and escalated to a > bite. > > The captured stack for that CPU, innermost frame first: > > qcom_soc_set_wdt_bite > qcom_wdt_bark_handler > __handle_irq_event_percpu > handle_irq_event > handle_fasteoi_irq > generic_handle_domain_irq > gic_handle_irq > do_interrupt_handler > el1_interrupt > el1h_64_irq_handler > el1h_64_irq > console_flush_all > console_unlock > vprintk_emit > dev_vprintk_emit > dev_printk_emit > __dev_printk > _dev_err > btspi_sleep_timeout_handler > call_timer_fn > __run_timer_base > run_timer_softirq > handle_softirqs > __do_softirq > ____do_softirq > call_on_irq_stack > do_softirq_own_stack > __irq_exit_rcu > irq_exit_rcu > el1_interrupt > el1h_64_irq_handler > el1h_64_irq > multi_cpu_stop > cpu_stopper_thread > smpboot_thread_fn > kthread > ret_from_fork > > Every other CPU stayed parked in the rendezvous the whole time, since > their stopper threads outrank msm_watchdog. Nothing could pet the > watchdog until the drain finished. > > This was observed through multi_cpu_stop(), but the hazard is not > specific to it. Every cpu stopper callback runs in stop_sched_class, > above msm_watchdog and every other thread on the CPU, so a slow flush > from any of them (including single-CPU callbacks such as the migration > and task-migration stoppers) can starve the watchdog just as well. The > fix therefore covers all stopper callbacks, not only multi_cpu_stop(). > > Fix this by having the cpu stopper mark the CPU active while a callback > runs, and having printk use that marker to defer legacy console flushes > until the callback returns: > > 1/2 stop_machine: Track when a CPU executes a stopper callback > > Add a per-CPU flag, set in the stopper dispatch path around the > callback, and an in_cpu_stop() accessor. > > 2/2 printk: Defer legacy console flushes while a CPU runs a stopper callback > > Route legacy console output through the offload path instead of > flushing it directly while a CPU is inside a stopper callback, and > flush it once the callback returns. Emergency and panic output is > unaffected. > > Reproduced and verified with an out-of-tree test module that triggers > stop_machine() with a queued console backlog and a printk() inside the > rendezvous, paired with a kprobe-based script that flags any console > flush happening while a CPU is inside a stopper callback. This is a fairly heavy series just to address a problem with legacy consoles that has always existed. How about instead a series to switch msm_serial.c/qcom_geni_serial.c over to NBCON? That is fairly straightforward (especially with the availability of CON_NBCON_ATOMIC_UNSAFE) and would help to move the kernel forward rather than improving the parts we are trying to get rid of. I would even be willing to convert those 2 drivers if you could provide the necessary testing for me. John