Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2005937rwl; Thu, 30 Mar 2023 04:53:52 -0700 (PDT) X-Google-Smtp-Source: AKy350YG0+Tzlg5Mn73HWPP3r6GcRfpgWS5wXtrrQky2hyfOrKqY6tUuTuN/+FOcQ7tM0d7IwS28 X-Received: by 2002:a05:6a20:1585:b0:d9:a977:fae with SMTP id h5-20020a056a20158500b000d9a9770faemr2009024pzj.3.1680177231882; Thu, 30 Mar 2023 04:53:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680177231; cv=none; d=google.com; s=arc-20160816; b=MiFCL1B6Jq+BAFCknNwj+v4oGvsaXC0wl0Xgcd4Muo1bA/DFC1qs7VRQGG3HyD9AEm Onr8LQsPQfTRI/z2J95imL3W9XC+7PDnGPki/oujDUPle89hAlfvT6Jai2Cs/GANA2Au 6gXtU+5qQ6hzAuSNlAXQlEfxPwHGh1Wf+39ZqPqv6m8+zR4hpzhOc+AqZgljm/7po9Ac 9zlMTm4Z4cMPw5NLbHLjv/q+YuPhWWr8eIVyvK4BM3lnv7SovhMu4fqgA3yUESNMjtDq ZeXRhWKFC5ny5GvYgLixi8Ca1I6XsuP9JdACm5BvA5OTgt1U0lwkIc6my7N7+cnS7oAc 2oMg== 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=CDsQGJ5mVHwKQTSqTirUAmTn1KY5xyP0qi9c6MOAeR0=; b=xWMKDbllLersBqSz/uz1PslYL28VrB3XoY6NT3TznL1Iah//edwl9qk5JtFtr7ZAm4 lD+96DN0llH5S3iWhQlLCxJzLYoVk3k7yf1k7pPQIxRamSRJKeurmFl2WgOalwhbgTWs f4xa23iClLReiGMuO6xGcMINS9coJb8YM1wKprYH5R1XV9/vRd5AzdX2AFKvc+4F2aT8 ChH4BFJ2tbd9BxLRUev3N9XH6iDMob0aJaZqk6ZtFU0FHwGNMSDRGMQczFTVptwADROD gzILsh2UgVsaA7QLbQpZBTCnteEWvCJ3PWbE3Q57MtHS01yZVjGDtHrB0wXULJ9tRw9l B5VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=G3v8P3ru; 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 65-20020a630244000000b0051323b8a185si15299399pgc.811.2023.03.30.04.53.33; Thu, 30 Mar 2023 04:53:51 -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=G3v8P3ru; 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 S231657AbjC3Lue (ORCPT + 99 others); Thu, 30 Mar 2023 07:50:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231159AbjC3Lu1 (ORCPT ); Thu, 30 Mar 2023 07:50:27 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36BE2A24B; Thu, 30 Mar 2023 04:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680177026; x=1711713026; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f7/hrgLyEe7uCgqzPwQBAiXJTS6cTMMnuaKLYQlQP9E=; b=G3v8P3ru+eaQYI7MqNa9vb+Hy499tRdtoMOlKZq9wzcolQVJpqIHwEgb LaH0yrgdJTc3rbq+tzAm0G3G8KhCWNrPxmGk9y3HrsCamrqtyFGw3sOMH +qOa3/Xj8miI5t18P6nXLhoDnStt6l7bu/UiuEF6+Dmpare1Hj0ws11VH CGcIGibNfP5jJCGriwGOdIH/MlBzpnicwRMo6Li15/PlR/BQh3WgP3PWd NcKFglfpg5MvfcLUtQ2hkyMxK5RZVJEYY1y48MOpTb3NNSWR/4E54m53v sp9lNV0qRbFbnIfERimIFYTbOLovQVCB/qr62l2PoODEL68EkUmmewYOk A==; X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="339868489" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="339868489" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 04:50:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="1014401448" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="1014401448" Received: from ngreburx-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.209.91]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 04:50:17 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 49CA4104545; Thu, 30 Mar 2023 14:50:00 +0300 (+03) 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 , Dario Faggioli , Dave Hansen , Mike Rapoport , David Hildenbrand , Mel Gorman , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, aarcange@redhat.com, peterx@redhat.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: [PATCHv9 09/14] x86/mm: Reserve unaccepted memory bitmap Date: Thu, 30 Mar 2023 14:49:51 +0300 Message-Id: <20230330114956.20342-10-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330114956.20342-1-kirill.shutemov@linux.intel.com> References: <20230330114956.20342-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index fb8cf953380d..483c36a28d2e 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -1316,6 +1316,23 @@ void __init e820__memblock_setup(void) int i; u64 end; + /* + * Mark unaccepted memory bitmap reserved. + * + * This kind of reservation usually done from early_reserve_memory(), + * but early_reserve_memory() called before e820__memory_setup(), so + * e820_table is not finalized and e820__end_of_ram_pfn() cannot be + * used to get correct RAM size. + */ + 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.39.2