From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE217C433FE for ; Mon, 25 Apr 2022 03:39:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9ABF76B00BC; Sun, 24 Apr 2022 23:39:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E5BC6B00BB; Sun, 24 Apr 2022 23:39:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70E3D6B00BA; Sun, 24 Apr 2022 23:39:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 5EA6F6B00B7 for ; Sun, 24 Apr 2022 23:39:52 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3906527AC8 for ; Mon, 25 Apr 2022 03:39:52 +0000 (UTC) X-FDA: 79393997424.10.AF0692C Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf15.hostedemail.com (Postfix) with ESMTP id 9378AA0034 for ; Mon, 25 Apr 2022 03:39:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650857991; x=1682393991; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B6xQElVKXMmk7bVMoMJbz0U88Nts50RHxDgA813tPNs=; b=QTUZ9IyGJhzNpV/c7qA0QsZG9tmf17Yp52w6x7a3qGto6/dzvWl4r73Z qnB0j6ATzf6C5RXmSbDYTGzFCU8J7zZNHM1BDxpxuw1OshfFITt1ssndv 4FNv05vC5WBg5cVkDIXPjzQ+yBRhUM3NAw5X1x/QSUcOPO3ls5egTDSL1 duPtgoklJpFDnMt/H8+5DzYSMktzktuyEPZYFKnyXv23ChJa3vMVrnaF0 kdL0IqraMSmUNOyYhBBGN0vxgfGNhAgACIhD0Hn23X4NM/JwWZTsYYJvQ o8nAMJ0m4JUzue4SgM06eiPF5dR1wTIVxBZwnXxWpRZWebpvQeCu9oXPy A==; X-IronPort-AV: E=McAfee;i="6400,9594,10327"; a="265294812" X-IronPort-AV: E=Sophos;i="5.90,287,1643702400"; d="scan'208";a="265294812" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2022 20:39:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,287,1643702400"; d="scan'208";a="871799384" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 24 Apr 2022 20:39:43 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id DC3785F2; Mon, 25 Apr 2022 06:39:35 +0300 (EEST) From: "Kirill A. Shutemov" To: Borislav Petkov , Andy Lutomirski , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel Cc: Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Varad Gautam , Dario Faggioli , Dave Hansen , Brijesh Singh , Mike Rapoport , David Hildenbrand , x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Mike Rapoport Subject: [PATCHv5 07/12] x86/mm: Reserve unaccepted memory bitmap Date: Mon, 25 Apr 2022 06:39:29 +0300 Message-Id: <20220425033934.68551-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220425033934.68551-1-kirill.shutemov@linux.intel.com> References: <20220425033934.68551-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=QTUZ9IyG; spf=none (imf15.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.115) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9378AA0034 X-Stat-Signature: t3asksuhpns5ntekamktj99q5q3itz76 X-HE-Tag: 1650857987-792154 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: A given page of memory can only be accepted once. The kernel has a need to accept memory both in the early decompression stage and during normal runtime. A bitmap used to communicate the acceptance state of each page between the decompression stage and normal runtime. boot_params is used to communicate location of the bitmap through out the boot. The bitmap is allocated and initially populated in EFI stub. Decompression stage accepts pages required for kernel/initrd and mark these pages accordingly in the bitmap. The main kernel picks up the bitmap from the same boot_params and uses it to determinate what has to be accepted on allocation. In the runtime kernel, reserve the bitmap's memory to ensure nothing overwrites it. The size of bitmap is determinated with e820__end_of_ram_pfn() which relies on setup_e820() marking unaccepted memory as E820_TYPE_RAM. Signed-off-by: Kirill A. Shutemov Acked-by: Mike Rapoport --- arch/x86/kernel/e820.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index f267205f2d5a..22d1fe48dcba 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -1316,6 +1316,16 @@ void __init e820__memblock_setup(void) int i; u64 end; + /* Mark unaccepted memory bitmap reserved */ + if (boot_params.unaccepted_memory) { + unsigned long size; + + /* One bit per 2MB */ + size = DIV_ROUND_UP(e820__end_of_ram_pfn() * PAGE_SIZE, + PMD_SIZE * BITS_PER_BYTE); + memblock_reserve(boot_params.unaccepted_memory, size); + } + /* * The bootstrap memblock region count maximum is 128 entries * (INIT_MEMBLOCK_REGIONS), but EFI might pass us more E820 entries -- 2.35.1