Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp93766pxb; Wed, 4 Nov 2020 15:44:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYY/MuftoXtVTmKnUlJoy9i6M1PgSyRRH8SysUAb4phTz4Eo8NgNb3C61TIG0v+/hMkNgs X-Received: by 2002:a17:906:22c6:: with SMTP id q6mr481388eja.433.1604533474650; Wed, 04 Nov 2020 15:44:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604533474; cv=none; d=google.com; s=arc-20160816; b=Ei7uIv4NQ7rdZXZa50yC+5aHH1b3CdjxheZWoHKVzFlXecSiI8c3/uJvo69nduCLuv Sh+sOVoVXwT5mRJu9dHbLwlbmoX//UFtyxL+A8qERMTpSVUfOaHCKxLNduD2rPN7EX9l 8mghZotHwlNWIJftnLCk3WppDtMtKktuhCskvhU9kfOzSv7O8oIuFceEWDWSGBaWWS/O K3v3gKl/hje3jYrfDfNV0iZgqqrjvXCKY6TIZ/mprB/f0RvH3t0Sl1Zx7fH/ujqhi07A NYj0sSxGakK7BEGN2EB0VBlKMhk/0FwpAw3mCA2/BjzqSkhfE8k7JmBIeuTRVm5fnZDE aZgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=a0nZYDo+CB6TegF98IJWvC66Pi+L/HwyZcY9j3Daq1w=; b=0G7ub6lzDFzwwvXAmDZ0at4ZnHqYqsihi6PmQnfHLv6K5QybYN/dKZFXh/UhEVQnxD OBMMDn0GH0LdiUZ8f/O8BktlRBmEunmpj9HceS12TjaHL/xIYog9ec4RWlAXuFLnlYnY RGU0tJBKh+MtqGSekSvahFoCYQMmTmYEIYf1osOI9GtT4nXc5Lk+FK64Y3CD5817t2dx TLcHpPWXyZscE2zOFqUNXNutvmGREtnaIeFKXxvDclf00dmn6icxwW0wZz2UVIAS8t9Q Z5O7AB5xndVuE4CT0d0ycnp5p+NCSs9v0jKlJb9s6XqlzL89fQ4rM83bewtmF2R4L+I8 VT5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=LVGPZfXn; 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 op24si1619179ejb.355.2020.11.04.15.44.01; Wed, 04 Nov 2020 15:44:34 -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=@atishpatra.org header.s=google header.b=LVGPZfXn; 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 S1732671AbgKDXht (ORCPT + 99 others); Wed, 4 Nov 2020 18:37:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726033AbgKDXht (ORCPT ); Wed, 4 Nov 2020 18:37:49 -0500 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AA0EC0613CF for ; Wed, 4 Nov 2020 15:37:49 -0800 (PST) Received: by mail-io1-xd43.google.com with SMTP id s10so373225ioe.1 for ; Wed, 04 Nov 2020 15:37:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=a0nZYDo+CB6TegF98IJWvC66Pi+L/HwyZcY9j3Daq1w=; b=LVGPZfXnEEe0PxuGVdeEhrmM549qsPkmNywLDOHuGXHLa9ITAjuP0e0LQcdiN2qINs 8Wat9PYnLvO2P+CCIWwaewexubKRK04XKlsykS5EQ4lpNU4xFUvCJRp16Iaq0Uouh1/y bhL5ia+m/XYcqspf6hohb4I8QjY71vnEaUJ6c= 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; bh=a0nZYDo+CB6TegF98IJWvC66Pi+L/HwyZcY9j3Daq1w=; b=BxBJcsnD25MLg43vLpGULmaRZ9r/0GqJtvO6OlhYDfjNlFbk42kzakJIKBcvzU2GUt 7UFHof51NBHNqxBIqHhGXArGTacNIiBib/n/rOi/FIp7JqRHUs2vWzddRu9QMeNu7XJz pImzCX8apNCkNoMgBru0HO4sQmrh2xdBRIqhlvfKwfY94EvoGZkpX0z/jJgeAx4/Y/pU LKvmVAqdR5whZBcrow+YiDSz9MNpw7USS3kwGcKv6oDPNBHOM6dWhuzDu6N0zSfmRZmj TooqQwpUxf8iQTS/+C469FAYMQAbyxwtsKaI1+qHWhWabMBhgWCUjmugGYdok8fbK+ns EDoA== X-Gm-Message-State: AOAM530M94hLsrkexLAs8J5RkKMUEUurj9QWdOqsrAFgzx6tRSbQyB44 +K4U8cQth2g3KK9PjumD4FLEOfazOIbfzwbPMM9W X-Received: by 2002:a05:6602:2d93:: with SMTP id k19mr312922iow.51.1604533068376; Wed, 04 Nov 2020 15:37:48 -0800 (PST) MIME-Version: 1.0 References: <20201104063713.3039035-1-anup.patel@wdc.com> In-Reply-To: <20201104063713.3039035-1-anup.patel@wdc.com> From: Atish Patra Date: Wed, 4 Nov 2020 15:37:37 -0800 Message-ID: Subject: Re: [PATCH] RISC-V: Use non-PGD mappings for early DTB access To: Anup Patel , Palmer Dabbelt Cc: Palmer Dabbelt , Paul Walmsley , Albert Ou , Anup Patel , "linux-kernel@vger.kernel.org List" , Atish Patra , Alistair Francis , linux-riscv Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 3, 2020 at 10:37 PM Anup Patel wrote: > > Currently, we use PGD mappings for early DTB mapping in early_pgd > but this breaks Linux kernel on SiFive Unleashed because on SiFive > Unleashed PMP checks don't work correctly for PGD mappings. > Not sure why this is an issue with Unleashed only. Microchip Polarfire SoC seems to work fine with early DTB pa as 0x88000000. However, unleashed fails to boot if the DTB is loaded any address below 0xC0000000 and it is mapped via PGD. > To fix early DTB mappings on SiFive Unleashed, we use non-PGD > mappings (i.e. PMD) for early DTB access. > > Fixes: 8f3a2b4a96dc ("RISC-V: Move DT mapping outof fixmap") > Signed-off-by: Anup Patel > --- > arch/riscv/mm/init.c | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c > index ea933b789a88..0d13d0c36a7d 100644 > --- a/arch/riscv/mm/init.c > +++ b/arch/riscv/mm/init.c > @@ -297,6 +297,7 @@ pmd_t fixmap_pmd[PTRS_PER_PMD] __page_aligned_bss; > #define NUM_EARLY_PMDS (1UL + MAX_EARLY_MAPPING_SIZE / PGDIR_SIZE) > #endif > pmd_t early_pmd[PTRS_PER_PMD * NUM_EARLY_PMDS] __initdata __aligned(PAGE_SIZE); > +pmd_t early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE); > > static pmd_t *__init get_pmd_virt_early(phys_addr_t pa) > { > @@ -494,6 +495,18 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) > load_pa + (va - PAGE_OFFSET), > map_size, PAGE_KERNEL_EXEC); > > +#ifndef __PAGETABLE_PMD_FOLDED > + /* Setup early PMD for DTB */ > + create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA, > + (uintptr_t)early_dtb_pmd, PGDIR_SIZE, PAGE_TABLE); > + /* Create two consecutive PMD mappings for FDT early scan */ > + pa = dtb_pa & ~(PMD_SIZE - 1); > + create_pmd_mapping(early_dtb_pmd, DTB_EARLY_BASE_VA, > + pa, PMD_SIZE, PAGE_KERNEL); > + create_pmd_mapping(early_dtb_pmd, DTB_EARLY_BASE_VA + PMD_SIZE, > + pa + PMD_SIZE, PMD_SIZE, PAGE_KERNEL); > + dtb_early_va = (void *)DTB_EARLY_BASE_VA + (dtb_pa & (PMD_SIZE - 1)); > +#else > /* Create two consecutive PGD mappings for FDT early scan */ > pa = dtb_pa & ~(PGDIR_SIZE - 1); > create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA, > @@ -501,6 +514,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) > create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA + PGDIR_SIZE, > pa + PGDIR_SIZE, PGDIR_SIZE, PAGE_KERNEL); > dtb_early_va = (void *)DTB_EARLY_BASE_VA + (dtb_pa & (PGDIR_SIZE - 1)); > +#endif > dtb_early_pa = dtb_pa; > > /* > -- > 2.25.1 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv FWIW: Tested on Unleashed & Polarfire SoC. Tested-by: Atish Patra Reviewed-by: Atish Patra @palmer: Can you consider this patch in next rcX PR ? -- Regards, Atish