Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2383007iof; Wed, 8 Jun 2022 03:56:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+EUWghkrMaGrzwoTMAXVU3oOyLPneJNBjzO+XENcvvHidvuq0lPr4w488T7SL2Gt6F4zR X-Received: by 2002:a05:6a00:a8f:b0:51b:5ca1:47f1 with SMTP id b15-20020a056a000a8f00b0051b5ca147f1mr34072883pfl.50.1654685775117; Wed, 08 Jun 2022 03:56:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654685775; cv=none; d=google.com; s=arc-20160816; b=QiNTTX3daSqyYbKvLCRcL+TEiMeaZ1D5xLwhtRxq1dQRQtHvPAHwgiaCd9ME4of+3G 74pI9Pti5ma8r6/RkYb/WwM0mvYDEiJwGpkUqt5t+bZsPS0mPbGhKhW2orRvlRF52Yho caWTEUNXxvRwtsAy5/03PRt9uM6937UWz8Y23uoJLscR4aq8WxeR1Git+d0aLGTV51F2 BFhFFejLIOgzuP2JZrilVysi05BA1UrMLsPtlMnOqjm6t3tPYQIS2Bn5XZxYK37dEvp1 G8w9nMu/3z8SMHNF6xbqD+lSbiBYZcJQz0SNLo5lFmWVZtfaw2dumjGGy33cAIOmBMab xAZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=sEHEjRGmX36MVX7I3CW3Ag7ueRgzzBbF2Okws9bZlv4=; b=0fQlYOmA6d9WsY7s4N/UXXCEnNPl7WRSssCA1lvJq3I8uZgux/ewQl/JowrPaf9U3h IlHEtMSM5f5DR0GDnzihVyDgKnmvSkfJDSEOuL0/VMtlfazYm7p0xy22isWwB2kAvIil FYlMUJlFJn31A+yogvXjMsWGgrFZ2tkn3Rf94iQ9HnUyJ94oo/z9QCA5ekwq5R14+vyc 0poVFJLLE1z5X/EL1ObPN4JD1YXGurP9eMeJhIyC4GmzFr8JEYP8qpBwunwC8e2D8GLZ GAyOkv0qHxd/181N48XVO1Yf3bMJ+FAj0FPoMJnojeAm0mDW5EAxUbIuuBRCY+hYcpsM G1qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RC45oZuU; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id j4-20020a635504000000b003f9d5d48e42si27602116pgb.99.2022.06.08.03.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 03:56:15 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RC45oZuU; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9C22B1790B8; Wed, 8 Jun 2022 03:21:39 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236570AbiFHKVQ (ORCPT + 99 others); Wed, 8 Jun 2022 06:21:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237677AbiFHKUB (ORCPT ); Wed, 8 Jun 2022 06:20:01 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 836AC1AA15E for ; Wed, 8 Jun 2022 03:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654682907; 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=sEHEjRGmX36MVX7I3CW3Ag7ueRgzzBbF2Okws9bZlv4=; b=RC45oZuUIaYCV0pYl2DpPztWCg1qt9CXFscOncoYpywEe8E4u6TqPO88xjH2aRRRygnQVq CHLCSmkY56iAPrMnSVGO79yV3ATxnel8Hx8LhCfESyWpNIEsqzdlugrbkLJF+OMO9oc+Jh ExE0VPzn+9lmtwJzGlkgZQhUaswu0xU= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-519-0vZOGhDaMqyopMruddCW_g-1; Wed, 08 Jun 2022 06:08:26 -0400 X-MC-Unique: 0vZOGhDaMqyopMruddCW_g-1 Received: by mail-wr1-f70.google.com with SMTP id v14-20020a5d610e000000b00213b51a0234so3995500wrt.11 for ; Wed, 08 Jun 2022 03:08:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=sEHEjRGmX36MVX7I3CW3Ag7ueRgzzBbF2Okws9bZlv4=; b=Q77ZOlCWsJANd1mTrNCDhJwac8UnEYXaW+14c547WBO8NSuX3M4rQsrSULGo88GjML 92mqCckhk8Qr2sQ5pcq6a0hpcJtIqorSwM4FN9ZEUBYNAX8icaFkrFeLqs+PryqJeoBl s1IAqFO/tXIbNa6WyaRa13rNXTmTCzGOZv05UNBoXlqBscdDbn6ThxBfjnKFKdJG/lxI f+BjYVa52LNpmVmCV/qiWRK/1R5A4QKY4WpK/XmfRPiLRfUyHDo70HhYEgGsUTpmdAKl gI7fCUou7rZ21sr77JLQt8UaBHXb8J5ujIQOXlQGyHqBPRjzrMkRzj61j72n2r1QgTjw /DRg== X-Gm-Message-State: AOAM53197MWLgwDofkjC16CVo/HHA+FtD5o7Yo5KMA1JF0fR69JkjC3e A/bdBQK0SkkENZ3pCf/rJXfeJFcXFUUi4soO9dWysjSOlZNP9nOo8vWXZ28yblKLRg0xjFjWU1/ rB030nrjdVt6gOyoJJsdYytvd X-Received: by 2002:a05:6000:170a:b0:215:6799:782c with SMTP id n10-20020a056000170a00b002156799782cmr25736327wrc.38.1654682905241; Wed, 08 Jun 2022 03:08:25 -0700 (PDT) X-Received: by 2002:a05:6000:170a:b0:215:6799:782c with SMTP id n10-20020a056000170a00b002156799782cmr25736249wrc.38.1654682904562; Wed, 08 Jun 2022 03:08:24 -0700 (PDT) Received: from ?IPV6:2003:cb:c705:ad00:db2:4c6:8f3a:2ec4? (p200300cbc705ad000db204c68f3a2ec4.dip0.t-ipconnect.de. [2003:cb:c705:ad00:db2:4c6:8f3a:2ec4]) by smtp.gmail.com with ESMTPSA id x4-20020adfffc4000000b0021018642ff8sm20678946wrs.76.2022.06.08.03.08.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Jun 2022 03:08:23 -0700 (PDT) Message-ID: Date: Wed, 8 Jun 2022 12:08:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH v3 5/6] mm: Add mirror flag back on initrd memory Content-Language: en-US To: Mike Rapoport , mawupeng Cc: ardb@kernel.org, corbet@lwn.net, will@kernel.org, catalin.marinas@arm.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, dvhart@infradead.org, andy@infradead.org, akpm@linux-foundation.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, paulmck@kernel.org, keescook@chromium.org, songmuchun@bytedance.com, rdunlap@infradead.org, damien.lemoal@opensource.wdc.com, swboyd@chromium.org, wei.liu@kernel.org, robin.murphy@arm.com, anshuman.khandual@arm.com, thunder.leizhen@huawei.com, wangkefeng.wang@huawei.com, gpiccoli@igalia.com, chenhuacai@kernel.org, geert@linux-m68k.org, chenzhou10@huawei.com, vijayb@linux.microsoft.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org References: <20220607093805.1354256-1-mawupeng1@huawei.com> <20220607093805.1354256-6-mawupeng1@huawei.com> <99900b31-2605-2c85-a1b7-9ef2666b58da@redhat.com> <29900b05-ec44-76a2-645a-22a13399d7fd@huawei.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: linux-kernel@vger.kernel.org On 08.06.22 12:02, Mike Rapoport wrote: > On Wed, Jun 08, 2022 at 03:27:09PM +0800, mawupeng wrote: >> >> 在 2022/6/7 22:49, Ard Biesheuvel 写道: >>> On Tue, 7 Jun 2022 at 14:22, David Hildenbrand wrote: >>>> >>>> On 07.06.22 11:38, Wupeng Ma wrote: >>>>> From: Ma Wupeng >>>>> >>>>> Initrd memory will be removed and then added in arm64_memblock_init() and this >>>>> will cause it to lose all of its memblock flags. The lost of MEMBLOCK_MIRROR >>>>> flag will lead to error log printed by find_zone_movable_pfns_for_nodes if >>>>> the lower 4G range has some non-mirrored memory. >>>>> >>>>> In order to solve this problem, the lost MEMBLOCK_MIRROR flag will be >>>>> reinstalled if the origin memblock has this flag. >>>>> >>>>> Signed-off-by: Ma Wupeng >>>>> --- >>>>> arch/arm64/mm/init.c | 9 +++++++++ >>>>> include/linux/memblock.h | 1 + >>>>> mm/memblock.c | 20 ++++++++++++++++++++ >>>>> 3 files changed, 30 insertions(+) >>>>> >>>>> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c >>>>> index 339ee84e5a61..11641f924d08 100644 >>>>> --- a/arch/arm64/mm/init.c >>>>> +++ b/arch/arm64/mm/init.c >>>>> @@ -350,9 +350,18 @@ void __init arm64_memblock_init(void) >>>>> "initrd not fully accessible via the linear mapping -- please check your bootloader ...\n")) { >>>>> phys_initrd_size = 0; >>>>> } else { >>>>> + int flags, ret; >>>>> + >>>>> + ret = memblock_get_flags(base, &flags); >>>>> + if (ret) >>>>> + flags = 0; >>>>> + >>>>> memblock_remove(base, size); /* clear MEMBLOCK_ flags */ >>>>> memblock_add(base, size); >>>>> memblock_reserve(base, size); >>>> >>>> Can you explain why we're removing+re-adding here exactly? Is it just to >>>> clear flags as the comment indicates? >>>> >>> >>> This should only happen if the placement of the initrd conflicts with >>> a mem= command line parameter or it is not covered by memblock for >>> some other reason. >>> >>> IOW, this should never happen, and if re-memblock_add'ing this memory >>> unconditionally is causing problems, we should fix that instead of >>> working around it. >> >> This will happen if we use initrdmem=3G,100M to reserve initrd memory below >> the 4G limit to test this scenario(just for testing, I have trouble to boot >> qemu with initrd enabled and memory below 4G are all mirror memory). >> >> Re-memblock_add'ing this memory unconditionally seems fine but clear all >> flags(especially MEMBLOCK_MIRROR) may lead to some error log. >> >>> >>>> If it's really just about clearing flags, I wonder if we rather want to >>>> have an interface that does exactly that, and hides the way this is >>>> actually implemented (obtain flags, remove, re-add ...), internally. >>>> >>>> But most probably there is more magic in the code and clearing flags >>>> isn't all it ends up doing. >>>> >>> >>> I don't remember exactly why we needed to clear the flags, but I think >>> it had to do with some corner case we hit when the initrd was >>> partially covered. >> If "mem=" is set in command line, memblock_mem_limit_remove_map() will >> remove all memory block without MEMBLOCK_NOMAP. Maybe this will bring the >> memory back if this initrd mem has the MEMBLOCK_NOMAP flag? >> >> The rfc version [1] introduce and use memblock_clear_nomap() to clear the >> MEMBLOCK_NOMAP of this initrd memblock. >> So maybe the usage of memblock_remove() is just to avoid introducing new >> function(memblock_clear_nomap)? >> >> Since commit 4c546b8a3469 ("memblock: add memblock_clear_nomap()") already >> introduced memblock_clear_nomap(). Can we use this to remove flag MEMBLOCK_NOMAP >> to solve this problem rather than bring flag MEMBLOCK_MIRROR back? > > AFAICT, there are two corner cases that re-adding initrd memory covers: > * initrd memory is not a part of the memory reported to memblock, either > because of firmware weirdness or because it was cut out with mem= > * initrd memory overlaps a NOMAP region > > So to make sure initrd memory is mapped properly and retains > MEMBLOCK_MIRROR I think the best we can do is > > memblock_add(); > memblock_clear_nomap(); > memblock_reserve(); Would simply detect+rejecting to boot on such setups be an option? The replies so far indicate to me that this is rather a corner case than a reasonable use case. -- Thanks, David / dhildenb