From dbce95e363392f0699a9a38c49d78d132511b9b8 Mon Sep 17 00:00:00 2001 From: Cristian Dumitrescu Date: Wed, 1 Dec 2021 12:21:19 +0000 Subject: [PATCH] pipeline: add check against loops Detect when a jump instruction, either conditional or unconditional, is jumping to itself, thus creating a loop, which is not allowed in data plane code. Signed-off-by: Cristian Dumitrescu Signed-off-by: Harshad Narayane --- lib/pipeline/rte_swx_pipeline.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c index c332d44bd1..1a50c4bb72 100644 --- a/lib/pipeline/rte_swx_pipeline.c +++ b/lib/pipeline/rte_swx_pipeline.c @@ -6000,6 +6000,19 @@ instr_label_check(struct instruction_data *instruction_data, CHECK(strcmp(label, instruction_data[j].label), EINVAL); } + /* Check that no jump instruction (either conditional or not) can jump to itself (loop). */ + for (i = 0; i < n_instructions; i++) { + struct instruction_data *data = &instruction_data[i]; + char *label = data->label; + char *jmp_label = data->jmp_label; + + /* Continue if this instruction does not have a label or it is not a jump. */ + if (!label[0] || !jmp_label[0]) + continue; + + CHECK(strcmp(label, jmp_label), EINVAL); + } + /* Get users for each instruction label. */ for (i = 0; i < n_instructions; i++) { struct instruction_data *data = &instruction_data[i];