Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp893587imm; Fri, 29 Jun 2018 08:04:29 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIDT3WNNhJfHQLhhmIlPHYv0bPuVQASXnTh+P1TpA4qUq36aW+/5qOJaBsl+9bgPxmN9fq8 X-Received: by 2002:a63:9d87:: with SMTP id i129-v6mr12477279pgd.395.1530284669135; Fri, 29 Jun 2018 08:04:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530284669; cv=none; d=google.com; s=arc-20160816; b=Ux0EcIrnkqh+kWwgY0goNCQaTosZSddKhQzEp9G7YXdT+z94IWR2fBNpciQ/42RTJ6 Y2fLXQMQTUimNPNbIpfhqnzFmxanzUGirY5+g6SafIJaSm7eUPzd5eVKHcs4CgmMxnJ5 3xG2TE2UuVNNp69aUGu5eBiQhLpEP38GH8E1bV+vvLQEpSpH7qZZ9X6mZjSDXJ7IY2nV X+adzAARNFQtwuYbycKlIRVGGgW5JU1CgZhHxI0c7X8hIMUm8sizE0JV8aWLAdSXRPJN pYFgxiabeIVKcFjCETUamTqLZXpgO2gEZ/ByhUxTgGC9VxGcufPz7sCkdR0rSOhrf/SO afww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=WxKiJuCOgCKHZlA9L7mT6aB/ZY5h90zBGsnlZ8sLFGw=; b=CkP1rYZZiTOiNrj87CWmUxlSCK8Z9CG0vNPvBn6PnPaBEZc8Pg8HbPW4BjOuXJw5OD tCi0x0jC0bju/OL9mETB9FRTFLprZP+iMZ/SlNIw2uzxYYBzQpzdM9WIYHDndgzyz98/ eha+vxyc5IAMR37QlM2el8m0prXcqYSF/8S5k7znvX60h7bsvKThqht9cSS/eTLPOMSl uxeD+eFAlpEGFKtAJ3zqbm3B64DVgIDH6ql+zNA3LqMBseIWkLy3HXiXQ2GUyeq3jIel rGOFiXhrLh62dgK60JUy50Bf67m/8PaUvDmwlM/APBP7vlOvZqRl4uu80JGwB7Tof5iJ TZcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6-v6si9610144pla.124.2018.06.29.08.04.09; Fri, 29 Jun 2018 08:04:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755235AbeF2LQ3 (ORCPT + 99 others); Fri, 29 Jun 2018 07:16:29 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:60072 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755201AbeF2LQY (ORCPT ); Fri, 29 Jun 2018 07:16:24 -0400 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 6651A1684; Fri, 29 Jun 2018 04:16:24 -0700 (PDT) Received: from en101.cambridge.arm.com (en101.cambridge.arm.com [10.1.206.73]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0F87C3F266; Fri, 29 Jun 2018 04:16:21 -0700 (PDT) From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, james.morse@arm.com, marc.zyngier@arm.com, cdall@kernel.org, eric.auger@redhat.com, julien.grall@arm.com, will.deacon@arm.com, catalin.marinas@arm.com, punit.agrawal@arm.com, qemu-devel@nongnu.org, Suzuki K Poulose Subject: [PATCH v3 04/20] kvm: arm64: Clean up VTCR_EL2 initialisation Date: Fri, 29 Jun 2018 12:15:24 +0100 Message-Id: <1530270944-11351-5-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530270944-11351-1-git-send-email-suzuki.poulose@arm.com> References: <1530270944-11351-1-git-send-email-suzuki.poulose@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the new helper for converting the parange to the physical shift. Also, add the missing definitions for the VTCR_EL2 register fields and use them instead of hard coding numbers. Cc: Marc Zyngier Cc: Christoffer Dall Signed-off-by: Suzuki K Poulose --- Changes since V2 - Part 2 of the split from original patch. - Also add missing VTCR field helpers and use them. --- arch/arm64/include/asm/kvm_arm.h | 3 +++ arch/arm64/kvm/hyp/s2-setup.c | 30 ++++++------------------------ 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index 6dd285e..3dffd38 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -106,6 +106,7 @@ #define VTCR_EL2_RES1 (1 << 31) #define VTCR_EL2_HD (1 << 22) #define VTCR_EL2_HA (1 << 21) +#define VTCR_EL2_PS_SHIFT TCR_EL2_PS_SHIFT #define VTCR_EL2_PS_MASK TCR_EL2_PS_MASK #define VTCR_EL2_TG0_MASK TCR_TG0_MASK #define VTCR_EL2_TG0_4K TCR_TG0_4K @@ -126,6 +127,8 @@ #define VTCR_EL2_VS_8BIT (0 << VTCR_EL2_VS_SHIFT) #define VTCR_EL2_VS_16BIT (1 << VTCR_EL2_VS_SHIFT) +#define VTCR_EL2_T0SZ(x) TCR_T0SZ(x) + /* * We configure the Stage-2 page tables to always restrict the IPA space to be * 40 bits wide (T0SZ = 24). Systems with a PARange smaller than 40 bits are diff --git a/arch/arm64/kvm/hyp/s2-setup.c b/arch/arm64/kvm/hyp/s2-setup.c index 603e1ee..81094f1 100644 --- a/arch/arm64/kvm/hyp/s2-setup.c +++ b/arch/arm64/kvm/hyp/s2-setup.c @@ -19,11 +19,13 @@ #include #include #include +#include u32 __hyp_text __init_stage2_translation(void) { u64 val = VTCR_EL2_FLAGS; u64 parange; + u32 phys_shift; u64 tmp; /* @@ -34,30 +36,10 @@ u32 __hyp_text __init_stage2_translation(void) parange = read_sysreg(id_aa64mmfr0_el1) & 7; if (parange > ID_AA64MMFR0_PARANGE_MAX) parange = ID_AA64MMFR0_PARANGE_MAX; - val |= parange << 16; + val |= parange << VTCR_EL2_PS_SHIFT; /* Compute the actual PARange... */ - switch (parange) { - case 0: - parange = 32; - break; - case 1: - parange = 36; - break; - case 2: - parange = 40; - break; - case 3: - parange = 42; - break; - case 4: - parange = 44; - break; - case 5: - default: - parange = 48; - break; - } + phys_shift = id_aa64mmfr0_parange_to_phys_shift(parange); /* * ... and clamp it to 40 bits, unless we have some braindead @@ -65,7 +47,7 @@ u32 __hyp_text __init_stage2_translation(void) * return that value for the rest of the kernel to decide what * to do. */ - val |= 64 - (parange > 40 ? 40 : parange); + val |= VTCR_EL2_T0SZ(phys_shift > 40 ? 40 : phys_shift); /* * Check the availability of Hardware Access Flag / Dirty Bit @@ -86,5 +68,5 @@ u32 __hyp_text __init_stage2_translation(void) write_sysreg(val, vtcr_el2); - return parange; + return phys_shift; } -- 2.7.4