From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796376454; b=nhQv4/jasmpcIUxlF0BdoOB8BltDbXZcCX8FGyu8LaxeB8a5bWr+QDOcr8xh7DH8WFUT fx2hGoKnGhTIW43FimXpfEUEu8wU1EqxnL29JFGdCRxAdQZgFiYTHQ0pHb7WVRs0p3Wh0 rh4oEjr8X4VvQ5sCZz7eGVOE9PcBmoAXbCP5PtR77L4Wu4WpWS/dJJBfE1jJZ0iRxsFOY ZQ3PFf9nTCYxc00fyOUd2xnYkvnWp+t1lyBq2ywkmjQfkskbAXuikYwJdnkDoECaIxBpy VN0uYQURF06pbWOGbFVxAdEXVxtZn+PRq6fLJeauAdTLJ65wyWJ30EDadpvETsfjZ+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796376454; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received: X-Received:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=vRStuMcttz03h53UlbhaVz+4gKVlI5Si5RMZa2/gTDA=; b=KqXeoLH+bDnu0VMpJP9pP8qrSplSrWCEtsvzc6gwKEu4dml/Y1PfFocrQA2FLM7vBhk8 RDs4Ux58ilLBJEzqmHXSeI0aYx7xQDWmo79LmBh8YpRACc4E4cfxA1BUd9b/t8G/1xnIx QES4njzHiNNLqsvF+JFb+ECoIloF8HbIKAER+/MYEejqcSb6Hofb8j6IHVZrviIQEsmXc QQ/FCnaBYzkl207AACwatPzKUAmTr6gxQIlQji6IuT3ZM4qRIqyk4tSk+6X7tCsFjGtSM WLKQN2a7sBsD6u2oZSt8zvOFX2hLtS2GUH4pGD5md5b3BXqc1p38NODSTyDgE0AYlRQ== 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=GCrCauhm; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b="TDjK5/Ds"; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 727AF606A322 for ; Fri, 4 Dec 2026 09:27:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 727AF606A322 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=GCrCauhm; dkim=pass (2048-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=TDjK5/Ds DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796376452; 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: in-reply-to:in-reply-to:references:references; bh=vRStuMcttz03h53UlbhaVz+4gKVlI5Si5RMZa2/gTDA=; b=GCrCauhmvFVzqA5i2/ZyhdP6z+qz0XBaI4jwPy17gQOyyV+0Ds+XBPlw7xevdNE7WARoBn 8siocgurUcnmagKUObrg7LedstdVpPKL0K0GgKViE08MuqdGB1hDP2hjZboSGYhQE96A/5 2pUFI3cJ5D7xpNOYLiAZQMEO2Qa0hcU= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-147-D7k5-3llMNWh1AaRsx4yQA-1; Fri, 4 Dec 2026 09:27:30 +0000 X-MC-Unique: D7k5-3llMNWh1AaRsx4yQA-1 X-Mimecast-MFC-AGG-ID: D7k5-3llMNWh1AaRsx4yQA_1796376449 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4b9fde3044dso5126655e9.0 for ; Fri, 04 Dec 2026 01:27:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1796376449; x=1796981249; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=vRStuMcttz03h53UlbhaVz+4gKVlI5Si5RMZa2/gTDA=; b=TDjK5/DsaH5NExaZGkTJzica2En2jhnhufcghSXUrJwN2r7vQB53J80WLfCtrN+Mmx Ahmmry09KnS6ffSNsYmypbSAM4gt/K83le2ho+9Zbmat8zYgCYVX6oWcyOFE6mFp2ELy MPyZn4mxwj06/RrS976ZPOCOIXAi7ifV+XfxB/N1yo8btXJe4/QLAAlm7RHhywsZbAGK sILotQXTDmXbRifJzZaFJMHTGk5Oj/Npov2PabaNd9JiFK6SCvh1DeIgrwVi+OvdlDaE lGmOIFYlN4pBYC6JOBSudjKuTHo5NWYXdEcMSmpx01q+i8Nv0NWFPEUWbQhaChi7Mdpy gfBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796376449; x=1796981249; h=in-reply-to:content-disposition:content-type:mime-version :references: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=vRStuMcttz03h53UlbhaVz+4gKVlI5Si5RMZa2/gTDA=; b=j5ula00dYmOjdf7RD8ppjoxme3Q7uc+CGhLOxWcKlmyOKjd7ixQdo88IIx7wBRvNP9 Tc9iCRQLOFBtalfGLE0fCfR+GFE2bkyqcmEWNKTB1yMC7L2Ku9B/0sTu5cu5AgBkjpJp hlQvdmBhm1Dg100yENgwdFObtJreqXvAELG5dIxeUr4U0xwKSm7xjgf+munq5O8jxHoV sT9V8aF8KgQrM32Tz6q9ln6gq0PqsAm+GLO68iO8IXnrUoHObeVEVAsEDhQIcuDwI/zp HbMNm+6LAPYTYRuCKcZUrfAfxa1oBqrj/pvCqRdi/8gKBqYGiYiIVSfW5pejiD8xxkoO q29A== X-Forwarded-Encrypted: i=1; AL+hErHCO+YLCydugF8VwlBfcnNjgUdLFZwCzSD+1Ve0ygsc/Ek9MI76g91RGi0Dh1kvRmwniUA=@vger.kernel.org X-Gm-Message-State: APuU4Z/j7OiihTZPHhCDI4UZEnWG0i32eCXbfKQP5JFBy7XWjAYuO7lp D/4RF/FhTSsCH5KCvd+OOU2S4fs+yQ/Rq3NGqFi9RbGE7QdifQodH2RAcvZLWn47GeFBbE4P8g1 YNgwy/Vm62xOExPVICmcuYdluyV1ZDPFnMSep+Q7pgSx9WkH2lAHFi4m7HYjm9Q== X-Gm-Gg: AZFdTZc6sukE/5WBmACsWip7WqmDBlzTS5GwsGB8lwmyMnF1XWcoI8W1RbACp+bLxeY Q7/Jb0zHyjbuZEcOz7ea1XjUB+jqdG0SUvKbxBnf49X5ZFKp1ACzlTL1mDqI0tc5O3FGP4xWUZU qRCL/ftKF43Raz0vcfrEJZCLovIMZOBkB4C2Z7PCs2EyAXFWsc1sj33RWIbZImi+jvHoBg+LVpt rl4Evy920QYUMgj8PFoZa5l3JpVs5i4ULxwGFuM5HIiqlQnhAeW/iWKZrJQIPcaKC3dAlgCZjuF +C2V2fiDJxOrVuBuqpV1Ac90Gsf6hzB/pwcuF+Pj8H/KFCJi8NFjF3ifYMmYKqnfzvJBJ2jHz3b CmYN0M4UVHS9vGen6+p+hh6A2a2OY+4MKBS/ZLrXXGg== X-Received: by 2002:a05:600c:500f:b0:4ba:59fa:510e with SMTP id 5b1f17b1804b1-4bbeb8edbd7mr22990325e9.23.1796376448732; Fri, 04 Dec 2026 01:27:28 -0800 (PST) X-Received: by 2002:a05:600c:500f:b0:4ba:59fa:510e with SMTP id 5b1f17b1804b1-4bbeb8edbd7mr22989625e9.23.1796376448073; Fri, 04 Dec 2026 01:27:28 -0800 (PST) Received: from redhat.com ([2a0d:6fc0:153a:4c00:6468:7acf:febf:a046]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea09a089sm77125055e9.1.2026.12.04.01.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 01:27:27 -0800 (PST) Date: Fri, 4 Dec 2026 04:27:25 -0500 From: "Michael S. Tsirkin" To: Alex Williamson Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH v3] vfio/pci: expose ACPI _ROM through a device region Message-ID: <20261204041456-mutt-send-email-mst@kernel.org> References: <147be6bed8795824d27429a8c717e2d1d08ad89f.1796307888.git.mst@redhat.com> <20261203145709.29c06f89@shazbot.org> <20261203173520-mutt-send-email-mst@kernel.org> <20261203190309.153e2b7f@shazbot.org> 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-Disposition: inline In-Reply-To: <20261203190309.153e2b7f@shazbot.org> On Thu, Dec 03, 2026 at 07:03:09PM -0700, Alex Williamson wrote: > 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. I actually have a fairly simple idea. How about we just declare that the size value is unavailable for this region? Set it to 0. Let's have userspace walk the PCIR chain. QEMU already knows the format. Drastically less kernel code. I'll post v4 with this idea. > 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