From nobody Thu May 15 03:44:28 2025 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1516872723244427.4780636545255; Thu, 25 Jan 2018 01:32:03 -0800 (PST) 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 CEF7378553; Thu, 25 Jan 2018 09:32:01 +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 8F265605D8; Thu, 25 Jan 2018 09:32:01 +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 3EFD918033DC; Thu, 25 Jan 2018 09:32:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0P9QvhI001065 for ; Thu, 25 Jan 2018 04:26:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 285092C322; Thu, 25 Jan 2018 09:26:57 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0721D65608; Thu, 25 Jan 2018 09:26:51 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:24:02 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH 15/15] conf: nodedev: Update PCI mdev capabilities dynamically 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: , MIME-Version: 1.0 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]); Thu, 25 Jan 2018 09:32:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Just like SRIOV, a PCI device is only capable of the mediated devices framework when it's bound to the vendor native driver, thus if a driver change occurs, e.g. vendor_native->vfio, we need to refresh some of the device's capabilities to reflect the reality, mdev included. Signed-off-by: Erik Skultety Suggested-by: Wu Zongyong --- src/conf/node_device_conf.c | 34 +++++++++++++++++++++++++++++++--- src/node_device/node_device_udev.c | 1 - 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 5fc5f6708..9e4273855 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2758,6 +2758,34 @@ virNodeDeviceGetPCIIOMMUGroupCaps(virNodeDevCapPCIDe= vPtr pci_dev) } =20 =20 +static int +virNodeDeviceGetPCIMdevTypesCaps(const char *sysfspath, + virNodeDevCapPCIDevPtr pci_dev) +{ + virMediatedDeviceTypePtr *types =3D NULL; + int rc =3D 0; + size_t i; + + /* this could be a refresh, so clear out the old data */ + for (i =3D 0; i < pci_dev->nmdev_types; i++) + virMediatedDeviceTypeFree(pci_dev->mdev_types[i]); + VIR_FREE(pci_dev->mdev_types); + pci_dev->nmdev_types =3D 0; + pci_dev->flags &=3D ~VIR_NODE_DEV_CAP_FLAG_PCI_MDEV; + + rc =3D virPCIGetMdevTypes(sysfspath, &types); + + if (rc <=3D 0) + return rc; + + VIR_STEAL_PTR(pci_dev->mdev_types, types); + pci_dev->nmdev_types =3D rc; + pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_MDEV; + + return 0; +} + + /* virNodeDeviceGetPCIDynamicCaps() get info that is stored in sysfs * about devices related to this device, i.e. things that can change * without this device itself changing. These must be refreshed @@ -2768,9 +2796,9 @@ int virNodeDeviceGetPCIDynamicCaps(const char *sysfsPath, virNodeDevCapPCIDevPtr pci_dev) { - if (virNodeDeviceGetPCISRIOVCaps(sysfsPath, pci_dev) < 0) - return -1; - if (virNodeDeviceGetPCIIOMMUGroupCaps(pci_dev) < 0) + if (virNodeDeviceGetPCISRIOVCaps(sysfsPath, pci_dev) < 0 || + virNodeDeviceGetPCIIOMMUGroupCaps(pci_dev) < 0 || + virNodeDeviceGetPCIMdevTypesCaps(sysfsPath, pci_dev) < 0) return -1; return 0; } diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 1ccf1f8b4..e10660ba0 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -484,7 +484,6 @@ udevProcessPCI(struct udev_device *device, } =20 ret =3D 0; - cleanup: virPCIDeviceFree(pciDev); virPCIEDeviceInfoFree(pci_express); --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list