From patchwork Thu Apr 28 09:32:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Alrae X-Patchwork-Id: 8967351 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8C16A9F441 for ; Thu, 28 Apr 2016 09:33:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DDE4620268 for ; Thu, 28 Apr 2016 09:33:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CF0D820256 for ; Thu, 28 Apr 2016 09:33:20 +0000 (UTC) Received: from localhost ([::1]:47436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aviK0-0000CX-69 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 28 Apr 2016 05:33:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aviJg-0008Mt-Bf for qemu-devel@nongnu.org; Thu, 28 Apr 2016 05:33:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aviJf-0001SM-5R for qemu-devel@nongnu.org; Thu, 28 Apr 2016 05:33:00 -0400 Received: from mailapp01.imgtec.com ([195.59.15.196]:7509) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aviJe-0001SA-VL for qemu-devel@nongnu.org; Thu, 28 Apr 2016 05:32:59 -0400 Received: from hhmail02.hh.imgtec.org (unknown [10.100.10.20]) by Websense Email with ESMTPS id 988D48BE9D666; Thu, 28 Apr 2016 10:32:54 +0100 (IST) Received: from localhost.localdomain (192.168.161.74) by hhmail02.hh.imgtec.org (10.100.10.20) with Microsoft SMTP Server (TLS) id 14.3.266.1; Thu, 28 Apr 2016 10:32:57 +0100 From: Leon Alrae To: Date: Thu, 28 Apr 2016 10:32:22 +0100 Message-ID: <1461835942-21213-2-git-send-email-leon.alrae@imgtec.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1461835942-21213-1-git-send-email-leon.alrae@imgtec.com> References: <1461835942-21213-1-git-send-email-leon.alrae@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [192.168.161.74] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.59.15.196 Subject: [Qemu-devel] [PULL for-2.6 1/1] target-mips: Fix RDHWR exception host PC 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: Yongbok Kim , James Hogan , Aurelien Jarno Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: James Hogan Commit b00c72180c36 ("target-mips: add PC, XNP reg numbers to RDHWR") changed the rdhwr helpers to use check_hwrena() to check the register being accessed is enabled in CP0_HWREna when used from user mode. If that check fails an EXCP_RI exception is raised at the host PC calculated with GETPC(). However check_hwrena() may not be fully inlined as the do_raise_exception() part of it is common regardless of the arguments. This causes GETPC() to calculate the address in the call in the helper instead of the generated code calling the helper. No TB will be found and the EPC reported with the resulting guest RI exception points to the beginning of the TB instead of the RDHWR instruction. We can't reliably force check_hwrena() to be inlined, and converting it to a macro would be ugly, so instead pass the host PC in as an argument, with each rdhwr helper passing GETPC(). This should avoid any dependence on compiler behaviour, and in practice seems to ensure the full inlining of check_hwrena() on x86_64. This issue causes failures when running a MIPS KVM (trap & emulate) guest in a MIPS QEMU TCG guest, as the inner guest kernel will do a RDHWR of counter, which is disabled in the outer guest's CP0_HWREna by KVM so it can emulate the inner guest's counter. The emulation fails and the RI exception is passed to the inner guest. Fixes: b00c72180c36 ("target-mips: add PC, XNP reg numbers to RDHWR") Signed-off-by: James Hogan Cc: Leon Alrae Cc: Yongbok Kim Cc: Aurelien Jarno Reviewed-by: Aurelien Jarno Reviewed-by: Leon Alrae Signed-off-by: Leon Alrae --- target-mips/op_helper.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/target-mips/op_helper.c b/target-mips/op_helper.c index 8ec1bef..4417e6b 100644 --- a/target-mips/op_helper.c +++ b/target-mips/op_helper.c @@ -2294,29 +2294,29 @@ void helper_deret(CPUMIPSState *env) } #endif /* !CONFIG_USER_ONLY */ -static inline void check_hwrena(CPUMIPSState *env, int reg) +static inline void check_hwrena(CPUMIPSState *env, int reg, uintptr_t pc) { if ((env->hflags & MIPS_HFLAG_CP0) || (env->CP0_HWREna & (1 << reg))) { return; } - do_raise_exception(env, EXCP_RI, GETPC()); + do_raise_exception(env, EXCP_RI, pc); } target_ulong helper_rdhwr_cpunum(CPUMIPSState *env) { - check_hwrena(env, 0); + check_hwrena(env, 0, GETPC()); return env->CP0_EBase & 0x3ff; } target_ulong helper_rdhwr_synci_step(CPUMIPSState *env) { - check_hwrena(env, 1); + check_hwrena(env, 1, GETPC()); return env->SYNCI_Step; } target_ulong helper_rdhwr_cc(CPUMIPSState *env) { - check_hwrena(env, 2); + check_hwrena(env, 2, GETPC()); #ifdef CONFIG_USER_ONLY return env->CP0_Count; #else @@ -2326,19 +2326,19 @@ target_ulong helper_rdhwr_cc(CPUMIPSState *env) target_ulong helper_rdhwr_ccres(CPUMIPSState *env) { - check_hwrena(env, 3); + check_hwrena(env, 3, GETPC()); return env->CCRes; } target_ulong helper_rdhwr_performance(CPUMIPSState *env) { - check_hwrena(env, 4); + check_hwrena(env, 4, GETPC()); return env->CP0_Performance0; } target_ulong helper_rdhwr_xnp(CPUMIPSState *env) { - check_hwrena(env, 5); + check_hwrena(env, 5, GETPC()); return (env->CP0_Config5 >> CP0C5_XNP) & 1; }