Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3018949rdb; Tue, 12 Sep 2023 22:04:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQtF/qkUdf3zmwGjiWyMP1SgtT+bgQmE75/7XlUy8+sjLd3rIwNwwWUKmtdbgsdIcp+e9t X-Received: by 2002:a1f:4b81:0:b0:495:d846:ebc0 with SMTP id y123-20020a1f4b81000000b00495d846ebc0mr1396354vka.16.1694581476912; Tue, 12 Sep 2023 22:04:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694581476; cv=none; d=google.com; s=arc-20160816; b=H+B2EE2eRRBdrtB1RiGu4qOyi4qe4UsDCXL+NVCOYn7KRtCTMC1nMuiOEJ0F3PoasO P2nzgX1mBffwdfbvka78aBqFtPhBaEV1ELwF0vXB4LujpXVducQlIrvC3IG1cKiWllo0 XWZ7Ad/QZuWpjRLICpt0EizC43Ij1He/JzQtHKjTWBxpeYL6AfEXhUqw17WXZHRvQ+N6 /04Jd3clIoQ7WBaFCRN5Et3AsjLQ7q8aaM1oeQisffnRXnotxTmvATL32h09RMQZxJqT hMdcfBYbtyV/UbEP8yE+uR3GY8MN9jVIxypZytFwa+qKyCbPqPYsJMdNVFUd4E8X4l2X OEKA== 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:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=fJ8L6QpBD//sqZK+hNaOJ0yvoOSMHQsUOH/807qzmTw=; fh=1rxWbse5Q4oxQgXvH6z3JfFMdt2Wo4Rlvt5WcDtlMWY=; b=FRUpFsLdyQbHvkZ6QxUTNBgoi/prvugEYZB4Hcjkg2jlCrM2jYnox+vnRR0RTlZGWq ZdJqvtMcMOeUCH0Py8Qf4J9VDxioXwiyvM+lfCsijr+rqLMkIVqUpqiUw/3Uqw1IMcLa 8F/89oqUKp+EyG2Mp/mNvHHAsyfYQk7JwW7AtC6862ULfyH1usmdk82/3PfByoWnNLdi ifRX9kBq7Ye0X7bWHnWPTr2I8NRfDp86hV0gKlbBoficYwi9RFw+a0Zgfm+I6NXT55J3 FX0IHYAgtqubKy1cDY+TsM4QdeI+14eCgPhq38HK5cTWSVlkAJzOUqDmHYgNIqUiZa+y xnZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=tS5UsJoo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id l190-20020a6388c7000000b005775e17f552si6126531pgd.249.2023.09.12.22.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 22:04:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=tS5UsJoo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 92798828DFDA; Tue, 12 Sep 2023 18:23:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238063AbjIMBXm (ORCPT + 99 others); Tue, 12 Sep 2023 21:23:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238050AbjIMBXj (ORCPT ); Tue, 12 Sep 2023 21:23:39 -0400 Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4401B1708 for ; Tue, 12 Sep 2023 18:23:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1694568212; bh=xWf1b2muuY0Mjkzl9OKGkFAm7aGKTwg/3EP4cheXjBQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=tS5UsJoo3AOqlMuGBTvriYqLuQg7XrL+uF1POWV7YQwjAOm9NKKiDu6R+LTd6HEkk gHPli3psuXCAeRDAFFII/FqhdJ5eilhSRPwAZ0IjHziKxw35K4W+Wsjnyp1LJPFCux zpdKcPx2B8ZTCs3BwEHVmdmlKkw1kiS9JVtLXZCY= Received: from [192.168.9.172] (unknown [101.88.25.36]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id 69BA360120; Wed, 13 Sep 2023 09:23:32 +0800 (CST) Message-ID: Date: Wed, 13 Sep 2023 09:23:31 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: [PATCH] LoongArch: Set all reserved memblocks on Node#0 at initialization Content-Language: en-US To: Huacai Chen Cc: Huacai Chen , loongarch@lists.linux.dev, Xuefeng Li , Guo Ren , Jiaxun Yang , linux-kernel@vger.kernel.org, loongson-kernel@lists.loongnix.cn, WANG Xuerui References: <20230911092810.3108092-1-chenhuacai@loongson.cn> From: WANG Xuerui In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 12 Sep 2023 18:23:46 -0700 (PDT) X-Spam-Status: No, score=-2.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email On 9/13/23 08:49, Huacai Chen wrote: > On Wed, Sep 13, 2023 at 12:08 AM WANG Xuerui wrote: >> On 9/11/23 17:28, Huacai Chen wrote: >>> After commit 61167ad5fecdea ("mm: pass nid to reserve_bootmem_region()") >>> we get a panic if DEFERRED_STRUCT_PAGE_INIT is enabled: >>> >>> [snip] >>> >>> The reason is early memblock_reserve() in memblock_init() set node id >> Why is it that only "early" but not "late" memblock_reserve() matters? I >> failed to see the reason because the arch-specific memblock_init() isn't >> even in the backtrace, which means that *neither* is the culprit. > Late memblock_reserve() operates on subregions of memblock.memory > regions. These reserved regions will be set to the correct node at the > first iteration of memmap_init_reserved_pages(). Thanks for the clarification. According to the code behavior (and the comment I left on the reordering change below) I'm now sure the intended meaning is "calling memblock_reserve() after memblock_set_node() is effectively leaving those regions with nid=MAX_NUMNODES" (or something like that, pointing out that the memblock_set_node() call actually had no effect in this case). "Early" and "late" in the context of init code can be especially confusing IMO :-) > > Huacai > >>> to MAX_NUMNODES, which causes NODE_DATA(nid) be a NULL dereference in >> "making NODE_DATA(nid) a NULL ..." >>> reserve_bootmem_region() -> init_reserved_page(). So set all reserved >>> memblocks on Node#0 at initialization to avoid this panic. >>> >>> Reported-by: WANG Xuerui >>> Signed-off-by: Huacai Chen >>> --- >>> arch/loongarch/kernel/mem.c | 4 +++- >>> 1 file changed, 3 insertions(+), 1 deletion(-) >>> >>> diff --git a/arch/loongarch/kernel/mem.c b/arch/loongarch/kernel/mem.c >>> index 4a4107a6a965..aed901c57fb4 100644 >>> --- a/arch/loongarch/kernel/mem.c >>> +++ b/arch/loongarch/kernel/mem.c >>> @@ -50,7 +50,6 @@ void __init memblock_init(void) >>> } >>> >>> memblock_set_current_limit(PFN_PHYS(max_low_pfn)); >>> - memblock_set_node(0, PHYS_ADDR_MAX, &memblock.memory, 0); >>> >>> /* Reserve the first 2MB */ >>> memblock_reserve(PHYS_OFFSET, 0x200000); >>> @@ -58,4 +57,7 @@ void __init memblock_init(void) >>> /* Reserve the kernel text/data/bss */ >>> memblock_reserve(__pa_symbol(&_text), >>> __pa_symbol(&_end) - __pa_symbol(&_text)); >>> + >>> + memblock_set_node(0, PHYS_ADDR_MAX, &memblock.memory, 0); >>> + memblock_set_node(0, PHYS_ADDR_MAX, &memblock.reserved, 0); >> So the reordering is for being able to override the newly added >> memblocks' nids to 0, and additionally doing the same for >> memblock.reserved is the actual fix. Looks okay. >>> } >> And I've tested the patch on the 2-way 3C5000L server, and it now >> correctly boots with deferred struct page init enabled. Thanks for >> providing such a quick fix! >> >> Tested-by: WANG Xuerui >> Reviewed-by: WANG Xuerui # with nits addressed >> >> -- >> WANG "xen0n" Xuerui >> >> Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/ >> >> -- WANG "xen0n" Xuerui Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/