From patchwork Fri Jun 14 09:59:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 804530 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) (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 44D3E19B580; Fri, 14 Jun 2024 09:59:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718359171; cv=none; b=RnZ2YkT+7BReNYUsQ3svRlzqNR/8jXx+CZkE1TvFjcyGGxJ4gTApAuCDRz0WKhmB13Zp7KEGVMD3pXiJHOp8nu9sID5njNdofjMqvDyEBgmAFelZWxFF2xuRWB6sxDml7hhrFhdRBvpBm5DT9kM1higpRnOMrBLiJ1uVCfSVJWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718359171; c=relaxed/simple; bh=9vhYdxi0S8qujCAi6MDx/KbyKlcMikSIOmV4M3XKOeo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jhdEBSEXsIrzNloVwdgR6DpfPriNW/L1q9YskRJh9rg8Jpi70oMl9EXMXXv5NfQOmzJWMhi8KMSc4po7ey+0cm4YhUaanj4Yxnvjrqa+TNSy3WP3ARB65NE4WLLZWf9hKcLSMxl5P+N8r1kToarocmI4vLXicE13Ns51LzS/QSs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.helo=mgamail.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ffcO+MOM; arc=none smtp.client-ip=192.198.163.16 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.helo=mgamail.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ffcO+MOM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718359170; x=1749895170; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9vhYdxi0S8qujCAi6MDx/KbyKlcMikSIOmV4M3XKOeo=; b=ffcO+MOMImo1xvHOQm3p703QGVE9m/PWbMdXCKxIu4XumHE/R18Iysna E35xmKTCWzDRFpgEdzqY6jasLAazUYrZfxF//CCkBorsv7cVcX1qcoYBV Ax9sTSeXi+pt2iAzzxRTK4Rsro7xgNhYxyKyLhbyNuEBhO4kMN14Kuwd/ 9fbnxuLs05aS3GsKLejClTbnWTlkJLAbq3OmxZYt1H2gdUthjdvQtcl/L +MtYRHScUpgItnxwOJcW39Soc++2PpKiEPv3DkdfE9fen4CQx80Ovy67Y eOxySmZbStRi/V1U0F1RW7kuZ5MYpG6L4r2FZ+nqvx5tiw74rZ4j9ums8 g==; X-CSE-ConnectionGUID: CuRuUGh+Rlm15xJJQqIm4w== X-CSE-MsgGUID: QRlmPp9ETau+T9sa9k2PMQ== X-IronPort-AV: E=McAfee;i="6700,10204,11102"; a="12072456" X-IronPort-AV: E=Sophos;i="6.08,237,1712646000"; d="scan'208";a="12072456" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2024 02:59:29 -0700 X-CSE-ConnectionGUID: GSw/siUMQveJZstD2MXDHg== X-CSE-MsgGUID: /HWnI9WBSBG29VhDnobarw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,237,1712646000"; d="scan'208";a="44995897" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa004.fm.intel.com with ESMTP; 14 Jun 2024 02:59:22 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 4D5162B56; Fri, 14 Jun 2024 12:59:09 +0300 (EEST) 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" , Ard Biesheuvel , Baoquan He , "H. Peter Anvin" , "Kirill A. Shutemov" , "K. Y. Srinivasan" , Haiyang Zhang , kexec@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-acpi@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Tao Liu Subject: [PATCHv12 16/19] x86/smp: Add smp_ops.stop_this_cpu() callback Date: Fri, 14 Jun 2024 12:59:01 +0300 Message-ID: <20240614095904.1345461-17-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240614095904.1345461-1-kirill.shutemov@linux.intel.com> References: <20240614095904.1345461-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Acked-by: Kai Huang Reviewed-by: Thomas Gleixner Tested-by: Tao Liu --- arch/x86/include/asm/smp.h | 1 + arch/x86/kernel/process.c | 7 +++++++ arch/x86/kernel/reboot.c | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h index a35936b512fe..ca073f40698f 100644 --- a/arch/x86/include/asm/smp.h +++ b/arch/x86/include/asm/smp.h @@ -35,6 +35,7 @@ struct smp_ops { int (*cpu_disable)(void); void (*cpu_die)(unsigned int cpu); void (*play_dead)(void); + void (*stop_this_cpu)(void); 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 0c63035d8164..1b3d417cd6c4 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -832,6 +832,13 @@ void __noreturn stop_this_cpu(void *dummy) */ cpumask_clear_cpu(cpu, &cpus_stop_mask); +#ifdef CONFIG_SMP + if (smp_ops.stop_this_cpu) { + smp_ops.stop_this_cpu(); + unreachable(); + } +#endif + for (;;) { /* * Use native_halt() so that memory contents don't change diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c index bb7a44af7efd..0e0a4cf6b5eb 100644 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -880,6 +880,12 @@ static int crash_nmi_callback(unsigned int val, struct pt_regs *regs) cpu_emergency_disable_virtualization(); atomic_dec(&waiting_for_crash_ipi); + + if (smp_ops.stop_this_cpu) { + smp_ops.stop_this_cpu(); + unreachable(); + } + /* Assume hlt works */ halt(); for (;;)