aya-rs / aya

Aya is an eBPF library for the Rust programming language, built with a focus on developer experience and operability.
https://aya-rs.dev/book/
Apache License 2.0
3.25k stars 291 forks source link

aya: convert bpf programs to assembly #1000

Open Billy99 opened 4 months ago

Billy99 commented 4 months ago

In aya/src/sys/bpf.rs, there are several simple bpf programs written as byte arrays. Rework these as assembly code and then generate the bytecode.


This change is Reviewable

netlify[bot] commented 4 months ago

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
Latest commit f52b574ebad853368809781f4a96d9ea40a77a10
Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/66a281327fcb8c0008742e64
Deploy Preview https://deploy-preview-1000--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.

alessandrod commented 3 months ago

Hello!

I don't think we should do this, for two reasons:

dave-tucker commented 3 months ago

Hello!

I don't think we should do this, for two reasons:

  • solana_rbpf implements SBPF - an eBPF dialect which is not compatible with kernel eBPF
  • as it is, the patch assembles at runtime, which incurs in a performance cost. If we could fork the solana_rbpf assembler and make it work at compile time that'd be great, and something I've been (idly) thinking about.

The issue here is twofold:

  1. Keeping little and big endian versions of the same programs around isn't nice
  2. Hand-encoding the asm instructions into byte arrays is error prone

If the solana_rbpf assembler is a no-go, that's totally fine. I can take a pass of doing something in macros a little like what libbpf does: https://github.com/libbpf/libbpf/blob/master/src/features.c#L51-L56

alessandrod commented 3 months ago

can take a pass of doing something in macros a little like what libbpf does:

something like this works, iirc there's an existing crate for it even

dave-tucker commented 3 months ago

can take a pass of doing something in macros a little like what libbpf does:

something like this works, iirc there's an existing crate for it even

oh cool! if you find it let me know.

alessandrod commented 3 months ago

can take a pass of doing something in macros a little like what libbpf does:

something like this works, iirc there's an existing crate for it even

oh cool! if you find it let me know.

it's not the one I saw a while ago but this seems ok https://github.com/arcjustin/bpf-ins

mergify[bot] commented 3 months ago

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