History

Merge tag 'probes-v6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

Pull kprobes updates from Masami Hiramatsu: - Skip negative return code check for snprintf in eprobe - Add recursive call test cases for kprobe unit test - Add 'char' type to probe events to show it as the character instead of value - Update kselftest kprobe-event testcase to ignore '__pfx_' symbols - Fix kselftest to check filter on eprobe event correctly - Add filter on eprobe to the README file in tracefs - Fix optprobes to check whether there is 'under unoptimizing' optprobe when optimizing another kprobe correctly - Fix optprobe to check whether there is 'under unoptimizing' optprobe when fetching the original instruction correctly - Fix optprobe to free 'forcibly unoptimized' optprobe correctly * tag 'probes-v6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: tracing/eprobe: no need to check for negative ret value for snprintf test_kprobes: Add recursed kprobe test case tracing/probe: add a char type to show the character value of traced arguments selftests/ftrace: Fix probepoint testcase to ignore __pfx_* symbols selftests/ftrace: Fix eprobe syntax test case to check filter support tracing/eprobe: Fix to add filter on eprobe description in README file x86/kprobes: Fix arch_check_optimized_kprobe check within optimized_kprobe range x86/kprobes: Fix __recover_optprobed_insn check optimizing logic kprobes: Fix to handle forcibly unoptimized kprobes on freeing_list

Linus Torvalds committed 3 years ago

Commit 2b79eb72 parents 0df8218 c96abae12 files · +117 −33Browse files

Showing the changes to kernel (5 of 12 files). Show all

Unified · Split

5 files
  1. kernel/kprobes.c +12 −15
  2. kernel/trace/trace.c +2 −2
  3. kernel/trace/trace_eprobe.c +4 −8
  4. kernel/trace/trace_probe.c +2 −0
  5. kernel/trace/trace_probe.h +1 −0
kernel/kprobes.c+12−15
@@ -458,7 +458,7 @@ static inline int kprobe_optready(struct kprobe *p) · 457 unmodified lines
458458 }
459459
460460 /* Return true if the kprobe is disarmed. Note: p must be on hash list */
461−static inline bool kprobe_disarmed(struct kprobe *p)
461+bool kprobe_disarmed(struct kprobe *p)
462462 {
463463 struct optimized_kprobe *op;
464464
@@ -555,17 +555,15 @@ static void do_unoptimize_kprobes(void) · 90 unmodified lines
555555 /* See comment in do_optimize_kprobes() */
556556 lockdep_assert_cpus_held();
557557
558− /* Unoptimization must be done anytime */
559− if (list_empty(&unoptimizing_list))
560− return;
558+ if (!list_empty(&unoptimizing_list))
559+ arch_unoptimize_kprobes(&unoptimizing_list, &freeing_list);
561560
562− arch_unoptimize_kprobes(&unoptimizing_list, &freeing_list);
563− /* Loop on 'freeing_list' for disarming */
561+ /* Loop on 'freeing_list' for disarming and removing from kprobe hash list */
564562 list_for_each_entry_safe(op, tmp, &freeing_list, list) {
565563 /* Switching from detour code to origin */
566564 op->kp.flags &= ~KPROBE_FLAG_OPTIMIZED;
567− /* Disarm probes if marked disabled */
568− if (kprobe_disabled(&op->kp))
565+ /* Disarm probes if marked disabled and not gone */
566+ if (kprobe_disabled(&op->kp) && !kprobe_gone(&op->kp))
569567 arch_disarm_kprobe(&op->kp);
570568 if (kprobe_unused(&op->kp)) {
571569 /*
@@ -662,7 +660,7 @@ void wait_for_kprobe_optimizer(void) · 90 unmodified lines
662660 mutex_unlock(&kprobe_mutex);
663661 }
664662
665−static bool optprobe_queued_unopt(struct optimized_kprobe *op)
663+bool optprobe_queued_unopt(struct optimized_kprobe *op)
666664 {
667665 struct optimized_kprobe *_op;
668666
@@ -797,14 +795,13 @@ static void kill_optimized_kprobe(struct kprobe *p) · 128 unmodified lines
797795 op->kp.flags &= ~KPROBE_FLAG_OPTIMIZED;
798796
799797 if (kprobe_unused(p)) {
800− /* Enqueue if it is unused */
801− list_add(&op->list, &freeing_list);
802798 /*
803− * Remove unused probes from the hash list. After waiting
804− * for synchronization, this probe is reclaimed.
805− * (reclaiming is done by do_free_cleaned_kprobes().)
799+ * Unused kprobe is on unoptimizing or freeing list. We move it
800+ * to freeing_list and let the kprobe_optimizer() remove it from
801+ * the kprobe hash list and free it.
806802 */
807− hlist_del_rcu(&op->kp.hlist);
803+ if (optprobe_queued_unopt(op))
804+ list_move(&op->list, &freeing_list);
808805 }
809806
810807 /* Don't touch the code, because it is already freed. */
kernel/trace/trace.c+2−2
@@ -5646,7 +5646,7 @@ static const char readme_msg[] = · 5645 unmodified lines
56465646 #ifdef CONFIG_HIST_TRIGGERS
56475647 "\t s:[synthetic/]<event> <field> [<field>]\n"
56485648 #endif
5649− "\t e[:[<group>/][<event>]] <attached-group>.<attached-event> [<args>]\n"
5649+ "\t e[:[<group>/][<event>]] <attached-group>.<attached-event> [<args>] [if <filter>]\n"
56505650 "\t -:[<group>/][<event>]\n"
56515651 #ifdef CONFIG_KPROBE_EVENTS
56525652 "\t place: [<module>:]<symbol>[+<offset>]|<memaddr>\n"
@@ -5663,7 +5663,7 @@ static const char readme_msg[] = · 10 unmodified lines
56635663 "\t $stack<index>, $stack, $retval, $comm,\n"
56645664 #endif
56655665 "\t +|-[u]<offset>(<fetcharg>), \\imm-value, \\\"imm-string\"\n"
5666− "\t type: s8/16/32/64, u8/16/32/64, x8/16/32/64, string, symbol,\n"
5666+ "\t type: s8/16/32/64, u8/16/32/64, x8/16/32/64, char, string, symbol,\n"
56675667 "\t b<bit-width>@<bit-offset>/<container-size>, ustring,\n"
56685668 "\t symstr, <type>\\[<array-size>\\]\n"
56695669 #ifdef CONFIG_HIST_TRIGGERS
kernel/trace/trace_eprobe.c+4−8
@@ -923,17 +923,13 @@ static int trace_eprobe_parse_filter(struct trace_eprobe *ep, int argc, const ch · 922 unmodified lines
923923
924924 p = ep->filter_str;
925925 for (i = 0; i < argc; i++) {
926− ret = snprintf(p, len, "%s ", argv[i]);
927− if (ret < 0)
928− goto error;
929− if (ret > len) {
930− ret = -E2BIG;
931− goto error;
932− }
926+ if (i)
927+ ret = snprintf(p, len, " %s", argv[i]);
928+ else
929+ ret = snprintf(p, len, "%s", argv[i]);
933930 p += ret;
934931 len -= ret;
935932 }
936− p[-1] = '\0';
937933
938934 /*
939935 * Ensure the filter string can be parsed correctly. Note, this
kernel/trace/trace_probe.c+2−0
@@ -50,6 +50,7 @@ DEFINE_BASIC_PRINT_TYPE_FUNC(x8, u8, "0x%x") · 49 unmodified lines
5050 DEFINE_BASIC_PRINT_TYPE_FUNC(x16, u16, "0x%x")
5151 DEFINE_BASIC_PRINT_TYPE_FUNC(x32, u32, "0x%x")
5252 DEFINE_BASIC_PRINT_TYPE_FUNC(x64, u64, "0x%Lx")
53+DEFINE_BASIC_PRINT_TYPE_FUNC(char, u8, "'%c'")
5354
5455 int PRINT_TYPE_FUNC_NAME(symbol)(struct trace_seq *s, void *data, void *ent)
5556 {
@@ -95,6 +96,7 @@ static const struct fetch_type probe_fetch_types[] = { · 39 unmodified lines
9596 ASSIGN_FETCH_TYPE_ALIAS(x16, u16, u16, 0),
9697 ASSIGN_FETCH_TYPE_ALIAS(x32, u32, u32, 0),
9798 ASSIGN_FETCH_TYPE_ALIAS(x64, u64, u64, 0),
99+ ASSIGN_FETCH_TYPE_ALIAS(char, u8, u8, 0),
98100 ASSIGN_FETCH_TYPE_ALIAS(symbol, ADDR_FETCH_TYPE, ADDR_FETCH_TYPE, 0),
99101
100102 ASSIGN_FETCH_TYPE_END
kernel/trace/trace_probe.h+1−0
@@ -166,6 +166,7 @@ DECLARE_BASIC_PRINT_TYPE_FUNC(x16); · 165 unmodified lines
166166 DECLARE_BASIC_PRINT_TYPE_FUNC(x32);
167167 DECLARE_BASIC_PRINT_TYPE_FUNC(x64);
168168
169+DECLARE_BASIC_PRINT_TYPE_FUNC(char);
169170 DECLARE_BASIC_PRINT_TYPE_FUNC(string);
170171 DECLARE_BASIC_PRINT_TYPE_FUNC(symbol);
171172