From 77122f9d68a3a6e3fbd266652467acbd7b5d3225 Mon Sep 17 00:00:00 2001 From: Romain Dolbeau Date: Thu, 6 Feb 2020 18:26:13 +0100 Subject: Replace static per-cpu with dynamic per-cpu data This solves the issue of loading the spl module on RISC-V. Reviewed-by: Brian Behlendorf Signed-off-by: Romain Dolbeau Closes #9942 --- module/os/linux/spl/spl-generic.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/module/os/linux/spl/spl-generic.c b/module/os/linux/spl/spl-generic.c index 091a52a78..c55ebf7c5 100644 --- a/module/os/linux/spl/spl-generic.c +++ b/module/os/linux/spl/spl-generic.c @@ -92,7 +92,7 @@ EXPORT_SYMBOL(p0); * and use them when in_interrupt() from linux/preempt_mask.h evaluates to * true. */ -static DEFINE_PER_CPU(uint64_t[2], spl_pseudo_entropy); +void __percpu *spl_pseudo_entropy; /* * spl_rand_next()/spl_rand_jump() are copied from the following CC-0 licensed @@ -141,7 +141,7 @@ random_get_pseudo_bytes(uint8_t *ptr, size_t len) ASSERT(ptr); - xp = get_cpu_var(spl_pseudo_entropy); + xp = get_cpu_ptr(spl_pseudo_entropy); s[0] = xp[0]; s[1] = xp[1]; @@ -163,7 +163,7 @@ random_get_pseudo_bytes(uint8_t *ptr, size_t len) xp[0] = s[0]; xp[1] = s[1]; - put_cpu_var(spl_pseudo_entropy); + put_cpu_ptr(spl_pseudo_entropy); return (0); } @@ -701,6 +701,9 @@ spl_random_init(void) uint64_t s[2]; int i = 0; + spl_pseudo_entropy = __alloc_percpu(2 * sizeof (uint64_t), + sizeof (uint64_t)); + get_random_bytes(s, sizeof (s)); if (s[0] == 0 && s[1] == 0) { @@ -717,7 +720,7 @@ spl_random_init(void) } for_each_possible_cpu(i) { - uint64_t *wordp = per_cpu(spl_pseudo_entropy, i); + uint64_t *wordp = per_cpu_ptr(spl_pseudo_entropy, i); spl_rand_jump(s); @@ -726,6 +729,12 @@ spl_random_init(void) } } +static void +spl_random_fini(void) +{ + free_percpu(spl_pseudo_entropy); +} + static void spl_kvmem_fini(void) { @@ -790,6 +799,7 @@ spl_fini(void) spl_taskq_fini(); spl_tsd_fini(); spl_kvmem_fini(); + spl_random_fini(); } module_init(spl_init); -- cgit v1.2.3