From patchwork Fri Feb 2 10:14:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 126629 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp495913ljc; Fri, 2 Feb 2018 02:17:43 -0800 (PST) X-Google-Smtp-Source: AH8x227FHOJ/4WWBFJTnn6Zdn/gZcdCdtPgR49kwEQtbA58+w4B91Dqi+YAJ2Ewlw2N871fFAK7T X-Received: by 10.36.31.5 with SMTP id d5mr2375340itd.136.1517566663099; Fri, 02 Feb 2018 02:17:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517566663; cv=none; d=google.com; s=arc-20160816; b=m7vIRqTAQZeuUl8Ii6ptl8mvCh2/Gi5nElNfkFJNcmlbax1IL8nr4yKLVeCw+9lus5 6TkbVgOfSnmwEeQGRnNDU/LPjKstavusADNkO8Sonf9Dk+rJByft8QhnsSc6aEsCGF9j YLDPnnZt/jfpbnSbbJRiiOdrOSRCKJ108OJhYVhoNY1IMbGux3HcEJtGiMwHyTXxzQzw NQnZNhIxJ1ELIWsNMNXINPXOokWk76FOlmbwxoj3G92iB6D3rZbpluK0siOxd+EZcvl+ IDRaa4R+To60egPmKcbhQhi7nK7EcXS7JS8Xwn6efB5Qu+NS/OEMj2SyijlvnDFwW5Mn eq2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:arc-authentication-results; bh=y7JVZ1Z8T36nf0fodl5PV2JPiHx9wLmpqvh8XJ506uc=; b=J8rFWqiCd1zoeWoIgBtXjZml6h25yW+NDPiJbDnUNCu7Iu7sdiubu/heisJPDJHnCm +tAb5NGMI4XnJXPQrL+cMhhJmzTTn+6upxfX2s8dOyDwZfWZvdNWyOOyIOZu3dN1gXVZ 0EEd5UCIcLkGDdSaOlV54fYeC/p2PAcpQCG+fUPENS+949T4gHP7peJwIazB3IqHb/5w BiT7U0jLjzEIQhdvTk7ecMsj2g3WOVykMWaQfasjkuYo1P3i3/0ig6hiMBL9rGaYsS9k x/pOo78H7URpympdhzHEyKZcyD/GBVt+QI7PoJ99D75HM2TikAeix2u61MhP8A3hBLYm XwxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id b11si1485967iob.148.2018.02.02.02.17.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Feb 2018 02:17:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ehYMy-0006FM-CV; Fri, 02 Feb 2018 10:14:56 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ehYMx-0006FF-Ct for xen-devel@lists.xen.org; Fri, 02 Feb 2018 10:14:55 +0000 X-Inumbo-ID: dec3b296-0801-11e8-ba59-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id dec3b296-0801-11e8-ba59-bc764e045a96; Fri, 02 Feb 2018 11:14:36 +0100 (CET) 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 D92EB1596; Fri, 2 Feb 2018 02:14:52 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CA1E93F487; Fri, 2 Feb 2018 02:14:51 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Fri, 2 Feb 2018 10:14:41 +0000 Message-Id: <20180202101444.3510-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180202101444.3510-1-julien.grall@arm.com> References: <20180202101444.3510-1-julien.grall@arm.com> Cc: andrew.cooper3@citrix.com, Julien Grall , sstabellini@kernel.org, andre.przywara@linaro.org Subject: [Xen-devel] [PATCH v3 1/4] xen/arm: traps: Merge try_handle_mmio() and handle_mmio() X-BeenThere: xen-devel@lists.xenproject.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.xenproject.org Sender: "Xen-devel" At the moment, try_handle_mmio() will do check on the HSR and bail out if one check fail. This means that another method will be tried to handle the fault even for bad access on emulated region. While this should not be an issue, this is not future proof. Move the checks of try_handle_mmio() in handle_mmio() after we identified the fault to target an emulated MMIO. While this does not fix the potential fall-through, a follow-up patch will do by distinguish the potential error. Note that the handle_mmio() was renamed to try_handle_mmio() and the prototype adapted. While merging the 2 functions, remove the check whether the fault is stage-2 abort on stage-1 translation walk because the instruction syndrome will always be invalid (see B3-1433 in DDI 0406C.c and D10-2460 in DDI 0487C.a). Signed-off-by: Julien Grall Reviewed-by: Andre Przywara --- Changes in v2: - Patch added --- xen/arch/arm/io.c | 43 ++++++++++++++++++++++++++++++++++++++----- xen/arch/arm/traps.c | 41 ----------------------------------------- xen/include/asm-arm/mmio.h | 4 +++- 3 files changed, 41 insertions(+), 47 deletions(-) diff --git a/xen/arch/arm/io.c b/xen/arch/arm/io.c index c748d8f5bf..c3e9239ffe 100644 --- a/xen/arch/arm/io.c +++ b/xen/arch/arm/io.c @@ -20,9 +20,12 @@ #include #include #include +#include #include #include +#include "decode.h" + static int handle_read(const struct mmio_handler *handler, struct vcpu *v, mmio_info_t *info) { @@ -100,19 +103,49 @@ static const struct mmio_handler *find_mmio_handler(struct domain *d, return handler; } -int handle_mmio(mmio_info_t *info) +int try_handle_mmio(struct cpu_user_regs *regs, + const union hsr hsr, + paddr_t gpa) { struct vcpu *v = current; const struct mmio_handler *handler = NULL; + const struct hsr_dabt dabt = hsr.dabt; + mmio_info_t info = { + .gpa = gpa, + .dabt = dabt + }; + + ASSERT(hsr.ec == HSR_EC_DATA_ABORT_LOWER_EL); - handler = find_mmio_handler(v->domain, info->gpa); + handler = find_mmio_handler(v->domain, info.gpa); if ( !handler ) return 0; - if ( info->dabt.write ) - return handle_write(handler, v, info); + /* All the instructions used on emulated MMIO region should be valid */ + if ( !dabt.valid ) + return 0; + + /* + * 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 ) + { + int rc; + + rc = decode_instruction(regs, &info.dabt); + if ( rc ) + { + gprintk(XENLOG_DEBUG, "Unable to decode instruction\n"); + return 0; + } + } + + if ( info.dabt.write ) + return handle_write(handler, v, &info); else - return handle_read(handler, v, info); + return handle_read(handler, v, &info); } void register_mmio_handler(struct domain *d, diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index c8534d6cff..2f8d790bb3 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -51,8 +51,6 @@ #include #include -#include "decode.h" - /* The base of the stack must always be double-word aligned, which means * that both the kernel half of struct cpu_user_regs (which is pushed in * entry.S) and struct cpu_info (which lives at the bottom of a Xen @@ -1864,45 +1862,6 @@ static inline bool hpfar_is_valid(bool s1ptw, uint8_t fsc) return s1ptw || (fsc == FSC_FLT_TRANS && !check_workaround_834220()); } -static bool try_handle_mmio(struct cpu_user_regs *regs, - const union hsr hsr, - paddr_t gpa) -{ - const struct hsr_dabt dabt = hsr.dabt; - mmio_info_t info = { - .gpa = gpa, - .dabt = dabt - }; - int rc; - - ASSERT(hsr.ec == HSR_EC_DATA_ABORT_LOWER_EL); - - /* 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); -} - /* * When using ACPI, most of the MMIO regions will be mapped on-demand * in stage-2 page tables for the hardware domain because Xen is not diff --git a/xen/include/asm-arm/mmio.h b/xen/include/asm-arm/mmio.h index 37e2b7a707..c941073257 100644 --- a/xen/include/asm-arm/mmio.h +++ b/xen/include/asm-arm/mmio.h @@ -56,7 +56,9 @@ struct vmmio { struct mmio_handler *handlers; }; -extern int handle_mmio(mmio_info_t *info); +int try_handle_mmio(struct cpu_user_regs *regs, + const union hsr hsr, + paddr_t gpa); void register_mmio_handler(struct domain *d, const struct mmio_handler_ops *ops, paddr_t addr, paddr_t size, void *priv);