diff mbox series

[v2,vfio,2/2] vfio/pds: Refactor/simplify reset logic

Message ID 20240228003205.47311-3-brett.creeley@amd.com (mailing list archive)
State New, archived
Headers show
Series vfio/pds: Fix and simplify resets | expand

Commit Message

Brett Creeley Feb. 28, 2024, 12:32 a.m. UTC
The current logic for handling resets is more complicated than it needs
to be. The deferred_reset flag is used to indicate a reset is needed
and the deferred_reset_state is the requested, post-reset, state. The
source of the requested reset isn't immediately obvious. Improve
readability by replacing deferred_reset_state with deferred_reset_type,
which can be either PDS_VFIO_DEVICE_RESET (initiated/requested by the
DSC) or PDS_VFIO_HOST_RESET (initiated/requested by the VMM).

Signed-off-by: Brett Creeley <brett.creeley@amd.com>
Reviewed-by: Shannon Nelson <shannon.nelson@amd.com>
---
 drivers/vfio/pci/pds/pci_drv.c  |  2 +-
 drivers/vfio/pci/pds/vfio_dev.c | 10 +++++-----
 drivers/vfio/pci/pds/vfio_dev.h |  7 ++++++-
 3 files changed, 12 insertions(+), 7 deletions(-)

Comments

Tian, Kevin Feb. 28, 2024, 4:55 a.m. UTC | #1
> From: Brett Creeley <brett.creeley@amd.com>
> Sent: Wednesday, February 28, 2024 8:32 AM
> 
> The current logic for handling resets is more complicated than it needs
> to be. The deferred_reset flag is used to indicate a reset is needed
> and the deferred_reset_state is the requested, post-reset, state. The
> source of the requested reset isn't immediately obvious. Improve
> readability by replacing deferred_reset_state with deferred_reset_type,
> which can be either PDS_VFIO_DEVICE_RESET (initiated/requested by the
> DSC) or PDS_VFIO_HOST_RESET (initiated/requested by the VMM).
> 
> Signed-off-by: Brett Creeley <brett.creeley@amd.com>
> Reviewed-by: Shannon Nelson <shannon.nelson@amd.com>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
diff mbox series

Patch

diff --git a/drivers/vfio/pci/pds/pci_drv.c b/drivers/vfio/pci/pds/pci_drv.c
index a34dda516629..4ac3da7abd32 100644
--- a/drivers/vfio/pci/pds/pci_drv.c
+++ b/drivers/vfio/pci/pds/pci_drv.c
@@ -57,7 +57,7 @@  static void pds_vfio_recovery(struct pds_vfio_pci_device *pds_vfio)
 	if (deferred_reset_needed) {
 		mutex_lock(&pds_vfio->reset_mutex);
 		pds_vfio->deferred_reset = true;
-		pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_ERROR;
+		pds_vfio->deferred_reset_type = PDS_VFIO_DEVICE_RESET;
 		mutex_unlock(&pds_vfio->reset_mutex);
 	}
 }
diff --git a/drivers/vfio/pci/pds/vfio_dev.c b/drivers/vfio/pci/pds/vfio_dev.c
index a286ebcc7112..1a791bef5de1 100644
--- a/drivers/vfio/pci/pds/vfio_dev.c
+++ b/drivers/vfio/pci/pds/vfio_dev.c
@@ -34,11 +34,12 @@  void pds_vfio_state_mutex_unlock(struct pds_vfio_pci_device *pds_vfio)
 		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) {
+		if (pds_vfio->deferred_reset_type == PDS_VFIO_DEVICE_RESET) {
 			pds_vfio_dirty_disable(pds_vfio, false);
+			pds_vfio->state = VFIO_DEVICE_STATE_ERROR;
+		} else {
+			pds_vfio->state = VFIO_DEVICE_STATE_RUNNING;
 		}
-		pds_vfio->state = pds_vfio->deferred_reset_state;
-		pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_RUNNING;
 		mutex_unlock(&pds_vfio->reset_mutex);
 		goto again;
 	}
@@ -50,7 +51,7 @@  void pds_vfio_reset(struct pds_vfio_pci_device *pds_vfio)
 {
 	mutex_lock(&pds_vfio->reset_mutex);
 	pds_vfio->deferred_reset = true;
-	pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_RUNNING;
+	pds_vfio->deferred_reset_type = PDS_VFIO_HOST_RESET;
 	if (!mutex_trylock(&pds_vfio->state_mutex)) {
 		mutex_unlock(&pds_vfio->reset_mutex);
 		return;
@@ -194,7 +195,6 @@  static int pds_vfio_open_device(struct vfio_device *vdev)
 		return err;
 
 	pds_vfio->state = VFIO_DEVICE_STATE_RUNNING;
-	pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_RUNNING;
 
 	vfio_pci_core_finish_enable(&pds_vfio->vfio_coredev);
 
diff --git a/drivers/vfio/pci/pds/vfio_dev.h b/drivers/vfio/pci/pds/vfio_dev.h
index e7b01080a1ec..19547fd8e956 100644
--- a/drivers/vfio/pci/pds/vfio_dev.h
+++ b/drivers/vfio/pci/pds/vfio_dev.h
@@ -10,6 +10,11 @@ 
 #include "dirty.h"
 #include "lm.h"
 
+enum pds_vfio_reset_type {
+	PDS_VFIO_HOST_RESET = 0,
+	PDS_VFIO_DEVICE_RESET = 1,
+};
+
 struct pds_vfio_pci_device {
 	struct vfio_pci_core_device vfio_coredev;
 
@@ -20,7 +25,7 @@  struct pds_vfio_pci_device {
 	enum vfio_device_mig_state state;
 	struct mutex reset_mutex; /* protect reset_done flow */
 	u8 deferred_reset;
-	enum vfio_device_mig_state deferred_reset_state;
+	enum pds_vfio_reset_type deferred_reset_type;
 	struct notifier_block nb;
 
 	int vf_id;