From 3a553fc65826e0e682ed0fff770ad0d421c6d407 Mon Sep 17 00:00:00 2001 From: Jens Freimann Date: Tue, 16 Jul 2013 09:04:04 +0200 Subject: s390x/kvm: implement floating-interrupt controller device This patch implements a floating-interrupt controller device (flic) which interacts with the s390 flic kvm_device. Signed-off-by: Jens Freimann Reviewed-by: Cornelia Huck Signed-off-by: Christian Borntraeger --- hw/intc/Makefile.objs | 1 + hw/intc/s390_flic.c | 286 +++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/s390-virtio-ccw.c | 8 +- hw/s390x/s390-virtio.c | 2 + 4 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 hw/intc/s390_flic.c (limited to 'hw') diff --git a/hw/intc/Makefile.objs b/hw/intc/Makefile.objs index 60eb936e0d..c8a2318d56 100644 --- a/hw/intc/Makefile.objs +++ b/hw/intc/Makefile.objs @@ -25,3 +25,4 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o +obj-$(CONFIG_S390_FLIC) += s390_flic.o diff --git a/hw/intc/s390_flic.c b/hw/intc/s390_flic.c new file mode 100644 index 0000000000..1a7876da78 --- /dev/null +++ b/hw/intc/s390_flic.c @@ -0,0 +1,286 @@ +/* + * QEMU S390x KVM floating interrupt controller (flic) + * + * Copyright 2014 IBM Corp. + * Author(s): Jens Freimann + * + * 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 +#include "qemu/error-report.h" +#include "hw/sysbus.h" +#include "sysemu/kvm.h" +#include "migration/qemu-file.h" +#include "hw/s390x/s390_flic.h" +#include "trace.h" + +#define FLIC_SAVE_INITIAL_SIZE getpagesize() +#define FLIC_FAILED (-1UL) +#define FLIC_SAVEVM_VERSION 1 + +void s390_flic_init(void) +{ + DeviceState *dev; + int r; + + if (kvm_enabled()) { + dev = qdev_create(NULL, "s390-flic"); + object_property_add_child(qdev_get_machine(), "s390-flic", + OBJECT(dev), NULL); + r = qdev_init(dev); + if (r) { + error_report("flic: couldn't create qdev"); + } + } +} + +/** + * flic_get_all_irqs - store all pending irqs in buffer + * @buf: pointer to buffer which is passed to kernel + * @len: length of buffer + * @flic: pointer to flic device state + * + * Returns: -ENOMEM if buffer is too small, + * -EINVAL if attr.group is invalid, + * -EFAULT if copying to userspace failed, + * on success return number of stored interrupts + */ +static int flic_get_all_irqs(KVMS390FLICState *flic, + void *buf, int len) +{ + struct kvm_device_attr attr = { + .group = KVM_DEV_FLIC_GET_ALL_IRQS, + .addr = (uint64_t) buf, + .attr = len, + }; + int rc; + + rc = ioctl(flic->fd, KVM_GET_DEVICE_ATTR, &attr); + + return rc == -1 ? -errno : rc; +} + +/** flic_enqueue_irqs - returns 0 on success + * @buf: pointer to buffer which is passed to kernel + * @len: length of buffer + * @flic: pointer to flic device state + * + * Returns: -EINVAL if attr.group is unknown + */ +static int flic_enqueue_irqs(void *buf, uint64_t len, + KVMS390FLICState *flic) +{ + int rc; + struct kvm_device_attr attr = { + .group = KVM_DEV_FLIC_ENQUEUE, + .addr = (uint64_t) buf, + .attr = len, + }; + + rc = ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); + + return rc ? -errno : 0; +} + +/** + * __get_all_irqs - store all pending irqs in buffer + * @flic: pointer to flic device state + * @buf: pointer to pointer to a buffer + * @len: length of buffer + * + * Returns: return value of flic_get_all_irqs + * Note: Retry and increase buffer size until flic_get_all_irqs + * either returns a value >= 0 or a negative error code. + * -ENOMEM is an exception, which means the buffer is too small + * and we should try again. Other negative error codes can be + * -EFAULT and -EINVAL which we ignore at this point + */ +static int __get_all_irqs(KVMS390FLICState *flic, + void **buf, int len) +{ + int r; + + do { + /* returns -ENOMEM if buffer is too small and number + * of queued interrupts on success */ + r = flic_get_all_irqs(flic, *buf, len); + if (r >= 0) { + break; + } + len *= 2; + *buf = g_try_realloc(*buf, len); + if (!buf) { + return -ENOMEM; + } + } while (r == -ENOMEM && len <= KVM_S390_FLIC_MAX_BUFFER); + + return r; +} + +/** + * kvm_flic_save - Save pending floating interrupts + * @f: QEMUFile containing migration state + * @opaque: pointer to flic device state + * + * Note: Pass buf and len to kernel. Start with one page and + * increase until buffer is sufficient or maxium size is + * reached + */ +static void kvm_flic_save(QEMUFile *f, void *opaque) +{ + KVMS390FLICState *flic = opaque; + int len = FLIC_SAVE_INITIAL_SIZE; + void *buf; + int count; + + buf = g_try_malloc0(len); + if (!buf) { + /* Storing FLIC_FAILED into the count field here will cause the + * target system to fail when attempting to load irqs from the + * migration state */ + error_report("flic: couldn't allocate memory"); + qemu_put_be64(f, FLIC_FAILED); + return; + } + + count = __get_all_irqs(flic, &buf, len); + if (count < 0) { + error_report("flic: couldn't retrieve irqs from kernel, rc %d", + count); + /* Storing FLIC_FAILED into the count field here will cause the + * target system to fail when attempting to load irqs from the + * migration state */ + qemu_put_be64(f, FLIC_FAILED); + } else { + qemu_put_be64(f, count); + qemu_put_buffer(f, (uint8_t *) buf, + count * sizeof(struct kvm_s390_irq)); + } + g_free(buf); +} + +/** + * kvm_flic_load - Load pending floating interrupts + * @f: QEMUFile containing migration state + * @opaque: pointer to flic device state + * @version_id: version id for migration + * + * Returns: value of flic_enqueue_irqs, -EINVAL on error + * Note: Do nothing when no interrupts where stored + * in QEMUFile + */ +static int kvm_flic_load(QEMUFile *f, void *opaque, int version_id) +{ + uint64_t len = 0; + uint64_t count = 0; + void *buf = NULL; + int r = 0; + + if (version_id != FLIC_SAVEVM_VERSION) { + r = -EINVAL; + goto out; + } + + count = qemu_get_be64(f); + len = count * sizeof(struct kvm_s390_irq); + if (count == FLIC_FAILED) { + r = -EINVAL; + goto out; + } + if (count == 0) { + r = 0; + goto out; + } + buf = g_try_malloc0(len); + if (!buf) { + r = -ENOMEM; + goto out; + } + + if (qemu_get_buffer(f, (uint8_t *) buf, len) != len) { + r = -EINVAL; + goto out_free; + } + r = flic_enqueue_irqs(buf, len, (struct KVMS390FLICState *) opaque); + +out_free: + g_free(buf); +out: + return r; +} + +static void kvm_s390_flic_realize(DeviceState *dev, Error **errp) +{ + KVMS390FLICState *flic_state = KVM_S390_FLIC(dev); + struct kvm_create_device cd = {0}; + int ret; + + flic_state->fd = -1; + if (!kvm_check_extension(kvm_state, KVM_CAP_DEVICE_CTRL)) { + trace_flic_no_device_api(errno); + return; + } + + cd.type = KVM_DEV_TYPE_FLIC; + ret = kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &cd); + if (ret < 0) { + trace_flic_create_device(errno); + return; + } + flic_state->fd = cd.fd; + + /* Register savevm handler for floating interrupts */ + register_savevm(NULL, "s390-flic", 0, 1, kvm_flic_save, + kvm_flic_load, (void *) flic_state); +} + +static void kvm_s390_flic_unrealize(DeviceState *dev, Error **errp) +{ + KVMS390FLICState *flic_state = KVM_S390_FLIC(dev); + + unregister_savevm(DEVICE(flic_state), "s390-flic", flic_state); +} + +static void kvm_s390_flic_reset(DeviceState *dev) +{ + KVMS390FLICState *flic = KVM_S390_FLIC(dev); + struct kvm_device_attr attr = { + .group = KVM_DEV_FLIC_CLEAR_IRQS, + }; + int rc = 0; + + if (flic->fd == -1) { + return; + } + + rc = ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); + if (rc) { + trace_flic_reset_failed(errno); + } +} + +static void kvm_s390_flic_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + + dc->realize = kvm_s390_flic_realize; + dc->unrealize = kvm_s390_flic_unrealize; + dc->reset = kvm_s390_flic_reset; +} + +static const TypeInfo kvm_s390_flic_info = { + .name = TYPE_KVM_S390_FLIC, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(KVMS390FLICState), + .class_init = kvm_s390_flic_class_init, +}; + +static void kvm_s390_flic_register_types(void) +{ + type_register_static(&kvm_s390_flic_info); +} + +type_init(kvm_s390_flic_register_types) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 733d988871..0d4f6ae2f3 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -13,13 +13,14 @@ #include "exec/address-spaces.h" #include "s390-virtio.h" #include "hw/s390x/sclp.h" +#include "hw/s390x/s390_flic.h" #include "ioinst.h" #include "css.h" #include "virtio-ccw.h" void io_subsystem_reset(void) { - DeviceState *css, *sclp; + DeviceState *css, *sclp, *flic; css = DEVICE(object_resolve_path_type("", "virtual-css-bridge", NULL)); if (css) { @@ -30,6 +31,10 @@ void io_subsystem_reset(void) if (sclp) { qdev_reset_all(sclp); } + flic = DEVICE(object_resolve_path_type("", "s390-flic", NULL)); + if (flic) { + qdev_reset_all(flic); + } } static int virtio_ccw_hcall_notify(const uint64_t *args) @@ -99,6 +104,7 @@ static void ccw_init(QEMUMachineInitArgs *args) s390_sclp_init(); s390_init_ipl_dev(args->kernel_filename, args->kernel_cmdline, args->initrd_filename, "s390-ccw.img"); + s390_flic_init(); /* register hypercalls */ virtio_ccw_register_hcalls(); diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c index 9eeda97920..0f03fd18b9 100644 --- a/hw/s390x/s390-virtio.c +++ b/hw/s390x/s390-virtio.c @@ -36,6 +36,7 @@ #include "hw/s390x/s390-virtio-bus.h" #include "hw/s390x/sclp.h" +#include "hw/s390x/s390_flic.h" #include "hw/s390x/s390-virtio.h" //#define DEBUG_S390 @@ -251,6 +252,7 @@ static void s390_init(QEMUMachineInitArgs *args) s390_sclp_init(); s390_init_ipl_dev(args->kernel_filename, args->kernel_cmdline, args->initrd_filename, ZIPL_FILENAME); + s390_flic_init(); /* register hypercalls */ s390_virtio_register_hcalls(); -- cgit v1.2.1 From 819bd3091e986c1b6b10203a7138a53b849a53e0 Mon Sep 17 00:00:00 2001 From: Dominik Dingel Date: Thu, 5 Sep 2013 13:54:39 +0200 Subject: s390x/async_pf: Check for apf extension and enable pfault S390 can also use async page faults, to enhance guest scheduling. In case of live migration we want to disable the feature and let all pending request finish. Signed-off-by: Dominik Dingel Signed-off-by: Jens Freimann Signed-off-by: Christian Borntraeger --- hw/intc/s390_flic.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'hw') diff --git a/hw/intc/s390_flic.c b/hw/intc/s390_flic.c index 1a7876da78..b2ef3e3f8e 100644 --- a/hw/intc/s390_flic.c +++ b/hw/intc/s390_flic.c @@ -63,6 +63,34 @@ static int flic_get_all_irqs(KVMS390FLICState *flic, return rc == -1 ? -errno : rc; } +static void flic_enable_pfault(KVMS390FLICState *flic) +{ + struct kvm_device_attr attr = { + .group = KVM_DEV_FLIC_APF_ENABLE, + }; + int rc; + + rc = ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); + + if (rc) { + fprintf(stderr, "flic: couldn't enable pfault\n"); + } +} + +static void flic_disable_wait_pfault(KVMS390FLICState *flic) +{ + struct kvm_device_attr attr = { + .group = KVM_DEV_FLIC_APF_DISABLE_WAIT, + }; + int rc; + + rc = ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); + + if (rc) { + fprintf(stderr, "flic: couldn't disable pfault\n"); + } +} + /** flic_enqueue_irqs - returns 0 on success * @buf: pointer to buffer which is passed to kernel * @len: length of buffer @@ -136,6 +164,8 @@ static void kvm_flic_save(QEMUFile *f, void *opaque) void *buf; int count; + flic_disable_wait_pfault((struct KVMS390FLICState *) opaque); + buf = g_try_malloc0(len); if (!buf) { /* Storing FLIC_FAILED into the count field here will cause the @@ -184,6 +214,8 @@ static int kvm_flic_load(QEMUFile *f, void *opaque, int version_id) goto out; } + flic_enable_pfault((struct KVMS390FLICState *) opaque); + count = qemu_get_be64(f); len = count * sizeof(struct kvm_s390_irq); if (count == FLIC_FAILED) { @@ -256,10 +288,14 @@ static void kvm_s390_flic_reset(DeviceState *dev) return; } + flic_disable_wait_pfault(flic); + rc = ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); if (rc) { trace_flic_reset_failed(errno); } + + flic_enable_pfault(flic); } static void kvm_s390_flic_class_init(ObjectClass *oc, void *data) -- cgit v1.2.1 From f2c55d1735175ab37ab9f69854460087112d2756 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Mon, 13 Jan 2014 09:26:49 +0100 Subject: s390x/virtio-hcall: Add range check for hypervisor call The handler for diag 500 did not check whether the requested function was in the supported range, so illegal values could crash QEMU in the worst case. Signed-off-by: Thomas Huth Reviewed-by: Cornelia Huck Signed-off-by: Christian Borntraeger CC: qemu-stable@nongnu.org --- hw/s390x/s390-virtio-hcall.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'hw') diff --git a/hw/s390x/s390-virtio-hcall.c b/hw/s390x/s390-virtio-hcall.c index ee626493c6..0e328d806d 100644 --- a/hw/s390x/s390-virtio-hcall.c +++ b/hw/s390x/s390-virtio-hcall.c @@ -26,11 +26,14 @@ void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn) int s390_virtio_hypercall(CPUS390XState *env) { - s390_virtio_fn fn = s390_diag500_table[env->regs[1]]; + s390_virtio_fn fn; - if (!fn) { - return -EINVAL; + if (env->regs[1] < MAX_DIAG_SUBCODES) { + fn = s390_diag500_table[env->regs[1]]; + if (fn) { + return fn(&env->regs[2]); + } } - return fn(&env->regs[2]); + return -EINVAL; } -- cgit v1.2.1 From 77319f22635e3f0ef86730503b4d18dd9a833529 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Tue, 14 Jan 2014 13:32:23 +0100 Subject: s390x/virtio-hcall: Specification exception for illegal subcodes So far, the DIAG 500 hypervisor call was only setting -EINVAL in R2 when a guest tried to call this function with an illegal subcode. This patch now changes the behavior so that a specification exception is thrown instead, since this is the common behavior of other DIAG functions (and other CPU instructions) when being called with illegal parameters. Signed-off-by: Thomas Huth Reviewed-by: Cornelia Huck Signed-off-by: Christian Borntraeger --- hw/s390x/s390-virtio-hcall.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'hw') diff --git a/hw/s390x/s390-virtio-hcall.c b/hw/s390x/s390-virtio-hcall.c index 0e328d806d..c7bdc2005d 100644 --- a/hw/s390x/s390-virtio-hcall.c +++ b/hw/s390x/s390-virtio-hcall.c @@ -31,7 +31,8 @@ int s390_virtio_hypercall(CPUS390XState *env) if (env->regs[1] < MAX_DIAG_SUBCODES) { fn = s390_diag500_table[env->regs[1]]; if (fn) { - return fn(&env->regs[2]); + env->regs[2] = fn(&env->regs[2]); + return 0; } } -- cgit v1.2.1 From 9da45bb217db41510684cbfd4e173186eb2f8477 Mon Sep 17 00:00:00 2001 From: Christian Borntraeger Date: Fri, 7 Feb 2014 13:41:58 +0100 Subject: s390x/eventfacility: mask out commands As a followup to commit 5f04c14a10fa7f259bc0808f35a0beda49f7821e (s390-sclp: Define New SCLP Codes) we should mask the sclp command not only in base sclp, but also in the event facility. Based on an initial patch from Ralf Hoppe. Signed-off-by: Christian Borntraeger --- hw/s390x/event-facility.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hw') diff --git a/hw/s390x/event-facility.c b/hw/s390x/event-facility.c index a73c0b924a..1e8c99ae94 100644 --- a/hw/s390x/event-facility.c +++ b/hw/s390x/event-facility.c @@ -299,7 +299,7 @@ static const TypeInfo s390_sclp_events_bus_info = { static void command_handler(SCLPEventFacility *ef, SCCB *sccb, uint64_t code) { - switch (code) { + switch (code & SCLP_CMD_CODE_MASK) { case SCLP_CMD_READ_EVENT_DATA: read_event_data(ef, sccb); break; -- cgit v1.2.1 From a0fa2cb8ccf0b73cfd3ac01d557401a2303c0de4 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Mon, 13 Jan 2014 12:19:03 +0100 Subject: s390x/sclp: Fixed the size of sccb and code parameter The pointer to the SCCB should not be limited to 32 bits only. In contrast to this, the command word parameter is only 32 bits (the upper 32 bits should be ignored). Signed-off-by: Thomas Huth Reviewed-by: Cornelia Huck Signed-off-by: Christian Borntraeger --- hw/s390x/sclp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'hw') diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c index 4e0c564c5c..6134d4f904 100644 --- a/hw/s390x/sclp.c +++ b/hw/s390x/sclp.c @@ -89,7 +89,7 @@ static void sclp_read_cpu_info(SCCB *sccb) sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_READ_COMPLETION); } -static void sclp_execute(SCCB *sccb, uint64_t code) +static void sclp_execute(SCCB *sccb, uint32_t code) { S390SCLPDevice *sdev = get_event_facility(); @@ -107,7 +107,7 @@ static void sclp_execute(SCCB *sccb, uint64_t code) } } -int sclp_service_call(uint32_t sccb, uint64_t code) +int sclp_service_call(uint64_t sccb, uint32_t code) { int r = 0; SCCB work_sccb; -- cgit v1.2.1 From 6e25280216fc23c8387892f76d961559da124528 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Mon, 13 Jan 2014 12:55:55 +0100 Subject: s390x/sclp: Add missing checks to SCLP handler If the 51 most significant bits of the SCCB address are zero or equal to the prefix, we should throw an specification exception, too. Also moved the check for privileged mode to sclp_service_call() to have all program checks in one place now. Signed-off-by: Thomas Huth Reviewed-by: Cornelia Huck Signed-off-by: Christian Borntraeger --- hw/s390x/sclp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'hw') diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c index 6134d4f904..98809777c8 100644 --- a/hw/s390x/sclp.c +++ b/hw/s390x/sclp.c @@ -107,7 +107,7 @@ static void sclp_execute(SCCB *sccb, uint32_t code) } } -int sclp_service_call(uint64_t sccb, uint32_t code) +int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code) { int r = 0; SCCB work_sccb; @@ -115,11 +115,16 @@ int sclp_service_call(uint64_t sccb, uint32_t code) hwaddr sccb_len = sizeof(SCCB); /* first some basic checks on program checks */ + if (env->psw.mask & PSW_MASK_PSTATE) { + r = -PGM_PRIVILEGED; + goto out; + } if (cpu_physical_memory_is_io(sccb)) { r = -PGM_ADDRESSING; goto out; } - if (sccb & ~0x7ffffff8ul) { + if ((sccb & ~0x1fffUL) == 0 || (sccb & ~0x1fffUL) == env->psa + || (sccb & ~0x7ffffff8UL) != 0) { r = -PGM_SPECIFICATION; goto out; } -- cgit v1.2.1 From 65e526c24e27863b2a0093e1350a8ae558be5936 Mon Sep 17 00:00:00 2001 From: Heinz Graalfs Date: Mon, 23 Dec 2013 10:25:38 +0100 Subject: s390x/event-facility: some renaming Do some renaming to shorten some identifiers and to emphasize sclp. Signed-off-by: Heinz Graalfs Acked-by: Cornelia Huck Signed-off-by: Christian Borntraeger --- hw/s390x/event-facility.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'hw') diff --git a/hw/s390x/event-facility.c b/hw/s390x/event-facility.c index 1e8c99ae94..e0ee7379e2 100644 --- a/hw/s390x/event-facility.c +++ b/hw/s390x/event-facility.c @@ -21,12 +21,12 @@ #include "hw/s390x/sclp.h" #include "hw/s390x/event-facility.h" -typedef struct EventTypesBus { +typedef struct SCLPEventsBus { BusState qbus; -} EventTypesBus; +} SCLPEventsBus; struct SCLPEventFacility { - EventTypesBus sbus; + SCLPEventsBus sbus; DeviceState *qdev; /* guest' receive mask */ unsigned int receive_mask; @@ -291,7 +291,7 @@ static void sclp_events_bus_class_init(ObjectClass *klass, void *data) { } -static const TypeInfo s390_sclp_events_bus_info = { +static const TypeInfo sclp_events_bus_info = { .name = TYPE_SCLP_EVENTS_BUS, .parent = TYPE_BUS, .class_init = sclp_events_bus_class_init, @@ -360,7 +360,7 @@ static void init_event_facility_class(ObjectClass *klass, void *data) k->init = init_event_facility; } -static const TypeInfo s390_sclp_event_facility_info = { +static const TypeInfo sclp_event_facility_info = { .name = "s390-sclp-event-facility", .parent = TYPE_DEVICE_S390_SCLP, .instance_size = sizeof(S390SCLPDevice), @@ -395,7 +395,7 @@ static void event_class_init(ObjectClass *klass, void *data) dc->exit = event_qdev_exit; } -static const TypeInfo s390_sclp_event_type_info = { +static const TypeInfo sclp_event_type_info = { .name = TYPE_SCLP_EVENT, .parent = TYPE_DEVICE, .instance_size = sizeof(SCLPEvent), @@ -406,9 +406,9 @@ static const TypeInfo s390_sclp_event_type_info = { static void register_types(void) { - type_register_static(&s390_sclp_events_bus_info); - type_register_static(&s390_sclp_event_facility_info); - type_register_static(&s390_sclp_event_type_info); + type_register_static(&sclp_events_bus_info); + type_register_static(&sclp_event_facility_info); + type_register_static(&sclp_event_type_info); } type_init(register_types) -- cgit v1.2.1 From 477a72a1eff40639761e103f5b7652af7746c48e Mon Sep 17 00:00:00 2001 From: Heinz Graalfs Date: Wed, 18 Dec 2013 10:10:49 +0100 Subject: s390x/event-facility: code restructure Code restructure in order to simplify class hierarchy - remove S390SCLPDevice abstract base class and move function pointers into new SCLPEventFacilityClass - implement SCLPEventFacility as SysBusDevice - use define constants for instance creation strings The following ascii-art shows the class structure wrt the SCLP EventFacility before (CURRENT) and after the restructure (NEW): ---- CURRENT: "s390-sclp-events-bus" +-------------------------+ | SCLPEventsBus | |-------------------------| |BusState qbus | +-------------------------+ +-------------------------+ | SCLPEventFacility | - to be replaced by new SCLPEventFacility, |-------------------------| which will be a SysBusDevice |SCLPEventsBus sbus | |DeviceState *qdev | |unsigned int receive_mask| +-------------------------+ +-------------------------+ | S390SCLPDeviceClass | - to be replaced by new SCLPEventFacilityClass |-------------------------| |DeviceClass qdev | |*(init)() | +-------------------------+ "s390-sclp-event-facility" | instance-of | V "s390-sclp-device" - this is an abstract class +-------------------------+ | S390SCLPDevice (A)| - to be replaced by new SCLPEventFacility |-------------------------| |SysBusDevice busdev | |SCLPEventFacility *ef | | | |*(sclp_command_handler)()| - these 2 go to new SCLPEventFacilityClass |*(event_pending)() | +-------------------------+ ---- NEW: "s390-sclp-events-bus" +-------------------------+ | SCLPEventsBus | |-------------------------| |BusState qbus | +-------------------------+ +-------------------------+ | SCLPEventFacilityClass | |-------------------------| |DeviceClass parent_class | | | |*(init)() | |*(command_handler)() | |*(event_pending)() | +-------------------------+ "s390-sclp-event-facility" +-------------------------+ | SCLPEventFacility | |-------------------------| |SysBusDevice parent_class| |SCLPEventsBus sbus | |unsigned int receive_mask| +-------------------------+ Signed-off-by: Heinz Graalfs Reviewed-by: Cornelia Huck Signed-off-by: Christian Borntraeger --- hw/s390x/event-facility.c | 34 +++++++++++++-------------- hw/s390x/sclp.c | 58 ++++++++++------------------------------------- 2 files changed, 28 insertions(+), 64 deletions(-) (limited to 'hw') diff --git a/hw/s390x/event-facility.c b/hw/s390x/event-facility.c index e0ee7379e2..8ad2dc4094 100644 --- a/hw/s390x/event-facility.c +++ b/hw/s390x/event-facility.c @@ -26,8 +26,8 @@ typedef struct SCLPEventsBus { } SCLPEventsBus; struct SCLPEventFacility { + SysBusDevice parent_obj; SCLPEventsBus sbus; - DeviceState *qdev; /* guest' receive mask */ unsigned int receive_mask; }; @@ -315,21 +315,15 @@ static void command_handler(SCLPEventFacility *ef, SCCB *sccb, uint64_t code) } } -static int init_event_facility(S390SCLPDevice *sdev) +static int init_event_facility(SCLPEventFacility *event_facility) { - SCLPEventFacility *event_facility; + DeviceState *sdev = DEVICE(event_facility); DeviceState *quiesce; - event_facility = g_malloc0(sizeof(SCLPEventFacility)); - sdev->ef = event_facility; - sdev->sclp_command_handler = command_handler; - sdev->event_pending = event_pending; - - /* Spawn a new sclp-events facility */ + /* Spawn a new bus for SCLP events */ qbus_create_inplace(&event_facility->sbus, sizeof(event_facility->sbus), - TYPE_SCLP_EVENTS_BUS, DEVICE(sdev), NULL); + TYPE_SCLP_EVENTS_BUS, sdev, NULL); event_facility->sbus.qbus.allow_hotplug = 0; - event_facility->qdev = (DeviceState *) sdev; quiesce = qdev_create(&event_facility->sbus.qbus, "sclpquiesce"); if (!quiesce) { @@ -346,25 +340,29 @@ static int init_event_facility(S390SCLPDevice *sdev) static void reset_event_facility(DeviceState *dev) { - S390SCLPDevice *sdev = SCLP_S390_DEVICE(dev); + SCLPEventFacility *sdev = EVENT_FACILITY(dev); - sdev->ef->receive_mask = 0; + sdev->receive_mask = 0; } static void init_event_facility_class(ObjectClass *klass, void *data) { - DeviceClass *dc = DEVICE_CLASS(klass); - S390SCLPDeviceClass *k = SCLP_S390_DEVICE_CLASS(klass); + SysBusDeviceClass *sbdc = SYS_BUS_DEVICE_CLASS(klass); + DeviceClass *dc = DEVICE_CLASS(sbdc); + SCLPEventFacilityClass *k = EVENT_FACILITY_CLASS(dc); dc->reset = reset_event_facility; k->init = init_event_facility; + k->command_handler = command_handler; + k->event_pending = event_pending; } static const TypeInfo sclp_event_facility_info = { - .name = "s390-sclp-event-facility", - .parent = TYPE_DEVICE_S390_SCLP, - .instance_size = sizeof(S390SCLPDevice), + .name = TYPE_SCLP_EVENT_FACILITY, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(SCLPEventFacility), .class_init = init_event_facility_class, + .class_size = sizeof(SCLPEventFacilityClass), }; static int event_qdev_init(DeviceState *qdev) diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c index 98809777c8..d8ddf35e58 100644 --- a/hw/s390x/sclp.c +++ b/hw/s390x/sclp.c @@ -18,11 +18,12 @@ #include "sysemu/sysemu.h" #include "hw/s390x/sclp.h" +#include "hw/s390x/event-facility.h" -static inline S390SCLPDevice *get_event_facility(void) +static inline SCLPEventFacility *get_event_facility(void) { ObjectProperty *op = object_property_find(qdev_get_machine(), - "s390-sclp-event-facility", + TYPE_SCLP_EVENT_FACILITY, NULL); assert(op); return op->opaque; @@ -91,7 +92,8 @@ static void sclp_read_cpu_info(SCCB *sccb) static void sclp_execute(SCCB *sccb, uint32_t code) { - S390SCLPDevice *sdev = get_event_facility(); + SCLPEventFacility *ef = get_event_facility(); + SCLPEventFacilityClass *efc = EVENT_FACILITY_GET_CLASS(ef); switch (code & SCLP_CMD_CODE_MASK) { case SCLP_CMDW_READ_SCP_INFO: @@ -102,7 +104,7 @@ static void sclp_execute(SCCB *sccb, uint32_t code) sclp_read_cpu_info(sccb); break; default: - sdev->sclp_command_handler(sdev->ef, sccb, code); + efc->command_handler(ef, sccb, code); break; } } @@ -156,11 +158,13 @@ out: void sclp_service_interrupt(uint32_t sccb) { - S390SCLPDevice *sdev = get_event_facility(); + SCLPEventFacility *ef = get_event_facility(); + SCLPEventFacilityClass *efc = EVENT_FACILITY_GET_CLASS(ef); + uint32_t param = sccb & ~3; /* Indicate whether an event is still pending */ - param |= sdev->event_pending(sdev->ef) ? 1 : 0; + param |= efc->event_pending(ef) ? 1 : 0; if (!param) { /* No need to send an interrupt, there's nothing to be notified about */ @@ -173,47 +177,9 @@ void sclp_service_interrupt(uint32_t sccb) void s390_sclp_init(void) { - DeviceState *dev = qdev_create(NULL, "s390-sclp-event-facility"); + DeviceState *dev = qdev_create(NULL, TYPE_SCLP_EVENT_FACILITY); - object_property_add_child(qdev_get_machine(), "s390-sclp-event-facility", + object_property_add_child(qdev_get_machine(), TYPE_SCLP_EVENT_FACILITY, OBJECT(dev), NULL); qdev_init_nofail(dev); } - -static int s390_sclp_dev_init(SysBusDevice *dev) -{ - int r; - S390SCLPDevice *sdev = (S390SCLPDevice *)dev; - S390SCLPDeviceClass *sclp = SCLP_S390_DEVICE_GET_CLASS(dev); - - r = sclp->init(sdev); - if (!r) { - assert(sdev->event_pending); - assert(sdev->sclp_command_handler); - } - - return r; -} - -static void s390_sclp_device_class_init(ObjectClass *klass, void *data) -{ - SysBusDeviceClass *dc = SYS_BUS_DEVICE_CLASS(klass); - - dc->init = s390_sclp_dev_init; -} - -static const TypeInfo s390_sclp_device_info = { - .name = TYPE_DEVICE_S390_SCLP, - .parent = TYPE_SYS_BUS_DEVICE, - .instance_size = sizeof(S390SCLPDevice), - .class_init = s390_sclp_device_class_init, - .class_size = sizeof(S390SCLPDeviceClass), - .abstract = true, -}; - -static void s390_sclp_register_types(void) -{ - type_register_static(&s390_sclp_device_info); -} - -type_init(s390_sclp_register_types) -- cgit v1.2.1 From 6fbef18a4c8b3cd9c3da4772ed5ddaec9be06fac Mon Sep 17 00:00:00 2001 From: Heinz Graalfs Date: Wed, 18 Dec 2013 13:59:57 +0100 Subject: s390x/event-facility: add support for live migration Add support for live migration using VMStateDescription. Signed-off-by: Heinz Graalfs Reviewed-by: Cornelia Huck Signed-off-by: Christian Borntraeger --- hw/s390x/event-facility.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'hw') diff --git a/hw/s390x/event-facility.c b/hw/s390x/event-facility.c index 8ad2dc4094..5b6d5c65b5 100644 --- a/hw/s390x/event-facility.c +++ b/hw/s390x/event-facility.c @@ -315,6 +315,17 @@ static void command_handler(SCLPEventFacility *ef, SCCB *sccb, uint64_t code) } } +static const VMStateDescription vmstate_event_facility = { + .name = "vmstate-event-facility", + .version_id = 0, + .minimum_version_id = 0, + .minimum_version_id_old = 0, + .fields = (VMStateField[]) { + VMSTATE_UINT32(receive_mask, SCLPEventFacility), + VMSTATE_END_OF_LIST() + } +}; + static int init_event_facility(SCLPEventFacility *event_facility) { DeviceState *sdev = DEVICE(event_facility); @@ -352,6 +363,7 @@ static void init_event_facility_class(ObjectClass *klass, void *data) SCLPEventFacilityClass *k = EVENT_FACILITY_CLASS(dc); dc->reset = reset_event_facility; + dc->vmsd = &vmstate_event_facility; k->init = init_event_facility; k->command_handler = command_handler; k->event_pending = event_pending; -- cgit v1.2.1 From c804c2a71752dd1e150cde768d8c54b02fa8bad9 Mon Sep 17 00:00:00 2001 From: Heinz Graalfs Date: Fri, 20 Dec 2013 12:02:17 +0100 Subject: s390x/event-facility: exploit realize/unrealize init/exit functionality of abstract SCLPEvent class is now exploiting realize/unrealize. Signed-off-by: Heinz Graalfs Reviewed-by: Cornelia Huck Signed-off-by: Christian Borntraeger --- hw/s390x/event-facility.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'hw') diff --git a/hw/s390x/event-facility.c b/hw/s390x/event-facility.c index 5b6d5c65b5..0777a93916 100644 --- a/hw/s390x/event-facility.c +++ b/hw/s390x/event-facility.c @@ -377,22 +377,31 @@ static const TypeInfo sclp_event_facility_info = { .class_size = sizeof(SCLPEventFacilityClass), }; -static int event_qdev_init(DeviceState *qdev) +static void event_realize(DeviceState *qdev, Error **errp) { - SCLPEvent *event = DO_UPCAST(SCLPEvent, qdev, qdev); + SCLPEvent *event = SCLP_EVENT(qdev); SCLPEventClass *child = SCLP_EVENT_GET_CLASS(event); - return child->init(event); + if (child->init) { + int rc = child->init(event); + if (rc < 0) { + error_setg(errp, "SCLP event initialization failed."); + return; + } + } } -static int event_qdev_exit(DeviceState *qdev) +static void event_unrealize(DeviceState *qdev, Error **errp) { - SCLPEvent *event = DO_UPCAST(SCLPEvent, qdev, qdev); + SCLPEvent *event = SCLP_EVENT(qdev); SCLPEventClass *child = SCLP_EVENT_GET_CLASS(event); if (child->exit) { - child->exit(event); + int rc = child->exit(event); + if (rc < 0) { + error_setg(errp, "SCLP event exit failed."); + return; + } } - return 0; } static void event_class_init(ObjectClass *klass, void *data) @@ -401,8 +410,8 @@ static void event_class_init(ObjectClass *klass, void *data) dc->bus_type = TYPE_SCLP_EVENTS_BUS; dc->unplug = qdev_simple_unplug_cb; - dc->init = event_qdev_init; - dc->exit = event_qdev_exit; + dc->realize = event_realize; + dc->unrealize = event_unrealize; } static const TypeInfo sclp_event_type_info = { -- cgit v1.2.1 From 7f00eb30febf1054c74b163ced984afcdbf6e670 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Sat, 8 Feb 2014 12:31:15 +0100 Subject: s390x/ipl: Fix crash of ELF images with arbitrary entry points When loading S390 kernels, the current code expects an ELF file with the start address 0x10000. Other ELF files cause a segmentation fault. To avoid these crashes, we should get the start address from the ELF file instead of always using a hard-coded address. Signed-off-by: Thomas Huth Acked-by: Cornelia Huck Signed-off-by: Christian Borntraeger --- hw/s390x/ipl.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'hw') diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c index 1a6397b88e..04fb1a8e05 100644 --- a/hw/s390x/ipl.c +++ b/hw/s390x/ipl.c @@ -95,7 +95,8 @@ static int s390_ipl_init(SysBusDevice *dev) } return 0; } else { - kernel_size = load_elf(ipl->kernel, NULL, NULL, NULL, NULL, + uint64_t pentry = KERN_IMAGE_START; + kernel_size = load_elf(ipl->kernel, NULL, NULL, &pentry, NULL, NULL, 1, ELF_MACHINE, 0); if (kernel_size == -1) { kernel_size = load_image_targphys(ipl->kernel, 0, ram_size); @@ -104,15 +105,19 @@ static int s390_ipl_init(SysBusDevice *dev) fprintf(stderr, "could not load kernel '%s'\n", ipl->kernel); return -1; } - /* we have to overwrite values in the kernel image, which are "rom" */ - strcpy(rom_ptr(KERN_PARM_AREA), ipl->cmdline); - /* - * we can not rely on the ELF entry point, since up to 3.2 this - * value was 0x800 (the SALIPL loader) and it wont work. For - * all (Linux) cases 0x10000 (KERN_IMAGE_START) should be fine. + * Is it a Linux kernel (starting at 0x10000)? If yes, we fill in the + * kernel parameters here as well. Note: For old kernels (up to 3.2) + * we can not rely on the ELF entry point - it was 0x800 (the SALIPL + * loader) and it won't work. For this case we force it to 0x10000, too. */ - ipl->start_addr = KERN_IMAGE_START; + if (pentry == KERN_IMAGE_START || pentry == 0x800) { + ipl->start_addr = KERN_IMAGE_START; + /* Overwrite parameters in the kernel image, which are "rom" */ + strcpy(rom_ptr(KERN_PARM_AREA), ipl->cmdline); + } else { + ipl->start_addr = pentry; + } } if (ipl->initrd) { ram_addr_t initrd_offset; -- cgit v1.2.1