From nobody Wed May 1 15:57:49 2024 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; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1512451601197526.9819320519508; Mon, 4 Dec 2017 21:26:41 -0800 (PST) Received: from localhost ([::1]:46528 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM5kV-0000uP-07 for importer@patchew.org; Tue, 05 Dec 2017 00:26:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM5jI-0000G0-IU for qemu-devel@nongnu.org; Tue, 05 Dec 2017 00:25:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eM5jH-0004ul-AO for qemu-devel@nongnu.org; Tue, 05 Dec 2017 00:25:16 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:42769) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eM5jG-0004tW-VJ; Tue, 05 Dec 2017 00:25:15 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 3yrVYx5MDHz9s9Y; Tue, 5 Dec 2017 16:25:09 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1512451509; bh=3MTJYRg5K7rpFOuQh1BA2g1lN2MxORLdORnFG/z2Qg4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FXTHN5nXToGbfXUUZzwRLCJx8ax4Q1q6LF1HcuWeUkLLpFu8cNKcQDrHErcrBkAj7 jB1o5YnSgPWkBuCEAprFNd869Ghl0DcAf/HUpORZOzXr9tlbb9pp4e7zcgD+U8Xsff //FTrLcGc0y7eMjH1H6zUPhd+h9Iaq9ksGAbNeHI= From: David Gibson To: peter.maydell@linaro.org Date: Tue, 5 Dec 2017 16:25:01 +1100 Message-Id: <20171205052501.13414-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171205052501.13414-1-david@gibson.dropbear.id.au> References: <20171205052501.13414-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 1/1] target/ppc: Fix system lockups caused by interrupt_request state corruption 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: qemu-devel@nongnu.org, agraf@suse.de, groug@kaod.org, Richard Purdie , qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Richard Purdie Occasionally in Linux guests on x86_64 we're seeing logs like: ppc_set_irq: 0x55b4e0d562f0 n_IRQ 8 level 1 =3D> pending 00000100req 000000= 04 when they should read: ppc_set_irq: 0x55b4e0d562f0 n_IRQ 8 level 1 =3D> pending 00000100req 000000= 02 The "00000004" is CPU_INTERRUPT_EXITTB yet the code calls cpu_interrupt(cs, CPU_INTERRUPT_HARD) ("00000002") in this function just before the log message. Something is causing the HARD bit setting to get lost. The knock on effect of losing that bit is the decrementer timer interrupts don't get delivered which causes the guest to sit idle in its idle handler and 'hang'. The issue occurs due to races from code which sets CPU_INTERRUPT_EXITTB. Rather than poking directly into cs->interrupt_request, that code needs to: a) hold BQL b) use the cpu_interrupt() helper This patch fixes the call sites to do this, fixing the hang. The calls are made from a variety of contexts so a helper function is added to handle the necessary locking. This can likely be improved and optimised in the fut= ure but it ensures the code is correct and doesn't lockup as it stands today. Signed-off-by: Richard Purdie Signed-off-by: David Gibson --- target/ppc/excp_helper.c | 7 +++---- target/ppc/helper_regs.h | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index e6009e70e5..37d2410726 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -207,7 +207,7 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int ex= cp_model, int excp) "Entering checkstop state\n"); } cs->halted =3D 1; - cs->interrupt_request |=3D CPU_INTERRUPT_EXITTB; + cpu_interrupt_exittb(cs); } if (env->msr_mask & MSR_HVB) { /* ISA specifies HV, but can be delivered to guest with HV cle= ar @@ -940,7 +940,7 @@ void helper_store_msr(CPUPPCState *env, target_ulong va= l) =20 if (excp !=3D 0) { CPUState *cs =3D CPU(ppc_env_get_cpu(env)); - cs->interrupt_request |=3D CPU_INTERRUPT_EXITTB; + cpu_interrupt_exittb(cs); raise_exception(env, excp); } } @@ -995,8 +995,7 @@ static inline void do_rfi(CPUPPCState *env, target_ulon= g nip, target_ulong msr) /* No need to raise an exception here, * as rfi is always the last insn of a TB */ - cs->interrupt_request |=3D CPU_INTERRUPT_EXITTB; - + cpu_interrupt_exittb(cs); /* Reset the reservation */ env->reserve_addr =3D -1; =20 diff --git a/target/ppc/helper_regs.h b/target/ppc/helper_regs.h index 2627a70176..84fd30c2db 100644 --- a/target/ppc/helper_regs.h +++ b/target/ppc/helper_regs.h @@ -20,6 +20,8 @@ #ifndef HELPER_REGS_H #define HELPER_REGS_H =20 +#include "qemu/main-loop.h" + /* Swap temporary saved registers with GPRs */ static inline void hreg_swap_gpr_tgpr(CPUPPCState *env) { @@ -96,6 +98,17 @@ static inline void hreg_compute_hflags(CPUPPCState *env) env->hflags |=3D env->hflags_nmsr; } =20 +static inline void cpu_interrupt_exittb(CPUState *cs) +{ + if (!qemu_mutex_iothread_locked()) { + qemu_mutex_lock_iothread(); + cpu_interrupt(cs, CPU_INTERRUPT_EXITTB); + qemu_mutex_unlock_iothread(); + } else { + cpu_interrupt(cs, CPU_INTERRUPT_EXITTB); + } +} + static inline int hreg_store_msr(CPUPPCState *env, target_ulong value, int alter_hv) { @@ -114,11 +127,11 @@ static inline int hreg_store_msr(CPUPPCState *env, ta= rget_ulong value, } if (((value >> MSR_IR) & 1) !=3D msr_ir || ((value >> MSR_DR) & 1) !=3D msr_dr) { - cs->interrupt_request |=3D CPU_INTERRUPT_EXITTB; + cpu_interrupt_exittb(cs); } if ((env->mmu_model & POWERPC_MMU_BOOKE) && ((value >> MSR_GS) & 1) !=3D msr_gs) { - cs->interrupt_request |=3D CPU_INTERRUPT_EXITTB; + cpu_interrupt_exittb(cs); } if (unlikely((env->flags & POWERPC_FLAG_TGPR) && ((value ^ env->msr) & (1 << MSR_TGPR)))) { --=20 2.14.3