Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2684801pxb; Sun, 24 Apr 2022 23:21:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwBrXDtFdENxg2GwkBTl092UVm82Z2STFqstq3FCPbPBq9QrdAZqkQsCGn73I+HTiFjRpp X-Received: by 2002:a17:902:aa88:b0:156:914b:dc79 with SMTP id d8-20020a170902aa8800b00156914bdc79mr16385983plr.138.1650867701786; Sun, 24 Apr 2022 23:21:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650867701; cv=none; d=google.com; s=arc-20160816; b=qtIVha+J0XeHKOWw+xPPDhwO2CpyG9/eDtm4yOebVhp33jqTJDLgXJhU8dxQW78QVZ ys4h/bMCZKeqep0IbG+hGaVeWDsMBI6gqJejy0+xLb7zHUYN5o1EhzE2+t1KYK0utn3X 9CYVVc9EmMMVayYyB1r7cD3q93AcTzuQTFOuWvBnJIMN0pHShdl3EzRp4zqZxB35gKfq lA/s6rNrJJcbwgXnxOJf9y9NeQTIAXyy3Yw59QcXBn3SF0HT9W/ZXmB3LY7jtFWSka02 c4BFrfNue8DbgTl/auDPn5oauScCZM3YSwjwYJWoc8Q2n6ouXTBEwyKxfj/Ffsuu5E+5 UDtg== 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=YRNVhv6mHLoPStgRYpv74M3EgOmPV79IS3fzkPwJIac=; b=VT33jauVNDEcA4Hgn1WqAXol045oL2hgS+OmrdHh6e6ifqlv6+I+WK/FFJSVxNv+42 YxuMoyxTTzGpM+cjRa1YIfbtGgLr0AOJDaopFAHPWoXXWdQIiiupprPh29jgB/+m5Tbi oU85XEv7bpFKMmqvyM2Zwq5AD0AtWUH46OZAsdEYfpyiA3jEB1NjprlCgYMiJv4z5iPh dae1GzrqhnXJhsN8fYYAWZdspcNdlAEUUsrJcaO419ew8uLKhiZuz1ijQrQnZBSijQnq gjk7zgKVbGo5eqAmI9oP16UzOUMphbVrdp1IMfKjtbQSwC5bK+EVS3ZfLrc/gNAg+0AT wc1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Mn2BW/5X"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e18-20020a63ee12000000b003a9f9442c75si16302460pgi.297.2022.04.24.23.21.27; Sun, 24 Apr 2022 23:21:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Mn2BW/5X"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234525AbiDYDoq (ORCPT + 99 others); Sun, 24 Apr 2022 23:44:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240716AbiDYDm6 (ORCPT ); Sun, 24 Apr 2022 23:42:58 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B79622F02C; Sun, 24 Apr 2022 20:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650857990; x=1682393990; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B6xQElVKXMmk7bVMoMJbz0U88Nts50RHxDgA813tPNs=; b=Mn2BW/5XwbM1o86DPiRSBW5QByDzIwAfqWC8eRSI7yrhMi8wgpv5Lo8T rC/yg0U3uENqLi7nc1s1Rr0/xmxKI8rNpyds6xJlToHLE63Jr0gpPLRLs cRd3fcQszX7U9623NmrBFe1/YidmvTz6tXO0IyMUiYrN4gPncqX11UdNu 6y2iRleZi0oYD9SF9jAN5AbA84tiTqK+0ja3vAGmfG3eiEEK+qDB7cXFX rvMO5Cwz+3uuelJTALiGXDCYKG4KO7YsRZBov2+6i5Yd8txZQaW+df+vg SS3Uf06EADhpSxPHc87o8VCg+dnXLvqjEqE6X5ukGssZBC4ViW/hHOmbC A==; X-IronPort-AV: E=McAfee;i="6400,9594,10327"; a="262727698" X-IronPort-AV: E=Sophos;i="5.90,287,1643702400"; d="scan'208";a="262727698" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.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 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE 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 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