From patchwork Tue Mar 7 15:50:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 95006 Delivered-To: patch@linaro.org Received: by 10.140.82.71 with SMTP id g65csp1952750qgd; Tue, 7 Mar 2017 08:08:10 -0800 (PST) X-Received: by 10.25.125.132 with SMTP id y126mr351136lfc.102.1488902889907; Tue, 07 Mar 2017 08:08:09 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b17si177712lfb.75.2017.03.07.08.08.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 07 Mar 2017 08:08:09 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51417 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHei-0000IB-AG for patch@linaro.org; Tue, 07 Mar 2017 11:08:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clHO4-0002SY-4w for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:50:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clHO3-0005qF-4E for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:50:56 -0500 Received: from mail-wr0-x231.google.com ([2a00:1450:400c:c0c::231]:33405) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1clHO2-0005px-KA for qemu-devel@nongnu.org; Tue, 07 Mar 2017 10:50:54 -0500 Received: by mail-wr0-x231.google.com with SMTP id u48so4379024wrc.0 for ; Tue, 07 Mar 2017 07:50:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xghB2+k6vzdm0OczMY4d5pjgKabpj0Re/RUs8e6z0kw=; b=HCrduoSAhTyjIJ/mR1ArsJb9us5E7JWGhAW6OOeeYxt0z/PbrQ25KLN0c/hYKtNI96 ORZf38SKPugYMlbVyjt/wNfNw6cWrSWC23cUxadfSRi4Ti6IyLsMjG1h5bofu77wyUjP rAjXU4UtKT9+QDt0QRL3U+W+2jUOUCuPw0JK8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xghB2+k6vzdm0OczMY4d5pjgKabpj0Re/RUs8e6z0kw=; b=kvcUaamtUV57RrkRQ31+WPkk1U3prKovAKe7pb/qoUWXtb9Rg01ZugdVurXoJpHWEs 2dI6AdlIEoCsNTr/ROdHhooc2dAVu3ld5b940moaE+F2zQId1S7VuFNMqdMnMeO3/LbO Ajrz6n5XRkB1siqYX9jHDDNo+geSK9JiDM+2PX7rbgMKa9xzEmz88JTbLo77fockFN3p qKEBVW6AijKl1BmaL/f0q4b609pqgY24nhQv/6oR56E/87ItwN+0Dzbu0emFY3cfweAb yAmk51hDgiETxGaYmuiXgKAocCj9+d35Zxrs7c5/c5UXezd+AKrF4+Fu/ysvUFgW+PmJ MYmg== X-Gm-Message-State: AMke39lLgLe86XKmjCFBnoNyXaER768jKQjM0/z+f9C20ZLD1yeh+r7NKv9+OPaqtLfy9Iyr X-Received: by 10.223.136.182 with SMTP id f51mr841671wrf.90.1488901853358; Tue, 07 Mar 2017 07:50:53 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id t103sm479237wrc.43.2017.03.07.07.50.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Mar 2017 07:50:49 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id B99513E3009; Tue, 7 Mar 2017 15:50:54 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org, rth@twiddle.net, pbonzini@redhat.com Date: Tue, 7 Mar 2017 15:50:47 +0000 Message-Id: <20170307155054.5833-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170307155054.5833-1-alex.bennee@linaro.org> References: <20170307155054.5833-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::231 Subject: [Qemu-devel] [PATCH v3 04/11] sparc/sparc64: grab BQL before calling cpu_check_irqs 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: mttcg@listserver.greensocs.com, nikunj@linux.vnet.ibm.com, Mark Cave-Ayland , a.rigo@virtualopensystems.com, qemu-devel@nongnu.org, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Artyom Tarasenko , fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" IRQ modification is part of device emulation and should be done while the BQL is held to prevent races when MTTCG is enabled. This adds assertions in the hw emulation layer and wraps the calls from helpers in the BQL. Reported-by: Mark Cave-Ayland Signed-off-by: Alex Bennée --- v3 - move BQL from cpu_put_psr to helper_wpsr - comment cpu_put_psr is under BQL --- hw/sparc/sun4m.c | 3 +++ hw/sparc64/sparc64.c | 3 +++ target/sparc/int64_helper.c | 3 +++ target/sparc/win_helper.c | 13 +++++++++++++ 4 files changed, 22 insertions(+) -- 2.11.0 diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c index 61416a6426..873cd7df9a 100644 --- a/hw/sparc/sun4m.c +++ b/hw/sparc/sun4m.c @@ -142,6 +142,9 @@ void cpu_check_irqs(CPUSPARCState *env) { CPUState *cs; + /* We should be holding the BQL before we mess with IRQs */ + g_assert(qemu_mutex_iothread_locked()); + if (env->pil_in && (env->interrupt_index == 0 || (env->interrupt_index & ~15) == TT_EXTINT)) { unsigned int i; diff --git a/hw/sparc64/sparc64.c b/hw/sparc64/sparc64.c index b3d219c769..4e4fdab065 100644 --- a/hw/sparc64/sparc64.c +++ b/hw/sparc64/sparc64.c @@ -55,6 +55,9 @@ void cpu_check_irqs(CPUSPARCState *env) uint32_t pil = env->pil_in | (env->softint & ~(SOFTINT_TIMER | SOFTINT_STIMER)); + /* We should be holding the BQL before we mess with IRQs */ + g_assert(qemu_mutex_iothread_locked()); + /* TT_IVEC has a higher priority (16) than TT_EXTINT (31..17) */ if (env->ivec_status & 0x20) { return; diff --git a/target/sparc/int64_helper.c b/target/sparc/int64_helper.c index 605747c93c..f942973c22 100644 --- a/target/sparc/int64_helper.c +++ b/target/sparc/int64_helper.c @@ -18,6 +18,7 @@ */ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "cpu.h" #include "exec/helper-proto.h" #include "exec/log.h" @@ -208,7 +209,9 @@ static bool do_modify_softint(CPUSPARCState *env, uint32_t value) env->softint = value; #if !defined(CONFIG_USER_ONLY) if (cpu_interrupts_enabled(env)) { + qemu_mutex_lock_iothread(); cpu_check_irqs(env); + qemu_mutex_unlock_iothread(); } #endif return true; diff --git a/target/sparc/win_helper.c b/target/sparc/win_helper.c index 71b3dd37e8..154279ecda 100644 --- a/target/sparc/win_helper.c +++ b/target/sparc/win_helper.c @@ -18,6 +18,7 @@ */ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "cpu.h" #include "exec/exec-all.h" #include "exec/helper-proto.h" @@ -82,6 +83,7 @@ void cpu_put_psr_raw(CPUSPARCState *env, target_ulong val) #endif } +/* Called with BQL held */ void cpu_put_psr(CPUSPARCState *env, target_ulong val) { cpu_put_psr_raw(env, val); @@ -153,7 +155,10 @@ void helper_wrpsr(CPUSPARCState *env, target_ulong new_psr) if ((new_psr & PSR_CWP) >= env->nwindows) { cpu_raise_exception_ra(env, TT_ILL_INSN, GETPC()); } else { + /* cpu_put_psr may trigger interrupts, hence BQL */ + qemu_mutex_lock_iothread(); cpu_put_psr(env, new_psr); + qemu_mutex_unlock_iothread(); } } @@ -368,7 +373,9 @@ void helper_wrpstate(CPUSPARCState *env, target_ulong new_state) #if !defined(CONFIG_USER_ONLY) if (cpu_interrupts_enabled(env)) { + qemu_mutex_lock_iothread(); cpu_check_irqs(env); + qemu_mutex_unlock_iothread(); } #endif } @@ -381,7 +388,9 @@ void helper_wrpil(CPUSPARCState *env, target_ulong new_pil) env->psrpil = new_pil; if (cpu_interrupts_enabled(env)) { + qemu_mutex_lock_iothread(); cpu_check_irqs(env); + qemu_mutex_unlock_iothread(); } #endif } @@ -408,7 +417,9 @@ void helper_done(CPUSPARCState *env) #if !defined(CONFIG_USER_ONLY) if (cpu_interrupts_enabled(env)) { + qemu_mutex_lock_iothread(); cpu_check_irqs(env); + qemu_mutex_unlock_iothread(); } #endif } @@ -435,7 +446,9 @@ void helper_retry(CPUSPARCState *env) #if !defined(CONFIG_USER_ONLY) if (cpu_interrupts_enabled(env)) { + qemu_mutex_lock_iothread(); cpu_check_irqs(env); + qemu_mutex_unlock_iothread(); } #endif }