linux-s390.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next)
@ 2015-05-11  8:44 Christian Borntraeger
  2015-05-11  8:44 ` [GIT PULL 1/9] KVM: s390: fix external call injection without sigp interpretation Christian Borntraeger
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-05-11  8:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alexander Graf, KVM, Cornelia Huck, Jens Freimann, linux-s390,
	Christian Borntraeger

Paolo,

the following changes since commit 5ebe6afaf0057ac3eaeb98defd5456894b446d22:

  Linux 4.1-rc2 (2015-05-03 19:22:23 -0700)

are available in the git repository at:

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

for you to fetch changes up to 06b36753a6466239fc945b6756e12d635621ae5f:

  KVM: s390: drop handling of interception code 12 (2015-05-08 15:51:17 +0200)

----------------------------------------------------------------
KVM: s390: Fixes and features for 4.2 (kvm/next)

Mostly a bunch of fixes, reworks and optimizations for s390.
There is one new feature (EDAT-2 inside the guest), which boils
down to 2GB pages.

----------------------------------------------------------------
Christian Borntraeger (3):
      KVM: s390: optimize round trip time in request handling
      KVM: s390: make exit_sie_sync more robust
      KVM: s390: provide functions for blocking all CPUs

David Hildenbrand (3):
      KVM: s390: fix external call injection without sigp interpretation
      KVM: s390: factor out and optimize floating irq VCPU kick
      KVM: s390: drop handling of interception code 12

Guenther Hutzl (2):
      KVM: s390: make EDAT1 depend on host support
      KVM: s390: Enable guest EDAT2 support

Jens Freimann (1):
      KVM: s390: optimize interrupt handling round trip time

 arch/s390/include/asm/kvm_host.h |  4 +-
 arch/s390/kernel/entry.S         |  2 +-
 arch/s390/kvm/intercept.c        | 16 --------
 arch/s390/kvm/interrupt.c        | 87 +++++++++++++++++++++++-----------------
 arch/s390/kvm/kvm-s390.c         | 51 ++++++++++++++---------
 arch/s390/kvm/kvm-s390.h         | 25 ++++++++++--
 arch/s390/kvm/priv.c             |  8 +++-
 7 files changed, 116 insertions(+), 77 deletions(-)

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [GIT PULL 1/9] KVM: s390: fix external call injection without sigp interpretation
  2015-05-11  8:44 [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next) Christian Borntraeger
@ 2015-05-11  8:44 ` Christian Borntraeger
  2015-05-11  8:44 ` [GIT PULL 2/9] KVM: s390: optimize round trip time in request handling Christian Borntraeger
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-05-11  8:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alexander Graf, KVM, Cornelia Huck, Jens Freimann, linux-s390,
	David Hildenbrand, stable, #, v4.0, Christian Borntraeger

From: David Hildenbrand <dahi@linux.vnet.ibm.com>

Commit ea5f49692575 ("KVM: s390: only one external call may be pending
at a time") introduced a bug on machines that don't have SIGP
interpretation facility installed.
The injection of an external call will now always fail with -EBUSY
(if none is already pending).

This leads to the following symptoms:
- An external call will be injected but with the wrong "src cpu id",
  as this id will not be remembered.
- The target vcpu will not be woken up, therefore the guest will hang if
  it cannot deal with unexpected failures of the SIGP EXTERNAL CALL
  instruction.
- If an external call is already pending, -EBUSY will not be reported.

Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Cc: stable@vger.kernel.org # v4.0
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/kvm/interrupt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 9de4726..2836b25 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -1061,7 +1061,7 @@ static int __inject_extcall(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)
 	if (sclp_has_sigpif())
 		return __inject_extcall_sigpif(vcpu, src_id);
 
-	if (!test_and_set_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs))
+	if (test_and_set_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs))
 		return -EBUSY;
 	*extcall = irq->u.extcall;
 	atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags);
-- 
2.3.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [GIT PULL 2/9] KVM: s390: optimize round trip time in request handling
  2015-05-11  8:44 [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next) Christian Borntraeger
  2015-05-11  8:44 ` [GIT PULL 1/9] KVM: s390: fix external call injection without sigp interpretation Christian Borntraeger
@ 2015-05-11  8:44 ` Christian Borntraeger
  2015-05-11  8:44 ` [GIT PULL 3/9] KVM: s390: make EDAT1 depend on host support Christian Borntraeger
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-05-11  8:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alexander Graf, KVM, Cornelia Huck, Jens Freimann, linux-s390,
	Christian Borntraeger

The fast path for a sie exit is that no kvm reqest is pending.
Make an early check to skip all single bit checks.

Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/kvm/kvm-s390.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 8cd8e7b..f5282e6 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -1720,6 +1720,8 @@ static bool ibs_enabled(struct kvm_vcpu *vcpu)
 
 static int kvm_s390_handle_requests(struct kvm_vcpu *vcpu)
 {
+	if (!vcpu->requests)
+		return 0;
 retry:
 	s390_vcpu_unblock(vcpu);
 	/*
-- 
2.3.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [GIT PULL 3/9] KVM: s390: make EDAT1 depend on host support
  2015-05-11  8:44 [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next) Christian Borntraeger
  2015-05-11  8:44 ` [GIT PULL 1/9] KVM: s390: fix external call injection without sigp interpretation Christian Borntraeger
  2015-05-11  8:44 ` [GIT PULL 2/9] KVM: s390: optimize round trip time in request handling Christian Borntraeger
@ 2015-05-11  8:44 ` Christian Borntraeger
  2015-05-11  8:44 ` [GIT PULL 4/9] KVM: s390: Enable guest EDAT2 support Christian Borntraeger
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-05-11  8:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alexander Graf, KVM, Cornelia Huck, Jens Freimann, linux-s390,
	Guenther Hutzl, Christian Borntraeger

From: Guenther Hutzl <hutzl@linux.vnet.ibm.com>

We should only enable EDAT1 for the guest if the host actually supports
it and the cpu model for the guest has EDAT-1 enabled.

Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Guenther Hutzl <hutzl@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/kvm/kvm-s390.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index f5282e6..2da36c4 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -1311,8 +1311,11 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 
 	atomic_set(&vcpu->arch.sie_block->cpuflags, CPUSTAT_ZARCH |
 						    CPUSTAT_SM |
-						    CPUSTAT_STOPPED |
-						    CPUSTAT_GED);
+						    CPUSTAT_STOPPED);
+
+	if (test_kvm_facility(vcpu->kvm, 8))
+		atomic_set_mask(CPUSTAT_GED, &vcpu->arch.sie_block->cpuflags);
+
 	kvm_s390_vcpu_setup_model(vcpu);
 
 	vcpu->arch.sie_block->ecb   = 6;
-- 
2.3.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [GIT PULL 4/9] KVM: s390: Enable guest EDAT2 support
  2015-05-11  8:44 [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next) Christian Borntraeger
                   ` (2 preceding siblings ...)
  2015-05-11  8:44 ` [GIT PULL 3/9] KVM: s390: make EDAT1 depend on host support Christian Borntraeger
@ 2015-05-11  8:44 ` Christian Borntraeger
  2015-05-11  8:44 ` [GIT PULL 5/9] KVM: s390: make exit_sie_sync more robust Christian Borntraeger
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-05-11  8:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alexander Graf, KVM, Cornelia Huck, Jens Freimann, linux-s390,
	Guenther Hutzl, Christian Borntraeger

From: Guenther Hutzl <hutzl@linux.vnet.ibm.com>

1. Enable EDAT2 in the list of KVM facilities

2. Handle 2G frames in pfmf instruction
If we support EDAT2, we may enable handling of 2G frames if not in 24
bit mode.

3. Enable EDAT2 in sie_block
If the EDAT2 facility is available we enable GED2 mode control in the
sie_block.

Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Guenther Hutzl <hutzl@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/include/asm/kvm_host.h | 1 +
 arch/s390/kvm/kvm-s390.c         | 6 ++++--
 arch/s390/kvm/priv.c             | 8 ++++++--
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index d01fc58..1011ac1 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -80,6 +80,7 @@ struct sca_block {
 #define CPUSTAT_MCDS       0x00000100
 #define CPUSTAT_SM         0x00000080
 #define CPUSTAT_IBS        0x00000040
+#define CPUSTAT_GED2       0x00000010
 #define CPUSTAT_G          0x00000008
 #define CPUSTAT_GED        0x00000004
 #define CPUSTAT_J          0x00000002
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 2da36c4..142d9b4 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -110,7 +110,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
 /* upper facilities limit for kvm */
 unsigned long kvm_s390_fac_list_mask[] = {
 	0xffe6fffbfcfdfc40UL,
-	0x005c800000000000UL,
+	0x005e800000000000UL,
 };
 
 unsigned long kvm_s390_fac_list_mask_size(void)
@@ -1313,7 +1313,9 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 						    CPUSTAT_SM |
 						    CPUSTAT_STOPPED);
 
-	if (test_kvm_facility(vcpu->kvm, 8))
+	if (test_kvm_facility(vcpu->kvm, 78))
+		atomic_set_mask(CPUSTAT_GED2, &vcpu->arch.sie_block->cpuflags);
+	else if (test_kvm_facility(vcpu->kvm, 8))
 		atomic_set_mask(CPUSTAT_GED, &vcpu->arch.sie_block->cpuflags);
 
 	kvm_s390_vcpu_setup_model(vcpu);
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index d22d8ee..ad42422 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -698,10 +698,14 @@ static int handle_pfmf(struct kvm_vcpu *vcpu)
 	case 0x00001000:
 		end = (start + (1UL << 20)) & ~((1UL << 20) - 1);
 		break;
-	/* We dont support EDAT2
 	case 0x00002000:
+		/* only support 2G frame size if EDAT2 is available and we are
+		   not in 24-bit addressing mode */
+		if (!test_kvm_facility(vcpu->kvm, 78) ||
+		    psw_bits(vcpu->arch.sie_block->gpsw).eaba == PSW_AMODE_24BIT)
+			return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
 		end = (start + (1UL << 31)) & ~((1UL << 31) - 1);
-		break;*/
+		break;
 	default:
 		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
 	}
-- 
2.3.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [GIT PULL 5/9] KVM: s390: make exit_sie_sync more robust
  2015-05-11  8:44 [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next) Christian Borntraeger
                   ` (3 preceding siblings ...)
  2015-05-11  8:44 ` [GIT PULL 4/9] KVM: s390: Enable guest EDAT2 support Christian Borntraeger
@ 2015-05-11  8:44 ` Christian Borntraeger
  2015-05-11  8:44 ` [GIT PULL 6/9] KVM: s390: provide functions for blocking all CPUs Christian Borntraeger
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-05-11  8:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alexander Graf, KVM, Cornelia Huck, Jens Freimann, linux-s390,
	Christian Borntraeger

exit_sie_sync is used to kick CPUs out of SIE and prevent reentering at
any point in time. This is used to reload the prefix pages and to
set the IBS stuff in a way that guarantees that after this function
returns we are no longer in SIE. All current users trigger KVM requests.

The request must be set before we block the CPUs to avoid races. Let's
make this implicit by adding the request into a new function
kvm_s390_sync_requests that replaces exit_sie_sync and split out
s390_vcpu_block and s390_vcpu_unblock, that can be used to keep
CPUs out of SIE independent of requests.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 arch/s390/include/asm/kvm_host.h |  3 ++-
 arch/s390/kernel/entry.S         |  2 +-
 arch/s390/kvm/kvm-s390.c         | 28 ++++++++++++++++++----------
 arch/s390/kvm/kvm-s390.h         |  2 +-
 4 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 1011ac1..444c412 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -96,7 +96,8 @@ struct kvm_s390_sie_block {
 #define PROG_IN_SIE (1<<0)
 	__u32	prog0c;			/* 0x000c */
 	__u8	reserved10[16];		/* 0x0010 */
-#define PROG_BLOCK_SIE 0x00000001
+#define PROG_BLOCK_SIE	(1<<0)
+#define PROG_REQUEST	(1<<1)
 	atomic_t prog20;		/* 0x0020 */
 	__u8	reserved24[4];		/* 0x0024 */
 	__u64	cputm;			/* 0x0028 */
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index 99b44ac..3238893 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -1005,7 +1005,7 @@ ENTRY(sie64a)
 .Lsie_gmap:
 	lg	%r14,__SF_EMPTY(%r15)		# get control block pointer
 	oi	__SIE_PROG0C+3(%r14),1		# we are going into SIE now
-	tm	__SIE_PROG20+3(%r14),1		# last exit...
+	tm	__SIE_PROG20+3(%r14),3		# last exit...
 	jnz	.Lsie_done
 	LPP	__SF_EMPTY(%r15)		# set guest id
 	sie	0(%r14)
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 142d9b4..9bc57af 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -1424,6 +1424,16 @@ void s390_vcpu_unblock(struct kvm_vcpu *vcpu)
 	atomic_clear_mask(PROG_BLOCK_SIE, &vcpu->arch.sie_block->prog20);
 }
 
+static void kvm_s390_vcpu_request(struct kvm_vcpu *vcpu)
+{
+	atomic_set_mask(PROG_REQUEST, &vcpu->arch.sie_block->prog20);
+}
+
+static void kvm_s390_vcpu_request_handled(struct kvm_vcpu *vcpu)
+{
+	atomic_clear_mask(PROG_REQUEST, &vcpu->arch.sie_block->prog20);
+}
+
 /*
  * Kick a guest cpu out of SIE and wait until SIE is not running.
  * If the CPU is not running (e.g. waiting as idle) the function will
@@ -1435,10 +1445,11 @@ void exit_sie(struct kvm_vcpu *vcpu)
 		cpu_relax();
 }
 
-/* Kick a guest cpu out of SIE and prevent SIE-reentry */
-void exit_sie_sync(struct kvm_vcpu *vcpu)
+/* Kick a guest cpu out of SIE to process a request synchronously */
+void kvm_s390_sync_request(int req, struct kvm_vcpu *vcpu)
 {
-	s390_vcpu_block(vcpu);
+	kvm_make_request(req, vcpu);
+	kvm_s390_vcpu_request(vcpu);
 	exit_sie(vcpu);
 }
 
@@ -1452,8 +1463,7 @@ static void kvm_gmap_notifier(struct gmap *gmap, unsigned long address)
 		/* match against both prefix pages */
 		if (kvm_s390_get_prefix(vcpu) == (address & ~0x1000UL)) {
 			VCPU_EVENT(vcpu, 2, "gmap notifier for %lx", address);
-			kvm_make_request(KVM_REQ_MMU_RELOAD, vcpu);
-			exit_sie_sync(vcpu);
+			kvm_s390_sync_request(KVM_REQ_MMU_RELOAD, vcpu);
 		}
 	}
 }
@@ -1728,7 +1738,7 @@ static int kvm_s390_handle_requests(struct kvm_vcpu *vcpu)
 	if (!vcpu->requests)
 		return 0;
 retry:
-	s390_vcpu_unblock(vcpu);
+	kvm_s390_vcpu_request_handled(vcpu);
 	/*
 	 * We use MMU_RELOAD just to re-arm the ipte notifier for the
 	 * guest prefix page. gmap_ipte_notify will wait on the ptl lock.
@@ -2213,8 +2223,7 @@ int kvm_s390_vcpu_store_adtl_status(struct kvm_vcpu *vcpu, unsigned long addr)
 static void __disable_ibs_on_vcpu(struct kvm_vcpu *vcpu)
 {
 	kvm_check_request(KVM_REQ_ENABLE_IBS, vcpu);
-	kvm_make_request(KVM_REQ_DISABLE_IBS, vcpu);
-	exit_sie_sync(vcpu);
+	kvm_s390_sync_request(KVM_REQ_DISABLE_IBS, vcpu);
 }
 
 static void __disable_ibs_on_all_vcpus(struct kvm *kvm)
@@ -2230,8 +2239,7 @@ static void __disable_ibs_on_all_vcpus(struct kvm *kvm)
 static void __enable_ibs_on_vcpu(struct kvm_vcpu *vcpu)
 {
 	kvm_check_request(KVM_REQ_DISABLE_IBS, vcpu);
-	kvm_make_request(KVM_REQ_ENABLE_IBS, vcpu);
-	exit_sie_sync(vcpu);
+	kvm_s390_sync_request(KVM_REQ_ENABLE_IBS, vcpu);
 }
 
 void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu)
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index ca108b9..8edca85 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -214,7 +214,7 @@ void kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu);
 void s390_vcpu_block(struct kvm_vcpu *vcpu);
 void s390_vcpu_unblock(struct kvm_vcpu *vcpu);
 void exit_sie(struct kvm_vcpu *vcpu);
-void exit_sie_sync(struct kvm_vcpu *vcpu);
+void kvm_s390_sync_request(int req, struct kvm_vcpu *vcpu);
 int kvm_s390_vcpu_setup_cmma(struct kvm_vcpu *vcpu);
 void kvm_s390_vcpu_unsetup_cmma(struct kvm_vcpu *vcpu);
 /* is cmma enabled */
-- 
2.3.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [GIT PULL 6/9] KVM: s390: provide functions for blocking all CPUs
  2015-05-11  8:44 [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next) Christian Borntraeger
                   ` (4 preceding siblings ...)
  2015-05-11  8:44 ` [GIT PULL 5/9] KVM: s390: make exit_sie_sync more robust Christian Borntraeger
@ 2015-05-11  8:44 ` Christian Borntraeger
  2015-05-11  8:44 ` [GIT PULL 7/9] KVM: s390: optimize interrupt handling round trip time Christian Borntraeger
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-05-11  8:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alexander Graf, KVM, Cornelia Huck, Jens Freimann, linux-s390,
	Christian Borntraeger

Some updates to the control blocks need to be done in a way that
ensures that no CPU is within SIE. Provide wrappers around the
s390_vcpu_block functions and adopt the TOD migration code to
update in a guaranteed fashion. Also rename these functions to
have the kvm_s390_ prefix as everything else.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 arch/s390/kvm/kvm-s390.c | 10 +++++-----
 arch/s390/kvm/kvm-s390.h | 23 +++++++++++++++++++++--
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 9bc57af..6bc69ab 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -454,10 +454,10 @@ static int kvm_s390_set_tod_low(struct kvm *kvm, struct kvm_device_attr *attr)
 
 	mutex_lock(&kvm->lock);
 	kvm->arch.epoch = gtod - host_tod;
-	kvm_for_each_vcpu(vcpu_idx, cur_vcpu, kvm) {
+	kvm_s390_vcpu_block_all(kvm);
+	kvm_for_each_vcpu(vcpu_idx, cur_vcpu, kvm)
 		cur_vcpu->arch.sie_block->epoch = kvm->arch.epoch;
-		exit_sie(cur_vcpu);
-	}
+	kvm_s390_vcpu_unblock_all(kvm);
 	mutex_unlock(&kvm->lock);
 	return 0;
 }
@@ -1414,12 +1414,12 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)
 	return kvm_s390_vcpu_has_irq(vcpu, 0);
 }
 
-void s390_vcpu_block(struct kvm_vcpu *vcpu)
+void kvm_s390_vcpu_block(struct kvm_vcpu *vcpu)
 {
 	atomic_set_mask(PROG_BLOCK_SIE, &vcpu->arch.sie_block->prog20);
 }
 
-void s390_vcpu_unblock(struct kvm_vcpu *vcpu)
+void kvm_s390_vcpu_unblock(struct kvm_vcpu *vcpu)
 {
 	atomic_clear_mask(PROG_BLOCK_SIE, &vcpu->arch.sie_block->prog20);
 }
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index 8edca85..c570478 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -211,8 +211,8 @@ int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr);
 int kvm_s390_vcpu_store_adtl_status(struct kvm_vcpu *vcpu, unsigned long addr);
 void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu);
 void kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu);
-void s390_vcpu_block(struct kvm_vcpu *vcpu);
-void s390_vcpu_unblock(struct kvm_vcpu *vcpu);
+void kvm_s390_vcpu_block(struct kvm_vcpu *vcpu);
+void kvm_s390_vcpu_unblock(struct kvm_vcpu *vcpu);
 void exit_sie(struct kvm_vcpu *vcpu);
 void kvm_s390_sync_request(int req, struct kvm_vcpu *vcpu);
 int kvm_s390_vcpu_setup_cmma(struct kvm_vcpu *vcpu);
@@ -228,6 +228,25 @@ int kvm_s390_handle_diag(struct kvm_vcpu *vcpu);
 int kvm_s390_inject_prog_irq(struct kvm_vcpu *vcpu,
 			     struct kvm_s390_pgm_info *pgm_info);
 
+static inline void kvm_s390_vcpu_block_all(struct kvm *kvm)
+{
+	int i;
+	struct kvm_vcpu *vcpu;
+
+	WARN_ON(!mutex_is_locked(&kvm->lock));
+	kvm_for_each_vcpu(i, vcpu, kvm)
+		kvm_s390_vcpu_block(vcpu);
+}
+
+static inline void kvm_s390_vcpu_unblock_all(struct kvm *kvm)
+{
+	int i;
+	struct kvm_vcpu *vcpu;
+
+	kvm_for_each_vcpu(i, vcpu, kvm)
+		kvm_s390_vcpu_unblock(vcpu);
+}
+
 /**
  * kvm_s390_inject_prog_cond - conditionally inject a program check
  * @vcpu: virtual cpu
-- 
2.3.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [GIT PULL 7/9] KVM: s390: optimize interrupt handling round trip time
  2015-05-11  8:44 [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next) Christian Borntraeger
                   ` (5 preceding siblings ...)
  2015-05-11  8:44 ` [GIT PULL 6/9] KVM: s390: provide functions for blocking all CPUs Christian Borntraeger
@ 2015-05-11  8:44 ` Christian Borntraeger
  2015-05-11  8:44 ` [GIT PULL 8/9] KVM: s390: factor out and optimize floating irq VCPU kick Christian Borntraeger
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-05-11  8:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alexander Graf, KVM, Cornelia Huck, Jens Freimann, linux-s390

From: Jens Freimann <jfrei@linux.vnet.ibm.com>

We can avoid checking guest control registers and guest PSW as well
as all the masking and calculations on the interrupt masks when
no interrupts are pending.

Also, the check for IRQ_PEND_COUNT can be removed, because we won't
enter the while loop if no interrupts are pending and invalid interrupt
types can't be injected.

Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Dominik Dingel <dingel@linux.vnet.ibm.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/kvm/interrupt.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 2836b25..acf4a4e 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -134,6 +134,8 @@ static unsigned long deliverable_irqs(struct kvm_vcpu *vcpu)
 
 	active_mask = pending_local_irqs(vcpu);
 	active_mask |= pending_floating_irqs(vcpu);
+	if (!active_mask)
+		return 0;
 
 	if (psw_extint_disabled(vcpu))
 		active_mask &= ~IRQ_PEND_EXT_MASK;
@@ -941,12 +943,9 @@ int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
 	if (cpu_timer_irq_pending(vcpu))
 		set_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs);
 
-	do {
-		irqs = deliverable_irqs(vcpu);
+	while ((irqs = deliverable_irqs(vcpu)) && !rc) {
 		/* bits are in the order of interrupt priority */
 		irq_type = find_first_bit(&irqs, IRQ_PEND_COUNT);
-		if (irq_type == IRQ_PEND_COUNT)
-			break;
 		if (is_ioirq(irq_type)) {
 			rc = __deliver_io(vcpu, irq_type);
 		} else {
@@ -958,9 +957,7 @@ int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
 			}
 			rc = func(vcpu);
 		}
-		if (rc)
-			break;
-	} while (!rc);
+	}
 
 	set_intercept_indicators(vcpu);
 
-- 
2.3.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [GIT PULL 8/9] KVM: s390: factor out and optimize floating irq VCPU kick
  2015-05-11  8:44 [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next) Christian Borntraeger
                   ` (6 preceding siblings ...)
  2015-05-11  8:44 ` [GIT PULL 7/9] KVM: s390: optimize interrupt handling round trip time Christian Borntraeger
@ 2015-05-11  8:44 ` Christian Borntraeger
  2015-05-11  8:44 ` [GIT PULL 9/9] KVM: s390: drop handling of interception code 12 Christian Borntraeger
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-05-11  8:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alexander Graf, KVM, Cornelia Huck, Jens Freimann, linux-s390,
	David Hildenbrand, Christian Borntraeger

From: David Hildenbrand <dahi@linux.vnet.ibm.com>

This patch factors out the search for a floating irq destination
VCPU as well as the kicking of the found VCPU. The search is optimized
in the following ways:

1. stopped VCPUs can't take any floating interrupts, so try to find an
   operating one. We have to take care of the special case where all
   VCPUs are stopped and we don't have any valid destination.

2. use online_vcpus, not KVM_MAX_VCPU. This speeds up the search
   especially if KVM_MAX_VCPU is increased one day. As these VCPU
   objects are initialized prior to increasing online_vcpus, we can be
   sure that they exist.

Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Dominik Dingel <dingel@linux.vnet.ibm.com>
Reviewed-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/kvm/interrupt.c | 74 +++++++++++++++++++++++++++++------------------
 1 file changed, 46 insertions(+), 28 deletions(-)

diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index acf4a4e..322ef9c 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -1337,12 +1337,54 @@ static int __inject_io(struct kvm *kvm, struct kvm_s390_interrupt_info *inti)
 	return 0;
 }
 
-static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti)
+/*
+ * Find a destination VCPU for a floating irq and kick it.
+ */
+static void __floating_irq_kick(struct kvm *kvm, u64 type)
 {
+	struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int;
 	struct kvm_s390_local_interrupt *li;
+	struct kvm_vcpu *dst_vcpu;
+	int sigcpu, online_vcpus, nr_tries = 0;
+
+	online_vcpus = atomic_read(&kvm->online_vcpus);
+	if (!online_vcpus)
+		return;
+
+	/* find idle VCPUs first, then round robin */
+	sigcpu = find_first_bit(fi->idle_mask, online_vcpus);
+	if (sigcpu == online_vcpus) {
+		do {
+			sigcpu = fi->next_rr_cpu;
+			fi->next_rr_cpu = (fi->next_rr_cpu + 1) % online_vcpus;
+			/* avoid endless loops if all vcpus are stopped */
+			if (nr_tries++ >= online_vcpus)
+				return;
+		} while (is_vcpu_stopped(kvm_get_vcpu(kvm, sigcpu)));
+	}
+	dst_vcpu = kvm_get_vcpu(kvm, sigcpu);
+
+	/* make the VCPU drop out of the SIE, or wake it up if sleeping */
+	li = &dst_vcpu->arch.local_int;
+	spin_lock(&li->lock);
+	switch (type) {
+	case KVM_S390_MCHK:
+		atomic_set_mask(CPUSTAT_STOP_INT, li->cpuflags);
+		break;
+	case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
+		atomic_set_mask(CPUSTAT_IO_INT, li->cpuflags);
+		break;
+	default:
+		atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags);
+		break;
+	}
+	spin_unlock(&li->lock);
+	kvm_s390_vcpu_wakeup(dst_vcpu);
+}
+
+static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti)
+{
 	struct kvm_s390_float_interrupt *fi;
-	struct kvm_vcpu *dst_vcpu = NULL;
-	int sigcpu;
 	u64 type = READ_ONCE(inti->type);
 	int rc;
 
@@ -1370,32 +1412,8 @@ static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti)
 	if (rc)
 		return rc;
 
-	sigcpu = find_first_bit(fi->idle_mask, KVM_MAX_VCPUS);
-	if (sigcpu == KVM_MAX_VCPUS) {
-		do {
-			sigcpu = fi->next_rr_cpu++;
-			if (sigcpu == KVM_MAX_VCPUS)
-				sigcpu = fi->next_rr_cpu = 0;
-		} while (kvm_get_vcpu(kvm, sigcpu) == NULL);
-	}
-	dst_vcpu = kvm_get_vcpu(kvm, sigcpu);
-	li = &dst_vcpu->arch.local_int;
-	spin_lock(&li->lock);
-	switch (type) {
-	case KVM_S390_MCHK:
-		atomic_set_mask(CPUSTAT_STOP_INT, li->cpuflags);
-		break;
-	case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
-		atomic_set_mask(CPUSTAT_IO_INT, li->cpuflags);
-		break;
-	default:
-		atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags);
-		break;
-	}
-	spin_unlock(&li->lock);
-	kvm_s390_vcpu_wakeup(kvm_get_vcpu(kvm, sigcpu));
+	__floating_irq_kick(kvm, type);
 	return 0;
-
 }
 
 int kvm_s390_inject_vm(struct kvm *kvm,
-- 
2.3.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [GIT PULL 9/9] KVM: s390: drop handling of interception code 12
  2015-05-11  8:44 [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next) Christian Borntraeger
                   ` (7 preceding siblings ...)
  2015-05-11  8:44 ` [GIT PULL 8/9] KVM: s390: factor out and optimize floating irq VCPU kick Christian Borntraeger
@ 2015-05-11  8:44 ` Christian Borntraeger
  2015-05-11  8:45 ` [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next) Christian Borntraeger
  2015-05-11 12:07 ` Paolo Bonzini
  10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-05-11  8:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alexander Graf, KVM, Cornelia Huck, Jens Freimann, linux-s390,
	David Hildenbrand, Christian Borntraeger

From: David Hildenbrand <dahi@linux.vnet.ibm.com>

Our implementation will never trigger interception code 12 as the
responsible setting is never enabled - and never will be.
The handler is dead code. Let's get rid of it.

Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/kvm/intercept.c | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/arch/s390/kvm/intercept.c b/arch/s390/kvm/intercept.c
index 9e3779e..7365e8a 100644
--- a/arch/s390/kvm/intercept.c
+++ b/arch/s390/kvm/intercept.c
@@ -241,21 +241,6 @@ static int handle_prog(struct kvm_vcpu *vcpu)
 	return kvm_s390_inject_prog_irq(vcpu, &pgm_info);
 }
 
-static int handle_instruction_and_prog(struct kvm_vcpu *vcpu)
-{
-	int rc, rc2;
-
-	vcpu->stat.exit_instr_and_program++;
-	rc = handle_instruction(vcpu);
-	rc2 = handle_prog(vcpu);
-
-	if (rc == -EOPNOTSUPP)
-		vcpu->arch.sie_block->icptcode = 0x04;
-	if (rc)
-		return rc;
-	return rc2;
-}
-
 /**
  * handle_external_interrupt - used for external interruption interceptions
  *
@@ -355,7 +340,6 @@ static const intercept_handler_t intercept_funcs[] = {
 	[0x00 >> 2] = handle_noop,
 	[0x04 >> 2] = handle_instruction,
 	[0x08 >> 2] = handle_prog,
-	[0x0C >> 2] = handle_instruction_and_prog,
 	[0x10 >> 2] = handle_noop,
 	[0x14 >> 2] = handle_external_interrupt,
 	[0x18 >> 2] = handle_noop,
-- 
2.3.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next)
  2015-05-11  8:44 [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next) Christian Borntraeger
                   ` (8 preceding siblings ...)
  2015-05-11  8:44 ` [GIT PULL 9/9] KVM: s390: drop handling of interception code 12 Christian Borntraeger
@ 2015-05-11  8:45 ` Christian Borntraeger
  2015-05-11 12:07 ` Paolo Bonzini
  10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-05-11  8:45 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alexander Graf, KVM, Cornelia Huck, Jens Freimann, linux-s390

feel free to ignore the "PREVIEW" tag in the subject - its a leftover.

Christian

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next)
  2015-05-11  8:44 [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next) Christian Borntraeger
                   ` (9 preceding siblings ...)
  2015-05-11  8:45 ` [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next) Christian Borntraeger
@ 2015-05-11 12:07 ` Paolo Bonzini
  10 siblings, 0 replies; 12+ messages in thread
From: Paolo Bonzini @ 2015-05-11 12:07 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: Alexander Graf, KVM, Cornelia Huck, Jens Freimann, linux-s390



On 11/05/2015 10:44, Christian Borntraeger wrote:
> Paolo,
> 
> the following changes since commit 5ebe6afaf0057ac3eaeb98defd5456894b446d22:
> 
>   Linux 4.1-rc2 (2015-05-03 19:22:23 -0700)
> 
> are available in the git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git  tags/kvm-s390-next-20150508
> 
> for you to fetch changes up to 06b36753a6466239fc945b6756e12d635621ae5f:
> 
>   KVM: s390: drop handling of interception code 12 (2015-05-08 15:51:17 +0200)
> 
> ----------------------------------------------------------------
> KVM: s390: Fixes and features for 4.2 (kvm/next)
> 
> Mostly a bunch of fixes, reworks and optimizations for s390.
> There is one new feature (EDAT-2 inside the guest), which boils
> down to 2GB pages.
> 
> ----------------------------------------------------------------
> Christian Borntraeger (3):
>       KVM: s390: optimize round trip time in request handling
>       KVM: s390: make exit_sie_sync more robust
>       KVM: s390: provide functions for blocking all CPUs
> 
> David Hildenbrand (3):
>       KVM: s390: fix external call injection without sigp interpretation
>       KVM: s390: factor out and optimize floating irq VCPU kick
>       KVM: s390: drop handling of interception code 12
> 
> Guenther Hutzl (2):
>       KVM: s390: make EDAT1 depend on host support
>       KVM: s390: Enable guest EDAT2 support
> 
> Jens Freimann (1):
>       KVM: s390: optimize interrupt handling round trip time
> 
>  arch/s390/include/asm/kvm_host.h |  4 +-
>  arch/s390/kernel/entry.S         |  2 +-
>  arch/s390/kvm/intercept.c        | 16 --------
>  arch/s390/kvm/interrupt.c        | 87 +++++++++++++++++++++++-----------------
>  arch/s390/kvm/kvm-s390.c         | 51 ++++++++++++++---------
>  arch/s390/kvm/kvm-s390.h         | 25 ++++++++++--
>  arch/s390/kvm/priv.c             |  8 +++-
>  7 files changed, 116 insertions(+), 77 deletions(-)
> 

Pulled, thanks.

Paolo

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-05-11 12:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-11  8:44 [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next) Christian Borntraeger
2015-05-11  8:44 ` [GIT PULL 1/9] KVM: s390: fix external call injection without sigp interpretation Christian Borntraeger
2015-05-11  8:44 ` [GIT PULL 2/9] KVM: s390: optimize round trip time in request handling Christian Borntraeger
2015-05-11  8:44 ` [GIT PULL 3/9] KVM: s390: make EDAT1 depend on host support Christian Borntraeger
2015-05-11  8:44 ` [GIT PULL 4/9] KVM: s390: Enable guest EDAT2 support Christian Borntraeger
2015-05-11  8:44 ` [GIT PULL 5/9] KVM: s390: make exit_sie_sync more robust Christian Borntraeger
2015-05-11  8:44 ` [GIT PULL 6/9] KVM: s390: provide functions for blocking all CPUs Christian Borntraeger
2015-05-11  8:44 ` [GIT PULL 7/9] KVM: s390: optimize interrupt handling round trip time Christian Borntraeger
2015-05-11  8:44 ` [GIT PULL 8/9] KVM: s390: factor out and optimize floating irq VCPU kick Christian Borntraeger
2015-05-11  8:44 ` [GIT PULL 9/9] KVM: s390: drop handling of interception code 12 Christian Borntraeger
2015-05-11  8:45 ` [PREVIEW: GIT PULL 0/9] KVM: s390: Fixes and features for 4.2 (kvm/next) Christian Borntraeger
2015-05-11 12:07 ` Paolo Bonzini

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).