Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vipin Sharma" <vipinsh@google.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v4 03/16] vfio/pci: Retrieve preserved device files after Live Update
Date: Wed, 13 May 2026 04:23:50 +0000	[thread overview]
Message-ID: <20260513042351.345FBC2BCB7@smtp.kernel.org> (raw)
In-Reply-To: <20260511234802.2280368-4-vipinsh@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] vfio_pci_liveupdate_can_finish logic error permanently leaks preserved KHO memory and wedges the session.
- [High] TOCTOU race in vfio_pci_liveupdate_freeze allows device reset while interrupts are active.
--

commit aeb30af9099697f73a40eb35a514bc4eaae76916
Author: Vipin Sharma <vipinsh@google.com>

vfio/pci: Retrieve preserved device files after Live Update

This commit implements the retrieve() and finish() file handler callbacks for
VFIO, enabling userspace to retrieve preserved VFIO device files after a Live
Update.

> diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio_pci_liveupdate.c
> index 5cc57bf39dbee..9142aaea94f2d 100644
> --- a/drivers/vfio/pci/vfio_pci_liveupdate.c
> +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c

[ ... ]

> @@ -203,13 +210,53 @@ static int vfio_pci_liveupdate_freeze(struct liveupdate_file_op_args *args)

[ ... ]

> +static bool vfio_pci_liveupdate_can_finish(struct liveupdate_file_op_args *args)
> +{
> +	return args->retrieve_status > 0;
> +}

Will this permanently leak preserved KHO memory and wedge the session if
retrieval fails or is never attempted?

If the Live Update Orchestrator (LUO) sets retrieve_status to 0 (userspace
never attempted retrieval) or to a negative error code (retrieval failed),
can_finish() will evaluate to false.

This will cause the LUO core's luo_file_finish() routine to abort with -EBUSY,
bypassing the finish() callback and leaking the KHO memory allocated for
args->serialized_data.

>  static void vfio_pci_liveupdate_finish(struct liveupdate_file_op_args *args)
>  {
> +	kho_restore_free(phys_to_virt(args->serialized_data));
>  }
>  
>  static const struct liveupdate_file_ops vfio_pci_liveupdate_file_ops = {
> @@ -218,6 +265,7 @@ static const struct liveupdate_file_ops vfio_pci_liveupdate_file_ops = {
>  	.unpreserve = vfio_pci_liveupdate_unpreserve,
>  	.freeze = vfio_pci_liveupdate_freeze,

I realize this problem wasn't introduced by this patch, but existed in the
immediately preceding patch in the series.

Is there a TOCTOU race in vfio_pci_liveupdate_freeze() that allows a device
reset while interrupts are active?

vfio_pci_liveupdate_freeze() reads vdev->irq_type to verify that interrupts
are disabled:

    if (vdev->irq_type != VFIO_PCI_NUM_IRQS) {
        pci_err(pdev, "Freeze failed! Interrupts are still enabled.\n");
        return -EINVAL;
    }

It does so without holding vdev->igate, which is the lock that protects VFIO
interrupt configuration.

Could a concurrent VFIO_DEVICE_SET_IRQS ioctl acquire vdev->igate, enable
interrupts, and update vdev->irq_type immediately after the safety check in
freeze() passes? 

freeze() would then acquire vdev->memory_lock and proceed to reset the PCI
device while interrupts are unsafely active, potentially leading to interrupt
storms or state corruption.

>  	.retrieve = vfio_pci_liveupdate_retrieve,
> +	.can_finish = vfio_pci_liveupdate_can_finish,
>  	.finish = vfio_pci_liveupdate_finish,
>  	.owner = THIS_MODULE,
>  };

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260511234802.2280368-1-vipinsh@google.com?part=3

  reply	other threads:[~2026-05-13  4:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11 23:47 [PATCH v4 00/16] vfio/pci: Base Live Update support for VFIO Vipin Sharma
2026-05-11 23:47 ` [PATCH v4 01/16] vfio/pci: Register a file handler with Live Update Orchestrator Vipin Sharma
2026-05-13  2:44   ` sashiko-bot
2026-05-11 23:47 ` [PATCH v4 02/16] vfio/pci: Preserve vfio-pci device files across Live Update Vipin Sharma
2026-05-12 20:59   ` David Matlack
2026-05-12 21:29     ` Vipin Sharma
2026-05-13  3:24   ` sashiko-bot
2026-05-11 23:47 ` [PATCH v4 03/16] vfio/pci: Retrieve preserved device files after " Vipin Sharma
2026-05-13  4:23   ` sashiko-bot [this message]
2026-05-11 23:47 ` [PATCH v4 04/16] vfio/pci: Notify PCI subsystem about devices preserved across " Vipin Sharma
2026-05-11 23:47 ` [PATCH v4 05/16] vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD Vipin Sharma
2026-05-11 23:47 ` [PATCH v4 06/16] vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device Vipin Sharma
2026-05-11 23:47 ` [PATCH v4 07/16] docs: liveupdate: Add documentation for VFIO PCI Vipin Sharma
2026-05-11 23:47 ` [PATCH v4 08/16] vfio: selftests: Build liveupdate library in VFIO selftests Vipin Sharma
2026-05-11 23:47 ` [PATCH v4 09/16] vfio: selftests: Add vfio_pci_liveupdate_uapi_test Vipin Sharma
2026-05-11 23:47 ` [PATCH v4 10/16] vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD Vipin Sharma
2026-05-11 23:47 ` [PATCH v4 11/16] vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED Vipin Sharma
2026-05-11 23:47 ` [PATCH v4 12/16] vfio: selftests: Add vfio_pci_liveupdate_kexec_test Vipin Sharma
2026-05-11 23:47 ` [PATCH v4 13/16] vfio: selftests: Expose iommu_modes to tests Vipin Sharma
2026-05-11 23:48 ` [PATCH v4 14/16] vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device Vipin Sharma
2026-05-11 23:48 ` [PATCH v4 15/16] vfio: selftests: Verify that opening VFIO device fails during Live Update Vipin Sharma
2026-05-11 23:48 ` [PATCH v4 16/16] vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma

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=20260513042351.345FBC2BCB7@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vipinsh@google.com \
    /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