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

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