Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2183906rbb; Tue, 27 Feb 2024 13:27:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWPdWb1tIebrNZ6WpTzkOuJyAVbbfwZeTiWYI+nVOPZmm6kacFTWHRW/zOcL6/m1nmkgecxbSpeaD2DX5ZrCL50GsVbOoytgh8duHUpMA== X-Google-Smtp-Source: AGHT+IHvcwzBSy2Wti0JT8fOuTd3KBIgaiqDPSQczDU9K8PDxN7LKGWpqqX0UsIt+udCgXz++KAu X-Received: by 2002:a05:6a20:94c9:b0:1a0:9115:48c8 with SMTP id ht9-20020a056a2094c900b001a0911548c8mr3986074pzb.51.1709069270580; Tue, 27 Feb 2024 13:27:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709069270; cv=pass; d=google.com; s=arc-20160816; b=XwzbYcHeaTYbXZiejFJ9DpYnIYRkxfSy8/GZNtyw4gUu7nDQ9shabZ8yQzNnH3m0qG aNBY+VYidS/teer+jbFZkTmRsyGI3je0KCu1sjnEvIT7sGAjCdynxFB+gf7atNpCOSKy KOODfuiQcsdDPh3NVwzxA/0P6J5XsrydqdXS6Hz50t6v11PSk+pceIK4ehzfhjb6OZ9n NA1+QSKcr45Z5LhoCPFxg+mF6eBMF0HkBM6+7EOvMCOK53UUz/KPVQeOuYIU2Bgw9+1f cRDGfNd2BnjUFlULCwKqkaBS6acF4q59bsjrUN4h5THSEnw4Eiq76GYfpP8qa7IX7eo3 WM2Q== 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=KOY34Zvq74JO7RzGLfSWs6V+YhWX6Y0Zxm2OXufSBCs=; fh=yQt9ROgMHUZejH3hDVFamAWFXphHuLLRaOt+BxF1Gfg=; b=Ii/i0ktC8X3wTVB4G9qMlCGYuWgstbSWTnpE7flsiLSp9/+atJqEifiVb7dm3+nc4p LV7kfc9USir0UpZeJMEm30R5BpCuGunKKa39+dgRb/pdwwPV4ip6calCIfXnSDAKXQwY KVTjgo9nqQQKdM7sKO9rRfreqieqfKepTZOXGHaZuRsNLsiWGcnxnrJUIJJ/oUcvWkMt k82+tFK80OcNuwQpwiuU6iKcokRmxEZGuvcjT74O47y+KhcSdEtOTyPD6eCoGPzuTbuH Wm/dMqqgU8Q3qKkkTlt/cdH65hixwtAZMCq1bY0FJ5IUoMot4KMx4du4JTrGsh3tWEEl hN4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=d14EV88l; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84044-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84044-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 136-20020a63008e000000b005dc7f609bb8si5985555pga.644.2024.02.27.13.27.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 13:27:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84044-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=d14EV88l; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84044-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84044-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4A04629146B for ; Tue, 27 Feb 2024 21:27:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E5B915A4A6; Tue, 27 Feb 2024 21:25:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="d14EV88l" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 A1C2915956C for ; Tue, 27 Feb 2024 21:25:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069119; cv=none; b=hjoeuca9ip3JRJpG8ftBtM2E1GAtFcAG+oWdlyYqPrwIetQWDVTbL0MFqUpDisllnX3iYCZdgtTIxXXp8fRwgtNIK00VLdZCpr94z2mXqMRyZ+ErWZlxZGfk43pSfUj49lUQR1D6cSd5K0eO41fykZAKc0nSEqGjKtkP9tiJ/ps= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069119; c=relaxed/simple; bh=R/jnQJ7PA5+pcFQcinQUmyRlg1Ef9fKzEGnFbhwA+qE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YZinVr64prEXImIYtaOGZoflRzzdK2Q2LsYVcg4DNjOfv2/JH8iNsn8Gqb+jr5l9G06vX7lv55W6c/LygFzKU0iwTd7IAc83lmCp6lMn5KjIPhrZNABcRuQWfwku7bgMOItRucR1YVGRk2v1Jnv3ghpFHkbYh2XkomJY/89WVxw= 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=d14EV88l; arc=none smtp.client-ip=198.175.65.16 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=1709069118; x=1740605118; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R/jnQJ7PA5+pcFQcinQUmyRlg1Ef9fKzEGnFbhwA+qE=; b=d14EV88ld00Sulgujh7RLzaDyIjZZMRAe/LxaFg743yl50l/qfFAPkoT 86R+Cslc3MM/nXOtze3TbSo/2CNDLmjLoP5oai/Phr9VpOTrWLfGwuWDr uIL2HLgogZgx/MVgDW6x7KGyZFvAWF6KEMVFtgvca1azjR3naML8WnAxu vnblSDThzf+wi54HUy8epX2ECL4Iac+uTKNMACaS8av613+/EgEZJROlg lyy8jIA/DgHIfzgmATbjbSMzQShOksRQNysq16DLrWGJUiFuwBizuWvaV YDWi99jLtGapyX+l8HHmo79V7aLfRC5ABKI7Bc7H50EdIpaC4RLszfGRG w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3567071" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3567071" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032922" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032922" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:25:02 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 720C6B0D; Tue, 27 Feb 2024 23:24:56 +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" , Dave Hansen Subject: [PATCHv8 11/17] x86/mm: Make e820_end_ram_pfn() cover E820_TYPE_ACPI ranges Date: Tue, 27 Feb 2024 23:24:46 +0200 Message-ID: <20240227212452.3228893-12-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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 Reviewed-by: Dave Hansen --- 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