From nobody Sun Feb 8 14:11:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1590009229; cv=none; d=zohomail.com; s=zohoarc; b=iPV9HVHm4MqEc5tvFHMVvl4Q0xNiCkm2K1a4dIBdtTPIrWIvUd/XgFIfkjWH/BAOYr3o/xfSh84zQvt73mFoyW7SUjwGIID8QoA/qh8kvnT9MA8D0V2tr7PruC0IMy2GGEm+pXY7X3zlBwvhYnxIAo4c2grulS/Q8tpQCJ0VHqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009229; 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; bh=MkyOqom2mCSL8Jo0Fe4v9iZxSifpNTnfGK3/2VXG7pY=; b=OPtUIFPMjiaEK1MOuapLI/rz005tdrSMNqEpeLgirzHGsgqKWGXnxdGUmnEITG3wwKagkvd5kLB72iBS8fUXzmOi7Ujcssfs4/itV9y9yhwpwl4PxgrEXWPY3+1ImedEBPZ2pijz6Ksm0B4lu0Mk1l/xEVEz9WMYZdnIIECbFDM= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= 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 1590009229857575.3001016151235; Wed, 20 May 2020 14:13:49 -0700 (PDT) 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-92-AiJSiX8MNTqfQyjD6WEoLQ-1; Wed, 20 May 2020 17:13:45 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AB948835B44; Wed, 20 May 2020 21:13:40 +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 8A63F5D9CC; Wed, 20 May 2020 21:13:40 +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 5A780180954D; Wed, 20 May 2020 21:13:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCpR4002392 for ; Wed, 20 May 2020 17:12:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id BBFB810D17BF; Wed, 20 May 2020 21:12:51 +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 A616F10D17BE for ; Wed, 20 May 2020 21:12:51 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (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 7B19C8ECB20 for ; Wed, 20 May 2020 21:12:51 +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-394-Tnku9IQXM_ylHKMoCYXqhQ-1; Wed, 20 May 2020 17:12:49 -0400 Received: by mail-qt1-f195.google.com with SMTP id c24so3812047qtw.7 for ; Wed, 20 May 2020 14:12:49 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009228; 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=MkyOqom2mCSL8Jo0Fe4v9iZxSifpNTnfGK3/2VXG7pY=; b=aAQJHJmKjUbxQ0V3SauZv3vCerZ2RCb42pI8EIMR0/Tb8lw+eAAM51JVR2JG10IbC7TfgK //laKbnDQUYHvt2HSmmgpjCnjjRWFw4ZqfRtpfaRF3YcpZiGub2+3o734EQGfeRWcQuG8w 7dql41Gc0ECHEBBR1Zt2of1Zf1+TLt4= X-MC-Unique: AiJSiX8MNTqfQyjD6WEoLQ-1 X-MC-Unique: Tnku9IQXM_ylHKMoCYXqhQ-1 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=MkyOqom2mCSL8Jo0Fe4v9iZxSifpNTnfGK3/2VXG7pY=; b=ikPnNHcl35SWTwHkmjA2PZ2nMM/6NCM+iGYDdB8ZSj6KXmVQi90XtFU4NJae1yYMxQ X91t8M1FuT7/sd2u+2dWIjWc/FF30KZX7hEyhl2eIKl6FIsNS58Ylq8DrsTLVzXGf6Ok ATbQLzEKpGgyzf++c6YOFO0FB5WLUE9Jz3W5RA7d7fsIxqoSqt57rrxPIwOJGz0q50zi r9nnm0Zoy9YmhrK/aJFyVbOhZCHBgp36zE6Ch4AjEZ4XLJ1vyHeCPwyAK9n6A+FZziOP g6XESQdfa59z+iXE69aMpbcYfQuU+yQxp1Fl/q8/8euLt4avMF+rrkPtTm9s9AWAbfL6 Fx+A== X-Gm-Message-State: AOAM532E9hj00RM+Ubh5AUEeGLqOfDULLM6XH9CasNAww2z0JxIFxMb2 G/Nq6vnOJhCqBtokzMCKSHcvFm2C X-Google-Smtp-Source: ABdhPJwlX9dfKuUP7J3EdXbq1s8MsmA4CGgEckcBAMbqLWuwSPbXiBdVu/uNWtapMtuSxn+zVHJh6A== X-Received: by 2002:ac8:8f7:: with SMTP id y52mr7638229qth.104.1590009168437; Wed, 20 May 2020 14:12:48 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 21/21] qemu_hotplug.c: use enhanced multifunction unplug if available Date: Wed, 20 May 2020 18:11:43 -0300 Message-Id: <20200520211143.2980117-22-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 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.14 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 64dd69b923..806dc98556 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -6123,6 +6123,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); @@ -6198,15 +6199,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)); @@ -6214,8 +6216,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.26.2