Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3812062imm; Mon, 17 Sep 2018 03:43:50 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaQbPeiDExbSAMRGbHSH6XkRO629oBdrKyQeazsqSQTxBkP/NYmlNkfywcgNzgRpAOguWLi X-Received: by 2002:a63:4745:: with SMTP id w5-v6mr23354569pgk.140.1537181030803; Mon, 17 Sep 2018 03:43:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537181030; cv=none; d=google.com; s=arc-20160816; b=cWDajFvGLKy3RTmNPlgLg5R9n2i1gIw65OnMl9klWWRQgqsIsVK1h51kc5CbOeS0vG mLXs/rdjEcScfcJRxTGGxTmQBKC6JPmMZD5vY7xlXJqOVkH2B/G8jBwJ52XXjh8/QVjZ ac05j/fsYoU35JW8di2tt0MxbMd7X/nsk9ym8ItiBPz/ATL64vwwtqSDWO0LgyeKUD/2 +Pkmrk5vp9TqbVjoipCJuLzAVznULfhJTn0HKbUaSAl6VGJfDO0o65I/PSHeawjw0+tm 3KUyeokTawKdSAGTW93hJ/sAuzRybHpiwZa8swjVwr9TwTKz7fxJ/cbuoQXK76HOYrO0 9FqA== 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=0IaLHeIN717m/S/ukChgr2P1z4erwEXYX5izTvj+9h8=; b=uhvTPZ61DZxbygCtIcA3oi1kQovXgklTIRTIZRsPaXLOuwI+RHph5maN2oV3eQr8Jq PAxjW/JHGLmaq4qRkINJeuiPlWV1s9q615fwvq/y+aU5UZ0Tyj0yL5NFv85P0/WVyBHv kGcZmUqX36gik4bcgcxnUGjfsRWeXj7aM9a3HzPqgL5uP2qTBRerQwpTabdFYioNWThJ p6uvqkkrDzAvTV9MjS9cJ6SHm1tIeuw24xZAzQc7CcMzEExL/S7J5uPjB0uBJht3bAX5 NMB2XV9zJ3LPxrHSJiaNbXkou0umrvKQ3sxeXegEtFFNRQlyub3OhZ3mwX8/yesoAJNn Mw1g== 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 b5-v6si15201928plz.485.2018.09.17.03.43.36; Mon, 17 Sep 2018 03:43:50 -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 S1728535AbeIQQJ6 (ORCPT + 99 others); Mon, 17 Sep 2018 12:09:58 -0400 Received: from foss.arm.com ([217.140.101.70]:56652 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728317AbeIQQJ5 (ORCPT ); Mon, 17 Sep 2018 12:09:57 -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 006311BB2; Mon, 17 Sep 2018 03:43:10 -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 79B7E3F5BD; Mon, 17 Sep 2018 03:43:07 -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 17/18] kvm: arm64: Limit the minimum number of page table levels Date: Mon, 17 Sep 2018 11:41:39 +0100 Message-Id: <20180917104144.19188-18-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 Since we are about to remove the lower limit on the IPA size, make sure that we do not go to 1 level page table (e.g, with 32bit IPA on 64K host with concatenation) to avoid splitting the host PMD huge pages at stage2. Cc: Marc Zyngier Cc: Christoffer Dall Signed-off-by: Suzuki K Poulose --- arch/arm64/include/asm/stage2_pgtable.h | 8 +++++++- arch/arm64/kvm/reset.c | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/stage2_pgtable.h b/arch/arm64/include/asm/stage2_pgtable.h index 352ec4158fdf..6a56fdff0823 100644 --- a/arch/arm64/include/asm/stage2_pgtable.h +++ b/arch/arm64/include/asm/stage2_pgtable.h @@ -72,8 +72,14 @@ /* * The number of PTRS across all concatenated stage2 tables given by the * number of bits resolved at the initial level. + * If we force more number of levels than necessary, we may have + * stage2_pgdir_shift > IPA, in which case, stage2_pgd_ptrs will have + * one entry. */ -#define __s2_pgd_ptrs(ipa, lvls) (1 << ((ipa) - pt_levels_pgdir_shift((lvls)))) +#define pgd_ptrs_shift(ipa, pgdir_shift) \ + ((ipa) > (pgdir_shift) ? ((ipa) - (pgdir_shift)) : 0) +#define __s2_pgd_ptrs(ipa, lvls) \ + (1 << (pgd_ptrs_shift((ipa), pt_levels_pgdir_shift(lvls)))) #define __s2_pgd_size(ipa, lvls) (__s2_pgd_ptrs((ipa), (lvls)) * sizeof(pgd_t)) #define stage2_pgd_ptrs(kvm) __s2_pgd_ptrs(kvm_phys_shift(kvm), kvm_stage2_levels(kvm)) diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c index 76972b19bdd7..0393bb974b23 100644 --- a/arch/arm64/kvm/reset.c +++ b/arch/arm64/kvm/reset.c @@ -190,10 +190,19 @@ int kvm_arm_config_vm(struct kvm *kvm, unsigned long type) { u64 vtcr = VTCR_EL2_FLAGS; u64 parange; + u8 lvls; if (type) return -EINVAL; + /* + * Use a minimum 2 level page table to prevent splitting + * host PMD huge pages at stage2. + */ + lvls = stage2_pgtable_levels(KVM_PHYS_SHIFT); + if (lvls < 2) + lvls = 2; + parange = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1) & 7; if (parange > ID_AA64MMFR0_PARANGE_MAX) parange = ID_AA64MMFR0_PARANGE_MAX; @@ -210,7 +219,8 @@ 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(stage2_pgtable_levels(KVM_PHYS_SHIFT)); + + vtcr |= VTCR_EL2_LVLS_TO_SL0(lvls); vtcr |= VTCR_EL2_T0SZ(KVM_PHYS_SHIFT); kvm->arch.vtcr = vtcr; -- 2.19.0