mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: "Theodore Ts'o" <tytso@mit.edu>, LKML <linux-kernel@vger.kernel.org>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Subject: [PATCH cleanups/resubmit 2/4] random: squelch sh compiler warning and ensure safe optimization
Date: Thu,  8 Jun 2017 14:29:30 +0200	[thread overview]
Message-ID: <20170608122932.23769-3-Jason@zx2c4.com> (raw)
In-Reply-To: <20170608122932.23769-1-Jason@zx2c4.com>

Odd versions of gcc for the sh4 architecture will actually warn about
flags being used while uninitialized, so we set them to zero. Non crazy
gccs will optimize that out again, so it doesn't make a difference.

Next, over aggressive gccs could inline the expression that defines
use_lock, which could then introduce a race resulting in a lock
imbalance. By using READ_ONCE, we prevent that fate. Finally, we make
that assignment const, so that gcc can still optimize a nice amount.

This patch was previously submitted as part of v5, but v4 was picked up,
so this represents a delta between v4 and v5.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/random.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 3bdeef13afda..cef9358ecf20 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -2066,8 +2066,8 @@ static DEFINE_PER_CPU(struct batched_entropy, batched_entropy_u64);
 u64 get_random_u64(void)
 {
 	u64 ret;
-	bool use_lock = crng_init < 2;
-	unsigned long flags;
+	const bool use_lock = READ_ONCE(crng_init) < 2;
+	unsigned long flags = 0;
 	struct batched_entropy *batch;
 #ifdef CONFIG_WARN_UNSEEDED_RANDOM
 	static void *previous = NULL;
@@ -2110,8 +2110,8 @@ static DEFINE_PER_CPU(struct batched_entropy, batched_entropy_u32);
 u32 get_random_u32(void)
 {
 	u32 ret;
-	bool use_lock = crng_init < 2;
-	unsigned long flags;
+	const bool use_lock = READ_ONCE(crng_init) < 2;
+	unsigned long flags = 0;
 	struct batched_entropy *batch;
 #ifdef CONFIG_WARN_UNSEEDED_RANDOM
 	static void *previous = NULL;
-- 
2.13.0

  parent reply	other threads:[~2017-06-08 12:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-08 12:29 [PATCH cleanups/resubmit 0/4] Cleanups & Resubmissions for Random-dev Jason A. Donenfeld
2017-06-08 12:29 ` [PATCH cleanups/resubmit 1/4] security/keys: ensure RNG is seeded before use Jason A. Donenfeld
2017-06-08 12:29 ` Jason A. Donenfeld [this message]
2017-06-08 12:29 ` [PATCH cleanups/resubmit 3/4] bluetooth/smp: ensure RNG is properly seeded before ECDH use Jason A. Donenfeld
2017-06-08 12:29 ` [PATCH cleanups/resubmit 4/4] crypto/rng: ensure that the RNG is ready before using Jason A. Donenfeld
2017-06-08 21:58 ` [PATCH cleanups/resubmit 0/4] Cleanups & Resubmissions for Random-dev Theodore Ts'o
2017-06-09  0:57   ` Jason A. Donenfeld
2017-06-09 17:44     ` Jason A. Donenfeld

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=20170608122932.23769-3-Jason@zx2c4.com \
    --to=jason@zx2c4.com \
    --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

all inboxes | Powered by JetHome®