From patchwork Fri Jan 24 19:12:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13949862 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 478A9C02181 for ; Fri, 24 Jan 2025 19:14:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbP76-0006iz-74; Fri, 24 Jan 2025 14:13:08 -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 1tbP73-0006iR-VV for qemu-devel@nongnu.org; Fri, 24 Jan 2025 14:13:05 -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 1tbP71-0007p0-RZ for qemu-devel@nongnu.org; Fri, 24 Jan 2025 14:13:05 -0500 Received: by mail-pl1-x642.google.com with SMTP id d9443c01a7336-21654fdd5daso43492015ad.1 for ; Fri, 24 Jan 2025 11:13:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737745982; x=1738350782; 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=CYTK4FOAGMQ4aoGzeevbgSFeP1zqyDousFfCzUkJiJA=; b=VMJtQzSnggu+rHPbDhrxiXPRxhxjrYy1QkzzG6ink+YJl/kvSxezqHGKsUOSTDrJ5Y 2smogLwNwlM84xJygcg7SvujRaMUnIvwjCqzuh6YaCnO8wj3sVS8Go8OvAblMfqBV5Vp n8vP2k6GARBo9kP3LVSi8v5NGjPXq2J8dMgcCx0HhZwNeWTT+UL0qJcRN+917cbF8Nu0 W2WLaSyp/qJdA5a2w6925li0av3eIbOosb9gQc2Ie9aibuUAlN20IRZBCHkBR7uJ54Gu ocE17JU6R1Yx0CZXAdtfczNyv/3obkPQXMTuZodX8pSmEX2yvDOeTDAIZtaWwthMPod/ PIcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737745982; x=1738350782; 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=CYTK4FOAGMQ4aoGzeevbgSFeP1zqyDousFfCzUkJiJA=; b=rbkZX+Wjyk4XNyEzGo9okJFcVdFrF08Vc/enpNROMqNXkSu7ZOrBeYvT6uBqnxLrBC 7yiuYeajBQ5V0WJl0zFlP6Nckwq8PtubsPsDTtD7BrXyVj1h/5Rg648lajjjg5PJXhlo DeQ+BBgPxBMmBUihTeYoG7+DciAXgginXXcJlWl72FtNrxaawu23jEMVqR+pL+/dnmEZ unO5tOFtgaQtualhCquQ5yVcTAb5uOtY01I1clIs5SoSR1SUs5UzdAKS6BVA9kpJmTXW a5787f0gQu0Xz5a5y3GiHWqIX0pSC6CfhxlQ1jaJndvfgBcfucn2GGEWcmc4aTt/Nkar poBA== X-Gm-Message-State: AOJu0YxBdqXzaUa/biyT5kowLB+sNrN/TuBjj6Xi3f1y36ovmRlmBPnh 1Cq1fnLZ3WmP7o4rZmT1yqjUIdBCm7Y5+rZ0UvQ187ypy4YZrck= X-Gm-Gg: ASbGnctRq1URHeHEaq6hxumLYc3kVpaB3BgvmOleErXFXxbbGSOAOrQ06csFBz+4r9O Esvc8saKhT3ZiwvBELh+mYPqQxN9AM/OkMPHM4rOjwWVeZhMVdY4rfTFXbw1+zHtTOZ7nn1e8Pw JsPCnMAfO9ucA6/07NPg+2Eb41B9GesaibyELx7OZwIG1066qZeidDlY0/41tlGsf4d5Zjx3bU0 IaiVbRKYeLVPxBsG7BWOvhemV0M9GzqzYjafqDrbdbxn7CrY9LDFhHTHAHMlADq1JuWuJUhVpWx Qy9IkNdBUr366thEyQ== X-Google-Smtp-Source: AGHT+IG4VKhmRPdJ0LCS8JPA0Tko1w+kh/qVkJdp4Gg+ih3cQ+8DQnATnlIGHkU2cA4Coicvf5O9lw== X-Received: by 2002:a05:6a00:1954:b0:72d:8d98:c247 with SMTP id d2e1a72fcca58-72daf9e0b54mr52365816b3a.8.1737745981826; Fri, 24 Jan 2025 11:13:01 -0800 (PST) Received: from localhost.localdomain ([58.37.175.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72f8a69eb75sm2318406b3a.12.2025.01.24.11.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 11:13:01 -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 v2 1/5] vfio/igd: remove GTT write quirk in IO BAR 4 Date: Sat, 25 Jan 2025 03:12:41 +0800 Message-ID: <20250124191245.12464-2-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250124191245.12464-1-tomitamoeko@gmail.com> References: <20250124191245.12464-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, T_SCC_BODY_TEXT_LINE=-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 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 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 Fri Jan 24 19:12:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13949863 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 D76A6C0218B for ; Fri, 24 Jan 2025 19:14:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbP77-0006jU-Jx; Fri, 24 Jan 2025 14:13:09 -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 1tbP75-0006ia-G2 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 14:13: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 1tbP73-0007pH-QB for qemu-devel@nongnu.org; Fri, 24 Jan 2025 14:13:07 -0500 Received: by mail-pl1-x641.google.com with SMTP id d9443c01a7336-21661be2c2dso43900675ad.1 for ; Fri, 24 Jan 2025 11:13:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737745984; x=1738350784; 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=hpBzjRP7lcZnfFl2TlBZJg+t978qeJXz0xSVkKJdZmw=; b=HEfL3R8LAE6CS1BL56yr8xDUOAXf4o+f2JitDfHkZ5ih9XeVlMLKFNVx4EXgL1ZDyE ZyLpnvwyN7XkQ4jfkSLCfNScrXfAvidAAOET3v3qU5e0UF0Z28xOUALFTfUAIJpmRjni rKoVNSgi8wpdTr6//K3EkLp1Oz8BKeGUa3vpTwPUtNCtO82yHoZncAC1jjKy+TwSKWev 6yMBmIPjXomLmr6ZBJPbh9+Epf4Ch6ny2WE3G89Q4h75W91vPLv0O0SlgD6qDmM314RJ rJkqH2BEzVTGbgia7rrAcVsqAV9rjU3NZ223oC/7dhzpla3PLCOcs7LqK3yrC7YeFV3r Eoww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737745984; x=1738350784; 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=hpBzjRP7lcZnfFl2TlBZJg+t978qeJXz0xSVkKJdZmw=; b=NDAgKbah1tXh5w4ZxhoLtY3R/vWbgGv9Jc2U3srj3H/bYGc5Arm+s8mHVlUcEEsBSu ZMxrrYz9byOycIj68giyBtLiOqC3+amdeWPJEJATokehUL9O+mEgKei+To/m9mdohJ0o gvtrCeWz+1V7Sya+YT4kGGz73fPyftWTlGPvESny5jsG+V+Lfj46xhPSCFYH33IS6lh6 kxWvj/5j3fJOgJsgBl6HBnt/9bvon5nkBgEAmHEQeOLsXpPUzKFSWsGHej5BTRxFEKmM 1BjMensjUyQdLLTHRhCqwOhXergQwDnmXDPiwJi9OpqneUJb/48AZZsrUhCgfnHznlFa ukTg== X-Gm-Message-State: AOJu0Yz35SryPVbl+hDqJjIRUAe9HsZisPuN5tJqERxBU2veUE1F5w6F wmtOOpSD0cYEMGBWKC8frQMELmZ3TWeQqTrRVg0MrjW19SDiR0w= X-Gm-Gg: ASbGncshCo8+K9cbWQLO/aVnf/ysGZfT7Q0zD8blFduZWaK7Vr5DXRRHb5WyPI/pgsn N9+TrmGWhKyDhWsNpqy/rwc3Bi0YX3nyrwYQafoI35VBWXihWLq6WrWYwaZyo9msqVRRpPvM33E 3ST1fVh0h4ClbiEGVj4rpH3BI8lWGyCK4omnLNUYtvf+ZY4gAqH9P8yoTnXWD0dbU3OqvZPDeVp C8c+bQj6os3rqExGYilMPUIK+PABorCS0PXzLyxQTnimmWlHpqBlGUlNRtfB2DY5kZ2rO9R4zyX VOjeRhpfAoBY7s38eA== X-Google-Smtp-Source: AGHT+IH9tCPG4/AODJdqi55ni/jqXRdVVJgh/9jddTcXmaB1iqj+nXihcTUshRATrhyLWNcDRr57tA== X-Received: by 2002:a05:6a21:9986:b0:1dc:7907:6d67 with SMTP id adf61e73a8af0-1eb215f52b2mr57746580637.40.1737745983747; Fri, 24 Jan 2025 11:13:03 -0800 (PST) Received: from localhost.localdomain ([58.37.175.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72f8a69eb75sm2318406b3a.12.2025.01.24.11.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 11:13:03 -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 v2 2/5] vfio/pci: add placeholder for device-specific config space quirks Date: Sat, 25 Jan 2025 03:12:42 +0800 Message-ID: <20250124191245.12464-3-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250124191245.12464-1-tomitamoeko@gmail.com> References: <20250124191245.12464-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, T_SCC_BODY_TEXT_LINE=-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 Some devices, such as IGD, require device-specific quirks to be applied to their pci config spaces. Currently, these quirks are either part of BAR quirk, or being a part of vfio_realize(). Add a placeholder for pci config quirks for moving the quirks to one place 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 fbe43b0a79..c40e3ca88f 100644 --- a/hw/vfio/pci-quirks.c +++ b/hw/vfio/pci-quirks.c @@ -1167,6 +1167,11 @@ bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, /* * 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 ab17a98ee5..e624ae56c4 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 43c166680a..5359e94f18 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 Fri Jan 24 19:12:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13949860 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 5F6CAC02181 for ; Fri, 24 Jan 2025 19:13:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbP79-0006ju-FB; Fri, 24 Jan 2025 14:13:11 -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 1tbP77-0006jL-AC for qemu-devel@nongnu.org; Fri, 24 Jan 2025 14:13:09 -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 1tbP75-0007pS-92 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 14:13:09 -0500 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-21bc1512a63so49280405ad.1 for ; Fri, 24 Jan 2025 11:13:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737745986; x=1738350786; 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=Em6RHhak2GvKHZXMSIavsdqeWIHHg4HYo+MkTfEaIeM=; b=kWyveV0nfBbM5aKtU+f9m7iHKlyzfB9CEidQTEvipPCnVueLEo/QtLX+/r5oY818XR RsxGYBq69Te9bLn1EZ+YPPZDGFG8X2vZWGLlBX5W8/hqpbWt6CVo76zyt0V+VfXSHBD+ eySzymeC265FhpDA48WYOlC1qzaxZSuFOVib3jqF6ydLjFP2AeSG9ZQ2BRAF0sHxis+H w8RsA7xNrVbVPomLJ6/0fe3OM6baULClHK019FJeHG/EqbwrWzCJyy0UaE+ghYGA0l3j 88oDxwYZ/850YfwmlgxGWJQ5lUyq3KlKpEaeImgjQ5FqxEE/FmpOlX9sSNp+drHWqu1X ZoIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737745986; x=1738350786; 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=Em6RHhak2GvKHZXMSIavsdqeWIHHg4HYo+MkTfEaIeM=; b=U8mMQ6NPyzyZF65TJ/ect18QQ9Hf9LxUzCaqRnR1xH74u6LEA7lA4jMHtyWOiN2rgt 2w6QHdSL8ByBX48L9Zovp+dNml9sL0MPNcuQyeP+2kAHx3X7JNEU71Y3ujiWspuNrh2P LWHsGtFx0WLJrMUxKJVmgnhl26TqWmPLfKQqQmDLMzSRadoR/HI83GlqKalIwGX1JYiC G8yC3Lxp5YHfz363hlqgl9mvui7Pu/q4ObXPEOu1bnFi0udWtR61O+9qvsvKDZ8phEqW mq+4Kj+vjNWFWa+/KIQnCCa7r32WBJBneAqsOaxFyETmL378r+5gCOHs3ZFQeVtOSr2y JHVg== X-Gm-Message-State: AOJu0Yz2KSVh1VEECxQJQxRSA3koCJKSwboLaUf+De1L+IzVtgx/ZuSW 2icD+9ocVdQXWUsSnVzjaORqSJ4ZxvNR6MxnX3Pwq8Vuk89A1+9Fz2b7dPGGXA== X-Gm-Gg: ASbGncsS53qNyABid9OOCTZjEUkg25UqUs1Et8mCFYv1VxQRE+DIlRQy1S1BcSCnI8v CQLrcybLJC9s1qYXrLU8IIIl/4LrGeV+/N5/aX7F2yP0ZtjS+S0ymsHrvFYXWrV1irN8xNsvl7h pRU3QiPAKo11H6CXQqu0rkGCiOXqXGeBEqRghi+Zlq7HBfLy8AyENzH58Z9l7I4KEB3CvbET6NW iZAlgbGz6jg4qEZ3LCeT6u++H7OR+YVzyrHZMENwxDMSShy6txLZtG5VFUwDA10OY4zJ34KaHGQ ScBjlcjoYQjB4NBoEA== X-Google-Smtp-Source: AGHT+IFlJZwbQOCEud+HN5vEW8YFK1taPgB8ORI70aXuBp2ZirboxYW5qerAPCfMuWGRYCdljNYGZg== X-Received: by 2002:a05:6a20:7f89:b0:1e0:dc34:2e7d with SMTP id adf61e73a8af0-1eb214650camr44843344637.5.1737745985605; Fri, 24 Jan 2025 11:13:05 -0800 (PST) Received: from localhost.localdomain ([58.37.175.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72f8a69eb75sm2318406b3a.12.2025.01.24.11.13.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 11:13:05 -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 v2 3/5] vfio/igd: refactor vfio_probe_igd_bar4_quirk() into pci config quirk Date: Sat, 25 Jan 2025 03:12:43 +0800 Message-ID: <20250124191245.12464-4-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250124191245.12464-1-tomitamoeko@gmail.com> References: <20250124191245.12464-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, T_SCC_BODY_TEXT_LINE=-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 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. If any failure occurs, the function simply returns and proceeds. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 31 +++++++++++++++++-------------- hw/vfio/pci-quirks.c | 6 +++++- hw/vfio/pci.h | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index ca3a32f4f2..376a26fbae 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -359,7 +359,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) { g_autofree struct vfio_region_info *rom = NULL; g_autofree struct vfio_region_info *opregion = NULL; @@ -378,10 +379,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; } /* @@ -395,7 +396,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) "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; + return true; } /* @@ -407,7 +408,7 @@ 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; } /* @@ -420,7 +421,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) if ((ret || !rom->size) && !vdev->pdev.romfile) { error_report("IGD device %s has no ROM, legacy mode disabled", vdev->vbasedev.name); - return; + return true; } /* @@ -431,7 +432,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) error_report("IGD device %s hotplugged, ROM disabled, " "legacy mode disabled", vdev->vbasedev.name); vdev->rom_read_failed = true; - return; + return true; } /* @@ -444,7 +445,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) if (ret) { error_report("IGD device %s does not support OpRegion access," "legacy mode disabled", vdev->vbasedev.name); - return; + return true; } ret = vfio_get_dev_region_info(&vdev->vbasedev, @@ -453,7 +454,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) if (ret) { error_report("IGD device %s does not support host bridge access," "legacy mode disabled", vdev->vbasedev.name); - return; + return true; } ret = vfio_get_dev_region_info(&vdev->vbasedev, @@ -462,7 +463,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) if (ret) { error_report("IGD device %s does not support LPC bridge access," "legacy mode disabled", vdev->vbasedev.name); - return; + return true; } gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4); @@ -476,7 +477,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) 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; + return true; } /* Create our LPC/ISA bridge */ @@ -484,7 +485,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) if (ret) { error_report("IGD device %s failed to create LPC bridge, " "legacy mode disabled", vdev->vbasedev.name); - return; + return true; } /* Stuff some host values into the VM PCI host bridge */ @@ -492,14 +493,14 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) if (ret) { error_report("IGD device %s failed to modify host bridge, " "legacy mode disabled", vdev->vbasedev.name); - return; + return true; } /* 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; + return true; } /* @@ -561,4 +562,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, (ggms_size + gms_size) / MiB); + + return true; } diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c index c40e3ca88f..b8379cb512 100644 --- a/hw/vfio/pci-quirks.c +++ b/hw/vfio/pci-quirks.c @@ -1169,6 +1169,11 @@ bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, */ 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; } @@ -1220,7 +1225,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 5359e94f18..5c64de0270 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 Fri Jan 24 19:12:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13949869 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 E4AA8C02181 for ; Fri, 24 Jan 2025 19:14:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbP7A-0006jx-Rk; Fri, 24 Jan 2025 14:13:12 -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 1tbP78-0006jX-Mc for qemu-devel@nongnu.org; Fri, 24 Jan 2025 14:13:10 -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 1tbP76-0007pn-Ty for qemu-devel@nongnu.org; Fri, 24 Jan 2025 14:13:10 -0500 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-21675fd60feso56260865ad.2 for ; Fri, 24 Jan 2025 11:13:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737745987; x=1738350787; 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=/rreBwOJjOLgAVavOMfVYZVMv6rRdXnJTWZ6kk51L4c=; b=nOoiz80ZCELhqkDqqtSnIZO1TOMrzvIqalPhFD2g6vB/ArwQpULjvxH6n0zUiBxJSL WbgpChrNrV5EscMzEqBrc6hs6vs9p+vtQpyTgIt0BIItj3adWEQtbDsfu1VFG3HBHPzc fPafVXXoxbF9ztGkgh9ypRKtjUjN8s0VwyhpMGwlPMlN8sPkFTkeApVnBr8zO8UGy8RS xKRIc473F3+rQGNAVrhV7t6DKx5ZUwvRoYrTVhHx8FAHQ46q2bVf1FRQHJRyvP8YBtN+ FZhwl4RIBI6xLnHDh8n96sQbPe/FywKMda/HFm0Lr3N4R4ufSIwwGg16o5GpUpMI5oxV af6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737745987; x=1738350787; 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=/rreBwOJjOLgAVavOMfVYZVMv6rRdXnJTWZ6kk51L4c=; b=J/WeAZMzCPe6VgrHfQOjxjZZ2i3d9Cno3rIGFkS9XfsoOMKT4JfmQg7q6a9n8A5WJq wdJAmzlBHFdF513KhTXRKfBd+Fns4dOjfIJh1C+XN3DWOaQbOZPWiQYQsF9HAuhNlCDY YJJq8ofhMgIxCgwhISWIVmrnPWj2P4hCfITMo1Q6KFJ1/2AxvQmhPNizkJhUDY6/OGpP a48WxpMvJdzu/tAmqVbjkGPTBPCr8k33F+X2nja+ELE4h/9vlnpK64JfnBkYc6tYC84M OGg/q89BHp1RkCbS6NlKYzMGtjf84CbKsXT9SihSLiWH5uta9/SilNm1VeurjenPgW5x aryA== X-Gm-Message-State: AOJu0YwmwqpwHBTjJ9fEGlQz2EYz0ZVQVPFEIet/FokI+an9Xy8lC/L0 q7Fn44A6aNHY95Ii5mT1HtGRpufysP2Zy36Zh1ZLZyvgjRqx3Kc= X-Gm-Gg: ASbGncvGtDF4AZ4Rra6kRZtE0sYkQUnRPuIgcA/R+WDNzTCZWLeraQ/Xy6LD2XBSvEG NLU0qM+0BehO1A5fVh9cDLUFFkDxsNqLQuFcVboKU55KBklon0Sadrz64bfvlho4eYzwYHWDfh+ Zs3F+1jJNMtOa818/fhZMy2Lq8Q3XD+bSHYvRhwzQ8fI6AZP8/qgC8swu3ZhuMNpnsyyEnxuG89 jTz7fblXIJNcl4hX0e++6d4bKraXokumC/j9x7h3s+uYuT78DWTZh4da+PFgUmJTLthzkwMPINe vp3c8zJIfhE2TFHlOQ== X-Google-Smtp-Source: AGHT+IG2QG0ppyJFwFtEoP7v+MeXi57vim1EtYYkMoNF3OfkKS1j8vwdbl1ECY+3odZy26AWJq7kfw== X-Received: by 2002:a05:6a20:8429:b0:1e1:e2d9:7f0a with SMTP id adf61e73a8af0-1eb2156f917mr59811442637.34.1737745987468; Fri, 24 Jan 2025 11:13:07 -0800 (PST) Received: from localhost.localdomain ([58.37.175.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72f8a69eb75sm2318406b3a.12.2025.01.24.11.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 11:13:07 -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 v2 4/5] vfio/igd: do not include GTT stolen size in etc/igd-bdsm-size Date: Sat, 25 Jan 2025 03:12:44 +0800 Message-ID: <20250124191245.12464-5-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250124191245.12464-1-tomitamoeko@gmail.com> References: <20250124191245.12464-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, T_SCC_BODY_TEXT_LINE=-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 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 376a26fbae..6e06dd774a 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) { @@ -368,7 +348,7 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, 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; @@ -528,7 +508,6 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, } } - ggms_size = igd_gtt_memory_size(gen, gmch); gms_size = igd_stolen_memory_size(gen, gmch); /* @@ -540,7 +519,7 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, * 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)); @@ -560,8 +539,7 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, 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)); return true; } From patchwork Fri Jan 24 19:12:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13949861 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 BE93DC0218C for ; Fri, 24 Jan 2025 19:14:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbP7C-0006kV-Fj; Fri, 24 Jan 2025 14:13:14 -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 1tbP7B-0006kC-0s for qemu-devel@nongnu.org; Fri, 24 Jan 2025 14:13:13 -0500 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tbP78-0007qG-UD for qemu-devel@nongnu.org; Fri, 24 Jan 2025 14:13:12 -0500 Received: by mail-pj1-x1042.google.com with SMTP id 98e67ed59e1d1-2eeb4d643a5so4583445a91.3 for ; Fri, 24 Jan 2025 11:13:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737745989; x=1738350789; 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=SDJQfkF7TGyKUeThCnNUPt37lNu38uEocV8mTihMwvM=; b=SvWoCeL06d1SlIDv1a0KC+gKil2BA5/xV87zCZynMqUMCqcLI29B3MRQbsHaZza2S8 r5ssU1DdWEXqJhsm9TvIDw7jYIl/Uawvlgv82smTrvRAq0kUrVVCnKt359JfdHO3ZAYZ ZuGPeSQUvVpmSYCLJx1snPqdWBEC0lGW3HrpftP7s29ms5sxJRQjOc7wH9cmw7+BcDMO vAWb9unAhYNnatP7kTlYyhtVXKXLe5vN+w+OH1gINl04LP5HEEs6EmXIOLxf6IKIDofL qIiEK8DptUGH37JWiCiXACTM9GWLRL6QKpvj7CXJ9gLMHtm8awuVwPFKl/VlFqThC8F7 mvgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737745989; x=1738350789; 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=SDJQfkF7TGyKUeThCnNUPt37lNu38uEocV8mTihMwvM=; b=OyWT4J3h2f/3ipcz0wQzhbrpLIp+rbjxiPOglcabVzAF1lyumLIctI2FpNSkjPeWMG Ro1CDp6Php8FBqQmZ/bvNYnvzggzKWSXfUWd7xgN/SVIdkR31xQ3+wxCGjQupmOJzAEp uiJxtYtcvwsn1phCGIqZrxt3K1If69FswyheSA0iWL/Rj3R4K5Zn4eJJ5XBSMhKLF6Ll MYyIiKGARDSvTPPqBqUapLRdCvKZGkavKp9TZqaCAyd0KZqfBnC6gP/5af3CmeKkpNAI V5KMF5uuhoE/A5fLzty6n4liY9Vbslf3TfA29Is1N4IGvQHpO4uO+VOCI9b4fEDNoVp1 +zxg== X-Gm-Message-State: AOJu0Yxzg4vnTnM5paBGsd/mmN4bni2jqREaBx5nHpdRvGS/qFaQU6ht fz7IInpaHsebOhNyEGnOBdDZdPY+a6+IppXP7iJlIvgRyGpp45E= X-Gm-Gg: ASbGncsjEKAOFqMw9hhB7+eQR1kF0vIw+LhBdPQoM+pGFpnzjo+i79yrboa95YA35ru xQ21R3+hVX/uiUGXCx1tpdnmSh1iTwReAE55Xe5TUQN7E6rSuZtH5XpVSCw6TdgehJ24kSv1jIq J1UgquJ+WE5CLsYNDuhOVuWTPvfzi0qLiVnQ/mwZRHPF26a9f5cjQjOBXBDrQCpcNjd7/6rz9vf /o4MJ0S3L9hbuLu+OEzpF+eY1yW5makJnNw5XziV7C52JfMcOi3xx7J21YWRZKDnrFeeJH3FC0U 2QYBWCY5Q+kbNz9pYQ== X-Google-Smtp-Source: AGHT+IFGuQi8+35i/rdlovFxz/fClmwbTUlny/0LqGXdE83kVUnBvq5mdSUWxHsDqq/vLXZ5s5owdg== X-Received: by 2002:a05:6a00:811:b0:72a:a7a4:b641 with SMTP id d2e1a72fcca58-72dafb71a28mr50515742b3a.18.1737745989352; Fri, 24 Jan 2025 11:13:09 -0800 (PST) Received: from localhost.localdomain ([58.37.175.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72f8a69eb75sm2318406b3a.12.2025.01.24.11.13.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 11:13:09 -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 v2 5/5] vfio/igd: handle x-igd-opregion in vfio_probe_igd_config_quirk() Date: Sat, 25 Jan 2025 03:12:45 +0800 Message-ID: <20250124191245.12464-6-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250124191245.12464-1-tomitamoeko@gmail.com> References: <20250124191245.12464-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1042; envelope-from=tomitamoeko@gmail.com; helo=mail-pj1-x1042.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, T_SCC_BODY_TEXT_LINE=-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 Both enable opregion option (x-igd-opregion) and legacy mode require setting up OpRegion copy for IGD devices. Move x-igd-opregion handler in vfio_realize() to vfio_probe_igd_config_quirk() to elimate duplicate code. Finally we moved all the IGD-related code into igd.c. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 143 +++++++++++++++++++++++++++++++++---------- hw/vfio/pci-quirks.c | 50 --------------- hw/vfio/pci.c | 25 -------- hw/vfio/pci.h | 4 -- 4 files changed, 110 insertions(+), 112 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 6e06dd774a..015beacf5f 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,55 @@ 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; +} + /* * 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,29 +389,83 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, bdsm_quirk, next); } +static bool vfio_igd_try_enable_opregion(VFIOPCIDevice *vdev, Error **errp) +{ + g_autofree struct vfio_region_info *opregion = NULL; + int ret; + + /* + * Hotplugging is not supprted for both opregion access and legacy mode. + * For legacy mode, we also need to mark the ROM failed. + */ + if (vdev->pdev.qdev.hotplugged) { + vdev->rom_read_failed = true; + 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; +} + bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, - Error **errp G_GNUC_UNUSED) + Error **errp) { 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; + PCIBus *bus; PCIDevice *lpc_bridge; int ret, gen; + bool legacy_mode, enable_opregion; uint64_t gms_size; uint64_t *bdsm_size; uint32_t gmch; Error *err = NULL; + if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) || + !vfio_is_vga(vdev)) { + return true; + } + /* * 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))) { + bus = pci_device_root_bus(&vdev->pdev); + legacy_mode = (&vdev->pdev == pci_find_device(bus, 0, PCI_DEVFN(0x2, 0))); + enable_opregion = (vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION); + + if (!enable_opregion && !legacy_mode) { + return true; + } + + if (!vfio_igd_try_enable_opregion(vdev, &err)) { + if (enable_opregion) { + error_propagate(errp, err); + return false; + } else if (legacy_mode) { + error_append_hint(&err, "IGD legacy mode disabled\n"); + error_report_err(err); + return true; + } + } + + if (!legacy_mode) { return true; } @@ -404,30 +508,10 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, return true; } - /* - * Ignore the hotplug corner case, mark the ROM failed, 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; - return true; - } - /* * 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 true; - } - 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); @@ -476,13 +560,6 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, return true; } - /* 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 true; - } - /* * 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 diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c index b8379cb512..f2b37910f0 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 e624ae56c4..1b90c78c5a 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3136,31 +3136,6 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) vfio_bar_quirk_setup(vdev, i); } - 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)) { - goto out_unset_idev; - } - } - /* QEMU emulates all of MSI & MSIX */ if (pdev->cap_present & QEMU_PCI_CAP_MSIX) { memset(vdev->emulated_config_bits + pdev->msix_cap, 0xff, diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 5c64de0270..b9e920a6b4 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -229,10 +229,6 @@ int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev, bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp); -bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, - struct vfio_region_info *info, - Error **errp); - void vfio_display_reset(VFIOPCIDevice *vdev); bool vfio_display_probe(VFIOPCIDevice *vdev, Error **errp); void vfio_display_finalize(VFIOPCIDevice *vdev);