[RFC,6/6] rcu: remove VLA warnings

Message ID 20240418103314.40705-7-konstantin.v.ananyev@yandex.ru (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series core libs: remove VLA warnings |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build fail github build: failed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS

Commit Message

Konstantin Ananyev April 18, 2024, 10:33 a.m. UTC
  From: Konstantin Ananyev <konstantin.ananyev@huawei.com>

1) ./lib/rcu/rte_rcu_qsbr.c:359:9: warning: ISO C90 forbids variable length array ‘data’ [-Wvla]
2) ./lib/rcu/rte_rcu_qsbr.c:422:9: warning: ISO C90 forbids variable length array ‘data’ [-Wvla]

In both cases we allocate VLA for one element from RCU deferred queue.
Right now, size of element in RCU queue is not limited by API.
The approach is to introduce some reasonable limitation on RCU DQ
element size.
Choose 128B for now.
With that in place we can replace both VLA occurencies with fixed size
array.

Note that such change need to be treated as API change.
So can be applied only at 24.11.

Signed-off-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>
---
 lib/rcu/rte_rcu_qsbr.c | 7 ++++---
 lib/rcu/rte_rcu_qsbr.h | 5 +++++
 2 files changed, 9 insertions(+), 3 deletions(-)
  

Comments

Morten Brørup April 19, 2024, 12:21 p.m. UTC | #1
> --- a/lib/rcu/rte_rcu_qsbr.h
> +++ b/lib/rcu/rte_rcu_qsbr.h
> @@ -86,6 +86,11 @@ struct __rte_cache_aligned rte_rcu_qsbr_cnt {
>  #define __RTE_QSBR_CNT_MAX ((uint64_t)~0)
>  #define __RTE_QSBR_TOKEN_SIZE sizeof(uint64_t)
> 
> +/**
> + * Max allowable size (in bytes) of each element in the defer queue
> + */
> +#define RTE_QSBR_ESIZE_MAX	(2 * RTE_CACHE_LINE_MIN_SIZE)

Consider moving this to /config/rte_config.h

With or without suggested change...
Acked-By: Morten Brørup <mb@smartsharesystems.com>
  

Patch

diff --git a/lib/rcu/rte_rcu_qsbr.c b/lib/rcu/rte_rcu_qsbr.c
index f08d974d07..6800ef03a5 100644
--- a/lib/rcu/rte_rcu_qsbr.c
+++ b/lib/rcu/rte_rcu_qsbr.c
@@ -278,7 +278,8 @@  rte_rcu_qsbr_dq_create(const struct rte_rcu_qsbr_dq_parameters *params)
 	if (params == NULL || params->free_fn == NULL ||
 		params->v == NULL || params->name == NULL ||
 		params->size == 0 || params->esize == 0 ||
-		(params->esize % 4 != 0)) {
+		(params->esize % 4 != 0) ||
+		params->esize > RTE_QSBR_ESIZE_MAX) {
 		RCU_LOG(ERR, "Invalid input parameter");
 		rte_errno = EINVAL;
 
@@ -356,7 +357,7 @@  int rte_rcu_qsbr_dq_enqueue(struct rte_rcu_qsbr_dq *dq, void *e)
 		return 1;
 	}
 
-	char data[dq->esize];
+	char data[RTE_QSBR_ESIZE_MAX + __RTE_QSBR_TOKEN_SIZE];
 	dq_elem = (__rte_rcu_qsbr_dq_elem_t *)data;
 	/* Start the grace period */
 	dq_elem->token = rte_rcu_qsbr_start(dq->v);
@@ -419,7 +420,7 @@  rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n,
 
 	cnt = 0;
 
-	char data[dq->esize];
+	char data[RTE_QSBR_ESIZE_MAX + __RTE_QSBR_TOKEN_SIZE];
 	/* Check reader threads quiescent state and reclaim resources */
 	while (cnt < n &&
 		rte_ring_dequeue_bulk_elem_start(dq->r, &data,
diff --git a/lib/rcu/rte_rcu_qsbr.h b/lib/rcu/rte_rcu_qsbr.h
index 0506191b80..892e5a31a4 100644
--- a/lib/rcu/rte_rcu_qsbr.h
+++ b/lib/rcu/rte_rcu_qsbr.h
@@ -86,6 +86,11 @@  struct __rte_cache_aligned rte_rcu_qsbr_cnt {
 #define __RTE_QSBR_CNT_MAX ((uint64_t)~0)
 #define __RTE_QSBR_TOKEN_SIZE sizeof(uint64_t)
 
+/**
+ * Max allowable size (in bytes) of each element in the defer queue
+ */
+#define RTE_QSBR_ESIZE_MAX	(2 * RTE_CACHE_LINE_MIN_SIZE)
+
 /* RTE Quiescent State variable structure.
  * This structure has two elements that vary in size based on the
  * 'max_threads' parameter.