History

kprobe: Simplify prepare_kprobe() by dropping redundant version

The function prepare_kprobe() is called during kprobe registration and is responsible for ensuring any architecture related preparation for the kprobe is done before returning. One of two versions of prepare_kprobe() is chosen depending on the availability of KPROBE_ON_FTRACE in the kernel configuration. Simplify the code by dropping the version when KPROBE_ON_FTRACE is not selected - instead relying on kprobe_ftrace() to return false when KPROBE_ON_FTRACE is not set. No functional change. Link: https://lkml.kernel.org/r/163163033696.489837.9264661820279300788.stgit@devnote2

Punit Agrawal committed 5 years ago

Commit 02afb8d1 parent 5d6de7d2 files · +14 −14Browse files

Unified · Split

2 files
  1. include/linux/kprobes.h +5 −0
  2. kernel/kprobes.c +9 −14
include/linux/kprobes.h+5−0
@@ -354,6 +354,11 @@ static inline void wait_for_kprobe_optimizer(void) { } · 353 unmodified lines
354extern void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,354extern void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
355 struct ftrace_ops *ops, struct ftrace_regs *fregs);355 struct ftrace_ops *ops, struct ftrace_regs *fregs);
356extern int arch_prepare_kprobe_ftrace(struct kprobe *p);356extern int arch_prepare_kprobe_ftrace(struct kprobe *p);
357#else
358static inline int arch_prepare_kprobe_ftrace(struct kprobe *p)
359{
360 return -EINVAL;
361}
357#endif362#endif
358 363
359int arch_check_ftrace_location(struct kprobe *p);364int arch_check_ftrace_location(struct kprobe *p);
kernel/kprobes.c+9−14
@@ -1033,15 +1033,6 @@ static struct ftrace_ops kprobe_ipmodify_ops __read_mostly = { · 1032 unmodified lines
1033static int kprobe_ipmodify_enabled;1033static int kprobe_ipmodify_enabled;
1034static int kprobe_ftrace_enabled;1034static int kprobe_ftrace_enabled;
1035 1035
1036/* Must ensure p->addr is really on ftrace */
1037static int prepare_kprobe(struct kprobe *p)
1038{
1039 if (!kprobe_ftrace(p))
1040 return arch_prepare_kprobe(p);
1041
1042 return arch_prepare_kprobe_ftrace(p);
1043}
1044
1045/* Caller must lock kprobe_mutex */1036/* Caller must lock kprobe_mutex */
1046static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops,1037static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops,
1047 int *cnt)1038 int *cnt)
@@ -1113,11 +1104,6 @@ static int disarm_kprobe_ftrace(struct kprobe *p) · 65 unmodified lines
1113 ipmodify ? &kprobe_ipmodify_enabled : &kprobe_ftrace_enabled);1104 ipmodify ? &kprobe_ipmodify_enabled : &kprobe_ftrace_enabled);
1114}1105}
1115#else /* !CONFIG_KPROBES_ON_FTRACE */1106#else /* !CONFIG_KPROBES_ON_FTRACE */
1116static inline int prepare_kprobe(struct kprobe *p)
1117{
1118 return arch_prepare_kprobe(p);
1119}
1120
1121static inline int arm_kprobe_ftrace(struct kprobe *p)1107static inline int arm_kprobe_ftrace(struct kprobe *p)
1122{1108{
1123 return -ENODEV;1109 return -ENODEV;
@@ -1129,6 +1115,15 @@ static inline int disarm_kprobe_ftrace(struct kprobe *p) · 5 unmodified lines
1129}1115}
1130#endif1116#endif
1131 1117
1118static int prepare_kprobe(struct kprobe *p)
1119{
1120 /* Must ensure p->addr is really on ftrace */
1121 if (kprobe_ftrace(p))
1122 return arch_prepare_kprobe_ftrace(p);
1123
1124 return arch_prepare_kprobe(p);
1125}
1126
1132/* Arm a kprobe with text_mutex */1127/* Arm a kprobe with text_mutex */
1133static int arm_kprobe(struct kprobe *kp)1128static int arm_kprobe(struct kprobe *kp)
1134{1129{