From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796308511; b=D8UV4hXLAL6MHyFQW8XhtoDJpbsUtGCGuxqDhaMJs6/8a+wssGydMd5ynOMO5cNPQQwV 7OiLEy6JJeeplAfZeuGmxJ4hjqWC48hHF6uIwD5XTybhoqQQWWhJeele7+FmEnQSB8jZN YgiKoIIB398WEarQ2qCRS8Y9s5rzm9hjOoUGrT1pxMy8uvZvqJ9reg5Yfhqo5U3Xs8VDK hRp02UurR0gQeVV4tJSr6lygJyJ1OG2pe1XeIJYSn9Q8vfr+At63ZFbiYdvFx6ocaHaHp EJiiuv5cSKT3wXJ0f8ExvrwclsYWICfnvyLe3fu6rXb1Ka3xILjmDuk2gF565u/y7mQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796308511; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:Date:From: To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:X-Mailer:X-Mutt-Fcc; bh=qabwG+tNYAmd2oOwf+6iymnOjPUNKMVC0BxakRpxKnY=; b=ZmxoaUHzqnRce2+1ST114yShUDBIyM/z4V9f+xT5BG+OXs11zhoeZbS5iNfUr8Zpnc8l D+tMRbycPZjF7XD/zWpgOMHmy2SR1QGvagzX/q+WWZvd/vIGs47+ncP/QvSdNZT+KM/Cy Sc9keuwaFj7pv8Hdc24EFU/zvDapIixiumtbiPMJ797zwRCLAqu1O8n+GLXqgfKIlXJx5 TJPDCYu66QV/9BsMVI23YcXOaNdBq3vif6CGWr8+A6JjP85mGAvVvilwGt4/a9EJJZig5 3MxI5rUDCJ3NYLo28ZxsS7sI0PKwXlKci609cEUwITjMnFxT2DYBixrK6ZkIeiO1QPw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=IhiBXz2M; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=FmpyDthj; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 305A9606A322 for ; Thu, 3 Dec 2026 14:35:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 305A9606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=IhiBXz2M; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=FmpyDthj DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796308510; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=qabwG+tNYAmd2oOwf+6iymnOjPUNKMVC0BxakRpxKnY=; b=IhiBXz2M5F4UJoBwNrfNKXxixvrnXA/XV+4IKLvpbbIuZtDBDe5MnYwKlvc8230jW65xBW GoeKLzqfc+9dvlsbHar70NO/05oxSav9wNcTB867iwqF2R+/Oq4xjctlykD5N4TJ9/FV1v BayqGg3NYcPRtGV0IFtS9TQHo9pn2kk= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-352-1-9I5ljJPoy9ZlcpBo2XYg-1; Thu, 3 Dec 2026 14:35:06 +0000 X-MC-Unique: 1-9I5ljJPoy9ZlcpBo2XYg-1 X-Mimecast-MFC-AGG-ID: 1-9I5ljJPoy9ZlcpBo2XYg_1796308504 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-4aae099f5baso7337770f8f.1 for ; Thu, 03 Dec 2026 06:35:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1796308504; x=1796913304; darn=vger.kernel.org; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=qabwG+tNYAmd2oOwf+6iymnOjPUNKMVC0BxakRpxKnY=; b=FmpyDthjmUTD9KS25gzS2enF2rQCtJP42OS557Pe3nVFByUr/W46fo11xtUZ9bviD7 Dofr5my7b9LWg9uDepdstkOFtjOCShk6gE0Nk50xIGyvP1zHzz/OKJPNoxU8TPCTKdVa 1OuAzNxmHi8VjqUfoSq+cSWbx3dB9Qa8W6JAN8NQLIxSfFlENWRaqymAfvHuwKLQquTR rOeppRVRM9L6YHYhrG0QEu3JFoVrUiZoS55QohQhCHETMeEb29Msn/igxFZxPukNV3Cv lOSAddbsbLtAdmKpyBHB+VIOquvZKUkngpjKqIUDOdXryELWJUrEg6rjtZzDwIk4WZqe 0jMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796308504; x=1796913304; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=qabwG+tNYA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:a05:6000:2c13:b0:4aa:5396:a7ad with SMTP id ffacd0b85a97d-4abb16e2e36mr84753652f8f.31.1796308504081; Thu, 03 Dec 2026 06:35:04 -0800 (PST) X-Received: by 2002:a05:6000:2c13:b0:4aa:5396:a7ad with SMTP id ffacd0b85a97d-4abb16e2e36mr84753573f8f.31.1796308503286; Thu, 03 Dec 2026 06:35:03 -0800 (PST) Received: from redhat.com ([2a0d:6fc0:153a:4c00:6468:7acf:febf:a046]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6bb989b3sm84182284f8f.51.2026.12.03.06.35.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 06:35:02 -0800 (PST) Date: Thu, 3 Dec 2026 09:35:01 -0500 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Alex Williamson , kvm@vger.kernel.org Subject: [PATCH v3] vfio/pci: expose ACPI _ROM through a device region Message-ID: <147be6bed8795824d27429a8c717e2d1d08ad89f.1796307888.git.mst@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email 2.51.2.2891.g4157995a80.dirty X-Mutt-Fcc: =sent 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. Signed-off-by: Michael S. Tsirkin --- 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 | 115 +++++++++++++++++++++++++++++++ include/uapi/linux/vfio.h | 9 +++ 4 files changed, 134 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index fcbb2da860e2a..49ec5a3a29ae5 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -829,6 +829,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 4e7162234a2eb..1af780d7f1f37 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 df88480876815..71ddf8f500508 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 #include #include +#include +#include #include #include #include @@ -198,6 +201,118 @@ 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 +/* Bound the firmware probe and cache to a reasonable option ROM size. */ +#define VFIO_PCI_ACPI_ROM_MAX SZ_16M + +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]; + loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK; + + if (iswrite) + return -EINVAL; + + if (!count || pos >= region->size) + return 0; + + count = min_t(size_t, count, region->size - pos); + count -= copy_to_user(buf, region->data + pos, count); + 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) +{ + kvfree(region->data); +} + +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); + union acpi_object args[] = { + { .integer = { .type = ACPI_TYPE_INTEGER } }, + { .integer = { .type = ACPI_TYPE_INTEGER, .value = SZ_4K } }, + }; + struct acpi_object_list params = { ARRAY_SIZE(args), args }; + size_t size = 0, capacity = 0; + void *rom = NULL; + acpi_handle method; + int ret = -EIO; + + if (!handle || ACPI_FAILURE(acpi_get_handle(handle, "_ROM", &method))) + return; + + /* + * Some firmware requires 4 KiB-aligned requests. Snapshot the image + * at open so reads never invoke AML and the size and contents agree. + */ + 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, ¶ms, + &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; + } + 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); +} +#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 e41437fa17ad0..0d77f860020e9 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -345,6 +345,15 @@ 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_ACPI */ +/* + * The device firmware's ACPI _ROM image, when available. The region size is + * the exact image length in bytes. This region supports read() and pread() + * only. It is independent of the PCI expansion ROM region. + */ +#define VFIO_REGION_SUBTYPE_ACPI_ROM (1) /* sub-types for VFIO_REGION_TYPE_PCI_* */ -- MST