public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [gdb/testsuite] Fix gdb.arch/i386-pkru.exp on linux
@ 2021-11-29 10:52 Tom de Vries
  2021-11-30 21:56 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2021-11-29 10:52 UTC (permalink / raw)
  To: gdb-patches

When running test-case gdb.arch/i386-pkru.exp on a machine with "Memory
Protection Keys for Userspace" support, we run into:
...
(gdb) PASS: gdb.arch/i386-pkru.exp: probe PKRU support
print $pkru^M
$2 = 1431655764^M
(gdb) FAIL: gdb.arch/i386-pkru.exp: pkru register
...

The test-case expects the $pkru register to have the default value 0, matching
the "init state" of 0 defined by the XSAVE hardware.

Since linux kernel version v4.9 containing commit acd547b29880 ("x86/pkeys:
Default to a restrictive init PKRU"), the register is set to 0x55555554 by
default (which matches the printed decimal value above).

Fix the FAIL by accepting this value for linux.

Tested on x86_64-linux.
---
 gdb/testsuite/gdb.arch/i386-pkru.exp | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/gdb.arch/i386-pkru.exp b/gdb/testsuite/gdb.arch/i386-pkru.exp
index f15e8ce89b0..670ada33be5 100644
--- a/gdb/testsuite/gdb.arch/i386-pkru.exp
+++ b/gdb/testsuite/gdb.arch/i386-pkru.exp
@@ -20,6 +20,15 @@ if { ![istarget i?86-*-*] && ![istarget x86_64-*-* ] } {
     return
 }
 
+set default_pkru_re 0x0
+if { [istarget *-*-linux*] } {
+    # Starting with v4.9, the linux kernel contains commit acd547b29880
+    # ("x86/pkeys: Default to a restrictive init PKRU"), which sets the
+    # pkru register to 0x55555554 by default.
+    set default_pkru_re (0x0|0x55555554)
+}
+
+
 set comp_flags "-I${srcdir}/../nat/"
 
 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
@@ -50,9 +59,7 @@ if { !$supports_pkru } {
 }
 
 # Test pkru register at startup
-# set test_string "0"
-
-gdb_test "print \$pkru" "= 0" "pkru register"
+gdb_test "print /x \$pkru" "= $default_pkru_re" "pkru register"
 
 # Read values from pseudo registers.
 gdb_breakpoint [ gdb_get_line_number "break here 1" ]

base-commit: c2611492786971de47464246b8271d6a6ab9421a
-- 
2.31.1


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

* Re: [PATCH] [gdb/testsuite] Fix gdb.arch/i386-pkru.exp on linux
  2021-11-29 10:52 [PATCH] [gdb/testsuite] Fix gdb.arch/i386-pkru.exp on linux Tom de Vries
@ 2021-11-30 21:56 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2021-11-30 21:56 UTC (permalink / raw)
  To: Tom de Vries via Gdb-patches

>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> Since linux kernel version v4.9 containing commit acd547b29880 ("x86/pkeys:
Tom> Default to a restrictive init PKRU"), the register is set to 0x55555554 by
Tom> default (which matches the printed decimal value above).

Tom> Fix the FAIL by accepting this value for linux.

This looks reasonable to me.

Tom

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

end of thread, other threads:[~2021-11-30 21:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-29 10:52 [PATCH] [gdb/testsuite] Fix gdb.arch/i386-pkru.exp on linux Tom de Vries
2021-11-30 21:56 ` Tom Tromey

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).