* [PATCH] hw/vfio: fix region fd initialization
@ 2025-07-10 15:48 John Levon
2025-07-11 11:40 ` Mark Cave-Ayland
2025-07-15 5:52 ` Cédric Le Goater
0 siblings, 2 replies; 3+ messages in thread
From: John Levon @ 2025-07-10 15:48 UTC (permalink / raw)
To: qemu-devel; +Cc: Cédric Le Goater, Alex Williamson, John Levon
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>
---
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);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] hw/vfio: fix region fd initialization
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
1 sibling, 0 replies; 3+ messages in thread
From: Mark Cave-Ayland @ 2025-07-11 11:40 UTC (permalink / raw)
To: John Levon, qemu-devel; +Cc: Cédric Le Goater, Alex Williamson
On 10/07/2025 16: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>
> ---
> 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);
Reviewed-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
ATB,
Mark.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hw/vfio: fix region fd initialization
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
1 sibling, 0 replies; 3+ messages in thread
From: Cédric Le Goater @ 2025-07-15 5:52 UTC (permalink / raw)
To: John Levon, qemu-devel; +Cc: Alex Williamson
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);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-15 5:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).