Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2532970lqb; Tue, 28 May 2024 02:59:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVE5N0pBPIVGRLSAOmfmKblJg+8BjXlt4KgrujoZ52bFLC5bQrZnURvHdj6q+HHcRaNeoCDQfLEYpypPLwqIWT6wZ7igXCK2jJh6PNyhA== X-Google-Smtp-Source: AGHT+IHnjntZ4l3qo9R2J+eFDHeKPEsRo71oU9Pxu4UNQaTFXxSEhP4bfP24CvNHljCuAUkGrhy2 X-Received: by 2002:a05:6214:5a02:b0:6ad:80d8:86c8 with SMTP id 6a1803df08f44-6ad80d88af5mr79612776d6.13.1716890379406; Tue, 28 May 2024 02:59:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716890379; cv=pass; d=google.com; s=arc-20160816; b=HPzG5WRNOQeUGmwD9FoWJNOPFaAqujadVLUYMMyyLTuNr+ko8jtbNesAi7fp6bHdH2 1+i1e2JurfRVaD5Xl36d7HIqNTJI7/eQ7rgHIhCt+ARxs63h7W5ZkkwhDUjXAxCBPS+I O1xMdBnppvLqYd2QnyxvmlRRpyQDUZ12/a4kma85xNPVCTFmeHD3YhfonSVkPGERIfZE U1f/D8uEKDKiNSO9uVRjuu8kz8C2kPREJilouTyOBoLC53JSP2ErgYkcA/92YeFfLY3B dK0513ers3b0JU4Xzisnpyf2YjYY6mdmj4W2lLhJFHA1e1OWS+jYM9pW2Y09t21AK/Bi DfwA== 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=xOA9M+LoKRx0dRmpyPNINT8/LsitfswehLxN3x5/knE=; fh=ovKGQAtVjTk/d+yrtY8HhWqFcBxdiS20rITf4pdsDg4=; b=n9EQEPDV1faO7xC9ey3xirk4bUV7rHvdadpNosC5JDtJGx2ynuSwdaoXUK68xyLbiH Px2i/jHIrEzrGW+G2JR7xTw5y9AIhlxOW66zrtxkBAagn1SaYRIWiy54thVAnZrz6KUW pLGMq4jRCn3SL26VzPYUlgDaFM4c7hiFkGkARpZqmqV/vnSNI+AZ35YrC5atQ+d0Tnpn AhZPV4rZqjFgGqxTHwbVUrYowdk2q0OjsI9s51SUKAu1gB0GhlDXYzHshC9+yE1T3j3n ztXGVyKWSNv759NT+Q0+CrzEX5iCpQ981tnPdhF5h5VY+/7lISMc0z2bHMB8WNJRX70d TRSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JcEGG3gx; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-192055-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192055-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 6a1803df08f44-6ac162b54d3si100024686d6.498.2024.05.28.02.59.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 02:59:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192055-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=JcEGG3gx; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-192055-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192055-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 5E04B1C23F72 for ; Tue, 28 May 2024 09:59:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33EE516F0E7; Tue, 28 May 2024 09:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JcEGG3gx" 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 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-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 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) -- 2.43.0