Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1094951rdb; Wed, 24 Jan 2024 04:57:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHTKzQ/bSJVI1jXl8rnicml/ujYZI8tfQJLTahILspv6jbwCSGGGhH9efwS1ujE+ohENiJi X-Received: by 2002:ac8:5cd2:0:b0:42a:556c:b03a with SMTP id s18-20020ac85cd2000000b0042a556cb03amr2197278qta.1.1706101032236; Wed, 24 Jan 2024 04:57:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706101032; cv=pass; d=google.com; s=arc-20160816; b=z1B9YZenMIonza+HdAXlyVsjXjbCpaPLwcl4nUvtgjrZ0UHAwUvHw85HTtMR1qSFAE aGGUq90OFW9lLU1O+qPX43wXaqjDAvyxruMSSHlYyQbv5vb201QDeLFO0TYayrtM6UPO B5PLcd1MnZaxCmQ84bazNJuMIRx0GlWhcRKZoJe6Bjl1d4FSN6j0hixHx811f7kbxnbW ELO8HFtP2h6LMhDIGi+m6ER7mZbCYsiFqbi78U6I3gFexri6QRZBMJcuBwABUl3RCUz6 KAsaDKxHLXUlG83aiAPgX7RGcTDjb98wSZZMvXVwBTHFJAIBVT3AZORrWeJLUiyA185R c+dg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=PxBuA3tza228VpHxq/8kDNlnhjjwxZOy50g367z+tN0=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=L7cZJxSjpDyCicq0U8GHN3MbWOFPgkKx7V7xcLkOJ9Jl3U1ibl3l66Dc6/F9EDSJ+N LUVa41lSWWKFMFAJ8FE3v59nnj82j/UmQ350DU7fVEuH+7eOMVzW6anRVIFOl3yEfpR3 3VUVR42ArdLlO/RMmBjqUpaHWG+f+nV5FjfsEK7ok40rVYuJr/rFsdoRjnAukKOJjZkM nljlzvrSF15GHQvHZHjn5dBchZR70nXB9JPEd3Bjl6w0NUAO5PCHOCEVwukJYDAsjDp0 mkJvj4qNs6gbxDGM3Dmk5PauEVA+84vb2NZvL/ppG9JSBhqZvRmZD1hI2IsPCWStdvuI cXIw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Pc8TIJ31; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-37026-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37026-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e9-20020ac85989000000b0042a544967besi2816830qte.456.2024.01.24.04.57.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 04:57:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37026-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Pc8TIJ31; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-37026-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37026-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 897B61C22F3D for ; Wed, 24 Jan 2024 12:57:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3BAB777F19; Wed, 24 Jan 2024 12:56:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Pc8TIJ31" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) (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 1C7BF7764D for ; Wed, 24 Jan 2024 12:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=134.134.136.31 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706101010; cv=none; b=UkyNz8dQl74V2+DvIjnQAH65qaNdF7KxvsZJX0vxNBvHLEuwvFPuHItxC8sf+iKv56hI0e6kSZGxRZiFMCMRN2ow03EGO8yX0ais/g6Cg3cIGUS57UBbTzwNKbck3Kzq0QD1JGAXbAN7448Nb5Eo2m1jCM81DEvHjN74mc5GBl0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706101010; c=relaxed/simple; bh=9DcFlB+EMYNkp2N6OZv2c5TmDu3Stsj7JMO1CUBiP2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZWWLcs1Uqlbv/n5NprB0IrV2xhy7IXUU5OzpfLlGIkjZUlM971zWCGj+9WMmuUl9nm+Pk+gmfN7X/7TKAPVYgX/sepLw85RefQhTugerPdayE6drZkjpNSaMrvRZWrNjns82xYP4v4RVlRgv/yOrt4rv9XeAOeyRDret7fkxDDI= 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=Pc8TIJ31; arc=none smtp.client-ip=134.134.136.31 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706101009; x=1737637009; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9DcFlB+EMYNkp2N6OZv2c5TmDu3Stsj7JMO1CUBiP2Q=; b=Pc8TIJ31qVbah25xFEwGy7iqcsZ8H+iRL3HJ5ywgFdVZn8CMadZJtypS RPDuhLL+35OBcnNuGUGBfCiPTbgVkU9oMPhx4q7hN9yPNKVThCVlPar27 f0IRQn85wvTuMMpjj93AFID6y4Y74rilNJT7+3HXqps/NHfEjH+/+ENpj sIVzSDyDwsM6RKdRJAM8i8x9mGlswxmbB1W1rDbAYf/+Af5pnZHUA+V7K rLqJxCcE9R8T00Jg6XT4bJR1CgwuFATq2hxn3MH13gjxT6oguZMo5R1Eg ngGFuNtd/RHyM7qlp9TuKKZoLh40pcdhfC1preXWqsjBlGASpxPc3pdhc w==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="466110045" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="466110045" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2024 04:56:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="735924057" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="735924057" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 24 Jan 2024 04:56:40 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id A7DA89EF; Wed, 24 Jan 2024 14:56:02 +0200 (EET) 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: [PATCHv6 11/16] x86/mm: Make e820_end_ram_pfn() cover E820_TYPE_ACPI ranges Date: Wed, 24 Jan 2024 14:55:52 +0200 Message-ID: <20240124125557.493675-12-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124125557.493675-1-kirill.shutemov@linux.intel.com> References: <20240124125557.493675-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.43.0