From nobody Mon Feb 9 01:06:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1681479907; cv=none; d=zohomail.com; s=zohoarc; b=GZNI32Qvw/ar6+mBf5CqTQWVzzpefLxjCXco/6SvfRskIQXB300dyClrdnGNEcqBQpN//PPQZeXiGrS0LsP3aKXdJLdYFS5/4ZRQ91nuimRs+SR55iUnbMAg4gLS79YbaKXntR95Xay7/fLuFHHvj9fFELkRSG8K9xFLXWN+Tqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681479907; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kog9dFSWWLIusJyo54Co8mQX0zCCFrHrF4rw2Tp44Fo=; b=AwyGQmm2BQ6ZM1V7TvwJdN8f+Xt5bfK576mTYDtV5lFnx+WdxPzhDcW2TYKUeXEjgPpDAU+xMaS1Nqqe3K+g8AZDIgRGegAxA+Tc4Xu0ISuytE1LJ8f4iRaG2nwjsKyXklbQVnmrdGE9utYbdWiScuIaJrogASrw73osP+DrzDo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1681479907684217.25174698515445; Fri, 14 Apr 2023 06:45:07 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-509-HgsucKOOPFKBL66JUzE03Q-1; Fri, 14 Apr 2023 09:44:26 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8363510334A7; Fri, 14 Apr 2023 13:44:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F325492C3A; Fri, 14 Apr 2023 13:44:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4F02319459FC; Fri, 14 Apr 2023 13:44:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 769A319472C0 for ; Fri, 14 Apr 2023 13:44:21 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6B152492C18; Fri, 14 Apr 2023 13:44:21 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id ECD05492C13; Fri, 14 Apr 2023 13:44:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681479906; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=kog9dFSWWLIusJyo54Co8mQX0zCCFrHrF4rw2Tp44Fo=; b=dPTTeUttw1mfTH5O7ye2Ega2pA1rzTm4UkCUP4D5oG1qLABQ4/jeAMGtGklkup/k4dMQ3d /Gsl6TZbSkJKQYNVhsVfdwmPxG6ebGZvvWosv7/yB9fGw/xgWMGXtMs4EM2eOhs2raRosS QBb/IapFxWr3lDtV7P8fix5s+jmats4= X-MC-Unique: HgsucKOOPFKBL66JUzE03Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/4] qemu: Move PCI backend setting into qemuDomainPrepareHostdev() Date: Fri, 14 Apr 2023 15:44:16 +0200 Message-Id: <52c0978dbcb5c633318ec58cc8702ad5c9e7adb2.1681479711.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhenzhong.duan@intel.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1681479908302100001 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Zhenzhong Duan virsh command domxml-to-native failed with below error but start command succeed for same domain xml. "internal error: invalid PCI passthrough type 'default'" If a PCI backend is not set in the XML, the supported one is then chosen in qemuHostdevPreparePCIDevicesCheckSupport(). But this function is not called anywhere from qemuConnectDomainXMLToNative(). But qemuDomainPrepareHostdev() is. And it is also called from domain startup/hotplug code. Therefore, move the backend setting to the common path. And since qemuDomainPrepareHostdev() is called transitively from our qemuxml2argvtest, we can just drop the code in testCompareXMLToArgvCreateArgs() that preselects the backend (if a mock for qemuHostdevHostSupportsPassthroughVFIO() is provided. Signed-off-by: Zhenzhong Duan Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 12 ++++++++++++ src/qemu/qemu_hostdev.c | 16 +++++++--------- src/qemu/qemu_hotplug.c | 2 +- tests/qemuxml2argvmock.c | 7 +++++++ tests/qemuxml2argvtest.c | 6 ------ 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 63b13b6875..6de846f158 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11275,6 +11275,18 @@ qemuDomainPrepareHostdev(virDomainHostdevDef *host= dev, } } =20 + if (hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && + hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI) { + bool supportsPassthroughVFIO =3D qemuHostdevHostSupportsPassthroug= hVFIO(); + virDomainHostdevSubsysPCIBackendType *backend =3D &hostdev->source= .subsys.u.pci.backend; + + if (*backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT && + supportsPassthroughVFIO && + virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) { + *backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO; + } + } + return 0; } =20 diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index 45cd1066f0..8408928c00 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -156,7 +156,7 @@ qemuHostdevHostSupportsPassthroughVFIO(void) static bool qemuHostdevPreparePCIDevicesCheckSupport(virDomainHostdevDef **hostdevs, size_t nhostdevs, - virQEMUCaps *qemuCaps) + virQEMUCaps *qemuCaps G_GNUC_UNUS= ED) { bool supportsPassthroughVFIO =3D qemuHostdevHostSupportsPassthroughVFI= O(); size_t i; @@ -173,17 +173,15 @@ qemuHostdevPreparePCIDevicesCheckSupport(virDomainHos= tdevDef **hostdevs, =20 switch (*backend) { case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT: - if (supportsPassthroughVFIO && - virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) { - *backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO; + /* qemuDomainPrepareHostdev() should have set different value = */ + if (supportsPassthroughVFIO) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("QEMU doesn't support VFIO PCI passthroug= h")); } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("host doesn't support passthrough of " - "host PCI devices")); - return false; + _("host doesn't support passthrough of host= PCI devices")); } - - break; + return false; =20 case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO: if (!supportsPassthroughVFIO) { diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 8902b40815..95ac0fd754 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1478,7 +1478,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriver *driver, &hostdev, 1, priv->qemuCaps, flags) <= 0) return -1; =20 - /* this could have been changed by qemuHostdevPreparePCIDevices */ + /* this could have been changed by qemuDomainPrepareHostdev */ backend =3D hostdev->source.subsys.u.pci.backend; =20 switch (backend) { diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c index f566ec539a..863fdf0351 100644 --- a/tests/qemuxml2argvmock.c +++ b/tests/qemuxml2argvmock.c @@ -33,6 +33,7 @@ #include "virscsivhost.h" #include "virtpm.h" #include "virutil.h" +#include "qemu/qemu_hostdev.h" #include "qemu/qemu_interface.h" #include "qemu/qemu_command.h" #include @@ -82,6 +83,12 @@ virSCSIVHostOpenVhostSCSI(int *vhostfd) return 0; } =20 +bool +qemuHostdevHostSupportsPassthroughVFIO(void) +{ + return true; +} + int virNetDevTapCreate(char **ifname, const char *tunpath G_GNUC_UNUSED, diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 1808d9fc02..8333749eea 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -407,12 +407,6 @@ testCompareXMLToArgvCreateArgs(virQEMUDriver *drv, for (i =3D 0; i < vm->def->nhostdevs; i++) { virDomainHostdevDef *hostdev =3D vm->def->hostdevs[i]; =20 - if (hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_T= YPE_PCI && - hostdev->source.subsys.u.pci.backend =3D=3D VIR_DOMAIN_HOSTDEV= _PCI_BACKEND_DEFAULT) { - hostdev->source.subsys.u.pci.backend =3D VIR_DOMAIN_HOSTDEV_PC= I_BACKEND_VFIO; - } - if (virHostdevIsSCSIDevice(hostdev)) { virDomainHostdevSubsysSCSI *scsisrc =3D &hostdev->source.subsy= s.u.scsi; =20 --=20 2.39.2