rcu: remove VLAs

Message ID 1741311613-26629-1-git-send-email-andremue@linux.microsoft.com (mailing list archive)
State New
Delegated to: David Marchand
Headers
Series rcu: remove VLAs |

Checks

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

Commit Message

Andre Muezerie March 7, 2025, 1:40 a.m. UTC
There are two lines that were using VLAs, which are not supported by
MSVC.

1)
../lib/rcu/rte_rcu_qsbr.c:326:12: warning: variable length array used [-Wvla]
  326 |         char data[dq->esize];
      |                   ^~~~~~~~~
2)
../lib/rcu/rte_rcu_qsbr.c:389:12: warning: variable length array used [-Wvla]
  389 |         char data[dq->esize];
      |                   ^~~~~~~~~

The short-term fix is to use alloca, to allow progress with the msvc
compatibility work.
The long-term plan involves API changes and therefore can only be applied
with a new release. This long-term plan consists of introducing some
reasonable limitation on RCU DQ element size.

Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
---
 lib/rcu/meson.build    | 7 -------
 lib/rcu/rte_rcu_qsbr.c | 6 +++---
 2 files changed, 3 insertions(+), 10 deletions(-)
  

Comments

David Marchand April 10, 2025, 11:39 a.m. UTC | #1
On Fri, Mar 7, 2025 at 2:40 AM Andre Muezerie
<andremue@linux.microsoft.com> wrote:
>
> There are two lines that were using VLAs, which are not supported by
> MSVC.
>
> 1)
> ../lib/rcu/rte_rcu_qsbr.c:326:12: warning: variable length array used [-Wvla]
>   326 |         char data[dq->esize];
>       |                   ^~~~~~~~~
> 2)
> ../lib/rcu/rte_rcu_qsbr.c:389:12: warning: variable length array used [-Wvla]
>   389 |         char data[dq->esize];
>       |                   ^~~~~~~~~
>
> The short-term fix is to use alloca, to allow progress with the msvc
> compatibility work.
> The long-term plan involves API changes and therefore can only be applied
> with a new release. This long-term plan consists of introducing some
> reasonable limitation on RCU DQ element size.
>
> Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>

Honnappa, any objection?
  

Patch

diff --git a/lib/rcu/meson.build b/lib/rcu/meson.build
index fb1f49ba63..71143f5210 100644
--- a/lib/rcu/meson.build
+++ b/lib/rcu/meson.build
@@ -11,10 +11,3 @@  sources = files('rte_rcu_qsbr.c')
 headers = files('rte_rcu_qsbr.h')
 
 deps += ['ring']
-
-# FIXME: this library was enabled for mingw target (a Windows target).
-# Relying on no_wvla_cflag would trigger a build error until the VLA in rte_rcu_qsbr.c is removed.
-# Disable the warning here for now.
-if cc.has_argument('-Wvla')
-    cflags += '-Wno-vla'
-endif
diff --git a/lib/rcu/rte_rcu_qsbr.c b/lib/rcu/rte_rcu_qsbr.c
index dbf31501a6..3f619e1607 100644
--- a/lib/rcu/rte_rcu_qsbr.c
+++ b/lib/rcu/rte_rcu_qsbr.c
@@ -323,7 +323,7 @@  int rte_rcu_qsbr_dq_enqueue(struct rte_rcu_qsbr_dq *dq, void *e)
 		return 1;
 	}
 
-	char data[dq->esize];
+	char *data = alloca(dq->esize);
 	dq_elem = (__rte_rcu_qsbr_dq_elem_t *)data;
 	/* Start the grace period */
 	dq_elem->token = rte_rcu_qsbr_start(dq->v);
@@ -386,10 +386,10 @@  rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n,
 
 	cnt = 0;
 
-	char data[dq->esize];
+	char *data = alloca(dq->esize);
 	/* Check reader threads quiescent state and reclaim resources */
 	while (cnt < n &&
-		rte_ring_dequeue_bulk_elem_start(dq->r, &data,
+		rte_ring_dequeue_bulk_elem_start(dq->r, data,
 					dq->esize, 1, available) != 0) {
 		dq_elem = (__rte_rcu_qsbr_dq_elem_t *)data;