From patchwork Wed Jul 31 20:37:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 170241 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4471391ile; Wed, 31 Jul 2019 13:39:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqzWxbqA5QowhblSfRwnm/HNAn+gmkTKlvZNK351jhX7XhK3Qv0AiGiDxwxeVKhwRLbgmysT X-Received: by 2002:a17:906:2da9:: with SMTP id g9mr52531257eji.182.1564605570715; Wed, 31 Jul 2019 13:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564605570; cv=none; d=google.com; s=arc-20160816; b=Yu9QZAKK4jAzHBchXbkRwuIyDuEFYNu7X0QXBuZHk9yCi3S0b4X4nR1bNihJ4cuHBJ FwBxJCr/Do1a/lMGqskBxefhg2o8ierJaseqPWsf/8Ws4ZcS1MgsFng1sdIT4Ua6tvdi aw0AeThLm4UJRXYTIKK8vh5SdVOVl5M7CW4Lz9WH0qrVIlH/KMtMEWslSs++UkvQsx8D cp6CsP3QqhOZSTLN7vS63ygCPv7RQf/tZZXHUaqdJQpC2DT3ypnHShuVdONlDxARm/i2 XRBdwvIdrelRl7vZfiYGvhuARHPs9JLGQWtr2tuMa/WHUAqlkczXUCBJ7IZzg9XVpMbg +FJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=ZRDl/Ha+kclTizhs/nHDa+7096PsBT003cOS/ic3LTY=; b=spcqFLIydcHQnCPudXqmEBTiAICXCBHGtmW+6DO1AMPWtIssi5uOp30PTmdq2iq0lE ZOmT3V+dg7pyh49DEZNDBn/4y/mWp8Js4LfqOGN4J7chhpRItJ5vJsP9hNE2YaoLftX1 bv/7Zj7nXdvn39WxAFg3MsBPirbYHoFxGRZlB3CC4hjezzuoCf6R6rED0txPzOgQe5p+ Whf9cRj1IG8Iak2V8a3y2F9VZFgJykVNTDmRRgWYYO2zYZX/OL73Gxu/3yL8QAByqkcu NNqYt89gHcGit85wlY6GMoGtWM32rrI9vSU2N8LIp8+4ZrObr61EhRGTN+x1IP3SFZTb xEgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=BrNtztSK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m55si21370481edm.55.2019.07.31.13.39.30 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Jul 2019 13:39:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=BrNtztSK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsvNh-0004W2-OL for patch@linaro.org; Wed, 31 Jul 2019 16:39:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60653) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsvMc-0003zv-8Q for qemu-devel@nongnu.org; Wed, 31 Jul 2019 16:38:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsvMa-0003Ig-KP for qemu-devel@nongnu.org; Wed, 31 Jul 2019 16:38:22 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:44059) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsvMa-0003Hq-Dt for qemu-devel@nongnu.org; Wed, 31 Jul 2019 16:38:20 -0400 Received: by mail-pl1-x641.google.com with SMTP id t14so30968102plr.11 for ; Wed, 31 Jul 2019 13:38:20 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=ZRDl/Ha+kclTizhs/nHDa+7096PsBT003cOS/ic3LTY=; b=BrNtztSKwNJY0w/qMsV8+5wn4WcG6r4UAkotM3F1Fr5GTPMAXcVgrqHjx1FIW66bFr voGvXlo+sk+LOwKuxpVJmzUqP6ryvIWJ+RccWHsdrYBIA5zpjgEzLk0S2s7M08DnGhae RoxZK0x9byYFKU8QZ7+41B6YLY9eg1o2PafxegkAmZ2hPwr7IjgDGhd6ygh1wkZD58CV yjLmRLyQm37yaiDumd+HxvlJqBvPJbKDRDQw6BWfghL1BFsBuDB/vJjWmiHZ8Xot0pjP QA2Yg8OIKXIwsasWN/QJkbLmtVffUpmMmVrARxz3QX5wmngBTyscEuAK3HrcevjdsHmS 5GIA== 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:mime-version:content-transfer-encoding; bh=ZRDl/Ha+kclTizhs/nHDa+7096PsBT003cOS/ic3LTY=; b=TIXf0/LRpyB8m470ryWotrn3Qqe5E/MBcvaGdUKlaIkQ/Gw0jLiDh5z6hrplD0mVJl 7swGNFMXC3JY3OepOopUYBomxz/LPJljzDPWmxIoIAY5R0C04HIM7Cv11tsY14/oi/Cb U52W6TqHMq8maNDZ1Jkrzu/Ubl8+rITmkq9utSGn9lHFZQlyup1DBSykuSCOZzTdvR4j YfBdBRb6VXfMBkYK9hH8WgsT1G++BDtPpj41MBjlCJ1zMSm91R+fLUqiEOf3xOFwnag7 KlvhJpqhITg3iZRbm9CGdh5N+RVDwv1xXKXTWjY7HX+WNyAraEmcPXej8OIFP5SNyhGW OQRw== X-Gm-Message-State: APjAAAUP4r+nAVnNDRXX7SIE1Z7SPIWc38v5ARgJxjZNromQr5QaX8Ys L3owuizc908AQpfSH+OBdB+PuYoXGNg= X-Received: by 2002:a17:902:7d8b:: with SMTP id a11mr68507527plm.306.1564605499140; Wed, 31 Jul 2019 13:38:19 -0700 (PDT) Received: from localhost.localdomain (97-113-7-119.tukw.qwest.net. [97.113.7.119]) by smtp.gmail.com with ESMTPSA id g4sm84054164pfo.93.2019.07.31.13.38.18 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 13:38:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 13:37:44 -0700 Message-Id: <20190731203813.30765-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190731203813.30765-1-richard.henderson@linaro.org> References: <20190731203813.30765-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 Subject: [Qemu-devel] [PATCH v2 03/32] target/arm: Install ASIDs for long-form from EL1 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" In addition to providing the core with the current ASID, this minimizes both the number of flushes due to non-changing ASID as well as the set of mmu_idx that are affected by each flush. In particular, updates to the secure mode registers flushes only the relevant secure mode mmu_idx's, and similarly non-secure updates only affect non-secure mmu_idx's. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- target/arm/helper.c | 73 +++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 25 deletions(-) -- 2.17.1 diff --git a/target/arm/helper.c b/target/arm/helper.c index b74c23a9bc..2a65f4127e 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -3327,6 +3327,36 @@ static const ARMCPRegInfo pmsav5_cp_reginfo[] = { REGINFO_SENTINEL }; +/* Called after a change to any of TTBR*_EL1 or TTBCR_EL1. */ +static void update_lpae_el1_asid(CPUARMState *env, int secure) +{ + CPUState *cs = env_cpu(env); + uint64_t ttbr0, ttbr1, ttcr; + int asid, idxmask; + + switch (secure) { + case ARM_CP_SECSTATE_S: + ttbr0 = env->cp15.ttbr0_s; + ttbr1 = env->cp15.ttbr1_s; + ttcr = env->cp15.tcr_el[3].raw_tcr; + /* Note that cp15.ttbr0_s == cp15.ttbr0_el[3], so S1E3 is affected. */ + /* ??? Secure EL3 really using the ASID field? Doesn't make sense. */ + idxmask = ARMMMUIdxBit_S1SE1 | ARMMMUIdxBit_S1SE0 | ARMMMUIdxBit_S1E3; + break; + case ARM_CP_SECSTATE_NS: + ttbr0 = env->cp15.ttbr0_ns; + ttbr1 = env->cp15.ttbr1_ns; + ttcr = env->cp15.tcr_el[1].raw_tcr; + idxmask = ARMMMUIdxBit_S12NSE1 | ARMMMUIdxBit_S12NSE0; + break; + default: + g_assert_not_reached(); + } + asid = extract64(ttcr & TTBCR_A1 ? ttbr1 : ttbr0, 48, 16); + + tlb_set_asid_for_mmuidx(cs, asid, idxmask, 0); +} + static void vmsa_ttbcr_raw_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { @@ -3363,18 +3393,16 @@ static void vmsa_ttbcr_raw_write(CPUARMState *env, const ARMCPRegInfo *ri, static void vmsa_ttbcr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { - ARMCPU *cpu = env_archcpu(env); TCR *tcr = raw_ptr(env, ri); - if (arm_feature(env, ARM_FEATURE_LPAE)) { - /* With LPAE the TTBCR could result in a change of ASID - * via the TTBCR.A1 bit, so do a TLB flush. - */ - tlb_flush(CPU(cpu)); - } /* Preserve the high half of TCR_EL1, set via TTBCR2. */ value = deposit64(tcr->raw_tcr, 0, 32, value); vmsa_ttbcr_raw_write(env, ri, value); + + if (arm_feature(env, ARM_FEATURE_LPAE)) { + /* The A1 bit controls which ASID is active. */ + update_lpae_el1_asid(env, ri->secure); + } } static void vmsa_ttbcr_reset(CPUARMState *env, const ARMCPRegInfo *ri) @@ -3392,24 +3420,19 @@ static void vmsa_ttbcr_reset(CPUARMState *env, const ARMCPRegInfo *ri) static void vmsa_tcr_el1_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { - ARMCPU *cpu = env_archcpu(env); - TCR *tcr = raw_ptr(env, ri); - - /* For AArch64 the A1 bit could result in a change of ASID, so TLB flush. */ - tlb_flush(CPU(cpu)); - tcr->raw_tcr = value; + raw_write(env, ri, value); + /* The A1 bit controls which ASID is active. */ + update_lpae_el1_asid(env, ri->secure); } -static void vmsa_ttbr_write(CPUARMState *env, const ARMCPRegInfo *ri, - uint64_t value) +static void vmsa_ttbr_el1_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) { - /* If the ASID changes (with a 64-bit write), we must flush the TLB. */ - if (cpreg_field_is_64bit(ri) && - extract64(raw_read(env, ri) ^ value, 48, 16) != 0) { - ARMCPU *cpu = env_archcpu(env); - tlb_flush(CPU(cpu)); - } raw_write(env, ri, value); + if (cpreg_field_is_64bit(ri)) { + /* The LPAE format (64-bit write) contains an ASID field. */ + update_lpae_el1_asid(env, ri->secure); + } } static void vttbr_write(CPUARMState *env, const ARMCPRegInfo *ri, @@ -3455,12 +3478,12 @@ static const ARMCPRegInfo vmsa_cp_reginfo[] = { .fieldoffset = offsetof(CPUARMState, cp15.esr_el[1]), .resetvalue = 0, }, { .name = "TTBR0_EL1", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 0, .opc2 = 0, - .access = PL1_RW, .writefn = vmsa_ttbr_write, .resetvalue = 0, + .access = PL1_RW, .writefn = vmsa_ttbr_el1_write, .resetvalue = 0, .bank_fieldoffsets = { offsetof(CPUARMState, cp15.ttbr0_s), offsetof(CPUARMState, cp15.ttbr0_ns) } }, { .name = "TTBR1_EL1", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 0, .opc2 = 1, - .access = PL1_RW, .writefn = vmsa_ttbr_write, .resetvalue = 0, + .access = PL1_RW, .writefn = vmsa_ttbr_el1_write, .resetvalue = 0, .bank_fieldoffsets = { offsetof(CPUARMState, cp15.ttbr1_s), offsetof(CPUARMState, cp15.ttbr1_ns) } }, { .name = "TCR_EL1", .state = ARM_CP_STATE_AA64, @@ -3715,12 +3738,12 @@ static const ARMCPRegInfo lpae_cp_reginfo[] = { .access = PL1_RW, .type = ARM_CP_64BIT | ARM_CP_ALIAS, .bank_fieldoffsets = { offsetof(CPUARMState, cp15.ttbr0_s), offsetof(CPUARMState, cp15.ttbr0_ns) }, - .writefn = vmsa_ttbr_write, }, + .writefn = vmsa_ttbr_el1_write, }, { .name = "TTBR1", .cp = 15, .crm = 2, .opc1 = 1, .access = PL1_RW, .type = ARM_CP_64BIT | ARM_CP_ALIAS, .bank_fieldoffsets = { offsetof(CPUARMState, cp15.ttbr1_s), offsetof(CPUARMState, cp15.ttbr1_ns) }, - .writefn = vmsa_ttbr_write, }, + .writefn = vmsa_ttbr_el1_write, }, REGINFO_SENTINEL };