From patchwork Mon Feb 13 18:10:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 64926 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 755763875DF7 for ; Mon, 13 Feb 2023 18:10:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 755763875DF7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676311828; bh=WEGfgtaFj67ivjMy//jjoY1QFUePLQF9nBHkRrlL0Cw=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=gshq+WmgUOckYU5FEMkPXlIIDnCgzoNk6xIGBvjnTHYuG/XmQ0NvaiiuMhEc53GnM KSlaG7u0iuJnzmq6cMtjRGAYugo3XdluqwaimF09TIE/+ezEEUWVxjpoEESdoL/hzd fAa3ruS69gr4KLPzNLF0NjwvZk0emWU9hnKdpbHk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 48C16385B50C for ; Mon, 13 Feb 2023 18:10:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 48C16385B50C Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 420B421DDB; Mon, 13 Feb 2023 18:10:02 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 285681391B; Mon, 13 Feb 2023 18:10:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gQ+/CPp86mNhdAAAMHmgww (envelope-from ); Mon, 13 Feb 2023 18:10:02 +0000 To: gdb-patches@sourceware.org Cc: "Markus T . Metzger" Subject: [PATCH] [gdb/testsuite] Add have_linux_btrace_bug Date: Mon, 13 Feb 2023 19:10:01 +0100 Message-Id: <20230213181001.25142-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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(+) base-commit: 14d0e6818a022b72c265f15f63c8ccc2fc8c302a 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