Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3025315pxb; Sun, 8 Nov 2020 23:46:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJx01W+hhxnIvOqnJaUxlV3rJF3giA8/LIH/p+gcvjfRnc3sUL5rcCdYSrpQyYr4HPSW3SC1 X-Received: by 2002:aa7:c546:: with SMTP id s6mr13889012edr.114.1604907977048; Sun, 08 Nov 2020 23:46:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604907977; cv=none; d=google.com; s=arc-20160816; b=zAfXShWnZuikGec1LHWUH0NXMoKLVotphSY84sDjftXg2VeEnLvOJHAoFpHFKO1uqd xJVUxfDQxYOukfo69obZgEoCqJPURfPshi2Q42rQvuTwCZMdf8ZioF1V+OphdZ0yySos coPUC1rQfV9gvMF0NdE/Qcjlh3URgZfFdRYlkvutzGGa7DdN48M/ni3ZRqE6ht523kGz V4DP+lO62rxA+2zMHc+GnOKzXtzcoRDj+79rimS+8pm7nuFbaso8bJu2cxleL2zibv7K cR9tg3WnfZG/evgspsyzaiq5/QsmiyEuSofqgLyu/e4AclS7RGTxdG7hVgC3U8aBDQy2 e85w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=BAzxImQeGew3V10Gaqbpb9UzE3FgbyZVObI8SUJB0VA=; b=bQdFVZjUtvCrVkQL6t5+9QiBwKcrDp8IAwy4VM39lsRCtyBLSQ9rnMNhHN4obCByUb jsrlJ/RKhTnQYpygEScDnMNVyc8GL2zEFj65c2cRpyl/0rixgBk0Nao4VHRnjks3mrN/ E/7k9QDEFLGg3r6/Sdm87y+2xoEJ/8HnMI7WqSWuyTwBxSEDKe8XPGQTAE2srR52U4By GUT8q2LNAi1ynUPG/7cc6ZmJcL9see+BJSL7YsAR6Ebm3+gXW1ZoEzEj8HCbCAbOf/Xc rK5wMkLnugUoI+ssZhUXjwFcgERTgN3Oxt20vLLCmjDZEyr7V7QsQrTFbUw/rlkmRT3c 1SOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=kVHWiVnD; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z2si6442946ejr.636.2020.11.08.23.45.53; Sun, 08 Nov 2020 23:46:17 -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=@sifive.com header.s=google header.b=kVHWiVnD; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729585AbgKIHoR (ORCPT + 99 others); Mon, 9 Nov 2020 02:44:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728038AbgKIHoR (ORCPT ); Mon, 9 Nov 2020 02:44:17 -0500 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38667C0613CF for ; Sun, 8 Nov 2020 23:44:17 -0800 (PST) Received: by mail-qv1-xf42.google.com with SMTP id 63so3618056qva.7 for ; Sun, 08 Nov 2020 23:44:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=BAzxImQeGew3V10Gaqbpb9UzE3FgbyZVObI8SUJB0VA=; b=kVHWiVnD0G8/FYfq6hhlxCzSZT8Njd8zOKuOz7NPGjAhjjj0yDi+s9MAL3my+eKufe YfH5JdtT9e7TuG7KQlDtqJS6O9cnBWPxylZObMOfQJJmymIwb2oGwkqPQ6pMPuD+BIp3 1WnqA/wxBv5Ghys0mPb8GZDuRbpEIikT1GbWB5OvIcIsqQlAN4lXNZm1OThjia98Mfde ipeqgHlDghxnMi4UHHLGoKlI1VPinX5A8jSNXCLS7rPrV/WB/Z1xdyRi1+p2Iuc/wLbf vTG6lHMIHNGie6nBkKS4V8sviX7IGbGp/f8W08hPk0b0lBJtOya+yhAzq+ADMz32LKD2 r9Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=BAzxImQeGew3V10Gaqbpb9UzE3FgbyZVObI8SUJB0VA=; b=fdrIRU0ATDvMbsB7hoojHOiV2/1k0LZbeePHZ3AZcLnYq65JxuaEde0aTtIdoDNKYW LNPPa9gvWFb9drS4OjwT3UYhNG4zZ/NoYmEfDNX1F7Fj5/MQDSgFz54qB3TEVmFt5ZQl ZqvIPJGufyLqJGvt8hKmEzi1PboB4PoZQP7iMdN9cVhHCrQQe1zDfWr3ni2wdMzovFs8 pEGd0LpbkhLtaEB89zrErLufnG2iVHoT8D1yuA97JBQvglZyysFiIVrTSBxuRKaXckyI 98Bv9TneJ4Ayhcg8w19EXhwlnCl5JKhwZr3M5EeAkpKRrYCic8rInf/8SzfhptfWFXOU JRCw== X-Gm-Message-State: AOAM530Ln8EzlwrNS+Zt7pl8wT2WWO0EhYSSZnoNLWLTy/jbhTcoW4tg Dgr+t+GV9/RL2bzeTVsIqPTG6Jy7BXjIKQCwWnGL2Q== X-Received: by 2002:ad4:55c2:: with SMTP id bt2mr2621224qvb.48.1604907855424; Sun, 08 Nov 2020 23:44:15 -0800 (PST) MIME-Version: 1.0 References: <20200917223716.2300238-1-atish.patra@wdc.com> <20200917223716.2300238-2-atish.patra@wdc.com> In-Reply-To: <20200917223716.2300238-2-atish.patra@wdc.com> From: Greentime Hu Date: Mon, 9 Nov 2020 15:44:03 +0800 Message-ID: Subject: Re: [PATCH v8 1/7] RISC-V: Move DT mapping outof fixmap To: Atish Patra Cc: Linux Kernel Mailing List , Anup Patel , Palmer Dabbelt , Albert Ou , Alistair Francis , Andrew Morton , Ard Biesheuvel , Arvind Sankar , Borislav Petkov , Heiko Carstens , Ingo Molnar , Kees Cook , linux-efi@vger.kernel.org, linux-riscv , Masahiro Yamada , Maxim Uvarov , Michal Simek , Mike Rapoport , Nick Desaulniers , Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Zong Li Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Atish Patra =E6=96=BC 2020=E5=B9=B49=E6=9C=8818=E6=97= =A5 =E9=80=B1=E4=BA=94 =E4=B8=8A=E5=8D=886:37=E5=AF=AB=E9=81=93=EF=BC=9A > > From: Anup Patel > > Currently, RISC-V reserves 1MB of fixmap memory for device tree. However, > it maps only single PMD (2MB) space for fixmap which leaves only < 1MB sp= ace > left for other kernel features such as early ioremap which requires fixma= p > as well. The fixmap size can be increased by another 2MB but it brings > additional complexity and changes the virtual memory layout as well. > If we require some additional feature requiring fixmap again, it has to b= e > moved again. > > Technically, DT doesn't need a fixmap as the memory occupied by the DT is > only used during boot. That's why, We map device tree in early page table > using two consecutive PGD mappings at lower addresses (< PAGE_OFFSET). > This frees lot of space in fixmap and also makes maximum supported > device tree size supported as PGDIR_SIZE. Thus, init memory section can b= e used > for the same purpose as well. This simplifies fixmap implementation. > > Signed-off-by: Anup Patel > Signed-off-by: Atish Patra > Reviewed-by: Palmer Dabbelt > Signed-off-by: Palmer Dabbelt > --- > arch/riscv/include/asm/fixmap.h | 3 --- > arch/riscv/include/asm/pgtable.h | 1 + > arch/riscv/kernel/head.S | 1 - > arch/riscv/kernel/head.h | 2 -- > arch/riscv/kernel/setup.c | 9 +++++++-- > arch/riscv/mm/init.c | 26 ++++++++++++-------------- > 6 files changed, 20 insertions(+), 22 deletions(-) > > diff --git a/arch/riscv/include/asm/fixmap.h b/arch/riscv/include/asm/fix= map.h > index 1ff075a8dfc7..11613f38228a 100644 > --- a/arch/riscv/include/asm/fixmap.h > +++ b/arch/riscv/include/asm/fixmap.h > @@ -22,9 +22,6 @@ > */ > enum fixed_addresses { > FIX_HOLE, > -#define FIX_FDT_SIZE SZ_1M > - FIX_FDT_END, > - FIX_FDT =3D FIX_FDT_END + FIX_FDT_SIZE / PAGE_SIZE - 1, > FIX_PTE, > FIX_PMD, > FIX_TEXT_POKE1, > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pg= table.h > index eaea1f717010..815f8c959dd4 100644 > --- a/arch/riscv/include/asm/pgtable.h > +++ b/arch/riscv/include/asm/pgtable.h > @@ -464,6 +464,7 @@ static inline void __kernel_map_pages(struct page *pa= ge, int numpages, int enabl > #define kern_addr_valid(addr) (1) /* FIXME */ > > extern void *dtb_early_va; > +extern uintptr_t dtb_early_pa; > void setup_bootmem(void); > void paging_init(void); > > diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S > index 0a4e81b8dc79..c6a37e8231a8 100644 > --- a/arch/riscv/kernel/head.S > +++ b/arch/riscv/kernel/head.S > @@ -259,7 +259,6 @@ clear_bss_done: > #endif > /* Start the kernel */ > call soc_early_init > - call parse_dtb > tail start_kernel > > .Lsecondary_start: > diff --git a/arch/riscv/kernel/head.h b/arch/riscv/kernel/head.h > index 105fb0496b24..b48dda3d04f6 100644 > --- a/arch/riscv/kernel/head.h > +++ b/arch/riscv/kernel/head.h > @@ -16,6 +16,4 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa); > extern void *__cpu_up_stack_pointer[]; > extern void *__cpu_up_task_pointer[]; > > -void __init parse_dtb(void); > - > #endif /* __ASM_HEAD_H */ > diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c > index 2c6dd329312b..edea7ef88402 100644 > --- a/arch/riscv/kernel/setup.c > +++ b/arch/riscv/kernel/setup.c > @@ -48,8 +48,9 @@ atomic_t hart_lottery __section(.sdata); > unsigned long boot_cpu_hartid; > static DEFINE_PER_CPU(struct cpu, cpu_devices); > > -void __init parse_dtb(void) > +static void __init parse_dtb(void) > { > + /* Early scan of device tree from init memory */ > if (early_init_dt_scan(dtb_early_va)) > return; > > @@ -62,6 +63,7 @@ void __init parse_dtb(void) > > void __init setup_arch(char **cmdline_p) > { > + parse_dtb(); > init_mm.start_code =3D (unsigned long) _stext; > init_mm.end_code =3D (unsigned long) _etext; > init_mm.end_data =3D (unsigned long) _edata; > @@ -76,7 +78,10 @@ void __init setup_arch(char **cmdline_p) > #if IS_ENABLED(CONFIG_BUILTIN_DTB) > unflatten_and_copy_device_tree(); > #else > - unflatten_device_tree(); > + if (early_init_dt_verify(__va(dtb_early_pa))) > + unflatten_device_tree(); > + else > + pr_err("No DTB found in kernel mappings\n"); > #endif > > #ifdef CONFIG_SWIOTLB > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c > index 787c75f751a5..2b651f63f5c4 100644 > --- a/arch/riscv/mm/init.c > +++ b/arch/riscv/mm/init.c > @@ -28,7 +28,9 @@ unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsign= ed long)] > EXPORT_SYMBOL(empty_zero_page); > > extern char _start[]; > -void *dtb_early_va; > +#define DTB_EARLY_BASE_VA PGDIR_SIZE > +void *dtb_early_va __initdata; > +uintptr_t dtb_early_pa __initdata; > > static void __init zone_sizes_init(void) > { > @@ -141,8 +143,6 @@ static void __init setup_initrd(void) > } > #endif /* CONFIG_BLK_DEV_INITRD */ > > -static phys_addr_t dtb_early_pa __initdata; > - > void __init setup_bootmem(void) > { > struct memblock_region *reg; > @@ -399,7 +399,7 @@ static uintptr_t __init best_map_size(phys_addr_t bas= e, phys_addr_t size) > > asmlinkage void __init setup_vm(uintptr_t dtb_pa) > { > - uintptr_t va, end_va; > + uintptr_t va, pa, end_va; > uintptr_t load_pa =3D (uintptr_t)(&_start); > uintptr_t load_sz =3D (uintptr_t)(&_end) - load_pa; > uintptr_t map_size =3D best_map_size(load_pa, MAX_EARLY_MAPPING_S= IZE); > @@ -448,16 +448,13 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) > load_pa + (va - PAGE_OFFSET), > map_size, PAGE_KERNEL_EXEC); > > - /* Create fixed mapping for early FDT parsing */ > - end_va =3D __fix_to_virt(FIX_FDT) + FIX_FDT_SIZE; > - for (va =3D __fix_to_virt(FIX_FDT); va < end_va; va +=3D PAGE_SIZ= E) > - create_pte_mapping(fixmap_pte, va, > - dtb_pa + (va - __fix_to_virt(FIX_FDT))= , > - PAGE_SIZE, PAGE_KERNEL); > - > - /* Save pointer to DTB for early FDT parsing */ > - dtb_early_va =3D (void *)fix_to_virt(FIX_FDT) + (dtb_pa & ~PAGE_M= ASK); > - /* Save physical address for memblock reservation */ > + /* Create two consecutive PGD mappings for FDT early scan */ > + pa =3D dtb_pa & ~(PGDIR_SIZE - 1); > + create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA, > + pa, PGDIR_SIZE, PAGE_KERNEL); Hi Anup, I hit a booting failure case in Unleashed board in v5.10-rc2. After debugging, it looks like something wrong in this patch. It will create 0x40000000 as a VA start address for this mapping in rv64 he= re. #define DTB_EARLY_BASE_VA PGDIR_SIZE but using __va(dtb_early_pa) to get the virtual address? if (early_init_dt_verify(__va(dtb_early_pa))) unflatten_device_tree(); Would you please to take a look at it? I am not sure if I misunderstand something. Thank you. :)