Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Luis Machado <lgustavo@codesourcery.com>
To: <gdb-patches@sourceware.org>, <palves@redhat.com>, <qiyaoltc@gmail.com>
Subject: [PATCH] PR21166: Validate rdrand/rdseed support separately in gdb.reverse/insn-reverse-x86.c
Date: Thu, 23 Feb 2017 19:29:00 -0000	[thread overview]
Message-ID: <1487878141-21578-1-git-send-email-lgustavo@codesourcery.com> (raw)

As reported in PR21166, there are Intel processors out there that support
rdrand but not rdseed. The fix is to verify both features separately and only
run rdrand/rdseed tests if supported.

Pedro, could you please confirm this fixes what you see in your Fedora box?

2017-02-23  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.reverse/insn-reverse.x86.c (check_rdrand_support): Renamed to ...
	(check_supported_features): ... this. Changed return type to void.
	(supports_rdseed): New static global.
	(rdseed): Check supports_rdseed.
	(initialize): Call check_supported_features.
---
 gdb/testsuite/gdb.reverse/insn-reverse-x86.c | 36 +++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/gdb/testsuite/gdb.reverse/insn-reverse-x86.c b/gdb/testsuite/gdb.reverse/insn-reverse-x86.c
index 7f87392..85b169d 100644
--- a/gdb/testsuite/gdb.reverse/insn-reverse-x86.c
+++ b/gdb/testsuite/gdb.reverse/insn-reverse-x86.c
@@ -18,20 +18,38 @@
 #include <cpuid.h>
 #include <stdint.h>
 
-/* 0 if the CPU supports rdrand/rdseed and non-zero otherwise.  */
+/* 0 if the CPU supports rdrand and non-zero otherwise.  */
 static unsigned int supports_rdrand;
 
-/* Returns non-zero if rdrand/rdseed instructions are supported and
-   zero otherwise.  */
+/* 0 if the CPU supports rdseed and non-zero otherwise.  */
+static unsigned int supports_rdseed;
 
-static unsigned int
-check_rdrand_support (void)
+/* Check supported features and set globals accordingly.  The globals
+   can be used to prevent unsupported tests from running.  */
+
+static void
+check_supported_features (void)
 {
   unsigned int rdrand_mask = (1 << 30);
+  unsigned int rdseed_mask = (1 << 18);
   unsigned int eax, ebx, ecx, edx;
+  unsigned int vendor;
+  unsigned int max_level;
+
+  max_level = __get_cpuid_max (0, &vendor);
+
+  if (max_level < 1)
+    return;
+
+  __cpuid (1, eax, ebx, ecx, edx);
 
-  __get_cpuid (1, &eax, &ebx, &ecx, &edx);
-  return ((ecx & rdrand_mask) == rdrand_mask);
+  supports_rdrand = ((ecx & rdrand_mask) == rdrand_mask);
+
+  if (max_level >= 7)
+    {
+      __cpuid_count (7, 0, eax, ebx, ecx, edx);
+      supports_rdseed = ((ebx & rdseed_mask) == rdseed_mask);
+    }
 }
 
 /* Test rdrand support for various output registers.  */
@@ -147,7 +165,7 @@ rdseed (void)
   /* Get a random seed from the rdseed assembly instruction.  */
   register long seed;
 
-  if (!supports_rdrand)
+  if (!supports_rdseed)
     return;
 
   /* 16-bit random seeds.  */
@@ -250,7 +268,7 @@ static void
 initialize (void)
 {
   /* Initialize supported features.  */
-  supports_rdrand = check_rdrand_support ();
+  check_supported_features ();
 }
 
 /* Functions testing instruction decodings.  GDB will test all of these.  */
-- 
2.7.4


             reply	other threads:[~2017-02-23 19:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-23 19:29 Luis Machado [this message]
2017-02-23 19:51 ` Pedro Alves
2017-02-23 20:00   ` Pedro Alves
2017-02-23 20:43     ` Luis Machado

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=1487878141-21578-1-git-send-email-lgustavo@codesourcery.com \
    --to=lgustavo@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    --cc=qiyaoltc@gmail.com \
    /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