Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eBPF-PSA: ingress to egress (I2E) cloning fails to compile #4958

Open
Trigary opened this issue Oct 10, 2024 · 2 comments
Open

eBPF-PSA: ingress to egress (I2E) cloning fails to compile #4958

Trigary opened this issue Oct 10, 2024 · 2 comments
Assignees
Labels
bug This behavior is unintended and should be fixed. ebpf-psa Topics related to the eBPF PSA back end

Comments

@Trigary
Copy link
Contributor

Trigary commented Oct 10, 2024

I am trying to compile a simple P4 program containing ingress to egress packet cloning (mirroring) logic with the p4c-ebpf backend targeting the PSA architecture, but the compilation fails, because invalid C code gets generated by the P4C compiler.

My minimalistic P4 program is almost completely empty with the following exceptions. The code follows the example found in the PSA specification.

control IngressImpl(inout headers_t hdr,
                    inout empty_meta_t user_meta,
                    in psa_ingress_input_metadata_t istd,
                    inout psa_ingress_output_metadata_t ostd) {
    apply {
        ostd.clone = true;
        ostd.clone_session_id = PSA_CLONE_SESSION_TO_CPU;
    }
}

control IngressDeparserImpl(packet_out packet,
                            out clone_i2e_meta_t clone_i2e_meta,
                            out empty_meta_t resubmit_meta,
                            out empty_meta_t normal_meta,
                            inout headers_t hdr,
                            in empty_meta_t user_meta,
                            in psa_ingress_output_metadata_t istd) {
    CommonDeparserImpl() deparser;
    apply {
        if (psa_clone_i2e(istd)) {
            clone_i2e_meta.test = 42;
        }
        deparser.apply(packet, hdr);
    }
}

I invoke the p4c-ebpf compiler via the Makefile found at backends/ebpf/runtime/kernel.mk. The compilation outputs the following:

$ cd $P4C_ROOT_DIR && make -f backends/ebpf/runtime/kernel.mk BPFOBJ=cloning_switch.c P4FILE=/dir/to/cloning_switch.p4 P4ARGS=--Wwarn psa

make[1]: Entering directory '/home/vm/p4c'
p4c-ebpf -I/home/vm/p4c/backends/ebpf/runtime//p4include --target kernel -o cloning_switch.c /home/vm/project/switch/debug/cloning_switch.p4 --Wwarn --arch psa;
Setting XDP2TC 'meta' mode by default for TC-based hook.
clang  -O2 -g -c -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value  -Wno-pointer-sign -Wno-compare-distinct-pointer-types -Wno-gnu-variable-sized-type-not-at-end -Wno-address-of-packed-member -Wno-tautological-compare -Wno-unknown-warning-option -Wnoparentheses-equality -I/home/vm/p4c/backends/ebpf/runtime/ -I/home/vm/p4c/backends/ebpf/runtime/usr/include/ -I/home/vm/p4c/backends/ebpf/runtime/contrib/libbpf/include/uapi/ -emit-llvm -DBTF -c -o cloning_switch.bc cloning_switch.c
make[1]: Leaving directory '/home/vm/p4c'
/home/vm/project/switch/debug/cloning_switch.p4(27): [--Wwarn=uninitialized_out_param] warning: out parameter 'clone_i2e_meta' may be uninitialized when 'IngressDeparserImpl' terminates
                            out clone_i2e_meta_t clone_i2e_meta,
                                                 ^^^^^^^^^^^^^^
/home/vm/natwork-t52/switch/debug/cloning_switch.p4(26)
control IngressDeparserImpl(packet_out packet,
        ^^^^^^^^^^^^^^^^^^^
cloning_switch.c:115:41: warning: incompatible pointer types assigning to 'u32 *' (aka 'unsigned int *') from 'const u8 *' (aka 'const unsigned char *') [-Wincompatible-pointer-types]
            if (data_size == 8) current = data + 4;
                                        ^ ~~~~~~~~
cloning_switch.c:375:1: error: expected expression
;
^
cloning_switch.c:377:17: error: use of undeclared identifier 'clone_i2e_meta'
                clone_i2e_meta.test = 42;            }
                ^
1 warning and 2 errors generated.
make[1]: *** [backends/ebpf/runtime/kernel.mk:81: psa] Error 1

The error at line 375 is completely justified based on the relevant part of the generated C code:

// [...]
    accept: {
        struct psa_ingress_input_metadata_t istd = {
            .ingress_port = ebpf_input_port,
            .packet_path = compiler_meta__->packet_path,
            .parser_error = ebpf_errorCode,
    };
        u8 hit;
        {
            ostd->clone = true;
                        ostd->clone_session_id = 0;
        }
    }
    {
        u8 tmp;
{
            tmp = /* psa_clone_i2e(istd) */
;
            if (tmp) {
                clone_i2e_meta.test = 42;            }

        }
// [...]

p4c version: Version 1.2.4.2 (SHA: 624c6be80 BUILD: RELEASE)
The P4 source file and the generated C file have been attached: cloning_switch.zip

@fruffy fruffy added ebpf-psa Topics related to the eBPF PSA back end bug This behavior is unintended and should be fixed. labels Oct 11, 2024
@Trigary Trigary changed the title eBPF-PSA: ingress to egress (I2C) cloning fails to compile eBPF-PSA: ingress to egress (I2E) cloning fails to compile Oct 25, 2024
@Trigary
Copy link
Contributor Author

Trigary commented Oct 25, 2024

Some tests verify that the cloning functionality is supported, but they don't try to pass data using the clone_i2e_meta or clone_e2e_meta parameters. I'm assuming only these parameters aren't implemented yet.

@Trigary
Copy link
Contributor Author

Trigary commented Oct 25, 2024

normal_meta also seems to be unsupported, leaving only headers to facilitate communication between the ingress and egress pipelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This behavior is unintended and should be fixed. ebpf-psa Topics related to the eBPF PSA back end
Projects
None yet
Development

No branches or pull requests

4 participants