Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp973402imm; Wed, 26 Sep 2018 09:34:45 -0700 (PDT) X-Google-Smtp-Source: ACcGV608Hp9i291ojdDxs7/WBnnhpXK3ot5RYgziBk0FArjcV6fY3MuuatugfkZWaQsnRG/y9NjO X-Received: by 2002:a63:fb07:: with SMTP id o7-v6mr6421743pgh.333.1537979685349; Wed, 26 Sep 2018 09:34:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537979685; cv=none; d=google.com; s=arc-20160816; b=Y/gJpaJBCqofz4tJDhhh2BkBlt4ULCfwfGUPOWj6FHFS4o959aW/foFzlIOR5Qsj4E iobkocp2R/uL4mEfKqQ2UCvbRpQs8JTK6H5+k+A0fgJ6dPAtlTTzbPujN9i2+CsH0xXq RZb6YPg9cy6r3vue6F8NDqxS0WpTvCFXb1YsbbqI1LGu4wdZhMGljzHA91//s0vxLE+s nIGbcppLjtlD703enqn7K7qDpVXv/zlIF1xjW94bTiKQj8sPjMQ2nq09iDcJe8EANOtA 11mGiw2nHmtD9aj0NCWtOC11f0Z1fXNwK+uE5ETaDLnRS57C/L8DPuMLU+RTgWOZ31WU 2bCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=uohqS8xetXJe6M0a8m4z+hDfEk1vW4OkKc6nAfqMXEw=; b=ikZEhsnBI1xkJTgx0ZPzy5P9kwgllhEwkKnEBiZn9NUx+KSSE7lR3TFJf7d8bGDGOJ lINa/omYfwuUQ7dHtQRx0aGPVGbjmMPc6PS0wrNttxL/txZ2mxZblNJBagsQSPUs0Ocl 9E8oJavqTzuTdVZ3/BqZutLOX229Lfu7OqfRLIqB3Wx9sIRRoEpvEGGvj2o3+gb/fIFX hTen2dCPnjX+xrGhSunxryEqWyT8beTReM5xZQXSpcjmJt3ITAZuqF61P2l61QLx/VC1 KihuRtHzJHQCjIVwxi/VZpOEku0sytmVmLHbMyVrtZ7Ll9DngNWk51YMo+Frf8D5mRNo tpAQ== 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 h185-v6si5419608pfc.172.2018.09.26.09.34.30; Wed, 26 Sep 2018 09:34:45 -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 S1728939AbeIZWrs (ORCPT + 99 others); Wed, 26 Sep 2018 18:47:48 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50082 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728685AbeIZWrq (ORCPT ); Wed, 26 Sep 2018 18:47:46 -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 8659B15AD; Wed, 26 Sep 2018 09:34:00 -0700 (PDT) Received: from en101.Emea.Arm.com (en101.emea.arm.com [10.4.13.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0CA6E3F5B3; Wed, 26 Sep 2018 09:33:57 -0700 (PDT) From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, marc.zyngier@arm.com, cdall@kernel.org, eric.auger@redhat.com, suzuki.poulose@arm.com, will.deacon@arm.com, dave.martin@arm.com, peter.maydell@linaro.org, pbonzini@redhat.com, rkrcmar@redhat.com, julien.grall@arm.com, linux-kernel@vger.kernel.org Subject: [PATCH v6 12/18] kvm: arm64: Configure VTCR_EL2.SL0 per VM Date: Wed, 26 Sep 2018 17:32:48 +0100 Message-Id: <20180926163258.20218-13-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180926163258.20218-1-suzuki.poulose@arm.com> References: <20180926163258.20218-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org VTCR_EL2 holds the following key stage2 translation table parameters: SL0 - Entry level in the page table lookup. T0SZ - Denotes the size of the memory addressed by the table. We have been using fixed values for the SL0 depending on the page size as we have a fixed IPA size. But since we are about to make it dynamic, we need to calculate the SL0 at runtime per VM. This patch adds a helper to compute the value of SL0 for a VM based on the IPA size. Cc: Marc Zyngier Cc: Christoffer Dall Reviewed-by: Eric Auger Signed-off-by: Suzuki K Poulose --- Changes since v5: - Improve commentary. Changes since v3: - Update reference to latest ARM ARM. - Update per-vm VTCR value of SL0. - Add helpers to decode levels from SL0. - Didn't pick up Reviewed-by tag from Eric, as there are some new changes in this version --- arch/arm64/include/asm/kvm_arm.h | 69 +++++++++++++++++++++++--------- arch/arm64/kvm/reset.c | 1 + 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index b236d90ca056..f913adb44f93 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -121,7 +121,6 @@ #define VTCR_EL2_IRGN0_WBWA TCR_IRGN0_WBWA #define VTCR_EL2_SL0_SHIFT 6 #define VTCR_EL2_SL0_MASK (3 << VTCR_EL2_SL0_SHIFT) -#define VTCR_EL2_SL0_LVL1 (1 << VTCR_EL2_SL0_SHIFT) #define VTCR_EL2_T0SZ_MASK 0x3f #define VTCR_EL2_VS_SHIFT 19 #define VTCR_EL2_VS_8BIT (0 << VTCR_EL2_VS_SHIFT) @@ -144,30 +143,60 @@ #define VTCR_EL2_COMMON_BITS (VTCR_EL2_SH0_INNER | VTCR_EL2_ORGN0_WBWA | \ VTCR_EL2_IRGN0_WBWA | VTCR_EL2_RES1) +/* + * VTCR_EL2:SL0 indicates the entry level for Stage2 translation. + * Interestingly, it depends on the page size. + * See D.10.2.121, VTCR_EL2, in ARM DDI 0487C.a + * + * ----------------------------------------- + * | Entry level | 4K | 16K/64K | + * ------------------------------------------ + * | Level: 0 | 2 | - | + * ------------------------------------------ + * | Level: 1 | 1 | 2 | + * ------------------------------------------ + * | Level: 2 | 0 | 1 | + * ------------------------------------------ + * | Level: 3 | - | 0 | + * ------------------------------------------ + * + * The table roughly translates to : + * + * SL0(PAGE_SIZE, Entry_level) = TGRAN_SL0_BASE - Entry_Level + * + * Where TGRAN_SL0_BASE is a magic number depending on the page size: + * TGRAN_SL0_BASE(4K) = 2 + * TGRAN_SL0_BASE(16K) = 3 + * TGRAN_SL0_BASE(64K) = 3 + * provided we take care of ruling out the unsupported cases and + * Entry_Level = 4 - Number_of_levels. + * + */ #ifdef CONFIG_ARM64_64K_PAGES -/* - * Stage2 translation configuration: - * 64kB pages (TG0 = 1) - * 2 level page tables (SL = 1) - */ -#define VTCR_EL2_TGRAN_FLAGS (VTCR_EL2_TG0_64K | VTCR_EL2_SL0_LVL1) + +#define VTCR_EL2_TGRAN VTCR_EL2_TG0_64K +#define VTCR_EL2_TGRAN_SL0_BASE 3UL + #elif defined(CONFIG_ARM64_16K_PAGES) -/* - * Stage2 translation configuration: - * 16kB pages (TG0 = 2) - * 2 level page tables (SL = 1) - */ -#define VTCR_EL2_TGRAN_FLAGS (VTCR_EL2_TG0_16K | VTCR_EL2_SL0_LVL1) + +#define VTCR_EL2_TGRAN VTCR_EL2_TG0_16K +#define VTCR_EL2_TGRAN_SL0_BASE 3UL + #else /* 4K */ -/* - * Stage2 translation configuration: - * 4kB pages (TG0 = 0) - * 3 level page tables (SL = 1) - */ -#define VTCR_EL2_TGRAN_FLAGS (VTCR_EL2_TG0_4K | VTCR_EL2_SL0_LVL1) + +#define VTCR_EL2_TGRAN VTCR_EL2_TG0_4K +#define VTCR_EL2_TGRAN_SL0_BASE 2UL + #endif -#define VTCR_EL2_FLAGS (VTCR_EL2_COMMON_BITS | VTCR_EL2_TGRAN_FLAGS) +#define VTCR_EL2_LVLS_TO_SL0(levels) \ + ((VTCR_EL2_TGRAN_SL0_BASE - (4 - (levels))) << VTCR_EL2_SL0_SHIFT) +#define VTCR_EL2_SL0_TO_LVLS(sl0) \ + ((sl0) + 4 - VTCR_EL2_TGRAN_SL0_BASE) +#define VTCR_EL2_LVLS(vtcr) \ + VTCR_EL2_SL0_TO_LVLS(((vtcr) & VTCR_EL2_SL0_MASK) >> VTCR_EL2_SL0_SHIFT) + +#define VTCR_EL2_FLAGS (VTCR_EL2_COMMON_BITS | VTCR_EL2_TGRAN) /* * ARM VMSAv8-64 defines an algorithm for finding the translation table * descriptors in section D4.2.8 in ARM DDI 0487C.a. diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c index 616120c4176b..1ced1e37374e 100644 --- a/arch/arm64/kvm/reset.c +++ b/arch/arm64/kvm/reset.c @@ -160,6 +160,7 @@ int kvm_arm_config_vm(struct kvm *kvm, unsigned long type) if (phys_shift > KVM_PHYS_SHIFT) phys_shift = KVM_PHYS_SHIFT; vtcr |= VTCR_EL2_T0SZ(phys_shift); + vtcr |= VTCR_EL2_LVLS_TO_SL0(kvm_stage2_levels(kvm)); /* * Enable the Hardware Access Flag management, unconditionally -- 2.19.0