From nobody Wed Apr 2 13:11:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1741285557; cv=none; d=zohomail.com; s=zohoarc; b=YCinuEgi2y2+DktNjh+6igxhPq0VIEPNc17GH7l0q0KIpEoYfZT0GKqaJ3NwWEgofqfXan215NIaOIQO5BBtIMtA/EvmtCW4h+tmhCdstzxoZJLuonjGqNaHOPHybcHXrZQsRdHgdg00sgBcq+fqJM6qD1HJ8vnkq9jlazmZ84s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741285557; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pXjnzMdFRw8UN/BnZINokoDYNlgpPuyWmsHQdzmGGak=; b=eDDGpfKO/9sqoff2Nvuro/PRG3t4tO8f9Mas//X7kdpM4suqCNUlNRPgU5axZOOZ2uD5H3+v5De5gNeWpPEEsc3ARk0ZbJeOcQwJrTcreZbmZjsqlKEITacZAtQqoJxWRGvOiqrjSyBpIRaMJehrnLfz4qqS88MzwCocyU+jnjc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741285557408991.0507273285224; Thu, 6 Mar 2025 10:25:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tqFXm-00035y-0y; Thu, 06 Mar 2025 13:02: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 1tqFXW-000336-Gp for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:01:49 -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 1tqFXS-000051-RO for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:01:44 -0500 Received: by mail-pl1-x643.google.com with SMTP id d9443c01a7336-22409077c06so21322595ad.1 for ; Thu, 06 Mar 2025 10:01:41 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af28126db9bsm1338498a12.58.2025.03.06.10.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 10:01:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741284100; x=1741888900; 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=SjOfkoqFukzYqRaGNLTfaUaVkLmujtfJKfFAthODfsfbSfMlxpD2BnYxeyE23iwYar XMkza3RuAzqPVwxsdEg1gYfBjrpCBhV+glNYQ5+iTSX01YGbloPVHp+o5gkY/n+e9xaD lBdYnPKEpDklSyUcxOzWVDWOBiKZLneJUgfteJeCftU52dkO487xZnZhw5mLGRoAlkeg jCs3bMCyyhRnDZOFoad0sqmPco9Jqsev1KuDrCqFYs0TykoOYmJr9gGWuVo+NJiB0vvU OIWQM+9E7QZk0ydhmQQFd1MJofNFp+qXPLe+YMl6tdyVNxkYtu9idZmlUQ9Ekk1uiRK8 6t3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741284100; x=1741888900; 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=LK3jil3LoegNgKAPcrv66dDz9eYIIL8jSY5F0gJYLpm6MYeI+UcfoOiiN6BzKbgsnE UaKy2umAHHHJy6P3yvx5mn2mngLwsmCzFQhmm4XfhkpsmmxiwkveAmWrWOwJPcuk/ihR qwFLmJLQ9AbAavWLBVAiSmE93WbUWufeH9BxXAzh2sBRK1t9wa4Y5J2MVkNY0mnpO6Bk EjfrW/KPrgK2YbiR4HohzkLG3NyWmaM7s2sReuolriKwnNpcSLNfKD0CGyVr8/y3nLuD j2yLNqNsLZWnhTA0wiD2hi+tV/1JOz69RhVJcdh7aJ/KnCHI0rgjRBpPvhj8Ss5A3gYt 57kw== X-Gm-Message-State: AOJu0YwKV3M9zR40CXgkrrlFegut6YG6jq/po5BI/tJE5I3sjury3t8l T00OJ0xJX/MdH74qQ1ZgKsGapmLm25vGI345G/gDpJbcz8icAxiGUbCqPMZEEw== X-Gm-Gg: ASbGncv7Eo+yV7yC0oYG1fyMsOmWNhRmqZ2eN5dSiCVFKxr3n3bIHfkegbYDAoSMrLZ Un5AwTD1xZKyHGFj9ZJeevI8LHr87m41X5TmtSqweyUowTcE0Hcc6BVwpcK8gzansGrIyh1oHFv bBcYe2NVdaXu3SPB4RKX0pncpKx9pLRmAWGQXvZyAom2JhfRIrKLZL7/2493TuTDZ04OcYe2rYE DGRth7IRzRSRAXhH6IOrvgbhfMKmRnjp40wss+vFlzoibpY80dQhvKvJ/1YDVJS0KKCMI9LjVS4 FcNwmPkm0yiPal+gh/UxDH9wDsn88ZPEVanhf2S70xOzWhjOOgQOG0tuLg== X-Google-Smtp-Source: AGHT+IEiiamkSUvp1Igj6O+INCEjbd3lWZMCuULwpW3dQjPhQNzFdGr5iN49ibRoDe42igO9KikSYg== X-Received: by 2002:a05:6a21:700f:b0:1f0:ea87:fab7 with SMTP id adf61e73a8af0-1f544aef35cmr739168637.13.1741284100301; Thu, 06 Mar 2025 10:01:40 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Cc: qemu-devel@nongnu.org, =?UTF-8?q?Corvin=20K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 01/10] vfio/igd: Remove GTT write quirk in IO BAR 4 Date: Fri, 7 Mar 2025 02:01:21 +0800 Message-ID: <20250306180131.32970-2-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250306180131.32970-1-tomitamoeko@gmail.com> References: <20250306180131.32970-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1741285561462019100 Content-Type: text/plain; charset="utf-8" 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/pciin= it.c#L319-332 Signed-off-by: Tomita Moeko Reviewed-by: Alex Williamson Reviewed-by: Corvin K=C3=B6hne Tested-by: Alex Williamson --- 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; } =20 -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 la= ter */ @@ -300,129 +294,6 @@ static int vfio_pci_igd_lpc_init(VFIOPCIDevice *vdev, return ret; } =20 -/* - * 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. Therefo= re - * we either have 2M/4k * 4 =3D 2k or 8M/4k * 8 =3D 16k as the maximum iob= ar 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 =3D vfio_pci_read_config(&vdev->pdev, IGD_GMCH, sizeof(g= mch)); - int gen =3D igd_gen(vdev); - uint64_t ggms_size =3D 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 m= odes. - * 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 thoug= h, 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 t= he 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 t= he - * 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 =3D opaque; - VFIOPCIDevice *vdev =3D igd->vdev; - - igd->index =3D ~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 =3D opaque; - VFIOPCIDevice *vdev =3D igd->vdev; - uint64_t val =3D data; - int gen =3D 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 p= oints - * to a 4k page, which we translate to a page from the VM allocated re= gion, - * 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 on= ly - * see the vBIOS writing up to (nearly) the 1MB barrier. In fact it o= ften - * seems to miss the last entry for an even 1MB GTT. Doing a gratuito= us - * write of that last entry does work, but is hopefully unnecessary si= nce - * we clear the previous GTT on initialization. - */ - if ((igd->index % 4 =3D=3D 1) && igd->index < vfio_igd_gtt_max(vdev)) { - if (gen < 8 || (igd->index % 8 =3D=3D 1)) { - uint64_t base; - - if (gen < 11) { - base =3D pci_get_long(vdev->pdev.config + IGD_BDSM); - } else { - base =3D pci_get_quad(vdev->pdev.config + IGD_BDSM_GEN11); - } - if (!base) { - hw_error("vfio-igd: Guest attempted to program IGD GTT bef= ore " - "BIOS reserved stolen memory. Unsupported BIOS?"= ); - } - - val =3D data - igd->bdsm + base; - } else { - val =3D 0; /* upper 32bits of pte, we only enable below 4G PTE= s */ - } - - 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 =3D ~0; -} - -static const MemoryRegionOps vfio_igd_data_quirk =3D { - .read =3D vfio_igd_quirk_data_read, - .write =3D vfio_igd_quirk_data_write, - .endianness =3D DEVICE_LITTLE_ENDIAN, -}; - -static uint64_t vfio_igd_quirk_index_read(void *opaque, - hwaddr addr, unsigned size) -{ - VFIOIGDQuirk *igd =3D opaque; - VFIOPCIDevice *vdev =3D igd->vdev; - - igd->index =3D ~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 =3D opaque; - VFIOPCIDevice *vdev =3D igd->vdev; - - igd->index =3D data; - - vfio_region_write(&vdev->bars[4].region, addr, data, size); -} - -static const MemoryRegionOps vfio_igd_index_quirk =3D { - .read =3D vfio_igd_quirk_index_read, - .write =3D vfio_igd_quirk_index_write, - .endianness =3D DEVICE_LITTLE_ENDIAN, -}; - #define IGD_GGC_MMIO_OFFSET 0x108040 #define IGD_BDSM_MMIO_OFFSET 0x1080C0 =20 @@ -494,14 +365,11 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, i= nt nr) g_autofree struct vfio_region_info *opregion =3D NULL; g_autofree struct vfio_region_info *host =3D NULL; g_autofree struct vfio_region_info *lpc =3D 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 =3D NULL; =20 /* @@ -634,32 +502,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, in= t nr) return; } =20 - /* Setup our quirk to munge GTT addresses to the VM allocated buffer */ - quirk =3D vfio_quirk_alloc(2); - igd =3D quirk->data =3D g_malloc0(sizeof(*igd)); - igd->vdev =3D vdev; - igd->index =3D ~0; - if (gen < 11) { - igd->bdsm =3D vfio_pci_read_config(&vdev->pdev, IGD_BDSM, 4); - } else { - igd->bdsm =3D vfio_pci_read_config(&vdev->pdev, IGD_BDSM_GEN11, 4); - igd->bdsm |=3D - (uint64_t)vfio_pci_read_config(&vdev->pdev, IGD_BDSM_GEN11 + 4= , 4) << 32; - } - igd->bdsm &=3D ~((1 * MiB) - 1); /* 1MB aligned */ - - memory_region_init_io(&quirk->mem[0], OBJECT(vdev), &vfio_igd_index_qu= irk, - 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_qui= rk, - 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 multiple= s 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, in= t nr) pci_set_quad(vdev->emulated_config_bits + IGD_BDSM_GEN11, ~0); } =20 - /* - * 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) !=3D sizeof(cmd_orig)) { - error_report("IGD device %s - failed to read PCI command register", - vdev->vbasedev.name); - } - - cmd =3D cmd_orig | PCI_COMMAND_IO; - - if (pwrite(vdev->vbasedev.fd, &cmd, sizeof(cmd), - vdev->config_offset + PCI_COMMAND) !=3D sizeof(cmd)) { - error_report("IGD device %s - failed to write PCI command register= ", - vdev->vbasedev.name); - } - - for (i =3D 1; i < vfio_igd_gtt_max(vdev); i +=3D 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) !=3D sizeof(cmd_orig)) { - error_report("IGD device %s - failed to restore PCI command regist= er", - vdev->vbasedev.name); - } - trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, (ggms_size + gms_size) / MiB); } --=20 2.47.2 From nobody Wed Apr 2 13:11:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1741285793; cv=none; d=zohomail.com; s=zohoarc; b=DIQA7cXormP1Mi8C1doYHpTRC9ZTUQoPuauu9g9xKpG7XlO5rkRxSYwfoLq+lbFVKEsB95P8dFwYtgYpQTyqifH9cB6WGnkObd57q+cyqtUkPvKlh8P7rljSEq98zPFQytfR28SOxYkFTF/M2kukLeEIaCudtX2UljWDyWIhWkI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741285793; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+f6msq+IO8zcZ2KQoBk0f5EVnSPIFuiTsc8ZvnAkAZY=; b=KUW10DXW6LMFPfjY7h7aWhM7+OWK/T1eehGQVHPytVKRbBJ5mdcvjgRunL465BtDPEOWlJrGGB3b7GrFOHedlVCT+HuJUxA8HJ3rxXLDpTUITuWyMjCiaqLgKY5fejJ0FcW2G+ci53NEzbnHo8vrFyA4X9Ua8DurH8myBj6UbH4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741285793005336.5508765213168; Thu, 6 Mar 2025 10:29:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tqFXp-00038L-T4; Thu, 06 Mar 2025 13:02:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tqFXh-00034A-N1 for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:01:57 -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 1tqFXW-00006r-A0 for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:01:56 -0500 Received: by mail-pl1-x642.google.com with SMTP id d9443c01a7336-22356471820so16975305ad.0 for ; Thu, 06 Mar 2025 10:01:45 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af28126db9bsm1338498a12.58.2025.03.06.10.01.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 10:01:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741284102; x=1741888902; 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=+f6msq+IO8zcZ2KQoBk0f5EVnSPIFuiTsc8ZvnAkAZY=; b=b2W98BmpTog2aMKgK2UzPnw7UL0SWkOF/Yb0DwL8RP4mneyVfrTVAGFSJKrKrMid/m yYMGkP6rtP3eAp0BBcaZhvj0WRawx6vz1GYBXMxsC21b3vpebqYY8g2BUMOlMdo+NsVq bDNxkrGUceBiwl41JJ2wqMtAGCiJMjAIcMUBvOVUr6fl6oPFkDtq5AFPm4YRTs5/m5ET CMiC3HE608oYhMVzU0/9CFq9fJrp6lciJo32uAWQvvK1D3RvQDL7/PKYS8ghs3hOru4a +llHkoFQVweTTNoujVoXa6Q90JlbJ3kIY3lc9+TJPyH5dU3pAKfyuWTFDyJLyu/V1Lne FM1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741284102; x=1741888902; 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=+f6msq+IO8zcZ2KQoBk0f5EVnSPIFuiTsc8ZvnAkAZY=; b=kDOAdqfE8XkIOwDuv90rQPX4Q5ZEJbCYMzHZYsQxEFNUxzbGp3GfcyLclOZFaG2izO mlk31bKy45tIChqBGlXREuJ2JuovYB6zx/z/01I+pWL5Dk5ytS5N+LmGo3qJXk6YHRXe 8a7iTcz7cXkkWsM7LVOcH3PyheL8HmRWBBIWmbF0fonKRXqBBUO+TCboSG6/u4Di6+Hc kFK9vcpYtmTCeleUPDDZ576VhuF/yv6JzylEc9pJWqkkx++289+GebDOyoDQXkzaH8G1 AntaM5E3/ofQNiB3tyTy7si7nPs6gYCrI0gmgyoZ+OKUkBKj5gXkrvgoGbgofpUiAhuu /PfA== X-Gm-Message-State: AOJu0Yx2p7ZVWtMcQsXgD6QvzhJ/tNfvy5aaZG5lrBP4XHI+icR6FbaI LbEPiEYAucW0G79DalcerrkgkjWQxrLSFe9vx19ztNkKVBnSuR8= X-Gm-Gg: ASbGncvktFHgjNRCb6dvs4EOIUdxOyUtSr/U2P6LF5mNVbDUd2IQnvlRII+8PslaS9W mz5oABI5c4IBiF8ydNMU57cX9OvxMFhwM+0ePR+4n9k/8eroDdeqIV4hrD8n9QgUrIa78qrm2iH CfmRKnkoemv9sfmsUHdNYcc+//6as6ivwQgV0I1IEm0pIkWyWz0puziw/lwvzDMMPiBNN2PvVA4 MNTqa8EAitXvIBie2fQeZ2x9qTrSHjpl1H4S4npHUgiZR1AngKdP5MIwA+G5mZpuStdzbhFIlX0 BPdTY6h8mVJAXvbFtKZguwl6ig1yPWFSBgsQ6OFKWqtMnl+JuYvxM94LpA== X-Google-Smtp-Source: AGHT+IEF+K3Ss1wzguIkGbbzV6KvhQNA3A5wDK09fZJGks8dteeIUbSV4VOfimtJPmuKpfG8LKbo0A== X-Received: by 2002:a05:6a20:7fa7:b0:1f3:4427:74ae with SMTP id adf61e73a8af0-1f544b18642mr829183637.25.1741284102463; Thu, 06 Mar 2025 10:01:42 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Cc: qemu-devel@nongnu.org, =?UTF-8?q?Corvin=20K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 02/10] vfio/igd: Do not include GTT stolen size in etc/igd-bdsm-size Date: Fri, 7 Mar 2025 02:01:22 +0800 Message-ID: <20250306180131.32970-3-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250306180131.32970-1-tomitamoeko@gmail.com> References: <20250306180131.32970-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1741285794888019100 Content-Type: text/plain; charset="utf-8" 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 IgdAssignmentDxe does now. [1] https://gitlab.com/qemu-project/seabios/-/blob/1.12-stable/src/fw/pciin= it.c#L319-332 Signed-off-by: Tomita Moeko Reviewed-by: Alex Williamson Reviewed-by: Corvin K=C3=B6hne Tested-by: Alex Williamson --- 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) =20 #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 =3D (gmch >> IGD_GMCH_GEN6_GGMS_SHIFT) & IGD_GMCH_GEN6_GGMS_M= ASK; - } else { - ggms =3D (gmch >> IGD_GMCH_GEN8_GGMS_SHIFT) & IGD_GMCH_GEN8_GGMS_M= ASK; - if (ggms !=3D 0) { - ggms =3D 1ULL << ggms; - } - } - - return ggms * MiB; -} =20 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 =3D 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 =3D NULL; @@ -527,7 +507,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) } } =20 - ggms_size =3D igd_gtt_memory_size(gen, gmch); gms_size =3D igd_stolen_memory_size(gen, gmch); =20 /* @@ -539,7 +518,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) * config offset 0x5C. */ bdsm_size =3D g_malloc(sizeof(*bdsm_size)); - *bdsm_size =3D cpu_to_le64(ggms_size + gms_size); + *bdsm_size =3D cpu_to_le64(gms_size); fw_cfg_add_file(fw_cfg_find(), "etc/igd-bdsm-size", bdsm_size, sizeof(*bdsm_size)); =20 @@ -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); } =20 - 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)); } --=20 2.47.2 From nobody Wed Apr 2 13:11:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1741284196; cv=none; d=zohomail.com; s=zohoarc; b=H+skPB/t5kwPMFXdlvBtxbCK8JgZrcAJwHl4S1CgpEvRWEPcA0eDf8E9zXuMa2s4iwEPloUSbNzE5pv/SEIzBTLOULcoK7wCtdbGE5bHr5cR8isRDQnEpdCWDfxSyf2IqdmEJcxZRGxJArxfVrkt42RMqp8sLREMgOEg3xtdLNw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741284196; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=stCgZpQtE1zFYYbrS3BPR9VSrLJmwkhXSnn+AFxTDO4=; b=fVrj57M/Wj2pRF4CEVTQd4UJ013FuA42cddF7ydYFy/4EsBcu1DifSx437oNjKeCz78MFZk7eys4iYWdY1OjXZEGw/zuEKQPigUUa1sgGI76pjmyuhr/8XobsNmKgVgYh35/08H1um2J55u73foiQ2DQbqiosecbvcwU3dPvkLY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741284196259867.8074425938721; Thu, 6 Mar 2025 10:03:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tqFXp-00038M-UL; Thu, 06 Mar 2025 13:02:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tqFXf-00033y-D1 for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:01:57 -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 1tqFXW-00007F-9n for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:01:51 -0500 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-223fd89d036so20056785ad.1 for ; Thu, 06 Mar 2025 10:01:45 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af28126db9bsm1338498a12.58.2025.03.06.10.01.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 10:01:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741284105; x=1741888905; 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=VlMLqKnNBbcjuIgr0eeNQOz2CN+oduGE1htLN9GVZ3VEf9KJ2b01pkrtKaZmzJ4Tla RZLZUyMpJgbSreDmU/0hQwzKYsn0gHIoDz/NRKO5GkJq3htWQph9gdB2wh5Vlh0TisVH tU/ZnWkTeGkRp0MbA8FjzfI1vXQ3DtfUc+qKeNy3AjzJ9EZRVXTULtYragwb6y9YyPiC +6VnrntpiNufSXLKWcikv/wIp2sQUadqcUpSoC4aUZUSbbJi05y9tfCvWPpe9gbzyyGB UMFfdiab2/xRHgqoPRv6HwS/2u+rvW1CAbjY06AB5NZrY5mikYDtUxQBcIPP+/N3FpSW mr+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741284105; x=1741888905; 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=F70GTNyAOq4M6aZ26qwDcQjnMFPjF00+3R3mA/qFumKqDHDO93SyT145MA13oeFDAS 47u1Vq9ClXDf7ogp+xvf9u7/RuDnxeCQEfAcz52P4rXZl8m1nCWqqiGJLGPu+2Sgyb0l gGaVirVqmp9xo6c+X9wzSVlVBhv+LFoB20IXLgtgqRwfDVkx3ohQO0rcWdhLEVaG2eLB Wfo2KMJsij+hH8q62W78Dy0HVvJhtUa/p5JOEjA0vCoBsBpNEr0d+weMgkl2Wv6bJafZ 6ykD2asV2Xbjy0wZ7nbWKK+Vyj1/7MaV+Jq0os7pNBFZGTrMe0gqV5s88JoPXPFwNpAe Vcxg== X-Gm-Message-State: AOJu0YySUQAxniLjEJluIwrEQmdWjIsdQ6fwjoPPusA469d16u8LnApx DRK/zqwz1WwSBub4cTlI2XuxTWtQDP47rGt78u4Y5Uh2Au7wsJly47+rRXyOEA== X-Gm-Gg: ASbGncsAAk1MViZOKLq9h3hKHd0Ycgh4CS4nrZ5JtGhSqCfpCP4P1fb+eHrkKOYgssO uAPBoAagjVlmUzbbrzcWllkTQr9Bb4kwFDX0dElXo3YzCyXcYS6ljDzly0C/ErBrNiNIKQ7P60u MC7+nYQzZzTIaAmhpo7qaNaq0uknszQjHoJ4/xVZQ8jLudRGRREuS8iTUw7KNf7VbQ1Uu/udsfx 9JANjRnH60RFdI03kZV8aHwnyWjUlz3ulFt+lee+hLT1s1lA09XZZHFo2Ub+zoRvJn0mpB2BIwp 6z06LgZGXtasq/rgqqKYb9NmDb6Up7xWFEteatjMnA6xBIareEOFFsAWAw== X-Google-Smtp-Source: AGHT+IG4JYNyfyeJViWCRhuaHcaPArr2NIPJdALGhMWAQM4oDSuzOb4yeNW4Fr/HLYT0S9dGrpSv7A== X-Received: by 2002:a05:6a21:497:b0:1f1:2a5:1667 with SMTP id adf61e73a8af0-1f544c381e0mr822134637.32.1741284104552; Thu, 06 Mar 2025 10:01:44 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Cc: qemu-devel@nongnu.org, =?UTF-8?q?Corvin=20K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 03/10] vfio/igd: Consolidate OpRegion initialization into a single function Date: Fri, 7 Mar 2025 02:01:23 +0800 Message-ID: <20250306180131.32970-4-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250306180131.32970-1-tomitamoeko@gmail.com> References: <20250306180131.32970-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1741284203932019000 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alex Williamson Reviewed-by: Corvin K=C3=B6hne Tested-by: Alex Williamson --- 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; } =20 +#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 la= ter */ @@ -138,6 +139,82 @@ static uint64_t igd_stolen_memory_size(int gen, uint32= _t gmch) return 0; } =20 +/* + * The OpRegion includes the Video BIOS Table, which seems important for + * telling the driver what sort of outputs it has. Without this, the devi= ce + * may work in the guest, but we may not get output. This also requires B= IOS + * 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 regi= ster + * 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 =3D g_malloc0(info->size); + ret =3D pread(vdev->vbasedev.fd, vdev->igd_opregion, + info->size, info->offset); + if (ret !=3D info->size) { + error_setg(errp, "failed to read IGD OpRegion"); + g_free(vdev->igd_opregion); + vdev->igd_opregion =3D 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 w= rite + * the reserved memory base address to the device ASLS register at 0xF= C. + * Alignment of this reserved region seems flexible, but using a 4k pa= ge + * 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 ha= ve + * 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 =3D 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 devi= ce"); + return false; + } + + ret =3D 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, t= he @@ -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 =3D NULL; - g_autofree struct vfio_region_info *opregion =3D NULL; g_autofree struct vfio_region_info *host =3D NULL; g_autofree struct vfio_region_info *lpc =3D NULL; PCIDevice *lpc_bridge; @@ -418,15 +494,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, in= t nr) * Check whether we have all the vfio device specific regions to * support legacy mode (added in Linux v4.6). If not, bail. */ - ret =3D vfio_get_dev_region_info(&vdev->vbasedev, - VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_I= NTEL, - 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 =3D vfio_get_dev_region_info(&vdev->vbasedev, VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_I= NTEL, VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG, &host); @@ -459,6 +526,13 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, in= t nr) return; } =20 + /* 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 =3D vfio_pci_igd_lpc_init(vdev, lpc); if (ret) { @@ -475,13 +549,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, in= t nr) return; } =20 - /* 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 multiple= s 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(VFIOPCIDev= ice *vdev, int nr) trace_vfio_quirk_rtl8168_probe(vdev->vbasedev.name); } =20 -#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 devi= ce - * may work in the guest, but we may not get output. This also requires B= IOS - * 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 regi= ster - * of the IGD device. - */ -bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, - struct vfio_region_info *info, Error **err= p) -{ - int ret; - - vdev->igd_opregion =3D g_malloc0(info->size); - ret =3D pread(vdev->vbasedev.fd, vdev->igd_opregion, - info->size, info->offset); - if (ret !=3D info->size) { - error_setg(errp, "failed to read IGD OpRegion"); - g_free(vdev->igd_opregion); - vdev->igd_opregion =3D 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 w= rite - * the reserved memory base address to the device ASLS register at 0xF= C. - * Alignment of this reserved region seems flexible, but using a 4k pa= ge - * 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 ha= ve - * 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 **e= rrp) vfio_bar_quirk_setup(vdev, i); } =20 +#ifdef CONFIG_VFIO_IGD if (!vdev->igd_opregion && vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) { - g_autofree struct vfio_region_info *opregion =3D NULL; - - if (vdev->pdev.qdev.hotplugged) { - error_setg(errp, - "cannot support IGD OpRegion feature on hotplugged " - "device"); - goto out_unset_idev; - } - - ret =3D vfio_get_dev_region_info(vbasedev, - VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_I= NTEL, - VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, &opregion); - if (ret) { - error_setg_errno(errp, -ret, - "does not support requested IGD OpRegion feat= ure"); - 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 =20 /* 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, =20 bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp); =20 -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); =20 void vfio_display_reset(VFIOPCIDevice *vdev); bool vfio_display_probe(VFIOPCIDevice *vdev, Error **errp); --=20 2.47.2 From nobody Wed Apr 2 13:11:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1741285644; cv=none; d=zohomail.com; s=zohoarc; b=bFxSd2L/Z1YnmrVAA2UV7WbB9RXXjRq8z1/m3Z7jknGxzXaRaA5WSUCUFv9gby/5P3kPq4/HAhb9w/JZYRO5wZ7ADAtPA6mR8esUmk24ZWdOBx69dBLNoj72CASYw2m/bgIkOkALdW6xO/7kgcu5Zs1E+G6xNcWJOFAxr/pc4FI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741285644; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Mvd2byRBLj1EWurRow3kwEAQYrHkAuspw1kE35aVtA8=; b=Y3eJviv+EhyNtjEunrGhRx3g12B/FIP8ZAtwB9dmftxJs69X/Bor5AbVWYDPuLohwtF9KgfLhbWduvGFmJN27WZV8Wxjdiv7G/Ubk/KYxbsuQCqtIScXzeTQpei1zfZ8ZFYx7EUN7d6fJFqN8RzqR/Cv+0qKrMInDBI15dEvi7A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741285644922534.1122187869669; Thu, 6 Mar 2025 10:27:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tqFXq-00038y-UV; Thu, 06 Mar 2025 13:02:06 -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 1tqFXk-00034s-3Z for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:02:00 -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 1tqFXa-000089-Ur for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:01:58 -0500 Received: by mail-pl1-x643.google.com with SMTP id d9443c01a7336-22337bc9ac3so21342435ad.1 for ; Thu, 06 Mar 2025 10:01:47 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af28126db9bsm1338498a12.58.2025.03.06.10.01.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 10:01:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741284107; x=1741888907; 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=Jsu+t8SGep7D8CVfGfRGz4covtcInakwnXsHbVMdIQZ99ynI8DF0yaJX2ZT4uERCY5 E6HbU7bUFDc668JT0/mL79UHYFlDCn8x0W6ox+VDd6joSqGut9JjajMk6yW6KYsqL5Eo t/n8H1/FCOKd5baKLpkwtpqnZmkP1kWhDkDtSYoxAw3jgM38czkji2cZEvs52esokDGO j8bXWFgb2BWHWQ0IsWvX9hYoDiv/Njn82iZzUGjmFqYpDVotiAZ++YAVWrqWRHC/5/wI 8H3oy2SGmkrq2DfcP32r7uiK9MQi3ZNPrZuPQbv84G8utoovqe6tLUiPuop8xLP1hkLn Zgsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741284107; x=1741888907; 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=X4JYqQr5x7DQ/2WxFTM7zNqr/hOQJUo/iT6B5aam1RjDabvQU2mMutJr+dK0KeUHlR zvX5sT7GO+TObhA4o/QOBktwrFhUn+RoIGUqScEwZR8yIP8izUwHtWUujsH2dwLYrbxs PshvhSRXlDjh3eMrJgmc4jF2OCwEcroeXUFKZvGtUtNQzlRemDPNFuBi6JZBp6Vd4boQ y4mueQwOk6/CDTr1qj5228NCUn4VUjVeVzFxcUnboo5v0d0JYmYPuw85vua/lkVwqezV bZwM92BVrfKAl+mvwC2WaImn5A6KoAH3SYpB/uISDsve6a425uve3GbAgEBZ12+BUUQu DzQw== X-Gm-Message-State: AOJu0YzIWyGc0qAeVmdpOtFySYT40R286sqQcPrVo8Drmx0woB62hMM6 u849W+aETK2IW/QABeQFgWaqWOs4tYR4vD8FgsZ5eBScKUlJqux50Rg6cRFdIw== X-Gm-Gg: ASbGncsqQjzpsVBgBU25Rnl0XNvZtsyQEKNEhhcciir5/sGvhRqO1/CikGIOrN7B/5N OU5bxLUCbEikqJFGSJgKT0HKaJE4FJgQlc24OCy5scpO5mH2ZCQxjh29faym2TzeDk/3JzXzOI/ A2fcqvOrFZukcV/HhEHbtSbldvy1REtcJta8UPwI0bmqpjF/nGbJDUddxqM9XOCLWfUCo91SVID EOqZMBYYBfQzwgOrtZAl+jUK9DWesT5WGFzBpeQl3AB6SpWRKYYl6Ht8MShha6EuYf2LkilCE0H K3A78WdoKYtuaPfiXGIzdlFeKItqMRV1RHw8AEcl+Qv3bXyWWjjh0PR+Kw== X-Google-Smtp-Source: AGHT+IEPu+g214qh6HyKpc9FbNm2wQshtagCkuKR9pSGN+w7eUUnIi/mwORZIcKOrfc87ef9uxr+kg== X-Received: by 2002:a05:6a21:78a7:b0:1f3:194b:30b0 with SMTP id adf61e73a8af0-1f544ad717cmr663232637.5.1741284106595; Thu, 06 Mar 2025 10:01:46 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Cc: qemu-devel@nongnu.org, =?UTF-8?q?Corvin=20K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 04/10] vfio/igd: Move LPC bridge initialization to a separate function Date: Fri, 7 Mar 2025 02:01:24 +0800 Message-ID: <20250306180131.32970-5-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250306180131.32970-1-tomitamoeko@gmail.com> References: <20250306180131.32970-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1741285646557019000 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alex Williamson Reviewed-by: Corvin K=C3=B6hne Tested-by: Alex Williamson --- 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; } =20 +static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice *vdev, Error **err= p) +{ + g_autofree struct vfio_region_info *host =3D NULL; + g_autofree struct vfio_region_info *lpc =3D 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 =3D 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 =3D vfio_get_dev_region_info(&vdev->vbasedev, + VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_I= NTEL, + 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 =3D vfio_get_dev_region_info(&vdev->vbasedev, + VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_I= NTEL, + VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG, &host); + if (ret) { + error_setg(errp, "IGD host bridge access is not supported by kerne= l"); + return false; + } + + /* Create/modify LPC bridge */ + ret =3D 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 =3D 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 =20 @@ -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 =3D NULL; - g_autofree struct vfio_region_info *host =3D NULL; - g_autofree struct vfio_region_info *lpc =3D 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, in= t nr) return; } =20 - /* - * 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 =3D 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 exis= ting " - "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, in= t nr) return; } =20 - /* - * Check whether we have all the vfio device specific regions to - * support legacy mode (added in Linux v4.6). If not, bail. - */ - ret =3D vfio_get_dev_region_info(&vdev->vbasedev, - VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_I= NTEL, - 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 =3D vfio_get_dev_region_info(&vdev->vbasedev, - VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_I= NTEL, - 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 =3D vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4); =20 /* @@ -533,19 +560,10 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, i= nt nr) return; } =20 - /* Create our LPC/ISA bridge */ - ret =3D 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 =3D 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; } =20 --=20 2.47.2 From nobody Wed Apr 2 13:11:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1741284224; cv=none; d=zohomail.com; s=zohoarc; b=nxn7lM0fTautSIpVF1Tj8jTb/WCJ4Woy7+DDOvzj+9ijmiJEfCs6D6x4HUVDRlpGKlrqEIRagNS7xtv+wsq9phyjandBpUIcrbVf+pVXjOE0TZ+X8z7vwnwK1TOSjyqNS92HNcV7hyB+lFyLyUr8ABuLY38BuknOmESsjop9pZA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741284224; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3PsFwF/uA/8VpOdWLdhwbP0WWGdT9opuyryY51WuBZk=; b=ObBWTK6Bqwk8+aqUwfmti0a3oYmpKrJYbWJlXNzjXixxggvTNPDUVO9SeRcQJhABlSZ+smISgN3CO8I+BGISFstTpmEY9G/W/benYOFHWytc3SksiNwsa8vkxCKolSF19puKwMWg9NPLCoozRx2EKn3OuJsy+kqtLaJT1R9tX/E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741284224591138.67967528412555; Thu, 6 Mar 2025 10:03:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tqFXo-00037H-2t; Thu, 06 Mar 2025 13:02:04 -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 1tqFXj-00034p-46 for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:02:00 -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 1tqFXb-00008G-02 for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:01:58 -0500 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-223959039f4so20660005ad.3 for ; Thu, 06 Mar 2025 10:01:49 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af28126db9bsm1338498a12.58.2025.03.06.10.01.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 10:01:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741284109; x=1741888909; 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=hK+ZbyUjkRa9YMQT7E4cd/Bbl24FSS3asy3+KC98MxwFfzdshRsg1d6GrAw5rGo5Ej EQXcB+I1im3UMLvd3DiVbadQHXyMv6vSKuezrRQJwdF7+ecZImBtC2oKqptf63m5FHam sgmfLtDBogSp6xl7E7dfFJwhU3wbFYXalHfdJ6C2ukew0AXI1plCo/ycVQRLGnzie84P kS+yKDT0tviZtbQ/vswEAn2v2TsvgQi9e3DwXuudVWeR5Q08wqFXDDovAkV6JZqabc6u BkeMgapW64fMoyyWdxxQh117h93SUowD8ZAkjh30wSEkIeNOkqldqkhMzyp9e+9ilE1N Gasg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741284109; x=1741888909; 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=UH++oawC9HkoYkts2VZiCSyD4LXq44F4bAP0tYcr+f5zD70fDQ/zv+2wkgcb2/X5/B oo3n379F22o38FQzYNKCWb1h0wb4VtIDY6jyz2gDMk/gO7E2bIX1vOfDyEX84EVMNveM h+COhzaJbQYT05qSYgwuEDp7T2PD6p8YZpDZ8mnwGj/a1KSuIgSfqs3ce8rTkNkEBAvY VbVGsgo6j8TfAzncUOzz47GRwDgdGw/Ux/yp4j5yXK1ZMMTin5wmFg/ihOMjwqQnE0Iu BZtSCV9yKQi0jrYjFz5fCcg8yTLmKBa+fW+FzwzcdB65Qu+XJRG7FbXs60G2YdtUmoBt Dtzg== X-Gm-Message-State: AOJu0YypM/LjgnyfS+tog21kyCoHvw17v2BAwAs2Oh343XYvbcs/J11k w10NBolv3197ZQgF4x1e/wTmM5kLvORox3UdczhZ7xaUC+Ds+JMKcm6JZ1TAGg== X-Gm-Gg: ASbGncsK7eWE62z6N+Vi9lLY0EGU6+ByHAeHd/h8jFQWTJQEPNmuY4JZ0Q01k/JqiSF HzmMqCU9vND8xzKsXi0cW3qErtP6TGjizC2J/zrHj1MsPUFfzu6bCP1MJuo/NexNMtt6ZWSjU8k qqlt6Xh6dbi9WNQ6kgGpqmk6tH33WGscPJKKMlAlofWRn/XF1IErfToox5FZQpQv/PgMo9t8UgC VA1Gbmddn+Rosg6fviaf0g/KhfNOtMF8ORwWoctVimxgjCWKpBZtV7oKFHujSEwwP2c8V5PbaV4 TRhoDGwWAT6RH2hoLon/saiLaDoLOdDkmsSGI6vDiW/gFxBi4Dm8+/5eTw== X-Google-Smtp-Source: AGHT+IEfDcc69/rQZ37g+UchCe2/B2HUPfGLw8hKwKNG8GOK0WX64d5JlT8EUw3LPpouNtdkCCParw== X-Received: by 2002:a05:6a21:7a43:b0:1f3:45f4:9ba0 with SMTP id adf61e73a8af0-1f544b1a99fmr853603637.25.1741284108739; Thu, 06 Mar 2025 10:01:48 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Cc: qemu-devel@nongnu.org, =?UTF-8?q?Corvin=20K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 05/10] vfio/pci: Add placeholder for device-specific config space quirks Date: Fri, 7 Mar 2025 02:01:25 +0800 Message-ID: <20250306180131.32970-6-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250306180131.32970-1-tomitamoeko@gmail.com> References: <20250306180131.32970-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1741284226569019100 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alex Williamson Reviewed-by: Corvin K=C3=B6hne Tested-by: Alex Williamson --- 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(VFIOPCIDev= ice *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 **er= rp) goto out_unset_idev; } =20 + 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, unsig= ned size); void vfio_vga_write(void *opaque, hwaddr addr, uint64_t data, unsigned siz= e); =20 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); --=20 2.47.2 From nobody Wed Apr 2 13:11:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1741284212; cv=none; d=zohomail.com; s=zohoarc; b=gK6y5YC1QNhE0U6fHjN6XL0fq1kNrLXDInhmzDH7LTWWWCyprULvdDq0ybOdu/yVvt855AVs8G2f9kkZ0prCN5akPxvZ4vE+KCUCfShFzaw6VjmDINyMyfEdunqAKVS/UgD/c3dRiG30M0rao2FCpdyzu2RJaB04Ng/1VWg8idk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741284212; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vFnj8MBzKLQ8mFbTFO8nM18EwA6rKViM/nHJPBpmhqc=; b=k7N4hjDqy09xzax3VpZ3k24V02njj5zX/AI9J9I1Y/4nbySJmJNthGzpHjlL71QLx9kFuAelWd+/TOLnGUnCHP1KF9CJ7M1NSOfts6WBre0xrgs9FVqF1sW5AV/5CtW5Bq2kdE29HklCOeNUiZW1uG8qGcEgPq89Y2dj6MD6rtY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741284212522337.12120772066226; Thu, 6 Mar 2025 10:03:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tqFXn-000362-7h; Thu, 06 Mar 2025 13:02: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 1tqFXj-00034q-4h for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:02:00 -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 1tqFXe-00008V-61 for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:01:58 -0500 Received: by mail-pl1-x643.google.com with SMTP id d9443c01a7336-2234e5347e2so19110315ad.1 for ; Thu, 06 Mar 2025 10:01:51 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af28126db9bsm1338498a12.58.2025.03.06.10.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 10:01:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741284111; x=1741888911; 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=mO4lEhpLWhlDCP7+JtFnniRWxCuYmrnJjocIpKVbCQlpFsaM5ap/HlgIjo8SehbuRo LnVwxKfoN30y1y7pGPII5WCCbBAE4XRMHz4nmKiIVXi8U0Jrg2PCkaz4zKJIvs6e4Jz6 BuvRLVMsGnhLXU6zSD2SGd/rKAgDfosW9pZv9OH98g/4mwbqCXE+tmpAxsvCepCLYlrO DvW6rNpAZH9yygfixxFWpttJKK6MIchLswWaB3xc2KPxqe5r+K6EsixEououfiLiejLs aYF2AgY0gDdEH6/3NnkYScWQA9ubqSo4A1ciHaRvTJBtC/J0hlbcbD+M8MLJwaYMHOrZ 1PiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741284111; x=1741888911; 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=AJY4syp5jJeit85FqLXYCxvlhPZ4U0MxI/iFF0/RAJBXlSFAB8DcyYSpxL/WTS7vzV QLzUJOYBUEm2bdepz6OZFbrOjI/Gvcwjkpx9VDg2FizeXbyyDVBZVQ5GOzoJlKNay22S bVXMd53ITzkWbOrxuoYZ1ZGsgzBka73yLBm+pvxZ2TNHfGBgs4G7IMW/7tEbAcMjucBN W6h/lkRueIqA231CofsHjpZYWuY/jSf4GpzCoA18AgOkjQFMqClBTxDox4QJd3q1peet QqHAX3Hpv2O1it/BcnF3AcmFlv2ZvXzgd2K77ljmz7r8/DnraeCzzn8xI7HQ9DL4Jt3x G8rg== X-Gm-Message-State: AOJu0Ywd11wW/TGmRi0/b+rWtK2gdZr9/Uimr8Uv1b6P9CvU69N97WTR n5KZBpC9TcuNEvDE5khtK+zYxPbhu+8vkXRH1Yaq7/FEHL40KSbVVrmr+H8JHQ== X-Gm-Gg: ASbGnctdi5k0sWNbigU6tNpSUr8rJegC3IcGnKBYmHsEz9kzP+jcA1IZpHMvur5SI6b Vnd5RJsyudoj5I+UoJeT4PrL+ersonpH6eCXc34HyMk1D5/vvCEn7QOZkmTuq1MJP43rJbXOugw 5PZfFY37A+Qh9dzZL9B1qYZ0uVa3SCsnO6Mr0LTQf00Bd4H6OCCnLbomdYSECK9ec/gmUymSdxL Zm5Xf8qzdG0NAJrU3KNy53LnXhNCwzp73zIKh8Ks4XHKwVY9nq3NRDh/9+p1UnaH6BI8Zzulhyc 1+/Eebm2GK+v9rw++NCfVT7Yy/CEn+DGbo8PW50P0xUgZJG5Si7viU6lFg== X-Google-Smtp-Source: AGHT+IENmvHsPrS0kwpU1Ma0bRKbiesz/Ltu41dNkcdERaesID4y1hrG6nk++9ARqOE67qzpfPT72Q== X-Received: by 2002:a05:6a20:7483:b0:1ee:d317:48e9 with SMTP id adf61e73a8af0-1f544ad8152mr675659637.6.1741284110856; Thu, 06 Mar 2025 10:01:50 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Cc: qemu-devel@nongnu.org, =?UTF-8?q?Corvin=20K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 06/10] vfio/igd: Refactor vfio_probe_igd_bar4_quirk into pci config quirk Date: Fri, 7 Mar 2025 02:01:26 +0800 Message-ID: <20250306180131.32970-7-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250306180131.32970-1-tomitamoeko@gmail.com> References: <20250306180131.32970-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1741284214699019100 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alex Williamson Reviewed-by: Corvin K=C3=B6hne Tested-by: Alex Williamson --- 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); } =20 -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 =3D NULL; int ret, gen; @@ -497,10 +498,10 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, i= nt nr) * PCI bus address. */ if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) || - !vfio_is_vga(vdev) || nr !=3D 4 || + !vfio_is_vga(vdev) || &vdev->pdev !=3D pci_find_device(pci_device_root_bus(&vdev->pdev), 0, PCI_DEVFN(0x2, 0))) { - return; + return true; } =20 /* @@ -512,7 +513,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) if (gen =3D=3D -1) { error_report("IGD device %s is unsupported in legacy mode, " "try SandyBridge or newer", vdev->vbasedev.name); - return; + return true; } =20 /* @@ -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; } =20 /* @@ -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 =3D true; - return; + return true; } =20 gmch =3D vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4); @@ -550,21 +551,21 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, i= nt 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; } =20 /* 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; } =20 /* 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; } =20 /* @@ -624,4 +625,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) } =20 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(VFIOPCIDev= ice *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; } =20 @@ -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 } =20 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 **er= rp); 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); =20 extern const PropertyInfo qdev_prop_nv_gpudirect_clique; =20 --=20 2.47.2 From nobody Wed Apr 2 13:11:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1741284196; cv=none; d=zohomail.com; s=zohoarc; b=I2MVo9QmFid249RM13uKwh4Dw8q0iEjqleuDO2lG7Cfwunr3W9KsYHsvboUCyncrImVQ37Bbi7T8mI5cbE30x82GJQ7Q4hkeKXAiba1mSJUeAqf19MsZdaMjtTwimJ8iXDaG8JIvZ5qPlDb5p+S26JWkpD5qyOMHC0XANkNA7os= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741284196; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KEzBw2eiAZv/edrA+dgMo//vRMLgwdY1/zctaB1iA3M=; b=Sr2Jxvb4X+c2Ig2WUou2pc/F+NqdnQOQ+0jLlePqJs4ZMEisQ36TYZ95UX3wrkvcU+bt1oB+B5VcsRsee4DV6Vc8fK81tjG9T446SsOTKT+EnjCKwmushnx1/zwOxBnmGN68P/bA/+f93wIT6BK1YhzEdaMHZVfaVGiaay/b3Ck= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741284196373391.3637168462793; Thu, 6 Mar 2025 10:03:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tqFXz-0003AH-E3; Thu, 06 Mar 2025 13:02:15 -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 1tqFXn-00036K-Dy for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:02:03 -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 1tqFXg-00009L-1d for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:02:03 -0500 Received: by mail-pl1-x642.google.com with SMTP id d9443c01a7336-2240b4de12bso24739285ad.2 for ; Thu, 06 Mar 2025 10:01:54 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af28126db9bsm1338498a12.58.2025.03.06.10.01.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 10:01:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741284113; x=1741888913; 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=KEzBw2eiAZv/edrA+dgMo//vRMLgwdY1/zctaB1iA3M=; b=kgM0rYOO/EenzGrH/IAfHbl6cLe2F/eFq+PlbUA/Y6dtzElS2HQ4cPmagXD27QhMSl 5db7EzgT8pwTAl9FlLKA/c/jMuPXWY1mMyGQboV1rfJ1QlwjtAZieffhoyved91sduli pQky0wXGqee0xsUJA8xKt9odSMPYeokEqHxoyaWwvZ47MBc2TeTw5F1WlbglaK3pEEpV wMOo/gCdo9NNvwtarXwuuEeoSBa4re5YafLIAIiI+3YJFM+0tEtRTWLdnP6QQlZ5Ke2C sgTUxsZa4jBmxa1Dew4etW4nRe7nUzbZQMrF01zFeWNQxx4h2fV0LEUyBpQDgbzQ2Oyq x0uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741284113; x=1741888913; 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=KEzBw2eiAZv/edrA+dgMo//vRMLgwdY1/zctaB1iA3M=; b=pb5Y2f0kjUKrk04QfYBOJk6CO64nR5jC+gAz6FGNtISxopR29nShkmYmBmjGFnvCv4 OTA2O87TvfbN1t4G+JkttBPnb+ob1ZVNuTO8Q0RN/sK6bOfuh7PIrLzcHohlVW2Yo/7R p9HYC3ubBysTaXKxdoIlAQ7IdhNMmOcElpEmqKCZDffJHue4BoztG9KwBmpZ8pFHY9Wl fppZrADPkvvGFbf06YBO64obm2YkaIlWFkY7B12fggv9c6sN8qRAD6JopqFIRyEz3AIq R75VbPYoaq8ikZ4LfcBIt/H9iFpVlg6W6ck1Cu5zdEYFQ8Vk3o6C8vYbg2weiTYHC2JV YSvQ== X-Gm-Message-State: AOJu0YyAYVZZJecmn5EYaUAJScGim7jDz3JGKqB+lb8HQVUr975AjMKj OGuWmzRDLYfFTYqR/YtN6aSwf6xAl93nHODX+cDXBVVhw+rRRlA= X-Gm-Gg: ASbGncso86D+84+DyA15lWSxaT9h0rFFJKL0d4tuczoWhgrN2anG542L8iuOPFK+Hj2 Sxb9GrP2QbF9aXjlAjeu6BRYdI7JZvTCKE5HyekV4anaDVj0EVpYS0NjWnwFem8I5lTfmq6sgoo Yrx9oCBNvc0FfRuPfnvZ11AIeyJGRSvzvIpxeFlt3RnmPnbaSai+ElzFCYNJwxhyPxzuKxbgylv GISTygZxrny+Y/D1wkECHvakEKfkfT0adpOlgZgGV5zUAgtB4nwPKua+6LzECSJ+j0enH1N+CYJ cwwM1XoHTASepudvEG2W+4vKR1aPptrltq2kGfgPngzTfvNdbRlrn307AA== X-Google-Smtp-Source: AGHT+IFu1mUXgHQDMjUHRZ2EOapE+Rk1wuT3ctevIZQQUOaG1F6EM8jl4VGMDc8otg2vr+k+clBBZA== X-Received: by 2002:a05:6a21:2d08:b0:1f3:47d6:aa05 with SMTP id adf61e73a8af0-1f5449336e0mr967761637.0.1741284113065; Thu, 06 Mar 2025 10:01:53 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Cc: qemu-devel@nongnu.org, =?UTF-8?q?Corvin=20K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 07/10] vfio/igd: Decouple common quirks from legacy mode Date: Fri, 7 Mar 2025 02:01:27 +0800 Message-ID: <20250306180131.32970-8-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250306180131.32970-1-tomitamoeko@gmail.com> References: <20250306180131.32970-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1741284203920019000 Content-Type: text/plain; charset="utf-8" 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 config option, x-igd-legacy-mode=3D[on|off|auto], is introduced to control the legacy mode only quirks. The default value is "auto", which keeps current behavior that enables legacy mode implicitly and continues on error when all following conditions are met. * Machine type is i440fx * IGD device is at guest BDF 00:02.0 If any one of the conditions above is not met, the default behavior is equivalent to "off", QEMU will fail immediately if any error occurs. Users can also use "on" to force enabling legacy mode. It checks if all the conditions above are met and set up legacy mode. QEMU will also fail immediately on error in this case. Additionally, the hotplug check in legacy mode is removed as hotplugging IGD device is never supported, and it will be checked when enabling the OpRegion quirk. Signed-off-by: Tomita Moeko Reviewed-by: Alex Williamson Reviewed-by: Corvin K=C3=B6hne Tested-by: Alex Williamson --- hw/vfio/igd.c | 127 +++++++++++++++++++++++++++++--------------------- hw/vfio/pci.c | 2 + hw/vfio/pci.h | 1 + 3 files changed, 77 insertions(+), 53 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index f5e19f1241..ac096e2eb5 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 !=3D 0 || - &vdev->pdev !=3D pci_find_device(pci_device_root_bus(&vdev->pdev), - 0, PCI_DEVFN(0x2, 0))) { + !vfio_is_vga(vdev) || nr !=3D 0) { return; } =20 @@ -482,14 +481,13 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, i= nt nr) QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, bdsm_quirk, next); } =20 -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 =3D NULL; int ret, gen; uint64_t gms_size; uint64_t *bdsm_size; uint32_t gmch; + bool legacy_mode_enabled =3D false; Error *err =3D NULL; =20 /* @@ -498,9 +496,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 !=3D pci_find_device(pci_device_root_bus(&vdev->pdev), - 0, PCI_DEVFN(0x2, 0))) { + !vfio_is_vga(vdev)) { return true; } =20 @@ -516,56 +512,67 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, return true; } =20 - /* - * 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 supp= ort. - */ - ret =3D 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 =3D true; - return true; - } - gmch =3D vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4); =20 /* - * If IGD VGA Disable is clear (expected) and VGA is not already enabl= ed, - * 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=3Doff */ - 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->igd_legacy_mode !=3D ON_OFF_AUTO_OFF) && + !strcmp(MACHINE_GET_CLASS(qdev_get_machine())->family, "pc_piix") = && + (&vdev->pdev =3D=3D pci_find_device(pci_device_root_bus(&vdev->pde= v), + 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 =3D NULL; + + legacy_mode_enabled =3D true; + warn_report("IGD legacy mode enabled, " + "use x-igd-legacy-mode=3Doff 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 su= pport. + */ + ret =3D vfio_get_region_info(&vdev->vbasedev, + VFIO_PCI_ROM_REGION_INDEX, &rom); + if ((ret || !rom->size) && !vdev->pdev.romfile) { + error_setg(&err, "Device has no ROM"); + goto error; + } =20 - /* 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 m= ode + * without VGA, but also no point in us enabling VGA if disabled in + * hardware. + */ + if (!(gmch & 0x2) && !vdev->vga && !vfio_populate_vga(vdev, &err))= { + error_setg(&err, "Unable to enable VGA access"); + goto error; + } =20 - /* 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, &err)) { + goto error; + } + + /* Setup LPC bridge / Host bridge PCI IDs */ + if (!vfio_pci_igd_setup_lpc_bridge(vdev, &err)) { + goto error; + } + } else if (vdev->igd_legacy_mode =3D=3D ON_OFF_AUTO_ON) { + error_setg(&err, + "Machine is not i440fx or assigned BDF is not 00:02.0"); + goto error; } =20 /* @@ -627,4 +634,18 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, (gms_size / MiB)); =20 return true; + +error: + /* + * When legacy mode is implicity enabled, continue on error, + * to keep compatibility + */ + if (legacy_mode_enabled && (vdev->igd_legacy_mode =3D=3D ON_OFF_AUTO_A= UTO)) { + error_report_err(err); + error_report("IGD legacy mode disabled"); + return true; + } + + error_propagate(errp, err); + return false; } diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index a58d555934..d5ff8c1ea8 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3363,6 +3363,8 @@ static const Property vfio_pci_dev_properties[] =3D { VFIO_FEATURE_ENABLE_REQ_BIT, true), DEFINE_PROP_BIT("x-igd-opregion", VFIOPCIDevice, features, VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT, false), + DEFINE_PROP_ON_OFF_AUTO("x-igd-legacy-mode", VFIOPCIDevice, + igd_legacy_mode, ON_OFF_AUTO_AUTO), 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..aa67ceb346 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -158,6 +158,7 @@ struct VFIOPCIDevice { uint32_t display_xres; uint32_t display_yres; int32_t bootindex; + OnOffAuto igd_legacy_mode; uint32_t igd_gms; OffAutoPCIBAR msix_relo; uint8_t pm_cap; --=20 2.47.2 From nobody Wed Apr 2 13:11:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1741286770; cv=none; d=zohomail.com; s=zohoarc; b=Bqnc8FG/tkyGbpavU/+dITpVcZg9DoXnhJbLhOmhZpOcCKzL4Vx38zJQADsX+PEfX6D6umjVvtKzibVS4t+pHiF+5WzYHmjOGeWlFKHcR8jyjkZPtozuqedv3K8rMFEGEmK/t+Ya0wXEWQQ9SqV7gpqcxPZ/SrE0BWoAZdQxIBc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741286770; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eYYJxJdIvSF4Ky9p+9rse8TFiw0pjojl4vD1VD595uU=; b=SakqSel9FXeZKT7Jd04RUQeb4O/obFxuOplFzfSYE0NAzQXXsV0XEghqkkcrmbr+sfnXigwK2TNoA1jbGMfjD/7r2obXcZsn+J8cUoaPNWwbm08xGGIIcjOVPnnE827qt24ffBQ0rQ9DFOnh2OOpl7yhtQYyIASWhiZvoNrgTvw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741286770691249.9812670405853; Thu, 6 Mar 2025 10:46:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tqFXy-00039D-5i; Thu, 06 Mar 2025 13:02: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 1tqFXk-000351-SV for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:02:00 -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 1tqFXh-00009k-3f for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:01:59 -0500 Received: by mail-pl1-x643.google.com with SMTP id d9443c01a7336-2234e5347e2so19112005ad.1 for ; Thu, 06 Mar 2025 10:01:56 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af28126db9bsm1338498a12.58.2025.03.06.10.01.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 10:01:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741284115; x=1741888915; 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=eYYJxJdIvSF4Ky9p+9rse8TFiw0pjojl4vD1VD595uU=; b=f7YZ9ox3iMuams7tvI8vToqiRPHzlr7WkWFzjLsd/QUZG6zLXb75E1qy2xyZ8gn4DC Pf1YTxzds+wVk9DY4VmqyoeW0WYvxNkPrx3u9i5O2r4oMmug/25QBUaBdrgoip9cOSP1 ld88s1+DmbJIJZ8imengsXrsghdH/JimjVTBhc319TWJOg/jrqc6ErYP2XkKlf+ZdLZm BB/JxihRdZeItELdBseW3GnNmibKbgAswRAOpXODSZLl+1tLRw9Yt4whwp04XTzKL9II 78RajEcWWdpc6ggG6U4R+ZxZ34l9luAEG6HgHbtnIs/928FOE0lBBB0pNCk/MhwnfmAZ Y5Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741284115; x=1741888915; 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=eYYJxJdIvSF4Ky9p+9rse8TFiw0pjojl4vD1VD595uU=; b=NVCrqaLx3Aq0KwcMk0LDPw0PcF//4m+oziLOkNjufSqRzzYeSaz9Zh6NpPP2AsFIJS cDD2aJ2jzIpMEZfPVvZuzNjBetYbNB5AmfIQaFOeUCyDHUrsNXMXy3q4eOG3MXf3/NGY vUX7SOIa0U2kvWwib0q4xMKH4SOZenKeThWnrTgtCHKTBuXleGFUimgjFgC629rny02v bHJTnP6WKLBuSH18H3+vbWCmJ3m/b1uLI66eJn5vsDES09DNCrTy03H4YYnQvPRuWCTx 4XvInfki40CEaSTN15/MLNqQxJPW6yERc/hebzR+T0F7reA58HLKKDXexfH8RRn28n+D AaXw== X-Gm-Message-State: AOJu0Yz2pUKx9K9Wnv4eWlzeUo4xh5Jo04j2c38YY26DRmcLXG2tN5X+ 2+p0nUHC4W2KBtH1THr4SVmqpU/Yg0ck2f0FCm190OrKbdy93fp7J/fjpAPq3Q== X-Gm-Gg: ASbGncvRSlLKly1+ViJ4jFo0vW3/j0+2CFzkjw1nq6MXTgcHDbMant2MCz7+gBtl4KG x9jq5FisfsgbPaWbCnWDABYjf3oovE1ZxDf86QIudneDaKl7z1KNE0lWcw6N1x9hi/GvEeZs0vB TpS340nem9A/Y1lpcus+831zqZxDPHFVAhY9UKuFyZcC8WzBSUcD7PGyWkoeBhjVOUcdHzGKVni eMgYuAD2Oj8eDdlIaSJGufuc7OQ5s58dslMI7V0odsL5oxj/cYVRAdESYdbu3mIOGiMWAiz9P+7 Y3TjQ6GbswYcNyZ1GuIsMnbFyDT2e6qmexI0BkSE/CNfzxMghh0pQL/4Eg== X-Google-Smtp-Source: AGHT+IE5vjZRx0YZHmWBZwEbjSAcMKl8mF/L61t494cETcOszhDUKoHE4uGo13GBYBYV3SAE5VbCVQ== X-Received: by 2002:a05:6a21:a49:b0:1f3:3e91:fad2 with SMTP id adf61e73a8af0-1f544af8695mr734006637.13.1741284115137; Thu, 06 Mar 2025 10:01:55 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Cc: qemu-devel@nongnu.org, =?UTF-8?q?Corvin=20K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 08/10] vfio/igd: Handle x-igd-opregion option in config quirk Date: Fri, 7 Mar 2025 02:01:28 +0800 Message-ID: <20250306180131.32970-9-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250306180131.32970-1-tomitamoeko@gmail.com> References: <20250306180131.32970-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1741286772231019000 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alex Williamson Reviewed-by: Corvin K=C3=B6hne Tested-by: Alex Williamson --- 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 ac096e2eb5..4c3862b61e 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -189,7 +189,7 @@ static bool vfio_pci_igd_opregion_init(VFIOPCIDevice *v= dev, return true; } =20 -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 =3D NULL; int ret; @@ -560,10 +560,8 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, = Error **errp) goto error; } =20 - /* Setup OpRegion access */ - if (!vfio_pci_igd_setup_opregion(vdev, &err)) { - goto error; - } + /* Enable OpRegion quirk */ + vdev->features |=3D VFIO_FEATURE_ENABLE_IGD_OPREGION; =20 /* Setup LPC bridge / Host bridge PCI IDs */ if (!vfio_pci_igd_setup_lpc_bridge(vdev, &err)) { @@ -575,6 +573,12 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, = Error **errp) goto error; } =20 + /* Setup OpRegion access */ + if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) && + !vfio_pci_igd_setup_opregion(vdev, errp)) { + goto error; + } + /* * Allow user to override dsm size using x-igd-gms option, in multiple= s 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 d5ff8c1ea8..c9a484fa68 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3136,15 +3136,6 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) vfio_bar_quirk_setup(vdev, i); } =20 -#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 aa67ceb346..0d0a18136a 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -230,8 +230,6 @@ int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev, =20 bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp); =20 -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); --=20 2.47.2 From nobody Wed Apr 2 13:11:07 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1741284196; cv=none; d=zohomail.com; s=zohoarc; b=LaoTyLKFhH5u3ysSUolngMWUjTBSNaCuk7KLMtYXgYoRdLdqEW5GzLmVa+qRA0Yxj97L0JEQjqOAMRIFUSfL2TK8Z4wVOhKnMnLfSY+DwxPXPquCTm5bp23n6hwUbx8jxW8gCWvovWb3txBIQ3z3HQwTiDnzQR65FBYPuL2IZnQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741284196; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=T8M9rnvjJnQ63p7IcHB549w9iy3Ic13BvRR7pu9O0E8=; b=d7ek+7e6Rp/oZeeS/H7NfrAm7B9SIJOclLN8Rs2YasC/IVOYEUtoblIls/PqQfqDoyIex0erfD/dzwHF4dOtV/ngPiMVDxNhMkdBHIBAkt3+b7i68QkmZ7Kz7osahhmjLxEjI1hTGExBtPOQkvu9fg9y/Oktq1pGm0wBS0guR8M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741284196374274.4013340278776; Thu, 6 Mar 2025 10:03:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tqFY2-0003AU-8a; Thu, 06 Mar 2025 13:02:18 -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 1tqFXn-000369-0X for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:02:03 -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 1tqFXi-0000As-Su for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:02:02 -0500 Received: by mail-pl1-x642.google.com with SMTP id d9443c01a7336-224171d6826so18100635ad.3 for ; Thu, 06 Mar 2025 10:01:58 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af28126db9bsm1338498a12.58.2025.03.06.10.01.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 10:01:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741284117; x=1741888917; 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=T8M9rnvjJnQ63p7IcHB549w9iy3Ic13BvRR7pu9O0E8=; b=EK5fqMjyWCgEKmBTVf3RJkdLdpel7yHGrGorohiLSLmAf8IgWopixGm3PZy36sx0LO DwLasSv6QHq0FO4yKCcihgAyJqq2QLnmsbzgIR6uV2uRnYTwzYKEfKYV9H1xkpprgnhE X2etTxSzoyJ5aag330QII61Ba2lb7NsvdX3CmvFNsDo6yxzYkoeG3r1rxN6NBLEne8wa MtZFOjf3MGHLzS1gApNZCFyDpWHefPb8OvFUvbPv9VgVWGDXppDDaLA+gqH/t2U+9HiH LNgLdk47mrxZWeEDDgJYummAz/rQDep6n/h1p1aci1M+BoU1/7l28WknJfdzGPqfnpOT eOdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741284117; x=1741888917; 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=T8M9rnvjJnQ63p7IcHB549w9iy3Ic13BvRR7pu9O0E8=; b=Kzwu7tpSulsvFdfHwaFeTeKebgzBA9D0HFFyII3mTJdmJFI90UvZCLgWJdLs7laWoM UNy/ME3mSzfKo8CvM6qjAYiRFL3uDtNGiYhwYIA2T0FtQ2zXNvjf3b9GakRk8b1bs54Q EDvL+kZT1dVBJk8qdGGwKKstZ1DYH7XXD7AgRkaR3xiJj38C660stlxtuixUZxnfXIZS HRchiOwWv6ozJq5IsKXCAEFqL7xSF+eWrBbYrpioAzDxYslRHHCUPpOQ08ILoVeoF1zH zAXzcI1odrLxkmz4w1w+YpZr0Bn4m2RYsJTxNae5mWGozaGsPR4deOr2pqIEKm7P6O3w Oaqw== X-Gm-Message-State: AOJu0Yy9sVI9cW8qDq7HlWC0K7rLDea6BXVp3pIVUIIcnyMhJC4d0a78 RxbC/Ses8t16T653subwQ7GN7RJFrUX5KCB45l13EXQtbq9bZBk= X-Gm-Gg: ASbGncuRPQEfFthdpbmVNCtbZRfGDpw2WlO3SnrsXzLulkzkzS9ZU0Q21EM6oOk9uCX +YhCjOZXxK0u6RiOOAsLZ/JuJNIUZJS+4lRgQaVAc2wy0B6IKVRvJogZMwjjKgKbpEDocdy08KH DMD8xzPceDIHV00I/mYs9ceWCGQdkuxPoneWkmPgim/6kWICQ0nDGgZ7sih0iPXTJAOM+MucyHg DX3x40Zrhs+MpV/yUKUubuBcza1+1R8DJkE29vob9PTbiC4vyNQtYn1VKrsVHYWQ/RzZDOhfCT+ bns8R2Z4eBGQwIW+dNQUAseAWN1hC33FIHwcU7jc+NAAMBNaOcP5ubKddg== X-Google-Smtp-Source: AGHT+IHIDHEzv65ld05hZ0sLqC+sutNGyUBEHk3QWa4OJK8rzqKl3agUH7dUa2yHvPjNUu15zeyaig== X-Received: by 2002:a17:902:ccca:b0:223:fabd:4f76 with SMTP id d9443c01a7336-224289946c6mr2838485ad.30.1741284117189; Thu, 06 Mar 2025 10:01:57 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Cc: qemu-devel@nongnu.org, =?UTF-8?q?Corvin=20K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 09/10] vfio/igd: Introduce x-igd-lpc option for LPC bridge ID quirk Date: Fri, 7 Mar 2025 02:01:29 +0800 Message-ID: <20250306180131.32970-10-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250306180131.32970-1-tomitamoeko@gmail.com> References: <20250306180131.32970-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1741284203801019000 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alex Williamson Reviewed-by: Corvin K=C3=B6hne Tested-by: Alex Williamson --- 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 4c3862b61e..6775ce2eac 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -560,13 +560,9 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, = Error **errp) goto error; } =20 - /* Enable OpRegion quirk */ + /* Enable OpRegion and LPC brige quirk */ vdev->features |=3D VFIO_FEATURE_ENABLE_IGD_OPREGION; - - /* Setup LPC bridge / Host bridge PCI IDs */ - if (!vfio_pci_igd_setup_lpc_bridge(vdev, &err)) { - goto error; - } + vdev->features |=3D VFIO_FEATURE_ENABLE_IGD_LPC; } else if (vdev->igd_legacy_mode =3D=3D ON_OFF_AUTO_ON) { error_setg(&err, "Machine is not i440fx or assigned BDF is not 00:02.0"); @@ -579,6 +575,12 @@ bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, = Error **errp) goto error; } =20 + /* Setup LPC bridge / Host bridge PCI IDs */ + if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_LPC) && + !vfio_pci_igd_setup_lpc_bridge(vdev, errp)) { + goto error; + } + /* * Allow user to override dsm size using x-igd-gms option, in multiple= s 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 c9a484fa68..d16cc5cc90 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3354,6 +3354,8 @@ static const Property vfio_pci_dev_properties[] =3D { VFIO_FEATURE_ENABLE_REQ_BIT, true), DEFINE_PROP_BIT("x-igd-opregion", VFIOPCIDevice, features, VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT, false), + DEFINE_PROP_BIT("x-igd-lpc", VFIOPCIDevice, features, + VFIO_FEATURE_ENABLE_IGD_LPC_BIT, false), DEFINE_PROP_ON_OFF_AUTO("x-igd-legacy-mode", VFIOPCIDevice, igd_legacy_mode, ON_OFF_AUTO_AUTO), DEFINE_PROP_ON_OFF_AUTO("enable-migration", VFIOPCIDevice, diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 0d0a18136a..a87333f3d5 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -154,6 +154,9 @@ struct VFIOPCIDevice { #define VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT 2 #define VFIO_FEATURE_ENABLE_IGD_OPREGION \ (1 << VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT) +#define VFIO_FEATURE_ENABLE_IGD_LPC_BIT 3 +#define VFIO_FEATURE_ENABLE_IGD_LPC \ + (1 << VFIO_FEATURE_ENABLE_IGD_LPC_BIT) OnOffAuto display; uint32_t display_xres; uint32_t display_yres; --=20 2.47.2 From nobody Wed Apr 2 13:11:07 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1741287431; cv=none; d=zohomail.com; s=zohoarc; b=ZUXRp3GnXqgzwkJkmI10KZhP0auXw+hF/smkQS3HbzgLURd7rB3EDCJUKJ9kCGOWXZ2rQp4HirSb2KSddZdkpOUkFxeivgoo784dFvf45QzACZfUCH78LdYjqBJrWxJEY9xnuAeEdb4zpKu1PK6w2iqusd81zF4meSAYP5+rtFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741287431; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+jrFIingrAbF5dij+VV01pN3aIuY/zKM1+KpxvGbRKI=; b=KzAOIuQ3ePB9oE0awXzEnVujMghZPXT6csv3wNEjT0NsAb12b+6AfH3r08a96GFpwgzAYS06rQBBz16uBXvmadGhOx6IpWg6j1nyIjKXv7RKM+IHw2d0jcwrQVBtT5D0x/Qo4sFylPN7jV1vejVwd7qHqWiVDEJRsVBpFjBjvK0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741287431538871.8350935240313; Thu, 6 Mar 2025 10:57:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tqFY0-0003AL-9A; Thu, 06 Mar 2025 13:02:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tqFXn-00036Z-IY for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:02:03 -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 1tqFXl-0000DN-OL for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:02:03 -0500 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-22401f4d35aso18439285ad.2 for ; Thu, 06 Mar 2025 10:02:01 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af28126db9bsm1338498a12.58.2025.03.06.10.01.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 10:01:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741284120; x=1741888920; 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=+jrFIingrAbF5dij+VV01pN3aIuY/zKM1+KpxvGbRKI=; b=BffE7O73YHCSxxL38icGoNCj2UY8CVfCkDJtA6aHAU8UdT6mRBC/Iu7j9g2N2qyjYH GccGPcOueWLZWyBKClMTY1GD75BcMDZV63sIqjC80paTXOj/F8ev/s0UqIdE4zaPXcss uBsqYlMmtXsb7pVCwgOieZINHdw/+y2VTwSsUhK+BG8y4kdqtiwqHz3nUbLXpHUkIiK7 yGh9Ko9qvBDYe+rtyr1j2G0a325JX8qaZZ3qgNwmW+rX4PlWzQRdqT7UJe/PAls2c89O TTLeve3Ks2DAUty2z1WRVNLPlrtFEWLF3bw99PRv9A4wvb1mw7UGvXZmJDtWmSbu1Ces TjSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741284120; x=1741888920; 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=+jrFIingrAbF5dij+VV01pN3aIuY/zKM1+KpxvGbRKI=; b=IJyLkO6L0Q2uGjfCNkKBjxMFisFVqxSLxw1CvrLTN6qalt7nvm3wh+EDTu7ZPbR9Gj HTRXVl/CVXaxh0VFFA8dtNLRVglgHTZjEwue0jnevieai+JBeQfnuBccwZb2p7lzi/kk FdJfWqsGNY+pItXc7c/1Tk0DTZENZQOGtjFReS/xI37IDc9UzbL9dIHTdnR1guzub5Uq e+vvRRgntYcFoqQi2/aNKEI35FxaCgJT00dBqOXcJQNPKAiCSs8PM5hO8QuROWwWRhit VwHhQyt+WvWTxb5C10N6oQV8fN8BPw7eXDQ3Fv7LlNzVcQNjL7rSNH7PTaljyhkxnx5n OFlg== X-Gm-Message-State: AOJu0YxTnTR5eYk8ubBFvoU3+3MX62Ryr4C5kaaVxzwvUlMUnYZCkJr4 a4VQw+YYEesQycWwW2ET/F/wl3Hhl4CpbPn6PK17Yxx/D/OPfkQ= X-Gm-Gg: ASbGncuZ+n21sw6R/kkGCiQQi52zlyTe/kKqdXmRDoK9zcOR6KEazsfZlk/ttiw/rz0 V58uEOHtbPy0sSKvdKuqR6r/a8inU6wUD/+K4UeObWe8RhUCZIpeUk0y95xklnqsv7+hHl0oQ2i f45SAKITZVVNYladu14V3/fhfdv6d/iYoHDxx5LNcSZYMieE2RgfIxNnMGHjt/Ns9wCBBnhqsHT x2TH2laK3WoTcAvqLqDvqBeibYW68zGMHj8aKkHoyITC1TuDX3oMFb2dNTCxLMxOJr7m7WuwZnk W73pjy2UcLPv41qz1lZc0IRnREFRStZHjzi4UX90nwvOwTV49il8uChXRA== X-Google-Smtp-Source: AGHT+IGM+vtzTBAbn3N/cHyXCI95F0tCreWUJsk8cg2uorxSD5Tj6eRkaJiFjpeTcqP8yizysmsBbg== X-Received: by 2002:a17:90b:1b0b:b0:2fa:e9b:33b8 with SMTP id 98e67ed59e1d1-2ff7ce989dcmr336874a91.18.1741284119206; Thu, 06 Mar 2025 10:01:59 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Cc: qemu-devel@nongnu.org, =?UTF-8?q?Corvin=20K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 10/10] vfio/igd: Fix broken KVMGT OpRegion support Date: Fri, 7 Mar 2025 02:01:30 +0800 Message-ID: <20250306180131.32970-11-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250306180131.32970-1-tomitamoeko@gmail.com> References: <20250306180131.32970-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1741287433973019000 Content-Type: text/plain; charset="utf-8" The KVMGT/GVT-g vGPU also exposes OpRegion. But unlike IGD passthrough, it only needs the OpRegion quirk. A previous change moved x-igd-opregion handling to config quirk breaks KVMGT functionality as it brings extra checks and applied other quirks. Here we check if the device is mdev (KVMGT) or not (passthrough), and then applies corresponding quirks. As before, users must manually specify x-igd-opregion=3Don to enable it on KVMGT devices. In the future, we may check the VID/DID and enable OpRegion automatically. Signed-off-by: Tomita Moeko Reviewed-by: Alex Williamson Reviewed-by: Corvin K=C3=B6hne Tested-by: Alex Williamson --- hw/vfio/igd.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 6775ce2eac..4c5d6a016b 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -481,7 +481,7 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int= nr) QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, bdsm_quirk, next); } =20 -bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp) +static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp) { int ret, gen; uint64_t gms_size; @@ -655,3 +655,28 @@ error: error_propagate(errp, err); return false; } + +/* + * KVMGT/GVT-g vGPU exposes an emulated OpRegion. So far, users have to sp= ecify + * x-igd-opregion=3Don to enable the access. + * TODO: Check VID/DID and enable opregion access automatically + */ +static bool vfio_pci_kvmgt_config_quirk(VFIOPCIDevice *vdev, Error **errp) +{ + if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) && + !vfio_pci_igd_setup_opregion(vdev, errp)) { + return false; + } + + return true; +} + +bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp) +{ + /* KVMGT/GVT-g vGPU is exposed as mdev */ + if (vdev->vbasedev.mdev) { + return vfio_pci_kvmgt_config_quirk(vdev, errp); + } + + return vfio_pci_igd_config_quirk(vdev, errp); +} --=20 2.47.2