Skip to content

Commit adb4583

Browse files
Martin SchwidefskyMartin Schwidefsky
authored andcommitted
[S390] kprobes: disable interrupts throughout
Execute the kprobe exception and fault handler with interrupts disabled. To disable the interrupts only while a single step is in progress is not good enough, a kprobe from interrupt context while another kprobe is handled can confuse the internal house keeping. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent becf91f commit adb4583

1 file changed

Lines changed: 27 additions & 14 deletions

File tree

‎arch/s390/kernel/kprobes.c‎

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <asm/sections.h>
3131
#include <linux/module.h>
3232
#include <linux/slab.h>
33+
#include <linux/hardirq.h>
3334

3435
DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
3536
DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
@@ -212,7 +213,7 @@ static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
212213
/* Set the PER control regs, turns on single step for this address */
213214
__ctl_load(kprobe_per_regs, 9, 11);
214215
regs->psw.mask |= PSW_MASK_PER;
215-
regs->psw.mask &= ~(PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK);
216+
regs->psw.mask &= ~(PSW_MASK_IO | PSW_MASK_EXT);
216217
}
217218

218219
static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
@@ -239,7 +240,7 @@ static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
239240
__get_cpu_var(current_kprobe) = p;
240241
/* Save the interrupt and per flags */
241242
kcb->kprobe_saved_imask = regs->psw.mask &
242-
(PSW_MASK_PER | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK);
243+
(PSW_MASK_PER | PSW_MASK_IO | PSW_MASK_EXT);
243244
/* Save the control regs that govern PER */
244245
__ctl_store(kcb->kprobe_saved_ctl, 9, 11);
245246
}
@@ -316,8 +317,6 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
316317
return 1;
317318

318319
ss_probe:
319-
if (regs->psw.mask & (PSW_MASK_PER | PSW_MASK_IO))
320-
local_irq_disable();
321320
prepare_singlestep(p, regs);
322321
kcb->kprobe_status = KPROBE_HIT_SS;
323322
return 1;
@@ -465,8 +464,6 @@ static int __kprobes post_kprobe_handler(struct pt_regs *regs)
465464
goto out;
466465
}
467466
reset_current_kprobe();
468-
if (regs->psw.mask & (PSW_MASK_PER | PSW_MASK_IO))
469-
local_irq_enable();
470467
out:
471468
preempt_enable_no_resched();
472469

@@ -482,7 +479,7 @@ static int __kprobes post_kprobe_handler(struct pt_regs *regs)
482479
return 1;
483480
}
484481

485-
int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
482+
static int __kprobes kprobe_trap_handler(struct pt_regs *regs, int trapnr)
486483
{
487484
struct kprobe *cur = kprobe_running();
488485
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
@@ -508,8 +505,6 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
508505
restore_previous_kprobe(kcb);
509506
else {
510507
reset_current_kprobe();
511-
if (regs->psw.mask & (PSW_MASK_PER | PSW_MASK_IO))
512-
local_irq_enable();
513508
}
514509
preempt_enable_no_resched();
515510
break;
@@ -553,15 +548,31 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
553548
return 0;
554549
}
555550

551+
int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
552+
{
553+
int ret;
554+
555+
if (regs->psw.mask & (PSW_MASK_IO | PSW_MASK_EXT))
556+
local_irq_disable();
557+
ret = kprobe_trap_handler(regs, trapnr);
558+
if (regs->psw.mask & (PSW_MASK_IO | PSW_MASK_EXT))
559+
local_irq_restore(regs->psw.mask & ~PSW_MASK_PER);
560+
return ret;
561+
}
562+
556563
/*
557564
* Wrapper routine to for handling exceptions.
558565
*/
559566
int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
560567
unsigned long val, void *data)
561568
{
562569
struct die_args *args = (struct die_args *)data;
570+
struct pt_regs *regs = args->regs;
563571
int ret = NOTIFY_DONE;
564572

573+
if (regs->psw.mask & (PSW_MASK_IO | PSW_MASK_EXT))
574+
local_irq_disable();
575+
565576
switch (val) {
566577
case DIE_BPT:
567578
if (kprobe_handler(args->regs))
@@ -572,16 +583,17 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
572583
ret = NOTIFY_STOP;
573584
break;
574585
case DIE_TRAP:
575-
/* kprobe_running() needs smp_processor_id() */
576-
preempt_disable();
577-
if (kprobe_running() &&
578-
kprobe_fault_handler(args->regs, args->trapnr))
586+
if (!preemptible() && kprobe_running() &&
587+
kprobe_trap_handler(args->regs, args->trapnr))
579588
ret = NOTIFY_STOP;
580-
preempt_enable();
581589
break;
582590
default:
583591
break;
584592
}
593+
594+
if (regs->psw.mask & (PSW_MASK_IO | PSW_MASK_EXT))
595+
local_irq_restore(regs->psw.mask & ~PSW_MASK_PER);
596+
585597
return ret;
586598
}
587599

@@ -595,6 +607,7 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
595607

596608
/* setup return addr to the jprobe handler routine */
597609
regs->psw.addr = (unsigned long)(jp->entry) | PSW_ADDR_AMODE;
610+
regs->psw.mask &= ~(PSW_MASK_IO | PSW_MASK_EXT);
598611

599612
/* r14 is the function return address */
600613
kcb->jprobe_saved_r14 = (unsigned long)regs->gprs[14];

0 commit comments

Comments
 (0)