From patchwork Tue Jun 14 12:02:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 12880968 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 BBDE9CCA47A for ; Tue, 14 Jun 2022 12:03:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B25EA8D0245; Tue, 14 Jun 2022 08:02:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0EEB8D0247; Tue, 14 Jun 2022 08:02:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8ADAF8D0245; Tue, 14 Jun 2022 08:02:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5F9F38D0247 for ; Tue, 14 Jun 2022 08:02:46 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 34D806177B for ; Tue, 14 Jun 2022 12:02:46 +0000 (UTC) X-FDA: 79576704732.16.3384EC2 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf01.hostedemail.com (Postfix) with ESMTP id 7654D400AE for ; Tue, 14 Jun 2022 12:02:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655208165; x=1686744165; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Vt7QSmHfxcGQwi2CPob9vBQysbMDXN+N63yj2aSmEdc=; b=d0N7IGfdtvGeKFUkxdu/t+7A4wUXRu2gYcR/ye6mScH30Nvqfc3lwpya BcwPaMDogctiIVLwUVJBgdxvCR/eL5AK1+AMhhgcZXffrc9dyyMrCjJea 479xSd9auq2Yu/EDvwAmhtUj4CQJFxhDBzFS5i6ZtNvMxBhb5u6A0jd/v 4+fpek4CEdcsM8NnqCNPFclCWl/1v4tDFVQap8lDHqa/FNTAihZgBE8y2 X6OLqPr6w78bc/HNq2+F34pe4QJ6yxO8Fxx0la6ETXaECCumGF7kOQaAf vVKK/Kf0NWTH4EdUCGM6VYuxRz63e89vCOY1TLam7fXt0F0aLTCk8lhDL A==; X-IronPort-AV: E=McAfee;i="6400,9594,10377"; a="340260657" X-IronPort-AV: E=Sophos;i="5.91,300,1647327600"; d="scan'208";a="340260657" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2022 05:02:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,300,1647327600"; d="scan'208";a="640332827" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 14 Jun 2022 05:02:36 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id C01F088D; Tue, 14 Jun 2022 15:02:32 +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: [PATCHv7 08/14] x86/mm: Reserve unaccepted memory bitmap Date: Tue, 14 Jun 2022 15:02:25 +0300 Message-Id: <20220614120231.48165-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220614120231.48165-1-kirill.shutemov@linux.intel.com> References: <20220614120231.48165-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655208165; 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=lC3G4n0zFqgOUruBrn2FFz4wqh1BEanTgj1uGK55NL0=; b=IxgHlqgX/53lBINsd3HhBcEAuOme5tALg9NDxMM23H1R/DiJIG6HzF+hrS4tMhcUeCnGfP ZijmV1hq4MBoOnQNT0H2nAt1KCspKjY3Z8PaRoUHeAk5J2GXCl+eqotq026w8SMuRUOaPG azOIyEmvm75zYXETqklfRaexqONbuSo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655208165; a=rsa-sha256; cv=none; b=d9cL5CFVe1IgzfeSsuUvQrqW5fNM5irGllBi6BGKV7zfisiXo1vOt91uAf/+gRfKBk3rtK xqjIM18iN+aiRCQTXZljZmw43Jc3lN2eZdxo7Zaol1p8ByDs3mchNxCKJlq6DHgZBhTJQ2 Vja5FvfNDa2btOvZzGRQH9su00DD0oM= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=d0N7IGfd; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf01.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.31) smtp.mailfrom=kirill.shutemov@linux.intel.com Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=d0N7IGfd; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf01.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.31) smtp.mailfrom=kirill.shutemov@linux.intel.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: 4z7kwe3t6pcboa3kmwbssinczxbhrz5g X-Rspamd-Queue-Id: 7654D400AE X-HE-Tag: 1655208165-316268 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 | 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