From nobody Tue Nov 26 17:43:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1570482847; cv=none; d=zoho.com; s=zohoarc; b=UpSaxGWz91fOm+COZMwFju0RKkocWPIabDqS1lefd3ufb9yCne8diEcCay3cH1g9JBnun79nrzLzdFIGIr3A3pJt4ADV6yCUNHWCPFnh4zO7oFquZJKOpMWsJPFiSJnMRU2YGeF9JRyURSMza8r1KhOUTfuPTFslGyaFhEnjxxc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570482847; 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:ARC-Authentication-Results; bh=BjXXcIwYObE/W6dbiZg6hAPLpuwITs/I8he9uzyoBoM=; b=mNbCnwny0A7lrjiJ0P+gJZfjp/8rWK4KUABpXjZnIdACJrHKvexyRxe6S0o5sJswqY5k9UNkOU8QJRbSt7sx6os63TEuB3lB9PA8xqBL1Mzkq6wWX9Bs1bFJeHpKJazk1yyC2dmk/aTCrim9StN/j9PGSM1iU7eTJkG6jfJrowc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570482847513661.5399534498669; Mon, 7 Oct 2019 14:14:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3563691761; Mon, 7 Oct 2019 21:14:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 06DF2600CE; Mon, 7 Oct 2019 21:14:05 +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 A1358180B536; Mon, 7 Oct 2019 21:14:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x97LBqrt012204 for ; Mon, 7 Oct 2019 17:11:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9291A6012A; Mon, 7 Oct 2019 21:11:52 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8AA5D600C1 for ; Mon, 7 Oct 2019 21:11:50 +0000 (UTC) Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9CED081F2F for ; Mon, 7 Oct 2019 21:11:49 +0000 (UTC) Received: by mail-qt1-f196.google.com with SMTP id c21so21335378qtj.12 for ; Mon, 07 Oct 2019 14:11:49 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:e8e7:3739:3e28:be31:8030]) by smtp.gmail.com with ESMTPSA id i30sm11333409qte.27.2019.10.07.14.11.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 14:11:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gP8/NjWHKJYaDf7hqgEQJmjuLY6XtonMxiZqz7u+7rE=; b=AQAVPvYMXqjFX+4yyxIseZdn3PaLdn/e9SDy8+LgiovNYMCB+zlXB6bfjVso/8accW 8Qek7ooH8vxhgw2WhqMQd4Jpxm9s6qgRnsu/yB+1oTCcRXV/Ey70salqdjOmmXXjuf+t zaWNkBPZjS0w6+pQEj4/vps85JamUC7OHbSFg2jYsuFcOkciYZv9hvIQPr6MB8v/5BO0 WONVtyTl3sdYoP/1w9JYLqJIr6jtZ/RDNII8D8E5TXP6PX4JX4eFY4itKt3+1xaQ2DnF Dr95nBU395fs+8cY1BwsMlTIZCdnbC5sXpRj8Dl8vrT5xrQnIKMT7zTRCT/PsprXcq8o lflg== 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=gP8/NjWHKJYaDf7hqgEQJmjuLY6XtonMxiZqz7u+7rE=; b=UuFz0bdAik2sD4A/n6X6SRseWtFEdYp/LxPGB5ukc+Kq3jNo7aas30Do9GociHTNQ8 6HNUYWsk/XDDnvySZ28WaUuu8zwYCjcrCXZd8oOa22qvLBP4OOp4Y6q5UDGiuW/rJZaQ M5YIpbab1C4cQwzs+wS509ALxlqpQHz3kmkJ7HlQuEzNY1bzBw6H559ZREIhlTRw8/ho UHMOULUS0UPwN9/aTjgOLdIMSGA/Ze9GmqpvWf6F1U//MwKq4sbv+GfDvM5ZhHlS6TL/ vlZ139/E3oJVOfMp1ZzGrIMIP1nmHq0PYI0ZabL0qqFVpUjqSzkQxlylZ829Ye3XfMCV xktw== X-Gm-Message-State: APjAAAXeDEfuOuqIMNddVZqBQpWentoN51vbnWZuajciV5fn58knkovq OajBuBV8LXvxTpWGq16+XF4e+9N2 X-Google-Smtp-Source: APXvYqyVi9suib8R7+ABPfTKJX56IcsxajhqkPLSyVeg3CU/kQuEPxAu1Es7oomnNrWCFp2qSaPg/w== X-Received: by 2002:ac8:2738:: with SMTP id g53mr31914958qtg.296.1570482708714; Mon, 07 Oct 2019 14:11:48 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Mon, 7 Oct 2019 18:11:33 -0300 Message-Id: <20191007211136.16730-2-danielhb413@gmail.com> In-Reply-To: <20191007211136.16730-1-danielhb413@gmail.com> References: <20191007211136.16730-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 07 Oct 2019 21:11:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 07 Oct 2019 21:11:49 +0000 (UTC) for IP:'209.85.160.196' DOMAIN:'mail-qt1-f196.google.com' HELO:'mail-qt1-f196.google.com' FROM:'danielhb413@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.153 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS) 209.85.160.196 mail-qt1-f196.google.com 209.85.160.196 mail-qt1-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , laine@laine.org Subject: [libvirt] [PATCH 1/4] utils: introducing PCI multifunction detection helpers 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 07 Oct 2019 21:14:06 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This patch introduces two helpers that will be used in the next patches. One is virpci.c:virPCIDeviceIsMultifunction(), and the other is virhostdev.c:virHostdevIsPCIMultifunctionDevice(). As the name suggests, the idea is to detect if a given dev/hostdev is a PCI multifunction device. Signed-off-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 2 ++ src/util/virhostdev.c | 24 ++++++++++++++++++++++++ src/util/virhostdev.h | 3 +++ src/util/virpci.c | 15 +++++++++++++++ src/util/virpci.h | 2 ++ 5 files changed, 46 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index eeab820eca..1c611ea8f4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2106,6 +2106,7 @@ virHostCPUStatsAssign; # util/virhostdev.h virHostdevFindUSBDevice; virHostdevIsMdevDevice; +virHostdevIsPCIMultifunctionDevice; virHostdevIsSCSIDevice; virHostdevManagerGetDefault; virHostdevPCINodeDeviceDetach; @@ -2684,6 +2685,7 @@ virPCIDeviceGetUnbindFromStub; virPCIDeviceGetUsedBy; virPCIDeviceHasPCIExpressLink; virPCIDeviceIsAssignable; +virPCIDeviceIsMultifunction; virPCIDeviceIsPCIExpress; virPCIDeviceListAdd; virPCIDeviceListAddCopy; diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 41fcab7222..1aa8e9729d 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -2191,3 +2191,27 @@ virHostdevUpdateActiveDomainDevices(virHostdevManage= rPtr mgr, =20 return 0; } + +bool +virHostdevIsPCIMultifunctionDevice(virDomainHostdevDefPtr hostdev) +{ + VIR_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/util/virhostdev.h b/src/util/virhostdev.h index 88501e2743..63a1d7367b 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -190,6 +190,9 @@ virHostdevIsSCSIDevice(virDomainHostdevDefPtr hostdev) bool virHostdevIsMdevDevice(virDomainHostdevDefPtr hostdev) ATTRIBUTE_NONNULL(1); +bool +virHostdevIsPCIMultifunctionDevice(virDomainHostdevDefPtr hostdev) + ATTRIBUTE_NONNULL(1); =20 /* functions used by NodeDevDetach/Reattach/Reset */ int virHostdevPCINodeDeviceDetach(virHostdevManagerPtr mgr, diff --git a/src/util/virpci.c b/src/util/virpci.c index ee78151e74..778e47ea08 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2863,6 +2863,21 @@ int virPCIGetHeaderType(virPCIDevicePtr dev, int *hd= rType) return 0; } =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; +} =20 void virPCIEDeviceInfoFree(virPCIEDeviceInfoPtr dev) diff --git a/src/util/virpci.h b/src/util/virpci.h index dc20f91710..7199882d6b 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -264,6 +264,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.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list