Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shameer Kolothum" <skolothumtho@nvidia.com>
Cc: linux-pci@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [RFC PATCH v2 03/16] vfio/pci: Buffer ROM reads before copying to userspace
Date: Tue, 29 Sep 2026 17:49:49 +0000	[thread overview]
Message-ID: <20260929174949.69BE11F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260929173305.204856-4-skolothumtho@nvidia.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] vfio/pci: soft lockup in vfio_pci_rom_read loops due to missing cond_resched
--

commit 27d4f4cebe481807304449721e6097b02db9fc50
Author: Shameer Kolothum <skolothumtho@nvidia.com>

vfio/pci: Buffer ROM reads before copying to userspace

This commit moves ROM reads into a separate helper, buffering the requested
ROM data and unmapping the ROM before copying it to userspace. This helps
keep userspace faults outside the recovery gate.

> diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
> --- a/drivers/vfio/pci/vfio_pci_rdwr.c
> +++ b/drivers/vfio/pci/vfio_pci_rdwr.c
[ ... ]
> +static ssize_t vfio_pci_rom_read(struct vfio_pci_core_device *vdev,
> +				 char __user *buf, size_t count, loff_t pos)
> +{
[ ... ]
> +	/*
> +	 * Certain devices (e.g. Intel X710) don't support qword
> +	 * access to the ROM bar. Otherwise PCI AER errors might be
> +	 * triggered.
> +	 *
> +	 * Disable qword access to the ROM bar universally, which
> +	 * worked reliably for years before qword access is enabled.
> +	 */
> +	while (done < length) {
> +		if (length - done >= 4 && IS_ALIGNED(pos + done, 4)) {
> +			u32 val = vfio_ioread32(io + pos + done);

[Severity: High]
Can this loop cause a soft lockup on large ROM reads?

If a userspace application or guest issues a large read on the ROM BAR (for
example, 16MB), this while loop in vfio_pci_rom_read() will perform millions
of synchronous MMIO reads without yielding.

Since each MMIO read can take significant time, this could stall the CPU core
for seconds and trigger a soft lockup panic. Should this loop include a
cond_resched() to prevent an untrusted guest from causing a local Denial of
Service?

> +
> +			memcpy(data + done, &val, sizeof(val));
> +			done += sizeof(val);
> +		} else if (length - done >= 2 && IS_ALIGNED(pos + done, 2)) {
[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260929173305.204856-1-skolothumtho@nvidia.com?part=3

  reply	other threads:[~2026-09-29 17:49 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 17:32 [RFC PATCH v2 00/16] vfio/pci: Handle PCI error recovery and report state to userspace Shameer Kolothum
2026-09-29 17:32 ` [RFC PATCH v2 01/16] vfio/pci: Add a device access gate Shameer Kolothum
2026-09-29 17:48   ` sashiko-bot
2026-09-29 17:32 ` [RFC PATCH v2 02/16] vfio/pci: Gate config space access Shameer Kolothum
2026-09-29 17:52   ` sashiko-bot
2026-09-29 17:32 ` [RFC PATCH v2 03/16] vfio/pci: Buffer ROM reads before copying to userspace Shameer Kolothum
2026-09-29 17:49   ` sashiko-bot [this message]
2026-09-29 17:32 ` [RFC PATCH v2 04/16] vfio/pci: Gate BAR and ROM access Shameer Kolothum
2026-09-29 17:41   ` sashiko-bot
2026-09-29 17:32 ` [RFC PATCH v2 05/16] vfio/pci: Fail BAR faults while access is blocked Shameer Kolothum
2026-09-29 17:45   ` sashiko-bot
2026-09-29 17:32 ` [RFC PATCH v2 06/16] vfio/pci: Gate interrupt configuration Shameer Kolothum
2026-09-29 17:43   ` sashiko-bot
2026-09-29 17:32 ` [RFC PATCH v2 07/16] vfio/pci: Gate function reset and runtime power management Shameer Kolothum
2026-09-29 17:48   ` sashiko-bot
2026-09-29 17:32 ` [RFC PATCH v2 08/16] vfio/pci: Gate device information queries and DMA-BUF export Shameer Kolothum
2026-09-29 17:44   ` sashiko-bot
2026-09-29 17:32 ` [RFC PATCH v2 09/16] vfio/pci: Add PCI error recovery state Shameer Kolothum
2026-09-29 17:44   ` sashiko-bot
2026-09-29 17:32 ` [RFC PATCH v2 10/16] vfio/pci: Quiesce INTx while access is blocked Shameer Kolothum
2026-09-29 17:45   ` sashiko-bot
2026-09-29 17:33 ` [RFC PATCH v2 11/16] vfio/pci: Add INTx recovery start and finish helpers Shameer Kolothum
2026-09-29 17:44   ` sashiko-bot
2026-09-29 17:33 ` [RFC PATCH v2 12/16] vfio/pci: Restore device state from slot_reset() Shameer Kolothum
2026-09-29 17:50   ` sashiko-bot
2026-09-29 17:33 ` [RFC PATCH v2 13/16] vfio/pci: Complete recovery in resume() Shameer Kolothum
2026-09-29 17:51   ` sashiko-bot
2026-09-29 17:33 ` [RFC PATCH v2 14/16] vfio/pci: Block device access during host recovery Shameer Kolothum
2026-09-29 17:51   ` sashiko-bot
2026-09-29 17:33 ` [RFC PATCH v2 15/16] vfio/pci: Add VFIO_DEVICE_FEATURE_PCI_ERROR_RECOVERY Shameer Kolothum
2026-09-29 17:48   ` sashiko-bot
2026-09-29 17:33 ` [RFC PATCH v2 16/16] vfio/pci: Enable host PCI error recovery for vfio-pci Shameer Kolothum
2026-09-29 17:49   ` 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=20260929174949.69BE11F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=skolothumtho@nvidia.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