diff options
| author | Laura Abbott <lauraa@codeaurora.org> | 2014-08-13 15:24:38 -0700 |
|---|---|---|
| committer | Olav Haugan <ohaugan@codeaurora.org> | 2016-10-08 10:43:21 -0700 |
| commit | ed1a203f6f2c4a2fc4a2d9135cd9669aef23e428 (patch) | |
| tree | 147bb6af05f7539dd00c6299b04fe6d5da775d0b /drivers/soc/qcom | |
| parent | fb25c8b683babfc18e583f634fb95a5fac7e12ef (diff) | |
soc: qcom: Add better support for early random numbers
The existing support for generating random numbers relied on
a hacked up version of CONFIG_ARCH_RANDOM and was prone to
scheduling while atomic bugs due to needing to take a mutex.
We don't actually need the additional randomness all the time,
the pool just needs to be initialized with some amount of random
data to avoid getting the same result each time. Switch to
this method for initializing the random pool.
Change-Id: I804ec7556cbd18ff2d9869a03069fda1dd519a79
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
[ohaugan@codeaurora.org: Fixed trivial merge conflicts]
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
Diffstat (limited to 'drivers/soc/qcom')
| -rw-r--r-- | drivers/soc/qcom/Kconfig | 8 | ||||
| -rw-r--r-- | drivers/soc/qcom/Makefile | 1 | ||||
| -rw-r--r-- | drivers/soc/qcom/early_random.c | 53 |
3 files changed, 62 insertions, 0 deletions
diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index 2bc74941abc8..8c43effadc70 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -821,4 +821,12 @@ config QCOM_SMCINVOKE Enable SMCInvoke driver which supports capability based secure communication between QSEE and HLOS. +config QCOM_EARLY_RANDOM + bool "Initialize random pool very early" + help + The standard random pool may not initialize until late in the boot + process which means that any calls to get random numbers before then + may not be truly random. Select this option to make an early call + to get some random data to put in the pool. If unsure, say N. + source "drivers/soc/qcom/memshare/Kconfig" diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index 434a114c000f..0105e03b082d 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -99,3 +99,4 @@ obj-$(CONFIG_MSM_RPM_LOG) += rpm_log.o obj-$(CONFIG_QSEE_IPC_IRQ_BRIDGE) += qsee_ipc_irq_bridge.o obj-$(CONFIG_WCD_DSP_GLINK) += wcd-dsp-glink.o obj-$(CONFIG_QCOM_SMCINVOKE) += smcinvoke.o +obj-$(CONFIG_QCOM_EARLY_RANDOM) += early_random.o diff --git a/drivers/soc/qcom/early_random.c b/drivers/soc/qcom/early_random.c new file mode 100644 index 000000000000..de38fc04676c --- /dev/null +++ b/drivers/soc/qcom/early_random.c @@ -0,0 +1,53 @@ +/* Copyright (c) 2013-2014, 2016, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include <linux/kernel.h> +#include <linux/random.h> + +#include <soc/qcom/scm.h> + +#include <asm/io.h> +#include <asm/cacheflush.h> + +#define TZ_SVC_CRYPTO 10 +#define PRNG_CMD_ID 0x01 + +struct tz_prng_data { + uint8_t *out_buf; + uint32_t out_buf_sz; +} __packed; + +DEFINE_SCM_BUFFER(common_scm_buf) +#define RANDOM_BUFFER_SIZE PAGE_SIZE +char random_buffer[RANDOM_BUFFER_SIZE] __aligned(PAGE_SIZE); + +void __init init_random_pool(void) +{ + struct tz_prng_data data; + int ret; + u32 resp; + + data.out_buf = (uint8_t *) virt_to_phys(random_buffer); + data.out_buf_sz = SZ_512; + dmac_flush_range(random_buffer, random_buffer + RANDOM_BUFFER_SIZE); + + ret = scm_call_noalloc(TZ_SVC_CRYPTO, PRNG_CMD_ID, &data, + sizeof(data), &resp, sizeof(resp), + common_scm_buf, SCM_BUFFER_SIZE(common_scm_buf)); + if (!ret) { + dmac_inv_range(random_buffer, random_buffer + + RANDOM_BUFFER_SIZE); + add_device_randomness(random_buffer, SZ_512); + } +} + |
