Skip to contentSkip to conversation

KVM: s390: add floating irq controller

RFC In review Jens Freimann 2 participants 4 messages Jul 26, 2013 – Jul 29, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover KVM: s390: add floating irq controller

This series adds a kvm_device that acts as a irq controller for floating interrupts. As a first step it implements functionality to retrieve and inject interrupts for the purpose of migration and for hardening the reset code by allowing user space to explicitly remove all pending floating interrupts.

PFAULT patches will also use this device for enabling/disabling pfault, therefore the pfault patch series will be reworked to use this device depending on review feedback

* Patch 1 adds a new data structure to hold interrupt information. The current one (struct kvm_s390_interrupt) does not allow to inject all kinds of interrupts, e.g. some data for program interrupts and machine check interruptions were missing.

* Patch 2 adds a kvm_device which supports getting/setting currently pending floating interrupts as well as deleting all currently pending interrupts

Jens Freimann (2):
s390/kvm: add and extend interrupt information data structs s390/kvm: add floating irq controller

 arch/s390/include/asm/kvm_host.h |  45 +----
 arch/s390/include/uapi/asm/kvm.h |   5 +
 arch/s390/kvm/interrupt.c        | 365 +++++++++++++++++++++++++--------------
 arch/s390/kvm/kvm-s390.c         |   1 +
 arch/s390/kvm/priv.c             |  22 +--
 arch/s390/kvm/sigp.c             |  14 +-
 include/linux/kvm_host.h         |   1 +
 include/uapi/linux/kvm.h         |  63 +++++++
 virt/kvm/kvm_main.c              |   3 +
 9 files changed, 330 insertions(+), 189 deletions(-)
Signature · 1 line
1.8.0.1
#1 lore raw

RFC 1/2 KVM: s390: add and extend interrupt information data structs

With the currently available struct kvm_s390_interrupt it is not possible to inject all kinds of interrupts as defined in the z/Architecture. Add interruption parameters to the structures to make sure we can inject all kinds of interrupts and move it to kvm.h

---
 arch/s390/include/asm/kvm_host.h |  45 +---------
 arch/s390/kvm/interrupt.c        | 189 +++++++++++++++++++--------------------
 arch/s390/kvm/priv.c             |  22 ++---
 arch/s390/kvm/sigp.c             |  14 +--
 include/uapi/linux/kvm.h         |  62 +++++++++++++
 5 files changed, 175 insertions(+), 157 deletions(-)
arch/s390/include/asm/kvm_host.h +2 -43
index 3238d40..c755a9d 100644
@@ -16,6 +16,7 @@
 #include <linux/hrtimer.h>
 #include <linux/interrupt.h>
 #include <linux/kvm_host.h>
+#include <linux/kvm.h>
 #include <asm/debug.h>
 #include <asm/cpu.h>
 
@@ -162,18 +163,6 @@ struct kvm_vcpu_stat {
 	u32 diagnose_9c;
 };
 
-struct kvm_s390_io_info {
-	__u16        subchannel_id;            /* 0x0b8 */
-	__u16        subchannel_nr;            /* 0x0ba */
-	__u32        io_int_parm;              /* 0x0bc */
-	__u32        io_int_word;              /* 0x0c0 */
-};
-
-struct kvm_s390_ext_info {
-	__u32 ext_params;
-	__u64 ext_params2;
-};
-
 #define PGM_OPERATION            0x01
 #define PGM_PRIVILEGED_OP	 0x02
 #define PGM_EXECUTE              0x03
@@ -182,39 +171,9 @@ struct kvm_s390_ext_info {
 #define PGM_SPECIFICATION        0x06
 #define PGM_DATA                 0x07
 
-struct kvm_s390_pgm_info {
-	__u16 code;
-};
-
-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;
-};
-
 struct kvm_s390_interrupt_info {
 	struct list_head list;
-	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;
-	};
+	struct kvm_s390_irq irq;
 };
 
 /* for local_interrupt.action_flags */
arch/s390/kvm/interrupt.c +93 -96

422 lines not on this page · raw message

arch/s390/kvm/priv.c +11 -11
index 0da3e6e..897fff2 100644
@@ -146,19 +146,19 @@ static int handle_tpi(struct kvm_vcpu *vcpu)
 		 * Store the two-word I/O interruption code into the
 		 * provided area.
 		 */
-		if (put_guest(vcpu, inti->io.subchannel_id, (u16 __user *)addr)
-		    || put_guest(vcpu, inti->io.subchannel_nr, (u16 __user *)(addr + 2))
-		    || put_guest(vcpu, inti->io.io_int_parm, (u32 __user *)(addr + 4)))
+		if (put_guest(vcpu, inti->irq.io.subchannel_id, (u16 __user *)addr)
+		    || put_guest(vcpu, inti->irq.io.subchannel_nr, (u16 __user *)(addr + 2))
+		    || put_guest(vcpu, inti->irq.io.io_int_parm, (u32 __user *)(addr + 4)))
 			return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
 	} else {
 		/*
 		 * Store the three-word I/O interruption code into
 		 * the appropriate lowcore area.
 		 */
-		put_guest(vcpu, inti->io.subchannel_id, (u16 __user *) __LC_SUBCHANNEL_ID);
-		put_guest(vcpu, inti->io.subchannel_nr, (u16 __user *) __LC_SUBCHANNEL_NR);
-		put_guest(vcpu, inti->io.io_int_parm, (u32 __user *) __LC_IO_INT_PARM);
-		put_guest(vcpu, inti->io.io_int_word, (u32 __user *) __LC_IO_INT_WORD);
+		put_guest(vcpu, inti->irq.io.subchannel_id, (u16 __user *) __LC_SUBCHANNEL_ID);
+		put_guest(vcpu, inti->irq.io.subchannel_nr, (u16 __user *) __LC_SUBCHANNEL_NR);
+		put_guest(vcpu, inti->irq.io.io_int_parm, (u32 __user *) __LC_IO_INT_PARM);
+		put_guest(vcpu, inti->irq.io.io_int_word, (u32 __user *) __LC_IO_INT_WORD);
 	}
 	kfree(inti);
 no_interrupt:
@@ -186,10 +186,10 @@ static int handle_tsch(struct kvm_vcpu *vcpu)
 	vcpu->run->exit_reason = KVM_EXIT_S390_TSCH;
 	vcpu->run->s390_tsch.dequeued = !!inti;
 	if (inti) {
-		vcpu->run->s390_tsch.subchannel_id = inti->io.subchannel_id;
-		vcpu->run->s390_tsch.subchannel_nr = inti->io.subchannel_nr;
-		vcpu->run->s390_tsch.io_int_parm = inti->io.io_int_parm;
-		vcpu->run->s390_tsch.io_int_word = inti->io.io_int_word;
+		vcpu->run->s390_tsch.subchannel_id = inti->irq.io.subchannel_id;
+		vcpu->run->s390_tsch.subchannel_nr = inti->irq.io.subchannel_nr;
+		vcpu->run->s390_tsch.io_int_parm = inti->irq.io.io_int_parm;
+		vcpu->run->s390_tsch.io_int_word = inti->irq.io.io_int_word;
 	}
 	vcpu->run->s390_tsch.ipb = vcpu->arch.sie_block->ipb;
 	kfree(inti);
arch/s390/kvm/sigp.c +7 -7
index bec398c..a8cd912 100644
@@ -65,8 +65,8 @@ static int __sigp_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr)
 	if (!inti)
 		return -ENOMEM;
 
-	inti->type = KVM_S390_INT_EMERGENCY;
-	inti->emerg.code = vcpu->vcpu_id;
+	inti->irq.type = KVM_S390_INT_EMERGENCY;
+	inti->irq.emerg.code = vcpu->vcpu_id;
 
 	spin_lock(&fi->lock);
 	li = fi->local_int[cpu_addr];
@@ -103,8 +103,8 @@ static int __sigp_external_call(struct kvm_vcpu *vcpu, u16 cpu_addr)
 	if (!inti)
 		return -ENOMEM;
 
-	inti->type = KVM_S390_INT_EXTERNAL_CALL;
-	inti->extcall.code = vcpu->vcpu_id;
+	inti->irq.type = KVM_S390_INT_EXTERNAL_CALL;
+	inti->irq.extcall.code = vcpu->vcpu_id;
 
 	spin_lock(&fi->lock);
 	li = fi->local_int[cpu_addr];
@@ -134,7 +134,7 @@ static int __inject_sigp_stop(struct kvm_s390_local_interrupt *li, int action)
 	inti = kzalloc(sizeof(*inti), GFP_ATOMIC);
 	if (!inti)
 		return -ENOMEM;
-	inti->type = KVM_S390_SIGP_STOP;
+	inti->irq.type = KVM_S390_SIGP_STOP;
 
 	spin_lock_bh(&li->lock);
 	if ((atomic_read(li->cpuflags) & CPUSTAT_STOPPED)) {
@@ -245,8 +245,8 @@ static int __sigp_set_prefix(struct kvm_vcpu *vcpu, u16 cpu_addr, u32 address,
 		goto out_li;
 	}
 
-	inti->type = KVM_S390_SIGP_SET_PREFIX;
-	inti->prefix.address = address;
+	inti->irq.type = KVM_S390_SIGP_SET_PREFIX;
+	inti->irq.prefix.address = address;
 
 	list_add_tail(&inti->list, &li->list);
 	atomic_set(&li->active, 1);
include/uapi/linux/kvm.h +62 -0

68 lines not on this page · raw message

Signature · 1 line
1.8.0.1
#2 lore raw

RFC 2/2 KVM: s390: add floating irq controller

In reply to Jens Freimann

This patch adds a floating irq controller as a kvm_device. It will be necesary for migration of floating interrupts as well as for hardening the reset code by allowing user space to explicitly remove all pending floating interrupts.

---
 arch/s390/include/uapi/asm/kvm.h |   5 +
 arch/s390/kvm/interrupt.c        | 192 +++++++++++++++++++++++++++++++--------
 arch/s390/kvm/kvm-s390.c         |   1 +
 include/linux/kvm_host.h         |   1 +
 include/uapi/linux/kvm.h         |   1 +
 virt/kvm/kvm_main.c              |   3 +
 6 files changed, 163 insertions(+), 40 deletions(-)
arch/s390/include/uapi/asm/kvm.h +5 -0
index d25da59..33d52b8 100644
@@ -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 */
arch/s390/kvm/interrupt.c +152 -40

212 lines not on this page · raw message

arch/s390/kvm/kvm-s390.c +1 -0
index ba694d2..b85a3f0 100644
@@ -150,6 +150,7 @@ int kvm_dev_ioctl_check_extension(long ext)
 	case KVM_CAP_ENABLE_CAP:
 	case KVM_CAP_S390_CSS_SUPPORT:
 	case KVM_CAP_IOEVENTFD:
+	case KVM_CAP_DEVICE_CTRL:
 		r = 1;
 		break;
 	case KVM_CAP_NR_VCPUS:
include/linux/kvm_host.h +1 -0
index a63d83e..fa517dd 100644
@@ -1052,6 +1052,7 @@ struct kvm_device *kvm_device_from_filp(struct file *filp);
 
 extern struct kvm_device_ops kvm_mpic_ops;
 extern struct kvm_device_ops kvm_xics_ops;
+extern struct kvm_device_ops kvm_flic_ops;
 
 #ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT
 
include/uapi/linux/kvm.h +1 -0
index d6a1584..c5aa7ce 100644
@@ -904,6 +904,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
virt/kvm/kvm_main.c +3 -0
index 1580dd4..cb017eb 100644
@@ -2282,6 +2282,9 @@ static int kvm_ioctl_create_device(struct kvm *kvm,
 		ops = &kvm_xics_ops;
 		break;
 #endif
+	case KVM_DEV_TYPE_FLIC:
+		ops = &kvm_flic_ops;
+		break;
 	default:
 		return -ENODEV;
 	}
Signature · 1 line
1.8.0.1
#3 lore raw
Quoted 6 lines · Jens Freimann

This patch adds a floating irq controller as a kvm_device. It will be necesary for migration of floating interrupts as well as for hardening the reset code by allowing user space to explicitly remove all pending floating interrupts.

[...]

Quoted 5 lines
arch/s390/kvm/interrupt.c +5 -0
+static void clear_floating_interrupts(struct kvm *kvm)
+{
+	struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int;
+	struct kvm_s390_interrupt_info  *n, *inti = NULL;
+

arch/s390/kvm/interrupt.c int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu, · line 860

Quoted 10 lines
arch/s390/kvm/interrupt.c +10 -0
+	if (atomic_read(&fi->active)) {
+		spin_lock_bh(&fi->lock);
+		list_for_each_entry_safe(inti, n, &fi->list, list) {
+			list_del(&inti->list);
+			kfree(inti);
+		}
+		atomic_set(&fi->active, 0);
+		spin_unlock_bh(&fi->lock);
+	}
+}

FWIW, unrelated to your patch, since it used to be always like this:
the sematics of fi->active atomic_t seem to be a bit odd. It only gets set while the fi->lock spinlock is held and might be read also while not holding the spinlock.
Either it's racy, the spinlock is not needed at all, or it should be held everytime.
Besides that the meaning of the "active" value seems to be the same as !list_empty()... so you could get rid of it.
Just a comment ;)

Quoted 7 lines
arch/s390/kvm/interrupt.c +7 -0
+static int flic_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
+{
+	int r;
+
+	switch (attr->group) {
+	case KVM_DEV_FLIC_ENQUEUE: {
+		struct kvm_s390_irq *s390irq;

arch/s390/kvm/interrupt.c int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu, · line 919

Quoted 10 lines
arch/s390/kvm/interrupt.c +10 -0
+		struct kvm_s390_interrupt_info *inti;
+		inti = kzalloc(sizeof(*inti), GFP_KERNEL);
+		if (!inti)
+			return -ENOMEM;
+		s390irq = kzalloc(sizeof(*s390irq), GFP_KERNEL);
+		if (!s390irq)
+			return -ENOMEM;
+		if (copy_from_user(s390irq, (u64 __user *)attr->addr,
+				  sizeof(s390irq)))
+			return -EFAULT;

User space triggerable memory leak.

arch/s390/kvm/interrupt.c int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu, · line 921

Quoted 2 lines
arch/s390/kvm/interrupt.c +2 -0
+		inti->irq = *s390irq;
+		__inject_vm(dev->kvm, inti);

I think you must check the irq type, otherwise the kernel may crash if it tries to deliver the interrupt and it doesn't match any of the known irqs. (or remove the BUG() in the deliver function, or both ;)