From patchwork Wed Jun 12 04:32:58 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: 10988449 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 5A8DC14BB for ; Wed, 12 Jun 2019 04:34:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45E9D28960 for ; Wed, 12 Jun 2019 04:34:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36ED52896D; Wed, 12 Jun 2019 04:34:29 +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 AFCBE2896D for ; Wed, 12 Jun 2019 04:34:28 +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=MCBGxMgMeUC8ccJuDbtmfcsIpAv/WLqKIor0v0spL+M=; b=jun3OYZUp0foIC 9iXAMvUvYxqip9mqyuPHZ6w0p8I1qCXvoTRo+xZVnm2YIfI3OW/zpYXzJG42IJk6tz3R+30CHJQa7 TV2CIijAxT0v7uVfLa23f/J1LwCUVPTnNVSbcNkvBFLl475+Xp25uuhZ4/2iOUuKkbJKdw7Gb6J2I BgEdytyBs020JConmgLWWBe6to5gL57QbTSEhdiD6FmMRSIID1YX4Q/6VXNnK+1zvBuQ7sABupsCp NsTAYmCCRZ9Mj1vANuodB5OdJR85ijsmG51qiH44FJsgqNLPScVj78+4wTjThkYb+euiqnmrVFbIO C+fo0EXcQHcozw4Uh6pg==; 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 1hauxs-00062b-0Q; Wed, 12 Jun 2019 04:34:24 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hauxo-00061h-Qm for linux-arm-kernel@lists.infradead.org; Wed, 12 Jun 2019 04:34:22 +0000 Received: by mail-pf1-x443.google.com with SMTP id 81so8813530pfy.13 for ; Tue, 11 Jun 2019 21:34:20 -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=K2wHGVYcbFiD0X9fma0Vn1g7+nxPq+Se3+5tmQQilTs=; b=HAe1PJzo+lVdhSyBIPzAUastU5KB9ox79M9ffr+34IeL9EAqtTvtV6W7gW9i2NsF9l XrJrqHhGBZY3//Eppb3Pvc5XA5CHrOKhARfuTTyvFvmfMHcxr6+2IJ8HkJbXGqoW6c6F 8aXqrDj64yBsrjSyBXigqK/e4/PBYW/2aaWag= 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=K2wHGVYcbFiD0X9fma0Vn1g7+nxPq+Se3+5tmQQilTs=; b=A6nckQaP2gqxrkz86U1f121NRnbz1QQaeX/KUN7H2H93LccMiBWeX6siGT4VzhQdYq tXMKeVWB6Em/u+uECMfbGsmvdNT3DOaRSsRio3Vrq54/3ERDFL2+9d66eYdnC6FvjTDA kdb9DdcyhqzkcRXzvZShTy4Ff/qpK1agWLqTv7L/xqAzCx7AO1JCGHSTccEOAuU5NLep zb2uwGM0oojtUim3Nv5V+oIhPdDtMrT5A+xsIOKyGPNEJB9gDRsphQXJ+4lwJXwaQrkV tvVg1cbqkcdK9gGMqHHtS5Nxk89M7IPRyyBr2mUbUxreu87RQzA5EHZDheMQmd+4r9tU gPjA== X-Gm-Message-State: APjAAAWj0rXzxUgHkXBOxGNnXgIY+IQ1UJbjCFspAoER43hpe3nxiIXa K3yqAhVYRnOjZx1BtieF6L1AJqwyElo6sw== X-Google-Smtp-Source: APXvYqwLveZ3syPiWzvEI+Za884bwFM/FtKaUwPOKcGDpfJF7RJscdXgBDwLhNymxcKBScjVtrnBPA== X-Received: by 2002:a17:90a:21ac:: with SMTP id q41mr31197020pjc.31.1560314059666; Tue, 11 Jun 2019 21:34:19 -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 k8sm15285998pfi.168.2019.06.11.21.34.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Jun 2019 21:34:19 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v6 1/3] arm64: map FDT as RW for early_init_dt_scan() Date: Wed, 12 Jun 2019 12:32:58 +0800 Message-Id: <20190612043258.166048-2-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190612043258.166048-1-hsinyi@chromium.org> References: <20190612043258.166048-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190611_213420_880947_6E3681F3 X-CRM114-Status: GOOD ( 16.62 ) 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 --- change log v5->v6: * no change. --- 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 93ed0df4df79..5d01365a4333 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 Wed Jun 12 04:33:00 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: 10988451 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 C252D14BB for ; Wed, 12 Jun 2019 04:34:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE1BE2817F for ; Wed, 12 Jun 2019 04:34:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A133328952; Wed, 12 Jun 2019 04:34:53 +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 2D6FF2817F for ; Wed, 12 Jun 2019 04:34:53 +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=RPiWxgOqr4UB5/eeMRvv8CMX7elL0ixNjJW2u/Czqm8=; b=KCTfT2Gr9qU+U4 0//mES0c0HFVMLr4kyotL53mtcTHwHMz9tx2IJa97kiMp6AgQJLoThnP3VSYiSE49/7CUwKeU5a4w JZF2LMj9cNOqp/VrIPAeVy5t4dq7Hz/GPEouVi48KbZFBLLzwPbSoKUpq/JZ3pqYo/AgHtSt1R03F LfNmSbR5rf+XMNyjztllXjqgX/LBjc79mudRFDY1bmrjjNeVFAr9PAVjqQDdS47/50+JgdoFd2t0Q O4IMExn07JKIYzPA41z4KWGzxm/pK7fjtHjArefuXfeYVTp+hUoc4ysmsPlSWaOqQnGd46jP/x5uS u+5mdK33ysoEKs6d2ZOw==; 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 1hauyE-0006JS-3P; Wed, 12 Jun 2019 04:34:46 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hauyA-0006Hm-1r for linux-arm-kernel@lists.infradead.org; Wed, 12 Jun 2019 04:34:43 +0000 Received: by mail-pl1-x644.google.com with SMTP id s24so6058637plr.8 for ; Tue, 11 Jun 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=FXV5Ws8+r5RPo/nKXnoHiLtGYbtFqiKOKRPXyhCi7kk=; b=WF6XEcrjnYm/TJx+cI4M997rrpyH1cFTH/f3AQedIs7pSSTy79gf+vaznSHQIU0Ezg ayYK7Azudp1Y8gy7eeukeYwME2A85H/PSOe3OM5sjWoSvbRQ/iRC3xvytM4I2hRtcL0H 2zFtgHFPl3zJ4Q+z9IKlwaWjBy24AtA4JKSR4= 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=FXV5Ws8+r5RPo/nKXnoHiLtGYbtFqiKOKRPXyhCi7kk=; b=Gm3VG0PXMwBKqrfp2XuPyHNo4lwhe6THs94UCiDspAESo9QIIihOtz9P27QCcIKE5L qlOuq4rQr0va+mpUw6GWZpCk/LSJMnwwIPA41rMcNdTnFhfGEV8KCWipGAgyh6qWx14T 6kARN9o95pdgh3qgZ1QKcoUp5Cm32ZV5OsZsy3S5CSiUJ6iC3e30UGO3iVjuchXqlYvw sM4+j9QRQ4s0aJrto3/7WBC/j/+mAogRRUc3me4ZGnQ3u+LVEg1sXTnGedXWGxONzpWD xzejeuyF0O+TUNOPeE9nmLMjJ5N4HyTNBLVhX9ljB9Zyo3qPzdd1I2OBoCeH9wNOdAXq YuuQ== X-Gm-Message-State: APjAAAXd1X1HxjDNgKeve/bILVMhHU8Teo146zIl86z/Qj/+5fIeklNU r/wNW6xhtxnyyjWPRE8vfRRgImqxYfVsXw== X-Google-Smtp-Source: APXvYqz0+oRQaQKhKlFNFx2+LDkTLS6Wb5yc/KHLfWZ3BuaHUGMHH37CG2EOx1uhfwpyGdes4XBmEw== X-Received: by 2002:a17:902:b705:: with SMTP id d5mr44143880pls.274.1560314080888; Tue, 11 Jun 2019 21:34:40 -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 k8sm15285998pfi.168.2019.06.11.21.34.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Jun 2019 21:34:40 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v6 2/3] fdt: add support for rng-seed Date: Wed, 12 Jun 2019 12:33:00 +0800 Message-Id: <20190612043258.166048-3-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190612043258.166048-1-hsinyi@chromium.org> References: <20190612043258.166048-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190611_213442_173021_A8CB11A3 X-CRM114-Status: GOOD ( 14.73 ) 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 --- change log v5->v6: * remove Documentation change --- drivers/of/fdt.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 3d36b5afd9bd..369130dbd42c 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 @@ -1052,6 +1053,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); @@ -1086,6 +1088,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 Jun 12 04:33:02 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: 10988453 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 8B0CB13AF for ; Wed, 12 Jun 2019 04:35:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72C5626BE9 for ; Wed, 12 Jun 2019 04:35:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 637B827816; Wed, 12 Jun 2019 04:35:20 +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 05A9626BE9 for ; Wed, 12 Jun 2019 04:35:20 +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=H5M428Brw1CVBTqqvYFl2zblGSluzRGwNdWJxSizHAg=; b=BMyrws9Ij6X9FG Us+QansBj/8sf/Mg8QZCbzLdQLT9Ccb3v5S8bOt1zwTD8XKIRKv5jWUDEtNIRkjK3d8T5KVN8069I XzaFR/CXFHtLr0oTc7J+DDZ6gkxcyr0B2VUQwgUc71mHS2QO9dU5fbzQsUWkoO71xMt3ZQqPLfpgW 5i1ik4n3XRCQsihc+94SqO97z2N1GrW+6k3stq5fsRSgDDPUv22Fi+L7o1mCq0WWKLszBBs0l8sip IqoztHk6GU0uoAVcDY1IA7eWw2PPvEqVIDRH7KVcVMs5yuduD5Ejk/QHqb/wESkebQnBDjzM71w7K J35z26qvlk6ralfaK2bA==; 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 1hauyh-0007lJ-29; Wed, 12 Jun 2019 04:35:15 +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 1hauyd-0007bL-My for linux-arm-kernel@lists.infradead.org; Wed, 12 Jun 2019 04:35:13 +0000 Received: by mail-pg1-x542.google.com with SMTP id 20so8198601pgr.4 for ; Tue, 11 Jun 2019 21:35: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=rJn1YZ706aJfrT07Hn2oI2Mia8615vCPrYsCrOsg17g=; b=nqTKRZCKIs+8kG9Liz37bjElzQMgiWIkqbp++oZGf4NKeWcTbix2jRPp8mGO/hAgR6 4+HNZHFyqoG6vx+pkuGWDOYH/mueiggyXED2gqRaFTKHeVEUfGhAMGncR0Y61bP1+Jng XWbBDY7gsgQmfzGku7MtRuYYrk4EaxY1CoudU= 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=rJn1YZ706aJfrT07Hn2oI2Mia8615vCPrYsCrOsg17g=; b=VdB+jevFVb6GVcBQu69Za2o4enEjQPqITy5RRp5abkiezSL6vEqDuiS7VeFzaMyknr /q2J7Yat2wM6vOf9FT2JtOKeajj/1eD/2O6GuQgJYEHnEA7YDkI5BVp6bMLL5bje9MZ9 QAeQT4IyTQfXlzntquZz3wOUVrBUf/X7W7Qu0WvLeNbii7vGEl3LSylvZ+Rq14Nu4Fy6 p5zitI9Ok0txYgB1wSE8sAWQwGob9eTsJ9C95Z+xYIEEfmhCf1xXIr+t+qhobIH1hdmw eVvjU+UkUd2XMqxb4ZQSRpZCrY4vcynYNzSrgdMctBeFofbgzBhN7xKZve0wU6Txfi0h s6Sw== X-Gm-Message-State: APjAAAUKTwXvSnksJB31/e/Wjq62/P1P002x2JoUs1Uo1U/aufxKerVc tNHtjbter0BHXaKYUaCvdr62FH0bbSI+Eg== X-Google-Smtp-Source: APXvYqy6WDq4Lk5pwGNHojTbI4ATefffHsAeuBNNuE8NFwZSff+br4DhRCYcJDdPXvX4l1j7ZaLK6w== X-Received: by 2002:a65:63c6:: with SMTP id n6mr18294203pgv.370.1560314110645; Tue, 11 Jun 2019 21:35: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 k8sm15285998pfi.168.2019.06.11.21.35.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Jun 2019 21:35:10 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v6 3/3] arm64: kexec_file: add rng-seed support Date: Wed, 12 Jun 2019 12:33:02 +0800 Message-Id: <20190612043258.166048-4-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190612043258.166048-1-hsinyi@chromium.org> References: <20190612043258.166048-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190611_213511_757424_DB97FCC5 X-CRM114-Status: GOOD ( 14.15 ) 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 v5->v6: * no change --- 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