Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1117020rdb; Fri, 22 Dec 2023 15:55:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVDpCaYPtRK0wYqaQvRvfGltRwXcolIXBpIUua7Ski05i0MdX9tBAgVSYWpp+MzMljjV5D X-Received: by 2002:a05:6a20:78a2:b0:194:a32d:b6aa with SMTP id d34-20020a056a2078a200b00194a32db6aamr2113969pzg.122.1703289337000; Fri, 22 Dec 2023 15:55:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703289336; cv=none; d=google.com; s=arc-20160816; b=wuUvjY2Z8goOyX06k+XOilHmK7como0D5baTUKuAqOGFgjjBLt379l31+RKcaqe/0p sD8geH9eLzeJSSHqVFN+Sv8hGBDcstPych6w+tg8+PyX8OY/MJrbsLuHDeKIBhBRV6X8 KUTqK5jJlpD9l2WKnTAC2RQrXyAZThcmFLPD3PVBgGexr4wu4462L2i/RBCMKgf1SUaq fQ1KAPXKgZBo5puVTH/SK2P9B1Wado8HovOIN9s1mZCfHUIi/JYscGMTu01E5dhqjzMx Zpp0o4DfoJCtAllRdLPydUlcB2ySDop72X/a4h4+m21qOpXXYE14yXxa/+IAQyyP0+8s qhSQ== ARC-Message-Signature: i=1; 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=F10G02aGVi1y/iSrdNRFKEDV7CZrvcc81PD87atfSjE=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=MW9FAI5u2asL53/Fo4TFpCzsT7Sg9c/bx7VAawDWZo3zsTyQkcNz2u3FyEvVDRh8M8 xx0qZ7sMFWcsOBPLdXfl42TzHF2F6rrdqK2cucd4B/xplVfYt+mWfjbTaXqDfgRcKP9M uy+LF/jM00MtjbxsSEF0AZ2vIt0dTOpyAIOruufmUriQAeFkgWSMEl++Z96E76g85dKY rZgVSZ23TLj0L7/L93vPaFEQIlecYKBsOsHkseSUMZi5yTkrMcSK1WNiVNK7Ec0daF1Q mUNRDF3ChvZuVlX07DwBttb27m49NDbLCKIbfh4dA48ZZOgH83qaIH0C7xSBw4brbtM6 UG0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ToNfnQmv; spf=pass (google.com: domain of linux-kernel+bounces-10141-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10141-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n9-20020a6563c9000000b005cd84f2c7a9si3887823pgv.763.2023.12.22.15.55.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 15:55:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10141-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ToNfnQmv; spf=pass (google.com: domain of linux-kernel+bounces-10141-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10141-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8AF71283C75 for ; Fri, 22 Dec 2023 23:55:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 404583BB36; Fri, 22 Dec 2023 23:52:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ToNfnQmv" X-Original-To: linux-kernel@vger.kernel.org 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 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: 8bit 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); 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); - 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(); + } } } 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, struct pt_regs *regs) cpu_emergency_disable_virtualization(); 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(); + } return NMI_HANDLED; } -- 2.41.0