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 X-Spam-Level: X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67BC9C433E0 for ; Wed, 13 Jan 2021 15:35:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C8DB7233ED for ; Wed, 13 Jan 2021 15:35:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8DB7233ED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CBE3D8D005D; Wed, 13 Jan 2021 10:35:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C6E678D002E; Wed, 13 Jan 2021 10:35:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B84C88D005D; Wed, 13 Jan 2021 10:35:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0120.hostedemail.com [216.40.44.120]) by kanga.kvack.org (Postfix) with ESMTP id 9F9BD8D002E for ; Wed, 13 Jan 2021 10:35:20 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 67A54824556B for ; Wed, 13 Jan 2021 15:35:20 +0000 (UTC) X-FDA: 77701150800.24.cap99_1016bf82751f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 43F2B1A4AC for ; Wed, 13 Jan 2021 15:35:20 +0000 (UTC) X-HE-Tag: cap99_1016bf82751f X-Filterd-Recvd-Size: 6249 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 15:35:19 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 7C93823382; Wed, 13 Jan 2021 15:35:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1610552118; bh=2fAgPs8iRZixNE2rGkHki+efkxNdgYDH4FZy5LEv3VM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=F1A4eKBwHqwQQ2qYuC89b9+He4HlKjY0H1dYtNxwyMT1oMmsGzwt+gLl63i2hjr1b 9sgIxpyB+ZheqIH0ZoEmwq1UQ0WAVGYMFLywO98V8JVaxMLEKFhfm4Vterv2EU3E5Z WWy3f8OpFdPxLS1J7URvHGbvbvWE109iF1jVLsswncBHyEPBbnpTfBDeGOyrr7NSfP 3GV2yongEt7ACqpbIeZNbXwKqoIvbsjPvuFt2C2tvbH6M2wpqT7muGV1QwcJR5LETC VeWPNG8dZ6HLSVFLjyz9VIwyobCOsMVGIOB3tNwRBxL4W3fNsZb1qR8ZLP9xniiOV5 8BfaF45qcxrkA== Date: Wed, 13 Jan 2021 17:35:09 +0200 From: Mike Rapoport To: David Hildenbrand Cc: Andrew Morton , Andrea Arcangeli , Baoquan He , Borislav Petkov , "H. Peter Anvin" , Ingo Molnar , Mel Gorman , Michal Hocko , Mike Rapoport , Qian Cai , Thomas Gleixner , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org Subject: Re: [PATCH v3 1/2] x86/setup: don't remove E820_TYPE_RAM for pfn 0 Message-ID: <20210113153509.GH1106298@kernel.org> References: <20210111194017.22696-1-rppt@kernel.org> <20210111194017.22696-2-rppt@kernel.org> <6ba6bde3-1520-5cd0-f987-32d543f0b79f@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6ba6bde3-1520-5cd0-f987-32d543f0b79f@redhat.com> 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 Wed, Jan 13, 2021 at 01:56:45PM +0100, David Hildenbrand wrote: > On 11.01.21 20:40, Mike Rapoport wrote: > > From: Mike Rapoport > > > > The first 4Kb of memory is a BIOS owned area and to avoid its allocation > > for the kernel it was not listed in e820 tables as memory. As the result, > > pfn 0 was never recognised by the generic memory management and it is not a > > part of neither node 0 nor ZONE_DMA. > > > > If set_pfnblock_flags_mask() would be ever called for the pageblock > > corresponding to the first 2Mbytes of memory, having pfn 0 outside of > > ZONE_DMA would trigger > > > > VM_BUG_ON_PAGE(!zone_spans_pfn(page_zone(page), pfn), page); > > > > Along with reserving the first 4Kb in e820 tables, several first pages are > > reserved with memblock in several places during setup_arch(). These > > reservations are enough to ensure the kernel does not touch the BIOS area > > and it is not necessary to remove E820_TYPE_RAM for pfn 0. > > > > Remove the update of e820 table that changes the type of pfn 0 and move the > > comment describing why it was done to trim_low_memory_range() that reserves > > the beginning of the memory. > > > > Signed-off-by: Mike Rapoport > > --- > > arch/x86/kernel/setup.c | 20 +++++++++----------- > > 1 file changed, 9 insertions(+), 11 deletions(-) > > > > diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c > > index 740f3bdb3f61..3412c4595efd 100644 > > --- a/arch/x86/kernel/setup.c > > +++ b/arch/x86/kernel/setup.c > > @@ -660,17 +660,6 @@ static void __init trim_platform_memory_ranges(void) > > > > static void __init trim_bios_range(void) > > { > > - /* > > - * A special case is the first 4Kb of memory; > > - * This is a BIOS owned area, not kernel ram, but generally > > - * not listed as such in the E820 table. > > - * > > - * This typically reserves additional memory (64KiB by default) > > - * since some BIOSes are known to corrupt low memory. See the > > - * Kconfig help text for X86_RESERVE_LOW. > > - */ > > - e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED); > > - > > /* > > * special case: Some BIOSes report the PC BIOS > > * area (640Kb -> 1Mb) as RAM even though it is not. > > @@ -728,6 +717,15 @@ early_param("reservelow", parse_reservelow); > > > > static void __init trim_low_memory_range(void) > > { > > + /* > > + * A special case is the first 4Kb of memory; > > + * This is a BIOS owned area, not kernel ram, but generally > > + * not listed as such in the E820 table. > > + * > > + * This typically reserves additional memory (64KiB by default) > > + * since some BIOSes are known to corrupt low memory. See the > > + * Kconfig help text for X86_RESERVE_LOW. > > + */ > > memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE)); > > } > > > > > > The only somewhat-confusing thing is that in-between > e820__memblock_setup() and trim_low_memory_range(), we already have > memblock allocations. So [0..4095] might look like ordinary memory until > we reserve it later on. > > E.g., reserve_real_mode() does a > > mem = memblock_find_in_range(0, 1<<20, size, PAGE_SIZE); > ... > memblock_reserve(mem, size); > set_real_mode_mem(mem); > > which looks kind of suspicious to me. Most probably I am missing > something, just wanted to point that out. We might want to do such > trimming/adjustments before any kind of allocations. You are right and it looks suspicious, but the first page is reserved at the very beginning of x86::setup_arch() and, moreover, memblock never allocates it (look at memblock::memblock_find_in_range_node()). As for the range 0x1000 <-> reserve_low, we are unlikely to allocate it in the default top-down mode. The bottom-up mode was only allocating memory above the kernel so this would also prevent allocation of the lowest memory, at least until the recent changes for CMA allocation: https://lore.kernel.org/lkml/20201217201214.3414100-1-guro@fb.com That said, we'd better consolidate all the trim_some_memory() and move it closer to the beginning of setup_arch(). I'm going to take a look at it in the next few days. > -- > Thanks, > > David / dhildenb > -- Sincerely yours, Mike.