Skip to contentSkip to conversation

lpm: fix unchecked return value

PATCH Superseded Ruifeng Wang 4 participants 10 messages Jul 16, 2020 – Jul 21, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lpm: fix unchecked return value

Coverity complains about unchecked return value of rte_rcu_qsbr_dq_enqueue. By default, defer queue size is big enough to hold all tbl8 groups. When enqueue fails, return error to the user to indicate system issue.

Coverity issue: 360832

Fixes 8a9f8564e9f9 ("lpm: implement RCU rule reclamation")
---
 lib/librte_lpm/rte_lpm.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
lib/librte_lpm/rte_lpm.c +11 -5
index 2db9e16a2..a6d3a7894 100644
@@ -532,11 +532,12 @@ tbl8_alloc(struct rte_lpm *lpm)
 	return group_idx;
 }
 
-static void
+static int
 tbl8_free(struct rte_lpm *lpm, uint32_t tbl8_group_start)
 {
 	struct rte_lpm_tbl_entry zero_tbl8_entry = {0};
 	struct __rte_lpm *internal_lpm;
+	int rc = 0;
 
 	internal_lpm = container_of(lpm, struct __rte_lpm, lpm);
 	if (internal_lpm->v == NULL) {
@@ -552,9 +553,13 @@ tbl8_free(struct rte_lpm *lpm, uint32_t tbl8_group_start)
 				__ATOMIC_RELAXED);
 	} else if (internal_lpm->rcu_mode == RTE_LPM_QSBR_MODE_DQ) {
 		/* Push into QSBR defer queue. */
-		rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
+		rc = rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
 				(void *)&tbl8_group_start);
+		if (rc != 0)
+			RTE_LOG(ERR, LPM, "Failed to push QSBR FIFO\n");
 	}
+
+	return rc;
 }
 
 static __rte_noinline int32_t
@@ -1041,6 +1046,7 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
 	uint32_t tbl24_index, tbl8_group_index, tbl8_group_start, tbl8_index,
 			tbl8_range, i;
 	int32_t tbl8_recycle_index;
+	int rc = 0;
 
 	/*
 	 * Calculate the index into tbl24 and range. Note: All depths larger
@@ -1097,7 +1103,7 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
 		 */
 		lpm->tbl24[tbl24_index].valid = 0;
 		__atomic_thread_fence(__ATOMIC_RELEASE);
-		tbl8_free(lpm, tbl8_group_start);
+		rc = tbl8_free(lpm, tbl8_group_start);
 	} else if (tbl8_recycle_index > -1) {
 		/* Update tbl24 entry. */
 		struct rte_lpm_tbl_entry new_tbl24_entry = {
@@ -1113,10 +1119,10 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
 		__atomic_store(&lpm->tbl24[tbl24_index], &new_tbl24_entry,
 				__ATOMIC_RELAXED);
 		__atomic_thread_fence(__ATOMIC_RELEASE);
-		tbl8_free(lpm, tbl8_group_start);
+		rc = tbl8_free(lpm, tbl8_group_start);
 	}
 #undef group_idx
-	return 0;
+	return (int32_t)rc;
 }
 
 /*
Signature · 1 line
2.17.1
#1 lore raw

Hi Ruifeng,

Quoted 31 lines · Ruifeng Wang

Coverity complains about unchecked return value of rte_rcu_qsbr_dq_enqueue. By default, defer queue size is big enough to hold all tbl8 groups. When enqueue fails, return error to the user to indicate system issue.

Coverity issue: 360832

Fixes 8a9f8564e9f9 ("lpm: implement RCU rule reclamation")
---
  lib/librte_lpm/rte_lpm.c | 16 +++++++++++-----
  1 file changed, 11 insertions(+), 5 deletions(-)
lib/librte_lpm/rte_lpm.c +2 -1
index 2db9e16a2..a6d3a7894 100644
@@ -532,11 +532,12 @@ tbl8_alloc(struct rte_lpm *lpm)
  	return group_idx;
  }
 
-static void
+static int
  tbl8_free(struct rte_lpm *lpm, uint32_t tbl8_group_start)
  {
  	struct rte_lpm_tbl_entry zero_tbl8_entry = {0};
  	struct __rte_lpm *internal_lpm;
+	int rc = 0;
 
  	internal_lpm = container_of(lpm, struct __rte_lpm, lpm);
  	if (internal_lpm->v == NULL) {

lib/librte_lpm/rte_lpm.c tbl8_free(struct rte_lpm *lpm, uint32_t tbl8_group_start) · line 557

Quoted 6 lines
lib/librte_lpm/rte_lpm.c +1 -1
@@ -552,9 +553,13 @@ tbl8_free(struct rte_lpm *lpm, uint32_t tbl8_group_start)
  				__ATOMIC_RELAXED);
  	} else if (internal_lpm->rcu_mode == RTE_LPM_QSBR_MODE_DQ) {
  		/* Push into QSBR defer queue. */
-		rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
+		rc = rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
  				(void *)&tbl8_group_start);

On failure rte_rcu_qsbr_dq_enqueue() returns 1 and sets rte_errno. Consequently, rc value is propagated to delete_depth_big() -> rte_lpm_delete(), and on failure the latter returns "1" value, which conflicts with the LPM API:
"0 on success, negative value otherwise"
I would suggest here to return -rte_errno if rc is equal to 1.

Quoted 39 lines
lib/librte_lpm/rte_lpm.c +8 -3
+		if (rc != 0)
+			RTE_LOG(ERR, LPM, "Failed to push QSBR FIFO\n");
  	}
+
+	return rc;
  }
 
  static __rte_noinline int32_t
@@ -1041,6 +1046,7 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
  	uint32_t tbl24_index, tbl8_group_index, tbl8_group_start, tbl8_index,
  			tbl8_range, i;
  	int32_t tbl8_recycle_index;
+	int rc = 0;
 
  	/*
  	 * Calculate the index into tbl24 and range. Note: All depths larger
@@ -1097,7 +1103,7 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
  		 */
  		lpm->tbl24[tbl24_index].valid = 0;
  		__atomic_thread_fence(__ATOMIC_RELEASE);
-		tbl8_free(lpm, tbl8_group_start);
+		rc = tbl8_free(lpm, tbl8_group_start);
  	} else if (tbl8_recycle_index > -1) {
  		/* Update tbl24 entry. */
  		struct rte_lpm_tbl_entry new_tbl24_entry = {
@@ -1113,10 +1119,10 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
  		__atomic_store(&lpm->tbl24[tbl24_index], &new_tbl24_entry,
  				__ATOMIC_RELAXED);
  		__atomic_thread_fence(__ATOMIC_RELEASE);
-		tbl8_free(lpm, tbl8_group_start);
+		rc = tbl8_free(lpm, tbl8_group_start);
  	}
  #undef group_idx
-	return 0;
+	return (int32_t)rc;
  }
 
  /*
Signature · 2 lines
Regards,
Vladimir
#2 lore raw
Quoted 46 lines

-----Original Message-----
From: Medvedkin, Vladimir <[email protected]>
Sent: Thursday, July 16, 2020 7:00 PM
To: Ruifeng Wang <[email protected]>; Bruce Richardson <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Phil Yang <[email protected]>
Subject: Re: [PATCH] lpm: fix unchecked return value

Hi Ruifeng,

Quoted 1 line · Ruifeng Wang

Coverity complains about unchecked return value of

rte_rcu_qsbr_dq_enqueue.

lib/librte_lpm/rte_lpm.c tbl8_free(struct rte_lpm *lpm, uint32_t

Quoted 30 lines

By default, defer queue size is big enough to hold all tbl8 groups. When enqueue fails, return error to the user to indicate system issue.

Coverity issue: 360832

Fixes 8a9f8564e9f9 ("lpm: implement RCU rule reclamation")
---
  lib/librte_lpm/rte_lpm.c | 16 +++++++++++-----
  1 file changed, 11 insertions(+), 5 deletions(-)
lib/librte_lpm/rte_lpm.c index renamed from lib/librte_lpm/rte_lpm.c +0 -0

2db9e16a2..a6d3a7894 100644

lib/librte_lpm/rte_lpm.c +2 -1
@@ -532,11 +532,12 @@ tbl8_alloc(struct rte_lpm *lpm)
  	return group_idx;
  }
 
-static void
+static int
  tbl8_free(struct rte_lpm *lpm, uint32_t tbl8_group_start)
  {
  	struct rte_lpm_tbl_entry zero_tbl8_entry = {0};
  	struct __rte_lpm *internal_lpm;
+	int rc = 0;
 
  	internal_lpm = container_of(lpm, struct __rte_lpm, lpm);
  	if (internal_lpm->v == NULL) {
@@ -552,9 +553,13 @@ tbl8_free(struct rte_lpm *lpm, uint32_t

tbl8_group_start)

Quoted 14 lines

lib/librte_lpm/rte_lpm.c tbl8_free(struct rte_lpm *lpm, uint32_t tbl8_group_start) · line 557

Quoted 6 lines
lib/librte_lpm/rte_lpm.c +1 -1
  				__ATOMIC_RELAXED);
  	} else if (internal_lpm->rcu_mode == RTE_LPM_QSBR_MODE_DQ) {
  		/* Push into QSBR defer queue. */
-		rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
+		rc = rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
  				(void *)&tbl8_group_start);

On failure rte_rcu_qsbr_dq_enqueue() returns 1 and sets rte_errno. Consequently, rc value is propagated to delete_depth_big() -> rte_lpm_delete(), and on failure the latter returns "1" value, which conflicts with the LPM API:
"0 on success, negative value otherwise"
I would suggest here to return -rte_errno if rc is equal to 1.

Yes, the return value is a little different from LPM APIs. Will change it in next version to keep consistent with other LPM APIs.

Thanks.
/Ruifeng

Quoted 49 lines

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t

Quoted 10 lines
lib/librte_lpm/rte_lpm.c +4 -0
+		if (rc != 0)
+			RTE_LOG(ERR, LPM, "Failed to push QSBR FIFO\n");
  	}
+
+	return rc;
  }
 
  static __rte_noinline int32_t
@@ -1041,6 +1046,7 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t

ip_masked,

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t · line 1046

Quoted 1 line
lib/librte_lpm/rte_lpm.c +0 -0
  	uint32_t tbl24_index, tbl8_group_index, tbl8_group_start,

tbl8_index,

Quoted 7 lines
lib/librte_lpm/rte_lpm.c +1 -0
  			tbl8_range, i;
  	int32_t tbl8_recycle_index;
+	int rc = 0;
 
  	/*
  	 * Calculate the index into tbl24 and range. Note: All depths

larger @@ -1097,7 +1103,7 @@ delete_depth_big(struct rte_lpm *lpm,

uint32_t ip_masked,

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,

Quoted 8 lines
  		 */
  		lpm->tbl24[tbl24_index].valid = 0;
  		__atomic_thread_fence(__ATOMIC_RELEASE);
lib/librte_lpm/rte_lpm.c +1 -1
-		tbl8_free(lpm, tbl8_group_start);
+		rc = tbl8_free(lpm, tbl8_group_start);
  	} else if (tbl8_recycle_index > -1) {
  		/* Update tbl24 entry. */
  		struct rte_lpm_tbl_entry new_tbl24_entry = { @@ -1113,10

+1119,10

Quoted 2 lines

@@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
__atomic_store(&lpm->tbl24[tbl24_index],

&new_tbl24_entry,

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked, · line 1128

Quoted 12 lines
  				__ATOMIC_RELAXED);
  		__atomic_thread_fence(__ATOMIC_RELEASE);
lib/librte_lpm/rte_lpm.c +2 -2
-		tbl8_free(lpm, tbl8_group_start);
+		rc = tbl8_free(lpm, tbl8_group_start);
  	}
  #undef group_idx
-	return 0;
+	return (int32_t)rc;
  }
 
  /*

--
Regards,
Vladimir

#3 lore raw

PATCH v2 1/1 lpm: fix unchecked return value

In reply to Ruifeng Wang

Coverity complains about unchecked return value of rte_rcu_qsbr_dq_enqueue. By default, defer queue size is big enough to hold all tbl8 groups. When enqueue fails, return error to the user to indicate system issue.

Coverity issue: 360832

Fixes 8a9f8564e9f9 ("lpm: implement RCU rule reclamation")

---
v2:
Converted return value to conform to LPM API convention. (Vladimir)

 lib/librte_lpm/rte_lpm.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
lib/librte_lpm/rte_lpm.c +13 -6
index 2db9e16a2..757436f49 100644
@@ -532,11 +532,12 @@ tbl8_alloc(struct rte_lpm *lpm)
 	return group_idx;
 }
 
-static void
+static int32_t
 tbl8_free(struct rte_lpm *lpm, uint32_t tbl8_group_start)
 {
 	struct rte_lpm_tbl_entry zero_tbl8_entry = {0};
 	struct __rte_lpm *internal_lpm;
+	int status;
 
 	internal_lpm = container_of(lpm, struct __rte_lpm, lpm);
 	if (internal_lpm->v == NULL) {
@@ -552,9 +553,15 @@ tbl8_free(struct rte_lpm *lpm, uint32_t tbl8_group_start)
 				__ATOMIC_RELAXED);
 	} else if (internal_lpm->rcu_mode == RTE_LPM_QSBR_MODE_DQ) {
 		/* Push into QSBR defer queue. */
-		rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
+		status = rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
 				(void *)&tbl8_group_start);
+		if (status == 1) {
+			RTE_LOG(ERR, LPM, "Failed to push QSBR FIFO\n");
+			return -rte_errno;
+		}
 	}
+
+	return 0;
 }
 
 static __rte_noinline int32_t
@@ -1040,7 +1047,7 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
 #define group_idx next_hop
 	uint32_t tbl24_index, tbl8_group_index, tbl8_group_start, tbl8_index,
 			tbl8_range, i;
-	int32_t tbl8_recycle_index;
+	int32_t tbl8_recycle_index, status = 0;
 
 	/*
 	 * Calculate the index into tbl24 and range. Note: All depths larger
@@ -1097,7 +1104,7 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
 		 */
 		lpm->tbl24[tbl24_index].valid = 0;
 		__atomic_thread_fence(__ATOMIC_RELEASE);
-		tbl8_free(lpm, tbl8_group_start);
+		status = tbl8_free(lpm, tbl8_group_start);
 	} else if (tbl8_recycle_index > -1) {
 		/* Update tbl24 entry. */
 		struct rte_lpm_tbl_entry new_tbl24_entry = {
@@ -1113,10 +1120,10 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
 		__atomic_store(&lpm->tbl24[tbl24_index], &new_tbl24_entry,
 				__ATOMIC_RELAXED);
 		__atomic_thread_fence(__ATOMIC_RELEASE);
-		tbl8_free(lpm, tbl8_group_start);
+		status = tbl8_free(lpm, tbl8_group_start);
 	}
 #undef group_idx
-	return 0;
+	return status;
 }
 
 /*
Signature · 1 line
2.17.1
#4 lore raw

Hi Ruifeng,

Quoted 69 lines · Ruifeng Wang

Coverity complains about unchecked return value of rte_rcu_qsbr_dq_enqueue. By default, defer queue size is big enough to hold all tbl8 groups. When enqueue fails, return error to the user to indicate system issue.

Coverity issue: 360832

Fixes 8a9f8564e9f9 ("lpm: implement RCU rule reclamation")

---
v2:
Converted return value to conform to LPM API convention. (Vladimir)

  lib/librte_lpm/rte_lpm.c | 19 +++++++++++++------
  1 file changed, 13 insertions(+), 6 deletions(-)
lib/librte_lpm/rte_lpm.c +11 -4
index 2db9e16a2..757436f49 100644
@@ -532,11 +532,12 @@ tbl8_alloc(struct rte_lpm *lpm)
  	return group_idx;
  }
 
-static void
+static int32_t
  tbl8_free(struct rte_lpm *lpm, uint32_t tbl8_group_start)
  {
  	struct rte_lpm_tbl_entry zero_tbl8_entry = {0};
  	struct __rte_lpm *internal_lpm;
+	int status;
 
  	internal_lpm = container_of(lpm, struct __rte_lpm, lpm);
  	if (internal_lpm->v == NULL) {
@@ -552,9 +553,15 @@ tbl8_free(struct rte_lpm *lpm, uint32_t tbl8_group_start)
  				__ATOMIC_RELAXED);
  	} else if (internal_lpm->rcu_mode == RTE_LPM_QSBR_MODE_DQ) {
  		/* Push into QSBR defer queue. */
-		rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
+		status = rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
  				(void *)&tbl8_group_start);
+		if (status == 1) {
+			RTE_LOG(ERR, LPM, "Failed to push QSBR FIFO\n");
+			return -rte_errno;
+		}
  	}
+
+	return 0;
  }
 
  static __rte_noinline int32_t
@@ -1040,7 +1047,7 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
  #define group_idx next_hop
  	uint32_t tbl24_index, tbl8_group_index, tbl8_group_start, tbl8_index,
  			tbl8_range, i;
-	int32_t tbl8_recycle_index;
+	int32_t tbl8_recycle_index, status = 0;
 
  	/*
  	 * Calculate the index into tbl24 and range. Note: All depths larger
@@ -1097,7 +1104,7 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
  		 */
  		lpm->tbl24[tbl24_index].valid = 0;
  		__atomic_thread_fence(__ATOMIC_RELEASE);
-		tbl8_free(lpm, tbl8_group_start);
+		status = tbl8_free(lpm, tbl8_group_start);
  	} else if (tbl8_recycle_index > -1) {
  		/* Update tbl24 entry. */
  		struct rte_lpm_tbl_entry new_tbl24_entry = {

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked, · line 1126

Quoted 9 lines
lib/librte_lpm/rte_lpm.c +2 -2
@@ -1113,10 +1120,10 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
  		__atomic_store(&lpm->tbl24[tbl24_index], &new_tbl24_entry,
  				__ATOMIC_RELAXED);
  		__atomic_thread_fence(__ATOMIC_RELEASE);
-		tbl8_free(lpm, tbl8_group_start);
+		status = tbl8_free(lpm, tbl8_group_start);
  	}
  #undef group_idx
-	return 0;
+	return status;

This will change rte_lpm_delete API. As a suggestion, you can leave it as it was before ("return 0"), and send separate patch (with "return status)" which will be targeted to 20.11.

Quoted 4 lines
lib/librte_lpm/rte_lpm.c +0 -0
  }
 
  /*
Signature · 2 lines
Regards,
Vladimir
#5 lore raw
Quoted 10 lines

-----Original Message-----
From: Medvedkin, Vladimir <[email protected]>
Sent: Saturday, July 18, 2020 1:12 AM
To: Ruifeng Wang <[email protected]>; Bruce Richardson <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Phil Yang <[email protected]>
Subject: Re: [PATCH v2] lpm: fix unchecked return value

Quoted 2 lines

Hi Ruifeng,

Hi Vladimir,

Quoted 78 lines · Ruifeng Wang
Quoted 1 line

Coverity complains about unchecked return value of

rte_rcu_qsbr_dq_enqueue.

lib/librte_lpm/rte_lpm.c tbl8_free(struct rte_lpm *lpm, uint32_t

Quoted 33 lines

By default, defer queue size is big enough to hold all tbl8 groups. When enqueue fails, return error to the user to indicate system issue.

Coverity issue: 360832

Fixes 8a9f8564e9f9 ("lpm: implement RCU rule reclamation")

---
v2:
Converted return value to conform to LPM API convention. (Vladimir)

  lib/librte_lpm/rte_lpm.c | 19 +++++++++++++------
  1 file changed, 13 insertions(+), 6 deletions(-)
lib/librte_lpm/rte_lpm.c index renamed from lib/librte_lpm/rte_lpm.c +0 -0

2db9e16a2..757436f49 100644

lib/librte_lpm/rte_lpm.c +2 -1
@@ -532,11 +532,12 @@ tbl8_alloc(struct rte_lpm *lpm)
  	return group_idx;
  }
 
-static void
+static int32_t
  tbl8_free(struct rte_lpm *lpm, uint32_t tbl8_group_start)
  {
  	struct rte_lpm_tbl_entry zero_tbl8_entry = {0};
  	struct __rte_lpm *internal_lpm;
+	int status;
 
  	internal_lpm = container_of(lpm, struct __rte_lpm, lpm);
  	if (internal_lpm->v == NULL) {
@@ -552,9 +553,15 @@ tbl8_free(struct rte_lpm *lpm, uint32_t

tbl8_group_start)

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t

Quoted 17 lines
lib/librte_lpm/rte_lpm.c +7 -1
  				__ATOMIC_RELAXED);
  	} else if (internal_lpm->rcu_mode == RTE_LPM_QSBR_MODE_DQ) {
  		/* Push into QSBR defer queue. */
-		rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
+		status = rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
  				(void *)&tbl8_group_start);
+		if (status == 1) {
+			RTE_LOG(ERR, LPM, "Failed to push QSBR FIFO\n");
+			return -rte_errno;
+		}
  	}
+
+	return 0;
  }
 
  static __rte_noinline int32_t
@@ -1040,7 +1047,7 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t

ip_masked,

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t · line 1048

Quoted 2 lines
lib/librte_lpm/rte_lpm.c +0 -0
  #define group_idx next_hop
  	uint32_t tbl24_index, tbl8_group_index, tbl8_group_start,

tbl8_index,

Quoted 7 lines
lib/librte_lpm/rte_lpm.c +1 -1
  			tbl8_range, i;
-	int32_t tbl8_recycle_index;
+	int32_t tbl8_recycle_index, status = 0;
 
  	/*
  	 * Calculate the index into tbl24 and range. Note: All depths

larger @@ -1097,7 +1104,7 @@ delete_depth_big(struct rte_lpm *lpm,

uint32_t ip_masked,

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,

Quoted 8 lines
  		 */
  		lpm->tbl24[tbl24_index].valid = 0;
  		__atomic_thread_fence(__ATOMIC_RELEASE);
lib/librte_lpm/rte_lpm.c +1 -1
-		tbl8_free(lpm, tbl8_group_start);
+		status = tbl8_free(lpm, tbl8_group_start);
  	} else if (tbl8_recycle_index > -1) {
  		/* Update tbl24 entry. */
  		struct rte_lpm_tbl_entry new_tbl24_entry = { @@ -1113,10

+1120,10

Quoted 2 lines

@@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
__atomic_store(&lpm->tbl24[tbl24_index],

&new_tbl24_entry,

Quoted 13 lines

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked, · line 1126

Quoted 8 lines
  				__ATOMIC_RELAXED);
  		__atomic_thread_fence(__ATOMIC_RELEASE);
lib/librte_lpm/rte_lpm.c +2 -2
-		tbl8_free(lpm, tbl8_group_start);
+		status = tbl8_free(lpm, tbl8_group_start);
  	}
  #undef group_idx
-	return 0;
+	return status;

This will change rte_lpm_delete API. As a suggestion, you can leave it as it was before ("return 0"), and send separate patch (with "return status)" which will be targeted to 20.11.

Is the change of API because a variable is returned instead of constant?
The patch passed ABI check on Travis: http://mails.dpdk.org/archives/test-report/2020-July/144864.html
So I didn't know there is API/ABI issue.

Thanks.
/Ruifeng

Quoted 8 lines
Quoted 4 lines
  }

/*

--
Regards,
Vladimir

#6 lore raw

Hi Ruifeng,

Quoted 106 lines · Ruifeng Wang
Quoted 10 lines

-----Original Message-----
From: Medvedkin, Vladimir <[email protected]>
Sent: Saturday, July 18, 2020 1:12 AM
To: Ruifeng Wang <[email protected]>; Bruce Richardson <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Phil Yang <[email protected]>
Subject: Re: [PATCH v2] lpm: fix unchecked return value

Quoted 2 lines

Hi Ruifeng,

Hi Vladimir,

Quoted 78 lines · Ruifeng Wang
Quoted 1 line

Coverity complains about unchecked return value of

rte_rcu_qsbr_dq_enqueue.

lib/librte_lpm/rte_lpm.c tbl8_free(struct rte_lpm *lpm, uint32_t

Quoted 33 lines

By default, defer queue size is big enough to hold all tbl8 groups. When enqueue fails, return error to the user to indicate system issue.

Coverity issue: 360832

Fixes 8a9f8564e9f9 ("lpm: implement RCU rule reclamation")

---
v2:
Converted return value to conform to LPM API convention. (Vladimir)

   lib/librte_lpm/rte_lpm.c | 19 +++++++++++++------
   1 file changed, 13 insertions(+), 6 deletions(-)
lib/librte_lpm/rte_lpm.c index renamed from lib/librte_lpm/rte_lpm.c +0 -0

2db9e16a2..757436f49 100644

lib/librte_lpm/rte_lpm.c +2 -1
@@ -532,11 +532,12 @@ tbl8_alloc(struct rte_lpm *lpm)
   	return group_idx;
   }
 
-static void
+static int32_t
   tbl8_free(struct rte_lpm *lpm, uint32_t tbl8_group_start)
   {
   	struct rte_lpm_tbl_entry zero_tbl8_entry = {0};
   	struct __rte_lpm *internal_lpm;
+	int status;
 
   	internal_lpm = container_of(lpm, struct __rte_lpm, lpm);
   	if (internal_lpm->v == NULL) {
@@ -552,9 +553,15 @@ tbl8_free(struct rte_lpm *lpm, uint32_t

tbl8_group_start)

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t

Quoted 17 lines
lib/librte_lpm/rte_lpm.c +7 -1
   				__ATOMIC_RELAXED);
   	} else if (internal_lpm->rcu_mode == RTE_LPM_QSBR_MODE_DQ) {
   		/* Push into QSBR defer queue. */
-		rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
+		status = rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
   				(void *)&tbl8_group_start);
+		if (status == 1) {
+			RTE_LOG(ERR, LPM, "Failed to push QSBR FIFO\n");
+			return -rte_errno;
+		}
   	}
+
+	return 0;
   }
 
   static __rte_noinline int32_t
@@ -1040,7 +1047,7 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t

ip_masked,

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t · line 1048

Quoted 2 lines
lib/librte_lpm/rte_lpm.c +0 -0
   #define group_idx next_hop
   	uint32_t tbl24_index, tbl8_group_index, tbl8_group_start,

tbl8_index,

Quoted 7 lines
lib/librte_lpm/rte_lpm.c +1 -1
   			tbl8_range, i;
-	int32_t tbl8_recycle_index;
+	int32_t tbl8_recycle_index, status = 0;
 
   	/*
   	 * Calculate the index into tbl24 and range. Note: All depths

larger @@ -1097,7 +1104,7 @@ delete_depth_big(struct rte_lpm *lpm,

uint32_t ip_masked,

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,

Quoted 8 lines
   		 */
   		lpm->tbl24[tbl24_index].valid = 0;
   		__atomic_thread_fence(__ATOMIC_RELEASE);
lib/librte_lpm/rte_lpm.c +1 -1
-		tbl8_free(lpm, tbl8_group_start);
+		status = tbl8_free(lpm, tbl8_group_start);
   	} else if (tbl8_recycle_index > -1) {
   		/* Update tbl24 entry. */
   		struct rte_lpm_tbl_entry new_tbl24_entry = { @@ -1113,10

+1120,10

Quoted 2 lines

@@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
__atomic_store(&lpm->tbl24[tbl24_index],

&new_tbl24_entry,

Quoted 13 lines

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked, · line 1126

Quoted 8 lines
   				__ATOMIC_RELAXED);
   		__atomic_thread_fence(__ATOMIC_RELEASE);
lib/librte_lpm/rte_lpm.c +2 -2
-		tbl8_free(lpm, tbl8_group_start);
+		status = tbl8_free(lpm, tbl8_group_start);
   	}
   #undef group_idx
-	return 0;
+	return status;

This will change rte_lpm_delete API. As a suggestion, you can leave it as it was before ("return 0"), and send separate patch (with "return status)" which will be targeted to 20.11.

Quoted 3 lines

Is the change of API because a variable is returned instead of constant?
The patch passed ABI check on Travis: http://mails.dpdk.org/archives/test-report/2020-July/144864.html
So I didn't know there is API/ABI issue.

Because new error status codes are returned. At the moment rte_lpm_delete() returns only -EINVAL. After patches it will also returns -ENOSPC. The user's code may not handle this returned error status.

On the other hand, from documentation about returned value:
"0 on success, negative value otherwise",
and given the fact that this behavior is only after calling rte_lpm_rcu_qsbr_add(), I think we can accept this patch. Bruce, please correct me.

Quoted 11 lines

Thanks.
/Ruifeng

Quoted 8 lines
Quoted 4 lines
   }
   /*

--
Regards,
Vladimir

Signature · 2 lines
Regards,
Vladimir
#7 lore raw
Quoted 118 lines · Vladimir

Hi Ruifeng,

Quoted 106 lines · Ruifeng Wang
Quoted 10 lines

-----Original Message-----
From: Medvedkin, Vladimir <[email protected]>
Sent: Saturday, July 18, 2020 1:12 AM
To: Ruifeng Wang <[email protected]>; Bruce Richardson <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Phil Yang <[email protected]>
Subject: Re: [PATCH v2] lpm: fix unchecked return value

Quoted 2 lines

Hi Ruifeng,

Hi Vladimir,

Quoted 78 lines · Ruifeng Wang
Quoted 1 line

Coverity complains about unchecked return value of

rte_rcu_qsbr_dq_enqueue.

lib/librte_lpm/rte_lpm.c tbl8_free(struct rte_lpm *lpm, uint32_t

Quoted 33 lines

By default, defer queue size is big enough to hold all tbl8 groups. When enqueue fails, return error to the user to indicate system issue.

Coverity issue: 360832

Fixes 8a9f8564e9f9 ("lpm: implement RCU rule reclamation")

---
v2:
Converted return value to conform to LPM API convention. (Vladimir)

   lib/librte_lpm/rte_lpm.c | 19 +++++++++++++------
   1 file changed, 13 insertions(+), 6 deletions(-)
lib/librte_lpm/rte_lpm.c index renamed from lib/librte_lpm/rte_lpm.c +0 -0

2db9e16a2..757436f49 100644

lib/librte_lpm/rte_lpm.c +2 -1
@@ -532,11 +532,12 @@ tbl8_alloc(struct rte_lpm *lpm)
   	return group_idx;
   }
 
-static void
+static int32_t
   tbl8_free(struct rte_lpm *lpm, uint32_t tbl8_group_start)
   {
   	struct rte_lpm_tbl_entry zero_tbl8_entry = {0};
   	struct __rte_lpm *internal_lpm;
+	int status;
 
   	internal_lpm = container_of(lpm, struct __rte_lpm, lpm);
   	if (internal_lpm->v == NULL) {
@@ -552,9 +553,15 @@ tbl8_free(struct rte_lpm *lpm, uint32_t

tbl8_group_start)

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t

Quoted 17 lines
lib/librte_lpm/rte_lpm.c +7 -1
   				__ATOMIC_RELAXED);
   	} else if (internal_lpm->rcu_mode == RTE_LPM_QSBR_MODE_DQ) {
   		/* Push into QSBR defer queue. */
-		rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
+		status = rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
   				(void *)&tbl8_group_start);
+		if (status == 1) {
+			RTE_LOG(ERR, LPM, "Failed to push QSBR FIFO\n");
+			return -rte_errno;
+		}
   	}
+
+	return 0;
   }
 
   static __rte_noinline int32_t
@@ -1040,7 +1047,7 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t

ip_masked,

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t · line 1048

Quoted 2 lines
lib/librte_lpm/rte_lpm.c +0 -0
   #define group_idx next_hop
   	uint32_t tbl24_index, tbl8_group_index, tbl8_group_start,

tbl8_index,

Quoted 7 lines
lib/librte_lpm/rte_lpm.c +1 -1
   			tbl8_range, i;
-	int32_t tbl8_recycle_index;
+	int32_t tbl8_recycle_index, status = 0;
 
   	/*
   	 * Calculate the index into tbl24 and range. Note: All depths

larger @@ -1097,7 +1104,7 @@ delete_depth_big(struct rte_lpm *lpm,

uint32_t ip_masked,

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,

Quoted 8 lines
   		 */
   		lpm->tbl24[tbl24_index].valid = 0;
   		__atomic_thread_fence(__ATOMIC_RELEASE);
lib/librte_lpm/rte_lpm.c +1 -1
-		tbl8_free(lpm, tbl8_group_start);
+		status = tbl8_free(lpm, tbl8_group_start);
   	} else if (tbl8_recycle_index > -1) {
   		/* Update tbl24 entry. */
   		struct rte_lpm_tbl_entry new_tbl24_entry = { @@ -1113,10

+1120,10

Quoted 2 lines

@@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
__atomic_store(&lpm->tbl24[tbl24_index],

&new_tbl24_entry,

Quoted 13 lines

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked, · line 1126

Quoted 8 lines
   				__ATOMIC_RELAXED);
   		__atomic_thread_fence(__ATOMIC_RELEASE);
lib/librte_lpm/rte_lpm.c +2 -2
-		tbl8_free(lpm, tbl8_group_start);
+		status = tbl8_free(lpm, tbl8_group_start);
   	}
   #undef group_idx
-	return 0;
+	return status;

This will change rte_lpm_delete API. As a suggestion, you can leave it as it was before ("return 0"), and send separate patch (with "return status)" which will be targeted to 20.11.

Quoted 3 lines

Is the change of API because a variable is returned instead of constant?
The patch passed ABI check on Travis: http://mails.dpdk.org/archives/test-report/2020-July/144864.html
So I didn't know there is API/ABI issue.

Because new error status codes are returned. At the moment rte_lpm_delete() returns only -EINVAL. After patches it will also returns -ENOSPC. The user's code may not handle this returned error status.

Quoted 6 lines

On the other hand, from documentation about returned value:
"0 on success, negative value otherwise",
and given the fact that this behavior is only after calling rte_lpm_rcu_qsbr_add(), I think we can accept this patch. Bruce, please correct me.

That sounds reasonable to me. No change in the committed ABI, since the specific values are not called out.

#8 lore raw
Quoted 120 lines · Bruce Richardson
Quoted 118 lines · Vladimir

Hi Ruifeng,

Quoted 101 lines · Ruifeng Wang
Quoted 10 lines

-----Original Message-----
From: Medvedkin, Vladimir <[email protected]>
Sent: Saturday, July 18, 2020 1:12 AM
To: Ruifeng Wang <[email protected]>; Bruce Richardson <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Phil Yang <[email protected]>
Subject: Re: [PATCH v2] lpm: fix unchecked return value

Quoted 2 lines

Hi Ruifeng,

Hi Vladimir,

Quoted 87 lines · Ruifeng Wang
Quoted 1 line

Coverity complains about unchecked return value of

rte_rcu_qsbr_dq_enqueue.

lib/librte_lpm/rte_lpm.c tbl8_free(struct rte_lpm *lpm, uint32_t

Quoted 33 lines

By default, defer queue size is big enough to hold all tbl8 groups. When enqueue fails, return error to the user to indicate system issue.

Coverity issue: 360832

Fixes 8a9f8564e9f9 ("lpm: implement RCU rule reclamation")

---
v2:
Converted return value to conform to LPM API convention. (Vladimir)

   lib/librte_lpm/rte_lpm.c | 19 +++++++++++++------
   1 file changed, 13 insertions(+), 6 deletions(-)
lib/librte_lpm/rte_lpm.c index renamed from lib/librte_lpm/rte_lpm.c +0 -0

2db9e16a2..757436f49 100644

lib/librte_lpm/rte_lpm.c +2 -1
@@ -532,11 +532,12 @@ tbl8_alloc(struct rte_lpm *lpm)
        return group_idx;
   }
 
-static void
+static int32_t
   tbl8_free(struct rte_lpm *lpm, uint32_t tbl8_group_start)
   {
        struct rte_lpm_tbl_entry zero_tbl8_entry = {0};
        struct __rte_lpm *internal_lpm;
+       int status;
 
        internal_lpm = container_of(lpm, struct __rte_lpm, lpm);
        if (internal_lpm->v == NULL) {
@@ -552,9 +553,15 @@ tbl8_free(struct rte_lpm *lpm, uint32_t

tbl8_group_start)

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t

Quoted 17 lines
lib/librte_lpm/rte_lpm.c +7 -1
                                __ATOMIC_RELAXED);
        } else if (internal_lpm->rcu_mode == RTE_LPM_QSBR_MODE_DQ) {
                /* Push into QSBR defer queue. */
-               rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
+               status = rte_rcu_qsbr_dq_enqueue(internal_lpm->dq,
                                (void *)&tbl8_group_start);
+               if (status == 1) {
+                       RTE_LOG(ERR, LPM, "Failed to push QSBR FIFO\n");
+                       return -rte_errno;
+               }
        }
+
+       return 0;
   }
 
   static __rte_noinline int32_t
@@ -1040,7 +1047,7 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t

ip_masked,

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t · line 1048

Quoted 2 lines
lib/librte_lpm/rte_lpm.c +0 -0
   #define group_idx next_hop
        uint32_t tbl24_index, tbl8_group_index, tbl8_group_start,

tbl8_index,

Quoted 7 lines
lib/librte_lpm/rte_lpm.c +1 -1
                        tbl8_range, i;
-       int32_t tbl8_recycle_index;
+       int32_t tbl8_recycle_index, status = 0;
 
        /*
         * Calculate the index into tbl24 and range. Note: All depths

larger @@ -1097,7 +1104,7 @@ delete_depth_big(struct rte_lpm *lpm,

uint32_t ip_masked,

lib/librte_lpm/rte_lpm.c delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,

Quoted 8 lines
                 */
                lpm->tbl24[tbl24_index].valid = 0;
                __atomic_thread_fence(__ATOMIC_RELEASE);
lib/librte_lpm/rte_lpm.c +1 -1
-               tbl8_free(lpm, tbl8_group_start);
+               status = tbl8_free(lpm, tbl8_group_start);
        } else if (tbl8_recycle_index > -1) {
                /* Update tbl24 entry. */
                struct rte_lpm_tbl_entry new_tbl24_entry = { @@ -1113,10

+1120,10

Quoted 2 lines

@@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,

                __atomic_store(&lpm->tbl24[tbl24_index],

&new_tbl24_entry,

Quoted 8 lines
                                __ATOMIC_RELAXED);
                __atomic_thread_fence(__ATOMIC_RELEASE);
lib/librte_lpm/rte_lpm.c +2 -2
-               tbl8_free(lpm, tbl8_group_start);
+               status = tbl8_free(lpm, tbl8_group_start);
        }
   #undef group_idx
-       return 0;
+       return status;
Quoted 8 lines
Quoted 4 lines

This will change rte_lpm_delete API. As a suggestion, you can leave it as it was before ("return 0"), and send separate patch (with "return status)" which will be targeted to 20.11.

Is the change of API because a variable is returned instead of constant?
The patch passed ABI check on Travis: http://mails.dpdk.org/archives/test-report/2020-July/144864.html
So I didn't know there is API/ABI issue.

Because new error status codes are returned. At the moment rte_lpm_delete() returns only -EINVAL. After patches it will also returns -ENOSPC. The user's code may not handle this returned error status.

Quoted 9 lines
Quoted 6 lines

On the other hand, from documentation about returned value:
"0 on success, negative value otherwise",
and given the fact that this behavior is only after calling rte_lpm_rcu_qsbr_add(), I think we can accept this patch. Bruce, please correct me.

That sounds reasonable to me. No change in the committed ABI, since the specific values are not called out.

I will take this as a second ack and merge this fix for rc2. Thanks.

Signature · 1 line
David Marchand
Acked-by Vladimir Medvedkin Acked-by Bruce Richardson on v2 1/1 Applied
#9 lore raw
In reply to Ruifeng Wang
Quoted 9 lines · Ruifeng Wang

Coverity complains about unchecked return value of rte_rcu_qsbr_dq_enqueue. By default, defer queue size is big enough to hold all tbl8 groups. When enqueue fails, return error to the user to indicate system issue.

Coverity issue: 360832

Fixes 8a9f8564e9f9 ("lpm: implement RCU rule reclamation")

Applied, thanks.

Signature · 1 line
David Marchand