From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 60D6322E3F0 for ; Thu, 8 Jan 2026 03:12:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767841925; cv=none; b=ZQBmD7zymhj8agHE0ETqpmwjbdJKoE7jGkyAimQ6Q6vKW14GtXZvTSxwjcoUkHo7ZE4UhiKbQycKIMp69j+pTCZVp456vkuqVxYbneaEAxydoWAVIDWQlwOmEFVsehnJ6GeMx9nMw8+EuC1cJXHNUQdPiwiB+hl9R01C+BcNRGg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767841925; c=relaxed/simple; bh=n232cD5q+hQpIaESBw0FPwRU9GyQlyLUdobVitz0Xxs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gfI71biEylkCyKTl1iMnFkMUbpniC8e5XqADl0BH24I5j7RtH3ezKYYNe2MrXu30S77P+n4AnFZT51Cs6m7DgsxsA7O/s7GRbBpikIG+R2KBUe6Gh8O8IwpgqxvAKxW3Tkip5QXEHqGmzq6vlN16UAJDc+82MnEC9Lco9zMof7s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=d9CY5FQG; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="d9CY5FQG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767841922; 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=veooc5fgy+qWGccmz/lnj0J1P/NYcTlr1eVWumE+dW0=; b=d9CY5FQG4mWsYkPvBQaesDmcrrSRjZES0tWML/bZR/1/pp1bFojGJEF9MsalSApkARHTmo 9D3yRuTPYLKUsMGm/uYorFGHnHNjrg8uvBg0sQOPFuICkUKOI8v7vy9xiCpEoc7yKuauKJ O4hhTeYapWs38YDjdJkL4guivQ0LMsw= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-678-rBYlK9zjMaeqBMLRfT0yNA-1; Wed, 07 Jan 2026 22:11:58 -0500 X-MC-Unique: rBYlK9zjMaeqBMLRfT0yNA-1 X-Mimecast-MFC-AGG-ID: rBYlK9zjMaeqBMLRfT0yNA_1767841917 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C8CE418005AE; Thu, 8 Jan 2026 03:11:55 +0000 (UTC) Received: from localhost (unknown [10.72.112.41]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4EA1A180009E; Thu, 8 Jan 2026 03:11:53 +0000 (UTC) Date: Thu, 8 Jan 2026 11:11:50 +0800 From: Baoquan He To: Pnina Feder Cc: akpm@linux-foundation.org, pmladek@suse.com, linux-kernel@vger.kernel.org, lkp@intel.com, mgorman@suse.de, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, senozhatsky@chromium.org, tglx@linutronix.de, vkondra@mobileye.com Subject: Re: [PATCH v4] panic: add panic_force_cpu= parameter to redirect panic to a specific CPU Message-ID: References: <20260105081808.1771473-1-pnina.feder@mobileye.com> <20260107215659.3619730-1-pnina.feder@mobileye.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20260107215659.3619730-1-pnina.feder@mobileye.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 On 01/07/26 at 11:56pm, Pnina Feder wrote: > Some platforms require panic handling to execute on a specific CPU for > crash dump to work reliably. This can be due to firmware limitations, Thanks for fixing this. Could you kindly reveal which platform this issue is from? > interrupt routing constraints, or platform-specific requirements where > only a single CPU is able to safely enter the crash kernel. > > Add the panic_force_cpu= kernel command-line parameter to redirect panic > execution to a designated CPU. When the parameter is provided, the CPU > that initially triggers panic forwards the panic context to the target > CPU via IPI, which then proceeds with the normal panic and kexec flow. > > If the specified CPU is invalid, offline, or a panic is already in > progress on another CPU, the redirection is skipped and panic continues > on the current CPU. What if both the original CPU and specified CPU are not able to function well on panic jumping? The crash dumping will fail in this case? > > Changes since v3: > - Dump original CPU's stack before redirecting to preserve debug info > - Add Documentation/admin-guide/kernel-parameters.txt entry > - Use smp_call_function_single_async() to avoid blocking in csd_lock() > - Add CONFIG_CRASH_DUMP dependency > - Reuse vpanic()'s static buffer instead of separate allocation > - Remove verbose warning messages > > Signed-off-by: Pnina Feder > --- > .../admin-guide/kernel-parameters.txt | 13 +++ > kernel/panic.c | 104 ++++++++++++++++++ > 2 files changed, 117 insertions(+) > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > index a8d0afde7f85..561ce09a6ae1 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -4753,6 +4753,19 @@ Kernel parameters > panic_on_warn=1 panic() instead of WARN(). Useful to cause kdump > on a WARN(). > > + panic_force_cpu= > + [KNL,SMP] Force panic handling to execute on a specific CPU. > + Format: > + Some platforms require panic handling to occur on a > + specific CPU for the crash kernel to function correctly. > + This can be due to firmware limitations, interrupt routing > + constraints, or platform-specific requirements where only > + a particular CPU can safely enter the crash kernel. > + When set, panic() will redirect execution to the specified > + CPU before proceeding with the normal panic and kexec flow. > + If the target CPU is offline or unavailable, panic proceeds > + on the current CPU. > + > panic_print= Bitmask for printing system info when panic happens. > User can chose combination of the following bits: > bit 0: print all tasks info > diff --git a/kernel/panic.c b/kernel/panic.c > index 0d52210a9e2b..414ef60d2306 100644 > --- a/kernel/panic.c > +++ b/kernel/panic.c > @@ -300,6 +300,103 @@ void __weak crash_smp_send_stop(void) > > atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID); > > +#if defined(CONFIG_SMP) && defined(CONFIG_CRASH_DUMP) > +/* CPU to redirect panic to, or -1 if disabled */ > +static int panic_force_cpu = -1; > +static call_single_data_t panic_csd; > + > +static int __init panic_force_cpu_setup(char *str) > +{ > + int cpu; > + > + if (!str) > + return -EINVAL; > + > + if (kstrtoint(str, 0, &cpu) || cpu < 0) { > + pr_warn("panic_force_cpu: invalid value '%s'\n", str); > + return -EINVAL; > + } > + > + panic_force_cpu = cpu; > + return 0; > +} > +early_param("panic_force_cpu", panic_force_cpu_setup); > + > +static void do_panic_on_target_cpu(void *info) > +{ > + panic("%s", (char *)info); > +} > + > +/** > + * panic_force_target_cpu - Redirect panic to a specific CPU for crash kernel > + * @fmt: panic message format string > + * @args: arguments for format string > + * > + * Some platforms require panic handling to occur on a specific CPU > + * for the crash kernel to function correctly. This function redirects > + * panic handling to the CPU specified via the panic_redirect_cpu= boot parameter. > + * > + * Returns true if panic should proceed on current CPU. > + * Returns false (never returns) if panic was redirected. > + */ > +__printf(3, 0) > +static bool panic_force_target_cpu(char *buf, int buf_size, const char *fmt, va_list args) > +{ > + int cpu = raw_smp_processor_id(); > + int target_cpu = panic_force_cpu; > + > + /* Feature not enabled via boot parameter */ > + if (target_cpu < 0) > + return true; > + > + /* Already on target CPU - proceed normally */ > + if (cpu == target_cpu) > + return true; > + > + /* Target CPU is offline, can't redirect */ > + if (!cpu_online(target_cpu)) > + return true; > + > + /* Another panic already in progress */ > + if (panic_in_progress()) > + return true; > + > + vsnprintf(buf, buf_size, fmt, args); > + > + console_verbose(); > + bust_spinlocks(1); > + > + pr_emerg("panic: Redirecting from CPU %d to CPU %d for crash kernel\n", > + cpu, target_cpu); > + > + /* Dump original CPU's stack before redirecting */ > + if (test_taint(TAINT_DIE) || oops_in_progress > 1) { > + panic_this_cpu_backtrace_printed = true; > + } else if (IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE)) { > + dump_stack(); > + panic_this_cpu_backtrace_printed = true; > + } > + > + printk_legacy_allow_panic_sync(); > + console_flush_on_panic(CONSOLE_FLUSH_PENDING); > + > + panic_csd.func = do_panic_on_target_cpu; > + panic_csd.info = buf; > + > + /* Use smp_call_function_single_async() to avoid blocking in csd_lock(). */ > + if (smp_call_function_single_async(target_cpu, &panic_csd) != 0) > + return true; > + > + return false; > +} > +#else > +__printf(3, 0) > +static inline bool panic_force_target_cpu(char *buf, int buf_size, const char *fmt, va_list args) > +{ > + return true; > +} > +#endif /* CONFIG_SMP && CONFIG CRASH_DUMP */ > + > bool panic_try_start(void) > { > int old_cpu, this_cpu; > @@ -451,6 +548,13 @@ void vpanic(const char *fmt, va_list args) > local_irq_disable(); > preempt_disable_notrace(); > > + /* > + * Redirect panic to target CPU if configured via panic_force_cpu=. > + * Returns false and never returns if panic was redirected. > + */ > + if (!panic_force_target_cpu(buf, sizeof(buf), fmt, args)) > + panic_smp_self_stop(); > + > /* > * It's possible to come here directly from a panic-assertion and > * not have preempt disabled. Some functions called from here want > -- > 2.43.0 >