Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2457807rdb; Mon, 12 Feb 2024 05:46:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVFhiiKJ5WdPLe8WqWhGTz0Mr6qiDINydyyyvCb0XR8+eiBVAuICAk3eO2/LCGiVJILhizAR/jnRZ5PSiWiv6mCDuWnBrPrpN62TjsMcg== X-Google-Smtp-Source: AGHT+IF0q7BIwlxoBb3BFF5CH4YM55/l93ESybJEo+7Jd+KEli5IUm59Si5uF1XSixoXcI6G5mWu X-Received: by 2002:a17:906:16d6:b0:a38:89a9:4206 with SMTP id t22-20020a17090616d600b00a3889a94206mr4609637ejd.75.1707745616157; Mon, 12 Feb 2024 05:46:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707745616; cv=pass; d=google.com; s=arc-20160816; b=h/AKFxl0NwPaMOMX5MPZLT2wWLzelG46KU6LJLsTifsSuIINuQ22k7LimcHJ5zzJgg pOVmzqg9mJ7c7rgEd+bg9DJjy4p9jsenlS3y87+ktCdXy0vrrdbk7K5Z/LthrGxApbBl gVBdSauWzkXBKBO4fvy+5EUR38H4ORg9KFD/m9a36YLl+30vX/4tRun06bzwB2iEY2BK syzYUzrO/pxRnl3gJl8/pqyjExyjXPLk4c/GaMKST+dBxYloQvoFSWgMJ6AlICZfV2s+ 2DTqejU6pA93QlWb1mjLS8s5EmRISHtcoNMZrA3iO2JvD2K2qGkU9mfZeiWt/Dl8ViAe SW0g== 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=VC8WdLgn07bikOrO/tMqv/jJgQS2FK/E49YIu2DjPmo=; b=SSKzTxEKYNqbbkSL8BpVQXtCMVjULJqEOMsSOinfY0g8c21cYT3ENmdLv8LbmY9l7O zszsVZ/ZJAdOZyF+Hh1++lEH7+7UMS9RwNz46G9hTPGHSylczEZQNZa+9h4dKKIiTIGC Wk44kV1HP0wqg8saBQ9L6nbW8XfHHgIY6wMlw3OAtEw2fme3AxTtaAwPsF1Su+6tFJQh +X7gfbfKwagfWkaq+8j/4FKpZmdnL35U6T4CNtZ0709lVZJbIcwqENNHZDhNm67hqcNb 0uzLYOXV/C1/LhQP52IPn2oANiNgitsZ6SuEZufTwVBy74WPeq04/CdRj83W3w+vxVcv sSmg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=C+I5uNVA; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61356-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61356-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCWeefL+3+xQ7fAyCqyqH7LAi66kKLHJsnEsiHkG1Qh0A6BQHdNE6vuSFNqQSni1uYdZvq+8I4tVNYY7E40YPogPCKMNY0r1ZqZQWgL7Sw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id xo7-20020a170907bb8700b00a3891d4fbd4si208415ejc.123.2024.02.12.05.46.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 05:46:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61356-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=C+I5uNVA; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61356-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61356-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 06D891F24C9D for ; Mon, 12 Feb 2024 10:47:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C6A13987A; Mon, 12 Feb 2024 10:45:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="C+I5uNVA" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 951123A8DD for ; Mon, 12 Feb 2024 10:45:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734708; cv=none; b=iaoK9FObhw/SB5DTCkGJSBkXR08unrfxqFrwI3f5dcqBEQlUGlCiwRIHS/t96uJMnGJ6O8U+zfw4pwwga3jc6y753hXp8y2jvI7CoRohE/yclYz+CpapYJboI62OG1b4oXAm9AHusq+8KdzUYU8qQXDCA7TZwaUryppj2noFWlE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734708; c=relaxed/simple; bh=9DcFlB+EMYNkp2N6OZv2c5TmDu3Stsj7JMO1CUBiP2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jNG0ncgijtuGLboizmfEsSyH0whWh9NPcGD8Bv4iSNK348GdGOwQhrUrQgBljRRqPb7y52xf5D7jGyVMyE2N/ecyLFyO87/rY8QhRtthNlnSVvKKsm5UWkNFXVN7Kj99d+OnEbikmVFj2MowlUnMjkNSbAAoL3jJaohYQ5iZevY= 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=C+I5uNVA; arc=none smtp.client-ip=192.198.163.17 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=1707734705; x=1739270705; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9DcFlB+EMYNkp2N6OZv2c5TmDu3Stsj7JMO1CUBiP2Q=; b=C+I5uNVAJMsC/ViIjKVgIRRGpTER8Oguy9rNsJzzXMWCTgPusyEojjfv 6unroMiSEBg5TcJjcKmNLek54uPjRcfCUJ71MWyiGSITFp4zfP2NRwHw0 y7BrbAeRkSudC8fbislLhbG6qmyE0DXie1J1FTadFo0uKXN5vzk5bjtc8 iDXgYVVuDmbLAmTO8H195U9CqeL6foR06umUB0w993kHx9bLgFpCZhE/y /IH47/fktMX+cmWgNTu4DgaZjuDBrIsE/DqAEujwb2YKqtDPs5SrMRVav bdZ7jeMZncywmFW3HCZL3aYB6ZlCmc0FlWHebZnH7p0Ry0JjC683Syu24 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1585079" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1585079" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:45:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035603" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035603" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:45:00 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 7D00E65E; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 11/16] x86/mm: Make e820_end_ram_pfn() cover E820_TYPE_ACPI ranges Date: Mon, 12 Feb 2024 12:44:43 +0200 Message-ID: <20240212104448.2589568-12-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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