All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] x86/random: Retry on RDSEED failure
@ 2024-01-30  8:30 Kirill A. Shutemov
  2024-01-30  8:30 ` [PATCH 2/2] x86/random: Issue a warning if RDRAND or RDSEED fails Kirill A. Shutemov
                   ` (2 more replies)
  0 siblings, 3 replies; 99+ messages in thread
From: Kirill A. Shutemov @ 2024-01-30  8:30 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin, x86, Theodore Ts'o, Jason A. Donenfeld
  Cc: Kuppuswamy Sathyanarayanan, Elena Reshetova, Jun Nakajima,
	Tom Lendacky, Kalra, Ashish, Sean Christopherson, linux-coco,
	linux-kernel, Kirill A. Shutemov

The function rdrand_long() retries 10 times before returning failure to
the caller. On the other hand, rdseed_long() gives up on the first
failure.

According to the Intel SDM, both instructions should follow the same
retry approach. This information can be found in the section titled
"Random Number Generator Instructions".

To align the behavior of rdseed_long() with rdrand_long(), it should be
modified to retry 10 times before giving up.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
 arch/x86/include/asm/archrandom.h | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/archrandom.h b/arch/x86/include/asm/archrandom.h
index 02bae8e0758b..918c5880de9e 100644
--- a/arch/x86/include/asm/archrandom.h
+++ b/arch/x86/include/asm/archrandom.h
@@ -33,11 +33,19 @@ static inline bool __must_check rdrand_long(unsigned long *v)
 
 static inline bool __must_check rdseed_long(unsigned long *v)
 {
+	unsigned int retry = RDRAND_RETRY_LOOPS;
 	bool ok;
-	asm volatile("rdseed %[out]"
-		     CC_SET(c)
-		     : CC_OUT(c) (ok), [out] "=r" (*v));
-	return ok;
+
+	do {
+		asm volatile("rdseed %[out]"
+			     CC_SET(c)
+			     : CC_OUT(c) (ok), [out] "=r" (*v));
+
+		if (ok)
+			return true;
+	} while (--retry);
+
+	return false;
 }
 
 /*
-- 
2.43.0


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

end of thread, other threads:[~2024-02-15 13:01 UTC | newest]

Thread overview: 99+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-30  8:30 [PATCH 1/2] x86/random: Retry on RDSEED failure Kirill A. Shutemov
2024-01-30  8:30 ` [PATCH 2/2] x86/random: Issue a warning if RDRAND or RDSEED fails Kirill A. Shutemov
2024-01-30 12:37   ` Jason A. Donenfeld
2024-01-30 13:45     ` Reshetova, Elena
2024-01-30 14:21       ` Jason A. Donenfeld
2024-01-30 14:55         ` Reshetova, Elena
2024-01-30 15:00           ` Jason A. Donenfeld
2024-01-30 17:31       ` Dave Hansen
2024-01-30 17:49         ` Jason A. Donenfeld
2024-01-30 17:58           ` Dave Hansen
2024-01-30 18:15             ` H. Peter Anvin
2024-01-30 18:23               ` Jason A. Donenfeld
2024-01-30 18:23             ` Jason A. Donenfeld
2024-01-30 18:37               ` Dave Hansen
2024-01-30 18:05           ` Daniel P. Berrangé
2024-01-30 18:24             ` Jason A. Donenfeld
2024-01-30 18:31             ` Jason A. Donenfeld
2024-01-30 18:40             ` H. Peter Anvin
2024-01-31  8:16             ` Reshetova, Elena
2024-01-31 11:59               ` Dr. Greg
2024-01-31 13:06               ` Jason A. Donenfeld
2024-01-31 18:02                 ` Reshetova, Elena
2024-01-31 20:35                 ` Dr. Greg
2024-02-01  4:47                   ` Theodore Ts'o
2024-02-01  9:54                     ` Dr. Greg
2024-02-01 11:08                       ` Daniel P. Berrangé
2024-02-01 21:04                         ` Dr. Greg
2024-02-02  7:56                           ` Reshetova, Elena
2024-02-01  7:26                   ` Reshetova, Elena
2024-02-01 10:52                     ` Dr. Greg
2024-02-06  1:12               ` Dr. Greg
2024-02-06  8:04                 ` Daniel P. Berrangé
2024-02-06 12:04                   ` Dr. Greg
2024-02-06 13:00                     ` Daniel P. Berrangé
2024-02-08 10:31                       ` Dr. Greg
2024-02-06 13:50                     ` Daniel P. Berrangé
2024-02-06 15:35                     ` Borislav Petkov
2024-02-08 11:44                       ` Dr. Greg
2024-02-09 17:31                         ` Borislav Petkov
2024-02-09 19:49                           ` Jason A. Donenfeld
2024-02-09 20:37                             ` Dave Hansen
2024-02-09 21:45                             ` Borislav Petkov
2024-02-06 18:49                     ` H. Peter Anvin
2024-02-08 16:38                       ` Dr. Greg
2024-01-30 15:50   ` Kuppuswamy Sathyanarayanan
2024-01-30 12:29 ` [PATCH 1/2] x86/random: Retry on RDSEED failure Jason A. Donenfeld
2024-01-30 12:51   ` Jason A. Donenfeld
2024-01-30 13:10   ` Reshetova, Elena
2024-01-30 14:06     ` Jason A. Donenfeld
2024-01-30 14:43       ` Daniel P. Berrangé
2024-01-30 15:12         ` Jason A. Donenfeld
2024-01-30 18:35       ` Jason A. Donenfeld
2024-01-30 19:06         ` Reshetova, Elena
2024-01-30 19:16           ` Jason A. Donenfeld
2024-01-31  7:56             ` Reshetova, Elena
2024-01-31 13:14               ` Jason A. Donenfeld
2024-01-31 14:07                 ` Theodore Ts'o
2024-01-31 14:45                   ` Jason A. Donenfeld
2024-01-31 14:52                     ` Jason A. Donenfeld
2024-01-31 17:10                     ` Theodore Ts'o
2024-01-31 17:37                       ` Reshetova, Elena
2024-01-31 18:01                         ` Jason A. Donenfeld
2024-02-01  4:57                           ` Theodore Ts'o
2024-02-01 18:09                             ` Jason A. Donenfeld
2024-02-01 18:46                               ` Dave Hansen
2024-02-01 19:02                                 ` H. Peter Anvin
2024-02-02  7:25                               ` Reshetova, Elena
2024-02-02 15:39                                 ` Theodore Ts'o
2024-02-03 10:12                                   ` Jason A. Donenfeld
2024-02-09 19:53                                     ` Jason A. Donenfeld
2024-02-12  8:25                                       ` Reshetova, Elena
2024-02-12 16:32                                         ` Theodore Ts'o
2024-02-13  7:28                                           ` Dan Williams
2024-02-13 23:13                                             ` Theodore Ts'o
2024-02-14  0:53                                               ` Dan Williams
2024-02-14  4:32                                                 ` Theodore Ts'o
2024-02-14  6:48                                                   ` Dan Williams
2024-02-14  6:54                                                   ` Reshetova, Elena
2024-02-14  8:34                                                   ` Nikolay Borisov
2024-02-14  9:34                                                     ` Dr. Greg
2024-02-14 17:30                                         ` Jason A. Donenfeld
2024-02-14 15:18                                 ` Reshetova, Elena
2024-02-14 17:21                                   ` Jason A. Donenfeld
2024-02-14 17:59                                     ` Reshetova, Elena
2024-02-14 19:32                                       ` Jason A. Donenfeld
2024-02-15  7:07                                         ` Reshetova, Elena
2024-02-15 12:58                                           ` Jason A. Donenfeld
2024-02-14 19:46                                     ` Tom Lendacky
2024-02-14 20:04                                       ` Jason A. Donenfeld
2024-02-14 20:11                                         ` Theodore Ts'o
2024-02-15 13:01                                           ` Jason A. Donenfeld
2024-02-14 20:14                                     ` Dave Hansen
2024-02-02 15:47                               ` James Bottomley
2024-02-02 16:05                                 ` Theodore Ts'o
2024-02-02 21:28                                   ` James Bottomley
2024-02-03 14:35                                     ` Theodore Ts'o
2024-02-06 19:12                                       ` H. Peter Anvin
2024-01-30 15:20     ` H. Peter Anvin
2024-01-30 15:44 ` Kuppuswamy Sathyanarayanan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.