From patchwork Tue Jan 9 19:04:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 10153129 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2B157603ED for ; Tue, 9 Jan 2018 19:06:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CE5328578 for ; Tue, 9 Jan 2018 19:06:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 110E32858F; Tue, 9 Jan 2018 19:06:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 812B128578 for ; Tue, 9 Jan 2018 19:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964923AbeAITGJ (ORCPT ); Tue, 9 Jan 2018 14:06:09 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:60008 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964887AbeAITFj (ORCPT ); Tue, 9 Jan 2018 14:05:39 -0500 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 625431610; Tue, 9 Jan 2018 11:05:39 -0800 (PST) Received: from e107814-lin.cambridge.arm.com (e107814-lin.cambridge.arm.com [10.1.206.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D9BD43F318; Tue, 9 Jan 2018 11:05:36 -0800 (PST) From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com, linux-kernel@vger.kernel.org, kristina.martsenko@arm.com, peter.maydell@linaro.org, suzuki.poulose@arm.com, pbonzini@redhat.com, rkrcmar@redhat.com, will.deacon@arm.com, ard.biesheuvel@linaro.org, mark.rutland@arm.com, catalin.marinas@arm.com Subject: [kvmtool hack 2/3] kvmtool: arm64: Add support for guest physical address size Date: Tue, 9 Jan 2018 19:04:13 +0000 Message-Id: <20180109190414.4017-19-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180109190414.4017-1-suzuki.poulose@arm.com> References: <20180109190414.4017-1-suzuki.poulose@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add an option to specify the physical address size used by this VM. Signed-off-by: Suzuki K Poulose --- arm/aarch64/include/kvm/kvm-config-arch.h | 5 ++++- arm/include/arm-common/kvm-config-arch.h | 1 + arm/kvm.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/arm/aarch64/include/kvm/kvm-config-arch.h b/arm/aarch64/include/kvm/kvm-config-arch.h index 04be43d..c4bb207 100644 --- a/arm/aarch64/include/kvm/kvm-config-arch.h +++ b/arm/aarch64/include/kvm/kvm-config-arch.h @@ -8,7 +8,10 @@ "Create PMUv3 device"), \ OPT_U64('\0', "kaslr-seed", &(cfg)->kaslr_seed, \ "Specify random seed for Kernel Address Space " \ - "Layout Randomization (KASLR)"), + "Layout Randomization (KASLR)"), \ + OPT_UINTEGER('\0', "phys-shift", &(cfg)->phys_shift, \ + "Specify maximum physical address size (not " \ + "the amount of memory)"), #include "arm-common/kvm-config-arch.h" diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h index 6a196f1..d841b0b 100644 --- a/arm/include/arm-common/kvm-config-arch.h +++ b/arm/include/arm-common/kvm-config-arch.h @@ -11,6 +11,7 @@ struct kvm_config_arch { bool has_pmuv3; u64 kaslr_seed; enum irqchip_type irqchip; + unsigned int phys_shift; }; int irqchip_parser(const struct option *opt, const char *arg, int unset); diff --git a/arm/kvm.c b/arm/kvm.c index 2ab436e..7573391 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -18,6 +18,14 @@ struct kvm_ext kvm_req_ext[] = { { 0, 0 }, }; +#ifndef KVM_CAP_ARM_CONFIG_PHYS_SHIFT +#define KVM_CAP_ARM_CONFIG_PHYS_SHIFT 151 +#endif + +#ifndef KVM_ARM_SET_PHYS_SIZE +#define KVM_ARM_SET_PHYS_SIZE _IOW(KVMIO, 0xb2, __u32) +#endif + bool kvm__arch_cpu_supports_vm(void) { /* The KVM capability check is enough. */ @@ -57,8 +65,30 @@ void kvm__arch_set_cmdline(char *cmdline, bool video) { } +static void kvm__init_phys_size(struct kvm *kvm) +{ + if (!kvm->cfg.arch.phys_shift) + goto default_phys_size; + if (kvm->cfg.arch.phys_shift > 48) + die("Physical memory size is limited to 48bits, %d\n", + kvm->cfg.arch.phys_shift); + + if (!kvm__supports_extension(kvm, KVM_CAP_ARM_CONFIG_PHYS_SHIFT)) { + pr_warning("System doesn't support phys size configuration\n"); + goto default_phys_size; + } + if (ioctl(kvm->vm_fd, KVM_ARM_SET_PHYS_SIZE, &kvm->cfg.arch.phys_shift)) + die("Failed to set physical memory size to %dbits\n", + kvm->cfg.arch.phys_shift); + return; +default_phys_size: + kvm->cfg.arch.phys_shift = 40; + return; +} + void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size) { + kvm__init_phys_size(kvm); /* * Allocate guest memory. We must align our buffer to 64K to * correlate with the maximum guest page size for virtio-mmio.