From patchwork Tue Dec 5 00:45:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 173621 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3134022vqy; Mon, 4 Dec 2023 16:46:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjA8Pf00Y92Ay9gyBz6Pt+e6gbCMrZDJMe36z63/V3LdNkV+6J+spJcYxdd/+g9YHd8ZGi X-Received: by 2002:a05:6a20:12d3:b0:154:b4cb:2e8c with SMTP id v19-20020a056a2012d300b00154b4cb2e8cmr3034043pzg.24.1701737216852; Mon, 04 Dec 2023 16:46:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701737216; cv=none; d=google.com; s=arc-20160816; b=UJBJYkTQEw/Pkk1MJ6fFrn4uYQTH5fR9JU14fw1or9nhP7srE1hGRupnwsnubEZrDm G0JNop8aTtkHbGsnunzVC9JEj+3FOxJ6gp9eOD3nFAj6B1ExgYO45/ZpR7LvZjFVuN3Y VoIE/TfM3TBhy+c+wLpoZKGmnSlxEitrmK+UFaiz/fYR8LI9GtQMUFRsLlQY6jzMI5HY AIRqbL05Y4nOKKHFZk5DCucyaLu+3EMuKfyH9Y3lDpMt4IQO7o78e7WXRAEGh6U3jrK8 KJyxpvGHpV99OK63sWt07GfAaPX0yD1t1V+UknOolMXGzCcR24VSDK39wGrfXksYROW3 XO2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OGa5Sb5Yd3bKocaXY/zr64R6NWyKjWK7l9b5pyL/EV0=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=uPrvlwUoJNkrBAhTnBwpaqGjsAJ1LyToVmW0z5NevEG9kgXd5DcTJBS7ij02TBYRfu ZA19tWjVVbXTwlru9JX/Wv2cDlhmQYeGsm15a/IWoj4fC2z0OsjYnN63zEi04mgcsXdB 05AAGbfRwbtEMh8eZeqB8kq3iQqOlzrla4ll0aTECC7QspmUFr+OPpIaMx6Ku4X2l7cS cPJmbnNUJssrWQVE7hjLKVTU4lz2LieJtsKL3Ars0aNtSSNHeF6YOmER+yPgKOiQyrdY 9JPXKjoUU/z0LigvmnMY49J76f60yFuTrh+L+W1WfY7y76CpyXn7mTp+HD21wzZWf+AE FsSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=F6IQpxEk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id bc4-20020a170902930400b001d05814624esi6020368plb.385.2023.12.04.16.46.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 16:46:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=F6IQpxEk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 184668048696; Mon, 4 Dec 2023 16:46:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376371AbjLEAqb (ORCPT + 99 others); Mon, 4 Dec 2023 19:46:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234828AbjLEApg (ORCPT ); Mon, 4 Dec 2023 19:45:36 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38CAF116 for ; Mon, 4 Dec 2023 16:45:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701737138; x=1733273138; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YaJcwdfsbT/u6tJs5uRbj4NUFmy4HkVgm/EwY5jjC6U=; b=F6IQpxEkhFTBIwCR8svjMWMRi3APMIdb3u1bGxLya4UaflqAsfoIwTWs 0fWnVzogu0i0zGjdrhB/RCXbmo9vuEEeAm0iuzSEihLybW4fnXewhrjSu 8/rQe8a1C1a/Y6D0jab+W9r9RieutvmvtoEozr7ItlN6lw4Di1nWjKy11 j5wXnkXAFHUfi2mdW4NftVNY8N7gQs14ViJb9BRbw4ALYfOuGUlbmwoZz PtSA0nvato+30k5YddLkckoog08DdLI3yUdddB7DqtrbvtObnPp4FY6PB HiZwF8dthXvVRQx33zWQyb3uOpgi9ZqnIgc48FNZqSoF8L5hKMNyZk2oG w==; X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="392688743" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="392688743" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 16:45:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="944067956" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="944067956" Received: from abijaz-mobl2.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.61.240]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 16:45:30 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 9FC0810A44E; Tue, 5 Dec 2023 03:45:20 +0300 (+03) 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: [PATCHv4 11/14] x86/mm: Make e820_end_ram_pfn() cover E820_TYPE_ACPI ranges Date: Tue, 5 Dec 2023 03:45:07 +0300 Message-ID: <20231205004510.27164-12-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231205004510.27164-1-kirill.shutemov@linux.intel.com> References: <20231205004510.27164-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 16:46:55 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784400803834486208 X-GMAIL-MSGID: 1784400803834486208 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)