Skip to content

Harpoon port #6

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

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft

Harpoon port #6

wants to merge 16 commits into from

Conversation

MinhPhan8803
Copy link
Member

@MinhPhan8803 MinhPhan8803 commented Mar 19, 2025

Currently WIP, not available to merge yet.

Add definition for PerfEventArray and its helper symbols. For the bpf_perf_event_output symbol specifically, currently only the bpf_perf_event_output_tp variant is supported.

Add the StreamableProgram trait that program types that can stream events through PerfEventArray should implement. This allows unifying the various streaming symbols into a single StreamableProgram::output_event() method in a manner similar to the overloaded helper bpf_perf_event_output().

Add a rex_uprobe macro and a KprobeFlavor enum in rex-macros/src/kprobe.rs to allow switching between kprobe variants in KProbe::expand().

Misc changes:

  • TaskStruct::get_comm() now returns a direct reference to the program name as a &CStr.
  • Expose the BPF_F_CURRENT_CPU constant as CURRENT_CPU.

Signed-off-by: MinhPhan8803 <nhatminhvinh8803@gmail.com>
Signed-off-by: MinhPhan8803 <nhatminhvinh8803@gmail.com>
Signed-off-by: MinhPhan8803 <nhatminhvinh8803@gmail.com>
Signed-off-by: MinhPhan8803 <nhatminhvinh8803@gmail.com>
Signed-off-by: MinhPhan8803 <nhatminhvinh8803@gmail.com>
@MinhPhan8803 MinhPhan8803 marked this pull request as draft March 19, 2025 21:05
Signed-off-by: MinhPhan8803 <nhatminhvinh8803@gmail.com>
@tianyin
Copy link
Member

tianyin commented Mar 21, 2025

this looks awesome!

Signed-off-by: MinhPhan8803 <nhatminhvinh8803@gmail.com>
Signed-off-by: MinhPhan8803 <nhatminhvinh8803@gmail.com>
Signed-off-by: MinhPhan8803 <nhatminhvinh8803@gmail.com>
Signed-off-by: MinhPhan8803 <nhatminhvinh8803@gmail.com>
// Design decision: the equivalent BPF helper writes the program name to
// a user-provided buffer, here we can take advantage of Rust's ownership by
// just providing a reference to the CString instead
pub fn get_comm(&self) -> Result<&CStr, ffi::FromBytesUntilNulError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this changes the function signature, the samples that use this function will need to be updated as well

let fn_name = self.item.sig.ident.clone();
let item = &self.item;
let function_name = format!("{}", fn_name);
let prog_ident =
format_ident!("PROG_{}", fn_name.to_string().to_uppercase());

let attached_function = if self.function.is_some() {
format!("rex/kprobe/{}", self.function.as_ref().unwrap())
format!("rex/{}/{}", flavor, self.function.as_ref().unwrap())
} else {
"rex/kprobe".to_string()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not respect the kprobe flavor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we could put the flavor inside the KProbe struct

@@ -0,0 +1,31 @@
[package]
name = "hello"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remember to change the sample name/metadata in all places.

let fn_name = self.item.sig.ident.clone();
let item = &self.item;
let function_name = format!("{}", fn_name);
let prog_ident =
format_ident!("PROG_{}", fn_name.to_string().to_uppercase());

let attached_function = if self.function.is_some() {
format!("rex/kprobe/{}", self.function.as_ref().unwrap())
format!("rex/{}/{}", flavor, self.function.as_ref().unwrap())
} else {
"rex/kprobe".to_string()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we could put the flavor inside the KProbe struct

process.kill()
std_out, std_err = process.communicate(timeout=7)
re_match = re.findall(
r"bpf_trace_printk: Rust triggered from PID \d+ on CPU .+", std_out, re.M
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will we have sanity test case for harpoon?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I haven't started working on the backend for the userspace app yet so I haven't really thought about what tests will look like.

…method to grab pointer from tp_ctx, fix KproveFlavor use, fix TaskStruct::get_comm use

Signed-off-by: MinhPhan8803 <nhatminhvinh8803@gmail.com>
… app

Signed-off-by: MinhPhan8803 <nhatminhvinh8803@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants