From: "Cédric Le Goater" <clg@redhat.com>
To: John Levon <john.levon@nutanix.com>, qemu-devel@nongnu.org
Cc: Alex Williamson <alex.williamson@redhat.com>
Subject: Re: [PATCH] hw/vfio: fix region fd initialization
Date: Tue, 15 Jul 2025 07:52:45 +0200 [thread overview]
Message-ID: <205c69d8-468e-4984-b27a-4a5fd619f4c6@redhat.com> (raw)
In-Reply-To: <20250710154842.1267253-1-john.levon@nutanix.com>
On 7/10/25 17:48, John Levon wrote:
> We were not initializing the region fd array to -1, so we would
> accidentally try to close(0) on cleanup for any region that is not
> referenced.
>
> Fixes: 95cdb024 ("vfio: add region info cache")
> Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Thanks,
C.
> ---
> hw/vfio/device.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/hw/vfio/device.c b/hw/vfio/device.c
> index 96cf21462c..52a1996dc4 100644
> --- a/hw/vfio/device.c
> +++ b/hw/vfio/device.c
> @@ -463,6 +463,8 @@ void vfio_device_detach(VFIODevice *vbasedev)
> void vfio_device_prepare(VFIODevice *vbasedev, VFIOContainerBase *bcontainer,
> struct vfio_device_info *info)
> {
> + int i;
> +
> vbasedev->num_irqs = info->num_irqs;
> vbasedev->num_regions = info->num_regions;
> vbasedev->flags = info->flags;
> @@ -477,6 +479,9 @@ void vfio_device_prepare(VFIODevice *vbasedev, VFIOContainerBase *bcontainer,
> vbasedev->num_regions);
> if (vbasedev->use_region_fds) {
> vbasedev->region_fds = g_new0(int, vbasedev->num_regions);
> + for (i = 0; i < vbasedev->num_regions; i++) {
> + vbasedev->region_fds[i] = -1;
> + }
> }
> }
>
> @@ -489,7 +494,6 @@ void vfio_device_unprepare(VFIODevice *vbasedev)
> if (vbasedev->region_fds != NULL && vbasedev->region_fds[i] != -1) {
> close(vbasedev->region_fds[i]);
> }
> -
> }
>
> g_clear_pointer(&vbasedev->reginfo, g_free);
prev parent reply other threads:[~2025-07-15 5:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-10 15:48 [PATCH] hw/vfio: fix region fd initialization John Levon
2025-07-11 11:40 ` Mark Cave-Ayland
2025-07-15 5:52 ` Cédric Le Goater [this message]
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=205c69d8-468e-4984-b27a-4a5fd619f4c6@redhat.com \
--to=clg@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=john.levon@nutanix.com \
--cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).