From patchwork Fri Jun 29 17:05:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 937038 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41HNMq0gKQz9rvt for ; Sat, 30 Jun 2018 03:06:15 +1000 (AEST) Received: from localhost ([::1]:43603 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYwqa-00072c-JN for incoming@patchwork.ozlabs.org; Fri, 29 Jun 2018 13:06:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39015) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYwpu-000714-4J for qemu-devel@nongnu.org; Fri, 29 Jun 2018 13:05:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYwpp-0007OP-6s for qemu-devel@nongnu.org; Fri, 29 Jun 2018 13:05:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38346 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYwpp-0007Nl-2T; Fri, 29 Jun 2018 13:05:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9A9E57A7E5; Fri, 29 Jun 2018 17:05:24 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-133.ams2.redhat.com [10.36.116.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 846B951DD; Fri, 29 Jun 2018 17:05:21 +0000 (UTC) From: David Hildenbrand To: qemu-s390x@nongnu.org Date: Fri, 29 Jun 2018 19:05:20 +0200 Message-Id: <20180629170520.13671-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 29 Jun 2018 17:05:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 29 Jun 2018 17:05:24 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v1] s390x/tcg: fix locking problem with tcg_s390_tod_updated X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , David Hildenbrand , Cornelia Huck , Alexander Graf , qemu-devel@nongnu.org, Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" tcg_s390_tod_updated() is always called with the iothread being locked (e.g. from S390TODClass->set() e.g. via HELPER(sck) or on incomming migration). The helper we call takes the lock itself - bad. Let's change that by factoring out updating the ckc timer. This now looks much nicer than having to call a helper from another function. While touch it we also make sure that env->ckc is updated even if the new value is -1ULL, for now it would not have been modified in that case. Reported-by: Christian Borntraeger Signed-off-by: David Hildenbrand Reviewed-by: Richard Henderson --- This survives my tests and the iotests Christian mentioned. target/s390x/misc_helper.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c index 7656a9b90a..3f91579570 100644 --- a/target/s390x/misc_helper.c +++ b/target/s390x/misc_helper.c @@ -149,26 +149,23 @@ uint64_t HELPER(stck)(CPUS390XState *env) return tod.low; } -/* Set Clock Comparator */ -void HELPER(sckc)(CPUS390XState *env, uint64_t time) +static void update_ckc_timer(CPUS390XState *env) { S390TODState *td = s390_get_todstate(); + uint64_t time; /* stop the timer and remove pending CKC IRQs */ timer_del(env->tod_timer); - qemu_mutex_lock_iothread(); + g_assert(qemu_mutex_iothread_locked()); env->pending_int &= ~INTERRUPT_EXT_CLOCK_COMPARATOR; - qemu_mutex_unlock_iothread(); /* the tod has to exceed the ckc, this can never happen if ckc is all 1's */ - if (time == -1ULL) { + if (env->ckc == -1ULL) { return; } - env->ckc = time; - /* difference between origins */ - time -= td->base.low; + time = env->ckc - td->base.low; /* nanoseconds */ time = tod2time(time); @@ -176,12 +173,21 @@ void HELPER(sckc)(CPUS390XState *env, uint64_t time) timer_mod(env->tod_timer, time); } +/* Set Clock Comparator */ +void HELPER(sckc)(CPUS390XState *env, uint64_t ckc) +{ + env->ckc = ckc; + + qemu_mutex_lock_iothread(); + update_ckc_timer(env); + qemu_mutex_unlock_iothread(); +} + void tcg_s390_tod_updated(CPUState *cs, run_on_cpu_data opaque) { S390CPU *cpu = S390_CPU(cs); - CPUS390XState *env = &cpu->env; - helper_sckc(env, env->ckc); + update_ckc_timer(&cpu->env); } /* Set Clock */