Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2541918rdb; Wed, 15 Nov 2023 04:03:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IHowUvrU9weymUP0GooM1MM/88/h+z+QtaxAcfaTNuYuwGdk4kCmlJz/DktoVWghSNnc3U9 X-Received: by 2002:a05:6a20:a124:b0:187:651d:7d9e with SMTP id q36-20020a056a20a12400b00187651d7d9emr1659838pzk.26.1700049813224; Wed, 15 Nov 2023 04:03:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700049813; cv=none; d=google.com; s=arc-20160816; b=u/Z3mB3c8NyImfPG6I+eIHVn1AoMvg+HV2hF2DNc3OthUDCt9CtQDKcz4FkD/kp/U+ HayZ8nL6SmyKGRhSfoYCNJzpg+QnbpJxudxMyhnWkAAiPDE69Die+DnIwpb8sL5vcht6 gWcbIAkrlPiexOQjfGi7c92ZHmUg7xu05GvY90fZLNAA2ddIMAFYrrlktC/4MIemKywB a8256ByiI1l7PEcNnhSetlKb4eMA6W6ISLwut65DwG+q3V5ZZVpsRxxyGnH5t5OioY6I cH5HkiGfyMHVW06/tC4D4V62jgV7aU1/a8tZwKeL/S4qHc8yUsQwI3kOZ7rhx5ZeBY/v uKCQ== 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=zXQpU+QFWfA2hZpEWIgE5ak3hucjjHWT37np1WvSvKj3NA8hI5TWlAhac0qwNlHNaS bbrEeZQlxijiBQbai5Nu2CFdCOyGD4YqVl6bGmc0GpE56829svufjrfk9pTS29Ck726+ 5M6Bpb2K5LNXNAqayIMWyXqsynr0kvbasyxr0WHVYFDyjudDuS/SSRzMZ2X5HvYuzvs5 d1QVOazcWIOgNUg2p8A9B8NZh/fWN3ILMLiPa+8FKSLTUZcGnjozGVJBtSQaL/N6LUGD 7wSPuaFdxN4TEtjlWPDDEZV1TG9zTaGWoiJbwu4JoLAOkk56IbXt/VJj+mcZaZ/pnKtl iIfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=daNds7G5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id v15-20020a17090a898f00b0027cde38c731si14770608pjn.17.2023.11.15.04.03.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 04:03:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=daNds7G5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 0426F81668A1; Wed, 15 Nov 2023 04:02:35 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234980AbjKOMCS (ORCPT + 99 others); Wed, 15 Nov 2023 07:02:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343736AbjKOMBd (ORCPT ); Wed, 15 Nov 2023 07:01:33 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DBC0120 for ; Wed, 15 Nov 2023 04:01:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700049689; x=1731585689; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YaJcwdfsbT/u6tJs5uRbj4NUFmy4HkVgm/EwY5jjC6U=; b=daNds7G5p8w9gpWbYCm7K+pDS7MLwMIeT2w7dap9mzDsSLYVLDapt/xs T+Q7PKjeZ/kqexMZ0RVsvSc9qndeFMymxVJx7OX7S1MtNLCtJjvj/LKt2 5n047KrYW/Y87G44HHEwC/mOlbza0/OznzRK5aP8YWurZrChABLqnKVpN 8TK28WL/3AKwNkHT8X093V5b4nTlprtYPqLGXn44Ys3L5pyuqFawOez5L FB8vOQH9PnI1u6YZEC+Sg6rCjhTlFTu8MYEb8GoEF9WctXH7mIuDPm9K5 Z6Kkel7+VSy+fva4ZNEkwJQPeWwMV1qoiLraULwZmk2ssawcgaIGfSM9q g==; X-IronPort-AV: E=McAfee;i="6600,9927,10894"; a="394780488" X-IronPort-AV: E=Sophos;i="6.03,304,1694761200"; d="scan'208";a="394780488" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 04:01:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,304,1694761200"; d="scan'208";a="13160261" Received: from mituomis-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.44.135]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 04:01:22 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id A8E8110A31D; Wed, 15 Nov 2023 15:01:12 +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: [PATCHv3 11/14] x86/mm: Make e820_end_ram_pfn() cover E820_TYPE_ACPI ranges Date: Wed, 15 Nov 2023 15:00:41 +0300 Message-ID: <20231115120044.8034-12-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231115120044.8034-1-kirill.shutemov@linux.intel.com> References: <20231115120044.8034-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 04:02:35 -0800 (PST) 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