From: sashiko-bot@kernel.org
To: "Farhan Ali" <alifm@linux.ibm.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v16 6/7] vfio/pci: Add a reset_done callback for vfio-pci driver
Date: Thu, 14 May 2026 23:54:16 +0000 [thread overview]
Message-ID: <20260514235417.7D992C2BCB3@smtp.kernel.org> (raw)
In-Reply-To: <20260514180059.1553-7-alifm@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] Concurrent execution of `vfio_pci_core_aer_reset_done` and `vfio_pci_core_disable` causes a Use-After-Free and data race on saved state.
- [High] UAPI breakage and runtime state corruption due to `reset_done` unconditionally restoring initialization state.
- [Medium] The error return value of `pci_load_saved_state()` is ignored, leading to potentially corrupted state restoration.
--
commit 50de5d9e39c609551f40181c5b1916513f9d200a
Author: Farhan Ali <alifm@linux.ibm.com>
vfio/pci: Add a reset_done callback for vfio-pci driver
On error recovery for a PCI device bound to vfio-pci driver, we want to
recover the state of the device to its last known saved state. The callback
restores the state of the device to its initial saved state.
> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
[ ... ]
> @@ -2255,6 +2255,17 @@ pci_ers_result_t vfio_pci_core_aer_err_detected(struct pci_dev *pdev,
> }
> EXPORT_SYMBOL_GPL(vfio_pci_core_aer_err_detected);
>
> +static void vfio_pci_core_aer_reset_done(struct pci_dev *pdev)
> +{
> + struct vfio_pci_core_device *vdev = dev_get_drvdata(&pdev->dev);
> +
Since pci_error_handlers->reset_done can be invoked by the PCI core at the
end of any device reset, including those initiated by userspace via the
VFIO_DEVICE_RESET ioctl, could this unconditionally overwrite the runtime
userspace configurations with the initial host state?
> + if (!vdev->pci_saved_state)
> + return;
Is there a potential use-after-free race on vdev->pci_saved_state here if a
user concurrently closes the VFIO file descriptor?
In vfio_pci_core_disable(), vdev->pci_saved_state can be freed via
pci_load_and_free_saved_state() before acquiring the PCI device lock. Since
this callback does not synchronize with the VFIO teardown path, could the
AER thread see vdev->pci_saved_state as valid, but then pass a dangling
pointer to pci_load_saved_state() after it is freed?
> +
> + pci_load_saved_state(pdev, vdev->pci_saved_state);
Should the return value of pci_load_saved_state() be checked here?
If it returns an error due to mismatched capability sizes, the partial
memcpy into pdev->saved_config_space is kept. Proceeding to call
pci_restore_state() might then push an inconsistent state to the hardware.
> + pci_restore_state(pdev);
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260514180059.1553-1-alifm@linux.ibm.com?part=6
next prev parent reply other threads:[~2026-05-14 23:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-14 18:00 [PATCH v16 0/7] Error recovery for vfio-pci devices on s390x Farhan Ali
2026-05-14 18:00 ` [PATCH v16 1/7] PCI: Allow per function PCI slots to fix slot reset on s390 Farhan Ali
2026-05-14 21:36 ` sashiko-bot
2026-05-14 18:00 ` [PATCH v16 2/7] PCI: Avoid saving config space state if inaccessible Farhan Ali
2026-05-14 22:08 ` sashiko-bot
2026-05-14 18:00 ` [PATCH v16 3/7] PCI: Fail FLR when config space is inaccessible Farhan Ali
2026-05-14 22:41 ` sashiko-bot
2026-05-14 18:00 ` [PATCH v16 4/7] s390/pci: Store PCI error information for passthrough devices Farhan Ali
2026-05-14 22:53 ` sashiko-bot
2026-05-14 18:00 ` [PATCH v16 5/7] vfio-pci/zdev: Add a device feature for error information Farhan Ali
2026-05-14 23:27 ` sashiko-bot
2026-05-14 18:00 ` [PATCH v16 6/7] vfio/pci: Add a reset_done callback for vfio-pci driver Farhan Ali
2026-05-14 23:54 ` sashiko-bot [this message]
2026-05-14 18:00 ` [PATCH v16 7/7] vfio/pci: Remove the pcie check for VFIO_PCI_ERR_IRQ_INDEX Farhan Ali
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=20260514235417.7D992C2BCB3@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alifm@linux.ibm.com \
--cc=linux-pci@vger.kernel.org \
--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