Skip to content

Commit

Permalink
backends/tc: Fix issues reported in #4327 (#4484)
Browse files Browse the repository at this point in the history
* tc: Fix ingress pipeline not restoring header pointer from metadata.

Issue reported in #4327.

* tc: Fix lookahead not restoring offsetVar.

Issue reported in #4327.

* Update p4tc golden outputs.
  • Loading branch information
thomascalvert-xlnx authored Feb 29, 2024
1 parent 24ecde7 commit dcae42a
Show file tree
Hide file tree
Showing 33 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backends/ebpf/ebpfParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class StateTranslationVisitor : public CodeGenInspector {
virtual void compileExtractField(const IR::Expression *expr, const IR::StructField *field,
unsigned hdrOffsetBits, EBPFType *type);
virtual void compileExtract(const IR::Expression *destination);
void compileLookahead(const IR::Expression *destination);
virtual void compileLookahead(const IR::Expression *destination);
void compileAdvance(const P4::ExternMethod *ext);
void compileVerify(const IR::MethodCallExpression *expression);

Expand Down
32 changes: 32 additions & 0 deletions backends/tc/ebpfCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ void TCIngressPipelinePNA::emit(EBPF::CodeBuilder *builder) {
builder->newline();
builder->emitIndent();
builder->appendFormat("unsigned %s = hdrMd->%s;", offsetVar.c_str(), offsetVar.c_str());
builder->newline();
builder->emitIndent();
builder->appendFormat("%s = %s + BYTES(%s);", headerStartVar.c_str(),
packetStartVar.c_str(), offsetVar.c_str());
}
builder->newline();
emitHeadersFromCPUMAP(builder);
Expand Down Expand Up @@ -705,6 +709,34 @@ void PnaStateTranslationVisitor::compileExtractField(const IR::Expression *expr,
builder->newline();
}

void PnaStateTranslationVisitor::compileLookahead(const IR::Expression *destination) {
cstring msgStr = Util::printf_format("Parser: lookahead for %s %s",
state->parser->typeMap->getType(destination)->toString(),
destination->toString());
builder->target->emitTraceMessage(builder, msgStr.c_str());

builder->emitIndent();
builder->blockStart();
builder->emitIndent();
builder->appendFormat("u8* %s_save = %s", state->parser->program->headerStartVar.c_str(),
state->parser->program->headerStartVar.c_str());
builder->endOfStatement(true);
builder->emitIndent();
builder->appendFormat("unsigned %s_save = %s", state->parser->program->offsetVar.c_str(),
state->parser->program->offsetVar.c_str());
builder->endOfStatement(true);
compileExtract(destination);
builder->emitIndent();
builder->appendFormat("%s = %s_save", state->parser->program->headerStartVar.c_str(),
state->parser->program->headerStartVar.c_str());
builder->endOfStatement(true);
builder->emitIndent();
builder->appendFormat("%s = %s_save", state->parser->program->offsetVar.c_str(),
state->parser->program->offsetVar.c_str());
builder->endOfStatement(true);
builder->blockEnd(true);
}

// =====================EBPFTablePNA=============================
void EBPFTablePNA::emitKeyType(EBPF::CodeBuilder *builder) {
builder->emitIndent();
Expand Down
1 change: 1 addition & 0 deletions backends/tc/ebpfCodeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class PnaStateTranslationVisitor : public EBPF::PsaStateTranslationVisitor {
protected:
void compileExtractField(const IR::Expression *expr, const IR::StructField *field,
unsigned hdrOffsetBits, EBPF::EBPFType *type) override;
void compileLookahead(const IR::Expression *destination) override;
};

class EBPFPnaParser : public EBPF::EBPFPsaParser {
Expand Down
1 change: 1 addition & 0 deletions testdata/p4tc_samples_outputs/calculator_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
6 changes: 6 additions & 0 deletions testdata/p4tc_samples_outputs/calculator_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h
check_p4calc: {
{
u8* hdr_start_save = hdr_start;
unsigned ebpf_packetOffsetInBits_save = ebpf_packetOffsetInBits;
if ((u8*)ebpf_packetEnd < hdr_start + BYTES(128 + 0)) {
ebpf_errorCode = PacketTooShort;
goto reject;
Expand Down Expand Up @@ -65,9 +66,11 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h
hdr_start += BYTES(128);

hdr_start = hdr_start_save;
ebpf_packetOffsetInBits = ebpf_packetOffsetInBits_save;
}
{
u8* hdr_start_save = hdr_start;
unsigned ebpf_packetOffsetInBits_save = ebpf_packetOffsetInBits;
if ((u8*)ebpf_packetEnd < hdr_start + BYTES(128 + 0)) {
ebpf_errorCode = PacketTooShort;
goto reject;
Expand Down Expand Up @@ -99,9 +102,11 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h
hdr_start += BYTES(128);

hdr_start = hdr_start_save;
ebpf_packetOffsetInBits = ebpf_packetOffsetInBits_save;
}
{
u8* hdr_start_save = hdr_start;
unsigned ebpf_packetOffsetInBits_save = ebpf_packetOffsetInBits;
if ((u8*)ebpf_packetEnd < hdr_start + BYTES(128 + 0)) {
ebpf_errorCode = PacketTooShort;
goto reject;
Expand Down Expand Up @@ -133,6 +138,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h
hdr_start += BYTES(128);

hdr_start = hdr_start_save;
ebpf_packetOffsetInBits = ebpf_packetOffsetInBits_save;
}
u32 select_0;
select_0 = (((((u32)(((u16)tmp_0.p << 8) | ((u16)tmp_2.four & 0xff)) << 8) & ((1 << 24) - 1)) | (((u32)tmp_4.ver & 0xff) & ((1 << 24) - 1))) & ((1 << 24) - 1));
Expand Down
1 change: 1 addition & 0 deletions testdata/p4tc_samples_outputs/checksum_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static __always_inline int process(struct __sk_buff *skb, struct Header_t *h, st
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
h = &(hdrMd->cpumap_hdr);
m = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
1 change: 1 addition & 0 deletions testdata/p4tc_samples_outputs/hash1_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
1 change: 1 addition & 0 deletions testdata/p4tc_samples_outputs/ipip_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
1 change: 1 addition & 0 deletions testdata/p4tc_samples_outputs/matchtype_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
if (!hdrMd)
return TC_ACT_SHOT;
unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits;
hdr_start = pkt + BYTES(ebpf_packetOffsetInBits);
hdr = &(hdrMd->cpumap_hdr);
user_meta = &(hdrMd->cpumap_usermeta);
{
Expand Down

0 comments on commit dcae42a

Please sign in to comment.