From patchwork Sun Feb 16 19:43:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 183560 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp4178799ile; Sun, 16 Feb 2020 11:44:23 -0800 (PST) X-Google-Smtp-Source: APXvYqzMjgrUHaEqXH3qzWETu/HHg6KMr20yrcFooEGgdjC4bBjovTwe575Y+TIcQP5fqAZkXjoL X-Received: by 2002:a37:a717:: with SMTP id q23mr11765134qke.169.1581882263639; Sun, 16 Feb 2020 11:44:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581882263; cv=none; d=google.com; s=arc-20160816; b=ueuCfX8GXrNPd5ohL1fhMKKbeQpy4+4pixfd9Lj1zTzXgAJWtz1u1l9XPUuOpi4fSS 51DZ03Em/mlKoYoOhKaECTn/wOspg/MCY6VxMgiN+F6Dn2X2AQMjvVoFaL8awwkZmx6q 39XQzRYtIXRv0bZyo6cx896Owh1CREQtLZ2zns8beuY/5g7awDYF2CO4fn9yWobiWIRy 1h3wGwikr6AurEFwPVe+VqHmxN++FYCsyeT83bIgRGAI5+YJSAF485LsLCdkhdQEXHMN UN2g75060t32NNXZmlaIFzwUdyGzhPj7wW8CfRikVYb9SWiAPaPoR3Ea7/qXiOBXzRXI c6Zw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=jKe60JzIR9wTTCupClDTcPlRGkah6P8mFmzkvCXt/nU=; b=LO+vOMNCapEkB8BWi0aisZkXDvLW34BHEha2o3hqP2vzq1aExwOUZ/qRboz99QPjMG M2qEz8TKU0OvA8Dfg8h8ane0pa3IdlfKsS05hepqO2XotwwTLsV6egCbHKINQCzyuUbH OETeh4IEb4dOmSeMcB76pA/83NtSZY8i/2CrjJqBfoNQp0NVgiiHk+kVB1WY8/r7Smcl ctlpI0+3hD9H5SKjtQOIpYBEkAnAjHRSKCBwEMRVRfnFo30xp37vPK3jxsTRkL4vfoDj zOBmMp9UbUIPf9TEc02HnZRY/Zxyn7R+E8zivyOAS3H1668eeUBz1cNAfoKhfx7RzrjI pFiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MFJ51olg; 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=pass (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 w6si6460042qki.47.2020.02.16.11.44.23 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 16 Feb 2020 11:44:23 -0800 (PST) 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=pass header.i=@linaro.org header.s=google header.b=MFJ51olg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j3Pq3-00048v-3z for patch@linaro.org; Sun, 16 Feb 2020 14:44:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34760) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j3PpZ-0003iF-1e for qemu-devel@nongnu.org; Sun, 16 Feb 2020 14:43:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j3PpX-0005cs-Mh for qemu-devel@nongnu.org; Sun, 16 Feb 2020 14:43:52 -0500 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:40646) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j3PpX-0005bh-HE for qemu-devel@nongnu.org; Sun, 16 Feb 2020 14:43:51 -0500 Received: by mail-pg1-x544.google.com with SMTP id z7so7889893pgk.7 for ; Sun, 16 Feb 2020 11:43:51 -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 :mime-version:content-transfer-encoding; bh=jKe60JzIR9wTTCupClDTcPlRGkah6P8mFmzkvCXt/nU=; b=MFJ51olgXjMW5MdZBN1Ft5GvIN6GtY9huC3Q8048vWVMuorOEKJA+zdx2AradH6XZX fVITTHDj6SRPYPSFxeVMIWcq2HK/Gh4ZkSD/mDSMFQP7qhHagU22iPIcsSZH0hGI40pi yW19rvbo8IjqlwBXZHQyIZpXjA1SzjqUyremndbhlOzg4PynZd6nt4eydyfwpN/DCL1B raVdyg5m1SVaSrFmpbndHEkdWT5du5nV9x6lLYpjvbgmFgwtp0Wwun9yPvMP+slBGzx0 HbcxY93qSld49VKCjf1A1VrgwlOjq2rVdMHA6ydnUqo5lB69bD36WuV2m6mipGno2Qv7 MiEw== 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=jKe60JzIR9wTTCupClDTcPlRGkah6P8mFmzkvCXt/nU=; b=FXPEvcZ67gE+Q9wLlWfpBSaxu65pz1PK3SX7Pw5TVTNdAf0eLfX2qyiYPNlNLuk80M IoFmZ1kmbvwb6pKzT511MLXY1vLFeK6ZxKuX1Q+0NmnydbfjxmE0Up2CvEU/kKiQnFNW BGyymWYGy70vBe98GMetBNRc+XpDhpyNZf++5Vr0ONb1YI2hWmAV4LWy3gcApZhI8cYA rHUgeglmhZ7YmQzac7oEMlYROubUzmiVdYLUGFwhwgkIo/z+xEzy9dHfHjMUN+uFkyR1 6LJbUL3Mi1TeNuXgI2bpnq+I9Ka65aQFBK3M2TyT6nL7o7OySF32DTWa1Rwag1/9S8tY +KDw== X-Gm-Message-State: APjAAAX/PpVR5qS4AdPpps5xIGc45h2wMzL7vn93W9m7OQAlyJ+NEsww piZDukEeDa1WUxX9XzCsNdMkPp2qdKk= X-Received: by 2002:a63:e755:: with SMTP id j21mr14372101pgk.330.1581882230265; Sun, 16 Feb 2020 11:43:50 -0800 (PST) Received: from localhost.localdomain (97-126-123-70.tukw.qwest.net. [97.126.123.70]) by smtp.gmail.com with ESMTPSA id y127sm13945188pfg.22.2020.02.16.11.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Feb 2020 11:43:49 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 4/4] target/arm: Split out aa64_va_parameter_tbi, aa64_va_parameter_tbid Date: Sun, 16 Feb 2020 11:43:43 -0800 Message-Id: <20200216194343.21331-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200216194343.21331-1-richard.henderson@linaro.org> References: <20200216194343.21331-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::544 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 Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For the purpose of rebuild_hflags_a64, we do not need to compute all of the va parameters, only tbi. Moreover, we can compute them in a form that is more useful to storing in hflags. This eliminates the need for aa64_va_parameter_both, so fold that in to aa64_va_parameter. The remaining calls to aa64_va_parameter are in get_phys_addr_lpae and in pauth_helper.c. This reduces the total cpu consumption of aa64_va_parameter in a kernel boot plus a kvm guest kernel boot from 3% to 0.5%. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/internals.h | 3 -- target/arm/helper.c | 68 +++++++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 34 deletions(-) -- 2.20.1 diff --git a/target/arm/internals.h b/target/arm/internals.h index 58c4d707c5..14328e3f7d 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1127,15 +1127,12 @@ typedef struct ARMVAParameters { unsigned tsz : 8; unsigned select : 1; bool tbi : 1; - bool tbid : 1; bool epd : 1; bool hpd : 1; bool using16k : 1; bool using64k : 1; } ARMVAParameters; -ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va, - ARMMMUIdx mmu_idx); ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, ARMMMUIdx mmu_idx, bool data); diff --git a/target/arm/helper.c b/target/arm/helper.c index eec7b01ab3..8d0f6eca27 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10234,12 +10234,34 @@ static uint8_t convert_stage2_attrs(CPUARMState *env, uint8_t s2attrs) } #endif /* !CONFIG_USER_ONLY */ -ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va, - ARMMMUIdx mmu_idx) +static int aa64_va_parameter_tbi(uint64_t tcr, ARMMMUIdx mmu_idx) +{ + if (regime_has_2_ranges(mmu_idx)) { + return extract64(tcr, 37, 2); + } else if (mmu_idx == ARMMMUIdx_Stage2) { + return 0; /* VTCR_EL2 */ + } else { + return extract32(tcr, 20, 1); + } +} + +static int aa64_va_parameter_tbid(uint64_t tcr, ARMMMUIdx mmu_idx) +{ + if (regime_has_2_ranges(mmu_idx)) { + return extract64(tcr, 51, 2); + } else if (mmu_idx == ARMMMUIdx_Stage2) { + return 0; /* VTCR_EL2 */ + } else { + return extract32(tcr, 29, 1); + } +} + +ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, + ARMMMUIdx mmu_idx, bool data) { uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; - bool tbi, tbid, epd, hpd, using16k, using64k; - int select, tsz; + bool epd, hpd, using16k, using64k; + int select, tsz, tbi; if (!regime_has_2_ranges(mmu_idx)) { select = 0; @@ -10248,11 +10270,9 @@ ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va, using16k = extract32(tcr, 15, 1); if (mmu_idx == ARMMMUIdx_Stage2) { /* VTCR_EL2 */ - tbi = tbid = hpd = false; + hpd = false; } else { - tbi = extract32(tcr, 20, 1); hpd = extract32(tcr, 24, 1); - tbid = extract32(tcr, 29, 1); } epd = false; } else { @@ -10266,28 +10286,30 @@ ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va, epd = extract32(tcr, 7, 1); using64k = extract32(tcr, 14, 1); using16k = extract32(tcr, 15, 1); - tbi = extract64(tcr, 37, 1); hpd = extract64(tcr, 41, 1); - tbid = extract64(tcr, 51, 1); } else { int tg = extract32(tcr, 30, 2); using16k = tg == 1; using64k = tg == 3; tsz = extract32(tcr, 16, 6); epd = extract32(tcr, 23, 1); - tbi = extract64(tcr, 38, 1); hpd = extract64(tcr, 42, 1); - tbid = extract64(tcr, 52, 1); } } tsz = MIN(tsz, 39); /* TODO: ARMv8.4-TTST */ tsz = MAX(tsz, 16); /* TODO: ARMv8.2-LVA */ + /* Present TBI as a composite with TBID. */ + tbi = aa64_va_parameter_tbi(tcr, mmu_idx); + if (!data) { + tbi &= ~aa64_va_parameter_tbid(tcr, mmu_idx); + } + tbi = (tbi >> select) & 1; + return (ARMVAParameters) { .tsz = tsz, .select = select, .tbi = tbi, - .tbid = tbid, .epd = epd, .hpd = hpd, .using16k = using16k, @@ -10295,16 +10317,6 @@ ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va, }; } -ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, - ARMMMUIdx mmu_idx, bool data) -{ - ARMVAParameters ret = aa64_va_parameters_both(env, va, mmu_idx); - - /* Present TBI as a composite with TBID. */ - ret.tbi &= (data || !ret.tbid); - return ret; -} - #ifndef CONFIG_USER_ONLY static ARMVAParameters aa32_va_parameters(CPUARMState *env, uint32_t va, ARMMMUIdx mmu_idx) @@ -12134,21 +12146,15 @@ static uint32_t rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, { uint32_t flags = rebuild_hflags_aprofile(env); ARMMMUIdx stage1 = stage_1_mmu_idx(mmu_idx); - ARMVAParameters p0 = aa64_va_parameters_both(env, 0, stage1); + uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; uint64_t sctlr; int tbii, tbid; flags = FIELD_DP32(flags, TBFLAG_ANY, AARCH64_STATE, 1); /* Get control bits for tagged addresses. */ - if (regime_has_2_ranges(mmu_idx)) { - ARMVAParameters p1 = aa64_va_parameters_both(env, -1, stage1); - tbid = (p1.tbi << 1) | p0.tbi; - tbii = tbid & ~((p1.tbid << 1) | p0.tbid); - } else { - tbid = p0.tbi; - tbii = tbid & !p0.tbid; - } + tbid = aa64_va_parameter_tbi(tcr, mmu_idx); + tbii = tbid & ~aa64_va_parameter_tbid(tcr, mmu_idx); flags = FIELD_DP32(flags, TBFLAG_A64, TBII, tbii); flags = FIELD_DP32(flags, TBFLAG_A64, TBID, tbid);