Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1092745rdb; Fri, 20 Oct 2023 08:14:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9yER6b6dBlgI/8Pb+Hr8mYKaxeK+a+6hRCgh8RMKnSPvx5FBYpMOBeUxTkp7Qjo0bppeo X-Received: by 2002:a05:6a21:7782:b0:16b:7f7d:8364 with SMTP id bd2-20020a056a21778200b0016b7f7d8364mr2111896pzc.58.1697814859046; Fri, 20 Oct 2023 08:14:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697814859; cv=none; d=google.com; s=arc-20160816; b=hpBQuGCTBLgJndytNxL1JWhC1B3RwC0GYerSi8KcAt/08UJjrbRv6n4XzRgL/Az2kP WQzkC5MWG6pA4KaBeJReBjMviuIoijHiBMePQnK0pbGMCoEQYPCIZqiIGvlfohsoSkWT mkF+ZKAyiWIHCorecOuGVdEJWwcYa1v9Ys0rfBsNa3KF93S0k+7mz/eG9g3rlG73A5z7 j70LeHbmI8gQQBYU0mvlek73Z/w7MgH+WSB70eSZyj31E1TY3A0n9nTR7h6fpjbRdUOm cNIX9VWxtBVAxtN6hXueSCwkPGL1aOvvkD5YKrCpQY8VzTeM/fm75KXjsjCn3NgFsWwa vRUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OGa5Sb5Yd3bKocaXY/zr64R6NWyKjWK7l9b5pyL/EV0=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=EZADhp+E1h4L3zWi/MQRoM+qV89u8iyaI0HFW23QOacqnOqldv3SozBBfJqnQyMkJv OmxioumNcIm67ZeIWEn0UwoLoHXl1fWzsCbKx7J1LM6J10vxhkaIHwyqCR9v9i4gWA8l PhOjG9xHfjm0s6mqkJVp2NM/3PHEpkraBTlSxNkBqT3NJZ2m5gcDlihduKMzDlp7UNpd e6VhXWm2QMzzUhuVTC18iiXZbvCl14NZL9K1r6ogHSo9kBVlFD7vXj6Y4t+f32/jGB/Y 57Mqr0FuCEPTdNyozWvdzmgflSkxRCYrvrtQ3aUbvOVovo7h8HjhruC0Tl91WaICIPlx AzpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VJBc3P0q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id j8-20020a056a00234800b006b4c1a2085fsi2138192pfj.168.2023.10.20.08.14.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 08:14:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VJBc3P0q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8570682D255D; Fri, 20 Oct 2023 08:14:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377679AbjJTPOD (ORCPT + 99 others); Fri, 20 Oct 2023 11:14:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377787AbjJTPNm (ORCPT ); Fri, 20 Oct 2023 11:13:42 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 236D51998 for ; Fri, 20 Oct 2023 08:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697814809; x=1729350809; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YaJcwdfsbT/u6tJs5uRbj4NUFmy4HkVgm/EwY5jjC6U=; b=VJBc3P0qpe0ByU1XgwpkB9U1lpThcFAqcKx2KS3TJRibXHjxW7Yn7DfM OnnCRHsSdYLX9fy4kl1QXmGRehQ8eewAahkip/118D8R4iHEfhAAksI9z IMLzSBy6o6zmBn8WK4FdEURQyLUcZ+VyMdsT4vAKxtZS4+9dCdxK72CgQ Oz4HVZlNzwrt/7LLNjhI7K6VapMcj8hjtY8gAPe/yt91X0E0jRpXZz3gh ksV/o7GLn4aCcy41YWx6kLoIJSbZk7X0ujTAHN2yDMucJkM7u4UVZgfsd EQBkdxj7Wkmr+2HQnAp+u7Sd4pDF3Hq+BWdzAymfPlCTkCyOL6dxbk845 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10869"; a="366742908" X-IronPort-AV: E=Sophos;i="6.03,239,1694761200"; d="scan'208";a="366742908" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2023 08:13:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10869"; a="1004634223" X-IronPort-AV: E=Sophos;i="6.03,239,1694761200"; d="scan'208";a="1004634223" Received: from dgutows1-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.39.237]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2023 08:12:56 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 50B4F10A29C; Fri, 20 Oct 2023 18:12:45 +0300 (+03) 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: [PATCHv2 10/13] x86/mm: Make e820_end_ram_pfn() cover E820_TYPE_ACPI ranges Date: Fri, 20 Oct 2023 18:12:39 +0300 Message-ID: <20231020151242.1814-11-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231020151242.1814-1-kirill.shutemov@linux.intel.com> References: <20231020151242.1814-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 20 Oct 2023 08:14:16 -0700 (PDT) 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 --- 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) -- 2.41.0