Commit 2fb4f725 authored by Matt Mackall's avatar Matt Mackall Committed by Linus Torvalds

[PATCH] random: Reservation flag in pool struct

Move the limit flag to the pool struct, begin process of eliminating extract
flags.
Signed-off-by: default avatarMatt Mackall <mpm@selenic.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 67d53899
...@@ -411,6 +411,7 @@ struct entropy_store { ...@@ -411,6 +411,7 @@ struct entropy_store {
struct poolinfo *poolinfo; struct poolinfo *poolinfo;
__u32 *pool; __u32 *pool;
const char *name; const char *name;
int limit;
/* read-write data: */ /* read-write data: */
spinlock_t lock ____cacheline_aligned_in_smp; spinlock_t lock ____cacheline_aligned_in_smp;
...@@ -426,6 +427,7 @@ static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS]; ...@@ -426,6 +427,7 @@ static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
static struct entropy_store input_pool = { static struct entropy_store input_pool = {
.poolinfo = &poolinfo_table[0], .poolinfo = &poolinfo_table[0],
.name = "input", .name = "input",
.limit = 1,
.lock = SPIN_LOCK_UNLOCKED, .lock = SPIN_LOCK_UNLOCKED,
.pool = input_pool_data .pool = input_pool_data
}; };
...@@ -433,6 +435,7 @@ static struct entropy_store input_pool = { ...@@ -433,6 +435,7 @@ static struct entropy_store input_pool = {
static struct entropy_store blocking_pool = { static struct entropy_store blocking_pool = {
.poolinfo = &poolinfo_table[1], .poolinfo = &poolinfo_table[1],
.name = "blocking", .name = "blocking",
.limit = 1,
.lock = SPIN_LOCK_UNLOCKED, .lock = SPIN_LOCK_UNLOCKED,
.pool = blocking_pool_data .pool = blocking_pool_data
}; };
...@@ -1178,7 +1181,6 @@ static void MD5Transform(__u32 buf[HASH_BUFFER_SIZE], __u32 const in[16]) ...@@ -1178,7 +1181,6 @@ static void MD5Transform(__u32 buf[HASH_BUFFER_SIZE], __u32 const in[16])
#define EXTRACT_ENTROPY_USER 1 #define EXTRACT_ENTROPY_USER 1
#define EXTRACT_ENTROPY_SECONDARY 2 #define EXTRACT_ENTROPY_SECONDARY 2
#define EXTRACT_ENTROPY_LIMIT 4
#define TMP_BUF_SIZE (HASH_BUFFER_SIZE + HASH_EXTRA_SIZE) #define TMP_BUF_SIZE (HASH_BUFFER_SIZE + HASH_EXTRA_SIZE)
#define SEC_XFER_SIZE (TMP_BUF_SIZE*4) #define SEC_XFER_SIZE (TMP_BUF_SIZE*4)
...@@ -1197,14 +1199,14 @@ static inline void xfer_secondary_pool(struct entropy_store *r, ...@@ -1197,14 +1199,14 @@ static inline void xfer_secondary_pool(struct entropy_store *r,
r->entropy_count < r->poolinfo->POOLBITS) { r->entropy_count < r->poolinfo->POOLBITS) {
int bytes = max_t(int, random_read_wakeup_thresh / 8, int bytes = max_t(int, random_read_wakeup_thresh / 8,
min_t(int, nbytes, TMP_BUF_SIZE)); min_t(int, nbytes, TMP_BUF_SIZE));
int rsvd = r->limit ? 0 : random_read_wakeup_thresh/4;
DEBUG_ENT("going to reseed %s with %d bits " DEBUG_ENT("going to reseed %s with %d bits "
"(%d of %d requested)\n", "(%d of %d requested)\n",
r->name, bytes * 8, nbytes * 8, r->entropy_count); r->name, bytes * 8, nbytes * 8, r->entropy_count);
bytes=extract_entropy(&input_pool, tmp, bytes, bytes=extract_entropy(&input_pool, tmp, bytes,
random_read_wakeup_thresh / 8, 0, random_read_wakeup_thresh / 8, rsvd, 0);
EXTRACT_ENTROPY_LIMIT);
add_entropy_words(r, tmp, (bytes + 3) / 4); add_entropy_words(r, tmp, (bytes + 3) / 4);
credit_entropy_store(r, bytes*8); credit_entropy_store(r, bytes*8);
} }
...@@ -1254,8 +1256,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void * buf, ...@@ -1254,8 +1256,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void * buf,
nbytes = 0; nbytes = 0;
} else { } else {
/* If limited, never pull more than available */ /* If limited, never pull more than available */
if (flags & EXTRACT_ENTROPY_LIMIT && if (r->limit && nbytes + reserved >= r->entropy_count / 8)
nbytes + reserved >= r->entropy_count / 8)
nbytes = r->entropy_count/8 - reserved; nbytes = r->entropy_count/8 - reserved;
if(r->entropy_count / 8 >= nbytes + reserved) if(r->entropy_count / 8 >= nbytes + reserved)
...@@ -1268,8 +1269,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void * buf, ...@@ -1268,8 +1269,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void * buf,
} }
DEBUG_ENT("debiting %d entropy credits from %s%s\n", DEBUG_ENT("debiting %d entropy credits from %s%s\n",
nbytes * 8, r->name, nbytes * 8, r->name, r->limit ? "" : " (unlimited)");
flags & EXTRACT_ENTROPY_LIMIT ? "" : " (unlimited)");
spin_unlock_irqrestore(&r->lock, cpuflags); spin_unlock_irqrestore(&r->lock, cpuflags);
...@@ -1450,7 +1450,6 @@ random_read(struct file * file, char __user * buf, size_t nbytes, loff_t *ppos) ...@@ -1450,7 +1450,6 @@ random_read(struct file * file, char __user * buf, size_t nbytes, loff_t *ppos)
n = extract_entropy(&blocking_pool, buf, n, 0, 0, n = extract_entropy(&blocking_pool, buf, n, 0, 0,
EXTRACT_ENTROPY_USER | EXTRACT_ENTROPY_USER |
EXTRACT_ENTROPY_LIMIT |
EXTRACT_ENTROPY_SECONDARY); EXTRACT_ENTROPY_SECONDARY);
DEBUG_ENT("read got %d bits (%d still needed)\n", DEBUG_ENT("read got %d bits (%d still needed)\n",
...@@ -1502,15 +1501,8 @@ static ssize_t ...@@ -1502,15 +1501,8 @@ static ssize_t
urandom_read(struct file * file, char __user * buf, urandom_read(struct file * file, char __user * buf,
size_t nbytes, loff_t *ppos) size_t nbytes, loff_t *ppos)
{ {
int flags = EXTRACT_ENTROPY_USER; return extract_entropy(&nonblocking_pool, buf, nbytes, 0, 0,
unsigned long cpuflags; EXTRACT_ENTROPY_USER);
spin_lock_irqsave(&input_pool.lock, cpuflags);
if (input_pool.entropy_count > input_pool.poolinfo->POOLBITS)
flags |= EXTRACT_ENTROPY_SECONDARY;
spin_unlock_irqrestore(&input_pool.lock, cpuflags);
return extract_entropy(&nonblocking_pool, buf, nbytes, 0, 0, flags);
} }
static unsigned int static unsigned int
......
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