From patchwork Fri Dec 22 23:52:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 182818 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1395133dyi; Fri, 22 Dec 2023 15:56:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGj4TlXG6AQVjzY1w/oiijAf5EJPZbK0q9fIPlMALtk8vOBCd08TEmU1/GMWacsiVQXRYbw X-Received: by 2002:a17:907:76eb:b0:a23:6e35:d311 with SMTP id kg11-20020a17090776eb00b00a236e35d311mr1257282ejc.153.1703289377026; Fri, 22 Dec 2023 15:56:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703289377; cv=none; d=google.com; s=arc-20160816; b=hoUWZGUdQEmVIQhOwtB9xg5jgQFfozjnxKqDip0gCRaMJ7k0Paekj/YF0vN94qBLbP oR6IhhFyq3IC8E0N2od3M4nSrNNZI63RCBTtkruxSQ92dWAfevl1K6fbp5B4T/1xCyi7 XVBENubcQqE7dAsrtwfrgKwhckFM2NWJKljutU9+lMPsbIT4j1Eb5T1To7haBwV3HoZh DqoFrpUrOpeDCJD4qfmtsiOhEEcLcKHUQ593YusQYI7uViRy9U4FNmNVgCVD1/Yc1m37 xArlddpr38LVPkfChb7MSpKpw6tUwQ6Cpcg2n9KshzLu5Kyl6K2rIuexjjCiExFtBKpt pTiQ== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10141-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u5-20020a1709060b0500b00a235eb079b9si2295150ejg.633.2023.12.22.15.56.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 15:56:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10141-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10141-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 am.mirrors.kernel.org (Postfix) with ESMTPS id A497A1F2119A for ; Fri, 22 Dec 2023 23:56:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2506D4CDE7; Fri, 22 Dec 2023 23:52:36 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786028361631320746 X-GMAIL-MSGID: 1786028361631320746 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; }