From nobody Sun Feb 8 07:07:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1580402771986887.8265302468297; Thu, 30 Jan 2020 08:46:11 -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-364-Phd_qdMJP3CHBGoSmhUHWg-1; Thu, 30 Jan 2020 11:46:05 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 07A98100551B; Thu, 30 Jan 2020 16:45:56 +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 B275188847; Thu, 30 Jan 2020 16:45:55 +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 7221718034ED; Thu, 30 Jan 2020 16:45:55 +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 00UGjR2i032083 for ; Thu, 30 Jan 2020 11:45:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id B18BF2166B2C; Thu, 30 Jan 2020 16:45:27 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AD7F42166B27 for ; Thu, 30 Jan 2020 16:45:27 +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 94244803B5C for ; Thu, 30 Jan 2020 16:45:27 +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-310-v2k1PT7MMTq86XyJBNlKgg-1; Thu, 30 Jan 2020 11:45:25 -0500 Received: by mail-qt1-f195.google.com with SMTP id w8so2954971qts.11 for ; Thu, 30 Jan 2020 08:45:24 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 08:45:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580402770; 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=Hsp1YljiZ17SvctLcn/Uz+kZddXp8RSMKfpBty+JVkk=; b=AbFe9ZAq+vuj9Z+VEBpJCc6TS0RXLf3TdEUwNI+PHe+ZfuU9nH3z4UJeiVuXHP7P1o5z7D wa35qD1KmJCM9L37DO3QJbZG50yGqadUiyDNuJQw3jvxbvChqMuqo4gyu4kVcU8KXaG97i 0izbdsPG6gUCWT5qPhPHq7IWLo4Ciaw= 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=uchFfOABKq0hRyg1by9mrhtw4DH8xJFVSVAcnH1S+e4=; b=gjUNP7PB3h+zP36ZjHchqnLhCy31aRyNkbkDXke1hhgJ5hsjcIG/NCtgTRpmUvVw3i X9sDcoCU31OggCJ6nUgC/eUBSWbG991N0OShrVQwkKYH5qWJG5pTsTEVoc6NVVMfhTgz F2LH96emnA6D/CS73Ou9BywdAtDqAgVmvg/nLaLZ7BEVRVaFYQaHgzaZNRoBkD+VhaGb Q1tBWCGfxCerJibjN/Sp6mOwNWrqPmvOGjN+RUaRpcpPuSlG803mXXGFwAhFJzhmVyER R9X6B8tbu9A/s2wrMQ8Eu2J5FVzegKk+CuvJ9sniK8uEcNjfxIf3+40uA+bh5wBbWa57 GAIA== X-Gm-Message-State: APjAAAXMSJ/9jmJM+jFCdZ6+KA+c629rkwOp/rTJsuF+lN1FJ1R4wwC6 ILRUzx9sX+c9AQE8uuCs9vsPmx8ugHI= X-Google-Smtp-Source: APXvYqw6UTonm+JU2TxGg47NeDr5mDbI7fkFROBIrtIiMoyfQk594yqTQosGKG7Ph4Twf9TBQBFALA== X-Received: by 2002:aed:2022:: with SMTP id 31mr5530869qta.321.1580402724401; Thu, 30 Jan 2020 08:45:24 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 21/21] qemu_hotplug.c: use enhanced multifunction unplug if available Date: Thu, 30 Jan 2020 13:44:33 -0300 Message-Id: <20200130164433.2694119-22-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: v2k1PT7MMTq86XyJBNlKgg-1 X-MC-Unique: Phd_qdMJP3CHBGoSmhUHWg-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 00UGjR2i032083 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.11 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" QEMU 4.2.0 introduced an enhanced version of the PCI multifunction hotunplug for the PSeries guest [1] where a single device_del of the function 0 will detach all the functions of the slot. The idea is to make this option similar to the behavior we already have on x86. This means that the unplug code in qemuDomainDetachMultifunctionDevice() can be simplified if the domain is running with QEMU 4.2.0 or newer. [1] https://github.com/qemu/qemu/commit/02a1536eee333123c7735cd36484da53b86= 0fbb7 Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_hotplug.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 00bd5499fe..567b9aba03 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -6033,6 +6033,7 @@ qemuDomainDetachMultifunctionDevice(virDomainObjPtr v= m, int slotaggridx =3D 0; virDomainHostdevSubsysPCIPtr pcisrc =3D NULL; qemuDomainObjPrivatePtr priv =3D vm->privateData; + int pSeriesEnhancedUnplugVersion; =20 qsort(devlist->devs, devlist->count, sizeof(*devlist->devs), qemuiHostdevPCIMultifunctionDevicesListSort); @@ -6108,15 +6109,16 @@ qemuDomainDetachMultifunctionDevice(virDomainObjPtr= vm, =20 qemuDomainObjEnterMonitor(driver, vm); =20 - /* must plug non-zero first, zero at last */ - for (i =3D devlist->count; i > 0; i--) { - hostdev =3D devlist->devs[i -1]->data.hostdev; - subsys =3D &hostdev->source.subsys; - pcisrc =3D &subsys->u.pci; - virDomainHostdevFind(vm->def, hostdev, &detach); + /* QEMU 4.2.0 introduced a new Pseries hotunplug mechanic, where + * the whole slot can be unplugged by hotunplugging function zero + * (see QEMU commit 02a1536eee for details). This makes it similar + * to what x86 does, as long as we hotunplug function zero first + * in all cases. */ + pSeriesEnhancedUnplugVersion =3D 4 * 1000000 + 2 * 1000; =20 - if (detach->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASS= IGNED) - continue; + if (virQEMUCapsGetVersion(priv->qemuCaps) >=3D pSeriesEnhancedUnplugVe= rsion) { + hostdev =3D devlist->devs[0]->data.hostdev; + virDomainHostdevFind(vm->def, hostdev, &detach); =20 if (qemuMonitorDelDevice(priv->mon, detach->info->alias) < 0) { ignore_value(qemuDomainObjExitMonitor(driver, vm)); @@ -6124,8 +6126,25 @@ qemuDomainDetachMultifunctionDevice(virDomainObjPtr = vm, virDomainAuditHostdev(vm, detach, "detach", false); goto reset; } - if (ARCH_IS_X86(vm->def->os.arch)) - break; /* deleting any one is enough! */ + } else { + /* We're running in an older QEMU, so we must plug non-zero first, + * zero at last. */ + for (i =3D devlist->count; i > 0; i--) { + hostdev =3D devlist->devs[i -1]->data.hostdev; + virDomainHostdevFind(vm->def, hostdev, &detach); + + if (detach->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_U= NASSIGNED) + continue; + + if (qemuMonitorDelDevice(priv->mon, detach->info->alias) < 0) { + ignore_value(qemuDomainObjExitMonitor(driver, vm)); + if (virDomainObjIsActive(vm)) + virDomainAuditHostdev(vm, detach, "detach", false); + goto reset; + } + if (ARCH_IS_X86(vm->def->os.arch)) + break; /* deleting any one is enough! */ + } } =20 if (qemuDomainObjExitMonitor(driver, vm) < 0) --=20 2.24.1