From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=202.12.124.152 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796349799; b=I0kccBvADT0bP4nO5g/2oGHKIsbFXG90la7ruRLxCZi62DiE59WkKoHfitlRpgx20zM3 QzU+H9rXRvkcdFKcThNGxMxPeoT76LfLf6oGu2JWuKeDFiXrYf2gcDX2I9xyX7NonY1xI ymFGkWAcwHKms/gqVoCbq93pHh5YtNoXlAVfUr3fgeqDODSPqcgiBa6aceqTFb6eOJ0bh KpI8kSM9EDPxYjSXv9rO0LpUkrm44hTSFG2G4q1XErkeYJxIWPAyEoqrzv8wUT0tC8CbY VJqUZa5PlXZzzkLzbGG4yHT+4Bx69Hz9ftRIerPrV7wFZSxr/Uv7zTYLEucC6IVYzeg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796349799; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: X-Mailer:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=OwA4GhIgPmzEco9Gpv2wrqMulNXfwdxMtL6KmeeK9W8=; b=FtFHd9U2dc4LfzX6afXnzh/WPcxRAz7dDBh2FTl3PTYt9Y/f2J2lqJ7XQpoUD/XYQK7A mUAjI9F/G/MtFHx3Qng4kfz7hrYebJqKY9JqS8LmTl7GvD5ufBWO/AY5lB9hvosSVPiWH P6zsdt9RquFEFFRcHoMhD+KmkgYVGLP2nTDRKhjM+uinDn1a5yGiGiwAirebVADObXpmy gf54P4YvgysyRNzTyxY/aD+epqHte+J4Kjj8ohEIeGCG4b06dwgy2xWbtBR0kMn+qKIM5 cl4cG3TAne+Vdarmo94dNssFOthMJLY7lnzD2gybtKQDRykO9sunufhdVa+ttJepkPQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=shazbot.org; spf=pass smtp.mailfrom=shazbot.org; dkim=pass header.d=shazbot.org header.i=@shazbot.org header.a=rsa-sha256 header.s=fm3 header.b=d78s4Un0; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=su7L9wMk; arc=none smtp.remote-ip=202.12.124.152 Received: from fhigh-b1-smtp.messagingengine.com (fhigh-b1-smtp.messagingengine.com [202.12.124.152]) (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 9A8B3606A32C for ; Fri, 4 Dec 2026 02:03:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9A8B3606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shazbot.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shazbot.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=shazbot.org header.i=@shazbot.org header.a=rsa-sha256 header.s=fm3 header.b=d78s4Un0; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=su7L9wMk Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfhigh.stl.internal (Postfix) with ESMTP id 004847A015A for ; Thu, 3 Dec 2026 21:03:17 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Thu, 03 Dec 2026 21:03:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shazbot.org; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1796349797; x=1796436197; bh=OwA4GhIgPmzEco9Gpv2wrqMulNXfwdxMtL6KmeeK9W8=; b= d78s4Un0dGf+/XvCtPxP2hjS8oflGcUmLJvdI2EdQCjQspMAztCFCDbXPY5GW3tN pFSzEGH5tSSgk0VbsmrHKp/I+YL91Z7/8CeWZNGnD76b34BCesWC0qKGdH7jNDOD s2515CukAu8SIdXEGr4WKzzWCWa1nF5vqSaSmCzZHpuD0dUm2cTpVWlTGvqRYAm5 GEoi7NAODNRMEC7P8KIFdd20R+TCPTIrkI5bule+geibPJ6/N0WenMWhBtc/TF4l RzuaWE6OfYSxK/5lAfEBJD6khkgphx85fXd/XsgBylPWHkij0PTWL8GOUeWNchFG ZsQvDsL4M1EyOaSiQnLNDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1796349797; x= 1796436197; bh=OwA4GhIgPmzEco9Gpv2wrqMulNXfwdxMtL6KmeeK9W8=; b=s u7L9wMkmxcslGqm2eyaaP3JBpriQC7Wnm1Ho0cqnNrJtFdJvWW897ataCoU8M6A7 H/imZw0ZPEssL1dpTGNYiBxtO+hSBzOXmG6fsw8JUf4I9MBcdhwL/qBXjGIXPtLQ GVjD89DAFwNrHetM70XmzM3XRUCQCe+QpPck50D2H6j9a3Bcw7bV8AFidQIq4CKR o3Qg0SmrZSXV7SiGTKU1ltO2K1bUJnYn7EyT1P3+A1KLOe4DkjltlQp43sktrS5r odRLjYvVNDWEBDIbjVqM0L3qhbUog4wtP/YfnYBxmiN4TDSB/biR6Odyf8Pnqe0E VJDkXowMtg6blXahe5AXQ== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=shazbot.org a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796349797; d=shazbot.org; mf=PGFsZXhAc2hhemJvdC5vcmc+; rt=PGt2bUB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:IiusnQs3EJfWe+oXott43fILrbTm4pUaFgse9GyVoadpZRD sZbwD+u0V+ZASwzW27b01DXTQ8mJdjrYfCuYbhzf6lLn3XK0EblMgxgBiimp3C4d q4NTSUakOTvgqCCRpCiL7onXWIo5QbPS+XYjKQoDdZvj2iL/guZgeVh2HfhMwql7 0oOvcizR17HGNBVpcTsZrB/RElAsgVUuJIzuzgQsBO+/1Jg3wjSrB0P1BDzP5Gvs iE2dB7UJCqqBgh4SODkqYk1TATtqPp4FFz5vXZTxo1/omotDnjdTyDnyr8llNbhc 17SnPPZnMio/nCCiguFFuod/glGYW3d6YS6+9qQ==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-transfer-encoding,content-type,date,feedback-id, from,in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:UghGkr84Jt/5UHKPNQz1dt5zHtOAQRwCYr5MwSaqpPE=:49WF/7/ThxnBhXNIGJTbwvcVxdRyYZQjl2nE9/HjZ+A=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTG32nC9xPBrx6OmtEgeqJ7iJYlhKhw+WjOxqLsUU8K4Nqaik3K8bet8VVmKzr9MZd /ZbOJ8SAjTWBuMW/21pzXz4+OBaJC79I/5QUWmJ6LsPVCgTQZNl4hqoSme5H7iaJ+4SAKO 6ZXzdW+q/p/M3yVQRhXa8hQZuxPy+pm9f/AyTCElnpxJyx/ru51V/wnj3iYPk920BlQ7kT 7LY/JDLhXlsmP2lCkdrTb3kKuujyvAAVRpoDDsU4nhHr1oZ7+oG+Oez73VpwAhoU1Z3Kxg hwQ9Nl1uoROPlZt+TNQegMUiA72gtaXlED3GsVStcxTMgxhsXN2JNtAROKVf6B+o2bk+ld KvXoCs93W93vGUONFcyzKpeRFhXVGuT4RusZh8WiFrqbJfI0NHDJS55YhBdVWw0HvjV4X5 a3W5Ig3XxkYjLsVNZQcyLT/K8PnBsp9rXrH6gYBx1QWFPQLDVzEB9iKzQ7RZ1K3SQWZ8eK S6e+B6hvcqlInZgBcWn5zzCNmvNGwZGNnX2SJdf+ICTFNZEUHp4+0rB2QkHwHZnQV/JnUc vTWmTs6qOz01ce5gPTEieTnLfW/Nh2DtazRxQ3sa6uPfxV0L/klPGFPU9g1SUXIiUvxyW2 XLGUaPpvv3e4Lwcsm8PsQBTzrdOsutFiFLKfT4qgwVBF3DxiJU0Us/eAaJHA X-ME-Proxy: Feedback-ID: i03f14258:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 3 Dec 2026 21:03:16 -0500 (EST) Date: Thu, 3 Dec 2026 19:03:09 -0700 From: Alex Williamson To: "Michael S. Tsirkin" Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, alex@shazbot.org Subject: Re: [PATCH v3] vfio/pci: expose ACPI _ROM through a device region Message-ID: <20261203190309.153e2b7f@shazbot.org> In-Reply-To: <20261203173520-mutt-send-email-mst@kernel.org> References: <147be6bed8795824d27429a8c717e2d1d08ad89f.1796307888.git.mst@redhat.com> <20261203145709.29c06f89@shazbot.org> <20261203173520-mutt-send-email-mst@kernel.org> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) X-Mailing-List: kvm@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-Transfer-Encoding: 7bit On Thu, 3 Dec 2026 18:06:34 -0500 "Michael S. Tsirkin" wrote: > On Thu, Dec 03, 2026 at 02:57:09PM -0700, Alex Williamson wrote: > > On Thu, 3 Dec 2026 09:35:01 -0500 > > "Michael S. Tsirkin" wrote: > > > +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. > > > + */ > > > > Can you cite some firmware that has this requirement? I don't want to > > come back to this in the future without an example of firmware that > > imposes this requirement. > > Yes, it's in nouveau history: > > In 2012 Ben Skeggs changed the initial ACPI ROM header probe > from _ROM(0, 3) to _ROM(0, 4096) for firmware compatibility. > > https://github.com/torvalds/linux/commit/d1626a965141 Let's cite the history in the comment then. > > That alone also doesn't feel like it justifies allocating up to 16MB of > > kernel memory and holding it for the whole user session. > > 16M of virtually contiguos memory a problem? > > Well I started with reading exactly what userspace requested. I then > got a comment that userspace reading byte by byte will invoke 4K ACPI > calls per page. So now I am caching it all. It is simple, at least. I think this was sashiko's comment on v1, where every call to vfio_pci_bar_rw() performed a brute force read of the full _ROM image to reevaluate the length. The example it provided was a user simply trying to read a 128KB ROM image with 4-byte accesses would trigger the sizing loop 32,768 times. Extrapolating, each loop would make 32 _ROM calls, plus another for the access itself, results in over a million _ROM calls. We can actually strategically size the ROM with just a few _ROM reads, cache that size, then perform one _ROM access for each of those 4-byte accesses. That's a one time sizing and 33x fewer _ROM calls to read the full image. That 33x scales linearly with the ROM size. This is what my v1 reply demonstrated. 16MB of kernel memory, that isn't even using GFP_KERNEL_ACCOUNT, that is rarely accessed, and doesn't even have a userspace that uses it yet, does seem excessive, IMO. > > We can > > perform reads with 4K alignment and return short reads to get the user > > onto the alignment we require. > > > > Sashiko notes a couple issues, particularly in this method of sizing > > the ROM. Why shouldn't we walk the ROM image chain read through _ROM > > to determine the size, save only that size in the init phase, then do > > aligned reads (if necessary), on demand as the user accesses? > > I don't mind, but didn't you worry about malformed firmware earlier? > Something about firmware burners? It's the same algorithm that pci_get_rom_size() uses on ROM BARs. On the PCI side the extent is bounded by the ROM BAR resource size, so we'd need some pragmatic limit to replace that. A short read or error walking the image chain should fail and generate a pci_info(). Probably also a good idea to test reading the last byte of the image chain. The burners issue was that some users update device firmware from the VM, so the previously proposed fall through (v2) could result in presenting an inconsistent view of the ROM BAR. Maybe the ROM BAR, maybe the _ROM. This isn't an issue with the separate device specific region, especially where the ROM image isn't provided by the device itself. It becomes a userspace problem not to repeat the fall-through trap. > > Aside from the alignment, and the device specific region proposed here, > > I basically proposed those mechanics in > > https://lore.kernel.org/all/20261015112719.20d08b4c@shazbot.org/ > > You actually complained about "letting the user so easily > monopolize the ACPI interpreter lock". If we invoke ACPI > in response to userspace system calls we do exactly that. > Confused. I believe that was my reiteration of the sashiko finding above, where I replied with the example code that does both the strategic and cached sizing, and on-demand _ROM calls for user access. I have waffled in my own thinking whether to use cached or on-demand access, but I think a few points skew in the direction of on-demand: - _ROM methods likely only exist for onboard devices - The known use cases are laptops - Laptops are often memory constrained - Laptops are rarely multi-tenant VM hosts Additionally, with the device specific region we can define our own access semantics and deprecate mechanisms that don't work. We could even define a read-once semantic if we needed to, versus being governed by the PCI spec for the ROM access semantics. Thanks, Alex