From patchwork Wed Aug 16 21:24:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 714176 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F360DC27C41 for ; Wed, 16 Aug 2023 21:25:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346455AbjHPVYr (ORCPT ); Wed, 16 Aug 2023 17:24:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346494AbjHPVYc (ORCPT ); Wed, 16 Aug 2023 17:24:32 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4DA61BE8 for ; Wed, 16 Aug 2023 14:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692221071; x=1723757071; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YaJcwdfsbT/u6tJs5uRbj4NUFmy4HkVgm/EwY5jjC6U=; b=VZ5ru0HFMbxZYJC5EjK0ukNJC9k5IBiXwxXRvRdRHdKIySSaxJf5U50E +K3oPQevAtGYZCsFZBzvXD2dDaFqJFfizOrYSCk8ur1vVlunLmn4Ovli+ /ucmWAYgRGSfJcmm2nI+N2MUsMTJM0UaZ3/kthPpkES8+ljLPa0FSF583 RTNaQq9Ul6ybOu0Q7oRFe9vbhUtzNeMqB5hZKopEOLIN8E78utifIkLl9 InNcckzFVnUX7ZzZrgQfQcc9QLhx1g7dzGtvy8uUPRsLDDdMTkJcmpCaD wTTA30lEjp+owXR077J974/QmmKHAgL9VPSTCoxYwiEFiyN/1jyKeg6UY g==; X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="438996880" X-IronPort-AV: E=Sophos;i="6.01,178,1684825200"; d="scan'208";a="438996880" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2023 14:24:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="908144440" X-IronPort-AV: E=Sophos;i="6.01,178,1684825200"; d="scan'208";a="908144440" Received: from vmusin-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.42.205]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2023 14:24:29 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id F2B8810A348; Thu, 17 Aug 2023 00:24:26 +0300 (+03) From: "Kirill A. Shutemov" To: ardb@kernel.org, dave.hansen@linux.intel.com Cc: kirill.shutemov@linux.intel.com, linux-efi@vger.kernel.org, x86@kernel.org Subject: [PATCH] x86/mm: Make e820_end_ram_pfn() cover E820_TYPE_ACPI ranges Date: Thu, 17 Aug 2023 00:24:18 +0300 Message-ID: <20230816212418.25069-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816190557.3738-1-ardb@kernel.org> References: <20230816190557.3738-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org 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 Reported-by: "Hongyu Ning" --- arch/x86/kernel/e820.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index fb8cf953380d..99c80680dc9e 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -827,7 +827,7 @@ u64 __init e820__memblock_alloc_reserved(u64 size, u64 align) /* * Find the highest page frame number we have available */ -static unsigned long __init e820_end_pfn(unsigned long limit_pfn, enum e820_type type) +static unsigned long __init e820_end_ram_pfn(unsigned long limit_pfn) { int i; unsigned long last_pfn = 0; @@ -838,7 +838,8 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, enum e820_type unsigned long start_pfn; unsigned long end_pfn; - if (entry->type != type) + if (entry->type != E820_TYPE_RAM && + entry->type != E820_TYPE_ACPI) continue; start_pfn = entry->addr >> PAGE_SHIFT; @@ -864,12 +865,12 @@ static unsigned long __init e820_end_pfn(unsigned long limit_pfn, enum e820_type unsigned long __init e820__end_of_ram_pfn(void) { - return e820_end_pfn(MAX_ARCH_PFN, E820_TYPE_RAM); + return e820_end_ram_pfn(MAX_ARCH_PFN); } unsigned long __init e820__end_of_low_ram_pfn(void) { - return e820_end_pfn(1UL << (32 - PAGE_SHIFT), E820_TYPE_RAM); + return e820_end_ram_pfn(1UL << (32 - PAGE_SHIFT)); } static void __init early_panic(char *msg)