* [PATCH v6 0/2] fix two issues in hisi_acc_vfio_pci driver
@ 2026-10-13 7:19 Longfang Liu
2026-10-13 7:19 ` [PATCH v6 1/2] hisi_acc_vfio_pci: fix NULL dereference in reset_prepare on PF passthrough Longfang Liu
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Longfang Liu @ 2026-10-13 7:19 UTC (permalink / raw)
To: alex.williamson, jgg; +Cc: kvm, linux-kernel, liulongfang
This series fixes two issues in the HiSilicon ACC VFIO PCI driver:
1. A NULL pointer dereference in reset_prepare() when a PF is bound
to the driver and passed through to a VM.
2. A 64KB page incompatibility on QM_HW_V3 hardware that breaks
migration and the guest kernel.
Changes since v5:
- Fix a potential NULL dereference in reset_prepare().
Open code &qm->pdev->dev at dev_err() to drop the local variable
evaluated before the mig_ops check.
Changes since v4:
- Removed dev_err() log from reset_prepare().
- Removed redundant pdev->is_virtfn check from probe().
Changes since v3:
- Merged the set_reset_flag fix into patch 1 (was a separate patch in v3)
- Replaced pf_qm guards with a mig_ops check at function entry.
- Moved the 64KB page check from open_device to probe, selecting generic
ops instead of rejecting the device.
Changes since v2:
- Remove redundant qm->io_base check.
- Drop PAGE_ALIGN for BAR2 configuration region.
Longfang Liu (2):
hisi_acc_vfio_pci: fix NULL dereference in reset_prepare on PF
passthrough
hisi_acc_vfio_pci: reject live migration on 64KB page with QM_HW_V3
hardware
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 46 ++++++++++++-------
1 file changed, 29 insertions(+), 17 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v6 1/2] hisi_acc_vfio_pci: fix NULL dereference in reset_prepare on PF passthrough
2026-10-13 7:19 [PATCH v6 0/2] fix two issues in hisi_acc_vfio_pci driver Longfang Liu
@ 2026-10-13 7:19 ` Longfang Liu
2026-10-13 7:19 ` [PATCH v6 2/2] hisi_acc_vfio_pci: reject live migration on 64KB page with QM_HW_V3 hardware Longfang Liu
2026-10-15 20:25 ` [PATCH v6 0/2] fix two issues in hisi_acc_vfio_pci driver Alex Williamson
2 siblings, 0 replies; 4+ messages in thread
From: Longfang Liu @ 2026-10-13 7:19 UTC (permalink / raw)
To: alex.williamson, jgg; +Cc: kvm, linux-kernel, liulongfang
When a PF is bound to the driver via driver_override and passed
through to a VM, its pf_qm stays NULL. The PCI error handler
reset_prepare() runs during open_device through
pci_try_reset_function(), before the mig_ops gate, and dereferences
the NULL pf_qm for the timeout log, crashing the kernel.
Move the mig_ops check to the entry of reset_prepare() and
aer_reset_done() so non-migration devices skip the QM_RESETTING
coordination. The dev local resolved &qm->pdev->dev before the
gate, so open code it at the dev_err() call where qm is known
valid. Also clear set_reset_flag together with QM_RESETTING in
aer_reset_done(); the flag was never cleared before, so a later
timed-out reset could release a foreign lock.
Fixes: b0eed085903e ("hisi_acc_vfio_pci: Add support for VFIO live migration")
Fixes: a22099ed7936f ("hisi_acc_vfio_pci: fix VF reset timeout issue")
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
---
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
index 86362ec424a5..e6fdf4d2e581 100644
--- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
+++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
@@ -1154,14 +1154,16 @@ static void hisi_acc_vf_pci_reset_prepare(struct pci_dev *pdev)
{
struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_drvdata(pdev);
struct hisi_qm *qm = hisi_acc_vdev->pf_qm;
- struct device *dev = &qm->pdev->dev;
u32 delay = 0;
+ if (!hisi_acc_vdev->core_device.vdev.mig_ops)
+ return;
+
/* All reset requests need to be queued for processing */
while (test_and_set_bit(QM_RESETTING, &qm->misc_ctl)) {
msleep(1);
if (++delay > QM_RESET_WAIT_TIMEOUT) {
- dev_err(dev, "reset prepare failed\n");
+ dev_err(&qm->pdev->dev, "reset prepare failed\n");
return;
}
}
@@ -1174,12 +1176,14 @@ static void hisi_acc_vf_pci_aer_reset_done(struct pci_dev *pdev)
struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_drvdata(pdev);
struct hisi_qm *qm = hisi_acc_vdev->pf_qm;
- if (hisi_acc_vdev->set_reset_flag)
- clear_bit(QM_RESETTING, &qm->misc_ctl);
-
if (!hisi_acc_vdev->core_device.vdev.mig_ops)
return;
+ if (hisi_acc_vdev->set_reset_flag) {
+ clear_bit(QM_RESETTING, &qm->misc_ctl);
+ hisi_acc_vdev->set_reset_flag = false;
+ }
+
mutex_lock(&hisi_acc_vdev->state_mutex);
hisi_acc_vf_reset(hisi_acc_vdev);
mutex_unlock(&hisi_acc_vdev->state_mutex);
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v6 2/2] hisi_acc_vfio_pci: reject live migration on 64KB page with QM_HW_V3 hardware
2026-10-13 7:19 [PATCH v6 0/2] fix two issues in hisi_acc_vfio_pci driver Longfang Liu
2026-10-13 7:19 ` [PATCH v6 1/2] hisi_acc_vfio_pci: fix NULL dereference in reset_prepare on PF passthrough Longfang Liu
@ 2026-10-13 7:19 ` Longfang Liu
2026-10-15 20:25 ` [PATCH v6 0/2] fix two issues in hisi_acc_vfio_pci driver Alex Williamson
2 siblings, 0 replies; 4+ messages in thread
From: Longfang Liu @ 2026-10-13 7:19 UTC (permalink / raw)
To: alex.williamson, jgg; +Cc: kvm, linux-kernel, liulongfang
On QM_HW_V3 (VF_CTRL mode) hardware with 64KB pages, the functional
region and migration registers share one BAR2 physical page with no
isolation, which leaks migration registers to the guest and causes
guest kernel calltrace under the KVM emulated device scheme.
The previous fix rejected the device in hisi_acc_vf_qm_init() during
open_device, returning -EINVAL and breaking passthrough entirely.
Move the drv_mode check into a helper called from probe() so that a
VF_CTRL device on a 64KB page is bound to the generic ops, keeping
passthrough working while disabling live migration.
Fixes: b0eed085903e ("hisi_acc_vfio_pci: Add support for VFIO live migration")
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
---
.../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 32 ++++++++++++-------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
index e6fdf4d2e581..818ad5112d7b 100644
--- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
+++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
@@ -1195,13 +1195,6 @@ static int hisi_acc_vf_qm_init(struct hisi_acc_vf_core_device *hisi_acc_vdev)
struct hisi_qm *vf_qm = &hisi_acc_vdev->vf_qm;
struct hisi_qm *pf_qm = hisi_acc_vdev->pf_qm;
struct pci_dev *vf_dev = vdev->pdev;
- u32 val;
-
- val = readl(pf_qm->io_base + QM_MIG_REGION_SEL);
- if (pf_qm->ver > QM_HW_V3 && (val & QM_MIG_REGION_EN))
- hisi_acc_vdev->drv_mode = HW_ACC_MIG_PF_CTRL;
- else
- hisi_acc_vdev->drv_mode = HW_ACC_MIG_VF_CTRL;
if (hisi_acc_vdev->drv_mode == HW_ACC_MIG_PF_CTRL) {
/*
@@ -1669,21 +1662,34 @@ static void hisi_acc_vf_debugfs_exit(struct hisi_acc_vf_core_device *hisi_acc_vd
hisi_acc_vdev->debug_migf = NULL;
}
+static enum hw_drv_mode hisi_acc_vf_get_drv_mode(struct hisi_qm *pf_qm)
+{
+ u32 val;
+
+ val = readl(pf_qm->io_base + QM_MIG_REGION_SEL);
+ if (pf_qm->ver > QM_HW_V3 && (val & QM_MIG_REGION_EN))
+ return HW_ACC_MIG_PF_CTRL;
+
+ return HW_ACC_MIG_VF_CTRL;
+}
+
static int hisi_acc_vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
{
struct hisi_acc_vf_core_device *hisi_acc_vdev;
const struct vfio_device_ops *ops = &hisi_acc_vfio_pci_ops;
+ enum hw_drv_mode drv_mode = HW_ACC_MIG_VF_CTRL;
+ resource_size_t func_len;
struct hisi_qm *pf_qm;
- int vf_id;
int ret;
pf_qm = hisi_acc_get_pf_qm(pdev);
if (pf_qm && pf_qm->ver >= QM_HW_V3) {
- vf_id = pci_iov_vf_id(pdev);
- if (vf_id >= 0)
- ops = &hisi_acc_vfio_pci_migrn_ops;
+ func_len = pci_resource_len(pdev, VFIO_PCI_BAR2_REGION_INDEX) >> 1;
+ drv_mode = hisi_acc_vf_get_drv_mode(pf_qm);
+ if (drv_mode == HW_ACC_MIG_VF_CTRL && func_len < PAGE_SIZE)
+ pci_warn(pdev, "migration not supported on 64KB pages with QM_HW_V3\n");
else
- pci_warn(pdev, "migration support failed, continue with generic interface\n");
+ ops = &hisi_acc_vfio_pci_migrn_ops;
}
hisi_acc_vdev = vfio_alloc_device(hisi_acc_vf_core_device,
@@ -1691,6 +1697,8 @@ static int hisi_acc_vfio_pci_probe(struct pci_dev *pdev, const struct pci_device
if (IS_ERR(hisi_acc_vdev))
return PTR_ERR(hisi_acc_vdev);
+ hisi_acc_vdev->drv_mode = drv_mode;
+
dev_set_drvdata(&pdev->dev, &hisi_acc_vdev->core_device);
ret = vfio_pci_core_register_device(&hisi_acc_vdev->core_device);
if (ret)
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v6 0/2] fix two issues in hisi_acc_vfio_pci driver
2026-10-13 7:19 [PATCH v6 0/2] fix two issues in hisi_acc_vfio_pci driver Longfang Liu
2026-10-13 7:19 ` [PATCH v6 1/2] hisi_acc_vfio_pci: fix NULL dereference in reset_prepare on PF passthrough Longfang Liu
2026-10-13 7:19 ` [PATCH v6 2/2] hisi_acc_vfio_pci: reject live migration on 64KB page with QM_HW_V3 hardware Longfang Liu
@ 2026-10-15 20:25 ` Alex Williamson
2 siblings, 0 replies; 4+ messages in thread
From: Alex Williamson @ 2026-10-15 20:25 UTC (permalink / raw)
To: Longfang Liu; +Cc: alex.williamson, jgg, kvm, linux-kernel, alex
On Tue, 13 Oct 2026 15:19:27 +0800
Longfang Liu <liulongfang@huawei.com> wrote:
> This series fixes two issues in the HiSilicon ACC VFIO PCI driver:
> 1. A NULL pointer dereference in reset_prepare() when a PF is bound
> to the driver and passed through to a VM.
> 2. A 64KB page incompatibility on QM_HW_V3 hardware that breaks
> migration and the guest kernel.
>
> Changes since v5:
> - Fix a potential NULL dereference in reset_prepare().
> Open code &qm->pdev->dev at dev_err() to drop the local variable
> evaluated before the mig_ops check.
>
> Changes since v4:
> - Removed dev_err() log from reset_prepare().
> - Removed redundant pdev->is_virtfn check from probe().
>
> Changes since v3:
> - Merged the set_reset_flag fix into patch 1 (was a separate patch in v3)
> - Replaced pf_qm guards with a mig_ops check at function entry.
> - Moved the 64KB page check from open_device to probe, selecting generic
> ops instead of rejecting the device.
>
> Changes since v2:
> - Remove redundant qm->io_base check.
> - Drop PAGE_ALIGN for BAR2 configuration region.
>
> Longfang Liu (2):
> hisi_acc_vfio_pci: fix NULL dereference in reset_prepare on PF
> passthrough
> hisi_acc_vfio_pci: reject live migration on 64KB page with QM_HW_V3
> hardware
>
> drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 46 ++++++++++++-------
> 1 file changed, 29 insertions(+), 17 deletions(-)
>
Applied to vfio next branch for v7.4. Thanks,
Alex
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-15 20:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-13 7:19 [PATCH v6 0/2] fix two issues in hisi_acc_vfio_pci driver Longfang Liu
2026-10-13 7:19 ` [PATCH v6 1/2] hisi_acc_vfio_pci: fix NULL dereference in reset_prepare on PF passthrough Longfang Liu
2026-10-13 7:19 ` [PATCH v6 2/2] hisi_acc_vfio_pci: reject live migration on 64KB page with QM_HW_V3 hardware Longfang Liu
2026-10-15 20:25 ` [PATCH v6 0/2] fix two issues in hisi_acc_vfio_pci driver Alex Williamson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®