LKML Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/5] random: remove unnecessary unlikely()
@ 2019-06-07 18:25 Yangtao Li
  2019-06-07 18:25 ` [PATCH 2/5] random: convert to ENTROPY_BITS Yangtao Li
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Yangtao Li @ 2019-06-07 18:25 UTC (permalink / raw)
  To: tytso, arnd, gregkh; +Cc: linux-kernel, Yangtao Li

WARN_ON() already contains an unlikely(), so it's not necessary to use
unlikely.

Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
---
 drivers/char/random.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 5d5ea4ce1442..bebf622c61c4 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -759,10 +759,9 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)
 		} while (unlikely(entropy_count < pool_size-2 && pnfrac));
 	}
 
-	if (unlikely(entropy_count < 0)) {
+	if (WARN_ON(entropy_count < 0)) {
 		pr_warn("random: negative entropy/overflow: pool %s count %d\n",
 			r->name, entropy_count);
-		WARN_ON(1);
 		entropy_count = 0;
 	} else if (entropy_count > pool_size)
 		entropy_count = pool_size;
@@ -1465,10 +1464,9 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
 	if (ibytes < min)
 		ibytes = 0;
 
-	if (unlikely(entropy_count < 0)) {
+	if (WARN_ON(entropy_count < 0)) {
 		pr_warn("random: negative entropy count: pool %s count %d\n",
 			r->name, entropy_count);
-		WARN_ON(1);
 		entropy_count = 0;
 	}
 	nfrac = ibytes << (ENTROPY_SHIFT + 3);
-- 
2.17.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/5] random: convert to ENTROPY_BITS
  2019-06-07 18:25 [PATCH 1/5] random: remove unnecessary unlikely() Yangtao Li
@ 2019-06-07 18:25 ` Yangtao Li
  2019-06-07 18:25 ` [PATCH 3/5] random: Add and use pr_fmt() Yangtao Li
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Yangtao Li @ 2019-06-07 18:25 UTC (permalink / raw)
  To: tytso, arnd, gregkh; +Cc: linux-kernel, Yangtao Li

Use DEFINE_SHOW_ATTRIBUTE macro to enhance code readability.

Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
---
 drivers/char/random.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index bebf622c61c4..d714a458f088 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -788,7 +788,7 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)
 			if (entropy_bits < 128)
 				return;
 			crng_reseed(&primary_crng, r);
-			entropy_bits = r->entropy_count >> ENTROPY_SHIFT;
+			entropy_bits = ENTROPY_BITS(r);
 		}
 
 		/* initialize the blocking pool if necessary */
@@ -1396,8 +1396,7 @@ EXPORT_SYMBOL_GPL(add_disk_randomness);
 static void _xfer_secondary_pool(struct entropy_store *r, size_t nbytes);
 static void xfer_secondary_pool(struct entropy_store *r, size_t nbytes)
 {
-	if (!r->pull ||
-	    r->entropy_count >= (nbytes << (ENTROPY_SHIFT + 3)) ||
+	if (!r->pull || ENTROPY_BITS(r) >= (nbytes << 3) ||
 	    r->entropy_count > r->poolinfo->poolfracbits)
 		return;
 
@@ -1435,8 +1434,7 @@ static void push_to_pool(struct work_struct *work)
 					      push_work);
 	BUG_ON(!r);
 	_xfer_secondary_pool(r, random_read_wakeup_bits/8);
-	trace_push_to_pool(r->name, r->entropy_count >> ENTROPY_SHIFT,
-			   r->pull->entropy_count >> ENTROPY_SHIFT);
+	trace_push_to_pool(r->name, ENTROPY_BITS(r), ENTROPY_BITS(r->pull));
 }
 
 /*
@@ -1479,8 +1477,7 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
 		goto retry;
 
 	trace_debit_entropy(r->name, 8 * ibytes);
-	if (ibytes &&
-	    (r->entropy_count >> ENTROPY_SHIFT) < random_write_wakeup_bits) {
+	if (ibytes && ENTROPY_BITS(r) < random_write_wakeup_bits) {
 		wake_up_interruptible(&random_write_wait);
 		kill_fasync(&fasync, SIGIO, POLL_OUT);
 	}
-- 
2.17.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/5] random: Add and use pr_fmt()
  2019-06-07 18:25 [PATCH 1/5] random: remove unnecessary unlikely() Yangtao Li
  2019-06-07 18:25 ` [PATCH 2/5] random: convert to ENTROPY_BITS Yangtao Li
@ 2019-06-07 18:25 ` Yangtao Li
  2019-06-10 19:12   ` Joe Perches
  2019-06-07 18:25 ` [PATCH 4/5] random: fix typo in add_timer_randomness() Yangtao Li
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Yangtao Li @ 2019-06-07 18:25 UTC (permalink / raw)
  To: tytso, arnd, gregkh; +Cc: linux-kernel, Yangtao Li

Prefix all printk/pr_<level> messages with "random: " to make the
logging a bit more consistent.

Miscellanea:

o Convert a printks to pr_notice
o Whitespace to align to open parentheses
o Remove embedded "random: " from pr_* as pr_fmt adds it

Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
---
 drivers/char/random.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index d714a458f088..f0c834af14a8 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -307,6 +307,8 @@
  * Eastlake, Steve Crocker, and Jeff Schiller.
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/utsname.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
@@ -760,7 +762,7 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)
 	}
 
 	if (WARN_ON(entropy_count < 0)) {
-		pr_warn("random: negative entropy/overflow: pool %s count %d\n",
+		pr_warn("negative entropy/overflow: pool %s count %d\n",
 			r->name, entropy_count);
 		entropy_count = 0;
 	} else if (entropy_count > pool_size)
@@ -883,7 +885,7 @@ static void crng_initialize(struct crng_state *crng)
 		invalidate_batched_entropy();
 		numa_crng_init();
 		crng_init = 2;
-		pr_notice("random: crng done (trusting CPU's manufacturer)\n");
+		pr_notice("crng done (trusting CPU's manufacturer)\n");
 	}
 	crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1;
 }
@@ -946,7 +948,7 @@ static int crng_fast_load(const char *cp, size_t len)
 		invalidate_batched_entropy();
 		crng_init = 1;
 		wake_up_interruptible(&crng_init_wait);
-		pr_notice("random: fast init done\n");
+		pr_notice("fast init done\n");
 	}
 	return 1;
 }
@@ -1031,15 +1033,15 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r)
 		crng_init = 2;
 		process_random_ready_list();
 		wake_up_interruptible(&crng_init_wait);
-		pr_notice("random: crng init done\n");
+		pr_notice("crng init done\n");
 		if (unseeded_warning.missed) {
-			pr_notice("random: %d get_random_xx warning(s) missed "
+			pr_notice("%d get_random_xx warning(s) missed "
 				  "due to ratelimiting\n",
 				  unseeded_warning.missed);
 			unseeded_warning.missed = 0;
 		}
 		if (urandom_warning.missed) {
-			pr_notice("random: %d urandom warning(s) missed "
+			pr_notice("%d urandom warning(s) missed "
 				  "due to ratelimiting\n",
 				  urandom_warning.missed);
 			urandom_warning.missed = 0;
@@ -1463,7 +1465,7 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
 		ibytes = 0;
 
 	if (WARN_ON(entropy_count < 0)) {
-		pr_warn("random: negative entropy count: pool %s count %d\n",
+		pr_warn("negative entropy count: pool %s count %d\n",
 			r->name, entropy_count);
 		entropy_count = 0;
 	}
@@ -1682,7 +1684,7 @@ static void _warn_unseeded_randomness(const char *func_name, void *caller,
 	print_once = true;
 #endif
 	if (__ratelimit(&unseeded_warning))
-		pr_notice("random: %s called from %pS with crng_init=%d\n",
+		pr_notice("%s called from %pS with crng_init=%d\n",
 			  func_name, caller, crng_init);
 }
 
@@ -1964,9 +1966,8 @@ urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
 	if (!crng_ready() && maxwarn > 0) {
 		maxwarn--;
 		if (__ratelimit(&urandom_warning))
-			printk(KERN_NOTICE "random: %s: uninitialized "
-			       "urandom read (%zd bytes read)\n",
-			       current->comm, nbytes);
+			pr_notice("%s: uninitialized urandom read (%zd bytes read)\n",
+				  current->comm, nbytes);
 		spin_lock_irqsave(&primary_crng.lock, flags);
 		crng_init_cnt = 0;
 		spin_unlock_irqrestore(&primary_crng.lock, flags);
-- 
2.17.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/5] random: fix typo in add_timer_randomness()
  2019-06-07 18:25 [PATCH 1/5] random: remove unnecessary unlikely() Yangtao Li
  2019-06-07 18:25 ` [PATCH 2/5] random: convert to ENTROPY_BITS Yangtao Li
  2019-06-07 18:25 ` [PATCH 3/5] random: Add and use pr_fmt() Yangtao Li
@ 2019-06-07 18:25 ` Yangtao Li
  2019-06-07 18:25 ` [PATCH 5/5] random: remove some dead code of poolinfo Yangtao Li
  2019-07-11 14:49 ` [PATCH 1/5] random: remove unnecessary unlikely() Frank Lee
  4 siblings, 0 replies; 9+ messages in thread
From: Yangtao Li @ 2019-06-07 18:25 UTC (permalink / raw)
  To: tytso, arnd, gregkh; +Cc: linux-kernel, Yangtao Li

s/entimate/estimate

Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
---
 drivers/char/random.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index f0c834af14a8..885707ac8e3b 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1247,7 +1247,7 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
 	/*
 	 * delta is now minimum absolute delta.
 	 * Round down by 1 bit on general principles,
-	 * and limit entropy entimate to 12 bits.
+	 * and limit entropy estimate to 12 bits.
 	 */
 	credit_entropy_bits(r, min_t(int, fls(delta>>1), 11));
 }
-- 
2.17.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/5] random: remove some dead code of poolinfo
  2019-06-07 18:25 [PATCH 1/5] random: remove unnecessary unlikely() Yangtao Li
                   ` (2 preceding siblings ...)
  2019-06-07 18:25 ` [PATCH 4/5] random: fix typo in add_timer_randomness() Yangtao Li
@ 2019-06-07 18:25 ` Yangtao Li
  2019-07-11 14:49 ` [PATCH 1/5] random: remove unnecessary unlikely() Frank Lee
  4 siblings, 0 replies; 9+ messages in thread
From: Yangtao Li @ 2019-06-07 18:25 UTC (permalink / raw)
  To: tytso, arnd, gregkh; +Cc: linux-kernel, Yangtao Li

Since it is not being used, so delete it.

Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
---
 drivers/char/random.c | 27 ---------------------------
 1 file changed, 27 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 885707ac8e3b..d83401e35f71 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -441,33 +441,6 @@ static const struct poolinfo {
 	/* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
 	/* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
 	{ S(32),	26,	19,	14,	7,	1 },
-#if 0
-	/* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1  -- 115 */
-	{ S(2048),	1638,	1231,	819,	411,	1 },
-
-	/* x^1024 + x^817 + x^615 + x^412 + x^204 + x + 1 -- 290 */
-	{ S(1024),	817,	615,	412,	204,	1 },
-
-	/* x^1024 + x^819 + x^616 + x^410 + x^207 + x^2 + 1 -- 115 */
-	{ S(1024),	819,	616,	410,	207,	2 },
-
-	/* x^512 + x^411 + x^308 + x^208 + x^104 + x + 1 -- 225 */
-	{ S(512),	411,	308,	208,	104,	1 },
-
-	/* x^512 + x^409 + x^307 + x^206 + x^102 + x^2 + 1 -- 95 */
-	{ S(512),	409,	307,	206,	102,	2 },
-	/* x^512 + x^409 + x^309 + x^205 + x^103 + x^2 + 1 -- 95 */
-	{ S(512),	409,	309,	205,	103,	2 },
-
-	/* x^256 + x^205 + x^155 + x^101 + x^52 + x + 1 -- 125 */
-	{ S(256),	205,	155,	101,	52,	1 },
-
-	/* x^128 + x^103 + x^78 + x^51 + x^27 + x^2 + 1 -- 70 */
-	{ S(128),	103,	78,	51,	27,	2 },
-
-	/* x^64 + x^52 + x^39 + x^26 + x^14 + x + 1 -- 15 */
-	{ S(64),	52,	39,	26,	14,	1 },
-#endif
 };
 
 /*
-- 
2.17.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/5] random: Add and use pr_fmt()
  2019-06-07 18:25 ` [PATCH 3/5] random: Add and use pr_fmt() Yangtao Li
@ 2019-06-10 19:12   ` Joe Perches
  0 siblings, 0 replies; 9+ messages in thread
From: Joe Perches @ 2019-06-10 19:12 UTC (permalink / raw)
  To: Yangtao Li, tytso, arnd, gregkh; +Cc: linux-kernel

On Fri, 2019-06-07 at 14:25 -0400, Yangtao Li wrote:
> Prefix all printk/pr_<level> messages with "random: " to make the
> logging a bit more consistent.
> 
> Miscellanea:
> 
> o Convert a printks to pr_notice
> o Whitespace to align to open parentheses
> o Remove embedded "random: " from pr_* as pr_fmt adds it
[]
> diff --git a/drivers/char/random.c b/drivers/char/random.c
[]
> @@ -1031,15 +1033,15 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r)
>  		crng_init = 2;
>  		process_random_ready_list();
>  		wake_up_interruptible(&crng_init_wait);
> -		pr_notice("random: crng init done\n");
> +		pr_notice("crng init done\n");
>  		if (unseeded_warning.missed) {
> -			pr_notice("random: %d get_random_xx warning(s) missed "
> +			pr_notice("%d get_random_xx warning(s) missed "
>  				  "due to ratelimiting\n",

Trivia:

It'd be nice to coalesce the format string fragments
into a single line at the same time too.

			pr_notice("%d get_random_xx warning(s) missed due to ratelimiting\n",
 				  unseeded_warning.missed);

>  			unseeded_warning.missed = 0;
>  		}
>  		if (urandom_warning.missed) {
> -			pr_notice("random: %d urandom warning(s) missed "
> +			pr_notice("%d urandom warning(s) missed "
>  				  "due to ratelimiting\n",

etc...




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/5] random: remove unnecessary unlikely()
  2019-06-07 18:25 [PATCH 1/5] random: remove unnecessary unlikely() Yangtao Li
                   ` (3 preceding siblings ...)
  2019-06-07 18:25 ` [PATCH 5/5] random: remove some dead code of poolinfo Yangtao Li
@ 2019-07-11 14:49 ` Frank Lee
  2019-10-29  7:14   ` Joe Perches
  4 siblings, 1 reply; 9+ messages in thread
From: Frank Lee @ 2019-07-11 14:49 UTC (permalink / raw)
  To: tytso, Arnd Bergmann, Greg Kroah-Hartman; +Cc: Linux Kernel Mailing List

ping...

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/5] random: remove unnecessary unlikely()
  2019-07-11 14:49 ` [PATCH 1/5] random: remove unnecessary unlikely() Frank Lee
@ 2019-10-29  7:14   ` Joe Perches
  2019-11-09  0:54     ` Joe Perches
  0 siblings, 1 reply; 9+ messages in thread
From: Joe Perches @ 2019-10-29  7:14 UTC (permalink / raw)
  To: Frank Lee, tytso, Arnd Bergmann, Greg Kroah-Hartman
  Cc: Linux Kernel Mailing List

On Thu, 2019-07-11 at 22:49 +0800, Frank Lee wrote:
> ping...

Ted?

Is there some reason this patch series was not applied?

https://lore.kernel.org/lkml/20190607182517.28266-1-tiny.windzz@gmail.com/
https://lore.kernel.org/lkml/20190607182517.28266-2-tiny.windzz@gmail.com/
https://lore.kernel.org/lkml/20190607182517.28266-3-tiny.windzz@gmail.com/
https://lore.kernel.org/lkml/20190607182517.28266-4-tiny.windzz@gmail.com/
https://lore.kernel.org/lkml/20190607182517.28266-5-tiny.windzz@gmail.com/


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/5] random: remove unnecessary unlikely()
  2019-10-29  7:14   ` Joe Perches
@ 2019-11-09  0:54     ` Joe Perches
  0 siblings, 0 replies; 9+ messages in thread
From: Joe Perches @ 2019-11-09  0:54 UTC (permalink / raw)
  To: Frank Lee, tytso, Arnd Bergmann, Greg Kroah-Hartman
  Cc: Linux Kernel Mailing List

On Tue, 2019-10-29 at 00:14 -0700, Joe Perches wrote:
> On Thu, 2019-07-11 at 22:49 +0800, Frank Lee wrote:
> > ping...
> 
> Ted?
> 
> Is there some reason this patch series was not applied?
> 
> https://lore.kernel.org/lkml/20190607182517.28266-1-tiny.windzz@gmail.com/
> https://lore.kernel.org/lkml/20190607182517.28266-2-tiny.windzz@gmail.com/
> https://lore.kernel.org/lkml/20190607182517.28266-3-tiny.windzz@gmail.com/
> https://lore.kernel.org/lkml/20190607182517.28266-4-tiny.windzz@gmail.com/
> https://lore.kernel.org/lkml/20190607182517.28266-5-tiny.windzz@gmail.com/

Ted?

Do you object to this series going into the tree at all?
If not, do you want someone else to pick it up?



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-07 18:25 [PATCH 1/5] random: remove unnecessary unlikely() Yangtao Li
2019-06-07 18:25 ` [PATCH 2/5] random: convert to ENTROPY_BITS Yangtao Li
2019-06-07 18:25 ` [PATCH 3/5] random: Add and use pr_fmt() Yangtao Li
2019-06-10 19:12   ` Joe Perches
2019-06-07 18:25 ` [PATCH 4/5] random: fix typo in add_timer_randomness() Yangtao Li
2019-06-07 18:25 ` [PATCH 5/5] random: remove some dead code of poolinfo Yangtao Li
2019-07-11 14:49 ` [PATCH 1/5] random: remove unnecessary unlikely() Frank Lee
2019-10-29  7:14   ` Joe Perches
2019-11-09  0:54     ` Joe Perches

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git