From nobody Wed Sep 3 01:49:32 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25819C6FA82 for ; Fri, 2 Sep 2022 12:44:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237278AbiIBMoc (ORCPT ); Fri, 2 Sep 2022 08:44:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237158AbiIBMmr (ORCPT ); Fri, 2 Sep 2022 08:42:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8643FE9252; Fri, 2 Sep 2022 05:32:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E1D1AB82A91; Fri, 2 Sep 2022 12:25:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BA52C433B5; Fri, 2 Sep 2022 12:25:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662121530; bh=IhVbyVuHrpBEk4YZR0s2ZpQoae/Jxu0YqRmfpMppHkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nDoKmnzndy05oxlT11L8XMrLTply5fHlVKmo8Nw6byxP9/J9AHuNbg24mgDTybgnN aVTSSX7oMuDO0dToefMqF4OP+nb21c2oG2Crsb1R6OAeZ5KtgOUMvw/EIhZJjBHnYu wmRrgw1dhf/Ft+WcP5z6gI7rGdCYz2DU5hZKZIwY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hsin-Yi Wang , Stephen Boyd , Mike Rapoport , Will Deacon , Michael Bestas Subject: [PATCH 4.19 38/56] arm64: map FDT as RW for early_init_dt_scan() Date: Fri, 2 Sep 2022 14:18:58 +0200 Message-Id: <20220902121401.651699297@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121400.219861128@linuxfoundation.org> References: <20220902121400.219861128@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Hsin-Yi Wang commit e112b032a72c78f15d0c803c5dc6be444c2e6c66 upstream. Currently in arm64, FDT is mapped to RO before it's passed to early_init_dt_scan(). However, there might be some codes (eg. commit "fdt: add support for rng-seed") that need to modify FDT during init. Map FDT to RO after early fixups are done. Signed-off-by: Hsin-Yi Wang Reviewed-by: Stephen Boyd Reviewed-by: Mike Rapoport Signed-off-by: Will Deacon [mkbestas: fixed trivial conflicts for 4.19 backport] Signed-off-by: Michael Bestas Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/mmu.h | 2 +- arch/arm64/kernel/kaslr.c | 5 +---- arch/arm64/kernel/setup.c | 9 ++++++++- arch/arm64/mm/mmu.c | 15 +-------------- 4 files changed, 11 insertions(+), 20 deletions(-) --- a/arch/arm64/include/asm/mmu.h +++ b/arch/arm64/include/asm/mmu.h @@ -98,7 +98,7 @@ extern void init_mem_pgprot(void); extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, unsigned long virt, phys_addr_t size, pgprot_t prot, bool page_mappings_only); -extern void *fixmap_remap_fdt(phys_addr_t dt_phys); +extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t pro= t); extern void mark_linear_text_alias_ro(void); =20 #endif /* !__ASSEMBLY__ */ --- a/arch/arm64/kernel/kaslr.c +++ b/arch/arm64/kernel/kaslr.c @@ -65,9 +65,6 @@ out: return default_cmdline; } =20 -extern void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size, - pgprot_t prot); - /* * This routine will be executed with the kernel mapped at its default vir= tual * address, and if it returns successfully, the kernel will be remapped, a= nd @@ -96,7 +93,7 @@ u64 __init kaslr_early_init(u64 dt_phys) * attempt at mapping the FDT in setup_machine() */ early_fixmap_init(); - fdt =3D __fixmap_remap_fdt(dt_phys, &size, PAGE_KERNEL); + fdt =3D fixmap_remap_fdt(dt_phys, &size, PAGE_KERNEL); if (!fdt) return 0; =20 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -183,9 +183,13 @@ static void __init smp_build_mpidr_hash( =20 static void __init setup_machine_fdt(phys_addr_t dt_phys) { - void *dt_virt =3D fixmap_remap_fdt(dt_phys); + int size; + void *dt_virt =3D fixmap_remap_fdt(dt_phys, &size, PAGE_KERNEL); const char *name; =20 + if (dt_virt) + memblock_reserve(dt_phys, size); + if (!dt_virt || !early_init_dt_scan(dt_virt)) { pr_crit("\n" "Error: invalid device tree blob at physical address %pa (virtual addre= ss 0x%p)\n" @@ -197,6 +201,9 @@ static void __init setup_machine_fdt(phy cpu_relax(); } =20 + /* Early fixups are done, map the FDT as read-only now */ + fixmap_remap_fdt(dt_phys, &size, PAGE_KERNEL_RO); + name =3D of_flat_dt_get_machine_name(); if (!name) return; --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -859,7 +859,7 @@ void __set_fixmap(enum fixed_addresses i } } =20 -void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t p= rot) +void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t pro= t) { const u64 dt_virt_base =3D __fix_to_virt(FIX_FDT); int offset; @@ -912,19 +912,6 @@ void *__init __fixmap_remap_fdt(phys_add return dt_virt; } =20 -void *__init fixmap_remap_fdt(phys_addr_t dt_phys) -{ - void *dt_virt; - int size; - - dt_virt =3D __fixmap_remap_fdt(dt_phys, &size, PAGE_KERNEL_RO); - if (!dt_virt) - return NULL; - - memblock_reserve(dt_phys, size); - return dt_virt; -} - int __init arch_ioremap_pud_supported(void) { /*