Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Longfang Liu" <liulongfang@huawei.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 1/2] hisi_acc_vfio_pci: fix live migration enable conditions for PF passthrough
Date: Mon, 03 Aug 2026 02:42:20 +0000	[thread overview]
Message-ID: <20260803024220.ABB9E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260803021857.2370179-2-liulongfang@huawei.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] The patch fails to prevent a Use-After-Free because `pf_qm` becomes a dangling pointer (not NULL) when the PF driver is unbound.
- [High] `set_reset_flag` is never cleared, causing spurious lock release during subsequent failed resets.
--

--- Patch [1]: [PATCH 1/2] hisi_acc_vfio_pci: fix live migration enable conditions for PF passthrough ---
commit 2cccd4c0444989d0fd451c1227c40bde4c25acb2
Author: Longfang Liu <liulongfang@huawei.com>
Subject: hisi_acc_vfio_pci: fix live migration enable conditions for PF passthrough

This commit attempts to fix a calltrace exception triggered when a user
unbinds the PF device driver from the host and directly passes it through to
a VM, then attempts live migration. It adds checks across operations that
depend on PF driver commands to ensure the PF's QM structure is available.

> diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
> index 86362ec424a50..36490be7a61aa 100644
> --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
> +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
> @@ -378,6 +378,11 @@ static int vf_qm_check_match(struct hisi_acc_vf_core_device *hisi_acc_vdev,
>  	if (migf->total_length < QM_MATCH_SIZE || hisi_acc_vdev->match_done)
>  		return 0;
>  
> +	if (!pf_qm || !pf_qm->io_base) {

[Severity: High]
This isn't a bug introduced by this patch, but since the patch attempts to
fix it here, does this check fully prevent a Use-After-Free?

When the PF driver is unbound while a VF is assigned to a VM,
pci_disable_sriov() warns but doesn't prevent the driver's remove callback
from executing, causing the PF's qm structure to be freed via devres.

This leaves hisi_acc_vdev->pf_qm as a dangling pointer rather than NULL.
Will the !pf_qm check fail to catch this, leading to a UAF read when
accessing pf_qm->io_base?

> +		dev_err(dev, "failed to match check for PF QM migration\n");
> +		return -ENODEV;
> +	}
> +
>  	ret = vf_qm_version_check(vf_data, dev);

[ ... ]

> @@ -1174,8 +1194,12 @@ 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->set_reset_flag) {
> +		if (qm && qm->io_base)
> +			clear_bit(QM_RESETTING, &qm->misc_ctl);

[Severity: High]
This is a pre-existing issue, but should the set_reset_flag be cleared after
releasing this lock?

If hisi_acc_vf_pci_reset_prepare() successfully acquires the lock, it sets
set_reset_flag = true. However, when hisi_acc_vf_pci_aer_reset_done()
clears the lock here, it doesn't appear to reset the flag back to false.

If a subsequent reset occurs and reset_prepare() fails to acquire the lock
(e.g., due to a timeout because another VF or the PF holds it), won't this
function erroneously clear the QM_RESETTING lock that is actively held by
another context?

> +		else
> +			dev_err(&pdev->dev, "PF QM not available for reset done\n");
> +	}
>  
>  	if (!hisi_acc_vdev->core_device.vdev.mig_ops)
>  		return;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260803021857.2370179-1-liulongfang@huawei.com?part=1

  reply	other threads:[~2026-08-03  2:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03  2:18 [PATCH 0/2] fix two issues related to the driver Longfang Liu
2026-08-03  2:18 ` [PATCH 1/2] hisi_acc_vfio_pci: fix live migration enable conditions for PF passthrough Longfang Liu
2026-08-03  2:42   ` sashiko-bot [this message]
2026-08-03  2:18 ` [PATCH 2/2] hisi_acc_vfio_pci: fix VF BAR2 mmap on 64KB page size Longfang Liu
2026-08-03  2:27   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260803024220.ABB9E1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=liulongfang@huawei.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox