From patchwork Thu Feb 23 19:29:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 19361 Received: (qmail 57722 invoked by alias); 23 Feb 2017 19:29:18 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 57253 invoked by uid 89); 23 Feb 2017 19:29:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=Hx-languages-length:2759, seeds X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Feb 2017 19:29:16 +0000 Received: from svr-orw-fem-06.mgc.mentorg.com ([147.34.97.120]) by relay1.mentorg.com with esmtp id 1cgz4k-00022w-MB from Luis_Gustavo@mentor.com ; Thu, 23 Feb 2017 11:29:14 -0800 Received: from Opsys.world.mentorg.com (147.34.91.1) by SVR-ORW-FEM-06.mgc.mentorg.com (147.34.97.120) with Microsoft SMTP Server id 14.3.224.2; Thu, 23 Feb 2017 11:29:14 -0800 From: Luis Machado To: , , Subject: [PATCH] PR21166: Validate rdrand/rdseed support separately in gdb.reverse/insn-reverse-x86.c Date: Thu, 23 Feb 2017 13:29:01 -0600 Message-ID: <1487878141-21578-1-git-send-email-lgustavo@codesourcery.com> MIME-Version: 1.0 X-IsSubscribed: yes 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 * 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 #include -/* 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. */