linux-coco.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: x86@kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"Elena Reshetova" <elena.reshetova@intel.com>,
	"H . Peter Anvin" <hpa@zytor.com>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
	"Theodore Ts'o" <tytso@mit.edu>,
	"Thomas Gleixner" <tglx@linutronix.de>
Subject: [PATCH v2 1/2] x86/archrandom: WARN if RDRAND fails and don't retry
Date: Wed, 14 Feb 2024 20:56:47 +0100	[thread overview]
Message-ID: <20240214195744.8332-2-Jason@zx2c4.com> (raw)
In-Reply-To: <20240214195744.8332-1-Jason@zx2c4.com>

According to both Intel [1] and AMD [2], RDRAND will never fail unless
the hardware is defective. The old advice to try 10 times is not
considered correct.

RDSEED is a different story. But with RDRAND never failing, WARN()ing
when it does seems like a reasonable thing to do, as it's probably
indicative of some deeper problem.

[1] https://lore.kernel.org/all/DM8PR11MB57503A2BB6F74618D64CC44AE74E2@DM8PR11MB5750.namprd11.prod.outlook.com/
[2] https://lore.kernel.org/all/20240209214530.GHZcac-vOym8k3IuJm@fat_crate.local/

Cc: Borislav Petkov <bp@alien8.de>
Cc: Daniel P. Berrangé <berrange@redhat.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Elena Reshetova <elena.reshetova@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 arch/x86/include/asm/archrandom.h | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/archrandom.h b/arch/x86/include/asm/archrandom.h
index 02bae8e0758b..1cc01ecd5e75 100644
--- a/arch/x86/include/asm/archrandom.h
+++ b/arch/x86/include/asm/archrandom.h
@@ -13,22 +13,18 @@
 #include <asm/processor.h>
 #include <asm/cpufeature.h>
 
-#define RDRAND_RETRY_LOOPS	10
-
 /* Unconditional execution of RDRAND and RDSEED */
 
 static inline bool __must_check rdrand_long(unsigned long *v)
 {
 	bool ok;
-	unsigned int retry = RDRAND_RETRY_LOOPS;
-	do {
-		asm volatile("rdrand %[out]"
-			     CC_SET(c)
-			     : CC_OUT(c) (ok), [out] "=r" (*v));
-		if (ok)
-			return true;
-	} while (--retry);
-	return false;
+	asm volatile("rdrand %[out]"
+		     CC_SET(c)
+		     : CC_OUT(c) (ok), [out] "=r" (*v));
+#ifndef KASLR_COMPRESSED_BOOT
+	WARN_ON(!ok);
+#endif
+	return ok;
 }
 
 static inline bool __must_check rdseed_long(unsigned long *v)
-- 
2.43.0


  reply	other threads:[~2024-02-14 19:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-14 19:56 [PATCH v2 0/2] CoCo/RDRAND brokenness fixes Jason A. Donenfeld
2024-02-14 19:56 ` Jason A. Donenfeld [this message]
2024-02-14 19:56 ` [PATCH v2 2/2] x86/coco: Require seeding RNG with RDRAND on CoCo systems Jason A. Donenfeld
2024-02-15  7:30   ` Reshetova, Elena
2024-02-15 13:22     ` Jason A. Donenfeld
2024-02-16  7:57       ` Reshetova, Elena
2024-02-16 18:17         ` Jason A. Donenfeld
2024-02-21  7:52           ` Reshetova, Elena
2024-02-21 12:24             ` 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=20240214195744.8332-2-Jason@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=berrange@redhat.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=elena.reshetova@intel.com \
    --cc=hpa@zytor.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=tytso@mit.edu \
    --cc=x86@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).