2013-01-24 14:08:56 +08:00
|
|
|
/*
|
|
|
|
* virtio ccw machine
|
|
|
|
*
|
|
|
|
* Copyright 2012 IBM Corp.
|
|
|
|
* Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or (at
|
|
|
|
* your option) any later version. See the COPYING file in the top-level
|
|
|
|
* directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hw/boards.h"
|
|
|
|
#include "exec/address-spaces.h"
|
|
|
|
#include "s390-virtio.h"
|
2013-02-04 22:40:22 +08:00
|
|
|
#include "hw/s390x/sclp.h"
|
2013-07-16 15:04:04 +08:00
|
|
|
#include "hw/s390x/s390_flic.h"
|
2013-01-24 14:08:56 +08:00
|
|
|
#include "ioinst.h"
|
|
|
|
#include "css.h"
|
|
|
|
#include "virtio-ccw.h"
|
2014-08-28 23:25:33 +08:00
|
|
|
#include "qemu/config-file.h"
|
2015-01-09 16:04:38 +08:00
|
|
|
#include "s390-pci-bus.h"
|
2015-06-27 02:01:00 +08:00
|
|
|
#include "hw/s390x/storage-keys.h"
|
2015-10-16 18:25:52 +08:00
|
|
|
#include "hw/compat.h"
|
2013-01-24 14:08:56 +08:00
|
|
|
|
2014-08-20 20:16:34 +08:00
|
|
|
#define TYPE_S390_CCW_MACHINE "s390-ccw-machine"
|
|
|
|
|
2015-03-12 20:53:51 +08:00
|
|
|
#define S390_CCW_MACHINE(obj) \
|
|
|
|
OBJECT_CHECK(S390CcwMachineState, (obj), TYPE_S390_CCW_MACHINE)
|
|
|
|
|
|
|
|
typedef struct S390CcwMachineState {
|
|
|
|
/*< private >*/
|
|
|
|
MachineState parent_obj;
|
|
|
|
|
|
|
|
/*< public >*/
|
|
|
|
bool aes_key_wrap;
|
|
|
|
bool dea_key_wrap;
|
|
|
|
} S390CcwMachineState;
|
|
|
|
|
2015-07-21 16:58:38 +08:00
|
|
|
static const char *const reset_dev_types[] = {
|
|
|
|
"virtual-css-bridge",
|
|
|
|
"s390-sclp-event-facility",
|
|
|
|
"s390-flic",
|
|
|
|
"diag288",
|
|
|
|
};
|
|
|
|
|
2015-10-01 16:49:47 +08:00
|
|
|
void subsystem_reset(void)
|
2013-07-25 22:37:37 +08:00
|
|
|
{
|
2015-07-21 16:58:38 +08:00
|
|
|
DeviceState *dev;
|
|
|
|
int i;
|
2013-07-25 22:37:37 +08:00
|
|
|
|
2015-07-21 16:58:38 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(reset_dev_types); i++) {
|
|
|
|
dev = DEVICE(object_resolve_path_type("", reset_dev_types[i], NULL));
|
|
|
|
if (dev) {
|
|
|
|
qdev_reset_all(dev);
|
|
|
|
}
|
2015-06-29 14:21:10 +08:00
|
|
|
}
|
2013-07-25 22:37:37 +08:00
|
|
|
}
|
|
|
|
|
2013-01-24 14:08:56 +08:00
|
|
|
static int virtio_ccw_hcall_notify(const uint64_t *args)
|
|
|
|
{
|
|
|
|
uint64_t subch_id = args[0];
|
|
|
|
uint64_t queue = args[1];
|
|
|
|
SubchDev *sch;
|
|
|
|
int cssid, ssid, schid, m;
|
|
|
|
|
|
|
|
if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
sch = css_find_subch(m, cssid, ssid, schid);
|
|
|
|
if (!sch || !css_subch_visible(sch)) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2015-05-29 14:15:27 +08:00
|
|
|
if (queue >= VIRTIO_CCW_QUEUE_MAX) {
|
2013-03-27 00:32:44 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2013-01-24 14:08:56 +08:00
|
|
|
virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int virtio_ccw_hcall_early_printk(const uint64_t *args)
|
|
|
|
{
|
|
|
|
uint64_t mem = args[0];
|
|
|
|
|
|
|
|
if (mem < ram_size) {
|
|
|
|
/* Early printk */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-05-29 21:01:55 +08:00
|
|
|
void s390_memory_init(ram_addr_t mem_size)
|
2013-01-24 14:08:56 +08:00
|
|
|
{
|
|
|
|
MemoryRegion *sysmem = get_system_memory();
|
|
|
|
MemoryRegion *ram = g_new(MemoryRegion, 1);
|
2015-05-29 21:01:55 +08:00
|
|
|
|
|
|
|
/* allocate RAM for core */
|
Fix bad error handling after memory_region_init_ram()
Symptom:
$ qemu-system-x86_64 -m 10000000
Unexpected error in ram_block_add() at /work/armbru/qemu/exec.c:1456:
upstream-qemu: cannot set up guest memory 'pc.ram': Cannot allocate memory
Aborted (core dumped)
Root cause: commit ef701d7 screwed up handling of out-of-memory
conditions. Before the commit, we report the error and exit(1), in
one place, ram_block_add(). The commit lifts the error handling up
the call chain some, to three places. Fine. Except it uses
&error_abort in these places, changing the behavior from exit(1) to
abort(), and thus undoing the work of commit 3922825 "exec: Don't
abort when we can't allocate guest memory".
The three places are:
* memory_region_init_ram()
Commit 4994653 (right after commit ef701d7) lifted the error
handling further, through memory_region_init_ram(), multiplying the
incorrect use of &error_abort. Later on, imitation of existing
(bad) code may have created more.
* memory_region_init_ram_ptr()
The &error_abort is still there.
* memory_region_init_rom_device()
Doesn't need fixing, because commit 33e0eb5 (soon after commit
ef701d7) lifted the error handling further, and in the process
changed it from &error_abort to passing it up the call chain.
Correct, because the callers are realize() methods.
Fix the error handling after memory_region_init_ram() with a
Coccinelle semantic patch:
@r@
expression mr, owner, name, size, err;
position p;
@@
memory_region_init_ram(mr, owner, name, size,
(
- &error_abort
+ &error_fatal
|
err@p
)
);
@script:python@
p << r.p;
@@
print "%s:%s:%s" % (p[0].file, p[0].line, p[0].column)
When the last argument is &error_abort, it gets replaced by
&error_fatal. This is the fix.
If the last argument is anything else, its position is reported. This
lets us check the fix is complete. Four positions get reported:
* ram_backend_memory_alloc()
Error is passed up the call chain, ultimately through
user_creatable_complete(). As far as I can tell, it's callers all
handle the error sanely.
* fsl_imx25_realize(), fsl_imx31_realize(), dp8393x_realize()
DeviceClass.realize() methods, errors handled sanely further up the
call chain.
We're good. Test case again behaves:
$ qemu-system-x86_64 -m 10000000
qemu-system-x86_64: cannot set up guest memory 'pc.ram': Cannot allocate memory
[Exit 1 ]
The next commits will repair the rest of commit ef701d7's damage.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1441983105-26376-3-git-send-email-armbru@redhat.com>
Reviewed-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
2015-09-11 22:51:43 +08:00
|
|
|
memory_region_init_ram(ram, NULL, "s390.ram", mem_size, &error_fatal);
|
2015-05-29 21:01:55 +08:00
|
|
|
vmstate_register_ram_global(ram);
|
|
|
|
memory_region_add_subregion(sysmem, 0, ram);
|
|
|
|
|
|
|
|
/* Initialize storage key device */
|
|
|
|
s390_skeys_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ccw_init(MachineState *machine)
|
|
|
|
{
|
2013-01-24 14:08:56 +08:00
|
|
|
int ret;
|
|
|
|
VirtualCssBus *css_bus;
|
2015-01-09 16:04:38 +08:00
|
|
|
DeviceState *dev;
|
2014-08-28 23:25:33 +08:00
|
|
|
|
2015-05-29 19:53:08 +08:00
|
|
|
s390_sclp_init();
|
2015-05-29 21:01:55 +08:00
|
|
|
s390_memory_init(machine->ram_size);
|
2013-01-24 14:08:56 +08:00
|
|
|
|
|
|
|
/* get a BUS */
|
|
|
|
css_bus = virtual_css_bus_init();
|
2014-05-07 22:42:57 +08:00
|
|
|
s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
|
2015-02-13 01:02:13 +08:00
|
|
|
machine->initrd_filename, "s390-ccw.img", true);
|
2013-07-16 15:04:04 +08:00
|
|
|
s390_flic_init();
|
2013-01-24 14:08:56 +08:00
|
|
|
|
2015-01-09 16:04:38 +08:00
|
|
|
dev = qdev_create(NULL, TYPE_S390_PCI_HOST_BRIDGE);
|
|
|
|
object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
|
|
|
|
OBJECT(dev), NULL);
|
|
|
|
qdev_init_nofail(dev);
|
|
|
|
|
2013-01-24 14:08:56 +08:00
|
|
|
/* register hypercalls */
|
|
|
|
virtio_ccw_register_hcalls();
|
|
|
|
|
|
|
|
/* init CPUs */
|
2015-06-27 02:01:00 +08:00
|
|
|
s390_init_cpus(machine->cpu_model);
|
2013-01-24 14:08:56 +08:00
|
|
|
|
|
|
|
if (kvm_enabled()) {
|
|
|
|
kvm_s390_enable_css_support(s390_cpu_addr2state(0));
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Create virtual css and set it as default so that non mcss-e
|
|
|
|
* enabled guests only see virtio devices.
|
|
|
|
*/
|
|
|
|
ret = css_create_css_image(VIRTUAL_CSSID, true);
|
|
|
|
assert(ret == 0);
|
|
|
|
|
|
|
|
/* Create VirtIO network adapters */
|
|
|
|
s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw");
|
2015-03-09 22:56:08 +08:00
|
|
|
|
|
|
|
/* Register savevm handler for guest TOD clock */
|
|
|
|
register_savevm(NULL, "todclock", 0, 1,
|
|
|
|
gtod_save, gtod_load, kvm_state);
|
2013-01-24 14:08:56 +08:00
|
|
|
}
|
|
|
|
|
2014-08-20 20:16:34 +08:00
|
|
|
static void ccw_machine_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
MachineClass *mc = MACHINE_CLASS(oc);
|
2014-08-20 20:16:35 +08:00
|
|
|
NMIClass *nc = NMI_CLASS(oc);
|
2014-08-20 20:16:34 +08:00
|
|
|
|
|
|
|
mc->init = ccw_init;
|
2015-07-21 19:47:32 +08:00
|
|
|
mc->reset = s390_machine_reset;
|
2014-08-20 20:16:34 +08:00
|
|
|
mc->block_default_type = IF_VIRTIO;
|
|
|
|
mc->no_cdrom = 1;
|
|
|
|
mc->no_floppy = 1;
|
|
|
|
mc->no_serial = 1;
|
|
|
|
mc->no_parallel = 1;
|
|
|
|
mc->no_sdcard = 1;
|
2014-12-03 22:38:28 +08:00
|
|
|
mc->use_sclp = 1;
|
2014-08-20 20:16:34 +08:00
|
|
|
mc->max_cpus = 255;
|
2014-08-20 20:16:35 +08:00
|
|
|
nc->nmi_monitor_handler = s390_nmi;
|
2014-08-20 20:16:34 +08:00
|
|
|
}
|
|
|
|
|
2015-03-12 20:53:51 +08:00
|
|
|
static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
|
|
|
|
|
|
|
|
return ms->aes_key_wrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void machine_set_aes_key_wrap(Object *obj, bool value,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
|
|
|
|
|
|
|
|
ms->aes_key_wrap = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
|
|
|
|
|
|
|
|
return ms->dea_key_wrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void machine_set_dea_key_wrap(Object *obj, bool value,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
|
|
|
|
|
|
|
|
ms->dea_key_wrap = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void s390_machine_initfn(Object *obj)
|
|
|
|
{
|
|
|
|
object_property_add_bool(obj, "aes-key-wrap",
|
|
|
|
machine_get_aes_key_wrap,
|
|
|
|
machine_set_aes_key_wrap, NULL);
|
|
|
|
object_property_set_description(obj, "aes-key-wrap",
|
|
|
|
"enable/disable AES key wrapping using the CPACF wrapping key",
|
|
|
|
NULL);
|
|
|
|
object_property_set_bool(obj, true, "aes-key-wrap", NULL);
|
|
|
|
|
|
|
|
object_property_add_bool(obj, "dea-key-wrap",
|
|
|
|
machine_get_dea_key_wrap,
|
|
|
|
machine_set_dea_key_wrap, NULL);
|
|
|
|
object_property_set_description(obj, "dea-key-wrap",
|
|
|
|
"enable/disable DEA key wrapping using the CPACF wrapping key",
|
|
|
|
NULL);
|
|
|
|
object_property_set_bool(obj, true, "dea-key-wrap", NULL);
|
|
|
|
}
|
|
|
|
|
2014-08-20 20:16:34 +08:00
|
|
|
static const TypeInfo ccw_machine_info = {
|
|
|
|
.name = TYPE_S390_CCW_MACHINE,
|
|
|
|
.parent = TYPE_MACHINE,
|
2015-07-01 17:16:57 +08:00
|
|
|
.abstract = true,
|
2015-03-12 20:53:51 +08:00
|
|
|
.instance_size = sizeof(S390CcwMachineState),
|
|
|
|
.instance_init = s390_machine_initfn,
|
2014-08-20 20:16:34 +08:00
|
|
|
.class_init = ccw_machine_class_init,
|
2014-08-20 20:16:35 +08:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_NMI },
|
|
|
|
{ }
|
|
|
|
},
|
2013-01-24 14:08:56 +08:00
|
|
|
};
|
|
|
|
|
2015-07-10 01:56:44 +08:00
|
|
|
#define CCW_COMPAT_2_4 \
|
2015-10-16 18:25:52 +08:00
|
|
|
HW_COMPAT_2_4 \
|
2015-07-10 01:56:44 +08:00
|
|
|
{\
|
|
|
|
.driver = TYPE_S390_SKEYS,\
|
|
|
|
.property = "migration-enabled",\
|
|
|
|
.value = "off",\
|
2015-09-11 21:16:44 +08:00
|
|
|
},{\
|
|
|
|
.driver = "virtio-blk-ccw",\
|
|
|
|
.property = "max_revision",\
|
|
|
|
.value = "0",\
|
|
|
|
},{\
|
|
|
|
.driver = "virtio-balloon-ccw",\
|
|
|
|
.property = "max_revision",\
|
|
|
|
.value = "0",\
|
|
|
|
},{\
|
|
|
|
.driver = "virtio-serial-ccw",\
|
|
|
|
.property = "max_revision",\
|
|
|
|
.value = "0",\
|
|
|
|
},{\
|
|
|
|
.driver = "virtio-9p-ccw",\
|
|
|
|
.property = "max_revision",\
|
|
|
|
.value = "0",\
|
|
|
|
},{\
|
|
|
|
.driver = "virtio-rng-ccw",\
|
|
|
|
.property = "max_revision",\
|
|
|
|
.value = "0",\
|
2015-10-08 21:11:34 +08:00
|
|
|
},{\
|
|
|
|
.driver = "virtio-net-ccw",\
|
|
|
|
.property = "max_revision",\
|
|
|
|
.value = "0",\
|
|
|
|
},{\
|
|
|
|
.driver = "virtio-scsi-ccw",\
|
|
|
|
.property = "max_revision",\
|
|
|
|
.value = "0",\
|
|
|
|
},{\
|
|
|
|
.driver = "vhost-scsi-ccw",\
|
|
|
|
.property = "max_revision",\
|
|
|
|
.value = "0",\
|
2015-07-10 01:56:44 +08:00
|
|
|
},
|
|
|
|
|
2015-07-01 17:16:57 +08:00
|
|
|
static void ccw_machine_2_4_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
MachineClass *mc = MACHINE_CLASS(oc);
|
2015-07-10 01:56:44 +08:00
|
|
|
static GlobalProperty compat_props[] = {
|
|
|
|
CCW_COMPAT_2_4
|
|
|
|
{ /* end of list */ }
|
|
|
|
};
|
2015-07-01 17:16:57 +08:00
|
|
|
|
|
|
|
mc->desc = "VirtIO-ccw based S390 machine v2.4";
|
2015-07-10 01:56:44 +08:00
|
|
|
mc->compat_props = compat_props;
|
2015-07-01 17:16:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo ccw_machine_2_4_info = {
|
2015-08-21 05:54:33 +08:00
|
|
|
.name = MACHINE_TYPE_NAME("s390-ccw-virtio-2.4"),
|
2015-07-01 17:16:57 +08:00
|
|
|
.parent = TYPE_S390_CCW_MACHINE,
|
|
|
|
.class_init = ccw_machine_2_4_class_init,
|
|
|
|
};
|
|
|
|
|
2015-07-17 19:16:52 +08:00
|
|
|
static void ccw_machine_2_5_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
MachineClass *mc = MACHINE_CLASS(oc);
|
|
|
|
|
|
|
|
mc->alias = "s390-ccw-virtio";
|
|
|
|
mc->desc = "VirtIO-ccw based S390 machine v2.5";
|
|
|
|
mc->is_default = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo ccw_machine_2_5_info = {
|
2015-08-21 05:54:33 +08:00
|
|
|
.name = MACHINE_TYPE_NAME("s390-ccw-virtio-2.5"),
|
2015-07-17 19:16:52 +08:00
|
|
|
.parent = TYPE_S390_CCW_MACHINE,
|
|
|
|
.class_init = ccw_machine_2_5_class_init,
|
|
|
|
};
|
|
|
|
|
2014-08-20 20:16:34 +08:00
|
|
|
static void ccw_machine_register_types(void)
|
2013-01-24 14:08:56 +08:00
|
|
|
{
|
2014-08-20 20:16:34 +08:00
|
|
|
type_register_static(&ccw_machine_info);
|
2015-07-01 17:16:57 +08:00
|
|
|
type_register_static(&ccw_machine_2_4_info);
|
2015-07-17 19:16:52 +08:00
|
|
|
type_register_static(&ccw_machine_2_5_info);
|
2013-01-24 14:08:56 +08:00
|
|
|
}
|
|
|
|
|
2014-08-20 20:16:34 +08:00
|
|
|
type_init(ccw_machine_register_types)
|