From patchwork Sun May 19 16:04:44 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: 10949477 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 EE00A112C for ; Sun, 19 May 2019 16:05:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB8A626B39 for ; Sun, 19 May 2019 16:05:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE9BE27F17; Sun, 19 May 2019 16:05:17 +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 6476226B39 for ; Sun, 19 May 2019 16:05:17 +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=rqEULs6n/rZWABpokhcieQ+eCYYPan9124uH3bL9zfY=; b=M3uhtV8npkYTF6 PZRdacRrfPvrypQ3X7DE0pIA9r4TPYHHxiGhWD6KBajmNhz00FoTwAMWrPOJ3kFPSuq8oSHvPBN7Z 8CAr81elgClsdqfSzOqIirXI9CnAndKxUfM7GO6EmRHN9D/9mqqw03M98OQFcoW5zSQWxGgkcpjy0 YuDjoSkQlZ2qxQXNaRC+iCWGM0/OlBA5i4Q+MErVyUFgQdGcVO7Co9eT2E7/5wPXCzpxqPNbeWCwN FipmcTzeCVjyHqJx6oi4Q+WiL22mryo/BhG/u+KYpipZ8ylWLaAvjkouIKkVF91+jtoGZS3Ym+3yO wsWoOSw0rBgMU/pRcZCg==; 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 1hSOJB-00067v-TC; Sun, 19 May 2019 16:05:09 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hSOJ8-0005iM-PS for linux-arm-kernel@lists.infradead.org; Sun, 19 May 2019 16:05:08 +0000 Received: by mail-pf1-x441.google.com with SMTP id c6so5989575pfa.10 for ; Sun, 19 May 2019 09:05:05 -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=HjgKgNWvkrWu2AB4Hfm3UsbNqpkTfiMRDxIt6YpDrD8=; b=F1SPpDoL5/a/tOtnEuMPcZHUmxrlYpCW55VLRABVi8Ktcj+pFOspwPpb/QdIdtJBsz 41Nz2EnmkcnqlqMJ4FH9DYTW9qOWF3B9mwhUR4kc12EXddRoh1xcNY+hvWUgG0kVZaSO nmtAnQFNNwpNY2cb4wM/TTE7HA6icohq7g9rs= 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=HjgKgNWvkrWu2AB4Hfm3UsbNqpkTfiMRDxIt6YpDrD8=; b=BRzjxhii6fcDnAG4Dz19iX8bu0eIitobA+57Ev1Z4IRuKLv70YBnqdh+KeR3wJQ6M1 pLPrv37cKZHptMYDeMeGirLaA5AoeKiAVC/lj1zKbbHIgXyFkumNDBcLYTJ6jlk93oWg EzLiBo3mCM4VP93beglo39fFB3Wy/KozfxkHqRiHl4JRgAXPBPFkwxcfKgurV6ev84S1 Ipta8zNgInwac7at5TstCzYs2ysC+ReSuR4cJU2hHGOtN8CvDTDi0Lr8Gfyy8ptqXzlB K0qxiR1yaLRo8Rx6rJDLLJ5yBQcqdqn22bNSwbIGWRuIuKOyKFTWy4rD60ETljcbuAFa meTA== X-Gm-Message-State: APjAAAXHHoUv9lsZ6rPfzUqv34YIxg/s9fbNwBs5xQZ+ktui4reKZtYy wvY+ie+JCR/DgKz3hCN/m5+TZ+a110k61A== X-Google-Smtp-Source: APXvYqzq2wiw9TB3Jsn9Sm+quwS8aysurwuin7NtHbnbO84Ogl+zCj5bZND02CjmQyW98Mvom1I2XQ== X-Received: by 2002:a62:e10f:: with SMTP id q15mr74698143pfh.56.1558281904958; Sun, 19 May 2019 09:05:04 -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 b23sm17547007pfi.6.2019.05.19.09.05.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 19 May 2019 09:05:04 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 1/3] amr64: map FDT as RW for early_init_dt_scan() Date: Mon, 20 May 2019 00:04:44 +0800 Message-Id: <20190519160446.320-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-20190519_090506_858938_90F38735 X-CRM114-Status: GOOD ( 15.70 ) 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, 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 code that needs to modify FDT during init. Map FDT to RW until unflatten DT. Signed-off-by: Hsin-Yi Wang --- change log v2->v4: * v3 abandoned * add an arg pgprot_t to fixmap_remap_fdt() --- arch/arm64/include/asm/mmu.h | 2 +- arch/arm64/kernel/setup.c | 5 ++++- arch/arm64/mm/mmu.c | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/mmu.h b/arch/arm64/include/asm/mmu.h index 67ef25d037ea..4499cb00ece7 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, pgprot_t prot); extern void mark_linear_text_alias_ro(void); #define INIT_MM_CONTEXT(name) \ diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 413d566405d1..064df3de1d14 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -181,7 +181,7 @@ 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); + void *dt_virt = fixmap_remap_fdt(dt_phys, PAGE_KERNEL); const char *name; if (!dt_virt || !early_init_dt_scan(dt_virt)) { @@ -320,6 +320,9 @@ void __init setup_arch(char **cmdline_p) /* Parse the ACPI tables for possible boot-time configuration */ acpi_boot_table_init(); + /* remap fdt to RO */ + fixmap_remap_fdt(__fdt_pointer, PAGE_KERNEL_RO); + if (acpi_disabled) unflatten_device_tree(); diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index a170c6369a68..29648e86f7e5 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -940,12 +940,12 @@ 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 *__init fixmap_remap_fdt(phys_addr_t dt_phys, pgprot_t prot) { void *dt_virt; int size; - dt_virt = __fixmap_remap_fdt(dt_phys, &size, PAGE_KERNEL_RO); + dt_virt = __fixmap_remap_fdt(dt_phys, &size, prot); if (!dt_virt) return NULL; From patchwork Sun May 19 16:04:45 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: 10949479 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 1A47D112C for ; Sun, 19 May 2019 16:05:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 072D526B39 for ; Sun, 19 May 2019 16:05:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC0C22845E; Sun, 19 May 2019 16:05:22 +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 610D026B39 for ; Sun, 19 May 2019 16:05:22 +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=KN01NZoootDbSFOa9As8JBBPu8xrOAtTiE/gwpfat0E=; b=ZZ1QMty3+4KaWn dzUBvkhg2p/SHRCsjbZShOMFryrOuuhwkPJ4xByy/4qdpbxhuC2+Ki2ufipcwQ4B+7NjxK7/4K5B9 6MxbMJm7SKRvb6oeYthkYwnzR+P334iKwnautM+TvjF4dMrn9HTUNr6RQtAWuYANecPBBzV7rxCUf H3Y5gfzo0j5nBx9FoyTju6iqUObSNr65G6MtBsDu7cRRANRX0eq7eLlCTaCMPlvBPp3iQ+T2wNSqw iO40f2k399lQyzF+gSZJFhu1AhjDfXPS7Xi4qWRy2xxNcEkPMsn+1Wa75pogRrba21xkuQxwdk66Y OlTLBLUREcOBPNMdghrg==; 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 1hSOJJ-0006FM-Lj; Sun, 19 May 2019 16:05:17 +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 1hSOJE-00069A-0Y for linux-arm-kernel@lists.infradead.org; Sun, 19 May 2019 16:05:15 +0000 Received: by mail-pf1-x444.google.com with SMTP id t87so6014264pfa.2 for ; Sun, 19 May 2019 09:05: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=gCFKWEfomzC/p8Cp2zu9+tMCVjDMCf+wEVZ+N8bS+5w=; b=T/7IReFvKjKaF14U1oGtHscyU/22SyS4d7KmRC5r07CtvxiAbogbfeuIroE/8H2wz0 nLTWIIZriLKgXnWDXlyBKjqUAsl9SsAMjTTs4IMZaZBFvDrupg39ZL7WTW3wXN2yB8aj f8BzAcUBvMPTNeGH08JCB9Xs2xfvt2oFwNK1Q= 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=gCFKWEfomzC/p8Cp2zu9+tMCVjDMCf+wEVZ+N8bS+5w=; b=SPjzfkYbPYVHSaXhr2CCIS3OmHVrJsuFH1iR6vblM/Zp/NMuDTHDqqtTH4rcx779/Q nA2spXTmYqLHU+SXe9IAgPE6gUDzQ2nV2dEXyZdvnoWQzmUlDHCMfXCMOnhbG3+oali/ KVfbC1csCgz/yzI9OMdSmB2CuE3nk5hMH628NelzHANXeLeyygQNhtA7c38nAf6cyFsD dNE6vj3J1F3BdXs94ZMWUw3M6s+UmBqsfydMt3ef7N4vrQchxJ6H5UuBZgqr/6aCgiUR mpi0F2ZRt7AY0KHJRtCNmz7TbBP4i/Xayz8edPQuQrtQbGeCHC43cp8brqwqyT99t9D+ QYIg== X-Gm-Message-State: APjAAAUh4XRd06I7UlO59zseuI0U0V9g3c2gdIFUAaIE8jiJ/G1sDTgk FgzVB5PAxmvTqk7lfsoexeq+KKrk78W6ng== X-Google-Smtp-Source: APXvYqy+Gmvo5+tw39P1k0XyadavsTQNx3uwPq73xdTjt//OfTcVKyZMNiRhgh9F9ySQ8HBIePPR/g== X-Received: by 2002:a63:a08:: with SMTP id 8mr69721219pgk.46.1558281910923; Sun, 19 May 2019 09:05:10 -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 b23sm17547007pfi.6.2019.05.19.09.05.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 19 May 2019 09:05:10 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 2/3] fdt: add support for rng-seed Date: Mon, 20 May 2019 00:04:45 +0800 Message-Id: <20190519160446.320-2-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190519160446.320-1-hsinyi@chromium.org> References: <20190519160446.320-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190519_090512_231439_CB208B31 X-CRM114-Status: GOOD ( 15.22 ) 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, 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 --- change log v2->v4: * v3 abandoned * fix doc error --- 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..7f3d72921b23 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_delprop(initial_boot_params, node, "rng-seed"); + } + /* break now */ return 1; } From patchwork Sun May 19 16:04:46 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: 10949481 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 CD3D36C5 for ; Sun, 19 May 2019 16:05:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B674928468 for ; Sun, 19 May 2019 16:05:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5CB428500; Sun, 19 May 2019 16:05:38 +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 4D89928468 for ; Sun, 19 May 2019 16:05:38 +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=jG7X12ZktBArWX/rvbZy2go3GWWO8N/5E96JhQN4ba0=; b=JrJWNEX7dVNxAk 76Vq6xa43f/QSewqEamZlwTl1ODeO35kgFd4prcbPFiS76aaD6T14yF3a3ZU2w0wv3sIXf754zgNA hONW8SKfo+qoB1e8qhnKMZTGfagh2IiNWT8K3uuwa3dbrmsa65e9TUczp9nsrQuAfcyqHsmxx3SEj 1mUPGl/iAuEaqjrxDPrm0Avtot9GBlp5qclFWVPbmlmlRAXAMqcTChqoB/9Vj+MrfDmP5WJsx+Lr7 1a+8/NZ5P0mkalGWy9qGLGV8nJsDLbeC78O/p9xcHD1J4XPYlhFO604+OFen5ZacaKcTVrICicGgN lB5ByN1oKmIj6ZM3T1iw==; 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 1hSOJY-0006Yt-RP; Sun, 19 May 2019 16:05:32 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hSOJJ-0006Es-1V for linux-arm-kernel@lists.infradead.org; Sun, 19 May 2019 16:05:18 +0000 Received: by mail-pg1-x543.google.com with SMTP id z3so5573110pgp.8 for ; Sun, 19 May 2019 09:05: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=w75P38v9z8QHVdxS6R3Brz2jpMYqR+5eP/w8pQb1nPA=; b=myLhk+2HXFCrC8o/7PfbYOhTcA2jCqzU4GnMO+/qE7+tzW5/ihlU7K3wVqAd3P3qFp xICCMbgzhgD631AA2NeQrSpXLwscwnDUO0aBm5iHLE0zRWfGzEbHCzknrCjQkhuHMmxX hGH4+kQwZHWBpzmD1p050soj0o6GVYepZs0Mw= 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=w75P38v9z8QHVdxS6R3Brz2jpMYqR+5eP/w8pQb1nPA=; b=G2PUz8DY+nR/c/bMwCkvn4ii/qpV0z7aH1hJ2s4ty81SzPMxG6In3kBcW6x6Qh/yNp m5e1zFoM5tLqnZPIk6b7/fvE4TuHQufOYgynpjSyzjvWOruTUNzgqsPQP5w2TWRopbjk p0vRoMa+KtX3Gv+awiXRZofcPgFcQrHidZ4YPkaX7+mfuhxdZogWsOQ3PJ+7fqt4aVAK vMtc0AuQIzZb/VMkRqBRDqF43DyTuQveMVxIn5wkj9XxYjXFIb9P84nI7GIk63BllZrh wxUKuAjJU2Z5/0rQHFavTgOhgE3EUFhmFTnMlFGzzau6Z01We7TECwYAo4w1oTIQZ7Yl IIYQ== X-Gm-Message-State: APjAAAX4mcH4jAB0V0hEBVyik1jMmvqmN3oVJmiCgx2XL9yJeRoSSgJc //TUOSXI8YulxqUEY17a1tS+lA69VAHCNQ== X-Google-Smtp-Source: APXvYqwrm3lDeGRnJx7g5EY5lJ5ZBzglEq7ClMbsGc6X8fVoF80Kv6SGb8mBvxA9elUTdo5UIIKIrw== X-Received: by 2002:a63:6884:: with SMTP id d126mr70417545pgc.154.1558281916225; Sun, 19 May 2019 09:05: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 b23sm17547007pfi.6.2019.05.19.09.05.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 19 May 2019 09:05:15 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 3/3] arm64: kexec_file: add rng-seed support Date: Mon, 20 May 2019 00:04:46 +0800 Message-Id: <20190519160446.320-3-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190519160446.320-1-hsinyi@chromium.org> References: <20190519160446.320-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190519_090517_169365_6043C059 X-CRM114-Status: GOOD ( 14.34 ) 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, 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 deleted after read, so use a default size 128 bytes here. Signed-off-by: Hsin-Yi Wang --- * Will add corresponding part to userspace kexec-tools if this is accepted. --- 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