pipeline: add check against loops
Checks
Commit Message
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 <cristian.dumitrescu@intel.com>
Signed-off-by: Harshad Narayane <harshad.suresh.narayane@intel.com>
---
lib/pipeline/rte_swx_pipeline.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
Comments
01/12/2021 13:21, Cristian Dumitrescu:
> 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 <cristian.dumitrescu@intel.com>
> Signed-off-by: Harshad Narayane <harshad.suresh.narayane@intel.com>
Applied, thanks.
> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Sunday, February 13, 2022 7:49 PM
> To: Suresh Narayane, Harshad <harshad.suresh.narayane@intel.com>;
> Dumitrescu, Cristian <cristian.dumitrescu@intel.com>
> Cc: dev@dpdk.org
> Subject: Re: [PATCH] pipeline: add check against loops
>
> 01/12/2021 13:21, Cristian Dumitrescu:
> > 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 <cristian.dumitrescu@intel.com>
> > Signed-off-by: Harshad Narayane <harshad.suresh.narayane@intel.com>
>
> Applied, thanks.
>
>
Thanks, Thomas.
Regards,
Cristian
@@ -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];