From patchwork Mon Feb 12 10:44:43 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: 199862 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2471963dyd; Mon, 12 Feb 2024 06:46:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXURXrPlzND2yV0npr6+WZBfT+KT/2dzOQgrxAwx/Hx+eLTnBXSeKs5xLVcwaz2E/nguqPEwHRlbVVua9EYuJihdVsaaQ== X-Google-Smtp-Source: AGHT+IH+PaU9BlS41qDaSgvnq3vOb/T0ERT0m4j3qpBwyUhzCkoRsSACkSXGNDfVCXZEjfPVkaPZ X-Received: by 2002:a2e:a70a:0:b0:2d0:cf99:a553 with SMTP id s10-20020a2ea70a000000b002d0cf99a553mr4184258lje.36.1707749188749; Mon, 12 Feb 2024 06:46:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707749188; cv=pass; d=google.com; s=arc-20160816; b=WwgyQ7jKBpxBtu+ysQAqEq/Cig75yWOPon7DLjiG0giMcAjtFAM7ZcFqfNYfDXqGiO TkaDDRTamyzkZWPN3a5nfGkHyAbmNn4iajqPLvQOHqmKsbxBnVZf5WmS4br9KV9fouHh JGgSamtlC7EcMGg/ZI7XoCVNTONiD9Nl4B8YrCVjqgR6uRnxOJaJDDOQmA496a/rx8rC EiJ4iGwftdjBohkmc000JdtTad0gbx+nUTHyaGXKcFHU3YbIObkAttoae+8Y87Fav+hH +PrzYfDdrDgwqMHsUQe5GK+Lqb3U84ySM0NvvDhniTkHSLbAtgPpM8Fyvhx1TCoe6AX4 BL1g== 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=GghSWHO7DZLH03YYyY3ejonZcbjIOkKJTpalz8/OcLM=; b=fNlY1/H4KHGVscQ9c0AKasMybllOjHInx9LwRT1PkrbxRkg/TPMeVOslXluHoqVrZW Lf8a3xZOkydPEZdIudDVUPF0ySsp091HlvOeXE6hNHoTJIJcmnF6bIeJZVrV1rC8oB1E hhxcQjXa8ourHoj1IXbVPdJeNF2wyY8UoO+7BWqvxLKKV7UrriIALIuGuPsCKySVNKWF ohOdqWtKwc2Rjsa01AjciMtue/lKwyvfF+ftrTpdJwINMJ4vFwkvPWTviGziQ0S2VTSt BVUULf3PQGjUTQUZ34B3DGHOyE4iUfGbpug3+iikfKFN70ih8VOX9NfnuT5wKwAzP1Uj zL5A==; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61356-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCWls3yFw5Vxsw9XaYCEcoPnwKVHQA4ST1R+45cJdXTRd6PklhPTFUfMSmht1/tucaaZcGi1vUqwZF3cRMc3eSvDIwYzQw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s27-20020a508d1b000000b0056156ce6d9dsi2746684eds.105.2024.02.12.06.46.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 06:46:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61356-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61356-ouuuleilei=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 6FE561F2536B for ; Mon, 12 Feb 2024 10:48:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18B733C464; Mon, 12 Feb 2024 10:45:12 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790704813307829950 X-GMAIL-MSGID: 1790704813307829950 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)