From patchwork Mon Feb 24 18:29:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13988764 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B305C021BB for ; Mon, 24 Feb 2025 18:35:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdGq-0001Pg-2h; Mon, 24 Feb 2025 13:33:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmdDF-0005gA-Tn for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:29:55 -0500 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdD7-0003JM-9d for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:29:52 -0500 Received: by mail-pl1-x641.google.com with SMTP id d9443c01a7336-220c8cf98bbso13344025ad.1 for ; Mon, 24 Feb 2025 10:29:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740421781; x=1741026581; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lPwdQyAYH1XWglrDs3yxsMrLIl2j/SlpqBC7lDIhGyg=; b=dAkccxEtyaI0P/JROy0UzVuBth76nQGX6N+hrrMsD2WEyC+Pn9IJHWd16HGJglxdFp k6wg92GT68Gx3XA1T0Iyo6/XwhN4lkJkvAFGD+WIZNPEjPZozA74t1bsYAikXcc71RqZ cXIqoM6ssFs/oi2tNZCE54RZWGVMG9muzIf7LmbpmhddgBoxKEZf8GesxdbVX993TN47 qSkETBmtyOdeUCe3HrylxAcQ8JzSRDUYJD39gfoJs0pk/cC5Y/8tqgClslMIqvw8Ar3T qfWOSu1RRhy+YE3IK0HG9A0sFGTAh9TZ5O+Pl7MLmCEIr07W+0ELBv8l1zSQumga2SRW njVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740421781; x=1741026581; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lPwdQyAYH1XWglrDs3yxsMrLIl2j/SlpqBC7lDIhGyg=; b=H0bAPvsotGNK4HOEdh5JiOALlK/SZanunOOcu92Sbk1LkMTABN9z/2WIEJMkPNDSke wF4mv37oba0sCXn+NrzCcFLg/kDDxZfA6qsJfgECZnLmsXAadklvQJJuQcKQ59lVof0i UHCH2IhbUJ9lq/7wzWzFVxMdUnv3tH2TLI3CJEKBX5wrL/JrvcUKgBxFXkjgHuijlR/b 3HbXEtMvH/Hh7sB7LsLIkkIWhkNOqMzIiAAV19hMuwNaFz7fcR7qDoOYvCHq/n+NuX2T Lrep6pjRAX9l+G6WDw61VAvQFWQhYntn/9D3CYNHmd1eHZ5gokKVeJJlxQJuXimoh/Zo TlvQ== X-Gm-Message-State: AOJu0YyfQvFnIbDacQhvNJP0nMuGzm32r38siafgyToL017rHYo2fLVS QOtcnXxZDAiZotldIacwmsL3TeJhlWD5Ix7BtcZ/4rKG/tTy1Zzzk/fRv4X7vg== X-Gm-Gg: ASbGncuSXZKJu9UN71E8j7ojJm6HbKOng4fLK+h1baiGrHi9qDSy9Jctp8676K1BxWA pUrXxw63dJa7UNvkTwHkigxxUG8exPu+AKnw4YMsQUAmEC3hhMLT697YFARYx6CC1cuqqbMfy0f s8WX+zcDbaauRxy7Y18BKR4Zb1X3obHKkRaQfVvmBE1tcIWPgL1gCZbG9kqnYJzVC5cIXt4D6jW Ekm2V3sHfikan5OZUw91b0ozjDBy0cxQh3P9RmB//CNIPIQNFwIc9HmG30cr6GeK4EgQuRAMTB9 n6X15OBL2cp6wyOOMlVPK2RwTrlN4WB5rCQPkqY= X-Google-Smtp-Source: AGHT+IFTTyAIcwmc+ghZnZ0tTw7Ml7hnOkduu6V9O7ot2F4A+nVPhazCUwc8uBHrY0hFNTEvcZJfFg== X-Received: by 2002:a17:903:2349:b0:21f:baa:80be with SMTP id d9443c01a7336-221a118a866mr240107215ad.46.1740421781215; Mon, 24 Feb 2025 10:29:41 -0800 (PST) Received: from localhost.localdomain ([116.227.8.253]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545cf6bsm183662615ad.123.2025.02.24.10.29.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 10:29:40 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Cc: qemu-devel@nongnu.org, Tomita Moeko Subject: [PATCH 01/10] vfio/igd: Remove GTT write quirk in IO BAR 4 Date: Tue, 25 Feb 2025 02:29:18 +0800 Message-ID: <20250224182927.31519-2-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250224182927.31519-1-tomitamoeko@gmail.com> References: <20250224182927.31519-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::641; envelope-from=tomitamoeko@gmail.com; helo=mail-pl1-x641.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The IO BAR4 of IGD devices contains a pair of 32-bit address/data registers, MMIO_Index (0x0) and MMIO_Data (0x4), which provide access to the MMIO BAR0 (GTTMMADR) from IO space. These registers are probably only used by the VBIOS, and are not documented by intel. The observed layout of MMIO_Index register is: 31 2 1 0 +-------------------------------------------------------------------+ | Offset | Rsvd | Sel | +-------------------------------------------------------------------+ - Offset: Byte offset in specified region, 4-byte aligned. - Sel: Region selector 0: MMIO register region (first half of MMIO BAR0) 1: GTT region (second half of MMIO BAR0). Pre Gen11 only. Currently, QEMU implements a quirk that adjusts the guest Data Stolen Memory (DSM) region address to be (addr - host BDSM + guest BDSM) when programming GTT entries via IO BAR4, assuming guest still programs GTT with host DSM address, which is not the case. Guest's BDSM register is emulated and initialized to 0 at startup by QEMU, then SeaBIOS programs its value[1]. As result, the address programmed to GTT entries by VBIOS running in guest are valid GPA, and this unnecessary adjustment brings inconsistency. [1] https://gitlab.com/qemu-project/seabios/-/blob/1.12-stable/src/fw/pciinit.c#L319-332 Link: https://lore.kernel.org/all/20250124191245.12464-1-tomitamoeko@gmail.com/ Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 191 +------------------------------------------------- 1 file changed, 1 insertion(+), 190 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index b1a237edd6..ca3a32f4f2 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -106,12 +106,6 @@ static int igd_gen(VFIOPCIDevice *vdev) return -1; } -typedef struct VFIOIGDQuirk { - struct VFIOPCIDevice *vdev; - uint32_t index; - uint64_t bdsm; -} VFIOIGDQuirk; - #define IGD_GMCH 0x50 /* Graphics Control Register */ #define IGD_BDSM 0x5c /* Base Data of Stolen Memory */ #define IGD_BDSM_GEN11 0xc0 /* Base Data of Stolen Memory of gen 11 and later */ @@ -300,129 +294,6 @@ static int vfio_pci_igd_lpc_init(VFIOPCIDevice *vdev, return ret; } -/* - * IGD Gen8 and newer support up to 8MB for the GTT and use a 64bit PTE - * entry, older IGDs use 2MB and 32bit. Each PTE maps a 4k page. Therefore - * we either have 2M/4k * 4 = 2k or 8M/4k * 8 = 16k as the maximum iobar index - * for programming the GTT. - * - * See linux:include/drm/i915_drm.h for shift and mask values. - */ -static int vfio_igd_gtt_max(VFIOPCIDevice *vdev) -{ - uint32_t gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, sizeof(gmch)); - int gen = igd_gen(vdev); - uint64_t ggms_size = igd_gtt_memory_size(gen, gmch); - - return (ggms_size / (4 * KiB)) * (gen < 8 ? 4 : 8); -} - -/* - * The IGD ROM will make use of stolen memory (GGMS) for support of VESA modes. - * Somehow the host stolen memory range is used for this, but how the ROM gets - * it is a mystery, perhaps it's hardcoded into the ROM. Thankfully though, it - * reprograms the GTT through the IOBAR where we can trap it and transpose the - * programming to the VM allocated buffer. That buffer gets reserved by the VM - * firmware via the fw_cfg entry added below. Here we're just monitoring the - * IOBAR address and data registers to detect a write sequence targeting the - * GTTADR. This code is developed by observed behavior and doesn't have a - * direct spec reference, unfortunately. - */ -static uint64_t vfio_igd_quirk_data_read(void *opaque, - hwaddr addr, unsigned size) -{ - VFIOIGDQuirk *igd = opaque; - VFIOPCIDevice *vdev = igd->vdev; - - igd->index = ~0; - - return vfio_region_read(&vdev->bars[4].region, addr + 4, size); -} - -static void vfio_igd_quirk_data_write(void *opaque, hwaddr addr, - uint64_t data, unsigned size) -{ - VFIOIGDQuirk *igd = opaque; - VFIOPCIDevice *vdev = igd->vdev; - uint64_t val = data; - int gen = igd_gen(vdev); - - /* - * Programming the GGMS starts at index 0x1 and uses every 4th index (ie. - * 0x1, 0x5, 0x9, 0xd,...). For pre-Gen8 each 4-byte write is a whole PTE - * entry, with 0th bit enable set. For Gen8 and up, PTEs are 64bit, so - * entries 0x5 & 0xd are the high dword, in our case zero. Each PTE points - * to a 4k page, which we translate to a page from the VM allocated region, - * pointed to by the BDSM register. If this is not set, we fail. - * - * We trap writes to the full configured GTT size, but we typically only - * see the vBIOS writing up to (nearly) the 1MB barrier. In fact it often - * seems to miss the last entry for an even 1MB GTT. Doing a gratuitous - * write of that last entry does work, but is hopefully unnecessary since - * we clear the previous GTT on initialization. - */ - if ((igd->index % 4 == 1) && igd->index < vfio_igd_gtt_max(vdev)) { - if (gen < 8 || (igd->index % 8 == 1)) { - uint64_t base; - - if (gen < 11) { - base = pci_get_long(vdev->pdev.config + IGD_BDSM); - } else { - base = pci_get_quad(vdev->pdev.config + IGD_BDSM_GEN11); - } - if (!base) { - hw_error("vfio-igd: Guest attempted to program IGD GTT before " - "BIOS reserved stolen memory. Unsupported BIOS?"); - } - - val = data - igd->bdsm + base; - } else { - val = 0; /* upper 32bits of pte, we only enable below 4G PTEs */ - } - - trace_vfio_pci_igd_bar4_write(vdev->vbasedev.name, - igd->index, data, val); - } - - vfio_region_write(&vdev->bars[4].region, addr + 4, val, size); - - igd->index = ~0; -} - -static const MemoryRegionOps vfio_igd_data_quirk = { - .read = vfio_igd_quirk_data_read, - .write = vfio_igd_quirk_data_write, - .endianness = DEVICE_LITTLE_ENDIAN, -}; - -static uint64_t vfio_igd_quirk_index_read(void *opaque, - hwaddr addr, unsigned size) -{ - VFIOIGDQuirk *igd = opaque; - VFIOPCIDevice *vdev = igd->vdev; - - igd->index = ~0; - - return vfio_region_read(&vdev->bars[4].region, addr, size); -} - -static void vfio_igd_quirk_index_write(void *opaque, hwaddr addr, - uint64_t data, unsigned size) -{ - VFIOIGDQuirk *igd = opaque; - VFIOPCIDevice *vdev = igd->vdev; - - igd->index = data; - - vfio_region_write(&vdev->bars[4].region, addr, data, size); -} - -static const MemoryRegionOps vfio_igd_index_quirk = { - .read = vfio_igd_quirk_index_read, - .write = vfio_igd_quirk_index_write, - .endianness = DEVICE_LITTLE_ENDIAN, -}; - #define IGD_GGC_MMIO_OFFSET 0x108040 #define IGD_BDSM_MMIO_OFFSET 0x1080C0 @@ -494,14 +365,11 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) g_autofree struct vfio_region_info *opregion = NULL; g_autofree struct vfio_region_info *host = NULL; g_autofree struct vfio_region_info *lpc = NULL; - VFIOQuirk *quirk; - VFIOIGDQuirk *igd; PCIDevice *lpc_bridge; - int i, ret, gen; + int ret, gen; uint64_t ggms_size, gms_size; uint64_t *bdsm_size; uint32_t gmch; - uint16_t cmd_orig, cmd; Error *err = NULL; /* @@ -634,32 +502,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) return; } - /* Setup our quirk to munge GTT addresses to the VM allocated buffer */ - quirk = vfio_quirk_alloc(2); - igd = quirk->data = g_malloc0(sizeof(*igd)); - igd->vdev = vdev; - igd->index = ~0; - if (gen < 11) { - igd->bdsm = vfio_pci_read_config(&vdev->pdev, IGD_BDSM, 4); - } else { - igd->bdsm = vfio_pci_read_config(&vdev->pdev, IGD_BDSM_GEN11, 4); - igd->bdsm |= - (uint64_t)vfio_pci_read_config(&vdev->pdev, IGD_BDSM_GEN11 + 4, 4) << 32; - } - igd->bdsm &= ~((1 * MiB) - 1); /* 1MB aligned */ - - memory_region_init_io(&quirk->mem[0], OBJECT(vdev), &vfio_igd_index_quirk, - igd, "vfio-igd-index-quirk", 4); - memory_region_add_subregion_overlap(vdev->bars[nr].region.mem, - 0, &quirk->mem[0], 1); - - memory_region_init_io(&quirk->mem[1], OBJECT(vdev), &vfio_igd_data_quirk, - igd, "vfio-igd-data-quirk", 4); - memory_region_add_subregion_overlap(vdev->bars[nr].region.mem, - 4, &quirk->mem[1], 1); - - QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, quirk, next); - /* * Allow user to override dsm size using x-igd-gms option, in multiples of * 32MiB. This option should only be used when the desired size cannot be @@ -717,37 +559,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) pci_set_quad(vdev->emulated_config_bits + IGD_BDSM_GEN11, ~0); } - /* - * This IOBAR gives us access to GTTADR, which allows us to write to - * the GTT itself. So let's go ahead and write zero to all the GTT - * entries to avoid spurious DMA faults. Be sure I/O access is enabled - * before talking to the device. - */ - if (pread(vdev->vbasedev.fd, &cmd_orig, sizeof(cmd_orig), - vdev->config_offset + PCI_COMMAND) != sizeof(cmd_orig)) { - error_report("IGD device %s - failed to read PCI command register", - vdev->vbasedev.name); - } - - cmd = cmd_orig | PCI_COMMAND_IO; - - if (pwrite(vdev->vbasedev.fd, &cmd, sizeof(cmd), - vdev->config_offset + PCI_COMMAND) != sizeof(cmd)) { - error_report("IGD device %s - failed to write PCI command register", - vdev->vbasedev.name); - } - - for (i = 1; i < vfio_igd_gtt_max(vdev); i += 4) { - vfio_region_write(&vdev->bars[4].region, 0, i, 4); - vfio_region_write(&vdev->bars[4].region, 4, 0, 4); - } - - if (pwrite(vdev->vbasedev.fd, &cmd_orig, sizeof(cmd_orig), - vdev->config_offset + PCI_COMMAND) != sizeof(cmd_orig)) { - error_report("IGD device %s - failed to restore PCI command register", - vdev->vbasedev.name); - } - trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, (ggms_size + gms_size) / MiB); } From patchwork Mon Feb 24 18:29:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13988796 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 83CF7C021A4 for ; Mon, 24 Feb 2025 18:41:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdNc-0002u4-5f; Mon, 24 Feb 2025 13:40:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmdDD-0005fY-On for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:29:54 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdD7-0003KB-T3 for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:29:51 -0500 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-2212a930001so16496855ad.0 for ; Mon, 24 Feb 2025 10:29:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740421783; x=1741026583; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tAilGogcJ69e+gk+U7AAsM5atW/gLI/r88D/oQ3BuBI=; b=fZ6oaba5g1JFxoXG3LedXfjOn0wvUmM4kxKYniwnJ1Xibw0jAnmb5w6I/Stiy9M3ZK +tTOguMBdn5cEvB/KGZNh3Yp8L6ruG3tAHe0rg9wnTBDfbSTk/3oQMfYu1j5Vqb0BwPo vMnKK4+pjAfZIDdVQ8uQJsb+8FdmTMvhWyMUU7h1lo9HwFUYlhJFrD8TGapauOmhTRrb Ueg+efzw12eZg25iKokHuQdT6nxDJ/fQ6YXcxUgZ5sKrwZ0BwbBGxyds95YnNzSoq4dI 7oQ405LMVAKRfXHSAyhgY8xozZ1p3pG+fUBsEgSpqw1fSD4cC14XcAbckWMG41uLF//o rVyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740421783; x=1741026583; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tAilGogcJ69e+gk+U7AAsM5atW/gLI/r88D/oQ3BuBI=; b=tqtnFybGW/+DQjGfdJa3Vpqp/ZLhXe+mWCjtgj50aD9rDh6r5nzR0S6i/7xRJfyysO 3LcCNsqrWhfH44M+5nq04kk7L0OtxjJ17sMstgO1GWc0UFNtHhgXvEiVsUBMOciCXX6f kqn2oH0ar+ZpHHiJax1fGT2knqpAC62DO+eTjaINBZZ3KOZQ/sKwpESr/obiNGHNbqO2 8Q84B7K6kr0EkXcCqJLuZ/VpNnvUR1gEltlIQfHzrffW52IxIrC3ziQLg3rkG6JOjH2y XO3/5293mqe5b7zi7pLmAZkakOpPG6/nfOZcxymLYr9i4OoKsp4y0cUL+s3Izhcy7ZQX 6/+w== X-Gm-Message-State: AOJu0Yy25COX4auzgLG6QOiP1RIlUaYc9EeyhFRT844Cov0tED+jXyzq O7uXqfKf6tuWV5O7GMIfejVsNxfAJIZnwlN/klCnFsk2CvYXHZY= X-Gm-Gg: ASbGnctd+Lg4mGxC0Lx372QISOGHHWIK7t4dTm3ngjnzU1n1Ov2pi1+MgA6cG8mHU9C hRWUsNZGkDMosJDRFnd96Tzv2yYpM8tPEp9+NYe2YfLcRGYz4qZSPZ3z0QnFiOoYZU5vELVBveY c6n8eNNKRW0Xu/J+bA0ShmEuM1Y+R+OdvUE1kVvDuYYUyP/tHTHwRi97BWYmPQczN/sq0YejZU5 YL+OfNRCwj5CqM395x/BxQJig0hE7yl1jBoq9BBrN168HOe6gwCE6vKySnYAiftmNyP671QxJN7 GAFndkIkypdsie5tiuYaTx3YfP9SmOU8T13Hhdo= X-Google-Smtp-Source: AGHT+IFucJTC84KK9NKpkudn0o/c9TawXufCk6sNAkF8gG9bqlnC2mJVWoUPiyOG+OGWKET/zhEgHA== X-Received: by 2002:a17:903:2f92:b0:220:e896:54e1 with SMTP id d9443c01a7336-221a10de4fdmr206300115ad.26.1740421783122; Mon, 24 Feb 2025 10:29:43 -0800 (PST) Received: from localhost.localdomain ([116.227.8.253]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545cf6bsm183662615ad.123.2025.02.24.10.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 10:29:42 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Cc: qemu-devel@nongnu.org, Tomita Moeko Subject: [PATCH 02/10] vfio/igd: Do not include GTT stolen size in etc/igd-bdsm-size Date: Tue, 25 Feb 2025 02:29:19 +0800 Message-ID: <20250224182927.31519-3-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250224182927.31519-1-tomitamoeko@gmail.com> References: <20250224182927.31519-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::644; envelope-from=tomitamoeko@gmail.com; helo=mail-pl1-x644.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Though GTT Stolen Memory (GSM) is right below Data Stolen Memory (DSM) in host address space, direct access to GSM is prohibited, and it is not mapped to guest address space. Both host and guest accesses GSM indirectly through the second half of MMIO BAR0 (GTTMMADR). Guest firmware only need to reserve a memory region for DSM and program the BDSM register with the base address of that region, that's actually what both SeaBIOS[1] and OVMF does now. [1] https://gitlab.com/qemu-project/seabios/-/blob/1.12-stable/src/fw/pciinit.c#L319-332 Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index ca3a32f4f2..dda4c7bb5d 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -112,28 +112,8 @@ static int igd_gen(VFIOPCIDevice *vdev) #define IGD_GMCH_GEN6_GMS_SHIFT 3 /* SNB_GMCH in i915 */ #define IGD_GMCH_GEN6_GMS_MASK 0x1f -#define IGD_GMCH_GEN6_GGMS_SHIFT 8 -#define IGD_GMCH_GEN6_GGMS_MASK 0x3 #define IGD_GMCH_GEN8_GMS_SHIFT 8 /* BDW_GMCH in i915 */ #define IGD_GMCH_GEN8_GMS_MASK 0xff -#define IGD_GMCH_GEN8_GGMS_SHIFT 6 -#define IGD_GMCH_GEN8_GGMS_MASK 0x3 - -static uint64_t igd_gtt_memory_size(int gen, uint16_t gmch) -{ - uint64_t ggms; - - if (gen < 8) { - ggms = (gmch >> IGD_GMCH_GEN6_GGMS_SHIFT) & IGD_GMCH_GEN6_GGMS_MASK; - } else { - ggms = (gmch >> IGD_GMCH_GEN8_GGMS_SHIFT) & IGD_GMCH_GEN8_GGMS_MASK; - if (ggms != 0) { - ggms = 1ULL << ggms; - } - } - - return ggms * MiB; -} static uint64_t igd_stolen_memory_size(int gen, uint32_t gmch) { @@ -367,7 +347,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) g_autofree struct vfio_region_info *lpc = NULL; PCIDevice *lpc_bridge; int ret, gen; - uint64_t ggms_size, gms_size; + uint64_t gms_size; uint64_t *bdsm_size; uint32_t gmch; Error *err = NULL; @@ -527,7 +507,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) } } - ggms_size = igd_gtt_memory_size(gen, gmch); gms_size = igd_stolen_memory_size(gen, gmch); /* @@ -539,7 +518,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) * config offset 0x5C. */ bdsm_size = g_malloc(sizeof(*bdsm_size)); - *bdsm_size = cpu_to_le64(ggms_size + gms_size); + *bdsm_size = cpu_to_le64(gms_size); fw_cfg_add_file(fw_cfg_find(), "etc/igd-bdsm-size", bdsm_size, sizeof(*bdsm_size)); @@ -559,6 +538,5 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) pci_set_quad(vdev->emulated_config_bits + IGD_BDSM_GEN11, ~0); } - trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, - (ggms_size + gms_size) / MiB); + trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, (gms_size / MiB)); } From patchwork Mon Feb 24 18:29:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13988758 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0A54CC021BB for ; Mon, 24 Feb 2025 18:32:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdF7-0007tW-Un; Mon, 24 Feb 2025 13:31:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmdDD-0005fX-HG for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:29:54 -0500 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdD9-0003LG-4x for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:29:51 -0500 Received: by mail-pl1-x643.google.com with SMTP id d9443c01a7336-220c665ef4cso82664325ad.3 for ; Mon, 24 Feb 2025 10:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740421785; x=1741026585; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0kLNEh9HDxPlg3F7QyIz3eXfGlUA0e6Zl/yhAOMn0zU=; b=a/GYbZhRe1mKFUpVmNub7cxjfbm0aiC7hPmquQA84tbxXRs1FkYqiBhEDz/DjsDOHa SXFY5WsZ6hikGbSF6wjEdhSrYiRQJ/anTMaWaJnxqkigy//w2gptfuONSrgCxiTGdzg+ ZJHV/+2RI7fNJlbv49EVSSpngu+TqXrYKsZq/Yrryu5xz8SWeXnoiH52V9bxZ1Aroquf wF/Fexzpkqr7/g+N8j32WoZaQSwFkGkFX6Z+q+JDuLMRLzFeNrS3TL8uHgljdR5Mo0fE 6PIJkonDuuI1HkZdWO7HQK1uKIs8ax7yX78tPDLqNmsjOOcCaFsZQwccLqhIJMbL+iax wwaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740421785; x=1741026585; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0kLNEh9HDxPlg3F7QyIz3eXfGlUA0e6Zl/yhAOMn0zU=; b=PtoJ4+YDzOOKvspn6LNfR3p4BdutdT3AZpsHC7vztKg3+y4jJd/LKTT2m0Rkb7tiJU h6bGl2zfYuOIR+DyehMfF8hNaBQZXCG8U99+Nc39MPLMlgkpC4sk0ZWyVurUqh18fqag VSmIt723IJu4O6CakAHeM8InnE2715PbIsQx9JWkLyBZ0RXZZtGvEDJtumQsYXKHuTZw uOEMSiB/pK1d2EnDJkM6KIkvj05SzoqBXbyjgpKFPQmOMOjVZJcE4raJuabY0OUBwQC5 d1rwSnz+y0er+5LzfXPWP5UJ44dn2Wy44C/ApbMo4aZsZtLbrFhNLjSbeEdWPxMcjgz/ fugg== X-Gm-Message-State: AOJu0YzUlk3Hew+jx1LpbewiLmfl+pd5uXYnx4tW9/poBnOE8oLDmYj+ 3w0e2btNYfNxH9dTGljXugq0+d+XAV2TiKdS4G24jDzdEkiQzO9+HcH67UyozA== X-Gm-Gg: ASbGncsl/L6+fhK5ciCOu9yvrrWx4AP0GxGueH9CxhRvFjzzZ3xMDbkJR1TpB1HXzDm uTc+OzaifK6xq7snfvWze+jK+OF1mCJMXd4VURqn82mXuLGxShh5k+M+FI45YlR6sgyYjNJCXk9 46tc3gNWonyG5Juh/FsELgcss2Vs5nlX4hhkxYQEIbkIs9WPZV/rizfvM6KpjPUXe6vOYtXAdSt TGBHi1fb0xSNhZcvCb7iGt7EB4Sc7s84x+RcRjduiD5nFjmmMyBlcYXd+N7+O10aGG3JtMHIVqQ rpAZ0yzDSwYZ/Jy2nH4JXDqQuiLzLblAeMZGlgY= X-Google-Smtp-Source: AGHT+IHJy5VPpAReOcowVJ73MUH1kZ7j0UbHrtDMEMa0g6kzQ0BsHckuMpZv6GoQPDEUMVzNPQQ/0g== X-Received: by 2002:a17:902:f544:b0:215:6cb2:7877 with SMTP id d9443c01a7336-2219ff827cdmr285377375ad.4.1740421785122; Mon, 24 Feb 2025 10:29:45 -0800 (PST) Received: from localhost.localdomain ([116.227.8.253]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545cf6bsm183662615ad.123.2025.02.24.10.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 10:29:44 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Cc: qemu-devel@nongnu.org, Tomita Moeko Subject: [PATCH 03/10] vfio/igd: Remove rombar check for legacy mode Date: Tue, 25 Feb 2025 02:29:20 +0800 Message-ID: <20250224182927.31519-4-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250224182927.31519-1-tomitamoeko@gmail.com> References: <20250224182927.31519-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::643; envelope-from=tomitamoeko@gmail.com; helo=mail-pl1-x643.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Legacy VBIOS support was removed in Gen 11 and later IGD devices. While we usually uses romfile for IGD-related DXE drivers, it's not always necessary. Remove the ROM BAR requirement for legacy mode to support newer devices without a specified romfile. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index dda4c7bb5d..4ae1122a2d 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -341,7 +341,6 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) { - g_autofree struct vfio_region_info *rom = NULL; g_autofree struct vfio_region_info *opregion = NULL; g_autofree struct vfio_region_info *host = NULL; g_autofree struct vfio_region_info *lpc = NULL; @@ -391,26 +390,12 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) } /* - * Most of what we're doing here is to enable the ROM to run, so if - * there's no ROM, there's no point in setting up this quirk. - * NB. We only seem to get BIOS ROMs, so a UEFI VM would need CSM support. - */ - ret = vfio_get_region_info(&vdev->vbasedev, - VFIO_PCI_ROM_REGION_INDEX, &rom); - if ((ret || !rom->size) && !vdev->pdev.romfile) { - error_report("IGD device %s has no ROM, legacy mode disabled", - vdev->vbasedev.name); - return; - } - - /* - * Ignore the hotplug corner case, mark the ROM failed, we can't - * create the devices we need for legacy mode in the hotplug scenario. + * Ignore the hotplug corner case, we can't create the devices we + * need for legacy mode in the hotplug scenario. */ if (vdev->pdev.qdev.hotplugged) { - error_report("IGD device %s hotplugged, ROM disabled, " - "legacy mode disabled", vdev->vbasedev.name); - vdev->rom_read_failed = true; + error_report("IGD device %s hotplugged, legacy mode disabled", + vdev->vbasedev.name); return; } From patchwork Mon Feb 24 18:29:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13988757 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3DCEAC021BB for ; Mon, 24 Feb 2025 18:32:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdEa-0007C7-SG; Mon, 24 Feb 2025 13:31:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmdDJ-0005id-65 for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:29:58 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdDC-0003My-4o for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:29:55 -0500 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-220d28c215eso73436425ad.1 for ; Mon, 24 Feb 2025 10:29:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740421788; x=1741026588; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YCCHlPi+FxqsaGVtlmnpzUh3V9i8PkuobSoBDnQT9Bk=; b=JGFn+nZKqNY212VYS5RG8gVRhB+KstTPU9LatdgxJjWt9IDNbspoSG5MzuCnXkADpW kxKY8f5Ep7av4xvWYCU6UCMbIsL/SzN9q6E/MUXvyM0E7fwZ2YNRTr8eYOMt0netBi9b 6U2oIKeYnQK87ylKyi7iWqJgCBCewfcAryepC71bJlOaJ7Q8XC3I0eNAfCLqSqATrSaC xvISe5rYCoBuMaLOUdFRIZbt41b3lX+v8J53X7w2FB1vlwNFpHu+L6obKh63E6i5RhUj xRgyJ24C4To0P/IuGU1EyJHAERZxLjszfBzC7yftGp7hT+ehs6tvdZPnsF0ZkcSSr9lb o8Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740421788; x=1741026588; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YCCHlPi+FxqsaGVtlmnpzUh3V9i8PkuobSoBDnQT9Bk=; b=MpnPmqiRurYZzYr9/3Etb9LwkX0Xc1VFVL8vCKUaqTLuWZ6ZS3yPUk1rgmpmzzU17C /gECJmtxN7n1s5B+ZBXdZ5JtiT/sifsLhcTrjFTC/ZrDH2l88JDWFl7V+ToEksIap0N7 iB/74FIlL4JI4SWDeUkaPk+LXP6Z4SWiFfOcYFk9OYY2ZSF5tR0bPf4id+4+UpPoWDA/ /qYjYyZEAQHDZfCszbGxEkYSfFYBk5XJn+WmAZreQuDMX3hPszxLe5CTm/NbzmA0Kmbr 5g8L7fKzfCjda2Bve2pF6PUlRGZz4k6uSmZy8N1oYp2BkUq8ifrrtUHzhi9Vfca+10eZ dmog== X-Gm-Message-State: AOJu0Yw2qPXnhFc1sNpsR3iim8QPGr4oG1xWe9yPzDUprWsTk4mycxHK rfcWFEswak715q/IPgTLLRu+sjnH3fNAIvVSN44J4CDElgAipcfkOsTbG1vgsA== X-Gm-Gg: ASbGncuw8UjJvlGzkL/TabMzkNxRLII/iH3Pg27d08EQR1JFD0c6Vnqu+lk1gFjiuxo fyYOsMsoLRDgg6marpJvKjWS6Xr7ft6r3Ix2BrwIFjtCaGgovEiRzXKw6bkav6mXP96gteO3Vpr TWxuI6O/jOZTEpHvM5naWBZqWSETLfToliGsuJ/HpZoFlh65D/5DflHIOhllBtx9WmLtBYhYRK4 jbLNimtWUdCHN0/buVY8OVfjZ4etuLw05/hu2YFImmx8UnvvOSGYaXpdA/uD8hHZo//3u3yCR8K gx6+kKqLW/IqVRi1J2322qg6vfHEGUoGqvwDeQs= X-Google-Smtp-Source: AGHT+IFEPoHZpbhwuiuN1iatqbtTb6riJOi8MfOnbJoZNs7go2bFFJQzmls705M00pfEDV1+5vGWfg== X-Received: by 2002:a17:903:191:b0:21f:6a36:7bf3 with SMTP id d9443c01a7336-22307b4bd13mr3740265ad.12.1740421787028; Mon, 24 Feb 2025 10:29:47 -0800 (PST) Received: from localhost.localdomain ([116.227.8.253]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545cf6bsm183662615ad.123.2025.02.24.10.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 10:29:46 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Cc: qemu-devel@nongnu.org, Tomita Moeko Subject: [PATCH 04/10] vfio/igd: Remove implicit VGA access enabled by legacy mode Date: Tue, 25 Feb 2025 02:29:21 +0800 Message-ID: <20250224182927.31519-5-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250224182927.31519-1-tomitamoeko@gmail.com> References: <20250224182927.31519-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::644; envelope-from=tomitamoeko@gmail.com; helo=mail-pl1-x644.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Modern EFI-based system and drivers like i915 no longer use VGA IO/MMIO registers. Currently, legacy mode checks if the VGA decoding cycle is claimed by IGD, and implicitly exposes VGA address spaces for device. As we are going to remove legacy mode, remove this implicit behavior. If users want to enable VGA access for IGD, use the common x-vga option explicily. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 4ae1122a2d..32ae263c23 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -430,20 +430,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) return; } - gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4); - - /* - * If IGD VGA Disable is clear (expected) and VGA is not already enabled, - * try to enable it. Probably shouldn't be using legacy mode without VGA, - * but also no point in us enabling VGA if disabled in hardware. - */ - if (!(gmch & 0x2) && !vdev->vga && !vfio_populate_vga(vdev, &err)) { - error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); - error_report("IGD device %s failed to enable VGA access, " - "legacy mode disabled", vdev->vbasedev.name); - return; - } - /* Create our LPC/ISA bridge */ ret = vfio_pci_igd_lpc_init(vdev, lpc); if (ret) { @@ -467,6 +453,8 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) return; } + gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4); + /* * Allow user to override dsm size using x-igd-gms option, in multiples of * 32MiB. This option should only be used when the desired size cannot be From patchwork Mon Feb 24 18:29:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13988761 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4DF07C021A4 for ; Mon, 24 Feb 2025 18:34:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdGu-0001gs-8Z; Mon, 24 Feb 2025 13:33:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmdDL-0005lL-W3 for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:30:01 -0500 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdDE-0003N5-Vx for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:29:59 -0500 Received: by mail-pl1-x642.google.com with SMTP id d9443c01a7336-220c8f38febso101231905ad.2 for ; Mon, 24 Feb 2025 10:29:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740421789; x=1741026589; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+Xs0oZUmiKgigK0ttBSqwyz2fzSA+xd8KRytqyUvu9g=; b=DOBR0VVQZMJZ0yshDgf0X/u4uLQyICx50l5UKbDIx2DIxzuk5E0LXf/pDx87b746Po 5Lo7p5VxJdV5Kqp2oa/pJKAz6mouXwfS1wY7Px7XOzzWOjY4OoIRlJuCrLK/RywuCHmy dDnvG+kjOsElubI+ZGJaAP8Bboau8TrrJsNIQNlFJAw9x7IFxj0Jlev2Gn9w1UCfKl3C eyt1MQsKB1NX5veKyRV0ZXDxztv7P/AEdwYMJoyD/S50AlrrrRSpzJiNXQBd7FwPh4kX cq2wATF9KOwBrERnl6rPa5JlCkqXl3agUqYBpamdzpgtdtPOyg2jJxSCRgBHQoXNnv+Y meZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740421789; x=1741026589; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+Xs0oZUmiKgigK0ttBSqwyz2fzSA+xd8KRytqyUvu9g=; b=vj41GPOR+tfZe0jXOwMTwvdcClHI0MjMS7M/jlZamZZSw5FLibn97g9U0WfJITOS0R VG2oLTxrtRSWz+8xOBAlK989NJuqUHtcY7m8S6MKMm4klzjNmDK09X2DWmsWBK3Jw6G0 yQY5ykVttz+fR6U02PRIyc1eb50e0AT7cAWxJrS5EPVnZEBikndEkDBUuT8UCXKH0LKP x3NJil49ft6XuAQ3LkS8d5b5PF58iDWX6ZzjsaHDvaJWDbe9RWOKS8nMnKNdaX4scqAl NPbd7KwtUOgBqMS6XfXWn0Yx7rWfs5XnCzuI1nkyHjvddO5DE+0GmMsPSpjQnsh+kTZP DC+A== X-Gm-Message-State: AOJu0Yxnjda6KXuxey0SNYVC3AlnsSsJPts/xafkdlMcQh4N2yE7G0vn FUcYN9LlQ6cZF4czCL1awWLCa5ihHh6VGyE60bhFQZqJO/O2wGo= X-Gm-Gg: ASbGncv1O/NPSHvPMFiHTlJb7wCNik4KEgvy50c2dHogqlALsZDW2THx9WN1YnCpw3e LhEbsHuXGD7aNWxVVBmGCCGPLM48NW4X/Ft3OSyS3PmpUV5qrOfso7EtgoeMiZw48IOocNSTHXj pujwGsiX82FfY4QCcukQXWQKA7wZSHHMOmNNvn7bRJYHM6bLONqd1fY9KErFzq0ds2xFj5NZsrQ 0XH8QjK6a+ugcBe0tTAHyXk8tvBL8hE9gx4BLhgTjLlt9BXWGfksQgQ/sOB2VtPSIuq79hjMsA0 CTgRlBArS7y3fseUWSJrm0V73qjsROO0Khi2g5w= X-Google-Smtp-Source: AGHT+IFkQgbH3w0XNQSLSs0IZW30wkVNYiXZJc1thKc1gtNS9q8KDQbESAPj8nsUriDgOXBqHnXKjw== X-Received: by 2002:a17:903:41c8:b0:215:ac55:fd72 with SMTP id d9443c01a7336-221a001576cmr214460635ad.37.1740421789005; Mon, 24 Feb 2025 10:29:49 -0800 (PST) Received: from localhost.localdomain ([116.227.8.253]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545cf6bsm183662615ad.123.2025.02.24.10.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 10:29:48 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Cc: qemu-devel@nongnu.org, Tomita Moeko Subject: [PATCH 05/10] vfio/pci: Make vfio_populate_vga static Date: Tue, 25 Feb 2025 02:29:22 +0800 Message-ID: <20250224182927.31519-6-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250224182927.31519-1-tomitamoeko@gmail.com> References: <20250224182927.31519-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::642; envelope-from=tomitamoeko@gmail.com; helo=mail-pl1-x642.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org vfio_populate_vga is no longer called in igd.c. Make it static. Signed-off-by: Tomita Moeko --- hw/vfio/pci.c | 2 +- hw/vfio/pci.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 89d900e9cf..1c45e3987e 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2662,7 +2662,7 @@ static VFIODeviceOps vfio_pci_ops = { .vfio_load_config = vfio_pci_load_config, }; -bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp) +static bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp) { VFIODevice *vbasedev = &vdev->vbasedev; g_autofree struct vfio_region_info *reg_info = NULL; diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 43c166680a..75505af6a3 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -226,8 +226,6 @@ bool vfio_pci_host_match(PCIHostDeviceAddress *addr, const char *name); int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev, struct vfio_pci_hot_reset_info **info_p); -bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp); - bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, struct vfio_region_info *info, Error **errp); From patchwork Mon Feb 24 18:29:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13988759 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3C38BC021BB for ; Mon, 24 Feb 2025 18:34:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdH1-00020x-LJ; Mon, 24 Feb 2025 13:33:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmdDQ-0005oW-R2 for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:30:05 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdDH-0003Na-1h for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:30:03 -0500 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-220e83d65e5so90760845ad.1 for ; Mon, 24 Feb 2025 10:29:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740421791; x=1741026591; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tXOjZtgFlfgDDzD85XnbBJ3mLhtlWv0xEfuhDPGRItM=; b=k/xWBeuQjXnKTUpFyLGm6Px0PcAoH4cGDpAMMfrjcmKP3aWaTicweKAV3EP5SepoKx XOKO9eIK8nqULxT4xyGVhXOJ5UhcitQ6S8DlhJvGq7fPLBqIvomO4+raMSymBJbmcPX0 Lb0V1KVhuelEdporSIXtWVmtJd0c54bIDAcXQG3ph3CTQQ1Rgi6vnY4VcXLWbZPD5RLp qNjmaykFcamHmUVSWzfquOZZ8IP9L1hfFbZMkSWyJrq1XTTPHXw6PQRIJjqpEvAPu+dG fmEuSXIc7B47nuIKpet2wNurEq1z2TYdDqSY7VjayfDWReQd3JHlgkeWvRkStHoDnG8F V8Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740421791; x=1741026591; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tXOjZtgFlfgDDzD85XnbBJ3mLhtlWv0xEfuhDPGRItM=; b=PPRFbweH4bx+zy9rujhyzNHv15E3gZuMLkj2bydoTi/nfXXIaVzZfgGDf+QimFSmgz 9SVZ5za4L5X39F1W52RdF7S3/56RgwhpyKShbpPrgyY2NTVWPWeohsUZVmJZg1XRW97F khgKziNpsbq5C02dQRUroB1MP+ApaXKEFtwiqFaneP5phduN4aEpxpri8hwW1KmttupF VKAw+cKcA4+rTfrtknVG46pDzsub0t5PdyNd9gBEDFnAxst3cxxvr14T44F1sdGXd29O 5e/qMmSLWi5j1XzsMMYID5r3+hdYVgy07Twb4oBjNA5KwDYbcnSSAm6M697Esao2i87w HCgQ== X-Gm-Message-State: AOJu0Yw7SptFA/N4M4+kh2X0Q0CWN0hwgrYIPxR2CWeL6T/Qy0bj7DFd 3d9so9sjNAVpgVndcLXyio2vLt9KGoaDyI4Q2hsMP7T0JfxVE6Z97EU4OZSpJQ== X-Gm-Gg: ASbGnctspFqWIlGm6azmpjUL3Z9SwvaiLLvkekrbNPNIsEeRD0ZtAzxtEhvAjrAf+UC nucXqRQ4Q1IwZwOUmlMG1DKi67vz+73imtXAcohM7Gy/KIcdVX/dod3FLrvGRQ8CbKPsMuWm8ld aYh+vgcaOFsz+ksedaMEFcYNb4OiQY56C40X4n0zFuYSGoWD+ywXWLdFYvfrsFnD6GlO/V0Skmd fgGkzlad5TjpXRB2R/1oMfL1RWzxhfmakilC1qh2ZkUc8y3k5LF1vhAph1gXZj3uqP53tVi5epg AClR8iio/grN4T5RSfz8iN+G5wHQ9P81A3hk8E8= X-Google-Smtp-Source: AGHT+IGTn3BRGTjR7r7wbP4M2yQxBmC/WB48+TKjpAnD7zwO9xi61IzgvUOtwy2hQ1GnrbZAitLivw== X-Received: by 2002:a17:902:f70d:b0:220:fae9:8a4 with SMTP id d9443c01a7336-2219ff31c0cmr229795855ad.6.1740421791022; Mon, 24 Feb 2025 10:29:51 -0800 (PST) Received: from localhost.localdomain ([116.227.8.253]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545cf6bsm183662615ad.123.2025.02.24.10.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 10:29:50 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Cc: qemu-devel@nongnu.org, Tomita Moeko Subject: [PATCH 06/10] vfio/igd: Consolidate OpRegion initialization into a single function Date: Tue, 25 Feb 2025 02:29:23 +0800 Message-ID: <20250224182927.31519-7-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250224182927.31519-1-tomitamoeko@gmail.com> References: <20250224182927.31519-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::644; envelope-from=tomitamoeko@gmail.com; helo=mail-pl1-x644.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Both x-igd-opregion option and legacy mode require identical steps to set up OpRegion for IGD devices. Consolidate these steps into a single vfio_pci_igd_setup_opregion function. The function call in pci.c is wrapped with ifdef temporarily to prevent build error for non-x86 archs, it will be removed later after the removal of legacy mode. Additionally, move vfio_pci_igd_opregion_init to igd.c to prevent it from being compiled in non-x86 builds. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 111 +++++++++++++++++++++++++++++++++---------- hw/vfio/pci-quirks.c | 50 ------------------- hw/vfio/pci.c | 22 ++------- hw/vfio/pci.h | 4 +- 4 files changed, 89 insertions(+), 98 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 32ae263c23..7c7461e22d 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -106,6 +106,7 @@ static int igd_gen(VFIOPCIDevice *vdev) return -1; } +#define IGD_ASLS 0xfc /* ASL Storage Register */ #define IGD_GMCH 0x50 /* Graphics Control Register */ #define IGD_BDSM 0x5c /* Base Data of Stolen Memory */ #define IGD_BDSM_GEN11 0xc0 /* Base Data of Stolen Memory of gen 11 and later */ @@ -138,6 +139,82 @@ static uint64_t igd_stolen_memory_size(int gen, uint32_t gmch) return 0; } +/* + * The OpRegion includes the Video BIOS Table, which seems important for + * telling the driver what sort of outputs it has. Without this, the device + * may work in the guest, but we may not get output. This also requires BIOS + * support to reserve and populate a section of guest memory sufficient for + * the table and to write the base address of that memory to the ASLS register + * of the IGD device. + */ +static bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, + struct vfio_region_info *info, + Error **errp) +{ + int ret; + + vdev->igd_opregion = g_malloc0(info->size); + ret = pread(vdev->vbasedev.fd, vdev->igd_opregion, + info->size, info->offset); + if (ret != info->size) { + error_setg(errp, "failed to read IGD OpRegion"); + g_free(vdev->igd_opregion); + vdev->igd_opregion = NULL; + return false; + } + + /* + * Provide fw_cfg with a copy of the OpRegion which the VM firmware is to + * allocate 32bit reserved memory for, copy these contents into, and write + * the reserved memory base address to the device ASLS register at 0xFC. + * Alignment of this reserved region seems flexible, but using a 4k page + * alignment seems to work well. This interface assumes a single IGD + * device, which may be at VM address 00:02.0 in legacy mode or another + * address in UPT mode. + * + * NB, there may be future use cases discovered where the VM should have + * direct interaction with the host OpRegion, in which case the write to + * the ASLS register would trigger MemoryRegion setup to enable that. + */ + fw_cfg_add_file(fw_cfg_find(), "etc/igd-opregion", + vdev->igd_opregion, info->size); + + trace_vfio_pci_igd_opregion_enabled(vdev->vbasedev.name); + + pci_set_long(vdev->pdev.config + IGD_ASLS, 0); + pci_set_long(vdev->pdev.wmask + IGD_ASLS, ~0); + pci_set_long(vdev->emulated_config_bits + IGD_ASLS, ~0); + + return true; +} + +bool vfio_pci_igd_setup_opregion(VFIOPCIDevice *vdev, Error **errp) +{ + g_autofree struct vfio_region_info *opregion = NULL; + int ret; + + /* Hotplugging is not supprted for opregion access */ + if (vdev->pdev.qdev.hotplugged) { + error_setg(errp, "IGD OpRegion is not supported on hotplugged device"); + return false; + } + + ret = vfio_get_dev_region_info(&vdev->vbasedev, + VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL, + VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, &opregion); + if (ret) { + error_setg_errno(errp, -ret, + "Device does not supports IGD OpRegion feature"); + return false; + } + + if (!vfio_pci_igd_opregion_init(vdev, opregion, errp)) { + return false; + } + + return true; +} + /* * The rather short list of registers that we copy from the host devices. * The LPC/ISA bridge values are definitely needed to support the vBIOS, the @@ -339,9 +416,9 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, bdsm_quirk, next); } + void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) { - g_autofree struct vfio_region_info *opregion = NULL; g_autofree struct vfio_region_info *host = NULL; g_autofree struct vfio_region_info *lpc = NULL; PCIDevice *lpc_bridge; @@ -389,29 +466,11 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) return; } - /* - * Ignore the hotplug corner case, we can't create the devices we - * need for legacy mode in the hotplug scenario. - */ - if (vdev->pdev.qdev.hotplugged) { - error_report("IGD device %s hotplugged, legacy mode disabled", - vdev->vbasedev.name); - return; - } /* * Check whether we have all the vfio device specific regions to * support legacy mode (added in Linux v4.6). If not, bail. */ - ret = vfio_get_dev_region_info(&vdev->vbasedev, - VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL, - VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, &opregion); - if (ret) { - error_report("IGD device %s does not support OpRegion access," - "legacy mode disabled", vdev->vbasedev.name); - return; - } - ret = vfio_get_dev_region_info(&vdev->vbasedev, VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL, VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG, &host); @@ -430,6 +489,13 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) return; } + /* Setup OpRegion access */ + if (!vfio_pci_igd_setup_opregion(vdev, &err)) { + error_append_hint(&err, "IGD legacy mode disabled\n"); + error_report_err(err); + return; + } + /* Create our LPC/ISA bridge */ ret = vfio_pci_igd_lpc_init(vdev, lpc); if (ret) { @@ -446,13 +512,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) return; } - /* Setup OpRegion access */ - if (!vfio_pci_igd_opregion_init(vdev, opregion, &err)) { - error_append_hint(&err, "IGD legacy mode disabled\n"); - error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); - return; - } - gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4); /* diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c index fbe43b0a79..cac0aa1910 100644 --- a/hw/vfio/pci-quirks.c +++ b/hw/vfio/pci-quirks.c @@ -1114,56 +1114,6 @@ static void vfio_probe_rtl8168_bar2_quirk(VFIOPCIDevice *vdev, int nr) trace_vfio_quirk_rtl8168_probe(vdev->vbasedev.name); } -#define IGD_ASLS 0xfc /* ASL Storage Register */ - -/* - * The OpRegion includes the Video BIOS Table, which seems important for - * telling the driver what sort of outputs it has. Without this, the device - * may work in the guest, but we may not get output. This also requires BIOS - * support to reserve and populate a section of guest memory sufficient for - * the table and to write the base address of that memory to the ASLS register - * of the IGD device. - */ -bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, - struct vfio_region_info *info, Error **errp) -{ - int ret; - - vdev->igd_opregion = g_malloc0(info->size); - ret = pread(vdev->vbasedev.fd, vdev->igd_opregion, - info->size, info->offset); - if (ret != info->size) { - error_setg(errp, "failed to read IGD OpRegion"); - g_free(vdev->igd_opregion); - vdev->igd_opregion = NULL; - return false; - } - - /* - * Provide fw_cfg with a copy of the OpRegion which the VM firmware is to - * allocate 32bit reserved memory for, copy these contents into, and write - * the reserved memory base address to the device ASLS register at 0xFC. - * Alignment of this reserved region seems flexible, but using a 4k page - * alignment seems to work well. This interface assumes a single IGD - * device, which may be at VM address 00:02.0 in legacy mode or another - * address in UPT mode. - * - * NB, there may be future use cases discovered where the VM should have - * direct interaction with the host OpRegion, in which case the write to - * the ASLS register would trigger MemoryRegion setup to enable that. - */ - fw_cfg_add_file(fw_cfg_find(), "etc/igd-opregion", - vdev->igd_opregion, info->size); - - trace_vfio_pci_igd_opregion_enabled(vdev->vbasedev.name); - - pci_set_long(vdev->pdev.config + IGD_ASLS, 0); - pci_set_long(vdev->pdev.wmask + IGD_ASLS, ~0); - pci_set_long(vdev->emulated_config_bits + IGD_ASLS, ~0); - - return true; -} - /* * Common quirk probe entry points. */ diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 1c45e3987e..56d7097a7a 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3132,30 +3132,14 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) vfio_bar_quirk_setup(vdev, i); } +#ifdef CONFIG_VFIO_IGD if (!vdev->igd_opregion && vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) { - g_autofree struct vfio_region_info *opregion = NULL; - - if (vdev->pdev.qdev.hotplugged) { - error_setg(errp, - "cannot support IGD OpRegion feature on hotplugged " - "device"); - goto out_unset_idev; - } - - ret = vfio_get_dev_region_info(vbasedev, - VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL, - VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, &opregion); - if (ret) { - error_setg_errno(errp, -ret, - "does not support requested IGD OpRegion feature"); - goto out_unset_idev; - } - - if (!vfio_pci_igd_opregion_init(vdev, opregion, errp)) { + if (!vfio_pci_igd_setup_opregion(vdev, errp)) { goto out_unset_idev; } } +#endif /* QEMU emulates all of MSI & MSIX */ if (pdev->cap_present & QEMU_PCI_CAP_MSIX) { diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 75505af6a3..ca7c0415f0 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -226,9 +226,7 @@ bool vfio_pci_host_match(PCIHostDeviceAddress *addr, const char *name); int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev, struct vfio_pci_hot_reset_info **info_p); -bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, - struct vfio_region_info *info, - Error **errp); +bool vfio_pci_igd_setup_opregion(VFIOPCIDevice *vdev, Error **errp); void vfio_display_reset(VFIOPCIDevice *vdev); bool vfio_display_probe(VFIOPCIDevice *vdev, Error **errp); From patchwork Mon Feb 24 18:29:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13988760 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 559B3C021BC for ; Mon, 24 Feb 2025 18:34:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdFC-00086I-FH; Mon, 24 Feb 2025 13:31:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmdDQ-0005oZ-S5 for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:30:05 -0500 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdDK-0003O5-4G for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:30:03 -0500 Received: by mail-pl1-x641.google.com with SMTP id d9443c01a7336-220ecbdb4c2so16485075ad.3 for ; Mon, 24 Feb 2025 10:29:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740421793; x=1741026593; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KhY1Lg5VGsGDQFWbkyrZVwx/wHZ+zRcPYDq3BO+PT9Y=; b=E+sG5b9Hc02ni4kazm+SpdMwX/D6ByclLMmtRDwsw/vxbR3m6ZWUIviVo44ZYukAJl rdavItCw1uU5HTcA7Sil8FJvCJTbWIljlEx/tN2gcgoeFkt5rE/LKatnLg7GPi3HwAdQ EoNpKV6FIbC+QNjeUnqRX437pG7y02MJWmTaLxqpR7e+/w3OQCO0CAauTMgnrSdhkWuM wOFe0ehgbAaShrT6DEWMPrZSP2itkU5yuWDc9WujUny0EcstzBKmF9X/i6AryVapekES FoPAg3Yr7mPbiOneGRV5CAjE2VOYHlKyPv0NkLG2OVEyGq8N8oAWHpDfsqvUaI+lLeg7 Q4ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740421793; x=1741026593; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KhY1Lg5VGsGDQFWbkyrZVwx/wHZ+zRcPYDq3BO+PT9Y=; b=auS54ONoRcYprnGxpqj2VkCRNj/52Y1CDEypCHCPcwW3U+vs77aN6zRzCEoELDLXaY OS/qZ2r42l5jw1JsTVFqCJPv3C85ACTHT3WBI1pFlM7pDjkNSMHBPrp0HvmWPJjDUOzv I9jHjCGraWvccga/SpYCZbCvzj2HVKafJcrJ5zR719eg06Qo/obnUWSG0gLr+1KjJ2rJ uCv6YWH43fNi+r1zU1j9W1nYLk0YCSwhJwXTLdnZa4VyqHKYbRO8lcfpenHk9MXvZbwm knPdg0KZYhy1Z3cvbxU63JsJ7bQR5/SP3w9ro0Imu4gAThfCRaioNllf+z0D/9UoN1Ki icuw== X-Gm-Message-State: AOJu0YwEUYJgH3SSgxsbquIvO8pShVfeVWzp91yQKF9OyNgqyRYt+NJq hFBcA6H8XdUPFpM6awMwr0Enf8kiSNs91DBSwDl5Tq5t9JB93iM= X-Gm-Gg: ASbGnctsrk/bZgxd/nQB+i0suvF90MtgtdLHNq8yH8bRkFFlsy8BdR1XBOgvkVa+vkr YFEAbF8R0Ml1H6y4SI/xHChhgwNFEDSigUyyk4oJILN+k8A1K57p4uRF0CxfJoYNxb8E+P0cpGj g7S+CKCUEReb7c9UrtpPYgdUBteLn/IkQy59y24PmTrnXXa3svBvyOxogsqGIcLbmD0v3fLo9UB /Btwquxa0sRtHoyCjLtWgeZWNlIYWExqxwjo8bF1AN5z+DhYSM94QtT98h1eSFD+PvjBV8WfKp1 Fk2cz/jtILMtAb7TlVU690EIWSf5FgOeSIGNwy0= X-Google-Smtp-Source: AGHT+IECHXff/G9p6rbvUA3LqO3W8a5ccNBfY9hRLK//ox9eBZN9z9vDNy3ueyETS82dOqPvTITkhw== X-Received: by 2002:a17:902:e803:b0:220:bc9e:fd6 with SMTP id d9443c01a7336-221a118a228mr234734815ad.44.1740421793036; Mon, 24 Feb 2025 10:29:53 -0800 (PST) Received: from localhost.localdomain ([116.227.8.253]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545cf6bsm183662615ad.123.2025.02.24.10.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 10:29:52 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Cc: qemu-devel@nongnu.org, Tomita Moeko Subject: [PATCH 07/10] vfio/igd: Move LPC bridge initialization to a separate function Date: Tue, 25 Feb 2025 02:29:24 +0800 Message-ID: <20250224182927.31519-8-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250224182927.31519-1-tomitamoeko@gmail.com> References: <20250224182927.31519-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::641; envelope-from=tomitamoeko@gmail.com; helo=mail-pl1-x641.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org A new option will soon be introduced to control whether to apply the LPC bridge/Host bridge ID quirk for the removal of implicit legacy mode. To prepare for this, move the LPC bridge initialization into a separate function. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 125 ++++++++++++++++++++++++++++---------------------- 1 file changed, 71 insertions(+), 54 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 7c7461e22d..17e731d7a0 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -351,6 +351,72 @@ static int vfio_pci_igd_lpc_init(VFIOPCIDevice *vdev, return ret; } +static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice *vdev, Error **errp) +{ + g_autofree struct vfio_region_info *host = NULL; + g_autofree struct vfio_region_info *lpc = NULL; + PCIDevice *lpc_bridge; + int ret; + + /* + * Copying IDs or creating new devices are not supported on hotplug + */ + if (vdev->pdev.qdev.hotplugged) { + error_setg(errp, "IGD LPC is not supported on hotplugged device"); + return false; + } + + /* + * We need to create an LPC/ISA bridge at PCI bus address 00:1f.0 that we + * can stuff host values into, so if there's already one there and it's not + * one we can hack on, this quirk is no-go. Sorry Q35. + */ + lpc_bridge = pci_find_device(pci_device_root_bus(&vdev->pdev), + 0, PCI_DEVFN(0x1f, 0)); + if (lpc_bridge && !object_dynamic_cast(OBJECT(lpc_bridge), + "vfio-pci-igd-lpc-bridge")) { + error_setg(errp, + "Cannot create LPC bridge due to existing device at 1f.0"); + return false; + } + + /* + * Check whether we have all the vfio device specific regions to + * support LPC quirk (added in Linux v4.6). + */ + ret = vfio_get_dev_region_info(&vdev->vbasedev, + VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL, + VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG, &lpc); + if (ret) { + error_setg(errp, "IGD LPC bridge access is not supported by kernel"); + return false; + } + + ret = vfio_get_dev_region_info(&vdev->vbasedev, + VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL, + VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG, &host); + if (ret) { + error_setg(errp, "IGD host bridge access is not supported by kernel"); + return false; + } + + /* Create/modify LPC bridge */ + ret = vfio_pci_igd_lpc_init(vdev, lpc); + if (ret) { + error_setg(errp, "Failed to create/modify LPC bridge for IGD"); + return false; + } + + /* Stuff some host values into the VM PCI host bridge */ + ret = vfio_pci_igd_host_init(vdev, host); + if (ret) { + error_setg(errp, "Failed to modify host bridge for IGD"); + return false; + } + + return true; +} + #define IGD_GGC_MMIO_OFFSET 0x108040 #define IGD_BDSM_MMIO_OFFSET 0x1080C0 @@ -419,10 +485,7 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) { - g_autofree struct vfio_region_info *host = NULL; - g_autofree struct vfio_region_info *lpc = NULL; - PCIDevice *lpc_bridge; - int ret, gen; + int gen; uint64_t gms_size; uint64_t *bdsm_size; uint32_t gmch; @@ -440,20 +503,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) return; } - /* - * We need to create an LPC/ISA bridge at PCI bus address 00:1f.0 that we - * can stuff host values into, so if there's already one there and it's not - * one we can hack on, legacy mode is no-go. Sorry Q35. - */ - lpc_bridge = pci_find_device(pci_device_root_bus(&vdev->pdev), - 0, PCI_DEVFN(0x1f, 0)); - if (lpc_bridge && !object_dynamic_cast(OBJECT(lpc_bridge), - "vfio-pci-igd-lpc-bridge")) { - error_report("IGD device %s cannot support legacy mode due to existing " - "devices at address 1f.0", vdev->vbasedev.name); - return; - } - /* * IGD is not a standard, they like to change their specs often. We * only attempt to support back to SandBridge and we hope that newer @@ -466,29 +515,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) return; } - - /* - * Check whether we have all the vfio device specific regions to - * support legacy mode (added in Linux v4.6). If not, bail. - */ - ret = vfio_get_dev_region_info(&vdev->vbasedev, - VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL, - VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG, &host); - if (ret) { - error_report("IGD device %s does not support host bridge access," - "legacy mode disabled", vdev->vbasedev.name); - return; - } - - ret = vfio_get_dev_region_info(&vdev->vbasedev, - VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL, - VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG, &lpc); - if (ret) { - error_report("IGD device %s does not support LPC bridge access," - "legacy mode disabled", vdev->vbasedev.name); - return; - } - /* Setup OpRegion access */ if (!vfio_pci_igd_setup_opregion(vdev, &err)) { error_append_hint(&err, "IGD legacy mode disabled\n"); @@ -496,19 +522,10 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) return; } - /* Create our LPC/ISA bridge */ - ret = vfio_pci_igd_lpc_init(vdev, lpc); - if (ret) { - error_report("IGD device %s failed to create LPC bridge, " - "legacy mode disabled", vdev->vbasedev.name); - return; - } - - /* Stuff some host values into the VM PCI host bridge */ - ret = vfio_pci_igd_host_init(vdev, host); - if (ret) { - error_report("IGD device %s failed to modify host bridge, " - "legacy mode disabled", vdev->vbasedev.name); + /* Setup LPC bridge / Host bridge PCI IDs */ + if (!vfio_pci_igd_setup_lpc_bridge(vdev, &err)) { + error_append_hint(&err, "IGD legacy mode disabled\n"); + error_report_err(err); return; } From patchwork Mon Feb 24 18:29:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13988785 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50671C021BB for ; Mon, 24 Feb 2025 18:37:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdH0-0001zH-Hd; Mon, 24 Feb 2025 13:33:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmdDO-0005n0-2W for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:30:04 -0500 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdDK-0003Ob-4I for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:30:01 -0500 Received: by mail-pl1-x642.google.com with SMTP id d9443c01a7336-2211cd4463cso95523035ad.2 for ; Mon, 24 Feb 2025 10:29:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740421795; x=1741026595; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VP4n7opB8QbukdZTzJ/LfTVgdfdNgX/zuMQKCJL71FE=; b=cbtJcPKT+laILcR9vOYpLeGgSH4S71mPg1FnsTzaw9qV4ABU4Pm93NhpDKub0sFJeF STpc2vPW/Nja7hhMvK3DxWCEBAAEiKvZSPtnxD9a30wRzIgXpZ42zKBOIkH2Zzwb9NYA Aspz40UBQyA/L04Ut5sqezyeJ8bBJaeZEXRdtW8L9FiqKIdgyXQNlTWY1IeULrBakb83 ylGcQkXCnTfj82ka7QzsgixBlP+vqzG3J2H6zh8oQxBKfAgDJXKq9f/x5p4HwA+TPW2U t1IhhKAeA6W1OSTWKpTOlhjJJp/tx0VfWR12WHbHH4JLZPlR1WS5q7o6oKcH0PQjc//p xF1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740421795; x=1741026595; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VP4n7opB8QbukdZTzJ/LfTVgdfdNgX/zuMQKCJL71FE=; b=vcqzjTmGCt71/m/IxITM8XgfJUqQNTfy8dCOXxpK2Ir+MbRyco4fKRqcC0t0qfumfr rYxYEsLoDuFIGPhgl+XwSNxn2ZxQzfPaPOf+w3x3N/3stWVSG+kqVaMrr7esKaWBoh3S 9XyhksgXRyqU0Ziklz0ETBh4eCKf777szh/yRiurCMwjJ0vrmhXcgla1VfgiNhdo8Wja 7t73/jxbj6oXFcMe7AVKvn2yk3HZqBCX8U40wN/3SXcO9qeb8RBKU3eP4q++pZFeadS9 1WPCv83X2lEj2Yl1wIyLEInwbiZrWmeVoqpT5tqlB13z0FJlhVIAeqpkxnQtsm3D1T7g KzJw== X-Gm-Message-State: AOJu0Yz0AicEewUq5bj7cFnc8Wz4TVA84+2PLeTB7xjQ2YSr3Bv8lRLj YrQA5TpJVEi72Hwq0boz1uZhWl+DlNDq3jrE7jd2VhIlDVNOZno= X-Gm-Gg: ASbGncvOmRjqCb75IIU6O6SqWj3y4Vn97p/AWx81W4DEZL8yyaXo74GJZKJ4N/JaEM0 v0gQmsZh3V6R7C5Q3wvkuUmxwSFte1V6YbcjdbF2gT56RDu+dKeZFgBhcNWGbqjeA7S1X0E0Sq9 ua/ickQZkn9CwucX4yq09vCR3C4NT9cxc7L7LuMfpKKi/iD+EQ8+4n3TSCps1sa/e3itQWwJPws 3ApjKOQzfiy+qVnnKjb6DQLRRGvsowJdojJVookD9bKDelG+4VX1sCRb2d+uALGpoT8QFGBHp0w 1lWkKhSYHnjFjn5h3ftIxpzAl37nlkBhFp+L39E= X-Google-Smtp-Source: AGHT+IE1w4lE5U9bUzPUCbbkcruo6kYxA/96ec9zeQ4Yck/h8QPGjs4Wt6qKa+nUQDBYCiRtrDGZdQ== X-Received: by 2002:a17:902:ccc8:b0:215:44fe:163e with SMTP id d9443c01a7336-22307b33029mr3774315ad.1.1740421794986; Mon, 24 Feb 2025 10:29:54 -0800 (PST) Received: from localhost.localdomain ([116.227.8.253]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545cf6bsm183662615ad.123.2025.02.24.10.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 10:29:54 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Cc: qemu-devel@nongnu.org, Tomita Moeko Subject: [PATCH 08/10] vfio/pci: Add placeholder for device-specific config space quirks Date: Tue, 25 Feb 2025 02:29:25 +0800 Message-ID: <20250224182927.31519-9-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250224182927.31519-1-tomitamoeko@gmail.com> References: <20250224182927.31519-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::642; envelope-from=tomitamoeko@gmail.com; helo=mail-pl1-x642.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org IGD devices require device-specific quirk to be applied to their PCI config space. Currently, it is put in the BAR4 quirk that does nothing to BAR4 itself. Add a placeholder for PCI config space quirks to hold that quirk later. Signed-off-by: Tomita Moeko --- hw/vfio/pci-quirks.c | 5 +++++ hw/vfio/pci.c | 4 ++++ hw/vfio/pci.h | 1 + 3 files changed, 10 insertions(+) diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c index cac0aa1910..8a81c60400 100644 --- a/hw/vfio/pci-quirks.c +++ b/hw/vfio/pci-quirks.c @@ -1117,6 +1117,11 @@ static void vfio_probe_rtl8168_bar2_quirk(VFIOPCIDevice *vdev, int nr) /* * Common quirk probe entry points. */ +bool vfio_config_quirk_setup(VFIOPCIDevice *vdev, Error **errp) +{ + return true; +} + void vfio_vga_quirk_setup(VFIOPCIDevice *vdev) { vfio_vga_probe_ati_3c3_quirk(vdev); diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 56d7097a7a..10f63d4589 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3124,6 +3124,10 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) goto out_unset_idev; } + if (!vfio_config_quirk_setup(vdev, errp)) { + goto out_unset_idev; + } + if (vdev->vga) { vfio_vga_quirk_setup(vdev); } diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index ca7c0415f0..5570f08f4f 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -205,6 +205,7 @@ uint64_t vfio_vga_read(void *opaque, hwaddr addr, unsigned size); void vfio_vga_write(void *opaque, hwaddr addr, uint64_t data, unsigned size); bool vfio_opt_rom_in_denylist(VFIOPCIDevice *vdev); +bool vfio_config_quirk_setup(VFIOPCIDevice *vdev, Error **errp); void vfio_vga_quirk_setup(VFIOPCIDevice *vdev); void vfio_vga_quirk_exit(VFIOPCIDevice *vdev); void vfio_vga_quirk_finalize(VFIOPCIDevice *vdev); From patchwork Mon Feb 24 18:29:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13988786 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA6EAC021BB for ; Mon, 24 Feb 2025 18:39:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdM7-0001LD-VE; Mon, 24 Feb 2025 13:39:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmdDO-0005nN-Ow for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:30:04 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdDK-0003Ps-NL for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:30:01 -0500 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-220e6028214so103493215ad.0 for ; Mon, 24 Feb 2025 10:29:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740421797; x=1741026597; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WWgHd6CvjQ8lpt36ZQ5+z6WnJSuOnamZfqpjigbR5uo=; b=LN6SVlpLk8d02jkd5FbkZk+srclQ8UHqSZgl3poZa8NLUz7HaZx/B89ftR7jCQnAw0 j7NiPj6IlXp6xn6kG5ukMmnlbvEQq39KfQi9K0V4cMWMT1ypIUUtIlCiXh++S649h0+I OHLwk8bzwfwzEl60nIrukLrjHdSvzj2YKSBEp9geKLJ+OlKmax0zGgKluDGf/w5NOlaI ry9MLFATwW2Nq8xhqUymbIII9q1+uiIT/ZMGNSaoXxPq4iyPk1ARKSuwxJeRP6uqe2TC swWT4065/Jma4T8O8PquGrL4/w/5tSfcXXDotAoSZf9ZvFOYklemmfgipI3HInhETCU9 gfZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740421797; x=1741026597; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WWgHd6CvjQ8lpt36ZQ5+z6WnJSuOnamZfqpjigbR5uo=; b=ES9BFOQlZIr0+FGGOxhG3c4JLceBoQkHOgaNZTQQe7q6U1oWo5p4YsY4dBzjr3c2Q1 hS95WXjIshAciPysmJYRRyBXfJj9w7NDqxZzkbh7d3tMdpzTU2oDUFUVh4f6Ml/BPk9H 7gOG+4SJzDBLJh4tnjnmMCuDmRvDnUp9KIjukjXxwfnYGQMJf26p7ziroQ8V+sAE6MH7 T+vfya2HNhtLRdwttPSDgLU7au+FoMkgnemuwfz1FIuwTnpcjVUBQOpd9KWRmGCNFW+1 3pQsP6qRbXzgEVtu9HL501Ktd90fqB8BuL8SJUBHHLh4tmtK63Nb/q9LO5yFYJsUkbXS BILg== X-Gm-Message-State: AOJu0YyE0lmwz5nebdqhFvbjN1/hZUEiOPQ8KzPC/MowNzH/BtKHJHjz CVG7UnjHQJQeZj59MZYPfdh0KUbf/4YOg4ShyDv7sJ9eoEG91Ms= X-Gm-Gg: ASbGncuBw3wqVKbFZ587QJpZ2Iu4x/khdeSdfU31R0nzjjF2qhXnW4rOKXpIPdrobcc LIj5evbkCR2ILXoAQ8T/YLLGm04sCCpmUp9hXE6LmY9Wn8zd5B/vuwgfgnWIx4RTTBNc7FhQswk AAAfe0XjUdEgwfaU+0CJUw7J0l2dZuNTUddEaMj3+wYLJzGHlabiU1wukp4Ie4Z64vSaX98Pjyp oJLfaCCwQ83jgyNl0xrDlrfwJwfc6wfmatz/rUUfJr9iHkEgds22Kag5GeHueEvDTGjBZog8x8n zgGPNlsa2M2IQ/ThwJzKtzxmFviBqvjtT0jRbC0= X-Google-Smtp-Source: AGHT+IH4teq3Pg6kGVeb/GrLxLEjGn2YP9U0A+s+E7AC0qYLT7+dnZXjipJFcLX8gtRMzpA93WYMbg== X-Received: by 2002:a17:902:d484:b0:21f:164d:93fa with SMTP id d9443c01a7336-2219ff82783mr204766935ad.6.1740421796990; Mon, 24 Feb 2025 10:29:56 -0800 (PST) Received: from localhost.localdomain ([116.227.8.253]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545cf6bsm183662615ad.123.2025.02.24.10.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 10:29:56 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Cc: qemu-devel@nongnu.org, Tomita Moeko Subject: [PATCH 09/10] vfio/igd: Refactor vfio_probe_igd_bar4_quirk into pci config quirk Date: Tue, 25 Feb 2025 02:29:26 +0800 Message-ID: <20250224182927.31519-10-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250224182927.31519-1-tomitamoeko@gmail.com> References: <20250224182927.31519-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::644; envelope-from=tomitamoeko@gmail.com; helo=mail-pl1-x644.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The actual IO BAR4 write quirk in vfio_probe_igd_bar4_quirk was removed in previous change, leaving the function not matching its name, so move it into the newly introduced vfio_config_quirk_setup. There is no functional change in this commit. For now, to align with current legacy mode behavior, it returns and proceeds on error. Later it will fail on error after the removal of legacy mode. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 16 +++++++++------- hw/vfio/pci-quirks.c | 6 +++++- hw/vfio/pci.h | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 17e731d7a0..1ed364b497 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -482,8 +482,8 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, bdsm_quirk, next); } - -void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) +bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, + Error **errp G_GNUC_UNUSED) { int gen; uint64_t gms_size; @@ -497,10 +497,10 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) * PCI bus address. */ if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) || - !vfio_is_vga(vdev) || nr != 4 || + !vfio_is_vga(vdev) || &vdev->pdev != pci_find_device(pci_device_root_bus(&vdev->pdev), 0, PCI_DEVFN(0x2, 0))) { - return; + return true; } /* @@ -512,21 +512,21 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) if (gen == -1) { error_report("IGD device %s is unsupported in legacy mode, " "try SandyBridge or newer", vdev->vbasedev.name); - return; + return true; } /* Setup OpRegion access */ if (!vfio_pci_igd_setup_opregion(vdev, &err)) { error_append_hint(&err, "IGD legacy mode disabled\n"); error_report_err(err); - return; + return true; } /* Setup LPC bridge / Host bridge PCI IDs */ if (!vfio_pci_igd_setup_lpc_bridge(vdev, &err)) { error_append_hint(&err, "IGD legacy mode disabled\n"); error_report_err(err); - return; + return true; } gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4); @@ -588,4 +588,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) } trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, (gms_size / MiB)); + + return true; } diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c index 8a81c60400..f2b37910f0 100644 --- a/hw/vfio/pci-quirks.c +++ b/hw/vfio/pci-quirks.c @@ -1119,6 +1119,11 @@ static void vfio_probe_rtl8168_bar2_quirk(VFIOPCIDevice *vdev, int nr) */ bool vfio_config_quirk_setup(VFIOPCIDevice *vdev, Error **errp) { +#ifdef CONFIG_VFIO_IGD + if (!vfio_probe_igd_config_quirk(vdev, errp)) { + return false; + } +#endif return true; } @@ -1170,7 +1175,6 @@ void vfio_bar_quirk_setup(VFIOPCIDevice *vdev, int nr) vfio_probe_rtl8168_bar2_quirk(vdev, nr); #ifdef CONFIG_VFIO_IGD vfio_probe_igd_bar0_quirk(vdev, nr); - vfio_probe_igd_bar4_quirk(vdev, nr); #endif } diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 5570f08f4f..6fe25c9701 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -217,7 +217,7 @@ bool vfio_add_virt_caps(VFIOPCIDevice *vdev, Error **errp); void vfio_quirk_reset(VFIOPCIDevice *vdev); VFIOQuirk *vfio_quirk_alloc(int nr_mem); void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr); -void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr); +bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp); extern const PropertyInfo qdev_prop_nv_gpudirect_clique; From patchwork Mon Feb 24 18:29:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13988763 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1C834C021A4 for ; Mon, 24 Feb 2025 18:35:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdH5-0002JJ-P0; Mon, 24 Feb 2025 13:33:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmdDS-0005sW-Rd for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:30:07 -0500 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdDQ-0003QU-DG for qemu-devel@nongnu.org; Mon, 24 Feb 2025 13:30:06 -0500 Received: by mail-pl1-x641.google.com with SMTP id d9443c01a7336-221050f3f00so107688515ad.2 for ; Mon, 24 Feb 2025 10:30:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740421799; x=1741026599; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GZ0KWWRMjO58+2EwLS0op2e0oRMhMHw5+zLruMclF5A=; b=gjWJwzRDf40jS6xSAMctQ3GFuBMvol03jNtEDUE2eTCoybuxFP3SGbonETFw8kYPGP nZP1hU4gVp3B5f0sUs1FB8v1eP25UY5VVjUJSPMdpaJogFarsZUvY7JRUtyyUFwnR0eM bjPAf0XHKOrCV6pip8WL68RhHuO9+P7yX/DkgYXdEIjdCs9nYfNpYs+yi50yVUp3eoKs 2C/TKPAgpVGSkM5feGQIvLozYtnXApYJMKkomAaioHLUgJd+mgQCOFUZQAzS1QgxULqh 4/Kd7dA7M/O8MdoKOfxukUPUNlFWKQxixUHOLDrWOczVmhwQa/u4+88Djq8Blp4oapfs 4JYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740421799; x=1741026599; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GZ0KWWRMjO58+2EwLS0op2e0oRMhMHw5+zLruMclF5A=; b=edAiIhzjztY223RSqVCOMFGmhT7EqVB3Ml515/x3TfqSbm7LFHKogNoMaGzFn5yfkn gbFw1HkTkQ0wtz113snjvjdDZdd7bJO11TSDhhpYbBzjCdk/qytaXFqjmSqsfZY98nbQ ZIdKEx6wtmRNIYzPDIe8v8sx1m6Ue81QktoS6ca7Zoyu/hJ7JVMnVmk3WaDZNNPwjFPu XkqUJ+ThESJhNN4VcPb5qYVeyvM1pJQ+A5lDg6DA4MJ2c8UgJXT59AtoClouF7xoxank j/qny37cwdBDkrk/8ktgmWYI9oWVJAH6kSWx7/ocQdObToyDObm3M5GtLQ9LDVCHNalY 4EZg== X-Gm-Message-State: AOJu0YzCLPAJuI14+u6xAYIhNn86BstXxRE4f0JRrPvj4jmKVTXoHWEA riU3QpHw33X0WBLF/mjHfVwvtiYTGvxDRhZqeLaBWxx/Pd0hfQQ= X-Gm-Gg: ASbGnctmzqSBjrtk9tv37RXz+kYXSDU5CJvsYUmi3j4zj/esol163EuKQ2Byw3gtH5l h9hk6/d4G1DytFa+pRIz0/mykSPbfVIHNfyFlAxwQyvDGYuIQJp33224Uwc6jyHuC+yVdklka2l FgAPI5eVCJIj6YTNIZuhaPH9NQiuDa+2rEOhikxRrb2AmzkUGF982hNBzK7KswXkImQUxY23FPQ hX1P0E61Q3BZjXyULHZjcm2Hb2KLnTru2LmwZBEN558VmIhrGsU3yMApW83Ah2DmWHK9sH+7LoP msba++PLXwCA1NZVt35KnhLD7wY9Hhe7ofMlkps= X-Google-Smtp-Source: AGHT+IFhRVxjQEqWCOV1a6/3ejmShP2JjfN6oBDMopUq+Emqa/9oA9boGbK2aSDj4DTF/G4vL/xdug== X-Received: by 2002:a17:902:db0f:b0:21f:988d:5756 with SMTP id d9443c01a7336-22307e6ccf6mr3065925ad.42.1740421799009; Mon, 24 Feb 2025 10:29:59 -0800 (PST) Received: from localhost.localdomain ([116.227.8.253]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545cf6bsm183662615ad.123.2025.02.24.10.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 10:29:58 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Cc: qemu-devel@nongnu.org, Tomita Moeko Subject: [PATCH 10/10] vfio/igd: Replace legacy mode with options Date: Tue, 25 Feb 2025 02:29:27 +0800 Message-ID: <20250224182927.31519-11-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250224182927.31519-1-tomitamoeko@gmail.com> References: <20250224182927.31519-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::641; envelope-from=tomitamoeko@gmail.com; helo=mail-pl1-x641.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org IGD-specific quirks are implicitly enabled by legacy mode, which is toggled by assigning IGD to 00:02.0. This patch replaces legacy mode with explicit options for these quirks. The OpRegion quirk is merged to the exisiting x-igd-opregion option, while a new option x-igd-lpc is defined for the LPC bridge / Host bridge ID quirk. The BDSM and GGC register quirks is applied to all known IGD devices. BDSM register, which contains HPA (meaningless to guest), is initialized to 0. GGC register is just a copy if x-igd-gms is not specified. Unlike legacy mode, these options do not require IGD BDF being 00:02.0, but guest drivers like EFI GOP driver still hardcodes the BDF. It is highly recommended to assign IGD to 00:02.0. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 38 +++++++++----------------------------- hw/vfio/pci.c | 11 ++--------- hw/vfio/pci.h | 3 +++ 3 files changed, 14 insertions(+), 38 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 1ed364b497..54a6a7b97f 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -426,15 +426,8 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) VFIOConfigMirrorQuirk *ggc_mirror, *bdsm_mirror; int gen; - /* - * This must be an Intel VGA device at address 00:02.0 for us to even - * consider enabling legacy mode. Some driver have dependencies on the PCI - * bus address. - */ if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) || - !vfio_is_vga(vdev) || nr != 0 || - &vdev->pdev != pci_find_device(pci_device_root_bus(&vdev->pdev), - 0, PCI_DEVFN(0x2, 0))) { + !vfio_is_vga(vdev) || nr != 0) { return; } @@ -482,24 +475,15 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, bdsm_quirk, next); } -bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, - Error **errp G_GNUC_UNUSED) +bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp) { int gen; uint64_t gms_size; uint64_t *bdsm_size; uint32_t gmch; - Error *err = NULL; - /* - * This must be an Intel VGA device at address 00:02.0 for us to even - * consider enabling legacy mode. The vBIOS has dependencies on the - * PCI bus address. - */ if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) || - !vfio_is_vga(vdev) || - &vdev->pdev != pci_find_device(pci_device_root_bus(&vdev->pdev), - 0, PCI_DEVFN(0x2, 0))) { + !vfio_is_vga(vdev)) { return true; } @@ -510,23 +494,19 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, */ gen = igd_gen(vdev); if (gen == -1) { - error_report("IGD device %s is unsupported in legacy mode, " - "try SandyBridge or newer", vdev->vbasedev.name); return true; } /* Setup OpRegion access */ - if (!vfio_pci_igd_setup_opregion(vdev, &err)) { - error_append_hint(&err, "IGD legacy mode disabled\n"); - error_report_err(err); - return true; + if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) && + !vfio_pci_igd_setup_opregion(vdev, errp)) { + return false; } /* Setup LPC bridge / Host bridge PCI IDs */ - if (!vfio_pci_igd_setup_lpc_bridge(vdev, &err)) { - error_append_hint(&err, "IGD legacy mode disabled\n"); - error_report_err(err); - return true; + if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_LPC) && + !vfio_pci_igd_setup_lpc_bridge(vdev, errp)) { + return false; } gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4); diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 10f63d4589..dde2b34d9d 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3136,15 +3136,6 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) vfio_bar_quirk_setup(vdev, i); } -#ifdef CONFIG_VFIO_IGD - if (!vdev->igd_opregion && - vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) { - if (!vfio_pci_igd_setup_opregion(vdev, errp)) { - goto out_unset_idev; - } - } -#endif - /* QEMU emulates all of MSI & MSIX */ if (pdev->cap_present & QEMU_PCI_CAP_MSIX) { memset(vdev->emulated_config_bits + pdev->msix_cap, 0xff, @@ -3363,6 +3354,8 @@ static const Property vfio_pci_dev_properties[] = { VFIO_FEATURE_ENABLE_REQ_BIT, true), DEFINE_PROP_BIT("x-igd-opregion", VFIOPCIDevice, features, VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT, false), + DEFINE_PROP_BIT("x-igd-lpc", VFIOPCIDevice, features, + VFIO_FEATURE_ENABLE_IGD_LPC_BIT, false), DEFINE_PROP_ON_OFF_AUTO("enable-migration", VFIOPCIDevice, vbasedev.enable_migration, ON_OFF_AUTO_AUTO), DEFINE_PROP_BOOL("migration-events", VFIOPCIDevice, diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 6fe25c9701..596c78e99e 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -154,6 +154,9 @@ struct VFIOPCIDevice { #define VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT 2 #define VFIO_FEATURE_ENABLE_IGD_OPREGION \ (1 << VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT) +#define VFIO_FEATURE_ENABLE_IGD_LPC_BIT 3 +#define VFIO_FEATURE_ENABLE_IGD_LPC \ + (1 << VFIO_FEATURE_ENABLE_IGD_LPC_BIT) OnOffAuto display; uint32_t display_xres; uint32_t display_yres;