Skip to content

Commit 477c024

Browse files
hansendcgregkh
authored andcommitted
x86/pkeys/selftests: Give better unexpected fault error messages
[ Upstream commit 55556b0 ] do_not_expect_pk_fault() is a helper that we call when we do not expect a PK fault to have occurred. But, it is a function, which means that it obscures the line numbers from pkey_assert(). It also gives no details. Replace it with an implementation that gives nice line numbers and also lets callers pass in a more descriptive message about what happened that caused the unexpected fault. Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Michael Ellermen <mpe@ellerman.id.au> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ram Pai <linuxram@us.ibm.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20180509171338.55D13B64@viggo.jf.intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4824a64 commit 477c024

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎tools/testing/selftests/x86/protection_keys.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -954,10 +954,11 @@ void expected_pk_fault(int pkey)
954954
last_si_pkey = -1;
955955
}
956956

957-
void do_not_expect_pk_fault(void)
958-
{
959-
pkey_assert(last_pkru_faults == pkru_faults);
960-
}
957+
#define do_not_expect_pk_fault(msg) do { \
958+
if (last_pkru_faults != pkru_faults) \
959+
dprintf0("unexpected PK fault: %s\n", msg); \
960+
pkey_assert(last_pkru_faults == pkru_faults); \
961+
} while (0)
961962

962963
int test_fds[10] = { -1 };
963964
int nr_test_fds;
@@ -1243,7 +1244,7 @@ void test_ptrace_of_child(int *ptr, u16 pkey)
12431244
pkey_assert(ret != -1);
12441245
/* Now access from the current task, and expect NO exception: */
12451246
peek_result = read_ptr(plain_ptr);
1246-
do_not_expect_pk_fault();
1247+
do_not_expect_pk_fault("read plain pointer after ptrace");
12471248

12481249
ret = ptrace(PTRACE_DETACH, child_pid, ignored, 0);
12491250
pkey_assert(ret != -1);
@@ -1287,7 +1288,7 @@ void test_executing_on_unreadable_memory(int *ptr, u16 pkey)
12871288
*/
12881289
madvise(p1, PAGE_SIZE, MADV_DONTNEED);
12891290
lots_o_noops_around_write(&scratch);
1290-
do_not_expect_pk_fault();
1291+
do_not_expect_pk_fault("executing on PROT_EXEC memory");
12911292
ptr_contents = read_ptr(p1);
12921293
dprintf2("ptr (%p) contents@%d: %x\n", p1, __LINE__, ptr_contents);
12931294
expected_pk_fault(pkey);

0 commit comments

Comments
 (0)