Commit 2132a96f authored by Greg Price's avatar Greg Price Committed by Theodore Ts'o

random: clarify bits/bytes in wakeup thresholds

These are a recurring cause of confusion, so rename them to
hopefully be clearer.
Signed-off-by: default avatarGreg Price <price@mit.edu>
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
parent 7d1b08c4
...@@ -295,14 +295,14 @@ ...@@ -295,14 +295,14 @@
* The minimum number of bits of entropy before we wake up a read on * The minimum number of bits of entropy before we wake up a read on
* /dev/random. Should be enough to do a significant reseed. * /dev/random. Should be enough to do a significant reseed.
*/ */
static int random_read_wakeup_thresh = 64; static int random_read_wakeup_bits = 64;
/* /*
* If the entropy count falls under this number of bits, then we * If the entropy count falls under this number of bits, then we
* should wake up processes which are selecting or polling on write * should wake up processes which are selecting or polling on write
* access to /dev/random. * access to /dev/random.
*/ */
static int random_write_wakeup_thresh = 28 * OUTPUT_POOL_WORDS; static int random_write_wakeup_bits = 28 * OUTPUT_POOL_WORDS;
/* /*
* The minimum number of seconds between urandom pool reseeding. We * The minimum number of seconds between urandom pool reseeding. We
...@@ -669,7 +669,7 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits) ...@@ -669,7 +669,7 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)
int entropy_bits = entropy_count >> ENTROPY_SHIFT; int entropy_bits = entropy_count >> ENTROPY_SHIFT;
/* should we wake readers? */ /* should we wake readers? */
if (entropy_bits >= random_read_wakeup_thresh) { if (entropy_bits >= random_read_wakeup_bits) {
wake_up_interruptible(&random_read_wait); wake_up_interruptible(&random_read_wait);
kill_fasync(&fasync, SIGIO, POLL_IN); kill_fasync(&fasync, SIGIO, POLL_IN);
} }
...@@ -678,9 +678,9 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits) ...@@ -678,9 +678,9 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)
* forth between them, until the output pools are 75% * forth between them, until the output pools are 75%
* full. * full.
*/ */
if (entropy_bits > random_write_wakeup_thresh && if (entropy_bits > random_write_wakeup_bits &&
r->initialized && r->initialized &&
r->entropy_total >= 2*random_read_wakeup_thresh) { r->entropy_total >= 2*random_read_wakeup_bits) {
static struct entropy_store *last = &blocking_pool; static struct entropy_store *last = &blocking_pool;
struct entropy_store *other = &blocking_pool; struct entropy_store *other = &blocking_pool;
...@@ -924,19 +924,19 @@ static void _xfer_secondary_pool(struct entropy_store *r, size_t nbytes) ...@@ -924,19 +924,19 @@ static void _xfer_secondary_pool(struct entropy_store *r, size_t nbytes)
{ {
__u32 tmp[OUTPUT_POOL_WORDS]; __u32 tmp[OUTPUT_POOL_WORDS];
/* For /dev/random's pool, always leave two wakeup worth's BITS */ /* For /dev/random's pool, always leave two wakeups' worth */
int rsvd = r->limit ? 0 : random_read_wakeup_thresh/4; int rsvd_bytes = r->limit ? 0 : random_read_wakeup_bits / 4;
int bytes = nbytes; int bytes = nbytes;
/* pull at least as many as BYTES as wakeup BITS */ /* pull at least as much as a wakeup */
bytes = max_t(int, bytes, random_read_wakeup_thresh / 8); bytes = max_t(int, bytes, random_read_wakeup_bits / 8);
/* but never more than the buffer size */ /* but never more than the buffer size */
bytes = min_t(int, bytes, sizeof(tmp)); bytes = min_t(int, bytes, sizeof(tmp));
trace_xfer_secondary_pool(r->name, bytes * 8, nbytes * 8, trace_xfer_secondary_pool(r->name, bytes * 8, nbytes * 8,
ENTROPY_BITS(r), ENTROPY_BITS(r->pull)); ENTROPY_BITS(r), ENTROPY_BITS(r->pull));
bytes = extract_entropy(r->pull, tmp, bytes, bytes = extract_entropy(r->pull, tmp, bytes,
random_read_wakeup_thresh / 8, rsvd); random_read_wakeup_bits / 8, rsvd_bytes);
mix_pool_bytes(r, tmp, bytes, NULL); mix_pool_bytes(r, tmp, bytes, NULL);
credit_entropy_bits(r, bytes*8); credit_entropy_bits(r, bytes*8);
} }
...@@ -952,7 +952,7 @@ static void push_to_pool(struct work_struct *work) ...@@ -952,7 +952,7 @@ static void push_to_pool(struct work_struct *work)
struct entropy_store *r = container_of(work, struct entropy_store, struct entropy_store *r = container_of(work, struct entropy_store,
push_work); push_work);
BUG_ON(!r); BUG_ON(!r);
_xfer_secondary_pool(r, random_read_wakeup_thresh/8); _xfer_secondary_pool(r, random_read_wakeup_bits/8);
trace_push_to_pool(r->name, r->entropy_count >> ENTROPY_SHIFT, trace_push_to_pool(r->name, r->entropy_count >> ENTROPY_SHIFT,
r->pull->entropy_count >> ENTROPY_SHIFT); r->pull->entropy_count >> ENTROPY_SHIFT);
} }
...@@ -987,7 +987,7 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min, ...@@ -987,7 +987,7 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
trace_debit_entropy(r->name, 8 * ibytes); trace_debit_entropy(r->name, 8 * ibytes);
if (ibytes && if (ibytes &&
(r->entropy_count >> ENTROPY_SHIFT) < random_write_wakeup_thresh) { (r->entropy_count >> ENTROPY_SHIFT) < random_write_wakeup_bits) {
wake_up_interruptible(&random_write_wait); wake_up_interruptible(&random_write_wait);
kill_fasync(&fasync, SIGIO, POLL_OUT); kill_fasync(&fasync, SIGIO, POLL_OUT);
} }
...@@ -1303,7 +1303,7 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) ...@@ -1303,7 +1303,7 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
wait_event_interruptible(random_read_wait, wait_event_interruptible(random_read_wait,
ENTROPY_BITS(&input_pool) >= ENTROPY_BITS(&input_pool) >=
random_read_wakeup_thresh); random_read_wakeup_bits);
if (signal_pending(current)) if (signal_pending(current))
return -ERESTARTSYS; return -ERESTARTSYS;
} }
...@@ -1334,9 +1334,9 @@ random_poll(struct file *file, poll_table * wait) ...@@ -1334,9 +1334,9 @@ random_poll(struct file *file, poll_table * wait)
poll_wait(file, &random_read_wait, wait); poll_wait(file, &random_read_wait, wait);
poll_wait(file, &random_write_wait, wait); poll_wait(file, &random_write_wait, wait);
mask = 0; mask = 0;
if (ENTROPY_BITS(&input_pool) >= random_read_wakeup_thresh) if (ENTROPY_BITS(&input_pool) >= random_read_wakeup_bits)
mask |= POLLIN | POLLRDNORM; mask |= POLLIN | POLLRDNORM;
if (ENTROPY_BITS(&input_pool) < random_write_wakeup_thresh) if (ENTROPY_BITS(&input_pool) < random_write_wakeup_bits)
mask |= POLLOUT | POLLWRNORM; mask |= POLLOUT | POLLWRNORM;
return mask; return mask;
} }
...@@ -1559,7 +1559,7 @@ struct ctl_table random_table[] = { ...@@ -1559,7 +1559,7 @@ struct ctl_table random_table[] = {
}, },
{ {
.procname = "read_wakeup_threshold", .procname = "read_wakeup_threshold",
.data = &random_read_wakeup_thresh, .data = &random_read_wakeup_bits,
.maxlen = sizeof(int), .maxlen = sizeof(int),
.mode = 0644, .mode = 0644,
.proc_handler = proc_dointvec_minmax, .proc_handler = proc_dointvec_minmax,
...@@ -1568,7 +1568,7 @@ struct ctl_table random_table[] = { ...@@ -1568,7 +1568,7 @@ struct ctl_table random_table[] = {
}, },
{ {
.procname = "write_wakeup_threshold", .procname = "write_wakeup_threshold",
.data = &random_write_wakeup_thresh, .data = &random_write_wakeup_bits,
.maxlen = sizeof(int), .maxlen = sizeof(int),
.mode = 0644, .mode = 0644,
.proc_handler = proc_dointvec_minmax, .proc_handler = proc_dointvec_minmax,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment