Patchwork powerpc: Feed entire flattened device tree into the random pool

login
register
mail settings
Submitter Anton Blanchard
Date July 25, 2013, 2:51 a.m.
Message ID <20130725125122.78accf44@kryten>
Download mbox | patch
Permalink /patch/261579/
State Superseded
Headers show

Comments

Anton Blanchard - July 25, 2013, 2:51 a.m.
We feed the entire DMI table into the random pool to provide
better random data during early boot, so do the same with the
flattened device tree.

Signed-off-by: Anton Blanchard <anton@samba.org>
---

It might be worth doing this somewhere common, but the only place
I could find (unflatten_device_tree) is almost certainly too
early in the boot process.
Michael Ellerman - July 25, 2013, 3:17 a.m.
On Thu, Jul 25, 2013 at 12:51:22PM +1000, Anton Blanchard wrote:
> 
> We feed the entire DMI table into the random pool to provide
> better random data during early boot, so do the same with the
> flattened device tree.
> 
> Signed-off-by: Anton Blanchard <anton@samba.org>
> ---
> 
> It might be worth doing this somewhere common, but the only place
> I could find (unflatten_device_tree) is almost certainly too
> early in the boot process.

Nice.

But why not put the initcall in drivers/of/fdt.c, that way it's not
early but it's still common ?

cheers

Patch

diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c
index 63d051f..6914851 100644
--- a/arch/powerpc/kernel/setup-common.c
+++ b/arch/powerpc/kernel/setup-common.c
@@ -35,6 +35,7 @@ 
 #include <linux/percpu.h>
 #include <linux/memblock.h>
 #include <linux/of_platform.h>
+#include <linux/random.h>
 #include <asm/io.h>
 #include <asm/paca.h>
 #include <asm/prom.h>
@@ -752,3 +753,13 @@  void arch_setup_pdev_archdata(struct platform_device *pdev)
 	pdev->dev.dma_mask = &pdev->archdata.dma_mask;
  	set_dma_ops(&pdev->dev, &dma_direct_ops);
 }
+
+/* Feed entire flattened device tree into the random pool */
+static int __init add_fdt_randomness(void)
+{
+	add_device_randomness(initial_boot_params,
+			      initial_boot_params->totalsize);
+
+	return 0;
+}
+core_initcall(add_fdt_randomness);