From nobody Thu May 2 13:49:17 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; 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1512145658202576.3878957305493; Fri, 1 Dec 2017 08:27:38 -0800 (PST) Received: from localhost ([::1]:58521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eKo9p-0003Pr-CI for importer@patchew.org; Fri, 01 Dec 2017 11:27:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56491) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eKncP-00062y-V4 for qemu-devel@nongnu.org; Fri, 01 Dec 2017 10:53:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eKnbn-0006ap-Iv for qemu-devel@nongnu.org; Fri, 01 Dec 2017 10:52:49 -0500 Received: from 5751f4a1.skybroadband.com ([87.81.244.161]:53677 helo=dan.rpsys.net) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eKnZI-0003SQ-OQ; Fri, 01 Dec 2017 10:49:36 -0500 Received: from hex ([192.168.3.34]) (authenticated bits=0) by dan.rpsys.net (8.15.2/8.15.2/Debian-3) with ESMTPSA id vB1FnJ5r014762 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 1 Dec 2017 15:49:20 GMT Received: from richard by hex with local (Exim 4.86_2) (envelope-from ) id 1eKnZ1-0005FK-1s; Fri, 01 Dec 2017 15:49:19 +0000 From: Richard Purdie To: qemu-devel@nongnu.org, david@gibson.dropbear.id.au Date: Fri, 1 Dec 2017 15:49:07 +0000 Message-Id: <1512143347-20128-1-git-send-email-richard.purdie@linuxfoundation.org> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: clamav-milter 0.99.2 at dan X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 87.81.244.161 Subject: [Qemu-devel] [PATCH v2] 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: Richard Purdie , qemu-ppc@nongnu.org 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" 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. Signed-off-by: Richard Purdie --- target/ppc/excp_helper.c | 16 +++++++++++++--- target/ppc/helper_regs.h | 10 ++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) v2: Fixes a compile issue with master and ensures BQL is held in one case where it potentially wasn't. diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index e6009e7..8040277 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -207,7 +207,13 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int e= xcp_model, int excp) "Entering checkstop state\n"); } cs->halted =3D 1; - cs->interrupt_request |=3D CPU_INTERRUPT_EXITTB; + 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); + } } if (env->msr_mask & MSR_HVB) { /* ISA specifies HV, but can be delivered to guest with HV cle= ar @@ -940,7 +946,9 @@ 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; + qemu_mutex_lock_iothread(); + cpu_interrupt(cs, CPU_INTERRUPT_EXITTB); + qemu_mutex_unlock_iothread(); raise_exception(env, excp); } } @@ -995,7 +1003,9 @@ static inline void do_rfi(CPUPPCState *env, target_ulo= ng 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; + qemu_mutex_lock_iothread(); + cpu_interrupt(cs, CPU_INTERRUPT_EXITTB); + qemu_mutex_unlock_iothread(); =20 /* Reset the reservation */ env->reserve_addr =3D -1; diff --git a/target/ppc/helper_regs.h b/target/ppc/helper_regs.h index 2627a70..0beaad5 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) { @@ -114,11 +116,15 @@ 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; + qemu_mutex_lock_iothread(); + cpu_interrupt(cs, CPU_INTERRUPT_EXITTB); + qemu_mutex_unlock_iothread(); } if ((env->mmu_model & POWERPC_MMU_BOOKE) && ((value >> MSR_GS) & 1) !=3D msr_gs) { - cs->interrupt_request |=3D CPU_INTERRUPT_EXITTB; + qemu_mutex_lock_iothread(); + cpu_interrupt(cs, CPU_INTERRUPT_EXITTB); + qemu_mutex_unlock_iothread(); } if (unlikely((env->flags & POWERPC_FLAG_TGPR) && ((value ^ env->msr) & (1 << MSR_TGPR)))) { --=20 2.7.4