Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp331609pxb; Wed, 13 Jan 2021 05:00:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJwo8U8cIYye50ti6mSFMmUEGpIPTkb17J6kyM98gMZf10NvKjuIdluNgnKfK3KmNGUaWJKs X-Received: by 2002:a17:906:4c48:: with SMTP id d8mr1475915ejw.358.1610542812121; Wed, 13 Jan 2021 05:00:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610542812; cv=none; d=google.com; s=arc-20160816; b=rhqBooVktlCGXG+yA+aOIcvVpO/XlFurOhJ4ecD89xhWHGPPHSDgQw1pKyrgFhW6bq ZpbfwMdmjzexmiaiLzvH+AwT43u3AW1S3LyfVt0O97cGQSmWA6mlN9BAD/nfTUq/ksWB 7x+9eqEpLPFihhIsvYBj1RZMEeZD0mUVcYlx7fNXwZvxjqjdlLGuE5WPG+zMUUMbGNcN u6F5AxksPQFHf2NgEiAdMfIx4hlQm/8CE1W0yN6uFFRTVcetlwREhufkVuXzubwG3OpF M+RWPoCCeqM0SZF/D8CZLu+4DvfqF/a5ESuaHr4lxGiJXmuPh+KKj2Dde+8cVv+ewLZb g3lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature; bh=7nsO2Z05lgvOVyM24wIVwTlc9VT/JvRNyy+q3CKB1bM=; b=S0er9w4zxPPZ/K49sr+xg4G99DFsY2rmX4iDVAYr2kjuNTln7EA06EXhSadAgM+oHp KDgv4sp7rV/oPHT83Rv7g6/aMwkqiV7S1XBn2JRNolSA7OAQZwSRxbs/P81oS7dvkIWx DeKr/w+Jyl7QsMcHvROUhq+9BYNcpSCEzwrn4EVuI6pD3HDxBSiku4O3ofbxxVwmLhES Xc6UtXaCLOQehoXlPLUqqnMA5mHElVp3m+rNwgX/nUwAJqvl5M+EU/HtrWMrRrpQOL5+ 4qMVEuS1QVaukNDH8IfC+c2GUa/l9Y3ZIIUm4q44Btc+R+4LgA0filTVavc3koLWvK95 Tc/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gOp8+xp7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qq23si866930ejb.232.2021.01.13.04.59.48; Wed, 13 Jan 2021 05:00:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gOp8+xp7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726900AbhAMM6X (ORCPT + 99 others); Wed, 13 Jan 2021 07:58:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56007 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725770AbhAMM6W (ORCPT ); Wed, 13 Jan 2021 07:58:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610542615; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7nsO2Z05lgvOVyM24wIVwTlc9VT/JvRNyy+q3CKB1bM=; b=gOp8+xp7e9x3n4c9c+W01d285BTXjK8yqsGsNeO9LrsV4oTYb9e2xG/dIQYThD7KJQkCvG 0B8gCvEdhyhaO5VJwN4tmrjc4x/K7ksAbqRjZCczB5uA1zn9LNn5abekf7XF+NwHKujLpp aqI67r81f9VFuWyO8lomjSoGfCB9jtk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-160-QH7rhcI_NJy5ppwsNlzcaA-1; Wed, 13 Jan 2021 07:56:51 -0500 X-MC-Unique: QH7rhcI_NJy5ppwsNlzcaA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 71B12107ACFB; Wed, 13 Jan 2021 12:56:49 +0000 (UTC) Received: from [10.36.114.135] (ovpn-114-135.ams2.redhat.com [10.36.114.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 121505D6A8; Wed, 13 Jan 2021 12:56:45 +0000 (UTC) Subject: Re: [PATCH v3 1/2] x86/setup: don't remove E820_TYPE_RAM for pfn 0 To: Mike Rapoport , Andrew Morton Cc: 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 References: <20210111194017.22696-1-rppt@kernel.org> <20210111194017.22696-2-rppt@kernel.org> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <6ba6bde3-1520-5cd0-f987-32d543f0b79f@redhat.com> Date: Wed, 13 Jan 2021 13:56:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <20210111194017.22696-2-rppt@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. -- Thanks, David / dhildenb