Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4644041iob; Sun, 8 May 2022 20:23:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzp6jUgOqQgHMS6TpYei8OqO/kX0WIbo84ByLyb38qnkEe+oP6jt1SmNpSmJE9flRMLyKL6 X-Received: by 2002:a17:903:2d0:b0:14d:8a8d:cb1 with SMTP id s16-20020a17090302d000b0014d8a8d0cb1mr14551914plk.50.1652066594654; Sun, 08 May 2022 20:23:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652066594; cv=none; d=google.com; s=arc-20160816; b=JSl4bLqUxd/2Zrue4GnXmBUzer/sQhVrBQxyRWvJB7B1iIZTCxukCX0ByrDz6Okni2 hSwdebzukFluL6Q9tKa4+zbnlrOi0kSz2kX1OB6ED+qvjt0xFnn+TsaqBJGihFsEmRn0 as8oG0QOYftDTekpdRtQqVmAImAzTfmnp9QEbPe7+CxpEerdlknejKW7mIr83mvoKMk/ N2jkv+K8dKF17UCx49EvhxUBruF2yLwXHFOcJPl/kk/M5z/uqrHRrf1+hbgSRQgmo0WE Bp/2DRNNOFBsSzidUjYr+cw51VG/8jxJbkQFLdhJqBSuKV1mv6ywkSqHEFsiqdQOKPzS TamA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=rCa7eNjVeMppq8L/kUv69MDo2c/0xX5B3HNrUpKRUig=; b=AkVXmIxjme16pAPjDX/B+OHp2unCk0Beed2Syv711WQm4YRZLzqrCMUY2KLfCyv2O0 cKBwNf7e1KbDqjsW82AnVR11RNvQaAQNYvuFsBQCpQXpJQnd5OfRbAvWrb1u0GZ4c90A MruBOTHKgnKhCN4rS7oYwwffXR40TV5fGd9mNPQ5yDYS1oUsAnehsKsYAqqE5tKC5ea3 H790KmqJpiM3b97dkhUP/B7aqf9Toaf9LyqOmpIb84ga48rQRQ+JATC23TKd49A97iSp 1Zs15qUNvD88/7bN8W9DuJcH7iUAoDCwF3FcbaOLIS9nsVp819AU2MIttqUL4LqFSLDI WoRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RIDfblY2; 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 i20-20020a63e914000000b003c1d945a16dsi12385595pgh.215.2022.05.08.20.23.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 20:23:14 -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=RIDfblY2; 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 8808E49F06; Sun, 8 May 2022 20:21:18 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1444941AbiEFXT7 (ORCPT + 99 others); Fri, 6 May 2022 19:19:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1444933AbiEFXT6 (ORCPT ); Fri, 6 May 2022 19:19:58 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AA57E703E3 for ; Fri, 6 May 2022 16:16:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651878972; 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: in-reply-to:in-reply-to:references:references; bh=rCa7eNjVeMppq8L/kUv69MDo2c/0xX5B3HNrUpKRUig=; b=RIDfblY2TSfgIExBjZibhREWfWaLxRVZfybLNaBvJV8Fnh65OAAufmW08tvPIJKE6SX2cH xqqTzz+QtbFJ1NDQB61Xk/2ZxGnayh4vBoP+vOhqVkuwYp3C0wdBBU17pxv3YD4qWRxyxd 0cFccHzilWuQNeQPBOeLIf//9K2as6I= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-290-FjaEmhX_OJa2_SLMPyjh_Q-1; Fri, 06 May 2022 19:16:07 -0400 X-MC-Unique: FjaEmhX_OJa2_SLMPyjh_Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AFDAD185A794; Fri, 6 May 2022 23:16:06 +0000 (UTC) Received: from localhost (ovpn-12-33.pek2.redhat.com [10.72.12.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E5DE07AE3; Fri, 6 May 2022 23:15:59 +0000 (UTC) Date: Sat, 7 May 2022 07:15:56 +0800 From: Baoquan He To: Zhen Lei Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , linux-kernel@vger.kernel.org, Dave Young , Vivek Goyal , Eric Biederman , kexec@lists.infradead.org, Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Jonathan Corbet , linux-doc@vger.kernel.org, Randy Dunlap , Feng Zhou , Kefeng Wang , Chen Zhou , John Donnelly , Dave Kleikamp Subject: Re: [PATCH v24 4/6] of: fdt: Add memory for devices by DT property "linux,usable-memory-range" Message-ID: <20220506231556.GC122876@MiWiFi-R3L-srv> References: <20220506114402.365-1-thunder.leizhen@huawei.com> <20220506114402.365-5-thunder.leizhen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220506114402.365-5-thunder.leizhen@huawei.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 05/06/22 at 07:44pm, Zhen Lei wrote: > From: Chen Zhou > > When reserving crashkernel in high memory, some low memory is reserved > for crash dump kernel devices and never mapped by the first kernel. > This memory range is advertised to crash dump kernel via DT property > under /chosen, > linux,usable-memory-range = > > We reused the DT property linux,usable-memory-range and made the low > memory region as the second range "BASE2 SIZE2", which keeps compatibility > with existing user-space and older kdump kernels. > > Crash dump kernel reads this property at boot time and call memblock_add() > to add the low memory region after memblock_cap_memory_range() has been > called. LGTM, Acked-by: Baoquan He > > Signed-off-by: Chen Zhou > Co-developed-by: Zhen Lei > Signed-off-by: Zhen Lei > Reviewed-by: Rob Herring > Tested-by: Dave Kleikamp > --- > drivers/of/fdt.c | 33 +++++++++++++++++++++++---------- > 1 file changed, 23 insertions(+), 10 deletions(-) > > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c > index ec315b060cd50d2..2f248d0acc04830 100644 > --- a/drivers/of/fdt.c > +++ b/drivers/of/fdt.c > @@ -973,16 +973,24 @@ static void __init early_init_dt_check_for_elfcorehdr(unsigned long node) > > static unsigned long chosen_node_offset = -FDT_ERR_NOTFOUND; > > +/* > + * The main usage of linux,usable-memory-range is for crash dump kernel. > + * Originally, the number of usable-memory regions is one. Now there may > + * be two regions, low region and high region. > + * To make compatibility with existing user-space and older kdump, the low > + * region is always the last range of linux,usable-memory-range if exist. > + */ > +#define MAX_USABLE_RANGES 2 > + > /** > * early_init_dt_check_for_usable_mem_range - Decode usable memory range > * location from flat tree > */ > void __init early_init_dt_check_for_usable_mem_range(void) > { > - const __be32 *prop; > - int len; > - phys_addr_t cap_mem_addr; > - phys_addr_t cap_mem_size; > + struct memblock_region rgn[MAX_USABLE_RANGES] = {0}; > + const __be32 *prop, *endp; > + int len, i; > unsigned long node = chosen_node_offset; > > if ((long)node < 0) > @@ -991,16 +999,21 @@ void __init early_init_dt_check_for_usable_mem_range(void) > pr_debug("Looking for usable-memory-range property... "); > > prop = of_get_flat_dt_prop(node, "linux,usable-memory-range", &len); > - if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells))) > + if (!prop || (len % (dt_root_addr_cells + dt_root_size_cells))) > return; > > - cap_mem_addr = dt_mem_next_cell(dt_root_addr_cells, &prop); > - cap_mem_size = dt_mem_next_cell(dt_root_size_cells, &prop); > + endp = prop + (len / sizeof(__be32)); > + for (i = 0; i < MAX_USABLE_RANGES && prop < endp; i++) { > + rgn[i].base = dt_mem_next_cell(dt_root_addr_cells, &prop); > + rgn[i].size = dt_mem_next_cell(dt_root_size_cells, &prop); > > - pr_debug("cap_mem_start=%pa cap_mem_size=%pa\n", &cap_mem_addr, > - &cap_mem_size); > + pr_debug("cap_mem_regions[%d]: base=%pa, size=%pa\n", > + i, &rgn[i].base, &rgn[i].size); > + } > > - memblock_cap_memory_range(cap_mem_addr, cap_mem_size); > + memblock_cap_memory_range(rgn[0].base, rgn[0].size); > + for (i = 1; i < MAX_USABLE_RANGES && rgn[i].size; i++) > + memblock_add(rgn[i].base, rgn[i].size); > } > > #ifdef CONFIG_SERIAL_EARLYCON > -- > 2.25.1 >