|
@@ -16,11 +16,8 @@
|
|
|
#include "exec/ram_addr.h"
|
|
|
#include "system/confidential-guest-support.h"
|
|
|
#include "hw/boards.h"
|
|
|
-#include "hw/s390x/s390-virtio-hcall.h"
|
|
|
#include "hw/s390x/sclp.h"
|
|
|
#include "hw/s390x/s390_flic.h"
|
|
|
-#include "hw/s390x/ioinst.h"
|
|
|
-#include "hw/s390x/css.h"
|
|
|
#include "virtio-ccw.h"
|
|
|
#include "qemu/config-file.h"
|
|
|
#include "qemu/ctype.h"
|
|
@@ -48,6 +45,9 @@
|
|
|
#include "migration/blocker.h"
|
|
|
#include "qapi/visitor.h"
|
|
|
#include "hw/s390x/cpu-topology.h"
|
|
|
+#include "kvm/kvm_s390x.h"
|
|
|
+#include "hw/virtio/virtio-md-pci.h"
|
|
|
+#include "hw/s390x/virtio-ccw-md.h"
|
|
|
#include CONFIG_DEVICES
|
|
|
|
|
|
static Error *pv_mig_blocker;
|
|
@@ -124,70 +124,86 @@ static void subsystem_reset(void)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static int virtio_ccw_hcall_notify(const uint64_t *args)
|
|
|
+static void s390_set_memory_limit(S390CcwMachineState *s390ms,
|
|
|
+ uint64_t new_limit)
|
|
|
{
|
|
|
- uint64_t subch_id = args[0];
|
|
|
- uint64_t data = args[1];
|
|
|
- SubchDev *sch;
|
|
|
- VirtIODevice *vdev;
|
|
|
- int cssid, ssid, schid, m;
|
|
|
- uint16_t vq_idx = data;
|
|
|
+ uint64_t hw_limit = 0;
|
|
|
+ int ret = 0;
|
|
|
|
|
|
- if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
|
|
|
- return -EINVAL;
|
|
|
+ assert(!s390ms->memory_limit && new_limit);
|
|
|
+ if (kvm_enabled()) {
|
|
|
+ ret = kvm_s390_set_mem_limit(new_limit, &hw_limit);
|
|
|
}
|
|
|
- sch = css_find_subch(m, cssid, ssid, schid);
|
|
|
- if (!sch || !css_subch_visible(sch)) {
|
|
|
- return -EINVAL;
|
|
|
- }
|
|
|
-
|
|
|
- vdev = virtio_ccw_get_vdev(sch);
|
|
|
- if (vq_idx >= VIRTIO_QUEUE_MAX || !virtio_queue_get_num(vdev, vq_idx)) {
|
|
|
- return -EINVAL;
|
|
|
+ if (ret == -E2BIG) {
|
|
|
+ error_report("host supports a maximum of %" PRIu64 " GB",
|
|
|
+ hw_limit / GiB);
|
|
|
+ exit(EXIT_FAILURE);
|
|
|
+ } else if (ret) {
|
|
|
+ error_report("setting the guest size failed");
|
|
|
+ exit(EXIT_FAILURE);
|
|
|
}
|
|
|
+ s390ms->memory_limit = new_limit;
|
|
|
+}
|
|
|
|
|
|
- if (virtio_vdev_has_feature(vdev, VIRTIO_F_NOTIFICATION_DATA)) {
|
|
|
- virtio_queue_set_shadow_avail_idx(virtio_get_queue(vdev, vq_idx),
|
|
|
- (data >> 16) & 0xFFFF);
|
|
|
+static void s390_set_max_pagesize(S390CcwMachineState *s390ms,
|
|
|
+ uint64_t pagesize)
|
|
|
+{
|
|
|
+ assert(!s390ms->max_pagesize && pagesize);
|
|
|
+ if (kvm_enabled()) {
|
|
|
+ kvm_s390_set_max_pagesize(pagesize, &error_fatal);
|
|
|
}
|
|
|
-
|
|
|
- virtio_queue_notify(vdev, vq_idx);
|
|
|
- return 0;
|
|
|
+ s390ms->max_pagesize = pagesize;
|
|
|
}
|
|
|
|
|
|
-static int virtio_ccw_hcall_early_printk(const uint64_t *args)
|
|
|
+static void s390_memory_init(MachineState *machine)
|
|
|
{
|
|
|
- uint64_t mem = args[0];
|
|
|
- MachineState *ms = MACHINE(qdev_get_machine());
|
|
|
+ S390CcwMachineState *s390ms = S390_CCW_MACHINE(machine);
|
|
|
+ MemoryRegion *sysmem = get_system_memory();
|
|
|
+ MemoryRegion *ram = machine->ram;
|
|
|
+ uint64_t ram_size = memory_region_size(ram);
|
|
|
+ uint64_t devmem_base, devmem_size;
|
|
|
|
|
|
- if (mem < ms->ram_size) {
|
|
|
- /* Early printk */
|
|
|
- return 0;
|
|
|
+ if (!QEMU_IS_ALIGNED(ram_size, 1 * MiB)) {
|
|
|
+ /*
|
|
|
+ * SCLP cannot possibly expose smaller granularity right now and KVM
|
|
|
+ * cannot handle smaller granularity. As we don't support NUMA, the
|
|
|
+ * region size directly corresponds to machine->ram_size, and the region
|
|
|
+ * is a single RAM memory region.
|
|
|
+ */
|
|
|
+ error_report("ram size must be multiples of 1 MiB");
|
|
|
+ exit(EXIT_FAILURE);
|
|
|
}
|
|
|
- return -EINVAL;
|
|
|
-}
|
|
|
|
|
|
-static void virtio_ccw_register_hcalls(void)
|
|
|
-{
|
|
|
- s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
|
|
|
- virtio_ccw_hcall_notify);
|
|
|
- /* Tolerate early printk. */
|
|
|
- s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
|
|
|
- virtio_ccw_hcall_early_printk);
|
|
|
-}
|
|
|
+ devmem_size = 0;
|
|
|
+ devmem_base = ram_size;
|
|
|
+#ifdef CONFIG_MEM_DEVICE
|
|
|
+ if (machine->ram_size < machine->maxram_size) {
|
|
|
|
|
|
-static void s390_memory_init(MemoryRegion *ram)
|
|
|
-{
|
|
|
- MemoryRegion *sysmem = get_system_memory();
|
|
|
+ /*
|
|
|
+ * Make sure memory devices have a sane default alignment, even
|
|
|
+ * when weird initial memory sizes are specified.
|
|
|
+ */
|
|
|
+ devmem_base = QEMU_ALIGN_UP(devmem_base, 1 * GiB);
|
|
|
+ devmem_size = machine->maxram_size - machine->ram_size;
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ s390_set_memory_limit(s390ms, devmem_base + devmem_size);
|
|
|
|
|
|
- /* allocate RAM for core */
|
|
|
+ /* Map the initial memory. Must happen after setting the memory limit. */
|
|
|
memory_region_add_subregion(sysmem, 0, ram);
|
|
|
|
|
|
+ /* Initialize address space for memory devices. */
|
|
|
+#ifdef CONFIG_MEM_DEVICE
|
|
|
+ if (devmem_size) {
|
|
|
+ machine_memory_devices_init(machine, devmem_base, devmem_size);
|
|
|
+ }
|
|
|
+#endif /* CONFIG_MEM_DEVICE */
|
|
|
+
|
|
|
/*
|
|
|
* Configure the maximum page size. As no memory devices were created
|
|
|
* yet, this is the page size of initial memory only.
|
|
|
*/
|
|
|
- s390_set_max_pagesize(qemu_maxrampagesize(), &error_fatal);
|
|
|
+ s390_set_max_pagesize(s390ms, qemu_maxrampagesize());
|
|
|
/* Initialize storage key device */
|
|
|
s390_skeys_init();
|
|
|
/* Initialize storage attributes device */
|
|
@@ -255,7 +271,7 @@ static void ccw_init(MachineState *machine)
|
|
|
qdev_realize_and_unref(DEVICE(ms->sclp), NULL, &error_fatal);
|
|
|
|
|
|
/* init memory + setup max page size. Required for the CPU model */
|
|
|
- s390_memory_init(machine->ram);
|
|
|
+ s390_memory_init(machine);
|
|
|
|
|
|
/* init CPUs (incl. CPU model) early so s390_has_feature() works */
|
|
|
s390_init_cpus(machine);
|
|
@@ -285,9 +301,6 @@ static void ccw_init(MachineState *machine)
|
|
|
OBJECT(dev));
|
|
|
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
|
|
|
|
|
|
- /* register hypercalls */
|
|
|
- virtio_ccw_register_hcalls();
|
|
|
-
|
|
|
s390_enable_css_support(s390_cpu_addr2state(0));
|
|
|
|
|
|
ret = css_create_css_image(VIRTUAL_CSSID, true);
|
|
@@ -535,11 +548,39 @@ static void s390_machine_reset(MachineState *machine, ResetType type)
|
|
|
s390_ipl_clear_reset_request();
|
|
|
}
|
|
|
|
|
|
+static void s390_machine_device_pre_plug(HotplugHandler *hotplug_dev,
|
|
|
+ DeviceState *dev, Error **errp)
|
|
|
+{
|
|
|
+ if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) {
|
|
|
+ virtio_ccw_md_pre_plug(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), errp);
|
|
|
+ } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) {
|
|
|
+ error_setg(errp,
|
|
|
+ "PCI-attached virtio based memory devices not supported");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
static void s390_machine_device_plug(HotplugHandler *hotplug_dev,
|
|
|
DeviceState *dev, Error **errp)
|
|
|
{
|
|
|
+ S390CcwMachineState *s390ms = S390_CCW_MACHINE(hotplug_dev);
|
|
|
+
|
|
|
if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
|
|
|
s390_cpu_plug(hotplug_dev, dev, errp);
|
|
|
+ } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) {
|
|
|
+ /*
|
|
|
+ * At this point, the device is realized and set all memdevs mapped, so
|
|
|
+ * qemu_maxrampagesize() will pick up the page sizes of these memdevs
|
|
|
+ * as well. Before we plug the device and expose any RAM memory regions
|
|
|
+ * to the system, make sure we don't exceed the previously set max page
|
|
|
+ * size. While only relevant for KVM, there is not really any use case
|
|
|
+ * for this with TCG, so we'll unconditionally reject it.
|
|
|
+ */
|
|
|
+ if (qemu_maxrampagesize() != s390ms->max_pagesize) {
|
|
|
+ error_setg(errp, "Memory device uses a bigger page size than"
|
|
|
+ " initial memory");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ virtio_ccw_md_plug(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), errp);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -549,9 +590,20 @@ static void s390_machine_device_unplug_request(HotplugHandler *hotplug_dev,
|
|
|
if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
|
|
|
error_setg(errp, "CPU hot unplug not supported on this machine");
|
|
|
return;
|
|
|
+ } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) {
|
|
|
+ virtio_ccw_md_unplug_request(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev),
|
|
|
+ errp);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static void s390_machine_device_unplug(HotplugHandler *hotplug_dev,
|
|
|
+ DeviceState *dev, Error **errp)
|
|
|
+{
|
|
|
+ if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) {
|
|
|
+ virtio_ccw_md_unplug(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), errp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms,
|
|
|
unsigned cpu_index)
|
|
|
{
|
|
@@ -598,7 +650,9 @@ static const CPUArchIdList *s390_possible_cpu_arch_ids(MachineState *ms)
|
|
|
static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
|
|
|
DeviceState *dev)
|
|
|
{
|
|
|
- if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
|
|
|
+ if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) ||
|
|
|
+ object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW) ||
|
|
|
+ object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) {
|
|
|
return HOTPLUG_HANDLER(machine);
|
|
|
}
|
|
|
return NULL;
|
|
@@ -758,8 +812,10 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data)
|
|
|
mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids;
|
|
|
/* it is overridden with 'host' cpu *in kvm_arch_init* */
|
|
|
mc->default_cpu_type = S390_CPU_TYPE_NAME("qemu");
|
|
|
+ hc->pre_plug = s390_machine_device_pre_plug;
|
|
|
hc->plug = s390_machine_device_plug;
|
|
|
hc->unplug_request = s390_machine_device_unplug_request;
|
|
|
+ hc->unplug = s390_machine_device_unplug;
|
|
|
nc->nmi_monitor_handler = s390_nmi;
|
|
|
mc->default_ram_id = "s390.ram";
|
|
|
mc->default_nic = "virtio-net-ccw";
|