From patchwork Fri Jun 14 09:58:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 804241 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 CAF6A198A11; Fri, 14 Jun 2024 09:59:25 +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=1718359167; cv=none; b=dgJPnTAJscxdrC38XLdHL823/CcY1q/rDwkvU0UYosFbXicYuzzMm1gQRJxRqKYtdxzVSEQkL9xC7xkHDspe08qNNvUAZzQgBElexlMNMyN3erBQVYgWuUdz10mP2pWm39T5cdd8kh3AnZNl4QlBKDnqysd7HkUav0sk7zujx3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718359167; c=relaxed/simple; bh=sMf7Bj61UHDCBOlFd+domeR/Su8pHK5UaLOkIveDSIM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qy58I8DkC6gnhOB6o9CGkmlMnYISUa2X0glbbpDQvbVP+UGaHJETw1blFlpbWA1Gmv6D1ij7xqiLod0Jo7LSZXhYsrkW5240pv/yC+EX85JIdf8Z11qaDXMsIzuNUzRwj0/JNzDd454ra1SYkUYvbI/UiaShr3WC8h4RT4uxm/M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.helo=mgamail.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=FzPXUuOx; 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="FzPXUuOx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718359166; x=1749895166; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sMf7Bj61UHDCBOlFd+domeR/Su8pHK5UaLOkIveDSIM=; b=FzPXUuOx3s9ht3Xap5S7ZE5sXyJ2Tb58N+7Dbw3WWm9GZ3HyZ5IQy7z8 TV7bL42bNEUp2bTSSlhmXp+TNT8gqQwUiHW4MdpK6L58Wyge+H4ef7M5P 0b6kEkRifWrtnRu6GaLOST2QZGR42tGASh3ag+t81+e20pIu/eNiEfuBU 1QN4hQ42PvfTuaXuk9vANiCxwrn+zhtT3gCFfYarsjz//StJsYA+qaJA1 Q+y4+vqqx8qVPA6IOzmcMz66u+ckpI+UurwWrtGzGIyandhTOZ21hH/FU 2j5D2B1xQzJYFtqEtYuYiUzAwPtv6yFzwbWp8lJBo9ueqAHUCk5glb+rT g==; X-CSE-ConnectionGUID: l4QEdaOJQyO5EJv1isj1HQ== X-CSE-MsgGUID: N/Y0B8npQ1e0sAahZmyR7w== X-IronPort-AV: E=McAfee;i="6700,10204,11102"; a="15466705" X-IronPort-AV: E=Sophos;i="6.08,237,1712646000"; d="scan'208";a="15466705" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2024 02:59:23 -0700 X-CSE-ConnectionGUID: 7bkpa9pFTPyeRcUwRDQleg== X-CSE-MsgGUID: U27jgO9IS663GpcuAt7e1g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,237,1712646000"; d="scan'208";a="77930013" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 14 Jun 2024 02:59:17 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 2074B2B0D; Fri, 14 Jun 2024 12:59:09 +0300 (EEST) 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" , Ard Biesheuvel , Baoquan He , "H. Peter Anvin" , "Kirill A. Shutemov" , "K. Y. Srinivasan" , Haiyang Zhang , kexec@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-acpi@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Dave Hansen , Tao Liu Subject: [PATCHv12 12/19] x86/mm: Make e820__end_ram_pfn() cover E820_TYPE_ACPI ranges Date: Fri, 14 Jun 2024 12:58:57 +0300 Message-ID: <20240614095904.1345461-13-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240614095904.1345461-1-kirill.shutemov@linux.intel.com> References: <20240614095904.1345461-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Tested-by: Tao Liu --- 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 68b09f718f10..4893d30ce438 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -828,7 +828,7 @@ u64 __init e820__memblock_alloc_reserved(u64 size, u64 align) /* * Find the highest page frame number we have available */ -static unsigned long __init e820_end_pfn(unsigned long limit_pfn, enum e820_type type) +static unsigned long __init e820__end_ram_pfn(unsigned long limit_pfn) { int i; unsigned long last_pfn = 0; @@ -839,7 +839,8 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, enum e820_type unsigned long start_pfn; unsigned long end_pfn; - if (entry->type != type) + if (entry->type != E820_TYPE_RAM && + entry->type != E820_TYPE_ACPI) continue; start_pfn = entry->addr >> PAGE_SHIFT; @@ -865,12 +866,12 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, enum e820_type unsigned long __init e820__end_of_ram_pfn(void) { - return e820_end_pfn(MAX_ARCH_PFN, E820_TYPE_RAM); + return e820__end_ram_pfn(MAX_ARCH_PFN); } unsigned long __init e820__end_of_low_ram_pfn(void) { - return e820_end_pfn(1UL << (32 - PAGE_SHIFT), E820_TYPE_RAM); + return e820__end_ram_pfn(1UL << (32 - PAGE_SHIFT)); } static void __init early_panic(char *msg)