]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
KVM: s390: factor out reading of the guest TOD clock
authorDavid Hildenbrand <dahi@linux.vnet.ibm.com>
Tue, 29 Sep 2015 14:20:36 +0000 (16:20 +0200)
committerChristian Borntraeger <borntraeger@de.ibm.com>
Tue, 13 Oct 2015 13:50:35 +0000 (15:50 +0200)
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
arch/s390/kvm/kvm-s390.c
arch/s390/kvm/kvm-s390.h

index a8be542b9cb087cee8739d9d239de1fbfb10525d..373e32346d68d6c3ae270ca39b96b09fe66b0a6e 100644 (file)
@@ -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);
 
        /*
index 87bd602f326c02053542a7544f3d5d171f97b14e..618c85411a51ea9a6a95cb116ab10098cbf7708d 100644 (file)
@@ -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, &gtod, sizeof(gtod)))
                return -EFAULT;
        VM_EVENT(kvm, 3, "QUERY: TOD base: 0x%llx\n", gtod);
index cc15ea3a150ec51dd24ad4252ae7e2d55e681c4c..1e70e00d3c5ecd4b97df9faa2d7d8b98fabecb58 100644 (file)
@@ -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