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

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