Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1977615rwe; Fri, 2 Sep 2022 06:54:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR5soQ/hP0ZK6Gx3tCqDyDho/X5dKA6IQBBofmXoHc53I2IkkrDhsS1kAtgiCZnM1prDwOtc X-Received: by 2002:a63:d1a:0:b0:42a:d321:faa4 with SMTP id c26-20020a630d1a000000b0042ad321faa4mr30934593pgl.532.1662126856380; Fri, 02 Sep 2022 06:54:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662126856; cv=none; d=google.com; s=arc-20160816; b=XB/wEHS/VncEtObWKIXblknnQRQttFVqbfbhFHy+bP90WR4sPnLe//ZE2MBZI9jYjw J6vOGrW2SC3Qy2xveitrlZsFlICcPMVNq7jyMeRSEsEXR379vZN3N+B9IcQ1f8BEOAXm PLsLO9lv73zUsEmIX5gGknJ6k2j7wOQwWPGSTjHUNfQp34ofu/J4QEZYBQYtBlGm4VHY TbTyY9pNiZLBgk+DT23cUicSi1E6v3fOr6Hjktxt6jzjsJIy8vew0RGIv5E59EVvLyYT UPnQJjKs47AGKOwi1LpwZd4W5PbNE00HVpM4qEnDlihjrztf/aH+c1ueqCWXZx02y0xG 5F0g== 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=qmG4nc3ksiwwWi38WMFCQF5PleUAfgVBuPirB4ZClTw=; b=DX9k1aGYhmF8i7fTrQbL22tpKzZ7mnD2rl2DuyJ0p8QYT9ptHOo44rNjJgUmngjq8e WPf6LA2JisrxTf/xiVtoW541LlyJWm5XTkzFtVICkx0WcoPR57frw81742/b2BtACdAz wVnjjKAV5c4Ytu6IW7CjOUPPHmaiFcnxkFIvYDtn3lRXD2ypDspHdeXI/aIbj6mFIkrz fS6YWcTNlvHKoj19BZPM7dpx6WwrmwzZVARE+cmR8wC276De7UTAmApk/qpNfNDNJ8/j fBICbJcwNbTmtBZBchIWqNvQ0oDWkx7nCMzPCF9J6aNk/lsDz2LxdHQwLez1NeysvJ9u 6tjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="D9bS/9FG"; 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 fa16-20020a17090af0d000b001faf63a881fsi1067589pjb.144.2022.09.02.06.54.05; Fri, 02 Sep 2022 06:54:16 -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="D9bS/9FG"; 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 S236297AbiIBMXy (ORCPT + 99 others); Fri, 2 Sep 2022 08:23:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236214AbiIBMWs (ORCPT ); Fri, 2 Sep 2022 08:22:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1F59D7D2A; Fri, 2 Sep 2022 05:21:51 -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 dfw.source.kernel.org (Postfix) with ESMTPS id C21036210A; Fri, 2 Sep 2022 12:21:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3CDAC433C1; Fri, 2 Sep 2022 12:21:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662121306; bh=OMHiNt1YikKt3MUFMW0UMBSOVzf0m8ARmas6rDbfFeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D9bS/9FG+81bOlMjS+ioTazyPt5pjaYgx/TyvoBQVFVtqw0MevKNjXgM62AcLrKXU 7FQpL8ESnJTmGitdaSY0jAlPwti0AK2XAqfEuhv+uxeyZrVz1YVKgz35s9qID6YvOy v63Leg1H8DK5MCvOFJ/Pgw2/wQiChA8nnox+RfkA= 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.9 27/31] arm64: map FDT as RW for early_init_dt_scan() Date: Fri, 2 Sep 2022 14:18:53 +0200 Message-Id: <20220902121357.730656291@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121356.732130937@linuxfoundation.org> References: <20220902121356.732130937@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.9 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 @@ -90,7 +90,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 allow_block_mappings); -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); #endif /* !__ASSEMBLY__ */ #endif --- 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 @@ -178,7 +178,11 @@ 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); + + if (dt_virt) + memblock_reserve(dt_phys, size); if (!dt_virt || !early_init_dt_scan(dt_virt)) { pr_crit("\n" @@ -191,6 +195,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); + dump_stack_set_arch_desc("%s (DT)", of_flat_dt_get_machine_name()); } --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -718,7 +718,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; @@ -771,19 +771,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) { /*