Skip to contentSkip to conversation

KVM: s390: patches for kvm-next

GIT PULL Cornelia Huck 1 participant 7 messages Dec 11, 2013

Subsystems (5)
Stable branch Documentation KVM s390 +1 more subsystems
lore
Share & tools
lore
#0 lore raw

Gleb, Paolo,

here are some more fixes and improvements that have been sitting in our tree. Please consider pulling.

The following changes since commit d6d63b51fe3bfea0cf596993afa480b0b3b02c32:

Merge tag 'kvm-s390-20131128' of git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into kvm-next (2013-11-28 15:30:16 +0100)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-20131211

for you to fetch changes up to ff1f3cb4b3ac5d039f02679f34cb1498d110d241:

KVM: s390: ioeventfd: ignore leftmost bits (2013-12-11 19:05:41 +0100)

----------------------------------------------------------------
Some further s390 patches for kvm-next.

Various improvements and bugfixes in the signal processor handling. Document kvm support for diagnose (s390 hypercalls). And last but not least, fix a bug in the s390 ioeventfd backend that was causing us grief in scenarios with 4G+ memory.

----------------------------------------------------------------
Cornelia Huck (1):
KVM: s390: diagnose call documentation

Dominik Dingel (1):
KVM: s390: ioeventfd: ignore leftmost bits

Thomas Huth (4):
KVM: s390: Use helper function to set CC in SIGP handler
KVM: s390: Add the SIGP order CONDITIONAL EMERGENCY SIGNAL
KVM: s390: Reworked SIGP RESTART order
KVM: s390: SIGP START has to report BUSY while stopping a CPU

 Documentation/virtual/kvm/hypercalls.txt |    3 ++
 Documentation/virtual/kvm/s390-diag.txt  |   80 ++++++++++++++++++++++++++++++
 arch/s390/include/asm/sigp.h             |    2 +
 arch/s390/kvm/diag.c                     |    2 +-
 arch/s390/kvm/sigp.c                     |   64 ++++++++++++++++++++----
 5 files changed, 139 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/virtual/kvm/s390-diag.txt
Signature · 1 line
1.7.9.5
#1 lore raw

[PULL 1/6] KVM: s390: diagnose call documentation

Add some further documentation on the DIAGNOSE calls we support.

---
 Documentation/virtual/kvm/hypercalls.txt |    3 ++
 Documentation/virtual/kvm/s390-diag.txt  |   80 ++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+)
 create mode 100644 Documentation/virtual/kvm/s390-diag.txt
Documentation/virtual/kvm/hypercalls.txt +3 -0
index 022198e..d922d73 100644
@@ -17,6 +17,9 @@ S390:
   S390 uses diagnose instruction as hypercall (0x500) along with hypercall
   number in R1.
 
+  For further information on the S390 diagnose call as supported by KVM,
+  refer to Documentation/virtual/kvm/s390-diag.txt.
+
  PowerPC:
   It uses R3-R10 and hypercall number in R11. R4-R11 are used as output registers.
   Return value is placed in R3.
Documentation/virtual/kvm/s390-diag.txt new file +80 -0

80 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

[PULL 2/6] KVM: s390: Use helper function to set CC in SIGP handler

In reply to Cornelia Huck

From: Thomas Huth <[email protected]>

We've got a helper function for setting the condition code now, so let's use it in the SIGP handler, too.

---
 arch/s390/kvm/sigp.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/s390/kvm/sigp.c +1 -2
index c370058..bc0d85a 100644
@@ -435,7 +435,6 @@ int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu)
 	if (rc < 0)
 		return rc;
 
-	vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
-	vcpu->arch.sie_block->gpsw.mask |= (rc & 3ul) << 44;
+	kvm_s390_set_psw_cc(vcpu, rc);
 	return 0;
 }
Signature · 1 line
1.7.9.5
#3 lore raw

[PULL 3/6] KVM: s390: Add the SIGP order CONDITIONAL EMERGENCY SIGNAL

In reply to Cornelia Huck

From: Thomas Huth <[email protected]>

This patch adds the missing SIGP order "conditional emergency signal" by calling the "emergency signal" SIGP handler if the required conditions are met.

---
 arch/s390/include/asm/sigp.h |    1 +
 arch/s390/kvm/sigp.c         |   37 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletion(-)
arch/s390/include/asm/sigp.h +1 -0
index 5a87d16..c002cd5 100644
@@ -12,6 +12,7 @@
 #define SIGP_SET_PREFIX		     13
 #define SIGP_STORE_STATUS_AT_ADDRESS 14
 #define SIGP_SET_ARCHITECTURE	     18
+#define SIGP_COND_EMERGENCY_SIGNAL   19
 #define SIGP_SENSE_RUNNING	     21
 
 /* SIGP condition codes */
arch/s390/kvm/sigp.c +36 -1
index bc0d85a..eee1402 100644
@@ -1,7 +1,7 @@
 /*
  * handling interprocessor communication
  *
- * Copyright IBM Corp. 2008, 2009
+ * Copyright IBM Corp. 2008, 2013
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License (version 2 only)
@@ -89,6 +89,37 @@ unlock:
 	return rc;
 }
 
+static int __sigp_conditional_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr,
+					u16 asn, u64 *reg)
+{
+	struct kvm_vcpu *dst_vcpu = NULL;
+	const u64 psw_int_mask = PSW_MASK_IO | PSW_MASK_EXT;
+	u16 p_asn, s_asn;
+	psw_t *psw;
+	u32 flags;
+
+	if (cpu_addr < KVM_MAX_VCPUS)
+		dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
+	if (!dst_vcpu)
+		return SIGP_CC_NOT_OPERATIONAL;
+	flags = atomic_read(&dst_vcpu->arch.sie_block->cpuflags);
+	psw = &dst_vcpu->arch.sie_block->gpsw;
+	p_asn = dst_vcpu->arch.sie_block->gcr[4] & 0xffff;  /* Primary ASN */
+	s_asn = dst_vcpu->arch.sie_block->gcr[3] & 0xffff;  /* Secondary ASN */
+
+	/* Deliver the emergency signal? */
+	if (!(flags & CPUSTAT_STOPPED)
+	    || (psw->mask & psw_int_mask) != psw_int_mask
+	    || ((flags & CPUSTAT_WAIT) && psw->addr != 0)
+	    || (!(flags & CPUSTAT_WAIT) && (asn == p_asn || asn == s_asn))) {
+		return __sigp_emergency(vcpu, cpu_addr);
+	} else {
+		*reg &= 0xffffffff00000000UL;
+		*reg |= SIGP_STATUS_INCORRECT_STATE;
+		return SIGP_CC_STATUS_STORED;
+	}
+}
+
 static int __sigp_external_call(struct kvm_vcpu *vcpu, u16 cpu_addr)
 {
 	struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;
@@ -417,6 +448,10 @@ int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu)
 		rc = __sigp_set_prefix(vcpu, cpu_addr, parameter,
 				       &vcpu->run->s.regs.gprs[r1]);
 		break;
+	case SIGP_COND_EMERGENCY_SIGNAL:
+		rc = __sigp_conditional_emergency(vcpu, cpu_addr, parameter,
+						  &vcpu->run->s.regs.gprs[r1]);
+		break;
 	case SIGP_SENSE_RUNNING:
 		vcpu->stat.instruction_sigp_sense_running++;
 		rc = __sigp_sense_running(vcpu, cpu_addr,
Signature · 1 line
1.7.9.5
#4 lore raw

[PULL 4/6] KVM: s390: Reworked SIGP RESTART order

In reply to Cornelia Huck

From: Thomas Huth <[email protected]>

When SIGP RESTART detected an illegal CPU address, there is no need to drop to userspace, we can return CC3 to the guest directly instead. Also renamed __sigp_restart() to sigp_check_callable() (since this is a better description of what the function is really doing) and moved a string specific to RESTART to the calling place instead, so that this function gets usable by other SIGP orders, too.

---
 arch/s390/kvm/sigp.c |   19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
arch/s390/kvm/sigp.c +11 -8
index eee1402..509547d 100644
@@ -363,7 +363,8 @@ static int __sigp_sense_running(struct kvm_vcpu *vcpu, u16 cpu_addr,
 	return rc;
 }
 
-static int __sigp_restart(struct kvm_vcpu *vcpu, u16 cpu_addr)
+/* Test whether the destination CPU is available and not busy */
+static int sigp_check_callable(struct kvm_vcpu *vcpu, u16 cpu_addr)
 {
 	struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;
 	struct kvm_s390_local_interrupt *li;
@@ -382,9 +383,6 @@ static int __sigp_restart(struct kvm_vcpu *vcpu, u16 cpu_addr)
 	spin_lock_bh(&li->lock);
 	if (li->action_bits & ACTION_STOP_ON_STOP)
 		rc = SIGP_CC_BUSY;
-	else
-		VCPU_EVENT(vcpu, 4, "sigp restart %x to handle userspace",
-			cpu_addr);
 	spin_unlock_bh(&li->lock);
 out:
 	spin_unlock(&fi->lock);
@@ -459,10 +457,15 @@ int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu)
 		break;
 	case SIGP_RESTART:
 		vcpu->stat.instruction_sigp_restart++;
-		rc = __sigp_restart(vcpu, cpu_addr);
-		if (rc == SIGP_CC_BUSY)
-			break;
-		/* user space must know about restart */
+		rc = sigp_check_callable(vcpu, cpu_addr);
+		if (rc == SIGP_CC_ORDER_CODE_ACCEPTED) {
+			VCPU_EVENT(vcpu, 4,
+				   "sigp restart %x to handle userspace",
+				   cpu_addr);
+			/* user space must know about restart */
+			rc = -EOPNOTSUPP;
+		}
+		break;
 	default:
 		return -EOPNOTSUPP;
 	}
Signature · 1 line
1.7.9.5
#5 lore raw

[PULL 5/6] KVM: s390: SIGP START has to report BUSY while stopping a CPU

In reply to Cornelia Huck

From: Thomas Huth <[email protected]>

Just like the RESTART order, the START order also has to report BUSY while a STOP request is pending, to avoid that the START might be ignored due to a race condition between the STOP and the START order.

---
 arch/s390/include/asm/sigp.h |    1 +
 arch/s390/kvm/sigp.c         |    5 +++++
 2 files changed, 6 insertions(+)
arch/s390/include/asm/sigp.h +1 -0
index c002cd5..d091aa1 100644
@@ -5,6 +5,7 @@
 #define SIGP_SENSE		      1
 #define SIGP_EXTERNAL_CALL	      2
 #define SIGP_EMERGENCY_SIGNAL	      3
+#define SIGP_START		      4
 #define SIGP_STOP		      5
 #define SIGP_RESTART		      6
 #define SIGP_STOP_AND_STORE_STATUS    9
arch/s390/kvm/sigp.c +5 -0
index 509547d..87c2b3a 100644
@@ -455,6 +455,11 @@ int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu)
 		rc = __sigp_sense_running(vcpu, cpu_addr,
 					  &vcpu->run->s.regs.gprs[r1]);
 		break;
+	case SIGP_START:
+		rc = sigp_check_callable(vcpu, cpu_addr);
+		if (rc == SIGP_CC_ORDER_CODE_ACCEPTED)
+			rc = -EOPNOTSUPP;    /* Handle START in user space */
+		break;
 	case SIGP_RESTART:
 		vcpu->stat.instruction_sigp_restart++;
 		rc = sigp_check_callable(vcpu, cpu_addr);
Signature · 1 line
1.7.9.5
#6 lore raw

[PULL 6/6] KVM: s390: ioeventfd: ignore leftmost bits

In reply to Cornelia Huck

From: Dominik Dingel <[email protected]>

The diagnose 500 subcode 3 contains the 32 bit subchannel id in bits 32-63 (counting from the left). As for other I/O instructions, bits 0-31 should be ignored and thus not be passed to kvm_io_bus_write_cookie().

This fixes a bug where the guest passed non-zero bits 0-31 which the host tried to interpret, leading to ioeventfd notification failures.

---
 arch/s390/kvm/diag.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/diag.c +1 -1
index 5ff29be..8216c0e 100644
@@ -121,7 +121,7 @@ static int __diag_virtio_hypercall(struct kvm_vcpu *vcpu)
 	 * - gpr 4 contains the index on the bus (optionally)
 	 */
 	ret = kvm_io_bus_write_cookie(vcpu->kvm, KVM_VIRTIO_CCW_NOTIFY_BUS,
-				      vcpu->run->s.regs.gprs[2],
+				      vcpu->run->s.regs.gprs[2] & 0xffffffff,
 				      8, &vcpu->run->s.regs.gprs[3],
 				      vcpu->run->s.regs.gprs[4]);
 
Signature · 1 line
1.7.9.5