From nobody Sat Dec 27 07:08:49 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (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 2979548CE5 for ; Fri, 22 Dec 2023 23:52:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ToNfnQmv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703289152; x=1734825152; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RhnEAsovR1/on/ST7snqUo3geUenPPWRU+fc0vbg0rk=; b=ToNfnQmv693/wPJpgF6e6+MtJYG0hrOxPDPvzp7iyjtr4z3CzITutxeG cdSDiNklo9I91NAoc5Heux1RS0jYGxtdI45/dqf4zQl5XLPs39iRFoQNw B4+7ZEH/8Om2dGTv4UvVTMEqqjhUtx6Zalzirz7Z0u/P/THXlRLerBXfB q5qG8X3oe69sf3cECNiD9wM3nWcT4/JEN4RlI2MNJeZKP68rI4C33+mRu l7FA2xM1gbaYjDnBfpZKbLxN/J9Vh2s/VGNvbCuJF/rLJ7OZc1ggzFike O2Xwa/RDQiNXlqsFq4XTNNJou0O0/Owl8osl2+lND1W/OwSbz8WdYqc9v g==; X-IronPort-AV: E=McAfee;i="6600,9927,10932"; a="395063351" X-IronPort-AV: E=Sophos;i="6.04,297,1695711600"; d="scan'208";a="395063351" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 15:52:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10932"; a="900623014" X-IronPort-AV: E=Sophos;i="6.04,297,1695711600"; d="scan'208";a="900623014" Received: from jeroenke-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.35.180]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 15:52:22 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 69FCD10A4E0; Sat, 23 Dec 2023 02:52:12 +0300 (+03) From: "Kirill A. Shutemov" To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , "Huang, Kai" , Baoquan He , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv5 14/16] x86/smp: Add smp_ops.stop_this_cpu() callback Date: Sat, 23 Dec 2023 02:52:06 +0300 Message-ID: <20231222235209.32143-15-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231222235209.32143-1-kirill.shutemov@linux.intel.com> References: <20231222235209.32143-1-kirill.shutemov@linux.intel.com> 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" If the helper is defined, it is called instead of halt() to stop the CPU at the end of stop_this_cpu() and on crash CPU shutdown. ACPI MADT will use it to hand over the CPU to BIOS in order to be able to wake it up again after kexec. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/smp.h | 1 + arch/x86/kernel/process.c | 20 +++++++++++++------- arch/x86/kernel/reboot.c | 12 ++++++++---- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h index 4fab2ed454f3..390d53fd34f9 100644 --- a/arch/x86/include/asm/smp.h +++ b/arch/x86/include/asm/smp.h @@ -38,6 +38,7 @@ struct smp_ops { int (*cpu_disable)(void); void (*cpu_die)(unsigned int cpu); void (*play_dead)(void); + void (*stop_this_cpu)(void); =20 void (*send_call_func_ipi)(const struct cpumask *mask); void (*send_call_func_single_ipi)(int cpu); diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index b6f4e8399fca..65c7971defd2 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -835,13 +835,19 @@ void __noreturn stop_this_cpu(void *dummy) */ cpumask_clear_cpu(cpu, &cpus_stop_mask); =20 - for (;;) { - /* - * Use native_halt() so that memory contents don't change - * (stack usage and variables) after possibly issuing the - * native_wbinvd() above. - */ - native_halt(); + if (smp_ops.stop_this_cpu) { + smp_ops.stop_this_cpu(); + unreachable(); + } else { + + for (;;) { + /* + * Use native_halt() so that memory contents don't + * change (stack usage and variables) after possibly + * issuing the native_wbinvd() above. + */ + native_halt(); + } } } =20 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c index 16dde83df49a..738b3e810196 100644 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -881,10 +881,14 @@ static int crash_nmi_callback(unsigned int val, struc= t pt_regs *regs) cpu_emergency_disable_virtualization(); =20 atomic_dec(&waiting_for_crash_ipi); - /* Assume hlt works */ - halt(); - for (;;) - cpu_relax(); + + if (smp_ops.stop_this_cpu) { + smp_ops.stop_this_cpu(); + } else { + halt(); + for (;;) + cpu_relax(); + } =20 return NMI_HANDLED; } --=20 2.41.0