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: 30584 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3156832wrr; Tue, 6 Dec 2022 17:51:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf6nPakPzRFYQ3dlN4gFITSbpxdQ7AiFxFIvMZIksJJ2SDGzieC0TthqW/ipl5XvlSEy38Lr X-Received: by 2002:a17:906:1748:b0:7b2:7fa8:3d84 with SMTP id d8-20020a170906174800b007b27fa83d84mr32289816eje.650.1670377909091; Tue, 06 Dec 2022 17:51:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670377909; cv=none; d=google.com; s=arc-20160816; b=Cw28oG0ai+LWd5HMgYFj9F8Ut3VlZKdjzAfJcCs+cusSLfIIH5bK9rjzSQZ7xT3yXJ UwMK9Fr/ASsUbRzV7SifBUcZMdl+ED55ka2AJxRmFWvZj+p+myVsms0LdrA0qEo5Tn9y Wbo0UiTBrAYf2BULtF5bNaDJDayz0xoP5m3wX6YvvTVpWHSWL0j0pwFuvahzx5oeU1aU yOQo/yZmJWvQoHjpw3xBu1Y2TTiKGsrGqvIJe1ZUBQq8sC0OIRf1w5C39LWLDrLF7/Qq HF+Ez9t8uBZ6m+CGAF7I89ngkMvP+I/OZPXLOR6oRRSJkNpext8SWR+N0qGx9rupz9nM C1Wg== 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=AbEhTgrAuKDGYsZ6/Y4F9BBFnx+cJUwn1WPTrIBrLw0=; b=B3YryrXt0cnxG3Kmxe3t9Mv1MWxNBX/0IPV9v4OUpiN1ZP5/1vD2Vm1g3q8SrsoE1c xwPx86ik/CnFInpmTEqrGG5SQ9h3bvPsIDyvmdJWQHXVjpEFgs0OshY6U3KD2rCzNvCo f41tiduNUX/8XU7qjthr6R84Ln2oz/X97ZX2mosvNFm8NxRcRNxfuaNbXMsTYZ1MgQ+r 5ZLfTrBccm8oIBWtFccKWjxcp/OnRXFOatfWt/0AlOHH28Xw1X5XprtQjQVjSgrrhvwo DlBFWxwspVaEOM5hEDKet236STx8yZKDFOSufumafoTQ0P6S82d/g5UqCqikZreJ1eeu 1j9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dJ6Kf+p7; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs44-20020a1709072d2c00b007c11812c620si1741699ejc.440.2022.12.06.17.51.26; Tue, 06 Dec 2022 17:51:49 -0800 (PST) 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=dJ6Kf+p7; 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 S229976AbiLGBuU (ORCPT + 99 others); Tue, 6 Dec 2022 20:50:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbiLGBuJ (ORCPT ); Tue, 6 Dec 2022 20:50:09 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1722532C6; Tue, 6 Dec 2022 17:49:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670377799; x=1701913799; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oBiSIOxE3eoLPk40ExcpaFUWqTkEiCbV0j2bGnDI4n8=; b=dJ6Kf+p7pq7OVLXdCIMJbKhO9G4PToMylfvLhXRMcImC4dSLwgiQDvhd Z0seE+3buo/iSbVFIOo/gZeLrKziE4t137pa1bvvaiyO7P9x45Y0ONGUY 096PCQQJMYEgrstWbWbk0GKICCr0FclPRydatuMaUMKl8zLrlQjhY2xBD qy9TIy3BMD97sdAFUHwW1vejSQGKz+ooqfBJ+gscqzvoJRfMMxuoms13N NZJ0djf7YePuHBTCulncAjGncCgFVhDU0JRFHWQjjFAFHjUIEP+wLDFWh QUAlV4yXyz9Ag9d60Cjd/UY86bXGc8zIutJZtQisCM+36Q6ZFW88i4hhz Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10553"; a="316794419" X-IronPort-AV: E=Sophos;i="5.96,223,1665471600"; d="scan'208";a="316794419" 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-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751518186310062295?= X-GMAIL-MSGID: =?utf-8?q?1751518186310062295?= 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