Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1398790iog; Tue, 14 Jun 2022 05:28:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkHdKVKC1QS1+MsKWjyUQIhZ8oGEOpZsBUdcu7sC9rccuWYRJyqh689e2+mfmSubf4hW+q X-Received: by 2002:a17:907:90c8:b0:711:c8e1:7109 with SMTP id gk8-20020a17090790c800b00711c8e17109mr4087979ejb.492.1655209709694; Tue, 14 Jun 2022 05:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209709; cv=none; d=google.com; s=arc-20160816; b=A4fFzDd15bBdczdQ4m3sPXIpTTFjIbMHB99EMxiprSzt70t+kO7GZSnIOQSNPvrQLT sU5z/g/+FHGL3w7bEsPxmFkiyO3IW3bw4PhkxuIKj5sfXyqxWCjWS22jcZpAgj6sSdBs o8Z6i5+iqb1ijT3j+RtYENoa7NqPe3M+CMZtxmdsF7x4Hz9IFberwgmjOWH/WvyLh0mC I+swUJ8vn+sO7cxOhYy77vrZuz1kVXoTwk5KNRiqwu9N6ferpdEwBjJUf9rPYamRPgQb /E8UEJFln++g1NvKC/zw5N7J0T0KJCtXM5KAorUe7vG8tnm2nKMSpSBy5Ga0UASivb8n JPtQ== 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=lC3G4n0zFqgOUruBrn2FFz4wqh1BEanTgj1uGK55NL0=; b=uu7kfiIZveg0xM1AJbn07wmov9BImWffEAIEYOTY8s+puRPjUe0pl46vfWx9N/BQX2 H93AU8Vl2FY0U3pm4piOBP4WGXgdwMM168ukAusl3l+/9uLmpwYkOp3i549h++5UMj5d IWZj+MGXMzZRET51/wDuvMN6sG/K8jU7J0juXBccHH5ElZoykb4d2E/rG7Z6ej/e0pZh Z+QnSq7dakL7hcOzHiRr7RyquK6ZG+r2hao4RYvahRXrNlFUmrVDIJI7d+DH/8KGcyUL BvNAurjioTHZXf62eTuNHg830eJDunkEFYA1pNZ+U7zS2gdoleS6Lri8Tz3ZiVL+ida9 aFHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GEKBtylH; 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 dd11-20020a1709069b8b00b00711e5f991casi12857921ejc.987.2022.06.14.05.28.02; Tue, 14 Jun 2022 05:28:29 -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=GEKBtylH; 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 S1356153AbiFNMDu (ORCPT + 99 others); Tue, 14 Jun 2022 08:03:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356147AbiFNMCr (ORCPT ); Tue, 14 Jun 2022 08:02:47 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA84B1A059; Tue, 14 Jun 2022 05:02:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655208166; x=1686744166; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Vt7QSmHfxcGQwi2CPob9vBQysbMDXN+N63yj2aSmEdc=; b=GEKBtylHwFaP+o3xce+saorgpcly852aTG/v1qst1Nv7KJWA5Tmy8alD ibmy9DCATOvOwGkecwSylfyHBT7G12+Kw0bsxIDJDT1wxIouejwsPPuwl 3wuft/enxoOcQMhRuoA0YYMlwoqXuIjO5BLk2EvtYajXjKjd0P2P1KAtU EgQ0pbdLWVcdo9aVlFfQbggs+W8Ve5VRBJqo/jXeXLPLTFCXQL/VvLSjS DBnOBzxTBQOdK6+VXLrkLpWxYr8Fee7WA/fAYJI+4Gn4w8dk4cuOt5QPy UUbvRsEYhFqeE7EAVHbeMkvXlYtx88hlzwmTN9SzuindeIDp8kqwV1AQC g==; X-IronPort-AV: E=McAfee;i="6400,9594,10377"; a="258432281" X-IronPort-AV: E=Sophos;i="5.91,300,1647327600"; d="scan'208";a="258432281" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 | 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 -- 2.35.1