From: Vipin Sharma <vipinsh@google.com>
To: Alex Mastro <amastro@fb.com>
Cc: David Matlack <dmatlack@google.com>,
Alex Williamson <alex@shazbot.org>,
Shuah Khan <shuah@kernel.org>,
Raghavendra Rao Ananta <rananta@google.com>,
kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] selftests/vfio: avoid VLAs
Date: Fri, 12 Jun 2026 16:45:43 -0700 [thread overview]
Message-ID: <20260612234154.GA667942.vipinsh@google.com> (raw)
In-Reply-To: <20260612-scratch-amastro-vfio-selftests-avoid-vlas-v1-1-ba3acb635f0a@fb.com>
On Fri, Jun 12, 2026 at 02:58:18PM -0700, Alex Mastro wrote:
> Allocate VFIO ioctl requests dynamically instead of using VLAs. GCC 11.5.0
> rejects initialized VLAs with:
>
> error: variable-sized object may not be initialized
>
> The replaced stack u8 arrays also do not guarantee native struct alignment
> for the aliased pointers.
>
> Fixes: 19faf6fd969c ("vfio: selftests: Add a helper library for VFIO selftests")
> Fixes: 20face8c75ff ("vfio: selftests: Add helper to set/override a vf_token")
> Signed-off-by: Alex Mastro <amastro@fb.com>
> Assisted-by: Codex:gpt-5.5-high
> ---
> tools/testing/selftests/vfio/lib/vfio_pci_device.c | 28 +++++++++++++---------
> 1 file changed, 17 insertions(+), 11 deletions(-)
>
> diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> index 94dc5fcecbeb..0b437435cce1 100644
> --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> @@ -30,13 +30,12 @@
> 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];
> - struct vfio_irq_set *irq = (void *)&buf;
> - int *irq_fds = (void *)&irq->data;
> + struct vfio_irq_set *irq;
> + size_t irq_size = sizeof(*irq) + sizeof(int) * count;
Nit: Can you change it to Reverse Fir Tree style? Same for the other
change.
Other than that this looks good. Thanks!
Tested-by: Vipin Sharma <vipinsh@google.com>
Reviewed-by: Vipin Sharma <vipinsh@google.com>
index 0b437435cce1..c70636c214bc 100644
--- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
+++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
@@ -31,8 +31,9 @@ static void vfio_pci_irq_set(struct vfio_pci_device *device,
u32 index, u32 vector, u32 count, int *fds)
{
struct vfio_irq_set *irq;
- size_t irq_size = sizeof(*irq) + sizeof(int) * count;
+ size_t irq_size;
+ irq_size = sizeof(*irq) + sizeof(int) * count;
irq = calloc(1, irq_size);
VFIO_ASSERT_NOT_NULL(irq);
irq->argsz = irq_size;
@@ -119,9 +120,10 @@ static int vfio_device_feature_ioctl(int fd, u32 flags, void *data,
size_t data_size)
{
struct vfio_device_feature *feature;
- size_t feature_size = sizeof(*feature) + data_size;
+ size_t feature_size;
int ret;
+ feature_size = sizeof(*feature) + data_size;
feature = calloc(1, feature_size);
VFIO_ASSERT_NOT_NULL(feature);
memcpy(feature->data, data, data_size);
next prev parent reply other threads:[~2026-06-12 23:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-12 21:58 [PATCH] selftests/vfio: avoid VLAs Alex Mastro
2026-06-12 23:45 ` Vipin Sharma [this message]
2026-06-15 15:19 ` Alex Mastro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260612234154.GA667942.vipinsh@google.com \
--to=vipinsh@google.com \
--cc=alex@shazbot.org \
--cc=amastro@fb.com \
--cc=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=rananta@google.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.