From: David Hildenbrand <david@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-s390x@nongnu.org, David Hildenbrand <david@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Huth <thuth@redhat.com>, Halil Pasic <pasic@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Eric Farman <farman@linux.ibm.com>,
Richard Henderson <richard.henderson@linaro.org>,
Ilya Leoshkevich <iii@linux.ibm.com>,
Janosch Frank <frankja@linux.ibm.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Cornelia Huck <cohuck@redhat.com>
Subject: [PATCH v1 13/14] s390x/virtio-ccw: add support for virtio based memory devices
Date: Tue, 10 Sep 2024 19:58:08 +0200 [thread overview]
Message-ID: <20240910175809.2135596-14-david@redhat.com> (raw)
In-Reply-To: <20240910175809.2135596-1-david@redhat.com>
Let's implement support for abstract virtio based memory devices, using
the virtio-pci implementation as an orientation.
As we neither support virtio-mem or virtio-pmem yet, the code is
effectively unused and not wired up. We'll implement support for
virtio-mem based on this next.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
MAINTAINERS | 2 +
hw/s390x/meson.build | 1 +
hw/s390x/virtio-ccw-md.c | 153 +++++++++++++++++++++++++++++++++++++++
hw/s390x/virtio-ccw-md.h | 44 +++++++++++
hw/virtio/Kconfig | 1 +
5 files changed, 201 insertions(+)
create mode 100644 hw/s390x/virtio-ccw-md.c
create mode 100644 hw/s390x/virtio-ccw-md.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 0c1bc69828..53ed2c5f0f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2400,6 +2400,8 @@ F: include/hw/virtio/virtio-crypto.h
virtio based memory device
M: David Hildenbrand <david@redhat.com>
S: Supported
+F: hw/s390x/virtio-ccw-md.c
+F: hw/s390x/virtio-ccw-md.h
F: hw/virtio/virtio-md-pci.c
F: include/hw/virtio/virtio-md-pci.h
F: stubs/virtio-md-pci.c
diff --git a/hw/s390x/meson.build b/hw/s390x/meson.build
index 71ec747f4c..4df40da855 100644
--- a/hw/s390x/meson.build
+++ b/hw/s390x/meson.build
@@ -48,6 +48,7 @@ endif
virtio_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi-ccw.c'))
virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-ccw.c'))
virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-ccw.c'))
+virtio_ss.add(when: 'CONFIG_VIRTIO_MD', if_true: files('virtio-ccw-md.c'))
s390x_ss.add_all(when: 'CONFIG_VIRTIO_CCW', if_true: virtio_ss)
hw_arch += {'s390x': s390x_ss}
diff --git a/hw/s390x/virtio-ccw-md.c b/hw/s390x/virtio-ccw-md.c
new file mode 100644
index 0000000000..de333282df
--- /dev/null
+++ b/hw/s390x/virtio-ccw-md.c
@@ -0,0 +1,153 @@
+/*
+ * Virtio CCW support for abstract virtio based memory device
+ *
+ * Copyright (C) 2024 Red Hat, Inc.
+ *
+ * Authors:
+ * David Hildenbrand <david@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/s390x/virtio-ccw-md.h"
+#include "hw/mem/memory-device.h"
+#include "qapi/error.h"
+#include "qemu/error-report.h"
+
+void virtio_ccw_md_pre_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp)
+{
+ DeviceState *dev = DEVICE(vmd);
+ HotplugHandler *bus_handler = qdev_get_bus_hotplug_handler(dev);
+ MemoryDeviceState *md = MEMORY_DEVICE(vmd);
+ Error *local_err = NULL;
+
+ if (!bus_handler && dev->hotplugged) {
+ /*
+ * Without a bus hotplug handler, we cannot control the plug/unplug
+ * order. We should never reach this point when hotplugging, but
+ * better add a safety net.
+ */
+ error_setg(errp, "hotplug of virtio based memory devices not supported"
+ " on this bus.");
+ return;
+ }
+
+ /*
+ * First, see if we can plug this memory device at all. If that
+ * succeeds, branch of to the actual hotplug handler.
+ */
+ memory_device_pre_plug(md, ms, &local_err);
+ if (!local_err && bus_handler) {
+ hotplug_handler_pre_plug(bus_handler, dev, &local_err);
+ }
+ error_propagate(errp, local_err);
+}
+
+void virtio_ccw_md_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp)
+{
+ DeviceState *dev = DEVICE(vmd);
+ HotplugHandler *bus_handler = qdev_get_bus_hotplug_handler(dev);
+ MemoryDeviceState *md = MEMORY_DEVICE(vmd);
+ Error *local_err = NULL;
+
+ /*
+ * Plug the memory device first and then branch off to the actual
+ * hotplug handler. If that one fails, we can easily undo the memory
+ * device bits.
+ */
+ memory_device_plug(md, ms);
+ if (bus_handler) {
+ hotplug_handler_plug(bus_handler, dev, &local_err);
+ if (local_err) {
+ memory_device_unplug(md, ms);
+ }
+ }
+ error_propagate(errp, local_err);
+}
+
+void virtio_ccw_md_unplug_request(VirtIOMDCcw *vmd, MachineState *ms,
+ Error **errp)
+{
+ VirtIOMDCcwClass *vmdc = VIRTIO_MD_CCW_GET_CLASS(vmd);
+ DeviceState *dev = DEVICE(vmd);
+ HotplugHandler *bus_handler = qdev_get_bus_hotplug_handler(dev);
+ HotplugHandlerClass *hdc;
+ Error *local_err = NULL;
+
+ if (!vmdc->unplug_request_check) {
+ error_setg(errp,
+ "this virtio based memory devices cannot be unplugged");
+ return;
+ }
+
+ if (!bus_handler) {
+ error_setg(errp, "hotunplug of virtio based memory devices not"
+ "supported on this bus");
+ return;
+ }
+
+ vmdc->unplug_request_check(vmd, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ /*
+ * Forward the async request or turn it into a sync request (handling it
+ * like qdev_unplug()).
+ */
+ hdc = HOTPLUG_HANDLER_GET_CLASS(bus_handler);
+ if (hdc->unplug_request) {
+ hotplug_handler_unplug_request(bus_handler, dev, &local_err);
+ } else {
+ virtio_ccw_md_unplug(vmd, ms, &local_err);
+ if (!local_err) {
+ object_unparent(OBJECT(dev));
+ }
+ }
+}
+
+void virtio_ccw_md_unplug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp)
+{
+ 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_ccw_md_info = {
+ .name = TYPE_VIRTIO_MD_CCW,
+ .parent = TYPE_VIRTIO_CCW_DEVICE,
+ .instance_size = sizeof(VirtIOMDCcw),
+ .class_size = sizeof(VirtIOMDCcwClass),
+ .abstract = true,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_MEMORY_DEVICE },
+ { }
+ },
+};
+
+static void virtio_ccw_md_register(void)
+{
+ type_register_static(&virtio_ccw_md_info);
+}
+type_init(virtio_ccw_md_register)
diff --git a/hw/s390x/virtio-ccw-md.h b/hw/s390x/virtio-ccw-md.h
new file mode 100644
index 0000000000..e83d40f6c4
--- /dev/null
+++ b/hw/s390x/virtio-ccw-md.h
@@ -0,0 +1,44 @@
+/*
+ * Virtio CCW support for abstract virtio based memory device
+ *
+ * Copyright (C) 2024 Red Hat, Inc.
+ *
+ * Authors:
+ * David Hildenbrand <david@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef HW_S390X_VIRTIO_CCW_MD_H
+#define HW_S390X_VIRTIO_CCW_MD_H
+
+#include "virtio-ccw.h"
+#include "qom/object.h"
+
+/*
+ * virtio-md-ccw: This extends VirtioCcwDevice.
+ */
+#define TYPE_VIRTIO_MD_CCW "virtio-md-ccw"
+
+OBJECT_DECLARE_TYPE(VirtIOMDCcw, VirtIOMDCcwClass, VIRTIO_MD_CCW)
+
+struct VirtIOMDCcwClass {
+ /* private */
+ VirtIOCCWDeviceClass parent;
+
+ /* public */
+ void (*unplug_request_check)(VirtIOMDCcw *vmd, Error **errp);
+};
+
+struct VirtIOMDCcw {
+ VirtioCcwDevice parent_obj;
+};
+
+void virtio_ccw_md_pre_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp);
+void virtio_ccw_md_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp);
+void virtio_ccw_md_unplug_request(VirtIOMDCcw *vmd, MachineState *ms,
+ Error **errp);
+void virtio_ccw_md_unplug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp);
+
+#endif
diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig
index 0afec2ae92..f4b14e1a44 100644
--- a/hw/virtio/Kconfig
+++ b/hw/virtio/Kconfig
@@ -25,6 +25,7 @@ config VIRTIO_MMIO
config VIRTIO_CCW
bool
select VIRTIO
+ select VIRTIO_MD_SUPPORTED
config VIRTIO_BALLOON
bool
--
2.46.0
next prev parent reply other threads:[~2024-09-10 18:02 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-10 17:57 [PATCH v1 00/14] s390x: virtio-mem support David Hildenbrand
2024-09-10 17:57 ` [PATCH v1 01/14] s390x/s390-virtio-ccw: don't crash on weird RAM sizes David Hildenbrand
2024-09-11 11:28 ` Janosch Frank
2024-09-11 12:38 ` David Hildenbrand
2024-09-11 12:46 ` Thomas Huth
2024-09-11 12:54 ` David Hildenbrand
2024-09-11 11:58 ` Thomas Huth
2024-09-12 20:28 ` Eric Farman
2024-09-23 9:19 ` David Hildenbrand
2024-09-23 15:36 ` Thomas Huth
2024-09-23 15:39 ` David Hildenbrand
2024-09-10 17:57 ` [PATCH v1 02/14] s390x/s390-virtio-hcall: remove hypercall registration mechanism David Hildenbrand
2024-09-11 16:02 ` Thomas Huth
2024-09-10 17:57 ` [PATCH v1 03/14] s390x/s390-virtio-hcall: prepare for more diag500 hypercalls David Hildenbrand
2024-09-11 17:04 ` Thomas Huth
2024-09-12 13:22 ` Nina Schoetterl-Glausch
2024-09-17 10:45 ` David Hildenbrand
2024-09-17 10:50 ` David Hildenbrand
2024-09-17 11:02 ` David Hildenbrand
2024-09-17 12:59 ` Nina Schoetterl-Glausch
2024-09-10 17:57 ` [PATCH v1 04/14] s390x: rename s390-virtio-hcall* to s390-hypercall* David Hildenbrand
2024-09-11 17:05 ` Thomas Huth
2024-09-10 17:58 ` [PATCH v1 05/14] s390x/s390-virtio-ccw: move setting the maximum guest size from sclp to machine code David Hildenbrand
2024-09-12 8:07 ` Thomas Huth
2024-09-10 17:58 ` [PATCH v1 06/14] s390x: introduce s390_get_memory_limit() David Hildenbrand
2024-09-12 8:10 ` Thomas Huth
2024-09-16 13:20 ` Nina Schoetterl-Glausch
2024-09-17 11:23 ` David Hildenbrand
2024-09-17 12:48 ` Nina Schoetterl-Glausch
2024-09-23 9:20 ` David Hildenbrand
2024-09-10 17:58 ` [PATCH v1 07/14] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT David Hildenbrand
2024-09-12 8:19 ` Thomas Huth
2024-09-12 10:54 ` Janosch Frank
2024-09-27 18:05 ` Halil Pasic
2024-09-27 18:34 ` David Hildenbrand
2024-09-30 11:11 ` Christian Borntraeger
2024-09-30 12:57 ` Halil Pasic
2024-10-01 9:15 ` Christian Borntraeger
2024-10-01 13:31 ` Halil Pasic
2024-10-01 14:35 ` Christian Borntraeger
2024-09-30 13:13 ` David Hildenbrand
2024-09-10 17:58 ` [PATCH v1 08/14] s390x/s390-stattrib-kvm: prepare memory devices and sparse memory layouts David Hildenbrand
2024-09-10 17:58 ` [PATCH v1 09/14] s390x/s390-skeys: prepare for memory devices David Hildenbrand
2024-09-10 17:58 ` [PATCH v1 10/14] s390x/pv: check initial, not maximum RAM size David Hildenbrand
2024-09-24 16:22 ` Nina Schoetterl-Glausch
2024-09-24 20:17 ` David Hildenbrand
2024-09-26 9:04 ` David Hildenbrand
2024-09-30 11:15 ` Christian Borntraeger
2024-09-30 11:37 ` Claudio Imbrenda
2024-09-30 13:14 ` David Hildenbrand
2024-09-30 13:26 ` Claudio Imbrenda
2024-09-10 17:58 ` [PATCH v1 11/14] s390x/s390-virtio-ccw: prepare for memory devices David Hildenbrand
2024-09-10 17:58 ` [PATCH v1 12/14] s390x: introduce s390_get_max_pagesize() David Hildenbrand
2024-09-26 10:22 ` David Hildenbrand
2024-09-10 17:58 ` David Hildenbrand [this message]
2024-09-10 17:58 ` [PATCH v1 14/14] s390x: virtio-mem support David Hildenbrand
2024-09-10 18:33 ` [PATCH v1 00/14] " Michael S. Tsirkin
2024-09-10 18:45 ` David Hildenbrand
2024-09-11 11:49 ` Janosch Frank
2024-09-11 12:28 ` David Hildenbrand
2024-09-11 14:04 ` Michael S. Tsirkin
2024-09-11 15:38 ` Cornelia Huck
2024-09-11 19:09 ` David Hildenbrand
2024-09-27 18:20 ` Halil Pasic
2024-09-27 18:29 ` David Hildenbrand
2024-09-30 21:49 ` Halil Pasic
2024-10-01 8:54 ` David Hildenbrand
2024-10-02 9:04 ` Janosch Frank
2024-10-07 12:23 ` David Hildenbrand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240910175809.2135596-14-david@redhat.com \
--to=david@redhat.com \
--cc=borntraeger@linux.ibm.com \
--cc=cohuck@redhat.com \
--cc=farman@linux.ibm.com \
--cc=frankja@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=mst@redhat.com \
--cc=pasic@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).