From patchwork Thu Aug 8 17:38:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Yi Wang X-Patchwork-Id: 11084603 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 802AF1395 for ; Thu, 8 Aug 2019 17:39:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 697EE28705 for ; Thu, 8 Aug 2019 17:39:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BE6928B8D; Thu, 8 Aug 2019 17:39:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DB5AF28705 for ; Thu, 8 Aug 2019 17:39:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=csg7Q4XYV4b3I8eG92/YZVcgwKx/Xt9csP8aDHHkz4A=; b=gJnEtDvknucR6A xd5U2WGhjMKUbisjpRTmPhPb1iRolS0IWFKanyZdW4p8Me60z2fPGJWAq+C+E7n5sIPyCepaML1Z+ Lni6+pNQDXDjJNDiiB72WqIasC0Glwc5eUOmrJOaXhICdGhJEkqrAa4y2sJL4pideTh4Q6YnpgoSY +e2aq5NgmkkoGFDn18s28Kq8wfVSxYoowAPL9YlkRx6sxuxYx6IFrQ7qbdtQiWvS9CMCHhIEopoWu 7XE2ZmbsLELxC2ljwR1of3/zlLFvdAue/9BpORJqSmQdV2gLG1f/Z+gpzodQfLOHE64KXEMmYs43Q u6OfMVONx0cJfu0m90gg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hvmNf-0007JC-GL; Thu, 08 Aug 2019 17:39:15 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hvmNc-0007Ia-2G for linux-arm-kernel@lists.infradead.org; Thu, 08 Aug 2019 17:39:13 +0000 Received: by mail-pf1-x444.google.com with SMTP id r1so44485748pfq.12 for ; Thu, 08 Aug 2019 10:39:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PivmghTlXg+yY8gg+X2M9V5T2UndrrUwzo+s775Y6U8=; b=HHpzoMiaF5QhupFhProjPvOBj9oGQnHALREOCxFfhLfSn+pfoPk9RX+KzsevNoKNls 6xyK8/xouf8+f+jy8WNgV5bNkGQ6T2Ew2CmKtP8Bu0RADOs72TZarnXgyRsbY+VBI0Vg 0Snt2FqpxPHvF/Rngt8F418W/xqxPh61YbvG8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PivmghTlXg+yY8gg+X2M9V5T2UndrrUwzo+s775Y6U8=; b=hX8qy8H9uQ/+3zXztpmcAWKVL/cG0xLLLsiMNxzsPZiaVSwjXzu5O2Xbk+ZfwHKpR4 Bmqmr/iOgIpyi+XU1wXs62q7RobaGo4BSEXQkXym7aEAgHcJdQlkH5cnU48dcVWEdYeG LYXEywFz37aBQXfgM6ppKekYYcaYATsuRg2mPN8QmT0BEK0NfSWn6pzzBdCWd6jW1hV+ fnPEN51zDSjMP8HAUVyeDfVYqALGzYG/Ir0KwVdWzdW7Bi7sdbCfJcTmsMx7fK2M+sZb XzhoZI++cUpR8uoWp0t9MX1HnqpfCcQNJL2RP6QLrdZV0YcIZ0U1g95p/QGbE6SxiJUL bnzg== X-Gm-Message-State: APjAAAXHPOHJMo3IKwjWiMAv8tOHZxRnrS/yxjSC2ZSECzYxUPQrS77Y rA5EMPXkYAARHkHtz4Z5KA0ntqkaeIZNWA== X-Google-Smtp-Source: APXvYqzDwoJ1bfGRRVX4ijyV+Kjvr5aUWXV9BpWjc8owrLnexJYXDJnKMtB1tnb9rgb6Dvm8QMrETQ== X-Received: by 2002:a62:1444:: with SMTP id 65mr16498905pfu.145.1565285951080; Thu, 08 Aug 2019 10:39:11 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:b852:bd51:9305:4261]) by smtp.gmail.com with ESMTPSA id y12sm105824412pfn.187.2019.08.08.10.39.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Aug 2019 10:39:10 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH RESEND v7 1/3] arm64: map FDT as RW for early_init_dt_scan() Date: Fri, 9 Aug 2019 01:38:03 +0800 Message-Id: <20190808173803.1146-2-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190808173803.1146-1-hsinyi@chromium.org> References: <20190808173803.1146-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190808_103912_103349_C4B61284 X-CRM114-Status: GOOD ( 16.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Yu Zhao , Kees Cook , Ard Biesheuvel , Catalin Marinas , Stephen Boyd , Will Deacon , linux-kernel@vger.kernel.org, Mike Rapoport , Jun Yao , Miles Chen , Rob Herring , James Morse , Hsin-Yi Wang , Andrew Murray , Andrew Morton , Laura Abbott , Frank Rowand , Robin Murphy Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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(-) diff --git a/arch/arm64/include/asm/mmu.h b/arch/arm64/include/asm/mmu.h index fd6161336653..f217e3292919 100644 --- a/arch/arm64/include/asm/mmu.h +++ b/arch/arm64/include/asm/mmu.h @@ -126,7 +126,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); #define INIT_MM_CONTEXT(name) \ diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c index 708051655ad9..d94a3e41cef9 100644 --- a/arch/arm64/kernel/kaslr.c +++ b/arch/arm64/kernel/kaslr.c @@ -62,9 +62,6 @@ static __init const u8 *kaslr_get_cmdline(void *fdt) 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 @@ -93,7 +90,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; diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 9c4bad7d7131..25f5127210f8 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -170,9 +170,13 @@ static void __init smp_build_mpidr_hash(void) 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" @@ -184,6 +188,9 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys) 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; diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 63d730c5b7a9..bed9db92be24 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -876,7 +876,7 @@ void __set_fixmap(enum fixed_addresses idx, } } -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; @@ -929,19 +929,6 @@ void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot) 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_p4d_supported(void) { return 0;