From nobody Wed May 8 12:04:28 2024 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589479985; cv=none; d=zohomail.com; s=zohoarc; b=TWyKSpWP7YX3qRpxaLbZnsuVIpgek32mi8fo9ewpVct7NXEWC3jTVWbZe+38s2p7rIqV5ehkWprOFLsIPYpG5zpQConApuBD1v8Rn6kf/OpWyT0/NuRaK5K9uaAZWdcVGGoMRNheRnsv9QeJfKh9Rn7p7wTcbVzvh4HqoJBMAo4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589479985; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=JHSuMplXtQt3jgE6/WgWbMH3q1262D2Q4/JE6MshXZQ=; b=OwiaPPvN/TFxok5KB0q3DxL76qOwMiY6ZmAglVGr7lq2bFpHJsr5Jiq9JMFoWXGjkVKKtMqbBlpvbRx5vjOmwdpAFSom6ZHXGe3yD95nF4saw5nYvP7f1bGBeKEw4uoLN4ONqKdWe259L8dvkWD3nJH2IuMwU2RUnj82B8cW4FQ= 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=pass 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 1589479985693606.3547704512932; Thu, 14 May 2020 11:13:05 -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-290-wsLaFslbOOCHkmfFnKIwkg-1; Thu, 14 May 2020 14:13:01 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 411871B18BC1; Thu, 14 May 2020 18:12:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 812F75C1D3; Thu, 14 May 2020 18:12:53 +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 6B7A24E98C; Thu, 14 May 2020 18:12:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04EICkjM028619 for ; Thu, 14 May 2020 14:12:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id F3177500D2; Thu, 14 May 2020 18:12:45 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-130.phx2.redhat.com [10.3.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA4A760F8D for ; Thu, 14 May 2020 18:12:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589479984; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=JHSuMplXtQt3jgE6/WgWbMH3q1262D2Q4/JE6MshXZQ=; b=f7WaOkT5pL+ND7dp6MHLAf2n8v1PUvmCuyooHQHuSKSeNoSmEzs3LWatpXvb2wC8Tgs1SN J1USTA1XV2GeuWA1FKPbRk8YQnbYSxZbQ++b1KCXIoHfrYfu+1IRdGd9MdXhazA5dCP4iP PN403HyE5AgBNkI4N25CmPRCI/FF/Sg= X-MC-Unique: wsLaFslbOOCHkmfFnKIwkg-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH] qemu: prevent attempts to detach a device on a controller with hotplug='off' Date: Thu, 14 May 2020 14:12:38 -0400 Message-Id: <20200514181238.2153800-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.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.16 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" Although the original patches to support controllers with hotplug=3D'off' were checking during hotplug/attach requests that the device was being plugged into a PCI controller that didn't have hotplug disabled, but I forgot to do the same for device detach (the main impetus for adding the feature was to prevent unplugs originating from within the guest, so it slipped my mind). So although the guest OS was ultimately unable to honor the unplug request, libvirt could still be used to make such a request, and since device attach/detach are asynchronous operations, the caller to libvirt would receive a success status back (the device would stubbornly/correctly remain in the domain status XML however) This patch remedies that, by looking at the controller for the device in the detach request, and immediately failing the operation if that controller has hotplug=3Doff. r changes. Lines starting Signed-off-by: Laine Stump Reviewed-by: Erik Skultety --- src/qemu/qemu_hotplug.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index ab5a7aef84..5fe125b1a7 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5891,6 +5891,33 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, return -1; } =20 + if (info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { + int controllerIdx =3D virDomainControllerFind(vm->def, + VIR_DOMAIN_CONTROLLER_= TYPE_PCI, + info->addr.pci.bus); + if (controllerIdx < 0) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("cannot hot unplug %s device with PCI guest a= ddress: " + VIR_PCI_DEVICE_ADDRESS_FMT + " - controller not found"), + virDomainDeviceTypeToString(detach.type), + info->addr.pci.domain, info->addr.pci.bus, + info->addr.pci.slot, info->addr.pci.function); + return -1; + } + + if (vm->def->controllers[controllerIdx]->opts.pciopts.hotplug + =3D=3D VIR_TRISTATE_SWITCH_OFF) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("cannot hot unplug %s device with PCI guest a= ddress: " + VIR_PCI_DEVICE_ADDRESS_FMT + " - not allowed by controller"), + virDomainDeviceTypeToString(detach.type), + info->addr.pci.domain, info->addr.pci.bus, + info->addr.pci.slot, info->addr.pci.function); + return -1; + } + } /* * Issue the qemu monitor command to delete the device (based on * its alias), and optionally wait a short time in case the --=20 2.25.4