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; From patchwork Thu Aug 8 17:38:05 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: 11084605 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 0AA781395 for ; Thu, 8 Aug 2019 17:39:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5FCD28705 for ; Thu, 8 Aug 2019 17:39:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6BA528B8D; Thu, 8 Aug 2019 17:39:33 +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 801E328705 for ; Thu, 8 Aug 2019 17:39:33 +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=pmu3buuCHqQbtCWbfhrG4/FmtuwRJP/L62AdSLdDO5o=; b=hQJcKM4moripFO ER9/K7Jv1HCX5VT19pAyYnhnlPAtpPapFNvQL5CNS2GYnVVi6jspKPmEXV9aCwJ6F2qKjhcaHi48i 0qhjOH931OSPP/cnElFPiBUQlIgpuXf542ASVLuP5hPJohMGDdlm8o9svBnNwLyCB/fhoaaKAKSUp OiWB1RKSaLr9OiXHq5tTluGqRdJVqQlrCQ+msLiMNCam2vQ6WVXt8JcNokG2EKFZAFij76vS7DYpb Jh4EAtNkaE1uHL6Cgz69kwgP4X476/rlxKhKoo0467K3Ck700saRHEzAEGF0X2vrn7x2meLMeAw1H rFZgMSJEJBRLm/ob2a6g==; 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 1hvmNw-0007bc-UI; Thu, 08 Aug 2019 17:39:32 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hvmNs-0007ZF-UU for linux-arm-kernel@lists.infradead.org; Thu, 08 Aug 2019 17:39:30 +0000 Received: by mail-pf1-x441.google.com with SMTP id r1so44486096pfq.12 for ; Thu, 08 Aug 2019 10:39:27 -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=DFyYlsPKtD2pIkl+6HQ9NsXCJu2oBYedJ0F8UrzQk24=; b=Yh9EIr82yon5IKwUIC8/aoF3FklHeBHZH9PfoCglI1X9pa0gurA07RhtfLxokIKnIz 81xyPWSnwnZLtp5kryW23U9msxajMEa5GnhdM44fHoSwcv0gQJEdVcOJVV7F2TrigyY7 Yl3Mm05/ax1pcApFg4xYKIsnxB9O+sRcfZRQ0= 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=DFyYlsPKtD2pIkl+6HQ9NsXCJu2oBYedJ0F8UrzQk24=; b=EnxCFdYgFL7oVY4SwQm/Y6eD63bgO+PwwWeQZGIEjugGSm2WWCQgCFmNVAJLoYNIsp 1rf/tX9k/Mkl4i1Pc/Z0rSgJYEJPxK/8D+SOuGMtfW7he6B60IfZl+Dfocw+OjuTICm8 l+DBWNzZ/VLU9tiLs8I1oS83eUfObX8TPvaQjdNjMq2DqXcDqVETKViIjRvMjsHsRy6b eQE4RKiSc0t8/c9i9Enjj33qFjwJohvIbKA/yY6rBemngsKiDiVABfjk9XhYDdUQn0BJ 44zEui+b6+M6/VE0tbHkOo1B5yrQ21ecCYo4dNSQizH5Dza+ZaoFqfnsmRD/AwFFv1SZ TUng== X-Gm-Message-State: APjAAAV68BsHwNZremebPYDDGHHRtjXy6a2GNhxmff5A7ZxhjolrGg/3 CDn30E9CGUGQKOcG13P6Nz/SRFuIRUWYDg== X-Google-Smtp-Source: APXvYqyEVq5aKjaC1auKdVBOl3Eitrh/DUCGqDLTS3ddRuXoM7KR+75fidcuNyU2aVJLs620qmfVoQ== X-Received: by 2002:a17:90a:d593:: with SMTP id v19mr5186942pju.1.1565285967016; Thu, 08 Aug 2019 10:39:27 -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.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Aug 2019 10:39:26 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH RESEND v7 2/3] fdt: add support for rng-seed Date: Fri, 9 Aug 2019 01:38:05 +0800 Message-Id: <20190808173803.1146-3-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_103928_982375_1BC508BA X-CRM114-Status: GOOD ( 14.97 ) 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 Introducing a chosen node, rng-seed, which is an entropy that can be passed to kernel called very early to increase initial device randomness. Bootloader should provide this entropy and the value is read from /chosen/rng-seed in DT. Signed-off-by: Hsin-Yi Wang Reviewed-by: Stephen Boyd Reviewed-by: Rob Herring --- drivers/of/fdt.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 9cdf14b9aaab..640c817cf65b 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -24,6 +24,7 @@ #include #include #include +#include #include /* for COMMAND_LINE_SIZE */ #include @@ -1044,6 +1045,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, { int l; const char *p; + const void *rng_seed; pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname); @@ -1078,6 +1080,14 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, pr_debug("Command line is: %s\n", (char*)data); + rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l); + if (rng_seed && l > 0) { + add_device_randomness(rng_seed, l); + + /* try to clear seed so it won't be found. */ + fdt_nop_property(initial_boot_params, node, "rng-seed"); + } + /* break now */ return 1; } From patchwork Thu Aug 8 17:38:07 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: 11084607 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 1AD00746 for ; Thu, 8 Aug 2019 17:39:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05E5128705 for ; Thu, 8 Aug 2019 17:39:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBF5F28B8D; Thu, 8 Aug 2019 17:39:50 +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 950D128705 for ; Thu, 8 Aug 2019 17:39:50 +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=WkHVdQXXSOv/9fS2LWbzHdzELLRJ0Cg6fRwTYwwj1cc=; b=ZZGfUQKCAJtTu7 6P+2ruCRmN1GR3b6Q+JsVAARG7ZHniHkBqlIsh8LitIORbGwfwmi7D1sNxO9awxzleHZzRNMq8c3u +HSxWmlRWnA+2hOjzvkKudMwGGtv0HDFqAzKVGMkNck2qI33TO77mg+kTOMeaOB45HNIgsiDyLLWS MvcyUeLXh90wLba2W3eTrkzeHECOhS5rvud47rDptZm5UmPuDmu4wIegErxcK37TTwYki0Ed04Oet 83NqANeOGqBkk16R/sgn69jnEQRK+Mz3IbAERnHu3s5JTMiY/7gIWPpsoCPxMelNptgPWVtxSb0/l 3kp/NphOdZXQWIbIbDZw==; 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 1hvmOE-0007rb-3K; Thu, 08 Aug 2019 17:39:50 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hvmOB-0007qc-14 for linux-arm-kernel@lists.infradead.org; Thu, 08 Aug 2019 17:39:48 +0000 Received: by mail-pg1-x544.google.com with SMTP id z14so7194967pga.5 for ; Thu, 08 Aug 2019 10:39:46 -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=h/yL8Ymy2LB/STS6J+Lq4m9W0ydt77fAXWIWGhH684M=; b=C0Tdu9oWw6g8jn0YCy/CUc0vBYErlEDkoKO0ggvyp3/u2SeUmwfPORoGPM4LeaiRRJ JnXa11Nr0XT7YDWpmLDBkLw+su/NAcq9L9MuzaABlUQVuFCoRTu/ea1ABq2d51thSbXa h3L4/ldUPBQ5CNJ3G5pzpA31cvXgxRP1Gqae0= 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=h/yL8Ymy2LB/STS6J+Lq4m9W0ydt77fAXWIWGhH684M=; b=nppPglOwfCdXoeRd06tNLozWJq7PKKi6Gicmfvn+RH8bDrewlbQOHRhUgm8a8oxSir MnxE+7bB5XOa7mZs8YlZiE3hDWkfyrf59uWnRmDKI7ktoa7loQwADL3BckIAvAT2bzQE hJ314kVKRQJq8RZg8HkjpExi24+QU+ZAmL3a7qljzzt7qpT2k+KspQ/j0XJDVM8azlqD nksdx58UZEjiFU/JfLkGA/6EDxw2VBEdDh/8QZzcSePtOb4DJEAz7y4s/2ILimx3AkIT CEHWxbVgyTPAG0VMDahyOO0j91XVz+Ywjs3N0cRp1GVT/gCOcKD7o9AH2SSDhJzCDInR OMXw== X-Gm-Message-State: APjAAAUKBHspb1wcQ2CWW1m4l2ly4Z/ci7UbagPFTVFXksC5DGlUVZA9 Frgzrzl2Bc+JsVB4SMRobkShD5L92fHaAQ== X-Google-Smtp-Source: APXvYqzhArDX4+b5Tep8MKl/+REDpR8R7lMugu/xbPdlvta78+f9dxTGpX+ohwloxZ3TNOhPSM5uEg== X-Received: by 2002:aa7:8a0a:: with SMTP id m10mr466871pfa.100.1565285986200; Thu, 08 Aug 2019 10:39:46 -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.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Aug 2019 10:39:45 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH RESEND v7 3/3] arm64: kexec_file: add rng-seed support Date: Fri, 9 Aug 2019 01:38:07 +0800 Message-Id: <20190808173803.1146-4-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_103947_084667_12D710D2 X-CRM114-Status: GOOD ( 13.78 ) 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 Adding "rng-seed" to dtb. It's fine to add this property if original fdt doesn't contain it. Since original seed will be wiped after read, so use a default size 128 bytes here. Signed-off-by: Hsin-Yi Wang Reviewed-by: Stephen Boyd --- arch/arm64/kernel/machine_kexec_file.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index ba78ee7ca990..7b08bf9499b6 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -27,6 +27,8 @@ #define FDT_PROP_INITRD_END "linux,initrd-end" #define FDT_PROP_BOOTARGS "bootargs" #define FDT_PROP_KASLR_SEED "kaslr-seed" +#define FDT_PROP_RNG_SEED "rng-seed" +#define RNG_SEED_SIZE 128 const struct kexec_file_ops * const kexec_file_loaders[] = { &kexec_image_ops, @@ -102,6 +104,19 @@ static int setup_dtb(struct kimage *image, FDT_PROP_KASLR_SEED); } + /* add rng-seed */ + if (rng_is_initialized()) { + u8 rng_seed[RNG_SEED_SIZE]; + get_random_bytes(rng_seed, RNG_SEED_SIZE); + ret = fdt_setprop(dtb, off, FDT_PROP_RNG_SEED, rng_seed, + RNG_SEED_SIZE); + if (ret) + goto out; + } else { + pr_notice("RNG is not initialised: omitting \"%s\" property\n", + FDT_PROP_RNG_SEED); + } + out: if (ret) return (ret == -FDT_ERR_NOSPACE) ? -ENOMEM : -EINVAL; @@ -110,7 +125,8 @@ static int setup_dtb(struct kimage *image, } /* - * More space needed so that we can add initrd, bootargs and kaslr-seed. + * More space needed so that we can add initrd, bootargs, kaslr-seed, and + * rng-seed. */ #define DTB_EXTRA_SPACE 0x1000