From patchwork Mon Feb 12 10:44:33 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: 199717 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2392213dyd; Mon, 12 Feb 2024 04:25:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWO8qn0p0zh5BaWx+2+/0GplijN1WCpwkF+SvC29aBxq1y9WU7ilkTLCNYfbm6kXYldZQss2EkRKiadbAZdz/UVyOJ+fg== X-Google-Smtp-Source: AGHT+IFg6B0jg+VSA3g1ghMTxsGfUzQ/rxhQC3YQXcx04a0ZBZ+5NF8k2bFDzl7727Jjd7QBIMl+ X-Received: by 2002:a0c:cc86:0:b0:68c:a48b:1837 with SMTP id f6-20020a0ccc86000000b0068ca48b1837mr6129978qvl.56.1707740741819; Mon, 12 Feb 2024 04:25:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707740741; cv=pass; d=google.com; s=arc-20160816; b=Ske8Pk3SPNSTx4hj+feEOB7S0Vhg97zw9+HJQVUpQGNezvgzaKCLwiq7nnJN6pn0Sz hI36IZbdHpzAycRpDX4TzHx7niUooaIAchVILSM6FMtVLxX0c1yMxljgIG1o0RvOmp6o XBQIm12MzOidtIhV1cmPbDwQ8xiN7h15Z9xSKDYo7msPo7t4VDXZI4ZOdUXIWl/7ek2e MsV7s0pDGGsYgOf91zWMDOHWUQ5UxPEFRI0CPcNMsWSmQd7SsR7pJ+BpgW/xslcWqizJ FkYOHMSxBMs0B/65WAC3pxyOpgn3HzNkvvQtxqBB9r5f5bPRG6iNeEa//4v6gQRQi8c9 2MqA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ggivcp34W9ZKldlp0j46NnLvy91MR7Cbf6oBjb5ZF5I=; fh=Xcm7+5ZdFt6keyeRiZ20zbjG0qsAKpcOrDWpPmDuQgo=; b=NchJmjAJkkc8o/9ZULYnYojbkm0j472nZfIsh5mTOTWe3R5P+FzuOgtdg2wWLc0C+G DiFLMVM2d3U90+nFpgR588AE4Dx/H5n8DuJF449glrCXJUC44AIydGBrtgITbKnntZUg xfQGhiqU+B696L1gc+c1ccqrx1ykhi6fm/3LHBff3yVVJXHVbvDSnEkydvVjGSyeKaFb j7QDHTpJbDlGWNOJ8RtqMHmoVqjM2zqaMWi13z+v1PQkDJwVULKcdl+E5TXX6VmLQaWf wEQPOMAWn8lYcJ8LqwajXMctpt3zOvlJL6LEjkiVXLaIH2FijWl97PyAZaR800kYMfUD cX2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dUB3ckbw; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61350-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61350-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCUL3rJ8JVWuDUeXQIk6Aflri3e5fUyj9pE1roQIASI+az/exPz1mfL/cq7E5RTk5SqsBavus3TThRy1DHINGKBh5LPB8g== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ke26-20020a056214301a00b0068cb086b38esi242058qvb.386.2024.02.12.04.25.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 04:25:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61350-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=dUB3ckbw; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61350-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61350-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 399931C22057 for ; Mon, 12 Feb 2024 10:47:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0ED343A8EB; Mon, 12 Feb 2024 10:45:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dUB3ckbw" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 3CDF238F8F for ; Mon, 12 Feb 2024 10:44:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734702; cv=none; b=tddSwpxcWpDVl3mryjUEsKUIUFVVUNx2+UCtY8MR59ealxOfq022/JNKO178aaqjr5z1eBcyNmBywkuJfnK5uwuxRsNgDa39y+XAkK6oBbn66qfgWN/efioJaqD/1EjcSXhcJxgEy1Kz8aEiuzDajaQjrTS52l5hRMGFbeZEVpc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734702; c=relaxed/simple; bh=qz1krj0wC55JXx44sTGWHpxuKY8Fuz6UzO1qVRE49gA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=catKNLQ8PAd9ME/kTlO8/57hcscrPTkp6mVhO9F1qCD4NDGyboe58PCQntp0JoGWEkZunPDzS1uD2RvBybr7qRXfqUWyhAFF6HZNXg8JMawA9xHn7HY/egTo4RHsGuH38Yte6bcXfuwU9bp/xxILKKLZuoUxdOZZA/O1umAMIQQ= 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=dUB3ckbw; arc=none smtp.client-ip=192.198.163.17 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=1707734699; x=1739270699; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qz1krj0wC55JXx44sTGWHpxuKY8Fuz6UzO1qVRE49gA=; b=dUB3ckbwfE+5/W6aDo8bdZ4L0z4GyzDJdAoI2IG8csp8cwgjiChU9qpE Vt6Y8rur7J/EdzTjytnAipdkFuGbPHIdNa7IZnskoM7kV1dyQ3PHy+UGG c3nsgx+C9jbpTSYSRjJKW4P2yH37u6xcxuku4hnpgBX6VheTbdLVBMH/U cXiHNlZyZnhiUSsyFKKHpJYy5cyhzK55E2XanjTKRh8RVV7UfSpVLcvKe AIZ7DWUes56rwPEy/iNQxmOqC1419UqKLmqnf52cyQEP/lOVYTc6A075K LFG4VCe4zjmc7ziw2wllFZHxlYZeZa3T9dk4NZ3b+1YSeQnsijYubgSYW A==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1584986" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1584986" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:44:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035571" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035571" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:44:54 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id E8134A3; Mon, 12 Feb 2024 12:44:52 +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: [PATCHv7 01/16] x86/acpi: Extract ACPI MADT wakeup code into a separate file Date: Mon, 12 Feb 2024 12:44:33 +0200 Message-ID: <20240212104448.2589568-2-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790695956409269580 X-GMAIL-MSGID: 1790695956409269580 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 Signed-off-by: Kirill A. Shutemov 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 5edec175b9bf..1c1c06f6c0f1 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1108,6 +1108,13 @@ config X86_LOCAL_APIC depends on X86_64 || SMP || X86_32_NON_STANDARD || X86_UP_APIC || PCI_MSI select IRQ_DOMAIN_HIERARCHY +config X86_ACPI_MADT_WAKEUP + def_bool y + depends on X86_64 + depends on ACPI + depends on SMP + depends on X86_LOCAL_APIC + config X86_IO_APIC def_bool y depends on X86_LOCAL_APIC || X86_UP_IOAPIC diff --git a/arch/x86/include/asm/acpi.h b/arch/x86/include/asm/acpi.h index f896eed4516c..2625b915ae7f 100644 --- a/arch/x86/include/asm/acpi.h +++ b/arch/x86/include/asm/acpi.h @@ -76,6 +76,11 @@ static inline bool acpi_skip_set_wakeup_address(void) #define acpi_skip_set_wakeup_address acpi_skip_set_wakeup_address +union acpi_subtable_headers; + +int __init acpi_parse_mp_wake(union acpi_subtable_headers *header, + const unsigned long end); + /* * Check if the CPU can handle C2 and deeper */ diff --git a/arch/x86/kernel/acpi/Makefile b/arch/x86/kernel/acpi/Makefile index fc17b3f136fe..8c7329c88a75 100644 --- a/arch/x86/kernel/acpi/Makefile +++ b/arch/x86/kernel/acpi/Makefile @@ -1,11 +1,12 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_ACPI) += boot.o -obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_$(BITS).o -obj-$(CONFIG_ACPI_APEI) += apei.o -obj-$(CONFIG_ACPI_CPPC_LIB) += cppc.o +obj-$(CONFIG_ACPI) += boot.o +obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_$(BITS).o +obj-$(CONFIG_ACPI_APEI) += apei.o +obj-$(CONFIG_ACPI_CPPC_LIB) += cppc.o +obj-$(CONFIG_X86_ACPI_MADT_WAKEUP) += madt_wakeup.o ifneq ($(CONFIG_ACPI_PROCESSOR),) -obj-y += cstate.o +obj-y += cstate.o endif diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c index 85a3ce2a3666..df3384dc42c7 100644 --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@ -67,13 +67,6 @@ static bool has_lapic_cpus __initdata; static bool acpi_support_online_capable; #endif -#ifdef CONFIG_X86_64 -/* Physical address of the Multiprocessor Wakeup Structure mailbox */ -static u64 acpi_mp_wake_mailbox_paddr; -/* Virtual address of the Multiprocessor Wakeup Structure mailbox */ -static struct acpi_madt_multiproc_wakeup_mailbox *acpi_mp_wake_mailbox; -#endif - #ifdef CONFIG_X86_IO_APIC /* * Locks related to IOAPIC hotplug @@ -370,60 +363,6 @@ acpi_parse_lapic_nmi(union acpi_subtable_headers * header, const unsigned long e return 0; } - -#ifdef CONFIG_X86_64 -static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip) -{ - /* - * Remap mailbox memory only for the first call to acpi_wakeup_cpu(). - * - * Wakeup of secondary CPUs is fully serialized in the core code. - * No need to protect acpi_mp_wake_mailbox from concurrent accesses. - */ - if (!acpi_mp_wake_mailbox) { - acpi_mp_wake_mailbox = memremap(acpi_mp_wake_mailbox_paddr, - sizeof(*acpi_mp_wake_mailbox), - MEMREMAP_WB); - } - - /* - * Mailbox memory is shared between the firmware and OS. Firmware will - * listen on mailbox command address, and once it receives the wakeup - * command, the CPU associated with the given apicid will be booted. - * - * The value of 'apic_id' and 'wakeup_vector' must be visible to the - * firmware before the wakeup command is visible. smp_store_release() - * ensures ordering and visibility. - */ - acpi_mp_wake_mailbox->apic_id = apicid; - acpi_mp_wake_mailbox->wakeup_vector = start_ip; - smp_store_release(&acpi_mp_wake_mailbox->command, - ACPI_MP_WAKE_COMMAND_WAKEUP); - - /* - * Wait for the CPU to wake up. - * - * The CPU being woken up is essentially in a spin loop waiting to be - * woken up. It should not take long for it wake up and acknowledge by - * zeroing out ->command. - * - * ACPI specification doesn't provide any guidance on how long kernel - * has to wait for a wake up acknowledgement. It also doesn't provide - * a way to cancel a wake up request if it takes too long. - * - * In TDX environment, the VMM has control over how long it takes to - * wake up secondary. It can postpone scheduling secondary vCPU - * indefinitely. Giving up on wake up request and reporting error opens - * possible attack vector for VMM: it can wake up a secondary CPU when - * kernel doesn't expect it. Wait until positive result of the wake up - * request. - */ - while (READ_ONCE(acpi_mp_wake_mailbox->command)) - cpu_relax(); - - return 0; -} -#endif /* CONFIG_X86_64 */ #endif /* CONFIG_X86_LOCAL_APIC */ #ifdef CONFIG_X86_IO_APIC @@ -1159,29 +1098,6 @@ static int __init acpi_parse_madt_lapic_entries(void) } return 0; } - -#ifdef CONFIG_X86_64 -static int __init acpi_parse_mp_wake(union acpi_subtable_headers *header, - const unsigned long end) -{ - struct acpi_madt_multiproc_wakeup *mp_wake; - - if (!IS_ENABLED(CONFIG_SMP)) - return -ENODEV; - - mp_wake = (struct acpi_madt_multiproc_wakeup *)header; - if (BAD_MADT_ENTRY(mp_wake, end)) - return -EINVAL; - - acpi_table_print_madt_entry(&header->common); - - acpi_mp_wake_mailbox_paddr = mp_wake->base_address; - - apic_update_callback(wakeup_secondary_cpu_64, acpi_wakeup_cpu); - - return 0; -} -#endif /* CONFIG_X86_64 */ #endif /* CONFIG_X86_LOCAL_APIC */ #ifdef CONFIG_X86_IO_APIC @@ -1378,7 +1294,7 @@ static void __init acpi_process_madt(void) smp_found_config = 1; } -#ifdef CONFIG_X86_64 +#ifdef CONFIG_X86_ACPI_MADT_WAKEUP /* * Parse MADT MP Wake entry. */ diff --git a/arch/x86/kernel/acpi/madt_wakeup.c b/arch/x86/kernel/acpi/madt_wakeup.c new file mode 100644 index 000000000000..7f164d38bd0b --- /dev/null +++ b/arch/x86/kernel/acpi/madt_wakeup.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include +#include +#include +#include +#include + +/* Physical address of the Multiprocessor Wakeup Structure mailbox */ +static u64 acpi_mp_wake_mailbox_paddr; + +/* Virtual address of the Multiprocessor Wakeup Structure mailbox */ +static struct acpi_madt_multiproc_wakeup_mailbox *acpi_mp_wake_mailbox; + +static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip) +{ + /* + * Remap mailbox memory only for the first call to acpi_wakeup_cpu(). + * + * Wakeup of secondary CPUs is fully serialized in the core code. + * No need to protect acpi_mp_wake_mailbox from concurrent accesses. + */ + if (!acpi_mp_wake_mailbox) { + acpi_mp_wake_mailbox = memremap(acpi_mp_wake_mailbox_paddr, + sizeof(*acpi_mp_wake_mailbox), + MEMREMAP_WB); + } + + /* + * Mailbox memory is shared between the firmware and OS. Firmware will + * listen on mailbox command address, and once it receives the wakeup + * command, the CPU associated with the given apicid will be booted. + * + * The value of 'apic_id' and 'wakeup_vector' must be visible to the + * firmware before the wakeup command is visible. smp_store_release() + * ensures ordering and visibility. + */ + acpi_mp_wake_mailbox->apic_id = apicid; + acpi_mp_wake_mailbox->wakeup_vector = start_ip; + smp_store_release(&acpi_mp_wake_mailbox->command, + ACPI_MP_WAKE_COMMAND_WAKEUP); + + /* + * Wait for the CPU to wake up. + * + * The CPU being woken up is essentially in a spin loop waiting to be + * woken up. It should not take long for it wake up and acknowledge by + * zeroing out ->command. + * + * ACPI specification doesn't provide any guidance on how long kernel + * has to wait for a wake up acknowledgment. It also doesn't provide + * a way to cancel a wake up request if it takes too long. + * + * In TDX environment, the VMM has control over how long it takes to + * wake up secondary. It can postpone scheduling secondary vCPU + * indefinitely. Giving up on wake up request and reporting error opens + * possible attack vector for VMM: it can wake up a secondary CPU when + * kernel doesn't expect it. Wait until positive result of the wake up + * request. + */ + while (READ_ONCE(acpi_mp_wake_mailbox->command)) + cpu_relax(); + + return 0; +} + +int __init acpi_parse_mp_wake(union acpi_subtable_headers *header, + const unsigned long end) +{ + struct acpi_madt_multiproc_wakeup *mp_wake; + + mp_wake = (struct acpi_madt_multiproc_wakeup *)header; + if (BAD_MADT_ENTRY(mp_wake, end)) + return -EINVAL; + + acpi_table_print_madt_entry(&header->common); + + acpi_mp_wake_mailbox_paddr = mp_wake->base_address; + + apic_update_callback(wakeup_secondary_cpu_64, acpi_wakeup_cpu); + + return 0; +} From patchwork Mon Feb 12 10:44:34 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: 199801 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2435773dyd; Mon, 12 Feb 2024 05:46:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWnvxAlTzf/kd0MaMXYuAvwQSA7CRFL7VEKWirnqHLfOab5JQuFQ14W4T5P18Dmm7eoXm2ZNUxtxWlGZMUVJ4OGWv28fw== X-Google-Smtp-Source: AGHT+IH6CqsI0NbIlpN/RRDb3o9fW6gVxws6uzaUJZeoOm4DnJserWHKeq0EUvmdtySb3AS90vIW X-Received: by 2002:a05:651c:1414:b0:2d0:a801:b4cd with SMTP id u20-20020a05651c141400b002d0a801b4cdmr3661399lje.38.1707745608576; Mon, 12 Feb 2024 05:46:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707745608; cv=pass; d=google.com; s=arc-20160816; b=r5bn/x1Z03seTaXgROo9oJ9tHsrhgXUvb0/+zzykPitaMgv8n9z3b5Pyh4nOzE5gpD QPqLh2trT1d14pRYyzN3AL6wjdxKVqL3lV4RoD5h/4WWEaJ0aI6SMtWXzH2nrwHCp+F7 AoVFtx8yLbeJJVjyBmq2d4X/kbIOnGfgq06PZo7PrbU2KelaAV4znGopJLfYvWub1nDe YVYq3+iQapkAfsIdLkO4LWIqwFP4GM7UaqGGHuRwz4Ga0+9oQQBduUaKdiBPcXgq+o8r pmEn9Bnxdx6gseEv288jVw97+T+IHI5/keZRDfO9yzXWZ+raDLiRL6FJ3CYFX2jXx2tY nBVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=OmyTK/ZD8egS/hdHc+6kQr84NCywF9FNJ49v4TdySnU=; fh=T4IDp7lsJEzuFSuB6oQma5ktnkQsMmqBCYF3pjruarE=; b=ph9NELeezEFbEv4B4fSdspvjQ9tNbKVt36N5Xk3v5Or0biTNRCDf0kabT3kq1v/zDm 0lWzXgUTe5GuaYcZkjF24KFBPmJhrETyFiDSfYglQ6Nt2D+pMbeZBIYsd8VUkr+Ou7T8 wqIXs9OUKXf3+yVm/u3uxHrHXUelAToei5MaqJtjSOP3w3STWYJ2Qj57NyDVD7TYlQur 3RqM6Zb13WYXC5j5MmJ/Z1FtD4tP39bpt/ihZIurkWuUM3++kEdELPk3Bw1DrcEkchq1 S5onUVdNAH3yHRbqGGFY/wtLRsETL3tV7mHVa1lgY8GYiJ4NYNBqoGVAk+x/v/GU0GWE niFQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JOB5sudH; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61351-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61351-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCUXF+F6n+qw0g1bleNbna7S8DFMHgDVp8T/g3OH2RK2MR3GFfQg2SWiH0FrrtFeRUQZrqsPU1Y6ffR4bvzWRTm0THNWHw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w22-20020a50d796000000b0055f0b19fa4dsi2870122edi.636.2024.02.12.05.46.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 05:46:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61351-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=JOB5sudH; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61351-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61351-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 23A871F244AC for ; Mon, 12 Feb 2024 10:47:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED6863A8E7; Mon, 12 Feb 2024 10:45:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JOB5sudH" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 68130383BF for ; Mon, 12 Feb 2024 10:45:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734704; cv=none; b=GzhmSWWsDmIwmcsJ47BB1Cs3kxo9Z0mHbeWb4+SgeIghHTRkgAfuGQe8gfqNUqqivEFUwrJ5lyJwhVoS8E/cFca4NhtSHjpTIiYdP18ETHaGqJD8lOBO9/ngjKIsbqMi4wKMYhiXw69B2GagPZiPgQ6xVgDr4eu9mE1leKYyAfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734704; c=relaxed/simple; bh=S6F/Ky7eP00etA13aVi6LSez70wEvbCqE2JWP4lJSJ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hkfAiG8nmr7FFof0mD3bG/78KPX3+l5GQQHvrRsj3fcP3OPt9rqDuOlTa17Gh6bLHN2XFLu0auAdf1OMaoqGyvQmMgoHRHGko7euGMDZ1bUrO23PANd95pEp5Bcb1onkfji9e/oe96SJdFFAlgzjwANEEd9QBPxKRAjexy7BS68= 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=JOB5sudH; arc=none smtp.client-ip=192.198.163.17 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=1707734701; x=1739270701; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=S6F/Ky7eP00etA13aVi6LSez70wEvbCqE2JWP4lJSJ4=; b=JOB5sudHXiyC01T9axP4090aW2XHYFQEduAGzITFWVuWMxinFF/9W6F6 x7dvMZ6JEaalni1iYWo1CuAsIQ2ktWinWsOO8e8Ea0kqm9DBA9wic0Byp Yji9Yjv5Wo0XwslYpXjYWvMqw4yBrhYsDq0HMs8Dd8x6KzV4/wzJep8bM L+6RaVfOrZCIW01C5a7Y8Zd4agqcWqcwSTckOV4FngfoaC8dVDlR+Uumj VsyK4L9bswKsApPH/ouZ6M9Syu/ctYcbK/9IFdd00ULHAOo79uOlKca21 7c11QSoP0bnNG+Ceu01F+o1mIMqRj+kQlS4jABFBbU25fE6VtOqzasIOT A==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1584996" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1584996" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:44:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035575" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035575" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:44:54 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 013BE468; Mon, 12 Feb 2024 12:44:52 +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: [PATCHv7 02/16] x86/apic: Mark acpi_mp_wake_* variables as __ro_after_init Date: Mon, 12 Feb 2024 12:44:34 +0200 Message-ID: <20240212104448.2589568-3-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790701059214913582 X-GMAIL-MSGID: 1790701059214913582 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 Mon Feb 12 10:44:35 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: 199703 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2382512dyd; Mon, 12 Feb 2024 04:05:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXpHpP6rqJOFbsWVPdNZ/ZAGe6m54BDxsUj1cjM5nt2nn0KnTjxXJJnsNKSkMGp+7oetI1BLaRkuY8Cm/HWIyvRKuqxCw== X-Google-Smtp-Source: AGHT+IEM0J6qmKgmSgrEsL1t1lqFfYqL+fW6zDH2OS+eZ2TwyMXLZAFfmEYWfGgnBs7BWhWvRWrp X-Received: by 2002:ae9:f808:0:b0:785:b7d7:86b3 with SMTP id x8-20020ae9f808000000b00785b7d786b3mr7916749qkh.23.1707739554910; Mon, 12 Feb 2024 04:05:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707739554; cv=pass; d=google.com; s=arc-20160816; b=yOI10nzDDS8QlEkfOt9G1HeoXSUrjGICY2m5+83NqAXsXS5IIzOIJSsUiqb3IPqbB1 HNrJKB4dacCtd4hpQPiUMCzEUnIm0N67MMlBnQwR7xNZTP+IpsPbcRMh6+OJEaaJMcPD UoEOqgkVcu4a8UP/sSOL+LePfzgIM1rKhtwjrtmKG8YldTYIA71XTulpOdtBduOi5s1c H3JqQiPEZzR8mMmolFyYB+DpGvMyNDVBJFc9CaQcsPIA5NX7RMUZ0U5kcOGNq/m4mTxU JNlCRpR11dHt3sVRAn7mqDQpWuyE/ic3uuFUuSs+RKj520O79WB4SUQhj6bqBab2JYp5 8fqQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=S26fjaDFAIJ37+8snV1yUJ/yjYua3qMKaCxClShx9iY=; fh=prFWjOLAdi/r/0g8jDbMaK2XA2FOMTqulvV7JXzIEKI=; b=EVmOCEoOP+GUMIc31EOXDlfmaT+Kj+J2pjwiw060vEvFU6SdpNu0BTS9epA5Ort8Ap xc7/yDoU9tzzcZIWzeuYrO4bSkRUPUL7qg6qBuaI/UczwGoBiqEy0sNkeKE+Zw0qS3y6 h4bEGmKiBWA7TPZZSSFShKptsRSBqSSOrdSUUdyPaigQTYyCjwR0/5tCmXkX1p1FzqrG egWZKSdoJm5r2wZjrIIpUjv+Jx58mm7YhYAnSpRc67mjMDPE6CH/scoN41LSTccTppF4 1dRg9GbjsSOvKnEVOfCs21x26djGLuTjkpauXdHtNqUIEnomcrJmYvmjqq1ewInMhL1Q zvQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PnwV2c1v; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61353-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61353-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVvSr5pnKnfMZkSj/w6DrXmTBbtU7SGML0uAA7GtrTSAAp3YYZkS2VMR8LyIXb+4qTKpdY/fQhYWEqZv/tjPBLLD1ocAw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id wv10-20020a05620a5a0a00b007859e867c1asi5471536qkn.557.2024.02.12.04.05.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 04:05:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61353-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=PnwV2c1v; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61353-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61353-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 E87861C21F84 for ; Mon, 12 Feb 2024 10:48:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3D723A8FF; Mon, 12 Feb 2024 10:45:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="PnwV2c1v" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 2221738FAA for ; Mon, 12 Feb 2024 10:45:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734705; cv=none; b=j5Yy8Es01cZJRuMF1XLQ0iUkcNxxF6nCeQWzxYPBt4rFCv5utT08SBikP/CslBI9NkTdxHXO1iLsK8hLMfqSijfLfe3J+kEr0wweFsa+pHR57rQ7Ak/AzMjgJ8lz2dLiv5BmmstnIHVR9mQZh3wWBdTOn2I3/3ZradUWLK8OB/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734705; c=relaxed/simple; bh=yc+q4KsjIiSfEwY6TeHFKJsFn5r2uXtVujdyv1Did04=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rLsHg5UAdybKQSd6VHcS/saMJKm7BccfoJ0zcEgQQfhQYdW7/R5Xe07JW9OuozVvR5q6fusFpKWN5iuwy8PDyY8Z+OxGMAc5zZ5zX87G+W08SJEN5Hfabs+1TGJ1fT8oZIHwk2/1VtLSNVLIjHb2yfC3qRS1g50a1Pl/3dH+ueQ= 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=PnwV2c1v; arc=none smtp.client-ip=192.198.163.17 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=1707734703; x=1739270703; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yc+q4KsjIiSfEwY6TeHFKJsFn5r2uXtVujdyv1Did04=; b=PnwV2c1vqqNAGFTXwNIWSW1zTdKI2UKDKpN8cyOIat7J0OtP8ow8Og/n 6EkxwcWvQgwhuDQVjjSpq8Hvz4jwMbK4bPtno3QoHJ5MCDsyqdyQgWORX ZV0gBjZrAFTRDOEL0F03ezN1z5pDnBqY9JqE2gg6SXARA4geHP2X2jVnv bZgidVt5/mVDzlYEGb3poJ6FAKez+hcmMRyJW3tVYz27uFdkxqcaF280C BnSlMTwFL1GYuR2vnzXDGSCRxX/yNMplzYojnKbQcRk8u3biM1X0QEFCP T410lM0QQ2bMkdvqF89WZ+dFNn513r6E3PF4Zd9wIk6LaL4LlucXAGTMA Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1584976" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1584976" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:44:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035569" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035569" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:44:54 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 0E7EE487; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 03/16] cpu/hotplug: Add support for declaring CPU offlining not supported Date: Mon, 12 Feb 2024 12:44:35 +0200 Message-ID: <20240212104448.2589568-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790694711477178106 X-GMAIL-MSGID: 1790694711477178106 The ACPI MADT mailbox wakeup method doesn't allow to offline CPU after it got woke up. Currently offlining hotplug is prevented based on the confidential computing attribute which is set for Intel TDX. But TDX is not the only possible user of the wake up method. The MADT wakeup can be implemented outside of a confidential computing environment. Offline support is a property of the wakeup method, not the CoCo implementation. Introduce cpu_hotplug_disable_offlining() that can be called to indicate that CPU offlining should be disabled. This function is going to replace CC_ATTR_HOTPLUG_DISABLED for ACPI MADT wakeup method. Signed-off-by: Kirill A. Shutemov Reviewed-by: Thomas Gleixner --- include/linux/cpu.h | 2 ++ kernel/cpu.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/linux/cpu.h b/include/linux/cpu.h index dcb89c987164..aa89ef93a884 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -139,6 +139,7 @@ extern void cpus_read_lock(void); extern void cpus_read_unlock(void); extern int cpus_read_trylock(void); extern void lockdep_assert_cpus_held(void); +extern void cpu_hotplug_disable_offlining(void); extern void cpu_hotplug_disable(void); extern void cpu_hotplug_enable(void); void clear_tasks_mm_cpumask(int cpu); @@ -154,6 +155,7 @@ static inline void cpus_read_lock(void) { } static inline void cpus_read_unlock(void) { } static inline int cpus_read_trylock(void) { return true; } static inline void lockdep_assert_cpus_held(void) { } +static inline void cpu_hotplug_disable_offlining(void) { } static inline void cpu_hotplug_disable(void) { } static inline void cpu_hotplug_enable(void) { } static inline int remove_cpu(unsigned int cpu) { return -EPERM; } diff --git a/kernel/cpu.c b/kernel/cpu.c index e6ec3ba4950b..7c28a07afe8b 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -484,6 +484,8 @@ static int cpu_hotplug_disabled; DEFINE_STATIC_PERCPU_RWSEM(cpu_hotplug_lock); +static bool cpu_hotplug_offline_disabled __ro_after_init; + void cpus_read_lock(void) { percpu_down_read(&cpu_hotplug_lock); @@ -543,6 +545,14 @@ static void lockdep_release_cpus_lock(void) rwsem_release(&cpu_hotplug_lock.dep_map, _THIS_IP_); } +/* Declare CPU offlining not supported */ +void cpu_hotplug_disable_offlining(void) +{ + cpu_maps_update_begin(); + cpu_hotplug_offline_disabled = true; + cpu_maps_update_done(); +} + /* * Wait for currently running CPU hotplug operations to complete (if any) and * disable future CPU hotplug (from sysfs). The 'cpu_add_remove_lock' protects @@ -1522,7 +1532,8 @@ static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target) * If the platform does not support hotplug, report it explicitly to * differentiate it from a transient offlining failure. */ - if (cc_platform_has(CC_ATTR_HOTPLUG_DISABLED)) + if (cc_platform_has(CC_ATTR_HOTPLUG_DISABLED) || + cpu_hotplug_offline_disabled) return -EOPNOTSUPP; if (cpu_hotplug_disabled) return -EBUSY; From patchwork Mon Feb 12 10:44: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: 199854 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2465950dyd; Mon, 12 Feb 2024 06:35:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFdAMht31/ET2A2tOqKpt74Kji4lR4LJQ2TQVC5w5yAEKf+yObNv4da7ciHqr7uMePsTUej X-Received: by 2002:a17:902:e54e:b0:1da:23e3:1de8 with SMTP id n14-20020a170902e54e00b001da23e31de8mr7014592plf.27.1707748530163; Mon, 12 Feb 2024 06:35:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707748530; cv=pass; d=google.com; s=arc-20160816; b=iT9MrP43ZBwMOIJsiXSVPZe1wjFrMywJAfU4UaMJEgWe4uyWKniL77DeSOpvP5FPWr SKuIHg87KwSwKfh6vqHm0myAvaZmrISMMP3WI8MmZYzSReNWjYyoF8UhILNYzkC5JG11 hqfCeXVkc3AwCkeqq8EZntktSCqm0olwfV1jRdygPmPTnnyrXFuyUXAzjnLadp9LE7Pf sMSA72BcSTs9Nei6r0upLmAC0I2rtJ5RGnZwuQlp+VX0v/pRQGZp89hHis/PH61M6v2y RLNv7wRfvyaPFwIxW65LrBRtYjaYhScHuuvfT9oLIr7mBqPlbia1Ds01CpSI6XgaNp9X FA5g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=iU1ZlftgLUZTKojE64KaxxDuYt8xfxFymPnSI3m2MEY=; fh=nQnOcCXvsO1b0/cqMPvW6F5Y7xIak/Z+GJ+Zeihnhp8=; b=h521+N0aD472TKEq8HUoxEnZjdoffSIpiPygHW0BzBxfuMYmJ7XqsSMAyAtognHCCb PrVSylGqHiDxAQIRgX04zyC4QgKtGKf/HKlyLM/OrxRbNmUUkXq/W6S+Gg0/gPhhd32C vBcAjkYC38RZazIgStTrs2BPPZipcBbYVvbb+NyUWt+BbZ+8PRntzwe4TbV3yoIaXiGm 8el1MW3F4GTyJLFm204eV1Yv0uu7eS0PVDuUHbEia8TbPBX/rwOfmjQiDr67dyFRPER5 w8jYQgxZXidPbsXp8JsQMAXs01XXs6gxJ9QKPnoabT9KUzU9mO+UOyt85Z2BJpGT1I8U b5pQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WCYdhkOQ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61354-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61354-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCXFNXP5vWVqSHzRy5Pg9ZA819yzA48LwCcqgVRndZiFR2RGN/73E/MBX4UxNvYOKy8GlYtUIz5KhqcLbA78pfekKwFxOA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b5-20020a170902650500b001d726df3b29si125469plk.305.2024.02.12.06.35.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 06:35:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61354-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=WCYdhkOQ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61354-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61354-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 68AFB2858F0 for ; Mon, 12 Feb 2024 10:48:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A16293BB2A; Mon, 12 Feb 2024 10:45:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WCYdhkOQ" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 B7F633984A for ; Mon, 12 Feb 2024 10:45:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734706; cv=none; b=l0MX1Ik6YwIT+ScHjF9AQhb10VpdVQLVEoQRJkcbPbf2BEx6vX6OtuuwzS6kNsqpb2vtsZlAuSd9wcvdXfQC7/MwTn4vh8na6W7hs6DIJJLhh5e6KbS91PTefNa7vtk/zSCH/AxB5po2q5pcCp/NBS3/tW50+sggheFovNJw0/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734706; c=relaxed/simple; bh=ihRAX/Eyt4LbMVM80nu0CT6hBURKtph1gZYnA+gKNPw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R45KJ88uMAbq2gynnOQmql5z8+dU5wsTSlHpjLevOc2NsVlObiBFxwYPdSa3/QJyPwoYoZjbX28xBXLsHm/I5IR6KH0Go7WiqMbo0EEeNFOHs6TQiTc9JjMc15f+W83/DFxb3+wqjEe3M8LQo46c0yORffTsL0N/Cxt5SKK2py0= 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=WCYdhkOQ; arc=none smtp.client-ip=192.198.163.17 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=1707734704; x=1739270704; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ihRAX/Eyt4LbMVM80nu0CT6hBURKtph1gZYnA+gKNPw=; b=WCYdhkOQISDp65W69B3IfwjyGx+9y1w2jfGMx+pepBoaWmyfLNqS9rgO obxpNrws5Zn2da/rJyRs19+Q27GuBSqDhnJ15F/rWRJGN5ZmlI8HVNt4k NDZQzkul+feRdHRD/IIzf9CeyDJnK8WkANeZH8Ee7vlcZWJkx6/Rod+HI kxMH4h/Y7IVLvPyZfVaupsd965sgsgDWS7gaouflvBIt+KGVJCZFnmTbq aSESAotfsENAYBVYqPpeqvaKv4EUayH5U8PAgnTy7CExuT14tPoNa/P98 J8LNJQTJXIlUW+5nliMeNLNNZUU6sKYTzSr1BNyOVpOUSgbjPCeFOuZRe A==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1585015" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1585015" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:44:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035577" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035577" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:44:54 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 1C79D532; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 04/16] cpu/hotplug, x86/acpi: Disable CPU offlining for ACPI MADT wakeup Date: Mon, 12 Feb 2024 12:44:36 +0200 Message-ID: <20240212104448.2589568-5-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790704122578064249 X-GMAIL-MSGID: 1790704122578064249 ACPI MADT doesn't allow to offline CPU after it got woke up. Currently CPU hotplug is prevented based on the confidential computing attribute which is set for Intel TDX. But TDX is not the only possible user of the wake up method. Disable CPU offlining on ACPI MADT wakeup enumeration. Signed-off-by: Kirill A. Shutemov Reviewed-by: Thomas Gleixner --- arch/x86/coco/core.c | 1 - arch/x86/kernel/acpi/madt_wakeup.c | 3 +++ include/linux/cc_platform.h | 10 ---------- kernel/cpu.c | 3 +-- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c index eeec9986570e..f07c3bb7deab 100644 --- a/arch/x86/coco/core.c +++ b/arch/x86/coco/core.c @@ -20,7 +20,6 @@ static bool noinstr intel_cc_platform_has(enum cc_attr attr) { switch (attr) { case CC_ATTR_GUEST_UNROLL_STRING_IO: - case CC_ATTR_HOTPLUG_DISABLED: case CC_ATTR_GUEST_MEM_ENCRYPT: case CC_ATTR_MEM_ENCRYPT: return true; diff --git a/arch/x86/kernel/acpi/madt_wakeup.c b/arch/x86/kernel/acpi/madt_wakeup.c index cf79ea6f3007..d222be8d7a07 100644 --- a/arch/x86/kernel/acpi/madt_wakeup.c +++ b/arch/x86/kernel/acpi/madt_wakeup.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include #include #include @@ -76,6 +77,8 @@ int __init acpi_parse_mp_wake(union acpi_subtable_headers *header, acpi_mp_wake_mailbox_paddr = mp_wake->base_address; + cpu_hotplug_disable_offlining(); + apic_update_callback(wakeup_secondary_cpu_64, acpi_wakeup_cpu); return 0; diff --git a/include/linux/cc_platform.h b/include/linux/cc_platform.h index cb0d6cd1c12f..d08dd65b5c43 100644 --- a/include/linux/cc_platform.h +++ b/include/linux/cc_platform.h @@ -80,16 +80,6 @@ enum cc_attr { * using AMD SEV-SNP features. */ CC_ATTR_GUEST_SEV_SNP, - - /** - * @CC_ATTR_HOTPLUG_DISABLED: Hotplug is not supported or disabled. - * - * The platform/OS is running as a guest/virtual machine does not - * support CPU hotplug feature. - * - * Examples include TDX Guest. - */ - CC_ATTR_HOTPLUG_DISABLED, }; #ifdef CONFIG_ARCH_HAS_CC_PLATFORM diff --git a/kernel/cpu.c b/kernel/cpu.c index 7c28a07afe8b..3ffdbb1f7bb4 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1532,8 +1532,7 @@ static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target) * If the platform does not support hotplug, report it explicitly to * differentiate it from a transient offlining failure. */ - if (cc_platform_has(CC_ATTR_HOTPLUG_DISABLED) || - cpu_hotplug_offline_disabled) + if (cpu_hotplug_offline_disabled) return -EOPNOTSUPP; if (cpu_hotplug_disabled) return -EBUSY; From patchwork Mon Feb 12 10:44: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: 199863 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2472029dyd; Mon, 12 Feb 2024 06:46:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXRM5O0ZCbGeABofBdPPC8jjJVwwlAeWTcKMLhVaqoTaeeTXKiurZ067YQB/uByRPe3olQIisTp6iFRAUyNDg+Rx5HBpQ== X-Google-Smtp-Source: AGHT+IGzc0IpMRHGt/KHNzLgRTZvN7wmd+kMBjL6FmY41lX/0W26grUAKwCINWoQbioKotrFNUBD X-Received: by 2002:a17:906:552:b0:a38:a174:1316 with SMTP id k18-20020a170906055200b00a38a1741316mr5660433eja.72.1707749196326; Mon, 12 Feb 2024 06:46:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707749196; cv=pass; d=google.com; s=arc-20160816; b=EUQSP+EQIu3vZ7VOL1wqlAlPV+x0ti6D+a5dIUVYNjoTZvFIcs/Q1hZNO9KGLBvJ/I DVFv9Wmb+zM4MPfT7J+y8BKkqd/2x5plTFvOYf4OwMNA5wu73hbFxtReh76uhTaiXm8I KlV3CoZQZyAvdm/5NX8b7B/E3Xw+j0M+bbdlIIQhLN6+IiL3mohDLOI7+5hgHWHHp1uD 3rB8I1doZ0Ml6KIc4DUHM+x1g6TDuQCrrQdOXQHbtStXA+tcC17AvQUMc0/5aOCVK3Xe SXhkKVH22Z0JBSEyMy4276K0XWL8bmt+EgDMlLryB85rGDcPOOe+O+kJNyUiJHulJvHO 96OQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=5nY5/kk8s6fYr//Cj2FkdJCG5YE9u6hL2PBs6U9nryU=; fh=D22QgflDCgBEPzKen67LG7jh59WhmG7jg7eBrnA8enY=; b=Wx1M0wkGATH828X1+U7+vpQG/w/CRXtr74MAJQMqWgbe8Fe7Oa7j9gb7rrNAFw7wXl 4xwYjHjvGofsafCj3PhC/aDoS0s70Yx+N13hBcHgJku+4zAEQKA7Qbc+LhQaK0z/x3f1 8R4EoYXT5DAt2nutD+yjKZCdyF8aBmzzCYf4g9JzpcZHLXc3KRyVLkpTVKCpc0n+haE/ pC41ECZrYQSYpN2JPJwsezUZHmMD1jf4+WGnHfDlQinbUzGPn+oVmU9YSl1OmcpahLcL FSqdXwnGaAfqr0wescU3ntXEnlUqnSCwVS7bucRXPtsZsg4rTKlx2eSmP9lYdi14Vwjx C1dw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Tylije1X; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61355-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61355-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCWWpRcKwDdymRG2GEOnQRkZ92hl3ZYvboE2OhqcbIWqpHw2js/4mSXuXxRIYLoRd/74WHkuTmSwRuStrukuEBwCfZxpgg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g2-20020a170906c18200b00a384f16e032si250257ejz.721.2024.02.12.06.46.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 06:46:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61355-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=Tylije1X; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61355-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61355-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 29A391F25819 for ; Mon, 12 Feb 2024 10:48:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 971803C063; Mon, 12 Feb 2024 10:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Tylije1X" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 418D03A8D0 for ; Mon, 12 Feb 2024 10:45:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734708; cv=none; b=YSZi1rH2xB9tw01CQu8Od2mJy4zrTI4Rj1kP+e+Y7D3MsznlO7pCIW+en6VjSv9iWsqkGwDocSDWs6rc5QZEF1IQgDDQNXGFv8owTIc41BIutmswbtV6D9TyGuBLQdhO0yUB4fH4LAaOt+NLVMHFh1fA7n/2Da3/GHF1ni5x+sw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734708; c=relaxed/simple; bh=LcZSO2fCT5WaMkS6shCgOhCUo14EJT04WN8x+U0u+KI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZMOpwxd4BjbYZNq7ug6ElUwuewDh660RJP3dZxylFQFR032MvGskC0XSvkcMfGio/2KlEFVVEhonDLjsUnYFJW6OpTUKbmUbgJ8ZxI9hVS6QxhlbUUlAqXJJ9WWuPLR20SJ1fJXt/AYXxSDnbcs4pWmv71CX2UxEl4k5NSZiX+M= 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=Tylije1X; arc=none smtp.client-ip=192.198.163.17 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=1707734705; x=1739270705; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LcZSO2fCT5WaMkS6shCgOhCUo14EJT04WN8x+U0u+KI=; b=Tylije1XYbeDB2PsUKT2HT5vnHXUbWdGgPOLE367e5DegQFUY0tRDbqn PadWDmmQmoAgy5r2m7jfevRpJVwRZVleCtfBt4zs3CKPSF7JO/gSlkqqZ jR3gdhKXbDuZ6sXUCcJoMC6z5x10nuCtzbxHAnMjJW0vLO/YpZE+ClX9c X7lMSR0qwAoMCM12iVAX2yCbJLJOwwHN0mF6XgBddw13GpsKrtfHyLXO1 fT5iyyznsvBpBJObBE1FBeV7BULBcnQbiWCu0KZlbNFQLGH0NmEXIh2Pq TyjPGniXekkq+CHH7mpSZfTtK6JWPorr09RHKZ21K9mAtHobth5vy7U4x w==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1585057" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1585057" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:45:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035599" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035599" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:45:00 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 2AEBC535; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 05/16] x86/kexec: Keep CR4.MCE set during kexec for TDX guest Date: Mon, 12 Feb 2024 12:44:37 +0200 Message-ID: <20240212104448.2589568-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790704821521035810 X-GMAIL-MSGID: 1790704821521035810 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 Mon Feb 12 10:44: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: 199848 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2460640dyd; Mon, 12 Feb 2024 06:26:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5kDAgXsskfvVBtpMsnzmW2rS32yX9t0Zw+tkVQyTKIgD63+W7rkdWnU01iTIDuztQbRIu X-Received: by 2002:a05:6402:b34:b0:561:46fe:56e9 with SMTP id bo20-20020a0564020b3400b0056146fe56e9mr5642278edb.10.1707747997215; Mon, 12 Feb 2024 06:26:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707747997; cv=pass; d=google.com; s=arc-20160816; b=YJvPAPk2MjJfRbXbBn+AAWujfsi8DkfTNGFeXgZv8IXC/SLZaBL0KIK0QddfU7slr5 M/JAW8mYKHBYyc88E27xBMWL2S1LVNKl5gkpeSFTYcFzFlK26IPjhpDpnqHbnIteZX8l ysnjg2cL+NsSbE1IrwRPFBCULxew60/cvteQQDDy7nMlSc+cy3JDsyhBNmrqDCfoMV1X 80PTfuyJ5dTjO1YZQpyjrzyaVaiV8LHu0uZ7W1Pm83d8bcPNRgESp7+RstNxU4J14hDv yuGXiZk2GgEbdjWC5zclMOWO94uHyJOSiBBkug/qZY0jiauimyPfElCGxTvA7Y4r6utR gTFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=DL9st433qELYzhZ2gFtSHkJnrWS2dkaweZNIikWEZZc=; fh=lmXLv/p1oG7nQkVo6lVKOHhNvXS0GZ/uO+KNtqo/3N4=; b=z+edzcOlcCVKvw0nE3IBykKyLTBM+bwrCmIU2YifyRSxQ+NLJQSuC5iVpMxaGwh4jX TVc1Rhdlq1dA8hF5yJCmrl1ThA3e4Phh0dlzWS0Pg+pX3uXiEuakouo68hnSaBwPVele fME9Su1CQm6/j+Yp4JHb9BHBTbYFmpou9m8W9JxCZRnwmLcGKYrXktPf8JbjIy4uL7bU HlJz7cpNNHcvizze2yEnCoayBu9MdFfJNYZRk+6erFyBUz7jE0jM0k172BNlWBYnYOMQ qDLbYlSCfB2615nvGt5EqrZwA8rQsP2ugW38/UXtanUGg0tKdDWj3PYTdtpa1cxUM25u nQtQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hyw+Gv9D; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61360-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61360-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCX8BfUM5Ag8CGJfYmSXnI/80RPbPrKRfr11uNtIHFW3kMUYHq+43Yc2XINdBIQe4z5BTIGNXvq7SNFOlA6+gdBwHaTCNw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e5-20020a50fb85000000b0055f43795b28si2835850edq.196.2024.02.12.06.26.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 06:26:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61360-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=hyw+Gv9D; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61360-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61360-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 60BE81F268BD for ; Mon, 12 Feb 2024 10:50:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07CA33D3A5; Mon, 12 Feb 2024 10:45:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hyw+Gv9D" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 58CA03B193 for ; Mon, 12 Feb 2024 10:45:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734712; cv=none; b=mGUh+a/CmqfrPa15FrH9/SnRAfzN7HVDNOQbaTowZHOW+0gtiBDW09O+mT7+DlAVoHGqFEim3Y+0w/lX8ZIFN3TwmjfGtE6Vc8l7d0/otVg9Mezi5qj8nuk+FSYbJd6IyVyRz8gTIvsqeaAimp5aYBwtqa8LO/LhqaB0BLf2clg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734712; c=relaxed/simple; bh=ELiZbW2ZqeUSKS5G3i8R2dwq9KKRIDZ8Css9qS0iE1E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KuAy85BR4o7SxwAkvVW7CnKb/f8prHd+foXE28HFaHySha3FB8mlzOR8CR3zbIjvyBJ/uXbX7kq45AdlO8xJOL1FHn7zQAP3G7fNwAYVv9k7XfLJDaeX7CSag23jf5HcZOqbIVqvK0SH0jeoAGtEar9MzVC+tiA9pWAsbc2JL2U= 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=hyw+Gv9D; arc=none smtp.client-ip=192.198.163.17 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=1707734708; x=1739270708; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ELiZbW2ZqeUSKS5G3i8R2dwq9KKRIDZ8Css9qS0iE1E=; b=hyw+Gv9DNrg18oCykQhBWfCKlBG+gNGG5OaT9W6VvRR1xe1/MqS4YGJ2 YjsbGQTE2kLH/jz87by348144/TCY1MC5VNifDHL803fUwW9d7REWGkrP ZNGr/XKUNT+bA+G+IW4GoC05cHr12jlvjJl/pH9VcP6euUL9Ua9XsF/dm UDpmJy1VFybmaPF58nvmv2BYq4WRbcbZvwqo61Dl+/P7o2PUBQP3fUHXr 9CyP1EoosaDfHwQQshqduHNy0n5VTHgHX+uzdT/Sx3hA6rLliPHr4SDMQ LWQWD/pwwlQPbyvZWtFaV1Jw1aXY0tHa+yK5GOn/8RFyG/WEKyIMBKNHB A==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1585039" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1585039" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:45:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035595" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035595" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:45:00 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 37A91537; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 06/16] x86/mm: Make x86_platform.guest.enc_status_change_*() return errno Date: Mon, 12 Feb 2024 12:44:38 +0200 Message-ID: <20240212104448.2589568-7-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790703564221365679 X-GMAIL-MSGID: 1790703564221365679 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 --- arch/x86/coco/tdx/tdx.c | 20 +++++++++++--------- arch/x86/hyperv/ivm.c | 9 +++------ arch/x86/include/asm/x86_init.h | 4 ++-- arch/x86/kernel/x86_init.c | 4 ++-- arch/x86/mm/mem_encrypt_amd.c | 8 ++++---- arch/x86/mm/pat/set_memory.c | 9 +++++---- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index c1cb90369915..26fa47db5782 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -798,28 +798,30 @@ static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc) return true; } -static bool tdx_enc_status_change_prepare(unsigned long vaddr, int numpages, - bool enc) +static int tdx_enc_status_change_prepare(unsigned long vaddr, int numpages, + bool enc) { /* * Only handle shared->private conversion here. * See the comment in tdx_early_init(). */ - if (enc) - return tdx_enc_status_changed(vaddr, numpages, enc); - return true; + if (enc && !tdx_enc_status_changed(vaddr, numpages, enc)) + return -EIO; + + return 0; } -static bool tdx_enc_status_change_finish(unsigned long vaddr, int numpages, +static int tdx_enc_status_change_finish(unsigned long vaddr, int numpages, bool enc) { /* * Only handle private->shared conversion here. * See the comment in tdx_early_init(). */ - if (!enc) - return tdx_enc_status_changed(vaddr, numpages, enc); - return true; + if (!enc && !tdx_enc_status_changed(vaddr, numpages, enc)) + return -EIO; + + return 0; } void __init tdx_early_init(void) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 7dcbf153ad72..49b4f427268f 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -510,13 +510,12 @@ static int hv_mark_gpa_visibility(u16 count, const u64 pfn[], * with host. This function works as wrap of hv_mark_gpa_visibility() * with memory base and size. */ -static bool hv_vtom_set_host_visibility(unsigned long kbuffer, int pagecount, bool enc) +static int hv_vtom_set_host_visibility(unsigned long kbuffer, int pagecount, bool enc) { enum hv_mem_host_visibility visibility = enc ? VMBUS_PAGE_NOT_VISIBLE : VMBUS_PAGE_VISIBLE_READ_WRITE; u64 *pfn_array; int ret = 0; - bool result = true; int i, pfn; pfn_array = kmalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL); @@ -530,17 +529,15 @@ static bool hv_vtom_set_host_visibility(unsigned long kbuffer, int pagecount, bo if (pfn == HV_MAX_MODIFY_GPA_REP_COUNT || i == pagecount - 1) { ret = hv_mark_gpa_visibility(pfn, pfn_array, visibility); - if (ret) { - result = false; + if (ret) goto err_free_pfn_array; - } pfn = 0; } } err_free_pfn_array: kfree(pfn_array); - return result; + return ret; } static bool hv_vtom_tlb_flush_required(bool private) diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h index c878616a18b8..c9503fe2d13a 100644 --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -150,8 +150,8 @@ struct x86_init_acpi { * @enc_cache_flush_required Returns true if a cache flush is needed before changing page encryption status */ struct x86_guest { - bool (*enc_status_change_prepare)(unsigned long vaddr, int npages, bool enc); - bool (*enc_status_change_finish)(unsigned long vaddr, int npages, bool enc); + int (*enc_status_change_prepare)(unsigned long vaddr, int npages, bool enc); + int (*enc_status_change_finish)(unsigned long vaddr, int npages, bool enc); bool (*enc_tlb_flush_required)(bool enc); bool (*enc_cache_flush_required)(void); }; diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c index a37ebd3b4773..f0f54e109eb9 100644 --- a/arch/x86/kernel/x86_init.c +++ b/arch/x86/kernel/x86_init.c @@ -131,8 +131,8 @@ struct x86_cpuinit_ops x86_cpuinit = { static void default_nmi_init(void) { }; -static bool enc_status_change_prepare_noop(unsigned long vaddr, int npages, bool enc) { return true; } -static bool enc_status_change_finish_noop(unsigned long vaddr, int npages, bool enc) { return true; } +static int enc_status_change_prepare_noop(unsigned long vaddr, int npages, bool enc) { return 0; } +static int enc_status_change_finish_noop(unsigned long vaddr, int npages, bool enc) { return 0; } static bool enc_tlb_flush_required_noop(bool enc) { return false; } static bool enc_cache_flush_required_noop(void) { return false; } static bool is_private_mmio_noop(u64 addr) {return false; } diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index 70b91de2e053..d314e577836d 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -283,7 +283,7 @@ static void enc_dec_hypercall(unsigned long vaddr, unsigned long size, bool enc) #endif } -static bool amd_enc_status_change_prepare(unsigned long vaddr, int npages, bool enc) +static int amd_enc_status_change_prepare(unsigned long vaddr, int npages, bool enc) { /* * To maintain the security guarantees of SEV-SNP guests, make sure @@ -292,11 +292,11 @@ static bool amd_enc_status_change_prepare(unsigned long vaddr, int npages, bool if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP) && !enc) snp_set_memory_shared(vaddr, npages); - return true; + return 0; } /* Return true unconditionally: return value doesn't matter for the SEV side */ -static bool amd_enc_status_change_finish(unsigned long vaddr, int npages, bool enc) +static int amd_enc_status_change_finish(unsigned long vaddr, int npages, bool enc) { /* * After memory is mapped encrypted in the page table, validate it @@ -308,7 +308,7 @@ static bool amd_enc_status_change_finish(unsigned long vaddr, int npages, bool e if (!cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) enc_dec_hypercall(vaddr, npages << PAGE_SHIFT, enc); - return true; + return 0; } static void __init __set_clr_pte_enc(pte_t *kpte, int level, bool enc) diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index e9b448d1b1b7..f92da8c9a86d 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2152,8 +2152,9 @@ static int __set_memory_enc_pgtable(unsigned long addr, int numpages, bool enc) cpa_flush(&cpa, x86_platform.guest.enc_cache_flush_required()); /* Notify hypervisor that we are about to set/clr encryption attribute. */ - if (!x86_platform.guest.enc_status_change_prepare(addr, numpages, enc)) - return -EIO; + ret = x86_platform.guest.enc_status_change_prepare(addr, numpages, enc); + if (ret) + return ret; ret = __change_page_attr_set_clr(&cpa, 1); @@ -2168,8 +2169,8 @@ static int __set_memory_enc_pgtable(unsigned long addr, int numpages, bool enc) /* Notify hypervisor that we have successfully set/clr encryption attribute. */ if (!ret) { - if (!x86_platform.guest.enc_status_change_finish(addr, numpages, enc)) - ret = -EIO; + ret = x86_platform.guest.enc_status_change_finish(addr, + numpages, enc); } return ret; From patchwork Mon Feb 12 10:44: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: 199701 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2381630dyd; Mon, 12 Feb 2024 04:04:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IF0xn7AXTpOGBIumm5uHkdeIE1Fb3cqm4LKMrQc74eTr0EaQcuo7sN7JFdAtMQVLVMNGsgw X-Received: by 2002:a17:902:d501:b0:1da:2c01:fef5 with SMTP id b1-20020a170902d50100b001da2c01fef5mr3461029plg.56.1707739466161; Mon, 12 Feb 2024 04:04:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707739466; cv=pass; d=google.com; s=arc-20160816; b=dRIMCmRvGwRv00mVR/rNnaaiGZaizZt3/qvb/hlXU57a7twImIttHMmAOr7hQr/OJY 3Qn8/S3JydSGUO1vMy8SXoJLZO2QiVjuRqOr9EmTtIZZ1CSyukeLePx1EZ/7e2JKKpt2 vshVRwrVfgGYZ+mZgexC/rH9Y9w4OTbGZHlJhJzVzgxnLYs3UvT+kXn/OpTlVOPr9RGP uF7wX9xoyH3deF5xDuuMpYaJCzz13D0E0+Vb8izx2obONJfU2t/Z/BDqbC7WXOsAfIC1 WLiLI8+REHruwb4MU0k9oTq7KkRcTBdH0Xs6fr+aAkL+Zen69YNDiIUg0OZx5SIgQKyy rIvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kxw9uVRF0uklRfRh6iTwvS8jLXK1PeQrAkZPaXxZPCw=; fh=6rLdNDfjENId5Me7Uud0sAEp/o76D4mz3U8D22/LUIk=; b=oQDpseQJxp9vgwpklahxxmMwcbr4zwbXRBhtcTBCmIvRu11wtNHRFD9r/lG4MU74rY eaBqhp5oQ2uOxcvJlKmzbnqu9Vy4s4b1yNuwisbeml5v2AnO3BwNgM9dXZ8JhI9BRzt8 M4Ppnil+dzaYtpRN4qEibRJiQCNr0SgvlePYZ7CxBfozDcxcWJRH19JW7FUP9cqgRT4e I99vbYufqDFdwF9CbZUOX0H3Hf789xzgr1GT9nZWQlO9j950gjTyI46XEUExvnsShlB+ 7xFJAvZKT8BsvmbGUqqjJ0pGu8YF7iCdP3Voqx0DKGBC4x7fyX8sL4Iy3XXtOCfMToai mJXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RGgpLoD2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61357-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61357-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVTWTbUJo3VZpqS3xmoO1sx9LeGyPEmZTiAFuRthwVnbhPI2ERjTBd8jFHkVLGlYmvPxUfxetXwD0DOYW94UaxvtzquQg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s21-20020a656915000000b005cde42fcb11si141471pgq.707.2024.02.12.04.04.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 04:04:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61357-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=RGgpLoD2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61357-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61357-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 70ED6285C69 for ; Mon, 12 Feb 2024 10:48:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B43363C070; Mon, 12 Feb 2024 10:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RGgpLoD2" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 4406B3A8D5 for ; Mon, 12 Feb 2024 10:45:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734708; cv=none; b=JENKDga0DLLeACPA8tewhBoOEToWoftolWvVdpozHWUxsAcyog6gWlWShPzJinF5+DCROMTQrc5UmYG4sFKTCb1tpTicFy3GHhfIDHrCET15XN+82sOpQMi/qn1PwRXMWIUMSOhuQ5Izr3Eh2B+8xh2TxqJQ7NPfySyIS6oKOcc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734708; c=relaxed/simple; bh=SxAJq8PySGkIldIS+Dq+6BevKxjnV/qVUXBP60oIUiw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rY8M6HCaN1Y4CAKHnrrxDen3YPmktBcA0irOjBb/2FUTaB6CY8C5+Nro5obi1hG05jZi0PlpDUbcuEi+TgBrphd2K3OXFJ/8an0/kgoYMlxZvZkosyvqh54gWI0fbtWkgVTTn38CcRXUepAbgrFTl+8p3SqDYIoXu2ne+xb95es= 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=RGgpLoD2; arc=none smtp.client-ip=192.198.163.17 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=1707734705; x=1739270705; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SxAJq8PySGkIldIS+Dq+6BevKxjnV/qVUXBP60oIUiw=; b=RGgpLoD23pZM1KAvseQfdqsnUo9zf+Vh25P/SEJo81e5kHVkjDY625Ti 13a5h2HGe3e6gXCoW7ApB1DIirVB2QGbbtJ72xxmEqxT3s39sJU66KhMJ TvHSc3mK2hgVxGpgq6HujSHT10tcSBVlk1efJA7vYV8ytTGf28SJEP5Pj hkWPZJ6ze6kUN3gY4NmP4WtCGvma5Xg82FUWgdjQ3m/qmYdK6MCmp4rp3 ufhqPVyjDks87adoEfDfYCoVP1yZU7tYgfomZx1P/HqVf0PQLsuqixvx5 GxN4bA+LYQMeJuBdg3AAOzDp/REq4IX4vvZl3q+T6eMl6sQyrE+qSIbgA Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1585047" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1585047" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:45:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035597" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035597" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:45:00 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 483AE53A; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 07/16] x86/mm: Return correct level from lookup_address() if pte is none Date: Mon, 12 Feb 2024 12:44:39 +0200 Message-ID: <20240212104448.2589568-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790694618230407042 X-GMAIL-MSGID: 1790694618230407042 lookup_address() only returns correct page table level for the entry if the entry is not none. Make the helper to always return correct 'level'. It allows to implement iterator over kernel page tables using lookup_address(). Add one more entry into enum pg_level to indicate size of VA covered by one PGD entry in 5-level paging mode. Signed-off-by: Kirill A. Shutemov Reviewed-by: Rick Edgecombe Reviewed-by: Baoquan He Reviewed-by: Dave Hansen --- arch/x86/include/asm/pgtable_types.h | 1 + arch/x86/mm/pat/set_memory.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index 0b748ee16b3d..3f648ffdfbe5 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -548,6 +548,7 @@ enum pg_level { PG_LEVEL_2M, PG_LEVEL_1G, PG_LEVEL_512G, + PG_LEVEL_256T, PG_LEVEL_NUM }; diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index f92da8c9a86d..3612e3167147 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -666,32 +666,32 @@ pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address, pud_t *pud; pmd_t *pmd; - *level = PG_LEVEL_NONE; + *level = PG_LEVEL_256T; if (pgd_none(*pgd)) return NULL; + *level = PG_LEVEL_512G; p4d = p4d_offset(pgd, address); if (p4d_none(*p4d)) return NULL; - *level = PG_LEVEL_512G; if (p4d_large(*p4d) || !p4d_present(*p4d)) return (pte_t *)p4d; + *level = PG_LEVEL_1G; pud = pud_offset(p4d, address); if (pud_none(*pud)) return NULL; - *level = PG_LEVEL_1G; if (pud_large(*pud) || !pud_present(*pud)) return (pte_t *)pud; + *level = PG_LEVEL_2M; pmd = pmd_offset(pud, address); if (pmd_none(*pmd)) return NULL; - *level = PG_LEVEL_2M; if (pmd_large(*pmd) || !pmd_present(*pmd)) return (pte_t *)pmd; From patchwork Mon Feb 12 10:44: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: 199702 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2381636dyd; Mon, 12 Feb 2024 04:04:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV6uE2NpVFmTZBr+ScwK/4gElp2HFOcEfddgH3R0JJeD3W5ZZzRwHVkmOvV9fdu57K3tY6U+8eEMh9FktGtsjmsXYtXNg== X-Google-Smtp-Source: AGHT+IEDXVD06GEVuLKd0oAlB000nNw1Ww7Ctokhu64wKMqwtO5W8Hg3ihSSFsCcC8hGWk5Pf1xt X-Received: by 2002:a62:aa18:0:b0:6de:12ae:68d6 with SMTP id e24-20020a62aa18000000b006de12ae68d6mr4876524pff.17.1707739466688; Mon, 12 Feb 2024 04:04:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707739466; cv=pass; d=google.com; s=arc-20160816; b=DMN2Sp5SC8drgJnWHLPSlWHHIS96+TWAxl5zZIICnyXp/vIHVKdBfk2mnDGlFYwFjk LEYHXWLLnsdjbqfkqd3nQ0J3MX/jFbtGXdNjZ4whrDe40peJY6aYY+F7FbsbRks0zBoI 7nWkBRIZwksT3WaTnbN3y7+vLA1mcgHdZdoBGrzb61rU3Qi7PnSs+o0cvGog0/uprPzn LC2vyg/iuK+hQABWC2a7B/+/n/MWb6qAKBpYT64qt4eaEN5SxMUASDY+ObFLM0kLxS8a bKa/sB2t5mVLnfP5d1eTF1Sac1+UsJBYdUqgn9EdBuawSUsNa+eVpMBL8KxCb88nK7+L f07A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=QbNVvvHkrGHh7BR7Qwt2J0OgUR8dAXMlMSzqos0/4mY=; fh=9pjAm4BxNj5nm9kUGUruITVWZNW2VNpBpmUYyogX64s=; b=o4cDy9BznONV83I3DU1Sdr33rA59jAxZm9q5BkoBPz0vMDAD+ftEA4l1Jw8hLu2skB OCRPmiKv5POSzanrEff/bzbCUNS++oKHR45bmjT6l9lSoHcYHNL6fkSis0v6LVdUjlYU 9mZzPLMrMzA+BHSPg8vMbpE9SK5z6FmbCxgXGG91qg3Ql1Spp175W+676HQoDjsVv53b fda+eY8edjQiTp+uBn6aPw+IxGjHJjE/LXpi794ql9RFj1S8A3No2i/HPt+vMe0/vVN+ YIF3gVqns3O8cxJFKdZW4D7xxwVJF8DgUA5cIe6M0jaDIszE10xOEmsqzFbHNG1DNZ3k jLuw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jY57t3qY; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61358-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61358-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCXdZGUww6Xc2w62+dqAZ2RC3efoNw6l9CcT3AsU0tsyfT+U8ZiQ3uhCYGDJ2V97r/enVofT8H0TyOWSA0hcKDF9uwHDGQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x32-20020a056a0018a000b006dbe30aeb1dsi4927185pfh.112.2024.02.12.04.04.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 04:04:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61358-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=jY57t3qY; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61358-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61358-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 73FF828600B for ; Mon, 12 Feb 2024 10:49:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BDD3824B2F; Mon, 12 Feb 2024 10:45:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jY57t3qY" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 5566A3B191 for ; Mon, 12 Feb 2024 10:45:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734710; cv=none; b=rs6Wg0bhYdn7lrVgyW4GgJxTuffhwBtMg6RNeemgDha/G0jFt4NP7e2u/0+8kzB/DK22hyntpS1XrSNPYHWioddT69IMdNEhwDYdVGjm4guNPfMH/oxjwe1eRhDYm3kYEqLdh+KGrLozTCSqlImqMI6U5No1miM1SwLJRQUIMxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734710; c=relaxed/simple; bh=ttorKfrAsCfwHjNDg0dNsgpEDrTBddN8JkJtVUzul2k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yw+uVtD+wZuIlUamYAMWXEoQ7IpjJQ3NRnQ93429jU6XN1XPHyvDWJD7SYeeXGIS4hull4sWlEzEl3K9qHCbQiO3flvRR1mrfTfxZn+uwpIz8T/ITZ6DPaZc1Vp09ZQMcpUAjBBSZFnaHo823cc0HnAdiDXkofOXrxMRYUkPEDU= 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=jY57t3qY; arc=none smtp.client-ip=192.198.163.17 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=1707734707; x=1739270707; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ttorKfrAsCfwHjNDg0dNsgpEDrTBddN8JkJtVUzul2k=; b=jY57t3qYL1YgZPvA3KmwHJC8ugSV5cqWXYdxz5wXsGvJVUbq8RLyZV+z K1zPqp9ye+QdowjxCsbVlvJK97g50II/pZKIAuOu4jv+3634NmK4SwLYM I3aBcJv8660NLOFh1OgTf5YagMTGsv7vvkeOJoYJ0Qw4LmReUwmaeBC4q MGTVsqrwSkQUvMxiwi66EDnf3CJMjnfComelVHZ+ioLlWWS0brEWvgSVy qI9g3D/sH9E9EALLrMcWCO0I44wiaMJ2F+0YAtPAbT1urIqr+Y0QPULby EXJN5ddd9tnGBRR1cMupBbbEBtKUu5M3xqrwlJvBt5Jt6DQhsn2GpStJy Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1585068" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1585068" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:45:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035601" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035601" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:45:00 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 54901541; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 08/16] x86/tdx: Account shared memory Date: Mon, 12 Feb 2024 12:44:40 +0200 Message-ID: <20240212104448.2589568-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790694619046331734 X-GMAIL-MSGID: 1790694619046331734 The kernel will convert all shared memory back to private during kexec. The direct mapping page tables will provide information on which memory is shared. It is extremely important to convert all shared memory. If a page is missed, it will cause the second kernel to crash when it accesses it. Keep track of the number of shared pages. This will allow for cross-checking against the shared information in the direct mapping and reporting if the shared bit is lost. Include a debugfs interface that allows for the check to be performed at any point. Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 69 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 26fa47db5782..fd212c9bad89 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -5,6 +5,7 @@ #define pr_fmt(fmt) "tdx: " fmt #include +#include #include #include #include @@ -38,6 +39,13 @@ #define TDREPORT_SUBTYPE_0 0 +static atomic_long_t nr_shared; + +static inline bool pte_decrypted(pte_t pte) +{ + return cc_mkdec(pte_val(pte)) == pte_val(pte); +} + /* Called from __tdx_hypercall() for unrecoverable failure */ noinstr void __noreturn __tdx_hypercall_failed(void) { @@ -821,6 +829,11 @@ static int tdx_enc_status_change_finish(unsigned long vaddr, int numpages, if (!enc && !tdx_enc_status_changed(vaddr, numpages, enc)) return -EIO; + if (enc) + atomic_long_sub(numpages, &nr_shared); + else + atomic_long_add(numpages, &nr_shared); + return 0; } @@ -896,3 +909,59 @@ void __init tdx_early_init(void) pr_info("Guest detected\n"); } + +#ifdef CONFIG_DEBUG_FS +static int tdx_shared_memory_show(struct seq_file *m, void *p) +{ + unsigned long addr, end; + unsigned long found = 0; + + addr = PAGE_OFFSET; + end = PAGE_OFFSET + get_max_mapped(); + + while (addr < end) { + unsigned long size; + unsigned int level; + pte_t *pte; + + pte = lookup_address(addr, &level); + size = page_level_size(level); + + if (pte && pte_decrypted(*pte)) + found += size / PAGE_SIZE; + + addr += size; + + cond_resched(); + } + + seq_printf(m, "Number of shared pages in kernel page tables: %16lu\n", + found); + seq_printf(m, "Number of pages accounted as shared: %16ld\n", + atomic_long_read(&nr_shared)); + return 0; +} + +static int tdx_shared_memory_open(struct inode *inode, struct file *file) +{ + return single_open(file, tdx_shared_memory_show, NULL); +} + +static const struct file_operations tdx_shared_memory_fops = { + .open = tdx_shared_memory_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static __init int debug_tdx_shared_memory(void) +{ + if (!cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return 0; + + debugfs_create_file("tdx_shared_memory", 0400, arch_debugfs_dir, + NULL, &tdx_shared_memory_fops); + return 0; +} +fs_initcall(debug_tdx_shared_memory); +#endif From patchwork Mon Feb 12 10:44: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: 199852 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2462162dyd; Mon, 12 Feb 2024 06:29:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWwbEH3C+cNygUGlFDZ7BWP7ixSEeQ/pkl3lGlSiFM8hLcsb6Gi0kEDTPWpmZBSg/1rStDRBrzKsWb0w7utEHvsjEQVmQ== X-Google-Smtp-Source: AGHT+IHZemnMr9XKEDXxC7GUyXXtNLuRvfFVAAlkQFHdhmuGxZs/74JlQSEOxGcn29XNQmorOAxH X-Received: by 2002:a05:6a21:3a97:b0:19e:c0dd:5dbf with SMTP id zv23-20020a056a213a9700b0019ec0dd5dbfmr5737701pzb.28.1707748168949; Mon, 12 Feb 2024 06:29:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707748168; cv=pass; d=google.com; s=arc-20160816; b=nQtlYpLoi2qgV9pZErWK22x93oBP7OFsjSwYA23Hli7LUIIqnpaby6wNHpMKW21vm5 qMc7ufTE/EdSAADZb7EpLcpHEYl0BmR/coRKfw9ywMpyiq5iQEZK25eEt1pX14u1sPs0 Lfw516zqgfGxbrhvjbFdmmJ/A0FQq5KEbh54Ta6crl7oQVaOziRFqO9UKQA6EClPjRmg iyoSwnkw98pTBe8bjOIT2GIb6ZVvLuojKNuokuQmgbZu7r/LToJO9S7mOapFdB6ggTI9 FN7WjsMsZox2umRC6PPcwmak4cQ5YZkJPNf3Be1xC3Ndqv+g4iLbT+mIcxrvMj6eSTq0 JFzg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=2lY/aNwLINnKOMbDQO5jsCiPZIA7GFZi3ZqNd3+Td/k=; fh=s9Tqf1G94QMk93C5GHCkVnIjoGG3Rfd7082CngthoIQ=; b=PLtJomWhxRVnXN5GqV1Ew2Ru8BlnkPkeH1rPZhjPZ8unEP+UV0G0BTUZKzXk5xxSNv 8rtDqcviWOMbRlEPtzEWoU5rPz34s20rZSPesC976XxFitWIuTJI91bZ7fEU1JJ1QKp0 ATsPtFSiEeXGlz6bdAmSAEfeie8Dz6dN1fPSYUYhyizhu7EM/BJ49MiQyBuo3t2vYPg+ WFJIUZ6xIYFB+fQ3dn7ORo+Y4t6wfiYxCpxogHz+tDyLc0m2qh5Sqk64f+nwk/MHrJxD HoOKFK8P6lOazMbcmHZ+bJ4Bn2xByIdJqFoLYtBbYePZEpfeT522FBw5+SMNo0UpmzyE tnjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TnDdjM5c; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61361-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61361-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVOvGnWWkL1gVzIyuqTwWAkENrvSxQPxZyryxCv7L3OAe9jfilY8b5Z5lHA+pWOaiXA3WHmkhunDqMoYeXkhgujDib+mg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ck14-20020a056a02090e00b005cd8f461cf1si331060pgb.515.2024.02.12.06.29.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 06:29:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61361-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=TnDdjM5c; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61361-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61361-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 77EE02866AF for ; Mon, 12 Feb 2024 10:50:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B487F3D38D; Mon, 12 Feb 2024 10:45:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="TnDdjM5c" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 58CE53B194 for ; Mon, 12 Feb 2024 10:45:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734712; cv=none; b=q/1k8cDagAf8MVH23x2maNAc6Q5fKPqkYQgm6AUOAGc2AFm3RmmebNAw8qi0clP00sCnA8mc5LujnXN2l/8ZXdhpQn2d/9jcA+8coLFgoLgwi/9R4GGLsuRglie4lPAxlakdgnr6N1IvChubAdg8EJX08zV7tQMS+a2p0hFPejI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734712; c=relaxed/simple; bh=OpIDWzdlg0any9JAzqVnZ+xhu2rjxA6sBoybOHgswyk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JTFGPV078NCQERoWAGP4tbLz2D2kP86ClwdJIM/i8c4hD7EwxRLOaUshNYiXBdTK3ovWCB9PbhdW+iTTslL9+0oLjn6TQvY25WE+VID5zaKMryGN/GnaxF4UxHe5XXkk5zu2pF3PSLYq9wKFLcrGHriIQnW7Ehl2dW/w5d3/i58= 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=TnDdjM5c; arc=none smtp.client-ip=192.198.163.17 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=1707734708; x=1739270708; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OpIDWzdlg0any9JAzqVnZ+xhu2rjxA6sBoybOHgswyk=; b=TnDdjM5cOtJFiPhIHPhYkXzlPxYd2fX7AN95Ba/3yCMfK0EXDLd2d4EW nGKV7XFexLny+1qXkhoPCGxVMbuuEzQUWkNLBodkbvc5FpnaYPHXDsq7s pva4zfjHTaT0gu3FSxDiOLeBAxTs2Wciri1VgCy9V4H1pqRymV1l1Gqcw FQxurSyJFTsYYMH5YZZ+0WIxietrvzfx2+dcdchTw66POzaOByjWwip1l 25ntY010M6IO3LcMV4mozkDyvff9EgcE1cjJEdbIJGkEPeZ+CSIlsoK7r vLpvXVUy9H7PsTVLF9xtOzdD1ku64dCZ/Ouhe0yJzefKFq4ZCvX/cEMXa Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1585090" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1585090" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:45:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035605" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035605" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:45:00 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 70AD1639; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 10/16] x86/tdx: Convert shared memory back to private on kexec Date: Mon, 12 Feb 2024 12:44:42 +0200 Message-ID: <20240212104448.2589568-11-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790703744026066706 X-GMAIL-MSGID: 1790703744026066706 TDX guests allocate shared buffers to perform I/O. It is done by allocating pages normally from the buddy allocator and converting them to shared with set_memory_decrypted(). The second kernel has no idea what memory is converted this way. It only sees E820_TYPE_RAM. Accessing shared memory via private mapping is fatal. It leads to unrecoverable TD exit. On kexec walk direct mapping and convert all shared memory back to private. It makes all RAM private again and second kernel may use it normally. The conversion occurs in two steps: stopping new conversions and unsharing all memory. In the case of normal kexec, the stopping of conversions takes place while scheduling is still functioning. This allows for waiting until any ongoing conversions are finished. The second step is carried out when all CPUs except one are inactive and interrupts are disabled. This prevents any conflicts with code that may access shared memory. Signed-off-by: Kirill A. Shutemov Reviewed-by: Rick Edgecombe --- arch/x86/coco/tdx/tdx.c | 124 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 2 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index fd212c9bad89..bb77a927a831 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -6,8 +6,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -15,6 +17,7 @@ #include #include #include +#include /* MMIO direction */ #define EPT_READ 0 @@ -41,6 +44,9 @@ static atomic_long_t nr_shared; +static atomic_t conversions_in_progress; +static bool conversion_allowed = true; + static inline bool pte_decrypted(pte_t pte) { return cc_mkdec(pte_val(pte)) == pte_val(pte); @@ -726,6 +732,14 @@ static bool tdx_tlb_flush_required(bool private) static bool tdx_cache_flush_required(void) { + /* + * Avoid issuing CLFLUSH on set_memory_decrypted() if conversions + * stopped. Otherwise it can race with unshare_all_memory() and trigger + * implicit conversion to shared. + */ + if (!conversion_allowed) + return false; + /* * AMD SME/SEV can avoid cache flushing if HW enforces cache coherence. * TDX doesn't have such capability. @@ -809,12 +823,25 @@ static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc) static int tdx_enc_status_change_prepare(unsigned long vaddr, int numpages, bool enc) { + atomic_inc(&conversions_in_progress); + + /* + * Check after bumping conversions_in_progress to serialize + * against tdx_kexec_stop_conversion(). + */ + if (!conversion_allowed) { + atomic_dec(&conversions_in_progress); + return -EBUSY; + } + /* * Only handle shared->private conversion here. * See the comment in tdx_early_init(). */ - if (enc && !tdx_enc_status_changed(vaddr, numpages, enc)) + if (enc && !tdx_enc_status_changed(vaddr, numpages, enc)) { + atomic_dec(&conversions_in_progress); return -EIO; + } return 0; } @@ -826,17 +853,107 @@ static int tdx_enc_status_change_finish(unsigned long vaddr, int numpages, * Only handle private->shared conversion here. * See the comment in tdx_early_init(). */ - if (!enc && !tdx_enc_status_changed(vaddr, numpages, enc)) + if (!enc && !tdx_enc_status_changed(vaddr, numpages, enc)) { + atomic_dec(&conversions_in_progress); return -EIO; + } if (enc) atomic_long_sub(numpages, &nr_shared); else atomic_long_add(numpages, &nr_shared); + atomic_dec(&conversions_in_progress); + return 0; } +static void tdx_kexec_stop_conversion(bool crash) +{ + /* Stop new private<->shared conversions */ + conversion_allowed = false; + + /* + * Make sure conversion_allowed is cleared before checking + * conversions_in_progress. + */ + barrier(); + + /* + * Crash kernel reaches here with interrupts disabled: can't wait for + * conversions to finish. + * + * If race happened, just report and proceed. + */ + if (!crash) { + unsigned long timeout; + + /* + * Wait for in-flight conversions to complete. + * + * Do not wait more than 30 seconds. + */ + timeout = 30 * USEC_PER_SEC; + while (atomic_read(&conversions_in_progress) && timeout--) + udelay(1); + } + + if (atomic_read(&conversions_in_progress)) + pr_warn("Failed to finish shared<->private conversions\n"); +} + +static void tdx_kexec_unshare_mem(void) +{ + unsigned long addr, end; + long found = 0, shared; + + /* + * Walk direct mapping and convert all shared memory back to private, + */ + + addr = PAGE_OFFSET; + end = PAGE_OFFSET + get_max_mapped(); + + while (addr < end) { + unsigned long size; + unsigned int level; + pte_t *pte; + + pte = lookup_address(addr, &level); + size = page_level_size(level); + + if (pte && pte_decrypted(*pte)) { + int pages = size / PAGE_SIZE; + + /* + * Touching memory with shared bit set triggers implicit + * conversion to shared. + * + * Make sure nobody touches the shared range from + * now on. + */ + set_pte(pte, __pte(0)); + + if (!tdx_enc_status_changed(addr, pages, true)) { + pr_err("Failed to unshare range %#lx-%#lx\n", + addr, addr + size); + } + + found += pages; + } + + addr += size; + } + + __flush_tlb_all(); + + shared = atomic_long_read(&nr_shared); + if (shared != found) { + pr_err("shared page accounting is off\n"); + pr_err("nr_shared = %ld, nr_found = %ld\n", shared, found); + } +} + void __init tdx_early_init(void) { struct tdx_module_args args = { @@ -896,6 +1013,9 @@ void __init tdx_early_init(void) x86_platform.guest.enc_cache_flush_required = tdx_cache_flush_required; x86_platform.guest.enc_tlb_flush_required = tdx_tlb_flush_required; + x86_platform.guest.enc_kexec_stop_conversion = tdx_kexec_stop_conversion; + x86_platform.guest.enc_kexec_unshare_mem = tdx_kexec_unshare_mem; + /* * TDX intercepts the RDMSR to read the X2APIC ID in the parallel * bringup low level code. That raises #VE which cannot be handled From patchwork Mon Feb 12 10:44: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: 199862 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2471963dyd; Mon, 12 Feb 2024 06:46:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXURXrPlzND2yV0npr6+WZBfT+KT/2dzOQgrxAwx/Hx+eLTnBXSeKs5xLVcwaz2E/nguqPEwHRlbVVua9EYuJihdVsaaQ== X-Google-Smtp-Source: AGHT+IH+PaU9BlS41qDaSgvnq3vOb/T0ERT0m4j3qpBwyUhzCkoRsSACkSXGNDfVCXZEjfPVkaPZ X-Received: by 2002:a2e:a70a:0:b0:2d0:cf99:a553 with SMTP id s10-20020a2ea70a000000b002d0cf99a553mr4184258lje.36.1707749188749; Mon, 12 Feb 2024 06:46:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707749188; cv=pass; d=google.com; s=arc-20160816; b=WwgyQ7jKBpxBtu+ysQAqEq/Cig75yWOPon7DLjiG0giMcAjtFAM7ZcFqfNYfDXqGiO TkaDDRTamyzkZWPN3a5nfGkHyAbmNn4iajqPLvQOHqmKsbxBnVZf5WmS4br9KV9fouHh JGgSamtlC7EcMGg/ZI7XoCVNTONiD9Nl4B8YrCVjqgR6uRnxOJaJDDOQmA496a/rx8rC EiJ4iGwftdjBohkmc000JdtTad0gbx+nUTHyaGXKcFHU3YbIObkAttoae+8Y87Fav+hH +PrzYfDdrDgwqMHsUQe5GK+Lqb3U84ySM0NvvDhniTkHSLbAtgPpM8Fyvhx1TCoe6AX4 BL1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=PxBuA3tza228VpHxq/8kDNlnhjjwxZOy50g367z+tN0=; fh=GghSWHO7DZLH03YYyY3ejonZcbjIOkKJTpalz8/OcLM=; b=fNlY1/H4KHGVscQ9c0AKasMybllOjHInx9LwRT1PkrbxRkg/TPMeVOslXluHoqVrZW Lf8a3xZOkydPEZdIudDVUPF0ySsp091HlvOeXE6hNHoTJIJcmnF6bIeJZVrV1rC8oB1E hhxcQjXa8ourHoj1IXbVPdJeNF2wyY8UoO+7BWqvxLKKV7UrriIALIuGuPsCKySVNKWF ohOdqWtKwc2Rjsa01AjciMtue/lKwyvfF+ftrTpdJwINMJ4vFwkvPWTviGziQ0S2VTSt BVUULf3PQGjUTQUZ34B3DGHOyE4iUfGbpug3+iikfKFN70ih8VOX9NfnuT5wKwAzP1Uj zL5A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=C+I5uNVA; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61356-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61356-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCWls3yFw5Vxsw9XaYCEcoPnwKVHQA4ST1R+45cJdXTRd6PklhPTFUfMSmht1/tucaaZcGi1vUqwZF3cRMc3eSvDIwYzQw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s27-20020a508d1b000000b0056156ce6d9dsi2746684eds.105.2024.02.12.06.46.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 06:46:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61356-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=C+I5uNVA; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61356-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61356-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 6FE561F2536B for ; Mon, 12 Feb 2024 10:48:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18B733C464; Mon, 12 Feb 2024 10:45:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="C+I5uNVA" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 951123A8DD for ; Mon, 12 Feb 2024 10:45:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734708; cv=none; b=iaoK9FObhw/SB5DTCkGJSBkXR08unrfxqFrwI3f5dcqBEQlUGlCiwRIHS/t96uJMnGJ6O8U+zfw4pwwga3jc6y753hXp8y2jvI7CoRohE/yclYz+CpapYJboI62OG1b4oXAm9AHusq+8KdzUYU8qQXDCA7TZwaUryppj2noFWlE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734708; c=relaxed/simple; bh=9DcFlB+EMYNkp2N6OZv2c5TmDu3Stsj7JMO1CUBiP2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jNG0ncgijtuGLboizmfEsSyH0whWh9NPcGD8Bv4iSNK348GdGOwQhrUrQgBljRRqPb7y52xf5D7jGyVMyE2N/ecyLFyO87/rY8QhRtthNlnSVvKKsm5UWkNFXVN7Kj99d+OnEbikmVFj2MowlUnMjkNSbAAoL3jJaohYQ5iZevY= 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=C+I5uNVA; arc=none smtp.client-ip=192.198.163.17 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=1707734705; x=1739270705; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9DcFlB+EMYNkp2N6OZv2c5TmDu3Stsj7JMO1CUBiP2Q=; b=C+I5uNVAJMsC/ViIjKVgIRRGpTER8Oguy9rNsJzzXMWCTgPusyEojjfv 6unroMiSEBg5TcJjcKmNLek54uPjRcfCUJ71MWyiGSITFp4zfP2NRwHw0 y7BrbAeRkSudC8fbislLhbG6qmyE0DXie1J1FTadFo0uKXN5vzk5bjtc8 iDXgYVVuDmbLAmTO8H195U9CqeL6foR06umUB0w993kHx9bLgFpCZhE/y /IH47/fktMX+cmWgNTu4DgaZjuDBrIsE/DqAEujwb2YKqtDPs5SrMRVav bdZ7jeMZncywmFW3HCZL3aYB6ZlCmc0FlWHebZnH7p0Ry0JjC683Syu24 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1585079" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1585079" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:45:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035603" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035603" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:45:00 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 7D00E65E; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 11/16] x86/mm: Make e820_end_ram_pfn() cover E820_TYPE_ACPI ranges Date: Mon, 12 Feb 2024 12:44:43 +0200 Message-ID: <20240212104448.2589568-12-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790704813307829950 X-GMAIL-MSGID: 1790704813307829950 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 Mon Feb 12 10:44: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: 199847 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2460473dyd; Mon, 12 Feb 2024 06:26:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEEcxZQSmSpXv9yfFqZdyE1Zd6/MZ6MNT89Temnv4jgCElS3yBw6xfZe8GcdHXKq8Klf3pB X-Received: by 2002:a17:906:4919:b0:a3c:8300:f4e3 with SMTP id b25-20020a170906491900b00a3c8300f4e3mr2953710ejq.11.1707747978625; Mon, 12 Feb 2024 06:26:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707747978; cv=pass; d=google.com; s=arc-20160816; b=R2P94v3NOJw43QMDAr6lcEAmieKQT2g+cntEKcrO3nwbcyavY6qZvIMwnb+uSh49h1 0ekZQBDO4I5KCFioUTxQ1z6FFAqgxlF0YFXeGVFb/MwVr6+3LqvpC+QTePlmkSIy12vi szs4OdyJFNa5H1RlBi7zpdJVC1hkTKxFEzRpej46dNoMWI36B3uR9KNZwUf1Fw6iD9uA fM0qH4IkVf0YN+tTaVwNc5IszgKvxUGNmTXCIwTyfTQPCJAPWUKqyNII1rbZxT0q5oRg 5dnpCFXoHIf9eoNMbYuL/gmQCspNKelEuJr0wIy5O+zdCRkT+nV9Zolv820KXoqbecXq 55Cw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=fABvBnrgE/PLl1NAhjF5Rw+aQz9r1T2Knjys8UFYPbY=; fh=qah/dMzqd9u/7NyezSf6FBwhiFF2g1KeuVjpmksiXVM=; b=S6UkMvdErjmDowQe/1rfx1S4B0E3luaPrOG36qSjR+A2Jj16DhtqVodgfjuiWFO0tK a4TALOIFRmsBC5sVlpm6iM4h2TWiniPrE2/97t2tZzn+wYrSeHCCBhP9nFpCo9qo3rPF Elgpx/sPXukRHYOBOp2NAPLO4cywxBxWddJMBEWXF5YHISY3qS1z5ZPreCVKVRPd0con RzhlDt2x8mrDZYma2QYBl8K6fPKZJqbs3AvqG/TsPiDtJWbC6CYzzhOqEs7qEr7HEpYA eDifAaBTkfEZgAMuXlwGhzBmjpA+1ivCRR8MHoLG+CfZtS/OAhBWZTjtKn6PdrOs9XEx zQHQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DeN7SviZ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61359-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61359-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVUy0mZlpJB9Ot0TqAYeGcEcoTpnDCE4ylFQkxqZRPS1rUIDzluSrTH0npv4ZIIIC5r5jLJYbhzJUXeiBr21FIm1O4dpQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lf22-20020a170906ae5600b00a3c10f092dasi230366ejb.437.2024.02.12.06.26.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 06:26:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61359-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=DeN7SviZ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61359-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61359-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 8872C1F26491 for ; Mon, 12 Feb 2024 10:49:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 303093CF68; Mon, 12 Feb 2024 10:45:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DeN7SviZ" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 530FF3B7AC for ; Mon, 12 Feb 2024 10:45:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734711; cv=none; b=jgylgaFGJhnv7sSs0AreWsmG4MI0FqR8pLt9EhcOVbrdPBF75Tieng2TFXZiDz48pxv4RbkoFSYZag0wYl1cQmB/aO6dOYHwmtyntMixIrNImEKiiOj1+u89oWIWLZDZFHryHaOAzQeeLAn3qZIq0exd6ZHNKv8ZQBxYbgYzWgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734711; c=relaxed/simple; bh=Z3vEItFOpb/ayuVNTPFqaC8pjBMvLFGfG4ld+bFARLw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=abzYJ0bun/+E+AGzIc5NDZAVD5tMhrimDTW+zxwYAtCvSzitU1PAHAs69xMSlzXOVmTjKUxNwqmZKLXc8e9CQhp9wad4Yulhl2agwqEiwJ11orfVgodG+041GMfGp21Hdo+AYC6a4ggAP7lmgamYLB38FSgsAIGmJS9BC1mWGPI= 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=DeN7SviZ; arc=none smtp.client-ip=192.198.163.17 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=1707734709; x=1739270709; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Z3vEItFOpb/ayuVNTPFqaC8pjBMvLFGfG4ld+bFARLw=; b=DeN7SviZTPHjNGdXrj5nUEMz/AJGS19RyOJooTMo595qwycG8LL9Rjti ANBPLWJHrSRvzLGgqJeq7xvAFmtr3YR1CN3Wo5QNzMCdbau8GIrPKs90+ eCe7wkqaEhdN1E+r+UQgwzvURqpdm+sYN8IvQJQgGOOjGX2UfsD1SgPg6 yHvkYNNEHPzkUz2HfroPupmL0dP5PHtykDlA3Kx09I0AZUMUt3fKnjxFo TbIKfk+AO1EUPiNzJQqbsUzOJUq4MGriyyHXtz21ebP5DMdSiudLTfyJ/ fpM+cHGTDcDBWkSIdUCcsPHYQVa1CB2N1cjRyRXkJOxzk+0dOjb6B39Qy A==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1585100" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1585100" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:45:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035608" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035608" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:45:00 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 8994A682; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 12/16] x86/acpi: Rename fields in acpi_madt_multiproc_wakeup structure Date: Mon, 12 Feb 2024 12:44:44 +0200 Message-ID: <20240212104448.2589568-13-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790703544106825572 X-GMAIL-MSGID: 1790703544106825572 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 Mon Feb 12 10:44: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: 199760 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2421317dyd; Mon, 12 Feb 2024 05:20:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXiOsMHM46hEdwK+0SzjNeRGeOof3VuavT3Kv5oV9IB1UNcllmwbgc9NRnKomz94iMtNjY+VUAOOMclU/X2PlFE8vqL6w== X-Google-Smtp-Source: AGHT+IGjtCnCvulFb1rtR3neaztR8Er5Y3K99f7XJymhgskjSIzknGSF4L63Fbv9mGi+P/RBL4NE X-Received: by 2002:a05:620a:1922:b0:785:db35:937c with SMTP id bj34-20020a05620a192200b00785db35937cmr1732324qkb.37.1707744008888; Mon, 12 Feb 2024 05:20:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707744008; cv=pass; d=google.com; s=arc-20160816; b=QyEG4LIigqj83zjgKBxMsE050X8HJK/MH9CagFgzUCO3HES991XpY+DYZHlFrO2wAL chf+dpTAf7FI7BS527n5IJZxa23faXBicoS5h/bkDt2y8v5RJh0qawmt8/iVkx/UhjMd bHzRpb9G6a2l36vRcCg2Pi4jDr1xh2o23h26qpJKhEjD4oTYIb3TfiJJebKb9K88Q5FP R5xzL1H2VhywUvdkvKbWt21LUTYpW7PhkBwNpJ1YyJCE7o9Dw/tyy+6WmJvvRYXgBOlc VRYWf9GLuPAm/HqWI4ypL698I33f+buPyfR6DU8G5Z49gn+71utgGk856L+Uh3afkPaF LCSA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=A477xU0NMiPmaRKikOD+AP/rAovKr91FXfBuKHuWsyo=; fh=4aIL7d1VYdjXQjAnBo7Sm4oRnloVcTX8WLpY3Pe+FwQ=; b=EF5ZHv1g8L3Ljm5uWD5/7MoZf+uMVbmj4rmrwGLNVWzHUfdr0ccjFtFPt0fLL8M9Nl Hn8AhHSuxUWhun+D/M21X9p1cCDQQyZdEDqkxMVufMS5kCIhDAFXt4OYpqnFGZvatR5T suq0YCUqb07P2JwK90/38pFzoBLg9dajqKyGAYCvsf7IEl4hegce6feuUMTgcdTyf2GY Ymhm+8gZ9DKMpI6h5RtI0dV71iTVyGnu16GPAd3SAdRuJlEuxWk1rXGmkd4uRYqxCx62 IC7FWnPMOuQLBSDCMrDfs9S8WlUcA6pTFr4ni4PB+y0UZSuIV1yuHNAUgEtjdpNT6bPX hqaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dkturCqX; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61362-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61362-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCU1sAxqdfUUIgtH9xjPlsCKiAD6A/HHIgH4TYllp+hm7lWEoXKsFUUR2liWqOHPFktoRykterHoglkKeol03gz3D1hPKg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id bs15-20020a05620a470f00b00786d37e82casi549441qkb.137.2024.02.12.05.20.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 05:20:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61362-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=dkturCqX; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61362-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61362-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 907361C230B4 for ; Mon, 12 Feb 2024 10:50:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A7B833D556; Mon, 12 Feb 2024 10:45:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dkturCqX" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 F03E73C08F for ; Mon, 12 Feb 2024 10:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734714; cv=none; b=Um79aEayQnEzKPuW1jyQ581FFVPva25/ZFTNSk/1eWb2eMpEgnnUAst6HV2iQ4MRyLB/heRxmoL4l7ApnN7ae6K4OHndmZdoRkC1Y8jx1k5sCRxIa9g2L0SOcn3qtXaKek6wNQHZFbZIfUVFsp1lOnxkdhfZlxWYo0zWkyquTWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734714; c=relaxed/simple; bh=dL+ZDyNfeHUiVdGS89eu26OHL8+JI0276K2FgncM1Wo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IVWaT8fNRY2o4PaN9xpBCwb4YYOX+IgLGWe878QxQi4jlqLBnjsvBNkqoEerZ5i42Ung626AZ2xOR5oMxb8Afa1ANQxzdUGiEYpsV53zb3sXuj8virlDXMJyMCdLAIeEi5gWnzk0/VOO4JlOrI5nuad85DyrZG6fTyRFVovORnI= 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=dkturCqX; arc=none smtp.client-ip=192.198.163.17 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=1707734711; x=1739270711; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dL+ZDyNfeHUiVdGS89eu26OHL8+JI0276K2FgncM1Wo=; b=dkturCqXD0O5oGshIpP7YNUl63o2G9HxmfdfohASIqKEP0wZwcMeZbUo Z1XtUcuCo4wSu+9WSZh01sPmN7gyvXInVmYKMDbA0rdcHGfVkLF20mNKH AEnKH0K7Jb56EPXOcKxAFfl54jtJfTu4ip5zDQRdB9bQWageBs2U/HRQK +Fl/Ug1ArRYVs9QDsGRaMNsZxILwkiXFxKV9J8B5cfsxWCYgJ2x2cI0j4 3GCsD0p5+yf55HX4GxP/dochwx+EqU53BWeT1wEbBX4tcBlNSVh3iM5C1 6vCwwMjoSq2BuDgdKzkRwq8ISYRViFSzkH921/CpbvQRqtPShS05OJXJ0 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1585118" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1585118" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:45:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035611" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035611" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:45:00 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 9629B693; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 13/16] x86/acpi: Do not attempt to bring up secondary CPUs in kexec case Date: Mon, 12 Feb 2024 12:44:45 +0200 Message-ID: <20240212104448.2589568-14-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790699382069829232 X-GMAIL-MSGID: 1790699382069829232 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 Mon Feb 12 10:44: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: 199793 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2432343dyd; Mon, 12 Feb 2024 05:40:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVY4tA9E/WLULzMsBvqVGxdoa9nRRHOLLAoF46/dxUm7gq4vQ/vEoHyJXmNRvklHpq9XrmqdUa9jBjfzegcYJTUIcs/Nw== X-Google-Smtp-Source: AGHT+IE32DWLiVIqWNZtuAmbhfsTm5zoyGK7YmDJ7yq5RMKZSgv+Sp6PLPFIup/9ONVOCwcHKV7b X-Received: by 2002:ae9:e517:0:b0:786:c1d1:ba6a with SMTP id w23-20020ae9e517000000b00786c1d1ba6amr655434qkf.25.1707745211567; Mon, 12 Feb 2024 05:40:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707745211; cv=pass; d=google.com; s=arc-20160816; b=Mug+1xfE3xgWqwaP26JPj3399pYuR/th0nJ7GEV6VEHG5Hok4kj4FX8bLyWuErrUED kf+cI7neM4HcK4OA0RuR2na9+I3alO1S0rPp6laa3vA/K0OGiRVyKwQ2fna8ik2OmzkB UWrUxgsR7LoQXXTkWyhL7B5/etRChYiTXC2JYPKA+UMHuo4kEa/RRTrP6uh3vla8M/uk B7oRW6EyCP5PQcLJdqKkR7gLDYYlzlkcdr7Gao0YMI8L++ZKZXo9Spj6NGFHkm7wC5q2 vOg71mfSidLkrKgcPKM1zItC84CYJhwD5Fti5OCd7bXLuKvn9k5Lfp0uieqL7VdLqBue mmTA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=OhSe+Z01wtsNPO2DlJRg/XljcMsm9Jtupl3TZ04Lwgk=; fh=nOUXiq+nuaGXdtxFa8Q7eYVCH+mfoPHgtaIlIFRh5jw=; b=UK9BnmXT9IROrcGzZikvQFg6jHKbzU4V5Bh+WV5LC86wSHuVsKXMmkFG31zssE7Mq6 f9p/VybqR8GBwIAxAxgUtxUfEgngbXEPSivP/jn1Erf7xlmaHhb84jPXZZSCkyOnjDsg LNs5DJLhmnEeK06EXC0XfuIkH9VB+yREhpGqT8LMy489GzrlB5t7PD2TpI8oRqwS2hfQ 7tUCjgs+NOCsVS9/3e9FR3qGHhOS7+qK1eUDFrtfpQSG/ROJEpVRxcDQD4F+mA//GeNE ps4s2ncLlb7j9krKNTjls9OBK5PEYBvzrnGj5aKJGSzlC1CCxoi92wegeFZYcHQD5Y04 JLTg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YYYCuHzB; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61363-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61363-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCUnKuOIRgTv5auC0r+fU1EklUQCBHqK3KOHyYD1q22n0wrMBMUbWdRMUW4TdycUjtYyIH1ko0bJ1OcwQ6xao+jFrfOu7Q== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x19-20020a05620a449300b0078553a07226si6432776qkp.570.2024.02.12.05.40.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 05:40:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61363-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=YYYCuHzB; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61363-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61363-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 4C89A1C230C2 for ; Mon, 12 Feb 2024 10:50:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94B3F3D54D; Mon, 12 Feb 2024 10:45:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YYYCuHzB" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 B903C3C488 for ; Mon, 12 Feb 2024 10:45:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734714; cv=none; b=U0y5rLr0HmRqcBhHi+wzz3LK6lpvw1wsCVVeG7UUgQwynKRQOpLFSuc6sqrG84BoBXD65xfsgjo5nZQsyEn9EIAmjplgyuZSpdEbYvlZysAniDRstvaSxRUoHTVfS5Mk29EJObz/RoFxWzAsAZAe+7FFFDlip09rXz+iSgV+8JE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734714; c=relaxed/simple; bh=urUcJtKDz0udsDAvAz2j1S+q/fX/vhzTd+7x3OIZGzI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HgV1Rh5atDl8gxuy2+VfZ2sliTgevmVKnf/9gDDX9L7mqrSc35rI7F7NzlhbDqfjHcr6b1/Bv/F/SH+3PaDUjlyvyok4zT9gIyviOKIKFsH+dDYNnw3a30/MVrh8cwYGERgmyajSNHl4MciYc4LwawL2Nlp/fm/znJUKL+FuPN0= 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=YYYCuHzB; arc=none smtp.client-ip=192.198.163.17 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=1707734712; x=1739270712; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=urUcJtKDz0udsDAvAz2j1S+q/fX/vhzTd+7x3OIZGzI=; b=YYYCuHzBS8toj7MqQIOJJzhMjBKHROIraddvg2fYI8QyVMxdFpr88ahZ EAKs+cC65yzdmSvlPjYaWM0DRC8AOIpJoZu/+xERR6A8Sizydqw3q/tCl skHdPmfCwGgLg+QCpIGpHzRKEESvvRrlVPbP8K5YjcwE2GQUQpsFRIsU7 XKqRASmQsyj6fwAr89Ig9LVW3uko8OLhlE9wwY1v6EIaj2t1BExP1oUbn eQO/70jax5LGwgIyVvI5nme7EqzvZUGlc7tOml7vm+H52A5b+Ka98RMOD zbKVX0ooikBCZJIqr2HI5TNr1UQQ0dZ1WCo6VxBdDuUnp+PQ5cVhJObNs w==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1585110" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1585110" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:45:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035612" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035612" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:45:00 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id A2F9B6B1; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 14/16] x86/smp: Add smp_ops.stop_this_cpu() callback Date: Mon, 12 Feb 2024 12:44:46 +0200 Message-ID: <20240212104448.2589568-15-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790700643130963274 X-GMAIL-MSGID: 1790700643130963274 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 Mon Feb 12 10:44: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: 199751 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2419487dyd; Mon, 12 Feb 2024 05:17:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKqq/95H48N5NHfDTvw8p4qIsciRC70193O2ZFfK+qeagaVa1MsTst8NCJgq7WrUW0tN0c X-Received: by 2002:a2e:95d3:0:b0:2d0:b285:ffc4 with SMTP id y19-20020a2e95d3000000b002d0b285ffc4mr4058318ljh.35.1707743826538; Mon, 12 Feb 2024 05:17:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707743826; cv=pass; d=google.com; s=arc-20160816; b=0o2ubsmPmaVp/d7SXlUlbAKetQb8ZjBFnLXZdEJJ5+2HM3KrOVWekM6xsUCGxhmCRf uQmU1XEekY81+L0MEURYznZOfruhw6/sO7I9CaXXNmX/BvPssOhFuTr+/OCKGm2eUtYj ScOXpl0MamRmqqJr/Tdt1Us1hJA7BT02xHHcCwiyK8ZaDz9U2sjCdPzLSPT9+xH0boM1 7qRXKjzoGFQ7VvLuMo154fYADS+yvB1V6QgfK8rrP6wNOE9MwjSmJad+kIVKUXljP6Tw p6Cw2jj3ZChElF9lz2R6NMmBglEiTr9M3B7FE3IeXoY/yKKlPHsMCrhAXkFK1v/GIu1F ++bg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tC0l902aAQNJZysp4ke9uf0VMLVFZv1kHnyDv7d3b6M=; fh=OCR/FsxB0ODprGp1qEVM6Pi2q1RU81sRoOuJ/okZgpQ=; b=e7DEV3R0ryKxIsk2xEP4yoMxtaRsKGqQvxYhp/J/DFCgk/92plitQrnG/SzSXl1Kx5 sHDBiSpD49F/H6QzA/u3UqEBJkbFX+iTjIYw/sCthtRohEcKLhVQ3NnRM7kRArJRbOkq xbDXwdKKotGlapTnh6L1WMrEI0h2XtV68Bf0ROROiBoiwWSeXsOMfg5s234/pEmCH3Jl akBHrLSNQqEO0ftF5bRUWsSv55N7XhN7eVTxEvHGwjYHCTaSp+KOnIBEyMgzqKKhLN5K s+35etF4sKTY/uTad4/BFMTI3GMyB7GS3d9EI2IjOgSzRIFlXpgVkwv1WUGrIYGYorX7 ERdA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=grjaH0Ry; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61365-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61365-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCW701eXCC5T8vDgFiCNmWwqrA1jLbrSL3jKQgf3PL1Isxy2/TOmD6NyxAj3qYfTT5eUnk+NANvUhXLA6X+UYk8nIqG0yw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s10-20020a056402164a00b00560ae7e5939si2690590edx.366.2024.02.12.05.17.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 05:17:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61365-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=grjaH0Ry; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61365-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61365-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 2034D1F26F99 for ; Mon, 12 Feb 2024 10:50:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A19DE3D974; Mon, 12 Feb 2024 10:45:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="grjaH0Ry" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 7D9D33CF43 for ; Mon, 12 Feb 2024 10:45:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734716; cv=none; b=ecwVaIbnhAYsWACKIdsZgVsVAcWXX3FigEebe/GWJrmxMPAOM/2RzqXpcac0nrfpZxpoaXauZ7a5OLnMeU+LgYdO0UzdcgNwRYlwbelz1us1zpM9eXd9tx0atVCvQtu7V2I0L4fS0RUgDV0tBQQ7OrK4r7uwS4ilhWCqcUE9KLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734716; c=relaxed/simple; bh=9HS0zSPwIGWp/4cXpPzLT+C1ZEn2tRFHFH5LFIKn6KI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fhnp1QJq9DP2D/sTmdG8MwLHd6Chh+eMLdWKLcCvR8dQRcka4HrwhH9cC/RKI3ib4Z+n5qaeu78+oO3ImxliIJdtKdlyUjNgqrxPy1I/hgNxaOAoW0sI7YkCA9ifcEpAcJ681fw2U7DbjdGCiHfazzMa5lixlu23IGftgQH3RYQ= 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=grjaH0Ry; arc=none smtp.client-ip=192.198.163.17 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=1707734713; x=1739270713; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9HS0zSPwIGWp/4cXpPzLT+C1ZEn2tRFHFH5LFIKn6KI=; b=grjaH0RyD7ofMArPvT39KByUMkhZPdmscywKGcJC3qYpOnVC6KOFWiyf 1WjAQP7c0VEtx5KJeLq9Ugd7Rd19/Ed1Qc0XeQcf/0vScdjrtA97S9lh+ zIWAbtP86bN6dhGxz7tRzaA9Rx/5WPYexHMKNOql5jlVYWoeJqtWbN31e RxaKnRx43HcASyB13YpnEGBCypCWt0n2rvcwajoUkACSsJxrtQd5teRVz sE5Gr61gaiod+c2TsguvJKj1ObE08TdWvvOnkeZdKz3M6Uz13naXGSBCa /S+bcv2g0Ukzmm89dbdqKrq+YTyH2xWoqES5F5yebei/pqdmN04E9nOep Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1585158" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1585158" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:45:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035657" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035657" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:45:05 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id AF2DD782; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 15/16] x86/mm: Introduce kernel_ident_mapping_free() Date: Mon, 12 Feb 2024 12:44:47 +0200 Message-ID: <20240212104448.2589568-16-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790699190601698964 X-GMAIL-MSGID: 1790699190601698964 The helper complements kernel_ident_mapping_init(): it frees the identity mapping that was previously allocated. It will be used in the error path to free a partially allocated mapping or if the mapping is no longer needed. The caller provides a struct x86_mapping_info with the free_pgd_page() callback hooked up and the pgd_t to free. Signed-off-by: Kirill A. Shutemov Acked-by: Kai Huang --- arch/x86/include/asm/init.h | 3 ++ arch/x86/mm/ident_map.c | 73 +++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/arch/x86/include/asm/init.h b/arch/x86/include/asm/init.h index cc9ccf61b6bd..14d72727d7ee 100644 --- a/arch/x86/include/asm/init.h +++ b/arch/x86/include/asm/init.h @@ -6,6 +6,7 @@ struct x86_mapping_info { void *(*alloc_pgt_page)(void *); /* allocate buf for page table */ + void (*free_pgt_page)(void *, void *); /* free buf for page table */ void *context; /* context for alloc_pgt_page */ unsigned long page_flag; /* page flag for PMD or PUD entry */ unsigned long offset; /* ident mapping offset */ @@ -16,4 +17,6 @@ struct x86_mapping_info { int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page, unsigned long pstart, unsigned long pend); +void kernel_ident_mapping_free(struct x86_mapping_info *info, pgd_t *pgd); + #endif /* _ASM_X86_INIT_H */ diff --git a/arch/x86/mm/ident_map.c b/arch/x86/mm/ident_map.c index 968d7005f4a7..3996af7b4abf 100644 --- a/arch/x86/mm/ident_map.c +++ b/arch/x86/mm/ident_map.c @@ -4,6 +4,79 @@ * included by both the compressed kernel and the regular kernel. */ +static void free_pte(struct x86_mapping_info *info, pmd_t *pmd) +{ + pte_t *pte = pte_offset_kernel(pmd, 0); + + info->free_pgt_page(pte, info->context); +} + +static void free_pmd(struct x86_mapping_info *info, pud_t *pud) +{ + pmd_t *pmd = pmd_offset(pud, 0); + int i; + + for (i = 0; i < PTRS_PER_PMD; i++) { + if (!pmd_present(pmd[i])) + continue; + + if (pmd_leaf(pmd[i])) + continue; + + free_pte(info, &pmd[i]); + } + + info->free_pgt_page(pmd, info->context); +} + +static void free_pud(struct x86_mapping_info *info, p4d_t *p4d) +{ + pud_t *pud = pud_offset(p4d, 0); + int i; + + for (i = 0; i < PTRS_PER_PUD; i++) { + if (!pud_present(pud[i])) + continue; + + if (pud_leaf(pud[i])) + continue; + + free_pmd(info, &pud[i]); + } + + info->free_pgt_page(pud, info->context); +} + +static void free_p4d(struct x86_mapping_info *info, pgd_t *pgd) +{ + p4d_t *p4d = p4d_offset(pgd, 0); + int i; + + for (i = 0; i < PTRS_PER_P4D; i++) { + if (!p4d_present(p4d[i])) + continue; + + free_pud(info, &p4d[i]); + } + + if (pgtable_l5_enabled()) + info->free_pgt_page(pgd, info->context); +} + +void kernel_ident_mapping_free(struct x86_mapping_info *info, pgd_t *pgd) +{ + int i; + + for (i = 0; i < PTRS_PER_PGD; i++) { + if (!pgd_present(pgd[i])) + continue; + + free_p4d(info, &pgd[i]); + } + + info->free_pgt_page(pgd, info->context); +} + static void ident_pmd_init(struct x86_mapping_info *info, pmd_t *pmd_page, unsigned long addr, unsigned long end) { From patchwork Mon Feb 12 10:44: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: 199750 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2419373dyd; Mon, 12 Feb 2024 05:16:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUXnGLVIOh7sdgZDC+6hhSJMCameePw6/WTSAJj9GC6l43+SW8Bg3EdPV4J+hgIim9iSR1qrxqW0MntqJbQ/hS6JOdcsg== X-Google-Smtp-Source: AGHT+IHiTduN+DQFyPp2Ymad+VVkt5AE5wUlpmnxyie2iL53SPuveE4cxUM49KMW2g4831XeDHqD X-Received: by 2002:aa7:c1d4:0:b0:55f:e4b3:4b73 with SMTP id d20-20020aa7c1d4000000b0055fe4b34b73mr4879362edp.39.1707743813405; Mon, 12 Feb 2024 05:16:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707743813; cv=pass; d=google.com; s=arc-20160816; b=DvQI+WnBDjppzAN2kqdp1fjIoa910tIou6pf4pkDSiGjTG407BLDlyTFbyJTkt0DsF COa3sizGSv2IDASruEKt2Tw3SovQBJknVhbxj/CeY/fSvhbAnAWgEdw3c+9eJCB/Ih/k vLz/t/qN4xlF0E6mAlrq7aKrrstltXf86rZ6yiEe+kzUfwUjXrgt601fYEC2kYeOQcVy SlemYbVeybN1w3GVz46V2c/Cv55fsbE6QfOtpYzA/jF9MuKGZL0Nd17cPqVdUXxlEGBa Zw28vvY7chUbW13A6q0ARkkE7oGBBeBu9YoB34jQ/SoG+q3EQN6/dgZXTC2XXdKcr24c t7Zg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Bx1V1g15xQfOm+SjjiqcwzJKqUfqswL3nB5AP3sSgB4=; fh=ZFgWukk0eBgeG7SBFMYUiS4ytrUr/FZ1c6EPkY+otRM=; b=MM7uD3jQ8n4RNM2wi7xKIUdcTKShjJ1sJh5r/M98xULGcwrjYWdU0ekp6cOAajmrOp 6xotyKxMXAHZaY29S85jh5qSUFOrv9iMX1lSzlhzbzmmNMP8KNgeirUikdG5mijhmVp9 WJ6J7gCPeijMWOi0zYXRmeGBqpTGycQQVIwiEyp/CjDRSg5NefoRG99/kHDQb5YpZ2Pj tN+J/Rr70eYj/YX0vk0Ok+gbnckUkPQam821L/pQ+xoySLaG8eda1jO6kLYl4317gYvL L/gW3uGoZpZXZJlWkMOgQizsJg2QjFgw8JyiX5Zrz45vBtHI02nOLVaX+z7MG16zNTyr XFvw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gVq33LnZ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61366-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61366-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVtGpNVjuwp0IODjYJkKkPvYwRmbssqU2kO8RLs/InhIkbZj69jpO1bVQ1sWLn5nyZpuJxqiLG4S1EHtXi3cyfWzQ74xw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id n1-20020a056402514100b0055a61376aeesi2650687edd.240.2024.02.12.05.16.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 05:16:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61366-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=gVq33LnZ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61366-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61366-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 71BD71F270AD for ; Mon, 12 Feb 2024 10:50:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 22C433D969; Mon, 12 Feb 2024 10:45:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gVq33LnZ" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 74D603CF41 for ; Mon, 12 Feb 2024 10:45:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734716; cv=none; b=CYjEcdse/0QxpbcdxjXUniOgEbolcO1W01T3zQzTBFmtOleh4PfluFN0x6fJmYDGjSxcQo/QqXghypESkxDDXLIB9pHqi3qdNHXtgP2wifhXEubkFxuSnurTic3nY1yUFJVOM6l84UPiaFFVtDWl6rLqknGFEHbaSlhxU2cDJ0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734716; c=relaxed/simple; bh=5rPhka26cuxx92EnGqjwsdfPdCSUmQ6iGaqaueVO7cw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IBde7cm4IVz4LRuiSZbm9gAr1496mYrZstPKMmitF6EK5mttwwaU4l+BQOZpXLRsIH6u93Cd2DDvItiEiP2pkCS59Z+60gkOwszUQokh3b4hwdMEX3Z+a2TqicAJLnT3TDOyz0BqrWvAv8RLnH62dMUYvRz1HvVgfsMO5pwZz9A= 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=gVq33LnZ; arc=none smtp.client-ip=192.198.163.17 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=1707734713; x=1739270713; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5rPhka26cuxx92EnGqjwsdfPdCSUmQ6iGaqaueVO7cw=; b=gVq33LnZhtozks4d2YdiySzgVvTCGRP54pmBSdxx9/c5auLz44bPqKHg ANZgerEVm0yngMlxoc/SYWzOv3xt02KAs3/vftH0WmqjT1kbL2ruUcd8+ dCp4tEMq0hKROvPO4rYHIgBgu6P8z8nu7IPEVL+EjEsRiykT53qTkS062 YjPxTH8s5ULk305kxArIP0BaWUsHz+F8n//dNZebVk/LU3gm4sdqwFkys bYczbV6248tTNctA7PPfHxGp1Cn276dwq3RnCKN94ufoI+szLnbg3Fkmr +X6KUyc76/5P3d7U0DUvoCuy4J9o5IbHLbcqWsxXY6ljl6EXJ/KAKzemb g==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1585149" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1585149" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:45:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035659" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035659" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:45:05 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id BC18B7F0; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 16/16] x86/acpi: Add support for CPU offlining for ACPI MADT wakeup method Date: Mon, 12 Feb 2024 12:44:48 +0200 Message-ID: <20240212104448.2589568-17-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790699177111184283 X-GMAIL-MSGID: 1790699177111184283 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) */