Skip to contentSkip to conversation

srandom32 fixes for networking v2

PATCH Applied Andi Kleen 2 participants 2 messages Apr 3, 2008

Subsystems (3)
lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 srandom32 fixes for networking v2

srandom32 fixes for networking v2

- Let it update the state of all CPUs. The network stack goes into pains to feed the current IP addresses in, but it is not very effective if that is only done for some random CPU instead of all. So change it to feed bits into all CPUs. I decided to do that lockless because well somewhat random results are ok.

v2: Drop rename so that this patch doesn't depend on x86 maintainers

---
 include/linux/net.h    |    2 +-
 include/linux/random.h |    2 +-
 lib/random32.c         |   19 ++++++++++++-------
 3 files changed, 14 insertions(+), 9 deletions(-)
lib/random32.c +9 -4
Index: linux/lib/random32.c
===================================================================
@@ -97,13 +97,18 @@ EXPORT_SYMBOL(random32);
  *	@seed: seed value
  *
  *	Add some additional seeding to the random32() pool.
- *	Note: this pool is per cpu so it only affects current CPU.
  */
 void srandom32(u32 entropy)
 {
-	struct rnd_state *state = &get_cpu_var(net_rand_state);
-	__set_random32(state, state->s1 ^ entropy);
-	put_cpu_var(state);
+	int i;
+	/*
+	 * No locking on the CPUs, but then somewhat random results are, well,
+	 * expected.
+	 */
+	for_each_possible_cpu (i) {
+		struct rnd_state *state = &per_cpu(net_rand_state, i);
+		__set_random32(state, state->s1 ^ entropy);
+	}
 }
 EXPORT_SYMBOL(srandom32);
 
maintainer Applied
#1 lore raw

From: Andi Kleen <[email protected]>
Date: Thu, 3 Apr 2008 22:36:11 +0200

Quoted 11 lines

srandom32 fixes for networking v2

- Let it update the state of all CPUs. The network stack goes into pains to feed the current IP addresses in, but it is not very effective if that is only done for some random CPU instead of all. So change it to feed bits into all CPUs. I decided to do that lockless because well somewhat random results are ok.

v2: Drop rename so that this patch doesn't depend on x86 maintainers

Applied, thanks.