From nobody Sun Feb 8 14:53:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009145; cv=none; d=zohomail.com; s=zohoarc; b=JWUZPYmoXQ/7wntet1gEP6ZYKnyNNfd5YJ8G9AcFAwFB0/+L2pchWIjOhta/CQirS4qxWv0il5robxMo8d2NRGf/UabkJT0SfsAVb5w9+QtiNEz7G/v+lxa3raoYo/1f46Mx7muDpiog8CXtysDQe83W+6r5vA3LY8SwvX+7ndA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009145; 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=EO9NydjIAYLyq/t6nIZozvEQJQm0gWEq0rGRIgFYvSY=; b=Kl7+YE1a6XTHCZrjkCpGLJmySY++Iblca0X2Uwab4F13mom9jQ1YQ9lHWf5p0GHu0mWnmwFSZudOtwP+cj4FGJPtjzYkoEO5/njZyyZCtzgdzlwyIdll3zAnQfNXwu+VtFV0CNI2pB8qnCYyl0BhoYAL94zDi28EYmH602pTjjI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1590009145486275.934237376071; Wed, 20 May 2020 14:12:25 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-467-N17VEHvDPH2wyWc37tEJuQ-1; Wed, 20 May 2020 17:12:21 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E9730BFC6; Wed, 20 May 2020 21:12:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 703C65D9CC; Wed, 20 May 2020 21:12:15 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6DCC84EE28; Wed, 20 May 2020 21:12:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCCmp002016 for ; Wed, 20 May 2020 17:12:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 59E392166BA3; Wed, 20 May 2020 21:12:12 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 558872166BA2 for ; Wed, 20 May 2020 21:12:10 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 64E0E80067A for ; Wed, 20 May 2020 21:12:10 +0000 (UTC) Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-99-hKYgnWCcNJaWxQEmr0oq4Q-1; Wed, 20 May 2020 17:12:08 -0400 Received: by mail-qt1-f194.google.com with SMTP id d7so3781810qtn.11 for ; Wed, 20 May 2020 14:12:07 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009144; 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=EO9NydjIAYLyq/t6nIZozvEQJQm0gWEq0rGRIgFYvSY=; b=BEi0KIjdTMMQzI/w6DGsya6jQWhSU2qFUmgVSku4pUkge6uNvsAQTiU2u3yI5ZGMO5MNLX bmQ31yDSwvMXwc6T9dMb4/0WepxfKgBSBdbaRWMIjWT8bcqHNVs/WEqOfrIRaJLaUH3PlW iiFCrytX5vPpAmH9MJJKofwm5m7AvXE= X-MC-Unique: N17VEHvDPH2wyWc37tEJuQ-1 X-MC-Unique: hKYgnWCcNJaWxQEmr0oq4Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EO9NydjIAYLyq/t6nIZozvEQJQm0gWEq0rGRIgFYvSY=; b=lLbzGbVgXAWqMHcztOwM+liYHZOj1K1jGN77QPxgdfJj5HZ+sAReiGG7mxraG6typV 4PyitxjDWU9FfIpZ0eSBxhTWL5NDZuFEVekB2f0gDC/I21+g6y6RsoK0uJEaz1G3gXY3 JMdf+gK5QKdcJzQEegytaHiPBphdbd85c51SJjnrvFgfqBMx3YuPi/ssm3MYU/uyfqXm 6BuFqqx0nUwpObrHyVZKc6K727uybT4QYgtjSLTTGaC0m+Jrv0wP0GgMiKNsLrLQnDSK k1WI8AtICUKNnTBemCAaXZ91hYYgNPegrKYdkOCLSrZMZFu9S56gaIjnIIuZolcYckCZ 9fzQ== X-Gm-Message-State: AOAM530MheELpfqV/9dbe7YLrQGOPoFuwwTinsG0KP+p1qPIOE3ioskR ps/7ik1fC6GZnL25DOXbYax/aWsm X-Google-Smtp-Source: ABdhPJzt1HJ3OpzSFl7XwPOcVPMGf2wAW27ke4d5SNeJj7O2O6LuFW96h3vj1CLV8YJcK3cNgV5eXA== X-Received: by 2002:ac8:36c7:: with SMTP id b7mr7540144qtc.269.1590009127219; Wed, 20 May 2020 14:12:07 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 02/21] utils: PCI multifunction detection helpers Date: Wed, 20 May 2020 18:11:24 -0300 Message-Id: <20200520211143.2980117-3-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This patch introduces two helpers that will be used in the next patches, virPCIDeviceIsMultifunction() and virHostdevIsPCIMultifunctionDevice(). Signed-off-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 31 +++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 3 +++ src/libvirt_private.syms | 2 ++ src/util/virpci.c | 17 +++++++++++++++++ src/util/virpci.h | 2 ++ 5 files changed, 55 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c201fc901d..0d289fbab5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -32659,3 +32659,34 @@ virHostdevIsVFIODevice(const virDomainHostdevDef *= hostdev) hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI && hostdev->source.subsys.u.pci.backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI= _BACKEND_VFIO; } + + +/** + * virHostdevIsPCIMultifunctionDevice + * @hostdev: host device to check + * + * Returns true if @hostdev is a PCI Multifunction device, false otherwise. + */ +bool +virHostdevIsPCIMultifunctionDevice(virDomainHostdevDefPtr hostdev) +{ + g_autoptr(virPCIDevice) pciDev =3D NULL; + virDomainHostdevSubsysPCIPtr pcisrc =3D &hostdev->source.subsys.u.pci; + + if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS || + hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PC= I) + return false; + + /* Libvirt should be able to perform all the operations in + * virPCIDeviceNew() even if it's running unprivileged, so if this + * fails, the device apparently doesn't currently exist on the host. + * Since we can't speculate, assume this device is not multifunction. + */ + pciDev =3D virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus, + pcisrc->addr.slot, pcisrc->addr.function); + + if (!pciDev) + return false; + + return virPCIDeviceIsMultifunction(pciDev); +} diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ddc75d8de2..e6d3e04109 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3840,3 +3840,6 @@ virHostdevIsMdevDevice(const virDomainHostdevDef *hos= tdev) bool virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev) ATTRIBUTE_NONNULL(1); +bool +virHostdevIsPCIMultifunctionDevice(virDomainHostdevDefPtr hostdev) + ATTRIBUTE_NONNULL(1); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fd04fcece3..c143264382 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -723,6 +723,7 @@ virDomainEventWatchdogNewFromObj; virDomainQemuMonitorEventNew; virDomainQemuMonitorEventStateRegisterID; virHostdevIsMdevDevice; +virHostdevIsPCIMultifunctionDevice; virHostdevIsSCSIDevice; virHostdevIsVFIODevice; =20 @@ -2794,6 +2795,7 @@ virPCIDeviceGetUnbindFromStub; virPCIDeviceGetUsedBy; virPCIDeviceHasPCIExpressLink; virPCIDeviceIsAssignable; +virPCIDeviceIsMultifunction; virPCIDeviceIsPCIExpress; virPCIDeviceListAdd; virPCIDeviceListAddCopy; diff --git a/src/util/virpci.c b/src/util/virpci.c index 6c7e6bbcab..82e86456c4 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2837,6 +2837,23 @@ int virPCIGetHeaderType(virPCIDevicePtr dev, int *hd= rType) } =20 =20 +bool +virPCIDeviceIsMultifunction(virPCIDevicePtr dev) +{ + int fd; + uint8_t type; + + if ((fd =3D virPCIDeviceConfigOpen(dev)) < 0) + return -1; + + type =3D virPCIDeviceRead8(dev, fd, PCI_HEADER_TYPE); + + virPCIDeviceConfigClose(dev, fd); + + return type & PCI_HEADER_TYPE_MULTI; +} + + void virPCIEDeviceInfoFree(virPCIEDeviceInfoPtr dev) { diff --git a/src/util/virpci.h b/src/util/virpci.h index f16d23614a..64a9109d9b 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -270,6 +270,8 @@ int virPCIDeviceGetLinkCapSta(virPCIDevicePtr dev, =20 int virPCIGetHeaderType(virPCIDevicePtr dev, int *hdrType); =20 +bool virPCIDeviceIsMultifunction(virPCIDevicePtr dev); + void virPCIEDeviceInfoFree(virPCIEDeviceInfoPtr dev); =20 ssize_t virPCIGetMdevTypes(const char *sysfspath, --=20 2.26.2