|
@@ -865,16 +865,24 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
|
|
|
if (r->entropy_count / 8 < min + reserved) {
|
|
|
nbytes = 0;
|
|
|
} else {
|
|
|
+ int entropy_count, orig;
|
|
|
+retry:
|
|
|
+ entropy_count = orig = ACCESS_ONCE(r->entropy_count);
|
|
|
/* If limited, never pull more than available */
|
|
|
- if (r->limit && nbytes + reserved >= r->entropy_count / 8)
|
|
|
- nbytes = r->entropy_count/8 - reserved;
|
|
|
-
|
|
|
- if (r->entropy_count / 8 >= nbytes + reserved)
|
|
|
- r->entropy_count -= nbytes*8;
|
|
|
- else
|
|
|
- r->entropy_count = reserved;
|
|
|
+ if (r->limit && nbytes + reserved >= entropy_count / 8)
|
|
|
+ nbytes = entropy_count/8 - reserved;
|
|
|
+
|
|
|
+ if (entropy_count / 8 >= nbytes + reserved) {
|
|
|
+ entropy_count -= nbytes*8;
|
|
|
+ if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
|
|
|
+ goto retry;
|
|
|
+ } else {
|
|
|
+ entropy_count = reserved;
|
|
|
+ if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
|
|
|
+ goto retry;
|
|
|
+ }
|
|
|
|
|
|
- if (r->entropy_count < random_write_wakeup_thresh)
|
|
|
+ if (entropy_count < random_write_wakeup_thresh)
|
|
|
wakeup_write = 1;
|
|
|
}
|
|
|
|