From patchwork Wed Jul 3 04:01:35 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: 11028919 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 4107F112C for ; Wed, 3 Jul 2019 04:02:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32CAF288D7 for ; Wed, 3 Jul 2019 04:02:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2716C28969; Wed, 3 Jul 2019 04:02:28 +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 AE3EC288D7 for ; Wed, 3 Jul 2019 04:02:27 +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=y7z3ekZS3g53lLOxCWIN05vN6H3j4koZ2ikFhHFJSC8=; b=I6PTBNuuEKnrCR XcLE1LAf+cRsDmt8IE6e0RTAnXX0WrvB/q/y4B49ARoMLpgG1GGL6W1baSSeeevBncHBiELmWTibl +50ADN3xMKBdKmLpizUP2UKKamGHodgjayKv8CKN98Y4jZmplrXGfbRB2he4Jc2U32MQmi09KQvS+ YR5arXXbXY3kBqNmTzGfkNfmr4qZ242sdnzWajvLz24vfBbMU/2D1pwAwpY37HWdLD9qltoxubwRn /Lvm9hQccapIDNYnXprkfTwCI0CAda8WHX0et3xgAS3COw/fmtFBuhaVnkKX4B5Ofewrv6zsA5ID8 Q6D+1SglPFgaJKMhkE+g==; 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 1hiWTN-0004mT-PW; Wed, 03 Jul 2019 04:02:22 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hiWTJ-0004jG-4N for linux-arm-kernel@lists.infradead.org; Wed, 03 Jul 2019 04:02:18 +0000 Received: by mail-pg1-x542.google.com with SMTP id i8so455479pgm.13 for ; Tue, 02 Jul 2019 21:02:16 -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=sE5oRPdvnR06Bfd/FTtYnLnxxFkCbEalP2abcHjeDU8=; b=i45m30PxRjJ+QfF7YsmsB920O0lzOqwcHSJWAm5pkRwMHE3Fa8Odbyv1u8nuW9F9S2 WJYWeTjXNsgwH5BrYwQ+lkpbsvPt6CMZrNT2EpfX5U8p4XivjywW3uq2mtOxYmTf1CBk gdV1w3pHjv12duPJZ6QlZuhjJXWO7g8hHYNhc= 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=sE5oRPdvnR06Bfd/FTtYnLnxxFkCbEalP2abcHjeDU8=; b=DVn4yDGfXK9P1uY39J4AATFhmSpuklG9T1Vux4DeYKDa3cf0Wmhomt5gcnLOrrVK+/ M693+i+0mMgLepUKJrUzJNzbc/Rdh8ssTRngK7OEIzMawT4QhtfQBJAMhcSdTWA1Ldl1 NVIEQw3WI1/kMV+Tok+jsYDc03o64lNJzGpUbP5jOMES8g/tPj0fuN7+C6WxALxVht8G kElT7byLJL8nqUO11orzUZzYt4OawoAKpxkQpcLedMrsNTmnaf98h2Lcfx5Pl+v40wE6 XOlDIBsk2b3gPJ0F46jM7V01LvtJD9CsQDh6QyaAENPoH9YRDZmWtpHNY9nqs/HfZtT8 adyg== X-Gm-Message-State: APjAAAW2ZXTvrp9vlUU2p0Lxhay+4Ddst5zFI3jaW4S5yJit+1aEjfgS NCMnV0qz0vwP0ANeyyTyEzkH0MBf9ZBwNg== X-Google-Smtp-Source: APXvYqx6ubXzVMy5VTfYWATgskEcFGPoppK1XdpHgeR0gsLFY6p2zOnwLkChe48hUu1VnvaIDKlbHA== X-Received: by 2002:a63:2006:: with SMTP id g6mr14382753pgg.287.1562126536114; Tue, 02 Jul 2019 21:02:16 -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 w16sm608327pfj.85.2019.07.02.21.02.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Jul 2019 21:02:15 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v7 1/3] arm64: map FDT as RW for early_init_dt_scan() Date: Wed, 3 Jul 2019 12:01:35 +0800 Message-Id: <20190703040135.169843-2-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190703040135.169843-1-hsinyi@chromium.org> References: <20190703040135.169843-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190702_210217_193843_E154D9BF X-CRM114-Status: GOOD ( 16.48 ) 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 --- No change since v5. --- 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 7e541f947b4c..754763b3fe28 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 750a69dde39b..54e93583085c 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 Wed Jul 3 04:01:37 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: 11028921 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 DD2DF112C for ; Wed, 3 Jul 2019 04:02:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFC94288D7 for ; Wed, 3 Jul 2019 04:02:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C121628969; Wed, 3 Jul 2019 04:02:58 +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 6056E288D7 for ; Wed, 3 Jul 2019 04:02:58 +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=GcgdQjEaF0RC09LMxZdqrirOCSLzDYVLVV61h+W2v0I=; b=mmiFPgoCv53MVL RhFFFRp1wY1imJ5HaCKfK6Z/FwXGLmf9cTLfhD9a3NP/3Hu39eDxfJCE59w1EzbfVjgDSx8H5nj8k L/p/prgeeZ0znG+WEvmZ5L72qaXw4OWt0I0x90xU7DpEcVHI7acS8WDhBx7ShcLD2EsnyC66u74Zh CRaLk19wjJaV5yJ59kZWDgl+KMMVw8PZ4eqv4+er2zhL2S5YBRSsE3Bvj2pehsU4j7sqLgcFXyyT+ xRsxvR0009nIzngHWKKpgpJ4QVw2a0+AkRG9TH5o17k2gvCr1lh7WTENkNywLTGXQpAdjIWQUUSpU y+Mn/HfnhlG453/8n8ww==; 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 1hiWTx-00055r-UX; Wed, 03 Jul 2019 04:02:58 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hiWTt-000555-SG for linux-arm-kernel@lists.infradead.org; Wed, 03 Jul 2019 04:02:55 +0000 Received: by mail-pl1-x643.google.com with SMTP id k8so458581plt.3 for ; Tue, 02 Jul 2019 21:02:53 -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=D0DdOpMQGVeAdF8kK+Kt9fgmekxnUEujrSDi9AB3YmM=; b=Q3x9sXJvjIsCzqPkwq91GFznkehlCZyQIblUxwqegBXIDgIUasLe9okJjER1twbMfm nWjqNor3p1Clensei6236mF0jhvK+Sz6FDfN6WVrsJSiR0TJYu/hCDDyIKsI81w9QiZw hBV7oc1Qdq03EnAcOb1WkjushbCfRrm8Rx+WU= 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=D0DdOpMQGVeAdF8kK+Kt9fgmekxnUEujrSDi9AB3YmM=; b=mQHy9l3D4vBmX6j61ZvzPaTwwF1g40ZZilbEKuH/qv2RVwgkHSewOC98X+WXXB80fA ENafXhKX/G1lGCleV2Pcf6seN7OzSbv+eFp/3LpX9Q0GJ6HUicFX34Wu1IdF9nJQjVIv h0yCsW8btM/VUSjm1lflWhe5mGAO3jby5a4lAQtm3/Fr3w2PQkHgBZZqcrYTNN+4j3gr QwJNWm0NkoSEIR+gWchgwpQ8k2Fh+cV+JEYtVtgRZaiBbeQ93QQBd/PLM3yDNapApdKG qSkay8+bhngwDr16iDFiaG0TEjG3vdmrLXz1Jn/7Osj+9Wp+Nk1Mekm60LyONbVxejzo ks2Q== X-Gm-Message-State: APjAAAW5QdcKiG178ffwjtmGoqY4mt1Vu8v2oN7r5WPm6pVy0z7fk/ke BF3N6qWpe0bW2NbApOJcFcamlztDlYlNrg== X-Google-Smtp-Source: APXvYqznyDfHYKikQKIqHH4oCiI9Z/+57ZuJwCnQCjDdBHt1Eb4/rlbJGAPXvGWmfJKbFYSPdnrnww== X-Received: by 2002:a17:902:a414:: with SMTP id p20mr37549962plq.187.1562126572996; Tue, 02 Jul 2019 21:02:52 -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 w16sm608327pfj.85.2019.07.02.21.02.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Jul 2019 21:02:52 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v7 2/3] fdt: add support for rng-seed Date: Wed, 3 Jul 2019 12:01:37 +0800 Message-Id: <20190703040135.169843-3-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190703040135.169843-1-hsinyi@chromium.org> References: <20190703040135.169843-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190702_210253_916281_3DD5308F X-CRM114-Status: GOOD ( 14.83 ) 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 --- No change since v6. --- drivers/of/fdt.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index cd17dc62a719..7be50e287ba6 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 @@ -1043,6 +1044,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); @@ -1077,6 +1079,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 Wed Jul 3 04:01:39 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: 11028923 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 20FDD1398 for ; Wed, 3 Jul 2019 04:05:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F350C28862 for ; Wed, 3 Jul 2019 04:05:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD1C428969; Wed, 3 Jul 2019 04:05:15 +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 670F828862 for ; Wed, 3 Jul 2019 04:05: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=8Ubhg9O48BVYLwRsxN9y4MCYK2C7W/TPla0fLGlZ36c=; b=jX3rO8xTC5Ed7w ubRUYemYkZ93boOzd1SXk/GhuspHuh4IFXbn7EImneLXUWpaQ7NY4ipMXAq2bfOfT0IbC4goZjA1f IdXcfoTpenUtIB0YNN4otI8pbaDwrlH0RDAAOArK8X1ThJZLafnpII0Otq0xidzrSUJ5VnCqgGNUQ SVTerCgk7fGK7qZGzu7/t3cj/lU1NYsa62gCMhGQy/IGC4JrqxXO9eqZ+obTeE0bQHMfgPZxCbNSz lYpQvU9/vFMval/hODH8fw5LcOsOnXEhMUJFjr64sMSqJ8PG+0qIEjelJr0mq9XjYmlsp+PDxfg9h JyutKK/HNvZUMnxvaUmA==; 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 1hiWW7-0006bh-7J; Wed, 03 Jul 2019 04:05:11 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hiWW2-00062B-PX for linux-arm-kernel@lists.infradead.org; Wed, 03 Jul 2019 04:05:08 +0000 Received: by mail-pg1-x541.google.com with SMTP id z75so476984pgz.5 for ; Tue, 02 Jul 2019 21:05:06 -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=Bm9umS6vs/dbbokDnbGJE7RR1jt4/TW8qx98n8+rRXs=; b=lwp8ivzrlsxLLgRlaT62i3vqrLwkdKgS7nSCUiMXz6cLeSlSGmHtCrk1acO9r4NXgZ fzRiFfltg50O42MTfX838YI6NXHyPqDAMy6U88E2UtGVqiAjFKmYirTmp8pt6EJVZ3Kc zd5JmV2q9PZTe58ovR7q4HVMtLykh5iQ058j0= 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=Bm9umS6vs/dbbokDnbGJE7RR1jt4/TW8qx98n8+rRXs=; b=tkM1xqD6tkLZqyL8IYQogN5PpFmnI6gDRiYtGgLtIBalSHaEQIKj/sqTYrqw0tYHDU QpGq+d2YZsvioMUxvniCuvHMG3YeepQNEg2RtFjkEAOSc/jvGamWxSGkhl3XkJNfpQWO otbPL1o/h+7ZTaxJuFJQpqdEaDXpTD779qAB9LTGlaSFZCcuphMzkA2cYL1uEUhp/tyn TQDaO5YiOCygFhGeJZA2YPKEYyB9EzV5duHLO3wyk1vgi088WQZva16FeY+azESo5Kqm XNo3pXQyBSPESRyYVdPCjWEHu+X3rvj2TduExZ2SuuUmicppzSw9NWMhk9Kgc1o1DUV8 EMQw== X-Gm-Message-State: APjAAAXmDgEq6lVzKjf/it+v7tGVBTZnR4gFSPlelnmhhRROTPW8y+3d Vkwviuea7AMWu6aADkDonKcJ07Vlm0Phgg== X-Google-Smtp-Source: APXvYqxSlvON1XYRESOb0HHRr/tTmlELefeQMA9+YaZ4lD8Nb2hIdAPpf8KZVxNsWdVkLy7H8dN7ow== X-Received: by 2002:a65:42cd:: with SMTP id l13mr5469866pgp.72.1562126705767; Tue, 02 Jul 2019 21:05:05 -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 w16sm608327pfj.85.2019.07.02.21.05.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Jul 2019 21:05:05 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v7 3/3] arm64: kexec_file: add rng-seed support Date: Wed, 3 Jul 2019 12:01:39 +0800 Message-Id: <20190703040135.169843-4-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190703040135.169843-1-hsinyi@chromium.org> References: <20190703040135.169843-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190702_210506_855576_A20E44CB X-CRM114-Status: GOOD ( 13.94 ) 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 --- change log v6->v7: * Use stack for rng_seed to avoid allocation failing. --- 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 58871333737a..81b5baad97aa 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