From nobody Mon Feb 9 19:25:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1692646450; cv=none; d=zohomail.com; s=zohoarc; b=PXfaLPzd1gW3Z9g9Bb6TB91eO9V3yCSGXTQzmkoN/UwI+LZ4vjOcDtEpcf1G9VilFSKhOeaA9NLj77lmjjRzZ7n8vWsBUQB0YR4T2Pq2TweO71EgCFyVZxhOEeuHaaV2S5EdXPENDqeZZGAxul9kUeMwKX+Sr7vdMlSa7prEAXQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692646450; 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=oRtVG7GR5kuTO18RdKHtT4chA8FgT1uQ0mTjV4BPFcw=; b=c87p41OT8iazRgnubNe+g3xHa/KSgLK6fYRY/mmIna/EZ4ZHOFJ8ekoAYGsScJTdgAm6xuJKCW1Ap/sw2y9+qj0cH/OP7qLQBaZkRuGHE2RDUgzOaGSflKVB8WeEbzbzPcxPdGC7a9xyDAx06AQjATOddhitNLZGyL60mQvIn0E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 169264645016197.7980429615676; Mon, 21 Aug 2023 12:34:10 -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-686-AiLCHUTxNem9vhDbL4UZiQ-1; Mon, 21 Aug 2023 15:33:45 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 67D628022E4; Mon, 21 Aug 2023 19:33:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 497E540D2843; Mon, 21 Aug 2023 19:33:43 +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 D993519465BD; Mon, 21 Aug 2023 19:33:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 21F7C1946588 for ; Mon, 21 Aug 2023 19:33:06 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id ECE8A403163; Mon, 21 Aug 2023 19:33:00 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.9.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4860492C13; Mon, 21 Aug 2023 19:33:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692646448; 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=oRtVG7GR5kuTO18RdKHtT4chA8FgT1uQ0mTjV4BPFcw=; b=gRoRwCafcd9Wrs3UoUc0ZROWERH8CSPSJMmU3ncCHL9By1Rjpwf127fI7X/Ro1g8MSn0LF 8VAPoHaOmU6dFskUxyyQwQ0Pd9O/SmcMbYWi+mvd4t/FSvTmqcJMs+V5kzUoHFFcEP8ArF pWQ+G1R6rr2w02scv+D/wFf6xCgXImA= X-MC-Unique: AiLCHUTxNem9vhDbL4UZiQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v3 7/8] node_device: support binding other drivers with virNodeDeviceDetachFlags() Date: Mon, 21 Aug 2023 15:32:57 -0400 Message-ID: <20230821193258.520859-8-laine@redhat.com> In-Reply-To: <20230821193258.520859-1-laine@redhat.com> References: <20230821193258.520859-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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: "Cc : Joao Martins" , "Cc : Cedric Le Goater" , "Cc : Jason Gunthorpe" Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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: 1692646451081100001 Content-Type: text/plain; charset="utf-8"; x-default="true" In the past, the only allowable values for the "driver" field of virNodeDeviceDetachFlags() were "kvm" or "vfio" for the QEMU driver, and "xen" for the libxl driver. Then "kvm" was deprecated and removed, so the driver name became essentially irrelevant (because it is always called via a particular hypervisor driver, and so the "xen" or "vfio" can be (and almost always is) implied. With the advent of VFIO variant drivers, the ability to explicitly specify a driver name once again becomes useful - it can be used to name the exact VFIO driver that we want bound to the device in place of vfio-pci, so this patch allows those other names to be passed down the call chain, where the code in virpci.c can make use of them. The names "vfio", "kvm", and "xen" retain their special meaning, though: 1) because there may be some application or configuration that still calls virNodeDeviceDetachFlags() with driverName=3D"vfio", this single value is substituted with the synonym of NULL, which means "bind the default driver for this device and hypervisor". This will currently result in the vfio-pci driver being bound to the device. 2) in the case of the libxl driver, "xen" means to use the standard driver used in the case of Xen ("pciback"). 3) "kvm" as a driver name always results in an error, as legacy KVM device assignment was removed from the kernel around 10 years ago. Signed-off-by: Laine Stump --- src/hypervisor/domain_driver.c | 9 ++++----- src/hypervisor/domain_driver.h | 2 ++ src/libxl/libxl_driver.c | 3 ++- src/qemu/qemu_driver.c | 33 +++++++++++++++++++-------------- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index a70f75f3ae..429784292a 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -462,6 +462,7 @@ virDomainDriverNodeDeviceReAttach(virNodeDevicePtr dev, int virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr dev, virHostdevManager *hostdevMgr, + virPCIStubDriver driverType, const char *driverName) { g_autoptr(virPCIDevice) pci =3D NULL; @@ -471,7 +472,7 @@ virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr d= ev, g_autoptr(virConnect) nodeconn =3D NULL; g_autoptr(virNodeDevice) nodedev =3D NULL; =20 - if (!driverName) + if (driverType =3D=3D VIR_PCI_STUB_DRIVER_NONE) return -1; =20 if (!(nodeconn =3D virGetConnectNodeDev())) @@ -504,10 +505,8 @@ virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr = dev, if (!pci) return -1; =20 - if (STREQ(driverName, "vfio")) - virPCIDeviceSetStubDriverType(pci, VIR_PCI_STUB_DRIVER_VFIO); - else if (STREQ(driverName, "xen")) - virPCIDeviceSetStubDriverType(pci, VIR_PCI_STUB_DRIVER_XEN); + virPCIDeviceSetStubDriverType(pci, driverType); + virPCIDeviceSetStubDriverName(pci, driverName); =20 return virHostdevPCINodeDeviceDetach(hostdevMgr, pci); } diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index 4241c86932..9942f58fda 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -22,6 +22,7 @@ =20 #include "node_device_conf.h" #include "virhostdev.h" +#include "virpci.h" =20 char * virDomainDriverGenerateRootHash(const char *drivername, @@ -58,6 +59,7 @@ int virDomainDriverNodeDeviceReAttach(virNodeDevicePtr de= v, =20 int virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr dev, virHostdevManager *hostdevMgr, + virPCIStubDriver driverType, const char *driverName); =20 int virDomainDriverAddIOThreadCheck(virDomainDef *def, diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 3d10f45850..079922dd32 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -5876,7 +5876,8 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev, =20 /* virNodeDeviceDetachFlagsEnsureACL() is being called by * virDomainDriverNodeDeviceDetachFlags() */ - return virDomainDriverNodeDeviceDetachFlags(dev, hostdev_mgr, driverNa= me); + return virDomainDriverNodeDeviceDetachFlags(dev, hostdev_mgr, + VIR_PCI_STUB_DRIVER_XEN, N= ULL); } =20 static int diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f8039160f4..f676744e9e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -70,7 +70,6 @@ #include "domain_driver.h" #include "domain_postparse.h" #include "domain_validate.h" -#include "virpci.h" #include "virpidfile.h" #include "virprocess.h" #include "libvirt_internal.h" @@ -11400,24 +11399,28 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, =20 virCheckFlags(0, -1); =20 - if (!driverName) - driverName =3D "vfio"; - - /* Only the 'vfio' driver is supported and a special error message for - * the previously supported 'kvm' driver is provided below. */ - if (STRNEQ(driverName, "vfio") && STRNEQ(driverName, "kvm")) { - virReportError(VIR_ERR_INVALID_ARG, - _("unknown driver name '%1$s'"), driverName); - return -1; - } + /* For historical reasons, if driverName is "vfio", that is the + * same as NULL, i.e. the default vfio driver for this device + */ + if (STREQ_NULLABLE(driverName, "vfio")) + driverName =3D NULL; =20 - if (STREQ(driverName, "kvm")) { + /* the "kvm" driver name was used a very long time ago to force + * "legacy KVM device assignment", which hasn't been supported in + * over 10 years. + */ + if (STREQ_NULLABLE(driverName, "kvm")) { virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", - _("KVM device assignment is no longer " + _("'legacy KVM' device assignment is no longer " "supported on this system")); return -1; } =20 + /* for any other driver, we can't know whether or not it is a VFIO + * driver until the device has been bound to it, so we will defer + * further validation until then. + */ + if (!qemuHostdevHostSupportsPassthroughVFIO()) { virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", _("VFIO device assignment is currently not " @@ -11427,7 +11430,9 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, =20 /* virNodeDeviceDetachFlagsEnsureACL() is being called by * virDomainDriverNodeDeviceDetachFlags() */ - return virDomainDriverNodeDeviceDetachFlags(dev, hostdev_mgr, driverNa= me); + return virDomainDriverNodeDeviceDetachFlags(dev, hostdev_mgr, + VIR_PCI_STUB_DRIVER_VFIO, + driverName); } =20 static int --=20 2.41.0