Skip to content

Commit 17248ea

Browse files
svens-s390Vasily Gorbik
authored andcommitted
s390: fix __EMIT_BUG() macro
Setting a kprobe on getname_flags() failed: $ echo 'p:tmr1 getname_flags +0(%r2):ustring' > kprobe_events -bash: echo: write error: Invalid argument Debugging the kprobes code showed that the address of getname_flags() is contained in the __bug_table. Kprobes doesn't allow to set probes at BUG() locations. $ objdump -j __bug_table -x build/fs/namei.o [..] 0000000000000108 R_390_PC32 .text+0x00000000000075a8 000000000000010c R_390_PC32 .L223+0x0000000000000004 I was expecting getname_flags() to start with a BUG(), but: 7598: e3 20 10 00 00 04 lg %r2,0(%r1) 759e: c0 f4 00 00 00 00 jg 759e <putname+0x7e> 75a0: R_390_PLT32DBL kmem_cache_free+0x2 75a4: a7 f4 00 01 j 75a6 <putname+0x86> 00000000000075a8 <getname_flags>: 75a8: c0 04 00 00 00 00 brcl 0,75a8 <getname_flags> 75ae: eb 6f f0 48 00 24 stmg %r6,%r15,72(%r15) 75b4: b9 04 00 ef lgr %r14,%r15 75b8: e3 f0 ff a8 ff 71 lay %r15,-88(%r15) So the BUG() is actually the last opcode of the previous function. Fix this by switching to using the MONITOR CALL (MC) instruction, and set the entry in __bug_table to the beginning of that MC. Reviewed-by: Heiko Carstens <[email protected]> Signed-off-by: Sven Schnelle <[email protected]> Signed-off-by: Vasily Gorbik <[email protected]>
1 parent 45f7a0d commit 17248ea

File tree

5 files changed

+46
-16
lines changed

5 files changed

+46
-16
lines changed

arch/s390/boot/head.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ ENTRY(startup_kdump)
329329
.quad .Lduct # cr5: primary-aste origin
330330
.quad 0 # cr6: I/O interrupts
331331
.quad 0 # cr7: secondary space segment table
332-
.quad 0 # cr8: access registers translation
332+
.quad 0x0000000000008000 # cr8: access registers translation
333333
.quad 0 # cr9: tracing off
334334
.quad 0 # cr10: tracing off
335335
.quad 0 # cr11: tracing off

arch/s390/include/asm/bug.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010

1111
#define __EMIT_BUG(x) do { \
1212
asm_inline volatile( \
13-
"0: j 0b+2\n" \
14-
"1:\n" \
13+
"0: mc 0,0\n" \
1514
".section .rodata.str,\"aMS\",@progbits,1\n" \
16-
"2: .asciz \""__FILE__"\"\n" \
15+
"1: .asciz \""__FILE__"\"\n" \
1716
".previous\n" \
1817
".section __bug_table,\"awM\",@progbits,%2\n" \
19-
"3: .long 1b-3b,2b-3b\n" \
18+
"2: .long 0b-2b,1b-2b\n" \
2019
" .short %0,%1\n" \
21-
" .org 3b+%2\n" \
20+
" .org 2b+%2\n" \
2221
".previous\n" \
2322
: : "i" (__LINE__), \
2423
"i" (x), \
@@ -29,12 +28,11 @@
2928

3029
#define __EMIT_BUG(x) do { \
3130
asm_inline volatile( \
32-
"0: j 0b+2\n" \
33-
"1:\n" \
31+
"0: mc 0,0\n" \
3432
".section __bug_table,\"awM\",@progbits,%1\n" \
35-
"2: .long 1b-2b\n" \
33+
"1: .long 0b-1b\n" \
3634
" .short %0\n" \
37-
" .org 2b+%1\n" \
35+
" .org 1b+%1\n" \
3836
".previous\n" \
3937
: : "i" (x), \
4038
"i" (sizeof(struct bug_entry))); \

arch/s390/kernel/entry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void specification_exception(struct pt_regs *regs);
4545
void transaction_exception(struct pt_regs *regs);
4646
void translation_exception(struct pt_regs *regs);
4747
void vector_exception(struct pt_regs *regs);
48+
void monitor_event_exception(struct pt_regs *regs);
4849

4950
void do_per_trap(struct pt_regs *regs);
5051
void do_report_trap(struct pt_regs *regs, int si_signo, int si_code, char *str);

arch/s390/kernel/pgm_check.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ PGM_CHECK_DEFAULT /* 3c */
8181
PGM_CHECK_DEFAULT /* 3d */
8282
PGM_CHECK_DEFAULT /* 3e */
8383
PGM_CHECK_DEFAULT /* 3f */
84-
PGM_CHECK_DEFAULT /* 40 */
84+
PGM_CHECK(monitor_event_exception) /* 40 */
8585
PGM_CHECK_DEFAULT /* 41 */
8686
PGM_CHECK_DEFAULT /* 42 */
8787
PGM_CHECK_DEFAULT /* 43 */

arch/s390/kernel/traps.c

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ void do_report_trap(struct pt_regs *regs, int si_signo, int si_code, char *str)
5353
if (fixup)
5454
regs->psw.addr = extable_fixup(fixup);
5555
else {
56-
enum bug_trap_type btt;
57-
58-
btt = report_bug(regs->psw.addr, regs);
59-
if (btt == BUG_TRAP_TYPE_WARN)
60-
return;
6156
die(regs, str);
6257
}
6358
}
@@ -245,6 +240,27 @@ void space_switch_exception(struct pt_regs *regs)
245240
do_trap(regs, SIGILL, ILL_PRVOPC, "space switch event");
246241
}
247242

243+
void monitor_event_exception(struct pt_regs *regs)
244+
{
245+
const struct exception_table_entry *fixup;
246+
247+
if (user_mode(regs))
248+
return;
249+
250+
switch (report_bug(regs->psw.addr - (regs->int_code >> 16), regs)) {
251+
case BUG_TRAP_TYPE_NONE:
252+
fixup = s390_search_extables(regs->psw.addr);
253+
if (fixup)
254+
regs->psw.addr = extable_fixup(fixup);
255+
break;
256+
case BUG_TRAP_TYPE_WARN:
257+
break;
258+
case BUG_TRAP_TYPE_BUG:
259+
die(regs, "monitor event");
260+
break;
261+
}
262+
}
263+
248264
void kernel_stack_overflow(struct pt_regs *regs)
249265
{
250266
bust_spinlocks(1);
@@ -255,8 +271,23 @@ void kernel_stack_overflow(struct pt_regs *regs)
255271
}
256272
NOKPROBE_SYMBOL(kernel_stack_overflow);
257273

274+
static void test_monitor_call(void)
275+
{
276+
int val = 1;
277+
278+
asm volatile(
279+
" mc 0,0\n"
280+
"0: xgr %0,%0\n"
281+
"1:\n"
282+
EX_TABLE(0b,1b)
283+
: "+d" (val));
284+
if (!val)
285+
panic("Monitor call doesn't work!\n");
286+
}
287+
258288
void __init trap_init(void)
259289
{
260290
sort_extable(__start_dma_ex_table, __stop_dma_ex_table);
261291
local_mcck_enable();
292+
test_monitor_call();
262293
}

0 commit comments

Comments
 (0)