All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: linux-s390@vger.kernel.org, kvm@vger.kernel.org
Cc: Christian Borntraeger <borntraeger@de.ibm.com>,
	Cornelia Huck <cohuck@redhat.com>,
	Janosch Frank <frankja@linux.vnet.ibm.com>,
	David Hildenbrand <david@redhat.com>
Subject: [PATCH RFC 1/6] KVM: s390: take care of clock-comparator sign control
Date: Wed,  7 Feb 2018 12:46:42 +0100	[thread overview]
Message-ID: <20180207114647.6220-2-david@redhat.com> (raw)
In-Reply-To: <20180207114647.6220-1-david@redhat.com>

Missed when enabling the Multiple-epoch facility. If the facility is
installed and the control is set, a sign based comaprison has to be
performed.

Right now we would inject wrong interrupts and ignore interrupt
conditions. Also the sleep time is calculated in a wrong way.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 arch/s390/kvm/interrupt.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 3ea9cfa31b16..a616e9b65f91 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -169,8 +169,15 @@ static int ckc_interrupts_enabled(struct kvm_vcpu *vcpu)
 
 static int ckc_irq_pending(struct kvm_vcpu *vcpu)
 {
-	if (vcpu->arch.sie_block->ckc >= kvm_s390_get_tod_clock_fast(vcpu->kvm))
+	const u64 now = kvm_s390_get_tod_clock_fast(vcpu->kvm);
+	const u64 ckc = vcpu->arch.sie_block->ckc;
+
+	if (vcpu->arch.sie_block->gcr[0] & 0x0020000000000000ul) {
+		if ((s64)ckc >= (s64)now)
+			return 0;
+	} else if (ckc >= now) {
 		return 0;
+	}
 	return ckc_interrupts_enabled(vcpu);
 }
 
@@ -1042,13 +1049,19 @@ int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
 
 static u64 __calculate_sltime(struct kvm_vcpu *vcpu)
 {
-	u64 now, cputm, sltime = 0;
+	const u64 now = kvm_s390_get_tod_clock_fast(vcpu->kvm);
+	const u64 ckc = vcpu->arch.sie_block->ckc;
+	u64 cputm, sltime = 0;
 
 	if (ckc_interrupts_enabled(vcpu)) {
-		now = kvm_s390_get_tod_clock_fast(vcpu->kvm);
-		sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now);
-		/* already expired or overflow? */
-		if (!sltime || vcpu->arch.sie_block->ckc <= now)
+		if (vcpu->arch.sie_block->gcr[0] & 0x0020000000000000ul) {
+			if ((s64)now < (s64)ckc)
+				sltime = tod_to_ns((s64)ckc - (s64)now);
+		} else if (now < ckc) {
+			sltime = tod_to_ns(ckc - now);
+		}
+		/* already expired */
+		if (!sltime)
 			return 0;
 		if (cpu_timer_interrupts_enabled(vcpu)) {
 			cputm = kvm_s390_get_cpu_timer(vcpu);
-- 
2.14.3

  reply	other threads:[~2018-02-07 11:46 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-07 11:46 [PATCH RFC 0/6] KVM: s390: Multiple-epoch facility fixes David Hildenbrand
2018-02-07 11:46 ` David Hildenbrand [this message]
2018-02-07 13:47   ` [PATCH RFC 1/6] KVM: s390: take care of clock-comparator sign control Collin L. Walling
2018-02-07 13:58     ` David Hildenbrand
2018-02-07 14:06       ` Christian Borntraeger
2018-02-16  9:45   ` Christian Borntraeger
2018-03-07  3:54   ` Patch "KVM: s390: take care of clock-comparator sign control" has been added to the 4.14-stable tree gregkh
2018-03-07  3:54   ` Patch "KVM: s390: take care of clock-comparator sign control" has been added to the 4.15-stable tree gregkh
2018-02-07 11:46 ` [PATCH RFC 2/6] KVM: s390: provide only a single function for setting the tod David Hildenbrand
2018-02-07 20:13   ` Collin L. Walling
2018-02-07 20:15     ` Collin L. Walling
2018-02-07 21:42     ` David Hildenbrand
2018-03-07  3:54   ` Patch "KVM: s390: provide only a single function for setting the tod (fix SCK)" has been added to the 4.14-stable tree gregkh
2018-03-07  3:54   ` Patch "KVM: s390: provide only a single function for setting the tod (fix SCK)" has been added to the 4.15-stable tree gregkh
2018-02-07 11:46 ` [PATCH RFC 3/6] KVM: s390: consider epoch index on hotplugged CPUs David Hildenbrand
2018-02-15 13:09   ` Cornelia Huck
2018-02-16  9:50   ` Christian Borntraeger
2018-03-07  3:54   ` Patch "KVM: s390: consider epoch index on hotplugged CPUs" has been added to the 4.14-stable tree gregkh
2018-03-07  3:54   ` Patch "KVM: s390: consider epoch index on hotplugged CPUs" has been added to the 4.15-stable tree gregkh
2018-02-07 11:46 ` [PATCH RFC 4/6] KVM: s390: consider epoch index on TOD clock syncs David Hildenbrand
2018-02-07 20:08   ` Collin L. Walling
2018-02-07 21:35     ` David Hildenbrand
2018-02-07 22:43       ` Collin L. Walling
2018-02-08 12:15         ` David Hildenbrand
2018-03-07  3:54   ` Patch "KVM: s390: consider epoch index on TOD clock syncs" has been added to the 4.14-stable tree gregkh
2018-03-07  3:54   ` Patch "KVM: s390: consider epoch index on TOD clock syncs" has been added to the 4.15-stable tree gregkh
2018-02-07 11:46 ` [PATCH RFC 5/6] KVM: s390: no need to inititalize kvm->arch members to 0 David Hildenbrand
2018-02-15 13:25   ` Cornelia Huck
2018-02-07 11:46 ` [PATCH RFC 6/6] KVM: s390: generalize kvm_s390_get_tod_clock_ext() David Hildenbrand
2018-02-15 14:08   ` Cornelia Huck
2018-02-15 14:14     ` David Hildenbrand
2018-02-15 14:17       ` Cornelia Huck
2018-02-15 14:25         ` David Hildenbrand
2018-02-07 11:50 ` [PATCH RFC 0/6] KVM: s390: Multiple-epoch facility fixes David Hildenbrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180207114647.6220-2-david@redhat.com \
    --to=david@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=frankja@linux.vnet.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.