Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3811893imm; Mon, 17 Sep 2018 03:43:40 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY6q2M9AC8WBvJ8J0oaEsRJPA/nmx81aaLW1HQZw7kgARLRU/A5raPHEkUTy+bPC6+eeN03 X-Received: by 2002:a63:da04:: with SMTP id c4-v6mr23244042pgh.398.1537181020719; Mon, 17 Sep 2018 03:43:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537181020; cv=none; d=google.com; s=arc-20160816; b=nG2bfrpwSWxcqEl0MH0S906tzKWJpWOhKvpVqBjej3keilRN8y/KfuhIRrPRzp/hXX IgezEppY9ffZDoq16F0OOqkY5wHhP9+fZWBSEnbkclxT9S7PwfcTgDJFgA+inKGe1dsc KM4O9DTNXiCPFGVbGat+bO/p3P8jeLbJNS0BnoZZYMXzGF5jSP0APC0FPeDQ0zuM0XFf 9o68jLCf9HIX1iBm5ns7EXIMqt2rPAMYaYC6f4WLi39nAIleQ4ANytIDk+OrnZ+OJYlk OxtlWnlJ1Bs1LlXdNtGdqbTkFnhRInqStpHSgKKFuRzX4BozGuiBLYC+9B/ibwvoM02Y Sh5Q== 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=yLBnqfrvHYZFJqMBw8OPrfQHdTKLT8iFyUCxtXq0BWY=; b=KSK15BNRSlWURmZOgnPECUmjqd+5T6TI6Zmm/Va5wcvTskf+EU1TjZcWCf+Ha5DwZb QPlrlkADEd9xUesiDLO6p62b9XBt+eFUF/T6r7uSEF83TPwO4KLQ6mO8UOWkUMISbXaH 5CRVTz9HBpEJCmpl8KkCjdnPTB7wnZdehXwqsoE4VnREjRU1x/y6hYs86Ov2ylv4X5i9 GjsYunPrmh+mS2YKnOVBo2/sDUaZlzSNbAqfJIgr30sYaBX20Zr3Hu0LsA4HfFCEZ+Dk cUcQHzbzKG1+4h8kzyr9jRosNFf8xaFbYIp+xcQGe7jFnOb5IiDqWY08Cxeks3CAVkQ3 kPiA== 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 r18-v6si14731241pgj.194.2018.09.17.03.43.25; Mon, 17 Sep 2018 03:43:40 -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 S1728455AbeIQQJr (ORCPT + 99 others); Mon, 17 Sep 2018 12:09:47 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:56584 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728440AbeIQQJq (ORCPT ); Mon, 17 Sep 2018 12:09: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 C79A01B4B; Mon, 17 Sep 2018 03:42:58 -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 4CC903F5BD; Mon, 17 Sep 2018 03:42:56 -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, pbonzini@redhat.com, rkrcmar@redhat.com, will.deacon@arm.com, catalin.marinas@arm.com, james.morse@arm.com, dave.martin@arm.com, julien.grall@arm.com, linux-kernel@vger.kernel.org, suzuki.poulose@arm.com Subject: [PATCH v5 13/18] kvm: arm64: Switch to per VM IPA limit Date: Mon, 17 Sep 2018 11:41:35 +0100 Message-Id: <20180917104144.19188-14-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180917104144.19188-1-suzuki.poulose@arm.com> References: <20180917104144.19188-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 Now that we can manage the stage2 page table per VM, switch the configuration details to per VM instance. The VTCR is updated with the values specific to the VM based on the configuration. We store the IPA size and the number of stage2 page table levels for the guest already in VTCR. Decode it back from the vtcr field wherever we need it. Cc: Marc Zyngier Cc: Christoffer Dall Signed-off-by: Suzuki K Poulose --- arch/arm64/include/asm/kvm_arm.h | 3 +++ arch/arm64/include/asm/kvm_mmu.h | 2 +- arch/arm64/include/asm/stage2_pgtable.h | 2 +- arch/arm64/kvm/reset.c | 4 +++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index 5c1487dc5dca..0a37c0513ede 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -200,6 +200,9 @@ ((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_IPA(vtcr) (64 - ((vtcr) & VTCR_EL2_T0SZ_MASK)) + /* * 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/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index ac3ca9690bad..77b1af9e64db 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -142,7 +142,7 @@ static inline unsigned long __kern_hyp_va(unsigned long v) */ #define KVM_PHYS_SHIFT (40) -#define kvm_phys_shift(kvm) KVM_PHYS_SHIFT +#define kvm_phys_shift(kvm) VTCR_EL2_IPA(kvm->arch.vtcr) #define kvm_phys_size(kvm) (_AC(1, ULL) << kvm_phys_shift(kvm)) #define kvm_phys_mask(kvm) (kvm_phys_size(kvm) - _AC(1, ULL)) diff --git a/arch/arm64/include/asm/stage2_pgtable.h b/arch/arm64/include/asm/stage2_pgtable.h index e5acda8e2e31..352ec4158fdf 100644 --- a/arch/arm64/include/asm/stage2_pgtable.h +++ b/arch/arm64/include/asm/stage2_pgtable.h @@ -43,7 +43,7 @@ */ #define stage2_pgtable_levels(ipa) ARM64_HW_PGTABLE_LEVELS((ipa) - 4) #define STAGE2_PGTABLE_LEVELS stage2_pgtable_levels(KVM_PHYS_SHIFT) -#define kvm_stage2_levels(kvm) stage2_pgtable_levels(kvm_phys_shift(kvm)) +#define kvm_stage2_levels(kvm) VTCR_EL2_LVLS(kvm->arch.vtcr) /* * With all the supported VA_BITs and 40bit guest IPA, the following condition diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c index d9b7a00993b6..51ecf0f7c912 100644 --- a/arch/arm64/kvm/reset.c +++ b/arch/arm64/kvm/reset.c @@ -167,7 +167,9 @@ int kvm_arm_config_vm(struct kvm *kvm, unsigned long type) vtcr |= (kvm_get_vmid_bits() == 16) ? VTCR_EL2_VS_16BIT : VTCR_EL2_VS_8BIT; - vtcr |= VTCR_EL2_LVLS_TO_SL0(kvm_stage2_levels(kvm)); + vtcr |= VTCR_EL2_LVLS_TO_SL0(stage2_pgtable_levels(KVM_PHYS_SHIFT)); + vtcr |= VTCR_EL2_T0SZ(KVM_PHYS_SHIFT); + kvm->arch.vtcr = vtcr; return 0; } -- 2.19.0