Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1397656rwd; Wed, 7 Jun 2023 15:56:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6NaCjtybify5LvskAq7HuEOKcAkrwr5BeGnQZ5F572HELT2r6I4KHF6aBcAW3ortoVsMP6 X-Received: by 2002:a17:902:f545:b0:1af:fe12:4e18 with SMTP id h5-20020a170902f54500b001affe124e18mr4274625plf.20.1686178581763; Wed, 07 Jun 2023 15:56:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686178581; cv=none; d=google.com; s=arc-20160816; b=dY4lpE4kSlMwLVUeGTQeke7Hd35nb7y1SM1Gw9OIE6G2oPbZ6E7R+5fTE8/U2X1qwM XrRPGxSyemsfOvmwjWYIFk+OqOJ44u9rCQGsXex2xjqXUKlkW7PmeH6gSVPynknAdxzb cyypont/Tl1rrnoj3NMiqrCENnqJEcX0EONqyMHl9GMji2PGmGshbebkd5x19h7EUVvJ VumTnVD9iZSPiL+4ogr+qfroSBc8+vY04YgImepM3fA3JYAkuow64hKy7qHSomaGDDcL LEhlh3YojQwYBunXwBdTKLit285i3bpu8FuWXWOb9CR1c7PaldSiEui4o+YA1Uz+IeZ3 b2gg== 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:subject:cc:to:from:date:message-id:dkim-signature; bh=cCAUrNmU+J815DYSZ5cktA1xY0j369ZobkcNeWzlNRk=; b=PYj8g6Vb3VlaQDttmeJL6dlT4GpLFJKw/okWbzVzRRuR/jI21oy/T0fvmaKlrE9XjH p98RgH4ut/Ac6t2Vt8tfK7izxc496OxwWdUnUzEf9dgSAk+mqIWDQb+sNoQ3RV2+mtl/ lRFOguP1syPkILEDnxtMd0Ti3CkDJxKrtLpFSPDrk0jtAj5b+MDktYzti1BpU7FXx5uY ApY6cs8Q5uVYToZRJbn1KsfqwqNbqZdXewuAOMifxBxXt0/zM7ptX+pDw0E6gZVpo2dw LRIvyeNesN+liltBKf1G5g+Ezdx1d9sVBUr3g4kheCkeOUqqqRPQb2+ZZVGtK0Ij9QUj OUWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=lEQB8zPB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jj11-20020a170903048b00b001ab039a411csi77814plb.17.2023.06.07.15.56.09; Wed, 07 Jun 2023 15:56:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=lEQB8zPB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232210AbjFGWn2 (ORCPT + 99 others); Wed, 7 Jun 2023 18:43:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230479AbjFGWn1 (ORCPT ); Wed, 7 Jun 2023 18:43:27 -0400 X-Greylist: delayed 1555 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 07 Jun 2023 15:43:22 PDT Received: from out203-205-221-242.mail.qq.com (out203-205-221-242.mail.qq.com [203.205.221.242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC49F1BDD for ; Wed, 7 Jun 2023 15:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1686177800; bh=cCAUrNmU+J815DYSZ5cktA1xY0j369ZobkcNeWzlNRk=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=lEQB8zPBROkJdjQ9M/gpk/Y2vHdtl3Wz2G0Z7DGgPlJbhE/bBPek7Vbnh8FFy5GB5 MeO+XkFLCUjUWmrNjoh6MCe4Zkvf+lwuP+ENI3ce72kjO0GuWqeOAoM/nUtB0JOm3V ak4sapX6BJb4z422KWz0s027AtPh/6/T0beyvW/s= Received: from localhost ([101.224.149.128]) by newxmesmtplogicsvrsza12-0.qq.com (NewEsmtp) with SMTP id 45691E38; Thu, 08 Jun 2023 06:17:22 +0800 X-QQ-mid: xmsmtpt1686176242t9fsqhh9d Message-ID: X-QQ-XMAILINFO: M/KZc43Jb0t6fZLsxm96JoAJQZPFjaWS36XYe1dvHTvjmeJMArfgm0LyjcSCZv 8tsaaiZE5Jo5PKS9RiucQ2gpPFKy/mLp0dKx8/g7g1K/19jUlopw1++CeQBrCcclgcld9Hl7mEuy PhLH6mWn21F4HTI1xhJa7W7kaZx6hir+HOBGvN/KulSLN118IlXeyNDBeSoufYu3FYb14aVZ4PGk /TG7YB4U/aCMp36XBkhHmG+Us8HqXImvf89UwfXFJZltnvaLshq/IMtA48MmV/L31c0HizgDBjPb jZnh7zgtS5wzKNg7e+l6c5DUP+jpTHlI07sd523vw76XAUgdV8VMK+0sN1YEFzHv5FHZwienqN7g Pleg/QpUgsxw+5Pifczx0wBbLcg0zmHuN45rlJ9IfkGtizP5WAYYISLQ196aOy0u0muiDPnLNK2P ViNFm3F87h8aUcmes9JhJK9dJkTvlBmbVe8VfATwX9KTq3oiMldHAadPlaMJsWmSCu1jnnVVf2qX YRwbnC1Q0JuyH6RQ+fY58Qwa4DTSAMia6WikMwGHOz0PIffK0iEd7OlM7eLTZPg0y/juMyKBSdKw ekZ+jkrM6jby/t73FKRkjTn2K8xTAy5+76GYGcclOu+XbAkUloNDDeEYUNJVNq0eAn0AWWTUXbF5 3mmtvOoGtMFsa0ouAZbJsmSfe8j1xZev2sR5uFrbX1gYnwhL+8WbZOeeSuK1NSAcoAzm84wZBN81 pea3xKqZz1MBpaHNYH2aXRDrXCyr9XzkFBkZWqcDoMGqUcWp3GJUXaEAYBkUbhZi+6W+kjjAfUDU YNgBInUWA+z3osMjmocBjsLfB1i9IeUWUnKz/N0YFGYqJSkEndWh1fwFD9GdG31kMSVsmaK7B+yh 9xQUZTBEBCGlyfW3uX73h/BuCk8U7T1sH1+oTMG/HYJN7dlpJn6jD4duuSFQwsvSaVmPmtBtWJ8y CAUc6ZUEYYDjDFGPkjgw== Date: Thu, 8 Jun 2023 06:17:22 +0800 From: Woody Zhang To: Conor Dooley Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, alexghiti@rivosinc.com Subject: Re: [PATCH] riscv: reserve DTB before possible memblock allocation X-OQ-MSGID: References: <20230607-jogging-grudging-70dede86bc53@spud> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230607-jogging-grudging-70dede86bc53@spud> X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HELO_DYNAMIC_IPADDR,RCVD_IN_DNSWL_NONE,RDNS_DYNAMIC,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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 Hi, Conor On Wed, Jun 07, 2023 at 07:17:28PM +0100, Conor Dooley wrote: >+CC Alex, you should take a look at this patch. > >On Wed, Jun 07, 2023 at 09:35:19PM +0800, Woody Zhang wrote: >> It's possible that early_init_fdt_scan_reserved_mem() allocates memory >> from memblock for dynamic reserved memory in `/reserved-memory` node. >> Any fixed reservation must be done before that to avoid potential >> conflicts. >> >> Reserve the DTB in memblock just after early scanning it. > >The rationale makes sense to me, I am just wondering what compelling >reason there is to move it away from the memblock_reserve()s for the >initd and vmlinux? Moving it above early_init_fdt_scan_reserved_mem() >should be the sufficient minimum & would keep things together. IMO, moving it to parse_dtb() is more reasonable as early scanning and reservation are both subject to DTB. It can also lower the risk to mess up the sequence in the future. BTW, it's also invoked in setup_machine_fdt() in arm64. Thanks, Woody > >Cheers, >Conor. > >> >> Signed-off-by: Woody Zhang >> --- >> arch/riscv/kernel/setup.c | 10 ++++++++++ >> arch/riscv/mm/init.c | 9 --------- >> 2 files changed, 10 insertions(+), 9 deletions(-) >> >> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c >> index 36b026057503..c147fa8da929 100644 >> --- a/arch/riscv/kernel/setup.c >> +++ b/arch/riscv/kernel/setup.c >> @@ -16,6 +16,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> #include >> @@ -256,6 +257,15 @@ static void __init parse_dtb(void) >> pr_err("No DTB passed to the kernel\n"); >> } >> >> + /* >> + * If DTB is built in, no need to reserve its memblock. >> + * Otherwise, do reserve it but avoid using >> + * early_init_fdt_reserve_self() since __pa() does >> + * not work for DTB pointers that are fixmap addresses >> + */ >> + if (!IS_ENABLED(CONFIG_BUILTIN_DTB)) >> + memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va)); >> + >> #ifdef CONFIG_CMDLINE_FORCE >> strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); >> pr_info("Forcing kernel command line to: %s\n", boot_command_line); >> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c >> index c6bb966e4123..f8c9a79acd94 100644 >> --- a/arch/riscv/mm/init.c >> +++ b/arch/riscv/mm/init.c >> @@ -254,15 +254,6 @@ static void __init setup_bootmem(void) >> */ >> early_init_fdt_scan_reserved_mem(); >> >> - /* >> - * If DTB is built in, no need to reserve its memblock. >> - * Otherwise, do reserve it but avoid using >> - * early_init_fdt_reserve_self() since __pa() does >> - * not work for DTB pointers that are fixmap addresses >> - */ >> - if (!IS_ENABLED(CONFIG_BUILTIN_DTB)) >> - memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va)); >> - >> dma_contiguous_reserve(dma32_phys_limit); >> if (IS_ENABLED(CONFIG_64BIT)) >> hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT); >> -- >> 2.39.2 >>