From patchwork Thu Jun 16 13:48:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 12883893 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 26370C43334 for ; Thu, 16 Jun 2022 13:51:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7qeHXx9+cIiKCwhVHSXiLBuUh1bfn+Qu3ycTCT4VzMs=; b=Sc64BMj8zGoVfu Z69/xvaD0OweQEbaEPbzxKurIfpug3U2stgeGy7qi2siIqj3wsMexJLHjD+1vcCcMAUpFdytQE0LH 30Z8poKRJC9g4ZGSQvZCGqIB74wpfZf8/N+bGPk/Ksbh2VK+B7Lm+ypbLHoSjvyShNm55HotNIzaT O6QzUgc/FKDMld+WwjaEb44J3Au2BCyEJalHDgS7JvOHqvuo2VxPQ33WqcluuBThnZiT5ldZrYGb+ amhP3O8RzHDsPdAxa2LlZCWvgxNPUw+9U+ogO4pWQoZ95fxu5orKXZpH1xiK/yD178cUGLyZsnKKw /LRmXMdilpWfLhxbwIRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o1ptB-002aOb-Rj; Thu, 16 Jun 2022 13:50:25 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o1prO-002ZUP-RX for linux-arm-kernel@lists.infradead.org; Thu, 16 Jun 2022 13:48:36 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1F9D612FC; Thu, 16 Jun 2022 06:48:33 -0700 (PDT) Received: from monolith.localdoman (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 762273F7F5; Thu, 16 Jun 2022 06:48:31 -0700 (PDT) From: Alexandru Elisei To: will@kernel.org, julien.thierry.kdev@gmail.com, maz@kernel.org, suzuki.poulose@arm.com, julien@xen.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, james.morse@arm.com, andre.przywara@arm.com Subject: [PATCH v4 kvmtool 05/12] arm/arm64: Fail if RAM size is too large for 32-bit guests Date: Thu, 16 Jun 2022 14:48:21 +0100 Message-Id: <20220616134828.129006-6-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220616134828.129006-1-alexandru.elisei@arm.com> References: <20220616134828.129006-1-alexandru.elisei@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220616_064834_987896_BECB7E85 X-CRM114-Status: GOOD ( 11.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For 64-bit guests, kvmtool exists with an error in kvm__get_vm_type() if the memory size is larger than what KVM supports. For 32-bit guests, the RAM size is silently rounded down to ARM_LOMAP_MAX_MEMORY in kvm__arch_init(). Be consistent and exit with an error when the user has configured the wrong RAM size for 32-bit guests. Reviewed-by: Andre Przywara Signed-off-by: Alexandru Elisei --- arm/aarch32/kvm.c | 4 ++++ arm/aarch64/kvm.c | 5 +++++ arm/kvm.c | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arm/aarch32/kvm.c b/arm/aarch32/kvm.c index ae33ac92479a..9d68d7a15ee2 100644 --- a/arm/aarch32/kvm.c +++ b/arm/aarch32/kvm.c @@ -2,4 +2,8 @@ void kvm__arch_validate_cfg(struct kvm *kvm) { + if (kvm->cfg.ram_size > ARM_LOMAP_MAX_MEMORY) { + die("RAM size 0x%llx exceeds maximum allowed 0x%llx", + kvm->cfg.ram_size, ARM_LOMAP_MAX_MEMORY); + } } diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index ca348f118a56..2134528bf7f2 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -39,6 +39,11 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset) void kvm__arch_validate_cfg(struct kvm *kvm) { + if (kvm->cfg.arch.aarch32_guest && + kvm->cfg.ram_size > ARM_LOMAP_MAX_MEMORY) { + die("RAM size 0x%llx exceeds maximum allowed 0x%llx", + kvm->cfg.ram_size, ARM_LOMAP_MAX_MEMORY); + } } /* diff --git a/arm/kvm.c b/arm/kvm.c index c5913000e1ed..af0feae495d7 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -65,7 +65,7 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size) * If using THP, then our minimal alignment becomes 2M. * 2M trumps 64K, so let's go with that. */ - kvm->ram_size = min(ram_size, (u64)ARM_MAX_MEMORY(kvm)); + kvm->ram_size = ram_size; kvm->arch.ram_alloc_size = kvm->ram_size + SZ_2M; kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs(kvm, hugetlbfs_path, kvm->arch.ram_alloc_size);