From patchwork Thu Aug 22 11:08:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Corvin_K=C3=B6hne?= X-Patchwork-Id: 13773233 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0FC10C54722 for ; Thu, 22 Aug 2024 11:24:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sh5v3-00081r-3k; Thu, 22 Aug 2024 07:23:57 -0400 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 1sh5uz-000800-4C for qemu-devel@nongnu.org; Thu, 22 Aug 2024 07:23:53 -0400 Received: from netsrv01.beckhoff.com ([62.159.14.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sh5ux-00035I-1A for qemu-devel@nongnu.org; Thu, 22 Aug 2024 07:23:52 -0400 Received: from 172.17.5.170 by netsrv01.beckhoff.com (Tls12, Aes256, Sha384, DiffieHellmanEllipticKey384); Thu, 22 Aug 2024 11:18:47 GMT DKIM-Signature: v=1; c=relaxed/relaxed; d=beckhoff.com; s=mail2022e; t=1724325527; bh=dw5PZHWoP2rzADIQR+kXL/3fIW9nweVv3qfNfRdXkvc=; h= Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id; a=ed25519-sha256; b= kWR/p8E1onAwPsiJOGVZ2nb3lzu9tDs0Jl6BPeTJ9eEY7mU0gqdX9VUwfb1NPJi3WTKzD7r79Ld45HIj85ITDw== DKIM-Signature: v=1; c=relaxed/relaxed; d=beckhoff.com; s=mail2022r; t=1724325527; bh=dw5PZHWoP2rzADIQR+kXL/3fIW9nweVv3qfNfRdXkvc=; h= Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id; a=rsa-sha256; b= raaLW5tcWy3JgbPEVhV5nGgClqjRMdNehdkTUOu3GTqIgsDGswEV6v7wTAr2IVRaUcAy4ibqF+TOGe45Vhyq/Gxp0+SS7sbtevda9JgW+3/9FlT5+w8x9RFU+7AjgD7k4FbPfOlR2CwGSLtt4NOBWKkQgbwExSqzJXZwHPEh1OTjjNPP6jvBPmjXys1DtGR8kl/XUVDnqmxDwzPy6VTS6SNN0AG0UxKIP41ZoSl1usGUzH2yGQitTCU6RoFf98LBaXbudLQyyhi/Y1MKI0qMP8O5Tp88q5XP+mSh8UJrkm0f915L198d+tS7IMSnAVtffw/Rh4icSL2/Fa0jPBUx2w== Received: from corvink-nb.c.koehne.headscale.beckhoff.dev (172.17.61.20) by ex04.beckhoff.com (172.17.5.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 22 Aug 2024 13:18:45 +0200 From: =?utf-8?q?Corvin_K=C3=B6hne?= To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Subject: [PATCH 1/7] vfio/igd: return an invalid generation for unknown devices Date: Thu, 22 Aug 2024 13:08:26 +0200 Message-ID: <20240822111819.34306-2-c.koehne@beckhoff.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240822111819.34306-1-c.koehne@beckhoff.com> References: <20240822111819.34306-1-c.koehne@beckhoff.com> MIME-Version: 1.0 X-Originating-IP: [172.17.61.20] X-ClientProxiedBy: ex01.beckhoff.com (172.17.2.168) To ex04.beckhoff.com (172.17.5.170) X-OLX-Disclaimer: EX04.BECKHOFF.COM Received-SPF: pass client-ip=62.159.14.10; envelope-from=C.Koehne@beckhoff.com; helo=netsrv01.beckhoff.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Intel changes it's specification quite often e.g. the location and size of the BDSM register has change for gen 11 devices and later. This causes our emulation to fail on those devices. So, it's impossible for us to use a suitable default value for unknown devices. Instead of returning a random generation value and hoping that everthing works fine, we should verify that different devices are working and add them to our list of known devices. Signed-off-by: Corvin Köhne --- hw/vfio/igd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index d320d032a7..650a323dda 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -90,7 +90,11 @@ static int igd_gen(VFIOPCIDevice *vdev) return 8; } - return 8; /* Assume newer is compatible */ + /* + * Unfortunately, Intel changes it's specification quite often. This makes + * it impossible to use a suitable default value for unknown devices. + */ + return -1; } typedef struct VFIOIGDQuirk { From patchwork Thu Aug 22 11:08:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Corvin_K=C3=B6hne?= X-Patchwork-Id: 13773229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6298CC5320E for ; Thu, 22 Aug 2024 11:24:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sh5v6-00088r-9c; Thu, 22 Aug 2024 07:24:00 -0400 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 1sh5v1-000811-ED for qemu-devel@nongnu.org; Thu, 22 Aug 2024 07:23:55 -0400 Received: from netsrv01.beckhoff.com ([62.159.14.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sh5uz-00035I-L8 for qemu-devel@nongnu.org; Thu, 22 Aug 2024 07:23:55 -0400 Received: from 172.17.5.170 by netsrv01.beckhoff.com (Tls12, Aes256, Sha384, DiffieHellmanEllipticKey384); Thu, 22 Aug 2024 11:18:47 GMT DKIM-Signature: v=1; c=relaxed/relaxed; d=beckhoff.com; s=mail2022e; t=1724325527; bh=AWbZyhEyhRSnXlYcrTmec6OE0eilRfZnjfvknaWGikc=; h= Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id; a=ed25519-sha256; b= Z9dmkT9WkwrOCkEd48M54Ukez3tvQaKBftghlKrE4316v8W6h95JB/7u40f+2PhAr3KxuFgrEKh0WdxlLDpoBQ== DKIM-Signature: v=1; c=relaxed/relaxed; d=beckhoff.com; s=mail2022r; t=1724325527; bh=AWbZyhEyhRSnXlYcrTmec6OE0eilRfZnjfvknaWGikc=; h= Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id; a=rsa-sha256; b= FHlzjauIl3Lc2nGih3lK2Ew1LhnAYXvoje45y2t0gWCF5sPwARqLOi8x58cNlFfLY98C7XvZk/raIU62oeWvYPYTMm6JRTCz/vmQ2meuqWbXcSUKQc3rueZP75JlFh6WyosIXdR04BSxM3mhCoBQqMIqQKfuQ84A8myEHdNjZHlBJv+vSBnqeqFskLaHSEmzUzds1Sfn6QIUpUeZL2Q0zOzy9J3aA34cz6RPoX0q3h4APMIlViIiud+wzg1IreOlmkUP9vZEvypfT7RyXS4CIAw40wmFBt8xnY5pEJb9m0WuPS01DKCCqsLi0c8SN5B8eBc/VUMmEjaspTDOR2+8Eg== Received: from corvink-nb.c.koehne.headscale.beckhoff.dev (172.17.61.20) by ex04.beckhoff.com (172.17.5.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 22 Aug 2024 13:18:45 +0200 From: =?utf-8?q?Corvin_K=C3=B6hne?= To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Subject: [PATCH 2/7] vfio/igd: support legacy mode for all known generations Date: Thu, 22 Aug 2024 13:08:27 +0200 Message-ID: <20240822111819.34306-3-c.koehne@beckhoff.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240822111819.34306-1-c.koehne@beckhoff.com> References: <20240822111819.34306-1-c.koehne@beckhoff.com> MIME-Version: 1.0 X-Originating-IP: [172.17.61.20] X-ClientProxiedBy: ex01.beckhoff.com (172.17.2.168) To ex04.beckhoff.com (172.17.5.170) X-OLX-Disclaimer: EX04.BECKHOFF.COM Received-SPF: pass client-ip=62.159.14.10; envelope-from=C.Koehne@beckhoff.com; helo=netsrv01.beckhoff.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We're soon going to add support for legacy mode to ElkhartLake and TigerLake devices. Those are gen 11 and 12 devices. At the moment, all devices identified by our igd_gen function do support legacy mode. This won't change when adding our new devices of gen 11 and 12. Therefore, it makes more sense to accept legacy mode for all known devices instead of maintaining a long list of known good generations. If we add a new generation to igd_gen which doesn't support legacy mode for some reason, it'll be easy to advance the check to reject legacy mode for this specific generation. Signed-off-by: Corvin Köhne --- hw/vfio/igd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 650a323dda..d5e57656a8 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -416,7 +416,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) * devices maintain compatibility with generation 8. */ gen = igd_gen(vdev); - if (gen != 6 && gen != 8) { + if (gen == -1) { error_report("IGD device %s is unsupported in legacy mode, " "try SandyBridge or newer", vdev->vbasedev.name); return; From patchwork Thu Aug 22 11:08:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Corvin_K=C3=B6hne?= X-Patchwork-Id: 13773232 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01811C52D7C for ; Thu, 22 Aug 2024 11:24:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sh5v7-0008Lc-U3; Thu, 22 Aug 2024 07:24:01 -0400 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 1sh5v2-00081q-NY for qemu-devel@nongnu.org; Thu, 22 Aug 2024 07:23:56 -0400 Received: from netsrv01.beckhoff.com ([62.159.14.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sh5v0-00035m-E4 for qemu-devel@nongnu.org; Thu, 22 Aug 2024 07:23:56 -0400 Received: from 172.17.5.170 by netsrv01.beckhoff.com (Tls12, Aes256, Sha384, DiffieHellmanEllipticKey384); Thu, 22 Aug 2024 11:18:48 GMT DKIM-Signature: v=1; c=relaxed/relaxed; d=beckhoff.com; s=mail2022e; t=1724325528; bh=7yYl05lZacMAh3tZlu2XKHEwlxzsHcRZiBDxfb3o9dE=; h= Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id; a=ed25519-sha256; b= Zryj9VyxiMxrTqpJPCgGKXAOTZ7WGiQcbOQRSdVzs6ktjwv9fC+/x4lCenqvjaivIVn4ioT/BOJZW3S4qGJMCw== DKIM-Signature: v=1; c=relaxed/relaxed; d=beckhoff.com; s=mail2022r; t=1724325528; bh=7yYl05lZacMAh3tZlu2XKHEwlxzsHcRZiBDxfb3o9dE=; h= Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id; a=rsa-sha256; b= JnessnGXxQLupbFF5mUsnvSIX3XnqKKhR5rejxSkAyGQXkBJYHfRsK0Hc6Xvk7G5qsLcNybjppIoxa0PCoO+PEaJ/gjP35V3etC/SWssO1pqlpxe0cqDRXyrJIYIQVArFpFIP9RlbWtEQbUhXwPXC86kKeRuPxdlxnzngyBgjUF1xzcmiPRi2sqJOrgoHg2twWtKUb/aJudrVLGTWXM7XlXiVJA/z/5D2u/NHAFGfAjUGG/Ba2TFNUfRwXwAPTAiyRfObFlzv62mg8XwOLCojyybXwWi2OHdMOFNkOQiLmK/Oh/Bq14vH/5o06vF3JOoFXHBy9JdowYsdYNu/OwEGw== Received: from corvink-nb.c.koehne.headscale.beckhoff.dev (172.17.61.20) by ex04.beckhoff.com (172.17.5.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 22 Aug 2024 13:18:45 +0200 From: =?utf-8?q?Corvin_K=C3=B6hne?= To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Subject: [PATCH 3/7] vfio/igd: use new BDSM register location and size for gen 11 and later Date: Thu, 22 Aug 2024 13:08:28 +0200 Message-ID: <20240822111819.34306-4-c.koehne@beckhoff.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240822111819.34306-1-c.koehne@beckhoff.com> References: <20240822111819.34306-1-c.koehne@beckhoff.com> MIME-Version: 1.0 X-Originating-IP: [172.17.61.20] X-ClientProxiedBy: ex01.beckhoff.com (172.17.2.168) To ex04.beckhoff.com (172.17.5.170) X-OLX-Disclaimer: EX04.BECKHOFF.COM Received-SPF: pass client-ip=62.159.14.10; envelope-from=C.Koehne@beckhoff.com; helo=netsrv01.beckhoff.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Intel changed the location and size of the BDSM register for gen 11 devices and later. We have to adjust our emulation for these devices to properly support them. Signed-off-by: Corvin Köhne --- hw/vfio/igd.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index d5e57656a8..0b6533bbf7 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -100,11 +100,12 @@ static int igd_gen(VFIOPCIDevice *vdev) typedef struct VFIOIGDQuirk { struct VFIOPCIDevice *vdev; uint32_t index; - uint32_t bdsm; + uint64_t bdsm; } VFIOIGDQuirk; #define IGD_GMCH 0x50 /* Graphics Control Register */ #define IGD_BDSM 0x5c /* Base Data of Stolen Memory */ +#define IGD_BDSM_GEN11 0xc0 /* Base Data of Stolen Memory of gen 11 and later */ /* @@ -313,9 +314,13 @@ static void vfio_igd_quirk_data_write(void *opaque, hwaddr addr, */ if ((igd->index % 4 == 1) && igd->index < vfio_igd_gtt_max(vdev)) { if (gen < 8 || (igd->index % 8 == 1)) { - uint32_t base; + uint64_t base; - base = pci_get_long(vdev->pdev.config + IGD_BDSM); + if (gen < 11) { + base = pci_get_long(vdev->pdev.config + IGD_BDSM); + } else { + base = pci_get_quad(vdev->pdev.config + IGD_BDSM_GEN11); + } if (!base) { hw_error("vfio-igd: Guest attempted to program IGD GTT before " "BIOS reserved stolen memory. Unsupported BIOS?"); @@ -519,7 +524,13 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) igd = quirk->data = g_malloc0(sizeof(*igd)); igd->vdev = vdev; igd->index = ~0; - igd->bdsm = vfio_pci_read_config(&vdev->pdev, IGD_BDSM, 4); + if (gen < 11) { + igd->bdsm = vfio_pci_read_config(&vdev->pdev, IGD_BDSM, 4); + } else { + igd->bdsm = vfio_pci_read_config(&vdev->pdev, IGD_BDSM_GEN11, 4); + igd->bdsm |= + (uint64_t)vfio_pci_read_config(&vdev->pdev, IGD_BDSM_GEN11 + 4, 4) << 32; + } igd->bdsm &= ~((1 * MiB) - 1); /* 1MB aligned */ memory_region_init_io(&quirk->mem[0], OBJECT(vdev), &vfio_igd_index_quirk, @@ -577,9 +588,15 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) pci_set_long(vdev->emulated_config_bits + IGD_GMCH, ~0); /* BDSM is read-write, emulated. The BIOS needs to be able to write it */ - pci_set_long(vdev->pdev.config + IGD_BDSM, 0); - pci_set_long(vdev->pdev.wmask + IGD_BDSM, ~0); - pci_set_long(vdev->emulated_config_bits + IGD_BDSM, ~0); + if (gen < 11) { + pci_set_long(vdev->pdev.config + IGD_BDSM, 0); + pci_set_long(vdev->pdev.wmask + IGD_BDSM, ~0); + pci_set_long(vdev->emulated_config_bits + IGD_BDSM, ~0); + } else { + pci_set_quad(vdev->pdev.config + IGD_BDSM_GEN11, 0); + pci_set_quad(vdev->pdev.wmask + IGD_BDSM_GEN11, ~0); + pci_set_quad(vdev->emulated_config_bits + IGD_BDSM_GEN11, ~0); + } /* * This IOBAR gives us access to GTTADR, which allows us to write to From patchwork Thu Aug 22 11:08:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Corvin_K=C3=B6hne?= X-Patchwork-Id: 13773230 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5A23AC3DA4A for ; Thu, 22 Aug 2024 11:24:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sh5v4-00083f-Qb; Thu, 22 Aug 2024 07:23:58 -0400 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 1sh5v2-00081N-Fk for qemu-devel@nongnu.org; Thu, 22 Aug 2024 07:23:56 -0400 Received: from netsrv01.beckhoff.com ([62.159.14.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sh5v0-00035l-Dt for qemu-devel@nongnu.org; Thu, 22 Aug 2024 07:23:56 -0400 Received: from 172.17.5.170 by netsrv01.beckhoff.com (Tls12, Aes256, Sha384, DiffieHellmanEllipticKey384); Thu, 22 Aug 2024 11:18:48 GMT DKIM-Signature: v=1; c=relaxed/relaxed; d=beckhoff.com; s=mail2022e; t=1724325528; bh=51g5v0YASy9hVByXKdNTFlH8GhBPc80zGQ+RejMqEuw=; h= Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id; a=ed25519-sha256; b= CuceMlyIjYx0zPQVCeHdeftVUpQOBQRgciV1ZO9PHRP0WG6WbJkkOhpXYfwZKdeZ/tvJn6oO+YiDSa3hhMa8Dw== DKIM-Signature: v=1; c=relaxed/relaxed; d=beckhoff.com; s=mail2022r; t=1724325528; bh=51g5v0YASy9hVByXKdNTFlH8GhBPc80zGQ+RejMqEuw=; h= Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id; a=rsa-sha256; b= F1Zs27GyFHZwvmD0vTgKtIS0O0mw2deg8VviA59jHLKG+MwF8KwhsqgoLnCbU7WKmaOc8EbOddg4knK7+26P4ib38Fn7CnRnk2SaIJOV1r90f5sUax52wGcWhfxf6m1MuEf7Ov5ZC30XUuU6xw/Sv++jUCCNUPRHEUEogdcGmtOZkY3msmK4UUVcALWFIFGUSC+jA4Wt6dasT79TuYzVM+fOSTsc3PYVuRXllYcUCH+ToUcMvSj/2s7+iDKIsiVQpFlvFPcjgptNb6XTXSGMEd8CR+EDbjePS/ti9aIQtEgKOApdb9ovzC9IKhWjuSLRVQnPbNm+TVTvOaRcRfcaPA== Received: from corvink-nb.c.koehne.headscale.beckhoff.dev (172.17.61.20) by ex04.beckhoff.com (172.17.5.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 22 Aug 2024 13:18:45 +0200 From: =?utf-8?q?Corvin_K=C3=B6hne?= To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Subject: [PATCH 4/7] vfio/igd: add new bar0 quirk to emulate BDSM mirror Date: Thu, 22 Aug 2024 13:08:29 +0200 Message-ID: <20240822111819.34306-5-c.koehne@beckhoff.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240822111819.34306-1-c.koehne@beckhoff.com> References: <20240822111819.34306-1-c.koehne@beckhoff.com> MIME-Version: 1.0 X-Originating-IP: [172.17.61.20] X-ClientProxiedBy: ex01.beckhoff.com (172.17.2.168) To ex04.beckhoff.com (172.17.5.170) X-OLX-Disclaimer: EX04.BECKHOFF.COM Received-SPF: pass client-ip=62.159.14.10; envelope-from=C.Koehne@beckhoff.com; helo=netsrv01.beckhoff.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The BDSM register is mirrored into MMIO space at least for gen 11 and later devices. Unfortunately, the Windows driver reads the register value from MMIO space instead of PCI config space for those devices [1]. Therefore, we either have to keep a 1:1 mapping for the host and guest address or we have to emulate the MMIO register too. Using the igd in legacy mode is already hard due to it's many constraints. Keeping a 1:1 mapping may not work in all cases and makes it even harder to use. An MMIO emulation has to trap the whole MMIO page. This makes accesses to this page slower compared to using second level address translation. Nevertheless, it doesn't have any constraints and I haven't noticed any performance degradation yet making it a better solution. [1] https://github.com/projectacrn/acrn-hypervisor/blob/5c351bee0f6ae46250eefc07f44b4a31e770f3cf/devicemodel/hw/pci/passthrough.c#L650-L653 Signed-off-by: Corvin Köhne --- hw/vfio/igd.c | 97 ++++++++++++++++++++++++++++++++++++++++++++ hw/vfio/pci-quirks.c | 1 + hw/vfio/pci.h | 1 + 3 files changed, 99 insertions(+) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 0b6533bbf7..863b58565e 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -374,6 +374,103 @@ static const MemoryRegionOps vfio_igd_index_quirk = { .endianness = DEVICE_LITTLE_ENDIAN, }; +#define IGD_BDSM_MMIO_OFFSET 0x1080C0 + +static uint64_t vfio_igd_quirk_bdsm_read(void *opaque, + hwaddr addr, unsigned size) +{ + VFIOPCIDevice *vdev = opaque; + uint64_t offset; + + offset = IGD_BDSM_GEN11 + addr; + + switch (size) { + case 1: + return pci_get_byte(vdev->pdev.config + offset); + case 2: + return le16_to_cpu(pci_get_word(vdev->pdev.config + offset)); + case 4: + return le32_to_cpu(pci_get_long(vdev->pdev.config + offset)); + case 8: + return le64_to_cpu(pci_get_quad(vdev->pdev.config + offset)); + default: + hw_error("igd: unsupported read size, %u bytes", size); + break; + } + + return 0; +} + +static void vfio_igd_quirk_bdsm_write(void *opaque, hwaddr addr, + uint64_t data, unsigned size) +{ + VFIOPCIDevice *vdev = opaque; + uint64_t offset; + + offset = IGD_BDSM_GEN11 + addr; + + switch (size) { + case 1: + pci_set_byte(vdev->pdev.config + offset, data); + break; + case 2: + pci_set_word(vdev->pdev.config + offset, data); + break; + case 4: + pci_set_long(vdev->pdev.config + offset, data); + break; + case 8: + pci_set_quad(vdev->pdev.config + offset, data); + break; + default: + hw_error("igd: unsupported read size, %u bytes", size); + break; + } +} + +static const MemoryRegionOps vfio_igd_bdsm_quirk = { + .read = vfio_igd_quirk_bdsm_read, + .write = vfio_igd_quirk_bdsm_write, + .endianness = DEVICE_LITTLE_ENDIAN, +}; + +void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) +{ + VFIOQuirk *quirk; + int gen; + + /* + * This must be an Intel VGA device at address 00:02.0 for us to even + * consider enabling legacy mode. Some driver have dependencies on the PCI + * bus address. + */ + if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) || + !vfio_is_vga(vdev) || nr != 0 || + &vdev->pdev != pci_find_device(pci_device_root_bus(&vdev->pdev), + 0, PCI_DEVFN(0x2, 0))) { + return; + } + + /* + * Only on IGD devices of gen 11 and above, the BDSM register is mirrored + * into MMIO space and read from MMIO space by the Windows driver. + */ + gen = igd_gen(vdev); + if (gen < 11) { + return; + } + + quirk = vfio_quirk_alloc(1); + quirk->data = vdev; + + memory_region_init_io(&quirk->mem[0], OBJECT(vdev), &vfio_igd_bdsm_quirk, + vdev, "vfio-igd-bdsm-quirk", 8); + memory_region_add_subregion_overlap(vdev->bars[0].region.mem, 0x1080C0, + &quirk->mem[0], 1); + + QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, quirk, next); +} + void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) { g_autofree struct vfio_region_info *rom = NULL; diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c index 39dae72497..d37f722cce 100644 --- a/hw/vfio/pci-quirks.c +++ b/hw/vfio/pci-quirks.c @@ -1259,6 +1259,7 @@ void vfio_bar_quirk_setup(VFIOPCIDevice *vdev, int nr) vfio_probe_nvidia_bar0_quirk(vdev, nr); vfio_probe_rtl8168_bar2_quirk(vdev, nr); #ifdef CONFIG_VFIO_IGD + vfio_probe_igd_bar0_quirk(vdev, nr); vfio_probe_igd_bar4_quirk(vdev, nr); #endif } diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index bf67df2fbc..5ad090a229 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -215,6 +215,7 @@ void vfio_setup_resetfn_quirk(VFIOPCIDevice *vdev); bool vfio_add_virt_caps(VFIOPCIDevice *vdev, Error **errp); void vfio_quirk_reset(VFIOPCIDevice *vdev); VFIOQuirk *vfio_quirk_alloc(int nr_mem); +void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr); void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr); extern const PropertyInfo qdev_prop_nv_gpudirect_clique; From patchwork Thu Aug 22 13:54:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Corvin_K=C3=B6hne?= X-Patchwork-Id: 13773557 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 42E40C3DA4A for ; Thu, 22 Aug 2024 13:56:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sh8HH-0002DX-CK; Thu, 22 Aug 2024 09:55:03 -0400 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 1sh8HF-00025S-I5 for qemu-devel@nongnu.org; Thu, 22 Aug 2024 09:55:01 -0400 Received: from netsrv01.beckhoff.com ([62.159.14.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sh8H8-0002ap-OI for qemu-devel@nongnu.org; Thu, 22 Aug 2024 09:55:01 -0400 Received: from 172.17.5.170 by netsrv01.beckhoff.com (Tls12, Aes256, Sha384, DiffieHellmanEllipticKey384); Thu, 22 Aug 2024 13:54:52 GMT DKIM-Signature: v=1; c=relaxed/relaxed; d=beckhoff.com; s=mail2022e; t=1724334892; bh=ObKhh5ctOrQTCNzAWvBPR008LcANC1kNYVDOEchZxFY=; h= Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id; a=ed25519-sha256; b= J6kz2J7HZkLZofhLCF6cc1w95UwHRpSFjk7zXSdXOftTJROUdQC+/gg4wTCeEaG9BErXLKQ++tVROI6oXb8ICg== DKIM-Signature: v=1; c=relaxed/relaxed; d=beckhoff.com; s=mail2022r; t=1724334892; bh=ObKhh5ctOrQTCNzAWvBPR008LcANC1kNYVDOEchZxFY=; h= Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id; a=rsa-sha256; b= OaABsvv+duGFbQyGkISYsSIDiYrX54nIt9nC5NridEctBeoHVBLVRgiLHkvShwhAUOGHmyb2KUn8x6la4/jtPlvyQZ76rRiIDGq5Zeyl9HVj0gkt27Z7O6t+RgtQQhZ/xQYFLvU+jE/kbE2hZ6RwYMInLAY1s3cK6HX0VwtnW7/ZNWaJjac6h/mjQLTDw7Z/M8UpBdmo2QVEPeOZxGXjfow4CSfB7RuJhDqR8P87/Es6r2h+uSTrl86AadTJd8EEq0RcwqS2Op5f8ixB6J707GqMJsHBjlzedj1kDgZmTHus0Wy7Su5serQdZDeS8nLqrVVeI9b19vBXnJtcYL+hBA== Received: from corvink-nb.c.koehne.headscale.beckhoff.dev (172.17.61.20) by ex04.beckhoff.com (172.17.5.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 22 Aug 2024 15:54:50 +0200 From: =?utf-8?q?Corvin_K=C3=B6hne?= To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Subject: [PATCH 5/7] vfio/igd: add ID's for ElkhartLake and TigerLake Date: Thu, 22 Aug 2024 15:54:14 +0200 Message-ID: <20240822135420.58849-5-c.koehne@beckhoff.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240822111819.34306-1-c.koehne@beckhoff.com> References: <20240822111819.34306-1-c.koehne@beckhoff.com> MIME-Version: 1.0 X-Originating-IP: [172.17.61.20] X-ClientProxiedBy: ex04.beckhoff.com (172.17.5.170) To ex04.beckhoff.com (172.17.5.170) X-OLX-Disclaimer: EX04.BECKHOFF.COM Received-SPF: pass client-ip=62.159.14.10; envelope-from=C.Koehne@beckhoff.com; helo=netsrv01.beckhoff.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org ElkhartLake and TigerLake devices were tested in legacy mode with Linux and Windows VMs. Both are working properly. It's likely that other Intel GPUs of gen 11 and 12 like IceLake device are working too. However, we're only adding known good devices for now. Signed-off-by: Corvin Köhne --- hw/vfio/igd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 863b58565e..84b0ec3139 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -88,6 +88,12 @@ static int igd_gen(VFIOPCIDevice *vdev) case 0x2200: case 0x5900: return 8; + /* ElkhartLake */ + case 0x4500: + return 11; + /* TigerLake */ + case 0x9A00: + return 12; } /* From patchwork Thu Aug 22 13:54:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Corvin_K=C3=B6hne?= X-Patchwork-Id: 13773558 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C390EC5321D for ; Thu, 22 Aug 2024 13:56:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sh8HI-0002GM-1q; Thu, 22 Aug 2024 09:55:04 -0400 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 1sh8HF-000278-S0 for qemu-devel@nongnu.org; Thu, 22 Aug 2024 09:55:01 -0400 Received: from netsrv01.beckhoff.com ([62.159.14.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sh8H8-0002aq-Na for qemu-devel@nongnu.org; Thu, 22 Aug 2024 09:55:01 -0400 Received: from 172.17.5.170 by netsrv01.beckhoff.com (Tls12, Aes256, Sha384, DiffieHellmanEllipticKey384); Thu, 22 Aug 2024 13:54:52 GMT DKIM-Signature: v=1; c=relaxed/relaxed; d=beckhoff.com; s=mail2022e; t=1724334892; bh=vZpI2KX970FCkxh4TIH5tOCE+9k5HnXqH3orDbOlCUg=; h= Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id; a=ed25519-sha256; b= ll4BqYlLqTjnTIpoEMlnysz2Hh/5mf/bEGRFUesyLXYBAZmQcbMIFfMcFsryXiCuIVjM+ZuPu1wvIguszRGpBQ== DKIM-Signature: v=1; c=relaxed/relaxed; d=beckhoff.com; s=mail2022r; t=1724334892; bh=vZpI2KX970FCkxh4TIH5tOCE+9k5HnXqH3orDbOlCUg=; h= Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id; a=rsa-sha256; b= JaEZc710jg0Zx6A6IciK7U5NAC1EWre9ETzGNZ/9WsVcYyBci6ZQfIgkAeTQF5ZkkNSRkOfS4wE0XtS/b78D7eWrF6QfmBfHuWqV7Q7UNGCv/1mv4fckEfpD7sw0PlFI5ruyLxQlJfkwJ4vr3Q3/tSbfLzrvXWSRsbuBC6KHVfFzhgjEWqohOnRqKwffIkMk3pnMO0j98t77bM/d8T8NlrwbFModFDpJDPbfKjcdKS+Y2e+E0dI11n+Oqlm+/KQyu2LA0ghx9uYH+HdYazqVvYy+dUByTn7AQwY1mMLh7A7r0GX2KMqgam1NiD0CRZeEE5XjdWkIZBfH5ssN8D4QEQ== Received: from corvink-nb.c.koehne.headscale.beckhoff.dev (172.17.61.20) by ex04.beckhoff.com (172.17.5.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 22 Aug 2024 15:54:50 +0200 From: =?utf-8?q?Corvin_K=C3=B6hne?= To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Subject: [PATCH 6/7] vfio/igd: don't set stolen memory size to zero Date: Thu, 22 Aug 2024 15:54:15 +0200 Message-ID: <20240822135420.58849-6-c.koehne@beckhoff.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240822111819.34306-1-c.koehne@beckhoff.com> References: <20240822111819.34306-1-c.koehne@beckhoff.com> MIME-Version: 1.0 X-Originating-IP: [172.17.61.20] X-ClientProxiedBy: ex04.beckhoff.com (172.17.5.170) To ex04.beckhoff.com (172.17.5.170) X-OLX-Disclaimer: EX04.BECKHOFF.COM Received-SPF: pass client-ip=62.159.14.10; envelope-from=C.Koehne@beckhoff.com; helo=netsrv01.beckhoff.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The stolen memory is required for the GOP (EFI) driver and the Windows driver. While the GOP driver seems to work with any stolen memory size, the Windows driver will crash if the size doesn't match the size allocated by the host BIOS. For that reason, it doesn't make sense to overwrite the stolen memory size. It's true that this wastes some VM memory. In the worst case, the stolen memory can take up more than a GB. However, that's uncommon. Additionally, it's likely that a bunch of RAM is assigned to VMs making use of GPU passthrough. Signed-off-by: Corvin Köhne --- hw/vfio/igd.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 84b0ec3139..122432e6a6 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -477,6 +477,23 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, quirk, next); } +static int igd_get_stolen_mb(int gen, uint32_t gmch) +{ + int gms; + + if (gen < 8) { + gms = (gmch >> 3) & 0x1f; + } else { + gms = (gmch >> 8) & 0xff; + } + + if (gms > 0x10) { + error_report("Unsupported IGD GMS value 0x%x", gms); + return 0; + } + return gms * 32; +} + void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) { g_autofree struct vfio_region_info *rom = NULL; @@ -654,23 +671,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) ggms_mb = 1 << ggms_mb; } - /* - * Assume we have no GMS memory, but allow it to be overridden by device - * option (experimental). The spec doesn't actually allow zero GMS when - * when IVD (IGD VGA Disable) is clear, but the claim is that it's unused, - * so let's not waste VM memory for it. - */ - gmch &= ~((gen < 8 ? 0x1f : 0xff) << (gen < 8 ? 3 : 8)); - - if (vdev->igd_gms) { - if (vdev->igd_gms <= 0x10) { - gms_mb = vdev->igd_gms * 32; - gmch |= vdev->igd_gms << (gen < 8 ? 3 : 8); - } else { - error_report("Unsupported IGD GMS value 0x%x", vdev->igd_gms); - vdev->igd_gms = 0; - } - } + gms_mb = igd_get_stolen_mb(gen, gmch); /* * Request reserved memory for stolen memory via fw_cfg. VM firmware From patchwork Thu Aug 22 13:54:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Corvin_K=C3=B6hne?= X-Patchwork-Id: 13773556 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DA337C5320E for ; Thu, 22 Aug 2024 13:55:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sh8HF-00026w-UY; Thu, 22 Aug 2024 09:55:01 -0400 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 1sh8HE-00020T-Cj for qemu-devel@nongnu.org; Thu, 22 Aug 2024 09:55:00 -0400 Received: from netsrv01.beckhoff.com ([62.159.14.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sh8H8-0002au-Nh for qemu-devel@nongnu.org; Thu, 22 Aug 2024 09:55:00 -0400 Received: from 172.17.5.170 by netsrv01.beckhoff.com (Tls12, Aes256, Sha384, DiffieHellmanEllipticKey384); Thu, 22 Aug 2024 13:54:53 GMT DKIM-Signature: v=1; c=relaxed/relaxed; d=beckhoff.com; s=mail2022e; t=1724334893; bh=d/oIKbgF+x1vzJ0O29d6n+1kiRF+USqgvvZ8Zv6x47M=; h= Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id; a=ed25519-sha256; b= xc1CJLE5vOWYcqapPneyywVp7LYbWlzH9PT0qGJR7xow1zauX0sJ0EqbZTCbJJgKHKqsTM1Mx/o1ehixzVe3DA== DKIM-Signature: v=1; c=relaxed/relaxed; d=beckhoff.com; s=mail2022r; t=1724334893; bh=d/oIKbgF+x1vzJ0O29d6n+1kiRF+USqgvvZ8Zv6x47M=; h= Subject:Subject:From:From:Date:Date:ReplyTo:ReplyTo:Cc:Cc:Message-Id:Message-Id; a=rsa-sha256; b= WxfFUSi9TEcqaIIw/4qnuQ6LBj5GGKFHC5WtYo39J7WtKFrVWFBtXZTY2Ki8qJvwN6fJNAsgHq3Vq+PEFFMt1udXcEsWKkzTeS+GC0jZYkQtW+iadba5BbXO3PRZezFlHbKK7DpgcRNkk29FdP/+4T1mwGDoskRfAw6muZ4xx5qI8KervgpgPSauII+fB7xJfwzUoBgDwShjlu0yzxAvNJUMKpo6acRrD1qwgR7BhfaKXI4zK6yCxL3YGtXC20iN2+7Sv+Z5rubOgnzociD7gK/2BktIYMt5TDJnaJMUILXhQ2NXsHKiVBXkUbAmCmnVQrzAwdHmrtK3DKPxhRuVUg== Received: from corvink-nb.c.koehne.headscale.beckhoff.dev (172.17.61.20) by ex04.beckhoff.com (172.17.5.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 22 Aug 2024 15:54:50 +0200 From: =?utf-8?q?Corvin_K=C3=B6hne?= To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= Subject: [PATCH 7/7] vfio/igd: correctly calculate stolen memory size for gen 9 and later Date: Thu, 22 Aug 2024 15:54:16 +0200 Message-ID: <20240822135420.58849-7-c.koehne@beckhoff.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240822111819.34306-1-c.koehne@beckhoff.com> References: <20240822111819.34306-1-c.koehne@beckhoff.com> MIME-Version: 1.0 X-Originating-IP: [172.17.61.20] X-ClientProxiedBy: ex04.beckhoff.com (172.17.5.170) To ex04.beckhoff.com (172.17.5.170) X-OLX-Disclaimer: EX04.BECKHOFF.COM Received-SPF: pass client-ip=62.159.14.10; envelope-from=C.Koehne@beckhoff.com; helo=netsrv01.beckhoff.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We have to update the calculation of the stolen memory size because we've seen devices using values of 0xf0 and above for the graphics mode select field. The new calculation was taken from the linux kernel [1]. [1] https://github.com/torvalds/linux/blob/7c626ce4bae1ac14f60076d00eafe71af30450ba/arch/x86/kernel/early-quirks.c#L455-L460 Signed-off-by: Corvin Köhne --- hw/vfio/igd.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 122432e6a6..70c60fe7bc 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -487,11 +487,18 @@ static int igd_get_stolen_mb(int gen, uint32_t gmch) gms = (gmch >> 8) & 0xff; } - if (gms > 0x10) { - error_report("Unsupported IGD GMS value 0x%x", gms); - return 0; + if (gen < 9) { + if (gms > 0x10) { + error_report("Unsupported IGD GMS value 0x%x", gms); + return 0; + } + return gms * 32; + } else { + if (gms < 0xf0) + return gms * 32; + else + return gms * 4 + 4; } - return gms * 32; } void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)