public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: "Markus T . Metzger" <markus.t.metzger@intel.com>
Subject: [PATCH] [gdb/testsuite] Add have_linux_btrace_bug
Date: Mon, 13 Feb 2023 19:10:01 +0100	[thread overview]
Message-ID: <20230213181001.25142-1-tdevries@suse.de> (raw)

The linux kernel commit 670638477aed ("perf/x86/intel/pt: Opportunistically
use single range output mode"), added in version v5.5.0 had a bug that was
fixed by commit ce0d998be927 ("perf/x86/intel/pt: Fix sampling using
single range output") in version 6.1.0.

The bug manifested for intel microarchitectures Rocket Lake, Raptor Lake and
Alder Lake.

Detect this set of conditions in a new proc have_linux_btrace_bug, and use it
in allow_btrace_tests.

I was initially planning to do just a require !have_linux_btrace_bug in the
failing test-cases, and that looked ok for PR30065 (with libipt) with just one
test-case failing, but there are a lot of fails for PR30073 (without libipt).

Tested on x86_64-linux.

PR testsuite/30073
PR testsuite/30075
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30073
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30075
---
 gdb/testsuite/lib/gdb.exp | 103 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 7f98f080328..a76397f50b8 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3851,6 +3851,10 @@ gdb_caching_proc allow_btrace_tests {
     gdb_exit
     remote_file build delete $obj
 
+    if { $allow_btrace_tests } {
+	set allow_btrace_tests [expr ![have_linux_btrace_bug]]
+    }
+
     verbose "$me:  returning $allow_btrace_tests" 2
     return $allow_btrace_tests
 }
@@ -9374,5 +9378,104 @@ proc has_dependency { file dep } {
     return [regexp $dep $output]
 }
 
+# Return 1 if the linux kernel btrace bug introduced in kernel commit
+# 670638477aed ("perf/x86/intel/pt: Opportunistically use single range output
+# mode"), may manifest.
+
+gdb_caching_proc have_linux_btrace_bug {
+    set me "have_linux_btrace_bug"
+
+    if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
+	return 0
+    }
+
+    if { ![istarget *-*-linux*] } {
+	return 0
+    }
+
+    set res [remote_exec target "uname -r"]
+    set status [lindex $res 0]
+    set output [lindex $res 1]
+    if { $status != 0 } {
+	return 0
+    }
+
+    set re ^($::decimal)\\.($::decimal)\\.($::decimal)
+    if { [regexp $re $output dummy v1 v2 v3] != 1 } {
+	return 0
+    }
+    set v [list $v1 $v2 $v3]
+
+    set affected_version \
+	[expr [version_compare [list 5 5 0] <= $v] \
+	     && [version_compare $v < [list 6 1 0]]]
+    if { ! $affected_version } {
+	return 0
+    }
+
+    # Compile a test program.
+    set src {
+	#include "nat/x86-gcc-cpuid.h"
+
+	int main() {
+	  unsigned int eax, ebx, ecx, edx;
+
+	  if (!__get_cpuid (0, &eax, &ebx, &ecx, &edx))
+	    return 0;
+
+	  int intel_p = (ebx == signature_INTEL_ebx
+			 && ecx == signature_INTEL_ecx
+			 && edx == signature_INTEL_edx);
+
+	  if (!intel_p)
+	    return 0;
+
+	  if (! __get_cpuid (1, &eax, &ebx, &ecx, &edx))
+	    return 0;
+
+	  unsigned int ex_fam_id = (eax >> 20) & 0xff;
+	  unsigned int ex_mod_id = (eax >> 16) & 0xf;
+	  unsigned int fam_id = (eax >> 8) & 0xf;
+	  unsigned int model = (eax >> 4) & 0xf;
+
+	  if (fam_id == 6 || fam_id == 15)
+	    model = model + (ex_mod_id << 4);
+	  if (fam_id == 15)
+	    fam_id = fam_id + ex_fam_id;
+
+	  if (fam_id == 6)
+	    {
+	      /* Rocket Lake.  */
+	      if (model == 167)
+		return 1;
+	      /* Alder Lake.  */
+	      if (model == 151 || model == 154)
+		return 1;
+	      /* Raptor Lake.  */
+	      if (model == 183)
+		return 1;
+	  }
+
+	  return 0;
+	}
+    }
+
+    set flags "incdir=$::srcdir/.."
+    if { ! [gdb_simple_compile $me $src executable $flags] } {
+	return 0
+    }
+
+    set result [remote_exec target $obj]
+    set status [lindex $result 0]
+    set output [lindex $result 1]
+    if { $output != "" } {
+	set status 0
+    }
+
+    remote_file build delete $obj
+
+    return $status
+}
+
 # Always load compatibility stuff.
 load_lib future.exp

base-commit: 14d0e6818a022b72c265f15f63c8ccc2fc8c302a
-- 
2.35.3


             reply	other threads:[~2023-02-13 18:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-13 18:10 Tom de Vries [this message]
2023-02-13 19:17 ` Metzger, Markus T
2023-02-14 10:59   ` [PATCH] [gdb/testsuite] Add xfail in gdb.python/py-record-btrace.exp Tom de Vries
2023-02-14 11:34     ` Metzger, Markus T

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=20230213181001.25142-1-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=markus.t.metzger@intel.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).