Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp113296iob; Tue, 17 May 2022 20:39:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxX7iHa2/0YIFvNig3GNwgFSNrrVnzR3K+EvQD6jV21bRuB5XMUbMCp5c4wc0dNfrD38jSz X-Received: by 2002:a63:8bc4:0:b0:3ab:5ff6:c4fb with SMTP id j187-20020a638bc4000000b003ab5ff6c4fbmr21797492pge.375.1652845182858; Tue, 17 May 2022 20:39:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652845182; cv=none; d=google.com; s=arc-20160816; b=PxnLIT/kYRwZ+RB3y46duJaDaFIISA+MeH5k/sqT8Ft8nBU0MtcEb+wzEUskdcRZkD Us7eXR3bR5/wZWplzCCyMPfY1J54VjyLb+2EPOT38zAtyWsa5F7Hl2pUWs2PVhCFZOSB 38yINrx6CPgFsif41+XljEXaqhgthmhqd5Dt0o63Aa0vDplC9MU5W0kO6OWt80E5bqZs dKY+ZVaYbbzZA0iRx4vhV1VwvlTFIVtzPX/q3vn6gPT7YEc1lBdpTMYHjWMoUOxtj0+Y /AJJ3doHTqKq1hMOfJ5YXJVn0EY09oXB8zhlHCha7GUAoSB7LMk8Khzj8v6j/ITomigD 0eAQ== 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=lC3G4n0zFqgOUruBrn2FFz4wqh1BEanTgj1uGK55NL0=; b=XBE/mUsTKA+1FhmbSGK5c+0483aHS/quFon9I5+qmWSTnGat8MZCnZgZuiVpQ2fF/T 9YJ8bUIIw8aOvBBoOkO2nYV0FycUs7ppL8ht/ChS7F5/8V3E5VwCOMmtsrQBhRHZh5QG CKUAwC9FGYu/vkyOSE6rrfrW/Q2uy74umAWGUxii+NL1TVeh5Q6TKrO6IQ7Z+LDf/jvl mpHBn0BtgS0+G5GObfasxfRBmmNBQJsl1+m+DwsHBOPhgRvS8Hh9RuAfpuEt4XX8x+hM CsZUCMmsuZNfzstMCxuiMcTKSH0dR8uQSpK8iSAqnvPRFD2wOwpd36eBHUe4yx/A56zU JUhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=D9ByoT0n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id o3-20020a170902d4c300b0015ed92d19adsi1577836plg.42.2022.05.17.20.39.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 20:39:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=D9ByoT0n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 816076B081; Tue, 17 May 2022 20:28:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350236AbiEQPfo (ORCPT + 99 others); Tue, 17 May 2022 11:35:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346491AbiEQPfH (ORCPT ); Tue, 17 May 2022 11:35:07 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E3384132D; Tue, 17 May 2022 08:35:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652801706; x=1684337706; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Vt7QSmHfxcGQwi2CPob9vBQysbMDXN+N63yj2aSmEdc=; b=D9ByoT0nD+tEvppwyoVkfoTQrkn5ceZ/PIdMisNTxYbtR9yaQQmNil/r q9Vl9isVjxY/6b0a2Nlyy8+BM7GZtkVVybZ6zqP5ZgZYgp+Vsp8GELgIw 3tDkx2K5LN4Nsdxw8NIkV5fF4vBNAzgXKA00pHIvJ4FEO0IjXzWVZ73wo 8GUBmgboumzUaXucU+H0O8y4FrhISphXJJAqvZA9lknEqT2xeSpCNo3IP A6uwCNsJPOetZzhpEPuxP15yPKLv46AA35/H5RGbbxAgEf0wVTXNOKRNy Kw3C5AApZlK2juG1Bg/tBspWrDffQ1/TbHS+BiNtYxjzFrU7bhZiG8ebQ Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10350"; a="296502079" X-IronPort-AV: E=Sophos;i="5.91,233,1647327600"; d="scan'208";a="296502079" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2022 08:35:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,233,1647327600"; d="scan'208";a="741831016" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 17 May 2022 08:34:58 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 979578F9; Tue, 17 May 2022 18:34:50 +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 , Mike Rapoport , David Hildenbrand , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, 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: [PATCHv6 07/15] x86/mm: Reserve unaccepted memory bitmap Date: Tue, 17 May 2022 18:34:36 +0300 Message-Id: <20220517153444.11195-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220517153444.11195-1-kirill.shutemov@linux.intel.com> References: <20220517153444.11195-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 to accept memory both in the early decompression stage and during normal runtime. A bitmap is 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 throughout the boot. The bitmap is allocated and initially populated in EFI stub. Decompression stage accepts pages required for kernel/initrd and marks these pages accordingly in the bitmap. The main kernel picks up the bitmap from the same boot_params and uses it to determine 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 determined 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