From nobody Wed Dec 17 05:28:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7B42E1F4174 for ; Wed, 26 Mar 2025 15:12:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743001935; cv=none; b=pTx5wAwLeH5sWAAgsmlCk1lZgzSyUJH4X0UwzbEXvNm3EDKfoAwmJNvbIAk6ESdDQZ4j/9u/Tr51T9mIAGBteoeogjNzS7CEhokwMvfjLwfK/GZHSzyN+0oqtMptT829NvzENA2BVex1DLKAjsePN5nTlrf3/WMHr1bcmQSYBG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743001935; c=relaxed/simple; bh=dvH6cZROBDqL/EIJB0ddluLgh3GMP5pgXEtD5g291tI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oQxBjv4Hpv/rJEVcoN/5DAetBXYAQcfNM++r5iZT8phmtHiLu/rCJ3KAEuqzqy6ffyuEgAPLj8oD9G5nwxUFtscLmkYOL1LlhmcNF5Qtdfnmpdbtsd6oCsCd+9eV0diUhXdALWysZAF6aQXpSZw5LUfT8xresIHTaKWrp6pvX7A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MurPLbRg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MurPLbRg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D6FDC4CEE8; Wed, 26 Mar 2025 15:12:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743001935; bh=dvH6cZROBDqL/EIJB0ddluLgh3GMP5pgXEtD5g291tI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MurPLbRgOhvxG7DGoeI4e6uf1uBNgQKuYEVn+R9J1Ys/ntkU8s2GjleUUf4P5gSje K0Qw27qmTj6yClEmUiZYU3Jw1dUraF20/y3Y5X2ULu4JIBKzJDJcs5zPefI7Hkzoie vbSpNhTmjCjRrUQu0tIv9GAwFTQynj6olDOMx+wonf4CXVF2xg0OSv6n4KuZs9Plps V14SmWmJUQLArdVDliLtaFaZ+VR12eQgLTD7XuLG8HExBuGdATgUYre2U3B9lGEfxr RcHi7NoRsrkmWAkQfXjInPNCwOkLvWM6CaaRHxsMWSD8aK5/8DS82WxDealKGyUyX0 LuAEXKNekpppw== From: carlos.bilbao@kernel.org To: tglx@linutronix.de Cc: bilbao@vt.edu, pmladek@suse.com, akpm@linux-foundation.org, jan.glauber@gmail.com, jani.nikula@intel.com, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, takakura@valinux.co.jp, john.ogness@linutronix.de, Carlos Bilbao Subject: [PATCH 1/2] panic: Allow archs to reduce CPU consumption after panic Date: Wed, 26 Mar 2025 10:12:03 -0500 Message-ID: <20250326151204.67898-2-carlos.bilbao@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250326151204.67898-1-carlos.bilbao@kernel.org> References: <20250326151204.67898-1-carlos.bilbao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Carlos Bilbao After handling a panic, the kernel enters a busy-wait loop, unnecessarily consuming CPU and potentially impacting other workloads including other guest VMs in the case of virtualized setups. Introduce cpu_halt_after_panic(), a weak function that archs can override for a more efficient halt of CPU work. By default, it preserves the pre-existing behavior of delay. Signed-off-by: Carlos Bilbao (DigitalOcean) Reviewed-by: Jan Glauber (DigitalOcean) --- kernel/panic.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/panic.c b/kernel/panic.c index fbc59b3b64d0..fafe3fa22533 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -276,6 +276,16 @@ static void panic_other_cpus_shutdown(bool crash_kexec) crash_smp_send_stop(); } =20 +/* + * Called after a kernel panic has been handled, at which stage halting + * the CPU can help reduce unnecessary CPU consumption. In the absence of + * arch-specific implementations, just delay + */ +static void __weak cpu_halt_after_panic(void) +{ + mdelay(PANIC_TIMER_STEP); +} + /** * panic - halt the system * @fmt: The text string to print @@ -474,7 +484,7 @@ void panic(const char *fmt, ...) i +=3D panic_blink(state ^=3D 1); i_next =3D i + 3600 / PANIC_BLINK_SPD; } - mdelay(PANIC_TIMER_STEP); + cpu_halt_after_panic(); } } =20 --=20 2.47.1 From nobody Wed Dec 17 05:28:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 037B51F4195 for ; Wed, 26 Mar 2025 15:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743001938; cv=none; b=X/GNUC5jpDIt1J+QCdhpHSABAmW8eQvQcsOOcyfcFTnpG+anU36rKTMNRfay71n3fRy+nGSzlnEos096T5jtVek4/gHBBU1gRz98vAAlF+KHFRgDbNlhDHycchHq9/yhpvw9mItACB+6XUMayTQ5L+xv6f29FFVj9F0nJdNeapA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743001938; c=relaxed/simple; bh=4TyOAkV/asFeWDnvfwSBEs2wwVovEdefZTWbQE3PUDc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d1bQ67IkILoH4Oj0eq1d356wjWm+M7lgRjNc7RKZ2mvtec+3eCSmNTioSHfrpwPfscu/pAAMo0528zyzM+QR9MepVPXWmpBStabg7OGN7apK4qbYgEsD0tDlZcrucLAN5ZZMmoPSVe+xJs/cjnNiRpLDS5G77cm8KUboIym4PNU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r/9yXMM6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r/9yXMM6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84351C4CEE8; Wed, 26 Mar 2025 15:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743001937; bh=4TyOAkV/asFeWDnvfwSBEs2wwVovEdefZTWbQE3PUDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r/9yXMM69DsOEWwzDOByqNUz9caRAVeeSER0UArvgUKRklQPcOB7m4mw8qIxj0v4s ++++JSk+BARfeYRaEAPs2GGkmMQfu3toFfzlK3JfUqRGWayg/iotQguElJD6gZTy2n ZYOiHtbbBK+4sFs8VeRfszvKI58b0bYDcjDiymL2J+V/73mNo2w5loJyuXEBpqMAok 9z51cAzNWi9OaR+3RkgruvAjtrc08RA40LsPjqkmtjlaDvE/vcUJmSEA4loSogt6sl VlfgaLUrHymjh9YOu7MSrH2aOcVsr2YMfTqzZeGR9VdNr8MNQIbz+ImYe/pO5//Gxy O6gWJzaHZ1dcg== From: carlos.bilbao@kernel.org To: tglx@linutronix.de Cc: bilbao@vt.edu, pmladek@suse.com, akpm@linux-foundation.org, jan.glauber@gmail.com, jani.nikula@intel.com, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, takakura@valinux.co.jp, john.ogness@linutronix.de, Carlos Bilbao Subject: [PATCH 2/2] x86/panic: Use safe_halt() for CPU halt after panic Date: Wed, 26 Mar 2025 10:12:04 -0500 Message-ID: <20250326151204.67898-3-carlos.bilbao@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250326151204.67898-1-carlos.bilbao@kernel.org> References: <20250326151204.67898-1-carlos.bilbao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Carlos Bilbao Include an arch/x86-specific function to halt CPU once the kernel has finished handling a panic, by defining the weak function cpu_halt_after_panic(). Signed-off-by: Carlos Bilbao (DigitalOcean) Reviewed-by: Jan Glauber (DigitalOcean) --- arch/x86/kernel/Makefile | 1 + arch/x86/kernel/panic.c | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 arch/x86/kernel/panic.c diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index f7918980667a..0e4d87596f5d 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -85,6 +85,7 @@ obj-y +=3D stacktrace.o obj-y +=3D cpu/ obj-y +=3D acpi/ obj-y +=3D reboot.o +obj-y +=3D panic.o obj-$(CONFIG_X86_MSR) +=3D msr.o obj-$(CONFIG_X86_CPUID) +=3D cpuid.o obj-$(CONFIG_PCI) +=3D early-quirks.o diff --git a/arch/x86/kernel/panic.c b/arch/x86/kernel/panic.c new file mode 100644 index 000000000000..0838bb7cf9a9 --- /dev/null +++ b/arch/x86/kernel/panic.c @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0 +// Author Carlos Bilbao +#include +#include + +void cpu_halt_after_panic(void) +{ + safe_halt(); +} --=20 2.47.1