From patchwork Thu Sep 15 11:28:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 9333229 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9CA1B6089F for ; Thu, 15 Sep 2016 11:31:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B14D295BA for ; Thu, 15 Sep 2016 11:31:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FC52295D7; Thu, 15 Sep 2016 11:31:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E4425295BA for ; Thu, 15 Sep 2016 11:31:26 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bkUqf-0004cw-Cd; Thu, 15 Sep 2016 11:28:57 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bkUqe-0004ap-Ug for xen-devel@lists.xen.org; Thu, 15 Sep 2016 11:28:57 +0000 Received: from [85.158.143.35] by server-7.bemta-6.messagelabs.com id D6/EE-15404-8F58AD75; Thu, 15 Sep 2016 11:28:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRWlGSWpSXmKPExsVysyfVTfd7661 wg77FlhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bD+9MZC1ZIVjx8spixgXGCUBcjF4eQwCZG ie+tF5khnNOMEp3ffzN2MXJysAloStz5/IkJxBYRkJa49vkyI0gRs0A7o8Ta/l5mkISwQIJEw 9rLQDYHB4uAqkRLTxZImFfAReLewntgJRICchInj01mBSnhFHCVWPJcFCQsBFRy7MROtgmM3A sYGVYxqhenFpWlFuka6SUVZaZnlOQmZuboGhqY6eWmFhcnpqfmJCYV6yXn525iBHqXAQh2MC7 763SIUZKDSUmU1y3tVrgQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCd59LUA5waLU9NSKtMwcYJjB pCU4eJREeH+ApHmLCxJzizPTIVKnGBWlxCH6BEASGaV5cG2w0L7EKCslzMsIdIgQT0FqUW5mC ar8K0ZxDkYlYd4ukCk8mXklcNNfAS1mAlq8Zc11kMUliQgpqQZG3Usiu9a3vdvDdT3s09Y2rc ztV3f5Ln8h1d8fIrFz7hX2OtWLey5LyZllTHiyfH/rTn/z5HlPuEL5Xx4WOphj7FX8+1N7nHv zj0s23fz1/yflKRyW/frG9ZPV39CMXs+1xoE3bzR+uXxnvuAu0xBG1tMyh2az5Z44cnbymzzm ftMMdVtxUfN0JZbijERDLeai4kQAcnxgIGgCAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-2.tower-21.messagelabs.com!1473938935!19501858!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51515 invoked from network); 15 Sep 2016 11:28:55 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-2.tower-21.messagelabs.com with SMTP; 15 Sep 2016 11:28:55 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 003E46CC; Thu, 15 Sep 2016 04:28:55 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.218.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F2BC73F251; Thu, 15 Sep 2016 04:28:53 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 15 Sep 2016 12:28:22 +0100 Message-Id: <1473938919-31976-7-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1473938919-31976-1-git-send-email-julien.grall@arm.com> References: <1473938919-31976-1-git-send-email-julien.grall@arm.com> Cc: proskurin@sec.in.tum.de, Julien Grall , sstabellini@kernel.org, steve.capper@arm.com, wei.chen@linaro.org Subject: [Xen-devel] [for-4.8][PATCH v2 06/23] xen/arm: traps: Move MMIO emulation code in a separate helper X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently, a stage-2 fault translation will likely access an emulated region. All the checks are pre-sanitity check for MMIO emulation. A follow-up patch will handle a new case that could lead to a stage-2 translation. To improve the clarity of the code and the changes, the current implementation is move in a separate helper. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Keep the break in FSC_FLT_TRANS - Use bool instead of bool_t --- xen/arch/arm/traps.c | 57 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index a5a5384..76e4152 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -2445,6 +2445,38 @@ static void do_trap_instr_abort_guest(struct cpu_user_regs *regs, inject_iabt_exception(regs, gva, hsr.len); } +static bool try_handle_mmio(struct cpu_user_regs *regs, + mmio_info_t *info) +{ + const struct hsr_dabt dabt = info->dabt; + int rc; + + /* stage-1 page table should never live in an emulated MMIO region */ + if ( dabt.s1ptw ) + return false; + + /* All the instructions used on emulated MMIO region should be valid */ + if ( !dabt.valid ) + return false; + + /* + * Erratum 766422: Thumb store translation fault to Hypervisor may + * not have correct HSR Rt value. + */ + if ( check_workaround_766422() && (regs->cpsr & PSR_THUMB) && + dabt.write ) + { + rc = decode_instruction(regs, &info->dabt); + if ( rc ) + { + gprintk(XENLOG_DEBUG, "Unable to decode instruction\n"); + return false; + } + } + + return !!handle_mmio(info); +} + static void do_trap_data_abort_guest(struct cpu_user_regs *regs, const union hsr hsr) { @@ -2488,29 +2520,7 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, break; } case FSC_FLT_TRANS: - if ( dabt.s1ptw ) - goto bad_data_abort; - - /* XXX: Decode the instruction if ISS is not valid */ - if ( !dabt.valid ) - goto bad_data_abort; - - /* - * Erratum 766422: Thumb store translation fault to Hypervisor may - * not have correct HSR Rt value. - */ - if ( check_workaround_766422() && (regs->cpsr & PSR_THUMB) && - dabt.write ) - { - rc = decode_instruction(regs, &info.dabt); - if ( rc ) - { - gprintk(XENLOG_DEBUG, "Unable to decode instruction\n"); - goto bad_data_abort; - } - } - - if ( handle_mmio(&info) ) + if ( try_handle_mmio(regs, &info) ) { advance_pc(regs, hsr); return; @@ -2521,7 +2531,6 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, hsr.bits, dabt.dfsc); } -bad_data_abort: gdprintk(XENLOG_DEBUG, "HSR=0x%x pc=%#"PRIregister" gva=%#"PRIvaddr " gpa=%#"PRIpaddr"\n", hsr.bits, regs->pc, info.gva, info.gpa); inject_dabt_exception(regs, info.gva, hsr.len);