From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36284C433DB for ; Tue, 9 Mar 2021 16:41:10 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C8D8A64FF3 for ; Tue, 9 Mar 2021 16:41:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8D8A64FF3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wYYzk48cJntGb05OTnUeGWb+5eyiXngHyV3nf8fSMAE=; b=W4gkDGLwmXvUQMsxPoblvNt+z I7yEtM5BAvGNR7mnHyYO6mR6VdEi7J9Ult4nFUSQFPNiDLvc8aTpdy9lCwiWyKE4BkQqYtHS9IyZ+ 7zYSV8Nqp8sNoNeSCuH2LDwTuVpYHR+yfg7aat9lV44R0tM0vIJiW5DPSp7eiX+elIGqBprpFOhVX xKKEd3js8uBvwH2Ub8FxiWXRoVI9Yl+hsHFJLl9w6bFUvZ1aPkwjlbR90PaXmLJ1osIPWgClvUUzW nZx2dghomqgKwR1dE62VaNyo5Wb7fnIyKU3+GY+AK4i75xFtuHqxdItZRBYQ/6KUUIiJf++GeK0iy 4nQ9Sn91A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lJfOe-0056Kg-Je; Tue, 09 Mar 2021 16:39:48 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lJfOO-0056HL-4b for linux-arm-kernel@lists.infradead.org; Tue, 09 Mar 2021 16:39:35 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9EA526521D; Tue, 9 Mar 2021 16:39:30 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=hot-poop.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lJfOK-000ayV-Tg; Tue, 09 Mar 2021 16:39:29 +0000 From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org Cc: Andre Przywara , Will Deacon , Alexandru Elisei Subject: [PATCH 3/3][Do not merge] kvmtool: arm64: Configure VM with the minimal required IPA space Date: Tue, 9 Mar 2021 16:39:09 +0000 Message-Id: <20210309163909.822149-4-maz@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210309163909.822149-1-maz@kernel.org> References: <20210309163909.822149-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: linux-arm-kernel@lists.infradead.org, Andre.Przywara@arm.com, will@kernel.org, alexandru.elisei@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210309_163932_488367_B6296787 X-CRM114-Status: GOOD ( 16.19 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There is some value in keeping the IPA space small, as it reduces the size of the stage-2 page tables. Let's compute the required space at VM creation time, and inform the kernel of our requirements. Signed-off-by: Marc Zyngier --- arm/aarch64/kvm.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index c4f81d0..981cb42 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -3,6 +3,7 @@ #include #include +#include /* * Return the TEXT_OFFSET value that the guest kernel expects. Note @@ -59,5 +60,22 @@ int kvm__arch_get_ipa_limit(struct kvm *kvm) int kvm__get_vm_type(struct kvm *kvm) { - return kvm__arch_get_ipa_limit(kvm); + unsigned int ipa_bits, max_ipa_bits; + unsigned long max_ipa; + + /* If we're running on an old kernel, use 0 as the VM type */ + max_ipa_bits = kvm__arch_get_ipa_limit(kvm); + if (!max_ipa_bits) + return 0; + + /* Otherwise, compute the minimal required IPA size */ + max_ipa = ARM_MEMORY_AREA + kvm->cfg.ram_size - 1; + ipa_bits = max(32, fls_long(max_ipa)); + pr_debug("max_ipa %lx ipa_bits %d max_ipa_bits %d", + max_ipa, ipa_bits, max_ipa_bits); + + if (ipa_bits > max_ipa_bits) + die("Memory too large for this system (needs %d bits, %d available)", ipa_bits, max_ipa_bits); + + return ipa_bits; } -- 2.30.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel