* [Qemu-devel] [PATCH 0/2] s390x/kvm: implement floating interrupt controller
@ 2013-09-06 12:19 Jens Freimann
2013-09-06 12:19 ` [Qemu-devel] [PATCH 1/2] linux-headers: update for s390 " Jens Freimann
2013-09-06 12:19 ` [Qemu-devel] [PATCH 2/2] s390x/kvm: implement floating-interrupt controller device Jens Freimann
0 siblings, 2 replies; 9+ messages in thread
From: Jens Freimann @ 2013-09-06 12:19 UTC (permalink / raw)
To: Christian Borntraeger, Cornelia Huck, Alexander Graf
Cc: Jens Freimann, Thomas Huth, qemu-devel, kvm, Andreas Faerber
This patchset enables the s390 floating interrupt controller kvm_device.
It is used to
* clear all pending floating interrupts in the kernel at device reset
* inject/retrieve interrupts into the kernel (used for migration)
Please note that the linux-headers changes are not yet merged by upstream
Jens Freimann (2):
linux-headers: update for s390 floating interrupt controller
s390x/kvm: implement floating-interrupt controller device
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 +++++++
linux-headers/asm-s390/kvm.h | 5 ++
linux-headers/linux/kvm.h | 65 +++++++++++++++
8 files changed, 276 insertions(+), 1 deletion(-)
create mode 100644 hw/intc/s390_flic.c
create mode 100644 include/hw/s390x/s390_flic.h
--
1.8.3.4
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH 1/2] linux-headers: update for s390 floating interrupt controller
2013-09-06 12:19 [Qemu-devel] [PATCH 0/2] s390x/kvm: implement floating interrupt controller Jens Freimann
@ 2013-09-06 12:19 ` Jens Freimann
2013-09-06 12:23 ` Peter Maydell
` (2 more replies)
2013-09-06 12:19 ` [Qemu-devel] [PATCH 2/2] s390x/kvm: implement floating-interrupt controller device Jens Freimann
1 sibling, 3 replies; 9+ messages in thread
From: Jens Freimann @ 2013-09-06 12:19 UTC (permalink / raw)
To: Christian Borntraeger, Cornelia Huck, Alexander Graf
Cc: Jens Freimann, Thomas Huth, qemu-devel, kvm, Andreas Faerber
Add symbols required for the s390 floating interrupt controller (flic)
Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
---
| 5 ++++
| 65 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+)
--git a/linux-headers/asm-s390/kvm.h b/linux-headers/asm-s390/kvm.h
index d25da59..33d52b8 100644
--- a/linux-headers/asm-s390/kvm.h
+++ b/linux-headers/asm-s390/kvm.h
@@ -16,6 +16,11 @@
#define __KVM_S390
+/* Device control API: s390-specific devices */
+#define KVM_DEV_FLIC_DEQUEUE 1
+#define KVM_DEV_FLIC_ENQUEUE 2
+#define KVM_DEV_FLIC_CLEAR_IRQS 3
+
/* for KVM_GET_REGS and KVM_SET_REGS */
struct kvm_regs {
/* general purpose regs for s390 */
--git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index c614070..1f34381 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -434,6 +434,70 @@ struct kvm_s390_interrupt {
__u64 parm64;
};
+struct kvm_s390_io_info {
+ __u16 subchannel_id;
+ __u16 subchannel_nr;
+ __u32 io_int_parm;
+ __u32 io_int_word;
+};
+
+struct kvm_s390_ext_info {
+ __u32 ext_params;
+ __u32 pad;
+ __u64 ext_params2;
+};
+
+struct kvm_s390_pgm_info {
+ __u64 trans_exc_code;
+ __u64 mon_code;
+ __u64 per_address;
+ __u32 data_exc_code;
+ __u16 code;
+ __u16 mon_class_nr;
+ __u8 per_code;
+ __u8 per_atmid;
+ __u8 exc_access_id;
+ __u8 per_access_id;
+ __u8 op_access_id;
+ __u8 pad[3];
+};
+
+struct kvm_s390_prefix_info {
+ __u32 address;
+};
+
+struct kvm_s390_extcall_info {
+ __u16 code;
+};
+
+struct kvm_s390_emerg_info {
+ __u16 code;
+};
+
+struct kvm_s390_mchk_info {
+ __u64 cr14;
+ __u64 mcic;
+ __u64 failing_storage_address;
+ __u32 ext_damage_code;
+ __u32 pad;
+ __u8 fixed_logout[16];
+};
+
+struct kvm_s390_irq {
+ __u64 type;
+ union {
+ struct kvm_s390_io_info io;
+ struct kvm_s390_ext_info ext;
+ struct kvm_s390_pgm_info pgm;
+ struct kvm_s390_emerg_info emerg;
+ struct kvm_s390_extcall_info extcall;
+ struct kvm_s390_prefix_info prefix;
+ struct kvm_s390_mchk_info mchk;
+ char reserved[64];
+ };
+};
+
+
/* for KVM_SET_GUEST_DEBUG */
#define KVM_GUESTDBG_ENABLE 0x00000001
@@ -839,6 +903,7 @@ struct kvm_device_attr {
#define KVM_DEV_TYPE_FSL_MPIC_20 1
#define KVM_DEV_TYPE_FSL_MPIC_42 2
#define KVM_DEV_TYPE_XICS 3
+#define KVM_DEV_TYPE_FLIC 4
/*
* ioctls for VM fds
--
1.8.3.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH 2/2] s390x/kvm: implement floating-interrupt controller device
2013-09-06 12:19 [Qemu-devel] [PATCH 0/2] s390x/kvm: implement floating interrupt controller Jens Freimann
2013-09-06 12:19 ` [Qemu-devel] [PATCH 1/2] linux-headers: update for s390 " Jens Freimann
@ 2013-09-06 12:19 ` Jens Freimann
2013-09-06 13:24 ` Christian Borntraeger
1 sibling, 1 reply; 9+ messages in thread
From: Jens Freimann @ 2013-09-06 12:19 UTC (permalink / raw)
To: Christian Borntraeger, Cornelia Huck, Alexander Graf
Cc: Jens Freimann, Thomas Huth, qemu-devel, kvm, Andreas Faerber
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 <jfrei@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
---
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 <jfrei@linux.vnet.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 <sys/ioctl.h>
+#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 <jfrei@linux.vnet.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.
+ */
+
+#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 */
--
1.8.3.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 1/2] linux-headers: update for s390 floating interrupt controller
2013-09-06 12:19 ` [Qemu-devel] [PATCH 1/2] linux-headers: update for s390 " Jens Freimann
@ 2013-09-06 12:23 ` Peter Maydell
2013-09-06 12:34 ` Jens Freimann
2013-09-06 12:32 ` Peter Maydell
2013-09-06 13:18 ` Christian Borntraeger
2 siblings, 1 reply; 9+ messages in thread
From: Peter Maydell @ 2013-09-06 12:23 UTC (permalink / raw)
To: Jens Freimann
Cc: Thomas Huth, kvm-devel, QEMU Developers, Alexander Graf,
Christian Borntraeger, Cornelia Huck, Andreas Faerber
On 6 September 2013 13:19, Jens Freimann <jfrei@linux.vnet.ibm.com> wrote:
> Add symbols required for the s390 floating interrupt controller (flic)
Updates to linux-headers should be the result of a sync
against a specified mainline kernel revision, please
(otherwise this should be an RFC patchset).
thanks
-- PMM
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 1/2] linux-headers: update for s390 floating interrupt controller
2013-09-06 12:19 ` [Qemu-devel] [PATCH 1/2] linux-headers: update for s390 " Jens Freimann
2013-09-06 12:23 ` Peter Maydell
@ 2013-09-06 12:32 ` Peter Maydell
2013-09-06 12:41 ` Jens Freimann
2013-09-06 13:18 ` Christian Borntraeger
2 siblings, 1 reply; 9+ messages in thread
From: Peter Maydell @ 2013-09-06 12:32 UTC (permalink / raw)
To: Jens Freimann
Cc: Thomas Huth, kvm-devel, QEMU Developers, Alexander Graf,
Christian Borntraeger, Cornelia Huck, Andreas Faerber,
Christoffer Dall
On 6 September 2013 13:19, Jens Freimann <jfrei@linux.vnet.ibm.com> wrote:
> @@ -839,6 +903,7 @@ struct kvm_device_attr {
> #define KVM_DEV_TYPE_FSL_MPIC_20 1
> #define KVM_DEV_TYPE_FSL_MPIC_42 2
> #define KVM_DEV_TYPE_XICS 3
> +#define KVM_DEV_TYPE_FLIC 4
Christoffer's patchset switching the ARM VGIC to this
list also uses 4 as its enumeration value:
https://lists.cs.columbia.edu/pipermail/kvmarm/2013-August/006822.html
That patchset isn't in yet, but maybe you should use
5 to avoid conflicts?
thanks
-- PMM
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 1/2] linux-headers: update for s390 floating interrupt controller
2013-09-06 12:23 ` Peter Maydell
@ 2013-09-06 12:34 ` Jens Freimann
0 siblings, 0 replies; 9+ messages in thread
From: Jens Freimann @ 2013-09-06 12:34 UTC (permalink / raw)
To: Peter Maydell
Cc: Thomas Huth, kvm-devel, Alexander Graf, QEMU Developers,
Christian Borntraeger, Cornelia Huck, Andreas Faerber
On Fri, Sep 06, 2013 at 01:23:32PM +0100, Peter Maydell wrote:
> On 6 September 2013 13:19, Jens Freimann <jfrei@linux.vnet.ibm.com> wrote:
> > Add symbols required for the s390 floating interrupt controller (flic)
>
> Updates to linux-headers should be the result of a sync
> against a specified mainline kernel revision, please
> (otherwise this should be an RFC patchset).
ok, I understand. I was not sure about that and only added a remark in
the cover letter
regards
Jens
> thanks
> -- PMM
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 1/2] linux-headers: update for s390 floating interrupt controller
2013-09-06 12:32 ` Peter Maydell
@ 2013-09-06 12:41 ` Jens Freimann
0 siblings, 0 replies; 9+ messages in thread
From: Jens Freimann @ 2013-09-06 12:41 UTC (permalink / raw)
To: Peter Maydell
Cc: Thomas Huth, kvm-devel, Alexander Graf, QEMU Developers,
Christian Borntraeger, Cornelia Huck, Andreas Faerber,
Christoffer Dall
On Fri, Sep 06, 2013 at 01:32:52PM +0100, Peter Maydell wrote:
> On 6 September 2013 13:19, Jens Freimann <jfrei@linux.vnet.ibm.com> wrote:
> > @@ -839,6 +903,7 @@ struct kvm_device_attr {
> > #define KVM_DEV_TYPE_FSL_MPIC_20 1
> > #define KVM_DEV_TYPE_FSL_MPIC_42 2
> > #define KVM_DEV_TYPE_XICS 3
> > +#define KVM_DEV_TYPE_FLIC 4
>
> Christoffer's patchset switching the ARM VGIC to this
> list also uses 4 as its enumeration value:
>
> https://lists.cs.columbia.edu/pipermail/kvmarm/2013-August/006822.html
>
> That patchset isn't in yet, but maybe you should use
> 5 to avoid conflicts?
sure, will do
regards
Jens
>
> thanks
> -- PMM
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 1/2] linux-headers: update for s390 floating interrupt controller
2013-09-06 12:19 ` [Qemu-devel] [PATCH 1/2] linux-headers: update for s390 " Jens Freimann
2013-09-06 12:23 ` Peter Maydell
2013-09-06 12:32 ` Peter Maydell
@ 2013-09-06 13:18 ` Christian Borntraeger
2 siblings, 0 replies; 9+ messages in thread
From: Christian Borntraeger @ 2013-09-06 13:18 UTC (permalink / raw)
To: Jens Freimann
Cc: Peter Maydell, Thomas Huth, kvm, Alexander Graf, qemu-devel,
Cornelia Huck, Andreas Faerber
On 06/09/13 14:19, Jens Freimann wrote:
> Add symbols required for the s390 floating interrupt controller (flic)
>
> Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
As Peter said, this should come via a sync, but you already mentioned that
in your cover-letter. I will Ack the kernel patch and let it come via
that way.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 2/2] s390x/kvm: implement floating-interrupt controller device
2013-09-06 12:19 ` [Qemu-devel] [PATCH 2/2] s390x/kvm: implement floating-interrupt controller device Jens Freimann
@ 2013-09-06 13:24 ` Christian Borntraeger
0 siblings, 0 replies; 9+ messages in thread
From: Christian Borntraeger @ 2013-09-06 13:24 UTC (permalink / raw)
To: Jens Freimann
Cc: Thomas Huth, kvm, Alexander Graf, qemu-devel, Cornelia Huck,
Andreas Faerber
On 06/09/13 14:19, Jens Freimann wrote:
> 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 <jfrei@linux.vnet.ibm.com>
> Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
>
> ---
> 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 <jfrei@linux.vnet.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 <sys/ioctl.h>
> +#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 <jfrei@linux.vnet.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.
> + */
> +
> +#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 */
>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-09-09 7:27 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-06 12:19 [Qemu-devel] [PATCH 0/2] s390x/kvm: implement floating interrupt controller Jens Freimann
2013-09-06 12:19 ` [Qemu-devel] [PATCH 1/2] linux-headers: update for s390 " Jens Freimann
2013-09-06 12:23 ` Peter Maydell
2013-09-06 12:34 ` Jens Freimann
2013-09-06 12:32 ` Peter Maydell
2013-09-06 12:41 ` Jens Freimann
2013-09-06 13:18 ` Christian Borntraeger
2013-09-06 12:19 ` [Qemu-devel] [PATCH 2/2] s390x/kvm: implement floating-interrupt controller device Jens Freimann
2013-09-06 13:24 ` Christian Borntraeger
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).