Message ID | 20230330114956.20342-10-kirill.shutemov@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1065232vqo; Thu, 30 Mar 2023 04:53:08 -0700 (PDT) X-Google-Smtp-Source: AKy350ZsXwvfpSe0vsRmNDUZNU/0E06wLpsZs1w0qZr4EVuuOeEoSbTOODO4VCv/xKoEelgRgL0b X-Received: by 2002:a17:902:e743:b0:1a2:19c1:a96d with SMTP id p3-20020a170902e74300b001a219c1a96dmr6767091plf.23.1680177188187; Thu, 30 Mar 2023 04:53:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680177188; cv=none; d=google.com; s=arc-20160816; b=cCKBZm+wvlAwqhoMkXcyo0Gbp3OGxs19uqgv58d9ce7Ji5Osmq3lt0GrxFxB0LOUp0 McGOdtTpBwKrLt8XAV7Qw3GOqXeav33jApX/5Sz2Sdm3V13xUkaHDgK4O9BgQBJN+s9m eUXFHtAL8o/ZY925jukVjBYnxsECRJ9exRnUjnz+C3JqFz1kB8HX4wuLVX+/NJ4Re7Wn PFz2mOZoAnwBhLXwHgwepDRNC1Q0AHypUHq1AyDKG81ySsLLPU2IrVDZFQy4c0zLHSaX n6j6Aa37k1R07F/8dQTv2Xr+b0bFob8nNktK4cV1gHRtYv3bWcD7rpp1WI5yZlQu3qNR hdAA== 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=CDsQGJ5mVHwKQTSqTirUAmTn1KY5xyP0qi9c6MOAeR0=; b=xWMKDbllLersBqSz/uz1PslYL28VrB3XoY6NT3TznL1Iah//edwl9qk5JtFtr7ZAm4 lD+96DN0llH5S3iWhQlLCxJzLYoVk3k7yf1k7pPQIxRamSRJKeurmFl2WgOalwhbgTWs f4xa23iClLReiGMuO6xGcMINS9coJb8YM1wKprYH5R1XV9/vRd5AzdX2AFKvc+4F2aT8 ChH4BFJ2tbd9BxLRUev3N9XH6iDMob0aJaZqk6ZtFU0FHwGNMSDRGMQczFTVptwADROD gzILsh2UgVsaA7QLbQpZBTCnteEWvCJ3PWbE3Q57MtHS01yZVjGDtHrB0wXULJ9tRw9l B5VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=G3v8P3ru; 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 n12-20020a170903110c00b001a27af16626si1338189plh.569.2023.03.30.04.52.55; Thu, 30 Mar 2023 04:53:08 -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=G3v8P3ru; 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 S229436AbjC3Lue (ORCPT <rfc822;rua109.linux@gmail.com> + 99 others); Thu, 30 Mar 2023 07:50:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231159AbjC3Lu1 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 30 Mar 2023 07:50:27 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36BE2A24B; Thu, 30 Mar 2023 04:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680177026; x=1711713026; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f7/hrgLyEe7uCgqzPwQBAiXJTS6cTMMnuaKLYQlQP9E=; b=G3v8P3ru+eaQYI7MqNa9vb+Hy499tRdtoMOlKZq9wzcolQVJpqIHwEgb LaH0yrgdJTc3rbq+tzAm0G3G8KhCWNrPxmGk9y3HrsCamrqtyFGw3sOMH +qOa3/Xj8miI5t18P6nXLhoDnStt6l7bu/UiuEF6+Dmpare1Hj0ws11VH CGcIGibNfP5jJCGriwGOdIH/MlBzpnicwRMo6Li15/PlR/BQh3WgP3PWd NcKFglfpg5MvfcLUtQ2hkyMxK5RZVJEYY1y48MOpTb3NNSWR/4E54m53v sp9lNV0qRbFbnIfERimIFYTbOLovQVCB/qr62l2PoODEL68EkUmmewYOk A==; X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="339868489" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="339868489" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 04:50:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="1014401448" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="1014401448" Received: from ngreburx-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.209.91]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 04:50:17 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 49CA4104545; Thu, 30 Mar 2023 14:50:00 +0300 (+03) From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> To: Borislav Petkov <bp@alien8.de>, Andy Lutomirski <luto@kernel.org>, Sean Christopherson <seanjc@google.com>, Andrew Morton <akpm@linux-foundation.org>, Joerg Roedel <jroedel@suse.de>, Ard Biesheuvel <ardb@kernel.org> Cc: Andi Kleen <ak@linux.intel.com>, Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>, David Rientjes <rientjes@google.com>, Vlastimil Babka <vbabka@suse.cz>, Tom Lendacky <thomas.lendacky@amd.com>, Thomas Gleixner <tglx@linutronix.de>, Peter Zijlstra <peterz@infradead.org>, Paolo Bonzini <pbonzini@redhat.com>, Ingo Molnar <mingo@redhat.com>, Dario Faggioli <dfaggioli@suse.com>, Dave Hansen <dave.hansen@intel.com>, Mike Rapoport <rppt@kernel.org>, David Hildenbrand <david@redhat.com>, Mel Gorman <mgorman@techsingularity.net>, 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" <kirill.shutemov@linux.intel.com>, Mike Rapoport <rppt@linux.ibm.com> Subject: [PATCHv9 09/14] x86/mm: Reserve unaccepted memory bitmap Date: Thu, 30 Mar 2023 14:49:51 +0300 Message-Id: <20230330114956.20342-10-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330114956.20342-1-kirill.shutemov@linux.intel.com> References: <20230330114956.20342-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761793474978255729?= X-GMAIL-MSGID: =?utf-8?q?1761793474978255729?= |
Series |
mm, x86/cc: Implement support for unaccepted memory
|
|
Commit Message
Kirill A. Shutemov
March 30, 2023, 11:49 a.m. UTC
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 <kirill.shutemov@linux.intel.com> Acked-by: Mike Rapoport <rppt@linux.ibm.com> --- 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