Received: by 2002:a17:906:6453:b0:98d:a79e:b696 with SMTP id l19csp114649ejn; Fri, 23 Jun 2023 05:23:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Wkrqp9vYwf2vaTlJfPqbR+FPl0Ym5Wyslgt0L6iR7Vw0D9f60VRiiY8x6a3FNOMlauWDL X-Received: by 2002:a05:622a:c5:b0:3fd:ecdc:1e0f with SMTP id p5-20020a05622a00c500b003fdecdc1e0fmr18033799qtw.17.1687523025304; Fri, 23 Jun 2023 05:23:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687523025; cv=none; d=google.com; s=arc-20160816; b=IGF1WvvZ0evT5TBOWzrOWLmeNlD/zHIubQFvOyF4jpWfKTXrucLfESPSZDkSC3c+2T hN4aguWUpXEyVfpEhtTpWkgeG9rU/LqElNDUwZ1R9g8MJGF0gi7lcVt26rFXzji/jVsa wWU0B8byO+i1Lgskj/5igTgDeqMBgqrO8EvrvfS/2HnTcjnslWAU5WCcmN10UMv8DwZ0 tsbLkIC0r3sJjXzlAb6M0Zsm8rdTMfHcPjNV6NL6x9N8muk0d/rczrsl1ucoe1CPJ9O0 UyWb+HqP0xXjJQcxnCPZmIrUmog0gjjn7wheefazmfptwA42Wpmj9jV1yKuqIiTR4df6 4nBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gielJ0AfJn9CLfmIJKUbtg9iV98xhrfLsmzzHLQYtZs=; b=a1gj1vneonil4JDqqIsrlYNyvv9j+/ZAeqemMmqeRv1Au3b7/tU/SMe4TmhFJ8zrQj yZz0jMptpneunegIuCF9UyhQGPEGT/u0Xetz2/5ytbB3i8U91zGcp8S0pxJey930L9Gt Jn+444AxBTX0Xgked6J+CQ2qsjQ/+CexsqGMgZxT3JWc6ruIyBNBN9PnVKL8iXisPas+ qfhq8eyxs3/wc/VBTFoQhw3lP3m8hEgaPlYyK9Dy0y0XeVDKPnMYpJ88pAxT0fnq8wP7 YqKGg3psN7hbIh88cfj/6nfDQ0iGkg8yeL3ARW2g9JVTrA1Vngqlj26siSsqFkG7M1kr Uj2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AK9DCVKV; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i7-20020ac85c07000000b003f6bece648dsi3529857qti.659.2023.06.23.05.23.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Jun 2023 05:23:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AK9DCVKV; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCfo3-00052c-7U; Fri, 23 Jun 2023 08:22:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qCfn3-0003pW-QD for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:21:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qCfmv-0003nR-AP for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:21:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687522874; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gielJ0AfJn9CLfmIJKUbtg9iV98xhrfLsmzzHLQYtZs=; b=AK9DCVKVmcufFeF5o0hjk1mCzKCtHeDd50NANc5mn41wF+aulKrx0WXa4zxF9j/ZzMy6hq qE4vIdffPTocxmgytAeStg04xAN0eWM5WT/paRNL9e168U7ec3yoZomw6V2EfpALQTNcvu ui9iqNhd6OCalskOBBJhJEMT7V2c1Hw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-673-TE4BoRlJOoyRR2X56HbnFg-1; Fri, 23 Jun 2023 08:21:10 -0400 X-MC-Unique: TE4BoRlJOoyRR2X56HbnFg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A92D38CC200; Fri, 23 Jun 2023 12:21:09 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.22.32.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6061C40C2063; Fri, 23 Jun 2023 12:21:07 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Peter Maydell , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , qemu-arm@nongnu.org, Gavin Shan Subject: [PATCH v2 4/7] virtio-md-pci: Handle unplug of virtio based memory devices Date: Fri, 23 Jun 2023 14:20:53 +0200 Message-Id: <20230623122056.374312-5-david@redhat.com> In-Reply-To: <20230623122056.374312-1-david@redhat.com> References: <20230623122056.374312-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: i0OxfdgIFZmN While we fence unplug requests from the outside, the VM can still trigger unplug of virtio based memory devices, for example, in Linux doing on a virtio-mem-pci device: # echo 0 > /sys/bus/pci/slots/3/power While doing that is not really expected to work without harming the guest OS (e.g., removing a virtio-mem device while it still provides memory), let's make sure that we properly handle it on the QEMU side. We'll add support for unplugging of virtio-mem devices in some configurations next. Signed-off-by: David Hildenbrand --- hw/virtio/virtio-md-pci.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio-md-pci.c b/hw/virtio/virtio-md-pci.c index e849c3131d..a22a259e2d 100644 --- a/hw/virtio/virtio-md-pci.c +++ b/hw/virtio/virtio-md-pci.c @@ -14,6 +14,7 @@ #include "hw/virtio/virtio-md-pci.h" #include "hw/mem/memory-device.h" #include "qapi/error.h" +#include "qemu/error-report.h" void virtio_md_pci_pre_plug(VirtIOMDPCI *vmd, MachineState *ms, Error **errp) { @@ -74,7 +75,27 @@ void virtio_md_pci_unplug_request(VirtIOMDPCI *vmd, MachineState *ms, void virtio_md_pci_unplug(VirtIOMDPCI *vmd, MachineState *ms, Error **errp) { - /* We don't support hot unplug of virtio based memory devices */ + DeviceState *dev = DEVICE(vmd); + HotplugHandler *bus_handler = qdev_get_bus_hotplug_handler(dev); + MemoryDeviceState *md = MEMORY_DEVICE(vmd); + Error *local_err = NULL; + + /* Unplug the memory device while it is still realized. */ + memory_device_unplug(md, ms); + + if (bus_handler) { + hotplug_handler_unplug(bus_handler, dev, &local_err); + if (local_err) { + /* Not expected to fail ... but still try to recover. */ + memory_device_plug(md, ms); + error_propagate(errp, local_err); + return; + } + } else { + /* Very unexpected, but let's just try to do the right thing. */ + warn_report("Unexpected unplug of virtio based memory device"); + qdev_unrealize(dev); + } } static const TypeInfo virtio_md_pci_info = { -- 2.40.1