pipeline: add check against loops

Message ID 20211201122119.77423-1-cristian.dumitrescu@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series pipeline: add check against loops |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS

Commit Message

Cristian Dumitrescu Dec. 1, 2021, 12:21 p.m. UTC
  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

Thomas Monjalon Feb. 13, 2022, 7:49 p.m. UTC | #1
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.
  
Cristian Dumitrescu Feb. 14, 2022, 10:41 a.m. UTC | #2
> -----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
  

Patch

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];