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.

Merge tag 'random-6.19-rc1-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/crng/random

Pull random number generator updates from Jason Donenfeld:

- Dynamically allocate cpumasks off of the stack if the kernel is
configured for a lot of CPUs, to handle a -Wframe-larger-than case

- The removal of next_pseudo_random32() after the last user was
switched over to the prandom interface

- The removal of get_random_u{8,16,32,64}_wait() functions, as there
were no users of those at all

- Some house keeping changes - a few grammar cleanups in the
comments, system_unbound_wq was renamed to system_dfl_wq, and
static_key_initialized no longer needs to be checked

* tag 'random-6.19-rc1-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/crng/random:
random: complete sentence of comment
random: drop check for static_key_initialized
random: remove unused get_random_var_wait functions
random: replace use of system_unbound_wq with system_dfl_wq
random: use offstack cpumask when necessary
prandom: remove next_pseudo_random32
media: vivid: use prandom
random: add missing words in function comments

+24 -39
+21 -17
drivers/char/random.c
··· 259 259 u8 key[CHACHA_KEY_SIZE]; 260 260 261 261 /* Immediately schedule the next reseeding, so that it fires sooner rather than later. */ 262 - if (likely(system_unbound_wq)) 263 - queue_delayed_work(system_unbound_wq, &next_reseed, crng_reseed_interval()); 262 + if (likely(system_dfl_wq)) 263 + queue_delayed_work(system_dfl_wq, &next_reseed, crng_reseed_interval()); 264 264 265 265 extract_entropy(key, sizeof(key)); 266 266 ··· 427 427 428 428 /* 429 429 * This returns random bytes in arbitrary quantities. The quality of the 430 - * random bytes is good as /dev/urandom. In order to ensure that the 430 + * random bytes is as good as /dev/urandom. In order to ensure that the 431 431 * randomness provided by this function is okay, the function 432 432 * wait_for_random_bytes() should be called and return 0 at least once 433 433 * at any point prior. ··· 491 491 492 492 /* 493 493 * Batched entropy returns random integers. The quality of the random 494 - * number is good as /dev/urandom. In order to ensure that the randomness 494 + * number is as good as /dev/urandom. In order to ensure that the randomness 495 495 * provided by this function is okay, the function wait_for_random_bytes() 496 496 * should be called and return 0 at least once at any point prior. 497 497 */ ··· 741 741 742 742 if (orig < POOL_READY_BITS && new >= POOL_READY_BITS) { 743 743 crng_reseed(NULL); /* Sets crng_init to CRNG_READY under base_crng.lock. */ 744 - if (static_key_initialized && system_unbound_wq) 745 - queue_work(system_unbound_wq, &set_ready); 744 + if (system_dfl_wq) 745 + queue_work(system_dfl_wq, &set_ready); 746 746 atomic_notifier_call_chain(&random_ready_notifier, 0, NULL); 747 747 #ifdef CONFIG_VDSO_GETRANDOM 748 748 WRITE_ONCE(vdso_k_rng_data->is_ready, true); ··· 794 794 * 795 795 * add_bootloader_randomness() is called by bootloader drivers, such as EFI 796 796 * and device tree, and credits its input depending on whether or not the 797 - * command line option 'random.trust_bootloader'. 797 + * command line option 'random.trust_bootloader' is set. 798 798 * 799 799 * add_vmfork_randomness() adds a unique (but not necessarily secret) ID 800 800 * representing the current instance of a VM to the pool, without crediting, ··· 915 915 add_latent_entropy(); 916 916 917 917 /* 918 - * If we were initialized by the cpu or bootloader before jump labels 919 - * or workqueues are initialized, then we should enable the static 920 - * branch here, where it's guaranteed that these have been initialized. 918 + * If we were initialized by the cpu or bootloader before workqueues 919 + * are initialized, then we should enable the static branch here. 921 920 */ 922 921 if (!static_branch_likely(&crng_is_ready) && crng_init >= CRNG_READY) 923 922 crng_set_ready(NULL); ··· 1295 1296 struct entropy_timer_state *stack = PTR_ALIGN((void *)stack_bytes, SMP_CACHE_BYTES); 1296 1297 unsigned int i, num_different = 0; 1297 1298 unsigned long last = random_get_entropy(); 1299 + cpumask_var_t timer_cpus; 1298 1300 int cpu = -1; 1299 1301 1300 1302 for (i = 0; i < NUM_TRIAL_SAMPLES - 1; ++i) { ··· 1310 1310 1311 1311 atomic_set(&stack->samples, 0); 1312 1312 timer_setup_on_stack(&stack->timer, entropy_timer, 0); 1313 + if (!alloc_cpumask_var(&timer_cpus, GFP_KERNEL)) 1314 + goto out; 1315 + 1313 1316 while (!crng_ready() && !signal_pending(current)) { 1314 1317 /* 1315 1318 * Check !timer_pending() and then ensure that any previous callback has finished 1316 1319 * executing by checking timer_delete_sync_try(), before queueing the next one. 1317 1320 */ 1318 1321 if (!timer_pending(&stack->timer) && timer_delete_sync_try(&stack->timer) >= 0) { 1319 - struct cpumask timer_cpus; 1320 1322 unsigned int num_cpus; 1321 1323 1322 1324 /* ··· 1328 1326 preempt_disable(); 1329 1327 1330 1328 /* Only schedule callbacks on timer CPUs that are online. */ 1331 - cpumask_and(&timer_cpus, housekeeping_cpumask(HK_TYPE_TIMER), cpu_online_mask); 1332 - 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); 1333 1331 /* In very bizarre case of misconfiguration, fallback to all online. */ 1334 1332 if (unlikely(num_cpus == 0)) { 1335 - timer_cpus = *cpu_online_mask; 1336 - num_cpus = cpumask_weight(&timer_cpus); 1333 + *timer_cpus = *cpu_online_mask; 1334 + num_cpus = cpumask_weight(timer_cpus); 1337 1335 } 1338 1336 1339 1337 /* Basic CPU round-robin, which avoids the current CPU. */ 1340 1338 do { 1341 - cpu = cpumask_next(cpu, &timer_cpus); 1339 + cpu = cpumask_next(cpu, timer_cpus); 1342 1340 if (cpu >= nr_cpu_ids) 1343 - cpu = cpumask_first(&timer_cpus); 1341 + cpu = cpumask_first(timer_cpus); 1344 1342 } while (cpu == smp_processor_id() && num_cpus > 1); 1345 1343 1346 1344 /* Expiring the timer at `jiffies` means it's the next tick. */ ··· 1356 1354 } 1357 1355 mix_pool_bytes(&stack->entropy, sizeof(stack->entropy)); 1358 1356 1357 + free_cpumask_var(timer_cpus); 1358 + out: 1359 1359 timer_delete_sync(&stack->timer); 1360 1360 timer_destroy_on_stack(&stack->timer); 1361 1361 }
+3 -1
drivers/media/test-drivers/vivid/vivid-vid-cap.c
··· 302 302 */ 303 303 freq_modulus = (dev->tv_freq - 676 /* (43.25-1) * 16 */) % (6 * 16); 304 304 if (freq_modulus > 2 * 16) { 305 + struct rnd_state prng; 306 + prandom_seed_state(&prng, dev->tv_freq ^ 0x55); 305 307 tpg_s_quality(&dev->tpg, TPG_QUAL_NOISE, 306 - next_pseudo_random32(dev->tv_freq ^ 0x55) & 0x3f); 308 + prandom_u32_state(&prng) & 0x3f); 307 309 return; 308 310 } 309 311 if (freq_modulus < 12 /*0.75 * 16*/ || freq_modulus > 20 /*1.25 * 16*/)
-6
include/linux/prandom.h
··· 47 47 state->s4 = __seed(i, 128U); 48 48 } 49 49 50 - /* Pseudo random number generator from numerical recipes. */ 51 - static inline u32 next_pseudo_random32(u32 seed) 52 - { 53 - return seed * 1664525 + 1013904223; 54 - } 55 - 56 50 #endif
-15
include/linux/random.h
··· 130 130 return ret; 131 131 } 132 132 133 - #define declare_get_random_var_wait(name, ret_type) \ 134 - static inline int get_random_ ## name ## _wait(ret_type *out) { \ 135 - int ret = wait_for_random_bytes(); \ 136 - if (unlikely(ret)) \ 137 - return ret; \ 138 - *out = get_random_ ## name(); \ 139 - return 0; \ 140 - } 141 - declare_get_random_var_wait(u8, u8) 142 - declare_get_random_var_wait(u16, u16) 143 - declare_get_random_var_wait(u32, u32) 144 - declare_get_random_var_wait(u64, u32) 145 - declare_get_random_var_wait(long, unsigned long) 146 - #undef declare_get_random_var 147 - 148 133 #ifdef CONFIG_SMP 149 134 int random_prepare_cpu(unsigned int cpu); 150 135 int random_online_cpu(unsigned int cpu);