From nobody Sun May 5 17:23:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579128141; cv=none; d=zohomail.com; s=zohoarc; b=Zzg/PAeX7a8Hdu18SnUFafujeQgUK5Z1Vi5EWm/fK2Hp0S6jfQ9/yuWR7vhHS6f3BFXTr5xxoWLh0fOEElgod94YJHJM+rH16vGQV+v4f0iMOkzxJpeeCLHJM7JC0+tWQPXawkc2DZMtOipUgLUYW6oOB8/+hSfwt/CSoTBqIgY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579128141; 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=esXjy09dsJah3p8AxFrJa2cBZHD3KQoNYbnWGZtRarM=; b=e2/qrGDjyfYDnvAfbe7IDbi/yTO41b3VRyVWcgjl9CRUJMJp6L+qPWSmc8Brb8dACQLxzoowdaxdrts+B6JJvQgMyS+Q0KD6G6Ukrd34aYmPWhbfJr7zKaZXo3w4KjTWX++ODAlMhkvo117Uiv02Zm1T666zPAqHmplJ260ahuE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15791281414791000.8076032187929; Wed, 15 Jan 2020 14:42:21 -0800 (PST) Received: from localhost ([::1]:33530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irrMi-0004lb-9Q for importer@patchew.org; Wed, 15 Jan 2020 17:42:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39858) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irrLN-0003Rb-SW for qemu-devel@nongnu.org; Wed, 15 Jan 2020 17:40:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irrLI-0002IH-W9 for qemu-devel@nongnu.org; Wed, 15 Jan 2020 17:40:57 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:37896 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1irrLH-0002E3-GC for qemu-devel@nongnu.org; Wed, 15 Jan 2020 17:40:51 -0500 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-226-Oa5i0Z8MP_mw1KKXJpb0aQ-1; Wed, 15 Jan 2020 17:40:48 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C432DB21 for ; Wed, 15 Jan 2020 22:40:47 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-94.brq.redhat.com [10.40.204.94]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2974B82062; Wed, 15 Jan 2020 22:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579128050; h=from:from: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; bh=esXjy09dsJah3p8AxFrJa2cBZHD3KQoNYbnWGZtRarM=; b=NlS9ri2oxgSyD/Ig+THJMiFPtQcRll4lUNy38DWl48YSq2r6x34vDPmk2hiMuRYaQqzVUl zjcB8JqJkiuSCNkd5jEyS03RcEctpjhWk+oWQSpIt6gBm3ZpDsEWQ5R4lHLeNcic06hRPj U38sc15og7SpIPUuPHYuUQXzuE+raFo= From: Julia Suvorova To: qemu-devel@nongnu.org Subject: [PATCH 1/2] qdev: Introduce qdev_get_bus_device Date: Wed, 15 Jan 2020 23:40:24 +0100 Message-Id: <20200115224025.538368-2-jusual@redhat.com> In-Reply-To: <20200115224025.538368-1-jusual@redhat.com> References: <20200115224025.538368-1-jusual@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: Oa5i0Z8MP_mw1KKXJpb0aQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S. Tsirkin" , Julia Suvorova , Gerd Hoffmann , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" For bus devices, it is useful to be able to handle the parent device. Signed-off-by: Julia Suvorova --- hw/core/qdev.c | 5 +++++ hw/pci-bridge/pci_expander_bridge.c | 4 +++- hw/scsi/scsi-bus.c | 4 +++- hw/usb/bus.c | 4 +++- hw/usb/dev-smartcard-reader.c | 32 +++++++++++++++++++++-------- hw/virtio/virtio-pci.c | 16 +++++++++++++-- include/hw/qdev-core.h | 2 ++ 7 files changed, 54 insertions(+), 13 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 9f1753f5cf..ad8226e240 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -114,6 +114,11 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *b= us) } } =20 +DeviceState *qdev_get_bus_device(const DeviceState *dev) +{ + return dev->parent_bus ? dev->parent_bus->parent : NULL; +} + /* Create a new device. This only initializes the device state structure and allows properties to be set. The device still needs to be realized. See qdev-core.h. */ diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expand= er_bridge.c index 0592818447..63a6c07406 100644 --- a/hw/pci-bridge/pci_expander_bridge.c +++ b/hw/pci-bridge/pci_expander_bridge.c @@ -125,9 +125,11 @@ static char *pxb_host_ofw_unit_address(const SysBusDev= ice *dev) assert(position >=3D 0); =20 pxb_dev_base =3D DEVICE(pxb_dev); - main_host =3D PCI_HOST_BRIDGE(pxb_dev_base->parent_bus->parent); + main_host =3D PCI_HOST_BRIDGE(qdev_get_bus_device(pxb_dev_base)); main_host_sbd =3D SYS_BUS_DEVICE(main_host); =20 + g_assert(main_host); + if (main_host_sbd->num_mmio > 0) { return g_strdup_printf(TARGET_FMT_plx ",%x", main_host_sbd->mmio[0].addr, position + 1); diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index ad0e7f6d88..3d9497882b 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -1558,10 +1558,12 @@ void scsi_device_purge_requests(SCSIDevice *sdev, S= CSISense sense) static char *scsibus_get_dev_path(DeviceState *dev) { SCSIDevice *d =3D SCSI_DEVICE(dev); - DeviceState *hba =3D dev->parent_bus->parent; + DeviceState *hba =3D qdev_get_bus_device(dev); char *id; char *path; =20 + g_assert(hba); + id =3D qdev_get_dev_path(hba); if (id) { path =3D g_strdup_printf("%s/%d:%d:%d", id, d->channel, d->id, d->= lun); diff --git a/hw/usb/bus.c b/hw/usb/bus.c index a6522f5429..26bf794315 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -587,9 +587,11 @@ static void usb_bus_dev_print(Monitor *mon, DeviceStat= e *qdev, int indent) static char *usb_get_dev_path(DeviceState *qdev) { USBDevice *dev =3D USB_DEVICE(qdev); - DeviceState *hcd =3D qdev->parent_bus->parent; + DeviceState *hcd =3D qdev_get_bus_device(qdev); char *id =3D NULL; =20 + g_assert(hcd); + if (dev->flags & (1 << USB_DEV_FLAG_FULL_PATH)) { id =3D qdev_get_dev_path(hcd); } diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c index 4568db2568..fbb3599ddd 100644 --- a/hw/usb/dev-smartcard-reader.c +++ b/hw/usb/dev-smartcard-reader.c @@ -1185,10 +1185,12 @@ void ccid_card_send_apdu_to_guest(CCIDCardState *ca= rd, uint8_t *apdu, uint32_t len) { DeviceState *qdev =3D DEVICE(card); - USBDevice *dev =3D USB_DEVICE(qdev->parent_bus->parent); + USBDevice *dev =3D USB_DEVICE(qdev_get_bus_device(qdev)); USBCCIDState *s =3D USB_CCID_DEV(dev); Answer *answer; =20 + g_assert(dev); + if (!ccid_has_pending_answers(s)) { DPRINTF(s, 1, "CCID ERROR: got an APDU without pending answers\n"); return; @@ -1208,9 +1210,11 @@ void ccid_card_send_apdu_to_guest(CCIDCardState *car= d, void ccid_card_card_removed(CCIDCardState *card) { DeviceState *qdev =3D DEVICE(card); - USBDevice *dev =3D USB_DEVICE(qdev->parent_bus->parent); + USBDevice *dev =3D USB_DEVICE(qdev_get_bus_device(qdev)); USBCCIDState *s =3D USB_CCID_DEV(dev); =20 + g_assert(dev); + ccid_on_slot_change(s, false); ccid_flush_pending_answers(s); ccid_reset(s); @@ -1219,9 +1223,11 @@ void ccid_card_card_removed(CCIDCardState *card) int ccid_card_ccid_attach(CCIDCardState *card) { DeviceState *qdev =3D DEVICE(card); - USBDevice *dev =3D USB_DEVICE(qdev->parent_bus->parent); + USBDevice *dev =3D USB_DEVICE(qdev_get_bus_device(qdev)); USBCCIDState *s =3D USB_CCID_DEV(dev); =20 + g_assert(dev); + DPRINTF(s, 1, "CCID Attach\n"); return 0; } @@ -1229,9 +1235,11 @@ int ccid_card_ccid_attach(CCIDCardState *card) void ccid_card_ccid_detach(CCIDCardState *card) { DeviceState *qdev =3D DEVICE(card); - USBDevice *dev =3D USB_DEVICE(qdev->parent_bus->parent); + USBDevice *dev =3D USB_DEVICE(qdev_get_bus_device(qdev)); USBCCIDState *s =3D USB_CCID_DEV(dev); =20 + g_assert(dev); + DPRINTF(s, 1, "CCID Detach\n"); if (ccid_card_inserted(s)) { ccid_on_slot_change(s, false); @@ -1242,9 +1250,11 @@ void ccid_card_ccid_detach(CCIDCardState *card) void ccid_card_card_error(CCIDCardState *card, uint64_t error) { DeviceState *qdev =3D DEVICE(card); - USBDevice *dev =3D USB_DEVICE(qdev->parent_bus->parent); + USBDevice *dev =3D USB_DEVICE(qdev_get_bus_device(qdev)); USBCCIDState *s =3D USB_CCID_DEV(dev); =20 + g_assert(dev); + s->bmCommandStatus =3D COMMAND_STATUS_FAILED; s->last_answer_error =3D error; DPRINTF(s, 1, "VSC_Error: %" PRIX64 "\n", s->last_answer_error); @@ -1261,9 +1271,11 @@ void ccid_card_card_error(CCIDCardState *card, uint6= 4_t error) void ccid_card_card_inserted(CCIDCardState *card) { DeviceState *qdev =3D DEVICE(card); - USBDevice *dev =3D USB_DEVICE(qdev->parent_bus->parent); + USBDevice *dev =3D USB_DEVICE(qdev_get_bus_device(qdev)); USBCCIDState *s =3D USB_CCID_DEV(dev); =20 + g_assert(dev); + s->bmCommandStatus =3D COMMAND_STATUS_NO_ERROR; ccid_flush_pending_answers(s); ccid_on_slot_change(s, true); @@ -1273,10 +1285,12 @@ static void ccid_card_unrealize(DeviceState *qdev, = Error **errp) { CCIDCardState *card =3D CCID_CARD(qdev); CCIDCardClass *cc =3D CCID_CARD_GET_CLASS(card); - USBDevice *dev =3D USB_DEVICE(qdev->parent_bus->parent); + USBDevice *dev =3D USB_DEVICE(qdev_get_bus_device(qdev)); USBCCIDState *s =3D USB_CCID_DEV(dev); Error *local_err =3D NULL; =20 + g_assert(dev); + if (ccid_card_inserted(s)) { ccid_card_card_removed(card); } @@ -1294,10 +1308,12 @@ static void ccid_card_realize(DeviceState *qdev, Er= ror **errp) { CCIDCardState *card =3D CCID_CARD(qdev); CCIDCardClass *cc =3D CCID_CARD_GET_CLASS(card); - USBDevice *dev =3D USB_DEVICE(qdev->parent_bus->parent); + USBDevice *dev =3D USB_DEVICE(qdev_get_bus_device(qdev)); USBCCIDState *s =3D USB_CCID_DEV(dev); Error *local_err =3D NULL; =20 + g_assert(dev); + if (card->slot !=3D 0) { error_setg(errp, "usb-ccid supports one slot, can't add %d", card->slot); diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index f723b9f631..8ce9269aab 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1317,9 +1317,21 @@ static uint64_t virtio_pci_notify_read(void *opaque,= hwaddr addr, static void virtio_pci_notify_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) { + DeviceState *dev =3D DEVICE(opaque); VirtIODevice *vdev =3D opaque; - VirtIOPCIProxy *proxy =3D VIRTIO_PCI(DEVICE(vdev)->parent_bus->parent); - unsigned queue =3D addr / virtio_pci_queue_mem_mult(proxy); + VirtIOPCIProxy *proxy =3D VIRTIO_PCI(qdev_get_bus_device(dev)); + unsigned queue; + + /* + * During unplug virtio device may have + * already been disconnected from the bus + */ + if (!proxy) { + warn_report("Device %s doesn't have parent bus", vdev->name); + return; + } + + queue =3D addr / virtio_pci_queue_mem_mult(proxy); =20 if (queue < VIRTIO_QUEUE_MAX) { virtio_queue_notify(vdev, queue); diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 1518495b1e..05d68f0f1a 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -452,6 +452,8 @@ Object *qdev_get_machine(void); /* FIXME: make this a link<> */ void qdev_set_parent_bus(DeviceState *dev, BusState *bus); =20 +DeviceState *qdev_get_bus_device(const DeviceState *dev); + extern bool qdev_hotplug; extern bool qdev_hot_removed; =20 --=20 2.24.1 From nobody Sun May 5 17:23:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579128218; cv=none; d=zohomail.com; s=zohoarc; b=TjGGp/27hgMr9MRcdX4mwsGquIuwZZcskFeIopEUI9UqWMaUzZj6pfgMDuReHzbODNEI0lh+uO1oOCpXTV8r61yitO6pmMcUJlrJ6N+p/VzyzWNjtOVNFvsJGmiBvNohJo95n1JpHJ3fWl6Z0bsuXmSgW5En4sSoGxUhc7zCuYw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579128218; 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=+9yw6/LNnvDWadt4xul8KRf2PtWuDEuatVXr8ZmJnkk=; b=YFfSzjezMBl7tAsmf/NyFwKB6/xJKLxVr7jP6+MF47/pzBTP1idDWGz/Gla59hupEnLNxI3bTxOyZOqi1pLCGl+DPxBeF7VXkFfyJqf3V+TlqApqClQvffE5BAlsNC3bKw/FYJoFRAhTgZ9ZT/mgLfGIJr3eR2ekKy6LV8+v87E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579128218085710.1142434678878; Wed, 15 Jan 2020 14:43:38 -0800 (PST) Received: from localhost ([::1]:33562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irrNw-0006t0-1v for importer@patchew.org; Wed, 15 Jan 2020 17:43:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39872) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irrLO-0003T0-SS for qemu-devel@nongnu.org; Wed, 15 Jan 2020 17:41:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irrLN-0002R8-Sg for qemu-devel@nongnu.org; Wed, 15 Jan 2020 17:40:58 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:51483 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1irrLN-0002K3-PQ for qemu-devel@nongnu.org; Wed, 15 Jan 2020 17:40:57 -0500 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-49-ulfZk2JMPSeVumHLOZQH6Q-1; Wed, 15 Jan 2020 17:40:53 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3CBD7800D41 for ; Wed, 15 Jan 2020 22:40:52 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-94.brq.redhat.com [10.40.204.94]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DD63182062; Wed, 15 Jan 2020 22:40:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579128054; h=from:from: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; bh=+9yw6/LNnvDWadt4xul8KRf2PtWuDEuatVXr8ZmJnkk=; b=hTHYIjjw5wC7v62pFRPTKE/mLPsmyM3ASUwK6zD47JJY4bDQUSYw2+kmWWr9KnvPBKaRs7 uVCfgZvCgNPe/vgmEOnMVOR7N13+XRxfHnJ4GLeSqIgCmVA0pOe+QahRl4WcmNpTHz10Mt w88mnmJKVkOtKF8PnqFS0Ta+7NyuU8A= From: Julia Suvorova To: qemu-devel@nongnu.org Subject: [PATCH 2/2] virtio-balloon: Reject qmp_balloon during hot-unplug Date: Wed, 15 Jan 2020 23:40:25 +0100 Message-Id: <20200115224025.538368-3-jusual@redhat.com> In-Reply-To: <20200115224025.538368-1-jusual@redhat.com> References: <20200115224025.538368-1-jusual@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: ulfZk2JMPSeVumHLOZQH6Q-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S. Tsirkin" , Julia Suvorova , Gerd Hoffmann , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Hot-unplug takes some time due to communication with the guest. Do not change the device while freeing up resources. Signed-off-by: Julia Suvorova --- balloon.c | 2 +- hw/virtio/virtio-balloon.c | 9 ++++++++- include/sysemu/balloon.h | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/balloon.c b/balloon.c index f104b42961..998ec53a0f 100644 --- a/balloon.c +++ b/balloon.c @@ -119,5 +119,5 @@ void qmp_balloon(int64_t target, Error **errp) } =20 trace_balloon_event(balloon_opaque, target); - balloon_event_fn(balloon_opaque, target); + balloon_event_fn(balloon_opaque, target, errp); } diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 57f3b9f22d..0fa4e4454b 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -717,12 +717,19 @@ static void virtio_balloon_stat(void *opaque, Balloon= Info *info) VIRTIO_BALLOON_PFN_SHIFT); } =20 -static void virtio_balloon_to_target(void *opaque, ram_addr_t target) +static void virtio_balloon_to_target(void *opaque, ram_addr_t target, + Error **errp) { + DeviceState *bus_dev =3D qdev_get_bus_device(DEVICE(opaque)); VirtIOBalloon *dev =3D VIRTIO_BALLOON(opaque); VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); ram_addr_t vm_ram_size =3D get_current_ram_size(); =20 + if (bus_dev && bus_dev->pending_deleted_event) { + error_setg(errp, "Hot-unplug of %s is in progress", vdev->name); + return; + } + if (target > vm_ram_size) { target =3D vm_ram_size; } diff --git a/include/sysemu/balloon.h b/include/sysemu/balloon.h index aea0c44985..b3a09ca946 100644 --- a/include/sysemu/balloon.h +++ b/include/sysemu/balloon.h @@ -17,7 +17,7 @@ #include "exec/cpu-common.h" #include "qapi/qapi-types-misc.h" =20 -typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t target); +typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t target, Error **e= rrp); typedef void (QEMUBalloonStatus)(void *opaque, BalloonInfo *info); =20 int qemu_add_balloon_handler(QEMUBalloonEvent *event_func, --=20 2.24.1