aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2020-08-20 08:55:50 +0200
committerWilly Tarreau <w@1wt.eu>2020-08-20 08:55:50 +0200
commit263ff7fa88b9b36bcc5138072f68de2974412330 (patch)
tree7e34a7757c915c2a76e61db771203f5ce1af0a94
parentc95dd5d255243a5b2e516db065e690e93074c241 (diff)
downloadprandom-20200820-siphash-noise.tar.gz
WIP: random32: make siprand_state 4 longs instead of an array20200820-siphash-noise
I've met this strange error while making for allmodconfig: scripts/kconfig/conf --syncconfig Kconfig CALL scripts/checksyscalls.sh CALL scripts/atomic/check-atomics.sh DESCEND objtool CC lib/random32.o In file included from ./include/asm-generic/percpu.h:7, from ./arch/x86/include/asm/percpu.h:390, from ./arch/x86/include/asm/preempt.h:6, from ./include/linux/preempt.h:78, from ./include/linux/percpu.h:6, from lib/random32.c:36: lib/random32.c:323:30: error: structure variable 'net_rand_state' with 'latent_entropy' attribute has a non-integer field 'v' 323 | static DEFINE_PER_CPU(struct siprand_state, net_rand_state) __latent_entropy; | ^~~~~~~~~~~~~ ./include/linux/percpu-defs.h:95:38: note: in definition of macro 'DEFINE_PER_CPU_SECTION' 95 | __PCPU_ATTRS(sec) __weak __typeof__(type) name | ^~~~ lib/random32.c:323:8: note: in expansion of macro 'DEFINE_PER_CPU' 323 | static DEFINE_PER_CPU(struct siprand_state, net_rand_state) __latent_entropy; | ^~~~~~~~~~~~~~ make[2]: *** [lib/random32.o] Error 1 make[1]: *** [lib] Error 2 make: *** [__sub-make] Error 2 It goes away when the members of the struct are all individual integers instead of an array of integers. We really don't care since they're always used separately, let's change this.
-rw-r--r--lib/random32.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/lib/random32.c b/lib/random32.c
index 6fcb7a92b40023..e09c7be374f622 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -317,7 +317,10 @@ static void __init prandom_state_selftest(void)
*/
struct siprand_state {
- unsigned long v[4];
+ unsigned long v0;
+ unsigned long v1;
+ unsigned long v2;
+ unsigned long v3;
};
static DEFINE_PER_CPU(struct siprand_state, net_rand_state) __latent_entropy;
@@ -345,14 +348,14 @@ EXPORT_PER_CPU_SYMBOL(net_rand_noise);
*/
static inline u32 siprand_u32(struct siprand_state *s)
{
- unsigned long v0 = s->v[0], v1 = s->v[1], v2 = s->v[2], v3 = s->v[3];
+ unsigned long v0 = s->v0, v1 = s->v1, v2 = s->v2, v3 = s->v3;
unsigned long n = __this_cpu_read(net_rand_noise);
v3 ^= n;
PRND_SIPROUND(v0, v1, v2, v3);
PRND_SIPROUND(v0, v1, v2, v3);
v0 ^= n;
- s->v[0] = v0; s->v[1] = v1; s->v[2] = v2; s->v[3] = v3;
+ s->v0 = v0; s->v1 = v1; s->v2 = v2; s->v3 = v3;
return v1 + v3;
}
//EXPORT_SYMBOL(siprand_u32);
@@ -420,8 +423,8 @@ void prandom_seed(u32 entropy)
for_each_possible_cpu(i) {
struct siprand_state *state = per_cpu_ptr(&net_rand_state, i);
- unsigned long v0 = state->v[0], v1 = state->v[1];
- unsigned long v2 = state->v[2], v3 = state->v[3];
+ unsigned long v0 = state->v0, v1 = state->v1;
+ unsigned long v2 = state->v2, v3 = state->v3;
do {
v3 ^= entropy;
@@ -430,10 +433,10 @@ void prandom_seed(u32 entropy)
v0 ^= entropy;
} while (unlikely(!v0 || !v1 || !v2 || !v3));
- WRITE_ONCE(state->v[0], v0);
- WRITE_ONCE(state->v[1], v1);
- WRITE_ONCE(state->v[2], v2);
- WRITE_ONCE(state->v[3], v3);
+ WRITE_ONCE(state->v0, v0);
+ WRITE_ONCE(state->v1, v1);
+ WRITE_ONCE(state->v2, v2);
+ WRITE_ONCE(state->v3, v3);
}
}
EXPORT_SYMBOL(prandom_seed);
@@ -463,8 +466,8 @@ static int __init prandom_init_early(void)
v0 ^= i;
state = per_cpu_ptr(&net_rand_state, i);
- state->v[0] = v0; state->v[1] = v1;
- state->v[2] = v2; state->v[3] = v3;
+ state->v0 = v0; state->v1 = v1;
+ state->v2 = v2; state->v3 = v3;
}
return 0;
@@ -518,10 +521,10 @@ static void prandom_reseed(struct timer_list *unused)
* we write contains no zero words.
*/
state = per_cpu_ptr(&net_rand_state, i);
- WRITE_ONCE(state->v[0], v0 ? v0 : -1ul);
- WRITE_ONCE(state->v[1], v1 ? v1 : -1ul);
- WRITE_ONCE(state->v[2], v2 ? v2 : -1ul);
- WRITE_ONCE(state->v[3], v3 ? v3 : -1ul);
+ WRITE_ONCE(state->v0, v0 ? v0 : -1ul);
+ WRITE_ONCE(state->v1, v1 ? v1 : -1ul);
+ WRITE_ONCE(state->v2, v2 ? v2 : -1ul);
+ WRITE_ONCE(state->v3, v3 ? v3 : -1ul);
}
/* reseed every ~60 seconds, in [40 .. 80) interval with slack */