Skip to content

Commit 4406f46

Browse files
shamiali2008Alex Williamson
authored andcommitted
hisi_acc_vfio_pci: Use its own PCI reset_done error handler
Register private handler for pci_error_handlers.reset_done and update state accordingly. Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Longfang Liu <liulongfang@huawei.com> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com> Link: https://lore.kernel.org/r/20220308184902.2242-10-shameerali.kolothum.thodi@huawei.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent b0eed08 commit 4406f46

2 files changed

Lines changed: 57 additions & 4 deletions

File tree

drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,27 @@ static void hisi_acc_vf_disable_fds(struct hisi_acc_vf_core_device *hisi_acc_vde
626626
}
627627
}
628628

629+
/*
630+
* This function is called in all state_mutex unlock cases to
631+
* handle a 'deferred_reset' if exists.
632+
*/
633+
static void
634+
hisi_acc_vf_state_mutex_unlock(struct hisi_acc_vf_core_device *hisi_acc_vdev)
635+
{
636+
again:
637+
spin_lock(&hisi_acc_vdev->reset_lock);
638+
if (hisi_acc_vdev->deferred_reset) {
639+
hisi_acc_vdev->deferred_reset = false;
640+
spin_unlock(&hisi_acc_vdev->reset_lock);
641+
hisi_acc_vdev->vf_qm_state = QM_NOT_READY;
642+
hisi_acc_vdev->mig_state = VFIO_DEVICE_STATE_RUNNING;
643+
hisi_acc_vf_disable_fds(hisi_acc_vdev);
644+
goto again;
645+
}
646+
mutex_unlock(&hisi_acc_vdev->state_mutex);
647+
spin_unlock(&hisi_acc_vdev->reset_lock);
648+
}
649+
629650
static void hisi_acc_vf_start_device(struct hisi_acc_vf_core_device *hisi_acc_vdev)
630651
{
631652
struct hisi_qm *vf_qm = &hisi_acc_vdev->vf_qm;
@@ -922,7 +943,7 @@ hisi_acc_vfio_pci_set_device_state(struct vfio_device *vdev,
922943
break;
923944
}
924945
}
925-
mutex_unlock(&hisi_acc_vdev->state_mutex);
946+
hisi_acc_vf_state_mutex_unlock(hisi_acc_vdev);
926947
return res;
927948
}
928949

@@ -935,10 +956,35 @@ hisi_acc_vfio_pci_get_device_state(struct vfio_device *vdev,
935956

936957
mutex_lock(&hisi_acc_vdev->state_mutex);
937958
*curr_state = hisi_acc_vdev->mig_state;
938-
mutex_unlock(&hisi_acc_vdev->state_mutex);
959+
hisi_acc_vf_state_mutex_unlock(hisi_acc_vdev);
939960
return 0;
940961
}
941962

963+
static void hisi_acc_vf_pci_aer_reset_done(struct pci_dev *pdev)
964+
{
965+
struct hisi_acc_vf_core_device *hisi_acc_vdev = dev_get_drvdata(&pdev->dev);
966+
967+
if (hisi_acc_vdev->core_device.vdev.migration_flags !=
968+
VFIO_MIGRATION_STOP_COPY)
969+
return;
970+
971+
/*
972+
* As the higher VFIO layers are holding locks across reset and using
973+
* those same locks with the mm_lock we need to prevent ABBA deadlock
974+
* with the state_mutex and mm_lock.
975+
* In case the state_mutex was taken already we defer the cleanup work
976+
* to the unlock flow of the other running context.
977+
*/
978+
spin_lock(&hisi_acc_vdev->reset_lock);
979+
hisi_acc_vdev->deferred_reset = true;
980+
if (!mutex_trylock(&hisi_acc_vdev->state_mutex)) {
981+
spin_unlock(&hisi_acc_vdev->reset_lock);
982+
return;
983+
}
984+
spin_unlock(&hisi_acc_vdev->reset_lock);
985+
hisi_acc_vf_state_mutex_unlock(hisi_acc_vdev);
986+
}
987+
942988
static int hisi_acc_vf_qm_init(struct hisi_acc_vf_core_device *hisi_acc_vdev)
943989
{
944990
struct vfio_pci_core_device *vdev = &hisi_acc_vdev->core_device;
@@ -1259,12 +1305,17 @@ static const struct pci_device_id hisi_acc_vfio_pci_table[] = {
12591305

12601306
MODULE_DEVICE_TABLE(pci, hisi_acc_vfio_pci_table);
12611307

1308+
static const struct pci_error_handlers hisi_acc_vf_err_handlers = {
1309+
.reset_done = hisi_acc_vf_pci_aer_reset_done,
1310+
.error_detected = vfio_pci_core_aer_err_detected,
1311+
};
1312+
12621313
static struct pci_driver hisi_acc_vfio_pci_driver = {
12631314
.name = KBUILD_MODNAME,
12641315
.id_table = hisi_acc_vfio_pci_table,
12651316
.probe = hisi_acc_vfio_pci_probe,
12661317
.remove = hisi_acc_vfio_pci_remove,
1267-
.err_handler = &vfio_pci_core_err_handlers,
1318+
.err_handler = &hisi_acc_vf_err_handlers,
12681319
};
12691320

12701321
module_pci_driver(hisi_acc_vfio_pci_driver);

drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ struct hisi_acc_vf_migration_file {
9898

9999
struct hisi_acc_vf_core_device {
100100
struct vfio_pci_core_device core_device;
101+
u8 deferred_reset:1;
101102
/* for migration state */
102103
struct mutex state_mutex;
103104
enum vfio_device_mig_state mig_state;
@@ -107,7 +108,8 @@ struct hisi_acc_vf_core_device {
107108
struct hisi_qm vf_qm;
108109
u32 vf_qm_state;
109110
int vf_id;
110-
111+
/* for reset handler */
112+
spinlock_t reset_lock;
111113
struct hisi_acc_vf_migration_file *resuming_migf;
112114
struct hisi_acc_vf_migration_file *saving_migf;
113115
};

0 commit comments

Comments
 (0)