Skip to content

Conversation

Copy link

Copilot AI commented Nov 22, 2025

Adds machinery to use kernel structures from vmlinux in Python BPF programs, enabling struct casting, field access on vmlinux structs, and using structs as HashMap key/value types.

Changes

Vmlinux struct handling

  • Pointer casting to vmlinux structs via constructor calls (e.g., struct_request(ctx.di))
  • Field access on vmlinux structs including register fields (e.g., req.__data_len, ctx.r15)
  • CO-RE (Compile Once, Run Everywhere) support via BTF probe_read helpers

Allocation & type system

  • Enhanced allocation pass to handle vmlinux struct pointer casts
  • Map lookup return value allocation based on value type for struct-typed maps
  • Improved debug info generation for struct types

HashMap extensions

  • Structs as HashMap key/value types with proper type handling

New helpers

  • bpf_probe_read_kernel for BTF-based reads
  • Helper wrappers: prandom, smp_processor_id, uid_gid

Example

from vmlinux import struct_request, struct_pt_regs
from pythonbpf import bpf, section

@bpf
@section("kprobe/blk_mq_start_request")
def trace_request(ctx: struct_pt_regs) -> c_int64:
    req = struct_request(ctx.di)  # Cast pointer to struct
    data_len = req.__data_len      # Access struct fields
    timeout = req.timeout
    print(f"request: len={data_len}, timeout={timeout}")
    return c_int64(0)

Moves tests/failing_tests/vmlinux/requests.pytests/passing_tests/vmlinux/requests.py. All existing passing tests unchanged.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Support machinery for request struct functionality Support vmlinux struct casting, field access, and struct-typed HashMaps Nov 22, 2025
Copilot finished work on behalf of varun-r-mallya November 22, 2025 08:07
Copilot AI requested a review from varun-r-mallya November 22, 2025 08:07
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.

2 participants