* [GIT PULL 00/10] KVM: s390: Fixes for 4.4
@ 2015-10-13 14:05 Christian Borntraeger
2015-10-13 14:05 ` [GIT PULL 01/10] KVM: s390: remove unused variable in __inject_vm Christian Borntraeger
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-10-13 14:05 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Alexander Graf, KVM, Cornelia Huck, Jens Freimann, linux-s390,
Christian Borntraeger
Paolo,
The following changes since commit 9ffecb10283508260936b96022d4ee43a7798b4c:
Linux 4.3-rc3 (2015-09-27 07:50:08 -0400)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-next-20151013
for you to fetch changes up to 60417fcc2b0235dfe3dcd589c56dbe3ea1a64c54:
KVM: s390: factor out reading of the guest TOD clock (2015-10-13 15:50:35 +0200)
----------------------------------------------------------------
KVM: s390: Fixes for 4.4
A bunch of fixes and optimizations for interrupt and time
handling. No fix is important enough to qualify for 4.3 or
stable.
----------------------------------------------------------------
Christian Borntraeger (1):
KVM: s390: remove unused variable in __inject_vm
David Hildenbrand (9):
KVM: s390: disabled wait cares about machine checks, not PER
KVM: s390: set interception requests for all floating irqs
KVM: s390: kvm_arch_vcpu_runnable already cares about timer interrupts
KVM: s390: drop out early in kvm_s390_has_irq()
KVM: s390: simplify in-kernel program irq injection
KVM: s390: correctly handle injection of pgm irqs and per events
KVM: s390: switch to get_tod_clock() and fix STP sync races
KVM: s390: factor out and fix setting of guest TOD clock
KVM: s390: factor out reading of the guest TOD clock
arch/s390/kvm/interrupt.c | 116 +++++++++++++++++-----------------------------
arch/s390/kvm/kvm-s390.c | 46 ++++++++----------
arch/s390/kvm/kvm-s390.h | 35 ++++++++++++--
arch/s390/kvm/priv.c | 19 ++------
4 files changed, 97 insertions(+), 119 deletions(-)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [GIT PULL 01/10] KVM: s390: remove unused variable in __inject_vm
2015-10-13 14:05 [GIT PULL 00/10] KVM: s390: Fixes for 4.4 Christian Borntraeger
@ 2015-10-13 14:05 ` Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 02/10] KVM: s390: disabled wait cares about machine checks, not PER Christian Borntraeger
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-10-13 14:05 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Alexander Graf, KVM, Cornelia Huck, Jens Freimann, linux-s390,
Christian Borntraeger
the float int structure is no longer used in __inject_vm.
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
arch/s390/kvm/interrupt.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 5c2c169..ab9f525 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -1390,12 +1390,9 @@ static void __floating_irq_kick(struct kvm *kvm, u64 type)
static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti)
{
- struct kvm_s390_float_interrupt *fi;
u64 type = READ_ONCE(inti->type);
int rc;
- fi = &kvm->arch.float_int;
-
switch (type) {
case KVM_S390_MCHK:
rc = __inject_float_mchk(kvm, inti);
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [GIT PULL 02/10] KVM: s390: disabled wait cares about machine checks, not PER
2015-10-13 14:05 [GIT PULL 00/10] KVM: s390: Fixes for 4.4 Christian Borntraeger
2015-10-13 14:05 ` [GIT PULL 01/10] KVM: s390: remove unused variable in __inject_vm Christian Borntraeger
@ 2015-10-13 14:06 ` Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 03/10] KVM: s390: set interception requests for all floating irqs Christian Borntraeger
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-10-13 14:06 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>
We don't care about program event recording irqs (synchronous
program irqs) but asynchronous irqs when checking for disabled
wait. Machine checks were missing.
Let's directly switch to the functions we have for that purpose
instead of testing once again for magic bits.
Reviewed-by: Christian Borntraeger <borntraeger@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/interrupt.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index ab9f525..1058240 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -51,11 +51,9 @@ static int psw_mchk_disabled(struct kvm_vcpu *vcpu)
static int psw_interrupts_disabled(struct kvm_vcpu *vcpu)
{
- if ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PER) ||
- (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_IO) ||
- (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_EXT))
- return 0;
- return 1;
+ return psw_extint_disabled(vcpu) &&
+ psw_ioint_disabled(vcpu) &&
+ psw_mchk_disabled(vcpu);
}
static int ckc_interrupts_enabled(struct kvm_vcpu *vcpu)
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [GIT PULL 03/10] KVM: s390: set interception requests for all floating irqs
2015-10-13 14:05 [GIT PULL 00/10] KVM: s390: Fixes for 4.4 Christian Borntraeger
2015-10-13 14:05 ` [GIT PULL 01/10] KVM: s390: remove unused variable in __inject_vm Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 02/10] KVM: s390: disabled wait cares about machine checks, not PER Christian Borntraeger
@ 2015-10-13 14:06 ` Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 04/10] KVM: s390: kvm_arch_vcpu_runnable already cares about timer interrupts Christian Borntraeger
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-10-13 14:06 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>
No need to separate pending and floating irqs when setting interception
requests. Let's do it for all equally.
Reviewed-by: Christian Borntraeger <borntraeger@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/interrupt.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 1058240..4f05520 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -107,14 +107,10 @@ static inline u8 int_word_to_isc(u32 int_word)
return (int_word & 0x38000000) >> 27;
}
-static inline unsigned long pending_floating_irqs(struct kvm_vcpu *vcpu)
+static inline unsigned long pending_irqs(struct kvm_vcpu *vcpu)
{
- return vcpu->kvm->arch.float_int.pending_irqs;
-}
-
-static inline unsigned long pending_local_irqs(struct kvm_vcpu *vcpu)
-{
- return vcpu->arch.local_int.pending_irqs;
+ return vcpu->kvm->arch.float_int.pending_irqs |
+ vcpu->arch.local_int.pending_irqs;
}
static unsigned long disable_iscs(struct kvm_vcpu *vcpu,
@@ -133,8 +129,7 @@ static unsigned long deliverable_irqs(struct kvm_vcpu *vcpu)
{
unsigned long active_mask;
- active_mask = pending_local_irqs(vcpu);
- active_mask |= pending_floating_irqs(vcpu);
+ active_mask = pending_irqs(vcpu);
if (!active_mask)
return 0;
@@ -202,7 +197,7 @@ static void __set_cpuflag(struct kvm_vcpu *vcpu, u32 flag)
static void set_intercept_indicators_io(struct kvm_vcpu *vcpu)
{
- if (!(pending_floating_irqs(vcpu) & IRQ_PEND_IO_MASK))
+ if (!(pending_irqs(vcpu) & IRQ_PEND_IO_MASK))
return;
else if (psw_ioint_disabled(vcpu))
__set_cpuflag(vcpu, CPUSTAT_IO_INT);
@@ -212,7 +207,7 @@ static void set_intercept_indicators_io(struct kvm_vcpu *vcpu)
static void set_intercept_indicators_ext(struct kvm_vcpu *vcpu)
{
- if (!(pending_local_irqs(vcpu) & IRQ_PEND_EXT_MASK))
+ if (!(pending_irqs(vcpu) & IRQ_PEND_EXT_MASK))
return;
if (psw_extint_disabled(vcpu))
__set_cpuflag(vcpu, CPUSTAT_EXT_INT);
@@ -222,7 +217,7 @@ static void set_intercept_indicators_ext(struct kvm_vcpu *vcpu)
static void set_intercept_indicators_mchk(struct kvm_vcpu *vcpu)
{
- if (!(pending_local_irqs(vcpu) & IRQ_PEND_MCHK_MASK))
+ if (!(pending_irqs(vcpu) & IRQ_PEND_MCHK_MASK))
return;
if (psw_mchk_disabled(vcpu))
vcpu->arch.sie_block->ictl |= ICTL_LPSW;
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [GIT PULL 04/10] KVM: s390: kvm_arch_vcpu_runnable already cares about timer interrupts
2015-10-13 14:05 [GIT PULL 00/10] KVM: s390: Fixes for 4.4 Christian Borntraeger
` (2 preceding siblings ...)
2015-10-13 14:06 ` [GIT PULL 03/10] KVM: s390: set interception requests for all floating irqs Christian Borntraeger
@ 2015-10-13 14:06 ` Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 05/10] KVM: s390: drop out early in kvm_s390_has_irq() Christian Borntraeger
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-10-13 14:06 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>
We can remove that double check.
Reviewed-by: Christian Borntraeger <borntraeger@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/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 4f05520..1260f8c 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -839,7 +839,7 @@ int kvm_s390_handle_wait(struct kvm_vcpu *vcpu)
vcpu->stat.exit_wait_state++;
/* fast path */
- if (kvm_cpu_has_pending_timer(vcpu) || kvm_arch_vcpu_runnable(vcpu))
+ if (kvm_arch_vcpu_runnable(vcpu))
return 0;
if (psw_interrupts_disabled(vcpu)) {
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [GIT PULL 05/10] KVM: s390: drop out early in kvm_s390_has_irq()
2015-10-13 14:05 [GIT PULL 00/10] KVM: s390: Fixes for 4.4 Christian Borntraeger
` (3 preceding siblings ...)
2015-10-13 14:06 ` [GIT PULL 04/10] KVM: s390: kvm_arch_vcpu_runnable already cares about timer interrupts Christian Borntraeger
@ 2015-10-13 14:06 ` Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 06/10] KVM: s390: simplify in-kernel program irq injection Christian Borntraeger
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-10-13 14:06 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>
Let's get rid of the local variable and exit directly if we found
any pending interrupt. This is not only faster, but also better
readable.
Reviewed-by: Christian Borntraeger <borntraeger@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/interrupt.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 1260f8c..10a0e8b 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -808,23 +808,21 @@ int kvm_s390_ext_call_pending(struct kvm_vcpu *vcpu)
int kvm_s390_vcpu_has_irq(struct kvm_vcpu *vcpu, int exclude_stop)
{
- int rc;
+ if (deliverable_irqs(vcpu))
+ return 1;
- rc = !!deliverable_irqs(vcpu);
-
- if (!rc && kvm_cpu_has_pending_timer(vcpu))
- rc = 1;
+ if (kvm_cpu_has_pending_timer(vcpu))
+ return 1;
/* external call pending and deliverable */
- if (!rc && kvm_s390_ext_call_pending(vcpu) &&
+ if (kvm_s390_ext_call_pending(vcpu) &&
!psw_extint_disabled(vcpu) &&
(vcpu->arch.sie_block->gcr[0] & 0x2000ul))
- rc = 1;
+ return 1;
- if (!rc && !exclude_stop && kvm_s390_is_stop_irq_pending(vcpu))
- rc = 1;
-
- return rc;
+ if (!exclude_stop && kvm_s390_is_stop_irq_pending(vcpu))
+ return 1;
+ return 0;
}
int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [GIT PULL 06/10] KVM: s390: simplify in-kernel program irq injection
2015-10-13 14:05 [GIT PULL 00/10] KVM: s390: Fixes for 4.4 Christian Borntraeger
` (4 preceding siblings ...)
2015-10-13 14:06 ` [GIT PULL 05/10] KVM: s390: drop out early in kvm_s390_has_irq() Christian Borntraeger
@ 2015-10-13 14:06 ` Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 07/10] KVM: s390: correctly handle injection of pgm irqs and per events Christian Borntraeger
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-10-13 14:06 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>
The main reason to keep program injection in kernel separated until now
was that we were able to do some checking, if really only the owning
thread injects program interrupts (via waitqueue_active(li->wq)).
This BUG_ON was never triggered and the chances of really hitting it, if
another thread injected a program irq to another vcpu, were very small.
Let's drop this check and turn kvm_s390_inject_program_int() and
kvm_s390_inject_prog_irq() into simple inline functions that makes use of
kvm_s390_inject_vcpu().
__must_check can be dropped as they are implicitely given by
kvm_s390_inject_vcpu(), to avoid ugly long function prototypes.
Reviewed-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@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/interrupt.c | 28 ----------------------------
arch/s390/kvm/kvm-s390.h | 24 ++++++++++++++++++++----
2 files changed, 20 insertions(+), 32 deletions(-)
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 10a0e8b..f603bac 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -977,34 +977,6 @@ static int __inject_prog(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)
return 0;
}
-int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code)
-{
- struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
- struct kvm_s390_irq irq;
-
- spin_lock(&li->lock);
- irq.u.pgm.code = code;
- __inject_prog(vcpu, &irq);
- BUG_ON(waitqueue_active(li->wq));
- spin_unlock(&li->lock);
- return 0;
-}
-
-int kvm_s390_inject_prog_irq(struct kvm_vcpu *vcpu,
- struct kvm_s390_pgm_info *pgm_info)
-{
- struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
- struct kvm_s390_irq irq;
- int rc;
-
- spin_lock(&li->lock);
- irq.u.pgm = *pgm_info;
- rc = __inject_prog(vcpu, &irq);
- BUG_ON(waitqueue_active(li->wq));
- spin_unlock(&li->lock);
- return rc;
-}
-
static int __inject_pfault_init(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)
{
struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index c446aab..3a368d2 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -175,6 +175,7 @@ static inline int kvm_s390_user_cpu_state_ctrl(struct kvm *kvm)
return kvm->arch.user_cpu_state_ctrl != 0;
}
+/* implemented in interrupt.c */
int kvm_s390_handle_wait(struct kvm_vcpu *vcpu);
void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu);
enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer);
@@ -185,7 +186,25 @@ int __must_check kvm_s390_inject_vm(struct kvm *kvm,
struct kvm_s390_interrupt *s390int);
int __must_check kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,
struct kvm_s390_irq *irq);
-int __must_check kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code);
+static inline int kvm_s390_inject_prog_irq(struct kvm_vcpu *vcpu,
+ struct kvm_s390_pgm_info *pgm_info)
+{
+ struct kvm_s390_irq irq = {
+ .type = KVM_S390_PROGRAM_INT,
+ .u.pgm = *pgm_info,
+ };
+
+ return kvm_s390_inject_vcpu(vcpu, &irq);
+}
+static inline int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code)
+{
+ struct kvm_s390_irq irq = {
+ .type = KVM_S390_PROGRAM_INT,
+ .u.pgm.code = code,
+ };
+
+ return kvm_s390_inject_vcpu(vcpu, &irq);
+}
struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm,
u64 isc_mask, u32 schid);
int kvm_s390_reinject_io_int(struct kvm *kvm,
@@ -231,9 +250,6 @@ extern unsigned long kvm_s390_fac_list_mask[];
/* implemented in diag.c */
int kvm_s390_handle_diag(struct kvm_vcpu *vcpu);
-/* implemented in interrupt.c */
-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)
{
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [GIT PULL 07/10] KVM: s390: correctly handle injection of pgm irqs and per events
2015-10-13 14:05 [GIT PULL 00/10] KVM: s390: Fixes for 4.4 Christian Borntraeger
` (5 preceding siblings ...)
2015-10-13 14:06 ` [GIT PULL 06/10] KVM: s390: simplify in-kernel program irq injection Christian Borntraeger
@ 2015-10-13 14:06 ` Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 08/10] KVM: s390: switch to get_tod_clock() and fix STP sync races Christian Borntraeger
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-10-13 14:06 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>
PER events can always co-exist with other program interrupts.
For now, we always overwrite all program interrupt parameters when
injecting any type of program interrupt.
Let's handle that correctly by only overwriting the relevant portion of
the program interrupt parameters. Therefore we can now inject PER events
and ordinary program interrupts concurrently, resulting in no loss of
program interrupts. This will especially by helpful when manually detecting
PER events later - as both types might be triggered during one SIE exit.
Reviewed-by: Christian Borntraeger <borntraeger@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/interrupt.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index f603bac..a8be542 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -972,7 +972,26 @@ static int __inject_prog(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)
trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_PROGRAM_INT,
irq->u.pgm.code, 0);
- li->irq.pgm = irq->u.pgm;
+ if (irq->u.pgm.code == PGM_PER) {
+ li->irq.pgm.code |= PGM_PER;
+ /* only modify PER related information */
+ li->irq.pgm.per_address = irq->u.pgm.per_address;
+ li->irq.pgm.per_code = irq->u.pgm.per_code;
+ li->irq.pgm.per_atmid = irq->u.pgm.per_atmid;
+ li->irq.pgm.per_access_id = irq->u.pgm.per_access_id;
+ } else if (!(irq->u.pgm.code & PGM_PER)) {
+ li->irq.pgm.code = (li->irq.pgm.code & PGM_PER) |
+ irq->u.pgm.code;
+ /* only modify non-PER information */
+ li->irq.pgm.trans_exc_code = irq->u.pgm.trans_exc_code;
+ li->irq.pgm.mon_code = irq->u.pgm.mon_code;
+ li->irq.pgm.data_exc_code = irq->u.pgm.data_exc_code;
+ li->irq.pgm.mon_class_nr = irq->u.pgm.mon_class_nr;
+ li->irq.pgm.exc_access_id = irq->u.pgm.exc_access_id;
+ li->irq.pgm.op_access_id = irq->u.pgm.op_access_id;
+ } else {
+ li->irq.pgm = irq->u.pgm;
+ }
set_bit(IRQ_PEND_PROG, &li->pending_irqs);
return 0;
}
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [GIT PULL 08/10] KVM: s390: switch to get_tod_clock() and fix STP sync races
2015-10-13 14:05 [GIT PULL 00/10] KVM: s390: Fixes for 4.4 Christian Borntraeger
` (6 preceding siblings ...)
2015-10-13 14:06 ` [GIT PULL 07/10] KVM: s390: correctly handle injection of pgm irqs and per events Christian Borntraeger
@ 2015-10-13 14:06 ` Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 09/10] KVM: s390: factor out and fix setting of guest TOD clock Christian Borntraeger
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-10-13 14:06 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>
Nobody except early.c makes use of store_tod_clock() to handle the
cc. So if we would get a cc != 0, we would be in more trouble.
Let's replace all users with get_tod_clock(). Returning a cc
on an ioctl sounded strange either way.
We can now also easily move the get_tod_clock() call into the
preempt_disable() section. This is in fact necessary to make the
STP sync work as expected. Otherwise the host TOD could change
and we would end up with a wrong epoch calculation.
Reviewed-by: Christian Borntraeger <borntraeger@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/kvm-s390.c | 18 ++++--------------
arch/s390/kvm/priv.c | 8 ++------
2 files changed, 6 insertions(+), 20 deletions(-)
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 0a67c40..a090779 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -523,19 +523,14 @@ static int kvm_s390_set_tod_low(struct kvm *kvm, struct kvm_device_attr *attr)
{
struct kvm_vcpu *cur_vcpu;
unsigned int vcpu_idx;
- u64 host_tod, gtod;
- int r;
+ u64 gtod;
if (copy_from_user(>od, (void __user *)attr->addr, sizeof(gtod)))
return -EFAULT;
- r = store_tod_clock(&host_tod);
- if (r)
- return r;
-
mutex_lock(&kvm->lock);
preempt_disable();
- kvm->arch.epoch = gtod - host_tod;
+ kvm->arch.epoch = gtod - get_tod_clock();
kvm_s390_vcpu_block_all(kvm);
kvm_for_each_vcpu(vcpu_idx, cur_vcpu, kvm)
cur_vcpu->arch.sie_block->epoch = kvm->arch.epoch;
@@ -581,15 +576,10 @@ static int kvm_s390_get_tod_high(struct kvm *kvm, struct kvm_device_attr *attr)
static int kvm_s390_get_tod_low(struct kvm *kvm, struct kvm_device_attr *attr)
{
- u64 host_tod, gtod;
- int r;
-
- r = store_tod_clock(&host_tod);
- if (r)
- return r;
+ u64 gtod;
preempt_disable();
- gtod = host_tod + kvm->arch.epoch;
+ gtod = get_tod_clock() + kvm->arch.epoch;
preempt_enable();
if (copy_to_user((void __user *)attr->addr, >od, sizeof(gtod)))
return -EFAULT;
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index 4d21dc4..b253de5 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -34,7 +34,7 @@
static int handle_set_clock(struct kvm_vcpu *vcpu)
{
struct kvm_vcpu *cpup;
- s64 hostclk, val;
+ s64 val;
int i, rc;
ar_t ar;
u64 op2;
@@ -49,15 +49,11 @@ static int handle_set_clock(struct kvm_vcpu *vcpu)
if (rc)
return kvm_s390_inject_prog_cond(vcpu, rc);
- if (store_tod_clock(&hostclk)) {
- kvm_s390_set_psw_cc(vcpu, 3);
- return 0;
- }
VCPU_EVENT(vcpu, 3, "SCK: setting guest TOD to 0x%llx", val);
- val = (val - hostclk) & ~0x3fUL;
mutex_lock(&vcpu->kvm->lock);
preempt_disable();
+ val = (val - get_tod_clock()) & ~0x3fUL;
kvm_for_each_vcpu(i, cpup, vcpu->kvm)
cpup->arch.sie_block->epoch = val;
preempt_enable();
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [GIT PULL 09/10] KVM: s390: factor out and fix setting of guest TOD clock
2015-10-13 14:05 [GIT PULL 00/10] KVM: s390: Fixes for 4.4 Christian Borntraeger
` (7 preceding siblings ...)
2015-10-13 14:06 ` [GIT PULL 08/10] KVM: s390: switch to get_tod_clock() and fix STP sync races Christian Borntraeger
@ 2015-10-13 14:06 ` Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 10/10] KVM: s390: factor out reading of the " Christian Borntraeger
2015-10-13 14:45 ` [GIT PULL 00/10] KVM: s390: Fixes for 4.4 Paolo Bonzini
10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-10-13 14:06 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>
Let's move that whole logic into one function. We now always use unsigned
values when calculating the epoch (to avoid over/underflow defined).
Also, we always have to get all VCPUs out of SIE before doing the update
to avoid running differing VCPUs with different TODs.
Acked-by: Christian Borntraeger <borntraeger@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/kvm-s390.c | 28 +++++++++++++++++-----------
arch/s390/kvm/kvm-s390.h | 1 +
arch/s390/kvm/priv.c | 15 +++------------
3 files changed, 21 insertions(+), 23 deletions(-)
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index a090779..87bd602 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -521,22 +521,12 @@ static int kvm_s390_set_tod_high(struct kvm *kvm, struct kvm_device_attr *attr)
static int kvm_s390_set_tod_low(struct kvm *kvm, struct kvm_device_attr *attr)
{
- struct kvm_vcpu *cur_vcpu;
- unsigned int vcpu_idx;
u64 gtod;
if (copy_from_user(>od, (void __user *)attr->addr, sizeof(gtod)))
return -EFAULT;
- mutex_lock(&kvm->lock);
- preempt_disable();
- kvm->arch.epoch = gtod - get_tod_clock();
- kvm_s390_vcpu_block_all(kvm);
- kvm_for_each_vcpu(vcpu_idx, cur_vcpu, kvm)
- cur_vcpu->arch.sie_block->epoch = kvm->arch.epoch;
- kvm_s390_vcpu_unblock_all(kvm);
- preempt_enable();
- mutex_unlock(&kvm->lock);
+ kvm_s390_set_tod_clock(kvm, gtod);
VM_EVENT(kvm, 3, "SET: TOD base: 0x%llx\n", gtod);
return 0;
}
@@ -1906,6 +1896,22 @@ retry:
return 0;
}
+void kvm_s390_set_tod_clock(struct kvm *kvm, u64 tod)
+{
+ struct kvm_vcpu *vcpu;
+ int i;
+
+ mutex_lock(&kvm->lock);
+ preempt_disable();
+ kvm->arch.epoch = tod - get_tod_clock();
+ kvm_s390_vcpu_block_all(kvm);
+ kvm_for_each_vcpu(i, vcpu, kvm)
+ vcpu->arch.sie_block->epoch = kvm->arch.epoch;
+ kvm_s390_vcpu_unblock_all(kvm);
+ preempt_enable();
+ mutex_unlock(&kvm->lock);
+}
+
/**
* kvm_arch_fault_in_page - fault-in guest page if necessary
* @vcpu: The corresponding virtual cpu
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index 3a368d2..cc15ea3 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -231,6 +231,7 @@ int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu);
/* implemented in kvm-s390.c */
+void kvm_s390_set_tod_clock(struct kvm *kvm, u64 tod);
long kvm_arch_fault_in_page(struct kvm_vcpu *vcpu, gpa_t gpa, int writable);
int kvm_s390_store_status_unloaded(struct kvm_vcpu *vcpu, unsigned long addr);
int kvm_s390_store_adtl_status_unloaded(struct kvm_vcpu *vcpu,
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index b253de5..77191b8 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -33,11 +33,9 @@
/* Handle SCK (SET CLOCK) interception */
static int handle_set_clock(struct kvm_vcpu *vcpu)
{
- struct kvm_vcpu *cpup;
- s64 val;
- int i, rc;
+ int rc;
ar_t ar;
- u64 op2;
+ u64 op2, val;
if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
@@ -50,14 +48,7 @@ static int handle_set_clock(struct kvm_vcpu *vcpu)
return kvm_s390_inject_prog_cond(vcpu, rc);
VCPU_EVENT(vcpu, 3, "SCK: setting guest TOD to 0x%llx", val);
-
- mutex_lock(&vcpu->kvm->lock);
- preempt_disable();
- val = (val - get_tod_clock()) & ~0x3fUL;
- kvm_for_each_vcpu(i, cpup, vcpu->kvm)
- cpup->arch.sie_block->epoch = val;
- preempt_enable();
- mutex_unlock(&vcpu->kvm->lock);
+ kvm_s390_set_tod_clock(vcpu->kvm, val);
kvm_s390_set_psw_cc(vcpu, 0);
return 0;
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [GIT PULL 10/10] KVM: s390: factor out reading of the guest TOD clock
2015-10-13 14:05 [GIT PULL 00/10] KVM: s390: Fixes for 4.4 Christian Borntraeger
` (8 preceding siblings ...)
2015-10-13 14:06 ` [GIT PULL 09/10] KVM: s390: factor out and fix setting of guest TOD clock Christian Borntraeger
@ 2015-10-13 14:06 ` Christian Borntraeger
2015-10-13 14:45 ` [GIT PULL 00/10] KVM: s390: Fixes for 4.4 Paolo Bonzini
10 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2015-10-13 14:06 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>
Let's factor this out and always use get_tod_clock_fast() when
reading the guest TOD.
STORE CLOCK FAST does not do serialization and, therefore, might
result in some fuzziness between different processors in a way
that subsequent calls on different CPUs might have time stamps that
are earlier. This semantics is fine though for all KVM use cases.
To make it obvious that the new function has STORE CLOCK FAST
semantics we name it kvm_s390_get_tod_clock_fast.
With this patch, we only have a handful of places were we
have to care about STP sync (using preempt_disable() logic).
Reviewed-by: Christian Borntraeger <borntraeger@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/interrupt.c | 15 +++------------
arch/s390/kvm/kvm-s390.c | 4 +---
arch/s390/kvm/kvm-s390.h | 10 ++++++++++
3 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index a8be542..373e323 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -69,13 +69,8 @@ static int ckc_interrupts_enabled(struct kvm_vcpu *vcpu)
static int ckc_irq_pending(struct kvm_vcpu *vcpu)
{
- preempt_disable();
- if (!(vcpu->arch.sie_block->ckc <
- get_tod_clock_fast() + vcpu->arch.sie_block->epoch)) {
- preempt_enable();
+ if (vcpu->arch.sie_block->ckc >= kvm_s390_get_tod_clock_fast(vcpu->kvm))
return 0;
- }
- preempt_enable();
return ckc_interrupts_enabled(vcpu);
}
@@ -851,9 +846,7 @@ int kvm_s390_handle_wait(struct kvm_vcpu *vcpu)
goto no_timer;
}
- preempt_disable();
- now = get_tod_clock_fast() + vcpu->arch.sie_block->epoch;
- preempt_enable();
+ now = kvm_s390_get_tod_clock_fast(vcpu->kvm);
sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now);
/* underflow */
@@ -892,9 +885,7 @@ enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer)
u64 now, sltime;
vcpu = container_of(timer, struct kvm_vcpu, arch.ckc_timer);
- preempt_disable();
- now = get_tod_clock_fast() + vcpu->arch.sie_block->epoch;
- preempt_enable();
+ now = kvm_s390_get_tod_clock_fast(vcpu->kvm);
sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now);
/*
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 87bd602..618c854 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -568,9 +568,7 @@ static int kvm_s390_get_tod_low(struct kvm *kvm, struct kvm_device_attr *attr)
{
u64 gtod;
- preempt_disable();
- gtod = get_tod_clock() + kvm->arch.epoch;
- preempt_enable();
+ gtod = kvm_s390_get_tod_clock_fast(kvm);
if (copy_to_user((void __user *)attr->addr, >od, sizeof(gtod)))
return -EFAULT;
VM_EVENT(kvm, 3, "QUERY: TOD base: 0x%llx\n", gtod);
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index cc15ea3..1e70e00 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -271,6 +271,16 @@ static inline void kvm_s390_vcpu_unblock_all(struct kvm *kvm)
kvm_s390_vcpu_unblock(vcpu);
}
+static inline u64 kvm_s390_get_tod_clock_fast(struct kvm *kvm)
+{
+ u64 rc;
+
+ preempt_disable();
+ rc = get_tod_clock_fast() + kvm->arch.epoch;
+ preempt_enable();
+ return rc;
+}
+
/**
* kvm_s390_inject_prog_cond - conditionally inject a program check
* @vcpu: virtual cpu
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [GIT PULL 00/10] KVM: s390: Fixes for 4.4
2015-10-13 14:05 [GIT PULL 00/10] KVM: s390: Fixes for 4.4 Christian Borntraeger
` (9 preceding siblings ...)
2015-10-13 14:06 ` [GIT PULL 10/10] KVM: s390: factor out reading of the " Christian Borntraeger
@ 2015-10-13 14:45 ` Paolo Bonzini
10 siblings, 0 replies; 12+ messages in thread
From: Paolo Bonzini @ 2015-10-13 14:45 UTC (permalink / raw)
To: Christian Borntraeger
Cc: Alexander Graf, KVM, Cornelia Huck, Jens Freimann, linux-s390
On 13/10/2015 16:05, Christian Borntraeger wrote:
> Paolo,
>
> The following changes since commit 9ffecb10283508260936b96022d4ee43a7798b4c:
>
> Linux 4.3-rc3 (2015-09-27 07:50:08 -0400)
>
> are available in the git repository at:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-next-20151013
>
> for you to fetch changes up to 60417fcc2b0235dfe3dcd589c56dbe3ea1a64c54:
>
> KVM: s390: factor out reading of the guest TOD clock (2015-10-13 15:50:35 +0200)
>
> ----------------------------------------------------------------
> KVM: s390: Fixes for 4.4
>
> A bunch of fixes and optimizations for interrupt and time
> handling. No fix is important enough to qualify for 4.3 or
> stable.
>
> ----------------------------------------------------------------
> Christian Borntraeger (1):
> KVM: s390: remove unused variable in __inject_vm
>
> David Hildenbrand (9):
> KVM: s390: disabled wait cares about machine checks, not PER
> KVM: s390: set interception requests for all floating irqs
> KVM: s390: kvm_arch_vcpu_runnable already cares about timer interrupts
> KVM: s390: drop out early in kvm_s390_has_irq()
> KVM: s390: simplify in-kernel program irq injection
> KVM: s390: correctly handle injection of pgm irqs and per events
> KVM: s390: switch to get_tod_clock() and fix STP sync races
> KVM: s390: factor out and fix setting of guest TOD clock
> KVM: s390: factor out reading of the guest TOD clock
>
> arch/s390/kvm/interrupt.c | 116 +++++++++++++++++-----------------------------
> arch/s390/kvm/kvm-s390.c | 46 ++++++++----------
> arch/s390/kvm/kvm-s390.h | 35 ++++++++++++--
> arch/s390/kvm/priv.c | 19 ++------
> 4 files changed, 97 insertions(+), 119 deletions(-)
>
Pulled, thanks.
Paolo
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2015-10-13 14:45 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-13 14:05 [GIT PULL 00/10] KVM: s390: Fixes for 4.4 Christian Borntraeger
2015-10-13 14:05 ` [GIT PULL 01/10] KVM: s390: remove unused variable in __inject_vm Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 02/10] KVM: s390: disabled wait cares about machine checks, not PER Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 03/10] KVM: s390: set interception requests for all floating irqs Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 04/10] KVM: s390: kvm_arch_vcpu_runnable already cares about timer interrupts Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 05/10] KVM: s390: drop out early in kvm_s390_has_irq() Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 06/10] KVM: s390: simplify in-kernel program irq injection Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 07/10] KVM: s390: correctly handle injection of pgm irqs and per events Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 08/10] KVM: s390: switch to get_tod_clock() and fix STP sync races Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 09/10] KVM: s390: factor out and fix setting of guest TOD clock Christian Borntraeger
2015-10-13 14:06 ` [GIT PULL 10/10] KVM: s390: factor out reading of the " Christian Borntraeger
2015-10-13 14:45 ` [GIT PULL 00/10] KVM: s390: Fixes for 4.4 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).