Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3529557pxf; Mon, 15 Mar 2021 11:35:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfkM83DZyvbiPihAGUREOW7sM2CaSiSDOe5zrJyAOg2hyzac3qaE+AW3umZH9BsQQJuhNq X-Received: by 2002:a17:906:b288:: with SMTP id q8mr25138692ejz.210.1615833334707; Mon, 15 Mar 2021 11:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833334; cv=none; d=google.com; s=arc-20160816; b=sYjc9uiXa8CV5Nyo+wAa5Zpg8nA6u9uecRiUdOVDCJyWJLSQC470B/eqn0qz/D0YgO Y/JkihleTSPrDaoQ4jwVugZ7ZuMa45vl6ng8sdAda0aCYlY5IBCpS9MVFvHN/DSP2I6o HJFw9X2kFm48uUUu/0S0RzYp+B7ETXN7bCz9l4rvigVKvHkrTq/cgCuP9VHq/UiSGsEe IxWhloyM6z+yDY9SXDi1iBkhP3nwZuzlhhAVlKBHujEw5gu08oq65aECs7rPDccf2qSy aLU7780inl9ZtDtqXp6uX3Avz8HjHH9Zy5lTiUudNTz/GqAAp0w24dbdOoB+w0l4LB6v 6i6w== 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=xndzWdNrVfgI/IY6gU1QuBWyXLPD9cfi36Dut6X/jKY=; b=a4ivEuVWsx+SKILua+V+z7cuMyPBm2HWKOHO6/bNB0me6X+tEuLJRFJkaqKhKFSHpg dhihbwqX6vkSSIBQpONvp+jgipgBuRNKnQEQcgrQYFLdNcQzEFe4kS44zp7qxPls1SGG D3HzCvxThI/z3eFOIo6r1DGTIVeuLbrpSWok92ZjiHEDyB3i9yAadhHydB3/dDLMEtrS Rqf+O+lOvXJyv0wIS8G03yx+ArkMLT3zP9m+pgXg/TFv2vlgUfwftHGnG97f1Z/yeLBY YWnbwkQ20d7iqPNXnXAcA0r9R5+69HtSJPTh9034QQdHSzQQLrm1jiKxdBr0QjGoQIhN A4yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c2WYHg4t; 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 t22si4219972ejj.746.2021.03.15.11.35.12; Mon, 15 Mar 2021 11:35:34 -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=c2WYHg4t; 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 S241539AbhCOOtG (ORCPT + 99 others); Mon, 15 Mar 2021 10:49:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:45534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238175AbhCOOWy (ORCPT ); Mon, 15 Mar 2021 10:22:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 08B7A64F43; Mon, 15 Mar 2021 14:22:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615818174; bh=DpkIbpQEfZ7SwN5Ce3lKP8CqAMzPfPB5FdqZBWagldw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c2WYHg4tzOJtuOdxU8AlUeJx6oNdoWtEoTfREIB/beakT5pTjZ3Bs89y6qhMh9AHE vgOxPvhYE6vVXLLleBbD7WUROR0hyatOFZKjM88AmrMwDg7/bp+ctX7QQ7bJIYXMFG uea3gjtXnkjf8/tKVN7An5pISfuc6JWbEEmK52RU= 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.10 281/290] KVM: arm64: Reject VM creation when the default IPA size is unsupported Date: Mon, 15 Mar 2021 15:22:31 +0100 Message-Id: <20210315135551.529410353@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135551.391322899@linuxfoundation.org> References: <20210315135541.921894249@linuxfoundation.org> <20210315135551.391322899@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 @@ -373,10 +373,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; } @@ -405,6 +404,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);