From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 73DF22CA0 for ; Fri, 28 Jan 2022 20:59:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643403555; x=1674939555; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=koK/VhFGViq6NfT00njMUR21vAbvfWnplJSVKWqjHls=; b=cHgxCU2mOw1V98F+hTBjXILfuuMbunQGi3S7yH69nnTUVsT/bqhlFQnm vJD7KS15ODEhsIqFfpu4nhRAoAqNdmYKx7R4c+YvcX8DsBLEcb4uBucC+ Xp5VIhs2ujlNZg5cczfsoVwhB7pTHhkfWwZ03yK9YRW8e9Jo3G7dBLGRH cQ7HnwUD3pNE+qRH1dvAclvW7MdrkE1PwNkht+DRhc+S4FvKy+3W6qiGy wGzTljrTRtEPDQEEGAxEaAoAselmOTJMKxo6+JNyS30NcQdXJFIvGNeUc zJreM44X1+yNAQyGlWg9nD+FxKWCCzUClERItJzmGRL1APaKn4AEWwXrn g==; X-IronPort-AV: E=McAfee;i="6200,9189,10241"; a="227865749" X-IronPort-AV: E=Sophos;i="5.88,324,1635231600"; d="scan'208";a="227865749" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2022 12:59:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,324,1635231600"; d="scan'208";a="533622715" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 28 Jan 2022 12:59:03 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id C5335477; Fri, 28 Jan 2022 22:59:09 +0200 (EET) 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" Subject: [PATCHv3 5/7] x86/mm: Reserve unaccepted memory bitmap Date: Fri, 28 Jan 2022 23:59:04 +0300 Message-Id: <20220128205906.27503-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220128205906.27503-1-kirill.shutemov@linux.intel.com> References: <20220128205906.27503-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Use a bitmap to communicate the acceptance state of each page between the decompression stage and normal runtime. This eliminates the possibility of attempting to double-accept a page. Allocate the bitmap during decompression stage and hand it over to the main kernel image via boot_params. In the runtime kernel, reserve the bitmap's memory to ensure nothing overwrites it. Signed-off-by: Kirill A. Shutemov --- 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 bc0657f0deed..3905bd1ca41d 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -1297,6 +1297,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.34.1