New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
link/kprobe: specify symbol offset #618
Conversation
This patch adds kprobe symbol offset and its unit test. With symbol offset, we can insert kprobes for functions inlined. Signed-off-by: Tonghao Zhang <zhangtonghao@didiglobal.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming that the kprobe only fires if the PC is exactly that of sym + offset. Is there a way to add a test where Offset != 0
to make sure this actually works all the way?
@@ -235,8 +240,12 @@ func pmuProbe(typ probeType, args probeArgs) (*perfEvent, error) { | |||
} | |||
|
|||
attr = unix.PerfEventAttr{ | |||
// The minimum size required for PMU kprobes is PERF_ATTR_SIZE_VER1, | |||
// since it added the config2 (Ext2) field. Use Ext2 as probe_offset. | |||
Size: unix.PERF_ATTR_SIZE_VER1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://classes.engineering.wustl.edu/cse522/man-pages/perf_event_open.2.pdf VER1 is available from 2.6 so this doesn't change the minimum required version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we don't set .size , the kernel will use the PERF_ATTR_SIZE_VER0 64B as default. The config2 will be not included in perf_event_attr.
the kernel code:
static int perf_copy_attr(struct perf_event_attr __user *uattr, struct perf_event_attr attr)
.....
/ ABI compatibility quirk: */
if (!size)
size = PERF_ATTR_SIZE_VER0; // config2 is not in VER0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Offset == 0 is ok, it is an option for linux kernel.
https://www.kernel.org/doc/html/latest/trace/kprobetrace.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lmb for more context, it's the same issue as #293
https://elixir.bootlin.com/linux/v5.17.1/source/include/uapi/linux/perf_event.h#L323
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should've been clearer, using ver1 LGTM.
I'm happy with this change, but would like a test. Maybe we can have a negative test where we get an error if we pass math.MaxUint32 or similar if using a valid offset is too complicated. |
@lmb Hi @mmat11 @lmb any thoughts ? this pr should be merged to master ? |
@nickcooper-zhangtonghao as @lmb suggested you could test this either with a negative test that will fail when using a bad offset or with a normal test (if you already know the offset for |
Signed-off-by: Tonghao Zhang <zhangtonghao@didiglobal.com>
HI @mmat11 |
This patch adds kprobe symbol offset and its unit test.
With symbol offset, we can insert kprobe for functions
inlined.
[PR closed https://github.com//pull/613]
Signed-off-by: Tonghao Zhang zhangtonghao@didiglobal.com