Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3662471rwr; Sun, 7 May 2023 17:20:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6k3CdKysbBp6k2HcwdMgKMjbXb6fywWmfMZCeZg97IX4m6L+ue58K4oa33ahruxe2OSQIQ X-Received: by 2002:a17:90b:b85:b0:24b:a5b6:e866 with SMTP id bd5-20020a17090b0b8500b0024ba5b6e866mr9064659pjb.24.1683505254398; Sun, 07 May 2023 17:20:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683505254; cv=none; d=google.com; s=arc-20160816; b=RPxh16/MmlSdNlhDA5KgDKdOvM1c98H8dmObF12Snx4Q4fBQteXBQCuwK7Nk+dCpXP XJNYciIDRyzOxDwgenNVm2BKua8Tqm2GjuXpYLeQ9OzAjWkidtMb7h1+QybsuuZrAYSF KGfEZ6a5U/BMnFDcjjwHsKuqQ+QPTEqvMgc9mFFUzj++s7aUXiZEps8Yu/oW5p/3mbdS nE3ogw6wTvnVzxjxj392+Jo1o8eeWB2qAYURrVSeJvToMFBp7cIDCigNN8AnSeAXycxw WJ4Cty9NUGqawLmrqKV3L7zMCmKP/Qa/dEe48YWlubFrbRWF2fZ2vEQXTfu2JBSSMxcz wpmg== 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=SxAVKXcnaB18uGCScmaGm0KtqOzQ9BlZ2AI3oJdJlic=; b=Xuu7CrKyA6JCiAzdd+agHRX2eGwLyk3sjqnQjFnv+BuUgGPQqIsnVhJSMfRJDNkv6e LQeZ2Z5xamDfPbVNwS6/B0VcGxrGknhm1/WBH5JK6u3+YvKoa3hMIfm2OzexT7UBGRff xQKgIIQXi8is7rywk+OPnesgEK1r4U9tF7pgFEQrvniAfJSYSMMxtvpJwWpCOIYnetx8 854BGeF3V5MFjWUk2s/PJGlHMyX3Ds0yUkSIq/gD9NwyV34r3gp+pUlH2GcQGSmTaCiQ jmiyrMNvpmEh0LZ+crBG3zmIwTExAoenZu9A/i/FaLcAG1mmgX8BsJWuhGB+5gpnGG9K RNpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fcZWfqn9; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l197-20020a633ece000000b0050bc9305e5bsi7195241pga.122.2023.05.07.17.20.37; Sun, 07 May 2023 17:20:54 -0700 (PDT) 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=fcZWfqn9; 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 S232152AbjEGXrE (ORCPT + 99 others); Sun, 7 May 2023 19:47:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231234AbjEGXqu (ORCPT ); Sun, 7 May 2023 19:46:50 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68E54100D0; Sun, 7 May 2023 16:46:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683503205; x=1715039205; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XL6vN5u+KeCOGSvPKGIDg51xwwNZ7oq3J9d7SYKdrYE=; b=fcZWfqn9q7bmmKZljKc6VQTOoLpHNUhvZ/Za2NEB4vyn4Uu+r5sVbIds YN1zsh7CVDpFHWGNsu4OoWy7LbRELGhFz7pKWkkNGJRfyFtxgkxAWdOJT 3aWJ40vTtSDNxmkMA53F8+c1cWrb02XK5tv4xyet46wfOat7pM40fgIFO oF0B7Td2Z6+4oMro+et5zoi8iE1iYCLc77U1OXgReKIwynVLBzQl9Nq6i 6x0jkVl7C/gq7qFwndb3MrfCV0Fz2B5cJOB4WnDloMHfp1Y7Yg3Cur2sd DW0MTqtDVjxzLxO1F9xvPG/4XPlRkKEKZgSztkO4XbgUEK+7HT7CWFleC A==; X-IronPort-AV: E=McAfee;i="6600,9927,10703"; a="349550290" X-IronPort-AV: E=Sophos;i="5.99,258,1677571200"; d="scan'208";a="349550290" 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 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 -- 2.39.3