From patchwork Tue May 28 09:55:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 799926 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (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 16FA716DEC3; Tue, 28 May 2024 09:55:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716890158; cv=none; b=bXVfPdoJr/XRDxXMZBnTcqTyOcP/VmypSMyRzltiNEPz5vqBb0tIzt1S+EKgnXat8WduSHi7Ej8LxWCRknlkcAlXfKn969+Lot35uEP15By0IFPk+bGsw1nxjeWIV/JMk7NFilkwI5uhSO8ayyveswiOGOiDPOUUJ2f0vJcmaD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716890158; c=relaxed/simple; bh=sMf7Bj61UHDCBOlFd+domeR/Su8pHK5UaLOkIveDSIM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IMUsuwJcfy/3aRLNMIaK5bDRNKPRKR6hzN1AOEnImw/Uq1bJ2rmQfnV2mv1I/Mz++KV1VeWrjEAzQgWSbNXx2TWAmjA22eJmEBMYAioZVay+r54ZHA3k/UxuwUQztY5N2tI6Nz1+R97b3PhDCQVrVfth5LGBz7WSnfsoib9uSNI= 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=JcEGG3gx; arc=none smtp.client-ip=198.175.65.21 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JcEGG3gx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716890157; x=1748426157; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sMf7Bj61UHDCBOlFd+domeR/Su8pHK5UaLOkIveDSIM=; b=JcEGG3gxqOmNpWX0CHVAb96OO2ZWTn803VpRoWxEDAEKGSHzoeK2E3B7 cReGwFvHP7wpa3L0SQpCNUqBl1/kiYbBRWna/VuZ80KvLDgR6XRgShEDw cnvYqdXHkOFfNtmtWlpeVO0PuGsGBYeHSOPeT7cXuF5/NGzCpnn1OeyNU 9eS/opp+uQoCupfzZiIlo99DzVvjq/tUYfJMylcm/sodcfP04PxZcbqEt MrM80EpA99smjmO+AgO6wm92AELVfznHDiCF4iMsH5DeUqHxEC5c080iE vjIIgfQAkUfcun6E/n6y71l1jV1R+mfmVpffF+952NwvaN+o703y9LVoy w==; X-CSE-ConnectionGUID: oS0Y6Vi+QpWi+SiEwkS3uw== X-CSE-MsgGUID: KnYwV+lTRRm6rzmgl9Exhw== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13172223" X-IronPort-AV: E=Sophos;i="6.08,194,1712646000"; d="scan'208";a="13172223" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 02:55:41 -0700 X-CSE-ConnectionGUID: EqEtkPlbT76zqiPKdizCBQ== X-CSE-MsgGUID: oM8gh7F1RIm7vDlXkwhjJw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,194,1712646000"; d="scan'208";a="39984758" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa004.jf.intel.com with ESMTP; 28 May 2024 02:55:34 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id D10058CE; Tue, 28 May 2024 12:55:26 +0300 (EEST) 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" , Ard Biesheuvel , Baoquan He , "H. Peter Anvin" , "Kirill A. Shutemov" , "K. Y. Srinivasan" , Haiyang Zhang , kexec@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-acpi@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Dave Hansen , Tao Liu Subject: [PATCHv11 12/19] x86/mm: Make e820__end_ram_pfn() cover E820_TYPE_ACPI ranges Date: Tue, 28 May 2024 12:55:15 +0300 Message-ID: <20240528095522.509667-13-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240528095522.509667-1-kirill.shutemov@linux.intel.com> References: <20240528095522.509667-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Dave Hansen Tested-by: Tao Liu --- 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 68b09f718f10..4893d30ce438 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -828,7 +828,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; @@ -839,7 +839,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; @@ -865,12 +866,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)