Title: fix: correct pinned maps handling and implement missing userspace setup by SiyuanSun0736 · Pull Request #13 · multikernel/kernelscript · GitHub
Open Graph Title: fix: correct pinned maps handling and implement missing userspace setup by SiyuanSun0736 · Pull Request #13 · multikernel/kernelscript
X Title: fix: correct pinned maps handling and implement missing userspace setup by SiyuanSun0736 · Pull Request #13 · multikernel/kernelscript
Description: Summary
This PR fixes critical issues in the pin keyword implementation for map declarations. Previously, pinned maps were incorrectly treated as global variables, leading to runtime failures. Additionally, this PR introduces a robust userspace setup including automatic directory creation and unique variable naming.
Problems Addressed
IR Generation Conflict: Pinned maps incorrectly generated both an IR map definition and an IR global variable. This caused userspace codegen to search for a non-existent __pinned_globals map, resulting in: Failed to find pinned globals map in eBPF object.
Missing Setup Logic: Map pinning logic was only triggered if the map was explicitly accessed in userspace C code. Pinned maps must be initialized even if used solely within the eBPF program.
Variable Name Collisions: Multiple pinned maps caused C compilation errors due to the hardcoded use of a single variable name (existing_fd) for all map instances.
FS Path Failures: The pinning process failed if the target directory in /sys/fs/bpf/ did not already exist.
Implementation Details (Before vs. After)
1. Fixing Incorrect Map Handling
Before: The generator erroneously looked for a __pinned_globals map for any pinned variable.
/* FAULTY LOGIC: Searching for non-existent global map */
pinned_globals_map_fd = bpf_obj_get("/sys/fs/bpf/maps_demo/globals/pinned_globals");
if (pinned_globals_map_fd < 0) {
struct bpf_map *pinned_globals_map = bpf_object__find_map_by_name(obj->obj, "__pinned_globals");
if (!pinned_globals_map) {
fprintf(stderr, "Failed to find pinned globals map in eBPF object\n"); // <--- Runtime Error
return 1;
}
}
After: Directly handles the specific map and ensures the BPF file system path is ready.
/* CORRECTED LOGIC: Direct map handling with unique naming and directory setup */
struct bpf_map *event_log_map = bpf_object__find_map_by_name(obj->obj, "event_log");
int event_log_existing_fd = bpf_obj_get("/sys/fs/bpf/maps_demo/maps/event_log");
if (event_log_existing_fd >= 0) {
event_log_fd = event_log_existing_fd;
} else {
ensure_bpf_dir("/sys/fs/bpf/maps_demo/maps"); // Recursive directory creation
bpf_map__pin(event_log_map, "/sys/fs/bpf/maps_demo/maps/event_log");
event_log_fd = bpf_map__fd(event_log_map);
}
2. Robust Directory Creation
Added ensure_bpf_dir C helper function to recursively create paths (e.g., /sys/fs/bpf/
Open Graph Description: Summary This PR fixes critical issues in the pin keyword implementation for map declarations. Previously, pinned maps were incorrectly treated as global variables, leading to runtime failures. Addi...
X Description: Summary This PR fixes critical issues in the pin keyword implementation for map declarations. Previously, pinned maps were incorrectly treated as global variables, leading to runtime failures. Addi...
Opengraph URL: https://github.com/multikernel/kernelscript/pull/13
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:1cda1a30-6b61-5bc9-6852-180c8f5c0c53 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | ACFE:2102F4:6736DA:9597C2:6A622A2F |
| html-safe-nonce | d0a7f754378a7770674f5fab88f2d9055a86544d6eea6a7a51ab7ae31548b95d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0ZFOjIxMDJGNDo2NzM2REE6OTU5N0MyOjZBNjIyQTJGIiwidmlzaXRvcl9pZCI6IjM2NDcxMDQ3NjcxNzk3NjIyMjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e000252718debd09fbba4c10df109bc7876e44eedbeab5495d5c88d4632c796d |
| hovercard-subject-tag | pull_request:3366950025 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/multikernel/kernelscript/pull/13/files |
| twitter:image | https://avatars.githubusercontent.com/u/100674758?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/100674758?s=400&v=4 |
| og:image:alt | Summary This PR fixes critical issues in the pin keyword implementation for map declarations. Previously, pinned maps were incorrectly treated as global variables, leading to runtime failures. Addi... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0e882415c7b47986d65f899389c870b31642bb1c6f36516eb042618596c60e62 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/multikernel/kernelscript git https://github.com/multikernel/kernelscript.git |
| octolytics-dimension-user_id | 202362072 |
| octolytics-dimension-user_login | multikernel |
| octolytics-dimension-repository_id | 1019261571 |
| octolytics-dimension-repository_nwo | multikernel/kernelscript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1019261571 |
| octolytics-dimension-repository_network_root_nwo | multikernel/kernelscript |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 230e2af5fc0870303dd4569d72d2bb393ed52c52 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width