From patchwork Wed Dec 7 01:49:27 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: 13066528 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 14498C3A5A7 for ; Wed, 7 Dec 2022 01:50:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 897568E000A; Tue, 6 Dec 2022 20:50:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8472B8E0001; Tue, 6 Dec 2022 20:50:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E7BF8E000A; Tue, 6 Dec 2022 20:50:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5CFD78E0001 for ; Tue, 6 Dec 2022 20:50:02 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3790DAB470 for ; Wed, 7 Dec 2022 01:50:02 +0000 (UTC) X-FDA: 80213829444.17.C3ADA94 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf30.hostedemail.com (Postfix) with ESMTP id 929178000F for ; Wed, 7 Dec 2022 01:50:00 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=aAtCL6I1; spf=none (imf30.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.115) 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=1670377800; a=rsa-sha256; cv=none; b=bYXxyddflhZGsgTowvblHPZWcxYYA5VJdvUsMuLK2TL8opuhqhx3qBFTxr9ijk1696fa7q fLvexWiwuKtZUIHt9omP+yVrHk1q8I/sbqGG9Wh6pla5Qqr3AyEpJ5J740LLMs5UjNJOfL 9Fy+n3BRDr9fNB1RPWZqqCHaEO08q1s= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=aAtCL6I1; spf=none (imf30.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.115) 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=1670377800; 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=AbEhTgrAuKDGYsZ6/Y4F9BBFnx+cJUwn1WPTrIBrLw0=; b=5rhe4lwUtLWVEDhUm3phy8udrxu5spqE86dj3A/N/zk61NuGdEfRnXwqyz6UYW0cmKk14P FWtQ4bmjeNcXNdqluRIiuZavRxXfDIZuuV9PxYALLO4Izx5+qWykqC6qapW0kHveMGNCx5 zqwulAAzdFWY+jTNln9QEhyaG4f0mzI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670377800; x=1701913800; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oBiSIOxE3eoLPk40ExcpaFUWqTkEiCbV0j2bGnDI4n8=; b=aAtCL6I1V4g0i9dgpdSO4twLE39ErSMCo6bVJttpa4SgNM8Y4CGJEikZ gMZ0XtgZaj7tNjz7JVw5J//2eiJBgbi5BpTVTRuvhtsH0N8OyjIZTXu9Z e4OlLCr3Kxvw9L9UaDXkhDZx3tJ/B7VII1tVwCQMlxxucNzo949acIxpy 979gtHd6UPMs/LtZ57YZjNFpK0w0Qre63eEHfhGAy0PBNS3f/FXXQX00s 0G2GIegeSGgabBfpOcxCy0Z0pPjC6TWcr7J2+yLUCNRJTxZW4Ei6dTg/c RTsZRgjRTf3aCoBqGx4JA7pFQuxwlbg0KRfCl1vCRRWME6ao5qzcRDQfQ w==; X-IronPort-AV: E=McAfee;i="6500,9779,10553"; a="316794413" X-IronPort-AV: E=Sophos;i="5.96,223,1665471600"; d="scan'208";a="316794413" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2022 17:49:59 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10553"; a="640082279" X-IronPort-AV: E=Sophos;i="5.96,223,1665471600"; d="scan'208";a="640082279" Received: from puneets1-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.38.123]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2022 17:49:51 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 814A0109C8C; Wed, 7 Dec 2022 04:49:39 +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: [PATCHv8 08/14] x86/mm: Reserve unaccepted memory bitmap Date: Wed, 7 Dec 2022 04:49:27 +0300 Message-Id: <20221207014933.8435-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221207014933.8435-1-kirill.shutemov@linux.intel.com> References: <20221207014933.8435-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Spamd-Result: default: False [0.74 / 9.00]; R_MISSING_CHARSET(2.50)[]; BAYES_HAM(-2.06)[87.48%]; MID_CONTAINS_FROM(1.00)[]; DMARC_POLICY_ALLOW(-0.50)[intel.com,none]; R_DKIM_ALLOW(-0.20)[intel.com:s=Intel]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; RCPT_COUNT_TWELVE(0.00)[33]; R_SPF_NA(0.00)[no SPF record]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; DKIM_TRACE(0.00)[intel.com:+]; TO_DN_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[4]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; ARC_NA(0.00)[] X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 929178000F X-Stat-Signature: k1jeuy9hoi4mn3j3aktptyk1wzqr8n8n X-HE-Tag: 1670377800-148992 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 9dac24680ff8..62068956bb76 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