public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matt Mackall <mpm@selenic.com>
To: Andrew Morton <akpm@osdl.org>, "Theodore Ts'o" <tytso@mit.edu>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 7/12] random pt3: Reseed pointer in pool struct
Date: Wed, 19 Jan 2005 00:17:22 -0800	[thread overview]
Message-ID: <8.64403262@selenic.com> (raw)
In-Reply-To: <7.64403262@selenic.com>

Put pointer to reseed pool in pool struct and automatically pull
entropy from it if it is set. This lets us remove the
EXTRACT_SECONDARY flag.

Signed-off-by: Matt Mackall <mpm@selenic.com>

Index: rnd/drivers/char/random.c
===================================================================
--- rnd.orig/drivers/char/random.c	2005-01-18 10:39:34.550137752 -0800
+++ rnd/drivers/char/random.c	2005-01-18 10:39:47.360504569 -0800
@@ -406,12 +406,14 @@
  *
  **********************************************************************/
 
+struct entropy_store;
 struct entropy_store {
 	/* mostly-read data: */
 	struct poolinfo *poolinfo;
 	__u32 *pool;
 	const char *name;
 	int limit;
+	struct entropy_store *pull;
 
 	/* read-write data: */
 	spinlock_t lock ____cacheline_aligned_in_smp;
@@ -436,6 +438,7 @@
 	.poolinfo = &poolinfo_table[1],
 	.name = "blocking",
 	.limit = 1,
+	.pull = &input_pool,
 	.lock = SPIN_LOCK_UNLOCKED,
 	.pool = blocking_pool_data
 };
@@ -443,6 +446,7 @@
 static struct entropy_store nonblocking_pool = {
 	.poolinfo = &poolinfo_table[1],
 	.name = "nonblocking",
+	.pull = &input_pool,
 	.lock = SPIN_LOCK_UNLOCKED,
 	.pool = nonblocking_pool_data
 };
@@ -1180,7 +1184,6 @@
  *********************************************************************/
 
 #define EXTRACT_ENTROPY_USER		1
-#define EXTRACT_ENTROPY_SECONDARY	2
 #define TMP_BUF_SIZE			(HASH_BUFFER_SIZE + HASH_EXTRA_SIZE)
 #define SEC_XFER_SIZE			(TMP_BUF_SIZE*4)
 
@@ -1195,7 +1198,7 @@
 static inline void xfer_secondary_pool(struct entropy_store *r,
 				       size_t nbytes, __u32 *tmp)
 {
-	if (r->entropy_count < nbytes * 8 &&
+	if (r->pull && r->entropy_count < nbytes * 8 &&
 	    r->entropy_count < r->poolinfo->POOLBITS) {
 		int bytes = max_t(int, random_read_wakeup_thresh / 8,
 				min_t(int, nbytes, TMP_BUF_SIZE));
@@ -1205,7 +1208,7 @@
 			  "(%d of %d requested)\n",
 			  r->name, bytes * 8, nbytes * 8, r->entropy_count);
 
-		bytes=extract_entropy(&input_pool, tmp, bytes,
+		bytes=extract_entropy(r->pull, tmp, bytes,
 				      random_read_wakeup_thresh / 8, rsvd, 0);
 		add_entropy_words(r, tmp, bytes);
 		credit_entropy_store(r, bytes*8);
@@ -1219,10 +1222,6 @@
  * number of bytes that are actually obtained.  If the EXTRACT_ENTROPY_USER
  * flag is given, then the buf pointer is assumed to be in user space.
  *
- * If the EXTRACT_ENTROPY_SECONDARY flag is given, then we are actually
- * extracting entropy from the secondary pool, and can refill from the
- * primary pool if needed.
- *
  * The min parameter specifies the minimum amount we can pull before
  * failing to avoid races that defeat catastrophic reseeding while the
  * reserved parameter indicates how much entropy we must leave in the
@@ -1242,8 +1241,7 @@
 	if (r->entropy_count > r->poolinfo->POOLBITS)
 		r->entropy_count = r->poolinfo->POOLBITS;
 
-	if (flags & EXTRACT_ENTROPY_SECONDARY)
-		xfer_secondary_pool(r, nbytes, tmp);
+	xfer_secondary_pool(r, nbytes, tmp);
 
 	/* Hold lock while accounting */
 	spin_lock_irqsave(&r->lock, cpuflags);
@@ -1358,8 +1356,7 @@
  */
 void get_random_bytes(void *buf, int nbytes)
 {
-	extract_entropy(&nonblocking_pool, (char *) buf, nbytes, 0, 0,
-			EXTRACT_ENTROPY_SECONDARY);
+	extract_entropy(&nonblocking_pool, (char *) buf, nbytes, 0, 0, 0);
 }
 
 EXPORT_SYMBOL(get_random_bytes);
@@ -1449,8 +1446,7 @@
 		DEBUG_ENT("reading %d bits\n", n*8);
 
 		n = extract_entropy(&blocking_pool, buf, n, 0, 0,
-				    EXTRACT_ENTROPY_USER |
-				    EXTRACT_ENTROPY_SECONDARY);
+				    EXTRACT_ENTROPY_USER);
 
 		DEBUG_ENT("read got %d bits (%d still needed)\n",
 			  n*8, (nbytes-n)*8);

  reply	other threads:[~2005-01-19  8:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-19  8:17 [PATCH 0/12] random pt3: More core and accounting cleanups Matt Mackall
2005-01-19  8:17 ` [PATCH 1/12] random pt3: More meaningful pool names Matt Mackall
2005-01-19  8:17   ` [PATCH 2/12] random pt3: Static allocation of pools Matt Mackall
2005-01-19  8:17     ` [PATCH 3/12] random pt3: Static sysctl bits Matt Mackall
2005-01-19  8:17       ` [PATCH 4/12] random pt3: Catastrophic reseed checks Matt Mackall
2005-01-19  8:17         ` [PATCH 5/12] random pt3: Entropy reservation accounting Matt Mackall
2005-01-19  8:17           ` [PATCH 6/12] random pt3: Reservation flag in pool struct Matt Mackall
2005-01-19  8:17             ` Matt Mackall [this message]
2005-01-19  8:17               ` [PATCH 8/12] random pt3: Break up extract_user Matt Mackall
2005-01-19  8:17                 ` [PATCH 9/12] random pt3: Remove dead MD5 copy Matt Mackall
2005-01-19  8:17                   ` [PATCH 10/12] random pt3: Simplify hash folding Matt Mackall
2005-01-19  8:17                     ` [PATCH 11/12] random pt3: Clean up hash buffering Matt Mackall
2005-01-19  8:17                       ` [PATCH 12/12] random pt3: Remove entropy batching Matt Mackall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8.64403262@selenic.com \
    --to=mpm@selenic.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox