* [PATCH v7] vfio/pci: expose ACPI _ROM through a device region
@ 2026-12-04 11:19 Michael S. Tsirkin
2026-12-04 11:54 ` sashiko-bot
2026-12-04 15:03 ` Alex Williamson
0 siblings, 2 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2026-12-04 11:19 UTC (permalink / raw)
To: Alex Williamson; +Cc: kvm
Some GPUs provide their option ROM through the ACPI _ROM method.
According to the spec, _ROM, if present, must supercede the
PCI ROM BAR, but VFIO currently provides no means to access its
contents.
Let's report it through a new VFIO_REGION_TYPE_ACPI subtype:
VFIO_REGION_SUBTYPE_ACPI_ROM.
Note that _ROM size is not provided by the firmware and has to be parsed
from the image. Let's leave this to userspace.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
Apologies for spamming, v6 was just completely broken.
Changes from v6:
Declare params after args.
Handle offsets >=4GB.
Changes from v3:
Drop rom cache and size heuristics, userspace can handle them.
Document source of 4k alignment information.
Changes from v2:
Leave ROM BAR alone to avoid a risk of regressions.
drivers/vfio/pci/vfio_pci_core.c | 1 +
drivers/vfio/pci/vfio_pci_priv.h | 9 ++++
drivers/vfio/pci/vfio_pci_rdwr.c | 89 ++++++++++++++++++++++++++++++++
include/uapi/linux/vfio.h | 9 ++++
4 files changed, 108 insertions(+)
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 511dcb49d2f6..8b43b5148f18 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -831,6 +831,7 @@ EXPORT_SYMBOL_GPL(vfio_pci_core_close_device);
void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev)
{
+ vfio_pci_register_acpi_rom(vdev);
vfio_pci_probe_mmaps(vdev);
#if IS_ENABLED(CONFIG_EEH)
eeh_dev_open(vdev->pdev);
diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_priv.h
index 4e7162234a2e..1af780d7f1f3 100644
--- a/drivers/vfio/pci/vfio_pci_priv.h
+++ b/drivers/vfio/pci/vfio_pci_priv.h
@@ -44,6 +44,15 @@ ssize_t vfio_pci_config_rw_single(struct vfio_pci_core_device *vdev,
ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
size_t count, loff_t *ppos, bool iswrite);
+#ifdef CONFIG_ACPI
+void vfio_pci_register_acpi_rom(struct vfio_pci_core_device *vdev);
+#else
+static inline void
+vfio_pci_register_acpi_rom(struct vfio_pci_core_device *vdev)
+{
+}
+#endif
+
#ifdef CONFIG_VFIO_PCI_VGA
ssize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev, char __user *buf,
size_t count, loff_t *ppos, bool iswrite);
diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
index df8848087681..35be5a8bc39a 100644
--- a/drivers/vfio/pci/vfio_pci_rdwr.c
+++ b/drivers/vfio/pci/vfio_pci_rdwr.c
@@ -10,8 +10,11 @@
* Author: Tom Lyon, pugs@cisco.com
*/
+#include <linux/acpi.h>
#include <linux/fs.h>
#include <linux/pci.h>
+#include <linux/sizes.h>
+#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/io.h>
#include <linux/vfio.h>
@@ -198,6 +201,92 @@ ssize_t vfio_pci_core_do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
}
EXPORT_SYMBOL_GPL(vfio_pci_core_do_io_rw);
+#ifdef CONFIG_ACPI
+static ssize_t vfio_pci_acpi_rom_rw(struct vfio_pci_core_device *vdev,
+ char __user *buf, size_t count,
+ loff_t *ppos, bool iswrite)
+{
+ unsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
+ struct vfio_pci_region *region = &vdev->region[index - VFIO_PCI_NUM_REGIONS];
+ u64 pos = *ppos & VFIO_PCI_OFFSET_MASK;
+ struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
+ union acpi_object *obj;
+ size_t available;
+ /*
+ * ACPI limits requests to 4K, and some FW seems to only handle
+ * full 4K aligned blocks. See
+ * ad4a36263535 ("drm/nouveau/bios: split out shadow methods").
+ * and
+ * d1626a965141 ("drm/nouveau/bios: fetch full 4KiB block to determine ACPI ROM image size").
+ */
+ size_t skip = pos % SZ_4K;
+ union acpi_object args[] = {
+ { .integer = { .type = ACPI_TYPE_INTEGER, .value = pos - skip } },
+ { .integer = { .type = ACPI_TYPE_INTEGER, .value = SZ_4K } },
+ };
+ struct acpi_object_list params = { ARRAY_SIZE(args), args };
+
+ if (iswrite)
+ return -EINVAL;
+
+ if (!count)
+ return 0;
+
+ /*
+ * A 32-bit AML interpreter cannot handle larger offsets, and ROMs
+ * larger than 4G are unlikely. Truncate at the 4G boundary.
+ */
+ if (pos > U32_MAX)
+ return 0;
+
+ if (ACPI_FAILURE(acpi_evaluate_object_typed(region->data, NULL, ¶ms,
+ &result, ACPI_TYPE_BUFFER)))
+ return -EIO;
+
+ obj = result.pointer;
+ available = min_t(size_t, obj->buffer.length, SZ_4K);
+ if (skip >= available) {
+ kfree(obj);
+ return 0;
+ }
+
+ count = min(count, available - skip);
+ count -= copy_to_user(buf, obj->buffer.pointer + skip, count);
+ kfree(obj);
+ if (!count)
+ return -EFAULT;
+
+ *ppos += count;
+ return count;
+}
+
+static void vfio_pci_acpi_rom_release(struct vfio_pci_core_device *vdev,
+ struct vfio_pci_region *region)
+{
+}
+
+static const struct vfio_pci_regops vfio_pci_acpi_rom_ops = {
+ .rw = vfio_pci_acpi_rom_rw,
+ .release = vfio_pci_acpi_rom_release,
+};
+
+void vfio_pci_register_acpi_rom(struct vfio_pci_core_device *vdev)
+{
+ acpi_handle handle = ACPI_HANDLE(&vdev->pdev->dev), method;
+ int ret;
+
+ if (!handle || ACPI_FAILURE(acpi_get_handle(handle, "_ROM", &method)))
+ return;
+
+ ret = vfio_pci_core_register_dev_region(vdev, VFIO_REGION_TYPE_ACPI,
+ VFIO_REGION_SUBTYPE_ACPI_ROM,
+ &vfio_pci_acpi_rom_ops, 0,
+ VFIO_REGION_INFO_FLAG_READ, method);
+ if (ret)
+ pci_info(vdev->pdev, "ACPI _ROM region unavailable (%d)\n", ret);
+}
+#endif /* CONFIG_ACPI */
+
ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
size_t count, loff_t *ppos, bool iswrite)
{
diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
index e41437fa17ad..6e81844d47ad 100644
--- a/include/uapi/linux/vfio.h
+++ b/include/uapi/linux/vfio.h
@@ -345,6 +345,7 @@ struct vfio_region_info_cap_type {
#define VFIO_REGION_TYPE_GFX (1)
#define VFIO_REGION_TYPE_CCW (2)
#define VFIO_REGION_TYPE_MIGRATION_DEPRECATED (3)
+#define VFIO_REGION_TYPE_ACPI (4)
/* sub-types for VFIO_REGION_TYPE_PCI_* */
@@ -428,6 +429,14 @@ struct vfio_region_gfx_edid {
/* sub-types for VFIO_REGION_TYPE_MIGRATION */
#define VFIO_REGION_SUBTYPE_MIGRATION_DEPRECATED (1)
+/* sub-types for VFIO_REGION_TYPE_ACPI */
+/*
+ * Read-only PCI expansion ROM from the device firmware's ACPI _ROM method.
+ * Size is always zero for this subtype. Userspace can parse the ROM image
+ * to determine its size.
+ */
+#define VFIO_REGION_SUBTYPE_ACPI_ROM (1)
+
struct vfio_device_migration_info {
__u32 device_state; /* VFIO device state */
#define VFIO_DEVICE_STATE_V1_STOP (0)
base-commit: 0b75cdfe60c4db031d8a6dcdf5c7ceafcfe5fa02
--
MST
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v7] vfio/pci: expose ACPI _ROM through a device region
2026-12-04 11:19 [PATCH v7] vfio/pci: expose ACPI _ROM through a device region Michael S. Tsirkin
@ 2026-12-04 11:54 ` sashiko-bot
2026-12-04 15:03 ` Alex Williamson
1 sibling, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-04 11:54 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: kvm
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] vfio/pci: 32-bit offset and bit-field overflow in
vfio_pci_acpi_rom_rw()
- [Medium] acpi: u32 overflow in acpi_ds_init_buffer_field() exposed via
VFIO _ROM
- [Medium] vfio/pci: unpinned ACPI _ROM handle cached in
vfio_pci_register_acpi_rom()
--
commit 48060cebe78f47e4a597a63ad3811049e5e9dde4
Author: Michael S. Tsirkin <mst@redhat.com>
vfio/pci: expose ACPI _ROM through a device region
This commit registers a read-only VFIO_REGION_SUBTYPE_ACPI_ROM device region
when a PCI device provides an ACPI _ROM method, allowing userspace to read
the option ROM in 4 KiB chunks.
> diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
> index df88480876815..ec324cdaa3cc7 100644
> --- a/drivers/vfio/pci/vfio_pci_rdwr.c
> +++ b/drivers/vfio/pci/vfio_pci_rdwr.c
> @@ -198,6 +201,92 @@ ssize_t vfio_pci_core_do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
> }
> EXPORT_SYMBOL_GPL(vfio_pci_core_do_io_rw);
>
> +#ifdef CONFIG_ACPI
> +static ssize_t vfio_pci_acpi_rom_rw(struct vfio_pci_core_device *vdev,
> + char __user *buf, size_t count,
> + loff_t *ppos, bool iswrite)
> +{
[ ... ]
> + size_t skip = pos % SZ_4K;
> + union acpi_object args[] = {
> + { .integer = { .type = ACPI_TYPE_INTEGER, .value = pos - skip } },
> + { .integer = { .type = ACPI_TYPE_INTEGER, .value = SZ_4K } },
> + };
> + struct acpi_object_list params = { ARRAY_SIZE(args), args };
[ ... ]
> + /*
> + * A 32-bit AML interpreter cannot handle larger offsets, and ROMs
> + * larger than 4G are unlikely. Truncate at the 4G boundary.
> + */
> + if (pos > U32_MAX)
> + return 0;
[Severity: High]
Can pos values near U32_MAX or at 512 MiB still overflow 32-bit arithmetic
in AML and ACPICA?
For pos in [0xFFFFF000, 0xFFFFFFFF], pos <= U32_MAX passes, so _ROM receives
Arg0 = 0xFFFFF000 and Arg1 = 0x1000. On a 32-bit ACPI table
(acpi_gbl_integer_byte_width == 4), acpi_ex_truncate_for32bit_table()
truncates Add(Arg0, Arg1) to 0, bypassing firmware bounds checks of the form
(Arg0 + Arg1) > RomSize.
In addition, at pos = 0x1FFFF000 (or 0xFFFFF000), a _ROM method using
CreateField(VROM, Arg0 * 8, Arg1 * 8, ...) overflows bit_offset (0xFFFF8000)
+ bit_count (0x8000) to 0 in u32 inside acpi_ds_init_buffer_field(),
bypassing the buffer-length check. acpi_ex_field_datum_io() then performs
an unchecked 4 KiB memcpy from buffer.pointer + 0x1FFFF000, which can oops
or copy 4 KiB of kernel heap memory to an unprivileged VFIO userspace
process. At pos = 0x20000000, (u32)(pos * 8) truncates to 0 and aliases
512 MiB back to offset 0.
Capping pos well below 512 MiB (such as a realistic PCI ROM limit like
SZ_16M) would prevent both byte and bit 32-bit overflows.
> + if (ACPI_FAILURE(acpi_evaluate_object_typed(region->data, NULL, ¶ms,
> + &result, ACPI_TYPE_BUFFER)))
> + return -EIO;
[Severity: Medium]
Does exposing acpi_evaluate_object_typed() on _ROM with arbitrary userspace
offsets hit an unchecked u32 overflow in ACPICA's
acpi_ds_init_buffer_field()?
drivers/acpi/acpica/dsopcode.c:acpi_ds_init_buffer_field() {
...
offset = (u32) offset_desc->integer.value;
...
if ((bit_offset + bit_count) > (8 * (u32)buffer_desc->buffer.length)) {
...
}
If platform _ROM AML creates a buffer field from an unclamped Arg0 and
userspace reads at pos = 0x1FFFF000, bit_offset + bit_count wraps to 0 in
u32 and passes the check. acpi_ex_prep_common_field_object() then sets
base_byte_offset to 0x1FFFF000 and acpi_ex_field_datum_io() reads 4 KiB past
buffer->pointer without bounds checking, letting an unprivileged VFIO user
trigger a page fault or leak kernel memory.
Checking for 32-bit truncation and overflow in acpi_ds_init_buffer_field()
(matching AML_MID_OP in exoparg3.c) alongside tightening the offset cap in
vfio_pci_acpi_rom_rw() would close this.
[ ... ]
> +void vfio_pci_register_acpi_rom(struct vfio_pci_core_device *vdev)
> +{
> + acpi_handle handle = ACPI_HANDLE(&vdev->pdev->dev), method;
> + int ret;
> +
> + if (!handle || ACPI_FAILURE(acpi_get_handle(handle, "_ROM", &method)))
> + return;
> +
> + ret = vfio_pci_core_register_dev_region(vdev, VFIO_REGION_TYPE_ACPI,
> + VFIO_REGION_SUBTYPE_ACPI_ROM,
> + &vfio_pci_acpi_rom_ops, 0,
> + VFIO_REGION_INFO_FLAG_READ, method);
[Severity: Medium]
Can caching the raw _ROM acpi_handle in region->data lead to a
use-after-free if the SSDT defining _ROM is dynamically unloaded while the
VFIO device fd remains open?
acpi_get_handle() returns an unrefcounted struct acpi_namespace_node
pointer. Unloading the SSDT via configfs (acpi_table_drop_item() ->
acpi_unload_table() -> acpi_ns_delete_node() -> kmem_cache_free()) frees
that node without invalidating region->data. Because
vfio_pci_acpi_rom_rw() passes region->data with a NULL pathname to
acpi_evaluate_object_typed(), ACPICA skips acpi_get_handle() and passes the
freed pointer directly to acpi_ns_get_external_pathname() ->
acpi_ns_build_normalized_path(), dereferencing freed slab memory.
Checking acpi_has_method(handle, "_ROM") at registration time and passing
ACPI_HANDLE(&vdev->pdev->dev) with pathname "_ROM" to
acpi_evaluate_object_typed() on each read would avoid holding a dangling
namespace node pointer.
--
Sashiko AI review · https://sashiko.dev/#/patchset/e0ca997750e9064ac6e17e2a7cbe957afed27ab1.1796383014.git.mst@redhat.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v7] vfio/pci: expose ACPI _ROM through a device region
2026-12-04 11:19 [PATCH v7] vfio/pci: expose ACPI _ROM through a device region Michael S. Tsirkin
2026-12-04 11:54 ` sashiko-bot
@ 2026-12-04 15:03 ` Alex Williamson
2026-12-04 15:41 ` Michael S. Tsirkin
1 sibling, 1 reply; 5+ messages in thread
From: Alex Williamson @ 2026-12-04 15:03 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: kvm, alex
On Fri, 4 Dec 2026 06:19:54 -0500
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> Some GPUs provide their option ROM through the ACPI _ROM method.
> According to the spec, _ROM, if present, must supercede the
> PCI ROM BAR, but VFIO currently provides no means to access its
> contents.
>
> Let's report it through a new VFIO_REGION_TYPE_ACPI subtype:
> VFIO_REGION_SUBTYPE_ACPI_ROM.
>
> Note that _ROM size is not provided by the firmware and has to be parsed
> from the image. Let's leave this to userspace.
Nak. This doesn't align with existing semantics that define other zero
sized regions as not present. It also makes it non-deterministic which
region a user is trying to access based on offset. The fixed region
spacing is implementation, not API. The API is to use region offset
and size from the region-info ioctl. We'll eventually be more densely
packing regions to account for BARs and device memory that exceed the
current 40 bit segmentation. Thanks,
Alex
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v7] vfio/pci: expose ACPI _ROM through a device region
2026-12-04 15:03 ` Alex Williamson
@ 2026-12-04 15:41 ` Michael S. Tsirkin
2026-12-04 16:38 ` Alex Williamson
0 siblings, 1 reply; 5+ messages in thread
From: Michael S. Tsirkin @ 2026-12-04 15:41 UTC (permalink / raw)
To: Alex Williamson; +Cc: kvm
On Fri, Dec 04, 2026 at 08:03:33AM -0700, Alex Williamson wrote:
> On Fri, 4 Dec 2026 06:19:54 -0500
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
>
> > Some GPUs provide their option ROM through the ACPI _ROM method.
> > According to the spec, _ROM, if present, must supercede the
> > PCI ROM BAR, but VFIO currently provides no means to access its
> > contents.
> >
> > Let's report it through a new VFIO_REGION_TYPE_ACPI subtype:
> > VFIO_REGION_SUBTYPE_ACPI_ROM.
> >
> > Note that _ROM size is not provided by the firmware and has to be parsed
> > from the image. Let's leave this to userspace.
>
> Nak. This doesn't align with existing semantics that define other zero
> sized regions as not present. It also makes it non-deterministic which
> region a user is trying to access based on offset. The fixed region
> spacing is implementation, not API. The API is to use region offset
> and size from the region-info ioctl. We'll eventually be more densely
> packing regions to account for BARs and device memory that exceed the
> current 40 bit segmentation. Thanks,
>
> Alex
Well exactly. And _ROM is not in device memory at all. It's offset is
wholly artificial. Isn't it? So wouldn't packing a zero sized one be
easier, going forward?
I don't insist, I can code up the parser, just making sure you are sure
this is what you want.
--
MST
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v7] vfio/pci: expose ACPI _ROM through a device region
2026-12-04 15:41 ` Michael S. Tsirkin
@ 2026-12-04 16:38 ` Alex Williamson
0 siblings, 0 replies; 5+ messages in thread
From: Alex Williamson @ 2026-12-04 16:38 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: kvm, alex
On Fri, 4 Dec 2026 10:41:06 -0500
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Fri, Dec 04, 2026 at 08:03:33AM -0700, Alex Williamson wrote:
> > On Fri, 4 Dec 2026 06:19:54 -0500
> > "Michael S. Tsirkin" <mst@redhat.com> wrote:
> >
> > > Some GPUs provide their option ROM through the ACPI _ROM method.
> > > According to the spec, _ROM, if present, must supercede the
> > > PCI ROM BAR, but VFIO currently provides no means to access its
> > > contents.
> > >
> > > Let's report it through a new VFIO_REGION_TYPE_ACPI subtype:
> > > VFIO_REGION_SUBTYPE_ACPI_ROM.
> > >
> > > Note that _ROM size is not provided by the firmware and has to be parsed
> > > from the image. Let's leave this to userspace.
> >
> > Nak. This doesn't align with existing semantics that define other zero
> > sized regions as not present. It also makes it non-deterministic which
> > region a user is trying to access based on offset. The fixed region
> > spacing is implementation, not API. The API is to use region offset
> > and size from the region-info ioctl. We'll eventually be more densely
> > packing regions to account for BARs and device memory that exceed the
> > current 40 bit segmentation. Thanks,
> >
> > Alex
>
> Well exactly. And _ROM is not in device memory at all. It's offset is
> wholly artificial. Isn't it? So wouldn't packing a zero sized one be
> easier, going forward?
>
> I don't insist, I can code up the parser, just making sure you are sure
> this is what you want.
Maybe there's a gap that isn't clear; all regions are offsets into the
device fd. All region offsets are arbitrary. We provide introspection
via the region-info ioctl.
The "push the problem to the user" solution here only works when each
region is sufficiently large and evenly segmented that we can use fixed
bits in the offset to determine the region handler. Aside from
breaking existing semantics of regions with zero size, this breaks down
when we want to densely pack regions and we need to know how much space
each region requires to lay out the offset to region handler mappings.
Therefore, we eventually need to do the same ROM image sizing
internally, and an interim solution like this requires that the
algorithm is compatible with whatever results the user got from their
own algorithm previously. I don't want to support that.
The ROM image walk internally to generate a cached size is really the
same approach I've been endorsing since my v1 reply. Thanks,
Alex
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-04 16:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 11:19 [PATCH v7] vfio/pci: expose ACPI _ROM through a device region Michael S. Tsirkin
2026-12-04 11:54 ` sashiko-bot
2026-12-04 15:03 ` Alex Williamson
2026-12-04 15:41 ` Michael S. Tsirkin
2026-12-04 16:38 ` Alex Williamson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox