From patchwork Thu Mar 30 11:49:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A . Shutemov" X-Patchwork-Id: 13194076 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 9D96BC761A6 for ; Thu, 30 Mar 2023 11:50:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D888E6B0085; Thu, 30 Mar 2023 07:50:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3BB86B0088; Thu, 30 Mar 2023 07:50:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B63A06B0087; Thu, 30 Mar 2023 07:50:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9A45F6B0083 for ; Thu, 30 Mar 2023 07:50:40 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 61DA61C65B4 for ; Thu, 30 Mar 2023 11:50:40 +0000 (UTC) X-FDA: 80625397440.29.6452712 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf28.hostedemail.com (Postfix) with ESMTP id 47E80C000B for ; Thu, 30 Mar 2023 11:50:38 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=hhOGEnxA; spf=none (imf28.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680177038; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CDsQGJ5mVHwKQTSqTirUAmTn1KY5xyP0qi9c6MOAeR0=; b=5OKePyWNg3n9CxZJQj4eReXVsDzbklJkDKlKAMQFAGN9aknCbxdtI9eXVAH1c8zrTJ7xbv mb4d6PB/bka15zW7O6D+a57KWQLFv8cvRJdPtDq+2qR2KV49gqOmvF2pm9kc2y1V7HRXm0 tqryxZXX8pJjNzjM+RXFUQathyam1Kw= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=hhOGEnxA; spf=none (imf28.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680177038; a=rsa-sha256; cv=none; b=MwOsAu6oHljTZA625pyQrqnOL4kE4KtISlyeMMMY+E2jpS5gpAkseGNMyoxySlanzkmrQc 5etDl9pBhFWPXO4W0sT1ZoM9btSe+OW/pJT6Kj0TdmeovQnY4zk0VxCkx7O3MJW370Q8EY qa5mWvQ/bBhWhSXEvmhsUMWuzDik/kM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680177038; x=1711713038; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f7/hrgLyEe7uCgqzPwQBAiXJTS6cTMMnuaKLYQlQP9E=; b=hhOGEnxAPBygVCkJZvrxEbuW02eMt60pJNw3LbLcv1yv6Cbzvyr9EVVl JmabqcK/rl5DCEmCDx0WXMmbUqSVErIQiF8goH8GDQHESkhih9/sGEoZ0 Zp4w63VuamvHD8NjJzmUTaZ/Z78orpci0gSHPvz0uxAZHLUQmyOD6sy5h /aYx2vGlzgNZy9b1d6KRVjW0WyUaVGnxVEMRBtKParpGf532o5tqXXZ6Z qgb+8PkFl2J6UMaBIPA0RR7Lmrj8/cKmpnX6eif6vRJnq+PJlzfxrtoDd 2Dp8F0cu5HqW8EU0wfQuY2Ye/cusjBKgFpgx/yfWlOel0++eUpDmck6Aj w==; X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="339868488" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="339868488" 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 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: zsaaq3mei53bnqnfxca75uhytn39mmfp X-Rspamd-Queue-Id: 47E80C000B X-HE-Tag: 1680177038-891458 X-HE-Meta: U2FsdGVkX1+ZiHx5QvFT9Qk+gAg+7a0QKDMNXa6+DdMiPuKx9RTv+8YE1f3wFJZt+lXnLj16emjhRCXR3l5DIry3jMzvcH1GNPNmoJoYmiPbWYgfDa2QZdA5GDUrEiqjJr15obyXpL2NCaergIwhsPq6/IvPMWrqxokimt6vdxXxx6cE9nrAzfjr4sCaUrFaKocTNKhlvDCx/jnKtoLSGY+U0lqhB/ZOZX9l6ZKrHt34MhX4/pPGdrRdrq7PCbjp2TiqRA6YxZV323P4UTNoXwiheY8rpgKSp90H+B6U133TwNzlLj0Ue6uNxZ/Voskuqx6cz0puq5nusFfvTPrY+McHKzQ1Wu+9lDt3VrOoFuDun2NQHYq2F+bsfJmNDS1O72BeViP2FY9/cmdao8Q89v98VIVpR0GFvJGiXKzTo97b1oaDkS4fVjaLKW9vkaRCRdPvl3yuctahSOM6gQ9jRoBl7z08HabLdp8qKBO6j9yYujfJ8F/BqAu//RuBRNPenf686ckLkgUaBoCyfwnzQ2ZOwn7k/f8jfSEdt8xFdz53IRLarIL9C70c45W41RN1sx6wWm5HdZt4JEvT1GW1J54ciW3+oHM4ZbKxpEItWuzS3YPllew8c6LMwalyeczbWBiGsDkxwagUnugeS0dXQvWeJLLDwxNu4jYdOERN0h94i3vYFD9rk5C3QuW1ryXHECDuusDqqnrsKOPMY1qkI6sLv+/IqJhXbrUXpT4iDFIxCLWYe0Uqv0+mY7ZmtNgThqn3s0ayLWkFVjppW4pvtMOzza8bFy8rBaP2f8otVZ6wxkXuBgL2/jdFnW4V1oEDN5ld5bZvb477QMa8KbyxWa5wGMQYdjgP8JztLeH2nOd8rzVUkBez2A1Am4vDm+T+rpCan0Cd4z3NN1V+VFXeoQs0bx5wogBbyjH6b7KognO3rLlclVkMEmufG6rmzLyOYVGQCLBufuBIUYlLren q1BqbCWh knNj/77pbS7hd6CeNohYYv4ifJyPn5reQ0GUy6g6qdi/8kFgymrrHCRf83sKaPCKpcg8tnueiwplIC93AWmMpfSI3QqDjNlgVwHFnRDmlXwkB1sjRfJJwmqhxM33KXqwjh9hFPGNTTwZBIboyfr3kImBuvMI70lZoK7eEsd4ZO5Qk+Fe9WvXaQb8Bhw== 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 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