Skip to content
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

Add support for stack argument #773

Closed
wants to merge 23 commits into from
Closed

Conversation

liyan-ah
Copy link

Add support for stack argument

related to #659

@netlify
Copy link

netlify bot commented Aug 30, 2023

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 5fc269e
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/6525205a2a35b80008af43d2
😎 Deploy Preview https://deploy-preview-773--aya-rs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mergify mergify bot added aya-bpf This is about aya-bpf (kernel) test A PR that improves test cases or CI labels Aug 30, 2023
@liyan-ah
Copy link
Author

@tamird
A test case is added to ensure stack_argument works okay.
Any other suggestions?

@tamird tamird requested a review from vadorovsky August 31, 2023 15:51
Copy link
Member

@vadorovsky vadorovsky left a comment

Choose a reason for hiding this comment

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

Just one nit.

The rest looks good. I like the tests!

bpf/aya-bpf/src/args.rs Outdated Show resolved Hide resolved
Copy link
Member

@vadorovsky vadorovsky left a comment

Choose a reason for hiding this comment

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

Thanks!

test/integration-test/Cargo.toml Outdated Show resolved Hide resolved
bpf/aya-bpf/src/args.rs Outdated Show resolved Hide resolved
bpf/aya-bpf/src/args.rs Outdated Show resolved Hide resolved
test/integration-test/src/tests/stack_argument.rs Outdated Show resolved Hide resolved
test/integration-ebpf/src/stack_argument.rs Outdated Show resolved Hide resolved
test/integration-ebpf/src/stack_argument.rs Outdated Show resolved Hide resolved
test/integration-ebpf/src/stack_argument.rs Outdated Show resolved Hide resolved
test/integration-ebpf/src/stack_argument.rs Outdated Show resolved Hide resolved
test/integration-test/src/tests/stack_argument.rs Outdated Show resolved Hide resolved
@mergify
Copy link

mergify bot commented Sep 25, 2023

@liyan-ah, this pull request is now in conflict and requires a rebase.

@mergify mergify bot added the needs-rebase label Sep 25, 2023
@liyan-ah liyan-ah reopened this Sep 26, 2023
@liyan-ah liyan-ah requested a review from vadorovsky September 26, 2023 09:42
@liyan-ah liyan-ah requested a review from tamird September 26, 2023 09:42
@liyan-ah
Copy link
Author

@tamird @vadorovsky
Any further suggestions?


//read argument, and send event
fn try_stack_argument(ctx: ProbeContext) -> Result<i32, i64> {
let _ = ARGS.insert(&0, &ctx.arg(0).ok_or(255)?, 0);
Copy link
Member

Choose a reason for hiding this comment

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

can we avoid these _?

Copy link
Author

@liyan-ah liyan-ah Sep 28, 2023

Choose a reason for hiding this comment

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

There would be warning if no let _.

warning: unused `Result` that must be used
  --> test/integration-ebpf/src/stack_argument.rs:23:5
   |
23 |     ARGS.insert(&0, &ctx.arg(0).ok_or(255)?, 0);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this `Result` may be an `Err` variant, which should be handled
   = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
   |
23 |     let _ = ARGS.insert(&0, &ctx.arg(0).ok_or(255)?, 0);
   |     +++++++

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the proper thing to do is handle these errors rather than silently ignore them. You probably want to return from the program on any error.

}
}

//read argument, and send event
Copy link
Member

Choose a reason for hiding this comment

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

what event? I don't understand this comment.

Copy link
Author

Choose a reason for hiding this comment

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

comment modified.

rustfmt.toml Outdated
@@ -1,3 +1,4 @@
edition = "2021"
Copy link
Member

Choose a reason for hiding this comment

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

why?

Copy link
Author

Choose a reason for hiding this comment

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

removed.

HashMap::try_from(bpf.take_map("ARGS").unwrap()).unwrap();
trigger_stack_argument(0, 1, 2, 3, 4, 5, 6, 7);

tokio::time::sleep(std::time::Duration::from_millis(100)).await;
Copy link
Member

Choose a reason for hiding this comment

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

why are we sleeping here?

Copy link
Author

Choose a reason for hiding this comment

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

The sleeping could be removed, and it works okay in my local environment. The sleeping is added just as referred in integration-test/src/tests/log.rs.

Copy link
Author

Choose a reason for hiding this comment

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

removed.

a_3: u64,
a_4: u64,
a_5: u64,
//in x86_64, from arg6, stack_argument would be used
Copy link
Member

Choose a reason for hiding this comment

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

please write a proper sentence and add a space after the //.

can you add a citation?

Copy link
Author

Choose a reason for hiding this comment

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

citation added.

//read argument, and send event
fn try_stack_argument(ctx: ProbeContext) -> Result<i32, i64> {
let _ = ARGS.insert(&0, &ctx.arg(0).ok_or(255)?, 0);
let _ = ARGS.insert(&1, &ctx.arg(1).ok_or(255)?, 0);
Copy link
Member

Choose a reason for hiding this comment

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

what's the story with these .ok_or(255)? I don't understand why this function returns a Result where the only possible "error" is 255.

Copy link
Author

Choose a reason for hiding this comment

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

There is no means for 255, just to make sure the test in stack_argument would failed.

Copy link
Member

Choose a reason for hiding this comment

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

I understand, but I do not think this is an appropriate thing to do. If these methods fail, we should just return from this program.

assert_eq!(args_map.keys().count(), 8);
for iter in args_map.iter() {
let iter_v = iter.unwrap();
assert_eq!(iter_v.0 as u64, iter_v.1);
Copy link
Member

Choose a reason for hiding this comment

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

please destructure instead of these point accesses.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure about this. Any problems with map.iter()?

Copy link
Member

Choose a reason for hiding this comment

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

let (key, value) = iter.unwrap()

@mergify
Copy link

mergify bot commented Sep 27, 2023

@liyan-ah, this pull request is now in conflict and requires a rebase.

@mergify mergify bot added the needs-rebase label Sep 27, 2023
@mergify mergify bot removed the needs-rebase label Sep 28, 2023
@liyan-ah liyan-ah requested a review from tamird September 28, 2023 03:45
@liyan-ah
Copy link
Author

@tamird

@tamird
Copy link
Member

tamird commented Sep 28, 2023

Please test this locally before pinging again.

@liyan-ah
Copy link
Author

@tamird
Check about this?

@liyan-ah
Copy link
Author

@tamird
The stack_argument should be used differently in different arch. How can I specify different integeration-ebpf test-case for arm, aarch64 and amd?
I have found none examples in other test cases. Does #[cfg(bpf_target_arch="amd")] works?
Or I would have to try with argument return values, which is rigorous.

Copy link
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

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

I'm running out of patience with this PR. Every revision is ridden with bugs. I'm inclined to stop reviewing this TBH.


//read argument, and send event
fn try_stack_argument(ctx: ProbeContext) -> Result<i32, i64> {
let _ = ARGS.insert(&0, &ctx.arg(0).ok_or(255)?, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Yes, the proper thing to do is handle these errors rather than silently ignore them. You probably want to return from the program on any error.

//read argument, and send event
fn try_stack_argument(ctx: ProbeContext) -> Result<i32, i64> {
let _ = ARGS.insert(&0, &ctx.arg(0).ok_or(255)?, 0);
let _ = ARGS.insert(&1, &ctx.arg(1).ok_or(255)?, 0);
Copy link
Member

Choose a reason for hiding this comment

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

I understand, but I do not think this is an appropriate thing to do. If these methods fail, we should just return from this program.

@@ -10,6 +10,7 @@ assert_matches = { workspace = true }
aya = { workspace = true }
aya-log = { workspace = true }
aya-obj = { workspace = true }
bytes = { workspace = true }
Copy link
Member

Choose a reason for hiding this comment

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

what is this?

// Notice that other languages, like Golang, or in other archs, like aarch64, may
// have different convention rules.
_a_6: u64,
_a_7: i64,
Copy link
Member

Choose a reason for hiding this comment

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

why is this a different type?

assert_eq!(args_map.keys().count(), 8);
for iter in args_map.iter() {
let iter_v = iter.unwrap();
assert_eq!(iter_v.0 as u64, iter_v.1);
Copy link
Member

Choose a reason for hiding this comment

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

let (key, value) = iter.unwrap()

break;
}
if stack {
let _ = ARGS.insert(&arg, &ctx.arg(arg as usize).ok_or(255)?, 0);
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be stack_arg?

@liyan-ah
Copy link
Author

I'm running out of patience with this PR. Every revision is ridden with bugs. I'm inclined to stop reviewing this TBH.

Sorry about that.

From my view, the mainly errors are specify different integeration-ebpf test-case for arm, aarch64 and amd. I would fix it latter.

@mergify
Copy link

mergify bot commented Oct 12, 2023

@liyan-ah, this pull request is now in conflict and requires a rebase.

@mergify mergify bot added the needs-rebase label Oct 12, 2023
@liyan-ah
Copy link
Author

Would reopen when I get some spare time.

@liyan-ah liyan-ah closed this Nov 13, 2023
@mergify mergify bot removed the needs-rebase label Nov 13, 2023
@liyan-ah liyan-ah deleted the new_sarg branch November 24, 2023 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aya-bpf This is about aya-bpf (kernel) test A PR that improves test cases or CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants