From patchwork Mon Aug 19 07:16:04 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: 11100371 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 F0C5318A6 for ; Mon, 19 Aug 2019 07:17:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6D54283AF for ; Mon, 19 Aug 2019 07:17:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAC5E2857B; Mon, 19 Aug 2019 07:17: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 6E163283AF for ; Mon, 19 Aug 2019 07:17:23 +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=ud8u+EXAYMzEGQGrZhUsuuNX4i6pFaAH8ga0YLl1guM=; b=s1DNqcEQf8CdtC hvMTpyYAZXkHn2hy4jUbMhyI4hKNtKgfWq0cN6X9h3ERSxxWZAycf4i1bJwTE1imIs64uQuuSkTfF MM3jGiFlwRG8dSRllJkjF/Fe8ma+D429VZpOqlVsGh3fYtNmpJH2INwAxw77IO6myuuXfbytSH8LS oygHjYbpzzBnkxmRcpl0fWS2txCYW/w5Vrd4ilv6Xr50X2xNoQvqFwYG63TDdV4ovFQfywws/EygP ej37jgG+93/hu1LoqpbpiHj6Gd47OTCHhxf4BA1mxLiKueVIh9X8u2bu6DK9XuX1JqhaOjQcNJU6Y pBnxAOW3Nn5RgDWeBJRw==; 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 1hzbus-0000YD-MH; Mon, 19 Aug 2019 07:17:22 +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 1hzbuR-0000DO-RK for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2019 07:16:58 +0000 Received: by mail-pf1-x443.google.com with SMTP id q139so627135pfc.13 for ; Mon, 19 Aug 2019 00:16:55 -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=whlU2jKeb6W06HKboMelpiZARB7kfwOYMGifREsRS7o=; b=n+kO1OzbnDNabC44hdvAoZ6wWxOeF6J3oy6z/+1xpoK1AKEx/oeTmIcJ/47kuW+vYo TH9NeH/qAQIOhctHs9uE5ifuIC/ZB6LazcH76PyV3RQrSHwAjyWpKxWm9FJZiOFyOKt4 SVRkQtzzAxxdceBXUOg4JWj07de3M8XCDbx7w= 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=whlU2jKeb6W06HKboMelpiZARB7kfwOYMGifREsRS7o=; b=rt0rBPCv3oXZxkXkX6ibIBIS4tf+JZCogvlHQeJUyxmSsSjdIYQMDI3IeEl2+tnJlF JyrrYvUdljE0dkBWBUYC+tbMwdGtcuqVOVXq3/tk+fcW6cJsRHyK7O8t80KV4ZLNnvvu LdV7Z39Pa9cK4V/STF7j4yRIAbw0S8ZZR6bHp7gykh6G6qWf6Nh+JjII2rWokz3iK+Am PdsyyWf+F8aE36/zYHR0ZhJsGDPW/Pnf7ooYzRmrF3fsFW2GXoNXUANC+a1PSdqUcX53 Amz4qWNhY5t7a5P4Uk2xSIEJJwIs1XjUntOdQFL1pH9VjxyEZfRVK2J/o7iyMYzkeNzu PYsw== X-Gm-Message-State: APjAAAXQehmuBcSxXGofABgoelUfIO9SwZYPMf74O/BKjZIVDt7yy/aK I+05CF+cjhxES3BAQexGsXT1D4l5eeU= X-Google-Smtp-Source: APXvYqwFY2xA6JURjP5ZOBOEfAL1xBbz+vV2fRyvwDoFXo8gURWLM936jFkZ0hWWWKqy5/YP/nJ5VA== X-Received: by 2002:a65:614a:: with SMTP id o10mr18316590pgv.407.1566199014955; Mon, 19 Aug 2019 00:16:54 -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 y9sm14691341pfn.152.2019.08.19.00.16.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Aug 2019 00:16:54 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 2/3] fdt: add support for rng-seed Date: Mon, 19 Aug 2019 15:16:04 +0800 Message-Id: <20190819071602.139014-3-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190819071602.139014-1-hsinyi@chromium.org> References: <20190819071602.139014-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190819_001656_751391_091FD600 X-CRM114-Status: GOOD ( 15.50 ) 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. Obtain of_fdt_crc32 for CRC check after early_init_dt_scan_nodes(), since early_init_dt_scan_chosen() would modify fdt to erase rng-seed. Signed-off-by: Hsin-Yi Wang Reviewed-by: Stephen Boyd Reviewed-by: Rob Herring --- Change from v7: obtain of_fdt_crc32 after early_init_dt_scan_nodes(). --- drivers/of/fdt.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 9cdf14b9aaab..97a75996993c 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 @@ -1044,6 +1045,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); @@ -1078,6 +1080,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; } @@ -1166,8 +1176,6 @@ bool __init early_init_dt_verify(void *params) /* Setup flat device-tree pointer */ initial_boot_params = params; - of_fdt_crc32 = crc32_be(~0, initial_boot_params, - fdt_totalsize(initial_boot_params)); return true; } @@ -1197,6 +1205,8 @@ bool __init early_init_dt_scan(void *params) return false; early_init_dt_scan_nodes(); + of_fdt_crc32 = crc32_be(~0, initial_boot_params, + fdt_totalsize(initial_boot_params)); return true; }