From patchwork Wed Apr 22 17:09:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 47423 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 384842121F for ; Wed, 22 Apr 2015 17:12:56 +0000 (UTC) Received: by lbos2 with SMTP id s2sf8622253lbo.2 for ; Wed, 22 Apr 2015 10:12:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=41ktmyy+n+82tngHsYmiV/SGibWfL6E4uWfTNhHH3bU=; b=IV1K9k3HaGt67y2jskO4AWGt2+joIEc7cBFtXEPJNihZXDa/dMvgVFMxreUPghq1ay scPoMBMgqEi1jTIgB6FE5JjjMnf0bFiSdLVBrmctKAURNj3Pg9nuqsbLt43r2griz1YT D7yzRd2p3yvp0boq2/9MSaItMVrsRvxphxaOZTFlrGbQIfJMDNBiBbuIvtH/htJrtcws S/Mfr7aVXGD3dwqgZ1nUhX1wbromMMc6V/Wx4ek/NB8EVsFrA3ta2DiLSHKo1gP9aVGz KVjGDKU8IlvsMz7ss3VVfysvWEN9tXv8rMPknUahZUdHACHgtaWa4cadbU1a02Ki4TTf fU2g== X-Gm-Message-State: ALoCoQkNOfl3h7f0eSRLCKkvVP8AqW5RTLagBYclwBSZDGzH2Da5/wBmP5ca7Cmho28lA/kShuiV X-Received: by 10.112.93.203 with SMTP id cw11mr11908931lbb.0.1429722775180; Wed, 22 Apr 2015 10:12:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.198.229 with SMTP id jf5ls212221lac.56.gmail; Wed, 22 Apr 2015 10:12:55 -0700 (PDT) X-Received: by 10.112.139.36 with SMTP id qv4mr25318918lbb.24.1429722775044; Wed, 22 Apr 2015 10:12:55 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id l16si4151211lab.64.2015.04.22.10.12.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Apr 2015 10:12:54 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbbqq2 with SMTP id qq2so185313683lbb.3 for ; Wed, 22 Apr 2015 10:12:54 -0700 (PDT) X-Received: by 10.152.36.161 with SMTP id r1mr25633699laj.88.1429722774914; Wed, 22 Apr 2015 10:12:54 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp69072lbt; Wed, 22 Apr 2015 10:12:53 -0700 (PDT) X-Received: by 10.229.204.10 with SMTP id fk10mr27623639qcb.1.1429722772875; Wed, 22 Apr 2015 10:12:52 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k132si5620833qhc.49.2015.04.22.10.12.52 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 22 Apr 2015 10:12:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:36244 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YkyCh-0003eQ-Gw for patch@linaro.org; Wed, 22 Apr 2015 13:12:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42056) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yky9m-0007Pq-6E for qemu-devel@nongnu.org; Wed, 22 Apr 2015 13:09:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yky9i-0004sq-1d for qemu-devel@nongnu.org; Wed, 22 Apr 2015 13:09:50 -0400 Received: from mail-oi0-f53.google.com ([209.85.218.53]:36703) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yky9h-0004sa-Po for qemu-devel@nongnu.org; Wed, 22 Apr 2015 13:09:45 -0400 Received: by oift201 with SMTP id t201so186215731oif.3 for ; Wed, 22 Apr 2015 10:09:45 -0700 (PDT) X-Received: by 10.182.66.106 with SMTP id e10mr24470985obt.42.1429722585460; Wed, 22 Apr 2015 10:09:45 -0700 (PDT) Received: from gbellows-linaro.gateway.pace.com (99-179-1-214.lightspeed.austtx.sbcglobal.net. [99.179.1.214]) by mx.google.com with ESMTPSA id w72sm3417636oie.28.2015.04.22.10.09.43 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 22 Apr 2015 10:09:44 -0700 (PDT) From: Greg Bellows To: qemu-devel@nongnu.org, peter.maydell@linaro.org, alex.bennee@linaro.org Date: Wed, 22 Apr 2015 12:09:19 -0500 Message-Id: <1429722561-12651-8-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1429722561-12651-1-git-send-email-greg.bellows@linaro.org> References: <1429722561-12651-1-git-send-email-greg.bellows@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.218.53 Cc: serge.fdrv@gmail.com, Greg Bellows Subject: [Qemu-devel] [PATCH v2 7/9] target-arm: Add EL3 and EL2 TCR checking X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: greg.bellows@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Updated get_phys_addr_lpae to check the appropriate TTBCR/TCR depending on the current EL. Support includes using the different TCR format as well as checks to insure TTBR1 is not used when in EL2 or EL3. Signed-off-by: Greg Bellows --- target-arm/helper.c | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/target-arm/helper.c b/target-arm/helper.c index 69a5891..e7ab5c4 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -5397,21 +5397,34 @@ static int get_phys_addr_lpae(CPUARMState *env, target_ulong address, int32_t tbi = 0; TCR *tcr = regime_tcr(env, mmu_idx); int ap, ns, xn, pxn; + uint32_t el = regime_el(env, mmu_idx); + bool ttbr1_valid = true; /* TODO: - * This code assumes we're either a 64-bit EL1 or a 32-bit PL1; - * it doesn't handle the different format TCR for TCR_EL2, TCR_EL3, - * and VTCR_EL2, or the fact that those regimes don't have a split - * TTBR0/TTBR1. Attribute and permission bit handling should also - * be checked when adding support for those page table walks. + * This code does not handle the different format TCR for VTCR_EL2. + * This code also does not support shareability levels. + * Attribute and permission bit handling should also be checked when adding + * support for those page table walks. */ - if (arm_el_is_aa64(env, regime_el(env, mmu_idx))) { + if (arm_el_is_aa64(env, el)) { va_size = 64; - if (extract64(address, 55, 1)) - tbi = extract64(tcr->raw_tcr, 38, 1); - else - tbi = extract64(tcr->raw_tcr, 37, 1); + if (el > 1) { + tbi = extract64(tcr->raw_tcr, 20, 1); + } else { + if (extract64(address, 55, 1)) { + tbi = extract64(tcr->raw_tcr, 38, 1); + } else { + tbi = extract64(tcr->raw_tcr, 37, 1); + } + } tbi *= 8; + + /* If we are in 64-bit EL2 or EL3 then there is no TTBR1, so mark it + * invalid. + */ + if (el > 1) { + ttbr1_valid = false; + } } /* Determine whether this address is in the region controlled by @@ -5432,13 +5445,14 @@ static int get_phys_addr_lpae(CPUARMState *env, target_ulong address, if (t0sz && !extract64(address, va_size - t0sz, t0sz - tbi)) { /* there is a ttbr0 region and we are in it (high bits all zero) */ ttbr_select = 0; - } else if (t1sz && !extract64(~address, va_size - t1sz, t1sz - tbi)) { + } else if (ttbr1_valid && t1sz && + !extract64(~address, va_size - t1sz, t1sz - tbi)) { /* there is a ttbr1 region and we are in it (high bits all one) */ ttbr_select = 1; } else if (!t0sz) { /* ttbr0 region is "everything not in the ttbr1 region" */ ttbr_select = 0; - } else if (!t1sz) { + } else if (!t1sz && ttbr1_valid) { /* ttbr1 region is "everything not in the ttbr0 region" */ ttbr_select = 1; } else { @@ -5467,6 +5481,9 @@ static int get_phys_addr_lpae(CPUARMState *env, target_ulong address, granule_sz = 11; } } else { + /* We should only be here if TTBR1 is valid */ + assert(ttbr1_valid); + ttbr = regime_ttbr(env, mmu_idx, 1); epd = extract32(tcr->raw_tcr, 23, 1); tsz = t1sz; @@ -5485,7 +5502,9 @@ static int get_phys_addr_lpae(CPUARMState *env, target_ulong address, */ if (epd) { - /* Translation table walk disabled => Translation fault on TLB miss */ + /* Translation table walk disabled => Translation fault on TLB miss + * Note: This is always 0 on 64-bit EL2 and EL3. + */ goto do_fault; }