From patchwork Tue Feb 27 18:16:14 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: 207474 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2995582dyb; Tue, 27 Feb 2024 14:16:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVUTqJVvaofS/+AN23S7eEI5OeBL8njq08BId711vSI/JHZAQghK5q9nKSq8/PyRjW7zLTIynoD6L9MX20GzASDIMMINQ== X-Google-Smtp-Source: AGHT+IESSpQKfRBddVt/gkXIIs1cWJis0Oa2E16q9iK4tLZWqi56RWcvKRtDRwnfOnr+bus9pxEL X-Received: by 2002:aa7:d916:0:b0:564:4504:cc2 with SMTP id a22-20020aa7d916000000b0056445040cc2mr8242003edr.16.1709072217215; Tue, 27 Feb 2024 14:16:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709072217; cv=pass; d=google.com; s=arc-20160816; b=St0Gcu81F/B/eE6iC5b7tIdIW/20nt5Tc3BzEf0PM5UcbCTmeRQ5vx3TFoaAGuad/8 CCZ9C5JdLxqL/6ECqcWCrW0TEdWbiBZHWPuSV6ihgM8OdsF0rzwO9qT9w6P+VZwqrDnN 8obbXaZppFTnPSDT38jniMOSWKLiCloyzOxF5LPU9Bh0fuP6Jq5Uzsfww64YieBnQp4E 8dUpEkuFE5/edBp+jEp5HqxNB/pCJJ5ZsmffP1Ly70r57BQua8e0RGmjq1hGco2vu8gm Q3MNuwhFZORWFbyeq5T6B35UVf10uqcfByfvK3FwGYHtIvFkVNSr9sv1QZu9NH+nRzyN gw7Q== 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=OhSe+Z01wtsNPO2DlJRg/XljcMsm9Jtupl3TZ04Lwgk=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=KqF9r6dXod1LwSNw/yE0RAM9VesA/uktgOvGyRlVF8OAE+srm7UQ2Vo6gyDhK8vIK7 xboIIn+Qv7l/zTLVZhVd854vgIjttv4bAv7eB4LH1+XRj5C2cg0jaD/Z3QVT658QfMCy SnrVAxRsReRS5W7gElzCY6hMkf1fkSuvScuGwRRrHD6jFnlGMNgHMlgZl0JMeWXhiqXT tqmbroo/bo4HcUGBgdWqoiA82azam8czwU8D388h8VDmjhsuWrVWfdeMSaoR3xMiCw7K gaQLAZABOw5hwTF8l3914SvqJNmeuq3aYnhBcpZ7NaeSYCtUc1QLP7FKRxHW8jMuyLa7 jATg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="iv/t1Yqr"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83819-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83819-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 ba14-20020a0564021ace00b005655dc8d470si1063664edb.611.2024.02.27.14.16.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:16:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83819-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="iv/t1Yqr"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83819-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83819-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 2B54F1F2C138 for ; Tue, 27 Feb 2024 18:19:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 70FE5157E6E; Tue, 27 Feb 2024 18:17:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iv/t1Yqr" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 92EF514E2C8 for ; Tue, 27 Feb 2024 18:17:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057826; cv=none; b=o+gKiUBBIL4037CcsTmSLz7l0eVtncKzmm42fcsSz9LYvmFioZwNgW48nIgWctgqnyePrA32A7pnTOIY87x1shxpwIZ2TEopPjHEZQzpb2aN2LGucBLBCr9CxAG5RH1ZEKBc8ZAPw2zcDifKtuccENxDxY8knJ3QNM4NwIimhmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057826; c=relaxed/simple; bh=urUcJtKDz0udsDAvAz2j1S+q/fX/vhzTd+7x3OIZGzI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cqg2V+AlFHUbZd4FoDbqu27yloI7j3hQSqbOtcdZvKcqj8rhk7AiKGoTAudQ3IykomPD/lPpNcLotSP3KKV8CiXo+IJALQSDToqCsjFJo8s5H1ITDl29tbCnNFmzJN+EisBQj3DhqNz30U5le9iYVSjT1JS7oc1kqZHNows6yHA= 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=iv/t1Yqr; arc=none smtp.client-ip=192.198.163.8 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=1709057824; x=1740593824; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=urUcJtKDz0udsDAvAz2j1S+q/fX/vhzTd+7x3OIZGzI=; b=iv/t1Yqr8vjqwHXgbP6YiVZvWoocZbti5avJSr6vgrjvPWjYW3YAdzmn HoDPl9Jailvai/ltb0RI6Ou2fJ3S9fVmsWD7UKqalWr/GPJHAFe8KXw0V VNPEvBUVr9Fp5FWyJPANCik50vOQ3mi5pzpfJsjUy6vNV+jf0IABs+/NW LPOrpHVWKu5E1eslfrRbH7wwX5TcZpXBjy+6O3OfTZZC/akDdlxy7dMIE +2cowM/yNBbhHqPf6ftN3nTJzpNQudRjT2FKrgewdm+QVPkFMDvnVIFGY a5moE6S1XVD8wqNzHOpKRb7HAQC7SHBfIj0/7af/dm9SOaLYlgvuAdZmd w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966170" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966170" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 10:16:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032740" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032740" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 10:16:26 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id EE59BA97; Tue, 27 Feb 2024 20:16:19 +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: [PATCHv8 14/16] x86/smp: Add smp_ops.stop_this_cpu() callback Date: Tue, 27 Feb 2024 20:16:14 +0200 Message-ID: <20240227181616.3032032-15-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227181616.3032032-1-kirill.shutemov@linux.intel.com> References: <20240227181616.3032032-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: 1792092109626278216 X-GMAIL-MSGID: 1792092109626278216 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 (;;)