From patchwork Tue Feb 27 21:24:36 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: 207481 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3004677dyb; Tue, 27 Feb 2024 14:41:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXiLv+utifQz+NO9W2BHRnRJ0PAY3Kuo1JLhIpGslOafe4htRBw3dyFjXq1pgCbi/saRSHYWdnspylhSq3kjIr/gSfQlA== X-Google-Smtp-Source: AGHT+IH0N8G1K7f354YA3cP7VeE6mCWeiOvBX1AARts0KTTw/jvi6odrO033iUujnznU/t+ZLg+o X-Received: by 2002:aa7:db9a:0:b0:565:50d4:c6dc with SMTP id u26-20020aa7db9a000000b0056550d4c6dcmr573217edt.16.1709073709786; Tue, 27 Feb 2024 14:41:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709073709; cv=pass; d=google.com; s=arc-20160816; b=r8Ars7s59GvakvimsQDjHOeQqjcJtHmMKEBcNsri6jPJf4EVOq74X13xYuG6XXfNAH CK/wlYDUccMsAGYpTGZd8zcRLXa8g185OrbRx5ASto3vVlF+VgxNnJ5eHdAN6wySCm2v J3JFTDRaIZPJBioDhsJ0P1URtHtyyy7UCj/e5gR4vE/l04zc3s6XthyWUMVDfiYsD95B v87ycgPhyLNnuDKGY1SpQEzjIDqCw8RTKU9RHZYuhiAkVGxC1/QiRoo1LS+t38sNBIBh 2l0ArdZSMjs98u9v53dIcGOaqDZKjPYAbE7hskkVa9Ke/bopasMnqBLAG4JUE1Cx/48k qjgA== 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=GR0/KFZdyBXdTxzRz2WvJMFQRYklQAhAwM4bsUvim5k=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=O2+MPWv9uv7/vZf6CoXHIiu+i59Nu1cc/a5edEFarUePXrronn/evO3W/S2GUxJCYd ohLt4fKWbIxZucK5fjSIxZ23DXGsnAAh5USR+xLe/f+SpYw4K10Dxvd7vJnlukz98Z77 lEDPRYUGRBpadZP10WIz7yMEmRtqZ6pw3Hs71afTdsNBPz2gXU/IAT3WEMjTk+96qOUi AYesdzM03fJNVOQN7kW9N+f44jLZwgjkOx44s5PQjlIfFLqWAxU38Fnbu3yBmc26shz5 3HfEbhjNXQ9migU5x/x7FgueURznK7hUsCvf1wUvf7De8kofO/Cwa9XxwPEG2yugflPT YQtg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=O9zZwN9t; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84032-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84032-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 f8-20020aa7d848000000b00565864f1abcsi1034408eds.95.2024.02.27.14.41.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:41:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84032-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=O9zZwN9t; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84032-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84032-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 9E5071F2C199 for ; Tue, 27 Feb 2024 21:26:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9BEAE155A55; Tue, 27 Feb 2024 21:25:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="O9zZwN9t" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 8F24F14F960 for ; Tue, 27 Feb 2024 21:25:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069106; cv=none; b=ENrbwDMmO9eR5XVyA0S27ojCrSvib3S1VPE2Sqo3BRh+12EoM3E+sXz9vWK519aWmXwpbYS3v2u0Rzno7WFXEUvX3qGAd7mpbRnYTn0oFlQst4e2kmquhA7yedlDXXoqyYELUO0bBJDZdkrnUZ90VRNEx8WAQwyoKrhveikxbKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069106; c=relaxed/simple; bh=qMBZiGoU4y42o4BmHvvOhM3MATjtBtt+QaYWF3uujSg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b/NCa+fUngXBEDyKZ5jJ4TuNeSCyfAseX0NQ6PrJepuIThrkCUrMyyNdlVBIUtkJUO6QiweGaf6rSMqJh3XusZ++SVyCJxIfdQQgAbcjIvTk4K+W36hEM38vR6AhutFfeq4kZDe5slFVA1KHkR161zaKoNxDUoDdl5kYg48NA30= 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=O9zZwN9t; arc=none smtp.client-ip=198.175.65.16 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=1709069105; x=1740605105; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qMBZiGoU4y42o4BmHvvOhM3MATjtBtt+QaYWF3uujSg=; b=O9zZwN9tNjATdKpUwW693IkUsnx6ZDqQz+sNQAtDqsDylFcE+0CX0n/p Ew4PCNJbPcdBousJs1626UtHSWPiAq3zkikbcxThmFjNkpELMWgD4P5xi r1OhoIFQ5K1Iw2pVKIrDqqW1uDvGAX5ZHejwRaH5KF+imUhv/7QGVLW+S QHRSjxIuTJPizWh/eJ+zmWQY2jboOZUW7RESMfaMKfFoMeA2JUV9fsZWx YrxIlcemOFuIoVTXqVUawYXW+XttbqtO9PYiXBKB5x5M/7aeFZHj8aSYg jhqNToBSTy0wcf9t7bYzJ6fcUYVOxLCQ30esVileP/vg2+FYWCSAV2Cev w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3566919" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3566919" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032888" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032888" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:24:56 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id D083A18F; Tue, 27 Feb 2024 23:24:55 +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/17] x86/acpi: Extract ACPI MADT wakeup code into a separate file Date: Tue, 27 Feb 2024 23:24:36 +0200 Message-ID: <20240227212452.3228893-2-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792093674454013221 X-GMAIL-MSGID: 1792093674454013221 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 Reviewed-by: Baoquan He Reviewed-by: Thomas Gleixner --- 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 c9d78ad936ec..e15b6f70f0ad 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1117,6 +1117,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 21:24:37 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: 207548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3050496dyb; Tue, 27 Feb 2024 16:30:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXiAdnaT9apy4C0v1YJuV3RC4i6KK6laFu1ndCBhInjNRa5L0IBJrtfLFUZ2MXCB8k8ufPmc1m56JC9ltl9IusDIzlEOA== X-Google-Smtp-Source: AGHT+IEvGoznigeqXJ5xSUjvecwNHmR96whstPFyxPflNvQBx4Lf/cE4EAu4FmqF8okPNgBA0MZl X-Received: by 2002:a17:902:ed0d:b0:1db:bec6:9147 with SMTP id b13-20020a170902ed0d00b001dbbec69147mr11091649pld.44.1709080226540; Tue, 27 Feb 2024 16:30:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709080226; cv=pass; d=google.com; s=arc-20160816; b=O2wM4cbI0Np2vNB1ZY6B9Lhzu9rzp00wJtlSHwbVmXnumPtKxGysFNDLt8KJx+QAOf 7kpAIGFCP4EXI2vjXJiq/V4vkcPgDSZPO/i4izPBW1IyAJTa5qDfk5mUT1hEQLkGOzmR WQ0Drcgk1gsjKjhRP5DsI5wQQC+sawHuQ46Lo4eyHQAU6cK1nb5R7S36xklVUdU/cSUO dLSaDJ9N7pTra5eKKBMTlyH+f8KzoEsJU4q3f2zmcokjjoYXIQ9MWJ2wMAn/R8a6quIu CYDuC6CVpDS7SgqQKc5B6WhPirR9gXsXIZizz3YKLJWCdnuYJQwufU5fXVl6S0iUsFy1 s8xA== 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=Usz6NqPuoR+4t6o4/+BGrule5lXSNDgUkzsE+6hTGrM=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=UEcuUCunW7UgzVVmkRjI4OOO9zkJMWvBa4Ezv/MjeoiDSG2/bEfJ2v84xGehTtI4+4 V8wTECXP8QoMIdpDQnswfCTGMs+gsOQllnLIAHlm6VSIG0yu2+iA7PoFlAYBr/QsHa6J jF1M97BEgdzfhMjnvo+os9lFMe/GKw6/RLqoIfuAJmLfcdB5fkwUJv09584KqI0ATVMX K1/5KnTZWXuvRijYyDHBJZtT3mZMyfR9oK1pcmPLKLYJ6Th9bcQTCFLLLOIwWu6500Uu KndPet1b7/c6Bs3Eu9lybEwPcG7NURO6yj+coVlO9M8CxeSbEVhhA0uzYXn6qTfMRqjC S+eg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MeqskkXT; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84031-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84031-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 d11-20020a170902654b00b001dc819f1591si2136433pln.463.2024.02.27.16.30.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 16:30:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84031-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=MeqskkXT; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84031-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84031-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 F32DF2893D5 for ; Tue, 27 Feb 2024 21:25:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F1FE14F9EA; Tue, 27 Feb 2024 21:25:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MeqskkXT" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 1A37314EFF3 for ; Tue, 27 Feb 2024 21:25:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069104; cv=none; b=VzUGD4NcFDkj5tOqIPZ20naHRMGddL2nTj4tOY9s8N30XgL8oEjC44HzfBIx+Tl4K/Q34H2EWiDhZRtVYVhLkKgDfxMWUMGg17NlHl8I9QXtOYPv84F98yCeOXvg1SxwXpVbkmAs/3OCvkr/uHLjRYeOjpafyBHfzQveqHRFeqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069104; c=relaxed/simple; bh=xIprGuZ+wzLEKGSqnVchQykT8aBwBOBoQqpTJEhq/2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P4hv1MjJ/4+yBaZayLac9pjICBv1bOAZhvT3FDfcQaVBltWmm/WyXbkQgFWToEQfvfzKSIL0DI1fm6nY6CYDtWDsIoB2DWXyzlM8AZOlGl4R3iVz95tIgUHVIyfONg01z2JG79e5sY5oOIA2Je9wHvJJXv32hzstbjV+/iglyBA= 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=MeqskkXT; arc=none smtp.client-ip=198.175.65.16 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=1709069103; x=1740605103; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xIprGuZ+wzLEKGSqnVchQykT8aBwBOBoQqpTJEhq/2g=; b=MeqskkXTRNlbjkpntg1p94Y+DoBTAyh1DWj/WzGj9LpJOApmIglEUEOh byP4AXDGVP3/JZaYrcRRfGHWzAl1cvFUyib/ittv+GSFHwxaRsBJA4fkJ beI4+/K8D0AUVvG0+SHiZTF11mG8K9GkLCgjI0AJbAvkoR6VVwSfNXXs7 g9XgtE0L3BBrE9clD1lLlh8wHG+lwja2KNHIRPXQtks8GXFOj89FNv1ID n5hB4CkL/jK7KIKthj+sSUm87/EpJeKzaHYUkAKzRHuSf8/KJHH+kzK9F bfhsprqIlmPu7USWbEZ65GrOVnF6sEhoO1G+ulGsE1AeLTlM0IgL3JARu A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3566906" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3566906" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032886" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032886" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:24:56 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id E4DB44C5; Tue, 27 Feb 2024 23:24:55 +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/17] x86/apic: Mark acpi_mp_wake_* variables as __ro_after_init Date: Tue, 27 Feb 2024 23:24:37 +0200 Message-ID: <20240227212452.3228893-3-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792100507489181690 X-GMAIL-MSGID: 1792100507489181690 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 Reviewed-by: Baoquan He Reviewed-by: Thomas Gleixner --- 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 21:24:38 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: 207549 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3050541dyb; Tue, 27 Feb 2024 16:30:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXPk5AhUNOPldEZudmDc6kHQcXScgNrezRJKeL72XN73g7uuP1hS2vRXoSp8kO+qC+7kC6c2LcfEt7I2PFxVW0a9dgRIA== X-Google-Smtp-Source: AGHT+IE6vGfYb5a/xqAPeGmoL/4iPn7JQhTgvY7Vx75SaztcIcWb4SBWKZFiLSmEome1kL5aYcDn X-Received: by 2002:a05:620a:472c:b0:787:a5ba:d58d with SMTP id bs44-20020a05620a472c00b00787a5bad58dmr4549898qkb.38.1709080230463; Tue, 27 Feb 2024 16:30:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709080230; cv=pass; d=google.com; s=arc-20160816; b=CR2If+sGYCedUVEXuaXfQaDbJNx4LZGvFeVzU5r/xSmHTQhTrz4rKpfW4th9h7JxCP VBCiMBcaOG8wWJhRMNSGGGAjjwCcWbS3F3pCCSt1Tw9ihhKpZTcotY9NlnBN38+k/uS6 hNIkxjNViociGJSgQsh21MHIkrdBcPYQ7ylWDkSe3J0ro/e23ODYAJWhhCkwiKI/xCIv 4uIsaLAi2Fv67Fq1wfS4AqGwRVv0z0ry6gd9Sw/5kix6Oat3zazyIUWXVJWsR1RS8RPd 4bp1WbFoTHEymKxoodp1b5N/cvegtNrCJCyRRFN2VcvSl0/tvX0GpzT81c7oWZY0f78v VJSg== 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=etMHlUsR1BlqAlrOQjvDNHmUlD8AOOr+8TmindilXy8=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=S8T5BtzlgkTxh0SNx1SuTSBTX/3mIi43tCLxe0nVDI8RK/f476AtlJFMY28Yh2RFSz bswejApUUOfmsrSNl7a/G6nK5+UzkkxfRVKj3cwS4n5JxkRA784Rb0HYk9D+IwnvlL7e q/v9Lx392RTg2ykN0O4Uj+jJ5eTH1CyKDgVp1iNZDGqytoUUtWeRIZp7l+Hlz2sqFZDn kfu3XkbhLtBy5+kcPADS6pxUwhq3FAhGvW3mAmvKOnR+TG6YaqNhEeGXSZOLyMLbff63 lA3FeqFMZR7bmRXiVDXtyvkfuW/BLnA4SNNaEOyrh8HSrnhqBTYiPViVvV0VTuwYi8Zc lX6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Hx2Fp6B3; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84036-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84036-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 s23-20020ae9f717000000b00787ba70821esi8823159qkg.694.2024.02.27.16.30.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 16:30:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84036-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=Hx2Fp6B3; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84036-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84036-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 66E1B1C24A83 for ; Tue, 27 Feb 2024 21:26:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 298B5156990; Tue, 27 Feb 2024 21:25:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Hx2Fp6B3" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 8706F14F995 for ; Tue, 27 Feb 2024 21:25:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069107; cv=none; b=EiP81H1VR1khtkZEYgfQ+rR8a/FRulyTPqXQRqzY9AFtDLSu1dJzv5N85ETiP0sH47M25ko/H6W50GdhAQVrPLC3A4jGktKA8q3LzshC9wuAV7WQyLr9Skzeb0pWcXYcjBVVKvgwbDxdcHE9b051MaCaKoogAbT1i6V7eNGBIGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069107; c=relaxed/simple; bh=G+mf0uc9JWYLESD7E7QcyEIUu6FPmOWbeObWlqzAyE8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KwotWAeUjHngAN72XIugARHMqc/MdQlyPdkkawoNFkD066SmNF2DZy4wC69U+nz2a40Wbw7q0zEWJWEtd/5AZLT2EaPeuK9rQjH1Y6BQwlH03cLbmnjZqPvNUAWHhCp/uGL5FiaYOwm8+ThZ1thOo9XBddb2HvpV3Shwnpqs2xI= 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=Hx2Fp6B3; arc=none smtp.client-ip=198.175.65.16 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=1709069107; x=1740605107; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=G+mf0uc9JWYLESD7E7QcyEIUu6FPmOWbeObWlqzAyE8=; b=Hx2Fp6B3SmLVL70IRNE2JJrQevobxQyEg1tP62AP39RVcgFPTaDsRdI3 2b4AYnIWzKCKKQWE0s945AN2c37yBcyjUl0g0w2WGuL4xnfYzD8Gj7Ak9 bqlHxtHBHjvgSV/5FUeph3MwfSNiR2WD0d47NAwVNw6BUDrfrtfF0DgeE XKj+kJvTRn8eBj5jMj81ixEodGY6BM75QayEsIFaFcear+eTv5xMOcEvy 08i1FXc0URakzCSLI3wmbuL4l79LJaO9h24XGHkQ1AJRHl6XdE3a0meLo wZWl0K8PGr67VI/P8T/RmdcwIHRkPHFsFmoXcOtNtmmlmOsxF1De9Pw04 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3566944" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3566944" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032894" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032894" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:24:57 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 00DFC524; Tue, 27 Feb 2024 23:24:55 +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/17] cpu/hotplug: Add support for declaring CPU offlining not supported Date: Tue, 27 Feb 2024 23:24:38 +0200 Message-ID: <20240227212452.3228893-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792100511837517953 X-GMAIL-MSGID: 1792100511837517953 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 7b36b3a4e336..ac6af196c6f5 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -483,6 +483,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); @@ -542,6 +544,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 @@ -1521,7 +1531,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 21:24:39 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: 207550 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3050562dyb; Tue, 27 Feb 2024 16:30:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWzAHbiBTTMLLnt2MAyn6TZLAoruTSUdeAMP/C79ZjnrLuIuV1/RF+qi93PVLMqKe+5lkojHjogWCcpf8BZ1AHSBrir0w== X-Google-Smtp-Source: AGHT+IEXYunwvuLdLHc52tBvu0DxoUMxdOGv093rqZbCVCMFabwX7OhAcE5/9aKaCz+KvU/EHgzk X-Received: by 2002:a17:90a:940c:b0:29a:9c12:785 with SMTP id r12-20020a17090a940c00b0029a9c120785mr7766243pjo.1.1709080232974; Tue, 27 Feb 2024 16:30:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709080232; cv=pass; d=google.com; s=arc-20160816; b=E1rgXG/ttY8Qxl107aRlKLNPlCPf9BAWnOtdG6TMs/xVagIC7piuu0aPztwAF8tuvm c0Z21QQfOnPjmqwv+MAg1drG7Fs9JdiUV2933ktpCh8YzT7uHdfeLCUcVZI7qJgPFs8W Gn6L9PRWArSYm+nHNgZXbx2NYkPWxUId8zdA8DH0dFMbmQ3bBbwOc9ggMBaiIHVV8wDR eQnA7RGTqy7r8OBNL7ymsoRBtu1NR4VhSYhUEg8dY0CB56BTUZHQYmBRVx6JueROxRwl 7bkoFNtnajHrVCEaL6w1Z5zHdPi/s1a9ElpswSGsSljB/HAUosGclMuOgaHO6TiXJI2u Behg== 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=oFPg1e4W+3x1wKJbkqedQVfBDACBojy0SZp4GcA/qI4=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=aXmT3cy8TD4+0pOMedQnMYGvVswOxe02+Z87E45BRm6zgDG8Vx8Vj9D5f4SzzB/2Um 8kyfJmSSMSeck0ubNHbv3b2+k04kbaPxxvQfILC0mcpWx7rAWW6znK/g+kDQpGf5cYDq NvAZwcwiQk4Z6G+o7l9/3jrwYkRBwBg4hQJq3TWTDpLnlYNZO++X8XHmDdLCaNK5KC33 140NvgoFnQWtbQyTkmL/Mom3F53aB8UUNmdvWC32mCFFFbYMLXJkQ9xdQwXhIvjJ4XSu D3CMyTvuUTtA+CztYxhYttqGuxRNEcjXs04c4GdJmuEiI3KZGaVspT7ei1jPDNNCcef0 XYVA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MEasphmp; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84035-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84035-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 sj6-20020a17090b2d8600b00299248f4a26si280667pjb.31.2024.02.27.16.30.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 16:30:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84035-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=MEasphmp; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84035-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84035-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 075A4290C51 for ; Tue, 27 Feb 2024 21:26:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A29C7156961; Tue, 27 Feb 2024 21:25:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MEasphmp" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 59F6414F991 for ; Tue, 27 Feb 2024 21:25:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069107; cv=none; b=FL+i8loLVlCLmSOWJhbXHwWt1z5lOtoEUgikpm6EL2uQ0yVzM35faFD4MDM0Z7Zdo+w1UtMo9yYjUqlMzN7xdHPHmUQYiRRp7+HDjklPfWznewRoFROQVaqlkp7s7T6siNUhH5N59HdSgxQXLZuH57WJKTpqG8pBwyNHUdr8wa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069107; c=relaxed/simple; bh=YLm/cL+dHPnuzS6G3vl9X6RCyiyNqBmXpbxGqPOhV1s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V7Rf9WaDBj4VUmO226/1Zu1P3gsnIIoovjc1LEhDFz4sKS8fWM/iHB6zrcamuKgZB35OsP3Y8d6fBlRwzQMXYVIaEKGem/slL864QwsmQxYTZXjGVA+RTlq6BFb++HVc8ktYJcFckI1Lnf23FYSTzMZsHUKgCIBRGrmRib/5kdQ= 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=MEasphmp; arc=none smtp.client-ip=198.175.65.16 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=1709069107; x=1740605107; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YLm/cL+dHPnuzS6G3vl9X6RCyiyNqBmXpbxGqPOhV1s=; b=MEasphmpA6dV5qLkyxYnitimEcN3wqJ3Lsz7U6G2REvX1j+/Ht8XpcsM j3imYxV0v7jOq0rJ/5a+rmSrptWkvwk4y4Zrkikiwqjtr2/jqBPC6oqNB j+nDiBbxGnjFhyK5r8N/y26guTIWQaelpnjEHeZMSmKlwHH2PQEezXY1Y odRhIxil7nL9MEOXB2l7BsCLjYWEOJUScIcE5IyZDpnWFGcKQQ0wkDDDP ziGRqJWCaB2WEpR3EG4+hLR0tTPsqEHBEYvi7/V6PJgsP7h1brOY2sfRI w+UussrHbfztuKH73Q1VbVN+M8BfN4h0nihgN/ziaDeO31rmfeSJ86BiC A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3566941" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3566941" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032892" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032892" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:24:57 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 0D322537; Tue, 27 Feb 2024 23:24:56 +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/17] cpu/hotplug, x86/acpi: Disable CPU offlining for ACPI MADT wakeup Date: Tue, 27 Feb 2024 23:24:39 +0200 Message-ID: <20240227212452.3228893-5-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792100514246301265 X-GMAIL-MSGID: 1792100514246301265 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 d07be9d05cd0..19614302e0c4 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 ac6af196c6f5..dde8e8472897 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1531,8 +1531,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 21:24:40 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: 207553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3051143dyb; Tue, 27 Feb 2024 16:31:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV/0zT9hINmjI5EcIjcKJ73ycpXQi+v1kCxswCNEXn5sjfBM/N64qNqPwoRHDne2OwK8fTJcGJymvOlUglBjkAAjIUtZQ== X-Google-Smtp-Source: AGHT+IGnJnBQMl5m2GIHp7NT0+XTdUvEy9qf6pkDKC2PYUDWyN8IP6p9oOYipPnkk+YP36/wAzV2 X-Received: by 2002:a05:651c:1a0b:b0:2d2:9460:142d with SMTP id by11-20020a05651c1a0b00b002d29460142dmr3194818ljb.14.1709080309128; Tue, 27 Feb 2024 16:31:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709080309; cv=pass; d=google.com; s=arc-20160816; b=i3WCw2QZsWLkF5Aj7IhZS6nFpfSl5Wq0tb0m43o/SnpKIC5nQqzGcYGKyPaGrVyX/4 GSz0jwPAJrDrR5pbAbsF2FkJeqj/PIWSu7niKVpVd01JC72r49AAancn+UFcPYD6Ex8G NcXHuzlQWGVpj6BACtr92BNparbPFbZjBNweimTh5kqG1jqV/wGO07byY2qTIcraZS9u kWkB/784FhoPqk0LbQ54ZYl7HAZi18Tg1kE02AK6jSTq06Q08z+DWi5FYMe9c60LAAqH Alj8vEGLUgi+TGJOwc/mAxCFX37164hv57ag9q7Ax1JCeCly3670oDMvP7KJmdMV/EAO sTbg== 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=+2yLDzWdEmtXDBblHO+SFqFiqLHLcrHt29f82nLCxQ4=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=RVeytW5eeNLmWnuQIaKQXzr41Nmm8k4wJmIgCM0jgZJsbRjhzGao6V8Aeadmy9Zge7 ETCzJVWy0C9NXV+uibG2y9V2bCNMttygPJAguAbzN6ngXl4C3xl+Ol9QzPVdupY/ObaB 60vP+h/2mlNcGxoR4aVqGmBo1pW7L8fYs7TKmzNM4imrxHQ/sq6CaW0TjHxwv16l3gQX J9pW3bZaj96KcIAhS0N2eFJy5c/8CpLJ5k8fHSqrLmRLlSsSatQi6DQwrMubaom9irkb gdqvTN7Br54iMppw6mrO5OQpUjBiI/AhAsmIaENS33HKFEaYZDvZIjtzUrWGayufGqjT 7gJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AObOYmFc; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84037-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84037-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 s3-20020a056402520300b005664532906fsi817181edd.271.2024.02.27.16.31.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 16:31:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84037-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=AObOYmFc; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84037-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84037-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 B09C71F2C956 for ; Tue, 27 Feb 2024 21:26:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D36B41586F5; Tue, 27 Feb 2024 21:25:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AObOYmFc" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 AA4CC154448 for ; Tue, 27 Feb 2024 21:25:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069111; cv=none; b=QpszwVNiZquGMOIXcaJGmyFqXF7PTctFqgNIRI+gEecdG1ss+damF27x9WfCukMRlxc8X06iH3QIONfniLCH2RtTyvOsRjTtHaPlZ08RER47j7QRRASr0TGZa+4krQ+aupCYjfIacBgEkf6XWrHxa/DowIZPNj09sK5AugZSRQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069111; c=relaxed/simple; bh=7jFuowaz0Vw+N4idIIhc+R9JJKXqB88Qml6sO/pIcmM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b9KAZAUxxmsUjBik2CkDO/2Anw8aPs81OQaO8rja2LKH/T2ZVj52rHWq8JGZ2ftj0h5GPyFHEW8eFCW6L1gaBgK1bX5rqltuBOmkU1/aM3+U413kkTv6r+PBh4WagcxZkjDqXq+RcwYcgrWCn796jLH7tft9xk63hIq2YVyp/ac= 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=AObOYmFc; arc=none smtp.client-ip=198.175.65.16 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=1709069110; x=1740605110; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7jFuowaz0Vw+N4idIIhc+R9JJKXqB88Qml6sO/pIcmM=; b=AObOYmFcs9hV2WrODGvUKGY6Fc02Vb+Dis7jv415V/3Mnw/bd6zckV1X Y3rEkUzWZ1Tqp+6WCOsAq14U5POLZMKeT4nOZ45Gw3N1nNvJIPJ5BHozL ++Ai9s91ZPPAIN5gGPoo5q8w6sUDN2ZahhAp7Q0mQjxAZH4n1MxZ/rLpE EIntPuUZTfifaEYzj4I1Dy9JDvn06jg9Ztz648CdYncRa6NidEwPcl0rp SOYt7VO8/10zoE2ivsCeSbqxKaZBP9CMGaPRoGPZfE+kfPQGKgRBTyUeC Or0OLAGETakqzKa3p8Nu6wOwZu1JcTtZT1MSIgkrksKOAeD1hO/5xkfhs w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3566990" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3566990" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032906" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032906" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:25:02 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 1E0E85F5; Tue, 27 Feb 2024 23:24:56 +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/17] x86/kexec: Keep CR4.MCE set during kexec for TDX guest Date: Tue, 27 Feb 2024 23:24:40 +0200 Message-ID: <20240227212452.3228893-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792100594315670245 X-GMAIL-MSGID: 1792100594315670245 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 Reviewed-by: Thomas Gleixner --- 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 21:24:41 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: 207485 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3005912dyb; Tue, 27 Feb 2024 14:45:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVngOZ5wnqfmbOIqDMWjDrX8R42Vo+nKQxOU1ZkoTdytXH5YSG3ttKHQBpRzY0j3ZYLVI6WB9tOE72zFQVNxO1QV8HtHg== X-Google-Smtp-Source: AGHT+IFvG3hbd2kS+/ZK7TnE++27XHM/fAohWLhEgf8F7svvmM8Mq9cC7IVeJT6Iz+7RlT/hX5s5 X-Received: by 2002:a05:622a:389:b0:42e:8beb:325 with SMTP id j9-20020a05622a038900b0042e8beb0325mr6198716qtx.31.1709073929242; Tue, 27 Feb 2024 14:45:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709073929; cv=pass; d=google.com; s=arc-20160816; b=LijBz7TCvx72rmj9MoCtxml5E/cXaX5Pt5lQiqudx7SUIR22ke8Gl1xyyoZ/0jjMLU Fmxs+Y880pVIgpWzMwHJd3JwGKjSlowkd9qXbVvhNIeLA1e4kA967QaLnvrjOIN+X9RW wZN3pl6YVqSykUR/mWLOer+Yg6IubYNaE03BGu6LutAdOXQ6kQrCCnlydAN9mfAkUimL NGggBuAnoMWTpO6JeE+u6SebqZBW9yzCxa73zQP6l+5wMlm8YdVNZhxNIg4yFJJKNzBw 4h0kPVtTnSdRQvdStYQ+XkExg2h38Pl2RKEHxnSqk9GCyTQBoQdJTY+13v7yzjizZj7b MT4w== 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=a3uAj9kw+ciVKnGrrZygHeOzqtvJwcIPC4jtYbJnW6E=; fh=yQt9ROgMHUZejH3hDVFamAWFXphHuLLRaOt+BxF1Gfg=; b=NxFLSHtogzRY/FCbLn7Dtq5jSVDlE76CqeVuYT/r/EToeYDMgR7rWnPewLvORJbxfs JXdThQnSpKlF54ZCbKf5ja8Kv7N5hDFKCbcdg/+po7Q/S1x5OajvsXDxn1bTDAA34NCX QsMlXzXVADVKMFjHQsFQxq6yRgZ29DH34a3xQQYuSv4OSsfTbnCYjpBYqOJJhf+F3F+3 66SGyQB6pGoVg+7BrZtbO2Xk/UPOzhXFHcecv7dtgX+Q1v/9HqAvj9wr4Vhizi1v2tZk qwEk48s2dUqW3p2NlS6t79aOoU2h3f2PVUpuREpbJhizrtsn9kvS372d+VuvyWO9M1PO eJNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lZejuTK7; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84045-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84045-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 ir7-20020a05622a6dc700b0042db20aba5bsi8203684qtb.750.2024.02.27.14.45.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:45:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84045-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=lZejuTK7; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84045-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84045-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 272CE1C28A62 for ; Tue, 27 Feb 2024 21:29:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 22CA914F9F8; Tue, 27 Feb 2024 21:25:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lZejuTK7" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 E8DFD15957C for ; Tue, 27 Feb 2024 21:25:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069119; cv=none; b=l9n2IuWFuLkiDwpFmFBHm3jgQL8Knd6+V9WN05n3WOs3ctIJ+JtQdXKmyuqECaf606jaJZ0IOImO/2dRIoOTMfh36hywicM63R2eNlApBNWJFYT6BTj7St6cM8B7/ppCOx/wYKrCq90ma3I0MWDIgndlnPSIJCVj5Mo70HL+NUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069119; c=relaxed/simple; bh=Qtq8KGe7CLg0f1T+K6clfMVgP4YdYp22V2UayvUSbDw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OgC5GaOokClwBjGHYULu52MTBI50E1ypgawrCL0V//tzebosVOxCt5IzIdIyGspSF8/TRCZtCX/Zrqr0ukHXZ8ZcFlnjKG7qmhKQchP1SOwLPsAsf7ebaOwmauAuAY7TgzIaXq2P+0ILk7+fk6wKd5MQZmLBQiabiP/av2Qfgvw= 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=lZejuTK7; arc=none smtp.client-ip=198.175.65.16 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=1709069118; x=1740605118; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Qtq8KGe7CLg0f1T+K6clfMVgP4YdYp22V2UayvUSbDw=; b=lZejuTK7FpwKHfi/2dKNx5X2KtkMGoUbrrpfM7Ba3EMAzU9fAifrbrVl LJEwYUnxqAhw5Mti9frH4Y/G8iUt3jao0iv9CegAUDPBKRYbcX6GqCEvD ghEIrmIt/xb3bM7279QoJHpi8c3LM7h3XqeOWxWfshNZbukgbmqFO/BX9 bxtlGsHBWCoUfvOBJtMtIZ6LFVbKTt8I8AF77duizdVYkbxOdsji6C0Yu 43cmNWAxUKLl+D5UQQ3ntAmDyydtl5H3ARyG8SMBjETCWdXxMMkECIbBX xfYldRlfi0bMW2Wocj6HXwLawKIIe0g3swaSWivDmASGyqtaIuxEbmjST A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3567073" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3567073" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032920" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032920" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:25:02 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 2AD0B631; Tue, 27 Feb 2024 23:24:56 +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" , Dave Hansen Subject: [PATCHv8 06/17] x86/mm: Make x86_platform.guest.enc_status_change_*() return errno Date: Tue, 27 Feb 2024 23:24:41 +0200 Message-ID: <20240227212452.3228893-7-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792093904670594941 X-GMAIL-MSGID: 1792093904670594941 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 Reviewed-by: Dave Hansen Acked-by: Kai Huang --- 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 f062715578a0..17104ebab359 100644 --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -148,8 +148,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 21:24:42 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: 207535 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3035573dyb; Tue, 27 Feb 2024 15:56:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVsSx7IxsT6ML1I+zVx/LNtLhI6rClD2fuoDgEOULklqCYr7OSYkU42sUk/9vnhKoUG27n4wYaRHA1UJlSSPRr9pqt32Q== X-Google-Smtp-Source: AGHT+IGuTfSYohp0OEDFWLHEYKHUbl3lNk2+cKnsvIGD8szdbU4Yjbnd6X3XuThnoYjclqz327tz X-Received: by 2002:a05:651c:104d:b0:2d2:99ee:e439 with SMTP id x13-20020a05651c104d00b002d299eee439mr2222017ljm.0.1709078200553; Tue, 27 Feb 2024 15:56:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709078200; cv=pass; d=google.com; s=arc-20160816; b=G2Ib2JjbCE4MyIrmGnaPSGLFl74PvekyM3sGRG76Tm0kHMDVOcerDZRxfMrZBmkvOT sFAJe5iOs+0/kTysJiu0xq3CzuGer32KkoYYp2tgSf7ng1D9OOOhCEvu0px2YeMA4qXm hM1o6ZdJoYKlMU9S43uYfl45mfVCbK1+U1t2Pjtn1CGwwoEzB4qpYoc6X7io2V5rmj6F NJySEv96nVkFlhheeONRn0dXGqXGqmh58UFdqWI47bCpBq511VjjLFH7KmaWSOxZMGks uBqOR+fxC4iR96QWCoFAdDbzAMZtf0//lCtO+6Vcf7HS0q0nrdC2MGdww8ON8UKmrwU/ S/IA== 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=0mAjGPI49n62/EKJrSnKcsTSDrzE9V31hmWpeYbvVb8=; fh=yQt9ROgMHUZejH3hDVFamAWFXphHuLLRaOt+BxF1Gfg=; b=JLAxMRRjaX40BkYY+v5/0dUxmK/D7xqaiz2nzrQbMGIT/I8TuOnm3iT98eYTGuuw+J kskXm54YM0qyYvN8qKY5MfdCWJBrohV5D+2lzGPByZ0mNvZYGn/9YKnd4eor7uoXEGR1 wAcczjFqmJtDms8dzNSos3/Cf0xJDQKRRL6s1lCe4toBVjdgVuSkG+7RB/BdiquZtMNY 7zYj9qGE4NcN/mG2bHudcEv3JFuVFF7RoB7PO/RzUd8gjKCR1p6+/gHgTsO6BBFUIg4/ GJpc1EYakb0R+5xwf+nOfekgy5dx6lUYJYZPGNuiaiqKGbUQ55Uc2j4i7fHRooru5aBM +zvQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LkAEIAH2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84046-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84046-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 a3-20020a50e703000000b005665b5ddb50si340826edn.108.2024.02.27.15.56.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 15:56:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84046-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=LkAEIAH2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84046-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84046-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 B9F021F2DFB4 for ; Tue, 27 Feb 2024 21:29:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7AD4E15B96A; Tue, 27 Feb 2024 21:25:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="LkAEIAH2" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 2D0E315959E for ; Tue, 27 Feb 2024 21:25:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069120; cv=none; b=DwGBDKUBhAx2hi8tvZQu3FJc1tuAMrBsQo5QBld1GugOLqXet9GoE45d/JV6+w7UnJAEeKOQ44/nZJvbGJVBcPjrBFhTOgxYbUVlZpnIbw7qrHtNJrYGx+XRos+lQhaJDhSqIfq3MT8/vXlqsJd6Zm3/tVHMSCu2yNqUjBxMREg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069120; c=relaxed/simple; bh=dUEuhxA1AlDC3wetWnBXvKm2CT6y7iSHZ1ZynKz3iIA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sMDJ2weRjoSuBodoRAmepH54NeZQojh3fN3r24lgr9P9Q+Wmu0cJ8MB/uQ0oenwSSFR8A9zzMQX7bxREbqU5RP2hlk5hj7q9v7GuIIcH0zaEulEJA36ZvFceTwedius7Evzljq/URS1iU2ucoS80b+0a6W0xuL7eGDWFjeNim6I= 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=LkAEIAH2; arc=none smtp.client-ip=198.175.65.16 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=1709069120; x=1740605120; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dUEuhxA1AlDC3wetWnBXvKm2CT6y7iSHZ1ZynKz3iIA=; b=LkAEIAH2t740lJlbSKfA5DWxq33xe4JeMi7DpIfc8aX7FMiYX4PcraIf qxHtfdp3+dqx4QBhhYY1mxiqOdilZufuSBXvS3Cf0lkkVDy4eojSnVYpB sHi0BzGkIKf32t3p9n9u/hean/FPFzqzGRW22JxdMJZckpIMEPLr8/r7i h2ARjwh6iax8Fq/hctXrgll5PVFS46mmnyxBn3/lOlheJxq+XE/cwa8E+ RqH8GO+/DLPkp8HQfAIwGQjuGo0hVzUyzE5TUPX3ebrqrTd6LW/jAcxjD Ao3VK96CqF2F3d2s3P4S7usKAk0FF1KEVdELnDLZ7CdHwCqUDghnzCj7H g==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3567076" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3567076" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032924" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032924" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:25:02 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 3CC85781; Tue, 27 Feb 2024 23:24:56 +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" , Dave Hansen Subject: [PATCHv8 07/17] x86/mm: Return correct level from lookup_address() if pte is none Date: Tue, 27 Feb 2024 23:24:42 +0200 Message-ID: <20240227212452.3228893-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792098383046787062 X-GMAIL-MSGID: 1792098383046787062 Currently, lookup_address() returns two things: 1. A "pte_t" (which might be a p[g4um]d_t) 2. The 'level' of the page tables where the "pte_t" was found (returned via a pointer) If no pte_t is found, 'level' is essentially garbage. Always fill out the level. For NULL "pte_t"s, fill in the level where the p*d_none() entry was found mirroring the "found" behavior. Always filling out the level allows using lookup_address() to precisely skip over holes when walking kernel page tables. Add one more entry into enum pg_level to indicate the size of the VA covered by one PGD entry in 5-level paging mode. Update comments for lookup_address() and lookup_address_in_pgd() to reflect changes in the interface. Signed-off-by: Kirill A. Shutemov Reviewed-by: Rick Edgecombe Reviewed-by: Baoquan He Reviewed-by: Dave Hansen --- arch/x86/include/asm/pgtable_types.h | 1 + arch/x86/mm/pat/set_memory.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 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..0d2267ad4e0e 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -657,7 +657,8 @@ static inline pgprot_t verify_rwx(pgprot_t old, pgprot_t new, unsigned long star /* * Lookup the page table entry for a virtual address in a specific pgd. - * Return a pointer to the entry and the level of the mapping. + * Return a pointer to the entry (or NULL if the entry does not exist) and + * the level of the entry. */ pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address, unsigned int *level) @@ -666,32 +667,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; @@ -704,9 +705,8 @@ pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address, * Lookup the page table entry for a virtual address. Return a pointer * to the entry and the level of the mapping. * - * Note: We return pud and pmd either when the entry is marked large - * or when the present bit is not set. Otherwise we would return a - * pointer to a nonexisting mapping. + * Note: the function returns p4d, pud or pmd either when the entry is marked + * large or when the present bit is not set. Otherwise it returns NULL. */ pte_t *lookup_address(unsigned long address, unsigned int *level) { From patchwork Tue Feb 27 21:24:43 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: 207544 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3045154dyb; Tue, 27 Feb 2024 16:16:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVavNCIVC5dFQkyo5NesDpXr0Z5JDojQG+AYkKdf8kskn6SxI6OU7NqCUz2a98oR5nAZkACvkcD26hhS/OqSoXTJaIFxg== X-Google-Smtp-Source: AGHT+IEGs3cYPLaoiIkbNPHEOZ8Y6lcESdZMBfSi1Ge3Lf3JxjTf0pRDE8Kw1WRRQLxkiR26s1RR X-Received: by 2002:ac2:5b1a:0:b0:512:eee2:d8d0 with SMTP id v26-20020ac25b1a000000b00512eee2d8d0mr6947144lfn.59.1709079402420; Tue, 27 Feb 2024 16:16:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709079402; cv=pass; d=google.com; s=arc-20160816; b=p0r9eoBjPM5VGv4jX0ki8Lcydx0LKoVZD6vZM5E5IzGeRWqTEVvl6QkjTkCDFYhN4Z HBsVfMhXhaOTH6SqaRz6JoiZT0IwpMDWPFDDqMiebmdd+wN4wJz1CdLfgN2nNtGl49/5 W+09maDlJ1ab+V5xi6paldzLV2lhrfW3RqSsDsGjaDhhF7TetJCQk3wXKCS1WtBv4pIv zYnzG3cOSPinyR7UQCdgtAWEl+X/+ZTWrAsz9wLpOOWGRk67dl5L5OuTtETVjd3PfWrp gDNnJKdfD1TBZYdmLKHRfCzWtoJzps2eNxXvFSb0dOR/wT5f5843qjFO9fPVEA8jVZ0o x5EA== 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=lMlTrFTrr7klW2adN5JqkbNkQ8V2FIXm7+yroDer/Yc=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=xBgnXYVgmV0ivP5c6lsZgtQc99IAXtg9SwE3qHm7S8Ur5JQDPpUKGMkdiTbEsrQu6W xix3SYVwi87Cr9wRuAupKJ6axrZjgWksCgrpImNOj7mF1J/uJFSkB4AlNzxmkBH3nsWY LrOq6ASa/AfbKQvqPH7k1iWDdfMaNZf0tWCNAuustcvIDpuiKYf9nasZiES8OeaPTI/y FlqirxhRzJ43hwTGAh1Mh8FOzUYr07KU/RMYPAwMe/yiiX6ZGyjTLMOPh3OwX+ll5QrY i9/xumLJk2XcGjwk6bJeXaF8dD/zNadhUmhccSHdYP4s+pJTUToo+BAO4bKzWAfDLJg7 l2Zg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=B261yzQ5; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84038-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84038-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 bn7-20020a170906c0c700b00a3e730bc98bsi1178312ejb.395.2024.02.27.16.16.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 16:16:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84038-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=B261yzQ5; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84038-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84038-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 F106A1F2CB29 for ; Tue, 27 Feb 2024 21:26:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B8A1E158D74; Tue, 27 Feb 2024 21:25:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="B261yzQ5" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 9B50B155A4D for ; Tue, 27 Feb 2024 21:25:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069112; cv=none; b=BdZLPtrObkg94wyWO3691haR8b4Q2bKCYnMbRerkqCmcMbSqfvieMqJ4APtJkAc+LLm+t+725OdZfCTSAm9Bt6chrpKw3liPJF4pdCoLAXRQE9BwfK1C6pdUntyaUNjSXD6wN6ksw1/wNKt/sfhgvkFwH+gQgv2Yc42Z3Bi3XaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069112; c=relaxed/simple; bh=W80pqKoVc1vqxX/XGuHFDF0b+nJhSWWU10+X3joqYlo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RjaSMki9uQJeMQeeq92o3wnhZrWY9m29tAsDV2NNcybJmALF8XC/3QSHM+Gb2I5xGuELXVJBoPFMn0kT6WgdI5dF5TTHJvwOIywFrVTH5QTqRqwBItHkOVPf9LoH4fjU8u9KvDZY5ZNNir3/WN6NVRT6lHxcRXaJINamtZV+6uo= 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=B261yzQ5; arc=none smtp.client-ip=198.175.65.16 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=1709069111; x=1740605111; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W80pqKoVc1vqxX/XGuHFDF0b+nJhSWWU10+X3joqYlo=; b=B261yzQ5U92MZnUe7LjCcfeDrkpZNJ1l29hSOsPgXAczD1BJBv+yKjGY amLVrVb0iK2C5I21yDoDvCalA/PuO07CB1V/vxcWsjZwl9STayGgKAnDG Y0lHjFd00kNgq0ISUWyxhJ8NU2BMPActVRrr72FHOPCpKoHnHFTQtkvl1 02ACYUHu6Tij3/kIp68PCOZqkZ1WfE62z0yp4kFvi2C7YV95hGefDU3b4 TkXQIghfTaHeA+8eLP065tCZV6CyK9F+3U77Byh6qX6zN/SOgSJJxiqMZ vx1TXSSRz1RN839LgBi90mHxJ/CWK95sEGT2RE8P0JHHuIiKp/+kXpMV+ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3567009" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3567009" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032910" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032910" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:25:02 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 48969812; Tue, 27 Feb 2024 23:24:56 +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/17] x86/tdx: Account shared memory Date: Tue, 27 Feb 2024 23:24:43 +0200 Message-ID: <20240227212452.3228893-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792097805462222752 X-GMAIL-MSGID: 1792099643233024787 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. Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 26fa47db5782..979891e97d83 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -38,6 +38,8 @@ #define TDREPORT_SUBTYPE_0 0 +static atomic_long_t nr_shared; + /* Called from __tdx_hypercall() for unrecoverable failure */ noinstr void __noreturn __tdx_hypercall_failed(void) { @@ -821,6 +823,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; } From patchwork Tue Feb 27 21:24:44 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: 207528 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3029655dyb; Tue, 27 Feb 2024 15:40:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWWZvjr200mCUa0EktwfqtVbGmPr9jIPVbplsjVLn40lue1dYttbsqbtTK+QIeEAG8Hc9jtIbzc5v8NukFVWgqf2SQbLg== X-Google-Smtp-Source: AGHT+IF0XqyamAkOKHA8fnjgxfNuYA09rg2ASGqcWqRD54dcOUc78qDPUtCZUW4lSYSJzpOpSkPu X-Received: by 2002:a05:6a00:1d8f:b0:6e4:f307:f554 with SMTP id z15-20020a056a001d8f00b006e4f307f554mr12157559pfw.0.1709077246937; Tue, 27 Feb 2024 15:40:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709077246; cv=pass; d=google.com; s=arc-20160816; b=j/DuUUztL7J+HK4K9B0O7Od8EtEgFsEyw5dI+a89iN0iSs8QEirlShFNnLV31Zj9NO fuCB10WhJ5maHZ+Nmt6m4hg8JjfCkfoeizb9d/fd6A/u91EZ+Mi9efRrtuMlYrnpUt91 YJAAANP2MGMxMFn8WAfPzHAbaoRHLYDNmD1TDKqasgCu6S8n1tMRrMDzXTAc5O7amY16 gEFEEaP1vkEyujrjo2H+v4nymLDxqmny93sp64JDPnVJwm4EI5OmGbxBHKXAlQ6ZSxUm BUJZHIX/yJ53EEn2zwJdFAf5Z0ElmcePUNtplLgAbb22v1En67jcEP0WTMdoUzaBtvcl Zabw== 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=UghgN0BOZRgETP78Zjj3/BXgZdFqA5hsE1PeN3wNWvI=; fh=/Ak5C2ws7sfmtivYsSuDzWsPTaU4mDhR0lpxQ6qr3D0=; b=uXGrEYOocPuH3RA1s/O2If/3ZAh2RP1x2jylh2UdBdUYrGPhufpUtugJ+kgk3t5cMB IGGzrESWWDY5T8MK4Z0spl/X5MjKZugzE32p199uJdk02ljyXiCxcRXruKrRiflfP13r TdEujRbcqL8WQrNRtWO6ZG2UnKKdXLaAxKHQcgEFtvVCz2i729zfvu7cNMP8y1AWoJHQ 0U+zthd1rhWfC6T+cKdPKUIOs/VwWqO6n+HYEVF5jHO42brX1sYW0gNImAHuHKjVKu6q KFz49xsa+jaJ3Q0A++UynFasrpzNedgIdV+szaRIJxgmo1q2rjZHduMO/iErGMMZzA5B K4cQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kufmpG25; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84039-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84039-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id v184-20020a6389c1000000b005dc8b2148ccsi6150955pgd.836.2024.02.27.15.40.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 15:40:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84039-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kufmpG25; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84039-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84039-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A8EBCB2611A for ; Tue, 27 Feb 2024 21:27:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7FF8158D95; Tue, 27 Feb 2024 21:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="kufmpG25" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 160F214F995 for ; Tue, 27 Feb 2024 21:25:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069113; cv=none; b=rB3EtkcW0DqCWwaxg3FjGm+IllhWCkTBpsGay/dsjntmIrXNQUrLvXAU0YvEOVKlCm3sCJ6v8Q7+0AiuoHmzIlJizK7YuFXzsZGXhOl3R5N0zz1WI+8M7rVu3Vjf4/0J+umQYQLQpmzF9Jj3VoryW0GchISvlFkwNsYKNmJNDV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069113; c=relaxed/simple; bh=zY37V7XVErjfFCm2UB1xv4FpFUFrbRduDqjfiU5sWzE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BhMfu+EQYmTKPK6Wa3z2firQeMDeXihqhW2fESbmat0i8Bb91jNY5SNj4Y3NhlCgfUw5ToogLwuiB99HNWbaZC7QhYbrTJFFvABGucWk+A8tlHenNxvQD7z76gpKxCHP6h1vHW8oOXSwQpBN0iEHGdlaslJacrH7gv33TABuT0M= 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=kufmpG25; arc=none smtp.client-ip=198.175.65.16 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=1709069112; x=1740605112; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zY37V7XVErjfFCm2UB1xv4FpFUFrbRduDqjfiU5sWzE=; b=kufmpG25CNxIGiYHepu/r/eRVqmVApzDcp8w5Zc4yMMf9EcD0yMJw1ww iOXGSW27LhSvFQBVRnFGCwZbXx9i4xsWS0mx89B60DFW5H3vUtYOxeyoJ wlKdEvgLThBC/UnOVDJHCE5h8WornOxeJX/TanUXDIh8SUFusPegVJskg P8r4e7wakeEldFm8r+memWtbFOWOTO2Y9OrLczx7JB4PyvrsoSxeUx97t eUVbYcbZDACSw6PE6947f0VC8nOE8g3264+fXVDLJxMhDs+gk71YETP9X HSdFL5XPaZ9ca3VLl0mdnPFbNBSsyiW3DFR27CT6DIFm2jXdHW5mE0X6a A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3567041" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3567041" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032908" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032908" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:25:02 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 5921C9AD; Tue, 27 Feb 2024 23:24:56 +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/17] x86/mm: Adding callbacks to prepare encrypted memory for kexec Date: Tue, 27 Feb 2024 23:24:44 +0200 Message-ID: <20240227212452.3228893-10-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792097383241151683 X-GMAIL-MSGID: 1792097383241151683 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 Reviewed-by: Kai Huang --- 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 17104ebab359..b4e4c2d7f967 100644 --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -152,6 +152,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 e74d0c4286c1..7a1560d7e62d 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -128,6 +128,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 21:24:45 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: 207534 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3035549dyb; Tue, 27 Feb 2024 15:56:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWeggMnRg0Uz+NLHVSs52fl6FXpvyyXhAaEyzrCTijXFkAG78RE8LG0p/0wC+TM4XT3NittxJTTJ745v+tuP62A4M0twA== X-Google-Smtp-Source: AGHT+IGXQ/RX/s6xHn++WMTNcodXbwq49kruxG90yBivd/I5bkfvpGrv9sfdHbxOfXxDK4SF8BuZ X-Received: by 2002:a17:906:d0d7:b0:a3f:c3f0:69bf with SMTP id bq23-20020a170906d0d700b00a3fc3f069bfmr787479ejb.13.1709078197529; Tue, 27 Feb 2024 15:56:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709078197; cv=pass; d=google.com; s=arc-20160816; b=r3gjscJcfcuh9tU0i8ShI8p1iti2ydsXDGTHpOj2XXIxRynqzjH+VgO6MRS8RPIVt7 YYZRNBZg8lQXq8Fg1dXiyuJIm71Vwe5yZ33Zk54ZAE+8iRGUiZOr82FCF0JNYBlTd5Qr ZZw2arxL/yz8GtkWzXPviHEXBilaJXk8+hHIvSI1WPxaji/QcvkAjHbiBU6GRzBtuoA2 Kq2RrSnjxknj8NXMUhsi0DrlaxukSVbAcP4bDnY58Z4dOJCMF8yiL5fG1pAygpRAUk+K I2Jkc0ce/xI0TRClPxGLQEZOXCj3lTR2gKFzPgyYk8hEQig48/XRdOU9JdUKw0tuKuTk KdjQ== 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=1/LIepJ8YYgKUU9WHWoDA1pw2OQ6YA2Xd6cXKdtLQjA=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=zCk56R2eBfH7SkU2zKfYERyHkeV38PicnWeXhEdLqDI5tSosHQ38bdfTlzd90cuVdP TZzTYzP0PAki3jUNpstLBToP75iYSK+zqfepGYcRUx3I5AuKNppzkl1TlYTLfyJG3mq2 F6yPqYKJCfCxZ1llaRPVrDWaStW5ivEC3KGYd9gveJfuEA9IKg0x04M8Gq3+3XyMGVXr ViC7p91Q93z5X/MAEYrq4+qkP45fP4U8O7HwOlVcui3RKGvGMHmkZIt1lBH0EJq/raIC WQ6wnAv9KMmBYnd9V2b5UO+XZ5vb65MBkho0XD8nHElRnkC8IOpyGTf5rfkswKW+qHgj +Rcg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="nX/Mm1GC"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84041-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84041-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 e14-20020a170906044e00b00a42ed61a969si1156626eja.957.2024.02.27.15.56.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 15:56:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84041-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="nX/Mm1GC"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84041-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84041-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 895671F2D47D for ; Tue, 27 Feb 2024 21:28:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8953815AABD; Tue, 27 Feb 2024 21:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="nX/Mm1GC" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 F0C3E158D6A for ; Tue, 27 Feb 2024 21:25:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069117; cv=none; b=J3DDG5k1W9hU/oCjX2kb+8WYa/Lf3E5TVPpWulzTp3j5OPEne5bp9/XCncy2BigQ24OVD4LK76rtarf4NhH0xK/5mQqICSMPkN+inz06EsMldrz4zme1NIINiyjvdVFpH2Zvll8hiz+CTin16+ZcdvHSYNJqleu+xL9evBAurE8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069117; c=relaxed/simple; bh=V4Wv9ihxrfAerMNIMD+R4MX+Bks/1ZXzWa1IUxhgkSg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=apLA5Law478syBEWkHS66wn44q5P8W9wAY5u5toDl3LU+q+mzdksnouzoQHcMxDSDx1ks1S9+Im1cK8JHGZMaQrQ5P/hVAD1atxGFmhhP3Nru0+D8nDl9aN6or7ZvSSCvk1PwcCSKqcUyycEGNIEcjMa1SXxDnW71qHOxrCRxD8= 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=nX/Mm1GC; arc=none smtp.client-ip=198.175.65.16 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=1709069115; x=1740605115; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V4Wv9ihxrfAerMNIMD+R4MX+Bks/1ZXzWa1IUxhgkSg=; b=nX/Mm1GC0lhYFwdiHMDK7DAMbmONHNWCA06JZMwZhqRdDUYQ1GAxblWr e1GQI3vCNFH2qSdg+sxxFBAWZBuGxMDEuOddF2GCx05YD6l6Kx1RMEy5Q ZipHLn3US4zcYkYE1TO8xHT0wL28YNbiweggRgnjob/KElYxB0E+MYo5v f+533V17fKBWdw962aeD61qxCGvwuBJ/qSnf0OV6Np8PhSzxGtG/2Si83 rr6oJ5KdqTucCXadpbdwvJYi0aGEufOZKuFp9YqEE/qU7WS7P8R/ej8ev Mt26VkvIGFPiEPImJg653VgyajxMC+KkVY9sMiqgzotDSUEfPxZthirTL w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3567056" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3567056" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032913" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032913" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:25:02 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 6579A9DB; Tue, 27 Feb 2024 23:24:56 +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/17] x86/tdx: Convert shared memory back to private on kexec Date: Tue, 27 Feb 2024 23:24:45 +0200 Message-ID: <20240227212452.3228893-11-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792096910349639877 X-GMAIL-MSGID: 1792098380019016081 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 | 72 +++++++++++++++++++++++++++++++ arch/x86/include/asm/pgtable.h | 5 +++ arch/x86/include/asm/set_memory.h | 3 ++ arch/x86/mm/pat/set_memory.c | 35 +++++++++++++-- 4 files changed, 112 insertions(+), 3 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 979891e97d83..cc67f7380055 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -14,6 +15,7 @@ #include #include #include +#include /* MMIO direction */ #define EPT_READ 0 @@ -831,6 +833,73 @@ static int tdx_enc_status_change_finish(unsigned long vaddr, int numpages, return 0; } +/* Stop new private<->shared conversions */ +static void tdx_kexec_stop_conversion(bool crash) +{ + /* + * Crash kernel reaches here with interrupts disabled: can't wait for + * conversions to finish. + * + * If race happened, just report and proceed. + */ + bool wait_for_lock = !crash; + + if (!stop_memory_enc_conversion(wait_for_lock)) + 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 = { @@ -890,6 +959,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 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index df0f7d4a96f3..87f18e4f9373 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -141,6 +141,11 @@ static inline int pte_young(pte_t pte) return pte_flags(pte) & _PAGE_ACCESSED; } +static inline bool pte_decrypted(pte_t pte) +{ + return cc_mkdec(pte_val(pte)) == pte_val(pte); +} + #define pmd_dirty pmd_dirty static inline bool pmd_dirty(pmd_t pmd) { diff --git a/arch/x86/include/asm/set_memory.h b/arch/x86/include/asm/set_memory.h index a5e89641bd2d..9d4a8e548820 100644 --- a/arch/x86/include/asm/set_memory.h +++ b/arch/x86/include/asm/set_memory.h @@ -48,8 +48,11 @@ int set_memory_wc(unsigned long addr, int numpages); int set_memory_wb(unsigned long addr, int numpages); int set_memory_np(unsigned long addr, int numpages); int set_memory_4k(unsigned long addr, int numpages); + +bool stop_memory_enc_conversion(bool wait); int set_memory_encrypted(unsigned long addr, int numpages); int set_memory_decrypted(unsigned long addr, int numpages); + int set_memory_np_noalias(unsigned long addr, int numpages); int set_memory_nonglobal(unsigned long addr, int numpages); int set_memory_global(unsigned long addr, int numpages); diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 0d2267ad4e0e..a81bb24b80c6 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2176,12 +2176,41 @@ static int __set_memory_enc_pgtable(unsigned long addr, int numpages, bool enc) return ret; } +static DECLARE_RWSEM(mem_enc_lock); + +/* + * Stop new private<->shared conversions. + * + * Taking the exclusive mem_enc_lock waits for in-flight conversions to complete. + * The lock is not released to prevent new conversions from being started. + * + * If sleep is not allowed, as in a crash scenario, try to take the lock. + * Failure indicates that there is a race with the conversion. + */ +bool stop_memory_enc_conversion(bool wait) +{ + if (!wait) + return down_write_trylock(&mem_enc_lock); + + down_write(&mem_enc_lock); + + return true; +} + static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc) { - if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) - return __set_memory_enc_pgtable(addr, numpages, enc); + int ret = 0; - return 0; + if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) { + if (!down_read_trylock(&mem_enc_lock)) + return -EBUSY; + + ret =__set_memory_enc_pgtable(addr, numpages, enc); + + up_read(&mem_enc_lock); + } + + return ret; } int set_memory_encrypted(unsigned long addr, int numpages) From patchwork Tue Feb 27 21:24:46 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: 207543 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3043159dyb; Tue, 27 Feb 2024 16:12:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUmvFyc0bn97auzLC2LSRuEUq5O3ClQcvtUn/fo91GxmsL5dky/hkUxogD2GB6k2+vjHJTKtCh6g778zvJWyUAsUNEtyA== X-Google-Smtp-Source: AGHT+IFPY5FAlJu7adyk1tnahEf5JhlRTBe/mNolbeAXatoH4ZvvwPLGWC6x5nebqVvlV1j8klcM X-Received: by 2002:a05:6a21:398f:b0:19e:a448:71cf with SMTP id ad15-20020a056a21398f00b0019ea44871cfmr4329751pzc.24.1709079129092; Tue, 27 Feb 2024 16:12:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709079129; cv=pass; d=google.com; s=arc-20160816; b=gIpGarjQJhhokLQD7HXycWDzsiGPdG1PEPfoJ0X5K02TXntXWQOsih96AE3Sw/8PAA Ew1E1H6J70YGheR9O5SpOYfIAOg0pDwWbfWuh4A3skNoEUgIJNncO6SzOTgQH+uw+AeI KXJSuWtqiWvtj0jrIRKcNYfVwkv7G9BCsaYhE4rQgwx3D+dpGA2o2715zHOMHd1uCR9r +NzlxL2rNWwhZeqAl6MdFM76J5QollPMbQ2gs34i9xtNn4QUIrEUmqDv6wD5UiyUmvFu zJMyGoVA4g79Ogpnl0qY0WKuLf8VnOpM9pdG8+jJlr3YsfeuWbtTAvTKMitF5mrYmBDA 0dUg== 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=KOY34Zvq74JO7RzGLfSWs6V+YhWX6Y0Zxm2OXufSBCs=; fh=yQt9ROgMHUZejH3hDVFamAWFXphHuLLRaOt+BxF1Gfg=; b=Ii/i0ktC8X3wTVB4G9qMlCGYuWgstbSWTnpE7flsiLSp9/+atJqEifiVb7dm3+nc4p LV7kfc9USir0UpZeJMEm30R5BpCuGunKKa39+dgRb/pdwwPV4ip6calCIfXnSDAKXQwY KVTjgo9nqQQKdM7sKO9rRfreqieqfKepTZOXGHaZuRsNLsiWGcnxnrJUIJJ/oUcvWkMt k82+tFK80OcNuwQpwiuU6iKcokRmxEZGuvcjT74O47y+KhcSdEtOTyPD6eCoGPzuTbuH Wm/dMqqgU8Q3qKkkTlt/cdH65hixwtAZMCq1bY0FJ5IUoMot4KMx4du4JTrGsh3tWEEl hN4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=d14EV88l; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84044-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84044-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j28-20020a63231c000000b005dc89648272si6162163pgj.24.2024.02.27.16.12.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 16:12:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84044-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=d14EV88l; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84044-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84044-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 82B4EB28572 for ; Tue, 27 Feb 2024 21:28:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D58E215B0F4; Tue, 27 Feb 2024 21:25:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="d14EV88l" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 A1C2915956C for ; Tue, 27 Feb 2024 21:25:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069119; cv=none; b=hjoeuca9ip3JRJpG8ftBtM2E1GAtFcAG+oWdlyYqPrwIetQWDVTbL0MFqUpDisllnX3iYCZdgtTIxXXp8fRwgtNIK00VLdZCpr94z2mXqMRyZ+ErWZlxZGfk43pSfUj49lUQR1D6cSd5K0eO41fykZAKc0nSEqGjKtkP9tiJ/ps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069119; c=relaxed/simple; bh=R/jnQJ7PA5+pcFQcinQUmyRlg1Ef9fKzEGnFbhwA+qE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YZinVr64prEXImIYtaOGZoflRzzdK2Q2LsYVcg4DNjOfv2/JH8iNsn8Gqb+jr5l9G06vX7lv55W6c/LygFzKU0iwTd7IAc83lmCp6lMn5KjIPhrZNABcRuQWfwku7bgMOItRucR1YVGRk2v1Jnv3ghpFHkbYh2XkomJY/89WVxw= 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=d14EV88l; arc=none smtp.client-ip=198.175.65.16 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=1709069118; x=1740605118; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R/jnQJ7PA5+pcFQcinQUmyRlg1Ef9fKzEGnFbhwA+qE=; b=d14EV88ld00Sulgujh7RLzaDyIjZZMRAe/LxaFg743yl50l/qfFAPkoT 86R+Cslc3MM/nXOtze3TbSo/2CNDLmjLoP5oai/Phr9VpOTrWLfGwuWDr uIL2HLgogZgx/MVgDW6x7KGyZFvAWF6KEMVFtgvca1azjR3naML8WnAxu vnblSDThzf+wi54HUy8epX2ECL4Iac+uTKNMACaS8av613+/EgEZJROlg lyy8jIA/DgHIfzgmATbjbSMzQShOksRQNysq16DLrWGJUiFuwBizuWvaV YDWi99jLtGapyX+l8HHmo79V7aLfRC5ABKI7Bc7H50EdIpaC4RLszfGRG w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3567071" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3567071" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032922" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032922" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:25:02 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 720C6B0D; Tue, 27 Feb 2024 23:24:56 +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" , Dave Hansen Subject: [PATCHv8 11/17] x86/mm: Make e820_end_ram_pfn() cover E820_TYPE_ACPI ranges Date: Tue, 27 Feb 2024 23:24:46 +0200 Message-ID: <20240227212452.3228893-12-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792099356418301128 X-GMAIL-MSGID: 1792099356418301128 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 Reviewed-by: Dave Hansen --- 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 21:24:47 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: 207536 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3035629dyb; Tue, 27 Feb 2024 15:56:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWew0+cM0XqSHFoSauYn15RQjFco9V2y4RjQEACBm1COalnYahYvSpdxidYKv2FNALeWqMitlUil+Qnrt/qUStzSo7EUg== X-Google-Smtp-Source: AGHT+IHGt0GFTvEUdQh8FMUikArfQ3ig1kuvEOMkOQFHBxkRJA/hQeRdvtnu/HT65BXAyzmxuwYS X-Received: by 2002:a17:907:20b9:b0:a3e:6aae:d342 with SMTP id pw25-20020a17090720b900b00a3e6aaed342mr7962667ejb.47.1709078213828; Tue, 27 Feb 2024 15:56:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709078213; cv=pass; d=google.com; s=arc-20160816; b=suK2mvLFIxhpjhwxtp3LJPDWisZw8UnN5QaCswKiXc2q9jF+kPvc46q7Uhn6Z8zszp teAybqzDkZQpi/SbWVq6yfmFJVuSbMyBSO0+Z4cYAaU7HAzUww6+vJW0Op4mhERQ4Z/j ZWlVKjTiX1QixV7blZjGZsbAvAdQSxSX5cTh1y5ijHZozTWW+a737zt344xuNDVzKLca C6goBqmS2Am4hipVBI7tdfpG4TKEOtoF2+gLaqIST2SMDiKTgO0FQlmGy8LDnFs2gCaK ahO1qhE/kdQpRiAyPlHsySV8qNd4bv6lyOHKpTp6e5GLXRoyjF9ZsiyDQK+mvXigCNfM KTZg== 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=/F//wi4v4NSuFeUhp5DsElNj4hG99xI8DSoq1ERe6f0=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=pBbBOYCkdnG8yBPjmwpxMhwS4CaAlAEdQ57TB0beMVagWoJPBnJiQIk+fGYRUpytWZ RtGTtrK1UZXlNNOdN716smKb+ILWJJyAPfLB5oLNjZskolTe7fTa3ZJCrPB9Q+NjtgT/ BIjFvFHoQxzWr+A9K1gxtrcYAJ60LZ6/4Ff9kbMdKTqhm5jXqhJrD5OidWN9we5zBvcf Q7MVciILjzN2CRwhbDRIExYeL+ASvKF++TTM1p8UUhROqHDst/YV1DWkFOhd5FYvtIbp 5ASDmKdc0xIIUpZhnJrTlCxU/SwdvgCv93Db+e+VajYjZdVHS4OjtgSAtHxXqfip36KU MmqQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=G6qeOqOV; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84043-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84043-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 f14-20020a170906c08e00b00a3faa046722si1095518ejz.410.2024.02.27.15.56.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 15:56:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84043-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=G6qeOqOV; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84043-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84043-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 6B55B1F2D607 for ; Tue, 27 Feb 2024 21:28:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 000C415AACF; Tue, 27 Feb 2024 21:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="G6qeOqOV" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 024D4158D9C for ; Tue, 27 Feb 2024 21:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069118; cv=none; b=pzdAyBDAPKH87BnC3kyCev2UsVB3II7NenMRwgOICBE5afN4fIUCm4+zGW0jXyyATLQI7GHQ+bNag+uO3etfJq4ymzeqZLvmazG0yWuhWi7A/AdwffAVWbxAGajH8rQLfo3siKWtHk6fy2Zaiu//MnlrQ0hMG/+FXqhVeZth7aI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069118; c=relaxed/simple; bh=pJgXfq63C3arXvCjRGyfK5PtseQeqyNecMgpXB9cqPk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pK7PW2qaEYp2mrvmdDCDiQ7XZ8YDBDNCucVBK+Ipx5RNqDkpa4IrCKbhhmIZtmvYGR8ATTcoLtYXJWZHComLJbDg9ZR5AZ0FtLW37GAkojwbdTy+zeHoVvXj6N1IY82GeUAy0oimia5IeDGuiAZ/KBNpKYz8b6HMGQ+/IoYqZfM= 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=G6qeOqOV; arc=none smtp.client-ip=198.175.65.16 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=1709069117; x=1740605117; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pJgXfq63C3arXvCjRGyfK5PtseQeqyNecMgpXB9cqPk=; b=G6qeOqOVvKITllVGcTyrGD4mog8VP58gl67fdYrdCW9nXZhQ5Nhezks/ /UUos3M7kMTtmMPKK5a00SCtPYMTkS+iPNFtOyWUltbDc+8J5CLQrCh8l PXG+X2ISRBAvrNMp+A9YNbXpfZVzOribuPmhvMP/VLwU/A8hG23uKLLyT lUkkiqWeZIcbLA3UrPGNo+Wiyw8xhR3knx6rUb2KOejPGQ90U3mdJIKGv z/mU72R8R/oU3uiSynMP9R/GZSqcS0i+uaDB4qUHyorAbTS2gZuv/DaII f21x9W/NJk90j3QZbYS12bHILwpYiNmbHuXbk1yd2jxx7oGiKhIE/llRw w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3567063" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3567063" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032916" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032916" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:25:02 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 83282EFB; Tue, 27 Feb 2024 23:24:56 +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/17] x86/acpi: Rename fields in acpi_madt_multiproc_wakeup structure Date: Tue, 27 Feb 2024 23:24:47 +0200 Message-ID: <20240227212452.3228893-13-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792098397320394614 X-GMAIL-MSGID: 1792098397320394614 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 Reviewed-by: Thomas Gleixner --- 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 21:24:48 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: 207551 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3050778dyb; Tue, 27 Feb 2024 16:31:01 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVrPVJULybzdPWtk6xLeuItUPI9vQMhiy4gk4B9gmxXLg2lzZwRQ66jbi9vP7NqktvCZoNkUdAOc/ZS3CsUC2cGZxByPw== X-Google-Smtp-Source: AGHT+IH3uYzJgGOC1WvIe3Ae28A44oTCxZKYHp37vl5yr2da85jz2MIH5BlqvAa25kzLcL3CiZzO X-Received: by 2002:a05:622a:1aa7:b0:42e:7e3d:747f with SMTP id s39-20020a05622a1aa700b0042e7e3d747fmr10978400qtc.16.1709080261605; Tue, 27 Feb 2024 16:31:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709080261; cv=pass; d=google.com; s=arc-20160816; b=tYfu/qfrE/r2B/nj8qV4PFE+8gq7rwRhauS8fatPUmTHjxEsAkiOZmej904K+g5u0i 14cNft/aKHYZEyjSIa979R0pfYdyQ2GUUfx5BYe4ACB2nZsynSzTjIdXHa3lNNkADSaK U8gyFsXZlXCbsW7c9Bgns8uYhzHAUc8weXMcIvLbmCpAD6oY2W7J6RejRnk5Fj/dzHvW Pl4Tor2pCHL1k2dGyjBOz3jPMwuMRmVlLvaTfsECOJ72+6tYg820mC6MnAWAlrBxHr2K 3KMrxpAt6Ci4lj7p/CmElPsRTXWdctzUKMC2nuB2fSBPFw7oC4lFaAhZoff+8S2kG8Sv y6rQ== 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=zFRc5F0OrXPq8GXF7D+lJqxFNo2ctkgLcQtX4R4Kfdw=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=xEQ854SfIMEtqFquVnQKsBS0FLMPy6m9rDqQWL/n/gmd35cgRpLi1UBvCOyr5zcJR4 uGBa0yRSg/9lH9OSx8jO9OSETJz6GexwbcmjCefo6WW36nW/0vTtrfA1D001qEwVMBwi suIAgapNITvas1OoZbkFmDSi2r4QHglPDiGX7AuJnjBL+anyd79pPHmzVAXeddOuvviy I8i81YMBIU6IqCrcaU1hDxbRCctct4KLFbH1NlObGUozP6bs1FPqbA71QzCL4bhBcAwH 3S8lDSaEp52sjm9Gc6rPMsYcjidid7VAgoNcbrr04BloQ8YX1nCef+w0bEcwGNB9Ik5a WPEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YaeI+QjV; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84042-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84042-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 c11-20020ac86e8b000000b0042e770d48dfsi8170756qtv.35.2024.02.27.16.31.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 16:31:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84042-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=YaeI+QjV; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84042-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84042-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 3F0231C278F6 for ; Tue, 27 Feb 2024 21:28:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1ED6115AAA6; Tue, 27 Feb 2024 21:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YaeI+QjV" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 78F54158D99 for ; Tue, 27 Feb 2024 21:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069117; cv=none; b=MNYeErTxQ8ff1AQHsIghf1qGikJXZyST5nsqB3KGV9cLJ7YaUo2rlBkI86CX7lJ8QJ219oo5ty+iW565Y4dmmKNfNX6HLad9AYStqUaAl+hXdpNVVUz6AbB3PBQfLJKyDy5Oey3QQ+xQ4nlI9ngWGoRoxd8T9sklAfN1XSolt/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069117; c=relaxed/simple; bh=4OahAA5tbkCWt5kWDDzHkciJDRb/0EhPa8AF3hktH9I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NpTeHu+PK4Hd7AFPKumM/bdK0qAk62tCa/k3PpGkS5H5oAj3UY+vEW5tgEVKdsWv6itSctDv7aVdS6c7Htr97nASgaKiqS+5IIeMrRAZAprEcmPlf783Km5uFcokc1/qNG+hkPUlHPWB5ZMXmX0ejp6vQDLUdQgLbCAdSgK2+l8= 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=YaeI+QjV; arc=none smtp.client-ip=198.175.65.16 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=1709069117; x=1740605117; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4OahAA5tbkCWt5kWDDzHkciJDRb/0EhPa8AF3hktH9I=; b=YaeI+QjVzbuMKqzfJYi/0W4Ha0jhhlnDENaJBftPVVOL9G0CmCG/3GsB kjaM+zZNQiEzhttFeSllo1youkNJD0P/DvJNLz/ZZ7SX21kUOW5sNP5IY bC8ViRO/Kx8+LhbY+KQmc8IB4O+CjKwTgKDN2qzGRgPqGpZDEswsbxmA8 95H/blNxGXsCUtElOnl4JB7v9kCwXk8oTdtv012/fkkdAGJub05XiQALf Z1ZOV9ZYw79KLbt+f7u+y0eaEO7xay70qdGBTB6/KgRFiZBxRZ9wAdW7C loRGwy5oBmPI19+WmLehw/CSMffkewl8BJCl8bvUwkI5BnE09tvTKENw1 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3567067" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3567067" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032918" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032918" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:25:02 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 90B3BF27; Tue, 27 Feb 2024 23:24:56 +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/17] x86/acpi: Do not attempt to bring up secondary CPUs in kexec case Date: Tue, 27 Feb 2024 23:24:48 +0200 Message-ID: <20240227212452.3228893-14-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792100544213497794 X-GMAIL-MSGID: 1792100544213497794 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 Reviewed-by: Thomas Gleixner --- 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 21:24:49 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: 207545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3045276dyb; Tue, 27 Feb 2024 16:16:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWbtiHpMFET/AHIg4C4jZxq5MrT1bZlW/M13hN/cMq/svNMw2e0dIvsqzrktunMzkOaurxdAKDfxZ5cRZMAPIp7p/P94g== X-Google-Smtp-Source: AGHT+IEvrmf5pn9opnv9pHtX4W2goTSDny3KPBRq9fO9sTvaFAAtSfHOwF3RM8MF7hdaiOZfLjxZ X-Received: by 2002:a17:906:416:b0:a3f:176d:23b9 with SMTP id d22-20020a170906041600b00a3f176d23b9mr7882230eja.37.1709079416775; Tue, 27 Feb 2024 16:16:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709079416; cv=pass; d=google.com; s=arc-20160816; b=JQBEs/1a2GHHpSyU6By3nn/HjqxnC0+wAxXhyqoRJbK7jR3gt1V6BxM37EPHN8VDwN 7cMxa2UTPGQ3SVuhnnef/RYcs+MUHU54NTfsQ3dpcFtLQEyOb2IhUp1XpHNn55P02Wiy Uk/k6prROVq49hWb4XQ+7Pr//AZ/paj7a8SytABjx9lInieQeGnUM+Sx0pAAWF2to33k NSBTH/cOH/wcXCeuW0SqHq4Ig8d1wdZcDx07d4H2Dwmww01qQQkitGR5Wf6sP6aEY+cT BfAke0c5BFVek9MKyC7rYUFYO2o2hqoZl1ajI1wdTVtzIRPbHTbMjETHjb57AEyfUnop ebHg== 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=1DIayc1K30UV8O/dasJJA9Pj6/H0Vw6+uliUsVfettk=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=f1ZtOj3aYQDB/UbKID0WgAqCB3H8G7qpEuzFsQOuV1ElfEQNBlxG8I5DrzSFjJaQSw lyyeqT5TQoepM3GBTi42rR/NW+FvLMI+VtyQOdufjRworKC5+Yb4Jx0G0//P24m4xZ9/ tLq+XivIYQYcdhL15tFrm+u344kE/hMzSl0dx+6gRKXgUX9NXqnB4Y9yy9JPtWHE8Bkz VAUeTYMwp+/08kACal8cPOiBmg3yfnQIWWaQ6GzAwfsfhE9vXG85WkOmXNgogUoPs3JM kdabeAO5D+i16c9tlvP7hW436+GxjS7E172S5k93NwmL0oMVf2dGG8U2J+FUQjiCKKI5 jWdA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZsWJYbi+; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84040-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84040-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 u24-20020a1709060b1800b00a43fecb8ef0si18411ejg.501.2024.02.27.16.16.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 16:16:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84040-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=ZsWJYbi+; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84040-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84040-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 EDC021F2CEBC for ; Tue, 27 Feb 2024 21:27:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C544159582; Tue, 27 Feb 2024 21:25:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZsWJYbi+" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 3F238158D65 for ; Tue, 27 Feb 2024 21:25:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069115; cv=none; b=K4/eNE5BnBwMJ0iHxSnc8zCLIFdedqZ3x7WS8/KhlX8pAfgOVwWE6Bn8ciH14H5azRGub5xTvPwWrJUe/dQ5z3ku/GB1H9OzWTR+LgV1v/CZgkz2mYUX19/ZID08K5oTuzOtrj6vQb72SC5x9rFGqBQ/SwBrC74sLWwIOX5f7YA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069115; c=relaxed/simple; bh=D4SysnZaXorUFc+XF+aGbS1csNj7xK6JLwiHqGE+3Sk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j8eSUqofGfm5axrLOQk972VPxbAcI/RK1Uz7jbgKkdhb7Fcjy30g1j6oQDrgCAd7nFwvoHApmZ4xHcfR2x73qgRHRYxkiN9nQRdDbFvABVhmM1IinZGYZCsEjnzwAxYeLTLR+eqvUsU3qF9+lqFeknEQ9c336YAO9GbzbKBclig= 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=ZsWJYbi+; arc=none smtp.client-ip=198.175.65.16 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=1709069115; x=1740605115; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D4SysnZaXorUFc+XF+aGbS1csNj7xK6JLwiHqGE+3Sk=; b=ZsWJYbi+NT1lZjnRH7rmr1RX2o6Shk+rJr2QMexGHQ6rq/Gkgv6cZ2Gp ztCM9m5cQGxLUy27BSQ0z0rsGgjJZiC/Tt6xkK7HYTMUiBRoR1/Y6CzG6 u2QrIwvVpWVZeRlUxE/5ELm3xIAT3Nb9/6qNcNrB+jLGqsOgm9T0XNE+c FJ9Vw6FA91Cd3t+wfPzr5TVr6/cshgFDp/5vBqlVc3Ih24Bbjz0iw/q7f CQme8TOgEI/FK/pvDs2N2FxMf++wMBcO16qkROlvnO4k+YGSsJKGWgfs+ j7nRhpi3xiZHg6RPnPTtOBgSHQMM50RqcYmnNRPjJvH5mvw+QZSxdO6co g==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3567045" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3567045" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032914" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032914" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:25:02 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 9E2D31033; Tue, 27 Feb 2024 23:24:56 +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/17] x86/smp: Add smp_ops.stop_this_cpu() callback Date: Tue, 27 Feb 2024 23:24:49 +0200 Message-ID: <20240227212452.3228893-15-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792099658252874896 X-GMAIL-MSGID: 1792099658252874896 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 Reviewed-by: Thomas Gleixner --- 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 21:24:50 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: 207567 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3071658dyb; Tue, 27 Feb 2024 17:25:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVk2L6XH0/bzkVNlptqndLY1vT2TWXXJc64iG/oJn32zLOyy2C6ZjwnAADj8xoAmHLzE1doTfoU+SyVJoIrY7RJgNgCVQ== X-Google-Smtp-Source: AGHT+IFrtOHgk3DZUHfh9/sS6XE1UxiO4fZPkhnpkJtA8GC+57bM4GasNqMi3PZljWvQzYgUSb0R X-Received: by 2002:a05:620a:16d0:b0:787:80bb:c2e7 with SMTP id a16-20020a05620a16d000b0078780bbc2e7mr3789583qkn.51.1709083537916; Tue, 27 Feb 2024 17:25:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709083537; cv=pass; d=google.com; s=arc-20160816; b=HSWLffUir7BSl64Qy4gqU7jqGvjLy3goeq/nct1Er8zhQuRZxNEEtj6B6gQNBeVobv 3KFGywGJNTCMUcheicqCohA6qkSwgQy+l68iwUdQKy5cdMu6A8DA1vF7AbZ6qPgZwnrf Iuo9ydDcXpErFzkkmUDowQIb7mic/m+Kg8yMucXdAQfX+Ykydo6YjQ3dlq1HboG/yZm7 tqU623e7Vjq2iXXHzzLKrD433uHZnFmGikm5li1i8PrnTuoC6zGM0d1xmgf16f4exkzT qG1fV1wfxB5i5W/MtDTVcD+SKDaoXFEhFHuHBYV5G8E6i0ndcBRvTo73EEfKORj3Y2zJ JIYA== 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=O0AdIajMed0x+5DvNJ7ZCJxKktw59OJ5uBa8s2TLyMY=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=RQTbblLpXdrxIHK7lI1In5YPCv/Ua64bJ4wOlcEK08nMTr+0pLtDq/BfJhInHGi7Ph CPOvlxK6Pj2j6tyTOIGo895s7/o8uYn2+HJ2iM9+rbnJce+iInjYXWPT/d04lQIx049a 1BmehceNqCgSlJUT+jgLWN6Yzm3SJ6Aa/MdblsfHq2Di6PXC48f8xJR7Po70Z5UY1wQh 8NCVcGu/9nPsrKIYzkZ3Bs1Skd8o+uQxzbExC1qtUhFs6LSx401VHgG/0Zz7Hgnm5iyh lKGqCrvkNQ4pPZdy1TDvEBGEOS8QdalvzopWxtHd8YTm9Sa4CJ9r6DveGp9oZ6L079UC mD+Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=d5htavVf; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84048-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84048-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 wl12-20020a05620a57cc00b007876b2cc8a6si8628916qkn.629.2024.02.27.17.25.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 17:25:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84048-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=d5htavVf; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84048-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84048-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 14F7A1C28D14 for ; Tue, 27 Feb 2024 21:29:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0193415B97D; Tue, 27 Feb 2024 21:25:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="d5htavVf" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 EDB4615A4A2 for ; Tue, 27 Feb 2024 21:25:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069121; cv=none; b=aanqDoNhTkSfkg4Zf3Ry0OzbNp0LCNzDNAgftAifmg+FLNDu7SxEV/zOBPIfaIPYc55aJO3r35+Y/XijGTkRVisDPHY0pENlpUYFa2OpFd7Xu2Efw5UXnY/ztLbnSXjTJ6EY9v7DFlD1iOqfP+Wqo92VVlq2AMCqxu0KST9+who= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069121; c=relaxed/simple; bh=wfElhcuLUzOIt/rpQx3fYg+5YYi1jjhrzzGUyBH3dyE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y3i5po2a9QeZjwF2ubkFk1sbj69JxWbW1JJf5OJ2aGPetGAINYH4F/p7bWwGh5CEPs9DbrEirwE6Sb5P2grQikMZm+FEBBwLwcQrJxpSKHFEohDqxX/N01p6Dx1/vqPK+0BL8Y66WBu759dC0hr3+qm0oy/Dc7YtjMzmQvG/IJ8= 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=d5htavVf; arc=none smtp.client-ip=198.175.65.16 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=1709069120; x=1740605120; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wfElhcuLUzOIt/rpQx3fYg+5YYi1jjhrzzGUyBH3dyE=; b=d5htavVfh4u7Y2SzqMnvLs0NzMF/pR9hIVZlnC0PGCYAa4mocgYHxp2V GikQuwSvozU+ElU86D98dUue8+gdDKEDenbDdgWooEqt5J04lpJiBvi1C Dk6M+Psn4BxuyESr+sRWqzJDEe7je30bT6C2YknpfkRQWxmg+BbwpZTu3 hzQ6LhtrnyEybh42gTZi662hvgnGIY2czfRbVHUS2zo3Rk12OYo+wRqtf sl4QDKp9pdn8c1OWCyB5bBNWcPnIx9qotgdSz2ugwY02SCnYJuYsPEtgG GGyEjDUHu2QMow9Q6dfxN7jMIT9kMlrKwqEoa8RWvkHbKYbI+D554Cmq6 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3567108" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3567108" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032931" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032931" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:25:08 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id AAD311063; Tue, 27 Feb 2024 23:24:56 +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/17] x86/mm: Introduce kernel_ident_mapping_free() Date: Tue, 27 Feb 2024 23:24:50 +0200 Message-ID: <20240227212452.3228893-16-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792103979527479591 X-GMAIL-MSGID: 1792103979527479591 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 f50cc210a981..bfc6611fd98d 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 21:24:51 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: 207572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3072599dyb; Tue, 27 Feb 2024 17:28:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXej1e10zwfLWLe3t2GVvk5fdf1UPYMB8Dk11Rj2m+aNCE7+2acnDvSt9KD36l4cqHYCcTHqM5ZIy/Lv/Qa8n20rLpq7Q== X-Google-Smtp-Source: AGHT+IGDTF62bwMc+QPrHVK7f7/7a4lRyV0by0FYRS5S0MzZQuo2tg3zdBOWij5bQHbflp2UEZRP X-Received: by 2002:a05:6512:114f:b0:512:f317:f5c0 with SMTP id m15-20020a056512114f00b00512f317f5c0mr8471463lfg.42.1709083694876; Tue, 27 Feb 2024 17:28:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709083694; cv=pass; d=google.com; s=arc-20160816; b=QJXuE1ddlZ9yJjHNgHzDRW6kUnZK9GINFw17bABdnLwLiyn+GAN44nsQpLd4AlfJcy blujmUCji5TD5+3axMAlUYuCMkfj4+KZLXDzisPI9BfRMIug04uwF4MbAiA9hZjDzCWc 0zomgPXduO1hfTIlrMgnNdzVfSZ5y2QbQNVaObvDFbcOxHaxyaGyBWmO+Bj0vV25M+Uo Rrj9qE7ZaXeL6HI1EUXKmE8NQ3NTGWEWF+Q4Dvz+pSp7wWkHPvFeuAsMaFjVX0lrjCPn q2RJQt5VL1bZreT/RaBWMTAQDWabRih7/eZmPIwiJ9Fb4amgioNkIigUE543vrpoQV7P xNZw== 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=h6pr2vz5uEtLWZGf7gQMBxBOYQcOBABpCPF2GL57e5Q=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=rfrvydsB9I/MdLATb+dOLNpGiQmhcXx4cpjKgbLZzowavyC//lFQCNxnG0/6LxBU0h lJ8nr5jVvRX5yLERfSbXfJcXXGvrqcQJxWG1Hbu4+o5ZWUa2ULMsmXIfuRjDZWVGYK03 tbSL0mwq4s1MA5Jr66SHSwC95ALpzA3ZoZxDpKhjv8Gb7nkYn2GdYVvE663/K0HDAl/6 PCbl+nLwl7nkrTytYxzyLI7sD4mrlQVEkqh91szQZepEUla3aCAyZXXxGlSkXLkjuvop AeNt66feTAgXouv/GH/GnTFBRl5JGewVKGxCgWMAfziQag9a7kXqeQK88jOB6TW1Exkr wYlA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TeePp4Ay; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84049-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84049-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 k5-20020a1709065fc500b00a3ebdea18e1si1215090ejv.240.2024.02.27.17.28.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 17:28:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84049-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=TeePp4Ay; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84049-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84049-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 C91951F2E234 for ; Tue, 27 Feb 2024 21:29:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7905315B99D; Tue, 27 Feb 2024 21:25:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="TeePp4Ay" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 EBC3115AAA3 for ; Tue, 27 Feb 2024 21:25:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069123; cv=none; b=naN4HidrbgBgO3QeSdy6ZECNWdhnAGTO8PkSqgWzSOXy7C9Onu0EUspxajAms3eX/Ce1vUyZubTWdSKRkC5H69Suupf30nhmxB8he0g+FRDybw20ZxhUALEav1q4FpiBSNYSiPq1OTiBalbFqUYDqjc0lWRUQW1M3q2qBEkGzrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069123; c=relaxed/simple; bh=txRUFpMSxXg5LAXaF41EiCvBKfa8Uy7Uc4euvd58Ye4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pf4o3eMXsMVS/8ZQZfnatUwuZhD7ACDGXLGH9BvcMp+U63SUt4jVj7x2g+35wnurLtASHYS+n5OMnszac5yFShTzvff5jY4VTZdLix7yoWSOhqkYvALgqeIiZserDDLodb8Xqs5K6Dm6BOzu0j8rVXit0R4bg1+4Te8uKErHq/0= 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=TeePp4Ay; arc=none smtp.client-ip=198.175.65.16 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=1709069121; x=1740605121; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=txRUFpMSxXg5LAXaF41EiCvBKfa8Uy7Uc4euvd58Ye4=; b=TeePp4AyW6pKcFQqkcR6VSzq27ha6ATMFSpNRkxCVLdfTtvUfOQBxy/N fu++2YopBpqYq2s1ez9MTsse4LZV6CPh/eNywaVw5evRCpnsHWwZALPyu znPV5x8YvogT3w2Ok4DiPDDfSgXUhgBHdInD0uvvpPfxm49b3ZHLFSeYI HoLi4V2u46kHfkq0E2GXMuarLfmXtsug7JQr/puCveiqefBbmWrkHH7/t VVaZ4xsYQ1TENdb/7+BdsmTDJsk7icosOJnbmg+vCFGSLPpkrBQ8kO3ZD DK3tKJXSOKk77qlPI3bCGJGeMAUgnZPRtJQ3/5ptoNXXQPoy3MOj9uRe+ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3567110" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3567110" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032933" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032933" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:25:08 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id BC9521207; Tue, 27 Feb 2024 23:24:56 +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/17] x86/acpi: Add support for CPU offlining for ACPI MADT wakeup method Date: Tue, 27 Feb 2024 23:24:51 +0200 Message-ID: <20240227212452.3228893-17-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792104144503585096 X-GMAIL-MSGID: 1792104144503585096 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 Reviewed-by: Thomas Gleixner --- 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) */ From patchwork Tue Feb 27 21:24:52 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: 207556 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3065691dyb; Tue, 27 Feb 2024 17:10:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWJZbTpH6gh31u4ALy87CAiFefEzHdxpIMWy0CoU8MRWqjaWfvlvBHBUJ3OvdO9awo8Yh85UbaR029k5ZzMDaD+s/urRg== X-Google-Smtp-Source: AGHT+IGjovuchXEmbCLB689puinKX0IQ9reEyaMmu5AaNmj1fqmhLAwKgmowhlZzSHSfu7l8cwG4 X-Received: by 2002:a9d:73d5:0:b0:6e2:bf19:194e with SMTP id m21-20020a9d73d5000000b006e2bf19194emr12748895otk.19.1709082605947; Tue, 27 Feb 2024 17:10:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709082605; cv=pass; d=google.com; s=arc-20160816; b=a/r5HzZmd8OByw89aWAW1DR2vqBx+2sqGCJLsRgNcP1U9MzQopCukGp8W3ii4h55q2 QZHAGa9sDtnm+Wga1Nq1xelMVt5AupFHE20TX4mw1M5427lQLtKdCO8hBflvE64n+z51 XaOPClzkzxxGNEiGAnd9LFcot/h04w4ZPZVvqdY0yR5+LrmaUgJuN9o1ym+wswM/srBG hH7QuAR+Gbd2ZLXo26SmaT8vwwK9irkJPmQ8XDtHidl1F8ZEEvgOeVj9v74fEACozl39 p/EKQ/Ej757dhhRkqNo03kYB8lJkwcxV25k/nnguWVyzwWUgQ9cOSUIQMisMB9Th30bD xaBg== 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=XRCAUvp8NBcMzHdjO9AXsmx8/AFSPxWuHFPr/8cJPHg=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=t5A53uoB3vAJRWr8LPlmbyZ64vmTchFych8LrrJ01jfsnBADo3LnJfnIwlB8+zYVbn gwNbcHmWITKqI6IMPCx+lTpq/BnQ8hVc4+ypk6s+zeb6BtyVxyL2LrrrsFyXbnHlRNSL +rQW8q9P160zR+P9v/Uir7wDV2TIsDjt+Ys79G5/Jjq/5lqsQSayoiyosNaYli9UEZyS wAfec0XmhcFYjR1SvB1jX5/PMENJ50ImLd3uUWKdXzTNpykCme8Z0EqBMEbDg/C66JL8 FQbjX5j4u5GlW+SgOyS+8WQW5Zhm5DmF+RiqdHi3FVVrP0RVprHulFYDZy0OHWmppy2L Pw7w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Tt2G7iS6; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84047-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84047-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k72-20020a636f4b000000b005dcc035ca8fsi6315541pgc.561.2024.02.27.17.10.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 17:10:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84047-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Tt2G7iS6; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84047-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84047-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C9734B2B66A for ; Tue, 27 Feb 2024 21:29:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2964F15B11A; Tue, 27 Feb 2024 21:25:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Tt2G7iS6" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 74AB615A493 for ; Tue, 27 Feb 2024 21:25:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069121; cv=none; b=Jm3i8XuzpQ1/DMLLk7KEorR95awqrxlGT5Z+M7aPj2HnaCEJ187x5SUiaMJqrw6TLrAxzdu+7llxdB6xCA6+iz7QwGSHNnMwmxyxOXtLLxxN+5abyNXdLf/jDDAMDwweyquTwJaXSZxdpkYBkG6XVtJjRPgRj9e6LE+4j22l7nU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069121; c=relaxed/simple; bh=210lCphqYKumbsSKrHahIq5zl6lhgbzI8RmOuXqd25g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SXVS6MB+fMrQODa7N+/jPA75WO+V+w55J09PJmZYXEndRgGTHheemnqymOcHAO1/hGfiHAgJrl4k6kXJYoq/4GGZbAbawo5WEH0uygZyXXpWKl3RXTr5e9JluqzRs/+A7+KUcQibMBClbmX0kJ/E6tIxx3v905u/A3926TjH3DY= 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=Tt2G7iS6; arc=none smtp.client-ip=198.175.65.16 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=1709069120; x=1740605120; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=210lCphqYKumbsSKrHahIq5zl6lhgbzI8RmOuXqd25g=; b=Tt2G7iS6HS3REwU32awORFUUG1ePAAHoJNiQ9/dzgavUkMOG9NXvxze9 xumD8xsUcUdjGi72iQKS9SaA5Xf8CASphpS2UDkubZZu1XKWIkpXuNGH6 2dYdyzRz54OEMGr31pwtNGGBCUODzj9RbWigQZh8i25h//ouZY3ywLwxe bywJqsRqKtzLiALHv3lnGotYqGv3pOt83jNjxRYfup6Naz8K2xZYq4Xar 3lfQm2k0lbKLk2lAcym3rJ6CHmyn4E+pRBkncIq1Htn0ukp/ndk2cLQ8h 7yuUGjsFaCMB1iz9awpChBGkZB9CQnWiK90x7wpUS3dQm3twuiTEmzVk1 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3567091" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3567091" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032929" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032929" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:25:08 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id C91C61210; Tue, 27 Feb 2024 23:24:56 +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 17/17] ACPI: tables: Print MULTIPROC_WAKEUP when MADT is parsed Date: Tue, 27 Feb 2024 23:24:52 +0200 Message-ID: <20240227212452.3228893-18-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792091626661851428 X-GMAIL-MSGID: 1792103002750026623 When MADT is parsed, print MULTIPROC_WAKEUP information: ACPI: MP Wakeup (version[1], mailbox[0x7fffd000], reset[0x7fffe068]) This debug information will be very helpful during bring up. Signed-off-by: Kirill A. Shutemov Reviewed-by: Baoquan He --- drivers/acpi/tables.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index b07f7d091d13..c59a3617bca7 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -198,6 +198,20 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header) } break; + case ACPI_MADT_TYPE_MULTIPROC_WAKEUP: + { + struct acpi_madt_multiproc_wakeup *p = + (struct acpi_madt_multiproc_wakeup *)header; + u64 reset_vector = 0; + + if (p->version >= ACPI_MADT_MP_WAKEUP_VERSION_V1) + reset_vector = p->reset_vector; + + pr_debug("MP Wakeup (version[%d], mailbox[%#llx], reset[%#llx])\n", + p->version, p->mailbox_address, reset_vector); + } + break; + case ACPI_MADT_TYPE_CORE_PIC: { struct acpi_madt_core_pic *p = (struct acpi_madt_core_pic *)header;