Coder Social home page Coder Social logo

Comments (7)

mihaibudiu avatar mihaibudiu commented on May 23, 2024

How about declaring hd as volatile?

from p4c-xdp.

williamtu avatar williamtu commented on May 23, 2024

then it uses only 136 byte
But volatile generates too large program, so verifier says:
"BPF program is too large. Proccessed 65537 insn"

from p4c-xdp.

mihaibudiu avatar mihaibudiu commented on May 23, 2024

That is weird, you would not expect this program to be so large.

Maybe you can play more with volatile; perhaps instead of a second structure hd__ you can just use a volatile pointer to hd and use to make a read between the parser and the deparser.

from p4c-xdp.

williamtu avatar williamtu commented on May 23, 2024

OK.
Actually the program size (number of instructions in the program) with and without volatile is roughly the same. Then it's weird that BPF verifier fails.

from p4c-xdp.

williamtu avatar williamtu commented on May 23, 2024

I actually like the generated with volatile. With volatile, the compile spills the ethernet src/dst to stack using 1 byte instead of 8 byte, so it uses much less stack. However, there is no reordering at all, it's easier to read, but maybe have some performance overhead?

At lease when reading out the hd.x.y, it will read it from the stack and with the right size (no longer fixed to 8 byte).
With volatile, the size is 1232 line of instructions
Without volatile, it is 1363.

Now I suspect there might be an issue in verifier.

from p4c-xdp.

kwjjyn avatar kwjjyn commented on May 23, 2024

Hi,
I using p4c-xdp to compile xdp7.p4 to get .c and .h files. And if I just compile the xdp7.c using clang directly,there's an error that

invalid stack off=-600 size=8

But when I add volatile before struct Headers hd in the xdp7.c , it would be no problem to load.
If there are any other ways to generate .c file with volatile from .p4 file using p4c-xdp compiler?
Otherwise I must add volatile before hd for ervery .c files which cannot be loaded into the kernel due to the hitting BPF stack.
Could you give me some advices?

from p4c-xdp.

osinstom avatar osinstom commented on May 23, 2024

@williamtu did you find the suitable solution for this problem ? We're also facing it in our uBPF backend. The volatile keyword helps to overcome BPF stack size problem, but the verifier doesn't allow to inject program then.

from p4c-xdp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.