Skip to content

Add four advanced runnable eBPF tutorial tools - #224

Open
yunwei37 wants to merge 13 commits into
mainfrom
feat/four-production-ebpf-tutorials
Open

yunwei37 wants to merge 13 commits into
mainfrom
feat/four-production-ebpf-tutorials

Conversation

@yunwei37

@yunwei37 yunwei37 commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

What changed

This PR adds four runnable eBPF tools with English and Chinese tutorials:

  • 55-dns-egress builds a minimal DNS-derived IP allowlist. It correlates DNS queries and responses, rejects unsolicited or mismatched responses, keeps learned A records for their TTL, and enforces the result at cgroup/connect4.
  • 56-tc-flow-index uses BPF objects, refcounts, and two rbtrees to maintain identity and traffic-ordered views of the same TC egress flow records.
  • 57-oom-watch profiles recorded memcg reclaim intervals and sampled kernel stacks, then correlates the accumulated profile with OOM victim selection and victim exit.
  • 60-afxdp-dump implements an exclusive, receive-only AF_XDP path with direct UMEM and ring management, packet filtering, frame recycling, and native-to-generic XDP fallback.

Each lesson includes a compact CLI, a deterministic integration test, the mechanism-relevant source and a link to the complete implementation, requirements, representative output from a real run, and primary upstream references.

The repository-local writing workflow keeps a single writer for reader-facing prose and avoids a mandatory second prose review for content-only work. It still requires implementation-aware fact checking of source excerpts, commands, behavior, versions, requirements, output, and relevant validation evidence.

Why

The examples fill four technical gaps in the tutorial series: DNS-derived connect policy, refcounted graph ownership with multiple indexes, reclaim profiling before an OOM kill, and a first standalone AF_XDP receive path. Each tool keeps the main kernel mechanism visible while still accepting a real cgroup or interface in normal mode.

Validation

  • Clean host builds passed for all four lesson implementations.
  • Integration tests passed for all four lessons as root on x86_64 Linux 7.2.0-rc4 built from kernel commit 1590cf0329716306e948a8fc29f1d3ee87d3989f.
  • The DNS demo passed its complete query-correlation, poisoning-resistance, live-TTL, and expired-TTL path.
  • AF_XDP passed native driver mode and explicit generic/SKB mode, including 65 packets through a 64-frame UMEM and a non-matching pass-through check.
  • Documentation unit tests and source-block validator tests pass.
  • Generated TOCs and compatibility tables are current.
  • Internal links, prohibited dash punctuation, merge markers, and git diff --check pass.

@yunwei37 yunwei37 changed the title Add four production-shaped eBPF tutorial tools Add four advanced runnable eBPF tutorial tools Jul 22, 2026
@yunwei37

Copy link
Copy Markdown
Member Author

Final dedicated review for exact head 41dff7e: NO BLOCKERS.\n\nReviewed the four tutorial implementations and bilingual rewrites, conflict resolution in the three repository-local skills, source-block synchronization, scope, version metadata, and KVM validation evidence. The reader-focused rewrite preserves complete kernel and user-space source while making the narrative follow each tool's real data flow. All four host builds and KVM scenarios passed; the final DNS refactor was rerun in KVM. No conflict markers, history deletion, relative-link regressions, or infrastructure/model/prompt leakage were found.

@yunwei37

Copy link
Copy Markdown
Member Author

Independent external review for exact head 41dff7e: NO BLOCKERS.\n\nThe review independently checked the three skill conflict resolutions, all four English/Chinese tutorials, byte-exact embedded source, program types and minimum-kernel claims, public sample-output provenance, CI scope, absolute links, and leakage constraints. It confirmed that the AF_XDP article now shows only output emitted by the public tool, all core kernel and user-space source remains complete, and the change set is proportional to four runnable advanced tutorials. The only nonblocking qualification is that the newest 6.16/7.1 APIs were exercised end to end on the shared Linux 7.2-rc4 KVM kernel rather than separately on every declared minimum kernel.

@yunwei37
yunwei37 marked this pull request as ready for review July 22, 2026 09:42
@yunwei37

yunwei37 commented Jul 26, 2026 •

Copy link
Copy Markdown
Member Author

Exact-head follow-up review is complete for f2f3ab9.

The review found that the content-only workflow had removed technical-fidelity checks and that several rewritten passages no longer matched the implementations. The final head now:

  • keeps the single-writer/no-second-prose-review path while restoring implementation-aware checks for source excerpts, commands, behavior, versions, requirements, output, and validation evidence;
  • describes lesson 60 as an exclusive AF_XDP receiver rather than passive packet capture and removes unsupported production-use claims;
  • qualifies lesson 57 around recorded/matched reclaim intervals and verifier risk;
  • fixes the lesson 56 four-file count and refreshes the PR body/generated titles.

Two independent final reviews found no actionable issues on the exact head. Documentation unit tests, source-block validator tests, generated indexes, internal links, punctuation/merge-marker scans, and git diff --check pass locally. CI is running on the final commit; there are no unresolved review threads.

AI-generated response; a maintainer will review and follow up later

@yunwei37 yunwei37 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reviewed the head f2f3ab94. Four new advanced tutorial tools plus skill
guidance updates (10562 lines added across 52 files, one new workflow step).

The size is mostly content, so the reviewable parts are: (a) the added
test-libbpf.yml step — whether it builds all four tools or only the first;
(b) the skill edits, which are net removals (−64, −76), meaning guidance was
consolidated — worth confirming nothing load-bearing was dropped.

Checks green.

AI-generated response; a maintainer will review and follow up later

@yunwei37
yunwei37 force-pushed the feat/four-production-ebpf-tutorials branch from f2f3ab9 to 3f3f553 Compare November 15, 2026 02:16
Copilot AI balanced review requested due to automatic review settings November 15, 2026 02:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@yunwei37 yunwei37 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reviewed head 3f3f553aaa

Tutorial 55 (DNS egress correlation) plus skill/guide updates. The BPF program attaches at cgroup_skb/egress, cgroup_skb/ingress, and cgroup/connect4 on one cgroup, and shares three maps: pending_queries and allowed_ips as LRU_HASH (1024 entries) and events as a 256 KiB ringbuf.

The parsing is conservative and says so. Transport validation checks IPv4 + UDP, rejects anything with frag_off & (IP_MF | IP_OFFSET), and compares the resolver address before computing the DNS offset; the prose states plainly that reassembly is not implemented. DNS_QUERY_LIFETIME_NS is 5 s, so a query with no observed response cannot authorize a connection indefinitely — the trust-chain claim the tutorial is built on.

src/55-dns-egress/tests/test_dns_egress.py plus a .config and Makefile make it self-testing, and TUTORIAL_IDEAS.md/README{,.zh}.md/the TOC generator test are updated in the same change.

AI patrol review

@yunwei37 yunwei37 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Verdict: ready to merge once CI is green

The change on this head was reviewed above and needs no fix. build fails at the bpftrace step of the helloworld example, and it fails identically on main itself:

test -n "$hello_symbol" || (echo "Error: raw hello function symbol not found" && exit 1)
Error: bpftrace failed to attach or trace the hello function

Base-branch failure; it does not block this head.

AI patrol review

@yunwei37 yunwei37 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Verdict: ready to merge once main's CI is fixed

Four new lessons (55-dns-egress, 56-tc-flow-index, 57-oom-watch, 60-afxdp-dump) with English and Chinese tutorials, a deterministic test each, plus the writing-workflow updates that produced them. The four fill gaps the series did not have — DNS-derived connect policy at cgroup/connect4, refcounted graph ownership with two rbtrees over the same TC flow records, reclaim profiling ahead of OOM victim selection, and a standalone AF_XDP receive path — and the body states what each one keeps visible, which is the right thing for a tutorial to be explicit about.

Both red jobs are main's, and both are already diagnosed:

  1. build in test-eunomia.yaml stops on Error: Unable to locate package llvm-14-dev / exit 100 — ubuntu-latest is now 26.04 and ships no LLVM 14. Fixed by #236/#237's pin to ubuntu-22.04.
  2. build in test-bpftrace.yml stops on test 37 uprobe-rust bpftrace attach: bpftrace -e "uprobe:...helloworld" under timeout 3 produced an empty output file, so grep -q "Attaching 1 probe" never matched and the step exited 1. That is the same step, unchanged by this PR, that #237 fixes twice over — timeout 10 and Attach(ing|ed).

docs, CodeFactor, GitGuardian and trigger all pass on this head.

What to check when it goes green. 52 files, 10566 insertions, four new src/NN-* trees each with a Makefile, .config, .gitignore, BPF and userspace C, a Python test, and two READMEs. The body's validation claims (kernel 7.2.0-rc4 at 1590cf03, AF_XDP native and generic, 65 packets through a 64-frame UMEM) are the kind of claim only a real run produces, and the TOC/compatibility-table generation is covered by scripts/test_generate_toc.py, which this PR also updates. The one thing the CI here cannot prove is that the four lessons still build on the runner's kernel — that is what the build matrix legs do once the two main failures are out of the way, so the first green run is the real validation.

AI patrol review

@yunwei37

yunwei37 commented Nov 19, 2026 •

Copy link
Copy Markdown
Member Author

Verdict: design problem — four tutorials in one PR, and the skill edits are the part that will conflict

Four complete tools (55-dns-egress, 56-tc-flow-index, and two more) with English and Chinese write-ups is a lot of value, and each one is described precisely enough to be reviewable — the DNS tool's "rejects unsolicited or mismatched responses, keeps learned A records for their TTL, enforces at cgroup/connect4" is the level of detail a tutorial needs.

The problem is the shape: 52 files / 10566 additions, of which a large share is .agents/skills/ — bpf-tutorial-writing-style, find-bpf-tutorial-topic, write-bpf-production-tutorial, and test-bpf-tutorial-kvm scripts. Skill files are shared by every tutorial author in this repo, so:

  • A PR that adds four tutorials and rewrites four skill files cannot be reviewed for either. A skill edit that is wrong for the other 60 tutorials is invisible among 10k lines of new content.
  • Any other tutorial PR in flight will conflict on those files.

Recommend: land the skill changes separately first (they are the reusable part, and they change how the next tutorial is written), then one PR per tutorial. Four PRs of ~2500 lines each are reviewable; one of 10566 is not.

Two smaller notes at 3f3f553a:

  • .agents/skills/test-bpf-tutorial-kvm/scripts/run-in-kvm.sh is a script change — that is tooling, not tutorial content, and belongs in the skill PR.
  • The four new src/5x-* directories should each carry a one-line entry in the tutorial index (README.md / mkdocs nav if this repo has one) so they are reachable; check that the index change is in the diff.

No check on the head is red.

AI patrol review

@yunwei37 yunwei37 added AI review: design problem patrol review verdict and removed AI review: merge after CI patrol review verdict labels Nov 19, 2026
@yunwei37

Copy link
Copy Markdown
Member Author

Adding the two facts that check out, and one correction:

  • The index is updated: README.md and README.zh.md are both in the diff, so the new 55-*/56-* entries are reachable. Withdrawn from the review above.
  • The skill edits are four files (.agents/skills/bpf-tutorial-writing-style, find-bpf-tutorial-topic, write-bpf-production-tutorial, plus test-bpf-tutorial-kvm/scripts/run-in-kvm.sh and an agents/openai.yaml), which is 5 of the 52 files — not "a large share". The split recommendation stands on reviewability (5 skill files shared by 60 tutorials, invisible inside 10k lines), not on volume.

The main point is unchanged: four tutorials at 10566 additions review as one unit or not at all.

AI patrol review

@yunwei37

Copy link
Copy Markdown
Member Author

Verdict: design problem

Restating for this head, since the corrections above narrowed the finding to one point: four tutorials in one 10566-line PR. The index entries are present (README.md/README.zh.md are both in the diff) and the skill edits are 5 of 52 files, so both of the smaller objections were withdrawn — what remains is that four tutorials at ~2500 lines each review as one unit or not at all, and the shared .agents/skills/ edits inside them cannot be judged for their effect on the other 60 tutorials.

Land the skill changes first, then one PR per tutorial.

AI patrol review

@yunwei37 yunwei37 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Verdict: design problem — the split is still the blocker, and the build check's red is now proven to be main's

The design verdict above stands unchanged: four tutorials in one 10566-line pull request, and the .agents/skills/ edits inside it cannot be judged for their effect on the other 60 tutorials. Land the skill changes first, then one pull request per tutorial.

What changed this run is the CI red, and it is not this branch's:

  • main's own test-bpftrace.yml run 43657301192 fails at 2026-11-15 00:16 with the identical assertion this head fails at 03:32:
    Error: bpftrace failed to attach or trace the hello function
  • The check greps for two things in the same file — traced and Attaching 1 probe. bpftrace 0.20+ prints Attaching 1 probe... and changed other wording around the same release, so the literal string is the fragile half, not the attach. main failing on it, and a bpftrace-attach-wording-fix branch existing, is the corroboration.
  • build is green on #229, #231 and #235, so the workflow is not red for every branch — only for heads that ran it after the main failure landed.

So the two build failures on this head (jobs 132668523564, 132668523667) do not discriminate against this diff, and they should not hold it once the split happens.

AI patrol review

@yunwei37
yunwei37 force-pushed the feat/four-production-ebpf-tutorials branch from 3f3f553 to 1a46298 Compare November 21, 2026 05:43

@yunwei37 yunwei37 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Verdict: design problem — unchanged by the rebase; the split is still the blocker, and the CI red that used to accompany it was the base's

Rebased 3f3f553a → 1a46298c onto main 861089e. All 13 commits keep their author (LinuxDev9002) and their subjects; the diff is still 52 files, +10566/−172.

The red check was the base, not this change. build failed in src/37-uprobe-rust at bpftrace failed to attach or trace the hello function, because the workflow ran timeout 3 and then looked only for "Attaching 1 probe". #237 fixed both on main (timeout 10, and Attach(ing|ed) 1 probe); this branch predates it, so the rebase brings the repair in. Builds are running on the new head.

What is still open is the review finding, and it is a decision for the author. Four tutorials ship as one 10566-line change:

  • 55-dns-egress, 56-tc-flow-index, 57-oom-watch and the fourth, each ~2500 lines of program plus English and Chinese prose.
  • Five files under .agents/skills/ ride along, so a reviewer cannot judge those edits' effect on the other tutorials in the same diff.

The index entries are correct and both READMEs are present, so the mechanics of adding tutorials are right. What needs splitting is the delivery: the skill changes on their own, then one pull request per tutorial. That is a rework of the author's packaging rather than of the code, so it stays with the author; nothing here is blocked on a maintainer.

AI patrol review

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants