From patchwork Wed Jan 24 12:55:55 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: 191584 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1018886dyi; Wed, 24 Jan 2024 06:20:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGy56Wp4AMN4sdeTiiOAMURfX1etjUYkyl2b/HCUopgCY9A3AFrsGpcLQkcNBRbZr/5T5NZ X-Received: by 2002:ad4:4eed:0:b0:686:a07f:cd04 with SMTP id dv13-20020ad44eed000000b00686a07fcd04mr2708437qvb.110.1706106015864; Wed, 24 Jan 2024 06:20:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706106015; cv=pass; d=google.com; s=arc-20160816; b=zxf3l+M5mQVRNwqbzuvzyqrPqX1ZESCprsrKOYgMiFHYu67tsVlsM+wtIqLnq4adG1 36BHehAJ0iOkfXfUbB6ZwI5Q7JtvBTr2ysm/55B4M2uss5TkReIEBm57b4DpAFKuRa1X vZWbr494TlVh1oxsLqcERS/waVWXm02P0cNKU3KEH/ubbjul7zJAlzg+hgDL8l1R7Iqs EG3ONQ9ycuz2h0un5hAC8Ys4j/lfYOX2NfE+frum5em88jkFLrb7i0b2TsQz3QCJIUQq DKDN33LXZwJZ/U8T5uwJensvBuzEOd1DoIxdAos39BM3BD84fa5t9b2F9kNyqqMTpQBT xwPQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=uUwKCPpS3rWhYaj/Bz1jxeNUFv4P+9IPCpw+Jxi9dLI=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=sJZSs5/1+pFD5xUBJTi9d1Qrv3zOiTU1IGmx7tzFOsC4g0IRtp06Vl7EpgQTBVTBed phvMAW/8UuSk5VeqWcpYkGf+gDQbqY3JMHQzfl5z8w0l1fOXLU1szT+ovrShIwaI+0zU NfCiT4C5W8Ric0yYT1mVqwjpwj2aezdXIz1jB9Z7LjmCosshAOriAHOOk+OaPwhjj9cD X1+6BLEcdkYMnAg59YXQgxEYs4eV4WoqsxT0ZGX6OZQgzVJmIgkVGmTI3IprH4rzP+qN +LvwPyKj4/d4Z0RFBKjdBTUFdnTmSDvkG1wrqpxtJwPTmCeD2Qmy6RDwgOmryWRxEiqk BbzQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eiFUuutV; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-37036-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37036-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id w16-20020a0cdf90000000b00684771ba581si10287190qvl.436.2024.01.24.06.20.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 06:20:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37036-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eiFUuutV; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-37036-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37036-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 414E91C231B9 for ; Wed, 24 Jan 2024 13:00:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB2AE77F24; Wed, 24 Jan 2024 12:57:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="eiFUuutV" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) (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 CD1DF7E76F for ; Wed, 24 Jan 2024 12:57:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706101065; cv=none; b=QRbswA9GHW5nP57viq4AzQTf/gW3XWbc3gCsYsyO1N/Np1NrVL2dkvQtSPK6UN1kpP+0dtdy3u9uk+r8x5bv7aDXecwSGR9Tr4BPjA+w9gSGr+zqQ5O+Ynj/riEl0IFZ4cDgIjFQxcmGRFSPJIrc/BrlCZ5ddgzHC2/IwjItwAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706101065; c=relaxed/simple; bh=tc3l0nnpCsD+Lhvt4gYpUVgX39QxTGQjtHhfAwFvtwg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uBf1RMyn4535rOQ6hHqVwZNY3zRSgaKGLPeYwamBM8HxOO6BQ6E4fazhY2vYojzgj6BGNrzjiQ/ZtHm0gEXgkBi9nVpXDPlELGIV8Vcjnd5prk2c48nCMCImKHsl2SwydyS3Pf5NQxptnm0vJzJSdgzjk6JeObxedZshhAiZ6F4= 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=eiFUuutV; arc=none smtp.client-ip=192.55.52.93 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706101063; x=1737637063; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tc3l0nnpCsD+Lhvt4gYpUVgX39QxTGQjtHhfAwFvtwg=; b=eiFUuutVLnHxtOzV/xeNnPaxSkjWPJgka5xbLkHkH+R0Vhs7RWKA787j HoOBXfnbDiU2XHUaFVRccX9ExsIEan+Pj85EEixJAR4z8AUIZ861XprMG 2XUvOly4LglDebXKJ9eoWzod5E9ltzemrRHQLNQu+IcZY8LZSMzrQiN6/ xssUxPJE4QaCOrWeUALruz+geQDRnFo+qW2CDlqgdUQ1xv2/M0nwHwm9h +stXafFJbDo8UEFlaI4qR3b9U6cQD/GZ2E6CaLPyuwY7OALgU+hbWRyw1 x05ho+ycAhHW2mjtq4h930ZuQHfU69gnzG9XKRaSzr7VtJRsKAH1004jf g==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="398990886" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="398990886" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2024 04:57:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="876685865" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="876685865" Received: from black.fi.intel.com ([10.237.72.28]) by FMSMGA003.fm.intel.com with ESMTP; 24 Jan 2024 04:57:38 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id CA188ADD; Wed, 24 Jan 2024 14:56:02 +0200 (EET) 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: [PATCHv6 14/16] x86/smp: Add smp_ops.stop_this_cpu() callback Date: Wed, 24 Jan 2024 14:55:55 +0200 Message-ID: <20240124125557.493675-15-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124125557.493675-1-kirill.shutemov@linux.intel.com> References: <20240124125557.493675-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788981822075399793 X-GMAIL-MSGID: 1788981822075399793 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 --- 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 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); 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 ab49ade31b0d..00c1b957476d 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -835,6 +835,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 0574d4ad6b41..0a75efe579c0 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 (;;)