From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 2002:a19:6d5:0:0:0:0:0 with SMTP id 204csp3143362lfg; Tue, 9 Mar 2021 12:31:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+B7Covvg0lgCGEWcJPWqw+E/ubj2fDq52HteLpgjoSvE1gAVa0kNlEulv9pEQVPaipfWE X-Received: by 2002:ab0:6847:: with SMTP id a7mr17090943uas.51.1615321917379; Tue, 09 Mar 2021 12:31:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615321917; cv=none; d=google.com; s=arc-20160816; b=MPWBNrbDhCtkW344kArh17Oa4Yjf0jR5PlyekQQKMlfv28Pp28q1sSGYBF3x2sN1BT fJgrRKuNT7TdcnSiHohPiqqKMHdByJxiQc/wqZktRZLNUubS+Dxz3HH86yvmtmVfDhJ/ T4x0ScMkqKBnccIs1z23WNIhBNoz8emRU3aIfGYITqBjLBKa3H88Ma9xCpUTNit7+6k0 MWCgxkujB/MbNwu/EVionMm1KXDZVm/hlmERXVRVuRjY2ynIGK2FWPTsu+uzJ2x0Lw7Q zjYh6nudk70PpeSGCtq4E+jx/epQpc1IqGS3QWrZGK0Zh87uinb4pC7+lmBrbVr4Lxfk 7RYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :references:in-reply-to:subject:to:from:message-id:date; bh=J0H+hxR9r7tunkVS1mvo4RoYJCPiaxxZQN1XHCS7Ihk=; b=XpgjBnHF1MzVrzk7GPCUD/RkUzuDnAiUGpb2Pu94gkB+Qiamet0asA73ZWHS/vsWdr BWlngX+7mAeTEwzGh1vRGCrmnnb2OLC8VigmFmUIuGoaVM9HF8Mi+MqjxDKrLx7U0SbG gZumffuPUlla4LM7ZiA3LjvIHMlqM5NnFXTI3Vh+j5A5zv9j5fE9XrUJ9grgTFCj8AA0 pm5COk2/6/lCvhuIscm09WE88ELczzSEreiz9FlmFp5T1gaMyhjnk4H/8isNy97hEgZL ioi/zUesEdW8EbPVCWF0ns8OYswuRexhry6SWQtgZf8Xfx3psx9a9vaHcayEtqln44Qg aALA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m18si2649372vsp.43.2021.03.09.12.31.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 09 Mar 2021 12:31:57 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from localhost ([::1]:54758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJj1I-0006po-JM for alex.bennee@linaro.org; Tue, 09 Mar 2021 15:31:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJhvi-0007bv-SE; Tue, 09 Mar 2021 14:22:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:40278) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJhvf-0006cr-TY; Tue, 09 Mar 2021 14:22:06 -0500 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 5644D64F6C; Tue, 9 Mar 2021 19:22:01 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lJhvb-000cVW-A9; Tue, 09 Mar 2021 19:21:59 +0000 Date: Tue, 09 Mar 2021 19:21:58 +0000 Message-ID: <87eegoxhd5.wl-maz@kernel.org> From: Marc Zyngier To: Andrew Jones Subject: Re: [PATCH] hw/arm/virt: KVM: The IPA lower bound is 32 In-Reply-To: <20210309185939.188431-1-drjones@redhat.com> References: <20210309185939.188431-1-drjones@redhat.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: drjones@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, eric.auger@redhat.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Received-SPF: pass client-ip=198.145.29.99; envelope-from=maz@kernel.org; helo=mail.kernel.org X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, qemu-devel@nongnu.org, eric.auger@redhat.com Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: T+NF7g77x5yy Hi Andrew, On Tue, 09 Mar 2021 18:59:39 +0000, Andrew Jones wrote: > > The virt machine already checks KVM_CAP_ARM_VM_IPA_SIZE to get the > upper bound of the IPA size. If that bound is lower than the highest > possible GPA for the machine, then QEMU will error out. However, the > IPA is set to 40 when the highest GPA is less than or equal to 40, > even when KVM may only support an IPA limit as low as 32. This means > KVM may fail the VM creation unnecessarily. Additionally, 40 is > selected with the value 0, which means use the default, and that gets > around a check in some versions of KVM, causing a difficult to debug > fail. Always use the IPA size that corresponds to the highest possible > GPA, unless it's lower than 32, in which case use 32. > > Signed-off-by: Andrew Jones > --- > hw/arm/virt.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/hw/arm/virt.c b/hw/arm/virt.c > index 371147f3ae9c..7bf563715b4e 100644 > --- a/hw/arm/virt.c > +++ b/hw/arm/virt.c > @@ -2547,14 +2547,13 @@ static int virt_kvm_type(MachineState *ms, const char *type_str) > "require an IPA range (%d bits) larger than " > "the one supported by the host (%d bits)", > requested_pa_size, max_vm_pa_size); > - exit(1); > + exit(1); > } > + > /* > - * By default we return 0 which corresponds to an implicit legacy > - * 40b IPA setting. Otherwise we return the actual requested PA > - * logsize > + * KVM requires the IPA size to be at least 32 bits. > */ > - return requested_pa_size > 40 ? requested_pa_size : 0; > + return requested_pa_size < 32 ? 32 : requested_pa_size; Doesn't this break on older kernels (pre 233a7cb23531, which is anything up 4.19), where the 'type' parameter passed at VM creation time was expected to be 0 and nothing else? I had a quick go at qemu a couple of weeks back and came up with the following hack, but never actually tested it (there is no way qemu can fit in the initramfs I am feeding to this damn machine...). Thanks, M. diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 371147f3ae..3301bb8dba 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2534,8 +2534,11 @@ static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine, static int virt_kvm_type(MachineState *ms, const char *type_str) { VirtMachineState *vms = VIRT_MACHINE(ms); - int max_vm_pa_size = kvm_arm_get_max_vm_ipa_size(ms); + int max_vm_pa_size; int requested_pa_size; + bool fixed_ipa; + + max_vm_pa_size = kvm_arm_get_max_vm_ipa_size(ms, &fixed_ipa); /* we freeze the memory map to compute the highest gpa */ virt_set_memmap(vms); @@ -2550,11 +2553,12 @@ static int virt_kvm_type(MachineState *ms, const char *type_str) exit(1); } /* - * By default we return 0 which corresponds to an implicit legacy - * 40b IPA setting. Otherwise we return the actual requested PA - * logsize + * We return the requested PA log size, unless KVM only supports + * the implicit legacy 40b IPA setting, in which case we return 0. */ - return requested_pa_size > 40 ? requested_pa_size : 0; + if (fixed_ipa) + return 0; + return requested_pa_size; } static void virt_machine_class_init(ObjectClass *oc, void *data) diff --git a/slirp b/slirp index 8f43a99191..ce94eba204 160000 --- a/slirp +++ b/slirp @@ -1 +1 @@ -Subproject commit 8f43a99191afb47ca3f3c6972f6306209f367ece +Subproject commit ce94eba2042d52a0ba3d9e252ebce86715e94275 diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 00e124c812..5f576730e6 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -230,12 +230,14 @@ bool kvm_arm_pmu_supported(void) return kvm_check_extension(kvm_state, KVM_CAP_ARM_PMU_V3); } -int kvm_arm_get_max_vm_ipa_size(MachineState *ms) +int kvm_arm_get_max_vm_ipa_size(MachineState *ms, bool *fixed_ipa) { KVMState *s = KVM_STATE(ms->accelerator); int ret; ret = kvm_check_extension(s, KVM_CAP_ARM_VM_IPA_SIZE); + *fixed_ipa = !(ret > 0); + return ret > 0 ? ret : 40; } diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h index eb81b7059e..75d7133a35 100644 --- a/target/arm/kvm_arm.h +++ b/target/arm/kvm_arm.h @@ -311,10 +311,11 @@ bool kvm_arm_sve_supported(void); /** * kvm_arm_get_max_vm_ipa_size: * @ms: Machine state handle + * @fixed_ipa: Indicate whether the IPA address space is a fixed value * * Returns the number of bits in the IPA address space supported by KVM */ -int kvm_arm_get_max_vm_ipa_size(MachineState *ms); +int kvm_arm_get_max_vm_ipa_size(MachineState *ms, bool *fixed_ipa); /** * kvm_arm_sync_mpstate_to_kvm: @@ -409,7 +410,7 @@ static inline void kvm_arm_add_vcpu_properties(Object *obj) g_assert_not_reached(); } -static inline int kvm_arm_get_max_vm_ipa_size(MachineState *ms) +static inline int kvm_arm_get_max_vm_ipa_size(MachineState *ms, bool *fixed_ipa) { g_assert_not_reached(); } -- Without deviation from the norm, progress is not possible.