Received: from eggs.gnu.org ([2001:4830:134:3::10]:38557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ai0YV-00005d-MD for qemu-devel@nongnu.org; Mon, 21 Mar 2016 10:11:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ai0YP-0000ER-UM for qemu-devel@nongnu.org; Mon, 21 Mar 2016 10:11:39 -0400 Received: from e06smtp06.uk.ibm.com ([195.75.94.102]:39892) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ai0YP-0000EK-M1 for qemu-devel@nongnu.org; Mon, 21 Mar 2016 10:11:33 -0400 Received: from localhost by e06smtp06.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 21 Mar 2016 14:11:32 -0000 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Date: Mon, 21 Mar 2016 15:02:08 +0100 Message-Id: <1458568928-3055-3-git-send-email-clg@fr.ibm.com> In-Reply-To: <1458568928-3055-1-git-send-email-clg@fr.ibm.com> References: <1458568928-3055-1-git-send-email-clg@fr.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [RFC PATCH 2/2] target-ppc: fix interrupt vectors address migration List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Gibson Cc: Thomas Huth , Mark Cave-Ayland , qemu-devel@nongnu.org, Alexander Graf , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , qemu-ppc@nongnu.org commit 2360b6e84f78 ("target-ppc: force update of msr bits in cpu_post_load") introduced a change to restore env->excp_prefix of a guest which could have altered its MSR_EP. To do this, cpu_post_load() invalidates msr and then calls ppc_store_msr() with the expected value in argument. The problem is that ppc_store_msr() relies on a 'valid' current msr before changing its value. The MSR_HVB and MSR_TGPR bits are excluded from the msr reset to keep the checks valid but the MSR_IR, MSR_DR, MSR_EP bits which are also used through the msr_{ir,dr,ep} macros, are reseted. This is an issue for CPUs not using MSR_EP, on the spapr platform for instance but all book3s are impacted. If excp_prefix is restored to some value, it will be reseted by this call, causing an ISEG exception on spapr guests. This patch proposal is to test the msr_mask before actually testing the MSR_EP bit and protect excp_prefix. Signed-off-by: Cédric Le Goater --- Should we just move the test in cpu_post_load() and not reset MSR_EP if it is not present in msr_mask ? like this is done for MSR_HVB and MSR_TGPR. I think this is making assumptions on what ppc_store_msr() is up to though. Maybe we could add a POWERPC_FLAGS_ for this purpose ? or test the excp_model ? There is room for improvement in ppc_store_msr(). It might need a new helper like ppc_restore_msr() ? Suggestions welcomed. target-ppc/helper_regs.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/target-ppc/helper_regs.h b/target-ppc/helper_regs.h index 271fddf17f0a..2a72e000ed83 100644 --- a/target-ppc/helper_regs.h +++ b/target-ppc/helper_regs.h @@ -92,9 +92,11 @@ static inline int hreg_store_msr(CPUPPCState *env, target_ulong value, /* Swap temporary saved registers with GPRs */ hreg_swap_gpr_tgpr(env); } - if (unlikely((value >> MSR_EP) & 1) != msr_ep) { - /* Change the exception prefix on PowerPC 601 */ - env->excp_prefix = ((value >> MSR_EP) & 1) * 0xFFF00000; + if ((env->msr_mask >> MSR_EP) & 1) { + if (unlikely((value >> MSR_EP) & 1) != msr_ep) { + /* Change the exception prefix on PowerPC 601 */ + env->excp_prefix = ((value >> MSR_EP) & 1) * 0xFFF00000; + } } #endif env->msr = value; -- 2.1.4