From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 D3FB717C65D for ; Mon, 25 Mar 2024 10:40:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363217; cv=none; b=Kh9PeIc7JaAVNwQ4Tep9PeqNjEdIiiyA6HzTT2Vs6IC+RxJuNAivTNaNWtnTzvAR1ZkkBPgK/gxHfUCqYmVJ1bJORtDs9MCS2MTdYwTiTLentmf3EwrLkniM3SdKAx0e2A6WulPKhY28IMxEZ2kcrPj/Q8EnBaq82qPjbBSr82k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363217; c=relaxed/simple; bh=XS9v6r6Jk+adSeAZY8Tb4Fo3ux2hFJKW1rTu361pNC8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NelIwbEBZ8tQWQbQ+grhTKAMB+csgi6+8LKlRULoddc5/KTUbYsCXIyu/2GFA/wL126ZwYQqwm742WtVRHStBFAs+DDhB6bRhdhOneyApUy/o1gCatGZ8iQXjLvNVNgHtAHgIsprrn+3zT1VPUgZpD4Wx17zEi7o6lb518gTOcU= 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=NqDaan+C; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="NqDaan+C" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363216; x=1742899216; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XS9v6r6Jk+adSeAZY8Tb4Fo3ux2hFJKW1rTu361pNC8=; b=NqDaan+C8Vf+m28OTYtFPXUf4zJQq3avz/LURFMevZ2QI0vBYQFMXpCE tRbeCz+rFxuEBbeUQXzxIkNXufV75wrWfEGc+hUD4O1Ea5lQAtbCeg0in Am4J7UvWTzWbNoEQYoAUMbmkfFBqk6b7PjVZgnRj7ssRyHBdatClrhI9Y ujHg4X9wAQ0IpPyURGt+BlPJc4cO8F1QrrkoW4p9/FaMtHSr66MKCs9oh vEZ/7g3vG3/wZdtq20vWMnbBJ2MtsvFCP5XW4PVGdtpoClecguocuH0ee 87q5d2ryd3IUuD4PXp79WR3WARptkEln8KZrtGHoLl3nKWOA8GxASAghc Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561330" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561330" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070135" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070135" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:05 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id D6C98E7; Mon, 25 Mar 2024 12:40:04 +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: [PATCHv9 01/17] x86/acpi: Extract ACPI MADT wakeup code into a separate file Date: Mon, 25 Mar 2024 12:38:55 +0200 Message-ID: <20240325103911.2651793-2-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In order to prepare for the expansion of support for the ACPI MADT wakeup method, move the relevant code into a separate file. Introduce a new configuration option to clearly indicate dependencies without the use of ifdefs. There have been no functional changes. Signed-off-by: Kirill A. Shutemov Reviewed-by: Kuppuswamy Sathyanarayanan Acked-by: Kai Huang Reviewed-by: Baoquan He Reviewed-by: Thomas Gleixner --- arch/x86/Kconfig | 7 +++ arch/x86/include/asm/acpi.h | 5 ++ arch/x86/kernel/acpi/Makefile | 11 ++-- arch/x86/kernel/acpi/boot.c | 86 +----------------------------- arch/x86/kernel/acpi/madt_wakeup.c | 82 ++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 90 deletions(-) create mode 100644 arch/x86/kernel/acpi/madt_wakeup.c diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 03483b23a009..0f5fd815bca3 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1119,6 +1119,13 @@ config X86_LOCAL_APIC depends on X86_64 || SMP || X86_32_NON_STANDARD || X86_UP_APIC || PCI_MSI select IRQ_DOMAIN_HIERARCHY =20 +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) =20 #define acpi_skip_set_wakeup_address acpi_skip_set_wakeup_address =20 +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 =20 -obj-$(CONFIG_ACPI) +=3D boot.o -obj-$(CONFIG_ACPI_SLEEP) +=3D sleep.o wakeup_$(BITS).o -obj-$(CONFIG_ACPI_APEI) +=3D apei.o -obj-$(CONFIG_ACPI_CPPC_LIB) +=3D cppc.o +obj-$(CONFIG_ACPI) +=3D boot.o +obj-$(CONFIG_ACPI_SLEEP) +=3D sleep.o wakeup_$(BITS).o +obj-$(CONFIG_ACPI_APEI) +=3D apei.o +obj-$(CONFIG_ACPI_CPPC_LIB) +=3D cppc.o +obj-$(CONFIG_X86_ACPI_MADT_WAKEUP) +=3D madt_wakeup.o =20 ifneq ($(CONFIG_ACPI_PROCESSOR),) -obj-y +=3D cstate.o +obj-y +=3D cstate.o endif =20 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c index 4bf82dbd2a6b..53b8802e01e7 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 =20 -#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 @@ -341,60 +334,6 @@ acpi_parse_lapic_nmi(union acpi_subtable_headers * hea= der, const unsigned long e =20 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 =3D 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 =3D apicid; - acpi_mp_wake_mailbox->wakeup_vector =3D 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 */ =20 #ifdef CONFIG_X86_IO_APIC @@ -1124,29 +1063,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 =3D (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 =3D 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 */ =20 #ifdef CONFIG_X86_IO_APIC @@ -1343,7 +1259,7 @@ static void __init acpi_process_madt(void) smp_found_config =3D 1; } =20 -#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 =3D 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 =3D apicid; + acpi_mp_wake_mailbox->wakeup_vector =3D 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 =3D (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 =3D mp_wake->base_address; + + apic_update_callback(wakeup_secondary_cpu_64, acpi_wakeup_cpu); + + return 0; +} --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 7C208149C6F for ; Mon, 25 Mar 2024 10:40:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363215; cv=none; b=UNF4zM5XAMhUQt4+cOADPHDAEr/xpJlyo7cRYpAoahgIAn0I7wi7wl5XX64JLOzUCVF2pDgwW3U8d4j/30aeiPrp9degTsEbnnAzHwnUtIlXXSG6OtJGbYgVhZmwjnGd+G5+IXIhifZZY6wwXy2fJg8wqyOZzDli606atXWdY4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363215; c=relaxed/simple; bh=xIprGuZ+wzLEKGSqnVchQykT8aBwBOBoQqpTJEhq/2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=in4kB2sZIV4M/5T/rdUj1p/IyGDgzpnFRHcfP3HqcDzDMyQQbRfjKkZMK14Dk0mdMEg5LB4/CGTZpizLj23VVfzc0uHGKRkxS/tiZ8Bmk5V+SOEv7AujF9DQ1oiJSRuOYyQ2Hx6oB5ZNdMjFsKn8hCHw4r8WKTiLtqjuHDtAWM8= 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=P46c9+cO; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="P46c9+cO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363213; x=1742899213; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xIprGuZ+wzLEKGSqnVchQykT8aBwBOBoQqpTJEhq/2g=; b=P46c9+cO1eZjFfSbibMw5G5ugNBgBojeQXWI7WWkKP2UMMxDjNSmJXpr U6x3GPGB/TflXDFfQavTjw8hmu7NcqreXHAkPhNRr48qSNOKgaj6TyXNt YuAHeptOtRd/uT+FCPNZlKpRRB2NUupE1JlA4JljGgFB9q/0s8HRdrAVQ 06oZ9zC9NIE8+zkTJZzFM7Bo7QF0YLpsDvYi/RWAUZDRGjo1j2Jw587fS mUFhIK8kCcG3a10ZIMNzSxqud5eXV37L2ThHUTT43/DVqdLQ8Knk+Wp2m QSYdufmICa2Lw0FTgO/ST6U19/RR3jEo2TGGd2rhzr7PY6/EClJ+HvJym w==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561310" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561310" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070131" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070131" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:05 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id E21EB3C5; Mon, 25 Mar 2024 12:40:04 +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: [PATCHv9 02/17] x86/apic: Mark acpi_mp_wake_* variables as __ro_after_init Date: Mon, 25 Mar 2024 12:38:56 +0200 Message-ID: <20240325103911.2651793-3-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =20 /* 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; =20 /* 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 __r= o_after_init; =20 static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip) { --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 CCF2A14A4C6 for ; Mon, 25 Mar 2024 10:40:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363217; cv=none; b=bnkcjs2PE8xPZTObAnTpc2lMzyV6sNUPeldY4V/00S6fDe4bukuVdgbzvABAht8XICT2OybTURp5hOqg3t8H/r7AyL8Oj8T6Idjk/As09IWlUJeGm0pQZRXO9nMSPWRXLDS1moff/a53HKVShV1enDmDav/Y91z7oDahUhOj29U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363217; c=relaxed/simple; bh=8vFnr3Q3IphY3txxegY5cysnm69dmjkFAnV1L+0G+mg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=szwQNwkQcGHi97pifSA1K+2+sl1Wnl7PylNUduLlN4skXLUuW+9KQKDcowWK/AcZ91Z0BlQDVaC2HYwRLP9nb5344RRRV1fbkIa9s3XhQ/1rvBafMchiS4wbstfpLXG5Eua98fsoasNxPQ0WW7IDnh39Ht9pk8j4qLdxsmGmAVE= 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=j09jTwUY; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="j09jTwUY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363216; x=1742899216; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8vFnr3Q3IphY3txxegY5cysnm69dmjkFAnV1L+0G+mg=; b=j09jTwUY9vzDUvQuGKpRFHzd0q1k9R/BLHqsOFjWOW0dbBAK3Fgq1BMe 0/hjsNqpFtvCXQ4IM097NtOS75KcS4JyXeN7L1U5Pyw2gjcxFHOcI2DpS CN5XvE4BmiYDRBSc0xqKS4/oQO6ixVrJyFYKX9/Tz3D9OjJxQ0L3edzTT gWM+qNTH2glFFBbErlcAUbWtWcokJxmEl29v13CoWNAjIfJfECYMF5QY3 k+b8vJBQ+4jL+BRDCQolyPYBWvOlILJxuU5Iskx3wdW23Y3S2Jowqe82R NozLJBNDQSMoXh1o5ASeetP2TjbyFKjgc3f40N5+Rh2pC6isXSdmOFTIq Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561320" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561320" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070133" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070133" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:05 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id EF22C484; Mon, 25 Mar 2024 12:40:04 +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: [PATCHv9 03/17] cpu/hotplug: Add support for declaring CPU offlining not supported Date: Mon, 25 Mar 2024 12:38:57 +0200 Message-ID: <20240325103911.2651793-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 ae5a20cf2f9c..2dd47d203d36 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -141,6 +141,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); @@ -156,6 +157,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 8f6affd051f7..08860baa6ce0 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -483,6 +483,8 @@ static int cpu_hotplug_disabled; =20 DEFINE_STATIC_PERCPU_RWSEM(cpu_hotplug_lock); =20 +static bool cpu_hotplug_offline_disabled __ro_after_init; + void cpus_read_lock(void) { percpu_down_read(&cpu_hotplug_lock); @@ -542,6 +544,14 @@ static void lockdep_release_cpus_lock(void) rwsem_release(&cpu_hotplug_lock.dep_map, _THIS_IP_); } =20 +/* Declare CPU offlining not supported */ +void cpu_hotplug_disable_offlining(void) +{ + cpu_maps_update_begin(); + cpu_hotplug_offline_disabled =3D 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' prot= ects @@ -1518,7 +1528,8 @@ static int cpu_down_maps_locked(unsigned int cpu, enu= m 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; --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 B5BD4149C73 for ; Mon, 25 Mar 2024 10:40:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363213; cv=none; b=hYaCD0iZiq+tQjiNOE6I+Dig5h/gEyLOz7qGTajc5Zk+SKCznvkx2Ktlv5Oj1Ke7pRBMXUs0lvyEFYpDqcYFTJw00kq4xEiLkFo9Tont+ullg9thHIKjGmHAjjenkpy0M4V7ZZQxLPdMa5CsFURndXBfxTJOMDKk2Ea31TmE75c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363213; c=relaxed/simple; bh=hh1ZFNCawXsWZU17nvbUwHOUKoxz/TVwWlfNy5iz5SE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A74MOMiFZdi4BX88yPFvsIzu8FMg9QvZJhabGXn1+DvtGhvysB1CyGvXvn8bxG7NuN548wdHh1EC8ocE8YKMV71bhviCetrPL1vO8u+yVZfO/gu8tAjzVFMVv76r8mE286F5sDcGCNYVTuYgrZYrvdYZJIAaHt4qp103h5jGgJQ= 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=iCMpHjJt; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iCMpHjJt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363212; x=1742899212; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hh1ZFNCawXsWZU17nvbUwHOUKoxz/TVwWlfNy5iz5SE=; b=iCMpHjJt9k/zIHI+gIDcz7kbOLtQzhLNXGHnFGhXTvsUKdh8UM9hEBTP EJAQHzfhZnMqKmqHVKksI6VYSENECpHZXROeSy89RecQtB6h/TizYAPr+ IFAUwOUfOdJKk5lPx8L7gBqRU4lw77IzHwaiYuKj2SGpVVydJKBTQ95gi V8heSUaStmVN2f0+kiolcStmGsyLOxrB++Bj+q8WH/AgCeU8P1bEB1nZj dMJrzQ1fU0v3tazcg+Q8oNNeGEdAR3rwv2G2uJDXqFwWwoopHXhj2ZRMM UTZkNlePsQDUwUhtWN3Pq8PYh3Dt2hPyoVcE9G+JiCJwXgHM+o4zaEV/k A==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561300" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561300" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070129" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070129" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:05 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 082DB524; Mon, 25 Mar 2024 12:40:05 +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: [PATCHv9 04/17] cpu/hotplug, x86/acpi: Disable CPU offlining for ACPI MADT wakeup Date: Mon, 25 Mar 2024 12:38:58 +0200 Message-ID: <20240325103911.2651793-5-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ACPI MADT doesn't allow to offline CPU after it got woke up. Currently CPU hotplug is prevented based on the confidential computing attribute which is set for Intel TDX. But TDX is not the only possible user of the wake up method. Disable CPU offlining on ACPI MADT wakeup enumeration. Signed-off-by: Kirill A. Shutemov Reviewed-by: Thomas Gleixner --- arch/x86/coco/core.c | 1 - arch/x86/kernel/acpi/madt_wakeup.c | 3 +++ include/linux/cc_platform.h | 10 ---------- kernel/cpu.c | 3 +-- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c index d07be9d05cd0..19614302e0c4 100644 --- a/arch/x86/coco/core.c +++ b/arch/x86/coco/core.c @@ -20,7 +20,6 @@ static bool noinstr intel_cc_platform_has(enum cc_attr at= tr) { 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, =20 acpi_mp_wake_mailbox_paddr =3D mp_wake->base_address; =20 + cpu_hotplug_disable_offlining(); + apic_update_callback(wakeup_secondary_cpu_64, acpi_wakeup_cpu); =20 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, }; =20 #ifdef CONFIG_ARCH_HAS_CC_PLATFORM diff --git a/kernel/cpu.c b/kernel/cpu.c index 08860baa6ce0..a70767aee9d0 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1528,8 +1528,7 @@ static int cpu_down_maps_locked(unsigned int cpu, enu= m 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; --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 7F3AC14A0AF for ; Mon, 25 Mar 2024 10:40:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363218; cv=none; b=SDvOJok7gDxYZodHqfayxs7EPKQePD2I2VMx8KBwj4oI1/QdGLHhkR20rDoO4LDfSuXnWUTSj9HnDCmn6wOl6M00NMYBUypoBF4X9NV+x3epfyzJw383XvfdTMDTXmk3shxg/7OXH8LHYSeeMZvgroZNlExOl2ShFpk9ZAKo8ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363218; c=relaxed/simple; bh=7jFuowaz0Vw+N4idIIhc+R9JJKXqB88Qml6sO/pIcmM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lWBlFCM9MQVpESN0z9TWKYPDAr6JWVZYW27DFYqw2zKW5De/cf4yT4vHd22ZRYTXgiwPYTriHH7cElsIEumC038gjSnQjwxuC4UQgBKjLiH4W5iRaQmiwx/R+DUUTAajPZCaJT/wdZi4xbiirjDmw/qboN+Zl3FREO7uIbeErzA= 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=jcOqF1gW; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jcOqF1gW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363216; x=1742899216; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7jFuowaz0Vw+N4idIIhc+R9JJKXqB88Qml6sO/pIcmM=; b=jcOqF1gWpfKrhBOoMDCkvEu+OSJEXc+xnQOqXnjAtowkDPc1k0vHiVG+ PIarShMNhiC1x76sACEMWpZrSEWH+jcXZLbi9JDUIpvHLjCQLuvOwRIYz bX9WqqTcfJD2pAcza6u/ZTjCqaB9M/ahLqv2iT40XrOxKN4+GptqxpkUJ V0rqGw/75zyPzAsfKtZnMAiVtcyxxIi3tGOBVp2iSsNn6HBPqDYW7gZqm eaRIdtKPZxUuvaVqgxevGcDGkbkEJCxrVInYofp0UTNTgh2oMT7M/liJx MFlKnqT0uy2DY067j8oVtkvqlEb+mqVA4VzJVUUSoSEAZhocEryU03Eej A==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561356" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561356" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070149" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070149" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:11 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 149005A8; Mon, 25 Mar 2024 12:40:05 +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: [PATCHv9 05/17] x86/kexec: Keep CR4.MCE set during kexec for TDX guest Date: Mon, 25 Mar 2024 12:38:59 +0200 Message-ID: <20240325103911.2651793-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/relocat= e_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 @@ */ =20 #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 =20 jmp 1f --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 5E644149C7E for ; Mon, 25 Mar 2024 10:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363221; cv=none; b=QFy7rewrj8u3v2zbJWT46efx2ooKLob8aWs/9WI/pywf91gjA6xcz7PBYK1EGK1B3XDT7zWinW3YIN11hjhAHu1ZW3d8yZMHO2eE5g7qg8ke8TW9Xwm5sMCnAQO+A0e6Hpmg1g38MyS0O+Nyif0lH3gjWFCDbuncvNj4kSdzY/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363221; c=relaxed/simple; bh=ougN67D/kq1SmTfIiMnsRqu94By12DPjybftCFC4vBw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uX2k62DPCcIQwUt6NcBROYQwoQxtoSoeqZSUTcK63e+7DStF07kRDgjzyF+GHW+6+/PHfPqYpT0DsJfg5XqUElGb+xJfiY5xQBlljc9JwkULUrP2P80+5L8MrUWRxhdon/TCRYaKwz8VuvoNc2OPZB0b6/DhGS8D7tU2Qr4tKkU= 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=YZIk7Dq1; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YZIk7Dq1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363219; x=1742899219; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ougN67D/kq1SmTfIiMnsRqu94By12DPjybftCFC4vBw=; b=YZIk7Dq1h5L6OwotHP4fGXqaAleDwRVcVT2R4CcIDzWFUoY/oTBcNQlm ZDul3qmE2k16As8rDKnu132KtXMOmSlGd3HfO7OMuF2eO5kmxT/6ypw3R ojekuPVxRis3jD2td6J25RbksGjpx+rhl4Kbzh06iNg+qLWhJAQyaif9J 1xwuPxPjwmVkrDRsz7eUltWNiLFRzMerNbcdBqjkUnVM85BAaYG0AjEpn PKcQd4hEHZHtgTPvzM4v38rYt/QqYwLy6M9ZM3EAyBwcY0ZoS0H32FRZc RJYNomp4DJzBO80U30URigm1Zq3w8p596hF7eUjwldT921C4iobQySMOJ A==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561417" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561417" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070161" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070161" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:11 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 25543643; Mon, 25 Mar 2024 12:40:05 +0200 (EET) From: "Kirill A. Shutemov" To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , "Huang, Kai" , Baoquan He , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Dave Hansen Subject: [PATCHv9 06/17] x86/mm: Make x86_platform.guest.enc_status_change_*() return errno Date: Mon, 25 Mar 2024 12:39:00 +0200 Message-ID: <20240325103911.2651793-7-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Kai Huang --- arch/x86/coco/tdx/tdx.c | 20 +++++++++++--------- arch/x86/hyperv/ivm.c | 9 +++------ arch/x86/include/asm/x86_init.h | 4 ++-- arch/x86/kernel/x86_init.c | 4 ++-- arch/x86/mm/mem_encrypt_amd.c | 8 ++++---- arch/x86/mm/pat/set_memory.c | 8 +++++--- 6 files changed, 27 insertions(+), 26 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 vadd= r, int numpages, bool enc) return true; } =20 -static bool tdx_enc_status_change_prepare(unsigned long vaddr, int numpage= s, - 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; } =20 -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; } =20 void __init tdx_early_init(void) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 768d73de0d09..870b82fce5ce 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -536,7 +536,7 @@ static bool hv_vtom_clear_present(unsigned long kbuffer= , int pagecount, bool enc * 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 pagecou= nt, bool enc) +static int hv_vtom_set_host_visibility(unsigned long kbuffer, int pagecoun= t, bool enc) { enum hv_mem_host_visibility visibility =3D enc ? VMBUS_PAGE_NOT_VISIBLE : VMBUS_PAGE_VISIBLE_READ_WRITE; @@ -544,7 +544,6 @@ static bool hv_vtom_set_host_visibility(unsigned long k= buffer, int pagecount, bo phys_addr_t paddr; void *vaddr; int ret =3D 0; - bool result =3D true; int i, pfn; =20 pfn_array =3D kmalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL); @@ -568,10 +567,8 @@ static bool hv_vtom_set_host_visibility(unsigned long = kbuffer, int pagecount, bo if (pfn =3D=3D HV_MAX_MODIFY_GPA_REP_COUNT || i =3D=3D pagecount - 1) { ret =3D hv_mark_gpa_visibility(pfn, pfn_array, visibility); - if (ret) { - result =3D false; + if (ret) goto err_free_pfn_array; - } pfn =3D 0; } } @@ -589,7 +586,7 @@ static bool hv_vtom_set_host_visibility(unsigned long k= buffer, int pagecount, bo if (set_memory_p(kbuffer, pagecount)) result =3D false; =20 - return result; + return ret; } =20 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_ini= t.h index b89b40f250e6..4770af4d6015 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 befor= e changing page encryption status */ struct x86_guest { - bool (*enc_status_change_prepare)(unsigned long vaddr, int npages, bool e= nc); - bool (*enc_status_change_finish)(unsigned long vaddr, int npages, bool en= c); + int (*enc_status_change_prepare)(unsigned long vaddr, int npages, bool en= c); + 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 a42830dc151b..69413ca37bfe 100644 --- a/arch/x86/kernel/x86_init.c +++ b/arch/x86/kernel/x86_init.c @@ -132,8 +132,8 @@ struct x86_cpuinit_ops x86_cpuinit =3D { =20 static void default_nmi_init(void) { }; =20 -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, unsi= gned long size, bool enc) #endif } =20 -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 lo= ng vaddr, int npages, bool if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP) && !enc) snp_set_memory_shared(vaddr, npages); =20 - return true; + return 0; } =20 /* Return true unconditionally: return value doesn't matter for the SEV si= de */ -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, b= ool 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); =20 - return true; + return 0; } =20 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 80c9037ffadf..e5b454036bf3 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2156,7 +2156,8 @@ static int __set_memory_enc_pgtable(unsigned long add= r, int numpages, bool enc) cpa_flush(&cpa, x86_platform.guest.enc_cache_flush_required()); =20 /* Notify hypervisor that we are about to set/clr encryption attribute. */ - if (!x86_platform.guest.enc_status_change_prepare(addr, numpages, enc)) + ret =3D x86_platform.guest.enc_status_change_prepare(addr, numpages, enc); + if (ret) goto vmm_fail; =20 ret =3D __change_page_attr_set_clr(&cpa, 1); @@ -2174,7 +2175,8 @@ static int __set_memory_enc_pgtable(unsigned long add= r, int numpages, bool enc) return ret; =20 /* Notify hypervisor that we have successfully set/clr encryption attribu= te. */ - if (!x86_platform.guest.enc_status_change_finish(addr, numpages, enc)) + ret =3D x86_platform.guest.enc_status_change_finish(addr, numpages, enc); + if (ret) goto vmm_fail; =20 return 0; @@ -2183,7 +2185,7 @@ static int __set_memory_enc_pgtable(unsigned long add= r, int numpages, bool enc) WARN_ONCE(1, "CPA VMM failure to convert memory (addr=3D%p, numpages=3D%d= ) to %s.\n", (void *)addr, numpages, enc ? "private" : "shared"); =20 - return -EIO; + return ret; } =20 static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc) --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 31F1217C6B3 for ; Mon, 25 Mar 2024 10:40:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363222; cv=none; b=fEXoiA6OA596nAfCQ65d0r60QiDiaBw1KXBTlVGeUVVLEJ1FXceR5cMQ9jix6bYztFO4sZN+Jpv0GzWqMa+0dkedoDXfGww0RG1W96NgMObtn15Mbihuw3hfSMgcsoljpLmpvxh+7ST7bWqofIHqm5LB8nN8HLoE/2daGW9mtPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363222; c=relaxed/simple; bh=ACL3RNhnKJDcGNWbnTjXRL1Ph76rTdi3HzpsJi8OSZs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l2gjmInUq35tlDNho/gEqRn846JJwykPXBNeU2/fRD5dSYoF/bVGL9rJOagM4j4FLkcuCkmwJ6Kx6CiqWJ7O3thffIvMj14sKrLnEglSKGoTcLo0LXqf/0g7gGsQ9P5jjLr+zyBu73lSMDVKOQEG/HAHgxx4guH3WLQoGfwNcp0= 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=Rx+tD79J; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Rx+tD79J" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363221; x=1742899221; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ACL3RNhnKJDcGNWbnTjXRL1Ph76rTdi3HzpsJi8OSZs=; b=Rx+tD79JzFYORYmd6wFaePoXzt/v2h/5VH0WMN/1j0cQfazcyS6MqQ8r lUn+IZtGZvYvC7uDLdn33h9Od6P+ZgYPCb1tznSkLN49ElOpFj1oSd1wM iUYq4op0se7E72Q6pwAGbsbySyUaVgr5MkGZ9Wh9GqIqZByiFj2dx5Vtk XbSeCS7S7nPntir+o7NAYikDfcvhGIYBLuwEK5aJuXTySsuUWIYZFgl65 tdpmIOB76kNu1EqvH1+0EyNnxMRWZGgiG9HMBSJyUMCl2xM/g3k/a62Gc /YXWLn8VmLOqzdI+shXgkMLDSeTG08n07vUSWpv5kH2BvhEVFBzIJIGll w==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561448" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561448" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070169" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070169" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:11 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 32B706AF; Mon, 25 Mar 2024 12:40:05 +0200 (EET) From: "Kirill A. Shutemov" To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , "Huang, Kai" , Baoquan He , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Dave Hansen Subject: [PATCHv9 07/17] x86/mm: Return correct level from lookup_address() if pte is none Date: Mon, 25 Mar 2024 12:39:01 +0200 Message-ID: <20240325103911.2651793-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, lookup_address() returns two things: 1. A "pte_t" (which might be a p[g4um]d_t) 2. The 'level' of the page tables where the "pte_t" was found (returned via a pointer) If no pte_t is found, 'level' is essentially garbage. Always fill out the level. For NULL "pte_t"s, fill in the level where the p*d_none() entry was found mirroring the "found" behavior. Always filling out the level allows using lookup_address() to precisely skip over holes when walking kernel page tables. Add one more entry into enum pg_level to indicate the size of the VA covered by one PGD entry in 5-level paging mode. Update comments for lookup_address() and lookup_address_in_pgd() to reflect changes in the interface. Signed-off-by: Kirill A. Shutemov Reviewed-by: Rick Edgecombe Reviewed-by: Baoquan He Reviewed-by: Dave Hansen --- arch/x86/include/asm/pgtable_types.h | 1 + arch/x86/mm/pat/set_memory.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pg= table_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 }; =20 diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index e5b454036bf3..6c49f69c0368 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -657,7 +657,8 @@ static inline pgprot_t verify_rwx(pgprot_t old, pgprot_= t new, unsigned long star =20 /* * Lookup the page table entry for a virtual address in a specific pgd. - * Return a pointer to the entry and the level of the mapping. + * Return a pointer to the entry (or NULL if the entry does not exist) and + * the level of the entry. */ pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address, unsigned int *level) @@ -666,32 +667,32 @@ pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned lon= g address, pud_t *pud; pmd_t *pmd; =20 - *level =3D PG_LEVEL_NONE; + *level =3D PG_LEVEL_256T; =20 if (pgd_none(*pgd)) return NULL; =20 + *level =3D PG_LEVEL_512G; p4d =3D p4d_offset(pgd, address); if (p4d_none(*p4d)) return NULL; =20 - *level =3D PG_LEVEL_512G; if (p4d_leaf(*p4d) || !p4d_present(*p4d)) return (pte_t *)p4d; =20 + *level =3D PG_LEVEL_1G; pud =3D pud_offset(p4d, address); if (pud_none(*pud)) return NULL; =20 - *level =3D PG_LEVEL_1G; if (pud_leaf(*pud) || !pud_present(*pud)) return (pte_t *)pud; =20 + *level =3D PG_LEVEL_2M; pmd =3D pmd_offset(pud, address); if (pmd_none(*pmd)) return NULL; =20 - *level =3D PG_LEVEL_2M; if (pmd_leaf(*pmd) || !pmd_present(*pmd)) return (pte_t *)pmd; =20 @@ -704,9 +705,8 @@ pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long = address, * Lookup the page table entry for a virtual address. Return a pointer * to the entry and the level of the mapping. * - * Note: We return pud and pmd either when the entry is marked large - * or when the present bit is not set. Otherwise we would return a - * pointer to a nonexisting mapping. + * Note: the function returns p4d, pud or pmd either when the entry is mar= ked + * large or when the present bit is not set. Otherwise it returns NULL. */ pte_t *lookup_address(unsigned long address, unsigned int *level) { --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 22B30149C76 for ; Mon, 25 Mar 2024 10:40:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363219; cv=none; b=bFmChVL+3SJsGMuuR1u4LL6cxu0WvhHxY2644TRirF+TkZRic1kMZHv2wrD9jqIEX59o+m00p8fi/yqyeoomvQgbjaHKcdzmKllGPnqaL7kMP4t328kvOlrG10R1ci6g6W0ux1nUGb3JZmNU73QqshBEJu0ANsZzOeEO2tKEB8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363219; c=relaxed/simple; bh=W80pqKoVc1vqxX/XGuHFDF0b+nJhSWWU10+X3joqYlo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=geqrbjvkzzL2RMs6KEDfEwrL2G21aEHmm9fuLiLMEyD+yydi7F2bCEydpN1u/xTQbcavExVp4bwqUy3IlSQxLf1jtbLyFI0Zw+7VF/1e3dIhQw2HZzXIRCjeR3dZD/9RHSOKZ1uN6zxSG3LvaH8IMIijiYwhnNBzKfPdkYn8OrM= 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=G7Z3tn2I; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="G7Z3tn2I" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363218; x=1742899218; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W80pqKoVc1vqxX/XGuHFDF0b+nJhSWWU10+X3joqYlo=; b=G7Z3tn2I4P37PP88W4L5IEhqk2lb8ynnp3PlK94MaiWoGv9CdaqAqui9 1Mc/htibamLA+HkOGNJxabWezfA1egZeatdsdIRASaul+C9YVrxKxRgEa umSCqE4mnrWpTHcksFqqSmZCJvU103xBx27RUv4qOcEzkLbPDwNnEc3+a k6PLaij854XfBPmGB0U03XYrJ3RErKSWLbMVAguMnD08hbez2U5dwN1r8 NvnQWiRR1HH6Pv3xV4ljK6cv2RY8UI5iFWXcdgTytRKO/WKCExEuAxc/m w0r2RTLwr5PZ1GzSPGl1r9EjC1PTZScqIzYqFdKgppc57EetZvOEVFMKb w==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561377" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561377" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070153" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070153" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:11 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 3F720815; Mon, 25 Mar 2024 12:40:05 +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: [PATCHv9 08/17] x86/tdx: Account shared memory Date: Mon, 25 Mar 2024 12:39:02 +0200 Message-ID: <20240325103911.2651793-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The kernel will convert all shared memory back to private during kexec. The direct mapping page tables will provide information on which memory is shared. It is extremely important to convert all shared memory. If a page is missed, it will cause the second kernel to crash when it accesses it. Keep track of the number of shared pages. This will allow for cross-checking against the shared information in the direct mapping and reporting if the shared bit is lost. Signed-off-by: Kirill A. Shutemov Reviewed-by: Kai Huang Reviewed-by: Kuppuswamy Sathyanarayanan --- arch/x86/coco/tdx/tdx.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 26fa47db5782..979891e97d83 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -38,6 +38,8 @@ =20 #define TDREPORT_SUBTYPE_0 0 =20 +static atomic_long_t nr_shared; + /* Called from __tdx_hypercall() for unrecoverable failure */ noinstr void __noreturn __tdx_hypercall_failed(void) { @@ -821,6 +823,11 @@ static int tdx_enc_status_change_finish(unsigned long = vaddr, int numpages, if (!enc && !tdx_enc_status_changed(vaddr, numpages, enc)) return -EIO; =20 + if (enc) + atomic_long_sub(numpages, &nr_shared); + else + atomic_long_add(numpages, &nr_shared); + return 0; } =20 --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 61820149C7C for ; Mon, 25 Mar 2024 10:40:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363224; cv=none; b=OgBQtnApDvb0Wp7C+5oL6KwwNqNfIsjmsUXILUolHF7NFC9kPczNhfoT4B5AHRogmZKEnbON7v711slfFNDr6eYoChFb5fdng2yX6Vhfl6VC5NZCyUU4Nh00RN9krMdWa8FBPleWvfQ4xo/thmjWxVzmmBvPsFfty1ADC3d2PeI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363224; c=relaxed/simple; bh=yAqWzbGmFNX9PCf901KN8YCyCCxd1h65J2N/iDwm1h8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aE40TQ/UdRVlAdJhEZ+xiwaC92XWxaXQU95KHk43stMquQs8V329CcHGMtq3wV8R/dVMmANLkE0UBCinPo6+qPZu2WkMpnLpI9Qh42Yt9Ux95hczY4h6+TxSs23z2myn5KHW8X/1oIVttxaFummq+2ri3P6OQr1GB/c5wnbKais= 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=V1fqCxiA; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="V1fqCxiA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363222; x=1742899222; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yAqWzbGmFNX9PCf901KN8YCyCCxd1h65J2N/iDwm1h8=; b=V1fqCxiAF4+PsIK20g1l/7lAbl/sGknQdSKcf9pTjQAJ6uLnRrZZ1GvA qeHhIIZJGK+y38R9HFYcwvLuoV6jivl3COdvAyIoeZEhxOQQjOp/zYGJe 2lrahEbdtJcKvTwrIOOSUII2fgtW+qJ4ZWRQ4g0gA0MtG+6r8i7p2r+Hu mtGOhK9/KRihkQ7kYbWq3/rF6T5e6gcZPrkLr2URpcszPg6yNTPp36P+P dlujhbw8EvezbiW5JSw98P9gfzpWvuViV6Lq9LT6X939NkIpCcwsxmBQ6 22LGz7ZkpnZnWSzO+P7FJJrERDZh1+E6rlfjOATDYlHuAGPeaiscmwB9v g==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561435" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561435" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070165" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070165" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:11 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 4C97C233; Mon, 25 Mar 2024 12:40:05 +0200 (EET) From: "Kirill A. Shutemov" To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , "Huang, Kai" , Baoquan He , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Nikolay Borisov Subject: [PATCHv9 09/17] x86/mm: Adding callbacks to prepare encrypted memory for kexec Date: Mon, 25 Mar 2024 12:39:03 +0200 Message-ID: <20240325103911.2651793-10-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" AMD SEV and Intel TDX guests allocate shared buffers for performing I/O. This is done by allocating pages normally from the buddy allocator and then converting them to shared using set_memory_decrypted(). On kexec, the second kernel is unaware of which memory has been converted in this manner. It only sees E820_TYPE_RAM. Accessing shared memory as private is fatal. Therefore, the memory state must be reset to its original state before starting the new kernel with kexec. The process of converting shared memory back to private occurs in two steps: - enc_kexec_stop_conversion() stops new conversions. - enc_kexec_unshare_mem() unshares all existing shared memory, reverting it back to private. Signed-off-by: Kirill A. Shutemov Reviewed-by: Nikolay Borisov x Reviewed-by: Kai Huang --- arch/x86/include/asm/x86_init.h | 2 ++ arch/x86/kernel/crash.c | 6 ++++++ arch/x86/kernel/reboot.c | 12 ++++++++++++ arch/x86/kernel/x86_init.c | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_ini= t.h index 4770af4d6015..f7c7d692407f 100644 --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -154,6 +154,8 @@ struct x86_guest { int (*enc_status_change_finish)(unsigned long vaddr, int npages, bool enc= ); bool (*enc_tlb_flush_required)(bool enc); bool (*enc_cache_flush_required)(void); + void (*enc_kexec_stop_conversion)(bool crash); + void (*enc_kexec_unshare_mem)(void); }; =20 /** diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index e74d0c4286c1..7a1560d7e62d 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -128,6 +128,12 @@ void native_machine_crash_shutdown(struct pt_regs *reg= s) #ifdef CONFIG_HPET_TIMER hpet_disable(); #endif + + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) { + x86_platform.guest.enc_kexec_stop_conversion(true); + x86_platform.guest.enc_kexec_unshare_mem(); + } + crash_save_cpu(regs, safe_smp_processor_id()); } =20 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c index f3130f762784..1ec478f40963 100644 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -716,6 +717,14 @@ static void native_machine_emergency_restart(void) =20 void native_machine_shutdown(void) { + /* + * Call enc_kexec_stop_conversion() while all CPUs are still active and + * interrupts are enabled. This will allow all in-flight memory + * conversions to finish cleanly. + */ + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT) && kexec_in_progress) + x86_platform.guest.enc_kexec_stop_conversion(false); + /* Stop the cpus and apics */ #ifdef CONFIG_X86_IO_APIC /* @@ -752,6 +761,9 @@ void native_machine_shutdown(void) #ifdef CONFIG_X86_64 x86_platform.iommu_shutdown(); #endif + + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT) && kexec_in_progress) + x86_platform.guest.enc_kexec_unshare_mem(); } =20 static void __machine_emergency_restart(int emergency) diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c index 69413ca37bfe..ab97d9b57636 100644 --- a/arch/x86/kernel/x86_init.c +++ b/arch/x86/kernel/x86_init.c @@ -136,6 +136,8 @@ static int enc_status_change_prepare_noop(unsigned long= vaddr, int npages, bool static int enc_status_change_finish_noop(unsigned long vaddr, int npages, = bool enc) { return 0; } static bool enc_tlb_flush_required_noop(bool enc) { return false; } static bool enc_cache_flush_required_noop(void) { return false; } +static void enc_kexec_stop_conversion_noop(bool crash) {} +static void enc_kexec_unshare_mem_noop(void) {} static bool is_private_mmio_noop(u64 addr) {return false; } =20 struct x86_platform_ops x86_platform __ro_after_init =3D { @@ -159,6 +161,8 @@ struct x86_platform_ops x86_platform __ro_after_init = =3D { .enc_status_change_finish =3D enc_status_change_finish_noop, .enc_tlb_flush_required =3D enc_tlb_flush_required_noop, .enc_cache_flush_required =3D enc_cache_flush_required_noop, + .enc_kexec_stop_conversion =3D enc_kexec_stop_conversion_noop, + .enc_kexec_unshare_mem =3D enc_kexec_unshare_mem_noop, }, }; =20 --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 EFA2F149C79 for ; Mon, 25 Mar 2024 10:40:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363224; cv=none; b=iknKWPRtlwsKyp7uJBR5uov5c0ycrZlk0rGLqw2yiYolWFytCQpvUqrN54uslHdNRXV+ITKvPNsHChL6KLN5XVIgwy19NL0lw+2ArhYzGDiAa4QGHjZmUjkqDcNQ98fSFsMQYLinHBz318CeGFJcl2S6/Ta9nlpO7drTR6DEoKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363224; c=relaxed/simple; bh=y7wjbfDtyey/10ilPuo4FM+4R4XPSMZCeymoAYV4H+4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HQCgBSraPQO+uSZHniKvMN2ZiM+3hZl52TpZqRbHZGoAX6qR6dpFjfpuOSBUSpjg6Q8gXpYa2QCU4Vnun20Kc58sjj4Ia31asKN8gespzrLfiiHDuPjX/HbBGbEpzOw0a46k+LnPvc8eXcRCeDOUQKd45mYY7O9cNpYAEaqnTnE= 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=NzUZ6vOu; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="NzUZ6vOu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363223; x=1742899223; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=y7wjbfDtyey/10ilPuo4FM+4R4XPSMZCeymoAYV4H+4=; b=NzUZ6vOu2dNUrppO0hDu1ozasq4ly6cooNOty35HuwWVBQjpGtd4wdFX eSOf7oMsVF2hHE10//mxyNr0Xj3BYXMfHAeqalqaEdVQMwQb+slwvJnD6 PVgud9WlLpkADnuxkc/jX+RAvHMR0dYELyV2SQT78uk66eC7LoIRQmVlM vKK6BPrlDQoD0WRiZCcBbjZ9aTVZDtYX/fHd7e5ADeJLF5e4zWMKpZ1uA nfLl5rsg1s/VsPVXngznHzu19P/RJblzPXsS2FIi3Z6FAtz02NqXfdvhD 09WLoI+XVQE5IvRuXdFPJMccOWPSZu65kA8Tjej7CCNiNXOMM4e0Z4Fjt w==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561409" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561409" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070160" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070160" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:12 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 677CEE3C; Mon, 25 Mar 2024 12:40:05 +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: [PATCHv9 10/17] x86/tdx: Convert shared memory back to private on kexec Date: Mon, 25 Mar 2024 12:39:04 +0200 Message-ID: <20240325103911.2651793-11-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Kai Huang --- arch/x86/coco/tdx/tdx.c | 72 +++++++++++++++++++++++++++++++ arch/x86/include/asm/pgtable.h | 5 +++ arch/x86/include/asm/set_memory.h | 3 ++ arch/x86/mm/pat/set_memory.c | 35 +++++++++++++-- 4 files changed, 112 insertions(+), 3 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 979891e97d83..cc67f7380055 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -14,6 +15,7 @@ #include #include #include +#include =20 /* MMIO direction */ #define EPT_READ 0 @@ -831,6 +833,73 @@ static int tdx_enc_status_change_finish(unsigned long = vaddr, int numpages, return 0; } =20 +/* Stop new private<->shared conversions */ +static void tdx_kexec_stop_conversion(bool crash) +{ + /* + * Crash kernel reaches here with interrupts disabled: can't wait for + * conversions to finish. + * + * If race happened, just report and proceed. + */ + bool wait_for_lock =3D !crash; + + if (!stop_memory_enc_conversion(wait_for_lock)) + pr_warn("Failed to finish shared<->private conversions\n"); +} + +static void tdx_kexec_unshare_mem(void) +{ + unsigned long addr, end; + long found =3D 0, shared; + + /* + * Walk direct mapping and convert all shared memory back to private, + */ + + addr =3D PAGE_OFFSET; + end =3D PAGE_OFFSET + get_max_mapped(); + + while (addr < end) { + unsigned long size; + unsigned int level; + pte_t *pte; + + pte =3D lookup_address(addr, &level); + size =3D page_level_size(level); + + if (pte && pte_decrypted(*pte)) { + int pages =3D 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 +=3D pages; + } + + addr +=3D size; + } + + __flush_tlb_all(); + + shared =3D atomic_long_read(&nr_shared); + if (shared !=3D found) { + pr_err("shared page accounting is off\n"); + pr_err("nr_shared =3D %ld, nr_found =3D %ld\n", shared, found); + } +} + void __init tdx_early_init(void) { struct tdx_module_args args =3D { @@ -890,6 +959,9 @@ void __init tdx_early_init(void) x86_platform.guest.enc_cache_flush_required =3D tdx_cache_flush_required; x86_platform.guest.enc_tlb_flush_required =3D tdx_tlb_flush_required; =20 + x86_platform.guest.enc_kexec_stop_conversion =3D tdx_kexec_stop_conversio= n; + x86_platform.guest.enc_kexec_unshare_mem =3D tdx_kexec_unshare_mem; + /* * TDX intercepts the RDMSR to read the X2APIC ID in the parallel * bringup low level code. That raises #VE which cannot be handled diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 315535ffb258..17f4d97fae06 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -140,6 +140,11 @@ static inline int pte_young(pte_t pte) return pte_flags(pte) & _PAGE_ACCESSED; } =20 +static inline bool pte_decrypted(pte_t pte) +{ + return cc_mkdec(pte_val(pte)) =3D=3D pte_val(pte); +} + #define pmd_dirty pmd_dirty static inline bool pmd_dirty(pmd_t pmd) { diff --git a/arch/x86/include/asm/set_memory.h b/arch/x86/include/asm/set_m= emory.h index 9aee31862b4a..44b6d711296c 100644 --- a/arch/x86/include/asm/set_memory.h +++ b/arch/x86/include/asm/set_memory.h @@ -49,8 +49,11 @@ int set_memory_wb(unsigned long addr, int numpages); int set_memory_np(unsigned long addr, int numpages); int set_memory_p(unsigned long addr, int numpages); int set_memory_4k(unsigned long addr, int numpages); + +bool stop_memory_enc_conversion(bool wait); int set_memory_encrypted(unsigned long addr, int numpages); int set_memory_decrypted(unsigned long addr, int numpages); + int set_memory_np_noalias(unsigned long addr, int numpages); int set_memory_nonglobal(unsigned long addr, int numpages); int set_memory_global(unsigned long addr, int numpages); diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 6c49f69c0368..21835339c0e6 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2188,12 +2188,41 @@ static int __set_memory_enc_pgtable(unsigned long a= ddr, int numpages, bool enc) return ret; } =20 +static DECLARE_RWSEM(mem_enc_lock); + +/* + * Stop new private<->shared conversions. + * + * Taking the exclusive mem_enc_lock waits for in-flight conversions to co= mplete. + * The lock is not released to prevent new conversions from being started. + * + * If sleep is not allowed, as in a crash scenario, try to take the lock. + * Failure indicates that there is a race with the conversion. + */ +bool stop_memory_enc_conversion(bool wait) +{ + if (!wait) + return down_write_trylock(&mem_enc_lock); + + down_write(&mem_enc_lock); + + return true; +} + static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc) { - if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) - return __set_memory_enc_pgtable(addr, numpages, enc); + int ret =3D 0; =20 - return 0; + if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) { + if (!down_read_trylock(&mem_enc_lock)) + return -EBUSY; + + ret =3D__set_memory_enc_pgtable(addr, numpages, enc); + + up_read(&mem_enc_lock); + } + + return ret; } =20 int set_memory_encrypted(unsigned long addr, int numpages) --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 9254C14A0B5 for ; Mon, 25 Mar 2024 10:40:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363222; cv=none; b=cyjHGDc3uQh7afHSEIQjZBZxRLeV2zbnUD+UiVaak8SWY4z3mU59F16n4feGYFevmjsqbUtMG2sLEjP2JotfZ9B/aU+y+5mbP40kR3Uamy1demJ0cIbleEp4UcBDP3fz32IUJEB1VRcjkY5GhzZ//GpKRXMitb5dCTF5Rz38tvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363222; c=relaxed/simple; bh=VFGBq1PSfgIQMFKRrc4wCIEiYZ92NiwhzOj7lLNvdxg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Msdu5CMvZi8c3xQqXHY18RuFuzQ9Pu/NzaioomJ4GrCsgFtDvvYK39sg50Tvchw0x6KNZ18Fs7NegSs76l8AWe0WF4KdrkN0KSRDSEla+gRPn95d5LJs1V2g8r2k+/aGX/dMpVp3HL4m1ZuFgC5ftHOeqHSjWc6dIrKCfBdD2+s= 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=geTl4GLH; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="geTl4GLH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363220; x=1742899220; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VFGBq1PSfgIQMFKRrc4wCIEiYZ92NiwhzOj7lLNvdxg=; b=geTl4GLH3Ke4BCvZ5/ALfLRSE8+sALn4PuB5bcOqLlU3+403Mhl3XoSK l3ucDMxbe5CEZ0wRUUk+3VBNNcAt0F9HSwqwqnBTpb/8aXCOSRcSy9wnj y6h53F2tk80UQYwBsXCJe6XqyBGuiitFeTO07KgCFMxkvwufw/eaIzZdp nzteqW8cAqIWCkZGrcLyPdAvxZ6NG2Z68gPQvJNyPWmHI9P+/42OgjYCd IxSnKtaDfPxBFJbBBzoTjcJT986aNQweup8wVEzxUkm6o9cawemIaADlw 0Tgc3a5kSy115Ypu8aBxJAnOyPoVxGQN4nMnSgo54p7n0Um/CedgYdY7+ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561430" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561430" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070163" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070163" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:11 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 78733F06; Mon, 25 Mar 2024 12:40:05 +0200 (EET) From: "Kirill A. Shutemov" To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , "Huang, Kai" , Baoquan He , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Dave Hansen Subject: [PATCHv9 11/17] x86/mm: Make e820_end_ram_pfn() cover E820_TYPE_ACPI ranges Date: Mon, 25 Mar 2024 12:39:05 +0200 Message-ID: <20240325103911.2651793-12-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 6f1b379e3b38..f29969428443 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 e82= 0_type type) +static unsigned long __init e820_end_ram_pfn(unsigned long limit_pfn) { int i; unsigned long last_pfn =3D 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; =20 - if (entry->type !=3D type) + if (entry->type !=3D E820_TYPE_RAM && + entry->type !=3D E820_TYPE_ACPI) continue; =20 start_pfn =3D entry->addr >> PAGE_SHIFT; @@ -864,12 +865,12 @@ static unsigned long __init e820_end_pfn(unsigned lon= g limit_pfn, enum e820_type =20 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); } =20 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)); } =20 static void __init early_panic(char *msg) --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 9733B14A4C7 for ; Mon, 25 Mar 2024 10:40:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363219; cv=none; b=QTessnNFZvx9d1XoIhopD3k/9mFXDz3qyAMWNDCa6ralOYvI1Ur1CuDH4IpraV8RY09B03d+702HjK9s7eYS7IhAj562WT/S+gkbb6XD8tRiAEsjU6TWMz6GdCxbCRzGgOQpvSYovNzjLHcqyQ6GxTyqpCcmrfS/CLxj/1KswRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363219; c=relaxed/simple; bh=pJgXfq63C3arXvCjRGyfK5PtseQeqyNecMgpXB9cqPk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z+k3j8GR5fHxO/AJDsiBP8k6kJtbb6os23GrZlJntD3VW4SmNCDkumYiyzI9atU3pCCnYLrTPpJL6t4UrJhJKJHPJu+tA8X+sA2NMncowA51Xl55//fPsMkJvNGvA2Qq4arztBE1JnT5I6fuloDgnKczWAnfE++le7iyTnnde7s= 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=SWdQxKTw; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="SWdQxKTw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363217; x=1742899217; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pJgXfq63C3arXvCjRGyfK5PtseQeqyNecMgpXB9cqPk=; b=SWdQxKTw3W5EiQFuIf7nlZBWQ16X1Jv8lo/q8AX6BbEbiGTRUqNjERNe HDpOYMbGjBepW9YE3l8W9ERH2Zzj/g5SRC+7Gi9m0l88plZicDY38j/LH bq6NMAoxedaLx4L0Aupe0A3KldQ11pS0385C6YlUT0sx+JkP4St1OXNLC fOv9N5pL8fRLT5SIqgJa3yXW5gybptzHWZ/qLsNg764IiE6xw3Q0JhMpc K/uwWF+oF9GIG+o8tgNs3IWaHZg2I1FGB/iLNEAYMx1CLTJLH11Lp5Sxk NJSRzNT7oQNwIKsmv1zRxPxhZwaEE61jMHRoEBxxO94wtc90uEiDNOhWi w==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561367" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561367" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070151" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070151" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:11 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 89FDDF2B; Mon, 25 Mar 2024 12:40:05 +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: [PATCHv9 12/17] x86/acpi: Rename fields in acpi_madt_multiproc_wakeup structure Date: Mon, 25 Mar 2024 12:39:06 +0200 Message-ID: <20240325103911.2651793-13-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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, =20 acpi_table_print_madt_entry(&header->common); =20 - acpi_mp_wake_mailbox_paddr =3D mp_wake->base_address; + acpi_mp_wake_mailbox_paddr =3D mp_wake->mailbox_address; =20 cpu_hotplug_disable_offlining(); =20 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 { =20 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; }; =20 #define ACPI_MULTIPROC_WAKEUP_MB_OS_SIZE 2032 --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 E15DA14D456 for ; Mon, 25 Mar 2024 10:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363225; cv=none; b=gb8P/JBVNSpSh2NoLZtUyyFJIwWsN8odPJbZGoxmF/817RGvJf7HMA2ypceTFy8/QQQ1OPQGbEMQz/A++9p4IkJ7lcKbrohyqHCU1KxnQYGYygO5sYpBRSASFeFkcUutoOGliz02unBKB07/a7z70IVB6ojwzGlymgPdpziLA6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363225; c=relaxed/simple; bh=4OahAA5tbkCWt5kWDDzHkciJDRb/0EhPa8AF3hktH9I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BPxIVm87xvzdyGDyELpK2mZvnG38fLuddmF2uKjUrBoRpinDtsb1+AxfINdvDofxk8fwzVjzy6uUvNpfcGx8TEN6zM78s9vLwmb9nZ9hsKn7O5fsxvpEGGZKJ/xjJY+L1b2SMJVoyncAXC+SuFcbrHDOAZhCly4Q3ua3HKsYWFY= 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=X54ZwAxi; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="X54ZwAxi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363220; x=1742899220; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4OahAA5tbkCWt5kWDDzHkciJDRb/0EhPa8AF3hktH9I=; b=X54ZwAxi2iMQ0RUgHUGbLrYDqVA0TzHe5xf5j2yQ2C7jtjRcr0lnLs+1 sDaKfqXNHBdhzYBUAvspqSrtqwixg87kp3eAl9CFqr54mDMnjWpXDXNPD BC+w1eiKHn9MhE5y1xDBXPt4FyE7SCC0xAMQTsymyXjlIReRoXIl6MGz7 9JmSoJg1Pxs1hGOSQCM/+1+86gPIq1V/W4Rmvh5MVcaz5udyKfWl/J9Mj D4/CrIrhfUuP/VdZBKu4FzrWJSxTKoEJXSHaknIEU7oWh49dcvD9VAKNo rOLLv7snKC3exv6AjD5x4giMyR4CphHhFf3l9E+4n8dJ4bzkUTAQgywFA w==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561390" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561390" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070155" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070155" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:11 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 97035F4F; Mon, 25 Mar 2024 12:40:05 +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: [PATCHv9 13/17] x86/acpi: Do not attempt to bring up secondary CPUs in kexec case Date: Mon, 25 Mar 2024 12:39:07 +0200 Message-ID: <20240325103911.2651793-14-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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_m= p_wake_mailbox __ro_afte =20 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 wi= th 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 sta= rt_ip) return 0; } =20 +static void acpi_mp_disable_offlining(struct acpi_madt_multiproc_wakeup *m= p_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 =3D 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_header= s *header, =20 acpi_mp_wake_mailbox_paddr =3D mp_wake->mailbox_address; =20 - cpu_hotplug_disable_offlining(); + acpi_mp_disable_offlining(mp_wake); =20 apic_update_callback(wakeup_secondary_cpu_64, acpi_wakeup_cpu); =20 --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 36FD5149C7D for ; Mon, 25 Mar 2024 10:40:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363220; cv=none; b=NspWBxkvi72lVVwf0NbOc9V5qLu9uTbqi80AteNnBgack820LD2gOIkXgyI7kCUP0sYKoo43ce52zCiwnRxR7X10duNXPZar8G5/Dvf1XxQvNTI2Lc9KHT1uqWgwELoo9oPsjgc2IpzDeQsbBpe/pl/9Ue4vjvv98yTOQ6SRjTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363220; c=relaxed/simple; bh=afEHAj6Ona/U1R3Hzh9Y6aqHqs5rMx6ECTCC4WyRrfQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rr0etIqh4GC60rnrD51lBjIklwWAM9WlmhkKDqQAUTN/ftBIFI24UqO3EZhfmgoWzRwTybpTVS0nLl8ne+IzCsZ9G4ZQYE0xSOx6kApuEiIStCLz2A/H5w2tQAmdzdovTTl+VgAnSYI0suibxg2eDAqXnXNe3QFybObuJDh99P0= 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=YvXNPEFI; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YvXNPEFI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363218; x=1742899218; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=afEHAj6Ona/U1R3Hzh9Y6aqHqs5rMx6ECTCC4WyRrfQ=; b=YvXNPEFIidDlKBr1pu6fAXOLEgtu0Hmw3x26P4nClEU/E+w2FMnhpYej k/snlZQHg/Zo2RqpK/LXpPaBVjV0MqgLwWLSfzv1UL7XK2A5IG9dwm6oV BBMIx/GVu3I4APgXACacvY+4TND2w4MPZQ0xH4LJswOafzrL8owvhg9ac jeZXixOGrhlQfiE8a6eCnPwpPQ+qtE1banM0Cn4yIlbCNIFPSflcHP6gj nL6esOzOzO7ca3a5m0aRKSmdXvJX9jedq6i8yO60VWWYLLb47pfA+vuHU mz4au6QEyjhhHuKTJo72dLPvlvSPXRwrHJKwglRcQn1sWpbF09Af40R5s w==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561397" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561397" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070157" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070157" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:12 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id A40251026; Mon, 25 Mar 2024 12:40:05 +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: [PATCHv9 14/17] x86/smp: Add smp_ops.stop_this_cpu() callback Date: Mon, 25 Mar 2024 12:39:08 +0200 Message-ID: <20240325103911.2651793-15-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 a35936b512fe..ca073f40698f 100644 --- a/arch/x86/include/asm/smp.h +++ b/arch/x86/include/asm/smp.h @@ -35,6 +35,7 @@ struct smp_ops { int (*cpu_disable)(void); void (*cpu_die)(unsigned int cpu); void (*play_dead)(void); + void (*stop_this_cpu)(void); =20 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 b8441147eb5e..f63f8fd00a91 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); =20 +#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 1ec478f40963..293ded05a4b0 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(); =20 atomic_dec(&waiting_for_crash_ipi); + + if (smp_ops.stop_this_cpu) { + smp_ops.stop_this_cpu(); + unreachable(); + } + /* Assume hlt works */ halt(); for (;;) --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 3210E17C6B0 for ; Mon, 25 Mar 2024 10:40:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363227; cv=none; b=YsYH4N94i462F/Kvi79N/R/1ITxnW69eXJt1Qm2D/lUB6GRKAo65HErEMfVPpfruVOW8B6ZR3MCzialQkg3xJa0GNsyjzMDTkJcdBkghW9oXbJZ8XMoXQmp4bKCcXOr1h/kST+SJy4nIzUiMsJPV+sTG3i87RjddBckWT7XP97E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363227; c=relaxed/simple; bh=bOB3euoyakUv2oEsB37yPol1Ac36digxpBM2Q7o9cSk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OsKXeJbjnq6x4OtV2qhnkh7ru9D8gmtpvXjIaw28aZSDc5zM+tRX4Giw13pdWb7Zb//nE9EZ7Olk+MbxDdDdR10p6gBuhLx+nvcNonM9jrdTowDeLid3+9tpyeZIsul0eNTyPJbQq0iFXhAwXjJ9DfU55xSuVzYN5TdoFjJCRW4= 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=TjkYF3Xy; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="TjkYF3Xy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363226; x=1742899226; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bOB3euoyakUv2oEsB37yPol1Ac36digxpBM2Q7o9cSk=; b=TjkYF3XytmGk5LkjONv+AAzhg90FqnJ89P6ofKbM8/Bat6Cg4Uo2IXFk zFjjswh+XJoWXj8aM80pojf1P8pDrpHTUHQZ/u//qsngzYHj8OQrrftSZ AC4hBlHNubZAmCyyS4HYebIBZkQk0vNCDUAgAaPb9QeXoqWw5TThKawNN L0Sktxvv4F5EF7KPtRAHfu3ZRPr/AmZBKijrtGL3JrcyvC08g65KYTP0i LpgwE7Qyar5UNPLatwThhJHFpDryGmNIWQ3LcrvCSfy/zgqeWTIv6I6sp RuG1Ll95AThigjmuSb41t0JgtFurQ7gRnrkXZd1xKaZ6oNp98K9I7keIk Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561478" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561478" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070174" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070174" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:16 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id B0553103A; Mon, 25 Mar 2024 12:40:05 +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: [PATCHv9 15/17] x86/mm: Introduce kernel_ident_mapping_free() Date: Mon, 25 Mar 2024 12:39:09 +0200 Message-ID: <20240325103911.2651793-16-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 @@ =20 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_pa= ge, unsigned long pstart, unsigned long pend); =20 +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 a204a332c71f..c74ea5753ed3 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. */ =20 +static void free_pte(struct x86_mapping_info *info, pmd_t *pmd) +{ + pte_t *pte =3D 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 =3D pmd_offset(pud, 0); + int i; + + for (i =3D 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 =3D pud_offset(p4d, 0); + int i; + + for (i =3D 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 =3D p4d_offset(pgd, 0); + int i; + + for (i =3D 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 =3D 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) { --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 7B80514A4C3 for ; Mon, 25 Mar 2024 10:40:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363226; cv=none; b=NkhAGIxD/+JAwI1INKF3SLAFRXwHQEKqqCet1+yDpxf+iD295J/oqYlp5+NNY9qKqShMU5ML4PJJl8zU96hEAAyYqiJJR2QMPMmfUVzjr1hSp2FC2c3BKlomk3dMrqKjEa/fAyWEcXvApG16Aiqk3FcpOPq1fuvnHjjA9u4aFis= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363226; c=relaxed/simple; bh=txRUFpMSxXg5LAXaF41EiCvBKfa8Uy7Uc4euvd58Ye4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zeib5NZxHryZs2FuZOjQFhcrn2pIuBTfC8JtRyaYY6sEVNcuBj5r6QVY7lRbzeqP267g9DgPKI4ZnVIVlG6M9RAknmFCw/shGiHDsUGBJFLEIbTQgWMVwFZWsUx5/B64iXLdzIQPawkNIHaFCp9OeD7f9oEOVhmYVyRbxC5djKk= 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=aVnFetFA; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="aVnFetFA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363224; x=1742899224; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=txRUFpMSxXg5LAXaF41EiCvBKfa8Uy7Uc4euvd58Ye4=; b=aVnFetFAv66SSgc/+x5ZJ8rbE445R/wBiAZWH24lroMIhiZJmejxxP6s VOWLHOGtNoM9X4nBCyghC5e+1phRSj+FUqEXYtXjzEhTU7KEq2hOKCFJn ld7OOET9+H790wPbY1N4IxpQbZCLp1gEKAyFcgjCSI+K5kVFDYY/pZJiO IBEkhubMSdPhpzTnlAF9THE5XLM6ohCd55XhMChgXx9pM8ze7DNlETqqk 5uL6fQjNDwCFx3rnQCflM42S067t0HbSzSkCiDiOHRpZbEHHt/6jS6npm SouXzdAvviLyBeApoRwMoAW5T4pAwT0mchc6b9u+S+YIx2G8ThJ6nTPtA A==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561469" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561469" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070172" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070172" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:16 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id BD02A10A0; Mon, 25 Mar 2024 12:40:05 +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: [PATCHv9 16/17] x86/acpi: Add support for CPU offlining for ACPI MADT wakeup method Date: Mon, 25 Mar 2024 12:39:10 +0200 Message-ID: <20240325103911.2651793-17-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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); =20 +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) +=3D boot.o obj-$(CONFIG_ACPI_SLEEP) +=3D sleep.o wakeup_$(BITS).o obj-$(CONFIG_ACPI_APEI) +=3D apei.o obj-$(CONFIG_ACPI_CPPC_LIB) +=3D cppc.o -obj-$(CONFIG_X86_ACPI_MADT_WAKEUP) +=3D madt_wakeup.o +obj-$(CONFIG_X86_ACPI_MADT_WAKEUP) +=3D madt_wakeup.o madt_playdead.o =20 ifneq ($(CONFIG_ACPI_PROCESSOR),) obj-y +=3D cstate.o diff --git a/arch/x86/kernel/acpi/madt_playdead.S b/arch/x86/kernel/acpi/ma= dt_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 =20 /* 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 __r= o_after_init; =20 +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 =3D 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 =3D apicid; + smp_store_release(&acpi_mp_wake_mailbox->command, + ACPI_MP_WAKE_COMMAND_TEST); + + /* Don't wait longer than a second. */ + timeout =3D 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_p= age */ +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() sw= itches + * to the identity mapping and the function has be present at the same spo= t in + * the virtual address space before and after switching page tables. + */ +static int __init init_transition_pgtable(pgd_t *pgd) +{ + pgprot_t prot =3D PAGE_KERNEL_EXEC_NOENC; + unsigned long vaddr, paddr; + p4d_t *p4d; + pud_t *pud; + pmd_t *pmd; + pte_t *pte; + + vaddr =3D (unsigned long)asm_acpi_mp_play_dead; + pgd +=3D pgd_index(vaddr); + if (!pgd_present(*pgd)) { + p4d =3D (p4d_t *)alloc_pgt_page(NULL); + if (!p4d) + return -ENOMEM; + set_pgd(pgd, __pgd(__pa(p4d) | _KERNPG_TABLE)); + } + p4d =3D p4d_offset(pgd, vaddr); + if (!p4d_present(*p4d)) { + pud =3D (pud_t *)alloc_pgt_page(NULL); + if (!pud) + return -ENOMEM; + set_p4d(p4d, __p4d(__pa(pud) | _KERNPG_TABLE)); + } + pud =3D pud_offset(p4d, vaddr); + if (!pud_present(*pud)) { + pmd =3D (pmd_t *)alloc_pgt_page(NULL); + if (!pmd) + return -ENOMEM; + set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE)); + } + pmd =3D pmd_offset(pud, vaddr); + if (!pmd_present(*pmd)) { + pte =3D (pte_t *)alloc_pgt_page(NULL); + if (!pte) + return -ENOMEM; + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE)); + } + pte =3D pte_offset_kernel(pmd, vaddr); + + paddr =3D __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 =3D { + .alloc_pgt_page =3D alloc_pgt_page, + .free_pgt_page =3D free_pgt_page, + .page_flag =3D __PAGE_KERNEL_LARGE_EXEC, + .kernpg_flag =3D _KERNPG_TABLE_NOENC, + }; + pgd_t *pgd; + + pgd =3D alloc_pgt_page(NULL); + if (!pgd) + return -ENOMEM; + + for (int i =3D 0; i < nr_pfn_mapped; i++) { + unsigned long mstart, mend; + + mstart =3D pfn_mapped[i].start << PAGE_SHIFT; + mend =3D 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 =3D acpi_mp_play_dead; + smp_ops.stop_this_cpu =3D acpi_mp_stop_this_cpu; + smp_ops.cpu_die =3D acpi_mp_cpu_die; + + acpi_mp_reset_vector_paddr =3D reset_vector; + acpi_mp_pgd =3D __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_head= ers *header, struct acpi_madt_multiproc_wakeup *mp_wake; =20 mp_wake =3D (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; =20 acpi_table_print_madt_entry(&header->common); =20 acpi_mp_wake_mailbox_paddr =3D mp_wake->mailbox_address; =20 - acpi_mp_disable_offlining(mp_wake); + if (mp_wake->version >=3D ACPI_MADT_MP_WAKEUP_VERSION_V1 && + mp_wake->header.length >=3D 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); + } =20 apic_update_callback(wakeup_secondary_cpu_64, acpi_wakeup_cpu); =20 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; }; =20 +/* Values for Version field above */ + +enum acpi_madt_multiproc_wakeup_version { + ACPI_MADT_MP_WAKEUP_VERSION_NONE =3D 0, + ACPI_MADT_MP_WAKEUP_VERSION_V1 =3D 1, + ACPI_MADT_MP_WAKEUP_VERSION_RESERVED =3D 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 =20 @@ -1134,7 +1146,8 @@ struct acpi_madt_multiproc_wakeup_mailbox { u8 reserved_firmware[ACPI_MULTIPROC_WAKEUP_MB_FIRMWARE_SIZE]; /* reserved= for firmware use */ }; =20 -#define ACPI_MP_WAKE_COMMAND_WAKEUP 1 +#define ACPI_MP_WAKE_COMMAND_WAKEUP 1 +#define ACPI_MP_WAKE_COMMAND_TEST 2 =20 /* 17: CPU Core Interrupt Controller (ACPI 6.5) */ =20 --=20 2.43.0 From nobody Sat Feb 7 08:44:55 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 E622B149DE5 for ; Mon, 25 Mar 2024 10:40:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363226; cv=none; b=pWBWVJP9wQf6shK1LjJtAzpcyvWxfXCyEx2V4AiVjY2Avv6b6WaDug8oHaBiaWdCak18IlYFkSgAPfK0jBOiJhI0kT3GAY1RRZggsC2YUGH858PsEZhCVA4X1YHXrD/CsvwIQSbl20RmycwcoCI4pK3Jw545ffupY8gGtEI+b/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363226; c=relaxed/simple; bh=PpxJd/xhncFPluKgayPJOUtPMmc+/bHV6y/nrvp0u78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iqwxeK1JJ6WKH3+OqfGKs77Kxixwb5kxldjHmaPVbcLivcHigVOMAM5dZ0Jn/wKXsntlHEm4QYORok6v2ZG5qfServUuVW5QdsSFhy4NiY95XnE/mYmMUQeWoQwPxC9EzePCDS6A74FByCcSPJLPKFfUrXeSxR1iB3/E/yNb0EY= 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=guLTd5yx; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="guLTd5yx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363225; x=1742899225; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PpxJd/xhncFPluKgayPJOUtPMmc+/bHV6y/nrvp0u78=; b=guLTd5yxcSCsUYZqhbDGVLstpeCeyfgG/RxqM3HmKZ3e6f5dBwjK3we/ 567ArTPvO2o0frgFifMrVllItomLz5/E4zVvMngdffix/i2T2+2S3+O5b G+GIBkV1B1VXTmIJQqm1N2BFUwSgRyqhDu1yeAYQ+w3AS/AL7nWJwZ+2W BhqbUCsllJY55r1Isv+hGtQspWXi7Cxw3vfwJCBXW3C7UYahiAPRckWfL Mtp4xZkGF1nEyeI10lcMt3E9I/RO9/0+4oeWTgOG+ScdkrRy3g9f7nt5z SfjqTRcNCzrihm4Fuu5IK1W8zF4fWU+PUWKKJh4rjT0GnSfFo8AOS5w46 g==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561488" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561488" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070176" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070176" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:17 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id C8E15112E; Mon, 25 Mar 2024 12:40:05 +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: [PATCHv9 17/17] ACPI: tables: Print MULTIPROC_WAKEUP when MADT is parsed Date: Mon, 25 Mar 2024 12:39:11 +0200 Message-ID: <20240325103911.2651793-18-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When MADT is parsed, print MULTIPROC_WAKEUP information: ACPI: MP Wakeup (version[1], mailbox[0x7fffd000], reset[0x7fffe068]) This debug information will be very helpful during bring up. Signed-off-by: Kirill A. Shutemov Reviewed-by: Baoquan He Reviewed-by: Kai Huang Reviewed-by: Kuppuswamy Sathyanarayanan --- drivers/acpi/tables.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index b976e5fc3fbc..9e1b01c35070 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -198,6 +198,20 @@ void acpi_table_print_madt_entry(struct acpi_subtable_= header *header) } break; =20 + case ACPI_MADT_TYPE_MULTIPROC_WAKEUP: + { + struct acpi_madt_multiproc_wakeup *p =3D + (struct acpi_madt_multiproc_wakeup *)header; + u64 reset_vector =3D 0; + + if (p->version >=3D ACPI_MADT_MP_WAKEUP_VERSION_V1) + reset_vector =3D p->reset_vector; + + pr_debug("MP Wakeup (version[%d], mailbox[%#llx], reset[%#llx])\n", + p->version, p->mailbox_address, reset_vector); + } + break; + case ACPI_MADT_TYPE_CORE_PIC: { struct acpi_madt_core_pic *p =3D (struct acpi_madt_core_pic *)header; --=20 2.43.0