From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (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 9130A26ED59 for ; Tue, 9 Dec 2025 05:12:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765257146; cv=none; b=rHMWHF2wLlRbibgdWjHKJHNEIdTSO7qwnBqeKdydTb6uhPQHl6oxsRjL+Xzw65VolOryo8AoZ/tzo64IJVmE238HdOkrvhZNc7FZvLMqo8iUw1/W+1mbL/pMgsfJDKuyHT/j0zWyXpgadpAv9tIBwHOQxSkaK0wuGStDnTfOQTw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765257146; c=relaxed/simple; bh=USe4Nh9zglOyml52CttZ/0U6Y19yDu20gnaM6uJM11M=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=OcuinDPpIryQ2+Fby5b9M3kZ2niAIYv0IrNvwBrcOAnx/M9hH8YRBFLp7aQerocaATx/4oz7GxK9bHTUZJMf0F8j5QX/EhxyyonSumSbGLcFgrgIR0HGs1FTRaDfY/a559BBQWIIubaRUUozzKP0eNiTOtbXbxq38wmagi0MYPQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=oM/zrDv8; arc=none smtp.client-ip=95.215.58.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="oM/zrDv8" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1765257140; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z3CTNHUh1p49DgCwod+V7w1QnmlsXEMiLLO1b9/jFbc=; b=oM/zrDv8pXmZjzVh7lyN0Z/I2noB3XHyr4v/xe2kVfS7EIU5BkQXbPjXmWh96PYPhgOhF9 87+/8yhJABAR75vpXjurdI3oM8YIyqlKehGXFHLmLG84KZNUeHVDbJag+TG7JvOjmE7F6K HshZuMtMwUR7/EWAmbo2y40WWIvNkd8= Date: Tue, 9 Dec 2025 13:12:14 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH 1/2] hung_task: Consolidate hung task warning into an atomic log block Content-Language: en-US To: Aaron Tomlin Cc: sean@ashe.io, linux-kernel@vger.kernel.org, mhiramat@kernel.org, akpm@linux-foundation.org, Petr Mladek , gregkh@linuxfoundation.org References: <20251209041218.1583600-1-atomlin@atomlin.com> <20251209041218.1583600-2-atomlin@atomlin.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang In-Reply-To: <20251209041218.1583600-2-atomlin@atomlin.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2025/12/9 12:12, Aaron Tomlin wrote: > Consolidate the multi-line console output in check_hung_task() into a new > helper function, hung_task_diagnostics(). > > This patch ensures the entire diagnostic block (task info, kernel > version, and sysctl advice) is logged to the ring buffer via a single > pr_err() call. This is critical in a concurrent environment to prevent > message lines from interleaving with other CPU activity, thus > maintaining contextual integrity of the warning message. > > Signed-off-by: Aaron Tomlin > --- > kernel/hung_task.c | 37 +++++++++++++++++++++++++++---------- > 1 file changed, 27 insertions(+), 10 deletions(-) > > diff --git a/kernel/hung_task.c b/kernel/hung_task.c > index d2254c91450b..d5109a0994c5 100644 > --- a/kernel/hung_task.c > +++ b/kernel/hung_task.c > @@ -223,6 +223,32 @@ static inline void debug_show_blocker(struct task_struct *task, unsigned long ti > } > #endif > > +/** > + * hung_task_diagnostics - Print structured diagnostic info for a hung task. > + * @t: The struct task_struct of the detected hung task. > + * > + * This function consolidates the printing of core diagnostic information > + * for a task found to be blocked. This approach ensures atomic logging > + * of the multi-line message block, preventing interleaving by other > + * console activity, thus maintaining contextual clarity. > + */ > +static void hung_task_diagnostics(struct task_struct *t) > +{ > + unsigned long blocked_secs = (jiffies - t->last_switch_time) / HZ; > + > + pr_err("INFO: task %s:%d blocked for more than %ld seconds.\n" > + " %s %s %.*s\n" > + "%s\n" "%s\n" forces an unconditional newline, causing a spurious blank line when the flag isn't set, right? > + "\"echo 0 > /proc/sys/kernel/hung_task_timeout_secs\"" > + " disables this message.\n", > + t->comm, t->pid, blocked_secs, > + print_tainted(), init_utsname()->release, > + (int)strcspn(init_utsname()->version, " "), > + init_utsname()->version, > + (t->flags & PF_POSTCOREDUMP) ? > + " Blocked by coredump." : ""); > +} > + > static void check_hung_task(struct task_struct *t, unsigned long timeout, > unsigned long prev_detect_count) > { > @@ -252,16 +278,7 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout, > if (sysctl_hung_task_warnings || hung_task_call_panic) { > if (sysctl_hung_task_warnings > 0) > sysctl_hung_task_warnings--; > - pr_err("INFO: task %s:%d blocked for more than %ld seconds.\n", > - t->comm, t->pid, (jiffies - t->last_switch_time) / HZ); > - pr_err(" %s %s %.*s\n", > - print_tainted(), init_utsname()->release, > - (int)strcspn(init_utsname()->version, " "), > - init_utsname()->version); > - if (t->flags & PF_POSTCOREDUMP) > - pr_err(" Blocked by coredump.\n"); > - pr_err("\"echo 0 > /proc/sys/kernel/hung_task_timeout_secs\"" > - " disables this message.\n"); > + hung_task_diagnostics(t); Since there's only one caller, why not just open-code it ... TBH, jamming everything into a single pr_err() call doesn't look any cleaner to me than the original code :( > sched_show_task(t); > debug_show_blocker(t, timeout); > Cheers, Lance