From nobody Sun Feb 8 21:46:55 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 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1580402777325444.5788125025356; Thu, 30 Jan 2020 08:46:17 -0800 (PST) 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-427-NC6d5FRiMTeKL-VYFwOahw-1; Thu, 30 Jan 2020 11:46:13 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C10741005F73; Thu, 30 Jan 2020 16:46:03 +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 830FD845A9; Thu, 30 Jan 2020 16:46:03 +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 2A17F18034FB; Thu, 30 Jan 2020 16:46:03 +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 00UGjQvF032071 for ; Thu, 30 Jan 2020 11:45:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2D99A2166B2C; Thu, 30 Jan 2020 16:45:26 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 28D9E2166B2B for ; Thu, 30 Jan 2020 16:45:26 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 0AAA28013A3 for ; Thu, 30 Jan 2020 16:45:26 +0000 (UTC) Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-336-65m3OLW5MuuPnT8CCYOtQw-1; Thu, 30 Jan 2020 11:45:23 -0500 Received: by mail-qt1-f195.google.com with SMTP id v25so2979606qto.7 for ; Thu, 30 Jan 2020 08:45:23 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:c177:887c:ce1b:6a44:15ec]) by smtp.gmail.com with ESMTPSA id 135sm3007157qkj.55.2020.01.30.08.45.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 08:45:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580402776; 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=huDQ9uyWM+tigPfSB5Bo451bvh1zfyprrs+aTAEU7wg=; b=M1UFctkOiF9ddLIjbEJUAe5hp/xrZj0TKZYAiRol7gXZtGGnXJlUMjB2I1huFJUCKUmUp2 +drxHjjt4IsxMNvvWNdpBGEM6rsRB4fYfkdU9pL3jk0Aft9lm+7l5tlERHE3LGyTT/VTn0 dZFuAMqvidRyNHRQHHTpTzN+EUvVjP0= 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=iOaCJpVUx+Jo3G9dTiRlvHHQgpGm7rz0zARU1duscVw=; b=GKq/j4vFG5Pt6zz8quu9QrA/rpjk0lCRbh4yeVSToLgM8TuKFoZtnmNkyxmt0W3VXj q/rfE0YfbvN9rEGfVD3bzcE46V5fPC4JH1ycEjmfaBkkMjKbC+ptTd1JUajV1xFF54/c Pkhyza8J22p0lbJXky61xXw0DM60UecnJtow8KOq/9/uXP4R7xCjJmbuwo3UUnV80S5t /o3XtgceoB255OVxk+MmEqJK7xejfVOnIoqkKZvtkOTcTaaxXGkbGETgfA50HkVLCwny R53iqU/g4GxQgain3QdCPDFUW4fNC9Yx8EjuyQBeHYu7sFxdSKI0DKF+jOd/gJiG4HOd xAFQ== X-Gm-Message-State: APjAAAWusPc4RD5pvFRyr46DokNld7raXNCMcGovsypP9f+JPIe7zF40 bh3RIyuefj9uLp0JG4gjAuiVjqz6azw= X-Google-Smtp-Source: APXvYqxZPyVHy8Ka18B0OY6hALLjzQqFXBNckXS6R+xely9T8gKZB2WwuTvl7NVbqRJfWMkWKXjXxQ== X-Received: by 2002:ac8:1e90:: with SMTP id c16mr5776116qtm.265.1580402722804; Thu, 30 Jan 2020 08:45:22 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 20/21] qemu_hotplug: do not hotplug/hotunplug 'unassigned' hostdevs Date: Thu, 30 Jan 2020 13:44:32 -0300 Message-Id: <20200130164433.2694119-21-danielhb413@gmail.com> In-Reply-To: <20200130164433.2694119-1-danielhb413@gmail.com> References: <20200130164433.2694119-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: 65m3OLW5MuuPnT8CCYOtQw-1 X-MC-Unique: NC6d5FRiMTeKL-VYFwOahw-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 00UGjQvF032071 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.15 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" The new address type 'unassigned' allows for a hostdev to be managed by Libvirt, but not be assigned for guest usage. This can allow us to execute PCI multifunction hotplug, with managed mode, leaving non-zero functions unassigned. For hotplug and unplug , we'll skip unassigned devices when setting or evaluating aggregateSlotIdx and when we're about to execute device_add/device_del in QEMU. For hotplug we'll also skip adress assignment. For unplug we won't mark the device for removal since we won't be executing device_del on it. Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_domain_address.c | 6 ++ src/qemu/qemu_hotplug.c | 16 ++++ tests/qemuhotplugtest.c | 9 ++ ...plug-multifunction-hostdev-pci-partial.xml | 27 ++++++ ...live+multifunction-hostdev-pci-partial.xml | 82 +++++++++++++++++++ 5 files changed, 140 insertions(+) create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-multifunction-= hostdev-pci-partial.xml create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-live+mult= ifunction-hostdev-pci-partial.xml diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 395f054b8d..c8fe6bbd64 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -3511,6 +3511,9 @@ qemuDomainPCIMultifunctionHostdevEnsurePCIAddresses(v= irDomainObjPtr vm, for (i =3D 0; i < devlist->count; i++) { virDomainHostdevDefPtr hostdev =3D devlist->devs[i]->data.hostdev; =20 + if (hostdev->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNAS= SIGNED) + continue; + if (qemuDomainIsPSeries(vm->def)) { /* Isolation groups are only relevant for pSeries guests */ if (qemuDomainFillDeviceIsolationGroup(vm->def, devlist->devs[= i]) < 0) @@ -3544,6 +3547,9 @@ qemuDomainPCIMultifunctionHostdevEnsurePCIAddresses(v= irDomainObjPtr vm, virDomainHostdevDefPtr hostdev =3D devlist->devs[i]->data.hostdev; virPCIDeviceAddress addr =3D hostdev->source.subsys.u.pci.addr; =20 + if (hostdev->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNAS= SIGNED) + continue; + devinfos->infos[addr.function] =3D hostdev->info; } =20 diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index fe823bb910..00bd5499fe 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1629,6 +1629,13 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr drive= r, goto error; } =20 + /* For an unassigned hostdev, add it to the domain definition + * and return without hotplugging it to QEMU. */ + if (hostdev->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGN= ED) { + vm->def->hostdevs[vm->def->nhostdevs++] =3D hostdev; + return 0; + } + if (!(devstr =3D qemuBuildPCIHostdevDevStr(vm->def, hostdev, 0, priv->= qemuCaps))) goto error; =20 @@ -6058,6 +6065,9 @@ qemuDomainDetachMultifunctionDevice(virDomainObjPtr v= m, =20 /* Check if the devices belong to same guest slot.*/ FOR_EACH_DEV_IN_DEVLIST() + if (detach->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASS= IGNED) + continue; + /* Pick one aggregateSlotIdx and compare against rest of them */ slotaggridx =3D slotaggridx ? slotaggridx : detach->info->aggregat= eSlotIdx; if (slotaggridx !=3D detach->info->aggregateSlotIdx) { @@ -6090,6 +6100,9 @@ qemuDomainDetachMultifunctionDevice(virDomainObjPtr v= m, if (qemuAssignDeviceHostdevAlias(vm->def, &detach->info->alias, -1= ) < 0) goto reset; =20 + if (detach->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASS= IGNED) + continue; + qemuDomainMarkDeviceAliasForRemoval(vm, detach->info->alias, false= ); } =20 @@ -6102,6 +6115,9 @@ qemuDomainDetachMultifunctionDevice(virDomainObjPtr v= m, pcisrc =3D &subsys->u.pci; virDomainHostdevFind(vm->def, hostdev, &detach); =20 + if (detach->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASS= IGNED) + continue; + if (qemuMonitorDelDevice(priv->mon, detach->info->alias) < 0) { ignore_value(qemuDomainObjExitMonitor(driver, vm)); if (virDomainObjIsActive(vm)) diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index ffd91b5250..50e4bd535b 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -843,6 +843,15 @@ mymain(void) QMP_DEVICE_DELETED("hostdev1") QMP_DEVICE_DELETED("hostdev0") QMP_OK); =20 + DO_TEST_ATTACH("base-live", "multifunction-hostdev-pci-partial", false= , true, + "device_add", QMP_OK, + "device_add", QMP_OK, + "device_add", QMP_OK); + DO_TEST_DETACH("base-live", "multifunction-hostdev-pci-partial", false= , false, + "device_del", QMP_DEVICE_DELETED("hostdev3") + QMP_DEVICE_DELETED("hostdev2") + QMP_DEVICE_DELETED("hostdev0") QMP_OK); + qemuTestSetHostArch(&driver, VIR_ARCH_PPC64); DO_TEST_ATTACH("pseries-base-live", "multifunction-hostdev-pci-2", fal= se, true, "device_add", QMP_OK, diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-multifunction-hostdev= -pci-partial.xml b/tests/qemuhotplugtestdevices/qemuhotplug-multifunction-h= ostdev-pci-partial.xml new file mode 100644 index 0000000000..5e01564d2b --- /dev/null +++ b/tests/qemuhotplugtestdevices/qemuhotplug-multifunction-hostdev-pci-pa= rtial.xml @@ -0,0 +1,27 @@ + + + + +
+ + + + + +
+ +
+ + + + +
+ + + + + +
+ + + diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+multifuncti= on-hostdev-pci-partial.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base-= live+multifunction-hostdev-pci-partial.xml new file mode 100644 index 0000000000..1808a0071e --- /dev/null +++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+multifunction-host= dev-pci-partial.xml @@ -0,0 +1,82 @@ + + hotplug + d091ea82-29e6-2e34-3005-f02617b36e87 + 4194304 + 4194304 + 4 + + hvm + + + + + + + + + destroy + restart + restart + + /usr/bin/qemu-system-x86_64 + + +
+ + + +
+ + + +
+ + + + + + +
+ + + + + + + + + + +
+ + +
+ + + + +
+ + +
+ + + + +
+ + +
+ + + + +
+ + +
+ + + + + --=20 2.24.1