From patchwork Mon May 27 04:33:34 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: 10962063 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 78C2E91E for ; Mon, 27 May 2019 04:34:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CD0728A41 for ; Mon, 27 May 2019 04:34:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C2F728A46; Mon, 27 May 2019 04:34:14 +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 C805028A41 for ; Mon, 27 May 2019 04:34:13 +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: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:In-Reply-To:References: List-Owner; bh=td53GrcULOVCI+HdOD6kQ5+kd70uUWrwcxjE61iAL3w=; b=RCBcDFLwOmGzU+ dGP+TCEttuJ4cwe9PYQXV9oOKLwQaEOEhKdR+SVFraSTqMxopkGRyDJtgl42Fr0n3IChZP+AYUD2I iwxFHVIZ/RGMFF/fxSLLaeaNJ1HUAVhJ/hn2YLA9ps7euFxMewORkdGnjhTrMZUcWPB+V/FMIBVR0 QhPj7BdBlkD1mFza4xo+Mr4V5B2TL428TrUuwCFmiaxnlBQNbc4FluI+oEN++l/9E/TOFOkwJd9r7 v0v9GKkEjFIY2YTzfQOrVtun+vXQA4QrJoef+bD900CVYVd5lodiaCoNcRLnT4eevyUAmW99GAotZ kwan1pKT8PewJUFoeBag==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hV7Kq-0000pF-VE; Mon, 27 May 2019 04:34:08 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hV7Kn-0000eL-R9 for linux-arm-kernel@lists.infradead.org; Mon, 27 May 2019 04:34:07 +0000 Received: by mail-pg1-x542.google.com with SMTP id v9so1957845pgr.13 for ; Sun, 26 May 2019 21:34:03 -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:mime-version :content-transfer-encoding; bh=HgOEOSf35gkBk8EP9rLhqUCfFEYRMzxK+VuxcWeDrSY=; b=dFM4dLDtn5ocdeppZAxVs/zkJh3N7HOVKku+ErKsgU5Nlp75hkx0lHaGFT3nIoMjBP bL0rHaJsk9pEt8rSL9E+ZE13cAVdMtJxdYKUxv2XQbA5VTIK35Em4xtA5c/dOd0irhQK PmW/VHeeukn3WW75C0KOPY/IOa3clLTLppW2A= 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:mime-version :content-transfer-encoding; bh=HgOEOSf35gkBk8EP9rLhqUCfFEYRMzxK+VuxcWeDrSY=; b=JTWryEgVnYNvs+FTGWmduUrs9q2GTduyw2foi4N2xpUmFUeTTQZ8IDeTM/4t2IrXIO APT4BRWB32/Ln1OnoLErC/M8k9gxTKXbAeDhJR8ug1RZ4LTsspZcK/kuwXWlRbAaBaEN 41/D+vgRJ0jXEj85mmtVpnq1fBGpElMYCk/yIIE+a2WT6XnpptPtuqD7v7EzS7H9n8nU C8I6gAjX7dQfinU3gmrQqTCOyWIcIqpnImssmOtvPMhbjm8KrEWwdP1Hd1zOrt/ieoXS RiikcaWaZrO0qjqowNlw3XVIHiyWLivraN2x+8UI19j8hBRhjE8+hkci81DR9POoKjBV fn0Q== X-Gm-Message-State: APjAAAWkEotByO/+s8hMoxlUhs0tckGT1IibfnVGdz4bR9u3banjvAkB HfHwnFl7YiG3xtBAyknqHDRYTWadGpTWYA== X-Google-Smtp-Source: APXvYqyOXt01Sx0OLykiEM+3ADVsJKHA+92ieraXNCiw5h2HTCPkJ20jn+kAbauIhVNs2AjJ5gqrSA== X-Received: by 2002:a63:ce57:: with SMTP id r23mr2854429pgi.367.1558931642361; Sun, 26 May 2019 21:34:02 -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 g9sm8236061pgs.78.2019.05.26.21.33.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 26 May 2019 21:34:01 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 1/3] arm64: map FDT as RW for early_init_dt_scan() Date: Mon, 27 May 2019 12:33:34 +0800 Message-Id: <20190527043336.112854-1-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190526_213405_904664_7484C220 X-CRM114-Status: GOOD ( 16.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Nicolas Boichat , 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 --- change log v4->v5: * move memblock_reserve() out from fixmap_remap_fdt() * fix subject and commit message --- 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 67ef25d037ea..27f6f17aae36 100644 --- a/arch/arm64/include/asm/mmu.h +++ b/arch/arm64/include/asm/mmu.h @@ -137,7 +137,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 06941c1fe418..92bb53460401 100644 --- a/arch/arm64/kernel/kaslr.c +++ b/arch/arm64/kernel/kaslr.c @@ -65,9 +65,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 @@ -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; diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 413d566405d1..6a7050319b5b 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -181,9 +181,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" @@ -195,6 +199,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 a1bfc4413982..be835c379b7e 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -887,7 +887,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; @@ -940,19 +940,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_pud_supported(void) { /* From patchwork Mon May 27 04:33: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: 10962065 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 C245091E for ; Mon, 27 May 2019 04:34:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFF7228A41 for ; Mon, 27 May 2019 04:34:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A226428A46; Mon, 27 May 2019 04:34:36 +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 38D4E28A41 for ; Mon, 27 May 2019 04:34:36 +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=nzjw0q79v9/8alwf5aPKEFqaIBdRwUlmBcYs58ZWSrs=; b=da7JOyRSmGgCM/ yVVgmY+mvuKMSIHYs+F0zInmWiPcQBqzDJtIn+8wLRUQm/WGQ8p5Cq2Ik9t4TKlIDE+d9YJs9PSEI ja0bw2FrquATtwMyOtQj/uLxr3eDkW6ul9T4ewpP0azv3EoP96M9bI21Ft4a/LOrdPBkQrJjc1Op1 jcp31YX+my2QgeHxQ504dUNunQdRnAoOGbHu+06UCvM6dp6Nt3Gds9u6UiwDPgCQ7g+5FGgIg/ZlS S3t6WZGR2KhT7vYHEHXoQ/1WD9TnFOtHSn4iUsQCn7VGAZodBhTZ4NDOq4giq67dHLIw05PxU40Fu z4yO+y4i6YBp2UbPCrCw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hV7LH-00015H-7O; Mon, 27 May 2019 04:34:35 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hV7LD-00013t-Iu for linux-arm-kernel@lists.infradead.org; Mon, 27 May 2019 04:34:32 +0000 Received: by mail-pf1-x444.google.com with SMTP id z26so8818951pfg.6 for ; Sun, 26 May 2019 21:34:30 -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=HVbr8yPZVgrbjdDwY4oDGzG2x6LajTHk+u9YRL60Obc=; b=eNJuvDVNY0xCYnOoRFQPfq1KCk5IYm3S+jBuGBUvHHg8kTyIIJl38TFvpNXP/SkaOB TTeuYIMA7uK8ZTOOGX/phsARK9XUCj1WTYlfDQleA4JDu96H9l407xOgGgtYPOtQne/p AHd+zhN4N1HMICiYBF54QEtO92ry5XbAKy7JE= 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=HVbr8yPZVgrbjdDwY4oDGzG2x6LajTHk+u9YRL60Obc=; b=bgflTcKiHkqVHPn5OoUS5tzP+PGe3uTY71bxnb47lw0QirlQTI2NyWiU7TpsX9xtDa ILVuGHl68St7WSVXDD3bzT7Q8k5YyLCT+rUAynp1Kbo7T5wfxmy5ZfwHs29ya2YzZl3r bSjT6YBnCt8GFE+kO/ntlStr/2SKgCvYKswo3fd++Rc4/iPbOouxapam5B9Zwk5J1ilf L28zOkExwUeFhD3D4rTT1BtdsQjDg8AC8tEoOiNk0ZV5JpamgJJ4h0HiV+sQJuAPWzue 67u9hp6MVaW8EhRfF9QOzJ60FdQo+9miU/1Z1h8mOcFhqCxQ59aGovZQCcyrnnCCDeYX MsMA== X-Gm-Message-State: APjAAAUV/g2ECjcqPTT93M5rD94qd2IKkTEGhlSXzAr56PyvDwWRfSdy j6jUjyoAa9zcVcjDwpxOM0q20XSEYQ6w2g== X-Google-Smtp-Source: APXvYqw1TUPqLXbXV7nXMmmJo/a19DnZPKiDk3xHcy+XoSwyNQrhr4A/Z7BVajQoeX3y3yvo0B52dQ== X-Received: by 2002:a63:4d0f:: with SMTP id a15mr22151895pgb.59.1558931669720; Sun, 26 May 2019 21:34:29 -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 g9sm8236061pgs.78.2019.05.26.21.34.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 26 May 2019 21:34:29 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 2/3] fdt: add support for rng-seed Date: Mon, 27 May 2019 12:33:35 +0800 Message-Id: <20190527043336.112854-2-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190527043336.112854-1-hsinyi@chromium.org> References: <20190527043336.112854-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190526_213431_617858_403FD2CF X-CRM114-Status: GOOD ( 15.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Nicolas Boichat , 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 --- change log v4->v5: * use fdt_nop_property() since property might not be wiped entirely if following entries are smaller than property length. --- Documentation/devicetree/bindings/chosen.txt | 14 ++++++++++++++ drivers/of/fdt.c | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/Documentation/devicetree/bindings/chosen.txt b/Documentation/devicetree/bindings/chosen.txt index 45e79172a646..678e81bc4383 100644 --- a/Documentation/devicetree/bindings/chosen.txt +++ b/Documentation/devicetree/bindings/chosen.txt @@ -28,6 +28,20 @@ mode) when EFI_RNG_PROTOCOL is supported, it will be overwritten by the Linux EFI stub (which will populate the property itself, using EFI_RNG_PROTOCOL). +rng-seed +----------- + +This property serves as an entropy to add device randomness. It is parsed +as a byte array, e.g. + +/ { + chosen { + rng-seed = <0x31 0x95 0x1b 0x3c 0xc9 0xfa 0xb3 ...>; + }; +}; + +This random value should be provided by bootloader. + stdout-path ----------- diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index de893c9616a1..9d63330582bb 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 @@ -1079,6 +1080,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); @@ -1113,6 +1115,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 Mon May 27 04:33:36 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: 10962067 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 B0AAC91E for ; Mon, 27 May 2019 04:34:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C07328A44 for ; Mon, 27 May 2019 04:34:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D33C28A41; Mon, 27 May 2019 04:34:51 +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 381D428A41 for ; Mon, 27 May 2019 04:34:51 +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=WpkjW+63Vfj1jkEx0mCU/JGYgAlyMfih9qiXiW59YEU=; b=rrHjaX5oo6LXT6 DjDMSRYTMe7ZIUHKFe23OTZ9d2w2WGCrYbs8xXgEBB8TTb6LA0WF2Vwf5jSUsYJHblO1uhmo/5GIV rcuzSbLYN7aykb0jn9Imr5nQTuq5WQRf0MM4KMb0K1P6sdQ0AJQUPp/rqQhQbXjvom4OA7tpwysN/ UfiKpHtmHyA3JN3HlBElguj4j3wBZzRn5JmHcA6sW2360XySP4vgBEe/KdR/k3YG2fa2NMi+w+vop BLoFhWBPWlsztE03mB5a4oIOydnu4PD5NLde1qgPoR+S54OHgv/sUVXaaIaxfKByzppe2xuQQTp05 vxGv8CdibhF2Wx7boxag==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hV7LS-0001Hh-6s; Mon, 27 May 2019 04:34:46 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hV7LO-0001EX-1k for linux-arm-kernel@lists.infradead.org; Mon, 27 May 2019 04:34:43 +0000 Received: by mail-pl1-x642.google.com with SMTP id d21so6536540plr.3 for ; Sun, 26 May 2019 21:34:41 -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=ck+F9ON2fnwh5hsuCM2qk61O5ay8betZRUcLdrsV0zI=; b=j+IVUH4GD9iVi5AQ0tl+V0V07fGHYVGHoxVefzWndaQjrffPAm/mM+Y1a4MoHG/U89 p4QW6JgFkcgCvXvu44W+yz5LXEyov6GrVrVr2UVCx0STuRuG3ubwLcBI05O8KwYQQfLS qLZSfJ4qa29snAGa1sfVHjphAC1pcvgYZ2mSU= 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=ck+F9ON2fnwh5hsuCM2qk61O5ay8betZRUcLdrsV0zI=; b=cV0M0VFDjVZv0dXLCHTr3lszeOSGNFqEJbj/eUOgNAiPjDQzg0JXlNt0uqYzXyP6Nc NlbcGYKUbpsaLfxc2hjvXnwtbs1RgOLYQdcSTbLmpXGq+BMDixECWDkd0E6Sc280fR0F GccB5jBWKrRm+WOJj+WF/VDbkEc4TbEpIMkqHSLZfv66jro8osw8+xA6ZxmqWNNHQHbc jjP5b9iA7gIdpZNsFbOwCeZWCrRkGa6NH4ZpaQTi3fH9HyeqyQ1rhNAqF2fWqOImvytI /FO7xnyfN0R0S7auEjJy4dFvYGT40fX3mX0w/Ps8aDnHoSZPaQ/tkJ2z69uhfxcUuCVQ 6S3g== X-Gm-Message-State: APjAAAWLvZ2HiyP/SP2gFY8PJrj++jsTCpJw+OCkZto9akeVHfg6pLIY 3lpIUSWAOiKIkNDki9MskLn6oDmC9Veabw== X-Google-Smtp-Source: APXvYqyFrdw0mUt2bWg6+Evu1JeLd/Bd0yblbKAiu9bKbdKsHxgMYuF4cWcEbZG6DgbrO2oVmrykTQ== X-Received: by 2002:a17:902:42d:: with SMTP id 42mr3916281ple.228.1558931681051; Sun, 26 May 2019 21:34:41 -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 g9sm8236061pgs.78.2019.05.26.21.34.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 26 May 2019 21:34:40 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 3/3] arm64: kexec_file: add rng-seed support Date: Mon, 27 May 2019 12:33:36 +0800 Message-Id: <20190527043336.112854-3-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190527043336.112854-1-hsinyi@chromium.org> References: <20190527043336.112854-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190526_213442_110597_CE8D534B X-CRM114-Status: GOOD ( 14.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Nicolas Boichat , 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 | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 58871333737a..d40fde72a023 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,23 @@ static int setup_dtb(struct kimage *image, FDT_PROP_KASLR_SEED); } + /* add rng-seed */ + if (rng_is_initialized()) { + void *rng_seed = kmalloc(RNG_SEED_SIZE, GFP_ATOMIC); + get_random_bytes(rng_seed, RNG_SEED_SIZE); + + ret = fdt_setprop(dtb, off, FDT_PROP_RNG_SEED, rng_seed, + RNG_SEED_SIZE); + kfree(rng_seed); + + 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 +129,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