Received: by 10.213.65.68 with SMTP id h4csp651074imn; Tue, 27 Mar 2018 06:22:39 -0700 (PDT) X-Google-Smtp-Source: AG47ELvGA6QIf7Qn7cGJbTHxdCNIFQS8lAR4krdLOjNr8TQU3MdNQjqwmqyb3jgZS41wEkzqWB24 X-Received: by 10.99.117.68 with SMTP id f4mr32138453pgn.437.1522156959012; Tue, 27 Mar 2018 06:22:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522156958; cv=none; d=google.com; s=arc-20160816; b=b6mFIhnolL6QRCW13Zt1T5xGntSvaI3sNAekx05zMu1uHj8UUvVSpPGq0dlgkru9e9 1Eh2OOLQaxMLR7jh4FMmbflX2KUaWrfLlyF+/nowCKslGU/brno0zFMxHvpEdpFLY70h h4BMTEVycTCz8fcdymlZiPr8blckmGaA8eAEiMQnZ2c3GAvQEYoGZ6GiBjeT0/4XXP41 TstYBNqLp96f6oT86WlOuO5cxAuZDfKDzlnKY16W5NEvykpL3TouVxvO0nZqIkUIKekI 4P+YQnTy8rrDukqmeMLf54Rr0WWhM6Z+QTfdzl1/srK3HjZhLyo6qtkX/sDzTgx/wWYr gqSA== 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=xpoC+K09hPBl3yZnzNYRaoGjDsIgcOP641GZSW3zxAU=; b=mYuCf9zSgn1TCIsvveOqOSlc96QH5L5M+dl8CSlyFalfoYlw2/tmc4yIAQF03V6iPd xoXAIO2NiqmT7EvLQASm3qtez0+cH4rOlu8WSGq/iqQRZ5N0JTTNtH6RdimZyB+hAZy6 OHuE/cfTbjJQeSo6JBxt3cONJwLgkjqDelfShmp0CYrOwj/HWKSHNkP9PkQwLRfKy4/g yx8EYM+b552xPIYotlvgQj/OUrNILKM6/mqeqru9FgAqUWILxZMXIXgwLz/+ZttWBNyv V4b2tVDIU03eybjCgiAYwEQ9rQonkrEOLRwx26qZx0R/dJGsQotxYVgIXmZnm+1ti6uR QIzA== 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 g8si842702pgv.740.2018.03.27.06.22.24; Tue, 27 Mar 2018 06:22:38 -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 S1753122AbeC0NUo (ORCPT + 99 others); Tue, 27 Mar 2018 09:20:44 -0400 Received: from foss.arm.com ([217.140.101.70]:55128 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752480AbeC0NQg (ORCPT ); Tue, 27 Mar 2018 09:16:36 -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 4C25880D; Tue, 27 Mar 2018 06:16:36 -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 A32CA3F24A; Tue, 27 Mar 2018 06:16:33 -0700 (PDT) From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, cdall@kernel.org, marc.zyngier@arm.com, punit.agrawal@arm.com, will.deacon@arm.com, catalin.marinas@arm.com, pbonzini@redhat.com, rkrcmar@redhat.com, ard.biesheuvel@linaro.org, peter.maydell@linaro.org, kristina.martsenko@arm.com, mark.rutland@arm.com, Suzuki K Poulose Subject: [PATCH v2 12/17] kvm: arm/arm64: Expose supported physical address limit for VM Date: Tue, 27 Mar 2018 14:15:22 +0100 Message-Id: <1522156531-28348-13-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522156531-28348-1-git-send-email-suzuki.poulose@arm.com> References: <1522156531-28348-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 Expose the maximum physical address size supported by the host for a VM. This could be later used by the userspace to choose the appropriate size for a given VM. The limit is determined as the minimum of actual CPU limit, the kernel limit (i.e, either 48 or 52) and the stage2 page table support limit (which is 40bits at the moment). For backward compatibility, we support a minimum of 40bits. The limit will be lifted as we add support for the stage2 to support the host kernel PA limit. This value may be different from what is exposed to the VM via CPU ID registers. The limit only applies to the stage2 page table. Cc: Christoffer Dall Cc: Marc Zyngier Cc: Peter Maydel Signed-off-by: Suzuki K Poulose --- Documentation/virtual/kvm/api.txt | 14 ++++++++++++++ arch/arm/include/asm/kvm_mmu.h | 5 +++++ arch/arm64/include/asm/kvm_mmu.h | 5 +++++ include/uapi/linux/kvm.h | 6 ++++++ virt/kvm/arm/arm.c | 6 ++++++ 5 files changed, 36 insertions(+) diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt index 792fa87..55908a8 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -3500,6 +3500,20 @@ Returns: 0 on success; -1 on error This ioctl can be used to unregister the guest memory region registered with KVM_MEMORY_ENCRYPT_REG_REGION ioctl above. +4.113 KVM_ARM_GET_MAX_VM_PHYS_SHIFT +Capability: basic +Architectures: arm, arm64 +Type: system ioctl +Parameters: none +Returns: log2(Maximum physical address space size) supported by the +hyperviosr. + +This ioctl can be used to identify the maximum physical address space size +supported by the hypervisor. The returned value indicates the maximum size +of the address that can be resolved by the stage2 translation table on +arm/arm64. On arm64, the value is decided based on the host kernel +configuration and the system wide safe value of ID_AA64MMFR0_EL1:PARange. +This may not match the value exposed to the VM in CPU ID registers. 5. The kvm_run structure ------------------------ diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h index 305aa40..50896da 100644 --- a/arch/arm/include/asm/kvm_mmu.h +++ b/arch/arm/include/asm/kvm_mmu.h @@ -318,6 +318,11 @@ static inline int kvm_map_vectors(void) #define kvm_phys_to_vttbr(addr) (addr) +static inline u32 kvm_get_ipa_limit(void) +{ + return KVM_PHYS_SHIFT; +} + #endif /* !__ASSEMBLY__ */ #endif /* __ARM_KVM_MMU_H__ */ diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 447bc10..a4c8c00 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -411,5 +411,10 @@ static inline u64 kvm_vttbr_baddr_mask(struct kvm *kvm) return GENMASK_ULL(PHYS_MASK_SHIFT - 1, x); } +static inline u32 kvm_get_ipa_limit(void) +{ + return KVM_PHYS_SHIFT; +} + #endif /* __ASSEMBLY__ */ #endif /* __ARM64_KVM_MMU_H__ */ diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 0fb5ef9..b737ee1 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -763,6 +763,12 @@ struct kvm_ppc_resize_hpt { #define KVM_GET_EMULATED_CPUID _IOWR(KVMIO, 0x09, struct kvm_cpuid2) /* + * Get the maximum physical address size supported by the host. + * Returns log2(Max-Physical-Address-Size) + */ +#define KVM_ARM_GET_MAX_VM_PHYS_SHIFT _IO(KVMIO, 0x0a) + +/* * Extension capability list. */ #define KVM_CAP_IRQCHIP 0 diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index 8b35a47..53bb05c 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -64,6 +64,7 @@ static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1); static u32 kvm_next_vmid; static unsigned int kvm_vmid_bits __read_mostly; static DEFINE_SPINLOCK(kvm_vmid_lock); +static u32 kvm_ipa_limit; static bool vgic_present; @@ -246,6 +247,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) long kvm_arch_dev_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) { + if (ioctl == KVM_ARM_GET_MAX_VM_PHYS_SHIFT) + return kvm_ipa_limit; + return -EINVAL; } @@ -1348,6 +1352,8 @@ static int init_common_resources(void) kvm_vmid_bits = kvm_get_vmid_bits(); kvm_info("%d-bit VMID\n", kvm_vmid_bits); + kvm_ipa_limit = kvm_get_ipa_limit(); + return 0; } -- 2.7.4