Skip to contentSkip to conversation

tracing: Add a way to filter function addresses to function names

PATCH New Steven Rostedt 1 participant 1 message Dec 13, 2022

Subsystems (2)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH 1/1 tracing: Add a way to filter function addresses to function names

From: "Steven Rostedt (Google)" <[email protected]>

There's been several times where an event records a function address in its field and I needed to filter on that address for a specific function name. It required looking up the function in kallsyms, finding its size, and doing a compare of "field >= function_start && field < function_end".

But this would change from boot to boot and is unreliable in scripts. Also, it is useful to have this at boot up, where the addresses will not be known. For example, on the boot command line:

trace_trigger="initcall_finish.traceoff if initcall_finish.function == acpi_init"

To implement this, add a ".function" prefix, that will check that the field is of size long, and the only operations allowed (so far) are "==" and "!=".

---
 Documentation/trace/events.rst     | 12 +++++
 kernel/trace/trace_events.c        |  2 +-
 kernel/trace/trace_events_filter.c | 79 +++++++++++++++++++++++++++++-
 3 files changed, 91 insertions(+), 2 deletions(-)
Documentation/trace/events.rst +12 -0
index c47f381d0c00..d0fd5c7220b7 100644
@@ -207,6 +207,18 @@ field name::
 As the kernel will have to know how to retrieve the memory that the pointer
 is at from user space.
 
+You can convert any long type to a function address and search by function name::
+
+  call_site.function == security_prepare_creds
+
+The above will filter when the field "call_site" falls on the address within
+"security_prepare_creds". That is, it will compare the value of "call_site" and
+the filter will return true if it is greater than or equal to the start of
+the function "security_prepare_creds" and less than the end of that function.
+
+The ".function" postfix can only be attached to values of size long, and can only
+be compared with "==" or "!=".
+
 5.2 Setting filters
 -------------------
 
kernel/trace/trace_events.c +1 -1
index 33e0b4f8ebe6..db6e2f399440 100644
@@ -2822,7 +2822,7 @@ static __init int setup_trace_triggers(char *str)
 		if (!trigger)
 			break;
 		bootup_triggers[i].event = strsep(&trigger, ".");
-		bootup_triggers[i].trigger = strsep(&trigger, ".");
+		bootup_triggers[i].trigger = strsep(&trigger, "");
 		if (!bootup_triggers[i].trigger)
 			break;
 	}
kernel/trace/trace_events_filter.c +78 -1

129 lines not on this page · raw message

Signature · 1 line
2.35.1