Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1974234rwe; Fri, 2 Sep 2022 06:50:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR5zifUDyp7p4Dp5jL9sAU+2Wau30pEQ+DjGvOqwjYDDkJQXGzB1fVr/Fd/3kwNqwB0P24Oo X-Received: by 2002:a63:cc51:0:b0:41f:12f5:675b with SMTP id q17-20020a63cc51000000b0041f12f5675bmr30036640pgi.69.1662126651887; Fri, 02 Sep 2022 06:50:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662126651; cv=none; d=google.com; s=arc-20160816; b=qS/FsC98qPy3yMWcIyASKSH1Bh/v2uLEMnCn0+TxaRQlXQ2qEXTqa0WAS2On/y+3TL 4dFJfDlZ91uWvIPAVLkRa6pqF09wDhyWK/cdLnuA6HJdekyAWnT1hpOMVTfNo/rhS0+L l9URsln/acGRl1tIu5knJdKYmrLOUuUS3n+tfyZV7Wy9mPDTywICbC7HEpMgSC4L3iMf vrbcj532UfMlnx8o/QVd80kO/B5XkFsB1UYKR/wgr+KLFBquHgdHo5aIPoeAB/kTU8vQ CE7OYkdgOTiQlEFj4VcI30hc9jwXN5QtnRPPsAfKNLFDjMdAwsPrmB32zMB2DVqWmSg3 PMCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MT8ZFtX7taKWxJ9P4/mG7aOg13nXRY8kCjedDyIIHH4=; b=gwGvs2rx126tUxE/aGBGVaYj6CIFmtMxgd6Ts8gjn/AQS6RZTMFcGqtE3Jwn1hF1lo 9rGE8/Q+NtbeU3hTj0JEqTqD7usKhwWrZTswl67Q7sEm7WNRt/VoZTMNQWHmD60YGwlV k3OK5CMWBEwdSS5bOTBkr+sDeTiWaYMvVh664A9Bt8VVDfCVgwMssosmoZaifSsOInXM mL5NntHiZYCUtM8whujQaMAbwmRH6PqsbY1KZFR+mXc/PaUWbAln7xaagU/5niPHIuHP XyfufNOUV9zJXqP6bvqS5+6ZF/mINbmq0QzA97hBGxl706b48QIpz8ddM/v5uecUBwcm 7vfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2RfcrWlW; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p19-20020a056a000a1300b0052bceb2fe4esi2261594pfh.221.2022.09.02.06.50.14; Fri, 02 Sep 2022 06:50:51 -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=@linuxfoundation.org header.s=korg header.b=2RfcrWlW; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236277AbiIBM0K (ORCPT + 99 others); Fri, 2 Sep 2022 08:26:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236275AbiIBMZi (ORCPT ); Fri, 2 Sep 2022 08:25:38 -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 187ACDC08B; Fri, 2 Sep 2022 05:23:15 -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 E0590B829B6; Fri, 2 Sep 2022 12:22:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E531C433D7; Fri, 2 Sep 2022 12:22:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662121369; bh=3fcpXD+as3eRC0Verdoa2PQP1rMKSElj8/i6wDbbRtk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2RfcrWlWzjXH+gu7guylIYsQ2swRO8xU8D2OVykMWgiKaehxk/p0A74cHU/gc1btS ZTBX8JvVF//S8sRHfeZCUbYxE8FQ24VFyhg1fOh3i+YYY5yOqYGrpmSebiCRyrsJGu jTremtzFP8aIG3pLvegDBq7l8507CjIJRvNGbi+E= 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.14 27/42] arm64: map FDT as RW for early_init_dt_scan() Date: Fri, 2 Sep 2022 14:18:51 +0200 Message-Id: <20220902121359.743151703@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121358.773776406@linuxfoundation.org> References: <20220902121358.773776406@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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.14 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 @@ -91,7 +91,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 prot); extern void mark_linear_text_alias_ro(void); #endif /* !__ASSEMBLY__ */ --- a/arch/arm64/kernel/kaslr.c +++ b/arch/arm64/kernel/kaslr.c @@ -65,9 +65,6 @@ out: return default_cmdline; } -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 virtual * address, and if it returns successfully, the kernel will be remapped, and @@ -96,7 +93,7 @@ u64 __init kaslr_early_init(u64 dt_phys) * attempt at mapping the FDT in setup_machine() */ early_fixmap_init(); - fdt = __fixmap_remap_fdt(dt_phys, &size, PAGE_KERNEL); + fdt = fixmap_remap_fdt(dt_phys, &size, PAGE_KERNEL); if (!fdt) return 0; --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -179,9 +179,13 @@ static void __init smp_build_mpidr_hash( static void __init setup_machine_fdt(phys_addr_t dt_phys) { - void *dt_virt = fixmap_remap_fdt(dt_phys); + int size; + void *dt_virt = fixmap_remap_fdt(dt_phys, &size, PAGE_KERNEL); const char *name; + 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 address 0x%p)\n" @@ -193,6 +197,9 @@ static void __init setup_machine_fdt(phy cpu_relax(); } + /* Early fixups are done, map the FDT as read-only now */ + fixmap_remap_fdt(dt_phys, &size, PAGE_KERNEL_RO); + name = of_flat_dt_get_machine_name(); if (!name) return; --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -836,7 +836,7 @@ void __set_fixmap(enum fixed_addresses i } } -void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot) +void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot) { const u64 dt_virt_base = __fix_to_virt(FIX_FDT); int offset; @@ -889,19 +889,6 @@ void *__init __fixmap_remap_fdt(phys_add return dt_virt; } -void *__init fixmap_remap_fdt(phys_addr_t dt_phys) -{ - void *dt_virt; - int size; - - dt_virt = __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) { /*