2024-02-28 00:32:40

by Brett Creeley

[permalink] [raw]
Subject: [PATCH v2 vfio 1/2] vfio/pds: Always clear the save/restore FDs on reset

After reset the VFIO device state will always be put in
VFIO_DEVICE_STATE_RUNNING, but the save/restore files will only be
cleared if the previous state was VFIO_DEVICE_STATE_ERROR. This
can/will cause the restore/save files to be leaked if/when the
migration state machine transitions through the states that
re-allocates these files. Fix this by always clearing the
restore/save files for resets.

Fixes: 7dabb1bcd177 ("vfio/pds: Add support for firmware recovery")
Cc: [email protected]
Signed-off-by: Brett Creeley <[email protected]>
Reviewed-by: Shannon Nelson <[email protected]>
---
drivers/vfio/pci/pds/vfio_dev.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/vfio/pci/pds/vfio_dev.c b/drivers/vfio/pci/pds/vfio_dev.c
index 4c351c59d05a..a286ebcc7112 100644
--- a/drivers/vfio/pci/pds/vfio_dev.c
+++ b/drivers/vfio/pci/pds/vfio_dev.c
@@ -32,9 +32,9 @@ void pds_vfio_state_mutex_unlock(struct pds_vfio_pci_device *pds_vfio)
mutex_lock(&pds_vfio->reset_mutex);
if (pds_vfio->deferred_reset) {
pds_vfio->deferred_reset = false;
+ pds_vfio_put_restore_file(pds_vfio);
+ pds_vfio_put_save_file(pds_vfio);
if (pds_vfio->state == VFIO_DEVICE_STATE_ERROR) {
- pds_vfio_put_restore_file(pds_vfio);
- pds_vfio_put_save_file(pds_vfio);
pds_vfio_dirty_disable(pds_vfio, false);
}
pds_vfio->state = pds_vfio->deferred_reset_state;
--
2.17.1



2024-02-28 04:55:47

by Tian, Kevin

[permalink] [raw]
Subject: RE: [PATCH v2 vfio 1/2] vfio/pds: Always clear the save/restore FDs on reset

> From: Brett Creeley <[email protected]>
> Sent: Wednesday, February 28, 2024 8:32 AM
>
> After reset the VFIO device state will always be put in
> VFIO_DEVICE_STATE_RUNNING, but the save/restore files will only be
> cleared if the previous state was VFIO_DEVICE_STATE_ERROR. This
> can/will cause the restore/save files to be leaked if/when the
> migration state machine transitions through the states that
> re-allocates these files. Fix this by always clearing the
> restore/save files for resets.
>
> Fixes: 7dabb1bcd177 ("vfio/pds: Add support for firmware recovery")
> Cc: [email protected]
> Signed-off-by: Brett Creeley <[email protected]>
> Reviewed-by: Shannon Nelson <[email protected]>

Reviewed-by: Kevin Tian <[email protected]>