From: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>,
Masami Hiramatsu <mhiramat@kernel.org>,
Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>,
linuxppc-dev@lists.ozlabs.org
Subject: [PATCH v2 5/6] powerpc/jprobes: Disable preemption when triggered through ftrace
Date: Fri, 22 Sep 2017 14:40:47 +0530 [thread overview]
Message-ID: <481ef9b0b83116b1ca72ec6c95266c5454073387.1505934128.git.naveen.n.rao@linux.vnet.ibm.com> (raw)
In-Reply-To: <9e98f74834af349564b71bc8443bdad55d6e37c6.1505934128.git.naveen.n.rao@linux.vnet.ibm.com>
In-Reply-To: <cover.1505934128.git.naveen.n.rao@linux.vnet.ibm.com>
KPROBES_SANITY_TEST throws the below splat when CONFIG_PREEMPT is
enabled:
[ 3.140410] Kprobe smoke test: started
[ 3.149680] DEBUG_LOCKS_WARN_ON(val > preempt_count())
[ 3.149684] ------------[ cut here ]------------
[ 3.149695] WARNING: CPU: 19 PID: 1 at kernel/sched/core.c:3094 preempt_count_sub+0xcc/0x140
[ 3.149699] Modules linked in:
[ 3.149705] CPU: 19 PID: 1 Comm: swapper/0 Not tainted 4.13.0-rc7-nnr+ #97
[ 3.149709] task: c0000000fea80000 task.stack: c0000000feb00000
[ 3.149713] NIP: c00000000011d3dc LR: c00000000011d3d8 CTR: c000000000a090d0
[ 3.149718] REGS: c0000000feb03400 TRAP: 0700 Not tainted (4.13.0-rc7-nnr+)
[ 3.149722] MSR: 8000000000021033 <SF,ME,IR,DR,RI,LE> CR: 28000282 XER: 00000000
[ 3.149732] CFAR: c00000000015aa18 SOFTE: 0
<snip>
[ 3.149786] NIP [c00000000011d3dc] preempt_count_sub+0xcc/0x140
[ 3.149790] LR [c00000000011d3d8] preempt_count_sub+0xc8/0x140
[ 3.149794] Call Trace:
[ 3.149798] [c0000000feb03680] [c00000000011d3d8] preempt_count_sub+0xc8/0x140 (unreliable)
[ 3.149804] [c0000000feb036e0] [c000000000046198] kprobe_handler+0x228/0x4b0
[ 3.149810] [c0000000feb03750] [c0000000000269c8] program_check_exception+0x58/0x3b0
[ 3.149816] [c0000000feb037c0] [c00000000000903c] program_check_common+0x16c/0x170
[ 3.149822] --- interrupt: 0 at kprobe_target+0x8/0x20
LR = init_test_probes+0x248/0x7d0
[ 3.149829] [c0000000feb03ab0] [c000000000e4f048] kp+0x0/0x80 (unreliable)
[ 3.149835] [c0000000feb03b10] [c00000000004ea60] livepatch_handler+0x38/0x74
[ 3.149841] [c0000000feb03ba0] [c000000000d0de54] init_kprobes+0x1d8/0x208
[ 3.149846] [c0000000feb03c40] [c00000000000daa8] do_one_initcall+0x68/0x1d0
[ 3.149852] [c0000000feb03d00] [c000000000ce44f0] kernel_init_freeable+0x298/0x374
[ 3.149857] [c0000000feb03dc0] [c00000000000dd84] kernel_init+0x24/0x160
[ 3.149863] [c0000000feb03e30] [c00000000000bfec] ret_from_kernel_thread+0x5c/0x70
[ 3.149867] Instruction dump:
[ 3.149871] 419effdc 3d22001b 39299240 81290000 2f890000 409effc8 3c82ffcb 3c62ffcb
[ 3.149879] 3884bc68 3863bc18 4803d5fd 60000000 <0fe00000> 4bffffa8 60000000 60000000
[ 3.149890] ---[ end trace 432dd46b4ce3d29f ]---
[ 3.166003] Kprobe smoke test: passed successfully
The issue is that we aren't disabling preemption in
kprobe_ftrace_handler(). Disable it.
Fixes: ead514d5fb30a0 ("powerpc/kprobes: Add support for KPROBES_ON_FTRACE")
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
arch/powerpc/kernel/kprobes-ftrace.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/kernel/kprobes-ftrace.c b/arch/powerpc/kernel/kprobes-ftrace.c
index 1e54ec8ad85f..4b1f34f685b1 100644
--- a/arch/powerpc/kernel/kprobes-ftrace.c
+++ b/arch/powerpc/kernel/kprobes-ftrace.c
@@ -80,6 +80,7 @@ void kprobe_ftrace_handler(unsigned long nip, unsigned long parent_nip,
/* Disable irq for emulating a breakpoint and avoiding preempt */
local_irq_save(flags);
hard_irq_disable();
+ preempt_disable();
p = get_kprobe((kprobe_opcode_t *)nip);
if (unlikely(!p) || kprobe_disabled(p))
@@ -101,12 +102,18 @@ void kprobe_ftrace_handler(unsigned long nip, unsigned long parent_nip,
kcb->kprobe_status = KPROBE_HIT_ACTIVE;
if (!p->pre_handler || !p->pre_handler(p, regs))
__skip_singlestep(p, regs, kcb, orig_nip);
- /*
- * If pre_handler returns !0, it sets regs->nip and
- * resets current kprobe.
- */
+ else {
+ /*
+ * If pre_handler returns !0, it sets regs->nip and
+ * resets current kprobe. In this case, we still need
+ * to restore irq, but not preemption.
+ */
+ local_irq_restore(flags);
+ return;
+ }
}
end:
+ preempt_enable_no_resched();
local_irq_restore(flags);
}
NOKPROBE_SYMBOL(kprobe_ftrace_handler);
--
2.14.1
next prev parent reply other threads:[~2017-09-22 9:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-22 9:10 [PATCH v2 0/6] powerpc/kprobes: More fixes Naveen N. Rao
2017-09-22 9:10 ` [PATCH v2 1/6] powerpc/kprobes: Some cosmetic updates to try_to_emulate() Naveen N. Rao
2017-10-08 8:43 ` [v2, " Michael Ellerman
2017-09-22 9:10 ` [PATCH v2 2/6] powerpc/kprobes: Do not suppress instruction emulation if a single run failed Naveen N. Rao
2017-09-22 9:10 ` [PATCH v2 3/6] powerpc/kprobes: Clean up jprobe detection in livepatch handler Naveen N. Rao
2017-09-22 9:10 ` [PATCH v2 4/6] powerpc/kprobes: Fix warnings from __this_cpu_read() on preempt kernels Naveen N. Rao
2017-09-22 9:10 ` Naveen N. Rao [this message]
2017-09-22 9:10 ` [PATCH v2 6/6] powerpc/jprobes: Validate break handler invocation as being due to a jprobe_return() Naveen N. Rao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=481ef9b0b83116b1ca72ec6c95266c5454073387.1505934128.git.naveen.n.rao@linux.vnet.ibm.com \
--to=naveen.n.rao@linux.vnet.ibm.com \
--cc=ananth@linux.vnet.ibm.com \
--cc=kamalesh@linux.vnet.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mhiramat@kernel.org \
--cc=mpe@ellerman.id.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).