Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3529618pxf; Mon, 15 Mar 2021 11:35:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2sSaQl1MWi/+HY16zFh/4ao6DnMO15lRjleQnTiiQEVo4P396hVOObBF9fnhboEF3gN5g X-Received: by 2002:aa7:c941:: with SMTP id h1mr31393029edt.85.1615833339978; Mon, 15 Mar 2021 11:35:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833339; cv=none; d=google.com; s=arc-20160816; b=H0+mnOlGwLoTJvvOTP8e/K+NPzKz1dhjpSbqe1C48T4CLmaUH8TT4dqDTBe6fTEjhP hK3GBf5LoSrXGl2odPcCEJeN8q9j42qBWbG/IzQ8XM9Dc4Ds/W5IiYNrvAwiedtTv/o/ BMvZrZ5tm2b8zI5UKzlculWgnX7rwxFruM31KNV6p+6KKsYTfKWCa1CQQoQ2IY3AzdGv qGODRYlcRrSJD/ktMoA6NfYUyw4Axty6u+msB+4z1fpGZQZB6q9S+FCrpOvSD1akSuok eHE/66GEDa6to5AXmwceJP5R8uSb4lzxVOaWFe/dDQ9xm5C8aUZ/ILY78akalmLHzA0N M+Ug== 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=NSn9gIQResy868rEyXF8GGCMpWsCF3JdaYIWPzWIyIU=; b=uKiJszjyxDpADwL0xTbuTxG8BV8RDFamz7AgN30whc46ayW0eiDEEQn21LMTPeC7Ig idZmIbzpzt40kOkF1oTjp8A8ishkO+tJVBDeMn+q9lVgfSa8QiccfM41aFq9+1mU0TPH dI3HRmo+TyAg/GMfMAlHOfDH3JfngGNx4VZsCQtFjUzuO0T+8TXIxHMICxWv6sN2xlle 8YYTwopzrjQhkC0F+zFlkE+/O9iHCQABaOJDU8h8NLpxtginej5R5CL1ZkeBeUHIPpvG V1K6WyDrNWrnoeE4zUjcJ6i2X7kIULDQidlDjn5g/y/akbvwlFlkuvQt6aLiHLCWPAsu ctdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GRnUDsIu; 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 n15si11350195edv.534.2021.03.15.11.35.17; Mon, 15 Mar 2021 11:35:39 -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=GRnUDsIu; 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 S233104AbhCOOth (ORCPT + 99 others); Mon, 15 Mar 2021 10:49:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:48878 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234240AbhCOOYy (ORCPT ); Mon, 15 Mar 2021 10:24:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3167265047; Mon, 15 Mar 2021 14:24:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615818288; bh=7MnvfKd837RLfo/gaxgjiy6cWwE0Vpuwlcy4TUIaAB0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GRnUDsIupPFNgF1+xVaS4D1bO+9kwlqhHl0MiOCR4Irsirx7PadSJbbBIeALsqlcc Qq3YkYZtgH+4HhSgXhqNNn1klxAvAeN177kW89Ygc3Ht4rDnoerGOLr5PycjXN6haj LniLnOzCDXeIT3sYUUfO8w3tK3S+EFgkNcn0QCnA= 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.11 298/306] KVM: arm64: Reject VM creation when the default IPA size is unsupported Date: Mon, 15 Mar 2021 15:24:23 +0100 Message-Id: <20210315135517.773732934@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135517.556638562@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> <20210315135517.556638562@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.rst | 3 +++ arch/arm64/kvm/reset.c | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -182,6 +182,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 @@ -324,10 +324,9 @@ int kvm_set_ipa_limit(void) } kvm_ipa_limit = id_aa64mmfr0_parange_to_phys_shift(parange); - WARN(kvm_ipa_limit < KVM_PHYS_SHIFT, - "KVM IPA Size Limit (%d bits) is smaller than default size\n", - kvm_ipa_limit); - kvm_info("IPA Size Limit: %d bits\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)" : "")); return 0; } @@ -356,6 +355,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; + } } mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1);