From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E12EBC433EF for ; Wed, 1 Jun 2022 13:43:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=P1aq2uqBY5fly1I4DLBg8umN+HSLIiFTsaF3GdiLLm0=; b=M0P2JVKjvTG3cn wESYnL+JzV6GDfYu+wzV3KEy+8/5D32HzY16rkfCm8fZZEgvM1WWSBCltwfBEKc9Jp77IkmIccwlA OILcgtWEhSIVaU/2Dk4jDB4QwY5oiG6TBJuzSb2z/GkOlt/qMbtYdnqTP1Ogm4jVtkNfS0W274aci RqHG/VJcnbpd+uE4Ain4iotmGxdJNnZwWd7DWRTU/bFs6IPXdHYQJ9esTVKGyx55lY0oh/8bpbUQv T6dL1NRQfcUGQ1AyqZjLT4sU7SyjqQX087KAh15SDuoMHR2ooylLQ9bUoaPjkPpodTu230Ws2fbFW NWow+k9Q9T74aj9ZNcHA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nwOby-00GKZe-Aw; Wed, 01 Jun 2022 13:42:10 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nwOaZ-00GJwD-GM for linux-arm-kernel@lists.infradead.org; Wed, 01 Jun 2022 13:40:45 +0000 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 80E921480; Wed, 1 Jun 2022 06:40:42 -0700 (PDT) Received: from donnerap.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 498693F73D; Wed, 1 Jun 2022 06:40:41 -0700 (PDT) Date: Mon, 30 May 2022 18:13:53 +0100 From: Andre Przywara To: Alexandru Elisei Cc: will@kernel.org, julien.thierry.kdev@gmail.com, maz@kernel.org, suzuki.poulose@arm.com, julien@xen.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, james.morse@arm.com Subject: Re: [PATCH v3 kvmtool 04/13] builtin-run: Rework RAM size validation Message-ID: <20220530181353.777d92ae@donnerap.cambridge.arm.com> In-Reply-To: <20220525112345.121321-5-alexandru.elisei@arm.com> References: <20220525112345.121321-1-alexandru.elisei@arm.com> <20220525112345.121321-5-alexandru.elisei@arm.com> Organization: ARM X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.32; aarch64-unknown-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220601_064043_644218_0530D45A X-CRM114-Status: GOOD ( 23.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, 25 May 2022 12:23:36 +0100 Alexandru Elisei wrote: > host_ram_size() uses sysconf() to calculate the available ram, and > sysconf() can fail. When that happens, host_ram_size() returns 0. kvmtool > warns the user when the configured VM ram size exceeds the size of the > host's memory, but doesn't take into account that host_ram_size() can > return 0. If the function returns zero, skip the warning. > > Since this can only happen when the user sets the memory size (via the > -m/--mem command line argument), skip the check entirely if the user hasn't > set it. Move the check to kvm_run_validate_cfg(), as it checks for valid > user configuration. > > Signed-off-by: Alexandru Elisei > --- > builtin-run.c | 20 +++++++++++++------- > 1 file changed, 13 insertions(+), 7 deletions(-) > > diff --git a/builtin-run.c b/builtin-run.c > index 4fc7cbed1d17..b1accbce7da3 100644 > --- a/builtin-run.c > +++ b/builtin-run.c > @@ -509,6 +509,8 @@ static void kvm_run_set_real_cmdline(struct kvm *kvm) > > static void kvm_run_validate_cfg(struct kvm *kvm) > { > + u64 available_ram; Just a nit, you can pull this declaration inside the if statement below, IIUC you will only need it there. Otherwise looks fine: Reviewed-by: Andre Przywara > + > if (kvm->cfg.kernel_filename && kvm->cfg.firmware_filename) > die("Only one of --kernel or --firmware can be specified"); > > @@ -518,6 +520,17 @@ static void kvm_run_validate_cfg(struct kvm *kvm) > > if (kvm->cfg.firmware_filename && kvm->cfg.initrd_filename) > pr_warning("Ignoring initrd file when loading a firmware image"); > + > + if (kvm->cfg.ram_size) { > + /* User specifies RAM size in megabytes. */ > + kvm->cfg.ram_size <<= MB_SHIFT; > + available_ram = host_ram_size(); > + if (available_ram && kvm->cfg.ram_size > available_ram) { > + pr_warning("Guest memory size %lluMB exceeds host physical RAM size %lluMB", > + (unsigned long long)kvm->cfg.ram_size >> MB_SHIFT, > + (unsigned long long)available_ram >> MB_SHIFT); > + } > + } > } > > static struct kvm *kvm_cmd_run_init(int argc, const char **argv) > @@ -596,13 +609,6 @@ static struct kvm *kvm_cmd_run_init(int argc, const char **argv) > > if (!kvm->cfg.ram_size) > kvm->cfg.ram_size = get_ram_size(kvm->cfg.nrcpus); > - else > - kvm->cfg.ram_size <<= MB_SHIFT; > - > - if (kvm->cfg.ram_size > host_ram_size()) > - pr_warning("Guest memory size %lluMB exceeds host physical RAM size %lluMB", > - (unsigned long long)kvm->cfg.ram_size >> MB_SHIFT, > - (unsigned long long)host_ram_size() >> MB_SHIFT); > > if (!kvm->cfg.dev) > kvm->cfg.dev = DEFAULT_KVM_DEV; _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel