* [PATCH] vfio: selftests: Fix VLA initialisation in vfio_pci_irq_set()
@ 2026-03-17 5:14 mhonap
2026-03-18 20:53 ` Alex Williamson
0 siblings, 1 reply; 3+ messages in thread
From: mhonap @ 2026-03-17 5:14 UTC (permalink / raw)
To: dmatlack, alwilliamson, dave.jiang, ankita
Cc: kjaju, kvm, linux-kernel, linux-kselftest, mhonap, stable
From: Manish Honap <mhonap@nvidia.com>
C does not permit an initialiser expression on a variable-length array
(C99 Section 6.7.9 constraint: "The type of the entity to be initialized
shall not be a variable length array type").
vfio_pci_irq_set() declared:
u8 buf[sizeof(struct vfio_irq_set) + sizeof(int) * count] = {};
where `count` is a runtime function parameter, making `buf` a VLA.
GCC rejects this with (tried with GCC-9.4.0):
error: variable-sized object may not be initialized
Fix by removing the `= {}` initialiser and inserting an explicit
memset() immediately after the declaration. memset() on a VLA is
perfectly legal and achieves the same zero-initialisation on all
conforming C implementations.
Fixes: 19faf6fd969c ("vfio: selftests: Add a helper library for VFIO selftests")
Cc: stable@vger.kernel.org
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: David Matlack <dmatlack@google.com>
Signed-off-by: Manish Honap <mhonap@nvidia.com>
---
This fix is self-contained: it touches only the existing vfio selftest
helper library and carries no dependency on any other patch. It was
originally included as PATCH 20/20 in the CXL Type-2 VFIO passthrough
RFC series [1] but belongs on the vfio list independently, as noted by
Dave Jiang.
[1] https://lore.kernel.org/all/20260311203440.752648-1-mhonap@nvidia.com/
tools/testing/selftests/vfio/lib/vfio_pci_device.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
index fac4c0ecadef..3258e814f450 100644
--- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
+++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
@@ -26,8 +26,10 @@
static void vfio_pci_irq_set(struct vfio_pci_device *device,
u32 index, u32 vector, u32 count, int *fds)
{
- u8 buf[sizeof(struct vfio_irq_set) + sizeof(int) * count] = {};
+ u8 buf[sizeof(struct vfio_irq_set) + sizeof(int) * count];
struct vfio_irq_set *irq = (void *)&buf;
+
+ memset(buf, 0, sizeof(buf));
int *irq_fds = (void *)&irq->data;
irq->argsz = sizeof(buf);
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] vfio: selftests: Fix VLA initialisation in vfio_pci_irq_set()
2026-03-17 5:14 [PATCH] vfio: selftests: Fix VLA initialisation in vfio_pci_irq_set() mhonap
@ 2026-03-18 20:53 ` Alex Williamson
2026-03-20 21:17 ` Alex Williamson
0 siblings, 1 reply; 3+ messages in thread
From: Alex Williamson @ 2026-03-18 20:53 UTC (permalink / raw)
To: mhonap
Cc: dmatlack, dave.jiang, ankita, kjaju, kvm, linux-kernel,
linux-kselftest, stable
On Tue, 17 Mar 2026 10:44:02 +0530
<mhonap@nvidia.com> wrote:
> From: Manish Honap <mhonap@nvidia.com>
>
> C does not permit an initialiser expression on a variable-length array
> (C99 Section 6.7.9 constraint: "The type of the entity to be initialized
> shall not be a variable length array type").
>
> vfio_pci_irq_set() declared:
>
> u8 buf[sizeof(struct vfio_irq_set) + sizeof(int) * count] = {};
>
> where `count` is a runtime function parameter, making `buf` a VLA.
>
> GCC rejects this with (tried with GCC-9.4.0):
>
> error: variable-sized object may not be initialized
>
> Fix by removing the `= {}` initialiser and inserting an explicit
> memset() immediately after the declaration. memset() on a VLA is
> perfectly legal and achieves the same zero-initialisation on all
> conforming C implementations.
>
> Fixes: 19faf6fd969c ("vfio: selftests: Add a helper library for VFIO selftests")
> Cc: stable@vger.kernel.org
> Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> Reviewed-by: David Matlack <dmatlack@google.com>
> Signed-off-by: Manish Honap <mhonap@nvidia.com>
> ---
>
> This fix is self-contained: it touches only the existing vfio selftest
> helper library and carries no dependency on any other patch. It was
> originally included as PATCH 20/20 in the CXL Type-2 VFIO passthrough
> RFC series [1] but belongs on the vfio list independently, as noted by
> Dave Jiang.
>
> [1] https://lore.kernel.org/all/20260311203440.752648-1-mhonap@nvidia.com/
>
> tools/testing/selftests/vfio/lib/vfio_pci_device.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> index fac4c0ecadef..3258e814f450 100644
> --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> @@ -26,8 +26,10 @@
> static void vfio_pci_irq_set(struct vfio_pci_device *device,
> u32 index, u32 vector, u32 count, int *fds)
> {
> - u8 buf[sizeof(struct vfio_irq_set) + sizeof(int) * count] = {};
> + u8 buf[sizeof(struct vfio_irq_set) + sizeof(int) * count];
> struct vfio_irq_set *irq = (void *)&buf;
> +
> + memset(buf, 0, sizeof(buf));
> int *irq_fds = (void *)&irq->data;
>
> irq->argsz = sizeof(buf);
> --
> 2.25.1
>
This unnecessarily split the declaration block. Without objection,
I'll commit this with the following change:
diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
index d306ab81123a..fc75e04ef010 100644
--- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
+++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
@@ -32,9 +32,9 @@ static void vfio_pci_irq_set(struct vfio_pci_device *device,
{
u8 buf[sizeof(struct vfio_irq_set) + sizeof(int) * count];
struct vfio_irq_set *irq = (void *)&buf;
+ int *irq_fds = (void *)&irq->data;
memset(buf, 0, sizeof(buf));
- int *irq_fds = (void *)&irq->data;
irq->argsz = sizeof(buf);
irq->flags = VFIO_IRQ_SET_ACTION_TRIGGER;
Thanks,
Alex
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] vfio: selftests: Fix VLA initialisation in vfio_pci_irq_set()
2026-03-18 20:53 ` Alex Williamson
@ 2026-03-20 21:17 ` Alex Williamson
0 siblings, 0 replies; 3+ messages in thread
From: Alex Williamson @ 2026-03-20 21:17 UTC (permalink / raw)
To: mhonap
Cc: dmatlack, dave.jiang, ankita, kjaju, kvm, linux-kernel,
linux-kselftest, stable, alex
On Wed, 18 Mar 2026 14:53:23 -0600
Alex Williamson <alwilliamson@nvidia.com> wrote:
> On Tue, 17 Mar 2026 10:44:02 +0530
> <mhonap@nvidia.com> wrote:
>
> > From: Manish Honap <mhonap@nvidia.com>
> >
> > C does not permit an initialiser expression on a variable-length array
> > (C99 Section 6.7.9 constraint: "The type of the entity to be initialized
> > shall not be a variable length array type").
> >
> > vfio_pci_irq_set() declared:
> >
> > u8 buf[sizeof(struct vfio_irq_set) + sizeof(int) * count] = {};
> >
> > where `count` is a runtime function parameter, making `buf` a VLA.
> >
> > GCC rejects this with (tried with GCC-9.4.0):
> >
> > error: variable-sized object may not be initialized
> >
> > Fix by removing the `= {}` initialiser and inserting an explicit
> > memset() immediately after the declaration. memset() on a VLA is
> > perfectly legal and achieves the same zero-initialisation on all
> > conforming C implementations.
> >
> > Fixes: 19faf6fd969c ("vfio: selftests: Add a helper library for VFIO selftests")
> > Cc: stable@vger.kernel.org
> > Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> > Reviewed-by: David Matlack <dmatlack@google.com>
> > Signed-off-by: Manish Honap <mhonap@nvidia.com>
> > ---
> >
> > This fix is self-contained: it touches only the existing vfio selftest
> > helper library and carries no dependency on any other patch. It was
> > originally included as PATCH 20/20 in the CXL Type-2 VFIO passthrough
> > RFC series [1] but belongs on the vfio list independently, as noted by
> > Dave Jiang.
> >
> > [1] https://lore.kernel.org/all/20260311203440.752648-1-mhonap@nvidia.com/
> >
> > tools/testing/selftests/vfio/lib/vfio_pci_device.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> > index fac4c0ecadef..3258e814f450 100644
> > --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> > +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> > @@ -26,8 +26,10 @@
> > static void vfio_pci_irq_set(struct vfio_pci_device *device,
> > u32 index, u32 vector, u32 count, int *fds)
> > {
> > - u8 buf[sizeof(struct vfio_irq_set) + sizeof(int) * count] = {};
> > + u8 buf[sizeof(struct vfio_irq_set) + sizeof(int) * count];
> > struct vfio_irq_set *irq = (void *)&buf;
> > +
> > + memset(buf, 0, sizeof(buf));
> > int *irq_fds = (void *)&irq->data;
> >
> > irq->argsz = sizeof(buf);
> > --
> > 2.25.1
> >
>
> This unnecessarily split the declaration block. Without objection,
> I'll commit this with the following change:
>
> diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> index d306ab81123a..fc75e04ef010 100644
> --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> @@ -32,9 +32,9 @@ static void vfio_pci_irq_set(struct vfio_pci_device *device,
> {
> u8 buf[sizeof(struct vfio_irq_set) + sizeof(int) * count];
> struct vfio_irq_set *irq = (void *)&buf;
> + int *irq_fds = (void *)&irq->data;
>
> memset(buf, 0, sizeof(buf));
> - int *irq_fds = (void *)&irq->data;
>
> irq->argsz = sizeof(buf);
> irq->flags = VFIO_IRQ_SET_ACTION_TRIGGER;
Applied with this fix to vfio next branch for v7.1. Thanks,
Alex
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-20 21:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-17 5:14 [PATCH] vfio: selftests: Fix VLA initialisation in vfio_pci_irq_set() mhonap
2026-03-18 20:53 ` Alex Williamson
2026-03-20 21:17 ` Alex Williamson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox