From nobody Wed May 14 12:35:25 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; dmarc=fail(p=none dis=none) header.from=linux.ibm.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1539920836230393.5011849590867; Thu, 18 Oct 2018 20:47:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2C4D9C03D466; Fri, 19 Oct 2018 03:47:14 +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 D87775C72E; Fri, 19 Oct 2018 03:47:13 +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 91CF318005B2; Fri, 19 Oct 2018 03:47:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9J3evl5031982 for ; Thu, 18 Oct 2018 23:40:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id EC01B884E4; Fri, 19 Oct 2018 03:40:57 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E20C6884E1 for ; Fri, 19 Oct 2018 03:40:56 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ECFF13084294 for ; Fri, 19 Oct 2018 03:40:54 +0000 (UTC) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w9J3dOU8110499 for ; Thu, 18 Oct 2018 23:40:54 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 2n70g074cg-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 18 Oct 2018 23:40:54 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 18 Oct 2018 21:40:53 -0600 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 18 Oct 2018 21:40:50 -0600 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w9J3enLh29098040 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 18 Oct 2018 20:40:49 -0700 Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 205656E054; Fri, 19 Oct 2018 03:40:49 +0000 (GMT) Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 065876E04E; Fri, 19 Oct 2018 03:40:47 +0000 (GMT) Received: from zyimindembp.cn.ibm.com (unknown [9.115.192.238]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 19 Oct 2018 03:40:46 +0000 (GMT) From: Yi Min Zhao To: libvir-list@redhat.com Date: Fri, 19 Oct 2018 11:40:12 +0800 In-Reply-To: <20181019034020.4757-1-zyimin@linux.ibm.com> References: <20181019034020.4757-1-zyimin@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18101903-0004-0000-0000-000014A11626 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009898; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000268; SDB=6.01104747; UDB=6.00571940; IPR=6.00884797; MB=3.00023816; MTD=3.00000008; XFM=3.00000015; UTC=2018-10-19 03:40:52 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18101903-0005-0000-0000-00008935769D Message-Id: <20181019034020.4757-7-zyimin@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-10-18_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=895 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810190033 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 19 Oct 2018 03:40:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 19 Oct 2018 03:40:55 +0000 (UTC) for IP:'148.163.156.1' DOMAIN:'mx0a-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'zyimin@linux.ibm.com' RCPT:'' X-RedHat-Spam-Score: 1.298 * (KHOP_DYNAMIC, RCVD_IN_DNSWL_LOW, SPF_PASS) 148.163.156.1 mx0a-001b2d01.pphosted.com 148.163.156.1 mx0a-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: fiuczy@linux.ibm.com, cohuck@redhat.com, abologna@redhat.com, bwalk@linux.ibm.com, jtomko@redhat.com, laine@laine.org Subject: [libvirt] [PATCH v7 06/14] conf: Introduce address caching for PCI extensions 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-Type: text/plain; charset="utf-8" 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 19 Oct 2018 03:47:14 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 This patch provides a caching mechanism for the device address extensions uid and fid on S390. For efficient sparse address allocation, we introduce two hash tables for uid/fid which hold the address set information per domain. Also in order to improve performance of searching available value, we introduce our own callbacks for the two hashtables. In this way, uid/fid is saved in hash key and hash value could be any non-NULL pointer due to no operation on hash value. That is also the reason why we don't introduce hash value free callback. Signed-off-by: Yi Min Zhao Reviewed-by: Boris Fiuczynski Reviewed-by: Bjoern Walk Reviewed-by: J=C3=A1n Tomko Reviewed-by: Andrea Bolognani --- src/bhyve/bhyve_device.c | 3 +- src/conf/domain_addr.c | 93 +++++++++++++++++++++++++++++++++- src/conf/domain_addr.h | 10 +++- src/qemu/qemu_domain_address.c | 6 ++- 4 files changed, 108 insertions(+), 4 deletions(-) diff --git a/src/bhyve/bhyve_device.c b/src/bhyve/bhyve_device.c index 207ac6a2dd..a59dfe4519 100644 --- a/src/bhyve/bhyve_device.c +++ b/src/bhyve/bhyve_device.c @@ -71,7 +71,8 @@ bhyveDomainPCIAddressSetCreate(virDomainDefPtr def, unsig= ned int nbuses) { virDomainPCIAddressSetPtr addrs; =20 - if ((addrs =3D virDomainPCIAddressSetAlloc(nbuses)) =3D=3D NULL) + if ((addrs =3D virDomainPCIAddressSetAlloc(nbuses, + VIR_PCI_ADDRESS_EXTENSION_NON= E)) =3D=3D NULL) return NULL; =20 if (virDomainPCIAddressBusSetModel(&addrs->buses[0], diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 442e6aab94..902837d4ee 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -27,6 +27,7 @@ #include "virlog.h" #include "virstring.h" #include "domain_addr.h" +#include "virhashcode.h" =20 #define VIR_FROM_THIS VIR_FROM_DOMAIN =20 @@ -727,8 +728,93 @@ virDomainPCIAddressReleaseAddr(virDomainPCIAddressSetP= tr addrs, addrs->buses[addr->bus].slot[addr->slot].functions &=3D ~(1 << addr->f= unction); } =20 + +static uint32_t +virZPCIAddrKeyCode(const void *name, + uint32_t seed) +{ + unsigned int value =3D *((unsigned int *)name); + return virHashCodeGen(&value, sizeof(value), seed); +} + + +static bool +virZPCIAddrKeyEqual(const void *namea, + const void *nameb) +{ + return *((unsigned int *)namea) =3D=3D *((unsigned int *)nameb); +} + + +static void * +virZPCIAddrKeyCopy(const void *name) +{ + unsigned int *copy; + + if (VIR_ALLOC(copy) < 0) + return NULL; + + *copy =3D *((unsigned int *)name); + return (void *)copy; +} + + +static void +virZPCIAddrKeyFree(void *name) +{ + VIR_FREE(name); +} + + +static void +virDomainPCIAddressSetExtensionFree(virDomainPCIAddressSetPtr addrs) +{ + if (!addrs || !addrs->zpciIds) + return; + + virHashFree(addrs->zpciIds->uids); + virHashFree(addrs->zpciIds->fids); + VIR_FREE(addrs->zpciIds); +} + + +static int +virDomainPCIAddressSetExtensionAlloc(virDomainPCIAddressSetPtr addrs, + virPCIDeviceAddressExtensionFlags ext= Flags) +{ + if (extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) { + if (addrs->zpciIds) + return 0; + + if (VIR_ALLOC(addrs->zpciIds) < 0) + return -1; + + if (!(addrs->zpciIds->uids =3D virHashCreateFull(10, NULL, + virZPCIAddrKeyCode, + virZPCIAddrKeyEqual, + virZPCIAddrKeyCopy, + virZPCIAddrKeyFree)= )) + goto error; + + if (!(addrs->zpciIds->fids =3D virHashCreateFull(10, NULL, + virZPCIAddrKeyCode, + virZPCIAddrKeyEqual, + virZPCIAddrKeyCopy, + virZPCIAddrKeyFree)= )) + goto error; + } + + return 0; + + error: + virDomainPCIAddressSetExtensionFree(addrs); + return -1; +} + + virDomainPCIAddressSetPtr -virDomainPCIAddressSetAlloc(unsigned int nbuses) +virDomainPCIAddressSetAlloc(unsigned int nbuses, + virPCIDeviceAddressExtensionFlags extFlags) { virDomainPCIAddressSetPtr addrs; =20 @@ -739,6 +825,10 @@ virDomainPCIAddressSetAlloc(unsigned int nbuses) goto error; =20 addrs->nbuses =3D nbuses; + + if (virDomainPCIAddressSetExtensionAlloc(addrs, extFlags) < 0) + goto error; + return addrs; =20 error: @@ -753,6 +843,7 @@ virDomainPCIAddressSetFree(virDomainPCIAddressSetPtr ad= drs) if (!addrs) return; =20 + virDomainPCIAddressSetExtensionFree(addrs); VIR_FREE(addrs->buses); VIR_FREE(addrs); } diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index 435b3c5d7f..8d64d6b795 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -116,6 +116,12 @@ typedef struct { } virDomainPCIAddressBus; typedef virDomainPCIAddressBus *virDomainPCIAddressBusPtr; =20 +typedef struct { + virHashTablePtr uids; + virHashTablePtr fids; +} virDomainZPCIAddressIds; +typedef virDomainZPCIAddressIds *virDomainZPCIAddressIdsPtr; + struct _virDomainPCIAddressSet { virDomainPCIAddressBus *buses; size_t nbuses; @@ -125,11 +131,13 @@ struct _virDomainPCIAddressSet { bool areMultipleRootsSupported; /* If true, the guest can use the pcie-to-pci-bridge controller */ bool isPCIeToPCIBridgeSupported; + virDomainZPCIAddressIdsPtr zpciIds; }; typedef struct _virDomainPCIAddressSet virDomainPCIAddressSet; typedef virDomainPCIAddressSet *virDomainPCIAddressSetPtr; =20 -virDomainPCIAddressSetPtr virDomainPCIAddressSetAlloc(unsigned int nbuses); +virDomainPCIAddressSetPtr virDomainPCIAddressSetAlloc(unsigned int nbuses, + virPCIDeviceAddressE= xtensionFlags extFlags); =20 void virDomainPCIAddressSetFree(virDomainPCIAddressSetPtr addrs); =20 diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index c0374ccaf3..665f6c1445 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1505,8 +1505,12 @@ qemuDomainPCIAddressSetCreate(virDomainDefPtr def, size_t i; bool hasPCIeRoot =3D false; virDomainControllerModelPCI defaultModel; + virPCIDeviceAddressExtensionFlags extFlags =3D VIR_PCI_ADDRESS_EXTENSI= ON_NONE; =20 - if ((addrs =3D virDomainPCIAddressSetAlloc(nbuses)) =3D=3D NULL) + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_ZPCI)) + extFlags |=3D VIR_PCI_ADDRESS_EXTENSION_ZPCI; + + if ((addrs =3D virDomainPCIAddressSetAlloc(nbuses, extFlags)) =3D=3D N= ULL) return NULL; =20 addrs->dryRun =3D dryRun; --=20 Yi Min -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list