From patchwork Thu Nov 23 18:32:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 119526 Delivered-To: patch@linaro.org Received: by 10.80.225.132 with SMTP id k4csp1172657edl; Thu, 23 Nov 2017 10:33:52 -0800 (PST) X-Google-Smtp-Source: AGs4zMaAtX4b8kA3xiI9m6ES4OuzOjW7ic0/Pkcsas7InEm0PdkOfbTClVNnL1Ultg42Oe/ngatV X-Received: by 10.36.1.4 with SMTP id 4mr13166257itk.59.1511462032861; Thu, 23 Nov 2017 10:33:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511462032; cv=none; d=google.com; s=arc-20160816; b=BzdlIUaxHTM2LuW33HSMIMcobTF1oRl+8Bxu3lLLmwTxE8Yh5hpK0ayNxw4L/JeEiN 4gjo3/+fLk96FJVLraHjrPlVOksofu5yGnkntkdcHTjIjRxE+ClBOEXhOzxHlslJJn0n INPv7lVCL9sZpkahorJI8Y7MsJO+yW3R2yRHcwEdcpEo3fKCgD2YTKJuqkCLyhPc1isA j9S7FbBAyMiLf7ao3piTEH1A0xGtYXg7NxdFyjitKNwSQ0khP8w778j2Vcm1KY7+1vC3 c1Ky7pfLPrx7Q5AaTNQG9zUGsAfA3oz+yq2omIfDOW/HpCdMxv9Zos5P9y4PVu6lETK6 siVg== 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:dkim-signature:arc-authentication-results; bh=U2AWX02EH8eIbOq6bax8bnIotYwyIZfkl3ezXgscaZ0=; b=gr2qWWrncSMAdeeex53fr/ht4mBNH41BK51lmIznEw3tkd1jLeMKFqt59TDq0T7fT6 xWokTzSo7tn6phAAPaWsysdR2JyPenbLOMSOkGod2scKNm6p7Ti2XjC2VJ28t+73gP0q COHI7dkd6zJZtg7x0XrgQUhpWp3mAVVQfR9IP2IcuwlkVLyomNAOKWx/KD6YjsfT6uth rE/aLZ4n84AaCM8kQoZDLBEHQbhkwvbP+1aDrf/rxY4v0rEKPuONcvlIEuoBoBcLFVJ7 SkDh4ASNRVtm4Eniq1ncc4/0yj1PDKTI6sxAYFZQgjV+hDZbIMRxMvppIVn8nwkh9Dms kuaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=AWq8n3z3; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 19si15883247ioi.205.2017.11.23.10.33.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Nov 2017 10:33:52 -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; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=AWq8n3z3; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.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 1eHwIa-0005S7-6d; Thu, 23 Nov 2017 18:32:32 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHwIZ-0005Ll-3G for xen-devel@lists.xen.org; Thu, 23 Nov 2017 18:32:31 +0000 Received: from [85.158.143.35] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-4.bemta-6.messagelabs.com id D1/C8-08078-E34171A5; Thu, 23 Nov 2017 18:32:30 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrKIsWRWlGSWpSXmKPExsXiVRvkrGsnIh5 lcGUjl8WSj4tZHBg9ju7+zRTAGMWamZeUX5HAmtHyZxNjwW/birarq1kbGN9rdzFycggJTGKU uDPZv4uRi4NFYB6zxIKlh5lAHAmBflaJ/s6t7CBVEgJ5ElsnL2SGsNMk7u09wARhl0n0nJ0DV MMBNElNYs2bKJBeIYE+JokX72aygMTZBHQk1s2oBSkXEZCWuPb5MiOIzSwQL/F46nU2EFtYIE fiwNf7YDaLgKpE9/nvYDW8ArYSUw8+gTpBXmJX20VWEJsTKH70wAdmiLU2Ep8/K05gFFzAyLC KUaM4tagstUjXyFgvqSgzPaMkNzEzR9fQwEwvN7W4ODE9NScxqVgvOT93EyMw2BiAYAfjn/mB hxglOZiURHllfolFCfEl5adUZiQWZ8QXleakFh9ilOHgUJLgvSkkHiUkWJSanlqRlpkDDHuYt AQHj5II7xJhoDRvcUFibnFmOkTqFKMlx749t/4wcTyb+bqBmWPa1dYmZiGWvPy8VClxXk+QBg GQhozSPLhxsNi8xCgrJczLCHSgEE9BalFuZgmq/CtGcQ5GJWHetyBX8WTmlcBtfQV0EBPQQT+ PC4McVJKIkJJqYGSyDG+uar8ZWFO/5Fz+b430a92t8yoEmho1z0r96vpzyVtXOb3o0LNGpu7O wzvKKvYtzGid7dNy6/A3xpblAT84D3zttUjkZZ5UOqf1bZFbv2fzFanDK0U5GK7KfJgntLQ6K vadZUXG4U3mPyM71677/GjlWpblOVvZmT2EnMpuzbL40m9eqsRSnJFoqMVcVJwIAOCWHgvIAg AA X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-4.tower-21.messagelabs.com!1511461950!76915742!1 X-Originating-IP: [74.125.82.67] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 60401 invoked from network); 23 Nov 2017 18:32:30 -0000 Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by server-4.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 23 Nov 2017 18:32:30 -0000 Received: by mail-wm0-f67.google.com with SMTP id g130so18043946wme.0 for ; Thu, 23 Nov 2017 10:32:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ynYblQUhdqBtIVnTU1fVzOwg+RNn3hpgKH19bHW2IZU=; b=AWq8n3z3C9R6n/d2mU/r6Xfx1QQFjMcI54W1wbOyJ9DM8aLAQSYdhtMh4wYCeeVD4D LBapNWsgbEpaYE4a/JeReIoh2CmsewbW+Q21ns8aD1qIlQzdYLKBgIPzMWuRzxGmjhIW NDUHDtnQcYUYP7Wsoipse42/5Az/2m9nulMQ0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ynYblQUhdqBtIVnTU1fVzOwg+RNn3hpgKH19bHW2IZU=; b=o5E6PT3gSGK0OfF2tD13ZS4qhAIwYUNulKoIxFjodNxh9WI5gx31opjC7a8rYt2ZBR 0SIJwsvu/x635NJzvdRptvR0DCQKoOV7g68ZEwIn26USx1gYpQvj14tgyvRP+8hFaQz1 0kdbh3z9vSWm8X1qM6+I9PWCqxTVZuNpdPTIyzcBwFmvZPH6TFuCwekDJapxl6VEUQxy K5NKESAqST1wevYwT41nvfwHVrkh1keUOiWpndRserucCpabSY5gC2qheuJS9aLtiu8J 5FkebKPoGTOxA0I9cDFeMwTroVFqZz2hjNigBcZ9W2apxrKjT2FdnJbohwtT65KhCWYC PRdQ== X-Gm-Message-State: AJaThX49XUyrONyoASeAjCzBC9SIsL4tKqyM3p+z5x5RQL0fkjP2zMd6 aMRBq7/dh3U9qNI2pWaw4r5vJ29zi/I= X-Received: by 10.28.8.80 with SMTP id 77mr7078912wmi.135.1511461949410; Thu, 23 Nov 2017 10:32:29 -0800 (PST) Received: from e108454-lin.cambridge.arm.com ([2001:41d0:1:6c23::1]) by smtp.gmail.com with ESMTPSA id n32sm41412950wrb.62.2017.11.23.10.32.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Nov 2017 10:32:28 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 23 Nov 2017 18:32:10 +0000 Message-Id: <20171123183210.12045-17-julien.grall@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171123183210.12045-1-julien.grall@linaro.org> References: <20171123183210.12045-1-julien.grall@linaro.org> Cc: sstabellini@kernel.org, Julien Grall , andre.przywara@linaro.org Subject: [Xen-devel] [PATCH for-next 16/16] xen/arm: traps: Merge do_trap_instr_abort_guest and do_trap_data_abort_guest 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" The two helpers do_trap_instr_abort_guest and do_trap_data_abort_guest are used trap stage-2 abort. While the former is only handling prefetch abort and the latter data abort, they are very similarly and does not warrant to have separate helpers. For instance, merging the both will make easier to maintain stage-2 abort handling. So consolidate the two helpers in a new helper do_trap_stage2_abort. Signed-off-by: Julien Grall --- xen/arch/arm/traps.c | 133 ++++++++++++++++----------------------------------- 1 file changed, 41 insertions(+), 92 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index a68e01b457..b83a2d9244 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1862,79 +1862,6 @@ static inline bool hpfar_is_valid(bool s1ptw, uint8_t fsc) return s1ptw || (fsc == FSC_FLT_TRANS && !check_workaround_834220()); } -static void do_trap_instr_abort_guest(struct cpu_user_regs *regs, - const union hsr hsr) -{ - int rc; - register_t gva; - uint8_t fsc = hsr.iabt.ifsc & ~FSC_LL_MASK; - paddr_t gpa; - mfn_t mfn; - - gva = get_hfar(false /* is_data */); - - /* - * If this bit has been set, it means that this instruction abort is caused - * by a guest external abort. We can handle this instruction abort as guest - * SError. - */ - if ( hsr.iabt.eat ) - return __do_trap_serror(regs, true); - - - if ( hpfar_is_valid(hsr.iabt.s1ptw, fsc) ) - gpa = get_faulting_ipa(gva); - else - { - /* - * Flush the TLB to make sure the DTLB is clear before - * doing GVA->IPA translation. If we got here because of - * an entry only present in the ITLB, this translation may - * still be inaccurate. - */ - flush_tlb_local(); - - /* - * We may not be able to translate because someone is - * playing with the Stage-2 page table of the domain. - * Return to the guest. - */ - rc = gva_to_ipa(gva, &gpa, GV2M_READ); - if ( rc == -EFAULT ) - return; /* Try again */ - } - - switch ( fsc ) - { - case FSC_FLT_PERM: - { - const struct npfec npfec = { - .insn_fetch = 1, - .gla_valid = 1, - .kind = hsr.iabt.s1ptw ? npfec_kind_in_gpt : npfec_kind_with_gla - }; - - p2m_mem_access_check(gpa, gva, npfec); - /* - * The only way to get here right now is because of mem_access, - * thus reinjecting the exception to the guest is never required. - */ - return; - } - case FSC_FLT_TRANS: - /* - * The PT walk may have failed because someone was playing - * with the Stage-2 page table. Walk the Stage-2 PT to check - * if the entry exists. If it's the case, return to the guest - */ - mfn = gfn_to_mfn(current->domain, _gfn(paddr_to_pfn(gpa))); - if ( !mfn_eq(mfn, INVALID_MFN) ) - return; - } - - inject_iabt_exception(regs, gva, hsr.len); -} - static bool try_handle_mmio(struct cpu_user_regs *regs, const union hsr hsr, paddr_t gpa) @@ -1946,6 +1873,8 @@ static bool try_handle_mmio(struct cpu_user_regs *regs, }; 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; @@ -2001,29 +1930,43 @@ static bool try_map_mmio(gfn_t gfn) return !map_regions_p2mt(d, gfn, 1, mfn, p2m_mmio_direct_c); } -static void do_trap_data_abort_guest(struct cpu_user_regs *regs, - const union hsr hsr) +static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs, + const union hsr hsr) { - const struct hsr_dabt dabt = hsr.dabt; + /* + * The encoding of hsr_iabt is a subset of hsr_dabt. So use + * hsr_dabt to represent an abort fault. + */ + const struct hsr_xabt xabt = hsr.xabt; int rc; vaddr_t gva; paddr_t gpa; - uint8_t fsc = hsr.dabt.dfsc & ~FSC_LL_MASK; + uint8_t fsc = xabt.fsc & ~FSC_LL_MASK; mfn_t mfn; + bool is_data = (hsr.ec == HSR_EC_DATA_ABORT_LOWER_EL); /* - * If this bit has been set, it means that this data abort is caused - * by a guest external abort. We treat this data abort as guest SError. + * If this bit has been set, it means that this stage-2 abort is caused + * by a guest external abort. We treat this stage-2 abort as guest SError. */ - if ( dabt.eat ) + if ( xabt.eat ) return __do_trap_serror(regs, true); - gva = get_hfar(true /* is_data */); + gva = get_hfar(is_data); - if ( hpfar_is_valid(dabt.s1ptw, fsc) ) + if ( hpfar_is_valid(xabt.s1ptw, fsc) ) gpa = get_faulting_ipa(gva); else { + /* + * Flush the TLB to make sure the DTLB is clear before + * doing GVA->IPA translation. If we got here because of + * an entry only present in the ITLB, this translation may + * still be inaccurate. + */ + if ( !is_data ) + flush_tlb_local(); + rc = gva_to_ipa(gva, &gpa, GV2M_READ); /* * We may not be able to translate because someone is @@ -2039,10 +1982,11 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, case FSC_FLT_PERM: { const struct npfec npfec = { - .read_access = !dabt.write, - .write_access = dabt.write, + .insn_fetch = !is_data, + .read_access = is_data && !hsr.dabt.write, + .write_access = is_data && !hsr.dabt.write, .gla_valid = 1, - .kind = dabt.s1ptw ? npfec_kind_in_gpt : npfec_kind_with_gla + .kind = xabt.s1ptw ? npfec_kind_in_gpt : npfec_kind_with_gla }; p2m_mem_access_check(gpa, gva, npfec); @@ -2056,8 +2000,10 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, /* * Attempt first to emulate the MMIO as the data abort will * likely happen in an emulated region. + * + * Note that emulated region cannot be executed */ - if ( try_handle_mmio(regs, hsr, gpa) ) + if ( is_data && try_handle_mmio(regs, hsr, gpa) ) { advance_pc(regs, hsr); return; @@ -2072,18 +2018,21 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, if ( !mfn_eq(mfn, INVALID_MFN) ) return; - if ( try_map_mmio(gaddr_to_gfn(gpa)) ) + if ( is_data && try_map_mmio(gaddr_to_gfn(gpa)) ) return; break; default: - gprintk(XENLOG_WARNING, "Unsupported DFSC: HSR=%#x DFSC=%#x\n", - hsr.bits, dabt.dfsc); + gprintk(XENLOG_WARNING, "Unsupported FSC: HSR=%#x DFSC=%#x\n", + hsr.bits, xabt.fsc); } gdprintk(XENLOG_DEBUG, "HSR=0x%x pc=%#"PRIregister" gva=%#"PRIvaddr " gpa=%#"PRIpaddr"\n", hsr.bits, regs->pc, gva, gpa); - inject_dabt_exception(regs, gva, hsr.len); + if ( is_data ) + inject_dabt_exception(regs, gva, hsr.len); + else + inject_iabt_exception(regs, gva, hsr.len); } static void enter_hypervisor_head(struct cpu_user_regs *regs) @@ -2216,11 +2165,11 @@ void do_trap_guest_sync(struct cpu_user_regs *regs) case HSR_EC_INSTR_ABORT_LOWER_EL: perfc_incr(trap_iabt); - do_trap_instr_abort_guest(regs, hsr); + do_trap_stage2_abort_guest(regs, hsr); break; case HSR_EC_DATA_ABORT_LOWER_EL: perfc_incr(trap_dabt); - do_trap_data_abort_guest(regs, hsr); + do_trap_stage2_abort_guest(regs, hsr); break; default: