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=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 6C8C1C54FCB for ; Mon, 27 Apr 2020 15:00:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4CF20206B9 for ; Mon, 27 Apr 2020 15:00:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727807AbgD0PA2 (ORCPT ); Mon, 27 Apr 2020 11:00:28 -0400 Received: from foss.arm.com ([217.140.110.172]:36658 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727006AbgD0PA2 (ORCPT ); Mon, 27 Apr 2020 11:00:28 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6746331B; Mon, 27 Apr 2020 08:00:27 -0700 (PDT) Received: from [10.37.8.240] (unknown [10.37.8.240]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D5FCE3F68F; Mon, 27 Apr 2020 08:00:25 -0700 (PDT) Subject: Re: [PATCH][kvmtool] kvm: Request VM specific limits instead of system-wide ones From: Alexandru Elisei To: Marc Zyngier , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: James Morse , Julien Thierry , Suzuki K Poulose , Will Deacon , Andre Przywara , Ard Biesheuvel References: <20200427141738.285217-1-maz@kernel.org> Message-ID: <7ac17890-72d1-1c81-e513-5d4f7841ca9d@arm.com> Date: Mon, 27 Apr 2020 16:00:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hi, On 4/27/20 3:44 PM, Alexandru Elisei wrote: > Hi, > > On 4/27/20 3:17 PM, Marc Zyngier wrote: >> On arm64, the maximum number of vcpus is constrained by the type >> of interrupt controller that has been selected (GICv2 imposes a >> limit of 8 vcpus, while GICv3 currently has a limit of 512). >> >> It is thus important to request this limit on the VM file descriptor >> rather than on the one that corresponds to /dev/kvm, as the latter >> is likely to return something that doesn't take the constraints into >> account. >> >> Reported-by: Ard Biesheuvel >> Signed-off-by: Marc Zyngier >> --- >> kvm.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/kvm.c b/kvm.c >> index e327541..3d5173d 100644 >> --- a/kvm.c >> +++ b/kvm.c >> @@ -406,7 +406,7 @@ int kvm__recommended_cpus(struct kvm *kvm) >> { >> int ret; >> >> - ret = ioctl(kvm->sys_fd, KVM_CHECK_EXTENSION, KVM_CAP_NR_VCPUS); >> + ret = ioctl(kvm->vm_fd, KVM_CHECK_EXTENSION, KVM_CAP_NR_VCPUS); >> if (ret <= 0) >> /* >> * api.txt states that if KVM_CAP_NR_VCPUS does not exist, >> @@ -421,7 +421,7 @@ int kvm__max_cpus(struct kvm *kvm) >> { >> int ret; >> >> - ret = ioctl(kvm->sys_fd, KVM_CHECK_EXTENSION, KVM_CAP_MAX_VCPUS); >> + ret = ioctl(kvm->vm_fd, KVM_CHECK_EXTENSION, KVM_CAP_MAX_VCPUS); >> if (ret <= 0) >> ret = kvm__recommended_cpus(kvm); >> > I've checked that gic__create comes before the call kvm__recommended_capus: > gic__create is in core_init (called via kvm__init->kvm_arch_init), and > kvm__recommended_cpus is in base_init (called via kvm__cpu_init -> > kvm__{recommended,max}_cpus). > > The KVM api documentation states that KVM_CHECK_EXTENSION is available for the vm > fd only if the system capability KVM_CAP_CHECK_EXTENSION_VM is present. kvmtool > already has a function for checking extensions on the vm fd, it's called > kvm__supports_vm_extension. Can we use that instead of doing the ioctl directly on > the vm fd? Scratch that, kvm__supports_vm_extension returns a bool, not an int. How about we write kvm__check_vm_extension that returns an int, and kvm__supports_vm_extension calls it? > > Thanks, > Alex