From nobody Tue Nov 4 19:07:44 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530531170034123.1786803618055; Mon, 2 Jul 2018 04:32:50 -0700 (PDT) Received: from localhost ([::1]:60217 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fZx4Y-0004RU-5w for importer@patchew.org; Mon, 02 Jul 2018 07:32:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fZwqe-0002MF-Rx for qemu-devel@nongnu.org; Mon, 02 Jul 2018 07:18:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fZwqd-0006J4-2r for qemu-devel@nongnu.org; Mon, 02 Jul 2018 07:18:24 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33502 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 1fZwqc-0006Im-T0; Mon, 02 Jul 2018 07:18:23 -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 7B329C12D1; Mon, 2 Jul 2018 11:18:22 +0000 (UTC) Received: from localhost (ovpn-116-251.ams2.redhat.com [10.36.116.251]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2B2871687C; Mon, 2 Jul 2018 11:18:22 +0000 (UTC) From: Cornelia Huck To: Peter Maydell Date: Mon, 2 Jul 2018 13:17:37 +0200 Message-Id: <20180702111737.18970-16-cohuck@redhat.com> In-Reply-To: <20180702111737.18970-1-cohuck@redhat.com> References: <20180702111737.18970-1-cohuck@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.1]); Mon, 02 Jul 2018 11:18:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 02 Jul 2018 11:18:22 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'cohuck@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] [PULL 15/15] 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 , qemu-s390x@nongnu.org, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand tcg_s390_tod_updated() is always called with the iothread being locked (e.g. from S390TODClass->set() e.g. via HELPER(sck) or on incoming 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 touching 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 Message-Id: <20180629170520.13671-1-david@redhat.com> Reviewed-by: Richard Henderson Signed-off-by: Cornelia Huck --- 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; } =20 -/* Set Clock Comparator */ -void HELPER(sckc)(CPUS390XState *env, uint64_t time) +static void update_ckc_timer(CPUS390XState *env) { S390TODState *td =3D s390_get_todstate(); + uint64_t time; =20 /* 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 &=3D ~INTERRUPT_EXT_CLOCK_COMPARATOR; - qemu_mutex_unlock_iothread(); =20 /* the tod has to exceed the ckc, this can never happen if ckc is all = 1's */ - if (time =3D=3D -1ULL) { + if (env->ckc =3D=3D -1ULL) { return; } =20 - env->ckc =3D time; - /* difference between origins */ - time -=3D td->base.low; + time =3D env->ckc - td->base.low; =20 /* nanoseconds */ time =3D tod2time(time); @@ -176,12 +173,21 @@ void HELPER(sckc)(CPUS390XState *env, uint64_t time) timer_mod(env->tod_timer, time); } =20 +/* Set Clock Comparator */ +void HELPER(sckc)(CPUS390XState *env, uint64_t ckc) +{ + env->ckc =3D 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 =3D S390_CPU(cs); - CPUS390XState *env =3D &cpu->env; =20 - helper_sckc(env, env->ckc); + update_ckc_timer(&cpu->env); } =20 /* Set Clock */ --=20 2.14.4