Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3] vfio/pci: expose ACPI _ROM through a device region
Date: Thu, 03 Dec 2026 14:56:08 +0000	[thread overview]
Message-ID: <sashiko-outbox-248032@kernel.org> (raw)
In-Reply-To: <147be6bed8795824d27429a8c717e2d1d08ad89f.1796307888.git.mst@redhat.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] vfio/pci: vfio_pci_register_acpi_rom() assumes short-read EOF
  on ACPI _ROM
- [Medium] vfio/pci: vfio_pci_register_acpi_rom() omits
  GFP_KERNEL_ACCOUNT and trim
--

commit adf1c581f5c9628496bf91c04bf27018695d4a66
Author: Michael S. Tsirkin <mst@redhat.com>

vfio/pci: expose ACPI _ROM through a device region

This commit adds a new VFIO_REGION_TYPE_ACPI region type with a
VFIO_REGION_SUBTYPE_ACPI_ROM subtype, snapshots the ACPI _ROM image at
device open, and exposes it as a read-only VFIO device region.

> diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
> index df88480876815..71ddf8f500508 100644
> --- a/drivers/vfio/pci/vfio_pci_rdwr.c
> +++ b/drivers/vfio/pci/vfio_pci_rdwr.c
> @@ -198,6 +201,118 @@ ssize_t vfio_pci_core_do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,

[ ... ]

> +void vfio_pci_register_acpi_rom(struct vfio_pci_core_device *vdev)
> +{

[ ... ]

> +	for (;;) {
> +		struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
> +		union acpi_object *obj;
> +		size_t len;
> +
> +		args[0].integer.value = size;
> +		if (ACPI_FAILURE(acpi_evaluate_object_typed(method, NULL, &params,
> +							    &result, ACPI_TYPE_BUFFER)))
> +			break;
> +
> +		obj = result.pointer;
> +		len = obj->buffer.length;
> +		if (len > SZ_4K || len > VFIO_PCI_ACPI_ROM_MAX - size) {
> +			ret = -EFBIG;
> +			kfree(obj);
> +			break;
> +		}
> +		if (size + len > capacity) {
> +			void *new_rom;
> +
> +			capacity = max_t(size_t, SZ_4K, capacity * 2);
> +			new_rom = kvrealloc(rom, capacity, GFP_KERNEL);
> +			if (!new_rom) {
> +				ret = -ENOMEM;
> +				kfree(obj);
> +				break;
> +			}
> +			rom = new_rom;
> +		}

[Severity: Medium]
Should this allocation use GFP_KERNEL_ACCOUNT and be trimmed to size once
probing completes?

The cached ROM buffer can reach 16 MiB and stays pinned for the lifetime
of the open device.  Using GFP_KERNEL leaves it outside the opening
process's memcg accounting, unlike other per-open allocations such as
vfio_pci_core_register_dev_region() and vfio_pci_ioeventfd().

Because capacity doubles and is never shrunk back to size, an image just
over a power-of-two boundary also keeps nearly twice as much kernel
memory allocated while the device remains open.

> +		if (len)
> +			memcpy(rom + size, obj->buffer.pointer, len);
> +		kfree(obj);
> +		size += len;
> +
> +		if (len < SZ_4K) {
> +			if (!size)
> +				return;
> +
> +			ret = vfio_pci_core_register_dev_region(vdev,
> +					VFIO_REGION_TYPE_ACPI,
> +					VFIO_REGION_SUBTYPE_ACPI_ROM,
> +					&vfio_pci_acpi_rom_ops, size,
> +					VFIO_REGION_INFO_FLAG_READ, rom);
> +			if (!ret)
> +				return;
> +			break;
> +		}
> +	}
> +
> +	pci_dbg(vdev->pdev, "ACPI _ROM region unavailable (%d)\n", ret);
> +	kvfree(rom);

[Severity: High]
Can this loop discard valid 4 KiB-aligned ROMs by relying on a short read
to detect EOF?

GPU option ROM images are routinely exact multiples of 4 KiB, so every
valid chunk returns SZ_4K and the loop probes _ROM at offset == rom_size.
ACPI _ROM does not guarantee a short or zero-length buffer past EOF.

On fixed-size DSDT buffers or OperationRegions, that out-of-bounds probe
can fail with an AML error such as AE_AML_BUFFER_LIMIT or return a
non-Buffer, breaking straight to kvfree(rom) and discarding the ROM.

Conversely, firmware that returns 4 KiB zero-padded or clamped buffers
past EOF never hits len < SZ_4K, runs 4096 AML evaluations up to 16 MiB,
and fails with -EFBIG; if it returns trailing non-ROM bytes before a
short read, the region size also exceeds the actual image length.

Aborting with -EFBIG when len > SZ_4K also differs from existing in-tree
ACPI _ROM readers in nouveau and amdgpu, which clamp the length to SZ_4K.

Parsing the PCI Expansion ROM headers to determine the exact image
length, similar to pci_get_rom_size() or nouveau's shadow_image(), would
avoid probing blindly past EOF.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/147be6bed8795824d27429a8c717e2d1d08ad89f.1796307888.git.mst@redhat.com?part=1

      reply	other threads:[~2026-12-03 14:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 14:35 [PATCH v3] vfio/pci: expose ACPI _ROM through a device region Michael S. Tsirkin
2026-12-03 14:56 ` sashiko-bot [this message]

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=sashiko-outbox-248032@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.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