From patchwork Fri Sep 6 12:19:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Freimann X-Patchwork-Id: 273171 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B42D22C00B9 for ; Fri, 6 Sep 2013 22:20:43 +1000 (EST) Received: from localhost ([::1]:37210 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHv1l-0004wI-NG for incoming@patchwork.ozlabs.org; Fri, 06 Sep 2013 08:20:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHv0z-0004WK-3l for qemu-devel@nongnu.org; Fri, 06 Sep 2013 08:20:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHv0o-00033b-Dw for qemu-devel@nongnu.org; Fri, 06 Sep 2013 08:19:52 -0400 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:49134) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHv0o-00033I-2i for qemu-devel@nongnu.org; Fri, 06 Sep 2013 08:19:42 -0400 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 6 Sep 2013 13:13:06 +0100 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 6 Sep 2013 13:13:03 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 6EE5817D8057 for ; Fri, 6 Sep 2013 13:19:42 +0100 (BST) Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by b06cxnps4076.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r86CJQ5T58327206 for ; Fri, 6 Sep 2013 12:19:26 GMT Received: from d06av09.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r86CJbX8025874 for ; Fri, 6 Sep 2013 06:19:37 -0600 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id r86CJbfN025869; Fri, 6 Sep 2013 06:19:37 -0600 Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 1122) id 223AA1224437; Fri, 6 Sep 2013 14:19:37 +0200 (CEST) From: Jens Freimann To: Christian Borntraeger , Cornelia Huck , Alexander Graf Date: Fri, 6 Sep 2013 14:19:30 +0200 Message-Id: <1378469970-62769-3-git-send-email-jfrei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1378469970-62769-1-git-send-email-jfrei@linux.vnet.ibm.com> References: <1378469970-62769-1-git-send-email-jfrei@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13090612-8372-0000-0000-00000719802B X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 195.75.94.108 Cc: Jens Freimann , Thomas Huth , qemu-devel@nongnu.org, kvm@vger.kernel.org, Andreas Faerber Subject: [Qemu-devel] [PATCH 2/2] s390x/kvm: implement floating-interrupt controller device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch implements a floating-interrupt controller device (flic) which interacts with the s390 flic kvm_device. It provides functionality to: * clear all pending floating interrupts in the kernel at device reset * inject/retrieve interrupts into the kernel (used for migration) Signed-off-by: Jens Freimann Reviewed-by: Thomas Huth Acked-by: Christian Borntraeger --- default-configs/s390x-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/s390_flic.c | 164 ++++++++++++++++++++++++++++++++++++++ hw/s390x/s390-virtio-ccw.c | 8 +- hw/s390x/s390-virtio.c | 2 + include/hw/s390x/s390_flic.h | 31 +++++++ 6 files changed, 206 insertions(+), 1 deletion(-) diff --git a/default-configs/s390x-softmmu.mak b/default-configs/s390x-softmmu.mak index 81fbc68..d843dc0 100644 --- a/default-configs/s390x-softmmu.mak +++ b/default-configs/s390x-softmmu.mak @@ -1,2 +1,3 @@ CONFIG_VIRTIO=y CONFIG_SCLPCONSOLE=y +CONFIG_S390_FLIC=$(CONFIG_KVM) diff --git a/hw/intc/Makefile.objs b/hw/intc/Makefile.objs index 2851eed..b2305aa 100644 --- a/hw/intc/Makefile.objs +++ b/hw/intc/Makefile.objs @@ -23,3 +23,4 @@ obj-$(CONFIG_OMAP) += omap_intc.o obj-$(CONFIG_OPENPIC_KVM) += openpic_kvm.o obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.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 0000000..9dfaafa --- /dev/null +++ b/hw/intc/s390_flic.c @@ -0,0 +1,164 @@ +/* + * QEMU S390x KVM floating interrupt controller (flic) + * + * Copyright 2013 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 "hw/sysbus.h" +#include "sysemu/kvm.h" +#include "migration/qemu-file.h" +#include "hw/s390x/s390_flic.h" + +void s390_flic_init(void) +{ + DeviceState *dev; + + if (kvm_enabled()) { + dev = qdev_create(NULL, "s390-flic"); + object_property_add_child(qdev_get_machine(), "s390-flic", + OBJECT(dev), NULL); + qdev_init_nofail(dev); + } +} + +static int flic_dequeue_irq(QEMUFile *f, struct kvm_s390_irq *s390irq, + KVMS390FLICState *flic) +{ + struct kvm_device_attr attr; + int rc; + + attr.group = KVM_DEV_FLIC_DEQUEUE; + attr.addr = (uint64_t) s390irq; + + rc = ioctl(flic->fd, KVM_GET_DEVICE_ATTR, &attr); + + return rc ? -errno : 0; +} + +static int flic_enqueue_irq(QEMUFile *f, struct kvm_s390_irq *s390irq, + KVMS390FLICState *flic) +{ + int rc; + struct kvm_device_attr attr; + + attr.group = KVM_DEV_FLIC_ENQUEUE; + attr.addr = (uint64_t) s390irq; + + rc = ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); + + return rc ? -errno : 0; +} + +/* Save pending floating interrupts. */ +static void kvm_floating_interrupt_save(QEMUFile *f, void *opaque) +{ + struct kvm_s390_irq s390irq = {0}; + int r = 0; + + while (!r) { + r = flic_dequeue_irq(f, &s390irq, opaque); + if (r == -ENODATA) { + /* At end of list: write special marker */ + memset(&s390irq, 0, sizeof(s390irq)); + s390irq.type = 0xffffffff; + } + qemu_put_buffer(f, (uint8_t *) &s390irq, sizeof(s390irq)); + } +} + +/* Load pending floating interrupts. */ +static int kvm_floating_interrupt_load(QEMUFile *f, void *opaque, int version_id) +{ + int r = 0; + struct kvm_s390_irq s390irq = {0}; + + while (!r) { + qemu_get_buffer(f, (uint8_t *) &s390irq, sizeof(s390irq)); + /* Watch for marker indicating end of list */ + if (s390irq.type == 0xffffffff) { + return 0; + } + r = flic_enqueue_irq(f, &s390irq, (struct KVMS390FLICState *) opaque); + } + + 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)) { + return; + } + + cd.type = KVM_DEV_TYPE_FLIC; + ret = kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &cd); + if (ret < 0) { + perror("flic: couldn't create kvm_device"); + return; + } + flic_state->fd = cd.fd; + + /* Register savevm handler for floating interrupts */ + register_savevm(NULL, "floatingint", 0, 1, kvm_floating_interrupt_save, + kvm_floating_interrupt_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), "floatingint", flic_state); +} + +static void kvm_s390_flic_reset(DeviceState *dev) +{ + KVMS390FLICState *flic = KVM_S390_FLIC(dev); + struct kvm_device_attr attr; + int rc = 0; + + if (flic->fd == -1) { + return; + } + + attr.group = KVM_DEV_FLIC_CLEAR_IRQS; + + rc = ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); + if (rc) { + perror("flic: reset failed"); + } +} + +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; + dc->no_user = 1; +} + +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 733d988..0d4f6ae 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 7adf92a..5b54af7 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(); diff --git a/include/hw/s390x/s390_flic.h b/include/hw/s390x/s390_flic.h new file mode 100644 index 0000000..2b83f35 --- /dev/null +++ b/include/hw/s390x/s390_flic.h @@ -0,0 +1,31 @@ +/* + * QEMU S390x KVM floating interrupt controller (flic) + * + * Copyright 2013 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. + */ + +#ifndef __KVM_S390_FLIC_H +#define __KVM_S390_FLIC_H + +#define TYPE_KVM_S390_FLIC "s390-flic" +#define KVM_S390_FLIC(obj) \ + OBJECT_CHECK(KVMS390FLICState, (obj), TYPE_KVM_S390_FLIC) + +typedef struct KVMS390FLICState { + DeviceState parent_obj; + + uint32_t fd; +} KVMS390FLICState; + +#ifdef CONFIG_KVM +void s390_flic_init(void); +#else +static inline void s390_flic_init(void) { } +#endif + +#endif /* __KVM_S390_FLIC_H */