From patchwork Mon May 13 00:38:18 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: 10940171 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 83BBA933 for ; Mon, 13 May 2019 00:39:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70A9D26419 for ; Mon, 13 May 2019 00:39:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6030726E38; Mon, 13 May 2019 00: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 F05C026419 for ; Mon, 13 May 2019 00: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: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=aKKcHwn3Kw/Ed3AXcuvSDnnhsU2D4/+PFXA2U8v7K2M=; b=pVxdMkrJx6K/2J 1wZOumZw4AFWKZa+BYmKvbRuaP9RYT0a5zOXw/vAOMSs576R5M7L/KZnr+N6IIL/0Cw2MFGMmoDaS YDN0VTTPJUeocEVSVtIgVg6VsAdlDiqRrqzvHB3jQ8KA5XeVdtWS0QQYSzbN9uZlmKbzw0dP2Tt9J 5XLb9Xtee5Y0J+f6GXg44O94hHbg9XOdkPtCx36sEJ2A5oSdGQw73e2JW4M5DtxUo0Q+1rpP9lMAV irxIHY93qKhemqEmgnOm0qF2OJRKJVgWLhl5owKP93aMn61xnxhiicW5PT2H/Wi81PCfonKkujkEd 9eUHyTq6tDs4XqVRJRig==; 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 1hPyzn-0007Z0-HP; Mon, 13 May 2019 00:39:11 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hPyzj-0007Yd-LV for linux-arm-kernel@lists.infradead.org; Mon, 13 May 2019 00:39:09 +0000 Received: by mail-pf1-x442.google.com with SMTP id y2so757275pfg.5 for ; Sun, 12 May 2019 17:39:07 -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=IgOJ9QLzOUW01yLV2OfG7YkSkZvw2ViCiy6aBBS6YFQ=; b=PAJDB8sdHVi0D44H/07DcJs+vX7Cb6MzLOV7JTtIBdbHIYzaIGW6owURsu25tGJfP9 Y8tm7gC8gBtob9CnxVZrElnfLEKoMkVic3khHAFKYDIS4xHKxMSValMptyH9vg4JGMsA cd04NRnP/ULXmIzpZPHml84TD4lCSO7ftc7/U= 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=IgOJ9QLzOUW01yLV2OfG7YkSkZvw2ViCiy6aBBS6YFQ=; b=W7z0j+158kRKxjTuSTCVsWTjpiYaX8vQjjZm7Q8XUq2ynF2J75Jvd/MpphSnBRWxaQ uQ7rVM6K3Ia4hUmMVsbzaajSfOGERKT/1x52caTzVHX+3M7T7Kqm5xbCvS80jevtgEq2 naWqdbdXq+66YFhmxu4WVjSMCvKUMEk9lhdPFx302HQXEvKCDNXIxLbGYOWA7uwkk/m/ hO50wUTIVIu8AYAorskoW7JBszyqrw3b0lS0Vy5Pm23qxdEfMylz/bTi9r0lJShI0WNA QfxJsZiq4aA7f8Fb/ynEYhrTX01Pl2zxREpyqgE0OX0s/60HvoBnpDiaw/eShBQgO/Qi HyvA== X-Gm-Message-State: APjAAAXqBgt/O2CIhg9cWlE/ANcynnk3z8KYauV7AQSYW0m/i/kbKmP/ YTI5Af2D+5jheaCsB1bSiUURghWOG5w= X-Google-Smtp-Source: APXvYqx8VoaPUnB/vcidvsLO44Gv71Rvn/n97EeuUINg+y35uX61qP9+WW9jO9KRmilThstyUVqPNw== X-Received: by 2002:a62:36c1:: with SMTP id d184mr7952363pfa.49.1557707946437; Sun, 12 May 2019 17:39:06 -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 a9sm14619577pgw.72.2019.05.12.17.39.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 May 2019 17:39:05 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 1/2] fdt: add support for rng-seed Date: Mon, 13 May 2019 08:38:18 +0800 Message-Id: <20190513003819.356-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-20190512_173907_740254_28EBF9D2 X-CRM114-Status: GOOD ( 14.71 ) 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, boot-architecture@lists.linaro.org, Michal Hocko , Kees Cook , Ard Biesheuvel , Catalin Marinas , Rasmus Villemoes , linux-kernel@vger.kernel.org, Will Deacon , Stephen Boyd , Miles Chen , Rob Herring , James Morse , Hsin-Yi Wang , Andrew Murray , Andrew Morton , Mike Rapoport , Frank Rowand 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: v1->v2: * call function in early_init_dt_scan_chosen * will add doc to devicetree-org/dt-schema on github if this is accepted --- Documentation/devicetree/bindings/chosen.txt | 14 ++++++++++++++ drivers/of/fdt.c | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/Documentation/devicetree/bindings/chosen.txt b/Documentation/devicetree/bindings/chosen.txt index 45e79172a646..fef5c82672dc 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 served 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..96ea5eba9dd5 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,15 @@ 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) + return 1; + + /* try to clear seed so it won't be found. */ + fdt_nop_property(initial_boot_params, node, "rng-seed"); + + add_device_randomness(rng_seed, l); + /* break now */ return 1; } From patchwork Mon May 13 00:38:19 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: 10940173 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 2459513AD for ; Mon, 13 May 2019 00:39:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1600B26419 for ; Mon, 13 May 2019 00:39:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0996C26E38; Mon, 13 May 2019 00:39:23 +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 93F0F26419 for ; Mon, 13 May 2019 00:39: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=W1W2Lfbr+rit67uZEu4KtldofwgYisAsCHlQGH+XUIE=; b=u2Nv4NpBHyUjDJ H0otfc2dP3J9kmq1gVeJyBFq3Rcnm9EGeqR3HJYJNQVWPKwXrinzM6FCoDn4b4opKxrCfNf5Pe0Cm AbT9/l+yxiPLV7NrkurdQeIvSB8n5AcgFIHviC4ZqTTFGXW4hxPDZVeim0rO09cLcdusKjj8GuxSo rgOp7Eerg2//T4hwezQ1jY0E88xRBJX4tL5xvc+Bz3E+CETNQT7CAvvWa12EBAfisYa/WPqeVisso cDK2yJFFIt2tQr47aWZhhFGFh0LhjxPzPmWRWreeRHUtV+HJMf81Do5iGF0J0zs8KYjCO2mJxHVd+ HT/THPwVEWFymloiVUJw==; 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 1hPyzx-0007lt-Df; Mon, 13 May 2019 00:39:21 +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 1hPyzt-0007hE-Qw for linux-arm-kernel@lists.infradead.org; Mon, 13 May 2019 00:39:19 +0000 Received: by mail-pf1-x444.google.com with SMTP id y11so6195929pfm.13 for ; Sun, 12 May 2019 17:39:17 -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=jbMbvlKHRDKPF33fkDdqZosCX8TlLi6L2lIp8AEgfEI=; b=ahcAC2+7tRqSmf9Sq99vuJtmBgerjrkeU5hvbO9VJcojV+ouWXEK2WeqLWILjwlbdt Wi53Y/OQI6YLkTJgy3lPLJJPk5CF8eddpc9pRhuK7JQ+wEabCM8KLJhCp5aFSUa4RvWI Qlz1Lwoz3OiB7nRfGUHgjdqktnzFo+efzXEbk= 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=jbMbvlKHRDKPF33fkDdqZosCX8TlLi6L2lIp8AEgfEI=; b=HDZWJhj0/ythqbyTZ7GZp1l5Lf9INR4VL47w28Lvh6ebQT4pwgDq1ZtnX2x4fdcFuv 5SPLzCaWH2ALbMFld4SI8qfYnhPpZT3DO8WHnC/6CK1/Wf8TBFSvyzv+u+7qS0mkoC5p V6vwE3h+0O8kAr9Zkpm9GrfX+8aFuKhMchdI5Xcdz6J4FmSdAtwj4He1d8aAL/7KXz/e I7gTROGsTtEMQNHWDnJJbRy9/4lPRqsIBSC1+BBIbChOb5jMSBRAmR8YIY5VobQ6+bJL /4+VSxq9CUVur3OGnorPe3Icf58RpANW2eV3xmf/fptL62ZXN2wstB5l0IMDgWqWT8u6 lxFw== X-Gm-Message-State: APjAAAXohlDrXrAby5sruuK+bNLR0jF+ZoU2JIEDc/jcptRAYpY2zdez tLfk5+A7Rw+oHagGs9TCNyJFhe3D1Ws= X-Google-Smtp-Source: APXvYqwvJ+s42h/ZoVPUfChayYtwKVcwlby7x/lX5fwmShnyI1xrkZYSHRWHIJyOpTadffshc3b6qg== X-Received: by 2002:a63:3dcf:: with SMTP id k198mr28317089pga.60.1557707956264; Sun, 12 May 2019 17:39: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 a9sm14619577pgw.72.2019.05.12.17.39.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 May 2019 17:39:15 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 2/2] amr64: map FDT as RW for early_init_dt_scan() Date: Mon, 13 May 2019 08:38:19 +0800 Message-Id: <20190513003819.356-2-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190513003819.356-1-hsinyi@chromium.org> References: <20190513003819.356-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190512_173917_902258_D3A4D344 X-CRM114-Status: GOOD ( 15.63 ) 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, boot-architecture@lists.linaro.org, Michal Hocko , Kees Cook , Ard Biesheuvel , Catalin Marinas , Rasmus Villemoes , linux-kernel@vger.kernel.org, Will Deacon , Stephen Boyd , Miles Chen , Rob Herring , James Morse , Hsin-Yi Wang , Andrew Murray , Andrew Morton , Mike Rapoport , Frank Rowand 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 --- arch/arm64/kernel/setup.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 413d566405d1..08b22c1e72a9 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -179,9 +179,13 @@ static void __init smp_build_mpidr_hash(void) pr_warn("Large number of MPIDR hash buckets detected\n"); } +extern void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size, + pgprot_t prot); + 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 || !early_init_dt_scan(dt_virt)) { @@ -320,6 +324,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); + if (acpi_disabled) unflatten_device_tree();