From mboxrd@z Thu Jan 1 00:00:00 1970 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 136B1C433FE for ; Wed, 12 Jan 2022 19:53:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68E316B020E; Wed, 12 Jan 2022 14:53:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6167E6B020F; Wed, 12 Jan 2022 14:53:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48FF56B0213; Wed, 12 Jan 2022 14:53:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0176.hostedemail.com [216.40.44.176]) by kanga.kvack.org (Postfix) with ESMTP id 1A6FE6B020E for ; Wed, 12 Jan 2022 14:53:51 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 9A665824C431 for ; Wed, 12 Jan 2022 19:53:50 +0000 (UTC) X-FDA: 79022685420.11.92C1AA0 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf04.hostedemail.com (Postfix) with ESMTP id EDC8B40012 for ; Wed, 12 Jan 2022 19:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642017229; x=1673553229; h=to:cc:references:from:subject:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=+z6qhzkY5AZh8lvp5ZYnAbRLSbu3XClV+3f1x7uGg64=; b=G7o6fonN2S+MrGU8lx9HfcBzXmVnERjt4Trz+A69Ul5RPy09Fyy9DpnW AWKTpgyNWaBcsz1uDW9tp2BBMeZ4xy39UYSOqmUHaAsA1fVinhPnKaZSI ebYViRu3cpx03sw0kFQu7rYTaGQHx8TeO2k/wY0kJRl0t6P8BxxKe6qaz oRbVrlbyQ+2NS5FCDJ+jUSV7MkZeLZ6QWgmB7SjhKtBK5/4gs/URYKW/u MmMZ0I8LbJD0q0joRvkWKYuCADzRV03tEtc8gcf8JUXLlYtD6WzCP1/qa rwbel0sTSp+jJT+BDh2092Ch6NDLtO++/tm2L5tplasVvt4LyVzjq8Zp8 Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10225"; a="223824035" X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="223824035" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 11:53:47 -0800 X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="593122646" Received: from kumarkan-mobl.amr.corp.intel.com (HELO [10.209.80.194]) ([10.209.80.194]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 11:53:45 -0800 To: "Kirill A. Shutemov" Cc: "Kirill A. Shutemov" , Borislav Petkov , Andy Lutomirski , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel , Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Varad Gautam , Dario Faggioli , x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220111113314.27173-1-kirill.shutemov@linux.intel.com> <20220111113314.27173-6-kirill.shutemov@linux.intel.com> <3a361a1d-0e14-8884-c5bb-90aeb87e38ef@intel.com> <20220112194302.cyxhjypsptr4mtix@box.shutemov.name> From: Dave Hansen Subject: Re: [PATCHv2 5/7] x86/mm: Reserve unaccepted memory bitmap Message-ID: Date: Wed, 12 Jan 2022 11:53:42 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <20220112194302.cyxhjypsptr4mtix@box.shutemov.name> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=G7o6fonN; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf04.hostedemail.com: domain of dave.hansen@intel.com has no SPF policy when checking 192.55.52.136) smtp.mailfrom=dave.hansen@intel.com X-Stat-Signature: r46iahnw3ad8gc1r34bnu4k3wq8u3xx7 X-Rspamd-Queue-Id: EDC8B40012 X-Rspamd-Server: rspam12 X-HE-Tag: 1642017228-714565 Content-Transfer-Encoding: quoted-printable 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: On 1/12/22 11:43 AM, Kirill A. Shutemov wrote: > On Tue, Jan 11, 2022 at 11:10:40AM -0800, Dave Hansen wrote: >> On 1/11/22 03:33, Kirill A. Shutemov wrote: >>> Unaccepted memory bitmap is allocated during decompression stage and >>> handed over to main kernel image via boot_params. The bitmap is used = to >>> track if memory has been accepted. >>> >>> Reserve unaccepted memory bitmap has to prevent reallocating memory f= or >>> other means. >> >> I'm having a hard time parsing that changelog, especially the second >> paragraph. Could you give it another shot? >=20 > What about this: >=20 > Unaccepted memory bitmap is allocated during decompression stage and > handed over to main kernel image via boot_params. >=20 > Kernel tracks what memory has been accepted in the bitmap. >=20 > Reserve memory where the bitmap is placed to prevent memblock from > re-allocating the memory for other needs. >=20 > ? Ahh, I get what you're trying to say now. But, it still really lacks a coherent problem statement. How about this? =3D=3D Problem =3D=3D A given page of memory can only be accepted once. The kernel has a need to accept memory both in the early decompression stage and during normal runtime. =3D=3D Solution =3D=3D Use a bitmap to communicate the acceptance state of each page between the decompression stage and normal runtime. This eliminates the possibility of attempting to double-accept a page. =3D=3D Details =3D=3D Allocate the bitmap during decompression stage and hand it over to the main kernel image via boot_params. In the runtime kernel, reserve the bitmap's memory to ensure nothing overwrites it. >>> + /* Mark unaccepted memory bitmap reserved */ >>> + if (boot_params.unaccepted_memory) { >>> + unsigned long size; >>> + >>> + /* One bit per 2MB */ >>> + size =3D DIV_ROUND_UP(e820__end_of_ram_pfn() * PAGE_SIZE, >>> + PMD_SIZE * BITS_PER_BYTE); >>> + memblock_reserve(boot_params.unaccepted_memory, size); >>> + } >> >> Is it OK that the size of the bitmap is inferred from >> e820__end_of_ram_pfn()? Is this OK in the presence of mem=3D and othe= r things >> that muck with the e820? >=20 > Good question. I think we are fine. If kernel is not able to allocate > memory from a part of physical address space we don't need the bitmap f= or > it either. That's a good point. If the e820 range does a one-way shrink it's probably fine. The only problem would be if the bitmap had space for for stuff past e820__end_of_ram_pfn() *and* it later needed to be accepte= d. Would it be worth recording the size of the reservation and then double-checking against it in the bitmap operations?