Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

random: use offstack cpumask when necessary

The entropy generation function keeps a local cpu mask on the stack,
which can trigger warnings in configurations with a large number of
CPUs:

drivers/char/random.c:1292:20: error: stack frame size (1288)
exceeds limit (1280) in 'try_to_generate_entropy' [-Werror,-Wframe-larger-than]

Use the cpumask interface to dynamically allocate it in those
configurations.

Fixes: 1c21fe00eda7 ("random: spread out jitter callback to different CPUs")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

authored by

Arnd Bergmann and committed by
Jason A. Donenfeld
5d49f1a5 3c0c81de

+12 -7
+12 -7
drivers/char/random.c
··· 1296 1296 struct entropy_timer_state *stack = PTR_ALIGN((void *)stack_bytes, SMP_CACHE_BYTES); 1297 1297 unsigned int i, num_different = 0; 1298 1298 unsigned long last = random_get_entropy(); 1299 + cpumask_var_t timer_cpus; 1299 1300 int cpu = -1; 1300 1301 1301 1302 for (i = 0; i < NUM_TRIAL_SAMPLES - 1; ++i) { ··· 1311 1310 1312 1311 atomic_set(&stack->samples, 0); 1313 1312 timer_setup_on_stack(&stack->timer, entropy_timer, 0); 1313 + if (!alloc_cpumask_var(&timer_cpus, GFP_KERNEL)) 1314 + goto out; 1315 + 1314 1316 while (!crng_ready() && !signal_pending(current)) { 1315 1317 /* 1316 1318 * Check !timer_pending() and then ensure that any previous callback has finished 1317 1319 * executing by checking timer_delete_sync_try(), before queueing the next one. 1318 1320 */ 1319 1321 if (!timer_pending(&stack->timer) && timer_delete_sync_try(&stack->timer) >= 0) { 1320 - struct cpumask timer_cpus; 1321 1322 unsigned int num_cpus; 1322 1323 1323 1324 /* ··· 1329 1326 preempt_disable(); 1330 1327 1331 1328 /* Only schedule callbacks on timer CPUs that are online. */ 1332 - cpumask_and(&timer_cpus, housekeeping_cpumask(HK_TYPE_TIMER), cpu_online_mask); 1333 - num_cpus = cpumask_weight(&timer_cpus); 1329 + cpumask_and(timer_cpus, housekeeping_cpumask(HK_TYPE_TIMER), cpu_online_mask); 1330 + num_cpus = cpumask_weight(timer_cpus); 1334 1331 /* In very bizarre case of misconfiguration, fallback to all online. */ 1335 1332 if (unlikely(num_cpus == 0)) { 1336 - timer_cpus = *cpu_online_mask; 1337 - num_cpus = cpumask_weight(&timer_cpus); 1333 + *timer_cpus = *cpu_online_mask; 1334 + num_cpus = cpumask_weight(timer_cpus); 1338 1335 } 1339 1336 1340 1337 /* Basic CPU round-robin, which avoids the current CPU. */ 1341 1338 do { 1342 - cpu = cpumask_next(cpu, &timer_cpus); 1339 + cpu = cpumask_next(cpu, timer_cpus); 1343 1340 if (cpu >= nr_cpu_ids) 1344 - cpu = cpumask_first(&timer_cpus); 1341 + cpu = cpumask_first(timer_cpus); 1345 1342 } while (cpu == smp_processor_id() && num_cpus > 1); 1346 1343 1347 1344 /* Expiring the timer at `jiffies` means it's the next tick. */ ··· 1357 1354 } 1358 1355 mix_pool_bytes(&stack->entropy, sizeof(stack->entropy)); 1359 1356 1357 + free_cpumask_var(timer_cpus); 1358 + out: 1360 1359 timer_delete_sync(&stack->timer); 1361 1360 timer_destroy_on_stack(&stack->timer); 1362 1361 }