From patchwork Mon Mar 3 17:52:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13999325 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 F0A86C282CD for ; Mon, 3 Mar 2025 17:53:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tp9yP-0001c9-C7; Mon, 03 Mar 2025 12:53:02 -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 1tp9xy-0001XE-0h for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:34 -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 1tp9xu-0000Fn-EO for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:33 -0500 Received: by mail-pl1-x643.google.com with SMTP id d9443c01a7336-22349dc31bcso83160835ad.3 for ; Mon, 03 Mar 2025 09:52:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741024349; x=1741629149; 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=pXjnzMdFRw8UN/BnZINokoDYNlgpPuyWmsHQdzmGGak=; b=NgFvlMJ6LuUQJ5HwSX2ZS9mufxTs6s7P2o1ia93TPQ2fqRTe1bt1BaAgj5vyKDtCMd awsotk98ySEqwcFqOVFbt4Wp5IerlXPKIOidbCvw/LEwklBx1yoRMOKgdmj8ZTiyvLQt CS+AYB4ucqkIWmbsq6YcHoSvIyNyOfcR36qSCLtoMNJYZC1guusOPttvb9/QXoGe3RGl dykDs2Dc2ftAGBmjPUn+LgrTP9Z0cVnNgowjChvnO6GWbb2TlYZ/S7bBuL422SOwMXzC ub1cGCQyyCa9fvbRxBOJLYyttS7fqjKSDHTP+lqbB1dWS0pBHtfSr8MSFYSphbIdklnc rEUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741024349; x=1741629149; 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=pXjnzMdFRw8UN/BnZINokoDYNlgpPuyWmsHQdzmGGak=; b=hyDyEfwp69e4AKtgjq37uV8+B5iVsbB3drvBG/FMI3iiwWl9AO02eB7QTQDLNLfJiL 5gQnWdmmwj827yjKLOnK+/GWoJVrUjRJXKWE+xKjz2G5TzD89bCeqbJ1BY1R9rx2GQpc WrdSdVVRI4Hz0t7PRlGPnMCBYPSsyUNoFZFYeBSzGppY4lPNIvSOTwfp2uTJMOEMPFbD IAIhGp2nyjbnT2hM5jrmxOjm7LhTm9hLYN1smfTTOKakjWgDynDnxAjW0YfeQMozkfpL V4WR6lgdnLAt/QZKipiTmIeVNmfkSo/PW4iqC5dTTZrnkCI5L39PYZF2V6h+c/Kd55Kx ks+g== X-Gm-Message-State: AOJu0Yyq1QcOkOvs5V4IxguK0bUfjG1ROJpwmVcw/Bvl0wY/SGc8Zen8 biZzsry74GyYJAYHPMJOBT7I3y2qES/GqsEQ+0FIXo0FceBkg8L/J1xpheTwaw== X-Gm-Gg: ASbGncu9+U9G3AapadOqwdi2xtAGe+sffjUr1UtHnbisaz6EzvYZpTjA6RfXhe/bySF QZWoLvqPqk4GI8Zx+t6wzq8jdbYMG6dPj1W0GthIRpyNfo0H1uSCNIc09YuXZShx+pge18oFxYm STNf6Y4Q9+xW1koiGknlQuNQ1o9DaET6HGxObn+6bmZs3eAMw3HmbzyurvfdUONjSThsyDZLRFW pW9yr4vjKoxO6eSjsIkVes2mbsffVOltVE94UvCQY753L99MS5RYjHXreNVRgoGrA7eeiYr2ViE 04KO7LAQmOoHYKwaTsdl7yeRun/WJMAeArfNsmQBIbgj7nQF2vocMYTlYA== X-Google-Smtp-Source: AGHT+IG6b74gWBuO9Sfau4/2npqudg3LNyonzc+EjX5ifkJ/9xK41WA/l7POvGgXTkaAALpXdGfCtQ== X-Received: by 2002:a17:903:3b83:b0:21f:4c8b:c511 with SMTP id d9443c01a7336-22369213d7cmr179930055ad.33.1741024348375; Mon, 03 Mar 2025 09:52:28 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2235052beaasm80625535ad.233.2025.03.03.09.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 09:52:27 -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, =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v2 1/9] vfio/igd: Remove GTT write quirk in IO BAR 4 Date: Tue, 4 Mar 2025 01:52:11 +0800 Message-ID: <20250303175220.74917-2-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250303175220.74917-1-tomitamoeko@gmail.com> References: <20250303175220.74917-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 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 Mon Mar 3 17:52:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13999324 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 33C2DC282CD for ; Mon, 3 Mar 2025 17:53:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tp9y7-0001YM-BP; Mon, 03 Mar 2025 12:52:45 -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 1tp9xy-0001XF-Bw for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:35 -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 1tp9xw-0000GK-CR for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:34 -0500 Received: by mail-pl1-x642.google.com with SMTP id d9443c01a7336-2239c066347so32359345ad.2 for ; Mon, 03 Mar 2025 09:52:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741024350; x=1741629150; 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=KXWyWSWbstX4BDEogXLQAUo8x582HzkrIWuWYvz0zsH9E7XBqnNazeumGHGM0iwZYU O78VMEpSMPZR3uP5GRAD1Sz0GPOlTToHtS9fIzLxj/XwNuGG6aF+CosnpltRXYcc3zU+ eg315rnRRLkfx0ZkPV/l3ThxX8wAdjXtNXzBnG3NKI694E9dTxCl/bL3DoZ2MNPPSBrR OGeZ1jvzaS/S7Zx7Y0xlnI/BqqTsFsakLtwLTMaMYicRMQgNUWw3S7Kyy0AgURWRTAoi Yy0+UOmluMjYuhDsyQEIU93InzSsrQzbBoPL9tOCvum/zcCtbwIv8aJwdfC186j3ZVI6 8u6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741024350; x=1741629150; 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=BdOdFsxpQhJIuAtR4fnGRko4YO8K7JqK0qn3r0dWtdgo/3zEs3U+lEDhLrXg1O4GUl 6bjaqJ9+DHTSwaZAARgyJiX8WywalpsG6rziMASRZTjgT8YCTKNf8winY4ZDUP7PD4/k qeHYHQBMWLJan3ZYAFYxJmUleskvoT+rmt5h/yIijgLxlPBeXS3oWfDrhsV72MZZ19Jl 74xLDU/83NRoA5oG6g5b77sQ90UBBXZ1fRQCHOTvW21RH2VCKA6dWO/qwXW/nohxAte+ f9yR9876Ew3d9oFRq3rUzJr30rZoNR+scW2fP47CQHFSQxHJ3LA3lprqcq3auQh3ZiPu frlA== X-Gm-Message-State: AOJu0YwmINn08rH2AjcqOiLDSZPU6OWIqiuiDRBZ+ynSGY0/fZaMYSjE 76DymJ/gJkYXc9uIwYRAC2A8huPqrJZPrCRS6Q5bM/bTTnTOZt8= X-Gm-Gg: ASbGncs2Iv2O6CsNvu/v9O6fbFcGKX/Xj08iSODBRY5T+t+Gb3EIj/yh91E+Nm6lgVW lVc1HKpvQ77UYB/4FajUA4CDxSbI71Ygj60ZmseD7yLTEubWgTP726WXrj9TAzmvO3wEoE17Z4W PGIyZ5fBPi6jra+WLitsDia63rhoNU9ym+3ydB7E0Jf2cxSYsE2ehKshpwXS30aQ1Ngj+BuKeOF U9xGlMYcWLAjhE4KDNYdUgXcugh9kk+FgD1BBRmuQJPzUhoYiDkMnmXQLt3E1uOboel+T2LbGG6 zTczj5VOrel0LvjHgIipoy9Sm46rylWhwRV6tfkmXw4Y6dSmftTkVsD7Zw== X-Google-Smtp-Source: AGHT+IGQZlUVzjR0TL2Y57P3Bh2O/3804iFF32DUopsZT6Ot8yQnpLZ91aEJ5mClDd+9bASOSxAyKw== X-Received: by 2002:a17:902:fc45:b0:21f:5638:2d8 with SMTP id d9443c01a7336-22369267243mr239876645ad.53.1741024350637; Mon, 03 Mar 2025 09:52:30 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2235052beaasm80625535ad.233.2025.03.03.09.52.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 09:52:30 -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, =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v2 2/9] vfio/igd: Do not include GTT stolen size in etc/igd-bdsm-size Date: Tue, 4 Mar 2025 01:52:12 +0800 Message-ID: <20250303175220.74917-3-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250303175220.74917-1-tomitamoeko@gmail.com> References: <20250303175220.74917-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 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 Mar 3 17:52:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13999326 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 CEA47C282CD for ; Mon, 3 Mar 2025 17:53:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tp9yd-0001lf-0v; Mon, 03 Mar 2025 12:53:20 -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 1tp9y1-0001Xu-LO for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:37 -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 1tp9xz-0000HS-8t for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:37 -0500 Received: by mail-pl1-x642.google.com with SMTP id d9443c01a7336-2232aead377so92527635ad.0 for ; Mon, 03 Mar 2025 09:52:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741024353; x=1741629153; 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=stCgZpQtE1zFYYbrS3BPR9VSrLJmwkhXSnn+AFxTDO4=; b=iwfcgLtu/3B0ZlH1VAKscfJhy7LNQHxOAOunZto2bSs1Pz9jOMnt01qP8nTJAFewOx T27UjctJNWkBdPHTisCb7KhznpeQ03P0yOoPpsJ4jSr8tz3QTX/X2seppe90D3uetV/5 WyiBm0JHea3AoQqlJK1WsC9icN9Q9ZxpYwggj5T2c3iRdT4eRu41LOne1pPXe/AJL3Vs nql0rkriQMfkHFgBPnaAbtZBI4oo86wLBacNbT97lNEVCBXfjwD/E/JRnpZTP7Z2w1Tg MXIcemMn5YBQVIrjO4ymTUh0vhAGmBetdNZs2LoAzuxC71ezHrt+nbicBa3Nbd7gbtzH 3LAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741024353; x=1741629153; 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=stCgZpQtE1zFYYbrS3BPR9VSrLJmwkhXSnn+AFxTDO4=; b=E4uPj5MuzVnXlCqvZo7C2RwullJTPv2yhnBQTZeeLXvLZqxY+tRIPzhm3UJX245cht FeXmTrq7KNgwFNFuJ8JiXfWUCX9g5Y1psOqUVQIkk6c42NDNG4uGY+u/HYuLNWAV7qkg +J3dUvLUeuElnrkyvmC3Ru/p10Zq+QDwkW9IZVbF3fa3vnrgTCRpR7110gypwYyHLzc2 1xpwIxUyacTxVv5kCAsW8pp78Ttsk8tQtXpO0fbehNMKvZ65U5NqXzTyGG/1eqaoIzpg RU+qaKkU8FSZUgch5e+FlUaYhR8TWSiFaWvAqOo0PMEvn/idb4W82LbX3ZRr1SfbXZat vwcA== X-Gm-Message-State: AOJu0Yz2W8OLY+23SrpGinic6RmCIUdC0St3b2NDgjm2QhIX5e8Ayfnw j/4qu/FwYY3ogW4gp8X5N+x3R8jk+FDaDiYdg+7Jf5DE4l5CU/fzTBEmI4dBVQ== X-Gm-Gg: ASbGncvl6VQEpkWwDV8Y2qA8Dp4v4ZDY5h171zxCl9qkpZBLql1+HUyqFDQcjzdcn3L D1uhk4/VHSbrS1cfxz6LWbUbmhlH+flxNH8Zs32gn9uHUefC+vpWjF8I0iKSkyCcazTybfC3zl0 ST1PJMxuAr38x/L/ATRHaFzM6VtulmAyF3/bh0QQ9SrBGDbyjD8UO4xPFI8BvdmruA/OUBHPUUt tLSSAPknlrFCjDCX18de5JdrHuytt/WsXZMwQw08Gx3qCl7GAKJrIBQZWYyJjt5B5wTkrbgrWU2 nmmnLr9prdr0wkQok4arvcFvht24kVXaO7j4s4ulO8HI1lb4KROZvSiyAQ== X-Google-Smtp-Source: AGHT+IF+4SaH7e2pbBSFJ1vhuCRdNvyj8fbVonPc23OhblTAYK2tNkN60qGNdkwWf1AjE88A3k6YNg== X-Received: by 2002:a17:902:e74f:b0:223:8256:533d with SMTP id d9443c01a7336-2238256592emr164541385ad.46.1741024352774; Mon, 03 Mar 2025 09:52:32 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2235052beaasm80625535ad.233.2025.03.03.09.52.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 09:52:32 -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, =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v2 3/9] vfio/igd: Consolidate OpRegion initialization into a single function Date: Tue, 4 Mar 2025 01:52:13 +0800 Message-ID: <20250303175220.74917-4-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250303175220.74917-1-tomitamoeko@gmail.com> References: <20250303175220.74917-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 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 after we decouple it from 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 | 101 +++++++++++++++++++++++++++++++++++-------- hw/vfio/pci-quirks.c | 50 --------------------- hw/vfio/pci.c | 22 ++-------- hw/vfio/pci.h | 4 +- 4 files changed, 88 insertions(+), 89 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index dda4c7bb5d..50e4007abe 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 @@ -342,7 +419,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; PCIDevice *lpc_bridge; @@ -418,15 +494,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) * 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); @@ -459,6 +526,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) { @@ -475,13 +549,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; - } - /* * 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 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 89d900e9cf..098d17b866 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 43c166680a..4763f14415 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -228,9 +228,7 @@ 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); +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 Mar 3 17:52:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13999338 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 87FDAC282CD for ; Mon, 3 Mar 2025 17:59:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tp9zK-0002op-VU; Mon, 03 Mar 2025 12:53:59 -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 1tp9y5-0001Yg-NO for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:45 -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 1tp9y3-0000J9-B5 for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:41 -0500 Received: by mail-pl1-x641.google.com with SMTP id d9443c01a7336-223959039f4so37462555ad.3 for ; Mon, 03 Mar 2025 09:52:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741024355; x=1741629155; 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=Mvd2byRBLj1EWurRow3kwEAQYrHkAuspw1kE35aVtA8=; b=VDAmKuNOpzN/vJn2ayzVCQ88IcFj2JcXtGGr4INrMZCQdmrHfHw+pheAJx7mW8/Ulb du8io2ChfASk0xDX9xynewaQNa9LqwGCYzLbb8t/MH5HZf5/Udn6QGYDWEmc867eWctZ FTzsVKzZ036FKNpkWmR8BI9P0HltW8j6XnpluWhmzOkDmk5Fi0q0kMHxNGpMtRoJcbyd QpUzV5JhXs2GS32aWstqlIesL6WNdC/jBXZrhC5LiczP6v5cODyfQ71COrf9JdV0b549 NwXq9k3GF1FIm3rlpmyqYu+HCwjBjL6/vUQ1TEfOomm3J0yaPqpIbZHYHoajd98L/1t/ V5/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741024355; x=1741629155; 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=Mvd2byRBLj1EWurRow3kwEAQYrHkAuspw1kE35aVtA8=; b=EQ+V96d5LJvgf6hlrjkfbqppDierW2q1X8C1nl7Q39BOd31D1kbtFzTAq22Sliiv/4 K47powPK88JdMpwkIkpZR/IxMlw3jQchHjEOAMgIUNFt5IaLSG7qIlVQwBqxpJn8mDUs Ybm+GljoRncPDssw75qFe6P/wM4Bf1IpXX3OIur6iGysh/eKu6knzv15aNKm0bTuf+P4 aGhgNx9cpx9Cz4slxIpclE0LUf7QFH5Gpxi4IaBOU3A/CB6TIbk3RcAaOrtkv2LUvpsc dCeVeYuwEx2T/VS9QuVD2uJdNEzHzgAQwEPZs6SoR2hqkd73zOMuzdCfSY9EVGAOffL3 wpUw== X-Gm-Message-State: AOJu0Yx2dspGfq9CmtlsFruiS+YQJsbmWFOVNi5VRf3IxFOcHdIIFA32 gV2H76A9/8VeU51Wc+97W4PrN+mtiTmAcz5gTfBcC/0SxSQ2IrAfmutsit6ylA== X-Gm-Gg: ASbGncuwUAq5N2o6fGP09DKkcsGaGoeKvCgMBp1mCGyubNcaOAWJLH0hUbpB4RJaDTr MdekuWQjmJD64jd0BtuI5N5so7e/UN8JQ2U+r6VdK+HkLUb8A7APxvFC9dbcCb7boAzRjrj+86v RQH4OZ9eNPcK5U6R5nO4H4fVRIlj0lWIZD4oSbFXxpHPvdF60DFwFvbFmka0NY7nQb/Z3u0zkx0 AjnDlSI3rXa0UkxQXIkti+ziPfO+PFlHEcALaBTB2R1v9EBMdvoAOLgigzyVben2qg6dA/c3JWM IHQsb56pu/C/OSwBUnIak+XMHCnz0lWH04xfqS20uPXgrhs/tfAKMwRHiw== X-Google-Smtp-Source: AGHT+IHzJS1tsyugZrX3KjEkCdkosAbjgjnSWifoNETh+SRLwxEZa6eyhUAm66s4d1YAjuq7ABk6NA== X-Received: by 2002:a17:902:c951:b0:21c:1140:136c with SMTP id d9443c01a7336-22368f6a15cmr200767725ad.3.1741024355016; Mon, 03 Mar 2025 09:52:35 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2235052beaasm80625535ad.233.2025.03.03.09.52.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 09:52:34 -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, =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v2 4/9] vfio/igd: Move LPC bridge initialization to a separate function Date: Tue, 4 Mar 2025 01:52:14 +0800 Message-ID: <20250303175220.74917-5-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250303175220.74917-1-tomitamoeko@gmail.com> References: <20250303175220.74917-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 decouple the LPC bridge/Host bridge ID quirk from legacy mode. To prepare for this, move the LPC bridge initialization into a separate function. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 122 +++++++++++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 52 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 50e4007abe..9d2b761d1d 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,9 +485,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 *host = NULL; - g_autofree struct vfio_region_info *lpc = NULL; - PCIDevice *lpc_bridge; int ret, gen; uint64_t gms_size; uint64_t *bdsm_size; @@ -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 @@ -490,28 +539,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; - } - gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4); /* @@ -533,19 +560,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 Mar 3 17:52:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13999327 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 CA1A7C282D1 for ; Mon, 3 Mar 2025 17:54:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tp9zJ-0002cS-NX; Mon, 03 Mar 2025 12:53:58 -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 1tp9y5-0001Yf-Ns for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:45 -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 1tp9y3-0000JK-BN for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:40 -0500 Received: by mail-pl1-x641.google.com with SMTP id d9443c01a7336-22337bc9ac3so90497395ad.1 for ; Mon, 03 Mar 2025 09:52:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741024357; x=1741629157; 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=3PsFwF/uA/8VpOdWLdhwbP0WWGdT9opuyryY51WuBZk=; b=GaoYSHl8YH5sx3hldunstBhn1c9LcWwRwo+muuhujMQ3X5pWSAZ/y/sc/gdTvosOzr Q+GQN+ja2IlVxxp345TnMK0VwNlgABLUl1fTrJhf0taywyy3iueC3zJ+wOId+pMMaAcD V38IhoTl6t8WYV/JcykvuU1WA8qSOs+qClBi8LPb0jCDCoe6mK1wq8jJLRC9WWn32B7k XMKs/fnc4bRg5a3D/7pFtHUIy9tEEljKhzXG0wW59KnT8J+sFAd3ICfrX+vjCus1ITeK +8bIHFV68jxCxpCbUcQvo24MFpgx+NFT5KDCkl6OTnc492r1HlTFVcPfIxoKI9AnPlqE YBJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741024357; x=1741629157; 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=3PsFwF/uA/8VpOdWLdhwbP0WWGdT9opuyryY51WuBZk=; b=qm37mDV3r7nqwRDYKXroAjcC1tOqjh+JIPxmleVJhvgpukNGh9BNAKK5t1EHrVqhe4 KeaKiW54oHP1vSWa1OWiyAwHOseI5FHAWYAE04tEQZ6Kh9YLcKdVLOaV+WFVyZPl+wmM /cWs+pLHQVaaRqKwzJHKt6VcmhvBU46oGGkgrAURF/Bt6hHemBlPbQhp9E2yRUi/iMGI Ifx2P9CdJgn/uWW7kuNI0vRRp7TokbHHbiVzfOWb0nm8yCuY4UV1GsiyZ2KHvwkaBjaf 3fde47ioxwUSbMSBaNCk9QKhuLTp3p4raHInw+GwNmRzNJlA97ZrHOtFODIQism8/ya2 IG1g== X-Gm-Message-State: AOJu0YzLah26+pa2dUL7B2LjapKqnLywTBZtg9ChQ7PhuEqai3+0OfAL CNtLiEKLyx+NejRS/3nLpkg7D+vrOkRvfBSs+k9YuTM7pCrrA/Rp9GY73sbpwA== X-Gm-Gg: ASbGncv79TP9ydnzhbd35PoUMb3Zer7vor/uAJQ5d9hF82voBNatEh/8wj3QZLg+SAN 5XPy4m2E4S9UExjBjvaiioX1r9NcFq9f+0VlqylJDkIel0LjzKD9gFQ54sbvk4lMHz0U+mKplCf XBclxNR1CZSulFQMVPK9OYsmBDFsQnIKj9NY+RoIu/fpv/f3N+pr8f0J6mc+Mz4P0OIQ4sZgkrU oJX++95YzVmuHseyxayOEHlV1/PQ5hY06C96sm234FYFT8k79HdPjHUM6EFzfsaVxdBlPdZv7Wo VqJ0/RDVh8azQdrpQqR0vjn1q0UhaCoXH2c2T2eLS8gI9n4HfbnhhQLZaQ== X-Google-Smtp-Source: AGHT+IGQsYfDOHGKlxTZnE/Hu7buARQmXlAycvBJpyzVTV3/Ece5PYqf/vXkHjkwPwCway89BHv1vg== X-Received: by 2002:a17:902:e80e:b0:223:5645:8e26 with SMTP id d9443c01a7336-22368f9590amr202838125ad.20.1741024357545; Mon, 03 Mar 2025 09:52:37 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2235052beaasm80625535ad.233.2025.03.03.09.52.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 09:52:36 -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, =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v2 5/9] vfio/pci: Add placeholder for device-specific config space quirks Date: Tue, 4 Mar 2025 01:52:15 +0800 Message-ID: <20250303175220.74917-6-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250303175220.74917-1-tomitamoeko@gmail.com> References: <20250303175220.74917-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 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 098d17b866..a58d555934 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 4763f14415..d54e43764b 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 Mar 3 17:52:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13999329 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 7FB62C282CD for ; Mon, 3 Mar 2025 17:54:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tp9yn-0001rB-0O; Mon, 03 Mar 2025 12:53:30 -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 1tp9y7-0001Yw-Ml for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:45 -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 1tp9y5-0000Je-IA for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:43 -0500 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-219f8263ae0so88091815ad.0 for ; Mon, 03 Mar 2025 09:52:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741024360; x=1741629160; 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=vFnj8MBzKLQ8mFbTFO8nM18EwA6rKViM/nHJPBpmhqc=; b=HuEeNi1ZSZ9Faz2M+RD74ZdW6TPZngZEA7uoKEvwk9mModyA80jKkzRSPOxo5Wm44S iKDr78kFCP1vylrOnHEIXXLCemhnRntXbbAA3T262Qkm1uAwjcVi+axmUlO9Qr/TACP+ tQMGz1+qT6azM7CBSjuhHizC/tC2SAwVzxOcLT2B5qkU9cygBTzcAXVfv83BusQ0ZSHg Otc2byusev7IG6H2DBIxfdjge3vhScp1dxlqwoc+ZN+e26u8PkhWzCZjtOcCYXa2FG/w AI56DTLH91BgQoFUwoK97fvxz0p7YyoP88iwqJ+iXG2AvtJvdkYGqAwazdqNR9O1Qk/5 9sZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741024360; x=1741629160; 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=vFnj8MBzKLQ8mFbTFO8nM18EwA6rKViM/nHJPBpmhqc=; b=UJjmlyUsFPpkzbrLcAwqtJBes5lA/vcF9qJXWJ9LOu8rfbsg97kSFUvJiRMFiea60A 4BqEiDUr0cdDOKkwv1ge0l7cxCzhkvk+3tJ3m42O5WGAUlORfu6yumCvjhUJJa0usveB Of9P7VOd+6KNpGi+n7VVkjtUbAtDaQRAy1QBMDkSlAuBPxZ8qFdRtCooxjs9vMO0vtjK miW24APE4xXlMFhWQyJdHG38yKENC6udW72kYx4nRTfv9Ofzaz9DC1kFzFqS2xlsISUl gGkh5BMWAdz2vx0xfC8/qkuBJ2g+jINSonRSAYoVlyW1U0ZEtU/wBkr5D0eWPSB0S/Nl EOIw== X-Gm-Message-State: AOJu0Yy1MOkiSF4kISNLoYI2u1ueMQCa6VI1h00U++Ih8Om9V3ZSgVjK Qm9yX1mkIxvYt1d6HmN2b9vmG6MJqTezw9u3dI/D82VzJgMZm78j16RSmUdHXg== X-Gm-Gg: ASbGnctEO5xj8cX2OhpyeZMVWwzg3X1ExMTo5+3OhPhYVAgvlntFwh+N/vdN+GnZvRs BSydpNjyGEsvJ85tizzAQNrahZ39+Gx545J7NNLfG4yx/CAmdzzDzXfgHvrf6CRTxS9Xt4AMb2a GjLuj89sgsYkTJwAje8M8Ct2Y1sIEGyG6TgHva8nXZ/DNyVJv6MuTsZFBo1EfitUrpg8u5trSkD ofdCboAFPOC5dKc391MeeNERrJ9nLDPx3e0nSrFdy4j7M5zjLCZFP9eP0Qy6n23ZP72yhPFsSvt lxIvvZoPOk9HnGJUNWXb7Jbc22yd+jxZfjLmHJslryWOejvxEAeOhaZ5UQ== X-Google-Smtp-Source: AGHT+IEq3+gQX8xDaHuG0rjLnBsDZnZW99VU+sJe2NR5Jl85DurYY+iQxfdUaOT/uUkQds+sHHjXiA== X-Received: by 2002:a17:902:ecd0:b0:223:3396:15e8 with SMTP id d9443c01a7336-22368f95a5cmr242810205ad.22.1741024359871; Mon, 03 Mar 2025 09:52:39 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2235052beaasm80625535ad.233.2025.03.03.09.52.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 09:52:39 -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, =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v2 6/9] vfio/igd: Refactor vfio_probe_igd_bar4_quirk into pci config quirk Date: Tue, 4 Mar 2025 01:52:16 +0800 Message-ID: <20250303175220.74917-7-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250303175220.74917-1-tomitamoeko@gmail.com> References: <20250303175220.74917-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 decoupling the quirks from legacy mode. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 21 ++++++++++++--------- hw/vfio/pci-quirks.c | 6 +++++- hw/vfio/pci.h | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 9d2b761d1d..f5e19f1241 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -482,7 +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) { g_autofree struct vfio_region_info *rom = NULL; int ret, gen; @@ -497,10 +498,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,7 +513,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; } /* @@ -525,7 +526,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; } /* @@ -536,7 +537,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; } gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4); @@ -550,21 +551,21 @@ 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; } /* 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; } /* @@ -624,4 +625,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 d54e43764b..2e81f9eb19 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 Mar 3 17:52:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13999337 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 8C460C282CD for ; Mon, 3 Mar 2025 17:58:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tp9zK-0002ie-9b; Mon, 03 Mar 2025 12:53:58 -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 1tp9y9-0001aA-MV for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:51 -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 1tp9y7-0000K7-EC for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:45 -0500 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-2234bec7192so71439275ad.2 for ; Mon, 03 Mar 2025 09:52:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741024362; x=1741629162; 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=ypBKTzocjelNd1zk+Kq7I1Qv1eqMSc9ppcbAV4fLn6U=; b=AI4zCAw85SNSV7bNJ6UX3RP4F887rOwjXg34wb+UYT7oou7rMUJRjqO4Nb3SUx7pzC v/iFDZhAb5aGyZPrKIAhvMOCyK50USRD0xcFeMI9j0+jiCc3TkeILAlPB3NR3mM3W7Du 6AmmJffy1EJCfQJ5nx7iPbgYx0uTJt2hzpSoDGp6Wcc4GZB0BDSsVDS7EchmBQzGLHUZ nerofosU4AgV9yjaRT+MprUEDY/EBGizoZ62+N5yuI/4wp3QTVlkphZsbV8qe1OxWq3b jrx9enKtK/psoz92lgMjlp0Jw1gIisdmK6t4sjvzphfmVmxZMQmNkt23o7n6g8cD3wV1 0njQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741024362; x=1741629162; 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=ypBKTzocjelNd1zk+Kq7I1Qv1eqMSc9ppcbAV4fLn6U=; b=NxV+ucydVn83Nq6tmzgYscspy0o2xzIAjTYBYD8SMOK5/CgULdnZ3FNEJqYO9ETbfp yERBCodUm5cCJCq9QWRrKG/80ckeU5FK7jmtdqa32yM1+bvdhMWMyOk4pCUtELMi2jS6 d/AEZiFpqsTWXFaVAYawVg4KqarShrx8al0aKjO3YUnSvSDVSltwCpxMZ2h8LtBngAdA NFrJb1a0O8yi3jMlnN5NkI3VMlCVOLsJpxtEKAkLWAzN5AoCdu44q4VjRdgty0U1HpRm tFh58PtHYm76/5pH/ifFwNnAVzd+sq12l+96UThRrvVei8DftKw6zww+cRV6zp10xxlH zx5w== X-Gm-Message-State: AOJu0YyTOI3nKEMOPlDglYo3nF70aoVcdVCw3a/HwcJARFM9n2V5lTht qH1VyXLRDeGRjjFx6acuuaMRE6xfcva7Ja0graLaf0lIabn/feQ= X-Gm-Gg: ASbGncuTdBdJbk+ZBWVYvLgL6yALM0d8ZnU/KkT+/Kd9BrC2Cu3gZU2iYyN2n7CECHi eGOP7vpBS2xLVCNWAI7BJiEV9XIgUfA184I7sfV4Sx/IzAEQLB+xl4tE7/sphWchBjqroYXqYIw ZGWXds6eSKLUwkoY4fIpcwRigUeDtRRimVTZJ2cq86mqfYpPkO8XarzOaOXmLamqZVAf8pwp74G UbDBa3si1Lld8O/N7xUx042CMTiCvQfpVOFiU9ij7qzCLn3zydC1v3KA19fC6YT020OaE5bWNIv j5qvEjx0YgHPtsLlC4ZKIGDdYVkG0bmMQS/iF4SwyVCFZOqulFbm4CAz+w== X-Google-Smtp-Source: AGHT+IHdB2eTDWixMyLLdhk2WhA3vX//+QRGtGh632k+IoYI7+y5yfrJVP5H1fxLJQcAoekVQU7i5g== X-Received: by 2002:a17:903:1252:b0:223:26da:4b6f with SMTP id d9443c01a7336-22368f74891mr234558535ad.14.1741024361980; Mon, 03 Mar 2025 09:52:41 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2235052beaasm80625535ad.233.2025.03.03.09.52.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 09:52:41 -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, =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v2 7/9] vfio/igd: Decouple common quirks from legacy mode Date: Tue, 4 Mar 2025 01:52:17 +0800 Message-ID: <20250303175220.74917-8-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250303175220.74917-1-tomitamoeko@gmail.com> References: <20250303175220.74917-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 So far, IGD-specific quirks all require enabling legacy mode, which is toggled by assigning IGD to 00:02.0. However, some quirks, like the BDSM and GGC register quirks, should be applied to all supported IGD devices. A new feature bit, VFIO_FEATURE_ENABLE_IGD_LEGACY_MODE, is introduced to control the legacy mode only quirks. To maintain backward compatibilty, this bit is set by default, but legacy mode is only enabled when: - Machine type is i440fx - IGD device is at guest BDF 00:02.0 - Not manually disabled by x-igd-legacy-mode=off Note that QEMU will now fail immediately if any error occurs when setting up legacy mode, instead of simply continues like before. If legacy mode is unwanted, it can be explicitly disabled by x-igd-legacy-mode=off. Additionally, the hotplug check in legacy mode is removed as it will be checked when enabling the OpRegion quirk. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 108 +++++++++++++++++++++++++------------------------- hw/vfio/pci.c | 2 + hw/vfio/pci.h | 3 ++ 3 files changed, 59 insertions(+), 54 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index f5e19f1241..40f5803be9 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -15,6 +15,7 @@ #include "qemu/error-report.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" +#include "hw/boards.h" #include "hw/hw.h" #include "hw/nvram/fw_cfg.h" #include "pci.h" @@ -432,9 +433,7 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) * 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,15 +481,12 @@ 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) { - g_autofree struct vfio_region_info *rom = NULL; int ret, 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 @@ -498,9 +494,7 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, * 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; } @@ -516,56 +510,62 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, return true; } - /* - * 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 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; - } - 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. + * For backward compatibilty, enable legacy mode when + * - Machine type is i440fx (pc_piix) + * - IGD device is at guest BDF 00:02.0 + * - Not manually disabled by x-igd-legacy-mode=off */ - 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 true; - } + if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_LEGACY_MODE) && + !strcmp(MACHINE_GET_CLASS(qdev_get_machine())->family, "pc_piix") && + (&vdev->pdev == pci_find_device(pci_device_root_bus(&vdev->pdev), + 0, PCI_DEVFN(0x2, 0)))) { + /* + * IGD legacy mode requires: + * - VBIOS in ROM BAR or file + * - VGA IO/MMIO ranges are claimed by IGD + * - OpRegion + * - Same LPC bridge and Host bridge VID/DID/SVID/SSID as host + */ + g_autofree struct vfio_region_info *rom = NULL; + + warn_report("IGD legacy mode enabled, " + "use x-igd-legacy-mode=off to disable it if unwanted."); + + /* + * 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 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_setg(errp, "Device has no ROM"); + return false; + } - /* 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 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, errp)) { + error_setg(errp, "Unable to enable VGA access"); + 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; + /* Setup OpRegion access */ + if (!vfio_pci_igd_setup_opregion(vdev, errp)) { + return false; + } + + /* Setup LPC bridge / Host bridge PCI IDs */ + if (!vfio_pci_igd_setup_lpc_bridge(vdev, errp)) { + return false; + } } /* diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index a58d555934..b0620a0ae8 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3363,6 +3363,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-legacy-mode", VFIOPCIDevice, features, + VFIO_FEATURE_ENABLE_IGD_LEGACY_MODE_BIT, true), 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 2e81f9eb19..b7b07644a8 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_LEGACY_MODE_BIT 4 +#define VFIO_FEATURE_ENABLE_IGD_LEGACY_MODE \ + (1 << VFIO_FEATURE_ENABLE_IGD_LEGACY_MODE_BIT) OnOffAuto display; uint32_t display_xres; uint32_t display_yres; From patchwork Mon Mar 3 17:52: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: 13999336 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 BEEF2C282CD for ; Mon, 3 Mar 2025 17:58:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tp9zP-0003Bp-3g; Mon, 03 Mar 2025 12:54:03 -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 1tp9yB-0001aK-Kn for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:53 -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 1tp9y9-0000KR-Gu for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:47 -0500 Received: by mail-pl1-x641.google.com with SMTP id d9443c01a7336-22349bb8605so91997065ad.0 for ; Mon, 03 Mar 2025 09:52:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741024364; x=1741629164; 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=qRtSHJvA2ZisXRCw+d0PCWWfXqzJR04ZEJdwHvxg6SI=; b=jrZjQuHtqwJbn2fW013VIeeLrHWvlAgIgl4nYU3hDqkWGY5bM7C6sg8scEzK+JGJqR 4baBIa591Dq5zeynzC3We5PuS1NoAv0ABcLWsqKVz2bJdRhcCuTylCxUaIwLStHDCvBT Db3D+hd7/bOxS8lowf9cwR5QySXw9BM6JL/cMmpgmuwn+SvUdLe7yiCaoE7j7XnkhlxD dpsmSikiw6WLodlx/ru49iFqVDxMk4fGgPsEQtDJtH6gXeoN40b8B1D+5itRZLe5y/VL N3LZtxsOH6vu1UDZGBv5+OC1oURlMbKSuwDy0Cc3uf675yJhLYt4tFbIGaLzwW7WaX5z JvJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741024364; x=1741629164; 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=qRtSHJvA2ZisXRCw+d0PCWWfXqzJR04ZEJdwHvxg6SI=; b=R1pIs+GZWXLoaZK7JptjDHYpPTi5cocMAzWk25zh+pn8UNoanrHNfaPNMmb5MfD+cg voPfkM+fNqzPL+sMcIPdCVT1d9kml0yrTz+fD70W6ChxdOMF91p3LrL5rzlRMLCfo0QE NgXaaol6xv9FvMc3MXOQaGFcv77WBnejKFvaX848HcObfwQbRGSxZwKseC7QB/wFTH2f Eckzbhy5IWtF5+PWhlfcjkSZmy6vlniXhSh9pveRFeKntd+IhpU3aETllUs1SZtteACS voByRNUZxRd2sb1MmrGNur2D0nUv83YCDc3dzUW+fkAaI1uo+e/KePdCzowD9qYlj5QD 4COQ== X-Gm-Message-State: AOJu0YywM7ymkqAY57q7XV9OP8mpuhdfIZCn/7uvjtUI2b0S8l3jP+mT jWiN3hyk5L0Qur1/xTGOaLoCGYv5InVegykygp3DkksyosVhOAlmz6PwFw6m1A== X-Gm-Gg: ASbGncsvQIsg6la7VOmQpmiritz3vAcJascV/A+xYlONp/hL4WZRuxsjcsRTD5IHqsP uml3anPwWOT1yf6KCfkT9WXsgiczx+o2jLjP9kRSSzFEAMziS310WNIjmU2GdIV5hSQsi+dkp65 WuQDVvWuOOn33brEduoeu+LLSEit717xRl+jUSEueyNCh98jUw/wwmZ9/ac/p9Bn9HlCN1KSWzG vWSdKNbuhi85JqdHJiZl20hPqT6EL2f8Y92U+adQCkSJLniZ/ODhTtcGm70ZvqtUgZ8dzKV8sdJ 6jAW7z02Kftw4PWv+bJ/Ou0SkzfCW7ykgRpnzjvcA/Amv067V7Jm0mUX6Q== X-Google-Smtp-Source: AGHT+IFZ3D1jkr20vtSH8vMGSnsN0+HBbREHyvo+VfTkeVqYaeCAk/59uoWAGXpE1iBddPTengG6cQ== X-Received: by 2002:a17:903:2412:b0:21f:8099:72e4 with SMTP id d9443c01a7336-22368fc97b7mr258114125ad.28.1741024364173; Mon, 03 Mar 2025 09:52:44 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2235052beaasm80625535ad.233.2025.03.03.09.52.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 09:52:43 -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, =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v2 8/9] vfio/igd: Handle x-igd-opregion option in config quirk Date: Tue, 4 Mar 2025 01:52:18 +0800 Message-ID: <20250303175220.74917-9-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250303175220.74917-1-tomitamoeko@gmail.com> References: <20250303175220.74917-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 Both enable OpRegion option (x-igd-opregion) and legacy mode require setting up OpRegion copy for IGD devices. As the config quirk no longer depends on legacy mode, we can now handle x-igd-opregion option there instead of in vfio_realize. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 14 +++++++++----- hw/vfio/pci.c | 9 --------- hw/vfio/pci.h | 2 -- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 40f5803be9..9bfaa24c24 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -189,7 +189,7 @@ static bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, return true; } -bool vfio_pci_igd_setup_opregion(VFIOPCIDevice *vdev, Error **errp) +static bool vfio_pci_igd_setup_opregion(VFIOPCIDevice *vdev, Error **errp) { g_autofree struct vfio_region_info *opregion = NULL; int ret; @@ -557,10 +557,8 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp) return false; } - /* Setup OpRegion access */ - if (!vfio_pci_igd_setup_opregion(vdev, errp)) { - return false; - } + /* Enable OpRegion quirk */ + vdev->features |= VFIO_FEATURE_ENABLE_IGD_OPREGION; /* Setup LPC bridge / Host bridge PCI IDs */ if (!vfio_pci_igd_setup_lpc_bridge(vdev, errp)) { @@ -568,6 +566,12 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp) } } + /* Setup OpRegion access */ + if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) && + !vfio_pci_igd_setup_opregion(vdev, errp)) { + return false; + } + /* * 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.c b/hw/vfio/pci.c index b0620a0ae8..8fb415cf45 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, diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index b7b07644a8..4bddfb80f8 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -232,8 +232,6 @@ int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev, bool vfio_populate_vga(VFIOPCIDevice *vdev, 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); void vfio_display_finalize(VFIOPCIDevice *vdev); From patchwork Mon Mar 3 17:52: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: 13999328 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 96144C282D1 for ; Mon, 3 Mar 2025 17:54:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tp9zN-00034y-GM; Mon, 03 Mar 2025 12:54:01 -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 1tp9yE-0001cK-6I for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:55 -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 1tp9yB-0000Ke-Fn for qemu-devel@nongnu.org; Mon, 03 Mar 2025 12:52:49 -0500 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-2234bec7192so71441215ad.2 for ; Mon, 03 Mar 2025 09:52:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741024366; x=1741629166; 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=dVDCsa3yLXvuTG05pS6r6MokNR6jdPXP7E/1Cp/7QYA=; b=ZPbx7AIex2YCF8g2CPkKzpqYMoGIpAIOI5dfl+wSsg2MYBSaLVHIPnZsV9HjqTenIu f2cOY87EyI/Ys23I70M1jv49XOcYDZrFRCTwCsAnVaWHa4cGgSEajavneMLcKE0FCSTx BhLHrGf8pKoD87SrGoiKfx700vl1UFD/0hxL14/5TZU99w6yjNthnxYH2SGGmXJikRY+ DEIHP0of/5m2a39bITuGhkg1XK0y9ZxhZK91b4zNWU72myJrdPL64SBf05V7ua11K6dj jXpHysYvFSbg6Oz8zmnx/8PL/k40iV7yFIc9aB8nBszgijq4BL5StjecZadc5UQ9A3HM P5ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741024366; x=1741629166; 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=dVDCsa3yLXvuTG05pS6r6MokNR6jdPXP7E/1Cp/7QYA=; b=KdZWiayMOqmmYpY18WRm3I6cLYS5CXJykb7jb4KxT8L2e3JoQoP3g70Temsbe5R2eX kRuIo5h9gaZrJ4Yc5F/VorNre0DaZ1sVDznXTWndJY7glsIjUhnpt9jWMv6dsSxfAQaD /a11rAPK5EOE5euVdr5FE5TSCXyJvtuVYPx3O0rNSg8adfLcMQKxe7EiF4APP8cCABZ5 OGhWXGI4VmSMRhoQP1PHpDSqntizqcK4N8NrEUn3lonF3X6GUfGFjd6I+p0PtvbuWBTB +vx3ILxqMDOq0xsvWjyWYnjSrI6QwVd9xMWN2BQIwXkTFi1T9D5w25Tw2LLhAdqGZD5x c8vQ== X-Gm-Message-State: AOJu0YwIGTADQ5Ju7L/hG++PykUKBZvytT1ktX/oi4LRXhdlDbVABnIQ 7X97Kxlq9CTpOD1hx8Fhd2+O6TbdsKUUGUL2IZEQCn63vjhjdTA= X-Gm-Gg: ASbGncuJQgw3irbpqXm4BTRcX/GmgJ6y12HgJxI57y5P1jfXQ8JOPv6vPDVrB/l4ITz CldqV8/EO7Ypyj69496vgiGcMfELtW+KlQrVO7R+Ms5QmlyPUvWByDfLZc3yNJs3p7+8npsOtcX jXIKeJD8bsF+Ta8n8V9YEfhHvRZ2v74IfYt9cG3sKDIlc4pTYbZjcYo7sbIjAFNrRB121w5zX3S 27/kmgvQUZCb2MtI66OBLAgZ41BHQ8aC05IfiC+at/fLrXJYF1j3awRkyqWAz1d9Gy1nhguLQ5s 6B2pXPwdmwTLBL2oMMNAFcc0smrV2RJluqJ1Ty3tAfWvIN97yJCKPtNhAg== X-Google-Smtp-Source: AGHT+IHv4QhhKLMP9Jj0T7VVKihohftTgmUaAYoISXjn9gP0chCyaCrRuLyrzblOtXNcFuwmoN/9Dw== X-Received: by 2002:a17:902:d511:b0:223:28a8:6101 with SMTP id d9443c01a7336-22368fa6da1mr213448025ad.29.1741024366244; Mon, 03 Mar 2025 09:52:46 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2235052beaasm80625535ad.233.2025.03.03.09.52.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 09:52:45 -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, =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v2 9/9] vfio/igd: Introduce x-igd-lpc option for LPC bridge ID quirk Date: Tue, 4 Mar 2025 01:52:19 +0800 Message-ID: <20250303175220.74917-10-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250303175220.74917-1-tomitamoeko@gmail.com> References: <20250303175220.74917-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 LPC bridge/Host bridge IDs quirk is also not dependent on legacy mode. Recent Windows driver no longer depends on these IDs, as well as Linux i915 driver, while UEFI GOP seems still needs them. Make it an option to allow users enabling and disabling it as needed. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 14 ++++++++------ hw/vfio/pci.c | 2 ++ hw/vfio/pci.h | 3 +++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 9bfaa24c24..d3ebbebe4e 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -557,13 +557,9 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp) return false; } - /* Enable OpRegion quirk */ + /* Enable OpRegion and LPC brige quirk */ vdev->features |= VFIO_FEATURE_ENABLE_IGD_OPREGION; - - /* Setup LPC bridge / Host bridge PCI IDs */ - if (!vfio_pci_igd_setup_lpc_bridge(vdev, errp)) { - return false; - } + vdev->features |= VFIO_FEATURE_ENABLE_IGD_LPC; } /* Setup OpRegion access */ @@ -572,6 +568,12 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp) return false; } + /* Setup LPC bridge / Host bridge PCI IDs */ + if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_LPC) && + !vfio_pci_igd_setup_lpc_bridge(vdev, errp)) { + return false; + } + /* * 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.c b/hw/vfio/pci.c index 8fb415cf45..1e49c4b58b 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3354,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_BIT("x-igd-legacy-mode", VFIOPCIDevice, features, VFIO_FEATURE_ENABLE_IGD_LEGACY_MODE_BIT, true), DEFINE_PROP_ON_OFF_AUTO("enable-migration", VFIOPCIDevice, diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 4bddfb80f8..dd645a5465 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) #define VFIO_FEATURE_ENABLE_IGD_LEGACY_MODE_BIT 4 #define VFIO_FEATURE_ENABLE_IGD_LEGACY_MODE \ (1 << VFIO_FEATURE_ENABLE_IGD_LEGACY_MODE_BIT)