From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796309770; b=0OwJlAwc2z+udR0rQfMLcPlTZgAlHVmLpqOMR7MV/+7neIJ/AxEJzMDN6mfnZ5fI6TJS dSMGudp5yYKMpkgmMJYvVCjDCRRf0cW9CVE9CB1mHC3f0hBntXHlyOKUMAe42McroXg5E 6sP1/76EhsUF41kgM8qwgH8wv7mUW7F/xk67+0WElOjVwFk51c3JfpgQNcFnOcSpZFFB8 Lpc2bt9YhzQwEFBjBtDa+B38w+H1Q9BJLs0t3NFiMwlDaDTf7vJ3+sgO/OlRlziUjrc9w qvnOvsbryp3YJRMPUvEl0Vqm/8hgEN356z3GekiajE+MpJWEv7WdRvEkkeq0T6lBE/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796309770; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=4r4bszyx3l6aMSl/4YaSmc8cy7qgv0wFmPnI0PHP+7c=; b=IdHnJ/57twhFUWE9dc2+ckyqfJKcZoZWQH1hnG9usLMDRlbvqByFvQC1JVaq4RbRLfmA PgjMRP8udvcsXkKhzEq3J2EhNvdHietbXhixHCASnVA1TDF4d6Wy35L3deae3pp76t68B jiEMZGapFei6QEkTB8pV2tLNMp7Gnx+Aw0JY1eZ5ZRvUX9hLHC9SOmmg1ziyja702jrR6 Cpn8an3ZD4iH9OB7kE+1BhRa3OJDDg0FO/WnECzJM7XPUsMaJkuyzFsFde+NfZvV/UtSE TTLmydPWQlrlyvWG4f87ULUebQf+XuyjTR9m15YuVXZZiB9ppE0UqlCSs12JKQsGvtQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=d3TtmfY6; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25809606A33F for ; Thu, 3 Dec 2026 14:56:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=d3TtmfY6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A09B1F000C1; Thu, 3 Dec 2026 14:56:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796309769; bh=4r4bszyx3l6aMSl/4YaSmc8cy7qgv0wFmPnI0PHP+7c=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=d3TtmfY6bjk3tUnE47QliYm4/vMvWtV1WhIaYsHbuZpnh7Ap2X5p7Pi8s/DcxrGzy K8QATC7yfSEeeny/0GlTvzMZ7XMhbMVIXAPhwdGINMHnsRHgnYZajzzaHN4BQU1a1g FwrYdB6yctRYs2eIfTufMoIdGD+lZCxOi0/iB514PfLZKoAuS5zsjd8ACeQXxJE5Li C/do+2bAk1T6A5nTFM5rpa1jAOZOchzBjsN1Nuoxv8qGMEqssQQox4oWKIp0TXkVMY pDIHkAN0PqR4jz4K6GNj05rHoi3fla/podzfkO3o4awORHLAYNSX059m2SzSSBPeWk 2JFC1Z4umCi0g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3] vfio/pci: expose ACPI _ROM through a device region Reply-To: sashiko-reviews@lists.linux.dev To: "Michael S. Tsirkin" Cc: kvm@vger.kernel.org In-Reply-To: <147be6bed8795824d27429a8c717e2d1d08ad89f.1796307888.git.mst@redhat.com> References: <147be6bed8795824d27429a8c717e2d1d08ad89f.1796307888.git.mst@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 14:56:08 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 =3D { ACPI_ALLOCATE_BUFFER, NULL }; > + union acpi_object *obj; > + size_t len; > + > + args[0].integer.value =3D size; > + if (ACPI_FAILURE(acpi_evaluate_object_typed(method, NULL, ¶ms, > + &result, ACPI_TYPE_BUFFER))) > + break; > + > + obj =3D result.pointer; > + len =3D obj->buffer.length; > + if (len > SZ_4K || len > VFIO_PCI_ACPI_ROM_MAX - size) { > + ret =3D -EFBIG; > + kfree(obj); > + break; > + } > + if (size + len > capacity) { > + void *new_rom; > + > + capacity =3D max_t(size_t, SZ_4K, capacity * 2); > + new_rom =3D kvrealloc(rom, capacity, GFP_KERNEL); > + if (!new_rom) { > + ret =3D -ENOMEM; > + kfree(obj); > + break; > + } > + rom =3D 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 +=3D len; > + > + if (len < SZ_4K) { > + if (!size) > + return; > + > + ret =3D 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 =3D=3D rom_siz= e. 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/147be6bed8795824d27= 429a8c717e2d1d08ad89f.1796307888.git.mst@redhat.com?part=3D1