Received: by 2002:a05:7412:518d:b0:e2:908c:2ebd with SMTP id fn13csp349952rdb; Thu, 5 Oct 2023 07:46:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEhSqr6uQD1nf8oqylNy5nkXP+yiz/MeaMiQrv0FzWMhPZbPFQeltA0xa+dsRmP9U77otn+ X-Received: by 2002:a05:6358:1ca:b0:134:eb97:ea01 with SMTP id e10-20020a05635801ca00b00134eb97ea01mr5229045rwa.27.1696517182717; Thu, 05 Oct 2023 07:46:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696517182; cv=none; d=google.com; s=arc-20160816; b=IuP6fMTBFAORY/LGTgthBxtKnV4RdhzXzrF/4nCHB+dObaERlDG83hxOmxh8XCP0J0 3qlofgRQqo0Qp/w0dj8cqC0a8l7zNNxOUb2H5Ga61nezcigVUHJ/HdAW6y54USnTZwVT feW88bi2MiXEzS6GOt8BPVUJitXalZD8pwL87ceUDT4XNULoSIS5mvPRZz+Qlm1UcwJ1 qEWexbwDOfIkEe4JQ2CptyZCLEKog+PzvWvp25Xa0EMO3jWiiKT7C8TLO6H3Ok+j4VoW ebh1VggRnNYqDjprSUSBdXTxo2twnFkcJL4Twr7ZVuXaslczC6jKgfweYcNku/u2DgZM qXsg== 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=F1gpqSS/HYttK+doOKuW4yrAifo5qykyq1MCI9SIQmQ=; b=d2wJy/sP6/xJKXfkcOPyoQQsqZro08UrCo8Ym7GtH2GPNmeoToXxlNu/4hxHoPSbNM ba+bH+if65kph/ePFkeiL+LQF8VI0qZxRNMdy8qT/+YAv9PEfucRwydhusB5PlqUyi1X c2Wdvxa4gZzz89Os9F5FqLz9Pc7DmehDuYfcX+ES1zkFcxg6C+KUJX/bQ6tqYjAXD279 KxIz8C9cX5apZyvEOGBH2DxNaA5t5Kdu6ZP3gTGNoB6XUDWsyVui0YKU80rdLqi1WYKn 21+m+m+tO5WlF6kqoLiM8KG7jKfLKiCsfZVPB1uvdcROqL3pc7DG043L+ElXiSL6smkx YEUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Sl4v6HhS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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. [23.128.96.37]) by mx.google.com with ESMTPS id h66-20020a636c45000000b0057790a5a8e7si1544355pgc.190.2023.10.05.07.46.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 07:46:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Sl4v6HhS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 E054980781F3; Thu, 5 Oct 2023 07:45:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238302AbjJEOn7 (ORCPT + 99 others); Thu, 5 Oct 2023 10:43:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237271AbjJEOiw (ORCPT ); Thu, 5 Oct 2023 10:38:52 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C56ED6615 for ; Thu, 5 Oct 2023 07:04:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696514680; x=1728050680; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YaJcwdfsbT/u6tJs5uRbj4NUFmy4HkVgm/EwY5jjC6U=; b=Sl4v6HhSg/Jw4mIs0rL82RT8qaeN/pOSa/we4w+XEU5AaI7ouAMRsej6 aBUP/l/ZJgHrtca0A6yFS37LkrH2GvloDlEQCF0mugqrhY14dUm2mlghB jHY2ZaTxOLjRAq8MWJD8Ocjxp3dfdOXoQIkQZbYf7u98ehEa+KbjSQsgd 2l6vdeQUATLE82oGeWqI64KD6pc+w9Y2ki0ZnqQCqW6nXTI4ARiEcAnue MuJBeawBjl6NKpfiKJi9FVe8rOFNyqsYEsj7UIirYp4Xp2pTGWozvZJD+ jYq2qSU8Vj7xNfPmG6vHMMqng1VFjxVQ4p/CJ/56JpngcDovh5WkrF3Bn Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="382357583" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="382357583" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 06:14:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="817564326" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="817564326" Received: from skwasnia-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.222.71]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 06:14:23 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 7D68910A155; Thu, 5 Oct 2023 16:14:14 +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 , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCH 11/13] x86/mm: Make e820_end_ram_pfn() cover E820_TYPE_ACPI ranges Date: Thu, 5 Oct 2023 16:14:00 +0300 Message-ID: <20231005131402.14611-12-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231005131402.14611-1-kirill.shutemov@linux.intel.com> References: <20231005131402.14611-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 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,URIBL_BLOCKED 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]); Thu, 05 Oct 2023 07:45:28 -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