From nobody Sun Feb 8 00:37:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 172867047566625.69138491461888; Fri, 11 Oct 2024 11:14:35 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 824E6170A; Fri, 11 Oct 2024 14:14:34 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 544C614D1; Fri, 11 Oct 2024 14:13:23 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id F2788148E; Fri, 11 Oct 2024 14:13:17 -0400 (EDT) Received: from mail-oa1-f54.google.com (mail-oa1-f54.google.com [209.85.160.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id CB0A613A8 for ; Fri, 11 Oct 2024 14:13:16 -0400 (EDT) Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-2884e6ed0daso916922fac.0 for ; Fri, 11 Oct 2024 11:13:16 -0700 (PDT) Received: from home.. ([2603:8081:c640:1::1003]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-2885844a8b7sm1047097fac.58.2024.10.11.11.13.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 11:13:14 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728670396; x=1729275196; darn=lists.libvirt.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=bHqerm6Gxonp0bEsVDiuoAOc86rFZNBWYYU34U4DERk=; b=i0VNgR0uYjuDH0d9aZ+FFz/zOGL6tY1vExg7wSt46QSJm1GkzHCe724DuvvhPW8zXu q9tgo7cZr4MhXaFpJWHcx4mqnXQD3jal0KtI2lQpF5gkDiQ6Qal9/DErw2m5fyun7m4q G9t3W3g7SY2i4vuE5ozDkul6sgPVp2pXetkWjoOYL/lRHnDbeeBwqdeBEZj2S7CTxc6g oaNB9fYMwOH8IACDR9SshYpKNtymF7vWt+n3ewGyl5zz6GzEBoNpy0baL33RGx97ruH6 Q/LICSyBjSckJBkOZOyZo8HmwHaHK683GD1xPmTF/1dYdqtQ9RjqDr2fEe2cpb75iNtF mtdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728670396; x=1729275196; 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=bHqerm6Gxonp0bEsVDiuoAOc86rFZNBWYYU34U4DERk=; b=RMNKPmTTiq6c5OsOzhEFDU6MjhE+wQ00MhZflSxT6SHpexxKI4HxDlVkGDBBKiXjvQ A9cpxkMK/u2rCTg4LvVQWFNLLq5MN2vKxq10YWuOw0F9mvbbH1CuSZPx1Nvsu4R803uE bpdeG6rl+suKlYFxniEPI8XH7Tyqjtty4RH5FtQDF+7scF2IrDpS2ldUEUMZxglsCBxM Q2YjovnsyN+nX+xABZVdbS9SuOm8hVLqmoUg7TujVcEw83HtWUD7U2KA1YQH++lg76XB K7FnY0yosGxQ4HBbhAlwFIa7XLV6zO8xvZvrrcOkHtwM8wT5RGfdun/jgVWO+ouegwee tVqw== X-Gm-Message-State: AOJu0YycH52uuoxOCsJYldXvGZ7KX79zPYi+dLt3xN15mNTzSccQc8J0 NTWJ9DEgmwyKIJdTZGw8KYolMrfxDmYPKuwR1ysX6SmPpPaLJ8/s/M8aKw== X-Google-Smtp-Source: AGHT+IFZlh+AkSQyPAyLrCaTAhDvoPpIRwf3thAkFHr1ZdAQskaXnlmLnkbvc4UtEVz5Jw1zbVFg0w== X-Received: by 2002:a05:6871:89e:b0:277:fe14:e68c with SMTP id 586e51a60fabf-2886df8f1d2mr2117636fac.33.1728670395633; Fri, 11 Oct 2024 11:13:15 -0700 (PDT) From: Praveen K Paladugu X-Google-Original-From: Praveen K Paladugu To: devel@lists.libvirt.org Subject: [PATCH 02/10] hypervisor: move HostdevHostSupportsPassthroughVFIO Date: Fri, 11 Oct 2024 13:13:03 -0500 Message-ID: <20241011181311.6813-3-prapal@linux.microsoft.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20241011181311.6813-1-prapal@linux.microsoft.com> References: <20241011181311.6813-1-prapal@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: YD3OHJQ62WLIA47WWJEJZ54J7SYPFY2G X-Message-ID-Hash: YD3OHJQ62WLIA47WWJEJZ54J7SYPFY2G X-MailFrom: praveenkpaladugu@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: liuwe@microsoft.com X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1728670477728116600 Content-Type: text/plain; charset="utf-8" Move HostdevHostSupportsPassthroughVFIO method to hypervisor to be shared between qemu and ch drivers. Signed-off-by: Praveen K Paladugu --- src/hypervisor/virhostdev.c | 16 ++++++++++++++++ src/hypervisor/virhostdev.h | 2 ++ src/libvirt_private.syms | 1 + src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_hostdev.c | 15 --------------- src/qemu/qemu_hostdev.h | 2 -- tests/domaincapstest.c | 2 +- 9 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index 4b06e74894..220578f0c0 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -29,12 +29,14 @@ #include "virhostdev.h" #include "viralloc.h" #include "virerror.h" +#include "virfile.h" #include "virlog.h" #include "virutil.h" #include "virnetdev.h" #include "configmake.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE +#define VIR_DEV_VFIO "/dev/vfio/vfio" =20 VIR_LOG_INIT("util.hostdev"); =20 @@ -2519,3 +2521,17 @@ virHostdevNeedsVFIO(const virDomainHostdevDef *hostd= ev) return virHostdevIsPCIDevice(hostdev) || virHostdevIsMdevDevice(hostdev); } + +bool +virHostdevHostSupportsPassthroughVFIO(void) +{ + /* condition 1 - host has IOMMU */ + if (!virHostHasIOMMU()) + return false; + + /* condition 2 - /dev/vfio/vfio exists */ + if (!virFileExists(VIR_DEV_VFIO)) + return false; + + return true; +} diff --git a/src/hypervisor/virhostdev.h b/src/hypervisor/virhostdev.h index b9e6108816..b7f8473560 100644 --- a/src/hypervisor/virhostdev.h +++ b/src/hypervisor/virhostdev.h @@ -235,3 +235,5 @@ virHostdevUpdateActiveNVMeDevices(virHostdevManager *ho= stdev_mgr, =20 bool virHostdevNeedsVFIO(const virDomainHostdevDef *hostdev); + +bool virHostdevHostSupportsPassthroughVFIO(void); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index cca071f866..39988cf0f4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1669,6 +1669,7 @@ virCloseCallbacksDomainRunForConn; =20 # hypervisor/virhostdev.h virHostdevFindUSBDevice; +virHostdevHostSupportsPassthroughVFIO; virHostdevManagerGetDefault; virHostdevNeedsVFIO; virHostdevPCINodeDeviceDetach; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index ac135aa301..e2f97c3d9a 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -6378,7 +6378,7 @@ static void virQEMUCapsFillDomainDeviceHostdevCaps(virQEMUCaps *qemuCaps, virDomainCapsDeviceHostdev *hostdev) { - bool supportsPassthroughVFIO =3D qemuHostdevHostSupportsPassthroughVFI= O(); + bool supportsPassthroughVFIO =3D virHostdevHostSupportsPassthroughVFIO= (); =20 hostdev->supported =3D VIR_TRISTATE_BOOL_YES; hostdev->mode.report =3D true; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index fda4439b0b..065a37445e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11698,7 +11698,7 @@ static int qemuDomainPrepareHostdevPCI(virDomainHostdevDef *hostdev, virQEMUCaps *qemuCaps) { - bool supportsPassthroughVFIO =3D qemuHostdevHostSupportsPassthroughVFI= O(); + bool supportsPassthroughVFIO =3D virHostdevHostSupportsPassthroughVFIO= (); virDeviceHostdevPCIDriverName *driverName =3D &hostdev->source.subsys.= u.pci.driver.name; =20 /* assign defaults for hostdev passthrough */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f27c21ca8c..e0adebf7ea 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11482,7 +11482,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, * further validation until then. */ =20 - if (!qemuHostdevHostSupportsPassthroughVFIO()) { + if (!virHostdevHostSupportsPassthroughVFIO()) { virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", _("VFIO device assignment is currently not supporte= d on this system")); return -1; diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index f25ccaf1a4..ab2769d482 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -130,21 +130,6 @@ qemuHostdevUpdateActiveDomainDevices(virQEMUDriver *dr= iver, } =20 =20 -bool -qemuHostdevHostSupportsPassthroughVFIO(void) -{ - /* condition 1 - host has IOMMU */ - if (!virHostHasIOMMU()) - return false; - - /* condition 2 - /dev/vfio/vfio exists */ - if (!virFileExists(QEMU_DEV_VFIO)) - return false; - - return true; -} - - int qemuHostdevPrepareOneNVMeDisk(virQEMUDriver *driver, const char *name, diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h index bbf7bb11e7..b6dd2e0207 100644 --- a/src/qemu/qemu_hostdev.h +++ b/src/qemu/qemu_hostdev.h @@ -23,8 +23,6 @@ =20 #include "qemu_conf.h" =20 -bool qemuHostdevHostSupportsPassthroughVFIO(void); - int qemuHostdevUpdateActiveNVMeDisks(virQEMUDriver *driver, virDomainDef *def); int qemuHostdevUpdateActiveMediatedDevices(virQEMUDriver *driver, diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index e557337617..e520c7d7bc 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -105,7 +105,7 @@ fillQemuCaps(virDomainCaps *domCaps, return -1; =20 /* The function above tries to query host's VFIO capabilities by calli= ng - * qemuHostdevHostSupportsPassthroughVFIO() which, however, can't be + * virHostdevHostSupportsPassthroughVFIO() which, however, can't be * successfully mocked as they are not exposed as internal APIs. There= fore, * instead of mocking set the expected values here by hand. */ VIR_DOMAIN_CAPS_ENUM_SET(domCaps->hostdev.pciBackend, --=20 2.44.0