264
264
#include <linux/syscalls.h>
265
265
#include <linux/completion.h>
266
266
#include <linux/uuid.h>
267
+ #include <linux/locallock.h>
267
268
#include <crypto/chacha20.h>
268
269
269
270
#include <asm/processor.h>
@@ -2086,6 +2087,7 @@ static rwlock_t batched_entropy_reset_lock = __RW_LOCK_UNLOCKED(batched_entropy_
2086
2087
* at any point prior.
2087
2088
*/
2088
2089
static DEFINE_PER_CPU (struct batched_entropy , batched_entropy_u64 ) ;
2090
+ static DEFINE_LOCAL_IRQ_LOCK (batched_entropy_u64_lock );
2089
2091
u64 get_random_u64 (void )
2090
2092
{
2091
2093
u64 ret ;
@@ -2106,7 +2108,7 @@ u64 get_random_u64(void)
2106
2108
warn_unseeded_randomness (& previous );
2107
2109
2108
2110
use_lock = READ_ONCE (crng_init ) < 2 ;
2109
- batch = & get_cpu_var ( batched_entropy_u64 );
2111
+ batch = & get_locked_var ( batched_entropy_u64_lock , batched_entropy_u64 );
2110
2112
if (use_lock )
2111
2113
read_lock_irqsave (& batched_entropy_reset_lock , flags );
2112
2114
if (batch -> position % ARRAY_SIZE (batch -> entropy_u64 ) == 0 ) {
@@ -2116,12 +2118,13 @@ u64 get_random_u64(void)
2116
2118
ret = batch -> entropy_u64 [batch -> position ++ ];
2117
2119
if (use_lock )
2118
2120
read_unlock_irqrestore (& batched_entropy_reset_lock , flags );
2119
- put_cpu_var ( batched_entropy_u64 );
2121
+ put_locked_var ( batched_entropy_u64_lock , batched_entropy_u64 );
2120
2122
return ret ;
2121
2123
}
2122
2124
EXPORT_SYMBOL (get_random_u64 );
2123
2125
2124
2126
static DEFINE_PER_CPU (struct batched_entropy , batched_entropy_u32 ) ;
2127
+ static DEFINE_LOCAL_IRQ_LOCK (batched_entropy_u32_lock );
2125
2128
u32 get_random_u32 (void )
2126
2129
{
2127
2130
u32 ret ;
@@ -2136,7 +2139,7 @@ u32 get_random_u32(void)
2136
2139
warn_unseeded_randomness (& previous );
2137
2140
2138
2141
use_lock = READ_ONCE (crng_init ) < 2 ;
2139
- batch = & get_cpu_var ( batched_entropy_u32 );
2142
+ batch = & get_locked_var ( batched_entropy_u32_lock , batched_entropy_u32 );
2140
2143
if (use_lock )
2141
2144
read_lock_irqsave (& batched_entropy_reset_lock , flags );
2142
2145
if (batch -> position % ARRAY_SIZE (batch -> entropy_u32 ) == 0 ) {
@@ -2146,7 +2149,7 @@ u32 get_random_u32(void)
2146
2149
ret = batch -> entropy_u32 [batch -> position ++ ];
2147
2150
if (use_lock )
2148
2151
read_unlock_irqrestore (& batched_entropy_reset_lock , flags );
2149
- put_cpu_var ( batched_entropy_u32 );
2152
+ put_locked_var ( batched_entropy_u32_lock , batched_entropy_u32 );
2150
2153
return ret ;
2151
2154
}
2152
2155
EXPORT_SYMBOL (get_random_u32 );
0 commit comments