Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2092594rbb; Tue, 27 Feb 2024 10:18:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVB8Ue5RhrqFM9ngxflAARZ/EQea7zw2x9XYDdynS8DxKfqJNg2Jx8V92NO/dappLXEtc/pTQFXtmIHZbDAn26LXkBrdIPTFwJBUX69qg== X-Google-Smtp-Source: AGHT+IHkF4cm0mLH0k227bTT9712Lh5iN0AcD0ogEDKROgO/TkEYY34ipeZZ+tptvvdNjmpW/6Fs X-Received: by 2002:a0c:ab12:0:b0:68f:52b3:57ad with SMTP id h18-20020a0cab12000000b0068f52b357admr2323123qvb.46.1709057891331; Tue, 27 Feb 2024 10:18:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709057891; cv=pass; d=google.com; s=arc-20160816; b=t8ALV0BmcDpO2QDQq/2abufXR097sc715zDiosDpfIU7vSQx3rBU5hAKEpChr+LvoH umUcaCeFqqJ3tfDWBm5oRulCCuA+8et/MmnY0LMAfIRgftbHBwPvjyNpYx9bFC6MHnIH 5+G0Zum6MHjvf6J6XQKY/9HEDEQuhNBk6dg1H2sHBot7lKvYMs6npGJSN2qCqnSWESJ0 jMJqIFfOlxDKRJk9wvX4SHoPBBbDN+1u6ZOn+4FSOpheFmQZIW21Zn58/98jU1irWwOI NJQnyVeW27YDTwGhlQx7R0dDEVu4ImczYMVBd+zQM/djIS5OUEC9Dbmdt06O/K35m4pU Nx3g== 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=eyDEDV7I5BJA/vzdWvBvmNXDjDjlE4LAvwV74w2Mhmn2E/QNzKty2ncDr63ZKRDQWK +TIzphfdPZX/vm8Xc/PPPOD1/77DyY9Yy7MFVwQEVO5x5/6285TTpdlhKN2t5yFzmuL4 EYqs/9PzrIfK2MmXq6+FN017IJYZPs9Ieuc6QNOWPLU1BEFa/GOclZEwP5PBDnOH2+vl 4lBfR+A3PbJgjVJySzOFDyPHU/v/O+E3xNutQGvEw6KBfWR28ger+wJmo2BZ2ego8mHO BdUdBlgLktm4IqWMSP0LiuGwIug7Ki8kLB8JRE+7d5mExEoK9QpX71P9/pU4+cbBrnWR Cd3A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QrnLl6wo; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83815-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83815-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id kl23-20020a056214519700b0068f01e212dcsi7791589qvb.324.2024.02.27.10.18.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:18:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83815-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QrnLl6wo; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83815-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83815-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 531441C25841 for ; Tue, 27 Feb 2024 18:18:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0B741487DC; Tue, 27 Feb 2024 18:17:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QrnLl6wo" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 9065F14830F for ; Tue, 27 Feb 2024 18:17:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057822; cv=none; b=DsDOTcbW2mBUA3LL+noJRyf3z5+8FxpQUgsIzkxzEA7dceGmcPYom9cAZZVyW8NiGXYiYQcNGgIug2zHw2WKVRpNrrCMu0by9E3HYD0lj+D98d0GM83tnRrAy5wi154fJEi4+ByILc1EQjx4xTHcBf29xtg/z/Va5Ge+zKaMZ7A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057822; c=relaxed/simple; bh=9DcFlB+EMYNkp2N6OZv2c5TmDu3Stsj7JMO1CUBiP2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UK4QMKvxnSQZfMqH1eIpPxfnFhSpvgMFG3oE5eKun7ptTwW5q4K/1u0DekiXAGQQfD6B+DPjpVJ2somEoMtSREOno3GN9h6CTV0B6thOdwdOkt5IR0csguexo9QbTTrwdJMTw1HFIKnaN53MX4tO80DCWSI2zKH4Y1lXUOg+jaY= 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=QrnLl6wo; arc=none smtp.client-ip=192.198.163.8 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=1709057820; x=1740593820; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9DcFlB+EMYNkp2N6OZv2c5TmDu3Stsj7JMO1CUBiP2Q=; b=QrnLl6wo/nWJVEO3+WyG7XtARE55HsfWFKBZ/IAyJa5jlFKaghK8O46a RdoHtm94wuMVe4e86J5V92r2tgTvuagdHsZJdpV3VwAqGxfpVKejLtCBU st/wAlczEHfI4AbVSyMc2JgcPUrgyGclLbslbLyppYa7Hp5S2IoyyBlAh /SMR3fTwh1xtb1ZT1uIUjyPUmCU3GCc+GzxAHGQGfkodsuSjUxvze/g+b Kln8P0hRKBbAYK2PKlMAKncRCm4qFXc36rK8Zw6yNqu4gX2Jih5zQFXe9 wbOXXy3AGmy/TEwoJh6szwtb0klEpDuMtCQ1XxLD87FhbWgjarJe30Cdu w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966113" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966113" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 10:16:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032729" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032729" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 10:16:26 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id CBF8D9DB; Tue, 27 Feb 2024 20:16:19 +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: [PATCHv8 11/16] x86/mm: Make e820_end_ram_pfn() cover E820_TYPE_ACPI ranges Date: Tue, 27 Feb 2024 20:16:11 +0200 Message-ID: <20240227181616.3032032-12-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227181616.3032032-1-kirill.shutemov@linux.intel.com> References: <20240227181616.3032032-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