cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-s390x-tcg-fix-locking-problem-with-tcg_s390_tod_upda.patch

26ba25
From 4013e52e76cb56a657c58fe03334d72d1ab1824b Mon Sep 17 00:00:00 2001
26ba25
From: David Hildenbrand <david@redhat.com>
26ba25
Date: Fri, 21 Dec 2018 15:36:11 +0000
26ba25
Subject: [PATCH 09/22] s390x/tcg: fix locking problem with
26ba25
 tcg_s390_tod_updated
26ba25
26ba25
RH-Author: David Hildenbrand <david@redhat.com>
26ba25
Message-id: <20181221153614.27961-10-david@redhat.com>
26ba25
Patchwork-id: 83754
26ba25
O-Subject: [RHEL-8.0 qemu-kvm v2 PATCH 09/12] s390x/tcg: fix locking problem with tcg_s390_tod_updated
26ba25
Bugzilla: 1653569
26ba25
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
26ba25
RH-Acked-by: Thomas Huth <thuth@redhat.com>
26ba25
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
26ba25
26ba25
tcg_s390_tod_updated() is always called with the iothread being locked
26ba25
(e.g. from S390TODClass->set() e.g. via HELPER(sck) or on incoming
26ba25
migration). The helper we call takes the lock itself - bad.
26ba25
26ba25
Let's change that by factoring out updating the ckc timer. This now looks
26ba25
much nicer than having to call a helper from another function.
26ba25
26ba25
While touching it we also make sure that env->ckc is updated even if the
26ba25
new value is -1ULL, for now it would not have been modified in that case.
26ba25
26ba25
Reported-by: Christian Borntraeger <borntraeger@de.ibm.com>
26ba25
Signed-off-by: David Hildenbrand <david@redhat.com>
26ba25
Message-Id: <20180629170520.13671-1-david@redhat.com>
26ba25
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
26ba25
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
26ba25
(cherry picked from commit 30c8db0e219a3c1d8b39c19e8b858830cb141738)
26ba25
Signed-off-by: David Hildenbrand <david@redhat.com>
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 target/s390x/misc_helper.c | 26 ++++++++++++++++----------
26ba25
 1 file changed, 16 insertions(+), 10 deletions(-)
26ba25
26ba25
diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c
26ba25
index d629b2f..ffb9f6c 100644
26ba25
--- a/target/s390x/misc_helper.c
26ba25
+++ b/target/s390x/misc_helper.c
26ba25
@@ -150,26 +150,23 @@ uint64_t HELPER(stck)(CPUS390XState *env)
26ba25
     return tod.low;
26ba25
 }
26ba25
 
26ba25
-/* Set Clock Comparator */
26ba25
-void HELPER(sckc)(CPUS390XState *env, uint64_t time)
26ba25
+static void update_ckc_timer(CPUS390XState *env)
26ba25
 {
26ba25
     S390TODState *td = s390_get_todstate();
26ba25
+    uint64_t time;
26ba25
 
26ba25
     /* stop the timer and remove pending CKC IRQs */
26ba25
     timer_del(env->tod_timer);
26ba25
-    qemu_mutex_lock_iothread();
26ba25
+    g_assert(qemu_mutex_iothread_locked());
26ba25
     env->pending_int &= ~INTERRUPT_EXT_CLOCK_COMPARATOR;
26ba25
-    qemu_mutex_unlock_iothread();
26ba25
 
26ba25
     /* the tod has to exceed the ckc, this can never happen if ckc is all 1's */
26ba25
-    if (time == -1ULL) {
26ba25
+    if (env->ckc == -1ULL) {
26ba25
         return;
26ba25
     }
26ba25
 
26ba25
-    env->ckc = time;
26ba25
-
26ba25
     /* difference between origins */
26ba25
-    time -= td->base.low;
26ba25
+    time = env->ckc - td->base.low;
26ba25
 
26ba25
     /* nanoseconds */
26ba25
     time = tod2time(time);
26ba25
@@ -177,12 +174,21 @@ void HELPER(sckc)(CPUS390XState *env, uint64_t time)
26ba25
     timer_mod(env->tod_timer, time);
26ba25
 }
26ba25
 
26ba25
+/* Set Clock Comparator */
26ba25
+void HELPER(sckc)(CPUS390XState *env, uint64_t ckc)
26ba25
+{
26ba25
+    env->ckc = ckc;
26ba25
+
26ba25
+    qemu_mutex_lock_iothread();
26ba25
+    update_ckc_timer(env);
26ba25
+    qemu_mutex_unlock_iothread();
26ba25
+}
26ba25
+
26ba25
 void tcg_s390_tod_updated(CPUState *cs, run_on_cpu_data opaque)
26ba25
 {
26ba25
     S390CPU *cpu = S390_CPU(cs);
26ba25
-    CPUS390XState *env = &cpu->env;
26ba25
 
26ba25
-    helper_sckc(env, env->ckc);
26ba25
+    update_ckc_timer(&cpu->env);
26ba25
 }
26ba25
 
26ba25
 /* Set Clock */
26ba25
-- 
26ba25
1.8.3.1
26ba25