From patchwork Sun May 7 23:46:13 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: 13233956 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 882A0C77B75 for ; Sun, 7 May 2023 23:46:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 754F96B0088; Sun, 7 May 2023 19:46:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7060C6B0089; Sun, 7 May 2023 19:46:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 509C26B008A; Sun, 7 May 2023 19:46:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3A2DD6B0088 for ; Sun, 7 May 2023 19:46:49 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 10FB91A0288 for ; Sun, 7 May 2023 23:46:49 +0000 (UTC) X-FDA: 80765096538.28.5DEB69A Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf22.hostedemail.com (Postfix) with ESMTP id E6ACBC0003 for ; Sun, 7 May 2023 23:46:46 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=gMSAfSx8; spf=none (imf22.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=1683503207; 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=SxAVKXcnaB18uGCScmaGm0KtqOzQ9BlZ2AI3oJdJlic=; b=vIQ/CNrvDbmkTNxH7nWIEsVFAJiDevhVMd2lwtW5LgLwyOsfPoWYmnlLoByo0MsVgNXAsA yV70S/WR5cS7JVfNYDKUQ8JBSSRzjvHAl4HJ40rS4NgaDcOMbNSQXS03/0vS7RxWvSgoBY Qun3YUO/xpQ2ND8N5pK/QaiAna9Mjhs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683503207; a=rsa-sha256; cv=none; b=N+RvYjTh6C/wSQ5nlkC/Zh3UV00b8+JP4RW8Jnvwk3K3jjXlVM4xEVP/52w/QEITqGV3h9 48LLHS2x9dnEXrdMvbQ5RTkmbblSlQx5Z4xa9+uJtvNlRQwnikGZsR51f4PHDcVr1W8MkJ DlUNCttO3biD5ZmMs0lMGflkxinvvvk= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=gMSAfSx8; spf=none (imf22.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683503207; x=1715039207; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XL6vN5u+KeCOGSvPKGIDg51xwwNZ7oq3J9d7SYKdrYE=; b=gMSAfSx8893oi4lAInR0ccjfUNDoZ08LIc1JYC/ulDrKmqr4zNGjoFV4 ol3xrXrrhRoiUT1otSYrN8APA1Ltb7P/plICLhy305gU3JWNsJbPqfYlL CgDTCcxTn3rOWdVcXDzVkuwt9tDyF0zHRjQOY0jphEv8odXNyvr84xpqK SOIvToiBhF5Vz/ioAPGSpaUvhuGx1bRtsAv8LzhZv4b5+dNBOH5HqAKLu Sfkx0r8zBIcju1/51AHrD00bSFIB69aNTwnjOeEDwIY0LatBRdec9NBm0 pwjN7DU+s8wsWKIXvMxhSw5utaK+RtTZaEmYAv5HNChIJBXSUP/zrYNvc A==; X-IronPort-AV: E=McAfee;i="6600,9927,10703"; a="349550288" X-IronPort-AV: E=Sophos;i="5.99,258,1677571200"; d="scan'208";a="349550288" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 May 2023 16:46:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10703"; a="701222810" X-IronPort-AV: E=Sophos;i="5.99,258,1677571200"; d="scan'208";a="701222810" Received: from dancaspi-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.61.73]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 May 2023 16:46:32 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 47A4610D334; Mon, 8 May 2023 02:46:20 +0300 (+03) From: "Kirill A. Shutemov" To: Borislav Petkov , Andy Lutomirski , Dave Hansen , 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 , 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: [PATCHv10 06/11] x86/mm: Reserve unaccepted memory bitmap Date: Mon, 8 May 2023 02:46:13 +0300 Message-Id: <20230507234618.18067-7-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230507234618.18067-1-kirill.shutemov@linux.intel.com> References: <20230507234618.18067-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: E6ACBC0003 X-Stat-Signature: iinqjm333uznksa1x8w18fpwm5anwrkg X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1683503206-922130 X-HE-Meta: U2FsdGVkX18YJAjvycaADX/g0x4JuR8XFZy42gfD5ljbPN1f/dYhk+42MUsJoQbEUFFKVIdBvgayAMHGD0fhRtYjjNNWtz+QMqXfRnxwEYBwETFWd/m0yEVTUTFUMT83SpCkBJTTyJVqz4CLigd1NK0zi1r1yk6ojId/aFlIvQcE4LX6y5xZ9/GLCCir7fFPytgg49nAdHmIVW8Xjxi6f1VpUFqcR+LCALB0BZrExpCaDEwEciu1X1KcNRcV2D5xndJooz+bU2vidYH/bytI6vUCEXKvN5z5G4E1CBZ6yrzhlYsPswLTW1AHMiXcT3vJCpyabIaRmPmrwBmYtTgXap/hY+1AtT2AugyKVKEGtB1sWC2NP1v7VUs604X4oKGmSHvqlbcjVP4j7IC6417Msth6hWMC4PKziKl+x5OGgwwOMhHmJGVDR97HSqeriRWmOc9suBrrFIJbDuZ+W3L9fxSyYxdYIZGx3/TUHR9hMod5iUC+yYTdhZcHhf4BIDlwmb+4QvOpREmlD32i1RPfPCxsKeqXm1DT/o+ZgcJCN7CuVOA376iVrAhILa5ugGY39I4cRlIi2ly63zq67tr537OrVDg6Wz/daoEo67aS8mxSxp3QdN8/pEnXY7T8duch5VSwtjTiqiEQw2sYpHD7E/FFppFyenl/hAeDHxMEZDE250AYAJAZ9SWBWAUH/Fuay5cCVqlaEObkI4hDQDbNZpn23wpmnuKHUh6donlIGEz3R0x1xCOBUzWo7NkuAKott0ZI4wzMtpeK7ZX/F1crhS5HDJXyAK+4ALTHD1d8N1Kmzf0d4lVVkvmdW0qiitI3cipxdBTH72gg7Wr/OojVo7KHpX/9MjTiTbJFjW3VtUuKmwMPjfSgeG/hXMSypj8+cJ8rrabGfEyoup1pUOgqYL5+dKLzVBzaxaNIWDDIPew6lXZI+idW/ivaM6gBp5Q4cwnBqzKP6ly1dLExx6U frIZ2s0y /3GwYkJFDuxT7xN+T8y0NcaiVP5PvwziTHk59QRn2b0WBshhUAIEpa18qvV28gPC7Ux5AUHtsKeCtWVQnYiLusbM7eVG292gi6BLYMxvN/xmNgqosV2RmphP0rcroKVbW46YVQXeGZMnCvm26INuBfmFHO0Gt0vn4Tjtj 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