Skip to content

Commit a22099e

Browse files
Weili Qianawilliam
authored andcommitted
hisi_acc_vfio_pci: fix VF reset timeout issue
If device error occurs during live migration, qemu will reset the VF. At this time, VF reset and device reset are performed simultaneously. The VF reset will timeout. Therefore, the QM_RESETTING flag is used to ensure that VF reset and device reset are performed serially. Fixes: b0eed08 ("hisi_acc_vfio_pci: Add support for VFIO live migration") Signed-off-by: Weili Qian <qianweili@huawei.com> Link: https://lore.kernel.org/r/20260122020205.2884497-2-liulongfang@huawei.com Signed-off-by: Alex Williamson <alex@shazbot.org>
1 parent 962ae68 commit a22099e

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,9 +1188,32 @@ hisi_acc_vfio_pci_get_device_state(struct vfio_device *vdev,
11881188
return 0;
11891189
}
11901190

1191+
static void hisi_acc_vf_pci_reset_prepare(struct pci_dev *pdev)
1192+
{
1193+
struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_drvdata(pdev);
1194+
struct hisi_qm *qm = hisi_acc_vdev->pf_qm;
1195+
struct device *dev = &qm->pdev->dev;
1196+
u32 delay = 0;
1197+
1198+
/* All reset requests need to be queued for processing */
1199+
while (test_and_set_bit(QM_RESETTING, &qm->misc_ctl)) {
1200+
msleep(1);
1201+
if (++delay > QM_RESET_WAIT_TIMEOUT) {
1202+
dev_err(dev, "reset prepare failed\n");
1203+
return;
1204+
}
1205+
}
1206+
1207+
hisi_acc_vdev->set_reset_flag = true;
1208+
}
1209+
11911210
static void hisi_acc_vf_pci_aer_reset_done(struct pci_dev *pdev)
11921211
{
11931212
struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_drvdata(pdev);
1213+
struct hisi_qm *qm = hisi_acc_vdev->pf_qm;
1214+
1215+
if (hisi_acc_vdev->set_reset_flag)
1216+
clear_bit(QM_RESETTING, &qm->misc_ctl);
11941217

11951218
if (hisi_acc_vdev->core_device.vdev.migration_flags !=
11961219
VFIO_MIGRATION_STOP_COPY)
@@ -1734,6 +1757,7 @@ static const struct pci_device_id hisi_acc_vfio_pci_table[] = {
17341757
MODULE_DEVICE_TABLE(pci, hisi_acc_vfio_pci_table);
17351758

17361759
static const struct pci_error_handlers hisi_acc_vf_err_handlers = {
1760+
.reset_prepare = hisi_acc_vf_pci_reset_prepare,
17371761
.reset_done = hisi_acc_vf_pci_aer_reset_done,
17381762
.error_detected = vfio_pci_core_aer_err_detected,
17391763
};

drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#define ERROR_CHECK_TIMEOUT 100
2929
#define CHECK_DELAY_TIME 100
30+
#define QM_RESET_WAIT_TIMEOUT 60000
3031

3132
#define QM_SQC_VFT_BASE_SHIFT_V2 28
3233
#define QM_SQC_VFT_BASE_MASK_V2 GENMASK(15, 0)
@@ -128,6 +129,7 @@ struct hisi_acc_vf_migration_file {
128129
struct hisi_acc_vf_core_device {
129130
struct vfio_pci_core_device core_device;
130131
u8 match_done;
132+
bool set_reset_flag;
131133
/*
132134
* io_base is only valid when dev_opened is true,
133135
* which is protected by open_mutex.

0 commit comments

Comments
 (0)