Skip to contentSkip to conversation

parisc: ftrace: get_kprobe() must be called with preempt disabled

PATCH In review Helge Deller 3 participants 4 messages Nov 3, 2020 – Nov 6, 2020

Subsystems (2)
lore
Share & tools
lore

Helge Deller

author maintainer
#0 lore raw

PATCH 1/1 parisc: ftrace: get_kprobe() must be called with preempt disabled

As noticed by Masami Hiramatsu, get_kprobe() must be called with preempt disabled.

arch/parisc/kernel/ftrace.c +12 -1
index 63e3ecb9da81..dd356ad18aca 100644
@@ -207,13 +212,22 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
 			   struct ftrace_ops *ops, struct pt_regs *regs)
 {
 	struct kprobe_ctlblk *kcb;
-	struct kprobe *p = get_kprobe((kprobe_opcode_t *)ip);
+	struct kprobe *p;
+
+	/*
+	 * We don't want to be preempted for the entire
+	 * duration of kprobe processing
+	 */
+	preempt_disable();
+	p = get_kprobe((kprobe_opcode_t *)ip);
 
 	if (unlikely(!p) || kprobe_disabled(p))
+		preempt_enable_no_resched();
 		return;
 
 	if (kprobe_running()) {
 		kprobes_inc_nmissed_count(p);
+		preempt_enable_no_resched();
 		return;
 	}
 
@@ -235,6 +249,8 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
 		}
 	}
 	__this_cpu_write(current_kprobe, NULL);
+
+	preempt_enable_no_resched();
 }
 NOKPROBE_SYMBOL(kprobe_ftrace_handler);
 
maintainer
#1 lore raw
Quoted 2 lines · On Tue, 3 Nov 2020 08:42:44 +0100 Helge Deller <[email protected]> wrote:

As noticed by Masami Hiramatsu, get_kprobe() must be called with preempt disabled.

Doesn't parisc ftrace implementation preempt off? Then it is required.

Steve, can we expect that op->func() is called under preempt off always on any arch or is it arch dependent?

Thank you,

Quoted 41 lines
arch/parisc/kernel/ftrace.c +12 -1
index 63e3ecb9da81..dd356ad18aca 100644
@@ -207,13 +212,22 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
 			   struct ftrace_ops *ops, struct pt_regs *regs)
 {
 	struct kprobe_ctlblk *kcb;
-	struct kprobe *p = get_kprobe((kprobe_opcode_t *)ip);
+	struct kprobe *p;
+
+	/*
+	 * We don't want to be preempted for the entire
+	 * duration of kprobe processing
+	 */
+	preempt_disable();
+	p = get_kprobe((kprobe_opcode_t *)ip);
 
 	if (unlikely(!p) || kprobe_disabled(p))
+		preempt_enable_no_resched();
 		return;
 
 	if (kprobe_running()) {
 		kprobes_inc_nmissed_count(p);
+		preempt_enable_no_resched();
 		return;
 	}
 
@@ -235,6 +249,8 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
 		}
 	}
 	__this_cpu_write(current_kprobe, NULL);
+
+	preempt_enable_no_resched();
 }
 NOKPROBE_SYMBOL(kprobe_ftrace_handler);
 
Signature · 1 line
Masami Hiramatsu <[email protected]>
maintainer
#2 lore raw
Quoted 11 lines · On Fri, 6 Nov 2020 11:17:58 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 2 lines · On Tue, 3 Nov 2020 08:42:44 +0100 Helge Deller <[email protected]> wrote:

As noticed by Masami Hiramatsu, get_kprobe() must be called with preempt disabled.

Doesn't parisc ftrace implementation preempt off? Then it is required.

Steve, can we expect that op->func() is called under preempt off always on any arch or is it arch dependent?

Currently all kprobe function callbacks are called with preempt disabled, because it doesn't have the RECURSIVE_SAFE flag set. And for callbacks without that set, it goes through a helper function that disables preemption. My current patch set (which is not upstreamed yet) is changing that, and I just posted a new patch series that does the preempt disable before the get_kprobe() function for parsic and other archs, to handle the new code.

Thus, parsic is currently OK (without my new patch set, it's called with preemption disabled).

-- Steve

author maintainer
#3 lore raw
Quoted 15 lines · Steven Rostedt
Quoted 11 lines · On Fri, 6 Nov 2020 11:17:58 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 2 lines · On Tue, 3 Nov 2020 08:42:44 +0100 Helge Deller <[email protected]> wrote:

As noticed by Masami Hiramatsu, get_kprobe() must be called with preempt disabled.

Doesn't parisc ftrace implementation preempt off? Then it is required.

Steve, can we expect that op->func() is called under preempt off always on any arch or is it arch dependent?

Quoted 7 lines

Currently all kprobe function callbacks are called with preempt disabled, because it doesn't have the RECURSIVE_SAFE flag set. And for callbacks without that set, it goes through a helper function that disables preemption. My current patch set (which is not upstreamed yet) is changing that, and I just posted a new patch series that does the preempt disable before the get_kprobe() function for parsic and other archs, to handle the new code.

Seems good. Thanks!

Quoted 2 lines

Thus, parsic is currently OK (without my new patch set, it's called with preemption disabled).

Ok.

Helge