From patchwork Mon Jan 9 23:08:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Zmudzinski X-Patchwork-Id: 13094497 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 7FA0CC5479D for ; Mon, 9 Jan 2023 23:08:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.474080.735000 (Exim 4.92) (envelope-from ) id 1pF1Fu-0008Eu-4v; Mon, 09 Jan 2023 23:08:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 474080.735000; Mon, 09 Jan 2023 23:08:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pF1Fu-0008En-1S; Mon, 09 Jan 2023 23:08:38 +0000 Received: by outflank-mailman (input) for mailman id 474080; Mon, 09 Jan 2023 23:08:36 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pF1Fs-0008EZ-Aa for xen-devel@lists.xenproject.org; Mon, 09 Jan 2023 23:08:36 +0000 Received: from sonic313-20.consmr.mail.gq1.yahoo.com (sonic313-20.consmr.mail.gq1.yahoo.com [98.137.65.83]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 897301bb-9072-11ed-91b6-6bf2151ebd3b; Tue, 10 Jan 2023 00:08:34 +0100 (CET) Received: from sonic.gate.mail.ne1.yahoo.com by sonic313.consmr.mail.gq1.yahoo.com with HTTP; Mon, 9 Jan 2023 23:08:31 +0000 Received: by hermes--production-ne1-7b69748c4d-bgkrh (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 21a3ec8339abfccbadeaea4f5ef812e7; Mon, 09 Jan 2023 23:08:29 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 897301bb-9072-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1673305711; bh=PUsS/L6kSgEs9TSDYOSdibVZnoomFtUQ/2FTOn4ShZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=elXzfvBDLs+x3PQygRw4UOuVqtKHJNztSmeANXFZPKbkjXODD9HVpM6UngsfZNCsUNy2JDgYBHu+ln6Crtg2AcIwICBkBig4MOQJgkIIALddShN1H8ppOWXhxpZFtNqAuktS00wFZqfg6lJ6O7PfrQUbnQy0ZmqYChoK6Pm/JDcuDg8YuX85J6rdPWZxmc4dFbvcBTZ8lNd98XtbK9IBE9yBkNvF1HtzZ7S1SL46zDEXLUHwWJPNfgXiTkS5gbbxVINtGupzdxS50bsCoBeI//O5rV9YHJX+IKfI4jk4NELWBvL+SQWSxj+i/SA3aO3s1dV/gFfSo1b5xBUMVvwpEg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1673305711; bh=Du1eQd5e3lE/n5cyxqbZF1SqsJq9/TIrud4RmL1t+rv=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=EqV1L9DzWBpmfjNT6DFmkvoslb9Tg0hh8943F8fvkbDYhCgCHBpJqoQVumBZeY08ibePhnHlkXpveZRSrdMUqytQo4u9kfYqyZ4+ckXTdRhBMZv7gbcYA4SVCYJzBsWUZrnkJqGHd6LaUdQljLqlh2ca1JDIcwOebu/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JBiU8lEi.PTkvvrndoMMkcNT FKNq3xtVB9mbkLGjx8sAacZ2EKKgW7CWr00ZiKJ4i1HAr07bBOr3_XHixAPdjvatOjV2v7gZx0Ck aZFUySehhNN1lNz5X8EswtAZFZq5T2lH9HLQ2S4i75t4Q2cNs7ODtY.g3jKIMDhqLn4A9_yKNiGJ XMeJayOJhqZPcG5XrpWz4z9UXG58tS9o_Ya_Dtfa.34.FheRV02vFB6U5PxAmgzQDh8uiUwNSxag oaut6Sy1dy9cuOPNcK6SsGMswTpB5v9zuBBiHSObxx9i.GtyqTuPLrMU5Jvv4un9CeKPy X-Sonic-MF: From: Chuck Zmudzinski To: anthony.perard@citrix.com Cc: xen-devel@lists.xenproject.org, Wei Liu , Juergen Gross , qemu-devel@nongnu.org Subject: [XEN PATCH 1/3] libxl/dm: Use "pc" machine type for Intel IGD passthrough Date: Mon, 9 Jan 2023 18:08:11 -0500 Message-Id: X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 The default qemu upstream "xenfv" machine type that is used when an HVM guest is configured for Intel IGD passthrough assigns slot 2 to the xen platform pci device. It is a requirement that slot 2 be assigned to the Intel IGD when it is passed through as the primary graphics adapter. Using the "pc" machine type instead of the "xenfv" machine type in that case makes it possible for qemu upstream to assign slot 2 to the IGD. Using the qemu "pc" machine and adding the xen platform device on the qemu command line instead of using the qemu "xenfv" machine which automatically adds the xen platform device earlier in the guest creation process does come with some degredation of startup performance: startup is slower and some vga drivers in use during early boot are unable to display the screen at the native resolution of the monitor, but once the guest operating system (Windows or Linux) is fully loaded, there is no noticeable difference in the performance of the guest when using the "pc" machine type instead of the "xenfv" machine type. With this patch, libxl continues to use default "xenfv" machine type with the default settings of xen_platform_pci enabled and igd gfx_passthru disabled. The patch only affects machines configured with gfx_passthru enabled. Signed-off-by: Chuck Zmudzinski --- Reviewers might find this patch easier to review by looking at the resulting code in the patched file instead of looking at the diff because it is hard to follow the logical flow of the resulting code in the diff because the patch moves the check for igd gfx_passthru before the check for disabling the xen platform device. That change was made because it results in a more simplified logical flow in the resulting code. tools/libs/light/libxl_dm.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c index fc264a3a13..2048815611 100644 --- a/tools/libs/light/libxl_dm.c +++ b/tools/libs/light/libxl_dm.c @@ -1809,7 +1809,26 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, flexarray_append(dm_args, b_info->extra_pv[i]); break; case LIBXL_DOMAIN_TYPE_HVM: - if (!libxl_defbool_val(b_info->u.hvm.xen_platform_pci)) { + if (libxl_defbool_val(b_info->u.hvm.gfx_passthru)) { + enum libxl_gfx_passthru_kind gfx_passthru_kind = + libxl__detect_gfx_passthru_kind(gc, guest_config); + switch (gfx_passthru_kind) { + case LIBXL_GFX_PASSTHRU_KIND_IGD: + /* + * Using the machine "pc" because with the default machine "xenfv" + * the xen-platform device will be assigned to slot 2, but with + * GFX_PASSTHRU_KIND_IGD, slot 2 needs to be reserved for the Intel IGD. + */ + machinearg = libxl__strdup(gc, "pc,accel=xen,suppress-vmdesc=on,igd-passthru=on"); + break; + case LIBXL_GFX_PASSTHRU_KIND_DEFAULT: + LOGD(ERROR, guest_domid, "unable to detect required gfx_passthru_kind"); + return ERROR_FAIL; + default: + LOGD(ERROR, guest_domid, "invalid value for gfx_passthru_kind"); + return ERROR_INVAL; + } + } else if (!libxl_defbool_val(b_info->u.hvm.xen_platform_pci)) { /* Switching here to the machine "pc" which does not add * the xen-platform device instead of the default "xenfv" machine. */ @@ -1831,22 +1850,6 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, } } - if (libxl_defbool_val(b_info->u.hvm.gfx_passthru)) { - enum libxl_gfx_passthru_kind gfx_passthru_kind = - libxl__detect_gfx_passthru_kind(gc, guest_config); - switch (gfx_passthru_kind) { - case LIBXL_GFX_PASSTHRU_KIND_IGD: - machinearg = GCSPRINTF("%s,igd-passthru=on", machinearg); - break; - case LIBXL_GFX_PASSTHRU_KIND_DEFAULT: - LOGD(ERROR, guest_domid, "unable to detect required gfx_passthru_kind"); - return ERROR_FAIL; - default: - LOGD(ERROR, guest_domid, "invalid value for gfx_passthru_kind"); - return ERROR_INVAL; - } - } - flexarray_append(dm_args, machinearg); for (i = 0; b_info->extra_hvm && b_info->extra_hvm[i] != NULL; i++) flexarray_append(dm_args, b_info->extra_hvm[i]); From patchwork Mon Jan 9 23:08:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Zmudzinski X-Patchwork-Id: 13094499 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 CE161C63797 for ; Mon, 9 Jan 2023 23:08:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.474082.735022 (Exim 4.92) (envelope-from ) id 1pF1Fx-0000KR-U2; Mon, 09 Jan 2023 23:08:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 474082.735022; Mon, 09 Jan 2023 23:08:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pF1Fx-0000KE-P5; Mon, 09 Jan 2023 23:08:41 +0000 Received: by outflank-mailman (input) for mailman id 474082; Mon, 09 Jan 2023 23:08:41 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pF1Fx-0000Gp-3m for xen-devel@lists.xenproject.org; Mon, 09 Jan 2023 23:08:41 +0000 Received: from sonic315-55.consmr.mail.gq1.yahoo.com (sonic315-55.consmr.mail.gq1.yahoo.com [98.137.65.31]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8b4624a4-9072-11ed-b8d0-410ff93cb8f0; Tue, 10 Jan 2023 00:08:37 +0100 (CET) Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Mon, 9 Jan 2023 23:08:34 +0000 Received: by hermes--production-ne1-7b69748c4d-bgkrh (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 21a3ec8339abfccbadeaea4f5ef812e7; Mon, 09 Jan 2023 23:08:30 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8b4624a4-9072-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1673305714; bh=6KQQVKXjX5bPI5/yTS20Ov1Ty8T7qISVmf3UrSeOprM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=PEM0aNGEXQPaqvoOKMU9QyD96JQr5zHZqkD3XdTeUDsr8UOaeO2eUCcfQC8eUzj6YvlHwhREB8BQeTAA/fQhhnLV0bKpwkosy3XaDR0++D6Wq93pLvBsp+lRLNsFhCuWe3S83y3GIsiZEoApYIhP38XFQgkU+V+71RWck/3sk4kRGGMqtlH6sKiY363PxXu0Pp6blaUbHk86dzsEIsJFAniHkUC4t6o9EUP0FenDRBc96qq8e1/py4lFl3kNKV8Uqbxi+kTSq/tFpbRpA7+M1GnZe1jb8gvYAevKFVGgBhSszHjhIDGF8HSfj4sU+V0J9DwCKKpmQ016z3jZHkau7Q== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1673305714; bh=TWHL1z/CiE8oh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0v7dX5dV95Zba9M395Yo0HdgyKGR7NUnF1VGd7Y0qFlC5tJ7ei5c_vkq6fGvP6E04 s2b7n7IgIMZgq_WJ2_kFQ1i5t7tmpqNjOsqn5.yQz3KL1d555sYEuku.aqF1sbBwDQNF9M.Tfjkw UsW1h6xASufEA_XmYbd4eQuRz3UJF551d.qvx.DiWZyXxP39hJhXnk_IGsArpAsI2MGxd_CngflA o8b4LEfjVUjev696HkHyZD0UG_Ydm.58C8_5km2VzkCOdKQM8Ula61X.ld84oFv83N3Gxcf82MXW mN0lwv9_y8DoWZoL6Kq5AtcAEjx5CNQRD2vz2GFNd8D5XgsxqZrV3JaR0B6RAG84OKk1v4.6FVvT EDyCdVXuhrqTy7RWME1YAyMfWQHxrhOqZ4dpxw7uTBG367fnglB1.JdIKvdS6C9EC3wXmBolmi1y XEwACp5xf8ktCagD_XZauILSdQ7gL46G_f2W3EDrW9EcleRLg083XsJAc6sxAYSNMy5yKEanA3rc - X-Sonic-MF: From: Chuck Zmudzinski To: anthony.perard@citrix.com Cc: xen-devel@lists.xenproject.org, Wei Liu , Juergen Gross , qemu-devel@nongnu.org Subject: [XEN PATCH 2/3] libxl/dm: Manage pci slot assignment for Intel IGD passthrough Date: Mon, 9 Jan 2023 18:08:12 -0500 Message-Id: <76d06f5d01e01df316230def4f31037695f11c1a.1673300848.git.brchuckz@aol.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 By default, except for the ich9-usb-uhci device which libxl assigns to slot 29 (0xid), libxl defers to qemu upstream's automatic slot assignment process, which is simply to assign each emulated device to the next available slot on the pci bus. With this default behavior, libxl and qemu will not configure the Intel IGD correctly. Specifically, the Intel IGD must be assigned to slot 2, but the current default behavior is to assign one of the emulated devices to slot 2. With this patch libxl uses qemu command line options to specify the slot address of each pci device in the guest when gfx_passthru is enabled for the Intel IGD. It uses the same simple algorithm of assigning the next available slot, except that it starts with slot 3 instead of slot 2 for the emulated devices. This process of slot assignment aims to simulate the behavior of existing machines as much as possible. The default behavior (when igd gfx_passthru is disabled) of letting qemu manage the slot addresses of emulated pci devices is preserved. The patch also preserves the special treatment for the ich9 usb2 controller (ich9-usb-ehci1) that libxl currently assigns to slot.function 29.7 and the associated ich9-usb-uhciN devices to slot 29 (0x1d). For future maintainance of this code, it is important that pci devices that are managed by the libxl__build_device_model_args_new function follow the logic of this patch and use the new local counter next_slot to assign the slot address instead of letting upstream qemu assign the slot if the guest is configured for Intel IGD passthrough, and preserve the current behavior of letting qemu assign the slot address otherwise. Signed-off-by: Chuck Zmudzinski --- The diff of this patch is easier to review if it is generated using the -b (aka --ignore-space-change) option of diff/git-diff to filter out some of the changes that are only due to white space. This patch is difficult to verify for correctness without testing all the devices that could be added by the libxl__build_device_model_args_new function. There are 12 places where the addr=%x option needed to be added to the arguments of the "-device" qemu option that adds an emulated pci device which corresponds to at least 12 different devices that could be affected by this patch if the patch contains mistakes that the compiler did not notice. One mistake the compiler would not notice is a missing next_slot++; statement that would result in qemu trying to assign a device to a slot that is already assigned, which is an error in qemu. I did enough tests to find some mistakes in the patch which of course I fixed before submitting the patch. So I cannot guarantee that there are not any other mistakes in the patch because I don't have the resources to do the necessary testing of the many possible configurations that could be affected by this patch. tools/libs/light/libxl_dm.c | 168 ++++++++++++++++++++++++++++++------ 1 file changed, 141 insertions(+), 27 deletions(-) diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c index 2048815611..2720b5d4d0 100644 --- a/tools/libs/light/libxl_dm.c +++ b/tools/libs/light/libxl_dm.c @@ -1205,6 +1205,20 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, const char *path, *chardev; bool is_stubdom = libxl_defbool_val(b_info->device_model_stubdomain); int rc; + int next_slot; + bool configure_pci_for_igd = false; + /* + * next_slot is only used when we need to configure the pci + * slots for the Intel IGD. Slot 2 will be for the Intel IGD. + */ + next_slot = 3; + if (libxl_defbool_val(b_info->u.hvm.gfx_passthru)) { + enum libxl_gfx_passthru_kind gfx_passthru_kind = + libxl__detect_gfx_passthru_kind(gc, guest_config); + if (gfx_passthru_kind == LIBXL_GFX_PASSTHRU_KIND_IGD) { + configure_pci_for_igd = true; + } + } dm_args = flexarray_make(gc, 16, 1); dm_envs = flexarray_make(gc, 16, 1); @@ -1372,6 +1386,20 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, if (b_info->cmdline) flexarray_vappend(dm_args, "-append", b_info->cmdline, NULL); + /* + * When the Intel IGD is configured for primary graphics + * passthrough, we need to manually add the xen platform + * device because the QEMU machine type is "pc". Add it first to + * simulate the behavior of the "xenfv" QEMU machine type which + * always adds the xen platform device first. But in this case it + * will be at slot 3 because we are reserving slot 2 for the IGD. + */ + if (configure_pci_for_igd && + libxl_defbool_val(b_info->u.hvm.xen_platform_pci)) { + flexarray_append_pair(dm_args, "-device", + GCSPRINTF("xen-platform,addr=%x", next_slot)); + next_slot++; + } /* Find out early if one of the disk is on the scsi bus and add a scsi * controller. This is done ahead to keep the same behavior as previous @@ -1381,7 +1409,14 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, continue; } if (strncmp(disks[i].vdev, "sd", 2) == 0) { - flexarray_vappend(dm_args, "-device", "lsi53c895a", NULL); + if (configure_pci_for_igd) { + flexarray_vappend(dm_args, "-device", + GCSPRINTF("lsi53c895a,addr=%x", next_slot), NULL); + next_slot++; + } else { + flexarray_vappend(dm_args, "-device", "lsi53c895a", + NULL); + } break; } } @@ -1436,31 +1471,67 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, flexarray_append(dm_args, "-spice"); flexarray_append(dm_args, spiceoptions); if (libxl_defbool_val(b_info->u.hvm.spice.vdagent)) { - flexarray_vappend(dm_args, "-device", "virtio-serial", - "-chardev", "spicevmc,id=vdagent,name=vdagent", "-device", - "virtserialport,chardev=vdagent,name=com.redhat.spice.0", - NULL); + if (configure_pci_for_igd) { + flexarray_vappend(dm_args, "-device", + GCSPRINTF("virtio-serial,addr=%x", next_slot), + "-chardev", "spicevmc,id=vdagent,name=vdagent", + "-device", + "virtserialport,chardev=vdagent,name=com.redhat.spice.0", + NULL); + next_slot++; + } else { + flexarray_vappend(dm_args, "-device", "virtio-serial", + "-chardev", "spicevmc,id=vdagent,name=vdagent", + "-device", + "virtserialport,chardev=vdagent,name=com.redhat.spice.0", + NULL); + } } } switch (b_info->u.hvm.vga.kind) { case LIBXL_VGA_INTERFACE_TYPE_STD: - flexarray_append_pair(dm_args, "-device", - GCSPRINTF("VGA,vgamem_mb=%d", - libxl__sizekb_to_mb(b_info->video_memkb))); + if (configure_pci_for_igd) { + flexarray_append_pair(dm_args, "-device", + GCSPRINTF("VGA,addr=%x,vgamem_mb=%d", next_slot, + libxl__sizekb_to_mb(b_info->video_memkb))); + next_slot++; + } else { + flexarray_append_pair(dm_args, "-device", + GCSPRINTF("VGA,vgamem_mb=%d", + libxl__sizekb_to_mb(b_info->video_memkb))); + } break; case LIBXL_VGA_INTERFACE_TYPE_CIRRUS: - flexarray_append_pair(dm_args, "-device", - GCSPRINTF("cirrus-vga,vgamem_mb=%d", - libxl__sizekb_to_mb(b_info->video_memkb))); + if (configure_pci_for_igd) { + flexarray_append_pair(dm_args, "-device", + GCSPRINTF("cirrus-vga,addr=%x,vgamem_mb=%d", next_slot, + libxl__sizekb_to_mb(b_info->video_memkb))); + next_slot++; + } else { + flexarray_append_pair(dm_args, "-device", + GCSPRINTF("cirrus-vga,vgamem_mb=%d", + libxl__sizekb_to_mb(b_info->video_memkb))); + } break; case LIBXL_VGA_INTERFACE_TYPE_NONE: break; case LIBXL_VGA_INTERFACE_TYPE_QXL: /* QXL have 2 ram regions, ram and vram */ - flexarray_append_pair(dm_args, "-device", - GCSPRINTF("qxl-vga,vram_size_mb=%"PRIu64",ram_size_mb=%"PRIu64, - (b_info->video_memkb/2/1024), (b_info->video_memkb/2/1024) ) ); + if (configure_pci_for_igd) { + flexarray_append_pair(dm_args, "-device", + GCSPRINTF("qxl-vga,addr=%x,vram_size_mb=%"PRIu64 + ",ram_size_mb=%"PRIu64, next_slot, + (b_info->video_memkb/2/1024), + (b_info->video_memkb/2/1024) ) ); + next_slot++; + } else { + flexarray_append_pair(dm_args, "-device", + GCSPRINTF("qxl-vga,vram_size_mb=%"PRIu64 + ",ram_size_mb=%"PRIu64, + (b_info->video_memkb/2/1024), + (b_info->video_memkb/2/1024) ) ); + } break; default: LOGD(ERROR, guest_domid, "Invalid emulated video card specified"); @@ -1496,8 +1567,15 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, } else if (b_info->u.hvm.usbversion) { switch (b_info->u.hvm.usbversion) { case 1: - flexarray_vappend(dm_args, - "-device", "piix3-usb-uhci,id=usb", NULL); + if (configure_pci_for_igd) { + flexarray_vappend(dm_args, "-device", + GCSPRINTF("piix3-usb-uhci,addr=%x,id=usb", + next_slot), NULL); + next_slot++; + } else { + flexarray_vappend(dm_args, + "-device", "piix3-usb-uhci,id=usb", NULL); + } break; case 2: flexarray_append_pair(dm_args, "-device", @@ -1509,8 +1587,15 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, i, 2*(i-1), i-1)); break; case 3: - flexarray_vappend(dm_args, - "-device", "nec-usb-xhci,id=usb", NULL); + if (configure_pci_for_igd) { + flexarray_vappend(dm_args, "-device", + GCSPRINTF("nec-usb-xhci,addr=%x,id=usb", + next_slot), NULL); + next_slot++; + } else { + flexarray_vappend(dm_args, + "-device", "nec-usb-xhci,id=usb", NULL); + } break; default: LOGD(ERROR, guest_domid, "usbversion parameter is invalid, " @@ -1542,8 +1627,15 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, switch (soundhw) { case LIBXL__QEMU_SOUNDHW_HDA: - flexarray_vappend(dm_args, "-device", "intel-hda", - "-device", "hda-duplex", NULL); + if (configure_pci_for_igd) { + flexarray_vappend(dm_args, "-device", + GCSPRINTF("intel-hda,addr=%x", next_slot), + "-device", "hda-duplex", NULL); + next_slot++; + } else { + flexarray_vappend(dm_args, "-device", "intel-hda", + "-device", "hda-duplex", NULL); + } break; default: flexarray_append_pair(dm_args, "-device", @@ -1573,10 +1665,18 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, guest_domid, nics[i].devid, LIBXL_NIC_TYPE_VIF_IOEMU); flexarray_append(dm_args, "-device"); - flexarray_append(dm_args, - GCSPRINTF("%s,id=nic%d,netdev=net%d,mac=%s", - nics[i].model, nics[i].devid, - nics[i].devid, smac)); + if (configure_pci_for_igd) { + flexarray_append(dm_args, + GCSPRINTF("%s,addr=%x,id=nic%d,netdev=net%d,mac=%s", + nics[i].model, next_slot, nics[i].devid, + nics[i].devid, smac)); + next_slot++; + } else { + flexarray_append(dm_args, + GCSPRINTF("%s,id=nic%d,netdev=net%d,mac=%s", + nics[i].model, nics[i].devid, + nics[i].devid, smac)); + } flexarray_append(dm_args, "-netdev"); flexarray_append(dm_args, GCSPRINTF("type=tap,id=net%d,ifname=%s," @@ -1865,8 +1965,15 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, if (b_info->type == LIBXL_DOMAIN_TYPE_HVM) { flexarray_append_pair(dm_envs, "XEN_DOMAIN_ID", GCSPRINTF("%d", guest_domid)); - if (b_info->u.hvm.hdtype == LIBXL_HDTYPE_AHCI) - flexarray_append_pair(dm_args, "-device", "ahci,id=ahci0"); + if (b_info->u.hvm.hdtype == LIBXL_HDTYPE_AHCI) { + if (configure_pci_for_igd) { + flexarray_append_pair(dm_args, "-device", + GCSPRINTF("ahci,addr=%x,id=ahci0", next_slot)); + next_slot++; + } else { + flexarray_append_pair(dm_args, "-device", "ahci,id=ahci0"); + } + } for (i = 0; i < num_disks; i++) { int disk, part; int dev_number = @@ -2043,7 +2150,14 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, switch (b_info->u.hvm.vendor_device) { case LIBXL_VENDOR_DEVICE_XENSERVER: flexarray_append(dm_args, "-device"); - flexarray_append(dm_args, "xen-pvdevice,device-id=0xc000"); + if (configure_pci_for_igd) { + flexarray_append(dm_args, + GCSPRINTF("xen-pvdevice,addr=%x,device-id=0xc000", + next_slot)); + next_slot++; + } else { + flexarray_append(dm_args, "xen-pvdevice,device-id=0xc000"); + } break; default: break; From patchwork Mon Jan 9 23:08:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Zmudzinski X-Patchwork-Id: 13094498 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 C7CD4C54EBD for ; Mon, 9 Jan 2023 23:08:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.474083.735033 (Exim 4.92) (envelope-from ) id 1pF1Fz-0000bq-9r; Mon, 09 Jan 2023 23:08:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 474083.735033; Mon, 09 Jan 2023 23:08:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pF1Fz-0000bd-6T; Mon, 09 Jan 2023 23:08:43 +0000 Received: by outflank-mailman (input) for mailman id 474083; Mon, 09 Jan 2023 23:08:41 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pF1Fx-0000Gp-O1 for xen-devel@lists.xenproject.org; Mon, 09 Jan 2023 23:08:41 +0000 Received: from sonic308-8.consmr.mail.gq1.yahoo.com (sonic308-8.consmr.mail.gq1.yahoo.com [98.137.68.32]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8be2d2cc-9072-11ed-b8d0-410ff93cb8f0; Tue, 10 Jan 2023 00:08:37 +0100 (CET) Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.gq1.yahoo.com with HTTP; Mon, 9 Jan 2023 23:08:35 +0000 Received: by hermes--production-ne1-7b69748c4d-bgkrh (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 21a3ec8339abfccbadeaea4f5ef812e7; Mon, 09 Jan 2023 23:08:32 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8be2d2cc-9072-11ed-b8d0-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1673305715; bh=ywgbO8lubWpnCassvIu6bBFzCJ/Z2sgLUfL80HdpzLE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=pxzV/H1HM06MpAMRVFL0ssYCJXP59bXc5GrKUx/QcQJz7S71dqm4BINX2rzahxX81MtJ3y6CVWoFA+Z+Yvgmo6ZVoj16k+n0jLXlMLmUGbVqJE84JQ4p85+kGNkvkZ+CV3G3IVhDqZXv8Dr2rU0tVBF9iP1z0HwzRVp6x8KAHGEMS7q2ZCfeFIysV2I3RHAkuX8M4I5xj4vKnkI7rl/dsIfHsF+8921Wr5K1wPt2gMyHI+eTg8B2Lwfenjxuz9UX2sw8CglGE+K7lJLFfjSPx6RSsEPaGgY5LceZhom1Eg4fk0O1PK2D4Q/HnAm9NnGscRgslm01AHt6AiaU1UA4ZQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1673305715; bh=keMjmw88+NB73GNZ0YN7HfypUkwkByV4+3fnszfn8CF=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=o5oc++gedcFxnVQru4ndLDTH+4PHQV48uZlZYgPEpbc9FMkTUtRJaY8ZIkTBLQ9efm7MNUoNRoYQnfOqkxARaYxTn/ztbDwwrODbc224H2IWyAX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c6yU5aZnWRrsB7joBr4FEDvkSxCzU_cBhRAjHfUTyoByUkBxTxMb9yt6ZM2ghZoX7M 4X44tPVu604f.o9ZuWAJy7zhT2IAzwp1aYlqfKywOZ8iwK89zwurgxNux8odcJGe8wTK_NaFL1kI 4UFtlTJ3XYeRL6fjGS6415Z5PVgwMpQ9qwVDnoW7fmctSGop.iWJO6ImljqeBecgMRDO0UFB.hbn rpzFDd3it6GvDxcNBoCdQDUkXIw_RwrNeqgzjAP2cKVqLBVt7Ft1u.ciEP9bWBj0_nhtGG.lPkDG y9c_Poj1g_5DWY9FwycTRu2KCaslyzwI2.DyIuP23TmQA0qm41xKWUkKkiK6wucoCyxzfS8lCYQ- - X-Sonic-MF: From: Chuck Zmudzinski To: anthony.perard@citrix.com Cc: xen-devel@lists.xenproject.org, Wei Liu , Juergen Gross , qemu-devel@nongnu.org Subject: [XEN PATCH 3/3] libxl/dm: Assign slot 2 by default for Intel IGD passthrough Date: Mon, 9 Jan 2023 18:08:13 -0500 Message-Id: <27bb3979f234c8de6b51be7bb8195e3cacb5181c.1673300848.git.brchuckz@aol.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 It is possible for the administrator to manually specify the virtual slot addresses of passed through pci devices on the guest's pci bus using the @VSLOT parameter in xl.cfg. With this patch, libxl will by default assign the Intel IGD to slot 2 when gfx_passthru is configured for the Intel IGD so it will no longer be necessary to use the @VSLOT setting to configure the IGD correctly. Also, with this patch, libxl will not override explicit @VSLOT settings by the administrator so in that case the patch will have no effect on guest behavior. The default behavior of letting qemu manage the slot addresses of passed through pci devices when gfx_passthru is disabled and the administrator does not set @VSLOT for passed through pci devices is also preserved. Signed-off-by: Chuck Zmudzinski --- tools/libs/light/libxl_dm.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c index 2720b5d4d0..b51ebae643 100644 --- a/tools/libs/light/libxl_dm.c +++ b/tools/libs/light/libxl_dm.c @@ -1207,6 +1207,7 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, int rc; int next_slot; bool configure_pci_for_igd = false; + const int igd_slot = 2; /* * next_slot is only used when we need to configure the pci * slots for the Intel IGD. Slot 2 will be for the Intel IGD. @@ -2173,6 +2174,27 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, flexarray_append(dm_envs, NULL); if (envs) *envs = (char **) flexarray_contents(dm_envs); + if (configure_pci_for_igd) { + libxl_device_pci *pci = NULL; + for (i = 0; i < guest_config->num_pcidevs; i++) { + pci = &guest_config->pcidevs[i]; + if (!pci->vdevfn) { + /* + * Find the Intel IGD and configure it for slot 2. + * Configure any other devices for slot next_slot. + * Since the guest is configured for IGD passthrough, + * assume the device on the host at slot 2 is the IGD. + */ + if (pci->domain == 0 && pci->bus == 0 && + pci->dev == igd_slot && pci->func == 0) { + pci->vdevfn = PCI_DEVFN(igd_slot, 0); + } else { + pci->vdevfn = PCI_DEVFN(next_slot, 0); + next_slot++; + } + } + } + } return 0; }