Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A00EE425CFE for ; Tue, 20 Jan 2026 13:56:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768917397; cv=none; b=EQ9Yf0Ps4hSRueljmdO2a4Zm40qCmGbsMEfHA3DKeo5IlVYJqK00pmxfrakYiRvF3wgX6IqljelAaZ5YN5U5lTd2irgKw/XTww+PDE/FX26CEzM37NADCoZ21cm5ipXCtaIbtx3XspwvCuZuXVHCR2HUggeUj9LUgGEV/8r9bS8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768917397; c=relaxed/simple; bh=+TXky4a52+3pRYSWPECuRtHDZ2ReBPv+z4fq7jJQxvU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qIpg89/e1uziwwHAPhURcDPSDYjoPr+GRO4kKsiNVlPfOX3uAAuhAbVytidKwnOp0mgJzXjZJF/res93R3Tk/JnC0NZunA/1z78c+0dVoikw3CIeomiCA4TT4aXZQw3jI3Vp0CMwV5VwZ68yluL5VbT2decqYzr5YmlCIojN1rc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=DUOlggkQ; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="DUOlggkQ" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4801eb2c0a5so34958875e9.3 for ; Tue, 20 Jan 2026 05:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1768917393; x=1769522193; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=PLLuTEII59m8g6juy1HrRlwpToW31C8fHH/o8do1D+g=; b=DUOlggkQgXcdHPiEVn1/KHSBubOZP/u2khKFeMxddmpr2BExr6ABK/730+fPUERd6Z 65UHj+8feBjmPUvJkjy5dR6SrXC4HEKSZ+XYlZAgDY/E3LxSxvy0hVXJr3f0t8aj40xy Qbi8wMeiZOTYsHBr55urmkQn0fJIYStvgIy2VhZx02Mg6I6TlsqGa57TSWYgYRTXb5GS fKI5WUIlaeIU48U80kNN4yQr0IjG9ygXQ8rPRVsc82IVE8feoZmIIYN6PNjjl2N21D5f 7cMPrTVMwYX0/I/YMiD2HLZW00QJ5uFnrKcz2VYETDRDwyRrtSYlT+GBhl5nA24036KU XHNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768917393; x=1769522193; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PLLuTEII59m8g6juy1HrRlwpToW31C8fHH/o8do1D+g=; b=gwjO4xCTbSblXeiEQtHVRa+Bk/Lg8vh8oGVmEo+7pvmYyurGUNn0FbXG57niyKDhIM nvjKOSIEaMvlHP+KqB2cUjGRemBVAah80VyZY/yu3bUObDRdOFDbe2e7+SBVnWrDq8O4 p3aVfquqIzOT8kVCHxu4tswdDZSDGpAd7v0LN6CV5PJ9oiHZp0BxvHsr6WrU+jCNluXK SH8Cf9hL4Sp1FKQJI+x6FdqCfqxokB/uH2NxfUb02XwthUz+/rKtQ4L7j0iYnQuP0SCA xj76PpqFNjqD1y8rW3pL6j7TzT4UIsPbh3XGp9UZb74xPcMyJf9EkQ1R35GlxP7BmeTN n3aQ== X-Forwarded-Encrypted: i=1; AJvYcCUw5+0O6Xtx/OzJf7nTxslQIJM2zFBtAoWRvtAe1ohrvYNY3oJyj4i/85LVvt5HqmdJMiBFqmT9fMWf1ck=@vger.kernel.org X-Gm-Message-State: AOJu0YwkfAOuljIIJvrf4yzx4CuFw9DHRof7/6k09tef/Zki4LyXdqKy 0JYs10viWm/7h+uNSuDNc3ENYGJF6PUKB98ERarWylTmILDoFXn03An9RXSzAc///sI= X-Gm-Gg: AY/fxX7i86Pjgb9LvXuxfObEAnSu2+R0fVYj/CaLUCMQVbTYhZFM37B9so+a8HEZOKc aRvrmq9gcpIy24WbmLTGr3J+Y+peg/TXJk3ff/ATLvS1lrECEKO0jGGd3uIFhY7wja9mWOeKBit 0fAd1Wha12fq75rsCvnbmIQdVwrRwQx0lWyillSDBj4JjAhPOYtPBNKcsaKcMVj98dwo5SRBJYo H+TY6i+vv0dZ0QZE+F2DNjz7TY7qnUlhkFdoKD75xa3MWNLykpdklm0y74TM7/SO9N537qT3mO2 m2C8RHDSnjX2O8Dvo1pC277mE0cWeC6Ga2u+n2SV25v3De6DcWa+a19F4GxkGFXB7zMqicyXU49 ccUOw4WcDb6YIydYmA8fSTv2U7qMev/ItRsP1a9IDGo+4Kf9NZ5tH9/X1drpSbHB3c9Q0jfRT8s FL3iIDbdynu/qjWA== X-Received: by 2002:a05:600c:620d:b0:477:63b5:7148 with SMTP id 5b1f17b1804b1-480288773f6mr137657455e9.6.1768917392797; Tue, 20 Jan 2026 05:56:32 -0800 (PST) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47f428acd0csm304167455e9.6.2026.01.20.05.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jan 2026 05:56:32 -0800 (PST) Date: Tue, 20 Jan 2026 14:56:30 +0100 From: Petr Mladek To: Pnina Feder Cc: akpm@linux-foundation.org, bhe@redhat.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 v7] panic: add panic_force_cpu= parameter to redirect panic to a specific CPU Message-ID: References: <20260115130552.3761679-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: <20260115130552.3761679-1-pnina.feder@mobileye.com> On Thu 2026-01-15 15:05:52, 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, > 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. > > The IPI delivery is implemented as a weak function (panic_smp_redirect_cpu) > so architectures with NMI support can override it for more reliable delivery. > > 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. > > --- a/kernel/panic.c > +++ b/kernel/panic.c > @@ -299,6 +301,128 @@ void __weak crash_smp_send_stop(void) > } > > atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID); > +atomic_t panic_redirect_cpu = ATOMIC_INIT(PANIC_CPU_INVALID); > + > +#if defined(CONFIG_SMP) && defined(CONFIG_CRASH_DUMP) > +static int __init panic_force_cpu_setup(char *str) > +{ > + int cpu; > + > + if (!str) > + return -EINVAL; > + > + if (kstrtoint(str, 0, &cpu) || cpu < 0) { It should also fail when (cpu >= nr_cpu_ids). IMHO, cpu_online(panic_force_cpu) might cause an invalid access otherwise. > + 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); [...] > +/** > + * panic_try_force_cpu - Redirect panic to a specific CPU for crash kernel > + * @buf: buffer to format the panic message into > + * @buf_size: size of the buffer > + * @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_force_cpu= boot parameter. > + * > + * Returns false if panic should proceed on current CPU. > + * Returns true if panic was redirected. > + */ > +__printf(3, 0) > +static bool panic_try_force_cpu(char *buf, int buf_size, const char *fmt, va_list args) > +{ > + int this_cpu = raw_smp_processor_id(); > + int old_cpu = PANIC_CPU_INVALID; > + > + /* Feature not enabled via boot parameter */ > + if (panic_force_cpu < 0) > + return false; > + > + /* Already on target CPU - proceed normally */ > + if (this_cpu == panic_force_cpu) > + return false; > + > + /* Target CPU is offline, can't redirect */ > + if (!cpu_online(panic_force_cpu)) > + return false; > + > + /* Another panic already in progress */ > + if (panic_in_progress()) { > + return false; > + } Note that the preferred (panic_force_cpu) could enter panic() right now and use the buffer shared buffer in parallel. > + /* > + * Only one CPU can do the redirect. Use atomic cmpxchg to ensure > + * we don't race with another CPU also trying to redirect. > + */ > + if (!atomic_try_cmpxchg(&panic_redirect_cpu, &old_cpu, this_cpu)) > + return false; > + > + vsnprintf(buf, buf_size, fmt, args); I am afraid that we can't share the buffer with the panic() function as safe way here. > + console_verbose(); > + bust_spinlocks(1); > + > + pr_emerg("panic: Redirecting from CPU %d to CPU %d for crash kernel.\n", > + this_cpu, panic_force_cpu); > + > + /* Dump original CPU before redirecting */ > + if (!test_taint(TAINT_DIE) && > + oops_in_progress <= 1 && > + IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE)) { > + dump_stack(); > + } > + > + printk_legacy_allow_panic_sync(); > + console_flush_on_panic(CONSOLE_FLUSH_PENDING); Please, remove the two above functions. They are not safe. They increase the risk that __crash_kexec() won't be called. They should be called only by panic() when __crash_kexec() was not called... > + if (panic_smp_redirect_cpu(panic_force_cpu, buf) != 0) { > + atomic_set(&panic_redirect_cpu, PANIC_CPU_INVALID); > + return false; If we return "false" here then panic() will continue on this cpu. This CPU will likely acquire "panic_cpu" and crash_exec() will likely fail because this is not the preferred CPU. We might want to warn about it. Or we should at least add a comment here. And maybe we even should not call crash_exec() in panic() when panic_redirect_cpu != PANIC_CPU_INVALID && panic_redirect_cpu != panic_cpu > + } > + > + /* IPI/NMI sent, this CPU should stop */ > + return true; > +} > +#else > +__printf(3, 0) > +static inline bool panic_try_force_cpu(char *buf, int buf_size, const char *fmt, va_list args) > +{ > + return false; > +} > +#endif /* CONFIG_SMP && CONFIG_CRASH_DUMP */ > > bool panic_try_start(void) > { Best Regards, Petr