From patchwork Tue Feb 27 18:16: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: 207442 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2972936dyb; Tue, 27 Feb 2024 13:23:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU9zwiYxUZBV3aQkvl7COHbseFNTPVhBAcsIrWrj8eKBH+nMbZZaKS0RMVUu7CAjkl6BAGX91feUcVCecXx9GHkrzQu+Q== X-Google-Smtp-Source: AGHT+IFRYBMOjXvwD12dP+dbL6fxO8yS1ktefy8NVEofWYMfrbm2/lbM6x5nl5ot/m4yZuaLDqxJ X-Received: by 2002:a05:6402:2036:b0:566:5a4b:b49b with SMTP id ay22-20020a056402203600b005665a4bb49bmr618914edb.33.1709068996690; Tue, 27 Feb 2024 13:23:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709068996; cv=pass; d=google.com; s=arc-20160816; b=gnu7EFmuT6NamrQ5Q3vFzQ+9WL0uIlbeSaWV8Xl/yBUVDJas6R2HhrggOAUtr/zSir x+qkCvOuVcDizLbjfMu1TPo7nWNFOh6l81H4PB7+vfF7oti2DTGGyOBfsEACTndKNH9z UqI/hoVMW9zOL0x5MxZpLdTfe/7dmp8tijZnYGXYs/xJ97+/CTn1aOVsUtkhncRPEKhO nrlgNXLKBeS7RL68VUfAatr52pPEmQHJO8twj91LlfPtu8nsz3ovURdgNAQL5oKGCQsd s1ULRqRAbXbGJ4yPc90TKzm1OwSnH2wmLFAnD5NshF/f2asCqrCJX8fK7T/Hfb2cSlt2 tgjA== 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=ggivcp34W9ZKldlp0j46NnLvy91MR7Cbf6oBjb5ZF5I=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=k7hdH6cPKnvTBUT1qfWeMuW4nY+lJ19auYi1X9yFi7/KJiyco5/97yslYgt9j0VPb0 9a3ZISM6eNqbrc1rSmIVf+1BRaJybJsco57gdRWHlUaRwTsq3ovsNo02U1UEO/A3AI8g onUrMryaNgmXn0KO/vHwbyGmjXNjUIkpYLbxkQmEIZq1wF637IQM0H38NUfJMjvcQ9yO GozEibkOS7xvtKp7mhPRhXU7Jb08taavU7GXGO0H2uOXqeNhrIZRoO2+F6cQBjLVkUwl 2qV3+zrzYb96p2NeAlzvnv/x/17jc3SMC/EgDHMNq9t2HN2jGV3PEKHG7WnX17QnC+Td ybFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EUDZfWHv; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83812-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83812-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. [147.75.80.249]) by mx.google.com with ESMTPS id s11-20020a50d48b000000b00565bc93ae7esi1038176edi.295.2024.02.27.13.23.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 13:23:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83812-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EUDZfWHv; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83812-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83812-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 53A6C1F2ACE6 for ; Tue, 27 Feb 2024 18:18:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 72E9C14EFF4; Tue, 27 Feb 2024 18:17:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="EUDZfWHv" 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 71069148FE9 for ; Tue, 27 Feb 2024 18:16:58 +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=1709057820; cv=none; b=KAeFefO7kDYP+V9WczC13yYtS1O2uJ0/D/aMTTnOfpr1lzc+pOAcJN997QO0s1UMPtT+QvXoGh8fyOCseN48NDlRbjSajcYZ5o7QJVjMYmMlTAOEp00g+ENBccpJCZ9q1q4E2QY3N3ZCJrdBFcMJ+QQTavohQAJuh6SBZe4AD/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057820; c=relaxed/simple; bh=qz1krj0wC55JXx44sTGWHpxuKY8Fuz6UzO1qVRE49gA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EZnJPYvZs/3UEP7fuz9h4Mr7/JmsRYZ1v0ZR+WyYMdArcu27Azas8JdBpqoltMxDmCXZ7qpAadzJpEKv2xzl8rS555oQIWYQ5+uZEkgEmgVpJyKOqznm0vm05KFwX7IU3P3adiAOPvX8ywAf+vIIZYWM3j9VX5olGFqhsDoM5qc= 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=EUDZfWHv; 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=1709057818; x=1740593818; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qz1krj0wC55JXx44sTGWHpxuKY8Fuz6UzO1qVRE49gA=; b=EUDZfWHvrvHSq3qyXlX6AtCICWC1La3+UinDCLzNxbgsssVmZSY28cCs UpcIw42n91VYV/Al2wGpfsj9KLnhveAsBTIJJ/kvox9YsV7MKx2p/twLQ KnsprihuTt+p7f8C4wZrS/74NjvksRLIRK68e0uevk0/DJKdfHhh+ozEk +kA8WsMm0TmWHGWzrDmcu5UQ6yyNWaA9lsR/dcSNgTN524yXhweWy3ykB wTQeAnE+p+SjZkGqTO8u8d8LU8H3KAFBTWoLn6QgVy9rYDtAiP7OmaR9U jm2bvLM6JfVoJWKI827Nbr4smBZak1wmBgxf8e26Fe0EQudqRpYNYm6WJ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966080" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966080" 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:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032713" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032713" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 10:16:20 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 3C2DD192; 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 01/16] x86/acpi: Extract ACPI MADT wakeup code into a separate file Date: Tue, 27 Feb 2024 20:16:01 +0200 Message-ID: <20240227181616.3032032-2-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: 1792088732358169482 X-GMAIL-MSGID: 1792088732358169482 In order to prepare for the expansion of support for the ACPI MADT wakeup method, move the relevant code into a separate file. Introduce a new configuration option to clearly indicate dependencies without the use of ifdefs. There have been no functional changes. Signed-off-by: Kirill A. Shutemov Reviewed-by: Kuppuswamy Sathyanarayanan Acked-by: Kai Huang --- arch/x86/Kconfig | 7 +++ arch/x86/include/asm/acpi.h | 5 ++ arch/x86/kernel/acpi/Makefile | 11 ++-- arch/x86/kernel/acpi/boot.c | 86 +----------------------------- arch/x86/kernel/acpi/madt_wakeup.c | 82 ++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 90 deletions(-) create mode 100644 arch/x86/kernel/acpi/madt_wakeup.c diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 5edec175b9bf..1c1c06f6c0f1 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1108,6 +1108,13 @@ config X86_LOCAL_APIC depends on X86_64 || SMP || X86_32_NON_STANDARD || X86_UP_APIC || PCI_MSI select IRQ_DOMAIN_HIERARCHY +config X86_ACPI_MADT_WAKEUP + def_bool y + depends on X86_64 + depends on ACPI + depends on SMP + depends on X86_LOCAL_APIC + config X86_IO_APIC def_bool y depends on X86_LOCAL_APIC || X86_UP_IOAPIC diff --git a/arch/x86/include/asm/acpi.h b/arch/x86/include/asm/acpi.h index f896eed4516c..2625b915ae7f 100644 --- a/arch/x86/include/asm/acpi.h +++ b/arch/x86/include/asm/acpi.h @@ -76,6 +76,11 @@ static inline bool acpi_skip_set_wakeup_address(void) #define acpi_skip_set_wakeup_address acpi_skip_set_wakeup_address +union acpi_subtable_headers; + +int __init acpi_parse_mp_wake(union acpi_subtable_headers *header, + const unsigned long end); + /* * Check if the CPU can handle C2 and deeper */ diff --git a/arch/x86/kernel/acpi/Makefile b/arch/x86/kernel/acpi/Makefile index fc17b3f136fe..8c7329c88a75 100644 --- a/arch/x86/kernel/acpi/Makefile +++ b/arch/x86/kernel/acpi/Makefile @@ -1,11 +1,12 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_ACPI) += boot.o -obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_$(BITS).o -obj-$(CONFIG_ACPI_APEI) += apei.o -obj-$(CONFIG_ACPI_CPPC_LIB) += cppc.o +obj-$(CONFIG_ACPI) += boot.o +obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_$(BITS).o +obj-$(CONFIG_ACPI_APEI) += apei.o +obj-$(CONFIG_ACPI_CPPC_LIB) += cppc.o +obj-$(CONFIG_X86_ACPI_MADT_WAKEUP) += madt_wakeup.o ifneq ($(CONFIG_ACPI_PROCESSOR),) -obj-y += cstate.o +obj-y += cstate.o endif diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c index 85a3ce2a3666..df3384dc42c7 100644 --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@ -67,13 +67,6 @@ static bool has_lapic_cpus __initdata; static bool acpi_support_online_capable; #endif -#ifdef CONFIG_X86_64 -/* Physical address of the Multiprocessor Wakeup Structure mailbox */ -static u64 acpi_mp_wake_mailbox_paddr; -/* Virtual address of the Multiprocessor Wakeup Structure mailbox */ -static struct acpi_madt_multiproc_wakeup_mailbox *acpi_mp_wake_mailbox; -#endif - #ifdef CONFIG_X86_IO_APIC /* * Locks related to IOAPIC hotplug @@ -370,60 +363,6 @@ acpi_parse_lapic_nmi(union acpi_subtable_headers * header, const unsigned long e return 0; } - -#ifdef CONFIG_X86_64 -static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip) -{ - /* - * Remap mailbox memory only for the first call to acpi_wakeup_cpu(). - * - * Wakeup of secondary CPUs is fully serialized in the core code. - * No need to protect acpi_mp_wake_mailbox from concurrent accesses. - */ - if (!acpi_mp_wake_mailbox) { - acpi_mp_wake_mailbox = memremap(acpi_mp_wake_mailbox_paddr, - sizeof(*acpi_mp_wake_mailbox), - MEMREMAP_WB); - } - - /* - * Mailbox memory is shared between the firmware and OS. Firmware will - * listen on mailbox command address, and once it receives the wakeup - * command, the CPU associated with the given apicid will be booted. - * - * The value of 'apic_id' and 'wakeup_vector' must be visible to the - * firmware before the wakeup command is visible. smp_store_release() - * ensures ordering and visibility. - */ - acpi_mp_wake_mailbox->apic_id = apicid; - acpi_mp_wake_mailbox->wakeup_vector = start_ip; - smp_store_release(&acpi_mp_wake_mailbox->command, - ACPI_MP_WAKE_COMMAND_WAKEUP); - - /* - * Wait for the CPU to wake up. - * - * The CPU being woken up is essentially in a spin loop waiting to be - * woken up. It should not take long for it wake up and acknowledge by - * zeroing out ->command. - * - * ACPI specification doesn't provide any guidance on how long kernel - * has to wait for a wake up acknowledgement. It also doesn't provide - * a way to cancel a wake up request if it takes too long. - * - * In TDX environment, the VMM has control over how long it takes to - * wake up secondary. It can postpone scheduling secondary vCPU - * indefinitely. Giving up on wake up request and reporting error opens - * possible attack vector for VMM: it can wake up a secondary CPU when - * kernel doesn't expect it. Wait until positive result of the wake up - * request. - */ - while (READ_ONCE(acpi_mp_wake_mailbox->command)) - cpu_relax(); - - return 0; -} -#endif /* CONFIG_X86_64 */ #endif /* CONFIG_X86_LOCAL_APIC */ #ifdef CONFIG_X86_IO_APIC @@ -1159,29 +1098,6 @@ static int __init acpi_parse_madt_lapic_entries(void) } return 0; } - -#ifdef CONFIG_X86_64 -static int __init acpi_parse_mp_wake(union acpi_subtable_headers *header, - const unsigned long end) -{ - struct acpi_madt_multiproc_wakeup *mp_wake; - - if (!IS_ENABLED(CONFIG_SMP)) - return -ENODEV; - - mp_wake = (struct acpi_madt_multiproc_wakeup *)header; - if (BAD_MADT_ENTRY(mp_wake, end)) - return -EINVAL; - - acpi_table_print_madt_entry(&header->common); - - acpi_mp_wake_mailbox_paddr = mp_wake->base_address; - - apic_update_callback(wakeup_secondary_cpu_64, acpi_wakeup_cpu); - - return 0; -} -#endif /* CONFIG_X86_64 */ #endif /* CONFIG_X86_LOCAL_APIC */ #ifdef CONFIG_X86_IO_APIC @@ -1378,7 +1294,7 @@ static void __init acpi_process_madt(void) smp_found_config = 1; } -#ifdef CONFIG_X86_64 +#ifdef CONFIG_X86_ACPI_MADT_WAKEUP /* * Parse MADT MP Wake entry. */ diff --git a/arch/x86/kernel/acpi/madt_wakeup.c b/arch/x86/kernel/acpi/madt_wakeup.c new file mode 100644 index 000000000000..7f164d38bd0b --- /dev/null +++ b/arch/x86/kernel/acpi/madt_wakeup.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include +#include +#include +#include +#include + +/* Physical address of the Multiprocessor Wakeup Structure mailbox */ +static u64 acpi_mp_wake_mailbox_paddr; + +/* Virtual address of the Multiprocessor Wakeup Structure mailbox */ +static struct acpi_madt_multiproc_wakeup_mailbox *acpi_mp_wake_mailbox; + +static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip) +{ + /* + * Remap mailbox memory only for the first call to acpi_wakeup_cpu(). + * + * Wakeup of secondary CPUs is fully serialized in the core code. + * No need to protect acpi_mp_wake_mailbox from concurrent accesses. + */ + if (!acpi_mp_wake_mailbox) { + acpi_mp_wake_mailbox = memremap(acpi_mp_wake_mailbox_paddr, + sizeof(*acpi_mp_wake_mailbox), + MEMREMAP_WB); + } + + /* + * Mailbox memory is shared between the firmware and OS. Firmware will + * listen on mailbox command address, and once it receives the wakeup + * command, the CPU associated with the given apicid will be booted. + * + * The value of 'apic_id' and 'wakeup_vector' must be visible to the + * firmware before the wakeup command is visible. smp_store_release() + * ensures ordering and visibility. + */ + acpi_mp_wake_mailbox->apic_id = apicid; + acpi_mp_wake_mailbox->wakeup_vector = start_ip; + smp_store_release(&acpi_mp_wake_mailbox->command, + ACPI_MP_WAKE_COMMAND_WAKEUP); + + /* + * Wait for the CPU to wake up. + * + * The CPU being woken up is essentially in a spin loop waiting to be + * woken up. It should not take long for it wake up and acknowledge by + * zeroing out ->command. + * + * ACPI specification doesn't provide any guidance on how long kernel + * has to wait for a wake up acknowledgment. It also doesn't provide + * a way to cancel a wake up request if it takes too long. + * + * In TDX environment, the VMM has control over how long it takes to + * wake up secondary. It can postpone scheduling secondary vCPU + * indefinitely. Giving up on wake up request and reporting error opens + * possible attack vector for VMM: it can wake up a secondary CPU when + * kernel doesn't expect it. Wait until positive result of the wake up + * request. + */ + while (READ_ONCE(acpi_mp_wake_mailbox->command)) + cpu_relax(); + + return 0; +} + +int __init acpi_parse_mp_wake(union acpi_subtable_headers *header, + const unsigned long end) +{ + struct acpi_madt_multiproc_wakeup *mp_wake; + + mp_wake = (struct acpi_madt_multiproc_wakeup *)header; + if (BAD_MADT_ENTRY(mp_wake, end)) + return -EINVAL; + + acpi_table_print_madt_entry(&header->common); + + acpi_mp_wake_mailbox_paddr = mp_wake->base_address; + + apic_update_callback(wakeup_secondary_cpu_64, acpi_wakeup_cpu); + + return 0; +} From patchwork Tue Feb 27 18:16:02 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: 207440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2972781dyb; Tue, 27 Feb 2024 13:22:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWK9Xlcf6a7sixai0XaX7+n3pAEwjBIH0FlnEGb7711uaWYe4rE15lJAbFEr8YsfKXpsd5pGdukcRrHk7Sdyu6LI4i+tQ== X-Google-Smtp-Source: AGHT+IG5Qh6afp07POHIm9QjZdiCmpILZqA20YgwV+pyNIiRhcHiBnmPJ20kxDa9cSeAD43kycF8 X-Received: by 2002:a50:eb4a:0:b0:565:ff41:472f with SMTP id z10-20020a50eb4a000000b00565ff41472fmr465799edp.21.1709068973410; Tue, 27 Feb 2024 13:22:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709068973; cv=pass; d=google.com; s=arc-20160816; b=Vrxi6vmPAFnKnJ9DpSEY8qwQu/D7i9XmF/NsU2w3e9WHmmU5OR5n+nweo1F3MdOg9I PSyXIx54rlx33Tm0vUelNwAUlPH5mC/Z+pmI7TFpQV9sVzxobIwn9StOfzJYL0SkXZxf 1eZpiSSoBn80mjXW8wgeyc/db9v24GBPZrLdU8NhRFOMh0WpCnryJ8IxvLaw6n+VSKZa vZ0BAPGy7XE6nPSSCdint/MxekYWHYpio1kXmfBVxz2qREpW/Vy+gfW/6wxdkgoDKZG+ 75KNfE1/VFJGCT9tqCAM2piFPStz+WH+yvYqjhBdqJbaFpATotD9ybxD3MfrRlM5UGXA yAgg== 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=OmyTK/ZD8egS/hdHc+6kQr84NCywF9FNJ49v4TdySnU=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=aU7DwbFm1e/cPcUui2z0cHCHZbbnEvXiDGz8UNpdkf1ZYJJDrXWXr8rF6dx3tTOCp9 JZd7nPWh9y6rz+9fiuViM25YvP402INL+mPjy4C5lwF+7MQDlrWBYc8w4MdTbxjBHiou ek6GSou2cXyhGAVk6qEERzgNnKrnbXaRiIRcPQ137yhnqFqtqcogEwWtLxFyKjqQzhj0 fE9pFdeas9wGt2PkbWMGOHp/SiFJi6TjZkcONT/9tvex+uqzaTSDSSKYAPuHt9ijKdR0 7auKw62S/UjytXKwZud1Zz7+wcae15XG6J8+UsmTvsw7f/fK2wxlqzK0Zk4E+KQo8/wi xOKQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LJSQ0Jke; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83808-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83808-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 di26-20020a056402319a00b005659a55527asi996888edb.532.2024.02.27.13.22.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 13:22:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83808-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=LJSQ0Jke; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83808-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83808-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 295FC1F240CC for ; Tue, 27 Feb 2024 18:17:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 36F1D149E01; Tue, 27 Feb 2024 18:17:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="LJSQ0Jke" 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 86DB8145FF9 for ; Tue, 27 Feb 2024 18:16:55 +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=1709057817; cv=none; b=OveAwgiLAwoqzLUBBRrNwTfayJ8EfExk3Zsmmj9rZ3z4hb9tydbZ5wnpE/xo8UBUk1pVLTuO4mzB0YE8g4Io5s0ORPia1Fs+S+4SK/NxdiAtZAWxucofVP5wJdU29/H52nga96ECKOeNza8FbDGPT7oCY870gMkkUoG5jwRCib4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057817; c=relaxed/simple; bh=S6F/Ky7eP00etA13aVi6LSez70wEvbCqE2JWP4lJSJ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kH8zujeso3kxzj9TkPTAVjenXmA8fz3KTD1zZp825tVJsBp0r3vE6lGEwI77e+tNb3KuHSQX4x5jg2/nvwd3dPW61v2FWoGPjLYDuNtBCBOqOfh8Llug5okpmY9b6DtzLGb8b/CMiZE+0uLU/0jOaefpl857UVBcYAMM6OttXcw= 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=LJSQ0Jke; 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=1709057815; x=1740593815; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=S6F/Ky7eP00etA13aVi6LSez70wEvbCqE2JWP4lJSJ4=; b=LJSQ0Jke0sk3DjeuNbjGISEzjE2YWKtAetLm9uaF+hGkLyDKCyYK/TqO p6XEqv+Su6ij7ePxZ5REz4syz8WZec2HbLON9+r3Gbvw003heVVfp9qiy HPck+bFYiJRjVU9O2SAC+g7L2g6XO1xawzHZ+1cJdLdbvw3csB4HLIgzm hq5VEH2IZwR+rUb4ySSx8dOsVVySPUBgXk1KG/HUrKGTppEswZ+Nz6enk zfOsNqfdyxSzE8O8ynqNu2RsXJUoREPE6d3D6LvAOmgDbyPrfl+LeVez2 vX7J0R2h6Y7/juHlizIXsnicEkvvtZ/wCbGWx2r01FpgIWLaQXw6Liwa+ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966039" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966039" 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:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032705" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032705" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 10:16:20 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 50D76426; 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 02/16] x86/apic: Mark acpi_mp_wake_* variables as __ro_after_init Date: Tue, 27 Feb 2024 20:16:02 +0200 Message-ID: <20240227181616.3032032-3-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: 1792088707704581905 X-GMAIL-MSGID: 1792088707704581905 acpi_mp_wake_mailbox_paddr and acpi_mp_wake_mailbox initialized once during ACPI MADT init and never changed. Signed-off-by: Kirill A. Shutemov Acked-by: Kai Huang --- arch/x86/kernel/acpi/madt_wakeup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/acpi/madt_wakeup.c b/arch/x86/kernel/acpi/madt_wakeup.c index 7f164d38bd0b..cf79ea6f3007 100644 --- a/arch/x86/kernel/acpi/madt_wakeup.c +++ b/arch/x86/kernel/acpi/madt_wakeup.c @@ -6,10 +6,10 @@ #include /* Physical address of the Multiprocessor Wakeup Structure mailbox */ -static u64 acpi_mp_wake_mailbox_paddr; +static u64 acpi_mp_wake_mailbox_paddr __ro_after_init; /* Virtual address of the Multiprocessor Wakeup Structure mailbox */ -static struct acpi_madt_multiproc_wakeup_mailbox *acpi_mp_wake_mailbox; +static struct acpi_madt_multiproc_wakeup_mailbox *acpi_mp_wake_mailbox __ro_after_init; static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip) { From patchwork Tue Feb 27 18:16:03 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: 207431 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2964346dyb; Tue, 27 Feb 2024 13:05:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXQETyLEQ95u9fk5Am8NALsVda6X+gmYtVFG4hArS80r/Cqa9ondWYJ1Ji8Y4xs6ntJf2Qd1/BEXXqgOJUWc43aJaKqaQ== X-Google-Smtp-Source: AGHT+IExUSeZKFlw2qvEnFP+XJdZCnazGCJTAaZ9yOK2rs92/TqfWVcRjILdNQFcmxl4yy8DgQ2D X-Received: by 2002:a05:6870:64a6:b0:21e:8c19:f716 with SMTP id cz38-20020a05687064a600b0021e8c19f716mr12745952oab.49.1709067916355; Tue, 27 Feb 2024 13:05:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709067916; cv=pass; d=google.com; s=arc-20160816; b=z5Ya36ayEavnLGswy69HkMktOMRiai2Tkli4C+yzu0j36E7aE/ljCQXQMIiqX96xBf AtEliBvIcsBwx5SBGdFW5nfGTWbF3jzw0aI0uOqHIKnnV/uAiZhhAaiIN4WIze0OaKSg X7fHDfmf84888f1/xcn9VWLkuvPQzJ0v2sotMktWkV9Xadk3aAk7a8FmHDmCI1ozuVeA 6S+k8mU9Pn4iy4IeabDdnwRrAp+YmgVui9dIKOe4OqVDppdWQO1oml0+/JW1trU0DhJn rKJNxgolOJ3dRz39h5Y3zbmodNmW+yB0JTokDdlTpVIqXMHM2Z58LHJgj2gnRQYARJrp DoIA== 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=S26fjaDFAIJ37+8snV1yUJ/yjYua3qMKaCxClShx9iY=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=mNTIiul03oAb1gtJCPHrJCH2A9NoNvPchuVLBshpydEW8iu5VXFAhL0/NXV/jkQGNJ NEWZ0E9ptwyJWHlm2gAsQw6tmwCy2RO1PjBpRUyxHJOVoBMdLGhsmaLcKYpGVwpIuydc l8mmX277fdmkVT/VwNWelN3cYG+qGI1+AyoD00qY2cAT223XO+maNthQc95/6ENFDeki 0mhrQfauv/ApbhrywLdyB9E+qG3+VH4vZ8h7dHLpasmrtobtwtG0ADhdUrpnzNAgsNzB Bndzxf8olFQ+kdVjndqG2uP7MRtmxtrV3atYeOKgG4YxIjRD92E0x/XfuwLhtzl/uFaJ Xz8Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HvBrCYbW; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83810-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83810-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. [147.75.199.223]) by mx.google.com with ESMTPS id h8-20020ac85e08000000b0042a2e4e2341si9032267qtx.780.2024.02.27.13.05.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 13:05:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83810-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HvBrCYbW; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83810-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83810-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 6BA461C254D6 for ; Tue, 27 Feb 2024 18:17:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D426B14C590; Tue, 27 Feb 2024 18:17:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="HvBrCYbW" 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 4E8401487DC for ; Tue, 27 Feb 2024 18:16:57 +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=1709057819; cv=none; b=pCSOpecwxVYbKTQDxQGOdWBmXXJ122SXhisq5kCXllKMbnsA+UlAwMawIaF1HGJsrbyHUikFuxRutubfpoaUeao2Fs83rrOmXzznofU+oc0NHO2CO+AIaeAYLq0GN/nvl3Aq53HyJcWaSCov2ee8uPoMoS7GPHB4xU3xSqfzvsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057819; c=relaxed/simple; bh=yc+q4KsjIiSfEwY6TeHFKJsFn5r2uXtVujdyv1Did04=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nQWbGD7sBLaFrJiwIDRUh0t+p5QXeLR+qdDxjdWTdacPYJt/JlM4ig4sf4BFGhtwilWRMezMsAJvlt7p9b5rEuuhKT5R2zVesDU2e9IuJR0712xGdo8oZdwYQ6T2G+LIzbkma+LdZzMlh67EKKCWUOI9V4dvSgCr38FK6xGfQ8I= 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=HvBrCYbW; 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=1709057817; x=1740593817; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yc+q4KsjIiSfEwY6TeHFKJsFn5r2uXtVujdyv1Did04=; b=HvBrCYbW2VVHmRB2bee0lpx1XcOFj9Re3d3deFpAvsUP1UFGsnkqptFl 8bCummoO31c8ANDVxVC9tw6/vsS/9EJ0MR4tmpE/fgAdC0NfD+y/zL6KD t2Nn8rT8tzyCZiROwLi/f16rHr/kFGozReowJi24OTwtELozV3Ct83jSx u1MZf9YQGOWASEkoyJwxmGZObpvnjI9UMB4cWX8SxrC1x7sKXSqDKHeLg 1rceeMFOKGWCyconhV+F9iu5R1sI1O3xQlyyq8Wg6URA+98QcpdpDCNYG gMreoOQlNZSoUiygBQfgmJHy4I2F1D8LpgqbgTW4gkKaroWBik6UAyIqR g==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966060" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966060" 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:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032709" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032709" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 10:16:20 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 5D3F8445; 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 03/16] cpu/hotplug: Add support for declaring CPU offlining not supported Date: Tue, 27 Feb 2024 20:16:03 +0200 Message-ID: <20240227181616.3032032-4-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: 1792087599864734087 X-GMAIL-MSGID: 1792087599864734087 The ACPI MADT mailbox wakeup method doesn't allow to offline CPU after it got woke up. Currently offlining hotplug is prevented based on the confidential computing attribute which is set for Intel TDX. But TDX is not the only possible user of the wake up method. The MADT wakeup can be implemented outside of a confidential computing environment. Offline support is a property of the wakeup method, not the CoCo implementation. Introduce cpu_hotplug_disable_offlining() that can be called to indicate that CPU offlining should be disabled. This function is going to replace CC_ATTR_HOTPLUG_DISABLED for ACPI MADT wakeup method. Signed-off-by: Kirill A. Shutemov Reviewed-by: Thomas Gleixner --- include/linux/cpu.h | 2 ++ kernel/cpu.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/linux/cpu.h b/include/linux/cpu.h index dcb89c987164..aa89ef93a884 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -139,6 +139,7 @@ extern void cpus_read_lock(void); extern void cpus_read_unlock(void); extern int cpus_read_trylock(void); extern void lockdep_assert_cpus_held(void); +extern void cpu_hotplug_disable_offlining(void); extern void cpu_hotplug_disable(void); extern void cpu_hotplug_enable(void); void clear_tasks_mm_cpumask(int cpu); @@ -154,6 +155,7 @@ static inline void cpus_read_lock(void) { } static inline void cpus_read_unlock(void) { } static inline int cpus_read_trylock(void) { return true; } static inline void lockdep_assert_cpus_held(void) { } +static inline void cpu_hotplug_disable_offlining(void) { } static inline void cpu_hotplug_disable(void) { } static inline void cpu_hotplug_enable(void) { } static inline int remove_cpu(unsigned int cpu) { return -EPERM; } diff --git a/kernel/cpu.c b/kernel/cpu.c index e6ec3ba4950b..7c28a07afe8b 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -484,6 +484,8 @@ static int cpu_hotplug_disabled; DEFINE_STATIC_PERCPU_RWSEM(cpu_hotplug_lock); +static bool cpu_hotplug_offline_disabled __ro_after_init; + void cpus_read_lock(void) { percpu_down_read(&cpu_hotplug_lock); @@ -543,6 +545,14 @@ static void lockdep_release_cpus_lock(void) rwsem_release(&cpu_hotplug_lock.dep_map, _THIS_IP_); } +/* Declare CPU offlining not supported */ +void cpu_hotplug_disable_offlining(void) +{ + cpu_maps_update_begin(); + cpu_hotplug_offline_disabled = true; + cpu_maps_update_done(); +} + /* * Wait for currently running CPU hotplug operations to complete (if any) and * disable future CPU hotplug (from sysfs). The 'cpu_add_remove_lock' protects @@ -1522,7 +1532,8 @@ static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target) * If the platform does not support hotplug, report it explicitly to * differentiate it from a transient offlining failure. */ - if (cc_platform_has(CC_ATTR_HOTPLUG_DISABLED)) + if (cc_platform_has(CC_ATTR_HOTPLUG_DISABLED) || + cpu_hotplug_offline_disabled) return -EOPNOTSUPP; if (cpu_hotplug_disabled) return -EBUSY; From patchwork Tue Feb 27 18:16:04 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: 207441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2972811dyb; Tue, 27 Feb 2024 13:22:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWQWfAnL3ZkUZDDx8Gy3J45ewT+0jifD0O6jeLkHKj4KRVBCDPIIQTrRXnXGap1vhV7z7SgYLQhK/zkIoKqs4IsNEEMcQ== X-Google-Smtp-Source: AGHT+IFLuEctGeH23C4WPG5WhL0uwFydusrq0g1ao6yoOt7daVZJfjKdLgHzlfcJ1sC3KLRFNCcR X-Received: by 2002:a17:906:2bcc:b0:a3e:6f98:c69d with SMTP id n12-20020a1709062bcc00b00a3e6f98c69dmr7729518ejg.63.1709068978598; Tue, 27 Feb 2024 13:22:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709068978; cv=pass; d=google.com; s=arc-20160816; b=BIYki0aMptFoEyC+4EaamYso7Qw6aYSqSeulD2SB+Fz0YnOPhBNj03SMhby321FyJQ juXq933NFFHzJYAvAraVOgTRBWSZk3wCH+UwS8eiS25csUFSlwfEyDbB6b0NUJOn+9k/ odgfz6TvAWu3aEEvN0cgc+TK3jdvKUVo5gqUIA8/Ef+5RGx5PMyu7O6NjH8DUMpusHos 1JRvpwjfQTtSW1Y8gNhTEXzR1NnO0jADW6j6cwlXRmVREp+x0wqMEFpqfZkgQUVj3Cd8 TvrEd7X4lreR+arRaiFYvlDj5iIwyB4xsnyaOreO8NWWaUrbSAxDrj4SJaDT5B3LzzZ7 nhYA== 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=iU1ZlftgLUZTKojE64KaxxDuYt8xfxFymPnSI3m2MEY=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=GKTkzBhjCDM5ckAnqM40QgIPre+5Lh927epQojkCMjc5d4+rwm6U1NVkQZRYWQ9pA/ IcFTMzdhJ7xqhdzk9N+3tTRaRuH93K5trGkrtcnrz3lG3a+K5ius0n3XsMDYXkfpTgLU DyWsA9o8vtxdayT/Cl2mDwxfO5k1s1an/DKMNfpHnQ3WSpYFsC0INyLSNC1YEzN703HD AlXiGDb/mqy4nnnBdFdlaKF2byEOQxLsZznL1gDpmQ7RwsVftA+zZuL1on8Z534xe0oK YDHmkVrdgB8sFKS5j4iugmoQDemrmWwCLXliGols68BLv65TT8eNkVVhZ5xwYZgNazx3 n/7w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ftf28WBX; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83811-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83811-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 d7-20020a1709064c4700b00a3ee5d34312si1079373ejw.1040.2024.02.27.13.22.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 13:22:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83811-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=Ftf28WBX; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83811-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83811-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 1E4341F29EC8 for ; Tue, 27 Feb 2024 18:18:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B4F914CAD9; Tue, 27 Feb 2024 18:17:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ftf28WBX" 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 E6C6414830D for ; Tue, 27 Feb 2024 18:16:57 +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=1709057819; cv=none; b=caJ3P+IHCT5xMWQuuGEE7vG7jFG0u99DXEeO7HXO1F+BkmZK+cjqkWSYWJ+/QzoaZtbPL3UhL0VJTdCo/ZBgHGroSAI7qCeGUUYcI+sWsAlMORu1nmVJcNg43YWcOYtQrOL2suvTKX6/QrJC+EdRzLuQFpHFQEi65n3fTLzUHk4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057819; c=relaxed/simple; bh=ihRAX/Eyt4LbMVM80nu0CT6hBURKtph1gZYnA+gKNPw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pF7P+xlYxLXQNoZ0AUlRR9zt9X04in4NXf04GOd74vHjr97iwXyE0joHQo7xhSEStGc5yKSmxp7KpZPKAkTX9rNEkv81XGq/VJ2d9OwCFs7eGzOG1YygdvzXmT92SofIMVlbPKpoNo3R4321VXBEnb+LyeAusS3ARkIreg2nQOw= 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=Ftf28WBX; 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=1709057818; x=1740593818; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ihRAX/Eyt4LbMVM80nu0CT6hBURKtph1gZYnA+gKNPw=; b=Ftf28WBXc2yw1cPpCjxWP+pVJItJg6QjwoT6gsPzW4JUEUgGEkck/xCY z2MULf/RoDoEezETNzCCOhXW6XicBm5tKDxBaMkrwgajagHAPoXrwkCQl xor5Ehjxg3mWa9Yro+3hLRUgCpilIcQ6T+hVyuSAJW/ZrxW/UBJAVayWD +kZ2zFBFPaSkAnyiX0zMSDn65TFZiAsmW7lVAsxHf0SmON0+2rP8i58O5 x1R8eEUeLEGtt5THcK6nTssNRUYSseZt4pt5Q6MMNSLyBHo8F3E5pyS5P nUsJhsZjOzi3oszKraUFQk6P0OIDug/+DpRgU80V/xc5cvo8Yufcdvj48 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966070" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966070" 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:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032712" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032712" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 10:16:20 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 69E614C1; 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 04/16] cpu/hotplug, x86/acpi: Disable CPU offlining for ACPI MADT wakeup Date: Tue, 27 Feb 2024 20:16:04 +0200 Message-ID: <20240227181616.3032032-5-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: 1792088712891315610 X-GMAIL-MSGID: 1792088712891315610 ACPI MADT doesn't allow to offline CPU after it got woke up. Currently CPU hotplug is prevented based on the confidential computing attribute which is set for Intel TDX. But TDX is not the only possible user of the wake up method. Disable CPU offlining on ACPI MADT wakeup enumeration. Signed-off-by: Kirill A. Shutemov Reviewed-by: Thomas Gleixner --- arch/x86/coco/core.c | 1 - arch/x86/kernel/acpi/madt_wakeup.c | 3 +++ include/linux/cc_platform.h | 10 ---------- kernel/cpu.c | 3 +-- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c index eeec9986570e..f07c3bb7deab 100644 --- a/arch/x86/coco/core.c +++ b/arch/x86/coco/core.c @@ -20,7 +20,6 @@ static bool noinstr intel_cc_platform_has(enum cc_attr attr) { switch (attr) { case CC_ATTR_GUEST_UNROLL_STRING_IO: - case CC_ATTR_HOTPLUG_DISABLED: case CC_ATTR_GUEST_MEM_ENCRYPT: case CC_ATTR_MEM_ENCRYPT: return true; diff --git a/arch/x86/kernel/acpi/madt_wakeup.c b/arch/x86/kernel/acpi/madt_wakeup.c index cf79ea6f3007..d222be8d7a07 100644 --- a/arch/x86/kernel/acpi/madt_wakeup.c +++ b/arch/x86/kernel/acpi/madt_wakeup.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include #include #include @@ -76,6 +77,8 @@ int __init acpi_parse_mp_wake(union acpi_subtable_headers *header, acpi_mp_wake_mailbox_paddr = mp_wake->base_address; + cpu_hotplug_disable_offlining(); + apic_update_callback(wakeup_secondary_cpu_64, acpi_wakeup_cpu); return 0; diff --git a/include/linux/cc_platform.h b/include/linux/cc_platform.h index cb0d6cd1c12f..d08dd65b5c43 100644 --- a/include/linux/cc_platform.h +++ b/include/linux/cc_platform.h @@ -80,16 +80,6 @@ enum cc_attr { * using AMD SEV-SNP features. */ CC_ATTR_GUEST_SEV_SNP, - - /** - * @CC_ATTR_HOTPLUG_DISABLED: Hotplug is not supported or disabled. - * - * The platform/OS is running as a guest/virtual machine does not - * support CPU hotplug feature. - * - * Examples include TDX Guest. - */ - CC_ATTR_HOTPLUG_DISABLED, }; #ifdef CONFIG_ARCH_HAS_CC_PLATFORM diff --git a/kernel/cpu.c b/kernel/cpu.c index 7c28a07afe8b..3ffdbb1f7bb4 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1532,8 +1532,7 @@ static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target) * If the platform does not support hotplug, report it explicitly to * differentiate it from a transient offlining failure. */ - if (cc_platform_has(CC_ATTR_HOTPLUG_DISABLED) || - cpu_hotplug_offline_disabled) + if (cpu_hotplug_offline_disabled) return -EOPNOTSUPP; if (cpu_hotplug_disabled) return -EBUSY; From patchwork Tue Feb 27 18:16:05 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: 207396 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2922128dyb; Tue, 27 Feb 2024 11:35:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUCVXsgfb0wlL3GZm6VKwpLfR1TXRkdHYaxSFywnPNmI5/Kmb87Si6eIhbuuohf7KW5W1mB3lfUbchJUuaZwT4xOMIgTg== X-Google-Smtp-Source: AGHT+IGk219ANcOlZN41YODrVVt8Ici1gtdcbvY+aQb/CKbAVcJO020hKcfiYcpQFiCoRRaBbCFG X-Received: by 2002:ac8:4888:0:b0:42e:6eac:12e8 with SMTP id i8-20020ac84888000000b0042e6eac12e8mr11105699qtq.0.1709062526271; Tue, 27 Feb 2024 11:35:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709062526; cv=pass; d=google.com; s=arc-20160816; b=kLcaA2cG5Xxwzhpr23m3PVzNFjTwExN2QmmMR0eGAQlY8DjuMb1Rme0ZRHT8vRQ1sl gbAN40zGtssQl0GHFYEKSiNFDfHoBZP8HqiZvFsr6FULovHX3h61Hjcb2Ye4kulvnDmP zoAXPeLMAvjtVaDBwgBrfQomS1BUrcfnTXNcLd+KiVJySrmr1IIOkgqkyrfVsGIzBI86 jbdbN0tjscteFzOFCNnPJwlLIRm1aMc64K4UhNdrnx8nGwGFWku8evOTemJcFMU4CWWQ zA3NdIWHWgcZJMDvKoISPeDa6m+V1DSbHtvSoDGKlmDCyy5hCsy+oTC+0WtwmdUJd4FA gIBw== 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=5nY5/kk8s6fYr//Cj2FkdJCG5YE9u6hL2PBs6U9nryU=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=Wa+lBkL8+4sebuwdZQtAerTm0RJZlftboG+RGBplqXQd7NGjeo2PowBevg6DU/OBeb Ia9RV3nAwjGwkdROYOOLuAR4QU4wXIlc1hFtFeKiXmxgHUcy/JjPiBDu5LCyIAgW95zQ srjOtMrMJrx1V2RFhcqMMfAB1LPheak4BBOKuMs2cfSYxFphhDpWL0btDx9wB27tiHI9 mDhHBVfDtQD1pOPUCGQ5fyitx8BqdfhRnCXzvTD/lEDbKiXWchEO8vWjncqmqGR4Fhbg qIXNpF5uN0iEa/2pwTJrDN2HDVXPl5MTiJK/S6cfy6ZTsyIqTY0ngCrPzzR2DykixYFS OGlQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DWzC+Ykj; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83813-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83813-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. [147.75.199.223]) by mx.google.com with ESMTPS id d22-20020ac85356000000b0042e78cfc501si7193393qto.544.2024.02.27.11.35.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 11:35:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83813-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DWzC+Ykj; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83813-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83813-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 46F811C25834 for ; Tue, 27 Feb 2024 18:18:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7EF3514DFFD; Tue, 27 Feb 2024 18:17:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DWzC+Ykj" 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 2BD97149019 for ; Tue, 27 Feb 2024 18:16:59 +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=1709057821; cv=none; b=DtW1xHS810Lih68blssaGuienhlNrfDgcnYSuzNw1njIjAmHgi/IvWk0FKN2jZ4lmJCGfx88zjaZ8zlmMZUcq2aUSeQDA2GMLknvdAJmyJ85BVXnRW+SD6sfGX4F1YLjGakE6MqfI5pl+k4YzoLOSYpe6oeXDaEWpjsrKGHmEgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057821; c=relaxed/simple; bh=LcZSO2fCT5WaMkS6shCgOhCUo14EJT04WN8x+U0u+KI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J0hTb4D1nrdnjgLl1LPEb/Sf6eXp61TkcSjTxhL93WunbJ1iW+rToAc8Pvq0qUTMXqqEzt5QPZu6CCvIEENxV1WfsDPlldOTJLWK+8AZD3fEr1/a0CN7PhIDUC5gamDwCMaODJjF4Mz46JYJyNx7Ohw+vVnP0OpjS7osD4RLZSE= 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=DWzC+Ykj; 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=1709057819; x=1740593819; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LcZSO2fCT5WaMkS6shCgOhCUo14EJT04WN8x+U0u+KI=; b=DWzC+Ykja44apzKIOzANZucSoRvPq0hGEgOLhi3HZ8EH8rAw7APbleNY WA5Td4TPsZ7NewP+rCa8s4hPsClPk1BOVK76nepvFYJvLtTP5xZ+1+Q9m AlIyQL+3HJAWoQJHShmDoryAYC7NuPIsHIo/UvorrfQNXTbMxnxsaeyus s5IBYcdaTDYg0WTjHISURIQOrzaAhXAeQ6XZNRTdhv+u+qieLK6APBYrw RWA609DKFgTSlRalPGxsKFWO449QVihZCrbFBd0gLbIgo5EAEpDmn80a2 YpRbsO+2fFQgTpTaABEfobHTiyZOJ8YxXCKTUCYPtzm56LFwYAdfzOL7O g==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966093" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966093" 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:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032725" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032725" 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 7AAD94C5; 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 05/16] x86/kexec: Keep CR4.MCE set during kexec for TDX guest Date: Tue, 27 Feb 2024 20:16:05 +0200 Message-ID: <20240227181616.3032032-6-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: 1792081947539409020 X-GMAIL-MSGID: 1792081947539409020 TDX guests are not allowed to clear CR4.MCE. Attempt to clear it leads to #VE. Use alternatives to keep the flag during kexec for TDX guests. The change doesn't affect non-TDX-guest environments. Signed-off-by: Kirill A. Shutemov Reviewed-by: Kai Huang --- arch/x86/kernel/relocate_kernel_64.S | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S index 56cab1bb25f5..e144bcf60cbe 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -5,6 +5,8 @@ */ #include +#include +#include #include #include #include @@ -145,12 +147,15 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped) * Set cr4 to a known state: * - physical address extension enabled * - 5-level paging, if it was enabled before + * - Machine check exception on TDX guest. Clearing MCE is not allowed + * in TDX guests. */ movl $X86_CR4_PAE, %eax testq $X86_CR4_LA57, %r13 jz 1f orl $X86_CR4_LA57, %eax 1: + ALTERNATIVE "", __stringify(orl $X86_CR4_MCE, %eax), X86_FEATURE_TDX_GUEST movq %rax, %cr4 jmp 1f From patchwork Tue Feb 27 18:16:06 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: 207478 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3000589dyb; Tue, 27 Feb 2024 14:30:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW/7iPFrowtHv/3BRp0xdkREpmqyCWQFe1Lw2maKk8PelnJzJvRo6udmWjOiidvWtKNKx33DvKfcPYOOnBSZKnt5TkvvA== X-Google-Smtp-Source: AGHT+IFtT3ySSbIMCwKMutQHe2tPMRDXIZTHJhigqzbnlMJ1IPxYifZDlKa8khbCXQVCMXFqhL5N X-Received: by 2002:a05:6a21:3993:b0:1a1:18ee:1df6 with SMTP id ad19-20020a056a21399300b001a118ee1df6mr332669pzc.35.1709073042280; Tue, 27 Feb 2024 14:30:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709073042; cv=pass; d=google.com; s=arc-20160816; b=d1oIL3OAw5OPopc8xdTsryg2IUlWmNutGiOFbZEOrImpNpbN622i+GMctiwilxPgSZ eR1LaX+xi/VRBG7XuRmD2BfhQWUZ99pwg22cFVu/+SIilAJjWKi4NjoG/Um21qqVtAsn X4JjCZW8gut1z3YlYezAPENEU8aBEmm3D08PBnrMvkzVQDkfP8ZDjtRXpkq+qGygqli3 /mc6u6xddlS4qHhUulBpNR0GQCT7PCHA0ENo58H5F4ACN2JE7a2cVwg1GynPYzyzCFfb VXWm13lD7I3Nn5Vq9K/DyaB2fWlMp5ivuVhZBZuUOxY5O+F9Hnsq6Q1TtJyGrYz9+r7Z Mrpw== 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=DL9st433qELYzhZ2gFtSHkJnrWS2dkaweZNIikWEZZc=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=KnhzUSTo1XCCoT7AoOnNEty9jDMoqm3+UKlYq1nv7PVBDDbq03c/y2IentgJzlus9N gaVu21udSVeew5URWC7kJCtJfAk0VbpvQICNzWC5+RSLSqC4yKJXMcPSS38b+y01chwQ GIDgZzGN9SVddtzk1/vtgzsQYQEM64T3drnX0/x8VLMlJLMHr+sDkSF76/i5ZTsk9UX8 +z5NqpVZQgOJX1rT7+VlFj9kVmK0QM7nMb/l9of3rktQfeSA8yEKsBjYviUPm1fHsjGY phxsvQp2N7tuZf1jGH/apEfimBS1IPeLELZSTIAlUMOiAZUeIc8syFEvFn7xGo0tX83d 3HsQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RsGdbVSz; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83822-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83822-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j23-20020a63ec17000000b005d42e7a9195si6037160pgh.713.2024.02.27.14.30.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:30:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83822-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RsGdbVSz; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83822-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83822-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id AECAD288257 for ; Tue, 27 Feb 2024 18:20:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA4C31586D4; Tue, 27 Feb 2024 18:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RsGdbVSz" 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 A9E4514F993 for ; Tue, 27 Feb 2024 18:17:06 +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=1709057829; cv=none; b=jgQs78L+9Gn+wQPUnZIKLT2l1PIWxCnZwYRnV6NfTjxVZ+Up8RuTwFt5NYPNlEkRtor+ZHyitarLI7n5VIRnTSketXVNrje2tIbeS6bxzeavuhLnRZ/e0N2zlNoNgL/hzbibY+N2pwgsrTr3YzdPtKYiR4zPd/7aNA19q0TUll0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057829; c=relaxed/simple; bh=ELiZbW2ZqeUSKS5G3i8R2dwq9KKRIDZ8Css9qS0iE1E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S07m6mdiqORodzeV3D5hATJQl4t9Zj5Gj8DGHHNJiBVWEImoe7B3FpKJt7MX8qKc9204oB4fxumMQJv0h7YlklEC7cjwLRLcIaGCAXrjc18osTIOMPkXGjTvFc/1/5jkyAqi/AX0bTEs+7DHZxJl8bLBPG0psDivPEweJSgnSlg= 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=RsGdbVSz; 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=1709057826; x=1740593826; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ELiZbW2ZqeUSKS5G3i8R2dwq9KKRIDZ8Css9qS0iE1E=; b=RsGdbVSzen+KIogIp0VL72owEBwLAmr+wpLxKon0ux8+uLIap9p7MRdW vy9Md97XE7BJiil+QaqjIDkhxTL5hCcyJNzZPJVfvjbPew0RwhqKOhpz5 6lKxmv4OzESBsduVYB8D3LTJhjJ1Ras6AcuHoDpNdMb940CyUqUACyaEZ ei8VG1M33+5i1BvZz8nx/uOI5uFx0VSoq2itGMHBGAlLLLGU0CO9fYcys /Q2C+P9VcJw635YuYOUe8o/oNy05WbemRaO1e1d+Rw4gnoLjBMLhXVmVt E+TMRA/p6avMOog6ebahWdQy91pO6Y6bMw0vBjiIx38JJIsHgAKEPnH5a w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966179" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966179" 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="937032741" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032741" 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 87EE74D7; 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 06/16] x86/mm: Make x86_platform.guest.enc_status_change_*() return errno Date: Tue, 27 Feb 2024 20:16:06 +0200 Message-ID: <20240227181616.3032032-7-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: 1792092974178648731 X-GMAIL-MSGID: 1792092974178648731 TDX is going to have more than one reason to fail enc_status_change_prepare(). Change the callback to return errno instead of assuming -EIO; enc_status_change_finish() changed too to keep the interface symmetric. Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 20 +++++++++++--------- arch/x86/hyperv/ivm.c | 9 +++------ arch/x86/include/asm/x86_init.h | 4 ++-- arch/x86/kernel/x86_init.c | 4 ++-- arch/x86/mm/mem_encrypt_amd.c | 8 ++++---- arch/x86/mm/pat/set_memory.c | 9 +++++---- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index c1cb90369915..26fa47db5782 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -798,28 +798,30 @@ static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc) return true; } -static bool tdx_enc_status_change_prepare(unsigned long vaddr, int numpages, - bool enc) +static int tdx_enc_status_change_prepare(unsigned long vaddr, int numpages, + bool enc) { /* * Only handle shared->private conversion here. * See the comment in tdx_early_init(). */ - if (enc) - return tdx_enc_status_changed(vaddr, numpages, enc); - return true; + if (enc && !tdx_enc_status_changed(vaddr, numpages, enc)) + return -EIO; + + return 0; } -static bool tdx_enc_status_change_finish(unsigned long vaddr, int numpages, +static int tdx_enc_status_change_finish(unsigned long vaddr, int numpages, bool enc) { /* * Only handle private->shared conversion here. * See the comment in tdx_early_init(). */ - if (!enc) - return tdx_enc_status_changed(vaddr, numpages, enc); - return true; + if (!enc && !tdx_enc_status_changed(vaddr, numpages, enc)) + return -EIO; + + return 0; } void __init tdx_early_init(void) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 7dcbf153ad72..49b4f427268f 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -510,13 +510,12 @@ static int hv_mark_gpa_visibility(u16 count, const u64 pfn[], * with host. This function works as wrap of hv_mark_gpa_visibility() * with memory base and size. */ -static bool hv_vtom_set_host_visibility(unsigned long kbuffer, int pagecount, bool enc) +static int hv_vtom_set_host_visibility(unsigned long kbuffer, int pagecount, bool enc) { enum hv_mem_host_visibility visibility = enc ? VMBUS_PAGE_NOT_VISIBLE : VMBUS_PAGE_VISIBLE_READ_WRITE; u64 *pfn_array; int ret = 0; - bool result = true; int i, pfn; pfn_array = kmalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL); @@ -530,17 +529,15 @@ static bool hv_vtom_set_host_visibility(unsigned long kbuffer, int pagecount, bo if (pfn == HV_MAX_MODIFY_GPA_REP_COUNT || i == pagecount - 1) { ret = hv_mark_gpa_visibility(pfn, pfn_array, visibility); - if (ret) { - result = false; + if (ret) goto err_free_pfn_array; - } pfn = 0; } } err_free_pfn_array: kfree(pfn_array); - return result; + return ret; } static bool hv_vtom_tlb_flush_required(bool private) diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h index c878616a18b8..c9503fe2d13a 100644 --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -150,8 +150,8 @@ struct x86_init_acpi { * @enc_cache_flush_required Returns true if a cache flush is needed before changing page encryption status */ struct x86_guest { - bool (*enc_status_change_prepare)(unsigned long vaddr, int npages, bool enc); - bool (*enc_status_change_finish)(unsigned long vaddr, int npages, bool enc); + int (*enc_status_change_prepare)(unsigned long vaddr, int npages, bool enc); + int (*enc_status_change_finish)(unsigned long vaddr, int npages, bool enc); bool (*enc_tlb_flush_required)(bool enc); bool (*enc_cache_flush_required)(void); }; diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c index a37ebd3b4773..f0f54e109eb9 100644 --- a/arch/x86/kernel/x86_init.c +++ b/arch/x86/kernel/x86_init.c @@ -131,8 +131,8 @@ struct x86_cpuinit_ops x86_cpuinit = { static void default_nmi_init(void) { }; -static bool enc_status_change_prepare_noop(unsigned long vaddr, int npages, bool enc) { return true; } -static bool enc_status_change_finish_noop(unsigned long vaddr, int npages, bool enc) { return true; } +static int enc_status_change_prepare_noop(unsigned long vaddr, int npages, bool enc) { return 0; } +static int enc_status_change_finish_noop(unsigned long vaddr, int npages, bool enc) { return 0; } static bool enc_tlb_flush_required_noop(bool enc) { return false; } static bool enc_cache_flush_required_noop(void) { return false; } static bool is_private_mmio_noop(u64 addr) {return false; } diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index 70b91de2e053..d314e577836d 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -283,7 +283,7 @@ static void enc_dec_hypercall(unsigned long vaddr, unsigned long size, bool enc) #endif } -static bool amd_enc_status_change_prepare(unsigned long vaddr, int npages, bool enc) +static int amd_enc_status_change_prepare(unsigned long vaddr, int npages, bool enc) { /* * To maintain the security guarantees of SEV-SNP guests, make sure @@ -292,11 +292,11 @@ static bool amd_enc_status_change_prepare(unsigned long vaddr, int npages, bool if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP) && !enc) snp_set_memory_shared(vaddr, npages); - return true; + return 0; } /* Return true unconditionally: return value doesn't matter for the SEV side */ -static bool amd_enc_status_change_finish(unsigned long vaddr, int npages, bool enc) +static int amd_enc_status_change_finish(unsigned long vaddr, int npages, bool enc) { /* * After memory is mapped encrypted in the page table, validate it @@ -308,7 +308,7 @@ static bool amd_enc_status_change_finish(unsigned long vaddr, int npages, bool e if (!cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) enc_dec_hypercall(vaddr, npages << PAGE_SHIFT, enc); - return true; + return 0; } static void __init __set_clr_pte_enc(pte_t *kpte, int level, bool enc) diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index e9b448d1b1b7..f92da8c9a86d 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2152,8 +2152,9 @@ static int __set_memory_enc_pgtable(unsigned long addr, int numpages, bool enc) cpa_flush(&cpa, x86_platform.guest.enc_cache_flush_required()); /* Notify hypervisor that we are about to set/clr encryption attribute. */ - if (!x86_platform.guest.enc_status_change_prepare(addr, numpages, enc)) - return -EIO; + ret = x86_platform.guest.enc_status_change_prepare(addr, numpages, enc); + if (ret) + return ret; ret = __change_page_attr_set_clr(&cpa, 1); @@ -2168,8 +2169,8 @@ static int __set_memory_enc_pgtable(unsigned long addr, int numpages, bool enc) /* Notify hypervisor that we have successfully set/clr encryption attribute. */ if (!ret) { - if (!x86_platform.guest.enc_status_change_finish(addr, numpages, enc)) - ret = -EIO; + ret = x86_platform.guest.enc_status_change_finish(addr, + numpages, enc); } return ret; From patchwork Tue Feb 27 18:16:07 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: 207399 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2922503dyb; Tue, 27 Feb 2024 11:36:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVbzJSxRQvDFC4ACafAcC2NTmxaHvsY4K9ek5BD/Wh8eT/SfO9uH14kXbXN6t4o5crvNmXydNkzJ72MPFpAT43Yp/WkaA== X-Google-Smtp-Source: AGHT+IFnrcA8g5Wxhk5DIsPWFREsvBGdExBmNVAmh0U4QQ7x71GONGneDuyVe56RnLkbiItDUArF X-Received: by 2002:a92:d312:0:b0:365:8250:f2fe with SMTP id x18-20020a92d312000000b003658250f2femr12918661ila.0.1709062581595; Tue, 27 Feb 2024 11:36:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709062581; cv=pass; d=google.com; s=arc-20160816; b=syvN/2O1bOH5RWn6s6BwQ8lQZgjsLHJKfdePrpJxao1+xvzInxyNTJkZMjQpHl/oIq rL5Arlva2cz1z4GDyjH6W6tSlWI9AuU7vUGXvSzg9nSrr72KxnmDsJCSbc9loMBBb1wU P0tvQ4QIPE19vIRSszIoK8FUZeP8Va3PJ5IN571zNNqLGSnYDxari5MnmugABVXUw14r BNFJ/u+7iTHSpk/JquixKxZTJRwYZwV6o6KPF3ebWZ7i4ouWqk9rYEOhj4CYooUoJtb0 +TEsdwFO0yCWry+PU2iplLvjC0J0UGmj+YeLVGqzocjldWWrZwU9bWSqJsa7yp+xNPqi 0VTQ== 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=kxw9uVRF0uklRfRh6iTwvS8jLXK1PeQrAkZPaXxZPCw=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=Otj4OGZBhugULV/6kY5FIyqj8Pf7RY6Qi1aJNx4HnCDPiGsliupgGJvaLYoOe9rCzQ pwPja5RWlIrQvvjej9XUPdRPDszWjLdkmsovNeKsXhZkXuUvXu/vRlJAGenU6OIRAfHK wiwGSayIQTynoCxSbocFU0vRTo6oK2OqBlRdPsmltweliq05tDWRg0SgTy3zhm+jt1Ew ulVDf+NkLNiI400aEsdSBq5byJouaTCQEX37Mil3We/rCuCJmNQDYW9jla70D9WPXXud pP68+k2z8vxz4TBpGUhalALj7ZFmY79kwCdE0SIKbEX5MhNtIoswsMNQJfUFyQGJKDnf hcFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ecb1cKDv; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83816-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83816-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 16-20020a631150000000b005dc4da21221si6001546pgr.419.2024.02.27.11.36.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 11:36:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83816-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ecb1cKDv; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83816-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83816-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9876E28E8DC for ; Tue, 27 Feb 2024 18:19:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 40732151CD7; Tue, 27 Feb 2024 18:17:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ecb1cKDv" 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 47F0D14AD23 for ; Tue, 27 Feb 2024 18:17:02 +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=1709057824; cv=none; b=cLweYUwMqFRMBIc51x2WVYTEcHLaWONkDr+jStnc1YX8xOdLmOiwhSa5SjCQ3LeoJ4GvGDzMPeq9E1ynMggXyhmq0kb5VSBmieMuBvvKgaIAbxrvMKoew+VCslDnuJlBdWH02jLgjrBkbRcp4tXNezc9xER0ORfZNL1wYlKfUa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057824; c=relaxed/simple; bh=SxAJq8PySGkIldIS+Dq+6BevKxjnV/qVUXBP60oIUiw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PiQYFBpIE58zkVfKnDSt6CPj8UtMzCf8erSe4bhn5uTfmnxzs61f0o4F9KaWqSX80qEwsBXHzn6HSxyMonbdtgzzX3y/NQG/keyRph3xthUxz2yeI7WLfH3taBB9yHu0paKr0j1iARuK7G2iJH9mMmNfbsSO2/Acr50YVYGvtlE= 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=Ecb1cKDv; 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=1709057822; x=1740593822; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SxAJq8PySGkIldIS+Dq+6BevKxjnV/qVUXBP60oIUiw=; b=Ecb1cKDvnj7O98b7Hvr9yu/Vt8vpwVAbyH4g7/3jNVmEocMX8soHTFn5 4c4at/LK02mTCLIcj+3kl1Xn9lK7npmd/N4fc5JtUvd+RxeZwhQqyvEev 0yYBgH14VGniu6GZIBEgVVh7tpI6GhEMuSjQ3mAE0Jqb4CSTTt+Hp3dnb RfvkYXxRzqJclPZXcYtOXZfrY6t89flpb2SGnS7Xxy8o/gzvPTJ0JAdwC /ph72sHtUykNVmMoaY2K4O4SXz4c3kxWW3lA/jJKYxtPjWb2YeY/e8+W6 whwYNXp4BZsSs15llJZagkjOCwMGSPw30hHz/b0bHE8k4SZVUa1nxC+Xr w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966140" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966140" 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="937032732" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032732" 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 94635692; 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 07/16] x86/mm: Return correct level from lookup_address() if pte is none Date: Tue, 27 Feb 2024 20:16:07 +0200 Message-ID: <20240227181616.3032032-8-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: 1792082005576719036 X-GMAIL-MSGID: 1792082005576719036 lookup_address() only returns correct page table level for the entry if the entry is not none. Make the helper to always return correct 'level'. It allows to implement iterator over kernel page tables using lookup_address(). Add one more entry into enum pg_level to indicate size of VA covered by one PGD entry in 5-level paging mode. Signed-off-by: Kirill A. Shutemov Reviewed-by: Rick Edgecombe --- arch/x86/include/asm/pgtable_types.h | 1 + arch/x86/mm/pat/set_memory.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index 0b748ee16b3d..3f648ffdfbe5 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -548,6 +548,7 @@ enum pg_level { PG_LEVEL_2M, PG_LEVEL_1G, PG_LEVEL_512G, + PG_LEVEL_256T, PG_LEVEL_NUM }; diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index f92da8c9a86d..3612e3167147 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -666,32 +666,32 @@ pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address, pud_t *pud; pmd_t *pmd; - *level = PG_LEVEL_NONE; + *level = PG_LEVEL_256T; if (pgd_none(*pgd)) return NULL; + *level = PG_LEVEL_512G; p4d = p4d_offset(pgd, address); if (p4d_none(*p4d)) return NULL; - *level = PG_LEVEL_512G; if (p4d_large(*p4d) || !p4d_present(*p4d)) return (pte_t *)p4d; + *level = PG_LEVEL_1G; pud = pud_offset(p4d, address); if (pud_none(*pud)) return NULL; - *level = PG_LEVEL_1G; if (pud_large(*pud) || !pud_present(*pud)) return (pte_t *)pud; + *level = PG_LEVEL_2M; pmd = pmd_offset(pud, address); if (pmd_none(*pmd)) return NULL; - *level = PG_LEVEL_2M; if (pmd_large(*pmd) || !pmd_present(*pmd)) return (pte_t *)pmd; From patchwork Tue Feb 27 18:16:08 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: 207395 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2922059dyb; Tue, 27 Feb 2024 11:35:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV/xfsRdIryWkytxe8f4SCw7DGU6L0Isbnr1lfr2cMYvKbWtzJ7IXpn8kY+EjQWoYCk6nUF7IZ4NL3vTju5x9P3DFuoqw== X-Google-Smtp-Source: AGHT+IHa6qNIWnMi9MGOVy0++wiaZPKpJ+HULeZ0m7bt+5KLhXqycalcnoxpJVhNOx3ItDOreyb4 X-Received: by 2002:a17:902:d2c4:b0:1db:5213:222 with SMTP id n4-20020a170902d2c400b001db52130222mr13801119plc.5.1709062519784; Tue, 27 Feb 2024 11:35:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709062519; cv=pass; d=google.com; s=arc-20160816; b=cYEctokiMk/aQ58pNVvrwST47RNyC2lBM+T61uJ5Mg5lKSfqUnHnMy7yQTkjitcS8U YbIe1HcNHA9YA7tTzU6BUSF+Ac/Jal5qr4XcJh7doNiA1jAtrUEdZ5n5TFjZx5ktSFzM jOxakfTrNENZ3zrr99Yk7kyZV60h1NPX9cObF8u8lKCuO61rI0RucTbbn8SL6SMFB0qu vShRYwYXF2Se/sZqh5+b63us4PRQ0zwgHpN4G1HnQJXFt4Qx95gBPTqHbaHoU9QiX9mt Orbib7zbuoe0VuJS04djONW5gVXgu1wPdZo9AXuk486rHzxjwIetpGZHrV/qt8dkI5l+ gwMQ== 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=QbNVvvHkrGHh7BR7Qwt2J0OgUR8dAXMlMSzqos0/4mY=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=ZP8EYCbiDizwgMgHdycQCJ3jfL76Im5scmu1zckA6RL0iNKs8MeublGJnI+hjkf9lU hS/rpm0KHL4ZYlV6obXC78f2tygJTeis+aba0CPRvbaZozcLKptLXn27JDuY2L2k3Ck3 5KNXPWF1z4V68yLbRU75xt9xGTa0l58R1P/WdpqTVodQctKshLP+FhouIKuWiLSrOX1x 55qqtAqo928grb9WdTpy+ofK7qN+UWZi2v7oKo8pLvA+yPX+ooz/2yRL9zstD42Egplr Q4KnTUjpNOSwtVatWa8ijdAhbWYZGWG2QdeazxYBKS/WSqwIuoMq4+ZSU1kiru1eAREc cNAw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NvuYTpxm; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83817-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83817-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e2-20020a17090301c200b001dc01351441si1853611plh.528.2024.02.27.11.35.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 11:35:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83817-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NvuYTpxm; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83817-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83817-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 733A928EAC0 for ; Tue, 27 Feb 2024 18:19:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A668F1534E9; Tue, 27 Feb 2024 18:17:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="NvuYTpxm" 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 39225145FF9 for ; Tue, 27 Feb 2024 18:17:01 +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=1709057824; cv=none; b=eGFKgv7lbL3y5eVZGDtpAF5PdFb6sszMpahsQ5TL2mHz2pYa/jY1+MpSe5pYpJUVdxCLNYS7cJL0g0g3njHPjOGgimjrwKkkT0DX/oiMxziYw6NNnMx0zyYNMnqcJHJl7Ib7R6aQEvoYuptlC9svPFmCqvpClP8jWLklQ6zR3Qc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057824; c=relaxed/simple; bh=ttorKfrAsCfwHjNDg0dNsgpEDrTBddN8JkJtVUzul2k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ILQXysfmMJzNk+VyP0d2UKa7M0t+zW25cxtvSFFcAiON4cDEIaL/3ZK/Apotj/eO+Kt8vmSfJxJFCIxUP4JzSxkpQ0C4D4N+26M91kMHEzRKTxM0Me21tQcTA9eq5+utorAiwjytEN63g10kI0INq3Jy9ggu7sa638TmCUK/X4k= 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=NvuYTpxm; 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=1709057821; x=1740593821; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ttorKfrAsCfwHjNDg0dNsgpEDrTBddN8JkJtVUzul2k=; b=NvuYTpxmDxBZlriaQQenUPBNvomz4hQD6aovLdNxLcYs0f6YB55sDUv0 sS/mjQRzZsTA58bOfD+wsEZm6RchzWv2WZ9x/1gCSuRAka+wvAC3Jj3pv nj+Wz8jrcA9iFhS2fzlQ79JINxVdi5/6PM5iWKw38Vj8QmMSA/3gMNv8N Cz6g3l/zRkMR+CfbryjOCEkYZoCcLlxTP6rXOky3NV9UNjmOq6Hqj9prz XvN6RKOrRu80ntDf7hOtxSi62ITLlK8kU+iOsz3n7hcJrcYsiw45JPDaf jhh68gbGAdrgXRmKQYuTiPxk67gzZ4xf1/6stRvZeLAwpNG8Lq8nN+2hy Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966127" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966127" 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="937032733" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032733" 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 A06DF812; 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 08/16] x86/tdx: Account shared memory Date: Tue, 27 Feb 2024 20:16:08 +0200 Message-ID: <20240227181616.3032032-9-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: 1792081940456107046 X-GMAIL-MSGID: 1792081940456107046 The kernel will convert all shared memory back to private during kexec. The direct mapping page tables will provide information on which memory is shared. It is extremely important to convert all shared memory. If a page is missed, it will cause the second kernel to crash when it accesses it. Keep track of the number of shared pages. This will allow for cross-checking against the shared information in the direct mapping and reporting if the shared bit is lost. Include a debugfs interface that allows for the check to be performed at any point. Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 69 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 26fa47db5782..fd212c9bad89 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -5,6 +5,7 @@ #define pr_fmt(fmt) "tdx: " fmt #include +#include #include #include #include @@ -38,6 +39,13 @@ #define TDREPORT_SUBTYPE_0 0 +static atomic_long_t nr_shared; + +static inline bool pte_decrypted(pte_t pte) +{ + return cc_mkdec(pte_val(pte)) == pte_val(pte); +} + /* Called from __tdx_hypercall() for unrecoverable failure */ noinstr void __noreturn __tdx_hypercall_failed(void) { @@ -821,6 +829,11 @@ static int tdx_enc_status_change_finish(unsigned long vaddr, int numpages, if (!enc && !tdx_enc_status_changed(vaddr, numpages, enc)) return -EIO; + if (enc) + atomic_long_sub(numpages, &nr_shared); + else + atomic_long_add(numpages, &nr_shared); + return 0; } @@ -896,3 +909,59 @@ void __init tdx_early_init(void) pr_info("Guest detected\n"); } + +#ifdef CONFIG_DEBUG_FS +static int tdx_shared_memory_show(struct seq_file *m, void *p) +{ + unsigned long addr, end; + unsigned long found = 0; + + addr = PAGE_OFFSET; + end = PAGE_OFFSET + get_max_mapped(); + + while (addr < end) { + unsigned long size; + unsigned int level; + pte_t *pte; + + pte = lookup_address(addr, &level); + size = page_level_size(level); + + if (pte && pte_decrypted(*pte)) + found += size / PAGE_SIZE; + + addr += size; + + cond_resched(); + } + + seq_printf(m, "Number of shared pages in kernel page tables: %16lu\n", + found); + seq_printf(m, "Number of pages accounted as shared: %16ld\n", + atomic_long_read(&nr_shared)); + return 0; +} + +static int tdx_shared_memory_open(struct inode *inode, struct file *file) +{ + return single_open(file, tdx_shared_memory_show, NULL); +} + +static const struct file_operations tdx_shared_memory_fops = { + .open = tdx_shared_memory_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static __init int debug_tdx_shared_memory(void) +{ + if (!cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return 0; + + debugfs_create_file("tdx_shared_memory", 0400, arch_debugfs_dir, + NULL, &tdx_shared_memory_fops); + return 0; +} +fs_initcall(debug_tdx_shared_memory); +#endif From patchwork Tue Feb 27 18:16:09 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: 207443 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2973013dyb; Tue, 27 Feb 2024 13:23:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXYP+v6aCu9MFiBQNdyo6Ik9VX3dt5q0BvKdAOB59ge4DFaAJJYYhLx+3K7m1Iaxrfo5MTSbVL/WfteNPG3+Z5gt1xR8A== X-Google-Smtp-Source: AGHT+IF1XDPdEzJV7/pLLcX8PlZ7jzAuYPcdXQG1yDP7nGX+xzTFU21YNwl3mZDOyjliHoY+UAmf X-Received: by 2002:aa7:d510:0:b0:566:414d:d70d with SMTP id y16-20020aa7d510000000b00566414dd70dmr1833868edq.17.1709069008519; Tue, 27 Feb 2024 13:23:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709069008; cv=pass; d=google.com; s=arc-20160816; b=bwpkh4Ove7buFWJPiicDrcUv5cRoFW21vFZtXytpMV1ZusQkhBjlt1Lfo5zgJCJhTf htZa0UwgMoThLe3qjIIQPmRaOJGth6zrAAsd8eWMQAphvjPmY0g+swFKtahdWk5SgsBp 5pkdhCpJtYjXoQTMAjWmFFe+g+6cJWlkyBbVD4EHJjwMIdQA08SjOLREltxGqm/qbBuQ FAbXfflAH9GKO4HD22+2m2Nlgk7ihSDvMB0al0lqLtUgDOhALdh5+Nj/tGSIqXvyfHZL ubeHNFGGFS6q4dIpBjyFx+jy982wGUAJ09VeoB89vDXhMDBZZ6yi8UeZG6ji+vAdQ25V E3Zg== 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=WD2JGEweFTEcyVG1Zgdz/cxp/owXWYDMRqs2tjc+ULE=; fh=/Ak5C2ws7sfmtivYsSuDzWsPTaU4mDhR0lpxQ6qr3D0=; b=t+BT/rUBaOGoTtjpjQd0crzrtqkyxsTJdb9kMi2ju9j/y5au3kM6IKgZzoVXANcI/K 9+typCzR2D5aZlXfgA/8iF/xDdRGLdyXszMIA0MLBdxJWrAjcO7wLGwBN7wzy94q9N+8 iz54HEtpvHSMDuLozk8/N60wmJk1CFX+HFGQyiC1jyKbsOtAgGCrrc7MFZhZpUF2amWU ioPuXnDfPnLOJHMyFFc8U08G7sRnmbsQd+nTf4+uKX4nLK1RLq7FhVIx5Yb5D2wgQuqN zuttqgrelOGQk4n51zMBA68d6HBFN37Tl2MxZ887YcMdS5tmqbogaXLubljQwLTyad3l GunA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KYZTuWPE; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83821-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83821-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. [147.75.80.249]) by mx.google.com with ESMTPS id f24-20020a056402161800b005661c8bfc04si979932edv.94.2024.02.27.13.23.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 13:23:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83821-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KYZTuWPE; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83821-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83821-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 3BD781F2BFAA for ; Tue, 27 Feb 2024 18:20:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D178514E2C8; Tue, 27 Feb 2024 18:17:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KYZTuWPE" 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 3C55B14EFE5 for ; Tue, 27 Feb 2024 18:17:05 +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=1709057827; cv=none; b=iCtgi/tKufqhwt8EYc3gfXziQGEcrXCh+1Bh3bmpoY7dPGjwkZk/pEn/QkzfnlM+ElDRx6Dg/G+Wk337KIr46OA6m5iFn/Ci2dpT3rPJNaGrYZUAX5GSPPSKzfKwakqSOxccFxVsKGbbNPQESMkeDxmwLtaZXGNDnlhQ0jW7LrM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057827; c=relaxed/simple; bh=284d6MdNJnzxJrEwLF3i2F8vgHGQ2onD2qQDE8fELP4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MimrH4HeXcquKoyI3Sc2Fp3V/sh0HbqUlcSWIXFL+VZnoUki3phuC8i7oR20U8Hc/sMoght6NlG/7arg9Km4vZj4xyt+N/3bsNRFF1Gxppayj8deTTU9Abnbj62q1oCXMmH4Bo0Gdza8zL5UauosOX1iMZy7DswnCyaxFAGZqU0= 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=KYZTuWPE; 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=1709057825; x=1740593825; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=284d6MdNJnzxJrEwLF3i2F8vgHGQ2onD2qQDE8fELP4=; b=KYZTuWPEjos9SPn43G7nSmV/3MtzmTo1I3m9VE04FpKeWC+0MbWs5bOk OIxhIh54SoZscwgkUG3wv3SYxb9W88pj4Tt4Vp/cLNrmtQwZwskXU2kq+ 0E4zlfIymp8LK8JoB8LOoNBWuu0E9wIduOdwMhFEHBEJqMwVZNEwqoV73 r0baZJ+x9jlZs1NnfhaUU6o9mBI3R+lZoKkv/6X0662iEBmwpAhQ0YJgW FlLcxzY4SJ8imU1apfF7dlHkja2KxIf7IWoJ4B1UnxuPcTxfoCQl+hH/N NHcRQOqL9f91aGvTo5I5f1bm/F6k0lF6KdCxfFt0gsBald50GmnCxZSzK g==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966191" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966191" 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:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032743" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032743" 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 B16ED9AB; 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" , Nikolay Borisov Subject: [PATCHv8 09/16] x86/mm: Adding callbacks to prepare encrypted memory for kexec Date: Tue, 27 Feb 2024 20:16:09 +0200 Message-ID: <20240227181616.3032032-10-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: 1792088744860377859 X-GMAIL-MSGID: 1792088744860377859 AMD SEV and Intel TDX guests allocate shared buffers for performing I/O. This is done by allocating pages normally from the buddy allocator and then converting them to shared using set_memory_decrypted(). On kexec, the second kernel is unaware of which memory has been converted in this manner. It only sees E820_TYPE_RAM. Accessing shared memory as private is fatal. Therefore, the memory state must be reset to its original state before starting the new kernel with kexec. The process of converting shared memory back to private occurs in two steps: - enc_kexec_stop_conversion() stops new conversions. - enc_kexec_unshare_mem() unshares all existing shared memory, reverting it back to private. Signed-off-by: Kirill A. Shutemov Reviewed-by: Nikolay Borisov x --- arch/x86/include/asm/x86_init.h | 2 ++ arch/x86/kernel/crash.c | 6 ++++++ arch/x86/kernel/reboot.c | 12 ++++++++++++ arch/x86/kernel/x86_init.c | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h index c9503fe2d13a..3196ff20a29e 100644 --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -154,6 +154,8 @@ struct x86_guest { int (*enc_status_change_finish)(unsigned long vaddr, int npages, bool enc); bool (*enc_tlb_flush_required)(bool enc); bool (*enc_cache_flush_required)(void); + void (*enc_kexec_stop_conversion)(bool crash); + void (*enc_kexec_unshare_mem)(void); }; /** diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index b6b044356f1b..3001f4857ed7 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -124,6 +124,12 @@ void native_machine_crash_shutdown(struct pt_regs *regs) #ifdef CONFIG_HPET_TIMER hpet_disable(); #endif + + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) { + x86_platform.guest.enc_kexec_stop_conversion(true); + x86_platform.guest.enc_kexec_unshare_mem(); + } + crash_save_cpu(regs, safe_smp_processor_id()); } diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c index 830425e6d38e..0574d4ad6b41 100644 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -716,6 +717,14 @@ static void native_machine_emergency_restart(void) void native_machine_shutdown(void) { + /* + * Call enc_kexec_stop_conversion() while all CPUs are still active and + * interrupts are enabled. This will allow all in-flight memory + * conversions to finish cleanly. + */ + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT) && kexec_in_progress) + x86_platform.guest.enc_kexec_stop_conversion(false); + /* Stop the cpus and apics */ #ifdef CONFIG_X86_IO_APIC /* @@ -752,6 +761,9 @@ void native_machine_shutdown(void) #ifdef CONFIG_X86_64 x86_platform.iommu_shutdown(); #endif + + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT) && kexec_in_progress) + x86_platform.guest.enc_kexec_unshare_mem(); } static void __machine_emergency_restart(int emergency) diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c index f0f54e109eb9..b95206ebc621 100644 --- a/arch/x86/kernel/x86_init.c +++ b/arch/x86/kernel/x86_init.c @@ -135,6 +135,8 @@ static int enc_status_change_prepare_noop(unsigned long vaddr, int npages, bool static int enc_status_change_finish_noop(unsigned long vaddr, int npages, bool enc) { return 0; } static bool enc_tlb_flush_required_noop(bool enc) { return false; } static bool enc_cache_flush_required_noop(void) { return false; } +static void enc_kexec_stop_conversion_noop(bool crash) {} +static void enc_kexec_unshare_mem_noop(void) {} static bool is_private_mmio_noop(u64 addr) {return false; } struct x86_platform_ops x86_platform __ro_after_init = { @@ -158,6 +160,8 @@ struct x86_platform_ops x86_platform __ro_after_init = { .enc_status_change_finish = enc_status_change_finish_noop, .enc_tlb_flush_required = enc_tlb_flush_required_noop, .enc_cache_flush_required = enc_cache_flush_required_noop, + .enc_kexec_stop_conversion = enc_kexec_stop_conversion_noop, + .enc_kexec_unshare_mem = enc_kexec_unshare_mem_noop, }, }; From patchwork Tue Feb 27 18:16:10 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: 207397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2922276dyb; Tue, 27 Feb 2024 11:35:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUcGYUjkUSdEWkJi6ft/JqmMm4lv6EWbLPX6X9myQO+xB/1+NoYFdU7MPz9mpKQI+NeFokvm0C3zLj29SHTLEpHGK6BAg== X-Google-Smtp-Source: AGHT+IEfatvOo0YAq74w2oUNkZbGmkFmiG16v+TepjSmt5scTXi2xnCLEUkuj0r+WVvhmX0wJVSf X-Received: by 2002:a9d:62c6:0:b0:6e4:87b0:bff8 with SMTP id z6-20020a9d62c6000000b006e487b0bff8mr12120327otk.11.1709062547610; Tue, 27 Feb 2024 11:35:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709062547; cv=pass; d=google.com; s=arc-20160816; b=ICeEDMqNFCORejS16lV9pCikAImcPqu4fqfNGdXAHU4TY3LvmmdAqzkwer3eGnukZE rGn1IpJtUgm7iJ3JXe4O3YPtWGQ9e3zqPpEiTvw/fJE7L8cXYzkLHxjD2niEXgA2GP1o 1797fRNZjrCIeC9uA8AoJ58fvjpUZ1OvzvT/9QFZig4W0bxk5t3f+L1qyMU+LIDoN5YE ztDDYaJw5gGxQh6joNLyEJb4+CRQ4yJ2Z/hEqKgExb6TYggUxqt6HRFyi9YX3/NhfYvv 3NrUBHkt9mdQIH0VcaRhsWn52hs7aQb8zTkULLrqestv6kvSOn9miVLtyq32ltiw8moc YmLw== 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=2lY/aNwLINnKOMbDQO5jsCiPZIA7GFZi3ZqNd3+Td/k=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=Ae0RchI34lLtVKzelGRSr9mLhgXbNdD/4vDqgIWbHbo6sWCB7+AJQaQZM77Btm2t7u X3UVUtexLeGxpTMb500iZS2NsC2+278EO2Qin3qLGZUzA83UXXzgPshkXF4vAkoL42Qv Fx/K+Y8jKgUBTlyEOqfw//6WIZsXV5nD/LdDjRRBmDr3B8Dp00/FlRA+21AC1L9yfzKm mpAoZ9rUGO7Mc/4Z4yhO7iUW73MoFxxoGQfABNdpqp5fGpJpTklSKG6oHYRFcJr+vOK9 b2CsZQ1hjQAsIIVOJTlddysjtZfPBWoO7D9qtP7+WZaGeN6Gb562f+EcJhTpEz3ItCum DRyA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ljmNej1b; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83814-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83814-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y22-20020aa78056000000b006e4c0cf47b2si5817834pfm.70.2024.02.27.11.35.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 11:35:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83814-ouuuleilei=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=ljmNej1b; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83814-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83814-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id DF8A228E429 for ; Tue, 27 Feb 2024 18:18:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F04A314F99C; Tue, 27 Feb 2024 18:17:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ljmNej1b" 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 CE409149DEE for ; Tue, 27 Feb 2024 18:16:59 +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=1709057822; cv=none; b=oCnm7roj7kdfVITPCdf6w/NEWXyItPfEy3OsQELfV7tjODUpGyyHrkgqZkqwLsed5QcjthqtsbySXg/yLUleGvVav04E24LV94U+df08ttIsOlctX1KNUC+aXnhF9wAhlMTCFh//2s4xUpdpz5TEv6dJplsWCB2HDDm7YUtdOMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057822; c=relaxed/simple; bh=OpIDWzdlg0any9JAzqVnZ+xhu2rjxA6sBoybOHgswyk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GCdxbgEN/js9YFsW8JTPS/Chb6B4R9/sdHx6VqjC0Nzej6NcN93waGLS+GqeHqsNf14vJQ+EYBPpWQrm5CZL+lnNaAhOMKAU+O8a7EUqYOgeEEUeP9l6jIaYjn+O1fWqApLaAJHZ/GiDJWLhy2sXeQH5vj05BrQD2FrvZXrUBsk= 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=ljmNej1b; 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=1709057820; x=1740593820; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OpIDWzdlg0any9JAzqVnZ+xhu2rjxA6sBoybOHgswyk=; b=ljmNej1bg0IkKYUr1C+SB3Xcn7JNOceWIVvItsxxow6tBM4FzDSs6A1V kaHf8XvtGOCRHo2XB6QxYG7ZqEo+vC/4icEfzSu4o02rZst11MMV5Wm+l iHKOTsDsL158NS2HaiLmJwvwXwEcbgdJMSIy2pI5EZqGevWDGKtPQxBll EQSqSrCpfZV5+1rp3IH6njQAg3E8IwFdOq1SmsMSP1jM+ExJiLHNzZHj2 CjWuGm6eQhSbswzgmhepGL8oPEqYSALaVzNGQwavd5O53Rkr6FimwnvR9 kUj3kKW+7DsxQbjwN/kSWm7+6fCM8kh4WWIVITbxcWIw4DMKg1Ul5jpac g==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966105" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966105" 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="937032727" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032727" 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 C1F679AD; 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 10/16] x86/tdx: Convert shared memory back to private on kexec Date: Tue, 27 Feb 2024 20:16:10 +0200 Message-ID: <20240227181616.3032032-11-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: 1792081969763969037 X-GMAIL-MSGID: 1792081969763969037 TDX guests allocate shared buffers to perform I/O. It is done by allocating pages normally from the buddy allocator and converting them to shared with set_memory_decrypted(). The second kernel has no idea what memory is converted this way. It only sees E820_TYPE_RAM. Accessing shared memory via private mapping is fatal. It leads to unrecoverable TD exit. On kexec walk direct mapping and convert all shared memory back to private. It makes all RAM private again and second kernel may use it normally. The conversion occurs in two steps: stopping new conversions and unsharing all memory. In the case of normal kexec, the stopping of conversions takes place while scheduling is still functioning. This allows for waiting until any ongoing conversions are finished. The second step is carried out when all CPUs except one are inactive and interrupts are disabled. This prevents any conflicts with code that may access shared memory. Signed-off-by: Kirill A. Shutemov Reviewed-by: Rick Edgecombe --- arch/x86/coco/tdx/tdx.c | 124 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 2 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index fd212c9bad89..bb77a927a831 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -6,8 +6,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -15,6 +17,7 @@ #include #include #include +#include /* MMIO direction */ #define EPT_READ 0 @@ -41,6 +44,9 @@ static atomic_long_t nr_shared; +static atomic_t conversions_in_progress; +static bool conversion_allowed = true; + static inline bool pte_decrypted(pte_t pte) { return cc_mkdec(pte_val(pte)) == pte_val(pte); @@ -726,6 +732,14 @@ static bool tdx_tlb_flush_required(bool private) static bool tdx_cache_flush_required(void) { + /* + * Avoid issuing CLFLUSH on set_memory_decrypted() if conversions + * stopped. Otherwise it can race with unshare_all_memory() and trigger + * implicit conversion to shared. + */ + if (!conversion_allowed) + return false; + /* * AMD SME/SEV can avoid cache flushing if HW enforces cache coherence. * TDX doesn't have such capability. @@ -809,12 +823,25 @@ static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc) static int tdx_enc_status_change_prepare(unsigned long vaddr, int numpages, bool enc) { + atomic_inc(&conversions_in_progress); + + /* + * Check after bumping conversions_in_progress to serialize + * against tdx_kexec_stop_conversion(). + */ + if (!conversion_allowed) { + atomic_dec(&conversions_in_progress); + return -EBUSY; + } + /* * Only handle shared->private conversion here. * See the comment in tdx_early_init(). */ - if (enc && !tdx_enc_status_changed(vaddr, numpages, enc)) + if (enc && !tdx_enc_status_changed(vaddr, numpages, enc)) { + atomic_dec(&conversions_in_progress); return -EIO; + } return 0; } @@ -826,17 +853,107 @@ static int tdx_enc_status_change_finish(unsigned long vaddr, int numpages, * Only handle private->shared conversion here. * See the comment in tdx_early_init(). */ - if (!enc && !tdx_enc_status_changed(vaddr, numpages, enc)) + if (!enc && !tdx_enc_status_changed(vaddr, numpages, enc)) { + atomic_dec(&conversions_in_progress); return -EIO; + } if (enc) atomic_long_sub(numpages, &nr_shared); else atomic_long_add(numpages, &nr_shared); + atomic_dec(&conversions_in_progress); + return 0; } +static void tdx_kexec_stop_conversion(bool crash) +{ + /* Stop new private<->shared conversions */ + conversion_allowed = false; + + /* + * Make sure conversion_allowed is cleared before checking + * conversions_in_progress. + */ + barrier(); + + /* + * Crash kernel reaches here with interrupts disabled: can't wait for + * conversions to finish. + * + * If race happened, just report and proceed. + */ + if (!crash) { + unsigned long timeout; + + /* + * Wait for in-flight conversions to complete. + * + * Do not wait more than 30 seconds. + */ + timeout = 30 * USEC_PER_SEC; + while (atomic_read(&conversions_in_progress) && timeout--) + udelay(1); + } + + if (atomic_read(&conversions_in_progress)) + pr_warn("Failed to finish shared<->private conversions\n"); +} + +static void tdx_kexec_unshare_mem(void) +{ + unsigned long addr, end; + long found = 0, shared; + + /* + * Walk direct mapping and convert all shared memory back to private, + */ + + addr = PAGE_OFFSET; + end = PAGE_OFFSET + get_max_mapped(); + + while (addr < end) { + unsigned long size; + unsigned int level; + pte_t *pte; + + pte = lookup_address(addr, &level); + size = page_level_size(level); + + if (pte && pte_decrypted(*pte)) { + int pages = size / PAGE_SIZE; + + /* + * Touching memory with shared bit set triggers implicit + * conversion to shared. + * + * Make sure nobody touches the shared range from + * now on. + */ + set_pte(pte, __pte(0)); + + if (!tdx_enc_status_changed(addr, pages, true)) { + pr_err("Failed to unshare range %#lx-%#lx\n", + addr, addr + size); + } + + found += pages; + } + + addr += size; + } + + __flush_tlb_all(); + + shared = atomic_long_read(&nr_shared); + if (shared != found) { + pr_err("shared page accounting is off\n"); + pr_err("nr_shared = %ld, nr_found = %ld\n", shared, found); + } +} + void __init tdx_early_init(void) { struct tdx_module_args args = { @@ -896,6 +1013,9 @@ void __init tdx_early_init(void) x86_platform.guest.enc_cache_flush_required = tdx_cache_flush_required; x86_platform.guest.enc_tlb_flush_required = tdx_tlb_flush_required; + x86_platform.guest.enc_kexec_stop_conversion = tdx_kexec_stop_conversion; + x86_platform.guest.enc_kexec_unshare_mem = tdx_kexec_unshare_mem; + /* * TDX intercepts the RDMSR to read the X2APIC ID in the parallel * bringup low level code. That raises #VE which cannot be handled From patchwork Tue Feb 27 18:16:11 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: 207415 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2955387dyb; Tue, 27 Feb 2024 12:45:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV+Ljd9NuBJcu+zzY528qefNF7sfKIoys6t3cHtMzDdumCkizDyqZgZ+lFlDFZeZBOhv+NdnL5II+X3z3sX1QJVg+CKBw== X-Google-Smtp-Source: AGHT+IELXe6IvzCkdW0hB9l0Zjj0c2ZG+fNz4zZyDeNkLQfp7NnR+X3QZpwWptRy4T2qAJVZ37kS X-Received: by 2002:a17:902:ce89:b0:1db:8c35:c40d with SMTP id f9-20020a170902ce8900b001db8c35c40dmr11462460plg.27.1709066733661; Tue, 27 Feb 2024 12:45:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709066733; cv=pass; d=google.com; s=arc-20160816; b=i+IdWkHTsoPB5xBs/QYFUey1/8vJV2h22bjOedlZ9bKd4/GACDd8vHuin6xJRbiUTK XGzdyI7EohLvKLYfJNkClhg7lG7vmFMAyeqcjlGpgmLcVxMssYb52KV9rO8RKAdoDEl/ zv5zl8jhevUiYqZXoRPEEiXq+wOgY25EmkHML27E9+NRRnaHQTQMEXUrJ2/njK5j7cMB nWkAozpdUVmuNeFIqS07K5elr2WigEEZUB9bJzhife9lfUXU1Ck5VDz40sNCoa6Y+MgS WchiH01TWQVVOQwJAXsBcxw2QRCBX+K4JW0DyQ8JEJGFy/YVSNusC8CKkuDQZF0KWsv6 h4bQ== 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=PxBuA3tza228VpHxq/8kDNlnhjjwxZOy50g367z+tN0=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=eyDEDV7I5BJA/vzdWvBvmNXDjDjlE4LAvwV74w2Mhmn2E/QNzKty2ncDr63ZKRDQWK +TIzphfdPZX/vm8Xc/PPPOD1/77DyY9Yy7MFVwQEVO5x5/6285TTpdlhKN2t5yFzmuL4 EYqs/9PzrIfK2MmXq6+FN017IJYZPs9Ieuc6QNOWPLU1BEFa/GOclZEwP5PBDnOH2+vl 4lBfR+A3PbJgjVJySzOFDyPHU/v/O+E3xNutQGvEw6KBfWR28ger+wJmo2BZ2ego8mHO BdUdBlgLktm4IqWMSP0LiuGwIug7Ki8kLB8JRE+7d5mExEoK9QpX71P9/pU4+cbBrnWR Cd3A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QrnLl6wo; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83815-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83815-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p6-20020a170902ebc600b001dcc1450482si1005327plg.553.2024.02.27.12.45.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 12:45:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83815-ouuuleilei=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=QrnLl6wo; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83815-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83815-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 5864028E2E8 for ; Tue, 27 Feb 2024 18:18:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4BCB14F991; Tue, 27 Feb 2024 18:17:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QrnLl6wo" 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 9065F14830F for ; Tue, 27 Feb 2024 18:17:00 +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=1709057822; cv=none; b=DsDOTcbW2mBUA3LL+noJRyf3z5+8FxpQUgsIzkxzEA7dceGmcPYom9cAZZVyW8NiGXYiYQcNGgIug2zHw2WKVRpNrrCMu0by9E3HYD0lj+D98d0GM83tnRrAy5wi154fJEi4+ByILc1EQjx4xTHcBf29xtg/z/Va5Ge+zKaMZ7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057822; c=relaxed/simple; bh=9DcFlB+EMYNkp2N6OZv2c5TmDu3Stsj7JMO1CUBiP2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UK4QMKvxnSQZfMqH1eIpPxfnFhSpvgMFG3oE5eKun7ptTwW5q4K/1u0DekiXAGQQfD6B+DPjpVJ2somEoMtSREOno3GN9h6CTV0B6thOdwdOkt5IR0csguexo9QbTTrwdJMTw1HFIKnaN53MX4tO80DCWSI2zKH4Y1lXUOg+jaY= 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=QrnLl6wo; 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=1709057820; x=1740593820; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9DcFlB+EMYNkp2N6OZv2c5TmDu3Stsj7JMO1CUBiP2Q=; b=QrnLl6wo/nWJVEO3+WyG7XtARE55HsfWFKBZ/IAyJa5jlFKaghK8O46a RdoHtm94wuMVe4e86J5V92r2tgTvuagdHsZJdpV3VwAqGxfpVKejLtCBU st/wAlczEHfI4AbVSyMc2JgcPUrgyGclLbslbLyppYa7Hp5S2IoyyBlAh /SMR3fTwh1xtb1ZT1uIUjyPUmCU3GCc+GzxAHGQGfkodsuSjUxvze/g+b Kln8P0hRKBbAYK2PKlMAKncRCm4qFXc36rK8Zw6yNqu4gX2Jih5zQFXe9 wbOXXy3AGmy/TEwoJh6szwtb0klEpDuMtCQ1XxLD87FhbWgjarJe30Cdu w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966113" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966113" 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="937032729" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032729" 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 CBF8D9DB; 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 11/16] x86/mm: Make e820_end_ram_pfn() cover E820_TYPE_ACPI ranges Date: Tue, 27 Feb 2024 20:16:11 +0200 Message-ID: <20240227181616.3032032-12-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: 1792086359544298127 X-GMAIL-MSGID: 1792086359544298127 e820__end_of_ram_pfn() is used to calculate max_pfn which, among other things, guides where direct mapping ends. Any memory above max_pfn is not going to be present in the direct mapping. e820__end_of_ram_pfn() finds the end of the ram based on the highest E820_TYPE_RAM range. But it doesn't includes E820_TYPE_ACPI ranges into calculation. Despite the name, E820_TYPE_ACPI covers not only ACPI data, but also EFI tables and might be required by kernel to function properly. Usually the problem is hidden because there is some E820_TYPE_RAM memory above E820_TYPE_ACPI. But crashkernel only presents pre-allocated crash memory as E820_TYPE_RAM on boot. If the preallocated range is small, it can fit under the last E820_TYPE_ACPI range. Modify e820__end_of_ram_pfn() and e820__end_of_low_ram_pfn() to cover E820_TYPE_ACPI memory. The problem was discovered during debugging kexec for TDX guest. TDX guest uses E820_TYPE_ACPI to store the unaccepted memory bitmap and pass it between the kernels on kexec. Signed-off-by: Kirill A. Shutemov --- arch/x86/kernel/e820.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index fb8cf953380d..99c80680dc9e 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -827,7 +827,7 @@ u64 __init e820__memblock_alloc_reserved(u64 size, u64 align) /* * Find the highest page frame number we have available */ -static unsigned long __init e820_end_pfn(unsigned long limit_pfn, enum e820_type type) +static unsigned long __init e820_end_ram_pfn(unsigned long limit_pfn) { int i; unsigned long last_pfn = 0; @@ -838,7 +838,8 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, enum e820_type unsigned long start_pfn; unsigned long end_pfn; - if (entry->type != type) + if (entry->type != E820_TYPE_RAM && + entry->type != E820_TYPE_ACPI) continue; start_pfn = entry->addr >> PAGE_SHIFT; @@ -864,12 +865,12 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, enum e820_type unsigned long __init e820__end_of_ram_pfn(void) { - return e820_end_pfn(MAX_ARCH_PFN, E820_TYPE_RAM); + return e820_end_ram_pfn(MAX_ARCH_PFN); } unsigned long __init e820__end_of_low_ram_pfn(void) { - return e820_end_pfn(1UL << (32 - PAGE_SHIFT), E820_TYPE_RAM); + return e820_end_ram_pfn(1UL << (32 - PAGE_SHIFT)); } static void __init early_panic(char *msg) From patchwork Tue Feb 27 18:16:12 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: 207398 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2922457dyb; Tue, 27 Feb 2024 11:36:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWm7a4KztESRxOTeJS2A3/NN03WEc7oF2xxwJ47K5GECStTrmarDFYl9iTDpn0KxEG5t5/X4G6ed201+B39qve/+CmMhA== X-Google-Smtp-Source: AGHT+IG5i4oODfLKPpM5lHiev8TOk7XOa4ap57ZtMPGueLz9gNnfLy1qxBJuVmIfZE1AhQa3wC0n X-Received: by 2002:a92:cf4d:0:b0:365:13c0:1bc3 with SMTP id c13-20020a92cf4d000000b0036513c01bc3mr11158297ilr.20.1709062573761; Tue, 27 Feb 2024 11:36:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709062573; cv=pass; d=google.com; s=arc-20160816; b=acFsoLjA7StqksgbcEzof7pFlnsXSLV39V1w1AGCmhiApeUKZT9+bj/7xgOXxwQj8X wivSt9v7SJLx7IUeDk7PHV2kawCSiwd1QAcc6YGwfBgozvVqQDqZjuHU1egrF3e/7wdg YzndFAbJ+OiM5pispzRKzaM2pIEPTh/UoAeKzutRB0OLskkfxM1gWYDNk0DuCTBM4yzh qa/wixU8z2AbREoCBHYDH+veWG3QxawDVtONsr1F+6pl4sqQrBB025/L3yUCR53OT11T Xl4FPQbBaEwe8ES5sNAMVj3UoBmy+GYwkLI0N2NR8D4fLJkWH78AKT/RjoMTq3arzrwO e/kA== 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=fABvBnrgE/PLl1NAhjF5Rw+aQz9r1T2Knjys8UFYPbY=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=AVEV88nKNoIGRoN6jLJGETp6IpieD91egrPIJi3P70nG0vJ66d0urH+a9jvbzmCE+D yZvjP1hn9xqdai1ANIshHdvgITFG7xzzdwxcImcnltyIOADFzDBBtr1+hpTVAfhoavbn 9RZ8dUVY6Il4eV0H8aksFR3GIfZg42o8FDB4O8QNLO61MHwPB6wKk10VQfyN7vcKaT9V 1q6ZZ5YF0+p782IPX5Y+sykjYtJGpWow8fpp+zhxeN3JV8C0rpFb/kaGmwSApLF4g5Ca DG9VU40uCQL29veLKS6lyvESGltC67sje2RVDhWBfkCK/AKzPl/uX+LxHY2W/aYHGkPS Tl5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BZH7q81e; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83818-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83818-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 66-20020a630045000000b005dc846e12adsi5882985pga.655.2024.02.27.11.36.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 11:36:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83818-ouuuleilei=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=BZH7q81e; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83818-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83818-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 5154A28EC2F for ; Tue, 27 Feb 2024 18:19:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39A2F14AD23; Tue, 27 Feb 2024 18:17:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BZH7q81e" 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 C2DD514C58D for ; Tue, 27 Feb 2024 18:17:02 +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=1709057824; cv=none; b=aMPzvRc4NxR4PHPOSr/T09UJEGAGsdzRhtb68egYQV7bVvsvEtIZ2z0BOKSEs73LeMqeelhkHmo30h4GsDaIZEGct1XobKbJpIpuwcypEnScZfbrglQUKvu3gG6dkVvlwiBIPV78DQJD1g4hisZeFQ+vTedBPsWglObRQ58nZ0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057824; c=relaxed/simple; bh=Z3vEItFOpb/ayuVNTPFqaC8pjBMvLFGfG4ld+bFARLw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aHO6YiAdT+Z7mFWMNWdgJS2nvJvsH09Y1xe38wybLRFoEPM2978MXZOwm7ZoSjmQHpmWlmeZgidv7E52NgWI+K+WtDnoyDzTWm6AU8itSEntxgvj6SRylNkUIF2AOgnIEHMo4fBzAH5WTghNObTUs4CWq3KUZSfdKPqZMP0fZ4E= 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=BZH7q81e; 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=1709057823; x=1740593823; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Z3vEItFOpb/ayuVNTPFqaC8pjBMvLFGfG4ld+bFARLw=; b=BZH7q81eedKj1aD1Vz0Rp78ESIY+Fgk28xF1SHRMS+pIwApQV3ots0a2 MTJUW+6uBwUAVmYMeyRCv+6Wes8zfNLOEFRmbRJ8hl3s3xGKfQxTdU70L kgRkBEjMg2hvnOj43p6Tgx/vmkkHIxScdY5joCmg9o4BiXk3BAV2kA0JB MmcWtkbWLUNQVdNoh15Ul9xRrMkEv/MWDbUg1qjmvAI1+7+KVj3F1CAW+ 02bjnNTMvOgFXE49OX4VouCgNzYIf8saUbMGfWJphbb9c9TDoFdLkUN5j TXefKV0lcbjp5ZUom2uPJTdosVMR9NG1JpJ14R7YJJfPEXB0cJ/eb5wAW w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966148" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966148" 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="937032736" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032736" 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 D5470A0D; 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 12/16] x86/acpi: Rename fields in acpi_madt_multiproc_wakeup structure Date: Tue, 27 Feb 2024 20:16:12 +0200 Message-ID: <20240227181616.3032032-13-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: 1792081997169822382 X-GMAIL-MSGID: 1792081997169822382 To prepare for the addition of support for MADT wakeup structure version 1, it is necessary to provide more appropriate names for the fields in the structure. The field 'mailbox_version' renamed as 'version'. This field signifies the version of the structure and the related protocols, rather than the version of the mailbox. This field has not been utilized in the code thus far. The field 'base_address' renamed as 'mailbox_address' to clarify the kind of address it represents. In version 1, the structure includes the reset vector address. Clear and distinct naming helps to prevent any confusion. Signed-off-by: Kirill A. Shutemov Reviewed-by: Kai Huang Reviewed-by: Kuppuswamy Sathyanarayanan --- arch/x86/kernel/acpi/madt_wakeup.c | 2 +- include/acpi/actbl2.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/acpi/madt_wakeup.c b/arch/x86/kernel/acpi/madt_wakeup.c index d222be8d7a07..004801b9b151 100644 --- a/arch/x86/kernel/acpi/madt_wakeup.c +++ b/arch/x86/kernel/acpi/madt_wakeup.c @@ -75,7 +75,7 @@ int __init acpi_parse_mp_wake(union acpi_subtable_headers *header, acpi_table_print_madt_entry(&header->common); - acpi_mp_wake_mailbox_paddr = mp_wake->base_address; + acpi_mp_wake_mailbox_paddr = mp_wake->mailbox_address; cpu_hotplug_disable_offlining(); diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index 9775384d61c6..e1a395af7591 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -1117,9 +1117,9 @@ struct acpi_madt_generic_translator { struct acpi_madt_multiproc_wakeup { struct acpi_subtable_header header; - u16 mailbox_version; + u16 version; u32 reserved; /* reserved - must be zero */ - u64 base_address; + u64 mailbox_address; }; #define ACPI_MULTIPROC_WAKEUP_MB_OS_SIZE 2032 From patchwork Tue Feb 27 18:16:13 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: 207479 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3002294dyb; Tue, 27 Feb 2024 14:35:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWRk0JLJL+sr1JFXyYi2z80xCf5PzN5grXlcjeOFEO63SmMUR8xXqiRLc6/G9Xb3JTrUrhVLasWYF9wWxk89kz/rexJ6g== X-Google-Smtp-Source: AGHT+IGEBPwtuQQ4JwONS9W8WWB9a1XHHGqeuGNCo0BvAwjWybWIDSEtFapGUcaa9/yXih2hGUEK X-Received: by 2002:a05:6a00:1796:b0:6e4:c88d:6e13 with SMTP id s22-20020a056a00179600b006e4c88d6e13mr1031019pfg.7.1709073318924; Tue, 27 Feb 2024 14:35:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709073318; cv=pass; d=google.com; s=arc-20160816; b=p1SL692K33qt386zcJfCvOcH3I5jcCbZAoogNyxWvRlcp/HxBLyAofx4Y93WnHfy/E dIHZCj8gowaLaUaJDlLH460A+fGeidaoHYtKzGRqWe3DBVArvz+tO0TYufGD4WQ67hLD m2CdLhJ3RxQLAOPSvt+2iiMKNYfiIO1vbA9/5LczBtrqhnPPwZo/ViUlAqong+smsRz6 sqKAYGNnTPnGe5VxzZFPSzPXacys4rRW64pUL5tin1mddjUueGJ7t3W954IGoIf1SRR0 TsZskfwyQwfjsP7t97LpxQT8rpiKQncIe5PAiVGh+sqsy9DtUG2SZfAo1pXwc8gINt7Y HJoA== 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=A477xU0NMiPmaRKikOD+AP/rAovKr91FXfBuKHuWsyo=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=MoQmlXTN7e4IRLstQAzkhIpswqs2eUp7O0fV/nCPOxVp0qn9hwj3kSAHR/0VtpuoMQ h8zUbKkNWs6V98YlWKdA681pY65fhKlddVPkEF96FHtnlHLCtttretXIL0qUMDkU1Wme USo8xYFYu9rPtUsIXwEgb3/YkNQ3p8m4d9DHJnXj6n85ggiKYrHGmvoDUVfX+smdgsBa CZp00fuaSRyYAmMbg8GJVjC7DsDpm7UvvB104rXY70LV+UaomSLzcEpzFFe+CQvJWx1v j5f2O+lTKlDzkSvppewNGmBvdkkXMxrQTSHD7vnbiUQGzrW/S367DtB7KnceXwDlvoZ9 Yhww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Hy8Dvf0U; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83820-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83820-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x25-20020a63b219000000b005dcc036c679si6053418pge.677.2024.02.27.14.35.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:35:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83820-ouuuleilei=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=Hy8Dvf0U; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83820-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83820-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 75A2F28F28F for ; Tue, 27 Feb 2024 18:20:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 10F0914F9EA; Tue, 27 Feb 2024 18:17:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Hy8Dvf0U" 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 8C77014E2C6 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=alp+EnG0JaBKyhDX0yAYZs1w3t++gQmOCHBCDBjBQokg88UzPQcv8J3Kk7jsMHJ8ggNaQ/SQHfFNYBOeKNlHxsU70yKYpY4miEQgqzMH7nuzuftT1JZXf3oe/eJfL5GbJ0cb+SjfXi9BI7QwuSg0Dxv8uEM79hqW2wheiSTJnv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057826; c=relaxed/simple; bh=dL+ZDyNfeHUiVdGS89eu26OHL8+JI0276K2FgncM1Wo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=docznx0KpiQqfUu9L8ZUxynFjAICeAzPC4tSP8GhkaM6Kq4CZuI0s4ZFmVAf3o/kYI21OuCu2Yt6lhg3LoYatMe6asBx1YoRJBMeQ2ch+XCuJjTzZhr0HJWsgFb7pcwkU0phaKalwhj60qhFNTakfGpNb5vkwWjQJkI9i7/wEuU= 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=Hy8Dvf0U; 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=dL+ZDyNfeHUiVdGS89eu26OHL8+JI0276K2FgncM1Wo=; b=Hy8Dvf0UWci8UdrKxTnj24ON3UX2onDCB4bKyXyNX9xiXqFOVziexPe8 fcwvunN03Zs5LD8FzW1JYcY/7p5XICq0MQt2RvnK8DfC1uXKOkdQvTGWe cV2dLHsCQI73YXlrF6LEnMjHP6b7Vh7rxPsenIochWtJ4jXT9zz7vuRCE 6Cf+YMEX4OKPSIf+fvgc+l/Iq4r//axN/dP4oMxreh372nCeI9oJSFBVO VW1hx+6vkZf4CT6Tm7RRG1gzAlYpBCcxAFzJK7TENxW0ij7YrilCXWa4h CHyS4ruQ/t1o2872n16fmmLYBIPd2Ta5z/hv7MkpzLpWVR0Glo6lFR44c A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966161" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966161" 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="937032737" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032737" 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 E44D1A43; 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 13/16] x86/acpi: Do not attempt to bring up secondary CPUs in kexec case Date: Tue, 27 Feb 2024 20:16:13 +0200 Message-ID: <20240227181616.3032032-14-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: 1792093264074738951 X-GMAIL-MSGID: 1792093264074738951 ACPI MADT doesn't allow to offline a CPU after it was onlined. This limits kexec: the second kernel won't be able to use more than one CPU. To prevent a kexec kernel from onlining secondary CPUs invalidate the mailbox address in the ACPI MADT wakeup structure which prevents a kexec kernel to use it. This is safe as the booting kernel has the mailbox address cached already and acpi_wakeup_cpu() uses the cached value to bring up the secondary CPUs. Note: This is a Linux specific convention and not covered by the ACPI specification. Signed-off-by: Kirill A. Shutemov Reviewed-by: Kai Huang Reviewed-by: Kuppuswamy Sathyanarayanan --- arch/x86/kernel/acpi/madt_wakeup.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/acpi/madt_wakeup.c b/arch/x86/kernel/acpi/madt_wakeup.c index 004801b9b151..30820f9de5af 100644 --- a/arch/x86/kernel/acpi/madt_wakeup.c +++ b/arch/x86/kernel/acpi/madt_wakeup.c @@ -14,6 +14,11 @@ static struct acpi_madt_multiproc_wakeup_mailbox *acpi_mp_wake_mailbox __ro_afte static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip) { + if (!acpi_mp_wake_mailbox_paddr) { + pr_warn_once("No MADT mailbox: cannot bringup secondary CPUs. Booting with kexec?\n"); + return -EOPNOTSUPP; + } + /* * Remap mailbox memory only for the first call to acpi_wakeup_cpu(). * @@ -64,6 +69,28 @@ static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip) return 0; } +static void acpi_mp_disable_offlining(struct acpi_madt_multiproc_wakeup *mp_wake) +{ + cpu_hotplug_disable_offlining(); + + /* + * ACPI MADT doesn't allow to offline a CPU after it was onlined. This + * limits kexec: the second kernel won't be able to use more than one CPU. + * + * To prevent a kexec kernel from onlining secondary CPUs invalidate the + * mailbox address in the ACPI MADT wakeup structure which prevents a + * kexec kernel to use it. + * + * This is safe as the booting kernel has the mailbox address cached + * already and acpi_wakeup_cpu() uses the cached value to bring up the + * secondary CPUs. + * + * Note: This is a Linux specific convention and not covered by the + * ACPI specification. + */ + mp_wake->mailbox_address = 0; +} + int __init acpi_parse_mp_wake(union acpi_subtable_headers *header, const unsigned long end) { @@ -77,7 +104,7 @@ int __init acpi_parse_mp_wake(union acpi_subtable_headers *header, acpi_mp_wake_mailbox_paddr = mp_wake->mailbox_address; - cpu_hotplug_disable_offlining(); + acpi_mp_disable_offlining(mp_wake); apic_update_callback(wakeup_secondary_cpu_64, acpi_wakeup_cpu); 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 (;;) From patchwork Tue Feb 27 18:16:15 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: 207446 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2973858dyb; Tue, 27 Feb 2024 13:25:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUZjP5eozlm0K1nTlSOjOiM3WAMHWlBnD/cTAdLqJaUldOha96MeaBCie+v/NvH/RzmbAyQ18Tj8Ltal7j/1PeyKCsGNA== X-Google-Smtp-Source: AGHT+IGJ3jxgbXfGftqgGIKEPtkg7QnZmpveIzSgfSD/LOv4cXfjwoP2C1qMUzDEzveA6w+k2BPz X-Received: by 2002:a05:6358:939e:b0:17b:c624:b0a1 with SMTP id h30-20020a056358939e00b0017bc624b0a1mr2711690rwb.23.1709069135002; Tue, 27 Feb 2024 13:25:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709069134; cv=pass; d=google.com; s=arc-20160816; b=oIeVnoPf6/7QwOiVpvfDEQEhWr9nq7Mje55+PEzOEK7nYljPAGLCzencZQ14QmJ6LO 5JyvnnEUDoODuEvDpoAs40cJCbD6jkaaetKV/KgR9DyoQSx8X/d/8x0vLHJ6kCmzGpiF ZfZOgJu10TTVQ9tgiz2aPgQQGRCqpVzYG5XDS2s42K33QcgKTzW7r23MphIkCnv4IRwJ 23Twer8Im+J79SI6IxSwEoT9BSs5zRzoGC/EjrVZ5518juK4bDGq8RQsfj/NtzsyW8aB jqZ/xXsPlQyqwupBLWwyses6C0h/a4ZMKLqrahbz99ZgdzhqL8VEZlTD/XTAUqmTTu+U CZyQ== 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=tC0l902aAQNJZysp4ke9uf0VMLVFZv1kHnyDv7d3b6M=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=MTM6W9RzSsCEapEasyuH/np5wo5F9Y04AxhWmBeJKle3BNkGBRSAIbW8NNOItcOgqG OtlSLztPOica2xJTKpkepf/wCxr9jZPRIiSSBH2/fpN/QR8OF8mSp0U6/cMto+JkosZs 5nvPNtp6Q33xxkjU/osaervDfQJ6CKBvF1HMrN5s21xvRtpS9OZQUe2m61CqNfDT+gzR DdQpGIcVxsYh1XnACzn3xD6gaqarCrI+1VpoeYA0Qdrf4LgiXWHv/sG9ViXZCgTTlSer WaydEPBShqFg44FJjhQRpmhP+P86hpUK2+GQyTAglIGzaX+iuacqZqM2knsaa17SmDbv gKew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k8VPUy6J; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83823-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83823-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 iw14-20020a0562140f2e00b006900841048asi5775793qvb.282.2024.02.27.13.25.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 13:25:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83823-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=k8VPUy6J; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83823-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83823-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 BB10F1C2734A for ; Tue, 27 Feb 2024 18:20:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A314156963; Tue, 27 Feb 2024 18:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="k8VPUy6J" 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 025C214F99E for ; Tue, 27 Feb 2024 18:17:06 +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=1709057829; cv=none; b=OfOFIX0/90EeqlnTAWNXs/F2zUtnLfASMKdi/gNWL30uQ9/7SvA0Dy4hmDiE+LKmdHbGAYoDGUQLngjsqFfbLB5YLJrqQ7Ulk8zU1Sc+UCjEB5u5kvpri0nGLe76NIG6wHKR6JqfB1JJ9l+eE9WYopa29ZlNnJ3bs5Aco/l6g2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057829; c=relaxed/simple; bh=9HS0zSPwIGWp/4cXpPzLT+C1ZEn2tRFHFH5LFIKn6KI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OD9FwAdijdbi7uOGtooxoQhv3rziCg8zs8NdXSUki1HAvaTp6nPMSSnew4lQvQ34A3pXqrp7AwVl4M27ebOuyMjlr5CRC09NQc/LIGVDfgc6YIVRE8aaRmE5L4pq1NWXRAzXdsiHG/TetxYWAYQB+cvXTUu1GZfp7+IbIPAKLA0= 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=k8VPUy6J; 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=1709057827; x=1740593827; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9HS0zSPwIGWp/4cXpPzLT+C1ZEn2tRFHFH5LFIKn6KI=; b=k8VPUy6J3tjI96DGHLF8XB3JsMxyRwpMcKH8WCtAgvn8VgiiUKVpippr 3ZzfRE4znzb9h354SeYoWNdkfARJcejVqqO81+R2UDwQKaiZiPu8Go0Sf pbKGZKsqS8ROZ0OfO/luknJNpShxClK1cqrkrmHXjLh48C1qLXt/tigTK hWVk7R4v5K+oo4uQijscINlBiS/yOqSK21mD37k8/N9QN5ZKoK4Du1C3Y DxhfkpBiuVMvutb98zZ/2+KB2QP+uYKEVKEjQJsjZeVvCwt/wIfG3xFCk /moDXZG/QAdFRS1bYwE/51pnrufnMPGu31bON/U1uzE1LhDYDT8Y/FP14 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966210" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966210" 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:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032747" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032747" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 10:16:31 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 0507CAE0; Tue, 27 Feb 2024 20:16:20 +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 15/16] x86/mm: Introduce kernel_ident_mapping_free() Date: Tue, 27 Feb 2024 20:16:15 +0200 Message-ID: <20240227181616.3032032-16-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: 1792088877174244907 X-GMAIL-MSGID: 1792088877174244907 The helper complements kernel_ident_mapping_init(): it frees the identity mapping that was previously allocated. It will be used in the error path to free a partially allocated mapping or if the mapping is no longer needed. The caller provides a struct x86_mapping_info with the free_pgd_page() callback hooked up and the pgd_t to free. Signed-off-by: Kirill A. Shutemov Acked-by: Kai Huang --- arch/x86/include/asm/init.h | 3 ++ arch/x86/mm/ident_map.c | 73 +++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/arch/x86/include/asm/init.h b/arch/x86/include/asm/init.h index cc9ccf61b6bd..14d72727d7ee 100644 --- a/arch/x86/include/asm/init.h +++ b/arch/x86/include/asm/init.h @@ -6,6 +6,7 @@ struct x86_mapping_info { void *(*alloc_pgt_page)(void *); /* allocate buf for page table */ + void (*free_pgt_page)(void *, void *); /* free buf for page table */ void *context; /* context for alloc_pgt_page */ unsigned long page_flag; /* page flag for PMD or PUD entry */ unsigned long offset; /* ident mapping offset */ @@ -16,4 +17,6 @@ struct x86_mapping_info { int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page, unsigned long pstart, unsigned long pend); +void kernel_ident_mapping_free(struct x86_mapping_info *info, pgd_t *pgd); + #endif /* _ASM_X86_INIT_H */ diff --git a/arch/x86/mm/ident_map.c b/arch/x86/mm/ident_map.c index 968d7005f4a7..3996af7b4abf 100644 --- a/arch/x86/mm/ident_map.c +++ b/arch/x86/mm/ident_map.c @@ -4,6 +4,79 @@ * included by both the compressed kernel and the regular kernel. */ +static void free_pte(struct x86_mapping_info *info, pmd_t *pmd) +{ + pte_t *pte = pte_offset_kernel(pmd, 0); + + info->free_pgt_page(pte, info->context); +} + +static void free_pmd(struct x86_mapping_info *info, pud_t *pud) +{ + pmd_t *pmd = pmd_offset(pud, 0); + int i; + + for (i = 0; i < PTRS_PER_PMD; i++) { + if (!pmd_present(pmd[i])) + continue; + + if (pmd_leaf(pmd[i])) + continue; + + free_pte(info, &pmd[i]); + } + + info->free_pgt_page(pmd, info->context); +} + +static void free_pud(struct x86_mapping_info *info, p4d_t *p4d) +{ + pud_t *pud = pud_offset(p4d, 0); + int i; + + for (i = 0; i < PTRS_PER_PUD; i++) { + if (!pud_present(pud[i])) + continue; + + if (pud_leaf(pud[i])) + continue; + + free_pmd(info, &pud[i]); + } + + info->free_pgt_page(pud, info->context); +} + +static void free_p4d(struct x86_mapping_info *info, pgd_t *pgd) +{ + p4d_t *p4d = p4d_offset(pgd, 0); + int i; + + for (i = 0; i < PTRS_PER_P4D; i++) { + if (!p4d_present(p4d[i])) + continue; + + free_pud(info, &p4d[i]); + } + + if (pgtable_l5_enabled()) + info->free_pgt_page(pgd, info->context); +} + +void kernel_ident_mapping_free(struct x86_mapping_info *info, pgd_t *pgd) +{ + int i; + + for (i = 0; i < PTRS_PER_PGD; i++) { + if (!pgd_present(pgd[i])) + continue; + + free_p4d(info, &pgd[i]); + } + + info->free_pgt_page(pgd, info->context); +} + static void ident_pmd_init(struct x86_mapping_info *info, pmd_t *pmd_page, unsigned long addr, unsigned long end) { From patchwork Tue Feb 27 18:16:16 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: 207447 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2973943dyb; Tue, 27 Feb 2024 13:25:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWJ4FM0fDgPl1vrtaINDnD7PO0WUn7AtzGFiVzCN/syZvXpMYz5X/aysbXfWMKAUAqAtoCUMtOA77O9l0KHYL7M7k+psg== X-Google-Smtp-Source: AGHT+IEMFQpSqgCpJ8OUmicfEukgZ7sLv3hepOu7p1g/gmrwqz9ZmeHWvlS0Dfg1Gk0ASOi/a126 X-Received: by 2002:a05:6214:624:b0:68f:cc6a:458b with SMTP id a4-20020a056214062400b0068fcc6a458bmr3932800qvx.50.1709069146675; Tue, 27 Feb 2024 13:25:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709069146; cv=pass; d=google.com; s=arc-20160816; b=UfBQoEParVF/Gp/WhS/u/l6Ylof/AjgYXNVbzNVyr527lP1NDnR/aLnC1/AUhHDm1L RWSpeS98kmry967eH+G0IAn22UDRanQZDBdFmICXdVru02brsQbucirmPGDPSJ1Vc9/B D9IHxSUYYkDwDyDDNaPACl3hP5eSrZaqbUd2otIotEM6BLcRXt7LW6mczC5jwL/I5olA DVEQGt7qfZp9NK0Z6V9Wn5OBVUxEQAbglxU/qT95nsPEIMNCWCuBc8nXS7X1yukO9Qzu EQSw4+u95ph5/rTdBtbc4yfC4pXWMIG1d48OiLSxgs/YRauwqmr6jVUqiSG5T1NrIBGQ M+ig== 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=Bx1V1g15xQfOm+SjjiqcwzJKqUfqswL3nB5AP3sSgB4=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=KT7PUdTvwp/Rt5fp7fvRarQLkINsELP2pPUGdYvrdC3yYkBf1hPScHl2z9zB2MrzVs 5pxAMkMFdw5EPwq1AuEnqMWD2rS7PFxwcj9A0TAoxbr4zGRbmoN0Sxl+oJrld4mgOQJ0 hboCd8TERoRrSXt9g0rrECHSrOWByryG0sKg3ZDnh/TD1OaXHcTF/uZuVf4Mri6LRX42 uRE7JICKEf/q0yupjre2noP6xPY1jbxMnFVP7rbAk/XddYCdHAkJryqAy4ZPGCPRiEFt ym+60fFpQIOnAb6wUFxLdC30SDzJVa7HTQBQssSRctlFsk2MtFURLBbbg2a6yvGVBtg4 i05g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BYL0uyvc; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83824-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83824-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. [147.75.199.223]) by mx.google.com with ESMTPS id h15-20020a0562140daf00b0068f08c94871si8472946qvh.513.2024.02.27.13.25.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 13:25:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83824-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BYL0uyvc; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83824-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83824-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 35AA71C27CA1 for ; Tue, 27 Feb 2024 18:20:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED4AB158D66; Tue, 27 Feb 2024 18:17:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BYL0uyvc" 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 5284314F9D5 for ; Tue, 27 Feb 2024 18:17:07 +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=1709057829; cv=none; b=cILM9sj3t086uY10x97mIKbQ5IUexS1MwpNauiY4sll8ObHJoynLJ+EiZGPSMQjStkSeH1s8KXMmlIqCX2Tulz8UKttKz2bxPwbnO1EMu4Bfpet75UegoYvIkjVnhsTj2amKGnnZOLeEXgaPu8x2vg1vlORJz5rX5vKwRD4nPkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057829; c=relaxed/simple; bh=5rPhka26cuxx92EnGqjwsdfPdCSUmQ6iGaqaueVO7cw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uYi3YwfO8u3NkxKcrdbje1zAhp+uNF+6ZVzcQc5DT06IXczO3Gq9MkI2htQz1aKJin/TGpxOinc8eiGjUnNx1OR1Gf6R2Jac9qLn8E/pwZgDto6bM60zZqUASC2DbrRieCVjsJwt+Q9iMGBO8I+G9UUMU3Ki76yZSDcvo5iyvm0= 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=BYL0uyvc; 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=1709057827; x=1740593827; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5rPhka26cuxx92EnGqjwsdfPdCSUmQ6iGaqaueVO7cw=; b=BYL0uyvc/9mXOvamAqc1FHulzt5dYVYw7zVXJGhzf08yt5GlJ82tSJt5 psgx9+DdN620mtEOrTqxsN7IQ4kvYZO6rqEewsFB1HjA//ZpsNhRaVy8J 6eN+1qzLoRW0IyISIW2H3oDRPipO7hklW9hmylHeEmJX9CGLSDt6Fpfyc o926osupYDojPffUzvRbPtNuZRxH68zf1T3dHrvgkLSXxtcjeSkE8m+U0 uxOPaIKEz7+TRc7geROdaSP4EBjbUJJdyXdDY29lSh8gwWBNdFncnPXqf 0C+JkEZSUSdXm0Mnwjrz0eo7OrxbpCwdSKX4j8jPNzlzM3h/1dmP7euw5 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966218" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966218" 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:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032749" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032749" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 10:16:31 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 0FA48B0A; Tue, 27 Feb 2024 20:16:20 +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 16/16] x86/acpi: Add support for CPU offlining for ACPI MADT wakeup method Date: Tue, 27 Feb 2024 20:16:16 +0200 Message-ID: <20240227181616.3032032-17-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: 1792088889687000661 X-GMAIL-MSGID: 1792088889687000661 MADT Multiprocessor Wakeup structure version 1 brings support of CPU offlining: BIOS provides a reset vector where the CPU has to jump to for offlining itself. The new TEST mailbox command can be used to test whether the CPU offlined itself which means the BIOS has control over the CPU and can online it again via the ACPI MADT wakeup method. Add CPU offling support for the ACPI MADT wakeup method by implementing custom cpu_die(), play_dead() and stop_this_cpu() SMP operations. CPU offlining makes is possible to hand over secondary CPUs over kexec, not limiting the second kernel to a single CPU. The change conforms to the approved ACPI spec change proposal. See the Link. Signed-off-by: Kirill A. Shutemov Link: https://lore.kernel.org/all/13356251.uLZWGnKmhe@kreacher Acked-by: Kai Huang Reviewed-by: Kuppuswamy Sathyanarayanan --- arch/x86/include/asm/acpi.h | 2 + arch/x86/kernel/acpi/Makefile | 2 +- arch/x86/kernel/acpi/madt_playdead.S | 28 ++++ arch/x86/kernel/acpi/madt_wakeup.c | 184 ++++++++++++++++++++++++++- include/acpi/actbl2.h | 15 ++- 5 files changed, 227 insertions(+), 4 deletions(-) create mode 100644 arch/x86/kernel/acpi/madt_playdead.S diff --git a/arch/x86/include/asm/acpi.h b/arch/x86/include/asm/acpi.h index 2625b915ae7f..021cafa214c2 100644 --- a/arch/x86/include/asm/acpi.h +++ b/arch/x86/include/asm/acpi.h @@ -81,6 +81,8 @@ union acpi_subtable_headers; int __init acpi_parse_mp_wake(union acpi_subtable_headers *header, const unsigned long end); +void asm_acpi_mp_play_dead(u64 reset_vector, u64 pgd_pa); + /* * Check if the CPU can handle C2 and deeper */ diff --git a/arch/x86/kernel/acpi/Makefile b/arch/x86/kernel/acpi/Makefile index 8c7329c88a75..37b1f28846de 100644 --- a/arch/x86/kernel/acpi/Makefile +++ b/arch/x86/kernel/acpi/Makefile @@ -4,7 +4,7 @@ obj-$(CONFIG_ACPI) += boot.o obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_$(BITS).o obj-$(CONFIG_ACPI_APEI) += apei.o obj-$(CONFIG_ACPI_CPPC_LIB) += cppc.o -obj-$(CONFIG_X86_ACPI_MADT_WAKEUP) += madt_wakeup.o +obj-$(CONFIG_X86_ACPI_MADT_WAKEUP) += madt_wakeup.o madt_playdead.o ifneq ($(CONFIG_ACPI_PROCESSOR),) obj-y += cstate.o diff --git a/arch/x86/kernel/acpi/madt_playdead.S b/arch/x86/kernel/acpi/madt_playdead.S new file mode 100644 index 000000000000..4e498d28cdc8 --- /dev/null +++ b/arch/x86/kernel/acpi/madt_playdead.S @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include +#include +#include +#include + + .text + .align PAGE_SIZE + +/* + * asm_acpi_mp_play_dead() - Hand over control of the CPU to the BIOS + * + * rdi: Address of the ACPI MADT MPWK ResetVector + * rsi: PGD of the identity mapping + */ +SYM_FUNC_START(asm_acpi_mp_play_dead) + /* Turn off global entries. Following CR3 write will flush them. */ + movq %cr4, %rdx + andq $~(X86_CR4_PGE), %rdx + movq %rdx, %cr4 + + /* Switch to identity mapping */ + movq %rsi, %cr3 + + /* Jump to reset vector */ + ANNOTATE_RETPOLINE_SAFE + jmp *%rdi +SYM_FUNC_END(asm_acpi_mp_play_dead) diff --git a/arch/x86/kernel/acpi/madt_wakeup.c b/arch/x86/kernel/acpi/madt_wakeup.c index 30820f9de5af..6cfe762be28b 100644 --- a/arch/x86/kernel/acpi/madt_wakeup.c +++ b/arch/x86/kernel/acpi/madt_wakeup.c @@ -1,10 +1,19 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include #include +#include #include +#include +#include +#include +#include #include #include +#include +#include +#include #include +#include /* Physical address of the Multiprocessor Wakeup Structure mailbox */ static u64 acpi_mp_wake_mailbox_paddr __ro_after_init; @@ -12,6 +21,154 @@ static u64 acpi_mp_wake_mailbox_paddr __ro_after_init; /* Virtual address of the Multiprocessor Wakeup Structure mailbox */ static struct acpi_madt_multiproc_wakeup_mailbox *acpi_mp_wake_mailbox __ro_after_init; +static u64 acpi_mp_pgd __ro_after_init; +static u64 acpi_mp_reset_vector_paddr __ro_after_init; + +static void acpi_mp_stop_this_cpu(void) +{ + asm_acpi_mp_play_dead(acpi_mp_reset_vector_paddr, acpi_mp_pgd); +} + +static void acpi_mp_play_dead(void) +{ + play_dead_common(); + asm_acpi_mp_play_dead(acpi_mp_reset_vector_paddr, acpi_mp_pgd); +} + +static void acpi_mp_cpu_die(unsigned int cpu) +{ + u32 apicid = per_cpu(x86_cpu_to_apicid, cpu); + unsigned long timeout; + + /* + * Use TEST mailbox command to prove that BIOS got control over + * the CPU before declaring it dead. + * + * BIOS has to clear 'command' field of the mailbox. + */ + acpi_mp_wake_mailbox->apic_id = apicid; + smp_store_release(&acpi_mp_wake_mailbox->command, + ACPI_MP_WAKE_COMMAND_TEST); + + /* Don't wait longer than a second. */ + timeout = USEC_PER_SEC; + while (READ_ONCE(acpi_mp_wake_mailbox->command) && --timeout) + udelay(1); + + if (!timeout) + pr_err("Failed to hand over CPU %d to BIOS\n", cpu); +} + +/* The argument is required to match type of x86_mapping_info::alloc_pgt_page */ +static void __init *alloc_pgt_page(void *dummy) +{ + return memblock_alloc(PAGE_SIZE, PAGE_SIZE); +} + +static void __init free_pgt_page(void *pgt, void *dummy) +{ + return memblock_free(pgt, PAGE_SIZE); +} + +/* + * Make sure asm_acpi_mp_play_dead() is present in the identity mapping at + * the same place as in the kernel page tables. asm_acpi_mp_play_dead() switches + * to the identity mapping and the function has be present at the same spot in + * the virtual address space before and after switching page tables. + */ +static int __init init_transition_pgtable(pgd_t *pgd) +{ + pgprot_t prot = PAGE_KERNEL_EXEC_NOENC; + unsigned long vaddr, paddr; + p4d_t *p4d; + pud_t *pud; + pmd_t *pmd; + pte_t *pte; + + vaddr = (unsigned long)asm_acpi_mp_play_dead; + pgd += pgd_index(vaddr); + if (!pgd_present(*pgd)) { + p4d = (p4d_t *)alloc_pgt_page(NULL); + if (!p4d) + return -ENOMEM; + set_pgd(pgd, __pgd(__pa(p4d) | _KERNPG_TABLE)); + } + p4d = p4d_offset(pgd, vaddr); + if (!p4d_present(*p4d)) { + pud = (pud_t *)alloc_pgt_page(NULL); + if (!pud) + return -ENOMEM; + set_p4d(p4d, __p4d(__pa(pud) | _KERNPG_TABLE)); + } + pud = pud_offset(p4d, vaddr); + if (!pud_present(*pud)) { + pmd = (pmd_t *)alloc_pgt_page(NULL); + if (!pmd) + return -ENOMEM; + set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE)); + } + pmd = pmd_offset(pud, vaddr); + if (!pmd_present(*pmd)) { + pte = (pte_t *)alloc_pgt_page(NULL); + if (!pte) + return -ENOMEM; + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE)); + } + pte = pte_offset_kernel(pmd, vaddr); + + paddr = __pa(vaddr); + set_pte(pte, pfn_pte(paddr >> PAGE_SHIFT, prot)); + + return 0; +} + +static int __init acpi_mp_setup_reset(u64 reset_vector) +{ + struct x86_mapping_info info = { + .alloc_pgt_page = alloc_pgt_page, + .free_pgt_page = free_pgt_page, + .page_flag = __PAGE_KERNEL_LARGE_EXEC, + .kernpg_flag = _KERNPG_TABLE_NOENC, + }; + pgd_t *pgd; + + pgd = alloc_pgt_page(NULL); + if (!pgd) + return -ENOMEM; + + for (int i = 0; i < nr_pfn_mapped; i++) { + unsigned long mstart, mend; + + mstart = pfn_mapped[i].start << PAGE_SHIFT; + mend = pfn_mapped[i].end << PAGE_SHIFT; + if (kernel_ident_mapping_init(&info, pgd, mstart, mend)) { + kernel_ident_mapping_free(&info, pgd); + return -ENOMEM; + } + } + + if (kernel_ident_mapping_init(&info, pgd, + PAGE_ALIGN_DOWN(reset_vector), + PAGE_ALIGN(reset_vector + 1))) { + kernel_ident_mapping_free(&info, pgd); + return -ENOMEM; + } + + if (init_transition_pgtable(pgd)) { + kernel_ident_mapping_free(&info, pgd); + return -ENOMEM; + } + + smp_ops.play_dead = acpi_mp_play_dead; + smp_ops.stop_this_cpu = acpi_mp_stop_this_cpu; + smp_ops.cpu_die = acpi_mp_cpu_die; + + acpi_mp_reset_vector_paddr = reset_vector; + acpi_mp_pgd = __pa(pgd); + + return 0; +} + static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip) { if (!acpi_mp_wake_mailbox_paddr) { @@ -97,14 +254,37 @@ int __init acpi_parse_mp_wake(union acpi_subtable_headers *header, struct acpi_madt_multiproc_wakeup *mp_wake; mp_wake = (struct acpi_madt_multiproc_wakeup *)header; - if (BAD_MADT_ENTRY(mp_wake, end)) + + /* + * Cannot use the standard BAD_MADT_ENTRY() to sanity check the @mp_wake + * entry. 'sizeof (struct acpi_madt_multiproc_wakeup)' can be larger + * than the actual size of the MP wakeup entry in ACPI table because the + * 'reset_vector' is only available in the V1 MP wakeup structure. + */ + if (!mp_wake) + return -EINVAL; + if (end - (unsigned long)mp_wake < ACPI_MADT_MP_WAKEUP_SIZE_V0) + return -EINVAL; + if (mp_wake->header.length < ACPI_MADT_MP_WAKEUP_SIZE_V0) return -EINVAL; acpi_table_print_madt_entry(&header->common); acpi_mp_wake_mailbox_paddr = mp_wake->mailbox_address; - acpi_mp_disable_offlining(mp_wake); + if (mp_wake->version >= ACPI_MADT_MP_WAKEUP_VERSION_V1 && + mp_wake->header.length >= ACPI_MADT_MP_WAKEUP_SIZE_V1) { + if (acpi_mp_setup_reset(mp_wake->reset_vector)) { + pr_warn("Failed to setup MADT reset vector\n"); + acpi_mp_disable_offlining(mp_wake); + } + } else { + /* + * CPU offlining requires version 1 of the ACPI MADT wakeup + * structure. + */ + acpi_mp_disable_offlining(mp_wake); + } apic_update_callback(wakeup_secondary_cpu_64, acpi_wakeup_cpu); diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index e1a395af7591..2aedda70ef88 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -1120,8 +1120,20 @@ struct acpi_madt_multiproc_wakeup { u16 version; u32 reserved; /* reserved - must be zero */ u64 mailbox_address; + u64 reset_vector; }; +/* Values for Version field above */ + +enum acpi_madt_multiproc_wakeup_version { + ACPI_MADT_MP_WAKEUP_VERSION_NONE = 0, + ACPI_MADT_MP_WAKEUP_VERSION_V1 = 1, + ACPI_MADT_MP_WAKEUP_VERSION_RESERVED = 2, /* 2 and greater are reserved */ +}; + +#define ACPI_MADT_MP_WAKEUP_SIZE_V0 16 +#define ACPI_MADT_MP_WAKEUP_SIZE_V1 24 + #define ACPI_MULTIPROC_WAKEUP_MB_OS_SIZE 2032 #define ACPI_MULTIPROC_WAKEUP_MB_FIRMWARE_SIZE 2048 @@ -1134,7 +1146,8 @@ struct acpi_madt_multiproc_wakeup_mailbox { u8 reserved_firmware[ACPI_MULTIPROC_WAKEUP_MB_FIRMWARE_SIZE]; /* reserved for firmware use */ }; -#define ACPI_MP_WAKE_COMMAND_WAKEUP 1 +#define ACPI_MP_WAKE_COMMAND_WAKEUP 1 +#define ACPI_MP_WAKE_COMMAND_TEST 2 /* 17: CPU Core Interrupt Controller (ACPI 6.5) */