Skip to contentSkip to conversation

kprobes: fix compilation when KPROBE_EVENTS is enabled without kretpobes

PATCH In review Sven Schnelle 3 participants 4 messages Apr 6, 2019 – Apr 8, 2019 kprobes

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kprobes: fix compilation when KPROBE_EVENTS is enabled without kretpobes

While implementing kprobes on PA-RISC (without kretprobes) compilation fails when CONFIG_KPROBE_EVENTS is enabled:

kernel/trace/trace_kprobe.o: in function `trace_kprobe_create':
kernel/trace/trace_kprobe.c:666: undefined reference to kprobe_on_func_entry' kernel/trace/trace_kprobe.o: in function trace_kprobe_on_func_entry':
kernel/trace/trace_kprobe.c:167: undefined reference to kprobe_on_func_entry' kernel/trace/trace_kprobe.c:167: undefined reference to kprobe_on_func_entry'
make: *** [Makefile:1029: vmlinux] Error 1

Given the fact that these functions have no dependencies on kretprobes i think they should be moved out of the #ifdef CONFIG_KRETPROBES block.

Cc "Naveen N. Rao" <[email protected]>
Cc Anil S Keshavamurthy <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Masami Hiramatsu <[email protected]>
---
 kernel/kprobes.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)
kernel/kprobes.c +20 -19
index c83e54727131..10a7e67fea67 100644
@@ -1819,6 +1819,26 @@ unsigned long __weak arch_deref_entry_point(void *entry)
 	return (unsigned long)entry;
 }
 
+bool __weak arch_kprobe_on_func_entry(unsigned long offset)
+{
+	return !offset;
+}
+
+bool kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym,
+			  unsigned long offset)
+{
+	kprobe_opcode_t *kp_addr = _kprobe_addr(addr, sym, offset);
+
+	if (IS_ERR(kp_addr))
+		return false;
+
+	if (!kallsyms_lookup_size_offset((unsigned long)kp_addr, NULL, &offset) ||
+					 !arch_kprobe_on_func_entry(offset))
+		return false;
+
+	return true;
+}
+
 #ifdef CONFIG_KRETPROBES
 /*
  * This kprobe pre_handler is registered with every kretprobe. When probe
@@ -1875,25 +1895,6 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs)
 }
 NOKPROBE_SYMBOL(pre_handler_kretprobe);
 
-bool __weak arch_kprobe_on_func_entry(unsigned long offset)
-{
-	return !offset;
-}
-
-bool kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset)
-{
-	kprobe_opcode_t *kp_addr = _kprobe_addr(addr, sym, offset);
-
-	if (IS_ERR(kp_addr))
-		return false;
-
-	if (!kallsyms_lookup_size_offset((unsigned long)kp_addr, NULL, &offset) ||
-						!arch_kprobe_on_func_entry(offset))
-		return false;
-
-	return true;
-}
-
 int register_kretprobe(struct kretprobe *rp)
 {
 	int ret = 0;
Signature · 1 line
2.20.1
Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · Sven Schnelle

While implementing kprobes on PA-RISC (without kretprobes) compilation fails when CONFIG_KPROBE_EVENTS is enabled:

Thanks for working on that! Is there a specific reason kretprobes is not being enabled on parisc?

Quoted 11 lines

kernel/trace/trace_kprobe.o: in function `trace_kprobe_create':
kernel/trace/trace_kprobe.c:666: undefined reference to kprobe_on_func_entry' kernel/trace/trace_kprobe.o: in function trace_kprobe_on_func_entry':
kernel/trace/trace_kprobe.c:167: undefined reference to kprobe_on_func_entry' kernel/trace/trace_kprobe.c:167: undefined reference to kprobe_on_func_entry'
make: *** [Makefile:1029: vmlinux] Error 1

Given the fact that these functions have no dependencies on kretprobes i think they should be moved out of the #ifdef CONFIG_KRETPROBES block.

Quoted 8 lines
Cc "Naveen N. Rao" <[email protected]>
Cc Anil S Keshavamurthy <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Masami Hiramatsu <[email protected]>
---
 kernel/kprobes.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

These functions were originally added only for kretprobes, but have taken on newer uses since then. So, for this patch:

However, I wonder if we should simply remove CONFIG_KRETPROBES altogether. All architectures supporting kprobes today also support kretprobes. I don't see why anyone would want to only disable kretprobes.

- Naveen

#2 lore raw

Hi Naveen,

Quoted 6 lines · Naveen N. Rao
Quoted 2 lines · Sven Schnelle

While implementing kprobes on PA-RISC (without kretprobes) compilation fails when CONFIG_KPROBE_EVENTS is enabled:

Thanks for working on that! Is there a specific reason kretprobes is not being enabled on parisc?

Reason is that i just started to add kprobes support to PA-RISC. I'm planning doing kretprobes as a second step and have separate patches for kprobe and kretprobe to keep things small.

Regards
Sven

maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Sven Schnelle
Quoted 10 lines · On Sat, 6 Apr 2019 17:55:43 +0200 Sven Schnelle <[email protected]> wrote:

While implementing kprobes on PA-RISC (without kretprobes) compilation fails when CONFIG_KPROBE_EVENTS is enabled:

kernel/trace/trace_kprobe.o: in function `trace_kprobe_create':
kernel/trace/trace_kprobe.c:666: undefined reference to kprobe_on_func_entry' kernel/trace/trace_kprobe.o: in function trace_kprobe_on_func_entry':
kernel/trace/trace_kprobe.c:167: undefined reference to kprobe_on_func_entry' kernel/trace/trace_kprobe.c:167: undefined reference to kprobe_on_func_entry'
make: *** [Makefile:1029: vmlinux] Error 1

Quoted 2 lines

Given the fact that these functions have no dependencies on kretprobes i think they should be moved out of the #ifdef CONFIG_KRETPROBES block.

Ah, I got it. Yes, this function had been introduced for kretprobe (because kretprobe must be the entry of functions) but is used for kprobe_event and bpf now.

It should be moved out of CONFIG_KPROBE_EVENTS.

Thank you,

Quoted 70 lines
Cc "Naveen N. Rao" <[email protected]>
Cc Anil S Keshavamurthy <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Masami Hiramatsu <[email protected]>
---
 kernel/kprobes.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)
kernel/kprobes.c +20 -19
index c83e54727131..10a7e67fea67 100644
@@ -1819,6 +1819,26 @@ unsigned long __weak arch_deref_entry_point(void *entry)
 	return (unsigned long)entry;
 }
 
+bool __weak arch_kprobe_on_func_entry(unsigned long offset)
+{
+	return !offset;
+}
+
+bool kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym,
+			  unsigned long offset)
+{
+	kprobe_opcode_t *kp_addr = _kprobe_addr(addr, sym, offset);
+
+	if (IS_ERR(kp_addr))
+		return false;
+
+	if (!kallsyms_lookup_size_offset((unsigned long)kp_addr, NULL, &offset) ||
+					 !arch_kprobe_on_func_entry(offset))
+		return false;
+
+	return true;
+}
+
 #ifdef CONFIG_KRETPROBES
 /*
  * This kprobe pre_handler is registered with every kretprobe. When probe
@@ -1875,25 +1895,6 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs)
 }
 NOKPROBE_SYMBOL(pre_handler_kretprobe);
 
-bool __weak arch_kprobe_on_func_entry(unsigned long offset)
-{
-	return !offset;
-}
-
-bool kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset)
-{
-	kprobe_opcode_t *kp_addr = _kprobe_addr(addr, sym, offset);
-
-	if (IS_ERR(kp_addr))
-		return false;
-
-	if (!kallsyms_lookup_size_offset((unsigned long)kp_addr, NULL, &offset) ||
-						!arch_kprobe_on_func_entry(offset))
-		return false;
-
-	return true;
-}
-
 int register_kretprobe(struct kretprobe *rp)
 {
 	int ret = 0;
Signature · 1 line
2.20.1
Signature · 1 line
Masami Hiramatsu <[email protected]>