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

aya: Implement .kconfig support #1017

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

davibe
Copy link
Contributor

@davibe davibe commented Sep 2, 2024

Implement support for external data symbols (kconfig) following libbpf
logic.

Copy link

netlify bot commented Sep 2, 2024

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 12b3727
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/66f6ac09a4e0d00008460d7b
😎 Deploy Preview https://deploy-preview-1017--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 This is about aya (userspace) aya-obj Relating to the aya-obj crate test A PR that improves test cases or CI labels Sep 2, 2024
@davibe davibe force-pushed the feature/kconfig-support branch 4 times, most recently from 94aae7c to da75812 Compare September 2, 2024 09:50
Copy link

mergify bot commented Sep 3, 2024

@davibe, this pull request is now in conflict and requires a rebase.

@mergify mergify bot added the needs-rebase label Sep 3, 2024
@davibe davibe force-pushed the feature/kconfig-support branch 2 times, most recently from 3dd4a80 to 00d6b57 Compare September 3, 2024 07:41
@mergify mergify bot removed the needs-rebase label Sep 3, 2024
Copy link

mergify bot commented Sep 3, 2024

Hey @alessandrod, this pull request changes the Aya Public API and requires your review.

@mergify mergify bot added the api/needs-review Makes an API change that needs review label Sep 3, 2024
@mergify mergify bot requested a review from alessandrod September 3, 2024 08:04
@davibe davibe closed this Sep 5, 2024
@davibe davibe reopened this Sep 5, 2024
Copy link

mergify bot commented Sep 8, 2024

⚠️ The sha of the head commit of this PR conflicts with #631. Mergify cannot evaluate rules on this PR. ⚠️

@davibe davibe force-pushed the feature/kconfig-support branch 7 times, most recently from 1d6718b to c60557e Compare September 14, 2024 20:11
@davibe davibe force-pushed the feature/kconfig-support branch 2 times, most recently from 9881292 to f3d8b7d Compare September 22, 2024 11:05
@davibe davibe force-pushed the feature/kconfig-support branch 4 times, most recently from 8859344 to eb618c2 Compare September 22, 2024 13:29
@davibe davibe marked this pull request as ready for review September 22, 2024 13:33
@davibe davibe force-pushed the feature/kconfig-support branch 4 times, most recently from b66fd84 to 67d8937 Compare September 25, 2024 20:19
Copy link
Member

@marysaka marysaka left a comment

Choose a reason for hiding this comment

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

Overall looks pretty solid, thanks for doing this 🙏

I would like the fix you did for the first commit to be squashed in it if possible.
It also seems that the commit (co-)author got lost in the way but I guess that's fine.

With all comments fixed, assume my r-b/approval 👍

Comment on lines +26 to +32
tokio = { workspace = true, features = [
"rt",
"macros",
"rt-multi-thread",
"net",
], optional = true }
flate2 = "1.0"
Copy link
Member

Choose a reason for hiding this comment

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

Why was that changed?

Comment on lines 547 to 564
let BtfType::DataSec(d) = t else { continue; };
let sec_name = self.string_at(d.name_offset)?;

return Ok((sec_name.into(), var.clone()));
}
for d in &d.entries {
let BtfType::Var(var) = self.types.type_by_id(d.btf_type)? else {
continue;
};

if target_var_name == self.string_at(var.name_offset)? {
if var.linkage == VarLinkage::Extern {
return Ok((sec_name.into(), var.clone()));
} else {
return Err(BtfError::InvalidExternalSymbol {
symbol_name: target_var_name.into(),
});
}
Copy link
Member

Choose a reason for hiding this comment

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

Just a nit but I would squash that to the first commit (the same apply for next commit)

aya-obj/src/btf/btf.rs Show resolved Hide resolved
aya-obj/src/btf/btf.rs Outdated Show resolved Hide resolved
test/integration-test/bpf/kconfig.bpf.c Outdated Show resolved Hide resolved
aya/src/bpf.rs Outdated
Comment on lines 179 to 182
if raw_value.len() > 2 || raw_value.ends_with('"') {
continue;
}

Copy link
Member

Choose a reason for hiding this comment

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

Oh yeah I completely inverted that check here...
Could you fix it and keep it for sanity checks as malformed data is still possible?

Copy link

mergify bot commented Sep 27, 2024

⚠️ The sha of the head commit of this PR conflicts with #631. Mergify cannot evaluate rules on this PR. ⚠️

static ref KCONFIG_DEFINITION: HashMap<String, Vec<u8>> = compute_kconfig_definition(&FEATURES);
}

fn to_bytes(value: u64) -> [u8; 8] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't this value.to_ne_bytes()?

@@ -610,6 +708,14 @@ impl Btf {
}
};
e.offset = *offset as u32;

if var.linkage == VarLinkage::Extern {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a comment explaining that this is needed for kconfig support

return Ok(None);
}

let mut kconfig_map_index = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is going on here? This is overridden at line 856?

&self,
target_var_name: &str,
) -> Result<(String, Var), BtfError> {
for t in &self.types.types {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perf wise this isn't great, as we iterate all the types for each kconfig symbol.
We should probably do one pass where we find the datasecs, then only scan those?

// clang-format on

// CONFIG_BPF=y => 1
extern unsigned int CONFIG_BPF __kconfig;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should test char, short, int and long here, to test different alignments

@@ -109,6 +114,133 @@ pub fn features() -> &'static Features {
&FEATURES
}

lazy_static! {
static ref KCONFIG_DEFINITION: HashMap<String, Vec<u8>> = compute_kconfig_definition(&FEATURES);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of this lazy static, we could have a KConfig type. Then we could have
EbpfLoader::with_kconfig(kconfig). This way we don't force people who don't
use kconfig to take the extra memory hit. It's a small hit, but people are using
aya in embedded systems so we shouldn't increase mem usage if we can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api/needs-review Makes an API change that needs review aya This is about aya (userspace) aya-obj Relating to the aya-obj crate test A PR that improves test cases or CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants