Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3525299pxf; Mon, 15 Mar 2021 11:29:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUsy8L/+mSKSojMJAbV56ZnvtvrZIyaEi7OmkTcdsAvk5zj9I0t6Uvc46buWQQHmXuZSXw X-Received: by 2002:a17:907:a06b:: with SMTP id ia11mr24978906ejc.294.1615832991760; Mon, 15 Mar 2021 11:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832991; cv=none; d=google.com; s=arc-20160816; b=U9HN/mgxdoWF43ctvhk+y16EfPmM5R6IIOX9sPEHlbRnwxHvxx8owd7ztjr3Q5LVaw EgHJm331ATUWpJgpGOlaeRGrysd3xXPIila1oJx5pARQ3XF4oVdtRBjcs5yidoZHev7T 7ZDGLwkR7WUeb2/NvQwTvFSOfXElLV+oOvud+5ZMHj85mILGmwmqYKjRVyYrRYsEX7ym VyeNNaHyaTMzoUNw2M10zqqPauwHSQxJrtCrg67M9VBDbE/39eLwvijTKh8SncxmeZDB FcSqbN8lfh2k632VyNgA0cTaDf1wQlk8fbG8DKrmTqQRMX1O8XI6GKwMhAoREf/exWS1 s7ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TPfsEHof3UUYPxfis++7N0ywc01rbO0c8sWjLuAQgXI=; b=ItLzKXIXBwZ07PF7jHg6rr6V9RU2xmnoFsnLzCGuLLg7X9caYfJM4WuEqBKG/UD8AW 1lesE1gGfAa872pV9FAsy1pesydM4Loo9+OlCBhRt5lBck8XpL4NEAOypc/d95DpZMdj O9gUvvMpQLLKvEt1Q0YNjN54zUm7081iOvatEfyaVrPs4BlVh+bdlfVPPufrObmUpFL2 5azVJrJboAlfQA44dKnwQYchZ+t4n6pOvIUr5OKRv2EEdtlA6DP5xG2eakZIog10wlWI lVaRw/BDVq8KwaKXfyo0zL5PFThzbHHSG6Gj5ERJBTKtMjoVkPdgBcf3ELSoaRcV1BFK pkyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Opf26Jjc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a20si12114356eda.157.2021.03.15.11.29.25; Mon, 15 Mar 2021 11:29:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Opf26Jjc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233279AbhCOOeq (ORCPT + 99 others); Mon, 15 Mar 2021 10:34:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:35186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233414AbhCOOBk (ORCPT ); Mon, 15 Mar 2021 10:01:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0FE8C64F2F; Mon, 15 Mar 2021 14:01:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816876; bh=cEGCOtMDGpg659riwCNFXJ4O5WLv1yj7SL9t6GPLMIU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Opf26JjcpjOnHZE7v46CYhy3+RPWAo+4p8hquFNOEzec2sZoAzpYg8hcQZd5IzpSx 5uTHiAhJ51oSyGOKfRJtDrHl+r/S/UqKRl4nHc6wYETD6zzWwPXnd3L3K9CsG6cDlp up22/CLQJ7431Rts8A5pSIARA9pJD7F24IaCUFoQ= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marc Zyngier , Andrew Jones , Eric Auger Subject: [PATCH 5.4 165/168] KVM: arm64: Reject VM creation when the default IPA size is unsupported Date: Mon, 15 Mar 2021 14:56:37 +0100 Message-Id: <20210315135555.785710226@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135550.333963635@linuxfoundation.org> References: <20210315135550.333963635@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Marc Zyngier Commit 7d717558dd5ef10d28866750d5c24ff892ea3778 upstream. KVM/arm64 has forever used a 40bit default IPA space, partially due to its 32bit heritage (where the only choice is 40bit). However, there are implementations in the wild that have a *cough* much smaller *cough* IPA space, which leads to a misprogramming of VTCR_EL2, and a guest that is stuck on its first memory access if userspace dares to ask for the default IPA setting (which most VMMs do). Instead, blundly reject the creation of such VM, as we can't satisfy the requirements from userspace (with a one-off warning). Also clarify the boot warning, and document that the VM creation will fail when an unsupported IPA size is provided. Although this is an ABI change, it doesn't really change much for userspace: - the guest couldn't run before this change, but no error was returned. At least userspace knows what is happening. - a memory slot that was accepted because it did fit the default IPA space now doesn't even get a chance to be registered. The other thing that is left doing is to convince userspace to actually use the IPA space setting instead of relying on the antiquated default. Fixes: 233a7cb23531 ("kvm: arm64: Allow tuning the physical address size for VM") Signed-off-by: Marc Zyngier Cc: stable@vger.kernel.org Reviewed-by: Andrew Jones Reviewed-by: Eric Auger Link: https://lore.kernel.org/r/20210311100016.3830038-2-maz@kernel.org Signed-off-by: Greg Kroah-Hartman --- Documentation/virt/kvm/api.txt | 3 +++ arch/arm64/kvm/reset.c | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) --- a/Documentation/virt/kvm/api.txt +++ b/Documentation/virt/kvm/api.txt @@ -172,6 +172,9 @@ is dependent on the CPU capability and t be retrieved using KVM_CAP_ARM_VM_IPA_SIZE of the KVM_CHECK_EXTENSION ioctl() at run-time. +Creation of the VM will fail if the requested IPA size (whether it is +implicit or explicit) is unsupported on the host. + Please note that configuring the IPA size does not affect the capability exposed by the guest CPUs in ID_AA64MMFR0_EL1[PARange]. It only affects size of the address translated by the stage2 level (guest physical to --- a/arch/arm64/kvm/reset.c +++ b/arch/arm64/kvm/reset.c @@ -378,10 +378,10 @@ void kvm_set_ipa_limit(void) pr_info("kvm: Limiting the IPA size due to kernel %s Address limit\n", (va_max < pa_max) ? "Virtual" : "Physical"); - WARN(ipa_max < KVM_PHYS_SHIFT, - "KVM IPA limit (%d bit) is smaller than default size\n", ipa_max); kvm_ipa_limit = ipa_max; - kvm_info("IPA Size Limit: %dbits\n", kvm_ipa_limit); + kvm_info("IPA Size Limit: %d bits%s\n", kvm_ipa_limit, + ((kvm_ipa_limit < KVM_PHYS_SHIFT) ? + " (Reduced IPA size, limited VM/VMM compatibility)" : "")); } /* @@ -408,6 +408,11 @@ int kvm_arm_setup_stage2(struct kvm *kvm return -EINVAL; } else { phys_shift = KVM_PHYS_SHIFT; + if (phys_shift > kvm_ipa_limit) { + pr_warn_once("%s using unsupported default IPA limit, upgrade your VMM\n", + current->comm); + return -EINVAL; + } } parange = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1) & 7;